[Bug 209660] net/samba4*: samba_server service file force runs all daemons if called with 'onestart'

From: <bugzilla-noreply_at_freebsd.org>
Date: Wed, 30 Jun 2021 18:04:19 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=209660

--- Comment #3 from Emrion <kmachine@free.fr> ---
I eventually wrote a patch to get the same behaviour, whether samba_server is
started by 'start' or 'onestart' command.

The idea is that the variable $samba_daemons should contain only the daemon
names it is supposed to start (mainly depending on rc.conf values). I followed
all the indications I found in the code and it seems to work. In some way, the
code of samba_server_config_init() is even simplified.

The patch is applicable at least for samba412 & 413. Seems the code of this
script hasn't changed since long time.

Applying this patch, you get this:

--------------------------
samba_server_defaultyes()
{
    load_rc_config $1
    eval ${1}_enable=\${${1}_enable-YES}
    if checkyesno ${1}_enable; then
        samba_daemons="$samba_daemons $1"
    fi
}

samba_server_config_init() {
    # Load configuration
    load_rc_config "${name}"
    # Defaults
    samba_server_enable=${samba_server_enable:=NO}
    samba_server_config=${samba_server_config=${samba_server_config_default}}
   
samba_server_configfile_arg=${samba_server_config:+--configfile="${samba_server_config}"}
                  #"
    #testparm_command="/usr/local/bin/samba-tool testparm --suppress-prompt
--verbose ${samba_server_configfile_arg}"
    testparm_command="/usr/local/bin/testparm --suppress-prompt --verbose
${samba_server_config}"
    # Determine what daemons are necessary to run Samba in the current role
    samba_server_role=$(${testparm_command} --parameter-name='server role'
2>/dev/null)
    case "${samba_server_role}" in
        active\ directory\ domain\ controller)
            samba_server_defaultyes "samba"
            ;;
        auto|*)
            samba_server_defaultyes "nmbd"
            samba_server_defaultyes "smbd"    
            # Winbindd will be active if it's set to "YES" in rc.conf
            # or if 'idmap id' is defined in smb4.conf
            load_rc_config "winbindd"
            samba_server_idmap=$(${testparm_command} --parameter-name='idmap
uid' 2>/dev/null)
            if [ -n "${samba_server_idmap}" ]; then
                    winbindd_enable="YES"
            fi
            if [ -n "$winbindd_enable" ] && checkyesno winbindd_enable; then
                samba_daemons="${samba_daemons} winbindd"
            fi
            ;;
    esac
    # Fetch parameters from configuration file
    samba_server_lockdir="$(${testparm_command} --parameter-name='lock
directory' 2>/dev/null)"
    samba_server_lockdir=${samba_server_lockdir:=/var/db/samba4}
    samba_server_piddir="$(${testparm_command} --parameter-name='pid directory'
2>/dev/null)"
    samba_server_piddir=${samba_server_piddir:=/var/run/samba4}
    samba_server_privatedir="$(${testparm_command} --parameter-name='private
dir' 2>/dev/null)"
    samba_server_privatedir=${samba_server_privatedir:=/var/db/samba4/private}
}
--------------------------

-- 
You are receiving this mail because:
You are the assignee for the bug.