From 64421129b672d0ce55c5aa235e5038dd2ea1b32b Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 2 Mar 2011 16:06:32 +0100 Subject: lib/util/util_pw: share sys_get{pw,gr} group of calls. Guenther --- lib/util/util_pw.c | 50 +++++++++++++++++++++++++++++++ lib/util/util_pw.h | 39 ++++++++++++++++++++++++ lib/util/wscript_build | 5 ++++ source3/Makefile.in | 2 +- source3/auth/token_util.c | 1 + source3/include/proto.h | 7 ----- source3/lib/system.c | 44 --------------------------- source3/lib/username.c | 1 + source3/lib/util.c | 1 + source3/passdb/pdb_interface.c | 1 + source3/passdb/util_unixsids.c | 1 + source3/rpc_server/srvsvc/srv_srvsvc_nt.c | 1 + source3/smbd/ntquotas.c | 1 + source3/torture/cmd_vfs.c | 1 + source3/wscript_build | 2 +- 15 files changed, 104 insertions(+), 53 deletions(-) create mode 100644 lib/util/util_pw.h diff --git a/lib/util/util_pw.c b/lib/util/util_pw.c index bda7e24ede..cb7b45c135 100644 --- a/lib/util/util_pw.c +++ b/lib/util/util_pw.c @@ -3,7 +3,12 @@ Safe versions of getpw* calls + Copyright (C) Andrew Tridgell 1992-1998 + Copyright (C) Jeremy Allison 1998-2005 Copyright (C) Andrew Bartlett 2002 + Copyright (C) Timur Bakeyev 2005 + Copyright (C) Bjoern Jacke 2006-2007 + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -20,6 +25,51 @@ */ #include "includes.h" +#include "system/passwd.h" +#include "lib/util/util_pw.h" + +/************************************************************************** + Wrappers for setpwent(), getpwent() and endpwent() +****************************************************************************/ + +void sys_setpwent(void) +{ + setpwent(); +} + +struct passwd *sys_getpwent(void) +{ + return getpwent(); +} + +void sys_endpwent(void) +{ + endpwent(); +} + +/************************************************************************** + Wrappers for getpwnam(), getpwuid(), getgrnam(), getgrgid() +****************************************************************************/ + +struct passwd *sys_getpwnam(const char *name) +{ + return getpwnam(name); +} + +struct passwd *sys_getpwuid(uid_t uid) +{ + return getpwuid(uid); +} + +struct group *sys_getgrnam(const char *name) +{ + return getgrnam(name); +} + +struct group *sys_getgrgid(gid_t gid) +{ + return getgrgid(gid); +} static struct passwd *alloc_copy_passwd(TALLOC_CTX *mem_ctx, const struct passwd *from) diff --git a/lib/util/util_pw.h b/lib/util/util_pw.h new file mode 100644 index 0000000000..fa212b9c61 --- /dev/null +++ b/lib/util/util_pw.h @@ -0,0 +1,39 @@ +/* + Unix SMB/CIFS implementation. + + Safe versions of getpw* calls + + Copyright (C) Andrew Tridgell 1992-1998 + Copyright (C) Jeremy Allison 1997-2001. + Copyright (C) Andrew Bartlett 2002 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef __LIB_UTIL_UTIL_PW_H__ +#define __LIB_UTIL_UTIL_PW_H__ + +void sys_setpwent(void); +struct passwd *sys_getpwent(void); +void sys_endpwent(void); +struct passwd *sys_getpwnam(const char *name); +struct passwd *sys_getpwuid(uid_t uid); +struct group *sys_getgrnam(const char *name); +struct group *sys_getgrgid(gid_t gid); +struct passwd *tcopy_passwd(TALLOC_CTX *mem_ctx, + const struct passwd *from); +struct passwd *_getpwnam_alloc(TALLOC_CTX *mem_ctx, const char *name); +struct passwd *_getpwuid_alloc(TALLOC_CTX *mem_ctx, uid_t uid); + +#endif /* __LIB_UTIL_UTIL_PW_H__ */ diff --git a/lib/util/wscript_build b/lib/util/wscript_build index 7f5b1d2c67..6aaf04c96e 100755 --- a/lib/util/wscript_build +++ b/lib/util/wscript_build @@ -86,3 +86,8 @@ bld.SAMBA_SUBSYSTEM('UTIL_RUNCMD', public_deps='tevent' ) +bld.SAMBA_SUBSYSTEM('UTIL_PW', + source='util_pw.c', + local_include=False, + public_deps='talloc' + ) diff --git a/source3/Makefile.in b/source3/Makefile.in index b2f4594f2c..109d0801ac 100644 --- a/source3/Makefile.in +++ b/source3/Makefile.in @@ -424,7 +424,7 @@ UTIL_OBJ = ../lib/util/rbtree.o ../lib/util/signal.o ../lib/util/time.o \ ../lib/util/tevent_werror.o \ ../lib/util/smb_threads.o ../lib/util/util_id.o \ ../lib/util/blocking.o ../lib/util/rfc1738.o \ - ../lib/util/select.o + ../lib/util/select.o ../lib/util/util_pw.o CRYPTO_OBJ = ../lib/crypto/crc32.o ../lib/crypto/md5.o \ ../lib/crypto/hmacmd5.o ../lib/crypto/arcfour.o \ diff --git a/source3/auth/token_util.c b/source3/auth/token_util.c index 4942740ed0..f88511d8d6 100644 --- a/source3/auth/token_util.c +++ b/source3/auth/token_util.c @@ -29,6 +29,7 @@ #include "memcache.h" #include "../librpc/gen_ndr/netlogon.h" #include "../libcli/security/security.h" +#include "../lib/util/util_pw.h" /**************************************************************************** Check for a SID in an struct security_token diff --git a/source3/include/proto.h b/source3/include/proto.h index 14ec2d6853..94cc9f9baa 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -868,13 +868,6 @@ void sys_srandom(unsigned int seed); int groups_max(void); int sys_getgroups(int setlen, gid_t *gidset); int sys_setgroups(gid_t UNUSED(primary_gid), int setlen, gid_t *gidset); -void sys_setpwent(void); -struct passwd *sys_getpwent(void); -void sys_endpwent(void); -struct passwd *sys_getpwnam(const char *name); -struct passwd *sys_getpwuid(uid_t uid); -struct group *sys_getgrnam(const char *name); -struct group *sys_getgrgid(gid_t gid); int sys_popen(const char *command); int sys_pclose(int fd); ssize_t sys_getxattr (const char *path, const char *name, void *value, size_t size); diff --git a/source3/lib/system.c b/source3/lib/system.c index 092287a602..d1a1403340 100644 --- a/source3/lib/system.c +++ b/source3/lib/system.c @@ -1345,50 +1345,6 @@ int sys_setgroups(gid_t UNUSED(primary_gid), int setlen, gid_t *gidset) #endif } -/************************************************************************** - Wrappers for setpwent(), getpwent() and endpwent() -****************************************************************************/ - -void sys_setpwent(void) -{ - setpwent(); -} - -struct passwd *sys_getpwent(void) -{ - return getpwent(); -} - -void sys_endpwent(void) -{ - endpwent(); -} - -/************************************************************************** - Wrappers for getpwnam(), getpwuid(), getgrnam(), getgrgid() -****************************************************************************/ - - -struct passwd *sys_getpwnam(const char *name) -{ - return getpwnam(name); -} - -struct passwd *sys_getpwuid(uid_t uid) -{ - return getpwuid(uid); -} - -struct group *sys_getgrnam(const char *name) -{ - return getgrnam(name); -} - -struct group *sys_getgrgid(gid_t gid) -{ - return getgrgid(gid); -} - /************************************************************************** Extract a command into an arg list. ****************************************************************************/ diff --git a/source3/lib/username.c b/source3/lib/username.c index 4e77bee304..eea906128e 100644 --- a/source3/lib/username.c +++ b/source3/lib/username.c @@ -21,6 +21,7 @@ #include "includes.h" #include "memcache.h" +#include "../lib/util/util_pw.h" /* internal functions */ static struct passwd *uname_string_combinations(char *s, TALLOC_CTX *mem_ctx, diff --git a/source3/lib/util.c b/source3/lib/util.c index b99d9d42a8..2690a6f649 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -25,6 +25,7 @@ #include "popt_common.h" #include "secrets.h" #include "ctdbd_conn.h" +#include "../lib/util/util_pw.h" /* Max allowable allococation - 256mb - 0x10000000 */ #define MAX_ALLOC_SIZE (1024*1024*256) diff --git a/source3/passdb/pdb_interface.c b/source3/passdb/pdb_interface.c index 8cdaaaa569..046ca650cf 100644 --- a/source3/passdb/pdb_interface.c +++ b/source3/passdb/pdb_interface.c @@ -26,6 +26,7 @@ #include "memcache.h" #include "nsswitch/winbind_client.h" #include "../libcli/security/security.h" +#include "../lib/util/util_pw.h" #undef DBGC_CLASS #define DBGC_CLASS DBGC_PASSDB diff --git a/source3/passdb/util_unixsids.c b/source3/passdb/util_unixsids.c index 00cab22deb..cf85a5dbf1 100644 --- a/source3/passdb/util_unixsids.c +++ b/source3/passdb/util_unixsids.c @@ -19,6 +19,7 @@ #include "includes.h" #include "../libcli/security/security.h" +#include "../lib/util/util_pw.h" bool sid_check_is_unix_users(const struct dom_sid *sid) { diff --git a/source3/rpc_server/srvsvc/srv_srvsvc_nt.c b/source3/rpc_server/srvsvc/srv_srvsvc_nt.c index f0a105e33e..a0ed295ed3 100644 --- a/source3/rpc_server/srvsvc/srv_srvsvc_nt.c +++ b/source3/rpc_server/srvsvc/srv_srvsvc_nt.c @@ -30,6 +30,7 @@ #include "../librpc/gen_ndr/ndr_security.h" #include "dbwrap.h" #include "session.h" +#include "../lib/util/util_pw.h" extern const struct generic_mapping file_generic_mapping; diff --git a/source3/smbd/ntquotas.c b/source3/smbd/ntquotas.c index 95e9ec3b24..141f1f81b2 100644 --- a/source3/smbd/ntquotas.c +++ b/source3/smbd/ntquotas.c @@ -18,6 +18,7 @@ */ #include "includes.h" +#include "../lib/util/util_pw.h" #undef DBGC_CLASS #define DBGC_CLASS DBGC_QUOTA diff --git a/source3/torture/cmd_vfs.c b/source3/torture/cmd_vfs.c index ea5004ce63..3d7420cba9 100644 --- a/source3/torture/cmd_vfs.c +++ b/source3/torture/cmd_vfs.c @@ -21,6 +21,7 @@ #include "includes.h" #include "vfstest.h" +#include "../lib/util/util_pw.h" static const char *null_string = ""; diff --git a/source3/wscript_build b/source3/wscript_build index 3e71e94c43..76abe0b9bb 100755 --- a/source3/wscript_build +++ b/source3/wscript_build @@ -773,7 +773,7 @@ bld.SAMBA3_SUBSYSTEM('KRBCLIENT', bld.SAMBA3_LIBRARY('samba3core', source=LIB_SRC, - deps='LIBCRYPTO ndr ndr-util security NDR_SECURITY charset NDR_MESSAGING LIBASYNC_REQ tdb-wrap3 samba-util3 CHARSET3 UTIL_TDB SAMBA_VERSION krb5 flag_mapping util_reg', + deps='LIBCRYPTO ndr ndr-util security NDR_SECURITY charset NDR_MESSAGING LIBASYNC_REQ tdb-wrap3 samba-util3 CHARSET3 UTIL_TDB UTIL_PW SAMBA_VERSION krb5 flag_mapping util_reg', private_library=True, vars=locals()) -- cgit