-const char jcc_rcs[] = "$Id: jcc.c,v 1.69 2002/03/04 23:50:00 jongfoster Exp $";
+const char jcc_rcs[] = "$Id: jcc.c,v 1.70 2002/03/05 04:52:42 oes Exp $";
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/jcc.c,v $
*
* Revisions :
* $Log: jcc.c,v $
+ * Revision 1.70 2002/03/05 04:52:42 oes
+ * Deleted non-errlog debugging code
+ *
* Revision 1.69 2002/03/04 23:50:00 jongfoster
* Splitting off bind_port() call into bind_port_helper(), with
* improved logging.
#include <sys/termios.h>
#endif /* sun */
+#ifdef unix
+#include <pwd.h>
+#endif
+
# include <signal.h>
# ifdef __BEOS__
void usage(const char *myname)
{
printf("JunkBuster proxy version " VERSION " (" HOME_PAGE_URL ")\n"
- "Usage: %s [--help] [--version] [--no-daemon] [--pidfile pidfile] [configfile]\n"
+ "Usage: %s [--help] [--version] [--no-daemon] [--pidfile pidfile] [--user user] [configfile]\n"
"Aborting.\n", myname);
exit(2);
#endif
{
int argc_pos = 0;
+ struct passwd *pw;
Argc = argc;
Argv = argv;
if (++argc_pos == argc) usage(argv[0]);
pidfile = strdup(argv[argc_pos]);
}
+
+ else if (strcmp(argv[argc_pos], "--user" ) == 0)
+ {
+ if (++argc_pos == argc) usage(argv[0]);
+ pw = getpwnam(argv[argc_pos]);
+
+ if (pw == NULL)
+ {
+ log_error(LOG_LEVEL_FATAL, "User %s not found.", argv[argc_pos]);
+ }
+ }
else
#endif /* defined(_WIN32) && !defined(_WIN_CONSOLE) */
{
close( 1 );
chdir("/");
- write_pid_file();
-
} /* -END- if (!no_daemon) */
+
+ /*
+ * As soon as we have written the PID file, we can switch
+ * to the user ID indicated by the --user option
+ */
+ write_pid_file();
+
+ if (setuid(pw->pw_uid))
+ {
+ log_error(LOG_LEVEL_FATAL, "Cannot setuid(): Insufficient permissions.");
+ }
+
}
#endif /* defined unix */
\fIpidfile\fP on exit. Failiure to create or delete the\r
\fIpidfile\fP is non-fatal. If no \fB--pidfile\fP option\r
is given, no PID file will be used.\r
+.TP\r
+\fB --user\fP \fIuser\fP (unix only)\r
+After (optionally) writing the PID file, assume the user ID\r
+of \fIuser\fP. Exit if the privileges are not sufficient to\r
+do so.\r
\r
.PP\r
If the \fIconfig file\fP is not specified on the command line,\r