changeset 2:2517dd7ac6d4

set username and group
author Simon Horman <horms@verge.net.au>
date Mon, 13 May 2002 16:23:00 +0900
parents c06480deb43d
children b9cfe75b8b91
files acconfig.h configure.in pbs/pbs.c pbs/pbs_log.h pbs/pbs_option.c pbs/pbs_option.h
diffstat 6 files changed, 73 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/acconfig.h	Mon May 13 15:48:39 2002 +0900
+++ b/acconfig.h	Mon May 13 16:23:00 2002 +0900
@@ -23,5 +23,11 @@
  *
  **********************************************************************/
 
+/* User to run perdition as */
+/* #define WITH_USER "nobody" */
+
+/* Group to run perdition as */
+/* #define WITH_GROUP "nobody" */
+
 /* Should we use DMALLOC */
 /* #define WITH_DMALLOC 1 */
--- a/configure.in	Mon May 13 15:48:39 2002 +0900
+++ b/configure.in	Mon May 13 16:23:00 2002 +0900
@@ -76,5 +76,26 @@
 
 )
 
+######################################################################
+# User and Group to run as
+
+AC_ARG_WITH(
+  user,
+  [  --with-user=USER        Run perdition-pbs as USER. [default=nobody]  ],
+  [ perdition_user="$withval" ],
+  [ perdition_user="nobody" ],
+)
+AC_DEFINE_UNQUOTED(WITH_USER, "$perdition_user", User to run perdition as )
+
+
+AC_ARG_WITH(
+  group,
+  [  --with-group=GROUP      Run perdition-pbs as GROUP. [default=nobody]  ],
+  [ perdition_group="$withval" ],
+  [ perdition_group="nobody" ],
+)
+AC_DEFINE_UNQUOTED(WITH_GROUP, "$perdition_group", Group to run perdition
+as )
+
 
 AC_OUTPUT(Makefile pbs/Makefile INSTALL)
--- a/pbs/pbs.c	Mon May 13 15:48:39 2002 +0900
+++ b/pbs/pbs.c	Mon May 13 16:23:00 2002 +0900
@@ -98,6 +98,8 @@
 		goto leave;
 	}
 
+	vanessa_socket_logger_set(pbs_vl);
+
 	opt = pbs_options_parse(argc, argv);
 	if(opt == NULL) {
 		PBS_DEBUG("pbs_options_parse");	
@@ -129,11 +131,19 @@
 		vanessa_logger_change_max_priority(pbs_vl, opt->log_level);
 	}
 
+	vanessa_socket_logger_set(pbs_vl);
+
 	if(opt->mode == PBS_MODE_DAEMON || 
 			opt->log_level == PBS_LOG_LEVEL_DEBUG) {
 		pbs_options_log(opt);
 	}
 
+	if(!geteuid() && vanessa_socket_daemon_setid(opt->user, opt->group)){
+		PBS_DEBUG("vanessa_socket_daemon_setid");
+		PBS_ERR("Fatal error setting group and userid. Exiting.");
+		vanessa_socket_daemon_exit_cleanly(-1);
+	}
+
 	/*Set signal handlers*/
 	signal(SIGHUP,    pbs_reread_handler);
 	signal(SIGINT,    pbs_exit_handler);
--- a/pbs/pbs_log.h	Mon May 13 15:48:39 2002 +0900
+++ b/pbs/pbs_log.h	Mon May 13 16:23:00 2002 +0900
@@ -37,7 +37,7 @@
 
 #include "pbs_db.h"
 
-#define LOG_IDENT "pbs"
+#define LOG_IDENT "perdition-pbs"
 
 extern vanessa_logger_t *pbs_vl;
 extern int errno;
--- a/pbs/pbs_option.c	Mon May 13 15:48:39 2002 +0900
+++ b/pbs/pbs_option.c	Mon May 13 16:23:00 2002 +0900
@@ -68,6 +68,8 @@
 		{"perfix",        'p', POPT_ARG_STRING, NULL, 'p'},
 		{"quiet",         'q', POPT_ARG_NONE,   NULL, 'q'},
 		{"regex",         'r', POPT_ARG_STRING, NULL, 'r'},
+		{"user",          'u', POPT_ARG_STRING, NULL, 'u'},
+		{"group",         'g', POPT_ARG_STRING, NULL, 'g'},
 		{NULL,             0,  0,               NULL,  0 }
 	};
 
@@ -88,6 +90,8 @@
 	opt->prefix = PBS_DEFAULT_PREFIX;
 	opt->log_level = PBS_DEFAULT_LOG_LEVEL;
 	opt->mode = PBS_DEFAULT_MODE;
