當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。