All of lore.kernel.org
 help / color / mirror / Atom feed
From: "corentin.labbe" <corentin.labbe@geomatys.fr>
To: linux-audit@redhat.com
Subject: Proof of concept patch, add dropping privileges to a non root user
Date: Tue, 20 Oct 2009 16:07:30 +0200	[thread overview]
Message-ID: <4ADDC422.3000108@geomatys.fr> (raw)

[-- 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 --]



             reply	other threads:[~2009-10-20 14:03 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-20 14:07 corentin.labbe [this message]
2009-10-20 15:14 ` Proof of concept patch, add dropping privileges to a non root user Serge E. Hallyn
2009-10-20 16:34 ` Steve Grubb

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4ADDC422.3000108@geomatys.fr \
    --to=corentin.labbe@geomatys.fr \
    --cc=linux-audit@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.