+	opt->user = PBS_DEFAULT_USERNAME;
+	opt->group = PBS_DEFAULT_GROUP;
 
   	if(argc==0 || argv==NULL) return(opt);
 
@@ -106,6 +110,9 @@
 			case 'F':
 				opt->log_facility = optarg;
 				break;
+			case 'g':
+				opt->group = optarg;
+				break;
 			case 'h':
 				pbs_usage(0);
 				break;
@@ -130,6 +137,9 @@
 			case 'r':
 				opt->regex = optarg;
 				break;
+			case 'u':
+				opt->user = optarg;
+				break;
 		}
 	}
 	
@@ -197,6 +207,8 @@
 	"                         has a leading '/' then it will be treated\n"
 	"                         as a file to log to.\n"
 	"                         (default \"%s\")\n"
+        "    -g, --group: GROUP   Group to run as\n"
+	"                         (default \"%s\")\n"
 	"    -L, --log_file FILE: Log file to monitor\n"
 	"                         (default \"%s\")\n"
 	"    --no_daemon:         Do not detach from terminal when in\n"
@@ -210,15 +222,19 @@
 	"                         the first result, and optionally the\n"
 	"                         username as the second result\n"
 	"                         (default \"%s\")\n"
+        "    -u, --user: USERNAME User to run as\n"
+	"                         (default \"%s\")\n"
 	"\n"
 	"Notes: Default for binary flags is off\n"
 	"       Keys are not used in \"daemon\" or \"purge\" mode.\n",
 	STR_NULL_SAFE(pbs_mode_str(PBS_DEFAULT_MODE)),
 	STR_NULL_SAFE(PBS_DEFAULT_DB_FILENAME),
+	STR_NULL_SAFE(PBS_DEFAULT_GROUP),
 	STR_NULL_SAFE(PBS_DEFAULT_LOG_FACILITY),
 	STR_NULL_SAFE(PBS_DEFAULT_LOG_FILENAME),
 	STR_NULL_SAFE(PBS_DEFAULT_PREFIX),
-	STR_NULL_SAFE(PBS_DEFAULT_REGEX)
+	STR_NULL_SAFE(PBS_DEFAULT_REGEX),
+	STR_NULL_SAFE(PBS_DEFAULT_USERNAME)
 	);
 
   	exit(exit_status);
@@ -228,22 +244,26 @@
 	PBS_INFO_UNSAFE(
 		"db_file=\"%s\" "
 		"debug=\"%s\" "
+		"group=\"%s\" "
 		"log_facility=\"%s\" "
 		"log_file=\"%s\" "
 		"mode=\"%s\" "
 		"no_daemon=\"%s\" "
 		"prefix=\"%s\" "
 		"quiet=\"%s\" "
-		"regex=\"%s\"",
+		"regex=\"%s\" "
+		"user=\"%s\"",
 		STR_NULL_SAFE(opt->db_filename),
 		BIN_OPT_STR(opt->log_level == PBS_LOG_LEVEL_DEBUG),
+		STR_NULL_SAFE(opt->group),
 		STR_NULL_SAFE(opt->log_facility),
 		STR_NULL_SAFE(opt->log_filename),
 		STR_NULL_SAFE(pbs_mode_str(opt->mode)),
 		BIN_OPT_STR(opt->no_daemon),
 		STR_NULL_SAFE(opt->prefix),
 		BIN_OPT_STR(opt->log_level == PBS_LOG_LEVEL_QUIET),
-		STR_NULL_SAFE(opt->regex)
+		STR_NULL_SAFE(opt->regex),
+		STR_NULL_SAFE(opt->user)
 	);
 }
 
--- a/pbs/pbs_option.h	Mon May 13 15:48:39 2002 +0900
+++ b/pbs/pbs_option.h	Mon May 13 16:23:00 2002 +0900
@@ -66,6 +66,16 @@
 #define PBS_DEFAULT_LOG_LEVEL PBS_LOG_LEVEL_NORMAL
 #define PBS_DEFAULT_LOG_FACILITY "mail"
 
+#ifdef WITH_GROUP
+#define PBS_DEFAULT_GROUP                        WITH_GROUP
+#else
+#define PBS_DEFAULT_GROUP                        "nobody"
+#endif /* WITH_GROUP */
+#ifdef WITH_USER
+#define PBS_DEFAULT_USERNAME                     WITH_USER
+#else
+#define PBS_DEFAULT_USERNAME                     "nobody"
+#endif /* WITH_USER */
 
 typedef struct {
 	const char *log_filename;
@@ -78,6 +88,8 @@
 	int log_level;
 	int mode;
 	const char **leftover;
+	const char *user;
+	const char *group;
 } pbs_options_t;
 
 pbs_options_t *pbs_options_parse(int argc, char **argv);