summaryrefslogtreecommitdiff
path: root/source3/groupdb
diff options
context:
space:
mode:
authorVolker Lendecke <vlendec@samba.org>2002-09-23 16:21:01 +0000
committerVolker Lendecke <vlendec@samba.org>2002-09-23 16:21:01 +0000
commit06ce201a29bb90a428a59a3d85752ccf2dca1bdd (patch)
treed9d5b595b3e2dfa5ce5dd04685c39c5e22763474 /source3/groupdb
parent83ca90a67dd3db225706d32ffe58b114e1faf7d3 (diff)
downloadsamba-06ce201a29bb90a428a59a3d85752ccf2dca1bdd.tar.gz
samba-06ce201a29bb90a428a59a3d85752ccf2dca1bdd.tar.bz2
samba-06ce201a29bb90a428a59a3d85752ccf2dca1bdd.zip
Ok, getting a bit more ambitious. Stop me, if this is wrong. ;-)
When creating a group you have to take care of the fact that the underlying unix might not like the group name. This change gets around that problem by giving the add group script the chance to invent a group name. It then must only return the newly created numerical gid. Volker (This used to be commit b959419ed38e66a12b63cad3e5fbfa849f952acc)
Diffstat (limited to 'source3/groupdb')
-rw-r--r--source3/groupdb/mapping.c30
1 files changed, 28 insertions, 2 deletions
diff --git a/source3/groupdb/mapping.c b/source3/groupdb/mapping.c
index 2c9c7f47ea..5641431246 100644
--- a/source3/groupdb/mapping.c
+++ b/source3/groupdb/mapping.c
@@ -1156,16 +1156,42 @@ BOOL get_uid_list_of_group(gid_t gid, uid_t **uid, int *num_uids)
Create a UNIX group on demand.
****************************************************************************/
-int smb_create_group(char *unix_group)
+int smb_create_group(char *unix_group, gid_t *new_gid)
{
pstring add_script;
int ret;
+ int fd = 0;
pstrcpy(add_script, lp_addgroup_script());
if (! *add_script) return -1;
pstring_sub(add_script, "%g", unix_group);
- ret = smbrun(add_script,NULL);
+ ret = smbrun(add_script, (new_gid!=NULL) ? &fd : NULL);
DEBUG(3,("smb_create_group: Running the command `%s' gave %d\n",add_script,ret));
+ if (ret != 0)
+ return ret;
+
+ if (fd != 0) {
+ fstring output;
+
+ *new_gid = 0;
+ if (read(fd, output, sizeof(output)) > 0) {
+ *new_gid = (gid_t)strtoul(output, NULL, 10);
+ }
+ close(fd);
+
+ if (*new_gid == 0) {
+ /* The output was garbage. We assume nobody
+ will create group 0 via smbd. Now we try to
+ get the group via getgrnam. */
+
+ struct group *grp = getgrnam(unix_group);
+ if (grp != NULL)
+ *new_gid = grp->gr_gid;
+ else
+ return 1;
+ }
+ }
+
return ret;
}