Annotation of pkgsrc/net/samba30/patches/patch-bv, Revision 1.1.1.1
1.1 asau 1: $NetBSD: patch-bv,v 1.2 2007/02/11 18:39:04 tron Exp $
2:
3: --- lib/util_pw.c.orig 2006-04-20 03:29:23.000000000 +0100
4: +++ lib/util_pw.c 2007-02-11 17:57:22.000000000 +0000
5: @@ -4,6 +4,7 @@
6: Safe versions of getpw* calls
7:
8: Copyright (C) Andrew Bartlett 2002
9: + Copyright (C) Luke Mewburn 2004
10:
11: This program is free software; you can redistribute it and/or modify
12: it under the terms of the GNU General Public License as published by
13: @@ -25,6 +26,7 @@
14: struct passwd *tcopy_passwd(TALLOC_CTX *mem_ctx, const struct passwd *from)
15: {
16: struct passwd *ret = TALLOC_P(mem_ctx, struct passwd);
17: + char *gecos;
18: if (!ret) {
19: return NULL;
20: }
21: @@ -32,7 +34,10 @@
22: ret->pw_passwd = talloc_strdup(ret, from->pw_passwd);
23: ret->pw_uid = from->pw_uid;
24: ret->pw_gid = from->pw_gid;
25: - ret->pw_gecos = talloc_strdup(ret, from->pw_gecos);
26: + gecos = (from->pw_gecos != NULL) ? passwd_expand_gecos(from) : NULL;
27: + ret->pw_gecos = talloc_strdup(ret, gecos);
28: + if (gecos != NULL)
29: + SAFE_FREE(gecos);
30: ret->pw_dir = talloc_strdup(ret, from->pw_dir);
31: ret->pw_shell = talloc_strdup(ret, from->pw_shell);
32: return ret;
33: @@ -126,3 +131,38 @@
34:
35: return tcopy_passwd(mem_ctx, temp);
36: }
37: +
38: +
39: +/****************************************************************
40: + Expand any `&' characters in pw_gecos with a capitalized pw_name.
41: +****************************************************************/
42: +
43: +char *passwd_expand_gecos(const struct passwd *pw)
44: +{
45: + char *p, *bp, *buf;
46: + size_t ac, buflen;
47: +
48: + if (!lp_passwd_expand_gecos()) {
49: + return smb_xstrdup(pw->pw_gecos);
50: + }
51: +
52: + ac = 0;
53: + /* count number of `&' in pw_gecos */
54: + for (p = pw->pw_gecos; *p; p++) {
55: + if (*p == '&')
56: + ac++;
57: + }
58: + buflen = strlen(pw->pw_gecos) + (ac * (strlen(pw->pw_name) - 1)) + 1;
59: + buf = smb_xmalloc_array(sizeof(char), buflen);
60: + bp = buf;
61: + for (p = pw->pw_gecos; *p; p++) {
62: + if (*p == '&') { /* replace & with capitalized pw_name */
63: + ac = snprintf(bp, buflen - (bp - buf),
64: + "%s", pw->pw_name);
65: + *bp = toupper((unsigned char)*bp);
66: + bp += ac;
67: + } else
68: + *bp++ = *p;
69: + }
70: + return buf;
71: +}
CVSweb <webmaster@jp.NetBSD.org>