--- utils/net_groupmap.c.orig 2003-09-24 19:16:13.000000000 +0200 +++ utils/net_groupmap.c 2004-01-29 13:38:06.000000000 +0100 @@ -80,6 +80,65 @@ return True; } +/****************************************************** + Update primary group SID in passdb with + for users whose Unix primary group is . Useful + after a net_groupmap add/modify/delete. +******************************************************/ +static BOOL update_users_primgroup_sid(const gid_t gid, fstring string_sid) +{ + SAM_ACCOUNT *sam_pwent=NULL; + struct passwd *pass=NULL; + fstring usrname = ""; + + /* Initialize static context */ + if(!initialize_password_db(True)) { + DEBUG(0,("update_users_primgroup_sid: Cannot initialize password database.\n")); + return False; + } + /* Open password database for update */ + if(!pdb_setsampwent(True)) { + DEBUG(0,("update_users_primgroup_sid: Cannot open password database.\n")); + return False; + } + + while (NT_STATUS_IS_OK(pdb_init_sam(&sam_pwent)) && pdb_getsampwent(sam_pwent)) { + fstrcpy(usrname,pdb_get_username(sam_pwent)); + if(!(pass = Get_Pwnam(usrname))) { + DEBUG(0,("update_users_primgroup_sid: Cannot find Unix account for %s.\n", usrname)); + return False; + } + + if ((pass->pw_gid) != (gid_t)-1) { + /* Check if user's primary group SID must be updated (if mapped gid is the user's primary group gid) */ + if (pass->pw_gid == gid) { + if (string_sid) { /* String specified, use it */ + pdb_set_group_sid_from_string(sam_pwent, string_sid, PDB_CHANGED); + } + else { /* no string specified, must compute the RID */ + pdb_set_group_sid_from_rid(sam_pwent, pdb_gid_to_group_rid(pass->pw_gid), PDB_CHANGED); + } + + /* Commit changes */ + if (pdb_update_sam_account(sam_pwent)) { + /* Works well with pdb LDAP, BUT !!Error!! while using pdb TDB : pdb_tdb.c invalidates + the iterator in tdb_update_sam (called by pdb_update_sam_account). The result is + an iterator error in the next pdb_getsampwent of the loop. MUST BE CORRECTED*/ + d_printf("Successully updated primary group SID for user %s\n", usrname); + } + else { + d_printf("Could not update primary group SID for user %s\n", usrname); + } + } + } + pdb_free_sam(&sam_pwent); + } + pdb_free_sam(&sam_pwent); + pdb_endsampwent(); + + return True; +} + /********************************************************* Dump a GROUP_MAP entry to stdout (long or short listing) **********************************************************/ @@ -287,6 +346,9 @@ } d_printf("Successully added group %s to the mapping db\n", ntgroup); + + update_users_primgroup_sid(gid, string_sid); + return 0; } @@ -303,6 +365,9 @@ int i; gid_t gid; + gid_t old_gid; + fstring usrsid = ""; + /* get the options */ for ( i=0; i