Skip to content

Commit 407cfd1

Browse files
committed
Issue #9168: now smtpd is able to bind privileged port.
2 parents 0cc147e + 711f87c commit 407cfd1

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

Lib/smtpd.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,16 @@ def parseargs():
678678
if __name__ == '__main__':
679679
options = parseargs()
680680
# Become nobody
681+
classname = options.classname
682+
if "." in classname:
683+
lastdot = classname.rfind(".")
684+
mod = __import__(classname[:lastdot], globals(), locals(), [""])
685+
classname = classname[lastdot+1:]
686+
else:
687+
import __main__ as mod
688+
class_ = getattr(mod, classname)
689+
proxy = class_((options.localhost, options.localport),
690+
(options.remotehost, options.remoteport))
681691
if options.setuid:
682692
try:
683693
import pwd
@@ -691,16 +701,6 @@ def parseargs():
691701
if e.errno != errno.EPERM: raise
692702
print('Cannot setuid "nobody"; try running with -n option.', file=sys.stderr)
693703
sys.exit(1)
694-
classname = options.classname
695-
if "." in classname:
696-
lastdot = classname.rfind(".")
697-
mod = __import__(classname[:lastdot], globals(), locals(), [""])
698-
classname = classname[lastdot+1:]
699-
else:
700-
import __main__ as mod
701-
class_ = getattr(mod, classname)
702-
proxy = class_((options.localhost, options.localport),
703-
(options.remotehost, options.remoteport))
704704
try:
705705
asyncore.loop()
706706
except KeyboardInterrupt:

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,8 @@ Core and Builtins
322322
Library
323323
-------
324324

325+
- Issue #9168: now smtpd is able to bind privileged port.
326+
325327
- Issue #12529: fix cgi.parse_header issue on strings with double-quotes and
326328
semicolons together. Patch by Ben Darnell and Petri Lehtinen.
327329

0 commit comments

Comments
 (0)