From 59b944ebff964c73f8b57443f6799cb0065c7dcc Mon Sep 17 00:00:00 2001 From: Ilia Ross Date: Wed, 11 Oct 2023 16:46:26 +0300 Subject: [PATCH 1/2] Fix to properly test unicode names --- samba/samba-lib.pl | 11 +++++++++++ samba/save_fshare.cgi | 2 +- samba/save_pshare.cgi | 2 +- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/samba/samba-lib.pl b/samba/samba-lib.pl index 873f392a8..c24472318 100755 --- a/samba/samba-lib.pl +++ b/samba/samba-lib.pl @@ -209,6 +209,17 @@ else { } } +# decode_unicode_string(string) +# Decodes a string from UTF-8 if needed +sub decode_unicode_string +{ +my ($str) = @_; +eval "use Encode"; +if ($@) { + return $str; + } +return decode('utf8', $str); +} # list_connections([share]) # Uses the smbstatus program to return a list of connections a share. Each diff --git a/samba/save_fshare.cgi b/samba/save_fshare.cgi index 108b1e537..73d5f347e 100755 --- a/samba/save_fshare.cgi +++ b/samba/save_fshare.cgi @@ -57,7 +57,7 @@ if ($name ne "global") { elsif ($in{'old_name'} ne $name && $exists{$name}) { &error(&text('savefshare_exist', $name)); } - elsif ($name !~ /^[A-Za-z0-9_\$\-\. ]+$/) { + elsif (&decode_unicode_string($name) !~ /^[\p{L}\p{N}_\$\-\.\s]+$/) { &error(&text('savefshare_mode', $name)); } elsif ($name eq "global") { # unreachable code ? EB diff --git a/samba/save_pshare.cgi b/samba/save_pshare.cgi index cca754dab..c7e8c438a 100755 --- a/samba/save_pshare.cgi +++ b/samba/save_pshare.cgi @@ -59,7 +59,7 @@ if ($name ne "global") { elsif ($in{'old_name'} ne $name && $exists{$name}) { &error(&text('savepshare_exist', $name)); } - elsif ($name !~ /^[\p{L}\p{N}_\$\-\.\s]+$/) { + elsif (&decode_unicode_string($name) !~ /^[\p{L}\p{N}_\$\-\.\s]+$/) { &error(&text('savepshare_name', $name)); } elsif ($name eq "global") { From 0457c1d1c01b2406a25a4f20fb49451e95b079a1 Mon Sep 17 00:00:00 2001 From: Ilia Ross Date: Wed, 11 Oct 2023 16:46:44 +0300 Subject: [PATCH 2/2] Fix not to double encode on modify --- samba/samba-lib.pl | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/samba/samba-lib.pl b/samba/samba-lib.pl index c24472318..bafd03b8b 100755 --- a/samba/samba-lib.pl +++ b/samba/samba-lib.pl @@ -119,8 +119,7 @@ for($i=0; $i<@conf; $i++) { elsif ($1 eq $_[0]) { &print_tempfile(CONF, "[$_[1]]\n"); foreach $k (grep {!/share_name/} (keys %share)) { - &print_tempfile(CONF, "\t$k = ", - &to_utf8($share{$k}),"\n"); + &print_tempfile(CONF, "\t$k = ", $share{$k},"\n"); } #&print_tempfile(CONF, "\n"); $replacing = 1; @@ -131,8 +130,7 @@ for($i=0; $i<@conf; $i++) { $first = 1; &print_tempfile(CONF, "[$_[1]]\n"); foreach $k (grep {!/share_name/} (keys %share)) { - &print_tempfile(CONF, "\t$k = ", - &to_utf8($share{$k}),"\n"); + &print_tempfile(CONF, "\t$k = ", $share{$k},"\n"); } &print_tempfile(CONF, "\n"); $replacing = 1;