1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19: #include <alloca.h>
20: #include <errno.h>
21: #include <stdio.h>
22: #include <unistd.h>
23: #include <pwd.h>
24:
25:
26:
27:
28:
29:
30: int __getpw (__uid_t uid, char *buf);
31:
32: int
33: __getpw (uid, buf)
34: __uid_t uid;
35: char *buf;
36: {
37: size_t buflen;
38: char *tmpbuf;
39: struct passwd resbuf, *p;
40:
41: if (buf == NULL)
42: {
43: __set_errno (EINVAL);
44: return -1;
45: }
46:
47: buflen = __sysconf (_SC_GETPW_R_SIZE_MAX);
48: tmpbuf = alloca (buflen);
49:
50: if (__getpwuid_r (uid, &resbuf, tmpbuf, buflen, &p) != 0)
51: return -1;
52:
53: if (p == NULL)
54: return -1;
55:
56: if (sprintf (buf, "%s:%s:%lu:%lu:%s:%s:%s", p->pw_name, p->pw_passwd,
57: (unsigned long int) p->pw_uid, (unsigned long int) p->pw_gid,
58: p->pw_gecos, p->pw_dir, p->pw_shell) < 0)
59: return -1;
60:
61: return 0;
62: }
63: weak_alias (__getpw, getpw)
64:
65: link_warning (getpw, "the `getpw' function is dangerous and should not be used.")