Exemple #1
0
 def get_config(self):
     config = ConfigNode('service.smb', self.configstore).__getstate__()
     if 'filemask' in config:
         if config['filemask'] is not None:
             config['filemask'] = get_unix_permissions(config['filemask'])
     if 'dirmask' in config:
         if config['dirmask'] is not None:
             config['dirmask'] = get_unix_permissions(config['dirmask'])
     return config
Exemple #2
0
 def get_config(self):
     config = ConfigNode('service.smb', self.configstore).__getstate__()
     if 'filemask' in config:
         if config['filemask'] is not None:
             config['filemask'] = get_unix_permissions(config['filemask'])
     if 'dirmask' in config:
         if config['dirmask'] is not None:
             config['dirmask'] = get_unix_permissions(config['dirmask'])
     return config
Exemple #3
0
 def get_config(self):
     config = ConfigNode("service.smb", self.configstore).__getstate__()
     if "filemask" in config:
         if config["filemask"] is not None:
             config["filemask"] = get_unix_permissions(config["filemask"])
     if "dirmask" in config:
         if config["dirmask"] is not None:
             config["dirmask"] = get_unix_permissions(config["dirmask"])
     return config
Exemple #4
0
def read_value(value, tv=ValueType.STRING):
    if value is None:
        if tv == ValueType.ARRAY:
            return []

        if tv == ValueType.DICT:
            return {}

        if tv == ValueType.SET:
            return set()

        return value

    if tv in (ValueType.STRING, ValueType.TEXT_FILE):
        return str(value)

    if tv in (ValueType.NUMBER, ValueType.SIZE):
        return int(value)

    if tv == ValueType.BOOLEAN:
        if type(value) is bool:
            return value

        if str(value).lower() in ('true', 'yes', 'on', '1'):
            return True

        if str(value).lower() in ('false', 'no', 'off', '0'):
            return False

    if tv == ValueType.SET:
        if type(value) is list:
            return set(value)
        else:
            return {value}

    if tv == ValueType.ARRAY:
        if type(value) is list:
            return value
        else:
            return [value]

    if tv == ValueType.DICT:
        if type(value) is dict:
            return value

    if tv == ValueType.OCTNUMBER:
        return int(value)

    if tv == ValueType.PERMISSIONS:
        if isinstance(value, str):
            value = string_to_int(value)
        return get_unix_permissions(value)

    if tv == ValueType.PASSWORD:
        return str(value)

    raise ValueError(
        _("Invalid value '{0}', expected {1} value".format(
            value,
            str(tv).split('ValueType.')[-1].lower())))
Exemple #5
0
def read_value(value, tv=ValueType.STRING):
    if value is None:
        if tv == ValueType.SET:
            return []

        if tv == ValueType.DICT:
            return {}

        return value

    if tv in (ValueType.STRING, ValueType.STRING_HEAD):
        return str(value)

    if tv in (ValueType.NUMBER, ValueType.SIZE):
        return int(value)

    if tv == ValueType.BOOLEAN:
        if type(value) is bool:
            return value

        if str(value).lower() in ('true', 'yes', 'on', '1'):
            return True

        if str(value).lower() in ('false', 'no', 'off', '0'):
            return False

    if tv == ValueType.SET:
        if type(value) is list:
            return value
        else:
            return [value]

    if tv == ValueType.DICT:
        if type(value) is dict:
            return value

    if tv == ValueType.OCTNUMBER:
        return int(value)

    if tv == ValueType.PERMISSIONS:
        if isinstance(value, str):
            value = string_to_int(value)
        return get_unix_permissions(value)

    raise ValueError(_("Invalid value '{0}', expected {1} value".format(value, str(tv).split('ValueType.')[-1].lower())))
