linux-hotplug.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [udev] apply permissions.conf support for wildcard and default name
@ 2003-11-19  2:50 Kay Sievers
  0 siblings, 0 replies; 2+ messages in thread
From: Kay Sievers @ 2003-11-19  2:50 UTC (permalink / raw)
  To: linux-hotplug

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

Hi,
here is the next feature :)

Permissions given in udev.permissions are not applied if no METHOD from
udev.config is found. I've added do_kernelname() to scan for known
permissions if we only use the default method.

Simple support for wildcards is also added:

#name:user:group:mode
hdb*:2702:2702:0660

results in:

drwxr-xr-x    2 root     root          240 Nov 19 03:45 .
drwxr-xr-x   23 root     root          528 Nov 17 03:36 ..
brw-r--r--    1 root     root       3,   0 Nov 19 03:45 hda
brw-r--r--    1 root     root       3,   1 Nov 19 03:45 hda1
brw-r--r--    1 root     root       3,   2 Nov 19 03:45 hda2
brw-r--r--    1 root     root       3,   4 Nov 19 03:45 hda4
brw-r-----    1 kay      kay        3,  64 Nov 19 03:45 hdb
brw-r-----    1 kay      kay        3,  65 Nov 19 03:45 hdb1
brw-r--r--    1 root     root      22,   0 Nov 19 03:45 hdc
crw-r--r--    1 root     root      81,   0 Nov 19 03:34 webcam0


thanks,
Kay

[-- Attachment #2: 05-namedev.c-permissions-wildcard+kernel-name.diff --]
[-- Type: text/plain, Size: 3509 bytes --]

--- ../udev/namedev.c	2003-11-19 01:41:48.000000000 +0100
+++ namedev.c	2003-11-19 03:30:37.000000000 +0100
@@ -105,24 +105,30 @@
 	struct list_head *tmp;
 	struct config_device *tmp_dev;
 
-	/* loop through the whole list of devices to see if we already have
-	 * this one... */
+	/* update the values if we already have the device */
 	list_for_each(tmp, &config_device_list) {
 		struct config_device *dev = list_entry(tmp, struct config_device, node);
-		if (strcmp(dev->name, new_dev->name) == 0) {
-			/* the same, copy the new info into this structure */
-			copy_var(dev, new_dev, type);
-			copy_var(dev, new_dev, mode);
-			copy_string(dev, new_dev, bus);
-			copy_string(dev, new_dev, sysfs_file);
-			copy_string(dev, new_dev, sysfs_value);
-			copy_string(dev, new_dev, id);
-			copy_string(dev, new_dev, place);
-			copy_string(dev, new_dev, kernel_name);
-			copy_string(dev, new_dev, owner);
-			copy_string(dev, new_dev, group);
-			return 0;
+		int len = strlen(new_dev->name);
+		if (new_dev->name[len-1] == '*') {
+			len--;
+			if (strncmp(dev->name, new_dev->name, len))
+				continue;
+		} else {
+			if (strcmp(dev->name, new_dev->name))
+				continue;
 		}
+		/* the same, copy the new info into this structure */
+		copy_var(dev, new_dev, type);
+		copy_var(dev, new_dev, mode);
+		copy_string(dev, new_dev, bus);
+		copy_string(dev, new_dev, sysfs_file);
+		copy_string(dev, new_dev, sysfs_value);
+		copy_string(dev, new_dev, id);
+		copy_string(dev, new_dev, place);
+		copy_string(dev, new_dev, kernel_name);
+		copy_string(dev, new_dev, owner);
+		copy_string(dev, new_dev, group);
+		return 0;
 	}
 
 	/* not found, lets create a new structure, and add it to the list */
@@ -743,6 +749,32 @@
 	return -ENODEV;
 }
 
+static void do_kernelname(struct sysfs_class_device *class_dev, struct udevice *udev)
+{
+	struct config_device *dev;
+	struct list_head *tmp;
+
+	strfieldcpy(udev->name, class_dev->name);
+	list_for_each(tmp, &config_device_list) {
+		dev = list_entry(tmp, struct config_device, node);
+		int len = strlen(dev->name);
+		if (dev->name[len-1] == '*') {
+			len--;
+			if (strncmp(dev->name, class_dev->name, len))
+				continue;
+		} else {
+			if (strcmp(dev->name, class_dev->name))
+				continue;
+		}
+		if (dev->mode != 0) {
+			dbg_parse("found permissions from config for '%s'", class_dev->name);
+			udev->mode = dev->mode;
+			strfieldcpy(udev->owner, dev->owner);
+			strfieldcpy(udev->group, dev->group);
+		}
+	}
+}
+
 static int get_attr(struct sysfs_class_device *class_dev, struct udevice *udev)
 {
 	struct sysfs_device *sysfs_device = NULL;
@@ -793,27 +825,28 @@
 	/* rules are looked at in priority order */
 	retval = do_callout(class_dev, udev);
 	if (retval == 0)
-		goto done;
+		goto found;
 
 	retval = do_label(class_dev, udev, sysfs_device);
 	if (retval == 0)
-		goto done;
+		goto found;
 
 	retval = do_number(class_dev, udev, sysfs_device);
 	if (retval == 0)
-		goto done;
+		goto found;
 
 	retval = do_topology(class_dev, udev, sysfs_device);
 	if (retval == 0)
-		goto done;
+		goto found;
 
 	retval = do_replace(class_dev, udev);
 	if (retval == 0)
-		goto done;
+		goto found;
 
-	strfieldcpy(udev->name, class_dev->name);
+	do_kernelname(class_dev, udev);
+	goto done;
 
-done:
+found:
 	/* substitute placeholder in NAME  */
 	while (1) {
 		char *pos = strchr(udev->name, '%');
@@ -854,6 +887,7 @@
 			break;
 	}
 
+done:
 	/* mode was never set above */
 	if (!udev->mode) {
 		udev->mode = get_default_mode(class_dev);

^ permalink raw reply	[flat|nested] 2+ messages in thread
* Re: [udev] apply permissions.conf support for wildcard and default name
@ 2003-11-19  6:42 Greg KH
  0 siblings, 0 replies; 2+ messages in thread
From: Greg KH @ 2003-11-19  6:42 UTC (permalink / raw)
  To: linux-hotplug

On Wed, Nov 19, 2003 at 03:50:14AM +0100, Kay Sievers wrote:
> Hi,
> here is the next feature :)

Heh, I keep wanting to make a release, and you're giving me good
features too fast :)

> Permissions given in udev.permissions are not applied if no METHOD from
> udev.config is found. I've added do_kernelname() to scan for known
> permissions if we only use the default method.

Good catch.

> Simple support for wildcards is also added:

Ah, thanks a lot.  I've applied this.

But hm, I don't seem to be able to change the mode of the device node
anymore.  We seem to be calling mknod properly, but the node isn't being
written properly.  I'll look into this tomorrow...

thanks,

greg k-h


-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
Does SourceForge.net help you be more productive?  Does it
help you create better code?  SHARE THE LOVE, and help us help
YOU!  Click Here: http://sourceforge.net/donate/
_______________________________________________
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

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

end of thread, other threads:[~2003-11-19  6:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-11-19  2:50 [udev] apply permissions.conf support for wildcard and default name Kay Sievers
  -- strict thread matches above, loose matches on Subject: below --
2003-11-19  6:42 Greg KH

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).