123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- #!/bin/bash
- TYPE="$1"
- USER="$2"
- PASS="$3"
- if [ "$USER" = "" -o "$PASS" = "" -o "$TYPE" = "" ]; then
- echo "syntax: $0 user-type login pass" >&2
- exit 1
- fi
- if [ "$TYPE" != "student" -a "$TYPE" != "teacher" ]; then
- echo "Unknown user type: $TYPE" >&2
- exit 4
- fi
- TYPE="${TYPE//[\/]/}"
- USER="${USER//[\/]/}"
- PASS="${PASS//[\/]/}"
- TMPDIR="$(mktemp -d)"
- if [ "$TMPDIR" = "" ]; then
- echo "error: cannot create temporary directory" >&2
- exit 2
- fi
- LDAP_LOGINPASS=($(awk -F '"' '{if ($1 == "masterDN=") {LOGIN=$2} if ($1 == "masterPw=") {PASS=$2}} END {print LOGIN"\t"PASS}' < /etc/smbldap-tools/smbldap_bind.conf))
- LDAP_LOGIN="${LDAP_LOGINPASS[0]}"
- LDAP_PASS="${LDAP_LOGINPASS[1]}"
- if [ "$LDAP_LOGIN" = "" -o "$LDAP_PASS" = "" ]; then
- echo "error: cannot parse ldap login/pass from /etc/smbldap-tools/smbldap_bind.conf" >&2
- exit 3
- fi
- smbldap-useradd "$USER"
- sed -e "s/@USER@/$USER/g" -e "s/@PASS@/$PASS/g" < /usr/local/share/ldap-workarounds/samba-adduser-"$TYPE"-fix-add.ldif > "$TMPDIR"/fix.ldif
- ldapmodify -x -D "$LDAP_LOGIN" -w "$LDAP_PASS" -f "$TMPDIR"/fix.ldif -h ldap.ut.mephi.ru
- sed -e "s/@USER@/$USER/g" -e "s/@PASS@/$PASS/g" < /usr/local/share/ldap-workarounds/samba-adduser-"$TYPE"-fix-replace.ldif > "$TMPDIR"/fix.ldif
- ldapmodify -x -D "$LDAP_LOGIN" -w "$LDAP_PASS" -f "$TMPDIR"/fix.ldif -h ldap.ut.mephi.ru
- echo "$PASS" | smbldap-passwd -p "$USER"
- #smbpasswd "$USER" -w "$PASS"
- rm -f "$TMPDIR"/{,.}* 2>/dev/null
- rmdir "$TMPDIR"
- exit 0
|