Exemple #6
0
def collect(datastore, path):
    try:
        st = os.stat(path, follow_symlinks=False)
    except OSError as err:
        # Can't access the file - delete index entry
        datastore.delete('fileindex', path)
        return

    volume = path.split('/')[2]
    datastore.upsert('fileindex', path, {
        'id': path,
        'volume': volume,
        'type': get_type(st),
        'atime': datetime.utcfromtimestamp(st.st_atime),
        'mtime': datetime.utcfromtimestamp(st.st_mtime),
        'ctime': datetime.utcfromtimestamp(st.st_ctime),
        'uid': st.st_uid,
        'gid': st.st_gid,
        'permissions': get_unix_permissions(st.st_mode)
    })
Exemple #7
0
def configure_params(smb, ad=False):
    conf = smbconf.SambaConfig('registry')
    conf.transaction_start()
    try:
        conf['netbios name'] = smb['netbiosname'][0]
        conf['netbios aliases'] = ' '.join(smb['netbiosname'][1:])

        if smb['bind_addresses']:
            conf['interfaces'] = ' '.join(['127.0.0.1'] +
                                          smb['bind_addresses'])

        conf['server string'] = smb['description']
        conf['server max protocol'] = smb['max_protocol']
        conf['server min protocol'] = smb['min_protocol']
        conf['encrypt passwords'] = 'yes'
        conf['dns proxy'] = 'no'
        conf['strict locking'] = 'no'
        conf['oplocks'] = 'yes'
        conf['deadtime'] = '15'
        conf['max log size'] = '51200'
        conf['max open files'] = str(
            int(get_sysctl('kern.maxfilesperproc')) - 25)
        conf['logging'] = 'logd@10'

        if 'filemask' in smb:
            if smb['filemask'] is not None:
                conf['create mode'] = perm_to_oct_string(
                    get_unix_permissions(smb['filemask'])).zfill(4)

        if 'dirmask' in smb:
            if smb['dirmask'] is not None:
                conf['directory mode'] = perm_to_oct_string(
                    get_unix_permissions(smb['dirmask'])).zfill(4)

        conf['load printers'] = 'no'
        conf['printing'] = 'bsd'
        conf['printcap name'] = '/dev/null'
        conf['disable spoolss'] = 'yes'
        conf['getwd cache'] = 'yes'
        conf['guest account'] = smb['guest_user']
        conf['map to guest'] = 'Bad User'
        conf['obey pam restrictions'] = yesno(smb['obey_pam_restrictions'])
        conf['directory name cache size'] = '0'
        conf['kernel change notify'] = 'no'
        conf['panic action'] = '/usr/local/libexec/samba/samba-backtrace'
        conf['nsupdate command'] = '/usr/local/bin/samba-nsupdate -g'
        conf['ea support'] = 'yes'
        conf['store dos attributes'] = 'yes'
        conf['lm announce'] = 'yes'
        conf['hostname lookups'] = yesno(smb['hostlookup'])
        conf['unix extensions'] = yesno(smb['unixext'])
        conf['time server'] = yesno(smb['time_server'])
        conf['null passwords'] = yesno(smb['empty_password'])
        conf['acl allow execute always'] = yesno(smb['execute_always'])
        conf['acl check permissions'] = 'true'
        conf['dos filemode'] = 'yes'
        conf['multicast dns register'] = yesno(smb['zeroconf'])
        conf['passdb backend'] = 'freenas'
        conf['log level'] = str(getattr(LogLevel, smb['log_level']).value)
        conf['username map'] = '/usr/local/etc/smbusers'
        conf['idmap config *: range'] = '90000001-100000000'
        conf['idmap config *: backend'] = 'tdb'
        conf['ntlm auth'] = 'yes'

        if not ad:
            conf['local master'] = yesno(smb['local_master'])
            conf['server role'] = 'auto'
            conf['workgroup'] = smb['workgroup']
    except BaseException as err:
        logger.error('Failed to update samba registry: {0}'.format(err),
                     exc_info=True)
        conf.transaction_cancel()
    else:
        conf.transaction_commit()
