--- hal-0.4.7/hald/hald.c.orig	2005-11-15 16:05:31.000000000 -0800
+++ hal-0.4.7/hald/hald.c	2005-11-15 16:06:22.000000000 -0800
@@ -173,6 +173,8 @@ usage ()
  		 "        --drop-privileges  Run as normal user instead of root (calling of\n"
  		 "                           external scripts to modify fstab etc. will not work\n" 
 		 "                           run as root)\n"
+		 "        --user=user        Run as user instead of " HAL_USER "\n"
+		 "        --group=group      Run as group instead of " HAL_GROUP "\n"
 		 "        --help             Show this information and exit\n"
 		 "\n"
 		 "The HAL daemon detects devices present in the system and provides the\n"
@@ -249,6 +251,9 @@ dbus_bool_t hald_is_shutting_down;
 
 static int startup_daemonize_pipe[2];
 
+static char *hal_user = HAL_USER;
+static char *hal_group = HAL_GROUP;
+
 /** Drop all but necessary privileges from hald when it runs as root.  Set the
  *  running user id to HAL_USER and group to HAL_GROUP and grant the following 
  *  capabilities: CAP_NET_ADMIN
@@ -261,16 +266,16 @@ drop_privileges ()
     struct group *gr = NULL;
 
     /* determine user id */
-    pw = getpwnam (HAL_USER);
+    pw = getpwnam (hal_user);
     if (!pw)  {
-	HAL_ERROR (("drop_privileges: user " HAL_USER " does not exist"));
+	HAL_ERROR (("drop_privileges: user does not exist"));
 	exit (-1);
     }
 
     /* determine primary group id */
-    gr = getgrnam (HAL_GROUP);
+    gr = getgrnam (hal_group);
     if(!gr) {
-	HAL_ERROR (("drop_privileges: group " HAL_GROUP " does not exist"));
+	HAL_ERROR (("drop_privileges: group does not exist"));
 	exit (-1);
     }
 
@@ -280,7 +285,7 @@ drop_privileges ()
 	exit (-1);
     }
 
-    if( initgroups (HAL_USER, gr->gr_gid)) {
+    if( initgroups (hal_user, gr->gr_gid)) {
 	HAL_ERROR (("drop_privileges: could not initialize groups"));
 	exit (-1);
     }
@@ -322,6 +327,7 @@ main (int argc, char *argv[])
 {
 	GMainLoop *loop;
 	guint sigterm_iochn_listener_source_id;
+	gint hald_drop_privileges = 0;
 
 	openlog ("hald", LOG_PID, LOG_DAEMON);
 
@@ -342,6 +348,8 @@ main (int argc, char *argv[])
 			{"verbose", 1, NULL, 0},
 			{"help", 0, NULL, 0},
 			{"drop-privileges", 0, NULL, 0},
+			{"user", 1, NULL, 0},
+			{"group", 1, NULL, 0},
 			{NULL, 0, NULL, 0}
 		};
 
@@ -376,7 +384,11 @@ main (int argc, char *argv[])
 					return 1;
 				}
 			} else if (strcmp (opt, "drop-privileges") == 0)
-				drop_privileges ();
+				hald_drop_privileges = 1;
+			else if (strcmp (opt, "user") == 0)
+				hal_user = strdup(optarg);
+			else if (strcmp (opt, "group") == 0)
+				hal_group = strdup(optarg);
 			break;
 
 		default:
@@ -386,6 +398,9 @@ main (int argc, char *argv[])
 		}
 	}
 
+	if (hald_drop_privileges)
+		drop_privileges ();
+
 	if (hald_is_verbose)
 		logger_enable ();
 	else
