2 * klibc_fixups.c - very simple implementation of stuff missing in klibc
4 * Copyright (C) 2003 Greg Kroah-Hartman <greg@kroah.com>
5 * Copyright (C) 2004 Kay Sievers <kay@vrfy.org>
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation version 2 of the License.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 675 Mass Ave, Cambridge, MA 02139, USA.
29 #include <sys/types.h>
32 #include "klibc_fixups.h"
36 #define PW_FILE "/etc/passwd"
37 #define GR_FILE "/etc/group"
38 #define UTMP_FILE "/var/run/utmp"
40 _syscall1(int, sysinfo, struct sysinfo *, info);
42 /* return the id of a passwd style line, selected by the users name */
43 static unsigned long get_id_by_name(const char *uname, const char *dbfile)
45 unsigned long id = -1;
56 if (file_map(dbfile, &buf, &bufsize) == 0) {
57 dbg("reading '%s' as db file", dbfile);
59 dbg("can't open '%s' as db file", dbfile);
63 /* loop through the whole file */
67 count = buf_get_line(buf, bufsize, cur);
69 strncpy(line, buf + cur, count);
78 name = strsep(&pos, ":");
83 if (strsep(&pos, ":") == NULL)
87 idstr = strsep(&pos, ":");
91 if (strcmp(uname, name) == 0) {
92 id = strtoul(idstr, &tail, 10);
96 dbg("id for '%s' is '%li'", name, id);
101 file_unmap(buf, bufsize);
105 struct passwd *getpwnam(const char *name)
107 static struct passwd pw;
109 memset(&pw, 0x00, sizeof(struct passwd));
110 pw.pw_uid = (uid_t) get_id_by_name(name, PW_FILE);
117 struct group *getgrnam(const char *name)
119 static struct group gr;
121 memset(&gr, 0x00, sizeof(struct group));
122 gr.gr_gid = (gid_t) get_id_by_name(name, GR_FILE);
135 ufd = open(UTMP_FILE, O_RDONLY);
136 fcntl(ufd, F_SETFD, FD_CLOEXEC);
137 lseek(ufd, 0, SEEK_SET);
147 struct utmp *getutent(void)
149 static struct utmp utmp;
157 retval = read(ufd, &utmp, sizeof(struct utmp));