Today is my 10.4 revival day. Though I don’t work much with 10.4 systems anymore, today I finally managed to write some articles on Mac OS X Server’s mail functionality, which I tested with 10.4 last summer.
If you work with 10.5 server, you might want to adapt the following to make it work in your environment.
If you have set up your mail server with hundreds or thousands of users, and finally decide to add new email aliases, which are just additional shortnames for your users, you would most likely generate a file with the users’ primary shortnames and the shortnames.
IN my case, I had to add firstname.lastname style aliases to my users, as they wanted email addresses in the form of firstname.lastname@domain.de.
The following script adds the new shortnames to the Open Directory database:
#!/bin/bash
#
# AddAliases 1.0, July 2007, Andre Aulich, www.andre-aulich.de
#
# Let's define some varaiables first:
#
# "USERS" automatically lists all available users in the local
# Open Directory domain. So if you run this script on your
# Open Directory Master, there's no need to touch this line.
# DON'T FORGET TO ENTER THE CORRECT USERNAME AND PASSWORD INTO THE
# NEXT LINE!
ODUSERS=$(dscl -u diradmin -P password /LDAPv3/127.0.0.1/ list /Users)
# "USERLIST" reflects the path to a file with all your users.
# The related file is supposed to hold the current shortname plus
# "firstname.lastname" in one line per user, separated by spaces.
# Example:
# test1 first1.last1
# test2 first2.last2
# test3 first3.last3
USERLIST=UserList
# Here's the script that actually does the work for us:
for i in $ODUSERS
do
# Let's have a look which shortnames this user has currently defined
# in our Open Directory database.
# DON'T FORGET TO ENTER THE CORRECT USERNAME AND PASSWORD INTO THE
# NEXT LINE!
CURRENTSHORTNAMES="$(dscl -u diradmin -P password /LDAPv3/127.0.0.1/ -read /Users/"$i" uid)"
echo "$i has the $CURRENTSHORTNAMES in your Open Directory database."
# Now let's see which shortnames we have in our external file:
NEWUID="$(cat $USERLIST | grep "$i")"
echo "In your USERLIST file this user's shortnames are: $NEWUID"
# If the user's Open Directory shortname does not exist in our
# USERLIST, let's skip this user and don't change her shortnames.
# Otherwise, if our USERLIST contains our user's shortname, let's
# go ahead and update these names:
if [ "$NEWUID" = "" ] ; then
echo "So there's nothing to update for user $i." >> ShortNameChange.log
else
echo "Changing shortnames for user $i to $NEWUID." >> ShortNameChange.log
# Let's extract the firstname-lastname shortname from our external file first:
APPEND=$(echo "$NEWUID" | awk -F" " '{print $2}')
# Now let's actually add the new shortnames.
# DON'T FORGET TO ENTER THE CORRECT USERNAME AND PASSWORD INTO THE
# NEXT LINE!
dscl -u diradmin -P password /LDAPv3/127.0.0.1/ -append /Users/$i uid "$APPEND"
fi
done
Use at your own risk!

