当前位置: 首页>>代码示例>>Python>>正文


Python os.setegid方法代码示例

本文整理汇总了Python中os.setegid方法的典型用法代码示例。如果您正苦于以下问题:Python os.setegid方法的具体用法?Python os.setegid怎么用?Python os.setegid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在os的用法示例。


在下文中一共展示了os.setegid方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: run_as

# 需要导入模块: import os [as 别名]
# 或者: from os import setegid [as 别名]
def run_as(pwent, umask=0o22):
    """Drop privileges to given user's password entry, and set up
    environment. Assumes the parent process has root privileges.
    """
    os.umask(umask)
    home = pwent.home
    try:
      os.chdir(home)
    except OSError:
      os.chdir("/")
    # drop privs to user
    os.setgroups(pwent.groups)
    os.setgid(pwent.gid)
    os.setegid(pwent.gid)
    os.setuid(pwent.uid)
    os.seteuid(pwent.uid)
    os.environ["HOME"] = home
    os.environ["USER"] = pwent.name
    os.environ["LOGNAME"] = pwent.name
    os.environ["SHELL"] = pwent.shell
    os.environ["PATH"] = "/bin:/usr/bin:/usr/local/bin"
    return None 
开发者ID:kdart,项目名称:pycopia,代码行数:24,代码来源:proctools.py

示例2: drop_privileges

# 需要导入模块: import os [as 别名]
# 或者: from os import setegid [as 别名]
def drop_privileges(uid, gid):
    try:
        if gid is not None:
            os.setgid(gid)
            os.setegid(gid)
            logger.debug('switched uid to {}'.format(uid))

        if uid is not None:
            os.setuid(uid)
            os.seteuid(uid)
            logger.debug('switched gid to {}'.format(gid))

        logger.info('running as {} ({}:{})'.format(args.user, uid, gid))
    except Exception as e:
        logger.error('dropping privileges failed: {}'.format(e))
        return False

    return True 
开发者ID:christgau,项目名称:wsdd,代码行数:20,代码来源:wsdd.py

示例3: callIntoPAM

# 需要导入模块: import os [as 别名]
# 或者: from os import setegid [as 别名]
def callIntoPAM(service, user, conv):
    """A testing hook.
    """
    pam = PAM.pam()
    pam.start(service)
    pam.set_item(PAM.PAM_USER, user)
    pam.set_item(PAM.PAM_CONV, conv)
    gid = os.getegid()
    uid = os.geteuid()
    os.setegid(0)
    os.seteuid(0)
    try:
        pam.authenticate() # these will raise
        pam.acct_mgmt()
        return 1
    finally:
        os.setegid(gid)
        os.seteuid(uid) 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:20,代码来源:pamauth.py

示例4: su

# 需要导入模块: import os [as 别名]
# 或者: from os import setegid [as 别名]
def su() -> None:
    """
    switch user. Useful when starting localslackirc
    as a service as root user.
    """
    if sys.platform.startswith('win'):
        return

    # Nothing to do, already not root
    if os.getuid() != 0:
        return

    username = environ.get('PROCESS_OWNER', 'nobody')
    userdata = pwd.getpwnam(username)
    os.setgid(userdata.pw_gid)
    os.setegid(userdata.pw_gid)
    os.setuid(userdata.pw_uid)
    os.seteuid(userdata.pw_uid) 
开发者ID:ltworf,项目名称:localslackirc,代码行数:20,代码来源:irc.py

示例5: get_cdv_change_code

# 需要导入模块: import os [as 别名]
# 或者: from os import setegid [as 别名]
def get_cdv_change_code():
    
        # cdv won't run on the dev machines as root.  nfs does not allow
        # root access to mounted drives.  --Dave
        if os.getuid() == 0 and getuid_for_path(".") != 0:
            seteugid_to_login()
    
        # fragile. XXXX
        l = os.popen("cdv history -c 1").readlines()[0].split(" ")
        if os.getuid() == 0:
            os.seteuid(0)
            #os.setegid(oldgid)
    
        l = [x.strip() for x in l if x.strip() != '']  # remove empty strings.
        x,code,x,x,x,x,dow,mo,dom,t,y = l
        month = "%.2d" % (months.index(mo)+1)
        dom = "%.2d" % int(dom)    # single digit day of month like 3 becomes 03
        t = "_".join(t.split(':')) # convert ':' to underscores in time.
        return y+"_"+month+"_"+dom+"_"+t+"_"+code 
开发者ID:kenorb-contrib,项目名称:BitTorrent,代码行数:21,代码来源:bdistutils.py

示例6: validatePublicKey

