Copyright (C) Andrew Bartlett 2002
Copyright (C) Gerald (Jerry) Carter 2003
Copyright (C) Marc VanHeyningen 2008
-
+ Copyright (C) Volker Lendecke 2009
+
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 3 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, see <http://www.gnu.org/licenses/>.
*/
*/
-/**
- * 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
*/
static char *negative_conn_cache_keystr(const char *domain, const char *server)
{
- const char NEGATIVE_CONN_CACHE_KEY_FMT[] = "%s/%s,%s";
char *keystr = NULL;
- SMB_ASSERT(domain != NULL);
+ if (domain == NULL) {
+ return NULL;
+ }
if (server == NULL)
server = "";
- keystr = talloc_asprintf(talloc_tos(),NEGATIVE_CONN_CACHE_KEY_FMT,
- NEGATIVE_CONN_CACHE_PREFIX, domain, server);
+ keystr = talloc_asprintf(talloc_tos(), "NEG_CONN_CACHE/%s,%s",
+ domain, server);
if (keystr == NULL) {
DEBUG(0, ("negative_conn_cache_keystr: malloc error\n"));
}
*/
static NTSTATUS negative_conn_cache_valuedecode(const char *value)
{
- NTSTATUS result = NT_STATUS_OK;
+ unsigned int v = NT_STATUS_V(NT_STATUS_INTERNAL_ERROR);
- SMB_ASSERT(value != NULL);
- if (sscanf(value, "%x", &(NT_STATUS_V(result))) != 1)
- DEBUG(0, ("negative_conn_cache_valuestr: unable to parse "
+ if (value == NULL) {
+ return NT_STATUS_INTERNAL_ERROR;
+ }
+ if (sscanf(value, "%x", &v) != 1) {
+ DEBUG(0, ("negative_conn_cache_valuedecode: unable to parse "
"value field '%s'\n", value));
- return result;
+ }
+ return NT_STATUS(v);
}
/**
if (key == NULL)
goto done;
- if (gencache_get(key, &value, NULL))
+ if (gencache_get(key, talloc_tos(), &value, 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));
TALLOC_FREE(key);
- SAFE_FREE(value);
+ TALLOC_FREE(value);
return 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)
-{
- 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:
- TALLOC_FREE(key);
- return;
-}
-
-
/**
* Add an entry to the failed connection cache
*
char *key = NULL;
char *value = NULL;
- SMB_ASSERT(!NT_STATUS_IS_OK(result));
+ if (NT_STATUS_IS_OK(result)) {
+ /* Nothing failed here */
+ return;
+ }
key = negative_conn_cache_keystr(domain, server);
if (key == NULL) {
DEBUG(1,("add_failed_connection_entry: failed to add "
"domain %s (%s) to failed conn cache\n",
domain, server));
-
+
done:
TALLOC_FREE(key);
TALLOC_FREE(value);
return;
}
-/**
- * Deletes all records from the negative connection cache in all domains
- */
-void flush_negative_conn_cache( void )
-{
- flush_negative_conn_cache_for_domain("*");
-}
-
-
/**
* Deletes all records for a specified domain from the negative connection
* cache