diff options
author | Volker Lendecke <vlendec@samba.org> | 2002-09-23 16:21:01 +0000 |
---|---|---|
committer | Volker Lendecke <vlendec@samba.org> | 2002-09-23 16:21:01 +0000 |
commit | b959419ed38e66a12b63cad3e5fbfa849f952acc (patch) | |
tree | 857ad4aff1cd0351c984d570f2415fe19d04196b /source/groupdb | |
parent | 42774a7753eb8be1ec04bcb5dda089910a1b6d0b (diff) | |
download | samba-b959419ed38e66a12b63cad3e5fbfa849f952acc.tar.gz samba-b959419ed38e66a12b63cad3e5fbfa849f952acc.tar.xz samba-b959419ed38e66a12b63cad3e5fbfa849f952acc.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
Diffstat (limited to 'source/groupdb')
-rw-r--r-- | source/groupdb/mapping.c | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/source/groupdb/mapping.c b/source/groupdb/mapping.c index 2c9c7f47eaf..56414312465 100644 --- a/source/groupdb/mapping.c +++ b/source/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; } |