Skip to content

Commit a01e80c

Browse files
committed
initial commit
0 parents  commit a01e80c

File tree

4 files changed

+786
-0
lines changed

4 files changed

+786
-0
lines changed

README

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
These are scripts related to LDAP!
2+
3+
migrate_common.ph/migrate_passwd.pl is a script from
4+
https://packages.debian.org/wheezy/migrationtools hacked up to follow
5+
some CClub conventions. It takes an /etc/passwd file and converts it
6+
into an LDIF, "LDAP Import Format".
7+
8+
add_user.sh takes a single /etc/passwd line as a command line
9+
argument, converts it into an LDIF with migrate_passwd.pl, and then
10+
imports it into the CClub LDAP server. If it isn't passed any
11+
arguments, it will grab the last line from
12+
/afs/club.cc.cmu.edu/service/etc/passwd.user and try importing that.
13+
14+
make_user_admin.sh doesn't exist but should eventually.
15+
16+
delete_user.sh doesn't exist but should eventually.

add_user.sh

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/bin/bash
2+
set -o nounset
3+
set -o errexit
4+
5+
LDAP_ACCMAKER_PASSWORD_FILE=/afs/club.cc.cmu.edu/service/ldap/secret/ldap_accmaker_password
6+
LDAP_IMPORT_SCRIPTS_DIR=/afs/club.cc.cmu.edu/service/ldap/import/
7+
8+
LDAP_URL=ldaps://ldap1.club.cc.cmu.edu
9+
LDAP_ADMIN_DN="cn=accmaker,ou=Administrators,ou=TopologyManagement,o=NetscapeRoot"
10+
11+
if [[ -z "$(klist | grep admin)" ]]; then
12+
echo "You need admin kerb credentials"
13+
exit 1
14+
fi
15+
aklog club.cc.cmu.edu
16+
17+
if [[ "$#" == "0" ]]; then
18+
# automagically try to add the most recent user
19+
PASSWD_LINE=$(tail -n 1 /afs/club.cc.cmu.edu/service/etc/passwd.user)
20+
echo "Will try to add the following user to LDAP"
21+
echo "$PASSWD_LINE"
22+
echo "If this is incorrect, press Ctrl-c now."
23+
echo "Then find the correct etc/passwd line for the user you wish"
24+
echo "to add to LDAP and provide it as an argument to this script."
25+
echo "It should be in /afs/club.cc.cmu.edu/service/etc/passwd.user maybe?"
26+
echo "Otherwise, if this is correct, press enter."
27+
read
28+
elif [[ $# -ne 1 ]]; then
29+
echo "Provide a single /etc/passwd line as an argument."
30+
echo "You'll need to quote it."
31+
exit 1
32+
else
33+
PASSWD_LINE=$1
34+
fi
35+
36+
# convert passwd format to LDIF format
37+
# we use our own version of migrate_passwd.pl because we've modified migrate_common.ph with cclub defaults
38+
TMP_LDIF=$(mktemp)
39+
cd $LDAP_IMPORT_SCRIPTS_DIR
40+
./migrate_passwd.pl <(echo "$PASSWD_LINE") $TMP_LDIF
41+
42+
# load LDIF format file into LDAP
43+
ldapadd -x -y $LDAP_ACCMAKER_PASSWORD_FILE -D $LDAP_ADMIN_DN -c -f $TMP_LDIF -H $LDAP_URL
44+
45+
echo "Successfully added user, probably"
46+
47+
### I might use this later, it's a template similar to what's generated by migrate_passwd.pl
48+
### template:
49+
# cat <<_HEREDOC_
50+
# dn: uid=$NEWUSER_USERNAME,ou=users,dc=club,dc=cc,dc=cmu,dc=edu
51+
# uid: $NEWUSER_USERNAME
52+
# cn: $NEWUSER_REALNAME
53+
# sn: $NEWUSER_SURNAME
54+
# objectClass: person
55+
# objectClass: organizationalPerson
56+
# objectClass: inetOrgPerson
57+
# objectClass: account
58+
# objectClass: posixAccount
59+
# objectClass: top
60+
# userPassword: {crypt}K
61+
# loginShell: $NEWUSER_SHELL
62+
# uidNumber: $NEWUSER_UID
63+
# gidNumber: $NEWUSER_GID
64+
# homeDirectory: /afs/club.cc.cmu.edu/usr/$NEWUSER_USERNAME
65+
# gecos: $NEWUSER_REALNAME
66+
# _HEREDOC_

0 commit comments

Comments
 (0)