X-Git-Url: https://git.distorted.org.uk/~mdw/become/blobdiff_plain/4c37c6af624a9d4dabadac32a5e566d388ee78d7..b0f66028a9a17a845590a4fe737a4f5e46f6b778:/src/become.c diff --git a/src/become.c b/src/become.c index 60cb1f3..1edb89c 100644 --- a/src/become.c +++ b/src/become.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: become.c,v 1.23 2003/10/12 10:00:06 mdw Exp $ + * $Id: become.c,v 1.25 2003/11/29 23:39:16 mdw Exp $ * * Main code for `become' * @@ -29,6 +29,12 @@ /*----- Revision history --------------------------------------------------* * * $Log: become.c,v $ + * Revision 1.25 2003/11/29 23:39:16 mdw + * Debianization. + * + * Revision 1.24 2003/10/15 09:27:06 mdw + * Make sure standard file descriptors are open before starting properly. + * * Revision 1.23 2003/10/12 10:00:06 mdw * Fix for daemon mode. Oops. * @@ -150,6 +156,7 @@ #include #include #include +#include extern char **environ; @@ -558,6 +565,17 @@ int main(int argc, char *argv[]) if (getuid() != geteuid()) flags |= f_setuid; + /* --- Make sure standard file descriptors are open --- */ + + { + int fd; + do { + if ((fd = open("/dev/null", O_RDWR)) < 0) + die(1, "couldn't open /dev/null: %s", strerror(errno)); + } while (fd <= STDERR_FILENO); + close(fd); + } + /* --- Read the environment into a hashtable --- */ { @@ -589,7 +607,7 @@ int main(int argc, char *argv[]) /* --- Group style options --- */ - { "group", gFlag_argReq, 0, 'g' }, + { "group", OPTF_ARGREQ, 0, 'g' }, #ifdef HAVE_SETGROUPS { "keep-groups", 0, 0, 'k' }, { "merge-groups", 0, 0, 'm' }, @@ -598,23 +616,23 @@ int main(int argc, char *argv[]) /* --- Command to run options --- */ - { "command", gFlag_argReq, 0, 'c' }, + { "command", OPTF_ARGREQ, 0, 'c' }, /* --- Server options --- */ #ifndef NONETWORK { "daemon", 0, 0, 'd' }, { "nofork", 0, 0, 'n' }, - { "port", gFlag_argReq, 0, 'p' }, - { "config-file", gFlag_argReq, 0, 'f' }, + { "port", OPTF_ARGREQ, 0, 'p' }, + { "config-file", OPTF_ARGREQ, 0, 'f' }, #endif /* --- Tracing options --- */ #ifndef NTRACE - { "impersonate", gFlag_argReq, 0, 'I' }, - { "trace", gFlag_argOpt, 0, 'T' }, - { "trace-level", gFlag_argOpt, 0, 'L' }, + { "impersonate", OPTF_ARGREQ, 0, 'I' }, + { "trace", OPTF_ARGOPT, 0, 'T' }, + { "trace-level", OPTF_ARGOPT, 0, 'L' }, #endif { 0, 0, 0, 0 } @@ -1308,7 +1326,7 @@ done_options: for (pp = banned; *pp; pp++) { if (**pp == '-') { p = *pp + 1; - if (memcmp(e->_base.name, p, strlen(p)) == 0) + if (strncmp(e->_base.name, p, strlen(p)) == 0) goto expunge; } else if (strcmp(e->_base.name, *pp) == 0) goto expunge;