def drop_privileges(user, call_setsid=True):
 if (os.geteuid() == 0):
  groups = [g.gr_gid for g in grp.getgrall() if (user in g.gr_mem)]
  os.setgroups(groups)
 user = pwd.getpwnam(user)
 os.setgid(user[3])
 os.setuid(user[2])
 os.environ['HOME'] = user[5]
 if call_setsid:
  try:
   os.setsid()
  except OSError:
   pass
 os.chdir('/')
 os.umask(18)

def drop_privileges ( user , call_setsid = True ) : if ( os . geteuid ( ) == 0 ) : groups = [ g . gr_gid for g in grp . getgrall ( ) if ( user in g . gr_mem ) ] os . setgroups ( groups ) user = pwd . getpwnam ( user ) os . setgid ( user [ 3 ] ) os . setuid ( user [ 2 ] ) os . environ [ 'HOME' ] = user [ 5 ] if call_setsid : try : os . setsid ( ) except OSError : pass os . chdir ( '/' ) os . umask ( 18 )
drops privileges to selected user .