/*
- * klibc_fixups.c - very simple implementation of stuff missing in klibc
+ * udev_libc_wrapper - wrapping of functions missing in a specific libc
+ * or not working in a statically compiled binary
*
* Copyright (C) 2003 Greg Kroah-Hartman <greg@kroah.com>
- * Copyright (C) 2004 Kay Sievers <kay@vrfy.org>
+ * Copyright (C) 2005 Kay Sievers <kay@vrfy.org>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
*
*/
-#ifdef __KLIBC__
-
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <sys/types.h>
-#include "pwd.h"
+#include "../udev_libc_wrapper.h"
#include "../udev.h"
#include "../udev_utils.h"
#include "../logging.h"
-#define PW_FILE "/etc/passwd"
-#define GR_FILE "/etc/group"
+
+#ifdef __KLIBC__
+#define __OWN_USERDB_PARSER__
+#endif
+#ifdef USE_STATIC
+#define __OWN_USERDB_PARSER__
+#endif
+
+#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)
+ dbg("specified user unknown '%s'", user);
+ 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)
+ dbg("specified group unknown '%s'", group);
+ 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 = -1;
+ unsigned long id = 0;
char line[LINE_SIZE];
char *buf;
char *bufline;
char *idstr;
char *tail;
- if (file_map(dbfile, &buf, &bufsize) == 0) {
- dbg("reading '%s' as db file", dbfile);
- } else {
+ if (file_map(dbfile, &buf, &bufsize) != 0) {
dbg("can't open '%s' as db file", dbfile);
- return -1;
+ return 0;
}
+ dbg("reading '%s' as db file", dbfile);
/* loop through the whole file */
cur = 0;
if (strcmp(uname, name) == 0) {
id = strtoul(idstr, &tail, 10);
- if (tail[0] != '\0')
- id = -1;
- else
+ if (tail[0] != '\0') {
+ id = 0;
+ dbg("no id found for '%s'", name);
+ } else
dbg("id for '%s' is '%li'", name, id);
break;
}
return id;
}
-struct passwd *getpwnam(const char *name)
+uid_t lookup_user(const char *user)
{
- static struct passwd pw;
+ unsigned long id;
- memset(&pw, 0x00, sizeof(struct passwd));
- pw.pw_uid = (uid_t) get_id_by_name(name, PW_FILE);
- if (pw.pw_uid < 0)
- return NULL;
- else
- return &pw;
+ id = get_id_by_name(user, PASSWD_FILE);
+ return (uid_t) id;
}
-struct group *getgrnam(const char *name)
+gid_t lookup_group(const char *group)
{
- static struct group gr;
+ unsigned long id;
- memset(&gr, 0x00, sizeof(struct group));
- gr.gr_gid = (gid_t) get_id_by_name(name, GR_FILE);
- if (gr.gr_gid < 0)
- return NULL;
- else
- return &gr;
+ id = get_id_by_name(group, GROUP_FILE);
+ return (gid_t) id;
}
-#endif /* __KLIBC__ */
+#endif /* __OWN_USERDB_PARSER__ */