Bug 209660 - net/samba4*: samba_server service file force runs all daemons if called with 'onestart'
Summary: net/samba4*: samba_server service file force runs all daemons if called with ...
Status: Closed Feedback Timeout
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Some People
Assignee: freebsd-ports-bugs (Nobody)
Keywords: needs-qa
Depends on:
Reported: 2016-05-20 10:14 UTC by zurvan.akarana
Modified: 2021-06-30 18:04 UTC (History)
4 users (show)

See Also:
vlad-fbsd: maintainer-feedback? (timur)

Patch for samba_server rc script (1.50 KB, patch)
2021-06-30 17:43 UTC, Emrion
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description zurvan.akarana 2016-05-20 10:14:52 UTC
This clause in /usr/local/etc/rc.d/samba_server (lines 120-122):

>     if [ -n "${_rc_prefix}" -a "${_rc_prefix}" = "one" ] || [ -n "${rc_force}" ] || [ -n "${rc_fast}" ]; then
>         force_run=yes
>     fi

forces nmbd and winbindd to be started regardless of the values of nmbd_enable and winbindd_enable in /etc/rc.conf.

If one wants to start samba_server manually (without having set samba_server_enable="YES") after boot they have no option but to use 'onestart' but then that will ignore disabling of nmbd and winbindd in rc.conf; even in situations where 'disable netbios = yes' is explicitly set in smb4.conf.

This leaves one with no option to start only smbd manually after boot without forcibly launching nmbd and winbindd which many not be desired in some scenarios.

This was checked with samba_server script shipped with samba41-4.1.22_2.
Comment 1 Emrion 2021-06-26 17:58:39 UTC
I did the same observation concerning samba412 & samba413 (latest versions).
I think this behaviour isn't normal.

I'm in a case where I don't have network connectivity at startup, so I delay the launch of samba via a cron entry. And, to do so, I'm obliged to use 'onestart' command.

Is it possible to correct this behavour?
Comment 2 Emrion 2021-06-30 17:43:59 UTC
Created attachment 226136 [details]
Patch for samba_server rc script

Launch the same daemons with command start or onestart
Comment 3 Emrion 2021-06-30 18:04:19 UTC
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:

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

samba_server_config_init() {
    # Load configuration
    load_rc_config "${name}"
    # Defaults
    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"
	    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
	    if [ -n "$winbindd_enable" ] && checkyesno winbindd_enable; then
		samba_daemons="${samba_daemons} winbindd"
    # Fetch parameters from configuration file
    samba_server_lockdir="$(${testparm_command} --parameter-name='lock directory' 2>/dev/null)"
    samba_server_piddir="$(${testparm_command} --parameter-name='pid directory' 2>/dev/null)"
    samba_server_privatedir="$(${testparm_command} --parameter-name='private dir' 2>/dev/null)"