From patchwork Sun Sep 11 21:55:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Atte_Heikkil=C3=A4?= X-Patchwork-Id: 12973081 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3BC88C6FA83 for ; Sun, 11 Sep 2022 21:56:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229643AbiIKVz7 (ORCPT ); Sun, 11 Sep 2022 17:55:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229597AbiIKVz6 (ORCPT ); Sun, 11 Sep 2022 17:55:58 -0400 Received: from mail-lf1-x12e.google.com (mail-lf1-x12e.google.com [IPv6:2a00:1450:4864:20::12e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B7A0F1FCF9 for ; Sun, 11 Sep 2022 14:55:56 -0700 (PDT) Received: by mail-lf1-x12e.google.com with SMTP id m15so11890891lfl.9 for ; Sun, 11 Sep 2022 14:55:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date; bh=hmxaQKzWXZTH4O4yYMco1W+/GxhI7KdZ7o/7OyTkUc0=; b=OmtuAsjwAN7/8mMD1phw0o96TsLtJZ/STHqYUsh7ehMpXW1LesxG8zRdbqrEIaMmYI GCma80hLu0SxDMVIGsDZ0CtchVsJCPwTjnkyRqwJQYQaj+IQ5z9ARQbDHEv3GU8FKlk8 E3Kosv9o12IFCowzxCi6p2jIFNl0rU7Y835Jxid4azbhwcZ+xieb8OYowO/6Z+OVqBOb TM49+mlnNjEKG0adTZGuIrzY84o0WkPFS5QbVpp/oNQ99aE8APU054yV85KYXS/w2jdI JdeZMG/MEmHSw59yRY5diEdjRnR/NPgg+lIbf305LRlZQvSRiXMbGQKD/hjY2tixT0QN iHJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date; bh=hmxaQKzWXZTH4O4yYMco1W+/GxhI7KdZ7o/7OyTkUc0=; b=A3G55urSyrZddbQHC8Oj95drEj+gxJTezK16Wug+pDSbEKcwAptpBltM7ytNpQH0Iq CIjf4ORC5mWNYvMnna+mnna+pZjmn/lI0DlGJyjzzPJaXtg6wjDqjnwvBjhTfMKlsC/6 oeHLfV3McVnClPCHLiZundXUycb6j2H1eSynxl/Ql9cac/q+wfYAWIl1S/s00RZ905C5 uleEYqpK8GZNQ6XAP1hKQqBmR9R451U3yDM3GzMHayREXFSjbmhbYV+AjPvSQT7Of5Sm zmmquqZ82x+LJV323Wb/UbESVlu73rkDnIHrmlBm39Zayh4B44XrFaK9GbvzqXaALUxf 5IAw== X-Gm-Message-State: ACgBeo0dBvvL0mLrQLlGbCxG6/2IdYObwah9kjZ7jAJBLxYiphBERSt7 NTyOuClsFdN/eQ2T1OaCH2svoRZaTIk= X-Google-Smtp-Source: AA6agR7nxge/BOCO3QWV+XP6qqhTCO0lixE9cU15VBwQxu1NsCFmP1iQWDF1zBcW7P7MWMTScRNmXA== X-Received: by 2002:a05:6512:3e1e:b0:499:34:e8a7 with SMTP id i30-20020a0565123e1e00b004990034e8a7mr3851856lfv.655.1662933355057; Sun, 11 Sep 2022 14:55:55 -0700 (PDT) Received: from pohjola.lan (mobile-user-2e84bc-66.dhcp.inet.fi. [46.132.188.66]) by smtp.gmail.com with ESMTPSA id b14-20020a05651c032e00b0026ac7cd51afsm789904ljp.57.2022.09.11.14.55.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Sep 2022 14:55:54 -0700 (PDT) From: =?utf-8?q?Atte_Heikkil=C3=A4?= To: linux-cifs@vger.kernel.org Cc: =?utf-8?q?Atte_Heikkil=C3=A4?= Subject: [PATCH v2 1/2] ksmbd: casefold utf-8 share names and fix ascii lowercase conversion Date: Mon, 12 Sep 2022 00:55:41 +0300 Message-Id: <20220911215542.104935-1-atteh.mailbox@gmail.com> X-Mailer: git-send-email 2.37.3 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org strtolower() corrupts all UTF-8 share names that have a byte in the C0 (À ISO8859-1) to DE (Þ ISO8859-1) range, since the non-ASCII part of ISO8859-1 is incompatible with UTF-8. Prevent this by checking that a byte is in the ASCII range with isascii(), before the conversion to lowercase with tolower(). Properly handle case-insensitivity of UTF-8 share names by casefolding them, but fallback to ASCII lowercase conversion on failure or if CONFIG_UNICODE is not set. Refactor to move the share name casefolding immediately after the share name extraction. Also, make the associated constness corrections. Signed-off-by: Atte Heikkilä Acked-by: Namjae Jeon --- v2: - added missing kfree() to -E2BIG error path of casefold_sharename() fs/ksmbd/connection.c | 8 ++++++ fs/ksmbd/connection.h | 1 + fs/ksmbd/mgmt/share_config.c | 18 +++----------- fs/ksmbd/mgmt/share_config.h | 2 +- fs/ksmbd/mgmt/tree_connect.c | 2 +- fs/ksmbd/mgmt/tree_connect.h | 2 +- fs/ksmbd/misc.c | 47 ++++++++++++++++++++++++++++++------ fs/ksmbd/misc.h | 2 +- fs/ksmbd/smb2pdu.c | 2 +- fs/ksmbd/unicode.h | 3 ++- 10 files changed, 59 insertions(+), 28 deletions(-) diff --git a/fs/ksmbd/connection.c b/fs/ksmbd/connection.c index 756ad631c019..12be8386446a 100644 --- a/fs/ksmbd/connection.c +++ b/fs/ksmbd/connection.c @@ -60,6 +60,12 @@ struct ksmbd_conn *ksmbd_conn_alloc(void) conn->local_nls = load_nls("utf8"); if (!conn->local_nls) conn->local_nls = load_nls_default(); + if (IS_ENABLED(CONFIG_UNICODE)) + conn->um = utf8_load(UNICODE_AGE(12, 1, 0)); + else + conn->um = ERR_PTR(-EOPNOTSUPP); + if (IS_ERR(conn->um)) + conn->um = NULL; atomic_set(&conn->req_running, 0); atomic_set(&conn->r_count, 0); conn->total_credits = 1; @@ -350,6 +356,8 @@ int ksmbd_conn_handler_loop(void *p) wait_event(conn->r_count_q, atomic_read(&conn->r_count) == 0); + if (IS_ENABLED(CONFIG_UNICODE)) + utf8_unload(conn->um); unload_nls(conn->local_nls); if (default_conn_ops.terminate_fn) default_conn_ops.terminate_fn(conn); diff --git a/fs/ksmbd/connection.h b/fs/ksmbd/connection.h index e7f7d5707951..41d96f5cef06 100644 --- a/fs/ksmbd/connection.h +++ b/fs/ksmbd/connection.h @@ -46,6 +46,7 @@ struct ksmbd_conn { char *request_buf; struct ksmbd_transport *transport; struct nls_table *local_nls; + struct unicode_map *um; struct list_head conns_list; /* smb session 1 per user */ struct xarray sessions; diff --git a/fs/ksmbd/mgmt/share_config.c b/fs/ksmbd/mgmt/share_config.c index c9bca1c2c834..5d039704c23c 100644 --- a/fs/ksmbd/mgmt/share_config.c +++ b/fs/ksmbd/mgmt/share_config.c @@ -26,7 +26,7 @@ struct ksmbd_veto_pattern { struct list_head list; }; -static unsigned int share_name_hash(char *name) +static unsigned int share_name_hash(const char *name) { return jhash(name, strlen(name), 0); } @@ -72,7 +72,7 @@ __get_share_config(struct ksmbd_share_config *share) return share; } -static struct ksmbd_share_config *__share_lookup(char *name) +static struct ksmbd_share_config *__share_lookup(const char *name) { struct ksmbd_share_config *share; unsigned int key = share_name_hash(name); @@ -119,7 +119,7 @@ static int parse_veto_list(struct ksmbd_share_config *share, return 0; } -static struct ksmbd_share_config *share_config_request(char *name) +static struct ksmbd_share_config *share_config_request(const char *name) { struct ksmbd_share_config_response *resp; struct ksmbd_share_config *share = NULL; @@ -190,20 +190,10 @@ static struct ksmbd_share_config *share_config_request(char *name) return share; } -static void strtolower(char *share_name) -{ - while (*share_name) { - *share_name = tolower(*share_name); - share_name++; - } -} - -struct ksmbd_share_config *ksmbd_share_config_get(char *name) +struct ksmbd_share_config *ksmbd_share_config_get(const char *name) { struct ksmbd_share_config *share; - strtolower(name); - down_read(&shares_table_lock); share = __share_lookup(name); if (share) diff --git a/fs/ksmbd/mgmt/share_config.h b/fs/ksmbd/mgmt/share_config.h index 902f2cb1963a..7f7e89ecfe61 100644 --- a/fs/ksmbd/mgmt/share_config.h +++ b/fs/ksmbd/mgmt/share_config.h @@ -74,7 +74,7 @@ static inline void ksmbd_share_config_put(struct ksmbd_share_config *share) __ksmbd_share_config_put(share); } -struct ksmbd_share_config *ksmbd_share_config_get(char *name); +struct ksmbd_share_config *ksmbd_share_config_get(const char *name); bool ksmbd_share_veto_filename(struct ksmbd_share_config *share, const char *filename); #endif /* __SHARE_CONFIG_MANAGEMENT_H__ */ diff --git a/fs/ksmbd/mgmt/tree_connect.c b/fs/ksmbd/mgmt/tree_connect.c index 97ab7987df6e..867c0286b901 100644 --- a/fs/ksmbd/mgmt/tree_connect.c +++ b/fs/ksmbd/mgmt/tree_connect.c @@ -17,7 +17,7 @@ struct ksmbd_tree_conn_status ksmbd_tree_conn_connect(struct ksmbd_conn *conn, struct ksmbd_session *sess, - char *share_name) + const char *share_name) { struct ksmbd_tree_conn_status status = {-ENOENT, NULL}; struct ksmbd_tree_connect_response *resp = NULL; diff --git a/fs/ksmbd/mgmt/tree_connect.h b/fs/ksmbd/mgmt/tree_connect.h index 71e50271dccf..0f97ddc1e39c 100644 --- a/fs/ksmbd/mgmt/tree_connect.h +++ b/fs/ksmbd/mgmt/tree_connect.h @@ -42,7 +42,7 @@ struct ksmbd_session; struct ksmbd_tree_conn_status ksmbd_tree_conn_connect(struct ksmbd_conn *conn, struct ksmbd_session *sess, - char *share_name); + const char *share_name); int ksmbd_tree_conn_disconnect(struct ksmbd_session *sess, struct ksmbd_tree_connect *tree_conn); diff --git a/fs/ksmbd/misc.c b/fs/ksmbd/misc.c index df991107ad2c..6473cdcf8e33 100644 --- a/fs/ksmbd/misc.c +++ b/fs/ksmbd/misc.c @@ -7,6 +7,7 @@ #include #include #include +#include #include "misc.h" #include "smb_common.h" @@ -226,26 +227,56 @@ void ksmbd_conv_path_to_windows(char *path) strreplace(path, '/', '\\'); } +static char *casefold_sharename(struct unicode_map *um, const char *name) +{ + char *cf_name; + int cf_len; + + cf_name = kzalloc(KSMBD_REQ_MAX_SHARE_NAME, GFP_KERNEL); + if (!cf_name) + return ERR_PTR(-ENOMEM); + + if (IS_ENABLED(CONFIG_UNICODE)) { + const struct qstr q_name = {.name = name, .len = strlen(name)}; + + if (!um) + goto out_ascii; + + cf_len = utf8_casefold(um, &q_name, cf_name, + KSMBD_REQ_MAX_SHARE_NAME); + if (cf_len < 0) + goto out_ascii; + + return cf_name; + } + +out_ascii: + cf_len = strscpy(cf_name, name, KSMBD_REQ_MAX_SHARE_NAME); + if (cf_len < 0) { + kfree(cf_name); + return ERR_PTR(-E2BIG); + } + + for (; *cf_name; ++cf_name) + *cf_name = isascii(*cf_name) ? tolower(*cf_name) : *cf_name; + return cf_name - cf_len; +} + /** * ksmbd_extract_sharename() - get share name from tree connect request * @treename: buffer containing tree name and share name * * Return: share name on success, otherwise error */ -char *ksmbd_extract_sharename(char *treename) +char *ksmbd_extract_sharename(struct unicode_map *um, const char *treename) { - char *name = treename; - char *dst; - char *pos = strrchr(name, '\\'); + const char *name = treename, *pos = strrchr(name, '\\'); if (pos) name = (pos + 1); /* caller has to free the memory */ - dst = kstrdup(name, GFP_KERNEL); - if (!dst) - return ERR_PTR(-ENOMEM); - return dst; + return casefold_sharename(um, name); } /** diff --git a/fs/ksmbd/misc.h b/fs/ksmbd/misc.h index aae2a252945f..fbb7db560a28 100644 --- a/fs/ksmbd/misc.h +++ b/fs/ksmbd/misc.h @@ -20,7 +20,7 @@ int get_nlink(struct kstat *st); void ksmbd_conv_path_to_unix(char *path); void ksmbd_strip_last_slash(char *path); void ksmbd_conv_path_to_windows(char *path); -char *ksmbd_extract_sharename(char *treename); +char *ksmbd_extract_sharename(struct unicode_map *um, const char *treename); char *convert_to_unix_name(struct ksmbd_share_config *share, const char *name); #define KSMBD_DIR_INFO_ALIGNMENT 8 diff --git a/fs/ksmbd/smb2pdu.c b/fs/ksmbd/smb2pdu.c index 19412ac701a6..62a8da520810 100644 --- a/fs/ksmbd/smb2pdu.c +++ b/fs/ksmbd/smb2pdu.c @@ -1883,7 +1883,7 @@ int smb2_tree_connect(struct ksmbd_work *work) goto out_err1; } - name = ksmbd_extract_sharename(treename); + name = ksmbd_extract_sharename(conn->um, treename); if (IS_ERR(name)) { status.ret = KSMBD_TREE_CONN_STATUS_ERROR; goto out_err1; diff --git a/fs/ksmbd/unicode.h b/fs/ksmbd/unicode.h index 5593024230ae..076f6034a789 100644 --- a/fs/ksmbd/unicode.h +++ b/fs/ksmbd/unicode.h @@ -24,6 +24,7 @@ #include #include #include +#include #define UNIUPR_NOLOWER /* Example to not expand lower case tables */ @@ -69,7 +70,7 @@ char *smb_strndup_from_utf16(const char *src, const int maxlen, const struct nls_table *codepage); int smbConvertToUTF16(__le16 *target, const char *source, int srclen, const struct nls_table *cp, int mapchars); -char *ksmbd_extract_sharename(char *treename); +char *ksmbd_extract_sharename(struct unicode_map *um, const char *treename); #endif /* From patchwork Sun Sep 11 21:55:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Atte_Heikkil=C3=A4?= X-Patchwork-Id: 12973082 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EF343C6FA86 for ; Sun, 11 Sep 2022 21:56:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229597AbiIKV4B (ORCPT ); Sun, 11 Sep 2022 17:56:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42700 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229498AbiIKV4A (ORCPT ); Sun, 11 Sep 2022 17:56:00 -0400 Received: from mail-lf1-x136.google.com (mail-lf1-x136.google.com [IPv6:2a00:1450:4864:20::136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A94451FCF9 for ; Sun, 11 Sep 2022 14:55:58 -0700 (PDT) Received: by mail-lf1-x136.google.com with SMTP id z25so11938867lfr.2 for ; Sun, 11 Sep 2022 14:55:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=u3ULhUZQNj/3EvXCA6Ax4jhCcnMt8WPOe6AavfYb3rI=; b=oCc8I679JoJDDMoFEywqhxNiVkwoyccZi6dijw9ZJIxR72RWAJCPMeA956Zkn1tYvv 7IFTQEpKoqATK8BLcK4jEJ77ENIoxP+9cdeW1qQQRaHJRuxS31yOAKZSRbO/30oy4zeg lPukq9HKlVqxWrxCc/4y8q499sXpvgQ2gKzmPTDef5xH8HWhjYFJiqOpsKn8FLHP/0Vq lJTpzbn2f8gsI5dKe8kTbusFnywTNMCKd7fQ4KDfe1/6Wsety2+HXxl8nBjV/CajeLEM h/PYpRLqPTfvYtT/vGw/yyNsqIemKIMUrB1ocDJHZ2ghZddlwWcU4vVBNFYZoU6yJN/X UgOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=u3ULhUZQNj/3EvXCA6Ax4jhCcnMt8WPOe6AavfYb3rI=; b=Eun3a3j4e8S7cqp6aYJs5BJPKTZHvQPT7FPwwMbU6oSNy6xhUS2sV4PASkoLvnvYyP wFOeDdjPvVwSyHklbBzAv7Y9544l+CWvjWGbua7REAnE3/+0HAlAyr8opF2e+uSksvOe zCwBKYco1yLN0i4GApGmCRVTllSwlZhw9lKNL2LPCA5iSmda1vPCA6QD0UyWFDnxATt0 Gk5d6Z4atYMPTGp5GmUiCd3ZEnYzT9wSxre1D1UUxAIHS7+xxPAuOkqI3WAhGLY2TSHD ROg1oRoG8DOzqhiGqswljry3AxOOW0ONP/9R+v/sDxDnMPASAygjI/ICbcQAsZiQiXSy lKhw== X-Gm-Message-State: ACgBeo2c4+2cMiRC5UrgwDLcTmlipmu7iaz0D2LM50br7bVbsFhCArMy iqoAXT1ntoasCsJjhHlPi/Vigd/H8ew= X-Google-Smtp-Source: AA6agR6kvof6pKiB9qJ7ycK65ocE9fE5JlUtJCn6hb/NRCmXOVuxnDUd70U6LN7f5OBR7enLMHj4Mw== X-Received: by 2002:ac2:4f03:0:b0:495:ec98:bcac with SMTP id k3-20020ac24f03000000b00495ec98bcacmr7637562lfr.339.1662933357007; Sun, 11 Sep 2022 14:55:57 -0700 (PDT) Received: from pohjola.lan (mobile-user-2e84bc-66.dhcp.inet.fi. [46.132.188.66]) by smtp.gmail.com with ESMTPSA id b14-20020a05651c032e00b0026ac7cd51afsm789904ljp.57.2022.09.11.14.55.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Sep 2022 14:55:56 -0700 (PDT) From: =?utf-8?q?Atte_Heikkil=C3=A4?= To: linux-cifs@vger.kernel.org Cc: =?utf-8?q?Atte_Heikkil=C3=A4?= Subject: [PATCH v2 2/2] ksmbd-tools: casefold utf-8 share names Date: Mon, 12 Sep 2022 00:55:42 +0300 Message-Id: <20220911215542.104935-2-atteh.mailbox@gmail.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220911215542.104935-1-atteh.mailbox@gmail.com> References: <20220911215542.104935-1-atteh.mailbox@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org Match kernel space behavior regarding case-insensitivity of UTF-8 share names by first NFD(I) normalizing and then casefolding them. Fallback to ASCII lowercase conversion on failure. Signed-off-by: Atte Heikkilä --- addshare/addshare.c | 6 +++--- include/management/share.h | 1 + lib/config_parser.c | 2 +- lib/management/share.c | 19 +++++++++++++++++++ mountd/rpc_srvsvc.c | 2 +- 5 files changed, 25 insertions(+), 5 deletions(-) diff --git a/addshare/addshare.c b/addshare/addshare.c index f5894c9..be4c67d 100644 --- a/addshare/addshare.c +++ b/addshare/addshare.c @@ -123,17 +123,17 @@ int main(int argc, char *argv[]) switch (c) { case 'a': g_free(share); - share = g_ascii_strdown(optarg, strlen(optarg)); + share = shm_casefold_share_name(optarg, strlen(optarg)); command = command_add_share; break; case 'd': g_free(share); - share = g_ascii_strdown(optarg, strlen(optarg)); + share = shm_casefold_share_name(optarg, strlen(optarg)); command = command_del_share; break; case 'u': g_free(share); - share = g_ascii_strdown(optarg, strlen(optarg)); + share = shm_casefold_share_name(optarg, strlen(optarg)); command = command_update_share; break; case 'o': diff --git a/include/management/share.h b/include/management/share.h index 306cca5..bb3952c 100644 --- a/include/management/share.h +++ b/include/management/share.h @@ -141,6 +141,7 @@ static inline int test_share_flag(struct ksmbd_share *share, int flag) struct ksmbd_share *get_ksmbd_share(struct ksmbd_share *share); void put_ksmbd_share(struct ksmbd_share *share); +char *shm_casefold_share_name(char *name, size_t len); struct ksmbd_share *shm_lookup_share(char *name); struct smbconf_group; diff --git a/lib/config_parser.c b/lib/config_parser.c index 2dbc0c7..a1dc85c 100644 --- a/lib/config_parser.c +++ b/lib/config_parser.c @@ -93,7 +93,7 @@ static int add_new_group(char *line) while (*end && *end != ']') end = g_utf8_find_next_char(end, NULL); - name = g_ascii_strdown(begin + 1, end - begin - 1); + name = shm_casefold_share_name(begin + 1, end - begin - 1); if (!name) goto out_free; diff --git a/lib/management/share.c b/lib/management/share.c index 22e6a83..fc09ea8 100644 --- a/lib/management/share.c +++ b/lib/management/share.c @@ -236,6 +236,25 @@ int shm_init(void) return 0; } +char *shm_casefold_share_name(char *name, size_t len) +{ + char *nfdi_name, *nfdicf_name; + + nfdi_name = g_utf8_normalize(name, len, G_NORMALIZE_NFD); + if (!nfdi_name) + goto out_ascii; + + nfdicf_name = g_utf8_casefold(nfdi_name, strlen(nfdi_name)); + if (!nfdicf_name) + goto out_ascii; + + g_free(nfdi_name); + return nfdicf_name; +out_ascii: + g_free(nfdi_name); + return g_ascii_strdown(name, len); +} + static struct ksmbd_share *__shm_lookup_share(char *name) { return g_hash_table_lookup(shares_table, name); diff --git a/mountd/rpc_srvsvc.c b/mountd/rpc_srvsvc.c index 38b984b..8716c34 100644 --- a/mountd/rpc_srvsvc.c +++ b/mountd/rpc_srvsvc.c @@ -171,7 +171,7 @@ static int srvsvc_share_get_info_invoke(struct ksmbd_rpc_pipe *pipe, int ret; gchar *share_name; - share_name = g_ascii_strdown(STR_VAL(hdr->share_name), + share_name = shm_casefold_share_name(STR_VAL(hdr->share_name), strlen(STR_VAL(hdr->share_name))); share = shm_lookup_share(share_name); if (!share)