summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Potter <tpot@samba.org>2000-11-01 04:31:19 +0000
committerTim Potter <tpot@samba.org>2000-11-01 04:31:19 +0000
commitae7911e4d85755085e5413b2de53155e19ac4a1a (patch)
tree272e0d621f84ed21b1bde94f6f0ca28eb69dddeb
parent71daef8167136de05922e3215850da7bb7d94548 (diff)
downloadsamba-ae7911e4d85755085e5413b2de53155e19ac4a1a.tar.gz
samba-ae7911e4d85755085e5413b2de53155e19ac4a1a.tar.bz2
samba-ae7911e4d85755085e5413b2de53155e19ac4a1a.zip
Added a authentication hook to smbwrapper which allows a (username,
workgroup, password) tuple to be provided by another function. (This used to be commit 644c78d64a6d7b7e44414c579de660321a0a6b34)
-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 */