r5647: Caches are good for performance, but you get a consistency problem.
authorVolker Lendecke <vlendec@samba.org>
Thu, 3 Mar 2005 16:52:44 +0000 (16:52 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 15:55:53 +0000 (10:55 -0500)
Fix bug # 2401.

Volker
(This used to be commit eb4ef94f244d28fe531d0b9f724a66ed3834b687)

source3/auth/auth_util.c
source3/groupdb/mapping.c
source3/lib/util_pw.c
source3/rpc_server/srv_samr_nt.c

index f3c01a58ca68efea5a1c2b9dc8d5e3917834f2f3..7cab3df99e4bd9452e0aac57e9f1b4160139cd36 100644 (file)
@@ -50,6 +50,7 @@ static int smb_create_user(const char *domain, const char *unix_username, const
        if (homedir)
                all_string_sub(add_script, "%H", homedir, sizeof(pstring));
        ret = smbrun(add_script,NULL);
+       flush_pwnam_cache();
        DEBUG(ret ? 0 : 3,("smb_create_user: Running the command `%s' gave %d\n",add_script,ret));
        return ret;
 }
index 1c29cc77c42a3241f978e7ffcfe472637b7f716b..5613240a12162bbe66990662549d54a57ba9a6fc 100644 (file)
@@ -1050,6 +1050,7 @@ int smb_set_primary_group(const char *unix_group, const char* unix_user)
                all_string_sub(add_script, "%g", unix_group, sizeof(add_script));
                all_string_sub(add_script, "%u", unix_user, sizeof(add_script));
                ret = smbrun(add_script,NULL);
+               flush_pwnam_cache();
                DEBUG(ret ? 0 : 3,("smb_set_primary_group: "
                         "Running the command `%s' gave %d\n",add_script,ret));
                return ret;
@@ -1060,6 +1061,7 @@ int smb_set_primary_group(const char *unix_group, const char* unix_user)
        if ( winbind_set_user_primary_group( unix_user, unix_group ) ) {
                DEBUG(3,("smb_delete_group: winbindd set the group (%s) as the primary group for user (%s)\n",
                        unix_group, unix_user));
+               flush_pwnam_cache();
                return 0;
        }               
        
index 0d7ffe09e9bc343a8b6358a9868d380e8c532a53..13349bad34e256684fc6d2b60e2e795859ca466a 100644 (file)
@@ -70,6 +70,20 @@ static void init_pwnam_cache(void)
        return;
 }
 
+void flush_pwnam_cache(void)
+{
+       int i;
+
+       init_pwnam_cache();
+
+       for (i=0; i<PWNAMCACHE_SIZE; i++) {
+               if (pwnam_cache[i] == NULL)
+                       continue;
+
+               passwd_free(&pwnam_cache[i]);
+       }
+}
+
 struct passwd *getpwnam_alloc(const char *name) 
 {
        int i;
index 8a10fa6d2da3812c9f575da8edcb432f3ad1b63b..139960f661316728438133698ff94fe94481a792 100644 (file)
@@ -2335,6 +2335,7 @@ NTSTATUS _samr_create_user(pipes_struct *p, SAMR_Q_CREATE_USER *q_u, SAMR_R_CREA
        
        /* implicit call to getpwnam() next.  we have a valid SID coming out of this call */
 
+       flush_pwnam_cache();
        nt_status = pdb_init_sam_new(&sam_pass, account, new_rid);
 
        /* this code is order such that we have no unnecessary retuns 
@@ -3805,6 +3806,7 @@ static int smb_delete_user(const char *unix_user)
                return -1;
        all_string_sub(del_script, "%u", unix_user, sizeof(del_script));
        ret = smbrun(del_script,NULL);
+       flush_pwnam_cache();
        DEBUG(ret ? 0 : 3,("smb_delete_user: Running the command `%s' gave %d\n",del_script,ret));
 
        return ret;