View | Details | Raw Unified | Return to bug 31026
Collapse All | Expand All

(-)a/branches/ucs-3.1/ucs-3.1-2/base/univention-server/check_connection (-30 / +12 lines)
 Lines 34-44    Link Here 
34
34
35
LOCKFILE=/tmp/.univention_check_connection
35
LOCKFILE=/tmp/.univention_check_connection
36
# create lock file
36
# create lock file
37
if ! lockfile-create -q --retry 0 $LOCKFILE; then
37
if ! lockfile-create -q --retry 0 "$LOCKFILE"; then
38
	exit 0
38
	exit 0
39
fi
39
fi
40
40
41
42
export PATH=$PATH:/sbin:/usr/sbin
41
export PATH=$PATH:/sbin:/usr/sbin
43
42
44
eval "$(/usr/sbin/univention-config-registry shell)"
43
eval "$(/usr/sbin/univention-config-registry shell)"
 Lines 53-99   if [ -n "$1" -a "$1" = "runParts" ]; then Link Here 
53
	run_parts=true
52
	run_parts=true
54
fi
53
fi
55
54
56
57
action () {
55
action () {
58
	dir="/etc/network/if-$1.d"
56
	dir="/etc/network/if-$1.d"
59
	export MODE=$1
57
	export MODE=$1
60
58
61
	if [ -d "$dir" -a "$run_parts" = "true" ]; then
59
	if [ -d "$dir" ] && "$run_parts"; then
62
		run-parts "$dir" >/dev/null
60
		run-parts "$dir" >/dev/null
63
	fi
61
	fi
64
}
62
}
65
63
66
connection_okay=0
64
if univention-ldap-server-available
67
65
then
68
if [ -n "$ldap_server_name" ]; then
66
	case "$auth_methods" in
69
	if /bin/netcat -q0 -w4 $ldap_server_name 7389 </dev/null >/dev/null 2>&1; then
67
	*ldap*) ;;
70
		connection_okay=1
68
	*)
71
	fi
72
fi
73
74
if [ -n "$ldap_server_addition" ] && [ $connection_okay = 0 ]; then
75
	for h in  $ldap_server_addition; do
76
		if /bin/netcat -q0 -w4 $h 7389 </dev/null >/dev/null 2>&1; then
77
			connection_okay=1
78
			break
79
		fi
80
	done
81
fi
82
83
if [ $connection_okay = 1 ]; then
84
	res="`echo $auth_methods | grep ldap`"
85
	if [ -z "$res" ]; then
86
		/usr/sbin/univention-config-registry set auth/methods="$auth_methods_default" >/dev/null
69
		/usr/sbin/univention-config-registry set auth/methods="$auth_methods_default" >/dev/null
87
		action up
70
		action up
88
	fi
71
	esac
89
else
72
else
90
	res="`echo $auth_methods | grep ldap`"
73
	case "$auth_methods" in
91
	if [ -n "$res" ]; then
74
	*ldap*)
92
		/usr/sbin/univention-config-registry set auth/methods=cache >/dev/null
75
		/usr/sbin/univention-config-registry set auth/methods=cache >/dev/null
93
		action down
76
		action down
94
	fi
77
	esac
95
96
fi
78
fi
97
79
98
# remove lock file
80
# remove lock file
99
lockfile-remove $LOCKFILE
81
lockfile-remove "$LOCKFILE"
(-)a/branches/ucs-3.1/ucs-3.1-2/base/univention-server/managed-client (-54 / +47 lines)
 Lines 31-44    Link Here 
