summaryrefslogtreecommitdiff
path: root/source3/libsmb
diff options
context:
space:
mode:
authorDerrell Lipman <derrell@samba.org>2005-12-25 21:46:58 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 11:05:58 -0500
commit44db82065acf46f3c35ac754974c983e168e3975 (patch)
tree08b1673bc58fc7722c18cf5fb5351322f98df33a /source3/libsmb
parentbd08ae25dccff147547cda7575e2171abeb2195f (diff)
downloadsamba-44db82065acf46f3c35ac754974c983e168e3975.tar.gz
samba-44db82065acf46f3c35ac754974c983e168e3975.tar.bz2
samba-44db82065acf46f3c35ac754974c983e168e3975.zip
r12485: r12044@cabra: derrell | 2005-12-25 16:46:47 -0500
When enumerating what could be a server name or a workgroup name, first check for an existing server structure. If none exists, then go through the previous determination of whether it's a serrver or a workgroup. This should avoid doing a NetBIOS name query each time, if we've already connected to the specified server. (While we're at it, clean up indenting and line length in this area of code.) (This used to be commit 85e4cab1d949f1ab9ce04b96de0b8d1c8113df67)
Diffstat (limited to 'source3/libsmb')
-rw-r--r--source3/libsmb/libsmbclient.c160
1 files changed, 87 insertions, 73 deletions
diff --git a/source3/libsmb/libsmbclient.c b/source3/libsmb/libsmbclient.c
index d2d45a7228..b81dd88424 100644
--- a/source3/libsmb/libsmbclient.c
+++ b/source3/libsmb/libsmbclient.c
@@ -2509,10 +2509,10 @@ static SMBCFILE *smbc_opendir_ctx(SMBCCTX *context, const char *fname)
* Server not an empty string ... Check the rest and see what
* gives
*/
- if (share[0] == (char)0) {
-
- if (path[0] != (char)0) { /* Should not have empty share with path */
+ if (*share == '\0') {
+ if (*path != '\0') {
+ /* Should not have empty share with path */
errno = EINVAL + 8197;
if (dir) {
SAFE_FREE(dir->fname);
@@ -2522,12 +2522,28 @@ static SMBCFILE *smbc_opendir_ctx(SMBCCTX *context, const char *fname)
}
- /* Check to see if <server><1D>, <server><1B>, or <server><20> translates */
- /* However, we check to see if <server> is an IP address first */
+ /*
+ * We don't know if <server> is really a server name
+ * or is a workgroup/domain name. If we already have
+ * a server structure for it, we'll use it.
+ * Otherwise, check to see if <server><1D>,
+ * <server><1B>, or <server><20> translates. We check
+ * to see if <server> is an IP address first.
+ */
+
+ /* See if we have an existing server */
+ srv = smbc_server(context, server, "IPC$",
+ workgroup, user, password);
+
+ /*
+ * If no existing server and not an IP addr, look for
+ * LMB or DMB
+ */
+ if (!srv &&
+ !is_ipaddress(server) &&
+ (resolve_name(server, &rem_ip, 0x1d) || /* LMB */
+ resolve_name(server, &rem_ip, 0x1b) )) { /* DMB */
- if (!is_ipaddress(server) && /* Not an IP addr so check next */
- (resolve_name(server, &rem_ip, 0x1d) || /* Found LMB */
- resolve_name(server, &rem_ip, 0x1b) )) { /* Found DMB */
fstring buserver;
dir->dir_type = SMBC_SERVER;
@@ -2535,22 +2551,23 @@ static SMBCFILE *smbc_opendir_ctx(SMBCCTX *context, const char *fname)
/*
* Get the backup list ...
*/
+ if (!name_status_find(server, 0, 0,
+ rem_ip, buserver)) {
-
- if (!name_status_find(server, 0, 0, rem_ip, buserver)) {
-
- DEBUG(0, ("Could not get name of local/domain master browser for server %s\n", server));
- errno = EPERM; /* FIXME, is this correct */
+ DEBUG(0, ("Could not get name of "
+ "local/domain master browser "
+ "for server %s\n", server));
+ errno = EPERM;
return NULL;
}
/*
- * Get a connection to IPC$ on the server if we do not already have one
- */
-
- srv = smbc_server(context, buserver, "IPC$", workgroup, user, password);
-
+ * Get a connection to IPC$ on the server if
+ * we do not already have one
+ */
+ srv = smbc_server(context, buserver, "IPC$",
+ workgroup, user, password);
if (!srv) {
DEBUG(0, ("got no contact to IPC$\n"));
if (dir) {
@@ -2564,8 +2581,8 @@ static SMBCFILE *smbc_opendir_ctx(SMBCCTX *context, const char *fname)
dir->srv = srv;
/* Now, list the servers ... */
-
- if (!cli_NetServerEnum(&srv->cli, server, 0x0000FFFE, list_fn,
+ if (!cli_NetServerEnum(&srv->cli, server,
+ 0x0000FFFE, list_fn,
(void *)dir)) {
if (dir) {
@@ -2573,75 +2590,72 @@ static SMBCFILE *smbc_opendir_ctx(SMBCCTX *context, const char *fname)
SAFE_FREE(dir);
}
return NULL;
-
}
- }
- else {
-
- if (resolve_name(server, &rem_ip, 0x20)) {
-
- /* Now, list the shares ... */
-
- dir->dir_type = SMBC_FILE_SHARE;
-
- srv = smbc_server(context, server, "IPC$", workgroup, user, password);
-
- if (!srv) {
+ } else if (srv ||
+ (resolve_name(server, &rem_ip, 0x20))) {
+
+ /* If we hadn't found the server, get one now */
+ if (!srv) {
+ srv = smbc_server(context, server,
+ "IPC$", workgroup,
+ user, password);
+ }
- if (dir) {
- SAFE_FREE(dir->fname);
- SAFE_FREE(dir);
- }
- return NULL;
+ if (!srv) {
+ if (dir) {
+ SAFE_FREE(dir->fname);
+ SAFE_FREE(dir);
+ }
+ return NULL;
- }
+ }
- dir->srv = srv;
+ dir->dir_type = SMBC_FILE_SHARE;
+ dir->srv = srv;
- /* Now, list the servers ... */
+ /* List the shares ... */
- if (net_share_enum_rpc(
- &srv->cli,
- list_fn,
- (void *) dir) < 0 &&
- cli_RNetShareEnum(
- &srv->cli,
- list_fn,
- (void *)dir) < 0) {
+ if (net_share_enum_rpc(
+ &srv->cli,
+ list_fn,
+ (void *) dir) < 0 &&
+ cli_RNetShareEnum(
+ &srv->cli,
+ list_fn,
+ (void *)dir) < 0) {
- errno = cli_errno(&srv->cli);
- if (dir) {
- SAFE_FREE(dir->fname);
- SAFE_FREE(dir);
- }
- return NULL;
-
- }
-
- }
- else {
-
- errno = ECONNREFUSED; /* Neither the workgroup nor server exists */
- if (dir) {
- SAFE_FREE(dir->fname);
- SAFE_FREE(dir);
- }
- return NULL;
-
- }
+ errno = cli_errno(&srv->cli);
+ if (dir) {
+ SAFE_FREE(dir->fname);
+ SAFE_FREE(dir);
+ }
+ return NULL;
+ }
+ } else {
+ /* Neither the workgroup nor server exists */
+ errno = ECONNREFUSED;
+ if (dir) {
+ SAFE_FREE(dir->fname);
+ SAFE_FREE(dir);
+ }
+ return NULL;
}
}
- else { /* The server and share are specified ... work from there ... */
+ else {
+ /*
+ * The server and share are specified ... work from
+ * there ...
+ */
pstring targetpath;
struct cli_state *targetcli;
- /* Well, we connect to the server and list the directory */
-
+ /* We connect to the server and list the directory */
dir->dir_type = SMBC_FILE_SHARE;
- srv = smbc_server(context, server, share, workgroup, user, password);
+ srv = smbc_server(context, server, share,
+ workgroup, user, password);
if (!srv) {