blob: e7f689dbd8714afb5a29f054cf5ee2d8b5754756 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
$NetBSD: patch-ao,v 1.1 2003/03/29 08:18:50 taca Exp $
Expand & in the gecos field to a capitalized login name.
--- lib/util_getent.c.orig Sat Feb 2 19:46:42 2002
+++ lib/util_getent.c Sun Oct 13 21:37:56 2002
@@ -155,6 +155,11 @@
struct sys_pwent *plist;
struct sys_pwent *pent;
struct passwd *pwd;
+#ifdef BSD
+# define BUFLEN 1024
+ char *bp, *gecos, *p, buf[BUFLEN];
+ int buflen;
+#endif
pent = (struct sys_pwent *) malloc(sizeof(struct sys_pwent));
if (pent == NULL) {
@@ -178,9 +183,38 @@
pent->pw_uid = pwd->pw_uid;
pent->pw_gid = pwd->pw_gid;
if (pwd->pw_gecos) {
+#ifdef BSD
+ gecos = pwd->pw_gecos;
+ if (*gecos == '*')
+ gecos++;
+ bp = buf;
+
+ /* copy gecos, interpolating & to be full name */
+ for (p = gecos; *p != '\0'; p++) {
+ if (bp >= &buf[BUFLEN - 1])
+ /* buffer overflow */
+ goto gecos_done;
+ if (*p == '&') {
+ /* interpolate full name */
+ snprintf(bp, BUFLEN - (bp - buf),
+ "%s", pwd->pw_name);
+ *bp = toupper(*bp);
+ bp += strlen(bp);
+ }
+ else
+ *bp++ = *p;
+ }
+ *bp = '\0';
+ if ((pent->pw_name = strdup(buf)) == NULL)
+ goto err;
+#else
if ((pent->pw_name = strdup(pwd->pw_gecos)) == NULL)
goto err;
+#endif
}
+#ifdef BSD
+ gecos_done:
+#endif
if (pwd->pw_dir) {
if ((pent->pw_name = strdup(pwd->pw_dir)) == NULL)
goto err;
|