这可能特定于https://github.com/atmoz/sftp/blob/master/entrypoint#L36
进行的参数解析但是我正在尝试创建一个带有空格的目录:
我尝试过的一些例子:
docker run -d atmoz/sftp:alpine-3.7 user:password:::Inbound - Test Dir
...
[entrypoint] Parsing user data: "user:password:::Inbound"
Creating mailbox file: No such file or directory
[entrypoint] Creating directory: /home/user/Inbound
[entrypoint] Parsing user data: "-"
[entrypoint] ERROR: Invalid username "-", do not match required regex pattern: [A-Za-z0-9._][A-Za-z0-9._-]{0,31}
docker run -d atmoz/sftp:alpine-3.7 user:password:::"Inbound - Test Dir"
...
[entrypoint] Creating directory: /home/user/Inbound
[entrypoint] Creating directory: /home/user/-
[entrypoint] Creating directory: /home/user/Test
[entrypoint] Creating directory: /home/user/Dir
docker run -d atmoz/sftp:alpine-3.7 "user:password:::Inbound - Test Dir"
...
[entrypoint] Creating directory: /home/user/Inbound
[entrypoint] Creating directory: /home/user/-
[entrypoint] Creating directory: /home/user/Test
[entrypoint] Creating directory: /home/user/Dir
docker run -d atmoz/sftp:alpine-3.7 user:password:::Inbound\ -\ Test\ Dir
...
[entrypoint] Creating directory: /home/user/Inbound
[entrypoint] Creating directory: /home/user/-
[entrypoint] Creating directory: /home/user/Test
[entrypoint] Creating directory: /home/user/Dir
docker run -d atmoz/sftp:alpine-3.7 user:password:::'Inbound - Test Dir'
...
[entrypoint] Creating directory: /home/user/Inbound
[entrypoint] Creating directory: /home/user/-
[entrypoint] Creating directory: /home/user/Test
[entrypoint] Creating directory: /home/user/Dir
答案 0 :(得分:3)
在我看来,这是createUser
函数中的错误,因为缺少包含目录名称的各种变量的双引号。无法通过在参数中添加转义符,引号等来解决此问题。您确实必须修复导致问题的脚本。
我还没有测试过,但是可以在第98-111行中适当地添加双引号来做到这一点:
# Make sure dirs exists
if [ -n "$dir" ]; then
IFS=',' read -a dirArgs <<< "$dir" # Quotes added here
for dirPath in "${dirArgs[@]}"; do # And here
dirPath="/home/$user/$dirPath"
if [ ! -d "$dirPath" ]; then
log "Creating directory: $dirPath"
mkdir -p "$dirPath" # And here
chown -R $uid:users "$dirPath" # And here
else
log "Directory already exists: $dirPath"
fi
done
fi
脚本中可能还有其他地方导致了此问题,但至少需要进行上述更改。另外,我添加引号的第一行仅在某些版本的bash上需要使用引号,但是最好以防万一。
p.s。第39行可能也应该修复:
IFS=':' read -a args <<< "$1"
当前版本使用$@
,这很奇怪。该函数只会传递一个参数,并且某些bash版本会误认为如果不加引号,那么使用我的版本是一种更好的方法。
shellcheck.net指出了一堆其他可疑的东西,但这是我认为应该解决的唯一另一件事。
答案 1 :(得分:0)
此问题已在基于以下线程的最新版本中得到修复:https://github.com/atmoz/sftp/issues/143