1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-22 13:34:15 +03:00

ctdb-scripts: Avoid using testparm to process its own output

When testparm processes the output of "testparm -v" (which includes
default values) it appears to do global checks (or some other sort of
initialisation logic) for all specified values.  This includes a DNS
lookup for the node's hostname, as a side-effect of a libldap
ldap_set_option() call when processing "ldap debug level".  If DNS
servers are down then this can induce timeouts, possibly resulting in
monitor timeouts.

Avoid this by using sed to extract configuration values from the
testparm cache file.

This is already shown to work when retrieving share paths, where
testparm is basically used as cat.  Update the sed pattern to avoid
matching empty values on the right-hand side of the equals ('=') -
this avoids the default empty path value (and "smb ports" never has an
empty value).

Corresponding test changes:

* 50.samba.monitor.111.sh no longer expects a failure from being
  unable to set smb ports, since testparm is no longer used in that
  code path.

* smb ports needs to be set in fake smb.conf so it is in the default
  output and can be extracted using sed.

* Although testparm --parameter-name is no longer used in
  50.samba.script, update the stub implementation (in case it is ever
  used again) to extract from fake smb.conf, since "smb ports" is now
  set there.  The change from $parameter to $param allows a long line
  to stay below 80 columns.

Signed-off-by: Martin Schwenke <mschwenke@ddn.com>
Reviewed-by: Volker Lendecke <vl@samba.org>

Autobuild-User(master): Volker Lendecke <vl@samba.org>
Autobuild-Date(master): Tue Feb 14 08:43:53 UTC 2023 on atb-devel-224
This commit is contained in:
Martin Schwenke 2023-02-13 14:59:18 +11:00 committed by Volker Lendecke
parent 9a04ca1e1c
commit 238056e5aa
4 changed files with 19 additions and 24 deletions

View File

@ -109,21 +109,24 @@ testparm_background_update()
testparm_foreground_update "$_timeout" >/dev/null 2>&1 </dev/null & testparm_foreground_update "$_timeout" >/dev/null 2>&1 </dev/null &
} }
testparm_cat() testparm_get ()
{ {
testparm -s "$smbconf_cache" "$@" 2>/dev/null _param="$1"
sed -n \
-e "s|^[[:space:]]*${_param}[[:space:]]*=[[:space:]]\(..*\)|\1|p" \
"$smbconf_cache"
} }
list_samba_shares() list_samba_shares()
{ {
testparm_cat | testparm_get "path" | sed -e 's/"//g'
sed -n -e 's@^[[:space:]]*path[[:space:]]*=[[:space:]]@@p' |
sed -e 's/"//g'
} }
list_samba_ports() list_samba_ports()
{ {
testparm_cat --parameter-name="smb ports" testparm_get "smb ports"
} }
########################### ###########################

View File

@ -10,7 +10,7 @@ ok_null
simple_test simple_test
export FAKE_TESTPARM_FAIL="yes" export FAKE_TESTPARM_FAIL="yes"
required_result 1 <<EOF ok <<EOF
WARNING: smb.conf cache update failed - using old cache file WARNING: smb.conf cache update failed - using old cache file
Load smb config files from ${CTDB_SYS_ETCDIR}/samba/smb.conf Load smb config files from ${CTDB_SYS_ETCDIR}/samba/smb.conf
rlimit_max: increasing rlimit_max (2048) to minimum Windows limit (16384) rlimit_max: increasing rlimit_max (2048) to minimum Windows limit (16384)
@ -19,7 +19,5 @@ Processing section "[share2]"
Processing section "[share3]" Processing section "[share3]"
Loaded services file OK. Loaded services file OK.
WARNING: 'workgroup' and 'netbios name' must differ. WARNING: 'workgroup' and 'netbios name' must differ.
Failed to set smb ports
EOF EOF
simple_test simple_test

View File

@ -40,3 +40,4 @@
map readonly = no map readonly = no
ea support = yes ea support = yes
dmapi support = no dmapi support = no
smb ports = 445 139

View File

@ -44,29 +44,22 @@ fi
# the global one, unless some other file is specified. # the global one, unless some other file is specified.
file="" file=""
parameter="" param=""
for i; do for i; do
case "$i" in case "$i" in
--parameter-name=*) parameter="${i#--parameter-name=}" ;; --parameter-name=*) param="${i#--parameter-name=}" ;;
-*) : ;; -*) : ;;
*) file="$i" ;; *) file="$i" ;;
esac esac
done done
# Just hard-code parameter requests for now. Later on they could be # Parse out parameter request
# parsed out of the file. if [ -n "$param" ]; then
case "$parameter" in sed -n \
security) -e "s|^[[:space:]]*${param}[[:space:]]*=[[:space:]]\(..*\)|\1|p" \
echo "ADS" "${file:-"${CTDB_SYS_ETCDIR}/samba/smb.conf"}"
exit 0 exit 0
;; fi
smb*ports)
echo "445 139"
exit 0
;;
?*) not_implemented "--parameter-name=$parameter" ;;
# Fall through if $parameter not set
esac
if [ -n "$file" ]; then if [ -n "$file" ]; then
# This should include the shares, since this is used when the # This should include the shares, since this is used when the