1
0
mirror of https://github.com/samba-team/samba.git synced 2025-03-27 22:50:26 +03:00

lib/util/util_pw: share sys_get{pw,gr} group of calls.

Guenther
This commit is contained in:
Günther Deschner 2011-03-02 16:06:32 +01:00
parent f4868ab646
commit 64421129b6
15 changed files with 104 additions and 53 deletions

View File

@ -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)

39
lib/util/util_pw.h Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#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__ */

View File

@ -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'
)

View File

@ -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 \

View File

@ -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

View File

@ -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);

View File

@ -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.
****************************************************************************/

View File

@ -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,

View File

@ -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)

View File

@ -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

View File

@ -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)
{

View File

@ -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;

View File

@ -18,6 +18,7 @@
*/
#include "includes.h"
#include "../lib/util/util_pw.h"
#undef DBGC_CLASS
#define DBGC_CLASS DBGC_QUOTA

View File

@ -21,6 +21,7 @@
#include "includes.h"
#include "vfstest.h"
#include "../lib/util/util_pw.h"
static const char *null_string = "";

View File

@ -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())