Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Samba doesn't work : permission denied when using smbpasswd #3937

Closed
unpWn4bl3 opened this issue Mar 24, 2019 · 10 comments
Closed

Samba doesn't work : permission denied when using smbpasswd #3937

unpWn4bl3 opened this issue Mar 24, 2019 · 10 comments

Comments

@unpWn4bl3
Copy link

unpWn4bl3 commented Mar 24, 2019

  • Your Windows build number: (Type ver at a Windows Command Prompt)
    Microsoft Windows [Version 10.0.17763.379]

  • What you're doing and what's happening: (Copy&paste the full set of specific command-line steps necessary to reproduce the behavior, and their output. Include screen shots if that helps demonstrate the problem.)
    I' trying to host a samba server in my Kali WSL. Before that I installed full Kali Linux by command
    sudo apt-get install kali-linux-full
    After configuration of /etc/samba/smb.conf, I use command
    smbpasswd -a share
    "share" is a user.

  • What's wrong / what should be happening instead:
    But after setting, I saw error information

root@Reese:~# smbpasswd -a share
New SMB password:
Retype new SMB password:
tdb(/var/run/samba/gencache_notrans.tdb): tdb_open_ex: tdb_new_database failed for /var/run/samba/gencache_notrans.tdb: Operation not permitted
tdb(/var/run/samba/gencache_notrans.tdb): tdb_open_ex: tdb_new_database failed for /var/run/samba/gencache_notrans.tdb: Operation not permitted
tdb(/var/run/samba/gencache_notrans.tdb): tdb_open_ex: tdb_new_database failed for /var/run/samba/gencache_notrans.tdb: Operation not permitted
root@Reese:~#

And when I tried to start service

root@Reese:~# service smbd start
[ ok ] Starting SMB/CIFS daemon: smbd.
root@Reese:~# service smbd status
[FAIL] smbd is not running ... failed!
root@Reese:~#
  • Strace of the failing command, if applicable: (If some_command is failing, then run strace -o some_command.strace -f some_command some_args, and link the contents of some_command.strace in a gist here).
root@Reese:~# strace -o smbpasswd.starce -f smbpasswd -a share
New SMB password:
Retype new SMB password:
tdb(/var/run/samba/gencache_notrans.tdb): tdb_open_ex: tdb_new_database failed for /var/run/samba/gencache_notrans.tdb: Operation not permitted
tdb(/var/run/samba/gencache_notrans.tdb): tdb_open_ex: tdb_new_database failed for /var/run/samba/gencache_notrans.tdb: Operation not permitted
tdb(/var/run/samba/gencache_notrans.tdb): tdb_open_ex: tdb_new_database failed for /var/run/samba/gencache_notrans.tdb: Operation not permitted
root@Reese:~#

*Configuration of my /etc/samba/smb.conf, neither would work (same error).

My configuration:
[global]
    workgroup = WORKGROUP
    server string = samba
    log file = /var/log/samba/log.%m
    log level = 0
    max log size = 1000
    security = user
    map to guest = Bad User
    passdb backend = smbpasswd
    smb passwd file = /etc/samba/smbpasswd
    username map = /etc/samba/smbusers
    guest account = nobody
    os level = 64

[homes]
    comment = user private
    path = /mnt/c/private/%u
    read only = No

[share]
    comment = home share
    guest ok = Yes
    path = /mnt/c/share
    read only = No
    public = Yes

Default configuration:

#
# Sample configuration file for the Samba suite for Debian GNU/Linux.
#
#
# This is the main Samba configuration file. You should read the
# smb.conf(5) manual page in order to understand the options listed
# here. Samba has a huge number of configurable options most of which
# are not shown in this example
#
# Some options that are often worth tuning have been included as
# commented-out examples in this file.
#  - When such options are commented with ";", the proposed setting
#    differs from the default Samba behaviour
#  - When commented with "#", the proposed setting is the default
#    behaviour of Samba but the option is considered important
#    enough to be mentioned here
#
# NOTE: Whenever you modify this file you should run the command
# "testparm" to check that you have not made any basic syntactic
# errors.

#======================= Global Settings =======================

[global]

## Browsing/Identification ###

# Change this to the workgroup/NT-domain name your Samba server will part of
   workgroup = WORKGROUP

#### Networking ####

# The specific set of interfaces / networks to bind to
# This can be either the interface name or an IP address/netmask;
# interface names are normally preferred
;   interfaces = 127.0.0.0/8 eth0

# Only bind to the named interfaces and/or networks; you must use the
# 'interfaces' option above to use this.
# It is recommended that you enable this feature if your Samba machine is
# not protected by a firewall or is a firewall itself.  However, this
# option cannot handle dynamic or non-broadcast interfaces correctly.
;   bind interfaces only = yes



