s3-torture/denytest.c: replace cli_read_old() with cli_read()
[Samba/gebeck_regimport.git] / lib / util / util_pw.c
blobc6e4680ec3faa44f3db9f6c37f0196e7659a8d4b
1 /*
2 Unix SMB/CIFS implementation.
4 Safe versions of getpw* calls
6 Copyright (C) Andrew Tridgell 1992-1998
7 Copyright (C) Jeremy Allison 1998-2005
8 Copyright (C) Andrew Bartlett 2002
9 Copyright (C) Timur Bakeyev 2005
10 Copyright (C) Bjoern Jacke 2006-2007
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 3 of the License, or
16 (at your option) any later version.
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program. If not, see <http://www.gnu.org/licenses/>.
27 #include "includes.h"
28 #include "system/passwd.h"
29 #include "lib/util/util_pw.h"
31 /**************************************************************************
32 Wrappers for setpwent(), getpwent() and endpwent()
33 ****************************************************************************/
35 void sys_setpwent(void)
37 setpwent();
40 struct passwd *sys_getpwent(void)
42 return getpwent();
45 void sys_endpwent(void)
47 endpwent();
50 /**************************************************************************
51 Wrappers for getpwnam(), getpwuid(), getgrnam(), getgrgid()
52 ****************************************************************************/
54 struct passwd *sys_getpwnam(const char *name)
56 return getpwnam(name);
59 struct passwd *sys_getpwuid(uid_t uid)
61 return getpwuid(uid);
64 struct group *sys_getgrnam(const char *name)
66 return getgrnam(name);
69 struct group *sys_getgrgid(gid_t gid)
71 return getgrgid(gid);
74 struct passwd *tcopy_passwd(TALLOC_CTX *mem_ctx,
75 const struct passwd *from)
77 struct passwd *ret = talloc_zero(mem_ctx, struct passwd);
79 if (ret == NULL)
80 return NULL;
82 ret->pw_name = talloc_strdup(ret, from->pw_name);
83 ret->pw_passwd = talloc_strdup(ret, from->pw_passwd);
84 ret->pw_uid = from->pw_uid;
85 ret->pw_gid = from->pw_gid;
86 ret->pw_gecos = talloc_strdup(ret, from->pw_gecos);
87 ret->pw_dir = talloc_strdup(ret, from->pw_dir);
88 ret->pw_shell = talloc_strdup(ret, from->pw_shell);
90 return ret;
93 struct passwd *getpwnam_alloc(TALLOC_CTX *mem_ctx, const char *name)
95 struct passwd *temp;
97 temp = sys_getpwnam(name);
99 if (!temp) {
100 #if 0
101 if (errno == ENOMEM) {
102 /* what now? */
104 #endif
105 return NULL;
108 return tcopy_passwd(mem_ctx, temp);
111 /****************************************************************************
112 talloc'ed version of getpwuid.
113 ****************************************************************************/
115 struct passwd *getpwuid_alloc(TALLOC_CTX *mem_ctx, uid_t uid)
117 struct passwd *temp;
119 temp = sys_getpwuid(uid);
121 if (!temp) {
122 #if 0
123 if (errno == ENOMEM) {
124 /* what now? */
126 #endif
127 return NULL;
130 return tcopy_passwd(mem_ctx, temp);