-
Notifications
You must be signed in to change notification settings - Fork 0
/
add_user.sh
executable file
·65 lines (57 loc) · 2.12 KB
/
add_user.sh
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
65
#!/bin/bash
set -o nounset
set -o errexit
LDAP_ACCMAKER_PASSWORD_FILE=/afs/club.cc.cmu.edu/service/ldap/secret/ldap_accmaker_password
LDAP_URL=ldap://ldap1.club.cc.cmu.edu
LDAP_ADMIN_DN="cn=accmaker,ou=Administrators,ou=TopologyManagement,o=NetscapeRoot"
if [[ -z "$(klist | grep admin)" ]]; then
echo "You need admin kerb credentials"
exit 1
fi
aklog club.cc.cmu.edu
if [[ "$#" == "0" ]]; then
# automagically try to add the most recent user
PASSWD_LINE=$(tail -n 1 /afs/club.cc.cmu.edu/service/etc/passwd.user)
echo "Will try to add the following user to LDAP"
echo "$PASSWD_LINE"
echo "If this is incorrect, press Ctrl-c now."
echo "Then find the correct etc/passwd line for the user you wish"
echo "to add to LDAP and provide it as an argument to this script."
echo "It should be in /afs/club.cc.cmu.edu/service/etc/passwd.user maybe?"
echo "Otherwise, if this is correct, press enter."
read
elif [[ $# -ne 1 ]]; then
echo "Provide a single /etc/passwd line as an argument."
echo "You'll need to quote it."
exit 1
else
PASSWD_LINE=$1
fi
# convert passwd format to LDIF format
# we use our own version of migrate_passwd.pl because we've modified migrate_common.ph with cclub defaults
TMP_LDIF=$(mktemp)
cd $(dirname $(readlink -f $0))
perl -I"$PWD" ./migrate_passwd.pl <(echo "$PASSWD_LINE") $TMP_LDIF
# load LDIF format file into LDAP
ldapadd -x -y $LDAP_ACCMAKER_PASSWORD_FILE -D $LDAP_ADMIN_DN -c -f $TMP_LDIF -H $LDAP_URL
echo "Successfully added user, probably"
### I might use this later, it's a template similar to what's generated by migrate_passwd.pl
### template:
# cat <<_HEREDOC_
# dn: uid=$NEWUSER_USERNAME,ou=users,dc=club,dc=cc,dc=cmu,dc=edu
# uid: $NEWUSER_USERNAME
# cn: $NEWUSER_REALNAME
# sn: $NEWUSER_SURNAME
# objectClass: person
# objectClass: organizationalPerson
# objectClass: inetOrgPerson
# objectClass: account
# objectClass: posixAccount
# objectClass: top
# userPassword: {crypt}K
# loginShell: $NEWUSER_SHELL
# uidNumber: $NEWUSER_UID
# gidNumber: $NEWUSER_GID
# homeDirectory: /afs/club.cc.cmu.edu/usr/$NEWUSER_USERNAME
# gecos: $NEWUSER_REALNAME
# _HEREDOC_