• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python util.runAsEffectiveUser函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python util.sibpath函数代码示例发布时间:2022-05-27
下一篇:
Python util.padTo函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap