#!/bin/sh
# Samba-TNG                                             passwd2ldif.sh
# --------------------------------------------------------------------
#
# Convert SAM-Dump to Smb-importable LDIF-Format
# Attention: Password will be username!
#

# --------------------------------------------------------------------
. ./prefs
SRC=$1
DST=$2
suffix="$usersuffix"

# --------------------------------------------------------------------
if [ "$DST" = "" ];then
	echo ""
	echo "usage: $(basename $0) <pdc-src-file> <ldif-dst-file>"
	echo ""
	exit 0
fi

# --------------------------------------------------------------------
echo "Converting <$SRC> to <$DST>..."

cat $SRC \
	|sed "s/ß/ss/g" \
	|sed "s/ä/ae/g" \
	|sed "s/ö/oe/g" \
	|sed "s/ü/ue/g" \
	|sed "s/Ä/Ae/g" \
	|sed "s/Ö/Oe/g" \
	|sed "s/Ü/Ue/g" \
	|awk -F: 'BEGIN{
}
{
	
	name=$1
	uid=$3
	gid=$4
	desc=$5
	home=$6
	shell=$7	

	print "dn: uid="name", "suf
	print "uid: "name
	print "cn: "desc
	print "objectClass: top"
	print "objectClass: account"
	print "objectClass: posixAccount"
	print "objectClass: shadowAccount"
	print "userPassword: "name
	print "homeDirectory: "home
	print "uidNumber: "uid
	print "gidNumber: "gid
	print "loginShell: "shell
	print ""
}
END{
}' suf="$suffix" > $DST

echo "Done."

# --------------------------------------------------------------------