#### Debugging/Accounting ####

# This tells Samba to use a separate log file for each machine
# that connects
   log file = /var/log/samba/log.%m

# Cap the size of the individual log files (in KiB).
   max log size = 1000

# We want Samba to only log to /var/log/samba/log.{smbd,nmbd}.
# Append syslog@1 if you want important messages to be sent to syslog too.
   logging = file

# Do something sensible when Samba crashes: mail the admin a backtrace
   panic action = /usr/share/samba/panic-action %d


####### Authentication #######

# Server role. Defines in which mode Samba will operate. Possible
# values are "standalone server", "member server", "classic primary
# domain controller", "classic backup domain controller", "active
# directory domain controller".
#
# Most people will want "standalone server" or "member server".
# Running as "active directory domain controller" will require first
# running "samba-tool domain provision" to wipe databases and create a
# new domain.
   server role = standalone server

   obey pam restrictions = yes

# This boolean parameter controls whether Samba attempts to sync the Unix
# password with the SMB password when the encrypted SMB password in the
# passdb is changed.
   unix password sync = yes

# For Unix password sync to work on a Debian GNU/Linux system, the following
# parameters must be set (thanks to Ian Kahan <<kahan@informatik.tu-muenchen.de> for
# sending the correct chat script for the passwd program in Debian Sarge).
   passwd program = /usr/bin/passwd %u
   passwd chat = *Enter\snew\s*\spassword:* %n\n *Retype\snew\s*\spassword:* %n\n *password\supdated\ssuccessfully* .

# This boolean controls whether PAM will be used for password changes
# when requested by an SMB client instead of the program listed in
# 'passwd program'. The default is 'no'.
   pam password change = yes

# This option controls how unsuccessful authentication attempts are mapped
# to anonymous connections
   map to guest = bad user

########## Domains ###########

#
# The following settings only takes effect if 'server role = primary
# classic domain controller', 'server role = backup domain controller'
# or 'domain logons' is set
#

# It specifies the location of the user's
# profile directory from the client point of view) The following
# required a [profiles] share to be setup on the samba server (see
# below)
;   logon path = \\%N\profiles\%U
# Another common choice is storing the profile in the user's home directory
# (this is Samba's default)
#   logon path = \\%N\%U\profile

# The following setting only takes effect if 'domain logons' is set
# It specifies the location of a user's home directory (from the client
# point of view)
;   logon drive = H:
#   logon home = \\%N\%U

# The following setting only takes effect if 'domain logons' is set
# It specifies the script to run during logon. The script must be stored
# in the [netlogon] share
# NOTE: Must be store in 'DOS' file format convention
;   logon script = logon.cmd

# This allows Unix users to be created on the domain controller via the SAMR
# RPC pipe.  The example command creates a user account with a disabled Unix
# password; please adapt to your needs
; add user script = /usr/sbin/adduser --quiet --disabled-password --gecos "" %u

# This allows machine accounts to be created on the domain controller via the
# SAMR RPC pipe.
# The following assumes a "machines" group exists on the system
; add machine script  = /usr/sbin/useradd -g machines -c "%u machine account" -d /var/lib/samba -s /bin/false %u

# This allows Unix groups to be created on the domain controller via the SAMR
# RPC pipe.
; add group script = /usr/sbin/addgroup --force-badname %g

############ Misc ############

# Using the following line enables you to customise your configuration
# on a per machine basis. The %m gets replaced with the netbios name
# of the machine that is connecting
;   include = /home/samba/etc/smb.conf.%m

# Some defaults for winbind (make sure you're not using the ranges
# for something else.)
;   idmap config * :              backend = tdb
;   idmap config * :              range   = 3000-7999
;   idmap config YOURDOMAINHERE : backend = tdb
;   idmap config YOURDOMAINHERE : range   = 100000-999999
;   template shell = /bin/bash

# Setup usershare options to enable non-root users to share folders
# with the net usershare command.

# Maximum number of usershare. 0 means that usershare is disabled.
#   usershare max shares = 100

# Allow users who've been granted usershare privileges to create
# public shares, not just authenticated ones
   usershare allow guests = yes

#======================= Share Definitions =======================

[homes]
   comment = Home Directories
   browseable = no

# By default, the home directories are exported read-only. Change the
# next parameter to 'no' if you want to be able to write to them.
   read only = yes

# File creation mask is set to 0700 for security reasons. If you want to
# create files with group=rw permissions, set next parameter to 0775.
   create mask = 0700

