From mboxrd@z Thu Jan 1 00:00:00 1970 From: Roy Marples Date: Tue, 01 Aug 2006 10:35:25 +0000 Subject: [PATCH] Only lookup uid/gid when applying rules Message-Id: <200608011135.25769.uberlord@gentoo.org> MIME-Version: 1 Content-Type: multipart/mixed; boundary="Boundary-00=_t5yzErmAGH+AqY+" List-Id: To: linux-hotplug@vger.kernel.org --Boundary-00=_t5yzErmAGH+AqY+ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline Hi List Attached is a patch that stops udev from doing a uid/gid lookup unless it is actually going to use the rule. This is important as udev ships with rules for user/group names that may not exist in /etc/passwd. Normally this would not be a problem, but if a system is configured for LDAP, NIS or some other off line system at boot time then things get very nasty. See Gentoo bug #99564 for futher commentary on this http://bugs.gentoo.org/show_bug.cgi?id=99564 Thanks -- Roy Marples Gentoo/Linux Developer (baselayout, networking) --Boundary-00=_t5yzErmAGH+AqY+ Content-Type: text/x-diff; charset="us-ascii"; name="udev-nolookup.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="udev-nolookup.patch" diff -u udev-094.orig/udev.c udev-094/udev.c --- udev-094.orig/udev.c 2006-07-07 14:39:34.000000000 +0100 +++ udev-094/udev.c 2006-07-07 14:41:39.000000000 +0100 @@ -128,7 +128,7 @@ } sysfs_init(); - udev_rules_init(&rules, 0); + udev_rules_init(&rules); dev = sysfs_device_get(devpath); if (dev == NULL) { diff -u udev-094.orig/udevd.c udev-094/udevd.c --- udev-094.orig/udevd.c 2006-07-07 14:39:34.000000000 +0100 +++ udev-094/udevd.c 2006-07-07 14:41:56.000000000 +0100 @@ -908,7 +908,7 @@ /* parse the rules and keep it in memory */ sysfs_init(); - udev_rules_init(&rules, 1); + udev_rules_init(&rules); export_initial_seqnum(); @@ -1088,7 +1088,7 @@ if (reload_config) { reload_config = 0; udev_rules_cleanup(&rules); - udev_rules_init(&rules, 1); + udev_rules_init(&rules); } /* forked child has returned */ diff -u udev-094.orig/udev_rules.h udev-094/udev_rules.h --- udev-094.orig/udev_rules.h 2006-07-07 14:39:34.000000000 +0100 +++ udev-094/udev_rules.h 2006-07-07 14:41:27.000000000 +0100 @@ -98,10 +98,9 @@ char *buf; size_t bufsize; size_t current; - int resolve_names; }; -extern int udev_rules_init(struct udev_rules *rules, int resolve_names); +extern int udev_rules_init(struct udev_rules *rules); extern void udev_rules_cleanup(struct udev_rules *rules); extern void udev_rules_iter_init(struct udev_rules *rules); diff -u udev-094.orig/udev_rules_parse.c udev-094/udev_rules_parse.c --- udev-094.orig/udev_rules_parse.c 2006-07-07 14:39:34.000000000 +0100 +++ udev-094/udev_rules_parse.c 2006-07-07 14:41:00.000000000 +0100 @@ -473,38 +473,12 @@ if (strcasecmp(key, "OWNER") == 0) { valid = 1; - if (rules->resolve_names && (!strchr(value, '$') && !strchr(value, '%'))) { - char *endptr; - strtoul(value, &endptr, 10); - if (endptr[0] != '\0') { - char owner[32]; - uid_t uid = lookup_user(value); - dbg("replacing username='%s' by id=%i", value, uid); - sprintf(owner, "%u", (unsigned int) uid); - add_rule_key(rule, &rule->owner, operation, owner); - continue; - } - } - add_rule_key(rule, &rule->owner, operation, value); continue; } if (strcasecmp(key, "GROUP") == 0) { valid = 1; - if (rules->resolve_names && (!strchr(value, '$') && !strchr(value, '%'))) { - char *endptr; - strtoul(value, &endptr, 10); - if (endptr[0] != '\0') { - char group[32]; - gid_t gid = lookup_group(value); - dbg("replacing groupname='%s' by id=%i", value, gid); - sprintf(group, "%u", (unsigned int) gid); - add_rule_key(rule, &rule->group, operation, group); - continue; - } - } - add_rule_key(rule, &rule->group, operation, value); continue; } @@ -637,13 +611,12 @@ return retval; } -int udev_rules_init(struct udev_rules *rules, int resolve_names) +int udev_rules_init(struct udev_rules *rules) { struct stat stats; int retval; memset(rules, 0x00, sizeof(struct udev_rules)); - rules->resolve_names = resolve_names; /* parse rules file or all matching files in directory */ if (stat(udev_rules_filename, &stats) != 0) diff -u udev-094.orig/udevstart.c udev-094/udevstart.c --- udev-094.orig/udevstart.c 2006-07-07 14:39:34.000000000 +0100 +++ udev-094/udevstart.c 2006-07-07 14:42:25.000000000 +0100 @@ -361,7 +361,7 @@ alarm(UDEV_ALARM_TIMEOUT); sysfs_init(); - udev_rules_init(&rules, 1); + udev_rules_init(&rules); udev_scan_class(&device_list); udev_scan_block(&device_list); diff -u udev-094.orig/udevtest.c udev-094/udevtest.c --- udev-094.orig/udevtest.c 2006-07-07 14:39:34.000000000 +0100 +++ udev-094/udevtest.c 2006-07-07 14:42:11.000000000 +0100 @@ -83,7 +83,7 @@ devpath = argv[1]; sysfs_init(); - udev_rules_init(&rules, 0); + udev_rules_init(&rules); dev = sysfs_device_get(devpath); if (dev == NULL) { --Boundary-00=_t5yzErmAGH+AqY+ Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys -- and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV --Boundary-00=_t5yzErmAGH+AqY+ Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net Linux-hotplug-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel --Boundary-00=_t5yzErmAGH+AqY+--