r18703: Fix the annoying effect that happens when nscd is running:
authorGünther Deschner <gd@samba.org>
Wed, 20 Sep 2006 00:15:50 +0000 (00:15 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 17:00:49 +0000 (12:00 -0500)
We usually do not get the results from user/group script modifications
immediately. A lot of users do add nscd restart/refresh commands into
their scripts to workaround that while we could flush the nscd caches
directly using libnscd.

Guenther
(This used to be commit 7db6ce295afbedfada7b207ad56566d2195a0d21)

12 files changed:
source3/Makefile.in
source3/groupdb/mapping.c
source3/include/includes.h
source3/lib/util.c
source3/nsswitch/winbindd.c
source3/nsswitch/winbindd_dual.c
source3/nsswitch/winbindd_util.c
source3/passdb/pdb_interface.c
source3/passdb/pdb_ldap.c
source3/passdb/pdb_smbpasswd.c
source3/passdb/pdb_tdb.c
source3/utils/net_rpc_samsync.c

index a8db82576cca9557033677af1d8a434859ca587b..49daac8f92c671665fd381566df428e7485043f8 100644 (file)
@@ -965,7 +965,7 @@ bin/smbd@EXEEXT@: $(SMBD_OBJ) @BUILD_POPT@ bin/.dummy
        @echo Linking $@
        @$(CC) $(FLAGS) @PIE_LDFLAGS@ -o $@ $(SMBD_OBJ) $(LDFLAGS) $(LDAP_LIBS) \
                $(KRB5LIBS) $(DYNEXP) $(PRINT_LIBS) $(AUTH_LIBS) \
-               $(ACL_LIBS) $(PASSDB_LIBS) $(LIBS) @POPTLIBS@ @SMBD_LIBS@
+               $(ACL_LIBS) $(PASSDB_LIBS) $(LIBS) @POPTLIBS@ @SMBD_LIBS@ $(NSCD_LIBS)
 
 bin/nmbd@EXEEXT@: $(NMBD_OBJ) @BUILD_POPT@ bin/.dummy
        @echo Linking $@
@@ -992,7 +992,7 @@ bin/smbctool@EXEEXT@: $(TOOL_OBJ) @BUILD_POPT@ bin/.dummy
 
 bin/net@EXEEXT@: $(NET_OBJ) @BUILD_POPT@ bin/.dummy
        @echo Linking $@
-       @$(CC) $(FLAGS) @PIE_LDFLAGS@ -o $@ $(NET_OBJ) $(DYNEXP) $(LDFLAGS) $(LIBS) @POPTLIBS@ $(KRB5LIBS) $(UUID_LIBS) $(LDAP_LIBS) $(PASSDB_LIBS) $(TERMLDFLAGS) $(TERMLIBS)
+       @$(CC) $(FLAGS) @PIE_LDFLAGS@ -o $@ $(NET_OBJ) $(DYNEXP) $(LDFLAGS) $(LIBS) @POPTLIBS@ $(KRB5LIBS) $(UUID_LIBS) $(LDAP_LIBS) $(PASSDB_LIBS) $(TERMLDFLAGS) $(TERMLIBS) $(NSCD_LIBS)
 
 bin/profiles@EXEEXT@: $(PROFILES_OBJ) @BUILD_POPT@ bin/.dummy
        @echo Linking $@
index 3d7b9f3f91a0aae850030108ea25e07702926e52..1d7934e9bf3d9c9144078a768492956ae8ca1a82 100644 (file)
@@ -878,9 +878,12 @@ int smb_create_group(const char *unix_group, gid_t *new_gid)
                pstring_sub(add_script, "%g", unix_group);
                ret = smbrun(add_script, &fd);
                DEBUG(ret ? 0 : 3,("smb_create_group: Running the command `%s' gave %d\n",add_script,ret));
+               if (ret == 0) {
+                       smb_nscd_flush_group_cache();
+               }
                if (ret != 0)
                        return ret;
-                       
+
                if (fd != 0) {
                        fstring output;
 
@@ -920,6 +923,9 @@ int smb_delete_group(const char *unix_group)
                pstring_sub(del_script, "%g", unix_group);
                ret = smbrun(del_script,NULL);
                DEBUG(ret ? 0 : 3,("smb_delete_group: Running the command `%s' gave %d\n",del_script,ret));
+               if (ret == 0) {
+                       smb_nscd_flush_group_cache();
+               }
                return ret;
        }
                
@@ -944,6 +950,9 @@ int smb_set_primary_group(const char *unix_group, const char* unix_user)
                flush_pwnam_cache();
                DEBUG(ret ? 0 : 3,("smb_set_primary_group: "
                         "Running the command `%s' gave %d\n",add_script,ret));
+               if (ret == 0) {
+                       smb_nscd_flush_group_cache();
+               }
                return ret;
        }
 
