From 3fe974c4feed33187294a0cb922c20f7dbfeaf43 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Fri, 16 Jan 2009 12:26:46 -0800 Subject: Fix a segfault if ? is there but the options are NULL. This is the case if SMBC_parse_path is called by SMBC_stat_ctx. --- source3/libsmb/libsmb_path.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/libsmb') diff --git a/source3/libsmb/libsmb_path.c b/source3/libsmb/libsmb_path.c index 2c3a5f8866..b0970d46db 100644 --- a/source3/libsmb/libsmb_path.c +++ b/source3/libsmb/libsmb_path.c @@ -286,7 +286,7 @@ SMBC_parse_path(TALLOC_CTX *ctx, DEBUG(4, ("Found options '%s'", q)); /* Copy the options */ - if (*pp_options != NULL) { + if (pp_options && *pp_options != NULL) { TALLOC_FREE(*pp_options); *pp_options = talloc_strdup(ctx, q); } -- cgit From 1c77c7f3d5b6cb29fac4606299c237c0e299f836 Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Fri, 16 Jan 2009 16:41:36 -0500 Subject: Treat file names in POSIX-like case-sensitive fashion by default *** THIS COMMIT CAUSES A CHANGE OF DEFAULT BEHAVIOR IN libsmbclient!!! *** - libsmbclient now calls cli_set_case_sensitive() for a new CLI. By default, it requests case-sensitive, but the old behavior of case-insensitive can be requested with smbc_setOptionCaseSensitive(context, False); The change of behavior is considered a bug fix, as it was previously possible to accidentally overwrite a file that had the same case-insensitive name but a different case-sensitive name as a previously-existing file, while creating a new file. Derrell --- source3/libsmb/libsmb_context.c | 1 + source3/libsmb/libsmb_server.c | 7 +++++++ source3/libsmb/libsmb_setget.c | 14 ++++++++++++++ 3 files changed, 22 insertions(+) (limited to 'source3/libsmb') diff --git a/source3/libsmb/libsmb_context.c b/source3/libsmb/libsmb_context.c index 66329e2860..ca8ceedbc2 100644 --- a/source3/libsmb/libsmb_context.c +++ b/source3/libsmb/libsmb_context.c @@ -69,6 +69,7 @@ smbc_new_context(void) smbc_setOptionFullTimeNames(context, False); smbc_setOptionOpenShareMode(context, SMBC_SHAREMODE_DENY_NONE); smbc_setOptionSmbEncryptionLevel(context, SMBC_ENCRYPTLEVEL_NONE); + smbc_setOptionCaseSensitive(context, True); smbc_setOptionBrowseMaxLmbCount(context, 3); /* # LMBs to query */ smbc_setOptionUrlEncodeReaddirEntries(context, False); smbc_setOptionOneSharePerServer(context, False); diff --git a/source3/libsmb/libsmb_server.c b/source3/libsmb/libsmb_server.c index f4714346d1..e2cc07118b 100644 --- a/source3/libsmb/libsmb_server.c +++ b/source3/libsmb/libsmb_server.c @@ -356,6 +356,13 @@ again: return NULL; } + /* POSIX-like - always request case-sensitivity by default. */ + if (smbc_getOptionCaseSensitive(context)) { + cli_set_case_sensitive(c, True); + } else { + cli_set_case_sensitive(c, False); + } + if (smbc_getOptionUseKerberos(context)) { c->use_kerberos = True; } diff --git a/source3/libsmb/libsmb_setget.c b/source3/libsmb/libsmb_setget.c index d0823bd77e..bca2a80d14 100644 --- a/source3/libsmb/libsmb_setget.c +++ b/source3/libsmb/libsmb_setget.c @@ -193,6 +193,20 @@ smbc_setOptionSmbEncryptionLevel(SMBCCTX *c, smbc_smb_encrypt_level level) c->internal->smb_encryption_level = level; } +/** Get whether to treat file names as case-sensitive. */ +smbc_bool +smbc_getOptionCaseSensitive(SMBCCTX *c) +{ + return c->internal->case_sensitive; +} + +/** Set whether to treat file names as case-sensitive. */ +void +smbc_setOptionCaseSensitive(SMBCCTX *c, smbc_bool b) +{ + c->internal->case_sensitive = b; +} + /** * Get from how many local master browsers should the list of workgroups be * retrieved. It can take up to 12 minutes or longer after a server becomes a -- cgit From c6b4f3526a262b22d5a97a3152f378778a497a26 Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Fri, 16 Jan 2009 20:26:46 -0500 Subject: [Bug 6022] smbc_urlencode and smbc_urldecode were not exported - Since the revamp of libsmbclient, there has still been an external declaration for smbc_urlencode and smbc_urldecode in libsmbclient.h, yet those functions were renamed and made private. The two choices were to remove the function names from libsmbclient.h or to make them public again. The reported requested that they be public. This commit makes it so. Derrell --- source3/libsmb/libsmb_dir.c | 2 +- source3/libsmb/libsmb_path.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'source3/libsmb') diff --git a/source3/libsmb/libsmb_dir.c b/source3/libsmb/libsmb_dir.c index 770014b6f6..e9b7b4f95a 100644 --- a/source3/libsmb/libsmb_dir.c +++ b/source3/libsmb/libsmb_dir.c @@ -895,7 +895,7 @@ smbc_readdir_internal(SMBCCTX * context, /* url-encode the name. get back remaining buffer space */ max_namebuf_len = - SMBC_urlencode(dest->name, src->name, max_namebuf_len); + smbc_urlencode(dest->name, src->name, max_namebuf_len); /* We now know the name length */ dest->namelen = strlen(dest->name); diff --git a/source3/libsmb/libsmb_path.c b/source3/libsmb/libsmb_path.c index b0970d46db..6d69924231 100644 --- a/source3/libsmb/libsmb_path.c +++ b/source3/libsmb/libsmb_path.c @@ -41,7 +41,7 @@ hex2int( unsigned int _char ) } /* - * SMBC_urldecode() + * smbc_urldecode() * and urldecode_talloc() (internal fn.) * * Convert strings of %xx to their single character equivalent. Each 'x' must @@ -122,7 +122,7 @@ urldecode_talloc(TALLOC_CTX *ctx, char **pp_dest, const char *src) } int -SMBC_urldecode(char *dest, +smbc_urldecode(char *dest, char *src, size_t max_dest_len) { @@ -138,7 +138,7 @@ SMBC_urldecode(char *dest, } /* - * SMBC_urlencode() + * smbc_urlencode() * * Convert any characters not specifically allowed in a URL into their %xx * equivalent. @@ -146,7 +146,7 @@ SMBC_urldecode(char *dest, * Returns the remaining buffer length. */ int -SMBC_urlencode(char *dest, +smbc_urlencode(char *dest, char *src, int max_dest_len) { -- cgit From 6d300399b52e0921ce205ef2f053b722b21edeeb Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Sat, 17 Jan 2009 13:33:25 -0500 Subject: Determine case sensitivity based on file system attributes. - Most of the time, we can determine from the file system we're connecting to whether it supports case sensitivity. In those cases, we now set the internal case sensitivity flag automatically. For those cases where the request to retrieve file system attributes fails, we'll use the user-specified option value. Derrell --- source3/libsmb/libsmb_context.c | 2 +- source3/libsmb/libsmb_server.c | 71 ++++++++++++++++++++++++++++++++++++----- source3/libsmb/libsmb_setget.c | 16 ++++++++-- 3 files changed, 78 insertions(+), 11 deletions(-) (limited to 'source3/libsmb') diff --git a/source3/libsmb/libsmb_context.c b/source3/libsmb/libsmb_context.c index ca8ceedbc2..c2c33e5302 100644 --- a/source3/libsmb/libsmb_context.c +++ b/source3/libsmb/libsmb_context.c @@ -69,7 +69,7 @@ smbc_new_context(void) smbc_setOptionFullTimeNames(context, False); smbc_setOptionOpenShareMode(context, SMBC_SHAREMODE_DENY_NONE); smbc_setOptionSmbEncryptionLevel(context, SMBC_ENCRYPTLEVEL_NONE); - smbc_setOptionCaseSensitive(context, True); + smbc_setOptionCaseSensitive(context, False); smbc_setOptionBrowseMaxLmbCount(context, 3); /* # LMBs to query */ smbc_setOptionUrlEncodeReaddirEntries(context, False); smbc_setOptionOneSharePerServer(context, False); diff --git a/source3/libsmb/libsmb_server.c b/source3/libsmb/libsmb_server.c index e2cc07118b..0ece5bb649 100644 --- a/source3/libsmb/libsmb_server.c +++ b/source3/libsmb/libsmb_server.c @@ -245,6 +245,8 @@ SMBC_server(TALLOC_CTX *ctx, int tried_reverse = 0; int port_try_first; int port_try_next; + int is_ipc = (share != NULL && strcmp(share, "IPC$") == 0); + uint32 fs_attrs = 0; const char *username_used; NTSTATUS status; @@ -310,6 +312,38 @@ SMBC_server(TALLOC_CTX *ctx, srv = NULL; } + /* Determine if this share supports case sensitivity */ + if (is_ipc) { + DEBUG(4, + ("IPC$ so ignore case sensitivity\n")); + } else if (!cli_get_fs_attr_info(c, &fs_attrs)) { + DEBUG(4, ("Could not retrieve " + "case sensitivity flag: %s.\n", + cli_errstr(c))); + + /* + * We can't determine the case sensitivity of + * the share. We have no choice but to use the + * user-specified case sensitivity setting. + */ + if (smbc_getOptionCaseSensitive(context)) { + cli_set_case_sensitive(c, True); + } else { + cli_set_case_sensitive(c, False); + } + } else { + DEBUG(4, + ("Case sensitive: %s\n", + (fs_attrs & FILE_CASE_SENSITIVE_SEARCH + ? "True" + : "False"))); + cli_set_case_sensitive( + c, + (fs_attrs & FILE_CASE_SENSITIVE_SEARCH + ? True + : False)); + } + /* * Regenerate the dev value since it's based on both * server and share @@ -356,13 +390,6 @@ again: return NULL; } - /* POSIX-like - always request case-sensitivity by default. */ - if (smbc_getOptionCaseSensitive(context)) { - cli_set_case_sensitive(c, True); - } else { - cli_set_case_sensitive(c, False); - } - if (smbc_getOptionUseKerberos(context)) { c->use_kerberos = True; } @@ -377,7 +404,7 @@ again: * 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' || is_ipc) { port_try_first = 139; port_try_next = 445; } else { @@ -483,6 +510,34 @@ again: DEBUG(4,(" tconx ok\n")); + /* Determine if this share supports case sensitivity */ + if (is_ipc) { + DEBUG(4, ("IPC$ so ignore case sensitivity\n")); + } else if (!cli_get_fs_attr_info(c, &fs_attrs)) { + DEBUG(4, ("Could not retrieve case sensitivity flag: %s.\n", + cli_errstr(c))); + + /* + * We can't determine the case sensitivity of the share. We + * have no choice but to use the user-specified case + * sensitivity setting. + */ + if (smbc_getOptionCaseSensitive(context)) { + cli_set_case_sensitive(c, True); + } else { + cli_set_case_sensitive(c, False); + } + } else { + DEBUG(4, ("Case sensitive: %s\n", + (fs_attrs & FILE_CASE_SENSITIVE_SEARCH + ? "True" + : "False"))); + cli_set_case_sensitive(c, + (fs_attrs & FILE_CASE_SENSITIVE_SEARCH + ? True + : False)); + } + if (context->internal->smb_encryption_level) { /* Attempt UNIX smb encryption. */ if (!NT_STATUS_IS_OK(cli_force_encryption(c, diff --git a/source3/libsmb/libsmb_setget.c b/source3/libsmb/libsmb_setget.c index bca2a80d14..9de49a5b3f 100644 --- a/source3/libsmb/libsmb_setget.c +++ b/source3/libsmb/libsmb_setget.c @@ -193,14 +193,26 @@ smbc_setOptionSmbEncryptionLevel(SMBCCTX *c, smbc_smb_encrypt_level level) c->internal->smb_encryption_level = level; } -/** Get whether to treat file names as case-sensitive. */ +/** + * Get whether to treat file names as case-sensitive if we can't determine + * when connecting to the remote share whether the file system is case + * sensitive. This defaults to FALSE since it's most likely that if we can't + * retrieve the file system attributes, it's a very old file system that does + * not support case sensitivity. + */ smbc_bool smbc_getOptionCaseSensitive(SMBCCTX *c) { return c->internal->case_sensitive; } -/** Set whether to treat file names as case-sensitive. */ +/** + * Set whether to treat file names as case-sensitive if we can't determine + * when connecting to the remote share whether the file system is case + * sensitive. This defaults to FALSE since it's most likely that if we can't + * retrieve the file system attributes, it's a very old file system that does + * not support case sensitivity. + */ void smbc_setOptionCaseSensitive(SMBCCTX *c, smbc_bool b) { -- cgit