Start > Linux Tips & Trics > XMail to CDB-database for use with qpsmtpd

XMail to CDB-database for use with qpsmtpd

1 oktober 2007

This scripts creates a Constant DataBase file. We use this to interact with the qpsmtpd plugin check_validrcptto_cdb.

  1.  
  2. #!/bin/bash
  3.  
  4. #this script creates a cdb file from xmail users and their aliases
  5.  
  6. OUTPUTFILE=/var/lib/qpsmtpd/rcptto/validrcptto.cdb
  7. XMAILROOT=/etc/xmail
  8.  
  9. #no more settings beyond this point
  10.  
  11. TMPFILE=$(mktemp /tmp/email2cdb.XXXXXXXXXX)
  12.  
  13. [ -d "$(dirname $OUTPUTFILE)" ] || {
  14.     echo "directory for OUTPUTFILE $OUTPUTFILE does not exists"
  15.     exit 3
  16. }
  17.  
  18. [ -f "$TMPFILE" ] && rm $TMPFILE
  19. touch $TMPFILE || {
  20.     echo "can not create $TMPFILE"
  21.     exit 9
  22. }
  23.  
  24. #paranoia strikes again:
  25. #chmod og-r $TMPFILE
  26.  
  27. #list all email boxes:
  28. cat $XMAILROOT/mailusers.tab \
  29.     | sed ‘s/"//g’ \
  30.     | awk ‘{print $2 "@" $1 "\t" $2 "@" $1}’ \
  31.     | sed ‘s/^*//’ \
  32.     | sed ‘s/*//’ >> $TMPFILE
  33.  
  34. #list aliases
  35. cat $XMAILROOT/aliases.tab \
  36.     | sed ‘s/"//g’ \
  37.     | awk ‘{print $2 "@" $1 "\t" $3 "@" $1}’ \
  38.     | sed ‘s/^*//’ \
  39.     | sed ‘s/*//’ >> $TMPFILE
  40.  
  41. #create cdb file
  42. cdb -cm $CDBOPTIONS  $OUTPUTFILE $TMPFILE || {
  43.     echo "can not create cdb file $OUTPUTFILE FROM $TMPFILE"
  44.     echo "WARNING: I did not remove $TMPFILE for debug purposes"
  45.     exit 9
  46. }
  47.  
  48. #cleanup:
  49. rm $TMPFILE
  50. exit 0
Categorie├źn:Linux Tips & Trics Tags:
  1. Nog geen reacties.
Geen reacties mogelijk.