summaryrefslogtreecommitdiff
path: root/source3/libsmb/libsmb_cache.c
diff options
context:
space:
mode:
Diffstat (limited to 'source3/libsmb/libsmb_cache.c')
-rw-r--r--source3/libsmb/libsmb_cache.c55
1 files changed, 27 insertions, 28 deletions
diff --git a/source3/libsmb/libsmb_cache.c b/source3/libsmb/libsmb_cache.c
index bfacea368d..53cd3d5a77 100644
--- a/source3/libsmb/libsmb_cache.c
+++ b/source3/libsmb/libsmb_cache.c
@@ -5,17 +5,17 @@
Copyright (C) Richard Sharpe 2000
Copyright (C) John Terpstra 2000
Copyright (C) Tom Jansen (Ninja ISD) 2002
-
+
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/>.
*/
@@ -34,7 +34,7 @@ struct smbc_server_cache {
char *workgroup;
char *username;
SMBCSRV *server;
-
+
struct smbc_server_cache *next, *prev;
};
@@ -53,51 +53,51 @@ SMBC_add_cached_server(SMBCCTX * context,
const char * username)
{
struct smbc_server_cache * srvcache = NULL;
-
+
if (!(srvcache = SMB_MALLOC_P(struct smbc_server_cache))) {
errno = ENOMEM;
DEBUG(3, ("Not enough space for server cache allocation\n"));
return 1;
}
-
+
ZERO_STRUCTP(srvcache);
-
+
srvcache->server = newsrv;
-
+
srvcache->server_name = SMB_STRDUP(server);
if (!srvcache->server_name) {
errno = ENOMEM;
goto failed;
}
-
+
srvcache->share_name = SMB_STRDUP(share);
if (!srvcache->share_name) {
errno = ENOMEM;
goto failed;
}
-
+
srvcache->workgroup = SMB_STRDUP(workgroup);
if (!srvcache->workgroup) {
errno = ENOMEM;
goto failed;
}
-
+
srvcache->username = SMB_STRDUP(username);
if (!srvcache->username) {
errno = ENOMEM;
goto failed;
}
-
+
DLIST_ADD(context->internal->server_cache, srvcache);
return 0;
-
+
failed:
SAFE_FREE(srvcache->server_name);
SAFE_FREE(srvcache->share_name);
SAFE_FREE(srvcache->workgroup);
SAFE_FREE(srvcache->username);
SAFE_FREE(srvcache);
-
+
return 1;
}
@@ -116,19 +116,19 @@ SMBC_get_cached_server(SMBCCTX * context,
const char * user)
{
struct smbc_server_cache * srv = NULL;
-
+
/* Search the cache lines */
for (srv = context->internal->server_cache; srv; srv = srv->next) {
-
+
if (strcmp(server,srv->server_name) == 0 &&
strcmp(workgroup,srv->workgroup) == 0 &&
strcmp(user, srv->username) == 0) {
-
+
/* If the share name matches, we're cool */
if (strcmp(share, srv->share_name) == 0) {
return srv->server;
}
-
+
/*
* We only return an empty share name or the attribute
* server on an exact match (which would have been
@@ -136,7 +136,7 @@ SMBC_get_cached_server(SMBCCTX * context,
*/
if (*share == '\0' || strcmp(share, "*IPC$") == 0)
continue;
-
+
/*
* Never return an empty share name or the attribute
* server if it wasn't what was requested.
@@ -144,7 +144,7 @@ SMBC_get_cached_server(SMBCCTX * context,
if (*srv->share_name == '\0' ||
strcmp(srv->share_name, "*IPC$") == 0)
continue;
-
+
/*
* If we're only allowing one share per server, then
* a connection to the server (other than the
@@ -163,7 +163,7 @@ SMBC_get_cached_server(SMBCCTX * context,
smbc_getFunctionRemoveCachedServer(context)(context, srv->server);
continue;
}
-
+
/*
* Save the new share name. We've
* disconnected from the old share, and are
@@ -178,13 +178,12 @@ SMBC_get_cached_server(SMBCCTX * context,
smbc_getFunctionRemoveCachedServer(context)(context, srv->server);
continue;
}
-
-
+
return srv->server;
}
}
}
-
+
return NULL;
}
@@ -199,10 +198,10 @@ SMBC_remove_cached_server(SMBCCTX * context,
SMBCSRV * server)
{
struct smbc_server_cache * srv = NULL;
-
+
for (srv = context->internal->server_cache; srv; srv = srv->next) {
if (server == srv->server) {
-
+
/* remove this sucker */
DLIST_REMOVE(context->internal->server_cache, srv);
SAFE_FREE(srv->server_name);
@@ -228,13 +227,13 @@ SMBC_purge_cached_servers(SMBCCTX * context)
struct smbc_server_cache * srv;
struct smbc_server_cache * next;
int could_not_purge_all = 0;
-
+
for (srv = context->internal->server_cache,
next = (srv ? srv->next :NULL);
srv;
srv = next,
next = (srv ? srv->next : NULL)) {
-
+
if (SMBC_remove_unused_server(context, srv->server)) {
/* could not be removed */
could_not_purge_all = 1;