Sanitize label in samba.lua

Prevent labels from having .., /, *, control characters, or quotes (this
generally messes things up) and limit them to a reasonable length. We
might possibly also want to do this in snmp.lua, I'm not sure if that
will break things though
This commit is contained in:
Kan18 2022-12-28 18:23:02 +04:00
parent f7ba900930
commit 8fbcc7b8bc
1 changed files with 7 additions and 3 deletions

View File

@ -59,6 +59,10 @@ local function sambaConnection(socket)
print('samba: Connection closed')
end
local function sanitizeLabel(computer)
return (computer.id.."_"..computer.label:gsub("[%c%.\"'/%*]", "")):sub(64)
end
Event.addRoutine(function()
print('samba: listening on port 139')
@ -79,10 +83,10 @@ Event.addRoutine(function()
end)
Event.on('network_attach', function(_, computer)
fs.mount(fs.combine('network', computer.label), 'netfs', computer.id)
fs.mount(fs.combine('network', sanitizeLabel(computer)), 'netfs', computer.id)
end)
Event.on('network_detach', function(_, computer)
print('samba: detaching ' .. computer.label)
fs.unmount(fs.combine('network', computer.label))
print('samba: detaching ' .. sanitizeLabel(computer))
fs.unmount(fs.combine('network', sanitizeLabel(computer)))
end)