public inbox for linux-audit@redhat.com
 help / color / mirror / Atom feed
* Proof of concept patch, add dropping privileges to a non root user
@ 2009-10-20 14:07 corentin.labbe
  2009-10-20 15:14 ` Serge E. Hallyn
  2009-10-20 16:34 ` Steve Grubb
  0 siblings, 2 replies; 3+ messages in thread
From: corentin.labbe @ 2009-10-20 14:07 UTC (permalink / raw)
  To: linux-audit

[-- Attachment #1: Type: text/plain, Size: 192 bytes --]

Hello

This is a patch that add a -u parameter to auditd.
This parameter permit to auditd to drop to an unprivilegied UID after initialization.

Any comment will be appreciated.

Cordially




[-- Attachment #2: auditd_drop_root_privilege.patch --]
[-- Type: text/x-patch, Size: 1349 bytes --]

--- src/auditd.c.orig	2009-10-05 14:18:52.000000000 +0200
+++ src/auditd.c	2009-10-05 14:55:36.000000000 +0200
@@ -471,9 +471,10 @@
 	struct ev_signal sigusr2_watcher;
 	struct ev_signal sigchld_watcher;
 	int rc;
+	int auditd_uid=0;
 
 	/* Get params && set mode */
-	while ((c = getopt(argc, argv, "flns:")) != -1) {
+	while ((c = getopt(argc, argv, "flns:u:")) != -1) {
 		switch (c) {
 		case 'f':
 			opt_foreground = 1;
@@ -481,6 +482,17 @@
 		case 'l':
 			opt_allow_links=1;
 			break;
+		case 'u':
+			auditd_uid = atoi(optarg);
+			if (auditd_uid > 65535) {
+				fprintf(stderr, "Invalid UID '%s' > 65535\n", optarg);
+				usage();
+			}
+			if (auditd_uid < 0) {
+				fprintf(stderr, "Invalid UID '%s' < 0\n", optarg);
+				usage();
+			}
+			break;
 		case 'n':
 			do_fork = 0;
 			break;
@@ -522,7 +534,7 @@
 
 #ifndef DEBUG
 	/* Make sure we are root */
-	if (getuid() != 0) {
+	if (getuid() != 0 && auditd_uid == 0) {
 		fprintf(stderr, "You must be root to run this program.\n");
 		return 4;
 	}
@@ -690,6 +702,14 @@
 		shutdown_dispatcher();
 		return 1;
 	}
+	
+	if (auditd_uid > 0)
+		if (setuid(auditd_uid) == -1) {
+			fprintf(stderr, "setuid error() %d.\n", errno);
+			shutdown_dispatcher();
+			return 1;
+		}
+	
 	audit_msg(LOG_NOTICE,
 	    "Init complete, auditd %s listening for events (startup state %s)",
 		VERSION,

[-- Attachment #3: Type: text/plain, Size: 0 bytes --]



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-10-21  0:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-10-20 14:07 Proof of concept patch, add dropping privileges to a non root user corentin.labbe
2009-10-20 15:14 ` Serge E. Hallyn
2009-10-20 16:34 ` Steve Grubb

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox