From 9e2f008bb99af8fd83136cbd8e5a785d5348276b Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 25 Jun 2003 18:08:00 +0000 Subject: forgot one file (This used to be commit ef978bd851431da373e005177504dbef2611cf4f) --- source3/libsmb/conncache.c | 158 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 158 insertions(+) create mode 100644 source3/libsmb/conncache.c (limited to 'source3/libsmb/conncache.c') diff --git a/source3/libsmb/conncache.c b/source3/libsmb/conncache.c new file mode 100644 index 0000000000..ab0501b0be --- /dev/null +++ b/source3/libsmb/conncache.c @@ -0,0 +1,158 @@ +/* + Unix SMB/CIFS implementation. + + Winbind daemon connection manager + + Copyright (C) Tim Potter 2001 + Copyright (C) Andrew Bartlett 2002 + Copyright (C) Gerald (Jerry) Carter 2003 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + + +#include "includes.h" + +#define FAILED_CONNECTION_CACHE_TIMEOUT 30 /* Seconds between attempts */ + +#define CONNCACHE_ADDR 1 +#define CONNCACHE_NAME 2 + +/* cache entry contains either a server name **or** and IP address as + the key. This means that a server could have two entries (one for each key) */ + +struct failed_connection_cache { + fstring domain_name; + fstring controller; + time_t lookup_time; + NTSTATUS nt_status; + struct failed_connection_cache *prev, *next; +}; + +static struct failed_connection_cache *failed_connection_cache; + +/********************************************************************** + Check for a previously failed connection +**********************************************************************/ + +NTSTATUS check_negative_conn_cache( const char *domain, const char *server ) +{ + struct failed_connection_cache *fcc; + NTSTATUS result = NT_STATUS_UNSUCCESSFUL; + + /* can't check if we don't have strings */ + + if ( !domain || !server ) + return NT_STATUS_OK; + + for (fcc = failed_connection_cache; fcc; fcc = fcc->next) { + + if ( !(strequal(domain, fcc->domain_name) && strequal(server, fcc->controller)) ) + continue; /* no match; check the next entry */ + + /* we have a match so see if it is still current */ + + if ((time(NULL) - fcc->lookup_time) > FAILED_CONNECTION_CACHE_TIMEOUT) + { + /* Cache entry has expired, delete it */ + + DEBUG(10, ("check_negative_conn_cache: cache entry expired for %s, %s\n", + domain, server )); + + DLIST_REMOVE(failed_connection_cache, fcc); + SAFE_FREE(fcc); + + return NT_STATUS_OK; + } + + /* The timeout hasn't expired yet so return false */ + + DEBUG(10, ("check_negative_conn_cache: returning negative entry for %s, %s\n", + domain, server )); + + result = fcc->nt_status; + return result; + } + + /* end of function means no cache entry */ + return NT_STATUS_OK; +} + +/********************************************************************** + Add an entry to the failed conneciton cache (aither a name of dotted + decimal IP +**********************************************************************/ + +void add_failed_connection_entry(const char *domain, const char *server, NTSTATUS result) +{ + struct failed_connection_cache *fcc; + + SMB_ASSERT(!NT_STATUS_IS_OK(result)); + + /* Check we already aren't in the cache. We always have to have + a domain, but maybe not a specific DC name. */ + + for (fcc = failed_connection_cache; fcc; fcc = fcc->next) { + if ( strequal(fcc->domain_name, domain) && strequal(fcc->controller, server) ) + { + DEBUG(10, ("add_failed_connection_entry_byname: domain %s (%s) already tried and failed\n", + domain, server )); + return; + } + } + + /* Create negative lookup cache entry for this domain and controller */ + + if ( !(fcc = (struct failed_connection_cache *)malloc(sizeof(struct failed_connection_cache))) ) + { + DEBUG(0, ("malloc failed in add_failed_connection_entry!\n")); + return; + } + + ZERO_STRUCTP(fcc); + + fstrcpy( fcc->domain_name, domain ); + fstrcpy( fcc->controller, server ); + fcc->lookup_time = time(NULL); + fcc->nt_status = result; + + DEBUG(10,("add_failed_connection_entry_byname: added domain %s (%s) to failed conn cache\n", + domain, server )); + + DLIST_ADD(failed_connection_cache, fcc); +} + +/**************************************************************************** +****************************************************************************/ + +void flush_negative_conn_cache( void ) +{ + struct failed_connection_cache *fcc; + + fcc = failed_connection_cache; + + while (fcc) { + struct failed_connection_cache *fcc_next; + + fcc_next = fcc->next; + DLIST_REMOVE(failed_connection_cache, fcc); + free(fcc); + + fcc = fcc_next; + } + +} + + -- cgit From 72876b79c9b3f0ab3cda6de42d5c8995aadd687e Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 25 Jun 2003 19:00:15 +0000 Subject: * fix typos in a few debug statements * check negative connection cache before ads_try_connect() in ads_find_dc() (This used to be commit 2a76101a3a31f5fca2f444b25e3f0486f7ef406f) --- source3/libsmb/conncache.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/libsmb/conncache.c') diff --git a/source3/libsmb/conncache.c b/source3/libsmb/conncache.c index ab0501b0be..da31e25a9c 100644 --- a/source3/libsmb/conncache.c +++ b/source3/libsmb/conncache.c @@ -107,7 +107,7 @@ void add_failed_connection_entry(const char *domain, const char *server, NTSTATU for (fcc = failed_connection_cache; fcc; fcc = fcc->next) { if ( strequal(fcc->domain_name, domain) && strequal(fcc->controller, server) ) { - DEBUG(10, ("add_failed_connection_entry_byname: domain %s (%s) already tried and failed\n", + DEBUG(10, ("add_failed_connection_entry: domain %s (%s) already tried and failed\n", domain, server )); return; } -- cgit From 2ff85e2f0a25697970e80beb4d58d81f05bcf800 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 16 Jul 2003 02:51:28 +0000 Subject: fix typo in debug log (This used to be commit 074da426708555de082d0c2e5ae3a5cddaadcdf4) --- source3/libsmb/conncache.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/libsmb/conncache.c') diff --git a/source3/libsmb/conncache.c b/source3/libsmb/conncache.c index da31e25a9c..e6604617d6 100644 --- a/source3/libsmb/conncache.c +++ b/source3/libsmb/conncache.c @@ -128,7 +128,7 @@ void add_failed_connection_entry(const char *domain, const char *server, NTSTATU fcc->lookup_time = time(NULL); fcc->nt_status = result; - DEBUG(10,("add_failed_connection_entry_byname: added domain %s (%s) to failed conn cache\n", + DEBUG(10,("add_failed_connection_entry: added domain %s (%s) to failed conn cache\n", domain, server )); DLIST_ADD(failed_connection_cache, fcc); -- cgit From f5b4721d6d60bf3b2bb5081469465cc7ee7e17e6 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 2 Jul 2004 01:09:10 +0000 Subject: r1326: Modification to get_dc_list to check negative cache. From "Joe Meadows" . Jeremy. (This used to be commit 4cc38b8aea51b55cc449cd2144f18de7d4819637) --- source3/libsmb/conncache.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'source3/libsmb/conncache.c') diff --git a/source3/libsmb/conncache.c b/source3/libsmb/conncache.c index e6604617d6..15cc75b129 100644 --- a/source3/libsmb/conncache.c +++ b/source3/libsmb/conncache.c @@ -154,5 +154,3 @@ void flush_negative_conn_cache( void ) } } - - -- cgit From acf9d61421faa6c0055d57fdee7db300dc5431aa Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 7 Dec 2004 18:25:53 +0000 Subject: r4088: Get medieval on our ass about malloc.... :-). Take control of all our allocation functions so we can funnel through some well known functions. Should help greatly with malloc checking. HEAD patch to follow. Jeremy. (This used to be commit 620f2e608f70ba92f032720c031283d295c5c06a) --- source3/libsmb/conncache.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/libsmb/conncache.c') diff --git a/source3/libsmb/conncache.c b/source3/libsmb/conncache.c index 15cc75b129..fe863db422 100644 --- a/source3/libsmb/conncache.c +++ b/source3/libsmb/conncache.c @@ -115,8 +115,7 @@ void add_failed_connection_entry(const char *domain, const char *server, NTSTATU /* Create negative lookup cache entry for this domain and controller */ - if ( !(fcc = (struct failed_connection_cache *)malloc(sizeof(struct failed_connection_cache))) ) - { + if ( !(fcc = SMB_MALLOC_P(struct failed_connection_cache)) ) { DEBUG(0, ("malloc failed in add_failed_connection_entry!\n")); return; } -- cgit From 4699d4741da8145b1a491eeafa4133133e194f94 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 30 Jan 2006 20:20:17 +0000 Subject: r13238: Fix from Qiao Yang to ensure we always update the failed time when we are adding a failed connection. Jeremy. (This used to be commit 6f5af1dd413d07430ead9382422dda14acf3464d) --- source3/libsmb/conncache.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'source3/libsmb/conncache.c') diff --git a/source3/libsmb/conncache.c b/source3/libsmb/conncache.c index fe863db422..2af4d57b80 100644 --- a/source3/libsmb/conncache.c +++ b/source3/libsmb/conncache.c @@ -105,10 +105,11 @@ void add_failed_connection_entry(const char *domain, const char *server, NTSTATU a domain, but maybe not a specific DC name. */ for (fcc = failed_connection_cache; fcc; fcc = fcc->next) { - if ( strequal(fcc->domain_name, domain) && strequal(fcc->controller, server) ) - { + if ( strequal(fcc->domain_name, domain) && strequal(fcc->controller, server) ) { DEBUG(10, ("add_failed_connection_entry: domain %s (%s) already tried and failed\n", domain, server )); + /* Update the failed time. */ + fcc->lookup_time = time(NULL); return; } } -- cgit From 0af1500fc0bafe61019f1b2ab1d9e1d369221240 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 3 Feb 2006 22:19:41 +0000 Subject: r13316: Let the carnage begin.... Sync with trunk as off r13315 (This used to be commit 17e63ac4ed8325c0d44fe62b2442449f3298559f) --- source3/libsmb/conncache.c | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) (limited to 'source3/libsmb/conncache.c') diff --git a/source3/libsmb/conncache.c b/source3/libsmb/conncache.c index 2af4d57b80..49512d7a2e 100644 --- a/source3/libsmb/conncache.c +++ b/source3/libsmb/conncache.c @@ -25,8 +25,6 @@ #include "includes.h" -#define FAILED_CONNECTION_CACHE_TIMEOUT 30 /* Seconds between attempts */ - #define CONNCACHE_ADDR 1 #define CONNCACHE_NAME 2 @@ -44,10 +42,13 @@ struct failed_connection_cache { static struct failed_connection_cache *failed_connection_cache; /********************************************************************** - Check for a previously failed connection + Check for a previously failed connection. + failed_cache_timeout is an a absolute number of seconds after which + we should time this out. If failed_cache_timeout == 0 then time out + immediately. If failed_cache_timeout == -1 then never time out. **********************************************************************/ -NTSTATUS check_negative_conn_cache( const char *domain, const char *server ) +NTSTATUS check_negative_conn_cache_timeout( const char *domain, const char *server, unsigned int failed_cache_timeout ) { struct failed_connection_cache *fcc; NTSTATUS result = NT_STATUS_UNSUCCESSFUL; @@ -59,22 +60,24 @@ NTSTATUS check_negative_conn_cache( const char *domain, const char *server ) for (fcc = failed_connection_cache; fcc; fcc = fcc->next) { - if ( !(strequal(domain, fcc->domain_name) && strequal(server, fcc->controller)) ) + if (!(strequal(domain, fcc->domain_name) && strequal(server, fcc->controller))) { continue; /* no match; check the next entry */ + } /* we have a match so see if it is still current */ + if (failed_cache_timeout != (unsigned int)-1) { + if (failed_cache_timeout == 0 || + (time(NULL) - fcc->lookup_time) > (time_t)failed_cache_timeout) { + /* Cache entry has expired, delete it */ - if ((time(NULL) - fcc->lookup_time) > FAILED_CONNECTION_CACHE_TIMEOUT) - { - /* Cache entry has expired, delete it */ - - DEBUG(10, ("check_negative_conn_cache: cache entry expired for %s, %s\n", - domain, server )); + DEBUG(10, ("check_negative_conn_cache: cache entry expired for %s, %s\n", + domain, server )); - DLIST_REMOVE(failed_connection_cache, fcc); - SAFE_FREE(fcc); + DLIST_REMOVE(failed_connection_cache, fcc); + SAFE_FREE(fcc); - return NT_STATUS_OK; + return NT_STATUS_OK; + } } /* The timeout hasn't expired yet so return false */ @@ -90,6 +93,11 @@ NTSTATUS check_negative_conn_cache( const char *domain, const char *server ) return NT_STATUS_OK; } +NTSTATUS check_negative_conn_cache( const char *domain, const char *server) +{ + return check_negative_conn_cache_timeout(domain, server, FAILED_CONNECTION_CACHE_TIMEOUT); +} + /********************************************************************** Add an entry to the failed conneciton cache (aither a name of dotted decimal IP -- cgit From 041e49d19604e5e0688abd02869eebabf8c585b0 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 14 Sep 2006 16:37:13 +0000 Subject: r18533: Ensure we clear out the failed connection cache for an entire domain when going back online. Jeremy. (This used to be commit c7e4c8d0b4d109ec67d4424dd446b74b55246c72) --- source3/libsmb/conncache.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'source3/libsmb/conncache.c') diff --git a/source3/libsmb/conncache.c b/source3/libsmb/conncache.c index 49512d7a2e..b8ddcb2ba9 100644 --- a/source3/libsmb/conncache.c +++ b/source3/libsmb/conncache.c @@ -162,3 +162,31 @@ void flush_negative_conn_cache( void ) } } + +/**************************************************************************** + Remove all negative entries for a domain. Used when going to online state in + winbindd. +****************************************************************************/ + +void flush_negative_conn_cache_for_domain(const char *domain) +{ + struct failed_connection_cache *fcc; + + fcc = failed_connection_cache; + + while (fcc) { + struct failed_connection_cache *fcc_next; + + fcc_next = fcc->next; + + if (strequal(fcc->domain_name, domain)) { + DEBUG(10,("flush_negative_conn_cache_for_domain: removed server %s " + " from failed cache for domain %s\n", + fcc->controller, domain)); + DLIST_REMOVE(failed_connection_cache, fcc); + free(fcc); + } + + fcc = fcc_next; + } +} -- cgit From d824b98f80ba186030cbb70b3a1e5daf80469ecd Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 9 Jul 2007 19:25:36 +0000 Subject: r23779: Change from v2 or later to v3 or later. Jeremy. (This used to be commit 407e6e695b8366369b7c76af1ff76869b45347b3) --- source3/libsmb/conncache.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/libsmb/conncache.c') diff --git a/source3/libsmb/conncache.c b/source3/libsmb/conncache.c index b8ddcb2ba9..790ad47fa5 100644 --- a/source3/libsmb/conncache.c +++ b/source3/libsmb/conncache.c @@ -9,7 +9,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, -- cgit From 5e54558c6dea67b56bbfaba5698f3a434d3dffb6 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 00:52:41 +0000 Subject: r23784: use the GPLv3 boilerplate as recommended by the FSF and the license text (This used to be commit b0132e94fc5fef936aa766fb99a306b3628e9f07) --- source3/libsmb/conncache.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/libsmb/conncache.c') diff --git a/source3/libsmb/conncache.c b/source3/libsmb/conncache.c index 790ad47fa5..c4a87623d7 100644 --- a/source3/libsmb/conncache.c +++ b/source3/libsmb/conncache.c @@ -18,8 +18,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ -- cgit From d4cbc4408eba4a06931cc93c59555c4abc2f5ee1 Mon Sep 17 00:00:00 2001 From: Marc VanHeyningen Date: Wed, 4 Jun 2008 15:22:50 -0700 Subject: Negative conn cache uses gencache (This used to be commit 8765eb8ad7bb978d3bb9c9ff8e557791fdc43009) --- source3/libsmb/conncache.c | 318 +++++++++++++++++++++++++++------------------ 1 file changed, 189 insertions(+), 129 deletions(-) (limited to 'source3/libsmb/conncache.c') diff --git a/source3/libsmb/conncache.c b/source3/libsmb/conncache.c index c4a87623d7..2df45c2b0f 100644 --- a/source3/libsmb/conncache.c +++ b/source3/libsmb/conncache.c @@ -6,6 +6,7 @@ Copyright (C) Tim Potter 2001 Copyright (C) Andrew Bartlett 2002 Copyright (C) Gerald (Jerry) Carter 2003 + Copyright (C) Marc VanHeyningen 2008 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -24,168 +25,227 @@ #include "includes.h" -#define CONNCACHE_ADDR 1 -#define CONNCACHE_NAME 2 - -/* cache entry contains either a server name **or** and IP address as - the key. This means that a server could have two entries (one for each key) */ - -struct failed_connection_cache { - fstring domain_name; - fstring controller; - time_t lookup_time; - NTSTATUS nt_status; - struct failed_connection_cache *prev, *next; -}; - -static struct failed_connection_cache *failed_connection_cache; - -/********************************************************************** - Check for a previously failed connection. - failed_cache_timeout is an a absolute number of seconds after which - we should time this out. If failed_cache_timeout == 0 then time out - immediately. If failed_cache_timeout == -1 then never time out. -**********************************************************************/ - -NTSTATUS check_negative_conn_cache_timeout( const char *domain, const char *server, unsigned int failed_cache_timeout ) +/** + * @file + * Negative connection cache implemented in terms of gencache API + * + * The negative connection cache stores names of servers which have + * been unresponsive so that we don't waste time repeatedly trying + * to contact them. It used to use an in-memory linked list, but + * this limited its utility to a single process + */ + + +/** + * prefix used for all entries put into the general cache + */ +static const char NEGATIVE_CONN_CACHE_PREFIX[] = "NEG_CONN_CACHE"; + +/** + * Marshalls the domain and server name into the key for the gencache + * record + * + * @param[in] domain required + * @param[in] server may be a FQDN or an IP address + * @return the resulting string, which the caller is responsible for + * SAFE_FREE()ing + * @retval NULL returned on error + */ +static char *negative_conn_cache_keystr(const char *domain, const char *server) { - struct failed_connection_cache *fcc; - NTSTATUS result = NT_STATUS_UNSUCCESSFUL; - - /* can't check if we don't have strings */ - - if ( !domain || !server ) - return NT_STATUS_OK; + const char NEGATIVE_CONN_CACHE_KEY_FMT[] = "%s/%s,%s"; + char *keystr = NULL; - for (fcc = failed_connection_cache; fcc; fcc = fcc->next) { + SMB_ASSERT(domain != NULL); + if (server == NULL) + server = ""; - if (!(strequal(domain, fcc->domain_name) && strequal(server, fcc->controller))) { - continue; /* no match; check the next entry */ - } - - /* we have a match so see if it is still current */ - if (failed_cache_timeout != (unsigned int)-1) { - if (failed_cache_timeout == 0 || - (time(NULL) - fcc->lookup_time) > (time_t)failed_cache_timeout) { - /* Cache entry has expired, delete it */ + if (asprintf(&keystr, NEGATIVE_CONN_CACHE_KEY_FMT, + NEGATIVE_CONN_CACHE_PREFIX, domain, server) == -1) + DEBUG(0, ("negative_conn_cache_keystr: malloc error\n")); - DEBUG(10, ("check_negative_conn_cache: cache entry expired for %s, %s\n", - domain, server )); + return keystr; +} - DLIST_REMOVE(failed_connection_cache, fcc); - SAFE_FREE(fcc); +/** + * Marshalls the NT status into a printable value field for the gencache + * record + * + * @param[in] status + * @return the resulting string, which the caller is responsible for + * SAFE_FREE()ing + * @retval NULL returned on error + */ +static char *negative_conn_cache_valuestr(NTSTATUS status) +{ + char *valuestr = NULL; - return NT_STATUS_OK; - } - } + if (asprintf(&valuestr, "%x", NT_STATUS_V(status)) == -1) + DEBUG(0, ("negative_conn_cache_valuestr: malloc error\n")); - /* The timeout hasn't expired yet so return false */ + return valuestr; +} - DEBUG(10, ("check_negative_conn_cache: returning negative entry for %s, %s\n", - domain, server )); +/** + * Un-marshalls the NT status from a printable field for the gencache + * record + * + * @param[in] value The value field from the record + * @return the decoded NT status + * @retval NT_STATUS_OK returned on error + */ +static NTSTATUS negative_conn_cache_valuedecode(const char *value) +{ + NTSTATUS result = NT_STATUS_OK; - result = fcc->nt_status; - return result; - } + SMB_ASSERT(value != NULL); + if (sscanf(value, "%x", &(NT_STATUS_V(result))) != 1) + DEBUG(0, ("negative_conn_cache_valuestr: unable to parse " + "value field '%s'\n", value)); + return result; +} - /* end of function means no cache entry */ - return NT_STATUS_OK; +/** + * Function passed to gencache_iterate to remove any matching items + * from the list + * + * @param[in] key Key to the record found and to be deleted + * @param[in] value Value to the record (ignored) + * @param[in] timeout Timeout remaining for the record (ignored) + * @param[in] dptr Handle for passing additional data (ignored) + */ +static void delete_matches(const char *key, const char *value, + time_t timeout, void *dptr) +{ + gencache_del(key); } + +/** + * Checks for a given domain/server record in the negative cache + * + * @param[in] domain + * @param[in] server may be either a FQDN or an IP address + * @return The cached failure status + * @retval NT_STATUS_OK returned if no record is found or an error occurs + */ NTSTATUS check_negative_conn_cache( const char *domain, const char *server) { - return check_negative_conn_cache_timeout(domain, server, FAILED_CONNECTION_CACHE_TIMEOUT); + NTSTATUS result = NT_STATUS_OK; + char *key = NULL; + char *value = NULL; + + key = negative_conn_cache_keystr(domain, server); + if (key == NULL) + goto done; + + if (gencache_get(key, &value, (time_t *) NULL)) + result = negative_conn_cache_valuedecode(value); + done: + DEBUG(9,("check_negative_conn_cache returning result %d for domain %s " + "server %s\n", NT_STATUS_V(result), domain, server)); + SAFE_FREE(key); + SAFE_FREE(value); + return result; } -/********************************************************************** - Add an entry to the failed conneciton cache (aither a name of dotted - decimal IP -**********************************************************************/ - -void add_failed_connection_entry(const char *domain, const char *server, NTSTATUS result) +/** + * Delete any negative cache entry for the given domain/server + * + * @param[in] domain + * @param[in] server may be either a FQDN or an IP address + */ +void delete_negative_conn_cache(const char *domain, const char *server) { - struct failed_connection_cache *fcc; + char *key = NULL; + + key = negative_conn_cache_keystr(domain, server); + if (key == NULL) + goto done; + + gencache_del(key); + DEBUG(9,("delete_negative_conn_cache removing domain %s server %s\n", + domain, server)); + done: + SAFE_FREE(key); + return; +} - SMB_ASSERT(!NT_STATUS_IS_OK(result)); - /* Check we already aren't in the cache. We always have to have - a domain, but maybe not a specific DC name. */ - - for (fcc = failed_connection_cache; fcc; fcc = fcc->next) { - if ( strequal(fcc->domain_name, domain) && strequal(fcc->controller, server) ) { - DEBUG(10, ("add_failed_connection_entry: domain %s (%s) already tried and failed\n", - domain, server )); - /* Update the failed time. */ - fcc->lookup_time = time(NULL); - return; - } - } +/** + * Add an entry to the failed conneciton cache + * + * @param[in] domain + * @param[in] server may be a FQDN or an IP addr in printable form + * @param[in] result error to cache; must not be NT_STATUS_OK + */ +void add_failed_connection_entry(const char *domain, const char *server, + NTSTATUS result) +{ + char *key = NULL; + char *value = NULL; - /* Create negative lookup cache entry for this domain and controller */ + SMB_ASSERT(!NT_STATUS_IS_OK(result)); - if ( !(fcc = SMB_MALLOC_P(struct failed_connection_cache)) ) { - DEBUG(0, ("malloc failed in add_failed_connection_entry!\n")); - return; + key = negative_conn_cache_keystr(domain, server); + if (key == NULL) { + DEBUG(0, ("add_failed_connection_entry: key creation error\n")); + goto done; } - ZERO_STRUCTP(fcc); - - fstrcpy( fcc->domain_name, domain ); - fstrcpy( fcc->controller, server ); - fcc->lookup_time = time(NULL); - fcc->nt_status = result; + value = negative_conn_cache_valuestr(result); + if (value == NULL) { + DEBUG(0, ("add_failed_connection_entry: value creation error\n")); + goto done; + } - DEBUG(10,("add_failed_connection_entry: added domain %s (%s) to failed conn cache\n", - domain, server )); + if (gencache_set(key, value, + time((time_t *) NULL + FAILED_CONNECTION_CACHE_TIMEOUT))) + DEBUG(9,("add_failed_connection_entry: added domain %s (%s) " + "to failed conn cache\n", domain, server )); + else + DEBUG(1,("add_failed_connection_entry: failed to add " + "domain %s (%s) to failed conn cache\n", + domain, server)); - DLIST_ADD(failed_connection_cache, fcc); + done: + SAFE_FREE(key); + SAFE_FREE(value); + return; } -/**************************************************************************** -****************************************************************************/ - +/** + * Deletes all records from the negative connection cache in all domains + */ void flush_negative_conn_cache( void ) { - struct failed_connection_cache *fcc; - - fcc = failed_connection_cache; - - while (fcc) { - struct failed_connection_cache *fcc_next; - - fcc_next = fcc->next; - DLIST_REMOVE(failed_connection_cache, fcc); - free(fcc); - - fcc = fcc_next; - } - + flush_negative_conn_cache_for_domain("*"); } -/**************************************************************************** - Remove all negative entries for a domain. Used when going to online state in - winbindd. -****************************************************************************/ - + +/** + * Deletes all records for a specified domain from the negative connection + * cache + * + * @param[in] domain String to match against domain portion of keys, or "*" + * to match all domains + */ void flush_negative_conn_cache_for_domain(const char *domain) { - struct failed_connection_cache *fcc; - - fcc = failed_connection_cache; - - while (fcc) { - struct failed_connection_cache *fcc_next; + char *key_pattern = NULL; - fcc_next = fcc->next; - - if (strequal(fcc->domain_name, domain)) { - DEBUG(10,("flush_negative_conn_cache_for_domain: removed server %s " - " from failed cache for domain %s\n", - fcc->controller, domain)); - DLIST_REMOVE(failed_connection_cache, fcc); - free(fcc); - } - - fcc = fcc_next; + key_pattern = negative_conn_cache_keystr(domain,"*"); + if (key_pattern == NULL) { + DEBUG(0, ("flush_negative_conn_cache_for_domain: " + "key creation error\n")); + goto done; } + + gencache_iterate(delete_matches, (void *) NULL, key_pattern); + DEBUG(8, ("flush_negative_conn_cache_for_domain: flushed domain %s\n", + domain)); + + done: + SAFE_FREE(key_pattern); + return; } -- cgit From a191f3d2fede9cfa19261060a2788df75bc15089 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Thu, 5 Jun 2008 09:00:37 +0200 Subject: Make the gencache based conncache use talloc_tos() (This used to be commit f7f912a478af64b07beeb58673b605da0c46db94) --- source3/libsmb/conncache.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'source3/libsmb/conncache.c') diff --git a/source3/libsmb/conncache.c b/source3/libsmb/conncache.c index 2df45c2b0f..b8f98085ce 100644 --- a/source3/libsmb/conncache.c +++ b/source3/libsmb/conncache.c @@ -59,10 +59,12 @@ static char *negative_conn_cache_keystr(const char *domain, const char *server) SMB_ASSERT(domain != NULL); if (server == NULL) server = ""; - - if (asprintf(&keystr, NEGATIVE_CONN_CACHE_KEY_FMT, - NEGATIVE_CONN_CACHE_PREFIX, domain, server) == -1) + + keystr = talloc_asprintf(talloc_tos(),NEGATIVE_CONN_CACHE_KEY_FMT, + NEGATIVE_CONN_CACHE_PREFIX, domain, server); + if (keystr == NULL) { DEBUG(0, ("negative_conn_cache_keystr: malloc error\n")); + } return keystr; } @@ -80,8 +82,10 @@ static char *negative_conn_cache_valuestr(NTSTATUS status) { char *valuestr = NULL; - if (asprintf(&valuestr, "%x", NT_STATUS_V(status)) == -1) + valuestr = talloc_asprintf(talloc_tos(), "%x", NT_STATUS_V(status)); + if (valuestr == NULL) { DEBUG(0, ("negative_conn_cache_valuestr: malloc error\n")); + } return valuestr; } @@ -144,7 +148,7 @@ NTSTATUS check_negative_conn_cache( const char *domain, const char *server) done: DEBUG(9,("check_negative_conn_cache returning result %d for domain %s " "server %s\n", NT_STATUS_V(result), domain, server)); - SAFE_FREE(key); + TALLOC_FREE(key); SAFE_FREE(value); return result; } @@ -167,7 +171,7 @@ void delete_negative_conn_cache(const char *domain, const char *server) DEBUG(9,("delete_negative_conn_cache removing domain %s server %s\n", domain, server)); done: - SAFE_FREE(key); + TALLOC_FREE(key); return; } @@ -192,13 +196,13 @@ void add_failed_connection_entry(const char *domain, const char *server, DEBUG(0, ("add_failed_connection_entry: key creation error\n")); goto done; } - + value = negative_conn_cache_valuestr(result); if (value == NULL) { DEBUG(0, ("add_failed_connection_entry: value creation error\n")); goto done; } - + if (gencache_set(key, value, time((time_t *) NULL + FAILED_CONNECTION_CACHE_TIMEOUT))) DEBUG(9,("add_failed_connection_entry: added domain %s (%s) " @@ -209,8 +213,8 @@ void add_failed_connection_entry(const char *domain, const char *server, domain, server)); done: - SAFE_FREE(key); - SAFE_FREE(value); + TALLOC_FREE(key); + TALLOC_FREE(value); return; } @@ -246,6 +250,6 @@ void flush_negative_conn_cache_for_domain(const char *domain) domain)); done: - SAFE_FREE(key_pattern); + TALLOC_FREE(key_pattern); return; } -- cgit From dd30dd2a14f4a883d737150de80d896b941180c5 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Thu, 5 Jun 2008 09:36:34 +0200 Subject: Fix a crash in add_failed_connection_entry (This used to be commit 2a689aa66af1de3d2e0d08b51e33e9a7015d6cb7) --- source3/libsmb/conncache.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source3/libsmb/conncache.c') diff --git a/source3/libsmb/conncache.c b/source3/libsmb/conncache.c index b8f98085ce..05344f4071 100644 --- a/source3/libsmb/conncache.c +++ b/source3/libsmb/conncache.c @@ -204,7 +204,8 @@ void add_failed_connection_entry(const char *domain, const char *server, } if (gencache_set(key, value, - time((time_t *) NULL + FAILED_CONNECTION_CACHE_TIMEOUT))) + time((time_t *) NULL) + + FAILED_CONNECTION_CACHE_TIMEOUT)) DEBUG(9,("add_failed_connection_entry: added domain %s (%s) " "to failed conn cache\n", domain, server )); else -- cgit From 304554115a2f2dc316386a9ea5bec237d67f595f Mon Sep 17 00:00:00 2001 From: Steven Danneman Date: Wed, 3 Sep 2008 15:31:39 -0700 Subject: Cleanup of DC enumeration in get_dcs() This is a fix for a few small inefficiencies/bugs in the get_dcs() path. * because the third add_one_dc_unique() loop was outside the ADS check all DCs returned from the non-sitename lookup were being tacked onto the dc_name_ip list twice. * add_one_dc_unique() now checks if the given IP address already exists before adding it to the list, making the returned list actually unique * added more thorough doxygen comment headers (This used to be commit cb2d488e1dbd90953c496c5e25d648977884f7e3) --- source3/libsmb/conncache.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/libsmb/conncache.c') diff --git a/source3/libsmb/conncache.c b/source3/libsmb/conncache.c index 05344f4071..b440d61048 100644 --- a/source3/libsmb/conncache.c +++ b/source3/libsmb/conncache.c @@ -177,7 +177,7 @@ void delete_negative_conn_cache(const char *domain, const char *server) /** - * Add an entry to the failed conneciton cache + * Add an entry to the failed connection cache * * @param[in] domain * @param[in] server may be a FQDN or an IP addr in printable form -- cgit