linux-hotplug.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Michal Schmidt <mschmidt@redhat.com>
To: linux-hotplug@vger.kernel.org
Subject: [PATCH] udev-acl: really fix ACL assignment in CK events
Date: Wed, 04 Aug 2010 09:53:25 +0000	[thread overview]
Message-ID: <20100804115325.6599879e@hammerfall> (raw)

The previous fix for udev-acl was incomplete. The ACL were not properly
assigned to the new user when switching from root's session because of
the test for 'uid != 0'.

Centralize the special handling of root to a single place (in set_facl).

(Also remove repeated #includes.)

https://bugzilla.redhat.com/show_bug.cgi?id`8712
---
 extras/udev-acl/udev-acl.c |   37 +++++++++++++++++++------------------
 1 files changed, 19 insertions(+), 18 deletions(-)

diff --git a/extras/udev-acl/udev-acl.c b/extras/udev-acl/udev-acl.c
index f2b5005..31e9991 100644
--- a/extras/udev-acl/udev-acl.c
+++ b/extras/udev-acl/udev-acl.c
@@ -12,20 +12,18 @@
  * General Public License for more details:
  */
 
-#include <stdio.h>
-#include <errno.h>
-#include <string.h>
-#include <inttypes.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
+#include <acl/libacl.h>
+#include <sys/stat.h>
 #include <errno.h>
 #include <getopt.h>
-#include <sys/stat.h>
 #include <glib.h>
-#include <acl/libacl.h>
+#include <inttypes.h>
 #include <libudev.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
 
 static int debug;
 
@@ -45,6 +43,10 @@ static int set_facl(const char* filename, uid_t uid, int add)
 	acl_permset_t permset;
 	int ret;
 
+	/* don't touch ACLs for root */
+	if (uid = 0)
+		return 0;
+
 	/* read current record */
 	acl = acl_get_file(filename, ACL_TYPE_ACCESS);
 	if (!acl)
@@ -190,8 +192,6 @@ static int consolekit_called(const char *ck_action, uid_t *uid, uid_t *uid2, con
 		if (s = NULL)
 			return -1;
 		u = strtoul(s, NULL, 10);
-		if (u = 0)
-			return 0;
 
 		s = getenv("CK_SEAT_SESSION_IS_LOCAL");
 		if (s = NULL)
@@ -205,8 +205,6 @@ static int consolekit_called(const char *ck_action, uid_t *uid, uid_t *uid2, con
 		if (s = NULL)
 			return -1;
 		u = strtoul(s, NULL, 10);
-		if (u = 0)
-			return 0;
 
 		s = getenv("CK_SEAT_OLD_SESSION_IS_LOCAL");
 		if (s = NULL)
@@ -331,6 +329,7 @@ int main (int argc, char* argv[])
 	};
 	int action = -1;
 	const char *device = NULL;
+	bool uid_given = false;
 	uid_t uid = 0;
 	uid_t uid2 = 0;
 	const char* remove_session_id = NULL;
@@ -357,6 +356,7 @@ int main (int argc, char* argv[])
 			device = optarg;
 			break;
 		case 'u':
+			uid_given = true;
 			uid = strtoul(optarg, NULL, 10);
 			break;
 		case 'd':
@@ -369,8 +369,9 @@ int main (int argc, char* argv[])
 		}
 	}
 
-	if (action < 0 && device = NULL && uid = 0)
-		consolekit_called(argv[optind], &uid, &uid2, &remove_session_id, &action);
+	if (action < 0 && device = NULL && !uid_given)
+		if (!consolekit_called(argv[optind], &uid, &uid2, &remove_session_id, &action))
+			uid_given = true;
 
 	if (action < 0) {
 		fprintf(stderr, "missing action\n\n");
@@ -378,13 +379,13 @@ int main (int argc, char* argv[])
 		goto out;
 	}
 
-	if (device != NULL && uid != 0) {
+	if (device != NULL && uid_given) {
 		fprintf(stderr, "only one option, --deviceÞVICEFILE or --user=UID expected\n\n");
 		rc = 3;
 		goto out;
 	}
 
-	if (uid != 0) {
+	if (uid_given) {
 		switch (action) {
 		case ACTION_ADD:
 			/* Add ACL for given uid to all matching devices. */
-- 
1.7.2


             reply	other threads:[~2010-08-04  9:53 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-04  9:53 Michal Schmidt [this message]
2010-08-04 10:03 ` [PATCH] udev-acl: really fix ACL assignment in CK events Kay Sievers

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=20100804115325.6599879e@hammerfall \
    --to=mschmidt@redhat.com \
    --cc=linux-hotplug@vger.kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).