Samba 创建掩码无法正常工作

Samba 创建掩码无法正常工作

我在 Linux 服务器(RHEL 6)上有一个 Samba 共享,可以通过 Windows 7 访问。

我将 samba 共享设置为创建掩码 0664,但当我从 Windows 7 计算机通过 samba 创建文件时,它会创建权限级别为 0674 的文件。如果我编辑文件,它也会将其权限更改为 0674。如果我删除共享的创建掩码并依赖默认创建掩码 0644,它会创建权限为 0774 的文件。我的 umask 是 0022。我尝试了手册中的许多设置,但似乎都没有奏效。有什么想法可以解决此问题吗?

理想情况下,新文件的权限级别为 0664,而现有文件将保持其权限级别。

作为参考,以下是输出testparm -v

[global]
    dos charset = CP850
    unix charset = UTF-8
    display charset = LOCALE
    workgroup = WORKGROUP
    realm =
    netbios name = SERVER
    netbios aliases =
    netbios scope =
    server string = Bart
    interfaces =
    bind interfaces only = No
    security = DOMAIN
    auth methods =
    encrypt passwords = Yes
    update encrypted = No
    client schannel = Auto
    server schannel = Auto
    allow trusted domains = Yes
    map to guest = Never
    null passwords = No
    obey pam restrictions = No
    password server = passwordserver.domain.com
    smb passwd file = /var/lib/samba/private/smbpasswd
    private dir = /var/lib/samba/private
    passdb backend = tdbsam
    algorithmic rid base = 1000
    root directory =
    guest account = nobody
    enable privileges = Yes
    pam password change = No
    passwd program =
    passwd chat = *new*password* %n\n *new*password* %n\n *changed*
    passwd chat debug = No
    passwd chat timeout = 2
    check password script =
    username map =
    password level = 0
    username level = 0
    unix password sync = No
    restrict anonymous = 0
    lanman auth = No
    ntlm auth = Yes
    client NTLMv2 auth = No
    client lanman auth = No
    client plaintext auth = No
    preload modules =
    dedicated keytab file =
    kerberos method = default
    map untrusted to domain = No
    log level = 0
    syslog = 1
    syslog only = No
    log file = /var/log/samba/log.%m
    max log size = 10240
    debug timestamp = Yes
    debug prefix timestamp = No
    debug hires timestamp = Yes
    debug pid = No
    debug uid = No
    debug class = No
    enable core files = Yes
    smb ports = 445 139
    large readwrite = Yes
    max protocol = NT1
    min protocol = CORE
    min receivefile size = 0
    read raw = Yes
    write raw = Yes
    disable netbios = No
    reset on zero vc = No
    acl compatibility = auto
    defer sharing violations = Yes
    nt pipe support = Yes
    nt status support = Yes
    announce version = 4.9
    announce as = NT
    max mux = 50
    max xmit = 16644
    name resolve order = lmhosts wins host bcast
    max ttl = 259200
    max wins ttl = 518400
    min wins ttl = 21600
    time server = No
    unix extensions = No
    use spnego = Yes
    client signing = auto
    server signing = No
    client use spnego = Yes
    client ldap sasl wrapping = plain
    enable asu support = No
    svcctl list =
    deadtime = 0
    getwd cache = Yes
    keepalive = 300
    lpq cache time = 30
    max smbd processes = 0
    paranoid server security = Yes
    max disk size = 0
    max open files = 16384
    socket options = TCP_NODELAY
    use mmap = Yes
    hostname lookups = No
    name cache timeout = 660
    ctdbd socket =
    cluster addresses =
    clustering = No
    ctdb timeout = 0
    load printers = No
    printcap cache time = 750
    printcap name =
    cups server =
    cups encrypt = No
    cups connection timeout = 30
    iprint server =
    disable spoolss = No
    addport command =
    enumports command =
    addprinter command =
    deleteprinter command =
    show add printer wizard = Yes
    os2 driver map =
    mangling method = hash2
    mangle prefix = 1
    max stat cache size = 256
    stat cache = Yes
    machine password timeout = 604800
    add user script =
    rename user script =
    delete user script =
    add group script =
    delete group script =
    add user to group script =
    delete user from group script =
    set primary group script =
    add machine script =
    shutdown script =
    abort shutdown script =
    username map script =
    logon script =
    logon path = \\%N\%U\profile
    logon drive =
    logon home = \\%N\%U
    domain logons = No
    init logon delayed hosts =
    init logon delay = 100
    os level = 20
    lm announce = Auto
    lm interval = 60
    preferred master = No
    local master = No
    domain master = Auto
    browse list = Yes
    enhanced browsing = Yes
    dns proxy = Yes
    wins proxy = No
    wins server =
    wins support = No
    wins hook =
    kernel oplocks = Yes
    lock spin time = 200
    oplock break wait time = 0
    ldap admin dn =
    ldap delete dn = No
    ldap group suffix =
    ldap idmap suffix =
    ldap machine suffix =
    ldap passwd sync = no
    ldap replication sleep = 1000
    ldap suffix =
    ldap ssl = start tls
    ldap ssl ads = No
    ldap deref = auto
    ldap follow referral = Auto
    ldap timeout = 15
    ldap connection timeout = 2
    ldap page size = 1024
    ldap user suffix =
    ldap debug level = 0
    ldap debug threshold = 10
    eventlog list =
    add share command =
    change share command =
    delete share command =
    preload =
    lock directory = /var/lib/samba
    state directory = /var/lib/samba
    cache directory = /var/lib/samba
    pid directory = /var/run
    utmp directory =
    wtmp directory =
    utmp = No
    default service =
    message command =
    get quota command =
    set quota command =
    remote announce =
    remote browse sync =
    socket address = 0.0.0.0
    nmbd bind explicit broadcast = Yes
    homedir map = auto.home
    afs username map =
    afs token lifetime = 604800
    log nt token command =
    time offset = 0
    NIS homedir = No
    registry shares = No
    usershare allow guests = No
    usershare max shares = 0
    usershare owner only = Yes
    usershare path = /var/lib/samba/usershares
    usershare prefix allow list =
    usershare prefix deny list =
    usershare template share =
    panic action =
    perfcount module =
    host msdfs = Yes
    passdb expand explicit = No
    idmap backend = tdb
    idmap alloc backend =
    idmap cache time = 604800
    idmap negative cache time = 120
    idmap uid =
    idmap gid =
    template homedir = /home/%D/%U
    template shell = /bin/false
    winbind separator = \
    winbind cache time = 300
    winbind reconnect delay = 30
    winbind max clients = 200
    winbind enum users = No
    winbind enum groups = No
    winbind use default domain = No
    winbind trusted domains only = No
    winbind nested groups = Yes
    winbind expand groups = 1
    winbind nss info = template
    winbind refresh tickets = No
    winbind offline logon = No
    winbind normalize names = No
    winbind rpc only = No
    create krb5 conf = Yes
    comment =
    path =
    username =
    invalid users =
    valid users =
    admin users =
    read list =
    write list =
    printer admin =
    force user =
    force group =
    read only = Yes
    acl check permissions = Yes
    acl group control = No
    acl map full control = Yes
    create mask = 0744
    force create mode = 00
    security mask = 0777
    force security mode = 00
    directory mask = 0755
    force directory mode = 00
    directory security mask = 0777
    force directory security mode = 00
    force unknown acl user = No
    inherit permissions = No
    inherit acls = No
    inherit owner = No
    guest only = No
    administrative share = No
    guest ok = No
    only user = No
    hosts allow =
    hosts deny =
    allocation roundup size = 1048576
    aio read size = 0
    aio write size = 0
    aio write behind =
    ea support = No
    nt acl support = Yes
    profile acls = No
    map acl inherit = No
    afs share = No
    smb encrypt = auto
    block size = 1024
    change notify = Yes
    directory name cache size = 100
    kernel change notify = Yes
    max connections = 0
    min print space = 0
    strict allocate = No
    strict sync = No
    sync always = No
    use sendfile = No
    write cache size = 0
    max reported print jobs = 0
    max print jobs = 1000
    printable = No
    printing = cups
    cups options = raw
    print command =
    lpq command = %p
    lprm command =
    lppause command =
    lpresume command =
    queuepause command =
    queueresume command =
    printer name =
    use client driver = No
    default devmode = Yes
    force printername = No
    printjob username = %U
    default case = lower
    case sensitive = Auto
    preserve case = Yes
    short preserve case = Yes
    mangling char = ~
    hide dot files = Yes
    hide special files = No
    hide unreadable = No
    hide unwriteable files = No
    delete veto files = No
    veto files =
    hide files =
    veto oplock files =
    map archive = Yes
    map hidden = No
    map system = No
    map readonly = yes
    mangled names = Yes
    store dos attributes = No
    dmapi support = No
    browseable = Yes
    access based share enum = No
    blocking locks = Yes
    csc policy = manual
    fake oplocks = No
    locking = Yes
    oplocks = Yes
    level2 oplocks = Yes
    oplock contention limit = 2
    posix locking = Yes
    strict locking = Auto
    share modes = Yes
    dfree cache time = 0
    dfree command =
    copy =
    preexec =
    preexec close = No
    postexec =
    root preexec =
    root preexec close = No
    root postexec =
    available = Yes
    volume =
    fstype = NTFS
    set directory = No
    wide links = No
    follow symlinks = Yes
    dont descend =
    magic script =
    magic output =
    delete readonly = No
    dos filemode = No
    dos filetimes = Yes
    dos filetime resolution = No
    fake directory create times = No
    vfs objects =
    msdfs root = No
    msdfs proxy =

