lib/util: Remove dummy wrapper for getpwnam().
[metze/samba/wip.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 getpwuid(), getgrnam(), getgrgid()
33 ****************************************************************************/
34
35 struct passwd *sys_getpwuid(uid_t uid)
36 {
37         return getpwuid(uid);
38 }
39
40 struct group *sys_getgrnam(const char *name)
41 {
42         return getgrnam(name);
43 }
44
45 struct group *sys_getgrgid(gid_t gid)
46 {
47         return getgrgid(gid);
48 }
49
50 struct passwd *tcopy_passwd(TALLOC_CTX *mem_ctx,
51                             const struct passwd *from)
52 {
53         struct passwd *ret = talloc_zero(mem_ctx, struct passwd);
54
55         if (ret == NULL)
56                 return NULL;
57
58         ret->pw_name = talloc_strdup(ret, from->pw_name);
59         ret->pw_passwd = talloc_strdup(ret, from->pw_passwd);
60         ret->pw_uid = from->pw_uid;
61         ret->pw_gid = from->pw_gid;
62         ret->pw_gecos = talloc_strdup(ret, from->pw_gecos);
63         ret->pw_dir = talloc_strdup(ret, from->pw_dir);
64         ret->pw_shell = talloc_strdup(ret, from->pw_shell);
65
66         return ret;
67 }
68
69 struct passwd *getpwnam_alloc(TALLOC_CTX *mem_ctx, const char *name)
70 {
71         struct passwd *temp;
72
73         temp = getpwnam(name);
74         
75         if (!temp) {
76 #if 0
77                 if (errno == ENOMEM) {
78                         /* what now? */
79                 }
80 #endif
81                 return NULL;
82         }
83
84         return tcopy_passwd(mem_ctx, temp);
85 }
86
87 /****************************************************************************
88  talloc'ed version of getpwuid.
89 ****************************************************************************/
90
91 struct passwd *getpwuid_alloc(TALLOC_CTX *mem_ctx, uid_t uid)
92 {
93         struct passwd *temp;
94
95         temp = sys_getpwuid(uid);
96         
97         if (!temp) {
98 #if 0
99                 if (errno == ENOMEM) {
100                         /* what now? */
101                 }
102 #endif
103                 return NULL;
104         }
105
106         return tcopy_passwd(mem_ctx, temp);
107 }