Merge pull request #2025 from webmin/dev/samba-support-utf8-names

Fix support for unicode names in Samba
This commit is contained in:
Jamie Cameron
2023-10-11 11:31:50 -07:00
committed by GitHub
3 changed files with 15 additions and 6 deletions

View File

@@ -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;
@@ -209,6 +207,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

View File

@@ -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

View File

@@ -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") {