diff options
author | Richard Sharpe <sharpe@samba.org> | 2003-04-04 23:39:16 +0000 |
---|---|---|
committer | Richard Sharpe <sharpe@samba.org> | 2003-04-04 23:39:16 +0000 |
commit | a59565bf3803c09e41559b2424baf812a1f49d33 (patch) | |
tree | 2947980714031f33f36fdba359c3031d9b7d520b /source3/libsmb | |
parent | 8f19f822564cbf87359ed908292d0a5ae198fa25 (diff) | |
download | samba-a59565bf3803c09e41559b2424baf812a1f49d33.tar.gz samba-a59565bf3803c09e41559b2424baf812a1f49d33.tar.bz2 samba-a59565bf3803c09e41559b2424baf812a1f49d33.zip |
Some more good stuff from coolo.
(This used to be commit 41b320ffc560117c0184999e30cc69723f40acbe)
Diffstat (limited to 'source3/libsmb')
-rw-r--r-- | source3/libsmb/cliconnect.c | 71 | ||||
-rw-r--r-- | source3/libsmb/libsmbclient.c | 65 |
2 files changed, 94 insertions, 42 deletions
diff --git a/source3/libsmb/cliconnect.c b/source3/libsmb/cliconnect.c index 75dcd62c2f..4bfa694e63 100644 --- a/source3/libsmb/cliconnect.c +++ b/source3/libsmb/cliconnect.c @@ -1384,3 +1384,74 @@ NTSTATUS cli_raw_tcon(struct cli_state *cli, return NT_STATUS_OK; } + +/* Return a cli_state pointing at the IPC$ share for the given server */ + +struct cli_state *get_ipc_connect(char *server, struct in_addr *server_ip, + struct user_auth_info *user_info) +{ + struct cli_state *cli; + pstring myname; + NTSTATUS nt_status; + + get_myname(myname); + + nt_status = cli_full_connection(&cli, myname, server, server_ip, 0, "IPC$", "IPC", + user_info->username, lp_workgroup(), user_info->password, + CLI_FULL_CONNECTION_ANNONYMOUS_FALLBACK, NULL); + + if (NT_STATUS_IS_OK(nt_status)) { + return cli; + } else if (is_ipaddress(server)) { + /* windows 9* needs a correct NMB name for connections */ + fstring remote_name; + + if (name_status_find("*", 0, 0, *server_ip, remote_name)) { + cli = get_ipc_connect(remote_name, server_ip, user_info); + if (cli) + return cli; + } + } + return NULL; +} + +/* Return the IP address and workgroup of a master browser on the + network. */ + +struct cli_state *get_ipc_connect_master_ip_bcast(pstring workgroup, struct user_auth_info *user_info) +{ + struct in_addr *ip_list; + struct cli_state *cli; + int i, count; + struct in_addr server_ip; + + /* Go looking for workgroups by broadcasting on the local network */ + + if (!name_resolve_bcast(MSBROWSE, 1, &ip_list, &count)) { + return False; + } + + for (i = 0; i < count; i++) { + static fstring name; + + if (!name_status_find("*", 0, 0x1d, ip_list[i], name)) + continue; + + if (!find_master_ip(name, &server_ip)) + continue; + + pstrcpy(workgroup, name); + + DEBUG(4, ("found master browser %s, %s\n", + name, inet_ntoa(ip_list[i]))); + + cli = get_ipc_connect(inet_ntoa(server_ip), &server_ip, user_info); + + if (!cli) + continue; + + return cli; + } + + return NULL; +} diff --git a/source3/libsmb/libsmbclient.c b/source3/libsmb/libsmbclient.c index acbde95b91..c04736d8f5 100644 --- a/source3/libsmb/libsmbclient.c +++ b/source3/libsmb/libsmbclient.c @@ -1476,43 +1476,6 @@ dir_list_fn(file_info *finfo, const char *mask, void *state) } - -/* Return the IP address and workgroup of a master browser on the - network. */ - -static BOOL find_master_ip_bcast(pstring workgroup, struct in_addr *server_ip) -{ - struct in_addr *ip_list; - int i, count; - - /* Go looking for workgroups by broadcasting on the local network */ - - if (!name_resolve_bcast(MSBROWSE, 1, &ip_list, &count)) { - return False; - } - - for (i = count-1; i < count; i++) { - static fstring name; - - DEBUG(0, ("name_status_find %d %s\n", i, inet_ntoa(ip_list[i]))); - - if (!name_status_find("*", 0, 0x1d, ip_list[i], name)) - continue; - - if (!find_master_ip(name, server_ip)) - continue; - - pstrcpy(workgroup, name); - - DEBUG(4, ("found master browser %s, %s\n", - name, inet_ntoa(ip_list[i]))); - - return True; - } - - return False; -} - static SMBCFILE *smbc_opendir_ctx(SMBCCTX *context, const char *fname) { fstring server, share, user, password; @@ -1568,9 +1531,8 @@ static SMBCFILE *smbc_opendir_ctx(SMBCCTX *context, const char *fname) if (server[0] == (char)0) { struct in_addr server_ip; - DEBUG(4, ("empty server\n")); if (share[0] != (char)0 || path[0] != (char)0) { - DEBUG(4,("share %d path %d\n", share[0], path[0])); + errno = EINVAL; if (dir) { SAFE_FREE(dir->fname); @@ -1585,22 +1547,41 @@ static SMBCFILE *smbc_opendir_ctx(SMBCCTX *context, const char *fname) pstrcpy(workgroup, lp_workgroup()); - if (!find_master_ip(lp_workgroup(), &server_ip)) { + if (!find_master_ip(workgroup, &server_ip)) { + struct user_auth_info u_info; + struct cli_state *cli; + DEBUG(4, ("Unable to find master browser for workgroup %s\n", workgroup)); - if (!find_master_ip_bcast(workgroup, &server_ip)) { + + /* find the name of the server ... */ + pstrcpy(u_info.username, user); + pstrcpy(u_info.password, password); + + if (!(cli = get_ipc_connect_master_ip_bcast(workgroup, &u_info))) { DEBUG(4, ("Unable to find master browser by " "broadcast\n")); errno = ENOENT; return NULL; } + + fstrcpy(server, cli->desthost); + + cli_shutdown(cli); + } else { + if (!name_status_find("*", 0, 0, server_ip, server)) { + errno = ENOENT; + return NULL; + } } + DEBUG(4, ("using workgroup %s %s\n", workgroup, server)); + /* * Get a connection to IPC$ on the server if we do not already have one */ - srv = smbc_server(context, inet_ntoa(server_ip), "IPC$", workgroup, user, password); + srv = smbc_server(context, server, "IPC$", workgroup, user, password); if (!srv) { |