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;
57static int verbose = DEBUG_LEVEL; 57static int verbose = DEBUG_LEVEL;
58static int foreground = 0; 58static int foreground = 0;
59static int exit_on_no_devices = 0; 59static int exit_on_no_devices = 0;
60static int preserve_privileges = 0;
60 61
61struct device_info { 62struct device_info {
62 uint32_t device_id; 63 uint32_t device_id;
@@ -1009,9 +1010,11 @@ static int daemonize()
1009static void usage() 1010static void usage()
1010{ 1011{
1011 printf("usage: usbmuxd [options]\n"); 1012 printf("usage: usbmuxd [options]\n");
1012 printf("\t-h|--help print this message.\n"); 1013 printf("\t-h|--help print this message\n");
1013 printf("\t-v|--verbose be verbose\n"); 1014 printf("\t-v|--verbose be verbose (use twice or more to increase)\n");
1014 printf("\t-f|--foreground do not daemonize\n"); 1015 printf("\t-f|--foreground do not daemonize\n");
1016 printf("\t-e|--exit-on-no-devices exit if no device is attached\n");
1017 printf("\t-p|--preserve-privileges do not drop privileges\n");
1015 printf("\n"); 1018 printf("\n");
1016} 1019}
1017 1020
@@ -1022,12 +1025,13 @@ static void parse_opts(int argc, char **argv)
1022 {"foreground", 0, NULL, 'f'}, 1025 {"foreground", 0, NULL, 'f'},
1023 {"verbose", 0, NULL, 'v'}, 1026 {"verbose", 0, NULL, 'v'},
1024 {"exit-on-no-devices", 0, NULL, 'e'}, 1027 {"exit-on-no-devices", 0, NULL, 'e'},
1028 {"preserve-privileges", 0, NULL, 'p'},
1025 {NULL, 0, NULL, 0} 1029 {NULL, 0, NULL, 0}
1026 }; 1030 };
1027 int c; 1031 int c;
1028 1032
1029 while (1) { 1033 while (1) {
1030 c = getopt_long(argc, argv, "hfve", longopts, (int *) 0); 1034 c = getopt_long(argc, argv, "hfvep", longopts, (int *) 0);
1031 if (c == -1) { 1035 if (c == -1) {
1032 break; 1036 break;
1033 } 1037 }
@@ -1045,6 +1049,9 @@ static void parse_opts(int argc, char **argv)
1045 case 'e': 1049 case 'e':
1046 exit_on_no_devices = 1; 1050 exit_on_no_devices = 1;
1047 break; 1051 break;
1052 case 'p':
1053 preserve_privileges = 1;
1054 break;
1048 default: 1055 default:
1049 usage(); 1056 usage();
1050 exit(2); 1057 exit(2);
@@ -1198,7 +1205,7 @@ int main(int argc, char **argv)
1198 } 1205 }
1199 } 1206 }
1200 // drop elevated privileges 1207 // drop elevated privileges
1201 if (getuid() == 0 || geteuid() == 0) { 1208 if (!preserve_privileges && (getuid() == 0 || geteuid() == 0)) {
1202 struct passwd *pw = getpwnam("nobody"); 1209 struct passwd *pw = getpwnam("nobody");
1203 if (pw) { 1210 if (pw) {
1204 setuid(pw->pw_uid); 1211 setuid(pw->pw_uid);