summaryrefslogtreecommitdiff
path: root/net/ja-samba/patches/patch-ap
blob: ca6dd135403c89ddec82537ab7de033822f6b3d6 (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
$NetBSD: patch-ap,v 1.3 2004/06/05 13:16:35 taca Exp $

Expand & in the gecos field to a capitalized login name.

--- lib/system.c.orig	2003-07-17 20:23:53.000000000 +0900
+++ lib/system.c
@@ -776,12 +776,47 @@ static int num_lookups; /* Counter so we
 
 static void copy_pwent(struct saved_pw *dst, struct passwd *pass)
 {
+#ifdef BSD
+# define BUFLEN 1024
+	char *bp, *gecos, *p, buf[BUFLEN];
+	int buflen;
+#endif
+
 	memcpy((char *)&dst->pass, pass, sizeof(struct passwd));
 
 	unix_to_dos(dst->pw_name, pass->pw_name);
 	dst->pass.pw_name = dst->pw_name;
 
+#ifdef BSD
+	gecos = pass->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 */
+			gecos = pass->pw_name;
+			goto gecos_done;
+		}
+		if (*p == '&') {
+			/* interpolate full name */
+			snprintf(bp, BUFLEN - (bp - buf), "%s", pass->pw_name);
+			*bp = toupper(*bp);
+			bp += strlen(bp);
+		}
+		else
+			*bp++ = *p;
+	}
+	*bp = '\0';
+	gecos = buf;
+
+  gecos_done:
+	fstrcpy(dst->pw_gecos, gecos);
+#else
 	fstrcpy(dst->pw_passwd, pass->pw_passwd);
+#endif
 	dst->pass.pw_passwd = dst->pw_passwd;
 
 	unix_to_dos(dst->pw_gecos, pass->pw_gecos);