# Directory creation mask is set to 0700 for security reasons. If you want to
# create dirs. with group=rw permissions, set next parameter to 0775.
   directory mask = 0700

# By default, \\server\username shares can be connected to by anyone
# with access to the samba server.
# The following parameter makes sure that only "username" can connect
# to \\server\username
# This might need tweaking when using external authentication schemes
   valid users = %S

# Un-comment the following and create the netlogon directory for Domain Logons
# (you need to configure Samba to act as a domain controller too.)
;[netlogon]
;   comment = Network Logon Service
;   path = /home/samba/netlogon
;   guest ok = yes
;   read only = yes

# Un-comment the following and create the profiles directory to store
# users profiles (see the "logon path" option above)
# (you need to configure Samba to act as a domain controller too.)
# The path below should be writable by all users so that their
# profile directory may be created the first time they log on
;[profiles]
;   comment = Users profiles
;   path = /home/samba/profiles
;   guest ok = no
;   browseable = no
;   create mask = 0600
;   directory mask = 0700

[printers]
   comment = All Printers
   browseable = no
   path = /var/spool/samba
   printable = yes
   guest ok = no
   read only = yes
   create mask = 0700

# Windows clients look for this share name as a source of downloadable
# printer drivers
[print$]
   comment = Printer Drivers
   path = /var/lib/samba/printers
   browseable = yes
   read only = yes
   guest ok = no
# Uncomment to allow remote administration of Windows print drivers.
# You may need to replace 'lpadmin' with the name of the group your
# admin users are members of.
# Please note that you also need to set appropriate Unix permissions
# to the drivers directory for these users to have write rights in it
;   write list = root, @lpadmin

I search for an hour but nothing I found works. Any solution? Many thanks.

@Biswa96
Copy link

Biswa96 commented Mar 24, 2019

WSL has some issue with /var/run.

@therealkenc
Copy link
Collaborator

^--- Yes, that's #2530. That may be the source of the smbpasswd problem. It might not, there is no way to tell because the template was deleted and no strace was provided. Samba server has worked for quite some time per #764.

@therealkenc
Copy link
Collaborator

In the edit you didn't link the strace(1) log (would be smbpasswd.starce). But very much appreciate you trying, and made me look.

Repro:

$ sudo apt update && sudo apt upgrade
$ grep -E "^NAME=|VERSION=" /etc/os-release    # sigh, where is lsb_release(1)
NAME="Kali GNU/Linux"
VERSION="2019.1"
$ sudo apt install samba
$ smbd --version
Version 4.9.4-Debian
$ sudo smbpasswd -a ken
[...same as you]

The fail is:

