summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/main.c b/src/main.c
index 3617e14..9e99c1b 100644
--- a/src/main.c
+++ b/src/main.c
@@ -57,6 +57,7 @@ static int fsock = -1;
static int verbose = DEBUG_LEVEL;
static int foreground = 0;
static int exit_on_no_devices = 0;
+static int preserve_privileges = 0;
struct device_info {
uint32_t device_id;
@@ -1009,9 +1010,11 @@ static int daemonize()
static void usage()
{
printf("usage: usbmuxd [options]\n");
- printf("\t-h|--help print this message.\n");
- printf("\t-v|--verbose be verbose\n");
- printf("\t-f|--foreground do not daemonize\n");
+ printf("\t-h|--help print this message\n");
+ printf("\t-v|--verbose be verbose (use twice or more to increase)\n");
+ printf("\t-f|--foreground do not daemonize\n");
+ printf("\t-e|--exit-on-no-devices exit if no device is attached\n");
+ printf("\t-p|--preserve-privileges do not drop privileges\n");
printf("\n");
}
@@ -1022,12 +1025,13 @@ static void parse_opts(int argc, char **argv)
{"foreground", 0, NULL, 'f'},
{"verbose", 0, NULL, 'v'},
{"exit-on-no-devices", 0, NULL, 'e'},
+ {"preserve-privileges", 0, NULL, 'p'},
{NULL, 0, NULL, 0}
};
int c;
while (1) {
- c = getopt_long(argc, argv, "hfve", longopts, (int *) 0);
+ c = getopt_long(argc, argv, "hfvep", longopts, (int *) 0);
if (c == -1) {
break;
}
@@ -1045,6 +1049,9 @@ static void parse_opts(int argc, char **argv)
case 'e':
exit_on_no_devices = 1;
break;
+ case 'p':
+ preserve_privileges = 1;
+ break;
default:
usage();
exit(2);
@@ -1198,7 +1205,7 @@ int main(int argc, char **argv)
}
}
// drop elevated privileges
- if (getuid() == 0 || geteuid() == 0) {
+ if (!preserve_privileges && (getuid() == 0 || geteuid() == 0)) {
struct passwd *pw = getpwnam("nobody");
if (pw) {
setuid(pw->pw_uid);