[path]
    comment = path
    path = /path/
    valid users = usera, userb, userc
    read only = No
    create mask = 0664
    directory mask = 0775
    wide links = Yes

答案1

该问题通常是由启用以下任一功能引起的:

  • map archive(所有者使用 unix 执行位)
  • map system(对组使用 unix 执行位)
  • map hidden(其他使用 unix 执行位)
  • inherit permissions导致 samba 忽略create mask
  • 还有inherit acls默认为否的

“MS-DOS 和 Unix 上的文件权限和属性”第 8 章 高级磁盘共享很好地解释了上述内容。

但是,Microsoft Office 产品会导致奇怪的行为并触发错误/意外行为。即使设置了create maskand/orforce create mode并避免了上述映射或继承选项,我也看到在使用 Microsoft Office 应用程序编辑文档时设置了组执行权限。其他程序不会发生这种情况,例如使用记事本编辑 .txt 文件,权限保持正常。Office 不仅会创建文件,还会对临时文件、重命名和权限造成一些干扰。

经过大量的挖掘之后,它可能还与 Samba POSIX ACL 错误混淆了:

在 Linux 端观察到的行为

通过 Windows 资源管理器上下文菜单创建的空 Word docx 文件的扩展 ACL(尚未通过 Word 打开和保存)

