From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kay Sievers Date: Wed, 22 Oct 2003 03:24:24 +0000 Subject: Re: [ANNOUNCE] udev 004 release MIME-Version: 1 Content-Type: multipart/mixed; boundary="5vNYLRcllDrimb99" Message-Id: List-Id: References: In-Reply-To: To: linux-hotplug@vger.kernel.org --5vNYLRcllDrimb99 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 --5vNYLRcllDrimb99 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline; filename="udev-add.c-permissions.diff" --- 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 #include #include +#include +#include #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; } --5vNYLRcllDrimb99-- ------------------------------------------------------- This SF.net email is sponsored by OSDN developer relations Here's your chance to show off your extensive product knowledge We want to know what you know. Tell us and you have a chance to win $100 http://www.zoomerang.com/survey.zgi?HRPT1X3RYQNC5V4MLNSV3E54 _______________________________________________ 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