From 7db6ce295afbedfada7b207ad56566d2195a0d21 Mon Sep 17 00:00:00 2001 From: =?utf8?q?G=C3=BCnther=20Deschner?= Date: Wed, 20 Sep 2006 00:15:50 +0000 Subject: [PATCH] r18703: Fix the annoying effect that happens when nscd is running: 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 --- source/Makefile.in | 4 ++-- source/groupdb/mapping.c | 17 ++++++++++++++++- source/include/includes.h | 4 ++++ source/lib/util.c | 21 +++++++++++++++++++++ source/nsswitch/winbindd.c | 3 ++- source/nsswitch/winbindd_dual.c | 3 ++- source/nsswitch/winbindd_util.c | 21 --------------------- source/passdb/pdb_interface.c | 6 ++++++ source/passdb/pdb_ldap.c | 4 ++++ source/passdb/pdb_smbpasswd.c | 4 ++++ source/passdb/pdb_tdb.c | 4 ++++ source/utils/net_rpc_samsync.c | 3 +++ 12 files changed, 68 insertions(+), 26 deletions(-) diff --git a/source/Makefile.in b/source/Makefile.in index a8db82576cc..49daac8f92c 100644 --- a/source/Makefile.in +++ b/source/Makefile.in @@ -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 $@ diff --git a/source/groupdb/mapping.c b/source/groupdb/mapping.c index 3d7b9f3f91a..1d7934e9bf3 100644 --- a/source/groupdb/mapping.c +++ b/source/groupdb/mapping.c @@ -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; } diff --git a/source/include/includes.h b/source/include/includes.h index 6c152bff0c8..bcf0fa42770 100644 --- a/source/include/includes.h +++ b/source/include/includes.h @@ -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 */ diff --git a/source/lib/util.c b/source/lib/util.c index e04ed977bb9..2391566e6c2 100644 --- a/source/lib/util.c +++ b/source/lib/util.c @@ -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"); +} diff --git a/source/nsswitch/winbindd.c b/source/nsswitch/winbindd.c index df8f821c8bf..8d5a7042c60 100644 --- a/source/nsswitch/winbindd.c +++ b/source/nsswitch/winbindd.c @@ -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 */ diff --git a/source/nsswitch/winbindd_dual.c b/source/nsswitch/winbindd_dual.c index 128c468dd3d..1a3de3f1e58 100644 --- a/source/nsswitch/winbindd_dual.c +++ b/source/nsswitch/winbindd_dual.c @@ -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. */ diff --git a/source/nsswitch/winbindd_util.c b/source/nsswitch/winbindd_util.c index a99115690d6..4d99b0fbe67 100644 --- a/source/nsswitch/winbindd_util.c +++ b/source/nsswitch/winbindd_util.c @@ -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, diff --git a/source/passdb/pdb_interface.c b/source/passdb/pdb_interface.c index cc05d974681..7252ea4c8c4 100644 --- a/source/passdb/pdb_interface.c +++ b/source/passdb/pdb_interface.c @@ -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; diff --git a/source/passdb/pdb_ldap.c b/source/passdb/pdb_ldap.c index e0f79c140dd..0f03a1cc6eb 100644 --- a/source/passdb/pdb_ldap.c +++ b/source/passdb/pdb_ldap.c @@ -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; diff --git a/source/passdb/pdb_smbpasswd.c b/source/passdb/pdb_smbpasswd.c index 905cf8f2a2d..afc00445f40 100644 --- a/source/passdb/pdb_smbpasswd.c +++ b/source/passdb/pdb_smbpasswd.c @@ -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 { diff --git a/source/passdb/pdb_tdb.c b/source/passdb/pdb_tdb.c index b16368baf17..e9beaa05368 100644 --- a/source/passdb/pdb_tdb.c +++ b/source/passdb/pdb_tdb.c @@ -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; } diff --git a/source/utils/net_rpc_samsync.c b/source/utils/net_rpc_samsync.c index 0b54a6c97fc..1337c11eca1 100644 --- a/source/utils/net_rpc_samsync.c +++ b/source/utils/net_rpc_samsync.c @@ -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 */ -- 2.34.1