blob: 6ed7ea9ce76c40e0b3d59fdb41f12b33bd66d22e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
#!/usr/bin/env bash
##
# Prompt for a shell then uses change_shell() to set the loginShell of LDAP users
#
# arguments:
# None
kchsh() {
shells=('/usr/bin/bash'
'/usr/bin/zsh')
dn=$(ldapwhoami -Q)
if [[ $? -eq 0 ]]; then
dn="${dn:3}"
else
dn="uid=$USER,ou=users,dc=kyriasis,dc=com"
fi
printf "Current shell for %s is %s\n" $dn $(get_current_shell $dn)
select shell in "${shells[@]}" quit;
do
if [[ $shell == "quit" ]]; then
printf "Shell not changed.\n"
break
else
change_shell "$dn" "$shell"
if [[ $? -eq 0 ]]; then
printf "Shell changed successfully.\n"
else
printf "Uh-oh...\n"
fi
break
fi
done
}
##
# Changes the current loginShell for an LDAP user
#
# arguments:
# $1: The distinguished name of the entry to change
# $2: The shell to change to
change_shell() {
ldapmodify -Q >>/dev/null <<-EOF
dn: $1
changetype: modify
replace: loginShell
loginShell: $2
EOF
}
##
# Get the current loginShell for an LDAP user
#
# arguments:
# $1: The distinguished name of the entry to get the shell for
get_current_shell() {
local shell="$(ldapsearch -Q -b "$1" loginShell | grep '^loginShell')"
printf "%s\n" "${shell:12}"
}
kchsh
|