@@ -967,6 +976,9 @@ int smb_add_user_group(const char *unix_group, const char *unix_user)
                pstring_sub(add_script, "%u", unix_user);
                ret = smbrun(add_script,NULL);
                DEBUG(ret ? 0 : 3,("smb_add_user_group: Running the command `%s' gave %d\n",add_script,ret));
+               if (ret == 0) {
+                       smb_nscd_flush_group_cache();
+               }
                return ret;
        }
        
@@ -990,6 +1002,9 @@ int smb_delete_user_group(const char *unix_group, const char *unix_user)
                pstring_sub(del_script, "%u", unix_user);
                ret = smbrun(del_script,NULL);
                DEBUG(ret ? 0 : 3,("smb_delete_user_group: Running the command `%s' gave %d\n",del_script,ret));
+               if (ret == 0) {
+                       smb_nscd_flush_group_cache();
+               }
                return ret;
        }
        
index 6c152bff0c8b4e6f30bc714e4c5f9a549ebbae25..bcf0fa42770bf1113fd173582faf3a8ea54bbb8e 100644 (file)
@@ -1237,4 +1237,8 @@ void exit_server(const char *const reason) NORETURN_ATTRIBUTE ;
 void exit_server_cleanly(const char *const reason) NORETURN_ATTRIBUTE ;
 void exit_server_fault(void) NORETURN_ATTRIBUTE ;
 
+#ifdef HAVE_LIBNSCD
+#include "libnscd.h"
+#endif
+
 #endif /* _INCLUDES_H */
index e04ed977bb978095710d633bf1259b233bbf95eb..2391566e6c20eb6af4384e06ee2bd05882a544a4 100644 (file)
@@ -3017,3 +3017,24 @@ int this_is_smp(void)
        return 0;
 #endif
 }
+
+static void smb_nscd_flush_cache(const char *service)
+{
+#ifdef HAVE_NSCD_FLUSH_CACHE
+       if (!nscd_flush_cache(service)) {
+               DEBUG(10,("failed to flush nscd cache for '%s' service: %s. "
+                         "Is nscd running?\n",
+                         service, strerror(errno)));
+       }
+#endif
+}
+
+void smb_nscd_flush_user_cache(void)
+{
+       return smb_nscd_flush_cache("passwd");
+}
+
+void smb_nscd_flush_group_cache(void)
+{
+       return smb_nscd_flush_cache("group");
+}
index df8f821c8bf4bc58fc468c14de00a4f48eba82b1..8d5a7042c6087dd1059b4bdc441fc37beebad70a 100644 (file)
@@ -1063,7 +1063,8 @@ int main(int argc, char **argv)
 
        init_idmap_child();
 
-       winbindd_flush_nscd_cache();
+       smb_nscd_flush_user_cache();
+       smb_nscd_flush_group_cache();
 
        /* Loop waiting for requests */
 
index 128c468dd3d2f660259c0da4b5a52cec88000aa6..1a3de3f1e5892dc225dc133f5d11cac21b391729 100644 (file)
@@ -606,7 +606,8 @@ static void child_msg_online(int msg_type, struct process_id src, void *buf, siz
        /* Set our global state as online. */
        set_global_winbindd_state_online();
 
-       winbindd_flush_nscd_cache();
+       smb_nscd_flush_user_cache();
+       smb_nscd_flush_group_cache();
 
        /* Try and mark everything online - delete any negative cache entries
           to force a reconnect now. */
index a99115690d6fed8e1582753bfa4b62299d558f1e..4d99b0fbe67e1d720c934c7b79ab6201e853a4fe 100644 (file)
@@ -1218,27 +1218,6 @@ BOOL winbindd_upgrade_idmap(void)
        return idmap_convert(idmap_name);
 }
 
