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,
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 <http://www.gnu.org/licenses/>.
*/
#include "includes.h"
#include "include/libsmbclient.h"
#include "../include/libsmb_internal.h"
+
+int smbc_default_cache_functions(SMBCCTX * context);
+
/*
* Structure we use if internal caching mechanism is used
* nothing fancy here.
* Add a new connection to the server cache.
* This function is only used if the external cache is not enabled
*/
-static int smbc_add_cached_server(SMBCCTX * context, SMBCSRV * new,
+static int smbc_add_cached_server(SMBCCTX * context, SMBCSRV * newsrv,
const char * server, const char * share,
const char * workgroup, const char * username)
{
ZERO_STRUCTP(srvcache);
- srvcache->server = new;
+ srvcache->server = newsrv;
srvcache->server_name = SMB_STRDUP(server);
if (!srvcache->server_name) {
SAFE_FREE(srvcache->share_name);
SAFE_FREE(srvcache->workgroup);
SAFE_FREE(srvcache->username);
+ SAFE_FREE(srvcache);
return 1;
}
* doesn't match the requested share, so
* disconnect from the current share.
*/
- if (! cli_tdis(&srv->server->cli)) {
+ if (! cli_tdis(srv->server->cli)) {
/* Sigh. Couldn't disconnect. */
- cli_shutdown(&srv->server->cli);
+ cli_shutdown(srv->server->cli);
+ srv->server->cli = NULL;
context->callbacks.remove_cached_srv_fn(context, srv->server);
continue;
}
+ /*
+ * Save the new share name. We've
+ * disconnected from the old share, and are
+ * about to connect to the new one.
+ */
+ SAFE_FREE(srv->share_name);
+ srv->share_name = SMB_STRDUP(share);
+ if (!srv->share_name) {
+ /* Out of memory. */
+ cli_shutdown(srv->server->cli);
+ srv->server->cli = NULL;
+ context->callbacks.remove_cached_srv_fn(context, srv->server);
+ continue;
+ }
+
+
return srv->server;
}
}