# 需要导入模块: import os [as 别名]
# 或者: from os import setegid [as 别名]
def validatePublicKey(self, pubKeyString):
        home = os.path.expanduser('~%s/.ssh/' % self.name)
        if home[0] == '~': # couldn't expand
            return defer.fail(Unauthorized('not valid user'))
        uid, gid = os.geteuid(), os.getegid()
        ouid, ogid = pwd.getpwnam(self.name)[2:4]
        os.setegid(ogid)
        os.seteuid(ouid)
        for file in ['authorized_keys', 'authorized_keys2']:
            if os.path.exists(home+file):
                lines = open(home+file).readlines()
                for l in lines:
                    try:
                        l2 = l.split()
                        if len(l2) < 2:
                            continue
                        if base64.decodestring(l2[1])==pubKeyString:
                            os.setegid(gid)
                            os.seteuid(uid)
                            return defer.succeed('')
                    except binascii.Error:
                        pass # we caught an ssh1 key
        os.setegid(gid)
        os.seteuid(uid)
        return defer.fail(error.ConchError('not valid key')) 
开发者ID:kenorb-contrib,项目名称:BitTorrent,代码行数:27,代码来源:identity.py

示例7: test_setegid

# 需要导入模块: import os [as 别名]
# 或者: from os import setegid [as 别名]
def test_setegid(self):
        if os.getuid() != 0:
            self.assertRaises(os.error, os.setegid, 0)
        self.assertRaises(TypeError, os.setegid, 'not an int')
        self.assertRaises(OverflowError, os.setegid, 1<<32) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:7,代码来源:test_os.py

示例8: setUp

# 需要导入模块: import os [as 别名]
# 或者: from os import setegid [as 别名]
def setUp(self):
            safe_rmpath(TESTFN)
            TestProcess.setUp(self)
            os.setegid(1000)
            os.seteuid(1000) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:7,代码来源:test_process.py

示例9: tearDown

# 需要导入模块: import os [as 别名]
# 或者: from os import setegid [as 别名]
def tearDown(self):
            os.setegid(self.PROCESS_UID)
            os.seteuid(self.PROCESS_GID)
            TestProcess.tearDown(self) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:6,代码来源:test_process.py

示例10: setUp

# 需要导入模块: import os [as 别名]
# 或者: from os import setegid [as 别名]
def setUp(self):
            super().setUp()
            os.setegid(1000)
            os.seteuid(1000) 
开发者ID:giampaolo,项目名称:psutil,代码行数:6,代码来源:test_process.py

示例11: tearDown

# 需要导入模块: import os [as 别名]
# 或者: from os import setegid [as 别名]
def tearDown(self):
            os.setegid(self.PROCESS_UID)
            os.seteuid(self.PROCESS_GID)
            super().tearDown() 
开发者ID:giampaolo,项目名称:psutil,代码行数:6,代码来源:test_process.py

示例12: test_setegid

# 需要导入模块: import os [as 别名]
# 或者: from os import setegid [as 别名]
def test_setegid(self):
                if os.getuid() != 0:
                    self.assertRaises(os.error, os.setegid, 0)
                self.assertRaises(OverflowError, os.setegid, 1<<32) 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:6,代码来源:test_os.py

示例13: impersonate_user

# 需要导入模块: import os [as 别名]
# 或者: from os import setegid [as 别名]
def impersonate_user(self, username, password):
            """Change process effective user/group ids to reflect
            logged in user.
            """
            try:
                pwdstruct = pwd.getpwnam(username)
            except KeyError:
                raise AuthorizerError(self.msg_no_such_user)
            else:
                os.setegid(pwdstruct.pw_gid)
                os.seteuid(pwdstruct.pw_uid) 
开发者ID:aliyun,项目名称:oss-ftp,代码行数:13,代码来源:authorizers.py

示例14: terminate_impersonation

# 需要导入模块: import os [as 别名]
# 或者: from os import setegid [as 别名]
def terminate_impersonation(self, username):
            """Revert process effective user/group IDs."""
            os.setegid(PROCESS_GID)
            os.seteuid(PROCESS_UID) 
开发者ID:aliyun,项目名称:oss-ftp,代码行数:6,代码来源:authorizers.py

示例15: test_setegid

# 需要导入模块: import os [as 别名]
# 或者: from os import setegid [as 别名]
def test_setegid(self):
        if os.getuid() != 0:
            self.assertRaises(os.error, os.setegid, 0)
        self.assertRaises(OverflowError, os.setegid, 1<<32) 
开发者ID:aliyun,项目名称:oss-ftp,代码行数:6,代码来源:test_os.py


注:本文中的os.setegid方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。