mirror of
https://github.com/samba-team/samba.git
synced 2024-12-24 21:34:56 +03:00
Added a authentication hook to smbwrapper which allows a (username,
workgroup, password) tuple to be provided by another function.
(This used to be commit 644c78d64a
)
This commit is contained in:
parent
71daef8167
commit
ae7911e4d8
@ -390,6 +390,34 @@ int smbw_errno(struct cli_state *c)
|
|||||||
return ret;
|
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)
|
return a connection to a server (existing or new)
|
||||||
*******************************************************/
|
*******************************************************/
|
||||||
@ -410,20 +438,13 @@ struct smbw_server *smbw_server(char *server, char *share)
|
|||||||
ip = ipzero;
|
ip = ipzero;
|
||||||
ZERO_STRUCT(c);
|
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 */
|
/* try to use an existing connection */
|
||||||
for (srv=smbw_srvs;srv;srv=srv->next) {
|
for (srv=smbw_srvs;srv;srv=srv->next) {
|
||||||
if (strcmp(server,srv->server_name)==0 &&
|
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) {
|
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(&calling, global_myname, 0x0);
|
||||||
make_nmb_name(&called , server, 0x20);
|
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));
|
DEBUG(4,("server_n=[%s] server=[%s]\n", server_n, server));
|
||||||
|
|
||||||
if ((p=strchr(server_n,'#')) && strcmp(p+1,"1D")==0) {
|
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;
|
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
|
/* some programs play with file descriptors fairly intimately. We
|
||||||
try to get out of the way by duping to a high fd number */
|
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) {
|
if (fcntl(SMBW_CLI_FD + srv->cli.fd, F_GETFD) && errno == EBADF) {
|
||||||
|
@ -19,6 +19,9 @@
|
|||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifndef _SMBW_H
|
||||||
|
#define _SMBW_H
|
||||||
|
|
||||||
#define SMBW_PREFIX "/smb/"
|
#define SMBW_PREFIX "/smb/"
|
||||||
#define SMBW_DUMMY "/dev/null"
|
#define SMBW_DUMMY "/dev/null"
|
||||||
|
|
||||||
@ -33,6 +36,8 @@ struct smbw_server {
|
|||||||
struct cli_state cli;
|
struct cli_state cli;
|
||||||
char *server_name;
|
char *server_name;
|
||||||
char *share_name;
|
char *share_name;
|
||||||
|
char *workgroup;
|
||||||
|
char *username;
|
||||||
dev_t dev;
|
dev_t dev;
|
||||||
BOOL no_pathinfo2;
|
BOOL no_pathinfo2;
|
||||||
};
|
};
|
||||||
@ -60,3 +65,8 @@ struct smbw_dir {
|
|||||||
char *path;
|
char *path;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef void (*smbw_get_auth_data_fn)(char *server, char *share,
|
||||||
|
char **workgroup, char **username,
|
||||||
|
char **password);
|
||||||
|
|
||||||
|
#endif /* _SMBW_H */
|
||||||
|
Loading…
Reference in New Issue
Block a user