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

Python smb_conf.SambaConf类代码示例

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

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



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

示例1: changeUserPasswd

    def changeUserPasswd(self, uid, passwd, oldpasswd = None, bind = False):
        """
        change SAMBA user password

        @param uid: user name
        @type  uid: str

        @param passwd: non encrypted password
        @type  passwd: str
        """

        # Don't update the password if we are using smbk5passwd
        conf = SambaConf()
        if conf.isValueTrue(conf.getContent("global", "ldap passwd sync")) in (0, 1):
            userdn = self.searchUserDN(uid)
            r = AF().log(PLUGIN_NAME, AA.SAMBA_CHANGE_USER_PASS, [(userdn,AT.USER)])
            # If the passwd has been encoded in the XML-RPC stream, decode it
            if isinstance(passwd, xmlrpclib.Binary):
                passwd = str(passwd)
            s = self.l.search_s(userdn, ldap.SCOPE_BASE)
            c, old = s[0]
            new = old.copy()
            new['sambaLMPassword'] = [smbpasswd.lmhash(passwd)]
            new['sambaNTPassword'] = [smbpasswd.nthash(passwd)]
            new['sambaPwdLastSet'] = [str(int(time()))]
            # Update LDAP
            modlist = ldap.modlist.modifyModlist(old, new)
            self.l.modify_s(userdn, modlist)
            self.runHook("samba.changeuserpasswd", uid, passwd)
            r.commit()

        return 0
开发者ID:sebastiendu,项目名称:mmc,代码行数:32,代码来源:smb_ldap.py


示例2: backupShare

def backupShare(share, media, login):
    """
    Launch as a background process the backup of a share
    """
    r = AF().log(PLUGIN_NAME, AA.SAMBA_BACKUP_SHARE, [(share, AT.SHARE), (login, AT.USER)], media)
    config = BasePluginConfig("base")
    cmd = os.path.join(config.backuptools, "backup.sh")
    if share == "homes":
        #  FIXME: Maybe we should have a configuration directive to tell that
        #  all users home are stored into /home
        savedir = "/home/"
    else:
        smbObj = SambaConf(SambaConfig("samba").samba_conf_file)
        savedir = smbObj.getContent(share, "path")
    # Run backup process in background
    shlaunchBackground(
        cmd
        + " "
        + share
        + " "
        + savedir
        + " "
        + config.backupdir
        + " "
        + login
        + " "
        + media
        + " "
        + config.backuptools,
        "backup share " + share,
        progressBackup,
    )
    r.commit()
    return os.path.join(config.backupdir, "%s-%s-%s" % (login, share, strftime("%Y%m%d")))
开发者ID:pavelpromin,项目名称:mmc,代码行数:34,代码来源:__init__.py


示例3: modShare

def modShare(
    name, path, comment, usergroups, users, permAll, admingroups, browseable=True, av=0, customparameters=None
):
    smbObj = SambaConf(SambaConfig("samba").samba_conf_file)
    smbObj.addShare(
        name, path, comment, usergroups, users, permAll, admingroups, browseable, av, customparameters, True
    )
    smbObj.save()
开发者ID:pavelpromin,项目名称:mmc,代码行数:8,代码来源:__init__.py


示例4: updateDomainNextRID

 def updateDomainNextRID(self):
     """
     Increment sambaNextRID
     """
     conf = SambaConf()
     domain = conf.getContent("global", "workgroup")
     result = self.search("(&(objectClass=sambaDomain)(sambaDomainName=%s))" % domain)
     dn, old = result[0][0]
     # update the old attributes
     new = old.copy()
     new['sambaNextRid'] = [ str(int(old['sambaNextRid'][0]) + 1) ]
     modlist = ldap.modlist.modifyModlist(old, new)
     self.l.modify_s(dn, modlist)
开发者ID:sebastiendu,项目名称:mmc,代码行数:13,代码来源:smb_ldap.py


示例5: getDomain

    def getDomain(self):
        """
        Return the LDAP sambaDomainName entry corresponding to the domain specified in smb.conf

        @return: the sambaDomainName entry
        @rtype: dict
        """
        conf = SambaConf()
        domain = conf.getContent("global", "workgroup")
        result = self.search("(&(objectClass=sambaDomain)(sambaDomainName=%s))" % domain)
        if len(result): ret = result[0][0][1]
        else: ret = {}
        return ret
开发者ID:sebastiendu,项目名称:mmc,代码行数:13,代码来源:smb_ldap.py


示例6: delShare

def delShare(name, file):
    smbObj = SambaConf(SambaConfig("samba").samba_conf_file)
    smbObj.delShare(name, file)
    smbObj.save()
    return 0
开发者ID:pavelpromin,项目名称:mmc,代码行数:5,代码来源:__init__.py


示例7: isProfiles

def isProfiles():
    """ check if global profiles are setup """
    smbObj = SambaConf(SambaConfig("samba").samba_conf_file)
    return smbObj.isProfiles()
