summaryrefslogtreecommitdiff
path: root/source3/lib
diff options
context:
space:
mode:
authorLuke Leighton <lkcl@samba.org>1999-07-06 21:50:29 +0000
committerLuke Leighton <lkcl@samba.org>1999-07-06 21:50:29 +0000
commit7be65db6400304a9ff94ebaa19d312a3d8481834 (patch)
tree48565507e05e388469207f3bbf7dffd81367d8db /source3/lib
parent7672761567005733cd0c82ac44a5973b6ff8ccd1 (diff)
downloadsamba-7be65db6400304a9ff94ebaa19d312a3d8481834.tar.gz
samba-7be65db6400304a9ff94ebaa19d312a3d8481834.tar.bz2
samba-7be65db6400304a9ff94ebaa19d312a3d8481834.zip
added jeremy's sys_getpwnam() and sys_getpwuid() routines from 2_0 tree.
(This used to be commit df756f37230bcc47ef6a2067b6ddd8a0e2a125d1)
Diffstat (limited to 'source3/lib')
-rw-r--r--source3/lib/system.c57
1 files changed, 57 insertions, 0 deletions
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));
+}