X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;ds=sidebyside;f=udev_utils.c;h=e892012132eff8678c5a7fdd139a5a6356fc28ab;hb=019d6669076f52994cca199fbbae6eefbb96aeb8;hp=003d7bded93cec5f68838514619ea9fd43897ae2;hpb=7ba2d2e6ae70964b68056283fcea209cb4b617ec;p=elogind.git diff --git a/udev_utils.c b/udev_utils.c index 003d7bded..e89201213 100644 --- a/udev_utils.c +++ b/udev_utils.c @@ -1,6 +1,4 @@ /* - * udev_utils.c - generic stuff used by udev - * * Copyright (C) 2004-2005 Kay Sievers * * This program is free software; you can redistribute it and/or modify it @@ -14,7 +12,7 @@ * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., - * 675 Mass Ave, Cambridge, MA 02139, USA. + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * */ @@ -28,6 +26,9 @@ #include #include #include +#include +#include +#include #include #include "udev.h" @@ -125,7 +126,6 @@ int add_matching_files(struct list_head *name_list, const char *dirname, const c { struct dirent *ent; DIR *dir; - char *ext; char filename[PATH_SIZE]; dbg("open directory '%s'", dirname); @@ -144,14 +144,16 @@ int add_matching_files(struct list_head *name_list, const char *dirname, const c continue; /* look for file matching with specified suffix */ - ext = strrchr(ent->d_name, '.'); - if (ext == NULL) - continue; - - if (strcmp(ext, suffix) != 0) - continue; - - dbg("put file '%s/%s' in list", dirname, ent->d_name); + if (suffix != NULL) { + const char *ext; + + ext = strrchr(ent->d_name, '.'); + if (ext == NULL) + continue; + if (strcmp(ext, suffix) != 0) + continue; + } + dbg("put file '%s/%s' into list", dirname, ent->d_name); snprintf(filename, sizeof(filename), "%s/%s", dirname, ent->d_name); filename[sizeof(filename)-1] = '\0'; @@ -161,3 +163,40 @@ int add_matching_files(struct list_head *name_list, const char *dirname, const c closedir(dir); return 0; } + +uid_t lookup_user(const char *user) +{ + struct passwd *pw; + uid_t uid = 0; + + errno = 0; + pw = getpwnam(user); + if (pw == NULL) { + if (errno == 0 || errno == ENOENT || errno == ESRCH) + err("specified user '%s' unknown", user); + else + err("error resolving user '%s': %s", user, strerror(errno)); + } else + uid = pw->pw_uid; + + return uid; +} + +extern gid_t lookup_group(const char *group) +{ + struct group *gr; + gid_t gid = 0; + + errno = 0; + gr = getgrnam(group); + if (gr == NULL) { + if (errno == 0 || errno == ENOENT || errno == ESRCH) + err("specified group '%s' unknown", group); + else + err("error resolving group '%s': %s", group, strerror(errno)); + } else + gid = gr->gr_gid; + + return gid; +} +