Jelajahi Sumber

Update SMB server default settings

Toby Chui 1 Minggu lalu
induk
melakukan
335dd80a33

+ 15 - 10
src/mod/fileservers/servers/smbserv/smbserv.go

@@ -141,22 +141,26 @@ func (m *Manager) allowPublic() bool {
 	return allow
 }
 
-// requireEncryption refuses clients that cannot encrypt. Off by default:
-// encryption costs speed, and SMB 2.1 clients could no longer connect.
+// requireEncryption refuses clients that cannot encrypt. On by default, the
+// setting Windows 10 and 11 connect with out of the box; turning it off lets
+// SMB 2.1 clients in at the cost of sending files in the clear.
 func (m *Manager) requireEncryption() bool {
-	on := false
+	on := true
 	if m.opt.Sysdb.KeyExists(settingsTable, "encrypt") {
 		m.opt.Sysdb.Read(settingsTable, "encrypt", &on)
 	}
 	return on
 }
 
-// useTrash sends deletes to the trash bin. Off by default, as with Samba and
-// as Windows expects of a network drive, where Explorer warns that a delete
-// is permanent.
+// useTrash sends deletes to the trash bin. On by default, so a delete from
+// Explorer can be undone from the web desktop, even though Explorer warns
+// that a delete on a network drive is permanent.
 func (m *Manager) useTrash() bool {
-	on := false
-	if m.opt.Trash != nil && m.opt.Sysdb.KeyExists(settingsTable, "trash") {
+	if m.opt.Trash == nil {
+		return false
+	}
+	on := true
+	if m.opt.Sysdb.KeyExists(settingsTable, "trash") {
 		m.opt.Sysdb.Read(settingsTable, "trash", &on)
 	}
 	return on
@@ -522,9 +526,10 @@ func (m *Manager) HandleConfig(w http.ResponseWriter, r *http.Request) {
 		return
 	}
 	public := postOnly(r, "public") == "true"
-	encrypt := postOnly(r, "encrypt") == "true"
+	//A form without a field keeps that setting's default (on)
+	encrypt := postOnly(r, "encrypt") != "false"
 	discover := postOnly(r, "discover") != "false"
-	trash := postOnly(r, "trash") == "true"
+	trash := postOnly(r, "trash") != "false"
 	stageLimit := m.stageLimitMB()
 	if v := postOnly(r, "stagelimit"); v != "" {
 		stageLimit, err = strconv.ParseInt(v, 10, 64)

+ 17 - 5
src/mod/fileservers/servers/smbserv/smbserv_test.go

@@ -564,10 +564,15 @@ func TestEncryptionSetting(t *testing.T) {
 	if err := r.m.ServerToggle(true); err != nil {
 		t.Fatal(err)
 	}
-	if r.m.requireEncryption() {
-		t.Fatal("encryption must be optional by default")
+	if !r.m.requireEncryption() {
+		t.Fatal("encryption must be required by default")
 	}
 	var res ConfigResult
+	json.Unmarshal(post(r.m.HandleConfig, url.Values{"port": {strconv.Itoa(port)}, "encrypt": {"false"}}).Body.Bytes(), &res)
+	if r.m.requireEncryption() || !res.Restarted {
+		t.Errorf("encrypt = %v, restarted = %v", r.m.requireEncryption(), res.Restarted)
+	}
+	res = ConfigResult{}
 	json.Unmarshal(post(r.m.HandleConfig, url.Values{"port": {strconv.Itoa(port)}, "encrypt": {"true"}}).Body.Bytes(), &res)
 	if !r.m.requireEncryption() || !res.Restarted {
 		t.Errorf("encrypt = %v, restarted = %v", r.m.requireEncryption(), res.Restarted)
@@ -683,16 +688,23 @@ func TestDiscoveryUUIDIsStable(t *testing.T) {
 func TestTrashSetting(t *testing.T) {
 	r := newRig(t)
 	if r.m.useTrash() {
-		t.Fatal("deletes are permanent by default")
+		t.Fatal("without a trash bin deletes are permanent")
 	}
 	r.opt.Trash = func(*filesystem.FileSystemHandler, string, string, string) error { return nil }
+	if !r.m.useTrash() {
+		t.Fatal("deletes go to the trash bin by default")
+	}
+	isOK(t, post(r.m.HandleConfig, url.Values{"port": {"1445"}, "trash": {"false"}}))
+	if r.m.useTrash() {
+		t.Error("an unticked box turns it off")
+	}
 	isOK(t, post(r.m.HandleConfig, url.Values{"port": {"1445"}, "trash": {"true"}}))
 	if !r.m.useTrash() {
 		t.Error("the setting must stick")
 	}
 	isOK(t, post(r.m.HandleConfig, url.Values{"port": {"1445"}}))
-	if r.m.useTrash() {
-		t.Error("an unticked box turns it off")
+	if !r.m.useTrash() {
+		t.Error("a form without the field keeps the default")
 	}
 	r.opt.Trash = nil
 	r.opt.Sysdb.Write(settingsTable, "trash", true)

+ 4 - 3
src/mod/storage/SMB_PROPOSAL.md

@@ -571,7 +571,8 @@ How the Phase 5 parts behave:
   most); logoff, revoked access and an open needing the lease close them.
   `PreviousSessionId` drops a session the server had not noticed was dead.
 - **Encryption** is negotiated whenever the client offers it. With "require
-  encryption" on, clients without it are refused at login and plain requests
+  encryption" on (the default, which Windows 10 and 11 connect with out of
+  the box), clients without it are refused at login and plain requests
   on an encrypted session get `STATUS_ACCESS_DENIED`. CCM is written in
   `crypt/encrypt.go` and checked against NIST SP 800-38C and RFC 3610 vectors.
   Captures keep the decrypted messages.
@@ -618,8 +619,8 @@ Samba 1.5 to 1.7 GB/s.
   the icon) through zeroconf, which works beside mDNSResponder. Seen by
   `dns-sd -B`. Follows `-allow_mdns`. Both announcements share one admin
   switch, "Show this server on the network", on by default.
-- **Trash.** With "Deleted files go to the trash bin" on (off by default, as
-  with Samba and as Windows expects of a network drive), deleted files move
+- **Trash.** With "Deleted files go to the trash bin" on (the default, so a
+  delete from Explorer can be undone from the web desktop), deleted files move
   into the drive's `.trash` the way the File Manager does it, through one
   shared `system_fs_moveToTrash`. Only files go there: Explorer deletes a
   folder's content first, so files arrive one by one under their old folders,