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


Python util.runAsEffectiveUser函数代码示例

本文整理汇总了Python中twisted.python.util.runAsEffectiveUser函数的典型用法代码示例。如果您正苦于以下问题:Python runAsEffectiveUser函数的具体用法?Python runAsEffectiveUser怎么用?Python runAsEffectiveUser使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: _testUIDGIDSwitch

 def _testUIDGIDSwitch(self, startUID, startGID, wantUID, wantGID, expectedUIDSwitches, expectedGIDSwitches):
     """
     Helper method checking the calls to C{os.seteuid} and C{os.setegid}
     made by L{util.runAsEffectiveUser}, when switching from startUID to
     wantUID and from startGID to wantGID.
     """
     self.mockos.euid = startUID
     self.mockos.egid = startGID
     util.runAsEffectiveUser(wantUID, wantGID, self._securedFunction, startUID, startGID, wantUID, wantGID)
     self.assertEquals(self.mockos.seteuidCalls, expectedUIDSwitches)
     self.assertEquals(self.mockos.setegidCalls, expectedGIDSwitches)
     self.mockos.seteuidCalls = []
     self.mockos.setegidCalls = []
开发者ID:hortonworkstest,项目名称:hortonworks-sandbox,代码行数:13,代码来源:test_util.py

示例2: checkKey

 def checkKey(self, credentials):
     """
     Retrieve files containing authorized keys and check against user
     credentials.
     """
     ouid, ogid = self._userdb.getpwnam(credentials.username)[2:4]
     for filepath in self.getAuthorizedKeysFiles(credentials):
         if not filepath.exists():
             continue
         try:
             lines = filepath.open()
         except IOError, e:
             if e.errno == errno.EACCES:
                 lines = runAsEffectiveUser(ouid, ogid, filepath.open)
             else:
                 raise
         for l in lines:
             l2 = l.split()
             if len(l2) < 2:
                 continue
             try:
                 if base64.decodestring(l2[1]) == credentials.blob:
                     return True
             except binascii.Error:
                 continue
开发者ID:12019,项目名称:OpenWrt_Luci_Lua,代码行数:25,代码来源:checkers.py

示例3: test_takesKeyworkArguments

 def test_takesKeyworkArguments(self):
     """
     L{util.runAsEffectiveUser} pass the keyword parameters to the given
     function.
     """
     result = util.runAsEffectiveUser(0, 0, lambda x, y=1, z=1: x*y*z, 2, z=3)
     self.assertEquals(result, 6)
开发者ID:P13RR3,项目名称:FrostCore,代码行数:7,代码来源:test_util.py

示例4: test_takeParameters

 def test_takeParameters(self):
     """
     L{util.runAsEffectiveUser} pass the given parameters to the given
     function.
     """
     result = util.runAsEffectiveUser(0, 0, lambda x: 2*x, 3)
     self.assertEquals(result, 6)
开发者ID:P13RR3,项目名称:FrostCore,代码行数:7,代码来源:test_util.py

示例5: test_forwardResult

 def test_forwardResult(self):
     """
     L{util.runAsEffectiveUser} forwards the result obtained by calling the
     given function
     """
     result = util.runAsEffectiveUser(0, 0, lambda: 1)
     self.assertEquals(result, 1)
开发者ID:P13RR3,项目名称:FrostCore,代码行数:7,代码来源:test_util.py

示例6: checkKey

 def checkKey(self, credentials):
     """
     Retrieve the keys of the user specified by the credentials, and check
     if one matches the blob in the credentials.
     """
     sshDir = os.path.expanduser(
         os.path.join("~", credentials.username, ".ssh"))
     if sshDir.startswith('~'): # didn't expand
         return False
     uid, gid = os.geteuid(), os.getegid()
     ouid, ogid = pwd.getpwnam(credentials.username)[2:4]
     for name in ['authorized_keys2', 'authorized_keys']:
         filename = os.path.join(sshDir, name)
         if not os.path.exists(filename):
             continue
         try:
             lines = open(filename)
         except IOError, e:
             if e.errno == errno.EACCES:
                 lines = runAsEffectiveUser(ouid, ogid, open, filename)
             else:
                 raise
         for l in lines:
             l2 = l.split()
             if len(l2) < 2:
                 continue
             try:
                 if base64.decodestring(l2[1]) == credentials.blob:
                     return True
             except binascii.Error:
                 continue
开发者ID:AnthonyNystrom,项目名称:YoGoMee,代码行数:31,代码来源:checkers.py

示例7: getPrivateKeys

 def getPrivateKeys(self):
     from twisted.python import log
     from twisted.python.util import runAsEffectiveUser 
     from twisted.conch.ssh import keys
     import os, errno
     privateKeys = {}
     for filename in os.listdir(self.dataRoot):
         if filename[:9] == 'ssh_host_' and filename[-4:]=='_key':
             fullPath = os.path.join(self.dataRoot, filename)
             try:
                 key = keys.Key.fromFile(fullPath)
             except IOError, e:
                 if e.errno == errno.EACCES:
                     # Not allowed, let's switch to root
                     key = runAsEffectiveUser(0, 0, keys.Key.fromFile, fullPath)
                     keyType = keys.objectType(key.keyObject)
                     privateKeys[keyType] = key
                 else:
                     raise
             except Exception, e:
                 log.msg('bad private key file %s: %s' % (filename, e))
             else:
                 if key: #Just to add this Fucking Line !
                     keyType = keys.objectType(key.keyObject)
                     privateKeys[keyType] = key
开发者ID:RobinDavid,项目名称:pystack,代码行数:25,代码来源:sshserver.py

示例8: _shadowGetByName

def _shadowGetByName(username):
    """
    Look up a user in the /etc/shadow database using the spwd module. If it is
    not available, return L{None}.

    @param username: the username of the user to return the shadow database
        information for.
    @type username: L{str}
    """
    if spwd is not None:
        f = spwd.getspnam
    else:
        return None
    return runAsEffectiveUser(0, 0, f, username)
开发者ID:esabelhaus,项目名称:secret-octo-dubstep,代码行数:14,代码来源:checkers.py

示例9: _shadowGetByName

def _shadowGetByName(username):
    """
    Look up a user in the /etc/shadow database using the spwd or shadow
    modules.  If neither module is available, return None.

    @param username: the username of the user to return the shadow database
        information for.
    """
    if spwd is not None:
        f = spwd.getspnam
    elif shadow is not None:
        f = shadow.getspnam
    else:
        return None
    return runAsEffectiveUser(0, 0, f, username)
开发者ID:12019,项目名称:OpenWrt_Luci_Lua,代码行数:15,代码来源:checkers.py

示例10: getPrivateKeys

 def getPrivateKeys(self):
     """
     Return the server private keys.
     """
     privateKeys = {}
     for filename in os.listdir(self.dataRoot):
         if filename[:9] == 'ssh_host_' and filename[-4:]=='_key':
             fullPath = os.path.join(self.dataRoot, filename)
             try:
                 key = keys.Key.fromFile(fullPath)
             except IOError, e:
                 if e.errno == errno.EACCES:
                     # Not allowed, let's switch to root
                     key = runAsEffectiveUser(0, 0, keys.Key.fromFile, fullPath)
                     keyType = keys.objectType(key.keyObject)
                     privateKeys[keyType] = key
                 else:
                     raise
             except Exception, e:
                 log.msg('bad private key file %s: %s' % (filename, e))
             else:
                 keyType = keys.objectType(key.keyObject)
                 privateKeys[keyType] = key
开发者ID:Almad,项目名称:twisted,代码行数:23,代码来源:factory.py


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