summaryrefslogtreecommitdiff
path: root/source3/smbd
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>1998-07-29 05:05:36 +0000
committerAndrew Tridgell <tridge@samba.org>1998-07-29 05:05:36 +0000
commitfb08c34cf3950f994701a9c98c89670f6346f7ab (patch)
treed24bacbacb7c84d89c52c2e7742a4fe4bea537b2 /source3/smbd
parent73dc9870af658dfe467e33ecefe2d740a0d0dbb0 (diff)
downloadsamba-fb08c34cf3950f994701a9c98c89670f6346f7ab.tar.gz
samba-fb08c34cf3950f994701a9c98c89670f6346f7ab.tar.bz2
samba-fb08c34cf3950f994701a9c98c89670f6346f7ab.zip
get rid of the runtime test for broken getgroups() and add a compile
time test instead. This also allows us to get rid of the igroups element of a couple of structures. (This used to be commit 8b25fe734166b76ceebf8d9543c706ebe0fddc96)
Diffstat (limited to 'source3/smbd')
-rw-r--r--source3/smbd/password.c108
-rw-r--r--source3/smbd/server.c12
-rw-r--r--source3/smbd/uid.c2
3 files changed, 37 insertions, 85 deletions
diff --git a/source3/smbd/password.c b/source3/smbd/password.c
index aae398dbda..0f8e33940f 100644
--- a/source3/smbd/password.c
+++ b/source3/smbd/password.c
@@ -137,14 +137,11 @@ void invalidate_vuid(uint16 vuid)
/* same number of igroups as groups */
vuser->n_groups = 0;
- if (vuser->groups && (vuser->groups != (gid_t *)vuser->igroups))
- free(vuser->groups);
+ if (vuser->groups) free(vuser->groups);
- if (vuser->igroups) free(vuser->igroups);
- if (vuser->sids ) free(vuser->sids);
+ if (vuser->sids) free(vuser->sids);
vuser->sids = NULL;
- vuser->igroups = NULL;
vuser->groups = NULL;
}
@@ -164,78 +161,41 @@ char *validated_username(uint16 vuid)
/****************************************************************************
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 setup_groups(char *user, int uid, int gid, int *p_ngroups, GID_T **p_groups)
{
- 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));
+ int i,ngroups;
+ GID_T *groups;
+ GID_T grp = 0;
+
+ 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));
+ }
+ }
+ return -1;
}
- }
- else
- {
- int i,ngroups;
- int *igroups;
- gid_t grp = 0;
- ngroups = getgroups(0,&grp);
- if (ngroups <= 0)
- ngroups = 32;
- igroups = (int *)malloc(sizeof(int)*ngroups);
- for (i=0;i<ngroups;i++)
- igroups[i] = 0x42424242;
- ngroups = getgroups(ngroups,(gid_t *)igroups);
-
- if (igroups[0] == 0x42424242)
- ngroups = 0;
-
- *p_ngroups = ngroups;
-
- /* The following bit of code is very strange. It is due to the
- fact that some OSes use int* and some use gid_t* for
- getgroups, and some (like SunOS) use both, one in prototypes,
- and one in man pages and the actual code. Thus we detect it
- dynamically using some very ugly code */
- if (ngroups > 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<ngroups;i++)
- if (igroups[i] == 0x42424242)
- groups_use_ints = False;
-
- if (groups_use_ints)
- {
- *p_igroups = igroups;
- *p_groups = (gid_t *)igroups;
- }
- else
- {
- gid_t *groups = (gid_t *)igroups;
- igroups = (int *)malloc(sizeof(int)*ngroups);
- for (i=0;i<ngroups;i++)
- {
- igroups[i] = groups[i];
- }
- *p_igroups = igroups;
- *p_groups = (gid_t *)groups;
- }
+ ngroups = getgroups(0,&grp);
+ if (ngroups <= 0) ngroups = 32;
+
+ groups = (GID_T *)malloc(sizeof(groups[0])*ngroups);
+
+ ngroups = getgroups(ngroups,(gid_t *)groups);
+
+ (*p_ngroups) = ngroups;
+
+ (*p_groups) = groups;
+
+ DEBUG(3,("%s is in %d groups\n",user,ngroups));
+ for (i=0;i<ngroups;i++) {
+ DEBUG(3,("%d ",(int)groups[i]));
}
- DEBUG(3,("%s is in %d groups\n",user,ngroups));
- for (i=0;i<ngroups;i++)
- DEBUG(3,("%d ",igroups[i]));
- DEBUG(3,("\n"));
- }
- return 0;
+ DEBUG(3,("\n"));
+
+ return 0;
}
@@ -299,13 +259,11 @@ uint16 register_vuid(int uid,int gid, char *unix_name, char *requested_name, BOO
vuser->n_groups = 0;
vuser->groups = NULL;
- vuser->igroups = NULL;
/* Find all the groups this uid is in and store them.
Used by become_user() */
setup_groups(unix_name,uid,gid,
&vuser->n_groups,
- &vuser->igroups,
&vuser->groups);
DEBUG(3,("uid %d registered to name %s\n",uid,unix_name));
diff --git a/source3/smbd/server.c b/source3/smbd/server.c
index 3469e45732..8eee0209b6 100644
--- a/source3/smbd/server.c
+++ b/source3/smbd/server.c
@@ -206,7 +206,7 @@ int dos_mode(int cnum,char *path,struct stat *sbuf)
((sbuf->st_mode & S_IWUSR) && current_user.uid==sbuf->st_uid) ||
((sbuf->st_mode & S_IWGRP) &&
in_group(sbuf->st_gid,current_user.gid,
- current_user.ngroups,current_user.igroups))))
+ current_user.ngroups,current_user.groups))))
result |= aRONLY;
} else {
if ((sbuf->st_mode & S_IWUSR) == 0)
@@ -356,7 +356,7 @@ int file_utime(int cnum, char *fname, struct utimbuf *times)
((sb.st_mode & S_IWUSR) && current_user.uid==sb.st_uid) ||
((sb.st_mode & S_IWGRP) &&
in_group(sb.st_gid,current_user.gid,
- current_user.ngroups,current_user.igroups)))) {
+ current_user.ngroups,current_user.groups)))) {
/* We are allowed to become root and change the filetime. */
become_root(False);
ret = sys_utime(fname, times);
@@ -3567,14 +3567,13 @@ int make_connection(char *service,char *user,char *password, int pwlen, char *de
/* groups stuff added by ih */
pcon->ngroups = 0;
- pcon->igroups = NULL;
pcon->groups = NULL;
if (!IS_IPC(cnum))
{
/* Find all the groups this uid is in and store them. Used by become_user() */
setup_groups(pcon->user,pcon->uid,pcon->gid,
- &pcon->ngroups,&pcon->igroups,&pcon->groups);
+ &pcon->ngroups,&pcon->groups);
/* check number of connections */
if (!claim_connection(cnum,
@@ -4267,11 +4266,8 @@ void close_cnum(int cnum, uint16 vuid)
num_connections_open--;
if (Connections[cnum].ngroups && Connections[cnum].groups)
{
- if (Connections[cnum].igroups != (int *)Connections[cnum].groups)
- free(Connections[cnum].groups);
- free(Connections[cnum].igroups);
+ free(Connections[cnum].groups);
Connections[cnum].groups = NULL;
- Connections[cnum].igroups = NULL;
Connections[cnum].ngroups = 0;
}
diff --git a/source3/smbd/uid.c b/source3/smbd/uid.c
index a8e0bf0d03..173fdaca03 100644
--- a/source3/smbd/uid.c
+++ b/source3/smbd/uid.c
@@ -242,7 +242,6 @@ BOOL become_user(connection_struct *conn, int cnum, uint16 vuid)
uid = conn->uid;
gid = conn->gid;
current_user.groups = conn->groups;
- current_user.igroups = conn->igroups;
current_user.ngroups = conn->ngroups;
}
else
@@ -258,7 +257,6 @@ BOOL become_user(connection_struct *conn, int cnum, uint16 vuid)
gid = conn->gid;
current_user.ngroups = vuser->n_groups;
current_user.groups = vuser->groups;
- current_user.igroups = vuser->igroups;
}
if (initial_uid == 0)