summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source3/smbwrapper/smbw.c57
-rw-r--r--source3/smbwrapper/smbw.h10
2 files changed, 56 insertions, 11 deletions
diff --git a/source3/smbwrapper/smbw.c b/source3/smbwrapper/smbw.c
index 5532e687ce..362f7b4964 100644
--- a/source3/smbwrapper/smbw.c
+++ b/source3/smbwrapper/smbw.c
@@ -390,6 +390,34 @@ int smbw_errno(struct cli_state *c)
return ret;
}
+/* Return a username and password given a server and share name */
+
+void get_envvar_auth_data(char *server, char *share, char **workgroup,
+ char **username, char **password)
+{
+ /* Fall back to shared memory/environment variables */
+
+ *username = smbw_getshared("USER");
+ if (!*username) *username = getenv("USER");
+ if (!*username) *username = "guest";
+
+ *workgroup = smbw_getshared("WORKGROUP");
+ if (!*workgroup) *workgroup = lp_workgroup();
+
+ *password = smbw_getshared("PASSWORD");
+ if (!*password) *password = "";
+}
+
+static smbw_get_auth_data_fn get_auth_data_fn = get_envvar_auth_data;
+
+/*****************************************************
+set the get auth data function
+******************************************************/
+void smbw_set_auth_data_fn(smbw_get_auth_data_fn fn)
+{
+ get_auth_data_fn = fn;
+}
+
/*****************************************************
return a connection to a server (existing or new)
*******************************************************/
@@ -410,20 +438,13 @@ struct smbw_server *smbw_server(char *server, char *share)
ip = ipzero;
ZERO_STRUCT(c);
- username = smbw_getshared("USER");
- if (!username) username = getenv("USER");
- if (!username) username = "guest";
-
- workgroup = smbw_getshared("WORKGROUP");
- if (!workgroup) workgroup = lp_workgroup();
-
- password = smbw_getshared("PASSWORD");
- if (!password) password = "";
-
/* try to use an existing connection */
for (srv=smbw_srvs;srv;srv=srv->next) {
if (strcmp(server,srv->server_name)==0 &&
- strcmp(share,srv->share_name)==0) return srv;
+ strcmp(share,srv->share_name)==0 &&
+ strcmp(workgroup,srv->workgroup)==0 &&
+ strcmp(username, srv->username) == 0)
+ return srv;
}
if (server[0] == 0) {
@@ -434,6 +455,8 @@ struct smbw_server *smbw_server(char *server, char *share)
make_nmb_name(&calling, global_myname, 0x0);
make_nmb_name(&called , server, 0x20);
+ get_auth_data_fn(server, share, &workgroup, &username, &password);
+
DEBUG(4,("server_n=[%s] server=[%s]\n", server_n, server));
if ((p=strchr(server_n,'#')) && strcmp(p+1,"1D")==0) {
@@ -539,6 +562,18 @@ struct smbw_server *smbw_server(char *server, char *share)
goto failed;
}
+ srv->workgroup = strdup(workgroup);
+ if (!srv->workgroup) {
+ errno = ENOMEM;
+ goto failed;
+ }
+
+ srv->username = strdup(username);
+ if (!srv->username) {
+ errno = ENOMEM;
+ goto failed;
+ }
+
/* some programs play with file descriptors fairly intimately. We
try to get out of the way by duping to a high fd number */
if (fcntl(SMBW_CLI_FD + srv->cli.fd, F_GETFD) && errno == EBADF) {
diff --git a/source3/smbwrapper/smbw.h b/source3/smbwrapper/smbw.h
index 7241f8b3c5..d059b20c78 100644
--- a/source3/smbwrapper/smbw.h
+++ b/source3/smbwrapper/smbw.h
@@ -19,6 +19,9 @@
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
+#ifndef _SMBW_H
+#define _SMBW_H
+
#define SMBW_PREFIX "/smb/"
#define SMBW_DUMMY "/dev/null"
@@ -33,6 +36,8 @@ struct smbw_server {
struct cli_state cli;
char *server_name;
char *share_name;
+ char *workgroup;
+ char *username;
dev_t dev;
BOOL no_pathinfo2;
};
@@ -60,3 +65,8 @@ struct smbw_dir {
char *path;
};
+typedef void (*smbw_get_auth_data_fn)(char *server, char *share,
+ char **workgroup, char **username,
+ char **password);
+
+#endif /* _SMBW_H */