From 1d08b9013a67184b0ecfe8b013926128719b68a6 Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Tue, 19 Apr 2005 19:23:49 +0000 Subject: r6392: - Fixes bug 2564: when smbc_opendir() was called with a file rather than a directory, the errno returned could end up as ENOENT rather than ENOTDIR. - Fixes some compiler warnings which showed up on IRIX, as reported by James Peach. (This used to be commit 615a62b21f8d2f7f97bde2f166ddd6849d39b95c) --- source3/libsmb/libsmbclient.c | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) (limited to 'source3/libsmb/libsmbclient.c') diff --git a/source3/libsmb/libsmbclient.c b/source3/libsmb/libsmbclient.c index 3e8e604ab1..791427f249 100644 --- a/source3/libsmb/libsmbclient.c +++ b/source3/libsmb/libsmbclient.c @@ -646,13 +646,10 @@ SMBCSRV *smbc_server(SMBCCTX *context, * Force use of port 139 for first try if share is $IPC, empty, or * null, so browse lists can work */ - if (share == NULL || *share == '\0' || strcmp(share, "IPC$") == 0) - { + if (share == NULL || *share == '\0' || strcmp(share, "IPC$") == 0) { port_try_first = 139; port_try_next = 445; - } - else - { + } else { port_try_first = 445; port_try_next = 139; } @@ -1905,6 +1902,8 @@ static SMBCFILE *smbc_opendir_ctx(SMBCCTX *context, const char *fname) fstring server, share, user, password, options; pstring workgroup; pstring path; + uint16 mode; + char *p; SMBCSRV *srv = NULL; SMBCFILE *dir = NULL; struct in_addr rem_ip; @@ -2197,6 +2196,7 @@ static SMBCFILE *smbc_opendir_ctx(SMBCCTX *context, const char *fname) /* Now, list the files ... */ + p = path + strlen(path); pstrcat(path, "\\*"); if (cli_list(&srv->cli, path, aDIR | aSYSTEM | aHIDDEN, dir_list_fn, @@ -2207,6 +2207,27 @@ static SMBCFILE *smbc_opendir_ctx(SMBCCTX *context, const char *fname) SAFE_FREE(dir); } errno = smbc_errno(context, &srv->cli); + + if (errno == EINVAL) { + /* + * See if they asked to opendir something + * other than a directory. If so, the + * converted error value we got would have + * been EINVAL rather than ENOTDIR. + */ + *p = '\0'; /* restore original path */ + + if (smbc_getatr(context, srv, path, + &mode, NULL, + NULL, NULL, NULL, + NULL) && + ! IS_DOS_DIR(mode)) { + + /* It is. Correct the error value */ + errno = ENOTDIR; + } + } + return NULL; } -- cgit