开发者ID:pavelpromin,项目名称:mmc,代码行数:4,代码来源:__init__.py


示例8: isPdc

def isPdc():
    try:
        smbObj = SambaConf(SambaConfig("samba").samba_conf_file)
    except:
        raise Exception("Can't open SAMBA configuration file")
    return smbObj.isPdc()
开发者ID:pavelpromin,项目名称:mmc,代码行数:6,代码来源:__init__.py


示例9: smbInfoSave

def smbInfoSave(options):
    """save information about global section"""
    smbObj = SambaConf(SambaConfig("samba").samba_conf_file)
    return smbObj.smbInfoSave(options)
开发者ID:pavelpromin,项目名称:mmc,代码行数:4,代码来源:__init__.py


示例10: getSmbInfo

def getSmbInfo():
    """get main information of global section"""
    smbObj = SambaConf(SambaConfig("samba").samba_conf_file)
    return smbObj.getSmbInfo()
开发者ID:pavelpromin,项目名称:mmc,代码行数:4,代码来源:__init__.py


示例11: shareCustomParameters

def shareCustomParameters(name):
    """get an array of additionnal params about a share"""
    smbObj = SambaConf(SambaConfig("samba").samba_conf_file)
    return smbObj.shareCustomParameters(name)
开发者ID:pavelpromin,项目名称:mmc,代码行数:4,代码来源:__init__.py


示例12: shareInfo

def shareInfo(name):
    """get an array of information about a share"""
    smbObj = SambaConf(SambaConfig("samba").samba_conf_file)
    return smbObj.shareInfo(name)
开发者ID:pavelpromin,项目名称:mmc,代码行数:4,代码来源:__init__.py


示例13: addShare

def addShare(name, path, comment, perms, admingroups, recursive=True, browseable=True, av=0, customparameters=None):
    smbObj = SambaConf(SambaConfig("samba").samba_conf_file)
    smbObj.addShare(name, path, comment, perms, admingroups, recursive, browseable, av, customparameters)
    smbObj.save()
开发者ID:inkhey,项目名称:mmc,代码行数:4,代码来源:__init__.py


示例14: activate

