#! /bin/sh

. /etc/control.d/functions-local-policy

CONFIG=/etc/samba/smb.conf

new_summary 'It specifies how often the MACHINE ACCOUNT PASSWORD stored in the TDB will be changed by winbind'

new_help disabled "Disable MACHINE PASSWORD TIMEOUT option"
new_help INTERVAL "Set the value how often MACHINE ACCOUNT PASSWORD stored in the TDB will be changed by winbind, in seconds (default is 604800)"

REQUEST="$*"

new_subst disabled \
	'^\s*[#;]\s*machine\s+password\s+timeout\s*=' \
	's/^\(\s*[#;]\)\?\(\s*machine\s\+password\s\+timeout\)\s*=.*/#\2 = 604800/'

check_default_option_with_section "global" "$CONFIG" "$REQUEST" \
	'machine password timeout' "604800" "disabled" \
	'^[[:digit:]]+$' || exit $?

control_subst_with_file_check "$CONFIG" "$REQUEST" "disabled" \
	'^[[:digit:]]+$' \
	"s/^\(\s*[#;]\)\?\(\s*machine\s\+password\s\+timeout\)\s*=.*/\2 = $REQUEST/" \
	'\s*machine\s+password\s+timeout\s*=\s*[^[:space:]]*\s*$' \
	's/^\s*machine\s\+password\s\+timeout\s*=\s*\([^[:space:]]*\)\s*$/\1/'

