diff options
author | Mattias Andrée <maandree@operamail.com> | 2014-05-06 15:32:47 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2014-05-06 15:32:47 +0200 |
commit | fcecad2b77f54c1ce356190168db8ac2c216f30d (patch) | |
tree | 47bdf6a30375154474ba36a9676bff0cffffdf1b /src/mds-server.c | |
parent | m (diff) | |
download | mds-fcecad2b77f54c1ce356190168db8ac2c216f30d.tar.gz mds-fcecad2b77f54c1ce356190168db8ac2c216f30d.tar.bz2 mds-fcecad2b77f54c1ce356190168db8ac2c216f30d.tar.xz |
add strequals and startswith macros + add drop_privileges macro that drops the group before the user
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rw-r--r-- | src/mds-server.c | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/src/mds-server.c b/src/mds-server.c index 9f7d16b..20fc97e 100644 --- a/src/mds-server.c +++ b/src/mds-server.c @@ -123,8 +123,7 @@ int main(int argc_, char** argv_) /* Drop privileges like it's hot. */ - if ((geteuid() == getuid() ? 0 : seteuid(getuid())) || - (getegid() == getgid() ? 0 : setegid(getgid()))) + if (drop_privileges()) { perror(*argv); return 1; @@ -143,7 +142,7 @@ int main(int argc_, char** argv_) for (i = 1; i < argc; i++) { char* arg = argv[i]; - if (!strcmp(arg, "--initial-spawn")) /* Initial spawn? */ + if (strequals(arg, "--initial-spawn")) /* Initial spawn? */ if (is_respawn == 1) { eprintf("conflicting arguments %s and %s cannot be combined.", @@ -152,7 +151,7 @@ int main(int argc_, char** argv_) } else is_respawn = 0; - else if (!strcmp(arg, "--respawn")) /* Respawning after crash? */ + else if (strequals(arg, "--respawn")) /* Respawning after crash? */ if (is_respawn == 0) { eprintf("conflicting arguments %s and %s cannot be combined.", @@ -161,7 +160,7 @@ int main(int argc_, char** argv_) } else is_respawn = 1; - else if (strstr(arg, "--socket-fd=") == arg) /* Socket file descriptor. */ + else if (startswith(arg, "--socket-fd=")) /* Socket file descriptor. */ { long int r; char* endptr; @@ -173,15 +172,15 @@ int main(int argc_, char** argv_) arg += strlen("--socket-fd="); r = strtol(arg, &endptr, 10); if ((*argv == '\0') || isspace(*argv) || - (endptr - arg != (ssize_t)strlen(arg)) - || (r < 0) || (r > INT_MAX)) + (endptr - arg != (ssize_t)strlen(arg)) || + (r < 0) || (r > INT_MAX)) { eprintf("invalid value for %s: %s.", "--socket-fd", arg); return 1; } socket_fd = (int)r; } - else if (!strcmp(arg, "--re-exec")) /* Re-exec state-marshal. */ + else if (strequals(arg, "--re-exec")) /* Re-exec state-marshal. */ reexec = 1; else /* Not recognised, it is probably for another server. */ |