Exemple #8
0
def configure_params(smb, ad=False):
    conf = smbconf.SambaConfig('registry')
    conf.transaction_start()
    try:
        conf['netbios name'] = smb['netbiosname'][0]
        conf['netbios aliases'] = ' '.join(smb['netbiosname'][1:])

        if smb['bind_addresses']:
            conf['interfaces'] = ' '.join(['127.0.0.1'] + smb['bind_addresses'])

        conf['server string'] = smb['description']
        conf['server max protocol'] = smb['max_protocol']
        conf['server min protocol'] = smb['min_protocol']
        conf['encrypt passwords'] = 'yes'
        conf['dns proxy'] = 'no'
        conf['strict locking'] = 'no'
        conf['oplocks'] = 'yes'
        conf['deadtime'] = '15'
        conf['max log size'] = '51200'
        conf['max open files'] = str(int(get_sysctl('kern.maxfilesperproc')) - 25)
        conf['logging'] = 'logd@10'

        if 'filemask' in smb:
            if smb['filemask'] is not None:
                conf['create mode'] = perm_to_oct_string(get_unix_permissions(smb['filemask'])).zfill(4)

        if 'dirmask' in smb:
            if smb['dirmask'] is not None:
                conf['directory mode'] = perm_to_oct_string(get_unix_permissions(smb['dirmask'])).zfill(4)

        conf['load printers'] = 'no'
        conf['printing'] = 'bsd'
        conf['printcap name'] = '/dev/null'
        conf['disable spoolss'] = 'yes'
        conf['getwd cache'] = 'yes'
        conf['guest account'] = smb['guest_user']
        conf['map to guest'] = 'Bad User'
        conf['obey pam restrictions'] = yesno(smb['obey_pam_restrictions'])
        conf['directory name cache size'] = '0'
        conf['kernel change notify'] = 'no'
        conf['panic action'] = '/usr/local/libexec/samba/samba-backtrace'
        conf['nsupdate command'] = '/usr/local/bin/samba-nsupdate -g'
        conf['ea support'] = 'yes'
        conf['store dos attributes'] = 'yes'
        conf['lm announce'] = 'yes'
        conf['hostname lookups'] = yesno(smb['hostlookup'])
        conf['unix extensions'] = yesno(smb['unixext'])
        conf['time server'] = yesno(smb['time_server'])
        conf['null passwords'] = yesno(smb['empty_password'])
        conf['acl allow execute always'] = yesno(smb['execute_always'])
        conf['acl check permissions'] = 'true'
        conf['dos filemode'] = 'yes'
        conf['multicast dns register'] = yesno(smb['zeroconf'])
        conf['passdb backend'] = 'freenas'
        conf['log level'] = str(getattr(LogLevel, smb['log_level']).value)
        conf['username map'] = '/usr/local/etc/smbusers'
        conf['idmap config *: range'] = '90000001-100000000'
        conf['idmap config *: backend'] = 'tdb'
        conf['ntlm auth'] = 'yes'

        if not ad:
            conf['local master'] = yesno(smb['local_master'])
            conf['server role'] = 'auto'
            conf['workgroup'] = smb['workgroup']
    except BaseException as err:
        logger.error('Failed to update samba registry: {0}'.format(err), exc_info=True)
        conf.transaction_cancel()
    else:
        conf.transaction_commit()
Exemple #9
0
 def get_config(self):
     config = ConfigNode('service.tftpd', self.configstore).__getstate__()
     config['umask'] = get_unix_permissions(config['umask'])
     return config
