Skip to content

Commit

Permalink
new set uid value in servers
Browse files Browse the repository at this point in the history
  • Loading branch information
joamag committed Oct 20, 2015
1 parent a0b43ac commit db576fe
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/netius/base/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,11 @@ def serve(
ssl = False,
key_file = None,
cer_file = None,
setuid = None,
backlog = 5,
load = True,
start = True,
env = False,
backlog = 5
env = False
):
# processes the various default values taking into account if
# the environment variables are meant to be processed for the
Expand All @@ -124,6 +125,7 @@ def serve(
ssl = self.get_env("SSL", ssl, cast = bool) if env else ssl
key_file = self.get_env("KEY_FILE", key_file) if env else key_file
cer_file = self.get_env("CER_FILE", cer_file) if env else cer_file
setuid = self.get_env("SETUID", setuid, cast = int) if env else setuid
backlog = self.get_env("BACKLOG", backlog, cast = int) if env else backlog

# runs the various extra variable initialization taking into
Expand Down Expand Up @@ -203,6 +205,10 @@ def serve(
self.socket.bind(address)
if type == TCP_TYPE: self.socket.listen(backlog)

# in case the set user id value the user of the current process should
# be changed so that it represents the new (possibly unprivileged user)
if setuid: os.setuid(setuid)

# in case the selected port is zero based, meaning that a randomly selected
# port has been assigned by the bind operation the new port must be retrieved
# and set for the current server instance as the new port (for future reference)
Expand Down

0 comments on commit db576fe

Please sign in to comment.