From cb5a46ac4164c46e120fe1d5242dc66791b50412 Mon Sep 17 00:00:00 2001 From: Stephen Gran Date: Sat, 9 May 2009 13:11:11 +0100 Subject: [PATCH] Do the checks for mail forwarding once at the start --- ud-generate | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/ud-generate b/ud-generate index f22b8de..f2c5c13 100755 --- a/ud-generate +++ b/ud-generate @@ -11,6 +11,7 @@ # Copyright (c) 2008 Mark Hymers # Copyright (c) 2008 Luk Claes # Copyright (c) 2008 Thomas Viehmann +# Copyright (c) 2009 Stephen Gran # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -463,6 +464,25 @@ def GenGroup(l,File): return grouprevmap +def CheckForward(): + global PasswdAttrs + for x in PasswdAttrs: + if x[1].has_key("emailForward") == 0: + continue + + if IsInGroup(x) == 0: + x[1].pop("emailForward") + continue + + # Do not allow people to try to buffer overflow busted parsers + if len(GetAttr(x,"emailForward")) > 200: + x[1].pop("emailForward") + continue + + # Check the forwarding address + if EmailCheck.match(GetAttr(x,"emailForward")) == None: + x[1].pop("emailForward") + # Generate the email forwarding list def GenForward(l,File): F = None @@ -476,16 +496,9 @@ def GenForward(l,File): # Write out the email address for each user for x in PasswdAttrs: - if x[1].has_key("emailForward") == 0 or IsInGroup(x) == 0: - continue - - # Do not allow people to try to buffer overflow busted parsers - if len(GetAttr(x,"emailForward")) > 200: + if x[1].has_key("emailForward") == 0: continue - # Check the forwarding address - if EmailCheck.match(GetAttr(x,"emailForward")) == None: - continue Line = "%s: %s" % (GetAttr(x,"uid"),GetAttr(x,"emailForward")) Line = Sanitize(Line) + "\n" F.write(Line) @@ -513,12 +526,6 @@ def GenAllForward(l,File): # Do not allow people to try to buffer overflow busted parsers Forward = GetAttr(x,"emailForward") - if len(Forward) > 200: - continue - - # Check the forwarding address - if EmailCheck.match(Forward) == None: - continue User = GetAttr(x,"uid") Fdb.write("+%d,%d:%s->%s\n"%(len(User),len(Forward),User,Forward)) @@ -1059,6 +1066,8 @@ for x in PasswdAttrs: PasswdAttrs = filter(lambda x: not x in RetiredUsers, PasswdAttrs) +CheckForward() + SSHFiles = GenSSHShadow(l) GenAllForward(l,GlobalDir+"mail-forward.cdb") GenMarkers(l,GlobalDir+"markers") -- 2.20.1