From 2e68682069ff72096f341b2fd3079aadf7c70a2f Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 12 Mar 1998 02:43:46 +0000 Subject: move setup_groups() into password.c so that swat can link without including server.o (This used to be commit 67bb8835c76e3efc43de55493971fe2402c0d709) --- source3/smbd/password.c | 86 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) (limited to 'source3/smbd/password.c') diff --git a/source3/smbd/password.c b/source3/smbd/password.c index b422dda36c..212d931e87 100644 --- a/source3/smbd/password.c +++ b/source3/smbd/password.c @@ -147,6 +147,92 @@ char *validated_username(uint16 vuid) return(vuser->name); } + +/**************************************************************************** +Setup the groups a user belongs to. +****************************************************************************/ +int setup_groups(char *user, int uid, int gid, int *p_ngroups, + int **p_igroups, gid_t **p_groups, + int **p_attrs) +{ + if (-1 == initgroups(user,gid)) + { + if (getuid() == 0) + { + DEBUG(0,("Unable to initgroups!\n")); + if (gid < 0 || gid > 16000 || uid < 0 || uid > 16000) + DEBUG(0,("This is probably a problem with the account %s\n",user)); + } + } + else + { + int i,ngroups; + int *igroups; + int *attrs; + gid_t grp = 0; + ngroups = getgroups(0,&grp); + if (ngroups <= 0) + ngroups = 32; + igroups = (int *)malloc(sizeof(int)*ngroups); + attrs = (int *)malloc(sizeof(int)*ngroups); + for (i=0;i 0) + { + /* does getgroups return ints or gid_t ?? */ + static BOOL groups_use_ints = True; + + if (groups_use_ints && + ngroups == 1 && + SVAL(igroups,2) == 0x4242) + groups_use_ints = False; + + for (i=0;groups_use_ints && i