$ getfacl test.docx 
# file: test.docx
# owner: tester
# group: tester
user::rw-
group::rw-
other::---

通过 MS word 2016 保存后

$ getfacl test.docx 
# file: test.docx
# owner: tester
# group: tester
user::rw-
user:tester:rw-
group::rw-
group:tester:rw-
mask::rwx

检查 Ubuntu 16.04 LTS 上的 samba 配置时,它似乎map archive默认启用,但应该使用所有者的执行位,而不是组执行位,所以这不是我的情况的原因

$ testparm -s -v 2>&1 | grep 'map archive'
map archive = Yes

在 Windows 端观察到的行为

使用 SysInternals 进程监视器并比较使用 notepad.exe 编辑 .txt 文件与使用 WINWORD.EXE 编辑 .docx 文件,办公套件做了很多花哨的操作,创建临时文件、重命名等。特别是,与 notepad.exe 不同,WINWORD.EXE 似乎会摆弄访问控制列表。如 procmon 所示

SetSecurityFile
Information:    Group, DACL

所以我怀疑这就是为什么 UNIX 组权限被 Microsoft Office 应用程序篡改的原因。

更深入的调查需要打开 Windows 文件对象安全审核才能查看到底发生了什么变化。事件 ID 4670 显示~WRD0000.tmp已应用的权限更改(我认为 Word 使用它来进行定期保存并在崩溃时进行恢复)。

Object:
    Object Server:    Security
    Object Type:    File
    Object Name:    C:\Users\<user>\Desktop\TestAudit\~WRD0000.tmp
    Handle ID:    0xfd0

Process:
    Process ID:    0x1ae4
    Process Name:    C:\Program Files\Microsoft Office\root\Office16\WINWORD.EXE

Permissions Change:
    Original Security Descriptor:
D:AI(A;ID;FA;;;SY)(A;ID;FA;;;BA)(A;ID;FA;;;S-1-5-<SID>-1001)
    New Security Descriptor:
D:(A;;0x1200a9;;;WD)(A;ID;FA;;;SY)(A;ID;FA;;;BA)(A;ID;FA;;;S-1-5-21-<SID>-1001)

SDDL(安全描述符定义语言)中的权限更改是 DACL(自由访问控制列表部分),其中似乎添加了额外的 ACE(访问控制条目)。ACE(A;;0x1200a9;;;WD)被添加到最前面。这是我的解释:

  • A;意思是允许访问,保持不变
  • ;没有继承
  • 0x1200a9;表示FILE_GENERIC_READ | FILE_EXECUTE读取和执行访问
  • WD指“所有人”受托人

然后,稍后,我在进程监视器中看到~WRD0000.tmp重命名为操作。因此,最终得到了 Word 出于某种原因所做的一些 ACE 更改。test.docxSetRenameInformationFiletest.docx

SysInternal 进程监视器输出

相关内容