diff options
| -rw-r--r-- | src/main.c | 14 |
1 files changed, 7 insertions, 7 deletions
| @@ -57,7 +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 | static int drop_privileges = 0; |
| 61 | 61 | ||
| 62 | struct device_info { | 62 | struct device_info { |
| 63 | uint32_t device_id; | 63 | uint32_t device_id; |
| @@ -1006,7 +1006,7 @@ static void usage() | |||
| 1006 | printf("\t-v|--verbose be verbose (use twice or more to increase)\n"); | 1006 | printf("\t-v|--verbose be verbose (use twice or more to increase)\n"); |
| 1007 | printf("\t-f|--foreground do not daemonize\n"); | 1007 | printf("\t-f|--foreground do not daemonize\n"); |
| 1008 | printf("\t-e|--exit-on-no-devices exit if no device is attached\n"); | 1008 | printf("\t-e|--exit-on-no-devices exit if no device is attached\n"); |
| 1009 | printf("\t-p|--preserve-privileges do not drop privileges\n"); | 1009 | printf("\t-d|--drop-privileges drop privileges after startup\n"); |
| 1010 | printf("\n"); | 1010 | printf("\n"); |
| 1011 | } | 1011 | } |
| 1012 | 1012 | ||
| @@ -1017,13 +1017,13 @@ static void parse_opts(int argc, char **argv) | |||
| 1017 | {"foreground", 0, NULL, 'f'}, | 1017 | {"foreground", 0, NULL, 'f'}, |
| 1018 | {"verbose", 0, NULL, 'v'}, | 1018 | {"verbose", 0, NULL, 'v'}, |
| 1019 | {"exit-on-no-devices", 0, NULL, 'e'}, | 1019 | {"exit-on-no-devices", 0, NULL, 'e'}, |
| 1020 | {"preserve-privileges", 0, NULL, 'p'}, | 1020 | {"drop-privileges", 0, NULL, 'd'}, |
| 1021 | {NULL, 0, NULL, 0} | 1021 | {NULL, 0, NULL, 0} |
| 1022 | }; | 1022 | }; |
| 1023 | int c; | 1023 | int c; |
| 1024 | 1024 | ||
| 1025 | while (1) { | 1025 | while (1) { |
| 1026 | c = getopt_long(argc, argv, "hfvep", longopts, (int *) 0); | 1026 | c = getopt_long(argc, argv, "hfved", longopts, (int *) 0); |
| 1027 | if (c == -1) { | 1027 | if (c == -1) { |
| 1028 | break; | 1028 | break; |
| 1029 | } | 1029 | } |
| @@ -1041,8 +1041,8 @@ static void parse_opts(int argc, char **argv) | |||
| 1041 | case 'e': | 1041 | case 'e': |
| 1042 | exit_on_no_devices = 1; | 1042 | exit_on_no_devices = 1; |
| 1043 | break; | 1043 | break; |
| 1044 | case 'p': | 1044 | case 'd': |
| 1045 | preserve_privileges = 1; | 1045 | drop_privileges = 1; |
| 1046 | break; | 1046 | break; |
| 1047 | default: | 1047 | default: |
| 1048 | usage(); | 1048 | usage(); |
| @@ -1200,7 +1200,7 @@ int main(int argc, char **argv) | |||
| 1200 | } | 1200 | } |
| 1201 | } | 1201 | } |
| 1202 | // drop elevated privileges | 1202 | // drop elevated privileges |
| 1203 | if (!preserve_privileges && (getuid() == 0 || geteuid() == 0)) { | 1203 | if (drop_privileges && (getuid() == 0 || geteuid() == 0)) { |
| 1204 | struct passwd *pw = getpwnam("nobody"); | 1204 | struct passwd *pw = getpwnam("nobody"); |
| 1205 | if (pw) { | 1205 | if (pw) { |
| 1206 | setuid(pw->pw_uid); | 1206 | setuid(pw->pw_uid); |