-void winbindd_flush_nscd_cache(void)
-{
-#ifdef HAVE_NSCD_FLUSH_CACHE
-
-       /* Flush nscd caches to get accurate new information */
-       int ret = nscd_flush_cache("passwd");
-       if (ret) {
-               DEBUG(5,("failed to flush nscd cache for 'passwd' service: %s\n",
-                       strerror(errno)));
-       }
-
-       ret = nscd_flush_cache("group");
-       if (ret) {
-               DEBUG(5,("failed to flush nscd cache for 'group' service: %s\n",
-                       strerror(errno)));
-       }
-#else
-       return;
-#endif
-}
-
 NTSTATUS lookup_usergroups_cached(struct winbindd_domain *domain,
                                  TALLOC_CTX *mem_ctx,
                                  const DOM_SID *user_sid,
index cc05d974681f7bfda238938235ad02e3000bcd5c..7252ea4c8c45460c17d7c54ddae1cd891006dd77 100644 (file)
@@ -366,6 +366,9 @@ static NTSTATUS pdb_default_create_user(struct pdb_methods *methods,
                add_ret = smbrun(add_script,NULL);
                DEBUG(add_ret ? 0 : 3, ("_samr_create_user: Running the command `%s' gave %d\n",
                                        add_script, add_ret));
+               if (add_ret == 0) {
+                       smb_nscd_flush_user_cache();
+               }
 
 #ifdef ENABLE_BUILD_FARM_HACKS
                if (add_ret != 0) {
@@ -443,6 +446,9 @@ static int smb_delete_user(const char *unix_user)
        all_string_sub(del_script, "%u", unix_user, sizeof(del_script));
        ret = smbrun(del_script,NULL);
        flush_pwnam_cache();
+       if (ret == 0) {
+               smb_nscd_flush_user_cache();
+       }
        DEBUG(ret ? 0 : 3,("smb_delete_user: Running the command `%s' gave %d\n",del_script,ret));
 
        return ret;
index e0f79c140dd6193f9b1f88121fcbb9ae3fd09c93..0f03a1cc6eb1a051f784e6fb45e93dc6f8ed0165 100644 (file)
@@ -1870,6 +1870,10 @@ static NTSTATUS ldapsam_rename_sam_account(struct pdb_methods *my_methods,
        DEBUG(rc ? 0 : 3,("Running the command `%s' gave %d\n", 
                          rename_script, rc));
 
+       if (rc == 0) {
+               smb_nscd_flush_user_cache();
+       }
+
        if (rc)
                return NT_STATUS_UNSUCCESSFUL;
 
index 905cf8f2a2d4582b4938145f1f29f5eb59afea63..afc00445f40846cdca620382e4669a80595bd7a4 100644 (file)
@@ -1550,6 +1550,10 @@ static NTSTATUS smbpasswd_rename_sam_account (struct pdb_methods *my_methods,
 
                DEBUG(rename_ret ? 0 : 3,("Running the command `%s' gave %d\n", rename_script, rename_ret));
 
+               if (rename_ret == 0) {
+                       smb_nscd_flush_user_cache();
+               }
+
                if (rename_ret) 
                        goto done; 
         } else {
index b16368baf17ca76cf2786d97e1d17d5ad5544ed1..e9beaa053682a1ef95847c9da0edf9ac7fee7109 100644 (file)
@@ -1461,6 +1461,10 @@ static NTSTATUS tdbsam_rename_sam_account(struct pdb_methods *my_methods,
 
        DEBUG(rename_ret ? 0 : 3,("Running the command `%s' gave %d\n", rename_script, rename_ret));
 
+       if (rename_ret == 0) {
+               smb_nscd_flush_user_cache();
+       }
+
        if (rename_ret) {
                goto done; 
        }
index 0b54a6c97fc502b7d6e19fed48b2612ba04f16c4..1337c11eca1500b2250b7d8bf9f161bb33799bec 100644 (file)
@@ -508,6 +508,9 @@ static NTSTATUS fetch_account_info(uint32 rid, SAM_ACCOUNT_INFO *delta)
                        add_ret = smbrun(add_script,NULL);
                        DEBUG(add_ret ? 0 : 1,("fetch_account: Running the command `%s' "
                                 "gave %d\n", add_script, add_ret));
+                       if (add_ret == 0) {
+                               smb_nscd_flush_user_cache();
+                       }
                }
                
                /* try and find the possible unix account again */