From 7be65db6400304a9ff94ebaa19d312a3d8481834 Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Tue, 6 Jul 1999 21:50:29 +0000 Subject: added jeremy's sys_getpwnam() and sys_getpwuid() routines from 2_0 tree. (This used to be commit df756f37230bcc47ef6a2067b6ddd8a0e2a125d1) --- source3/lib/system.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) (limited to 'source3/lib/system.c') diff --git a/source3/lib/system.c b/source3/lib/system.c index edf8bb9da7..7bb64ab723 100644 --- a/source3/lib/system.c +++ b/source3/lib/system.c @@ -536,3 +536,60 @@ int sys_getgroups(int setlen, gid_t *gidset) return ngroups; #endif /* HAVE_BROKEN_GETGROUPS */ } + +/* + * We only wrap pw_name and pw_passwd for now as these + * are the only potentially modified fields. + */ + +/************************************************************************** + Helper function for getpwnam/getpwuid wrappers. +****************************************************************************/ + +static struct passwd *setup_pwret(struct passwd *pass) +{ + static pstring pw_name; + static pstring pw_passwd; + static struct passwd pw_ret; + + if (pass == NULL) + { + return NULL; + } + + memcpy((char *)&pw_ret, pass, sizeof(struct passwd)); + + if (pass->pw_name) + { + pw_name[0] = '\0'; + pw_ret.pw_name = pw_name; + pstrcpy(pw_ret.pw_name, pass->pw_name); + } + + if (pass->pw_passwd) + { + pw_passwd[0] = '\0'; + pw_ret.pw_passwd = pw_passwd; + pstrcpy(pw_ret.pw_passwd, pass->pw_passwd); + } + + return &pw_ret; +} + +/************************************************************************** + Wrapper for getpwnam(). Always returns a static that can be modified. +****************************************************************************/ + +struct passwd *sys_getpwnam(const char *name) +{ + return setup_pwret(getpwnam(name)); +} + +/************************************************************************** + Wrapper for getpwuid(). Always returns a static that can be modified. +****************************************************************************/ + +struct passwd *sys_getpwuid(uid_t uid) +{ + return setup_pwret(getpwuid(uid)); +} -- cgit