|
3 |
# Univention Home Mounter |
3 |
# Univention Home Mounter |
4 |
# mount the homedir |
4 |
# mount the homedir |
5 |
# |
5 |
# |
6 |
# Copyright 2004-2012 Univention GmbH |
6 |
# Copyright 2004-2013 Univention GmbH |
7 |
# |
7 |
# |
8 |
# http://www.univention.de/ |
8 |
# http://www.univention.de/ |
9 |
# |
9 |
# |
|
43 |
# as the uid and deliver consequently a wrong or an empty result. |
43 |
# as the uid and deliver consequently a wrong or an empty result. |
44 |
|
44 |
|
45 |
numeric="" |
45 |
numeric="" |
46 |
numeric=`echo "$username" | egrep ^[0-9]+$` || true |
46 |
numeric=`egrep ^[0-9]+$ <<<"$username" || true |
47 |
first_numeric=`echo "$username" | egrep ^[0-9].*$` || true |
47 |
first_numeric=`egrep ^[0-9].*$ <<<"$username" || true |
48 |
|
48 |
|
49 |
eval "$(univention-config-registry shell ldap/hostdn)" |
49 |
ldap_hostdn=$(univention-config-registry get ldap/hostdn) |
50 |
|
50 |
|
51 |
if [ -z "$numeric" ] && [ -z "$first_numeric" ]; then |
51 |
if [ -z "$numeric" ] && [ -z "$first_numeric" ]; then |
52 |
pw_entry=`getent passwd "$username"` |
52 |
pw_entry=`getent passwd "$username"` |
53 |
|
53 |
|
54 |
for i in 1 2 3 4 5 6; do |
54 |
OIFS="$IFS" |
55 |
pw_fields[$i]=`echo $pw_entry | awk -F ':' '{ print $'$i' }'` |
55 |
IFS=':' |
56 |
done |
56 |
set -- $pw_entry |
|
|
57 |
IFS="$OIFS" |
57 |
|
58 |
|
58 |
HOME=${pw_fields[6]} |
59 |
HOME="$6" |
59 |
UID_NUMBER=${pw_fields[3]} |
60 |
UID_NUMBER="$3" |
60 |
GID_NUMBER=${pw_fields[4]} |
61 |
GID_NUMBER="$4" |
61 |
else |
62 |
else |
62 |
ldap_result=`ldapsearch -x -ZZ -D "$ldap_hostdn" -y /etc/machine.secret -LLL uid="$username" homeDirectory uidNumber gidNumber` |
63 |
ldap_result=`ldapsearch -x -ZZ -D "$ldap_hostdn" -y /etc/machine.secret -LLL uid="$username" homeDirectory uidNumber gidNumber` |
63 |
if [ $? = 0 ]; then |
64 |
if [ $? = 0 ]; then |
64 |
HOME=`echo "$ldap_result" | grep ^homeDirectory | sed -e 's|homeDirectory: ||'` |
65 |
HOME=$(sed -ne 's|^homeDirectory: ||p' <<<"$ldap_result") |
65 |
UID_NUMBER=`echo "$ldap_result" | grep ^uidNumber | sed -e 's|uidNumber: ||'` |
66 |
UID_NUMBER=$(sed -ne 's|^uidNumber: ||p' <<<"$ldap_result") |
66 |
GID_NUMBER=`echo "$ldap_result" | grep ^gidNumber | sed -e 's|gidNumber: ||'` |
67 |
GID_NUMBER=$(sed -ne 's|^gidNumber: ||p' <<<"$ldap_result") |
67 |
else |
68 |
else |
68 |
pw_entry=`grep ^"$username" /etc/passwd` |
69 |
pw_entry=`grep ^"$username" /etc/passwd` |
69 |
|
70 |
|
70 |
for i in 1 2 3 4 5 6; do |
71 |
OIFS="$IFS" |
71 |
pw_fields[$i]=`echo $pw_entry | awk -F ':' '{ print $'$i' }'` |
72 |
IFS=':' |
72 |
done |
73 |
set -- $pw_entry |
|
|
74 |
IFS="$OIFS" |
73 |
|
75 |
|
74 |
HOME=${pw_fields[6]} |
76 |
HOME="$6" |
75 |
UID_NUMBER=${pw_fields[3]} |
77 |
UID_NUMBER="$3" |
76 |
GID_NUMBER=${pw_fields[4]} |
78 |
GID_NUMBER="$4" |
77 |
fi |
79 |
fi |
78 |
|
80 |
|
79 |
fi |
81 |
fi |
|
105 |
# doesn't exist yet, this will fail. We could probably login via krsh before |
107 |
# doesn't exist yet, this will fail. We could probably login via krsh before |
106 |
# to make sure it exists and mount it then. Running krsh here isn't pretty |
108 |
# to make sure it exists and mount it then. Running krsh here isn't pretty |
107 |
# though. |
109 |
# though. |
108 |
homeattr=`ldapsearch -x -ZZ -D "$ldap_hostdn" -y /etc/machine.secret -z 1 "(&(objectClass=posixAccount)(objectClass=automount)(uid=$USER))" automountInformation -LLL | /usr/bin/ldapsearch-wrapper | sed -n 's/automountInformation: \(.*\)/\1/p'` |
110 |
homeattr=`ldapsearch -x -ZZLLL -D "$ldap_hostdn" -y /etc/machine.secret -z 1 "(&(objectClass=posixAccount)(objectClass=automount)(uid=$USER))" automountInformation -LLL | /usr/bin/ldapsearch-wrapper | sed -n 's/automountInformation: \(.*\)/\1/p'` |
109 |
if [ -z "$homeattr" ]; then |
111 |
if [ -z "$homeattr" ]; then |
110 |
eval "$(univention-config-registry shell server/role)" |
112 |
server_role=$(univention-config-registry get server/role) |
111 |
|
113 |
|
112 |
if [ -z "$server_role" ]; then |
114 |
if [ -z "$server_role" ]; then |
113 |
# Thin Client |
115 |
# Thin Client |
|
119 |
fi |
121 |
fi |
120 |
# Otherwise look for servers |
122 |
# Otherwise look for servers |
121 |
eval "$(univention-config-registry shell ldap/mydn)" |
123 |
eval "$(univention-config-registry shell ldap/mydn)" |
122 |
for server in `univention_policy_result -D "$ldap_hostdn" -y /etc/machine.secret -s "$ldap_mydn" | grep "univentionFileServer" | sed -e 's|.*univentionFileServer=||' | sed -e 's|"||g'`; do |
124 |
for server in `univention_policy_result -D "$ldap_hostdn" -y /etc/machine.secret -s "$ldap_mydn" | sed -en 's|"||g;s|.*univentionFileServer=||p'`; do |
123 |
if [ -n "$server" ]; then |
125 |
if [ -n "$server" ]; then |
124 |
# mount in heartbeat-situations needs to be done from /ha/home, but normally /home fits |
126 |
# mount in heartbeat-situations needs to be done from /ha/home, but normally /home fits |
125 |
if mount -t nfs $server:/home /ramdisk/home || mount -t nfs $server:/ha/home /ramdisk/home |
127 |
if mount -t nfs $server:/home /ramdisk/home || mount -t nfs $server:/ha/home /ramdisk/home |
|
162 |
REALHOME="$HOME" |
164 |
REALHOME="$HOME" |
163 |
fi |
165 |
fi |
164 |
|
166 |
|
165 |
host=`echo "$homeattr" | sed 's/.* \([^ ]*\):\([^ ]*\)/\1/'` |
167 |
host=`sed 's/.* \([^ ]*\):\([^ ]*\)/\1/' <<<"$homeattr"` |
166 |
path=`echo "$homeattr" | sed 's/.* \([^ ]*\):\([^ ]*\)/\2/'` |
168 |
path=`sed 's/.* \([^ ]*\):\([^ ]*\)/\2/' <<<"$homeattr"` |
167 |
if [ -z "$host" ] || [ -z "$path" ]; then |
169 |
if [ -z "$host" ] || [ -z "$path" ]; then |
168 |
logger "Bad information in LDAP. Not mounting home directory." |
170 |
logger "Bad information in LDAP. Not mounting home directory." |
169 |
exit 1 |
171 |
exit 1 |