s4:torture/smb2: add v2 lease requests
[Samba/wip.git] / lib / util / util_pw.c
blobab3808f006ef77c81e4b112483145cbae690692b
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 struct passwd *tcopy_passwd(TALLOC_CTX *mem_ctx,
32 const struct passwd *from)
34 struct passwd *ret = talloc_zero(mem_ctx, struct passwd);
36 if (ret == NULL)
37 return NULL;
39 ret->pw_name = talloc_strdup(ret, from->pw_name);
40 ret->pw_passwd = talloc_strdup(ret, from->pw_passwd);
41 ret->pw_uid = from->pw_uid;
42 ret->pw_gid = from->pw_gid;
43 ret->pw_gecos = talloc_strdup(ret, from->pw_gecos);
44 ret->pw_dir = talloc_strdup(ret, from->pw_dir);
45 ret->pw_shell = talloc_strdup(ret, from->pw_shell);
47 return ret;
50 struct passwd *getpwnam_alloc(TALLOC_CTX *mem_ctx, const char *name)
52 struct passwd *temp;
54 temp = getpwnam(name);
56 if (!temp) {
57 #if 0
58 if (errno == ENOMEM) {
59 /* what now? */
61 #endif
62 return NULL;
65 return tcopy_passwd(mem_ctx, temp);
68 /****************************************************************************
69 talloc'ed version of getpwuid.
70 ****************************************************************************/
72 struct passwd *getpwuid_alloc(TALLOC_CTX *mem_ctx, uid_t uid)
74 struct passwd *temp;
76 temp = getpwuid(uid);
78 if (!temp) {
79 #if 0
80 if (errno == ENOMEM) {
81 /* what now? */
83 #endif
84 return NULL;
87 return tcopy_passwd(mem_ctx, temp);