From 9d65e0778425b1e49e789178999ce98e59395569 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Thu, 10 Mar 2005 23:41:19 +0000 Subject: r5735: rest of derrel's patch for BUG 2308; had to move the options structure from the _SMBCCTX to the internals structure to maintain binary compatibility (derrel, we should talk more about this) (This used to be commit a5ea01bf15758bb2be26ba16784dc0975be783bf) --- source3/libsmb/libsmb_cache.c | 55 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 47 insertions(+), 8 deletions(-) (limited to 'source3/libsmb/libsmb_cache.c') diff --git a/source3/libsmb/libsmb_cache.c b/source3/libsmb/libsmb_cache.c index ddb2753523..dabf5a527d 100644 --- a/source3/libsmb/libsmb_cache.c +++ b/source3/libsmb/libsmb_cache.c @@ -1,3 +1,4 @@ + /* Unix SMB/CIFS implementation. SMB client library implementation (server cache) @@ -23,12 +24,8 @@ #include "includes.h" -/* - * Define this to get the real SMBCFILE and SMBCSRV structures - */ -#define _SMBC_INTERNAL #include "include/libsmbclient.h" - +#include "../include/libsmb_internal.h" /* * Structure we use if internal caching mechanism is used * nothing fancy here. @@ -115,11 +112,53 @@ static SMBCSRV * smbc_get_cached_server(SMBCCTX * context, const char * server, /* Search the cache lines */ for (srv=((struct smbc_server_cache *)context->server_cache);srv;srv=srv->next) { + if (strcmp(server,srv->server_name) == 0 && - strcmp(share,srv->share_name) == 0 && strcmp(workgroup,srv->workgroup) == 0 && - strcmp(user, srv->username) == 0) - return srv->server; + 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 + * caught above). + */ + 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. + */ + 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 + * attribute server connection) is cool. + */ + if (context->options.one_share_per_server) { + /* + * The currently connected share name + * doesn't match the requested share, so + * disconnect from the current share. + */ + if (! cli_tdis(&srv->server->cli)) { + /* Sigh. Couldn't disconnect. */ + cli_shutdown(&srv->server->cli); + context->callbacks.remove_cached_srv_fn(context, srv->server); + continue; + } + + return srv->server; + } + } } return NULL; -- cgit