Fix macros for next and opaque quota ops. Spotted by metze
[Samba/vl.git] / source3 / lib / util_pw.c
blob9d075a05e885bfc080f7257c3298a2cbcdbd8d5c
1 /*
2 Unix SMB/CIFS implementation.
4 Safe versions of getpw* calls
6 Copyright (C) Andrew Bartlett 2002
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include "includes.h"
25 static struct passwd *alloc_copy_passwd(const struct passwd *from)
27 struct passwd *ret = smb_xmalloc(sizeof(struct passwd));
28 ZERO_STRUCTP(ret);
29 ret->pw_name = smb_xstrdup(from->pw_name);
30 ret->pw_passwd = smb_xstrdup(from->pw_passwd);
31 ret->pw_uid = from->pw_uid;
32 ret->pw_gid = from->pw_gid;
33 ret->pw_gecos = smb_xstrdup(from->pw_gecos);
34 ret->pw_dir = smb_xstrdup(from->pw_dir);
35 ret->pw_shell = smb_xstrdup(from->pw_shell);
36 return ret;
39 void passwd_free (struct passwd **buf)
41 if (!*buf) {
42 DEBUG(0, ("attempted double-free of allocated passwd\n"));
43 return;
46 SAFE_FREE((*buf)->pw_name);
47 SAFE_FREE((*buf)->pw_passwd);
48 SAFE_FREE((*buf)->pw_gecos);
49 SAFE_FREE((*buf)->pw_dir);
50 SAFE_FREE((*buf)->pw_shell);
52 SAFE_FREE(*buf);
55 struct passwd *getpwnam_alloc(const char *name)
57 struct passwd *temp;
59 temp = sys_getpwnam(name);
61 if (!temp) {
62 #if 0
63 if (errno == ENOMEM) {
64 /* what now? */
66 #endif
67 return NULL;
70 return alloc_copy_passwd(temp);
73 struct passwd *getpwuid_alloc(uid_t uid)
75 struct passwd *temp;
77 temp = sys_getpwuid(uid);
79 if (!temp) {
80 #if 0
81 if (errno == ENOMEM) {
82 /* what now? */
84 #endif
85 return NULL;
88 return alloc_copy_passwd(temp);