$NetBSD: patch-bv,v 1.1 2005/11/14 08:05:28 jlam Exp $ --- lib/util_pw.c.orig 2005-10-12 13:03:30.000000000 -0400 +++ lib/util_pw.c @@ -4,6 +4,7 @@ Safe versions of getpw* calls Copyright (C) Andrew Bartlett 2002 + Copyright (C) Luke Mewburn 2004 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -144,3 +145,38 @@ struct passwd *getpwuid_alloc(uid_t uid) return alloc_copy_passwd(temp); } + + +/**************************************************************** + Expand any `&' characters in pw_gecos with a capitalized pw_name. +****************************************************************/ + +char *passwd_expand_gecos(const struct passwd *pw) +{ + char *p, *bp, *buf; + size_t ac, buflen; + + if (!lp_passwd_expand_gecos()) { + return smb_xstrdup(pw->pw_gecos); + } + + ac = 0; + /* count number of `&' in pw_gecos */ + for (p = pw->pw_gecos; *p; p++) { + if (*p == '&') + ac++; + } + buflen = strlen(pw->pw_gecos) + (ac * (strlen(pw->pw_name) - 1)) + 1; + buf = smb_xmalloc_array(sizeof(char), buflen); + bp = buf; + for (p = pw->pw_gecos; *p; p++) { + if (*p == '&') { /* replace & with capitalized pw_name */ + ac = snprintf(bp, buflen - (bp - buf), + "%s", pw->pw_name); + *bp = toupper((unsigned char)*bp); + bp += ac; + } else + *bp++ = *p; + } + return buf; +}