diff options
Diffstat (limited to 'source3/lib')
-rw-r--r-- | source3/lib/system.c | 50 | ||||
-rw-r--r-- | source3/lib/util.c | 14 |
2 files changed, 58 insertions, 6 deletions
diff --git a/source3/lib/system.c b/source3/lib/system.c index f474633dd1..cae688eb4c 100644 --- a/source3/lib/system.c +++ b/source3/lib/system.c @@ -464,7 +464,7 @@ char *dos_getwd(char *s) /******************************************************************* chown isn't used much but OS/2 doesn't have it ********************************************************************/ -int sys_chown(char *fname,int uid,int gid) +int sys_chown(char *fname,uid_t uid,gid_t gid) { #ifndef HAVE_CHOWN static int done; @@ -634,3 +634,51 @@ void sys_srandom(unsigned int seed) exit(1); #endif } + +/************************************************************************** + Wrapper for getgroups. Deals with broken (int) case. +****************************************************************************/ + +int sys_getgroups(int setlen, gid_t *gidset) +{ +#if !defined(HAVE_BROKEN_GETGROUPS) + return getgroups(setlen, gidset); +#else + + GID_T gid; + GID_T *group_list; + int i, ngroups; + + if(setlen == 0) { + return getgroups(setlen, &gid); + } + + /* + * Broken case. We need to allocate a + * GID_T array of size setlen. + */ + + if(setlen < 0) { + errno = EINVAL; + return -1; + } + + if((group_list = (GID_T *)malloc(setlen * sizoef(GID_T))) == NULL) { + DEBUG(0,("sys_getgroups: Malloc fail.\n")); + return -1; + } + + if((ngroups = getgroups(setlen, group_list)) < 0) { + int saved_errno = errno; + free((char *)group_list); + errno = saved_errno; + return -1; + } + + for(i = 0; i < ngroups; i++) + gidset[i] = (gid_t)group_list[i]; + + free((char *)group_list); + return ngroups; +#endif /* HAVE_BROKEN_GETGROUPS */ +} diff --git a/source3/lib/util.c b/source3/lib/util.c index 8561c4f3f4..37c7a5519e 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -346,7 +346,8 @@ void close_sockets(void ) /**************************************************************************** determine whether we are in the specified group ****************************************************************************/ -BOOL in_group(gid_t group, int current_gid, int ngroups, GID_T *groups) + +BOOL in_group(gid_t group, gid_t current_gid, int ngroups, gid_t *groups) { int i; @@ -4033,6 +4034,7 @@ struct hostent *Get_Hostbyname(char *name) /**************************************************************************** check if a process exists. Does this work on all unixes? ****************************************************************************/ + BOOL process_exists(int pid) { return(kill(pid,0) == 0 || errno != ESRCH); @@ -4042,24 +4044,26 @@ BOOL process_exists(int pid) /******************************************************************* turn a uid into a user name ********************************************************************/ -char *uidtoname(int uid) + +char *uidtoname(uid_t uid) { static char name[40]; struct passwd *pass = getpwuid(uid); if (pass) return(pass->pw_name); - slprintf(name, sizeof(name) - 1, "%d",uid); + slprintf(name, sizeof(name) - 1, "%d",(int)uid); return(name); } /******************************************************************* turn a gid into a group name ********************************************************************/ -char *gidtoname(int gid) + +char *gidtoname(gid_t gid) { static char name[40]; struct group *grp = getgrgid(gid); if (grp) return(grp->gr_name); - slprintf(name,sizeof(name) - 1, "%d",gid); + slprintf(name,sizeof(name) - 1, "%d",(int)gid); return(name); } |