Patch for tmda-ofmipd: home script without --vdomains-path
Lloyd Zusman <[email protected]>
| Newsgroups | gmane.mail.spam.tmda.devel,gmane.mail.spam.tmda.user |
|---|---|
| Message-ID | <[email protected]> |
I'm using Courier as my MTA, and I want to use tmda-ofmipd with it. However, the LDAP-based virtual user mechanism I'm using with Courier differs from the type that is used by VPopMail. Specifically, it doesn't make use of any kind of virtual domains file that is normally specified by the --vdomains-path command-line argument to tmda-ofmipd. I already have a script that works the same as a standard --vhome-script, in that it takes a user id and domain name on the command line, and it prints Courier's idea of the mail user's home directory to stdout. However, I can't pass that script name to the standard version of tmda-ofmipd, because --vhome-script processing fails without a valid virtual domain file that must also be passed in via --vdomains-path. I don't want to complicate my system adminstration duties by creating and maintaining such a virtual domain file, just so that tmda-ofmipd will work for me. In order to fix this problem, I have patched tmda-ofmipd in the following way ... I have specified a new command-line argument: -H <script> --home-script <script> This works the same as --vhome-script, but it doesn't cause tmda-ofmipd to go through the VPopMail logic, and therefore, it doesn't make use of any --vdomains-path file. This option can only be used when --vhome-script and --vdomains-file are not present on the command line. The specified script will be invoked with a user id and domain name as its two command line arguments, and it writes the mail home directory to stdout. The tmda-ofmipd program will use this script to figure out a user's mail home, which is the place in which it looks for that user's .tmda subdirectory. The reason I did this via a new command-line argument is to minimize the restructuring of tmda-ofmipd, and to make the new version backwards compatible with the old one. The patch is attached. Feedback is welcome and desired. Thanks. -- Lloyd Zusman [email protected] God bless you.
tmda-ofmipd.patch
(text/x-patch, 6.6 KB)
*** tmda-ofmipd.orig Sat Sep 17 13:25:41 2005
--- tmda-ofmipd Sat Sep 17 13:53:27 2005
***************
*** 172,175 ****
--- 172,180 ----
the --vhome-script parameter above.
+ -H <script>
+ --home-script <script>
+ Just like --vhome-script, above, but doesn't require the use
+ --vdomains-path, which is mandatory for that option.
+
-t <script>
--throttle-script <script>
***************
*** 225,229 ****
--- 230,236 ----
connections = 20
vhomescript = None
+ homescript = None
vdomainspath = '/var/qmail/control/virtualdomains'
+ vdomainspathspecified = None
throttlescript = None
***************
*** 270,290 ****
try:
opts, args = getopt.getopt(sys.argv[1:],
! 'p:u:a:R:A:Fc:C:dVhfbPS:v:t:', ['proxyport=',
! 'username=',
! 'authfile=',
! 'remoteauth=',
! 'authprog=',
! 'fallback',
! 'configdir=',
! 'connections=',
! 'debug',
! 'version',
! 'help',
! 'foreground',
! 'background',
! 'pure-proxy',
! 'vhome-script=',
! 'vdomains-path=',
! 'throttle-script='])
except getopt.error, msg:
usage(1, msg)
--- 277,298 ----
try:
opts, args = getopt.getopt(sys.argv[1:],
! 'p:u:a:R:A:Fc:C:dVhfbPS:H:v:t:', ['proxyport=',
! 'username=',
! 'authfile=',
! 'remoteauth=',
! 'authprog=',
! 'fallback',
! 'configdir=',
! 'connections=',
! 'debug',
! 'version',
! 'help',
! 'foreground',
! 'background',
! 'pure-proxy',
! 'vhome-script=',
! 'home-script=',
! 'vdomains-path=',
! 'throttle-script='])
except getopt.error, msg:
usage(1, msg)
***************
*** 353,363 ****
elif opt in ('-S', '--vhome-script'):
vhomescript = arg
elif opt in ('-v', '--vdomains-path'):
vdomainspath = arg
elif opt in ('-t', '--throttle-script'):
throttlescript = arg
! if vhomescript and configdir:
! msg = "WARNING: --vhome-script and --config-dir are incompatible." + \
" Ignoring --config-dir."
configdir = None
--- 361,378 ----
elif opt in ('-S', '--vhome-script'):
vhomescript = arg
+ elif opt in ('-H', '--home-script'):
+ homescript = arg
elif opt in ('-v', '--vdomains-path'):
+ vdomainspathspecified = True
vdomainspath = arg
elif opt in ('-t', '--throttle-script'):
throttlescript = arg
! if (vhomescript or vdomainspathspecified) and homescript:
! raise ValueError, \
! '--home-script is not compatible with --vhome-script or --vdomains-path.'
!
! if configdir and (vhomescript or homescript):
! msg = "WARNING: --[v]home-script and --config-dir are incompatible." + \
" Ignoring --config-dir."
configdir = None
***************
*** 1136,1143 ****
will have his mail tagged using his TMDA config file."""
def process_message(self, peer, mailfrom, rcpttos, data, auth_username):
if configdir is None:
# ~user/.tmda/
! tmda_configdir = os.path.join(os.path.expanduser
! ('~' + auth_username), '.tmda')
else:
tmda_configdir = os.path.join(os.path.expanduser
--- 1151,1171 ----
will have his mail tagged using his TMDA config file."""
def process_message(self, peer, mailfrom, rcpttos, data, auth_username):
+ if homescript:
+ userinfo = auth_username.split('@', 1)
+ user = userinfo[0]
+ if len(userinfo) > 1:
+ domain = userinfo[1]
+ else:
+ domain = ''
+ homedir = Util.getvuserhomedir(user, domain, homescript)
+ print >> DEBUGSTREAM, 'user homedir: "%s"' % (homedir,)
+ # This is so "~" will work in the .tmda/* files.
+ os.environ['HOME'] = homedir
+ else:
+ # This is so "~" will always work in the .tmda/* files.
+ os.environ['HOME'] = Util.gethomedir(auth_username)
if configdir is None:
# ~user/.tmda/
! tmda_configdir = os.path.join(os.environ['HOME'], '.tmda')
else:
tmda_configdir = os.path.join(os.path.expanduser
***************
*** 1153,1158 ****
inject_cmd = [inject_path, '-c', tmda_configfile] + rcpttos
- # This is so "~" will always work in the .tmda/* files.
- os.environ['HOME'] = Util.gethomedir(auth_username)
# If running as uid 0, fork the tmda-inject process, and
# then change UID and GID to the authenticated user.
--- 1181,1184 ----