summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKay Sievers <kay.sievers@suse.de>2006-08-20 18:25:57 +0200
committerKay Sievers <kay.sievers@suse.de>2006-08-20 18:25:57 +0200
commit3a020a85da768808a03f1574b001d1d06d55ae07 (patch)
treee17643bf1097ced6d6630a3e0fee1bfb917da6d0
parent5c51e31e0e794d8fcdc1225c65985571c9820949 (diff)
remove built-in /etc/passwd /etc/group parser
-rw-r--r--udev.h2
-rw-r--r--udev_sysdeps.c139
-rw-r--r--udev_sysdeps.h3
-rw-r--r--udev_utils.c40
4 files changed, 43 insertions, 141 deletions
diff --git a/udev.h b/udev.h
index d681ad5613..0377a8a65b 100644
--- a/udev.h
+++ b/udev.h
@@ -139,6 +139,8 @@ extern char *name_list_add(struct list_head *name_list, const char *name, int so
extern char *name_list_key_add(struct list_head *name_list, const char *key, const char *value);
extern void name_list_cleanup(struct list_head *name_list);
extern int add_matching_files(struct list_head *name_list, const char *dirname, const char *suffix);
+extern uid_t lookup_user(const char *user);
+extern gid_t lookup_group(const char *group);
/* udev_utils_string.c */
extern int strcmp_pattern(const char *p, const char *s);
diff --git a/udev_sysdeps.c b/udev_sysdeps.c
index 9ec5a73ed9..3cd12277cf 100644
--- a/udev_sysdeps.c
+++ b/udev_sysdeps.c
@@ -29,19 +29,7 @@
#include "udev.h"
-#ifndef __GLIBC__
-#define __OWN_USERDB_PARSER__
-#endif
-
#ifdef __GLIBC__
-#define __OWN_STRLCPYCAT__
-#endif
-
-#ifdef USE_STATIC
-#define __OWN_USERDB_PARSER__
-#endif
-
-#ifdef __OWN_STRLCPYCAT__
size_t strlcpy(char *dst, const char *src, size_t size)
{
size_t bytes = 0;
@@ -85,129 +73,4 @@ size_t strlcat(char *dst, const char *src, size_t size)
*q = '\0';
return bytes;
}
-#endif /* __OWN_STRLCPYCAT__ */
-
-#ifndef __OWN_USERDB_PARSER__
-#include <sys/types.h>
-#include <pwd.h>
-#include <grp.h>
-
-uid_t lookup_user(const char *user)
-{
- struct passwd *pw;
- uid_t uid = 0;
-
- pw = getpwnam(user);
- if (pw == NULL) {
- if (errno == 0 || errno == ENOENT || errno == ESRCH)
- err("specified user unknown '%s'", user);
- else
- err("error resolving user '%s': %s", user, strerror(errno));
- } else
- uid = pw->pw_uid;
-
- return uid;
-}
-
-gid_t lookup_group(const char *group)
-{
- struct group *gr;
- gid_t gid = 0;
-
- gr = getgrnam(group);
- if (gr == NULL) {
- if (errno == 0 || errno == ENOENT || errno == ESRCH)
- err("specified group unknown '%s'", group);
- else
- err("error resolving group '%s': %s", group, strerror(errno));
- } else
- gid = gr->gr_gid;
-
- return gid;
-}
-
-#else /* __OWN_USERDB_PARSER__ */
-
-#define PASSWD_FILE "/etc/passwd"
-#define GROUP_FILE "/etc/group"
-
-/* return the id of a passwd style line, selected by the users name */
-static unsigned long get_id_by_name(const char *uname, const char *dbfile)
-{
- unsigned long id = 0;
- char line[LINE_SIZE];
- char *buf;
- char *bufline;
- size_t bufsize;
- size_t cur;
- size_t count;
- char *pos;
- char *name;
- char *idstr;
- char *tail;
-
- if (file_map(dbfile, &buf, &bufsize) != 0) {
- err("can't open '%s' as db file: %s", dbfile, strerror(errno));
- return 0;
- }
- dbg("search '%s' in '%s'", uname, dbfile);
-
- /* loop through the whole file */
- cur = 0;
- while (cur < bufsize) {
- count = buf_get_line(buf, bufsize, cur);
- bufline = &buf[cur];
- cur += count+1;
-
- if (count >= sizeof(line))
- continue;
-
- memcpy(line, bufline, count-1);
- line[count-1] = '\0';
- pos = line;
-
- /* get name */
- name = strsep(&pos, ":");
- if (name == NULL)
- continue;
-
- /* skip pass */
- if (strsep(&pos, ":") == NULL)
- continue;
-
- /* get id */
- idstr = strsep(&pos, ":");
- if (idstr == NULL)
- continue;
-
- if (strcmp(uname, name) == 0) {
- id = strtoul(idstr, &tail, 10);
- if (tail[0] != '\0') {
- id = 0;
- dbg("no id found for '%s'", name);
- } else
- dbg("id for '%s' is '%li'", name, id);
- break;
- }
- }
-
- file_unmap(buf, bufsize);
- return id;
-}
-
-uid_t lookup_user(const char *user)
-{
- unsigned long id;
-
- id = get_id_by_name(user, PASSWD_FILE);
- return (uid_t) id;
-}
-
-gid_t lookup_group(const char *group)
-{
- unsigned long id;
-
- id = get_id_by_name(group, GROUP_FILE);
- return (gid_t) id;
-}
-#endif /* __OWN_USERDB_PARSER__ */
+#endif /* __GLIBC__ */
diff --git a/udev_sysdeps.h b/udev_sysdeps.h
index 530218f7b9..36c86f3356 100644
--- a/udev_sysdeps.h
+++ b/udev_sysdeps.h
@@ -162,9 +162,6 @@ static inline int inotify_add_watch(int fd, const char *name, uint32_t mask)
#endif
#endif
-extern uid_t lookup_user(const char *user);
-extern gid_t lookup_group(const char *group);
-
extern size_t strlcpy(char *dst, const char *src, size_t size);
extern size_t strlcat(char *dst, const char *src, size_t size);
diff --git a/udev_utils.c b/udev_utils.c
index 003d7bded9..b198892c01 100644
--- a/udev_utils.c
+++ b/udev_utils.c
@@ -28,6 +28,9 @@
#include <ctype.h>
#include <dirent.h>
#include <syslog.h>
+#include <pwd.h>
+#include <grp.h>
+#include <sys/types.h>
#include <sys/utsname.h>
#include "udev.h"
@@ -161,3 +164,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 unknown '%s'", 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 unknown '%s'", group);
+ else
+ err("error resolving group '%s': %s", group, strerror(errno));
+ } else
+ gid = gr->gr_gid;
+
+ return gid;
+}
+