$NetBSD: patch-ap,v 1.4 2004/07/23 16:45:43 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,6 +776,11 @@ static int num_lookups; /* Counter so we static void copy_pwent(struct saved_pw *dst, struct passwd *pass) { +#ifdef BSD + char *bp, *gecos, *p; + pstring buf, buf2; +#endif + memcpy((char *)&dst->pass, pass, sizeof(struct passwd)); unix_to_dos(dst->pw_name, pass->pw_name); @@ -783,9 +788,39 @@ static void copy_pwent(struct saved_pw * fstrcpy(dst->pw_passwd, pass->pw_passwd); dst->pass.pw_passwd = dst->pw_passwd; +#ifdef BSD + if (pass->pw_gecos) { + 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[PSTRING_LEN - 1]) { + /* buffer overflow */ + gecos = pass->pw_name; + goto gecos_done; + } + if (*p == '&') { + /* interpolate full name */ + snprintf(bp, PSTRING_LEN - (bp - buf), "%s", + pass->pw_name); + *bp = toupper(*bp); + bp += strlen(bp); + } + else + *bp++ = *p; + } + *bp = '\0'; + gecos = buf; - unix_to_dos(dst->pw_gecos, pass->pw_gecos); + gecos_done: + unix_to_dos(buf2, gecos); + fstrcpy(dst->pw_gecos, buf2); + } dst->pass.pw_gecos = dst->pw_gecos; +#endif unix_to_dos(dst->pw_dir, pass->pw_dir); dst->pass.pw_dir = dst->pw_dir;