summaryrefslogtreecommitdiffstats
path: root/daemon/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'daemon/main.c')
-rw-r--r--daemon/main.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/daemon/main.c b/daemon/main.c
index 363f3d5..18b28a8 100644
--- a/daemon/main.c
+++ b/daemon/main.c
@@ -56,7 +56,7 @@ int should_discover;
56static int verbose = 0; 56static int verbose = 0;
57static int foreground = 0; 57static int foreground = 0;
58static int drop_privileges = 0; 58static int drop_privileges = 0;
59static const char *drop_user = "usbmux"; 59static const char *drop_user = NULL;
60static int opt_udev = 0; 60static int opt_udev = 0;
61static int opt_exit = 0; 61static int opt_exit = 0;
62static int exit_signal = 0; 62static int exit_signal = 0;
@@ -336,8 +336,7 @@ static void usage()
336 printf("\t-h|--help Print this message.\n"); 336 printf("\t-h|--help Print this message.\n");
337 printf("\t-v|--verbose Be verbose (use twice or more to increase).\n"); 337 printf("\t-v|--verbose Be verbose (use twice or more to increase).\n");
338 printf("\t-f|--foreground Do not daemonize (implies one -v).\n"); 338 printf("\t-f|--foreground Do not daemonize (implies one -v).\n");
339 printf("\t-U|--user[=USER] Change to this user after startup (needs usb privileges).\n"); 339 printf("\t-U|--user USER Change to this user after startup (needs usb privileges).\n");
340 printf("\t If USER is not specified, defaults to usbmux.\n");
341 printf("\t-u|--udev Run in udev operation mode.\n"); 340 printf("\t-u|--udev Run in udev operation mode.\n");
342 printf("\t-x|--exit Tell a running instance to exit if there are no devices\n"); 341 printf("\t-x|--exit Tell a running instance to exit if there are no devices\n");
343 printf("\t connected (must be in udev mode).\n"); 342 printf("\t connected (must be in udev mode).\n");
@@ -361,7 +360,7 @@ static void parse_opts(int argc, char **argv)
361 int c; 360 int c;
362 361
363 while (1) { 362 while (1) {
364 c = getopt_long(argc, argv, "hfvuU::xX", longopts, (int *) 0); 363 c = getopt_long(argc, argv, "hfvuU:xX", longopts, (int *) 0);
365 if (c == -1) { 364 if (c == -1) {
366 break; 365 break;
367 } 366 }
@@ -378,8 +377,7 @@ static void parse_opts(int argc, char **argv)
378 break; 377 break;
379 case 'U': 378 case 'U':
380 drop_privileges = 1; 379 drop_privileges = 1;
381 if(optarg) 380 drop_user = optarg;
382 drop_user = optarg;
383 break; 381 break;
384 case 'u': 382 case 'u':
385 opt_udev = 1; 383 opt_udev = 1;
@@ -519,7 +517,13 @@ int main(int argc, char *argv[])
519 517
520 // drop elevated privileges 518 // drop elevated privileges
521 if (drop_privileges && (getuid() == 0 || geteuid() == 0)) { 519 if (drop_privileges && (getuid() == 0 || geteuid() == 0)) {
522 struct passwd *pw = getpwnam(drop_user); 520 struct passwd *pw;
521 if (!drop_user) {
522 usbmuxd_log(LL_FATAL, "No user to drop privileges to?");
523 res = -1;
524 goto terminate;
525 }
526 pw = getpwnam(drop_user);
523 if (!pw) { 527 if (!pw) {
524 usbmuxd_log(LL_FATAL, "Dropping privileges failed, check if user '%s' exists!", drop_user); 528 usbmuxd_log(LL_FATAL, "Dropping privileges failed, check if user '%s' exists!", drop_user);
525 res = -1; 529 res = -1;