Exemple #10
0
def configure_params(smb, ad=False):
    conf = smbconf.SambaConfig("registry")
    conf["netbios name"] = smb["netbiosname"][0]
    conf["netbios aliases"] = " ".join(smb["netbiosname"][1:])

    if smb["bind_addresses"]:
        conf["interfaces"] = " ".join(["127.0.0.1"] + smb["bind_addresses"])

    conf["server string"] = smb["description"]
    conf["encrypt passwords"] = "yes"
    conf["dns proxy"] = "no"
    conf["strict locking"] = "no"
    conf["oplocks"] = "yes"
    conf["deadtime"] = "15"
    conf["max log size"] = "51200"
    conf["max open files"] = str(int(get_sysctl("kern.maxfilesperproc")) - 25)

    if smb["syslog"]:
        conf["syslog only"] = "yes"
        conf["syslog"] = "1"

    if "filemask" in smb:
        if smb["filemask"] is not None:
            conf["create mode"] = perm_to_oct_string(get_unix_permissions(smb["filemask"])).zfill(4)

    if "dirmask" in smb:
        if smb["dirmask"] is not None:
            conf["directory mode"] = perm_to_oct_string(get_unix_permissions(smb["dirmask"])).zfill(4)

    conf["load printers"] = "no"
    conf["printing"] = "bsd"
    conf["printcap name"] = "/dev/null"
    conf["disable spoolss"] = "yes"
    conf["getwd cache"] = "yes"
    conf["guest account"] = smb["guest_user"]
    conf["map to guest"] = "Bad User"
    conf["obey pam restrictions"] = yesno(smb["obey_pam_restrictions"])
    conf["directory name cache size"] = "0"
    conf["kernel change notify"] = "no"
    conf["panic action"] = "/usr/local/libexec/samba/samba-backtrace"
    conf["nsupdate command"] = "/usr/local/bin/samba-nsupdate -g"
    conf["ea support"] = "yes"
    conf["store dos attributes"] = "yes"
    conf["lm announce"] = "yes"
    conf["hostname lookups"] = yesno(smb["hostlookup"])
    conf["unix extensions"] = yesno(smb["unixext"])
    conf["time server"] = yesno(smb["time_server"])
    conf["null passwords"] = yesno(smb["empty_password"])
    conf["acl allow execute always"] = yesno(smb["execute_always"])
    conf["acl check permissions"] = "true"
    conf["dos filemode"] = "yes"
    conf["multicast dns register"] = yesno(smb["zeroconf"])
    conf["passdb backend"] = "freenas"
    conf["log level"] = str(getattr(LogLevel, smb["log_level"]).value)
    conf["username map"] = "/usr/local/etc/smbusers"
    conf["idmap config *: range"] = "90000001-100000000"
    conf["idmap config *: backend"] = "tdb"

    if not ad:
        conf["local master"] = yesno(smb["local_master"])
        conf["server role"] = "auto"
        conf["workgroup"] = smb["workgroup"]
Exemple #11
0
 def get_config(self):
     config = ConfigNode('service.tftpd', self.configstore).__getstate__()
     config['umask'] = get_unix_permissions(config['umask'])
     return config
Exemple #12
0
def read_value(value, tv=ValueType.STRING):
    if value is None:
        if tv == ValueType.ARRAY:
            return []

        if tv == ValueType.DICT:
            return {}

        if tv == ValueType.SET:
            return set()

        if tv == ValueType.BOOLEAN:
            return False

        return value

    if tv in (ValueType.STRING, ValueType.TEXT_FILE):
        return str(value)

    if tv in (ValueType.NUMBER, ValueType.SIZE):
        return int(value)

    if tv == ValueType.BOOLEAN:
        if type(value) is bool:
            return value

        if str(value).lower() in ('true', 'yes', 'on', '1'):
            return True

        if str(value).lower() in ('false', 'no', 'off', '0'):
            return False

    if tv == ValueType.SET:
        if type(value) is list:
            return set(value)
        else:
            return {value}

    if tv == ValueType.ARRAY:
        if type(value) is list:
            return value
        else:
            return [value]

    if tv == ValueType.DICT:
        if type(value) is dict:
            return value

    if tv == ValueType.OCTNUMBER:
        return int(value)

    if tv == ValueType.PERMISSIONS:
        if isinstance(value, str):
            value = string_to_int(value)
        else:
            if value > 0o777:
                raise ValueError('Invalid permissions format - use octal notation with maximum value of 0o777')

        return get_unix_permissions(value)

    if tv == ValueType.PASSWORD:
        return Password(str(value))

    raise ValueError(_("Invalid value '{0}', expected {1} value".format(value, str(tv).split('ValueType.')[-1].lower())))