All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kay Sievers <kay@vrfy.org>
To: linux-hotplug@vger.kernel.org
Subject: Re: [ANNOUNCE] udev 004 release
Date: Wed, 22 Oct 2003 03:24:24 +0000	[thread overview]
Message-ID: <marc-linux-hotplug-106681728327497@msgid-missing> (raw)
In-Reply-To: <marc-linux-hotplug-106675444401980@msgid-missing>

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

On Tue, Oct 21, 2003 at 01:50:46PM -0700, Greg KH wrote:
> On Tue, Oct 21, 2003 at 10:34:04PM +0200, Kay Sievers wrote:
> 
> > I was looking how to set permissions on the created node.
> > What is the future of struct device_attr?
> > Same values are in struct udevice now?
> 
> device_attr will go away.  I was leaving the namedev.c file alone when I
> did the udevice cleanups so that merging with Dan's changes would be
> easier.  Now I'm about to go clean that up.

Hi,

attached is a patch for udev-add.c to set file permissions.
The problem is that the resolving of owner/group name to its numeric id
needs shared libc libs. What does this mean for klibc?


gcc --static  -o udev udev.o udev-add.o udev-remove.o udevdb.o logging.o namedev.o tdb/tdb.o tdb/spinlock.o -lsysfs -lc -Llibsysfs 
udev-add.o(.text+0x3bf): In function `create_node':
udev-add.o(.text+0x2f6):/usr/src/udev/udev-add.c:122: warning: Using 'getpwnam' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
udev-add.o(.text+0x32d):/usr/src/udev/udev-add.c:128: warning: Using 'endpwent' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking


thanks,

Kay

[-- Attachment #2: udev-add.c-permissions.diff --]
[-- Type: text/plain, Size: 1916 bytes --]

--- udev-add.c.orig	2003-10-22 03:03:34.000000000 +0200
+++ udev-add.c	2003-10-22 05:02:02.000000000 +0200
@@ -27,6 +27,8 @@
 #include <fcntl.h>
 #include <unistd.h>
 #include <errno.h>
+#include <pwd.h>
+#include <grp.h>
 
 #include "udev.h"
 #include "udev_version.h"
@@ -98,7 +100,63 @@
 		dbg("mknod(%s, %#o, %u, %u) failed with error '%s'",
 		    filename, dev->mode, dev->major, dev->minor, strerror(errno));
 
-	// FIXME set the ownership of the node
+	/* set the ownership of the node if requested */
+	if ((*dev->owner == 0x00) && (*dev->group == 0x00))
+		return retval;
+
+	uid_t uid;
+	gid_t gid;
+
+	/* get current ownership */
+	struct stat file_stat;
+	lstat (filename, &file_stat);
+	uid = file_stat.st_uid;
+	gid = file_stat.st_gid;
+
+	if (*dev->owner != 0x00) {
+		char *endptr;
+		unsigned long id = strtoul(dev->owner, &endptr, 10);
+		/* if id is not numeric, ask system */
+		if (*endptr) {
+			dbg("got ascii owner: %s", dev->owner);
+			struct passwd *pwd = getpwnam (dev->owner);
+			if (pwd)
+				uid = pwd->pw_uid;
+			else
+				dbg("unable to resolve uid from string: %s",
+				    dev->owner);
+			endpwent();
+		} else {
+			uid = (uid_t) id;
+			dbg("got numeric owner: %u", uid);
+		}
+	}
+
+	if (*dev->group != 0x00) {
+		char *endptr;
+		unsigned long id = strtoul(dev->group, &endptr, 10);
+		/* if id is not numeric, ask system */
+		if (*endptr) {
+			dbg("got ascii group: %s", dev->group);
+			struct group *grp = getgrnam (dev->group);
+			if (grp)
+				gid = grp->gr_gid;
+			else
+				dbg("unable to resolve gid from string: %s",
+				    dev->group);
+			endgrent();
+		} else {
+			gid = (gid_t) id;
+			dbg("got numeric group: %u", gid);
+		}
+	}
+
+	dbg("chown(%s, %u, %u)", filename, uid, gid);
+	retval = chown(filename, uid, gid);
+	if (retval)
+		dbg("chown(%s, %u, %u) failed with error '%s'", filename,
+		    uid, gid, strerror(errno));
+
 	return retval;
 }
 

  parent reply	other threads:[~2003-10-22  3:24 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-10-21 16:28 [ANNOUNCE] udev 004 release Greg KH
2003-10-21 20:34 ` Kay Sievers
2003-10-21 20:50 ` Greg KH
2003-10-21 21:45 ` Jesse Barnes
2003-10-21 22:13 ` Greg KH
2003-10-22  1:46 ` Greg KH
2003-10-22  3:24 ` Kay Sievers [this message]
2003-10-22  7:09 ` Daniel Stekloff
2003-10-22  8:52 ` Ananth N Mavinakayanahalli
2003-10-22 23:52 ` Greg KH
2003-10-24 13:42 ` Kay Sievers
2003-10-25 10:40 ` Erik van Konijnenburg
2003-10-25 10:40 ` Erik van Konijnenburg
2003-11-14  1:36 ` Greg KH
2003-11-23 21:32 ` Greg KH
  -- strict thread matches above, loose matches on Subject: below --
2003-10-21 16:28 Greg KH
2003-10-21 21:45 ` Jesse Barnes
2003-10-21 22:13   ` Greg KH
2003-10-22  1:46     ` Greg KH

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=marc-linux-hotplug-106681728327497@msgid-missing \
    --to=kay@vrfy.org \
    --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 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.