--- source/libsmb/libsmbclient.c 2005-03-24 13:55:42.227190952 -0800 +++ source-new/libsmb/libsmbclient.c 2005-03-24 13:54:59.395702328 -0800 @@ -541,6 +541,8 @@ SMBCSRV *smbc_server(SMBCCTX *context, pstring ipenv; struct in_addr ip; int tried_reverse = 0; + BOOL anon_logon = False; + fstring cache_user; zero_ip(&ip); ZERO_STRUCT(c); @@ -647,13 +649,15 @@ SMBCSRV *smbc_server(SMBCCTX *context, if (!cli_session_setup(&c, username, password, strlen(password), password, strlen(password), - workgroup) && - /* try an anonymous login if it failed */ - !cli_session_setup(&c, "", "", 1,"", 0, workgroup)) { - cli_shutdown(&c); - errno = EPERM; - return NULL; - } + workgroup)) { + anon_logon = True; + /* try an anonymous login if it failed */ + if(!cli_session_setup(&c, "", "", 1,"", 0, workgroup)) { + cli_shutdown(&c); + errno = EPERM; + return NULL; + } + } DEBUG(4,(" session setup ok\n")); @@ -684,7 +688,14 @@ SMBCSRV *smbc_server(SMBCCTX *context, /* now add it to the cache (internal or external) */ /* Let the cache function set errno if it wants to */ errno = 0; - if (context->callbacks.add_cached_srv_fn(context, srv, server, share, workgroup, username)) { + + if (anon_logon) { + fstrcpy(cache_user, ""); + } else { + fstrcpy(cache_user, username); + } + + if (context->callbacks.add_cached_srv_fn(context, srv, server, share, workgroup, cache_user)) { int saved_errno = errno; DEBUG(3, (" Failed to add server to cache\n")); errno = saved_errno;