31
# <http://www.gnu.org/licenses/>.
31
# <http://www.gnu.org/licenses/>.
32
32
33
. /usr/share/univention-lib/base.sh
33
. /usr/share/univention-lib/base.sh
34
create_logfile_if_missing /var/log/univention/managed-client.log "root:adm" 640
34
LOG=/var/log/univention/managed-client.log
35
create_logfile_if_missing "$LOG" "root:adm" 640
36
37
map () {
38
	cat /etc/univention/templates/mapping/*.univention-config-registry-mapping |
39
	while IFS== read ldap ucr
40
	do
41
		if [ "$1" = "$ldap" ]
42
		then
43
			ucr=${ucr#\"} ucr=${ucr%\"}
44
			echo "$ucr"
45
			return
46
		fi
47
	done
48
	echo "$1"
49
}
35
50
36
case $1 in
51
case "$1" in
37
	start)
52
	start)
38
		univention-config-registry set domain/connection=false >/dev/null 2>&1
53
		univention-config-registry set domain/connection=false >/dev/null 2>&1
39
54
40
		echo -n "Setting up Managed Client "
55
		echo -n "Setting up Managed Client "
41
		echo "Setting up Managed Client `date`" $LOG>>/var/log/univention/managed-client.log 2>&1
56
		echo "Setting up Managed Client `date`" >>"$LOG" 2>&1
42
57
43
		eval "$(univention-config-registry shell)"
58
		eval "$(univention-config-registry shell)"
44
59
 Lines 49-120   case $1 in Link Here 
49
		# check configuration
64
		# check configuration
50
		if [ -z "$ldap_server_name" -o -z "$ldap_base" -o -z "$ldap_hostdn" ]; then
65
		if [ -z "$ldap_server_name" -o -z "$ldap_base" -o -z "$ldap_hostdn" ]; then
51
			echo "setup failed"
66
			echo "setup failed"
52
			echo "setup failed" >>/var/log/univention/managed-client.log 2>&1
67
			echo "setup failed" >>"$LOG"
53
			exit 1
68
			exit 1
54
		fi
69
		fi
55
70
56
		# check for ldap server
71
		# check for ldap server
57
		if /bin/netcat -q0 -w4 $ldap_server_name 7389 </dev/null >/dev/null 2>&1; then
72
		if univention-ldap-server-available &&
58
			ldapsearch -x -h $ldap_server_name -ZZ -D "$ldap_hostdn" -y /etc/machine.secret -b $ldap_base -s BASE | ldapsearch-wrapper >>/var/log/univention/managed-client.log 2>&1
73
			ldapsearch -x -h "$ldap_server_name" -ZZ -D "$ldap_hostdn" -y /etc/machine.secret -b "$ldap_base" -s BASE >>"$LOG" 2>&1
59
			if [ $? = 0 ]; then
74
		then
60
				univention-config-registry set domain/connection=true >/dev/null 2>&1
75
			univention-config-registry set domain/connection=true >/dev/null 2>&1
61
62
				if [ -z "$ldap_mydn" ]; then
63
					ldap_mydn="$(ldapsearch -x -h $ldap_server_name -ZZ -D "$ldap_hostdn" -y /etc/machine.secret -b $ldap_base "(&(objectClass=univentionClient)(objectClass=univentionHost)(cn=$hostname))"  | ldapsearch-wrapper | grep ^dn | sed -e 's|dn: ||')"
64
				fi
65
66
				if [ -n "$ldap_hostdn" ]; then
67
					use_dn="$ldap_hostdn"
68
				elif [ -n "$ldap_mydn" ]; then
69
					use_dn="$ldap_mydn"
70
				fi
71
72
				if [ -n "$use_dn" ]; then
73
					# get policy result
74
					univention-config-registry unset univentionAutoStartScript
75
					univention-config-registry set ldap/mydn="$use_dn" >/dev/null 2>&1
76
77
					policy_file=$(mktemp)
78
					policy_file_result=$(mktemp)
79
80
					univention_policy_result -D "$ldap_hostdn" -y /etc/machine.secret -s "$use_dn" > $policy_file
81
82
					cat $policy_file | while read line; do
83
76
84
						# split the line a=b in a and b
77
			if [ -z "$ldap_mydn" ]; then
85
						var="${line%%=*}"
78
				ldap_mydn="$(ldapsearch -x -h "$ldap_server_name" -ZZ -D "$ldap_hostdn" -y /etc/machine.secret -b $ldap_base "(&(objectClass=univentionClient)(objectClass=univentionHost)(cn=$hostname))" | ldapsearch-wrapper | sed -ne 's|^dn: ||p;T;q')"
86
						val="${line#*=}"
79
			fi
87
88
						if [ -n "$var" ] && [ -n "$val" ]; then
89
							new_value=$(grep "$var=" /etc/univention/templates/mapping/* | head -n 1 | sed -e 's|.*=||;s|"||g')
90
							if [ -n "${new_value}" ]; then
91
								echo $line | sed -e "s|${var}=|${new_value}=|g" -e 's|="|=|' -e 's|"$||' >> $policy_file_result
92
							else
93
								echo $line | sed -e 's|="|=|' -e 's|"$||' >> $policy_file_result
94
							fi
95
						fi
96
80
97
					done
81
			if [ -n "$ldap_hostdn" ]; then
82
				use_dn="$ldap_hostdn"
83
			elif [ -n "$ldap_mydn" ]; then
84
				use_dn="$ldap_mydn"
85
			fi
98
86
99
					univention-config-registry set $(cat $policy_file_result) >> /var/log/univention/managed-client.log 2>&1
87
			if [ -n "$use_dn" ]; then
100
				fi
88
				# get policy result
101
	
89
				univention-config-registry unset univentionAutoStartScript
102
	
90
				univention-config-registry set ldap/mydn="$use_dn" >/dev/null 2>&1
103
			else
91
104
				echo "E: connection to $ldap_server_name failed" >>/var/log/univention/managed-client.log 2>&1
92
				univention_policy_result -D "$ldap_hostdn" -y /etc/machine.secret -s "$use_dn" |
93
				while IFS== read var val; do
94
					if [ -n "$var" ] && [ -n "$val" ]; then
95
						var=$(map "$var")
96
						val=${val#\"} val=${val%\"}
97
						printf "$var=$val\0"
98
					fi
99
				done |
100
				xrags -0r univention-config-registry set >>"$LOG" 2>&1
105
			fi
101
			fi
106
		else
102
		else
107
			echo "E: connection to $ldap_server_name failed" >>/var/log/univention/managed-client.log 2>&1
103
			echo "E: connection to $ldap_server_name failed" >>"$LOG" 2>&1
108
		fi
104
		fi
109
105
110
106
		if [ "$(univention-config-registry get univentionXMouseDevice)" = "/dev/input/mice" ]; then
111
		if [ "`univention-config-registry get univentionXMouseDevice`" = "/dev/input/mice" ]; then
112
			modprobe mousedev
107
			modprobe mousedev
113
		fi
108
		fi
114
109
115
116
		echo "done"
110
		echo "done"
117
118
		;;
111
		;;
119
esac
112
esac
120
113
(-)a/branches/ucs-3.1/ucs-3.1-2/base/univention-server/mobile-client (-52 / +47 lines)
 Lines 31-44    Link Here 
31
# <http://www.gnu.org/licenses/>.
31
# <http://www.gnu.org/licenses/>.
32
32
33
. /usr/share/univention-lib/base.sh
33
. /usr/share/univention-lib/base.sh
34
create_logfile_if_missing /var/log/univention/mobile-client.log "root:adm" 640
34
LOG=/var/log/univention/mobile-client.log
35
create_logfile_if_missing "$LOG" "root:adm" 640
36
37
map () {
38
	cat /etc/univention/templates/mapping/*.univention-config-registry-mapping |
39
	while IFS== read ldap ucr
40
	do
41
		if [ "$1" = "$ldap" ]
42
		then
43
			ucr=${ucr#\"} ucr=${ucr%\"}
44
			echo "$ucr"
45
			return
46
		fi
47
	done
48
	echo "$1"
49
}
35
50
36
case $1 in
51
case "$1" in
37
	start)
52
	start)
38
		univention-config-registry set domain/connection=false >/dev/null 2>&1
53
		univention-config-registry set domain/connection=false >/dev/null 2>&1
39
54
40
		echo -n "Setting up Mobile Client "
55
		echo -n "Setting up Mobile Client "
41
		echo "Setting up Mobile Client `date`" $LOG>>/var/log/univention/mobile-client.log 2>&1
56
		echo "Setting up Mobile Client `date`" >>"$LOG" 2>&1
42
57
43
		eval "$(univention-config-registry shell)"
58
		eval "$(univention-config-registry shell)"
44
59
 Lines 49-118   case $1 in Link Here 
49
		# check configuration
64
		# check configuration
50
		if [ -z "$ldap_server_name" -o -z "$ldap_base" -o -z "$ldap_hostdn" ]; then
65
		if [ -z "$ldap_server_name" -o -z "$ldap_base" -o -z "$ldap_hostdn" ]; then
51
			echo "setup failed"
66
			echo "setup failed"
52
			echo "setup failed" >>/var/log/univention/mobile-client.log 2>&1
67
			echo "setup failed" >>"$LOG"
53
			exit 1
68
			exit 1
54
		fi
69
		fi
55
70
56
		# check for ldap server
71
		# check for ldap server
57
		if /bin/netcat -q0 -w4 $ldap_server_name 7389 </dev/null >/dev/null 2>&1; then
72
		if univention-ldap-server-available &&
58
			ldapsearch -x -h $ldap_server_name -ZZ -D "$ldap_hostdn" -y /etc/machine.secret -b $ldap_base -s BASE | ldapsearch-wrapper>>/var/log/univention/mobile-client.log 2>&1
73
			ldapsearch -x -h "$ldap_server_name" -ZZ -D "$ldap_hostdn" -y /etc/machine.secret -b "$ldap_base" -s BASE >>"$LOG" 2>&1
59
			if [ $? = 0 ]; then
74
		then
60
				univention-config-registry set domain/connection=true >/dev/null 2>&1
75
			univention-config-registry set domain/connection=true >/dev/null 2>&1
61
62
				if [ -z "$ldap_mydn" ]; then
63
					ldap_mydn="$(ldapsearch -x -h $ldap_server_name -ZZ -D "$ldap_hostdn" -y /etc/machine.secret -b $ldap_base "(&(objectClass=univentionMobileClient)(objectClass=univentionHost)(cn=$hostname))" | ldapsearch-wrapper | grep ^dn | sed -e 's|dn: ||')"
64
				fi
65
66
				if [ -n "$ldap_hostdn" ]; then
67
					use_dn="$ldap_hostdn"
68
				elif [ -n "$ldap_mydn" ]; then
69
					use_dn="$ldap_mydn"
70
				fi
71
72
				if [ -n "$use_dn" ]; then
73
					# get policy result
74
					univention-config-registry unset univentionAutoStartScript
75
					univention-config-registry set ldap/mydn="$use_dn" >/dev/null 2>&1
76
77
					policy_file=$(mktemp)
78
					policy_file_result=$(mktemp)
79
80
					univention_policy_result -D "$ldap_hostdn" -y /etc/machine.secret -s "$use_dn" > $policy_file
81
82
					cat $policy_file | while read line; do
83
76
84
						# split the line a=b in a and b
77
			if [ -z "$ldap_mydn" ]; then
85
						var="${line%%=*}"
78
				ldap_mydn="$(ldapsearch -x -h "$ldap_server_name" -ZZ -D "$ldap_hostdn" -y /etc/machine.secret -b $ldap_base "(&(objectClass=univentionMobileClient)(objectClass=univentionHost)(cn=$hostname))" | ldapsearch-wrapper | sed -ne 's|^dn: ||p;T;q')"
86
						val="${line#*=}"
79
			fi
87
88
						if [ -n "$var" ] && [ -n "$val" ]; then
89
							new_value=$(grep "$var=" /etc/univention/templates/mapping/* | head -n 1 | sed -e 's|.*=||;s|"||g')
90
							if [ -n "${new_value}" ]; then
91
								echo $line | sed -e "s|${var}=|${new_value}=|g" -e 's|="|=|' -e 's|"$||' >> $policy_file_result
92
							else
93
								echo $line | sed -e 's|="|=|' -e 's|"$||' >> $policy_file_result
94
							fi
95
						fi
96
80
97
					done
81
			if [ -n "$ldap_hostdn" ]; then
82
				use_dn="$ldap_hostdn"
83
			elif [ -n "$ldap_mydn" ]; then
84
				use_dn="$ldap_mydn"
85
			fi
98
86
99
					univention-config-registry set $(cat $policy_file_result) >> /var/log/univention/mobile-client.log 2>&1
87
			if [ -n "$use_dn" ]; then
100
				fi
88
				# get policy result
101
			else
89
				univention-config-registry unset univentionAutoStartScript
102
				echo "E: connection to $ldap_server_name failed" >>/var/log/univention/mobile-client.log 2>&1
90
				univention-config-registry set ldap/mydn="$use_dn" >/dev/null 2>&1
91
92
				univention_policy_result -D "$ldap_hostdn" -y /etc/machine.secret -s "$use_dn" |
93
				while IFS== read var val; do
94
					if [ -n "$var" ] && [ -n "$val" ]; then
95
						var=$(map "$var")
96
						val=${val#\"} val=${val%\"}
97
						printf "$var=$val\0"
98
					fi
99
				done |
100
				xrags -0r univention-config-registry set >>"$LOG" 2>&1
103
			fi
101
			fi
104
		else
102
		else
105
			echo "E: connection to $ldap_server_name failed" >>/var/log/univention/mobile-client.log 2>&1
103
			echo "E: connection to $ldap_server_name failed" >>"$LOG" 2>&1
106
		fi
104
		fi
107
105
108
106
		if [ "$(univention-config-registry get univentionXMouseDevice)" = "/dev/input/mice" ]; then
109
		if [ "`univention-config-registry get univentionXMouseDevice`" = "/dev/input/mice" ]; then
110
			modprobe mousedev
107
			modprobe mousedev
111
		fi
108
		fi
112
109
113
114
		echo "done"
110
		echo "done"
115
116
		;;
111
		;;
117
esac
112
esac
118
113
(-)a/branches/ucs-3.1/ucs-3.1-2/base/univention-server/server_password_change (-72 / +65 lines)
 Lines 41-46   FAIL () { # log error message to log file and std-err, then fail Link Here 
41
	exit 1
41
	exit 1
42
}
42
}
43
43
44
try_ldap () { # try to connect LDAP server
45
	local trial_counter=60
46
	while [ $trial_counter -ge 0 ]
47
	do
48
		sleep 1
49
		if univention-ldapsearch -D "$ldap_hostdn" -y "$1" -h "$ldap_master" -p "$ldap_master_port" -s base > /dev/null 2>&3
50
		then
51
			return 0
52
		fi
53
	done
54
	return 1
55
}
56
44
eval "$(/usr/sbin/univention-config-registry shell)"
57
eval "$(/usr/sbin/univention-config-registry shell)"
45
58
46
# 0 -> set to true
59
# 0 -> set to true
 Lines 58-68   fi Link Here 
58
if [ -z "$ldap_hostdn" ]; then
71
if [ -z "$ldap_hostdn" ]; then
59
	FAIL "failed to change server password: empty config-registry variable ldap/hostdn"
72
	FAIL "failed to change server password: empty config-registry variable ldap/hostdn"
60
fi
73
fi
61
62
if [ ! -e "/etc/machine.secret" ]; then
74
if [ ! -e "/etc/machine.secret" ]; then
63
	FAIL "failed to change server password: /etc/machine.secret not found"
75
	FAIL "failed to change server password: /etc/machine.secret not found"
64
fi
76
fi
65
66
if [ -e "/var/lib/univention-directory-replication/failed.ldif" ]; then
77
if [ -e "/var/lib/univention-directory-replication/failed.ldif" ]; then
67
	FAIL "failed to change server password: /var/lib/univention-directory-replication/failed.ldif exists"
78
	FAIL "failed to change server password: /var/lib/univention-directory-replication/failed.ldif exists"
68
fi
79
fi
 Lines 76-109   else Link Here 
76
fi
87
fi
77
88
78
# Try to use a trivial command just to check that LDAP server is reachable.
89
# Try to use a trivial command just to check that LDAP server is reachable.
79
univention-ldapsearch -D "$ldap_hostdn" -w "$(cat /etc/machine.secret)" -s base > /dev/null 2>&3
90
if ! univention-ldapsearch -D "$ldap_hostdn" -y /etc/machine.secret -s base > /dev/null 2>&3
80
if [ $? -ne 0 ]; then
91
then
81
	FAIL "failed to contact LDAP server: cannot connect with univention-ldapsearch"
92
	FAIL "failed to contact LDAP server: cannot connect with univention-ldapsearch"
82
fi
93
fi
83
94
84
new_password=$(makepasswd --chars 8)
95
new_pass=$(mktemp /etc/machine.secret.XXXXXXXX)
85
old_password=$(cat /etc/machine.secret)
96
old_pass=$(mktemp /etc/machine.secret.XXXXXXXX)
97
trap "rm -f '$new_pass' '$old_pass'" EXIT
86
98
87
if [ -z "$new_password" ]; then
99
cp /etc/machine.secret "$old_pass"
100
makepasswd --chars 8 | tr -d '\n' >"$new_pass"
101
102
if [ ! -s "$new_pass" ]; then
88
	FAIL "failed to change server password: makepasswd returned an empty password"
103
	FAIL "failed to change server password: makepasswd returned an empty password"
89
fi
104
fi
90
105
91
# Try to run hook scripts for "prechange" (which are named '^[A-Za-z0-9_-]+$')
106
# Try to run hook scripts for "prechange" (which are named '^[A-Za-z0-9_-]+$')
92
# Never use --exit-on-error with run-parts scripts because after an exit-on-error
107
# Never use --exit-on-error with run-parts scripts because after an exit-on-error
93
# we wouldn't know which scripts have received a "prechange" and need a "nochange".
108
# we wouldn't know which scripts have received a "prechange" and need a "nochange".
94
run-parts --verbose --arg prechange -- /usr/lib/univention-server/server_password_change.d >&3 2>&3
109
if ! run-parts --verbose --arg prechange -- /usr/lib/univention-server/server_password_change.d >&3 2>&3
95
# If ANY of the scripts fails while doing "prechange", then rollback with "nochange".
110
# If ANY of the scripts fails while doing "prechange", then rollback with "nochange".
96
if [ $? != 0 ]; then
111
then
97
	# Use run-parts without --exit-on-error; go through all scripts.
112
	# Use run-parts without --exit-on-error; go through all scripts.
98
	run-parts --verbose --arg nochange -- /usr/lib/univention-server/server_password_change.d >&3 2>&3
113
	run-parts --verbose --arg nochange -- /usr/lib/univention-server/server_password_change.d >&3 2>&3
99
	FAIL "run-parts failed during prechange, rolling back with nochange, server password unchanged"
114
	FAIL "run-parts failed during prechange, rolling back with nochange, server password unchanged"
100
fi
115
fi
101
116
102
# Try to modify the server password with UDM.
117
# Try to modify the server password with UDM.
103
/usr/sbin/univention-directory-manager "computers/$server_role" modify --binddn "$ldap_hostdn" --bindpwd "$old_password" --dn "$ldap_hostdn" --set password="$new_password" >&3 2>&3
118
if ! /usr/sbin/univention-directory-manager "computers/$server_role" modify \
119
	--binddn "$ldap_hostdn" --bindpwfile "$old_pass" \
120
	--dn "$ldap_hostdn" --set password="$(cat "$new_pass")" >&3 2>&3
104
# If changing the server password with UDM failed for some unknown reason,
121
# If changing the server password with UDM failed for some unknown reason,
105
# then rollback the previous run-parts operation. 
122
# then rollback the previous run-parts operation. 
106
if [ $? != 0 ]; then
123
then
107
	# run hook scripts for "nochange" (which are named '^[A-Za-z0-9_-]+$')
124
	# run hook scripts for "nochange" (which are named '^[A-Za-z0-9_-]+$')
108
	run-parts --verbose --arg nochange -- /usr/lib/univention-server/server_password_change.d >&3 2>&3
125
	run-parts --verbose --arg nochange -- /usr/lib/univention-server/server_password_change.d >&3 2>&3
109
	FAIL "failed to change server password for $ldap_hostdn"
126
	FAIL "failed to change server password for $ldap_hostdn"
 Lines 112-185   fi Link Here 
112
# If the changed server password has really been set correctly, then we can already use it.
129
# If the changed server password has really been set correctly, then we can already use it.
113
# Try to use the new password with LDAP against the MASTER.
130
# Try to use the new password with LDAP against the MASTER.
114
# Repeat this several times, just in case password distribution takes some time.
131
# Repeat this several times, just in case password distribution takes some time.
115
trial_counter=60
132
if ! try_ldap "$new_pass"
116
while sleep 1
133
then
117
do
134
	# The server is in an inconsistent state because the new password has
118
	# Try to use a trivial command just to check that the new password works.
135
	# been set with UDM but LDAP does't work with it. Do not continue with
119
	univention-ldapsearch -D "$ldap_hostdn" -w "$new_password" -h "$ldap_master" -p "$ldap_master_port" -s base > /dev/null 2>&3
136
	# changes that would only worsen the situation. Instead, try to rollback.
120
	if [ $? -eq 0 ]; then
137
	# Reset the old password with UDM and give up.
121
		# OK, password worked against master, go on with the script.
138
	/usr/sbin/univention-directory-manager "computers/$server_role" modify \
122
		break
139
		--binddn "$ldap_hostdn" --bindpwfile "$new_pass" \
123
	fi
140
		--dn "$ldap_hostdn" --set password="$(cat "$old_pass")" >&3 2>&3
124
	# If the new password failed for a long time, give up.
141
125
	if [ $trial_counter -eq 0 ]; then
142
	# run hook scripts for "nochange" (which are named '^[A-Za-z0-9_-]+$')
126
		# The server is in an inconsistent state because the new password has
143
	run-parts --verbose --arg nochange -- /usr/lib/univention-server/server_password_change.d >&3 2>&3
127
		# been set with UDM but LDAP does't work with it. Do not continue with
144
	FAIL "resetting old server password for $ldap_hostdn, because access to LDAP master did not work with the new password"
128
		# changes that would only worsen the situation. Instead, try to rollback.
145
fi
129
		# Reset the old password with UDM and give up.
130
		/usr/sbin/univention-directory-manager "computers/$server_role" modify --binddn "$ldap_hostdn" --bindpwd "$new_password" --dn "$ldap_hostdn" --set password="$old_password" >&3 2>&3
131
132
		# run hook scripts for "nochange" (which are named '^[A-Za-z0-9_-]+$')
133
		run-parts --verbose --arg nochange -- /usr/lib/univention-server/server_password_change.d >&3 2>&3
134
		FAIL "resetting old server password for $ldap_hostdn, because access to LDAP master did not work with the new password"
135
	fi
136
	trial_counter=$(( trial_counter - 1))
137
done
138
146
139
# Now that we are sure the new password already works with LDAP master,
147
# Now that we are sure the new password already works with LDAP master,
140
# we can dare to overwrite the machine password. The machine password is
148
# we can dare to overwrite the machine password. The machine password is
141
# needed by the Listener who replicates the changed password to the
149
# needed by the Listener who replicates the changed password to the
142
# local server's LDAP.
150
# local server's LDAP.
143
echo "$(date +"%y%m%d%H%M"): $old_password" >>/etc/machine.secret.old
151
echo -n "$(date +"%y%m%d%H%M"): " >>/etc/machine.secret.old
152
cat "$old_pass" >>/etc/machine.secret.old
144
chmod 600 /etc/machine.secret.old
153
chmod 600 /etc/machine.secret.old
145
154
146
# change machine.secret and restart listener
155
# change machine.secret and restart listener
147
echo -n "$new_password" >/etc/machine.secret
156
cp "$new_pass" >/etc/machine.secret
148
chmod 600 /etc/machine.secret
157
chmod 600 /etc/machine.secret
149
[ -e /etc/init.d/univention-directory-listener ] && invoke-rc.d univention-directory-listener restart >&3
158
[ -x /etc/init.d/univention-directory-listener ] && invoke-rc.d univention-directory-listener restart >&3
150
159
151
# The password is changed on the master now, but it is not clear if
160
# The password is changed on the master now, but it is not clear if
152
# this change has been replicated to the local host yet.
161
# this change has been replicated to the local host yet.
153
# Do the same test as above but with the local LDAP replication.
162
# Do the same test as above but with the local LDAP replication.
154
trial_counter=60
163
if ! try_ldap "$new_pass"
155
while sleep 1
164
then
156
do
165
	# The server is in an inconsistent state because the new password has
157
	# Try to use a trivial command just to check that the new password works.
166
	# been set with UDM but LDAP does't work with it. Do not continue with
158
	univention-ldapsearch -D "$ldap_hostdn" -w "$new_password" -s base > /dev/null 2>&3
167
	# changes that would only worsen the situation. Instead, try to rollback.
159
	if [ $? -eq 0 ]; then
168
	# Reset the old password with UDM and give up.
160
		# OK, password worked, go on with the script.
169
	/usr/sbin/univention-directory-manager "computers/$server_role" modify \
161
		break
170
		--binddn "$ldap_hostdn" --bindpwfile "$new_pass" \
162
	fi
171
		--dn "$ldap_hostdn" --set password="$(cat "$old_pass")" >&3 2>&3
163
	# If the new password failed for a long time, give up.
172
164
	if [ $trial_counter -eq 0 ]; then
173
	# Rollback /etc/machine.secret and restart listener
165
		# The server is in an inconsistent state because the new password has
174
	cp "$old_pass" /etc/machine.secret
166
		# been set with UDM but LDAP does't work with it. Do not continue with
175
	chmod 600 /etc/machine.secret
167
		# changes that would only worsen the situation. Instead, try to rollback.
176
	[ -x /etc/init.d/univention-directory-listener ] && invoke-rc.d univention-directory-listener restart >&3
168
		# Reset the old password with UDM and give up.
177
169
178
	# run hook scripts for "nochange" (which are named '^[A-Za-z0-9_-]+$')
170
		/usr/sbin/univention-directory-manager "computers/$server_role" modify --binddn "$ldap_hostdn" --bindpwd "$new_password" --dn "$ldap_hostdn" --set password="$old_password" >&3 2>&3
179
	run-parts --verbose --arg nochange -- /usr/lib/univention-server/server_password_change.d >&3 2>&3
171
180
	FAIL "resetting old server password for $ldap_hostdn, because access to local LDAP did not work with the new password"
172
		# Rollback /etc/machine.secret and restart listener
181
fi
173
		awk '{pwd=$2}; END {printf("%s", pwd)}' /etc/machine.secret.old > /etc/machine.secret
174
		chmod 600 /etc/machine.secret
175
		[ -e /etc/init.d/univention-directory-listener ] && invoke-rc.d univention-directory-listener restart >&3
176
177
		# run hook scripts for "nochange" (which are named '^[A-Za-z0-9_-]+$')
178
		run-parts --verbose --arg nochange -- /usr/lib/univention-server/server_password_change.d >&3 2>&3
179
		FAIL "resetting old server password for $ldap_hostdn, because access to local LDAP did not work with the new password"
180
	fi
181
	trial_counter=$(( trial_counter - 1))
182
done
183
182
184
# At this point the server password has been changed.
183
# At this point the server password has been changed.
185
# The change has gone beyond the point-of-no-return and
184
# The change has gone beyond the point-of-no-return and
 Lines 188-199   done Link Here 
188
# obvious through the log file. It is essential now to
187
# obvious through the log file. It is essential now to
189
# go all the way through all the run-parts scripts with postchange.
188
# go all the way through all the run-parts scripts with postchange.
190
189
191
if [ "$server_role" != "domaincontroller_master" ] && [ "$server_role" != "domaincontroller_backup" ]; then
192
	if [ -x /etc/init.d/univention-directory-listener ]; then
193
		invoke-rc.d univention-directory-listener crestart >&3 2>&3
194
	fi
195
fi
196
197
# run hook scripts for "postchange" (which are named '^[A-Za-z0-9_-]+$')
190
# run hook scripts for "postchange" (which are named '^[A-Za-z0-9_-]+$')
198
# Use run-parts without --exit-on-error; go through all scripts.
191
# Use run-parts without --exit-on-error; go through all scripts.
199
run-parts --verbose --arg postchange -- /usr/lib/univention-server/server_password_change.d >&3 2>&3
192
run-parts --verbose --arg postchange -- /usr/lib/univention-server/server_password_change.d >&3 2>&3
(-)a/branches/ucs-3.1/ucs-3.1-2/base/univention-server/univention-ldap-server-available (-18 / +9 lines)
 Lines 30-54    Link Here 
30
# /usr/share/common-licenses/AGPL-3; if not, see
30
# /usr/share/common-licenses/AGPL-3; if not, see
31
# <http://www.gnu.org/licenses/>.
31
# <http://www.gnu.org/licenses/>.
32
32
33
export PATH=$PATH:/sbin:/usr/sbin
33
export PATH=/sbin:/usr/sbin:$PATH
34
34
35
eval "$(univention-config-registry shell)"
35
eval "$(univention-config-registry shell ldap/server/name ldap/server/addition ldap/server/port)"
36
36
37
exit_code=1
37
for h in $ldap_server_name $ldap_server_addition
38
38
do
39
if [ -n "$ldap_server_name" ]; then
39
	if /bin/netcat -q0 -w4 "$h" "${ldap_server_port:-7389}" </dev/null >/dev/null 2>&1
40
	if /bin/netcat -q0 -w4 $ldap_server_name 7389 </dev/null >/dev/null 2>&1; then
40
	then
41
		exit_code=0
41
		exit 0
42
	fi
42
	fi
43
fi
43
done
44
45
if [ -n "$ldap_server_addition" ] && [ $exit_code = 1 ]; then
46
	for h in  $ldap_server_addition; do
47
		if /bin/netcat -q0 -w4 $h 7389 </dev/null >/dev/null 2>&1; then
48
			exit_code=0
49
			break
50
		fi
51
	done
52
fi
53
44
54
exit $exit_code
45
exit 1

Return to bug 31026