]>
git.ipfire.org Git - thirdparty/systemd.git/blob - klibc_fixups.c
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.
28 #include <sys/types.h>
30 #include "klibc_fixups.h"
33 #define PW_FILE "/etc/passwd"
34 #define GR_FILE "/etc/group"
36 /* return the id of a passwd style line, selected by the users name */
37 static unsigned long get_id_by_name(const char *uname
, const char *dbfile
)
39 unsigned long id
= -1;
47 file
= fopen(dbfile
, "r");
49 dbg("unable to open file '%s'", dbfile
);
54 pos
= fgets(buf
, sizeof(buf
), file
);
59 name
= strsep(&pos
, ":");
64 if (strsep(&pos
, ":") == NULL
)
68 idstr
= strsep(&pos
, ":");
72 if (strcmp(uname
, name
) == 0) {
73 id
= strtoul(idstr
, &tail
, 10);
77 dbg("id for '%s' is '%li'", name
, id
);
86 struct passwd
*getpwnam(const char *name
)
88 static struct passwd pw
;
90 memset(&pw
, 0x00, sizeof(struct passwd
));
91 pw
.pw_uid
= (uid_t
) get_id_by_name(name
, PW_FILE
);
98 struct group
*getgrnam(const char *name
)
100 static struct group gr
;
102 memset(&gr
, 0x00, sizeof(struct group
));
103 gr
.gr_gid
= (gid_t
) get_id_by_name(name
, GR_FILE
);