diff options
| author | 2009-05-21 22:25:21 +0200 | |
|---|---|---|
| committer | 2009-05-21 22:25:21 +0200 | |
| commit | f8141b55b230dd4c66b39cee843149bdabe13580 (patch) | |
| tree | 1c9faa5b8a381ceaa06813062be883ebefef91d9 /src | |
| parent | 0c55afdb315f12b0f2a37f37a3ec711c75507c0d (diff) | |
| download | usbmuxd-f8141b55b230dd4c66b39cee843149bdabe13580.tar.gz usbmuxd-f8141b55b230dd4c66b39cee843149bdabe13580.tar.bz2 | |
Added parameter -p to prevent usbmuxd from dropping privileges
(see this as a workaround for systems where the usb device access is
restricted)
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.c | 17 |
1 files changed, 12 insertions, 5 deletions
| @@ -57,6 +57,7 @@ static int fsock = -1; | |||
| 57 | static int verbose = DEBUG_LEVEL; | 57 | static int verbose = DEBUG_LEVEL; |
| 58 | static int foreground = 0; | 58 | static int foreground = 0; |
| 59 | static int exit_on_no_devices = 0; | 59 | static int exit_on_no_devices = 0; |
| 60 | static int preserve_privileges = 0; | ||
| 60 | 61 | ||
| 61 | struct device_info { | 62 | struct device_info { |
| 62 | uint32_t device_id; | 63 | uint32_t device_id; |
| @@ -1009,9 +1010,11 @@ static int daemonize() | |||
| 1009 | static void usage() | 1010 | static 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); |