def activate():
    """
     this function define if the module "base" can be activated.
     @return: return True if this module can be activate
     @rtype: boolean
    """
    config = SambaConfig("samba")

    if config.disabled:
        logger.info("samba plugin disabled by configuration.")
        return False

    if config.defaultSharesPath:
        if config.defaultSharesPath.endswith("/"):
            logger.error("Trailing / is not allowed in defaultSharesPath")
            return False
        if not os.path.exists(config.defaultSharesPath):
            logger.error("The default shares path '%s' does not exist" % config.defaultSharesPath)
            return False

    for cpath in config.authorizedSharePaths:
        if cpath.endswith("/"):
            logger.error("Trailing / is not allowed in authorizedSharePaths")
            return False
        if not os.path.exists(cpath):
            logger.error("The authorized share path '%s' does not exist" % cpath)
            return False

    # Verify if samba conf file exist
    conf = config.samba_conf_file
    if not os.path.exists(conf):
        logger.error(conf + " does not exist")
        return False

    # validate smb.conf
    smbconf = SambaConf()
    if not smbconf.validate(conf):
        logger.error("SAMBA configuration file is not valid")
        return False

    # For each share, test if it sharePath exists
    for share in getDetailedShares():
        shareName = share[0]
        infos = shareInfo(shareName)
        if infos:
            sharePath = infos["sharePath"]
            if sharePath and not "%" in sharePath and not os.path.exists(sharePath):
                # only show error
                logger.error("The samba share path '%s' does not exist." % sharePath)
        else:
            return False

    try:
        ldapObj = ldapUserGroupControl()
    except ldap.INVALID_CREDENTIALS:
        logger.error("Can't bind to LDAP: invalid credentials.")
        return False

    # Test if the Samba LDAP schema is available in the directory
    try:
        schema = ldapObj.getSchema("sambaSamAccount")
        if len(schema) <= 0:
            logger.error("Samba schema is not included in LDAP directory")
            return False
    except:
        logger.exception("invalid schema")
        return False

    # Verify if init script exist
    init = config.samba_init_script
    if not os.path.exists(init):
        logger.error(init + " does not exist")
        return False

    # If SAMBA is defined as a PDC, make extra checks
    if smbconf.isPdc():
        samba = SambaLDAP()
        # Create SAMBA computers account OU if it doesn't exist
        head, path = samba.baseComputersDN.split(",", 1)
        ouName = head.split("=")[1]
        samba.addOu(ouName, path)
        # Check that a sambaDomainName entry is in LDAP directory
        domainInfos = samba.getDomain()
        # Set domain policy
        samba.setDomainPolicy()
        if not domainInfos:
            logger.error(
                "Can't find sambaDomainName entry in LDAP for domain %s. Please check your SAMBA LDAP configuration."
                % smbconf.getContent("global", "workgroup")
            )
            return False
        smbconfbasesuffix = smbconf.getContent("global", "ldap suffix")
        if not smbconfbasesuffix:
            logger.error("SAMBA 'ldap suffix' option is not setted.")
            return False
        if ldap.explode_dn(samba.baseDN) != ldap.explode_dn(smbconfbasesuffix):
            logger.error("SAMBA 'ldap suffix' option is not equal to MMC 'baseDN' option.")
            return False
        # Check that SAMBA and MMC given OU are in sync
        for option in [
#.........这里部分代码省略.........
开发者ID:pavelpromin,项目名称:mmc,代码行数:101,代码来源:__init__.py


示例15: getACLOnShare

def getACLOnShare(name):
    smbObj = SambaConf(SambaConfig("samba").samba_conf_file)
    return smbObj.getACLOnShare(name)
开发者ID:pavelpromin,项目名称:mmc,代码行数:3,代码来源:__init__.py


示例16: getDetailedShares

def getDetailedShares():
    """Get a complete array of information about all shares"""
    smbObj = SambaConf(SambaConfig("samba").samba_conf_file)
    resList = smbObj.getDetailedShares()
    return resList
开发者ID:pavelpromin,项目名称:mmc,代码行数:5,代码来源:__init__.py


示例17: setDomainPolicy

    def setDomainPolicy(self):
        """
        Try to sync the samba domain policy with the default OpenLDAP policy
        """
        conf = SambaConf()
        domain = conf.getContent("global", "workgroup")
        result = self.search("(&(objectClass=sambaDomain)(sambaDomainName=%s))" % domain)
        dn, old = result[0][0]
        # update the old attributes
        new = old.copy()
        # get the default ppolicy values
        try:
            from mmc.plugins.ppolicy import getDefaultPPolicy
        except ImportError:
            # don't try to change samba policies
            pass
        else:
            try:
                ppolicy = getDefaultPPolicy()[1]
            except (ldap.NO_SUCH_OBJECT, IOError):
                # no default password policy set
                pass
            else:
                # samba default values
                options = {
                    "sambaMinPwdLength": ["5"],
                    "sambaMaxPwdAge": ["-1"],
                    "sambaMinPwdAge": ["0"],
                    "sambaPwdHistoryLength": ["0"],
                    "sambaLockoutThreshold": ["0"],
                    "sambaLockoutDuration": ["30"]
                }
                if 'pwdMinLength' in ppolicy:
                    options['sambaMinPwdLength'] = ppolicy['pwdMinLength']
                if 'pwdMaxAge' in ppolicy and ppolicy['pwdMaxAge'][0] != "0":
                    options['sambaMaxPwdAge'] = ppolicy['pwdMaxAge']
                if 'pwdMinAge' in ppolicy:
                    options['sambaMinPwdAge'] = ppolicy['pwdMinAge']
                if 'pwdInHistory' in ppolicy:
                    options['sambaPwdHistoryLength'] = ppolicy['pwdInHistory']
                if 'pwdLockout' in ppolicy and ppolicy['pwdLockout'][0] == "TRUE" \
                    and 'pwdMaxFailure' in ppolicy and ppolicy['pwdMaxFailure'][0] != '0':
                        if 'pwdLockoutDuration' in ppolicy:
                            options['sambaLockoutDuration'] = ppolicy['pwdLockoutDuration']
                        options['sambaLockoutThreshold'] = ppolicy['pwdMaxFailure']
                else:
                    options['sambaLockoutThreshold'] = ["0"]

                update = False
                for attr, value in options.iteritems():
                    # Update attributes if needed
                    if new[attr] != value:
                        new[attr] = value
                        update = True

                if update:
                    modlist = ldap.modlist.modifyModlist(old, new)
                    try:
                        self.l.modify_s(dn, modlist)
                    except ldap.UNDEFINED_TYPE:
                        # don't fail if attributes don't exist
                        pass
                    logger.info("SAMBA domain policy synchronized with password policies")
开发者ID:sebastiendu,项目名称:mmc,代码行数:63,代码来源:smb_ldap.py


示例18: serialize

 def serialize(self):
     smbconf = SambaConf()
     data = {'sessions': len(smbconf.getConnected()),
             'shares': len(smbconf.getSmbStatus())}
     return data
开发者ID:AnatomicJC,项目名称:mmc,代码行数:5,代码来源:panel.py


示例19: getDetailedShares

def getDetailedShares(filter="", start=0, end=None):
    """Get a complete array of information about all shares"""
    smbObj = SambaConf(SambaConfig("samba").samba_conf_file)
    resList = smbObj.getDetailedShares(filter, start, end)
    return resList
开发者ID:neoclust,项目名称:pulse,代码行数:5,代码来源:__init__.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python config.PluginConfig类代码示例发布时间:2022-05-27
下一篇:
Python mirror_api.MirrorApi类代码示例发布时间: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