lib/util: Remove dummy wrapper for getpwuid().
[obnox/samba/samba-obnox.git] / lib / util / util_pw.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    Safe versions of getpw* calls
5
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
11
12    
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.
17    
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.
22    
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/>.
25 */
26
27 #include "includes.h"
28 #include "system/passwd.h"
29 #include "lib/util/util_pw.h"
30
31 /**************************************************************************
32  Wrappers for getgrnam(), getgrgid()
33 ****************************************************************************/
34
35 struct group *sys_getgrnam(const char *name)
36 {
37         return getgrnam(name);
38 }
39
40 struct group *sys_getgrgid(gid_t gid)
41 {
42         return getgrgid(gid);
43 }
44
45 struct passwd *tcopy_passwd(TALLOC_CTX *mem_ctx,
46                             const struct passwd *from)
47 {
48         struct passwd *ret = talloc_zero(mem_ctx, struct passwd);
49
50         if (ret == NULL)
51                 return NULL;
52
53         ret->pw_name = talloc_strdup(ret, from->pw_name);
54         ret->pw_passwd = talloc_strdup(ret, from->pw_passwd);
55         ret->pw_uid = from->pw_uid;
56         ret->pw_gid = from->pw_gid;
57         ret->pw_gecos = talloc_strdup(ret, from->pw_gecos);
58         ret->pw_dir = talloc_strdup(ret, from->pw_dir);
59         ret->pw_shell = talloc_strdup(ret, from->pw_shell);
60
61         return ret;
62 }
63
64 struct passwd *getpwnam_alloc(TALLOC_CTX *mem_ctx, const char *name)
65 {
66         struct passwd *temp;
67
68         temp = getpwnam(name);
69         
70         if (!temp) {
71 #if 0
72                 if (errno == ENOMEM) {
73                         /* what now? */
74                 }
75 #endif
76                 return NULL;
77         }
78
79         return tcopy_passwd(mem_ctx, temp);
80 }
81
82 /****************************************************************************
83  talloc'ed version of getpwuid.
84 ****************************************************************************/
85
86 struct passwd *getpwuid_alloc(TALLOC_CTX *mem_ctx, uid_t uid)
87 {
88         struct passwd *temp;
89
90         temp = getpwuid(uid);
91         
92         if (!temp) {
93 #if 0
94                 if (errno == ENOMEM) {
95                         /* what now? */
96                 }
97 #endif
98                 return NULL;
99         }
100
101         return tcopy_passwd(mem_ctx, temp);
102 }