source: branches/samba-3.3.x/source/libsmb/conncache.c

Last change on this file was 206, checked in by Herwig Bauernfeind, 17 years ago

Import Samba 3.3 branch at 3.0.0 level (psmedley's port)

File size: 6.7 KB
Line 
1/*
2 Unix SMB/CIFS implementation.
3
4 Winbind daemon connection manager
5
6 Copyright (C) Tim Potter 2001
7 Copyright (C) Andrew Bartlett 2002
8 Copyright (C) Gerald (Jerry) Carter 2003
9 Copyright (C) Marc VanHeyningen 2008
10
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 3 of the License, or
14 (at your option) any later version.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program. If not, see <http://www.gnu.org/licenses/>.
23*/
24
25
26#include "includes.h"
27
28/**
29 * @file
30 * Negative connection cache implemented in terms of gencache API
31 *
32 * The negative connection cache stores names of servers which have
33 * been unresponsive so that we don't waste time repeatedly trying
34 * to contact them. It used to use an in-memory linked list, but
35 * this limited its utility to a single process
36 */
37
38
39/**
40 * prefix used for all entries put into the general cache
41 */
42static const char NEGATIVE_CONN_CACHE_PREFIX[] = "NEG_CONN_CACHE";
43
44/**
45 * Marshalls the domain and server name into the key for the gencache
46 * record
47 *
48 * @param[in] domain required
49 * @param[in] server may be a FQDN or an IP address
50 * @return the resulting string, which the caller is responsible for
51 * SAFE_FREE()ing
52 * @retval NULL returned on error
53 */
54static char *negative_conn_cache_keystr(const char *domain, const char *server)
55{
56 const char NEGATIVE_CONN_CACHE_KEY_FMT[] = "%s/%s,%s";
57 char *keystr = NULL;
58
59 SMB_ASSERT(domain != NULL);
60 if (server == NULL)
61 server = "";
62
63 keystr = talloc_asprintf(talloc_tos(),NEGATIVE_CONN_CACHE_KEY_FMT,
64 NEGATIVE_CONN_CACHE_PREFIX, domain, server);
65 if (keystr == NULL) {
66 DEBUG(0, ("negative_conn_cache_keystr: malloc error\n"));
67 }
68
69 return keystr;
70}
71
72/**
73 * Marshalls the NT status into a printable value field for the gencache
74 * record
75 *
76 * @param[in] status
77 * @return the resulting string, which the caller is responsible for
78 * SAFE_FREE()ing
79 * @retval NULL returned on error
80 */
81static char *negative_conn_cache_valuestr(NTSTATUS status)
82{
83 char *valuestr = NULL;
84
85 valuestr = talloc_asprintf(talloc_tos(), "%x", NT_STATUS_V(status));
86 if (valuestr == NULL) {
87 DEBUG(0, ("negative_conn_cache_valuestr: malloc error\n"));
88 }
89