Index: lib/util_getent.c =================================================================== --- lib/util_getent.c 20 Jul 2004 16:28:03 -0000 1.1.1.2 +++ lib/util_getent.c 13 Dec 2004 12:11:27 -0000 1.4 @@ -156,8 +156,7 @@ struct sys_pwent * getpwent_list(void) pent->pw_uid = pwd->pw_uid; pent->pw_gid = pwd->pw_gid; if (pwd->pw_gecos) { - if ((pent->pw_gecos = strdup(pwd->pw_gecos)) == NULL) - goto err; + pent->pw_gecos = passwd_expand_gecos(pwd); } if (pwd->pw_dir) { if ((pent->pw_dir = strdup(pwd->pw_dir)) == NULL) Index: lib/util_pw.c =================================================================== --- lib/util_pw.c 20 Jul 2004 16:28:03 -0000 1.1.1.1 +++ lib/util_pw.c 13 Dec 2004 23:04:47 -0000 1.3 @@ -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 @@ -87,3 +88,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(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; +} Index: param/loadparm.c =================================================================== --- param/loadparm.c 7 Nov 2004 20:43:23 -0000 1.1.1.7 +++ param/loadparm.c 13 Dec 2004 12:11:27 -0000 1.4 @@ -265,6 +265,7 @@ typedef struct BOOL bUnixPasswdSync; BOOL bPasswdChatDebug; int iPasswdChatTimeout; + BOOL bPasswdExpandGecos; BOOL bTimestampLogs; BOOL bNTSmbSupport; BOOL bNTPipeSupport; @@ -814,6 +816,7 @@ static struct parm_struct parm_table[] = {"passwd chat", P_STRING, P_GLOBAL, &Globals.szPasswdChat, NULL, NULL, FLAG_ADVANCED}, {"passwd chat debug", P_BOOL, P_GLOBAL, &Globals.bPasswdChatDebug, NULL, NULL, FLAG_ADVANCED}, {"passwd chat timeout", P_INTEGER, P_GLOBAL, &Globals.iPasswdChatTimeout, NULL, NULL, FLAG_ADVANCED}, + {"passwd expand gecos", P_BOOL, P_GLOBAL, &Globals.bPasswdExpandGecos, NULL, NULL, FLAG_ADVANCED}, {"check password script", P_STRING, P_GLOBAL, &Globals.szCheckPasswordScript, NULL, NULL, FLAG_ADVANCED}, {"username map", P_STRING, P_GLOBAL, &Globals.szUsernameMap, NULL, NULL, FLAG_ADVANCED}, {"password level", P_INTEGER, P_GLOBAL, &Globals.pwordlevel, NULL, NULL, FLAG_ADVANCED}, @@ -1427,6 +1431,7 @@ static void init_globals(void) Globals.bPamPasswordChange = False; Globals.bPasswdChatDebug = False; Globals.iPasswdChatTimeout = 2; /* 2 second default. */ + Globals.bPasswdExpandGecos = False; Globals.bNTPipeSupport = True; /* Do NT pipes by default. */ Globals.bNTStatusSupport = True; /* Use NT status by default. */ Globals.bStatCache = True; /* use stat cache by default */ @@ -1750,6 +1755,7 @@ FN_GLOBAL_BOOL(lp_pam_password_change, & FN_GLOBAL_BOOL(lp_unix_password_sync, &Globals.bUnixPasswdSync) FN_GLOBAL_BOOL(lp_passwd_chat_debug, &Globals.bPasswdChatDebug) FN_GLOBAL_INTEGER(lp_passwd_chat_timeout, &Globals.iPasswdChatTimeout) +FN_GLOBAL_BOOL(lp_passwd_expand_gecos, &Globals.bPasswdExpandGecos) FN_GLOBAL_BOOL(lp_nt_pipe_support, &Globals.bNTPipeSupport) FN_GLOBAL_BOOL(lp_nt_status_support, &Globals.bNTStatusSupport) FN_GLOBAL_BOOL(lp_stat_cache, &Globals.bStatCache) Index: passdb/passdb.c =================================================================== --- passdb/passdb.c 19 Aug 2004 13:39:13 -0000 1.1.1.5 +++ passdb/passdb.c 13 Dec 2004 12:11:27 -0000 1.2 @@ -246,6 +246,7 @@ static NTSTATUS pdb_set_sam_sids(SAM_ACC NTSTATUS pdb_fill_sam_pw(SAM_ACCOUNT *sam_account, const struct passwd *pwd) { NTSTATUS ret; + char *gecos; if (!pwd) { return NT_STATUS_UNSUCCESSFUL; @@ -254,7 +255,9 @@ NTSTATUS pdb_fill_sam_pw(SAM_ACCOUNT *sa pdb_fill_default_sam(sam_account); pdb_set_username(sam_account, pwd->pw_name, PDB_SET); - pdb_set_fullname(sam_account, pwd->pw_gecos, PDB_SET); + gecos = passwd_expand_gecos(pwd); + pdb_set_fullname(sam_account, gecos, PDB_SET); + SAFE_FREE(gecos); pdb_set_unix_homedir(sam_account, pwd->pw_dir, PDB_SET);