10538 openat(AT_FDCWD, "/var/run/samba/gencache_notrans.tdb", O_RDWR|O_CREAT, 0644) = 13
10538 fcntl(13, F_GETFD)                = 0
10538 fcntl(13, F_SETFD, FD_CLOEXEC)    = 0
10538 fcntl(13, F_SETLKW, {l_type=F_WRLCK, l_whence=SEEK_SET, l_start=0, l_len=1}) = 0
10538 fcntl(13, F_SETLK, {l_type=F_WRLCK, l_whence=SEEK_SET, l_start=4, l_len=1}) = 0
10538 fcntl(13, F_SETLKW, {l_type=F_WRLCK, l_whence=SEEK_SET, l_start=168, l_len=0}) = 0
10538 lseek(13, 0, SEEK_SET)            = 0
10538 ftruncate(13, 0)                  = 0
10538 write(13, "TDB file\n\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 40172) = 40172
10538 ftruncate(13, 401576)             = 0
10538 mmap(NULL, 401408, PROT_READ|PROT_WRITE, MAP_SHARED, 13, 0) = -1 EPERM (Operation not permitted)

Perms on /var/run/samba/gencache_notrans.tdb look okay after the openat().

$ ls -l /var/run/samba/gencache_notrans.tdb
-rw-r--r-- 1 root root 401576 Mar 25 01:53 /var/run/samba/gencache_notrans.tdb

So that EPERM isn't good. Dropping question tag; it isn't your config.

@strarsis
Copy link

strarsis commented May 1, 2019

@therealkenc: I also encountered this issue after upgrading WSL Ubuntu from 16.04 to 18.04.
samba server service was renamed from samba to smbd and doesn't start anymore with these errors in samba log.

@therealkenc
Copy link
Collaborator

Yes, Version 4.7.6-Ubuntu is broken alright. I should have said that explicitly but the OP was kali so I ran with it.

Your post was motivation enough to look. In March I wanted to blame our old friend ftruncate()/mmap() but the sequence didn't fit, which is why I left it chirping crickets. Anyway after more effort looking than I intended, I ended up with ghost of #2974.

Hand on a stack, on Real Linux™ /run is also noexec. But it takes.

// gcc 3937.cpp && sudo strace ./a.out 2>&1 >/dev/null | grep 401408
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, const char *argv[])
{
    constexpr size_t mm_sz = 401408;
    int fd = open("/run/foo.tbd", O_RDWR|O_CREAT|O_TRUNC, 0644);
    constexpr size_t ext_sz = 401576;
    char *buf = static_cast<char*>(malloc(ext_sz));
    memset(buf, '?', ext_sz);
    constexpr size_t sz = 40172;
    write(fd, buf, sz);
#if 0 // not the problem, but it seemed at least plausible at the time
    fcntl(fd, F_SETFD, FD_CLOEXEC);
    struct flock fl = {F_WRLCK, SEEK_SET, 0, 1};
    fcntl(fd, F_SETLKW, &fl);
    fl = {F_WRLCK, SEEK_SET, 0, 1};
    fcntl(fd, F_SETLK, &fl);
    fl = {F_WRLCK, SEEK_SET, 168, 0};
    fcntl(fd, F_SETLKW, &fl);
    lseek(fd, 0, SEEK_SET);
    ftruncate(fd, 0);
    write(fd, buf, sz);
    ftruncate(fd, ext_sz);
#endif
    mmap(NULL, mm_sz, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
    return 0;
}

image

image

Sad face if Ben ends up pointing out something obvious for a second time.

@brelian
Copy link

brelian commented Sep 16, 2019

I have been trying to find the solution for a day. Can anyone solve this problem and share the solution?

@therealkenc
Copy link
Collaborator

therealkenc commented Sep 16, 2019

Can anyone solve this problem and share the solution?

  • Re-mount /run tmpfs without the noexec flag as mentioned above. Noting I can't actually confirm that solution just at this moment, because I don't have a WSL1 distro or a 17763 or 18362 Win10 handy. But that was the problem last time I looked in May.
  • Use WSL2, with the new localhost sharing thing turned off.

Bearing in mind that Samba on WSL1 isn't especially useful for much because port 445 is already spoken for.

@brelian
Copy link

brelian commented Sep 24, 2019

Can anyone solve this problem and share the solution?

  • Re-mount /run tmpfs without the noexec flag as mentioned above. Noting I can't actually confirm that solution just at this moment, because I don't have a WSL1 distro or a 17763 or 18362 Win10 handy. But that was the problem last time I looked in May.
  • Use WSL2, with the new localhost sharing thing turned off.

Bearing in mind that Samba on WSL1 isn't especially useful for much because port 445 is already spoken for.

Thanks @therealkenc . I solved this issue used WSL2.

@DanielSmedegaardBuus
Copy link

Can anyone solve this problem and share the solution?

  • Re-mount /run tmpfs without the noexec flag as mentioned above. Noting I can't actually confirm that solution just at this moment, because I don't have a WSL1 distro or a 17763 or 18362 Win10 handy. But that was the problem last time I looked in May.
  • Use WSL2, with the new localhost sharing thing turned off.

Bearing in mind that Samba on WSL1 isn't especially useful for much because port 445 is already spoken for.

Can you elaborate on solution 1? Trying to remount /run fails for me:

> sudo mount -o remount,exec /run
mount: /run: mount point not mounted or bad option.

...but mount, though...

rootfs on / type lxfs (rw,noatime) 
none on /dev type tmpfs (rw,noatime,mode=755)
sysfs on /sys type sysfs (rw,nosuid,nodev,noatime)
proc on /proc type proc (rw,nosuid,nodev,noexec,noatime)
devpts on /dev/pts type devpts (rw,nosuid,noexec,noatime,gid=5,mode=620)
none on /run type tmpfs (rw,nosuid,noexec,noatime,mode=755)
none on /run/lock type tmpfs (rw,nosuid,nodev,noexec,noatime)
none on /run/shm type tmpfs (rw,nosuid,nodev,noatime)
none on /run/user type tmpfs (rw,nosuid,nodev,noexec,noatime,mode=755)
binfmt_misc on /proc/sys/fs/binfmt_misc type binfmt_misc (rw,noatime)

@DanielSmedegaardBuus
Copy link

DanielSmedegaardBuus commented Mar 17, 2021

Wait, what the... hell... Actually, /run wasn't mounted at all!

sudo mount -o exec -t tmpfs none /run actually mounts the tmpfs on /run, and then smbpasswd AND smbd - which was my first problem - work just fine! I wonder if this fixes other related problems as well. This is really weird :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants