Exemplo n.º 1
0
    def run(self, id):
        share = self.datastore.get_by_id('shares', id)
        self.datastore.delete('shares', id)

        try:
            smb_conf = smbconf.SambaConfig('registry')
            smb_conf.transaction_start()
            try:
                del smb_conf.shares[share['name']]
            except BaseException as err:
                smb_conf.transaction_cancel()
                raise TaskException(
                    errno.EBUSY, 'Failed to update samba configuration: {0}',
                    err)
            else:
                smb_conf.transaction_commit()

            reload_samba()
            drop_share_connections(share['name'])
        except smbconf.SambaConfigException:
            raise TaskException(errno.EFAULT, 'Cannot access samba registry')

        self.dispatcher.dispatch_event('share.smb.changed', {
            'operation': 'delete',
            'ids': [id]
        })
Exemplo n.º 2
0
    def run(self, share):
        normalize(
            share['properties'], {
                'read_only': False,
                'guest_ok': False,
                'guest_only': False,
                'browseable': True,
                'recyclebin': False,
                'show_hidden_files': False,
                'previous_versions': True,
                'vfs_objects': [],
                'hosts_allow': None,
                'hosts_deny': None,
                'extra_parameters': {}
            })

        id = self.datastore.insert('shares', share)
        path = self.dispatcher.call_sync('share.translate_path', id)

        try:
            smb_conf = smbconf.SambaConfig('registry')
            smb_share = smbconf.SambaShare()
            convert_share(self.dispatcher, smb_share, path, share['enabled'],
                          share['properties'])
            smb_conf.shares[share['name']] = smb_share
            reload_samba()
        except smbconf.SambaConfigException:
            raise TaskException(errno.EFAULT, 'Cannot access samba registry')

        self.dispatcher.dispatch_event('share.smb.changed', {
            'operation': 'create',
            'ids': [id]
        })

        return id
Exemplo n.º 3
0
    def run(self, id, updated_fields):
        share = self.datastore.get_by_id('shares', id)
        oldname = share['name']
        newname = updated_fields.get('name', oldname)
        share.update(updated_fields)
        self.datastore.update('shares', id, share)
        path = self.dispatcher.call_sync('share.translate_path', share['id'])

        try:
            smb_conf = smbconf.SambaConfig('registry')
            if oldname != newname:
                del smb_conf.shares[oldname]
                smb_share = smbconf.SambaShare()
                smb_conf.shares[newname] = smb_share

            smb_share = smb_conf.shares[newname]
            convert_share(self.dispatcher, smb_share, path, share['enabled'],
                          share['properties'])
            smb_share.save()
            reload_samba()

            if not share['enabled']:
                drop_share_connections(share['name'])
        except smbconf.SambaConfigException:
            raise TaskException(errno.EFAULT, 'Cannot access samba registry')

        self.dispatcher.dispatch_event('share.smb.changed', {
            'operation': 'update',
            'ids': [id]
        })
Exemplo n.º 4
0
    def run(self, share):
        normalize(share['properties'], {
            'read_only': False,
            'guest_ok': False,
            'guest_only': False,
            'browseable': True,
            'recyclebin': False,
            'show_hidden_files': False,
            'previous_versions': True,
            'vfs_objects': [],
            'hosts_allow': [],
            'hosts_deny': [],
            'users_allow': [],
            'users_deny': [],
            'groups_allow': [],
            'groups_deny': [],
            'full_audit_prefix': '%u|%I|%m|%S',
            'full_audit_priority': 'notice',
            'full_audit_failure': 'connect',
            'full_audit_success': 'open mkdir unlink rmdir rename',
            'case_sensitive': 'AUTO',
            'allocation_roundup_size': 1048576,
            'ea_support': True,
            'store_dos_attributes': True,
            'map_archive': True,
            'map_hidden': False,
            'map_readonly': True,
            'map_system': False,
            'fruit_metadata': 'STREAM'

        })

        id = self.datastore.insert('shares', share)
        path = self.dispatcher.call_sync('share.translate_path', id)

        try:
            smb_conf = smbconf.SambaConfig('registry')
            smb_conf.transaction_start()
            try:
                smb_share = smbconf.SambaShare()
                convert_share(self.dispatcher, smb_share, path, share['enabled'], share['properties'])
                smb_conf.shares[share['name']] = smb_share
            except BaseException as err:
                smb_conf.transaction_cancel()
                raise TaskException(errno.EBUSY, 'Failed to update samba configuration: {0}', err)
            else:
                smb_conf.transaction_commit()

            reload_samba()
        except smbconf.SambaConfigException:
            raise TaskException(errno.EFAULT, 'Cannot access samba registry')

        self.dispatcher.dispatch_event('share.smb.changed', {
            'operation': 'create',
            'ids': [id]
        })

        return id
Exemplo n.º 5
0
    def configure_smb(self, enable):
        workgroup = self.workgroup
        cfg = smbconf.SambaConfig('registry')
        params = {
            'server role': 'member server',
            'local master': 'no',
            'domain master': 'no',
            'preferred master': 'no',
            'domain logons': 'no',
            'workgroup': workgroup,
            'realm': self.parameters['realm'],
            'security': 'ads',
            'winbind cache time': str(self.context.cache_ttl),
            'winbind offline logon': 'yes',
            'winbind enum users': 'no',
            'winbind enum groups': 'no',
            'winbind nested groups': 'yes',
            'winbind use default domain': 'no',
            'winbind refresh tickets': 'no',
            'client use spnego': 'yes',
            'allow trusted domains': 'no',
            'client ldap sasl wrapping':
            self.parameters['sasl_wrapping'].lower(),
            'template shell': '/bin/sh',
            'template homedir': '/home/%U'
        }

        if enable:
            for k, v in params.items():
                logger.debug('Setting samba parameter "{0}" to "{1}"'.format(
                    k, v))
                cfg[k] = v
        else:
            for k in params:
                del cfg[k]

            params = {
                'server role':
                'auto',
                'workgroup':
                self.context.configstore.get('service.smb.workgroup'),
                'local master':
                yesno(self.context.configstore.get('service.smb.local_master'))
            }

            for k, v in params.items():
                logger.debug('Setting samba parameter "{0}" to "{1}"'.format(
                    k, v))
                cfg[k] = v

        self.context.client.call_sync('service.restart', 'smb')
Exemplo n.º 6
0
    def run(self, id):
        share = self.datastore.get_by_id('shares', id)
        self.datastore.delete('shares', id)

        try:
            smb_conf = smbconf.SambaConfig('registry')
            del smb_conf.shares[share['name']]

            reload_samba()
            drop_share_connections(share['name'])
        except smbconf.SambaConfigException:
            raise TaskException(errno.EFAULT, 'Cannot access samba registry')

        self.dispatcher.dispatch_event('share.smb.changed', {
            'operation': 'delete',
            'ids': [id]
        })
Exemplo n.º 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()
Exemplo n.º 8
0
    def configure_smb(self, enable):
        workgroup = self.parameters['realm'].split('.')[0]
        cfg = smbconf.SambaConfig('registry')
        params = {
            'server role':
            'member server',
            'local master':
            'no',
            'domain master':
            'no',
            'preferred master':
            'no',
            'domain logons':
            'no',
            'workgroup':
            workgroup,
            'realm':
            self.parameters['realm'],
            'security':
            'ads',
            'winbind cache time':
            str(self.context.cache_ttl),
            'winbind offline logon':
            'yes',
            'winbind enum users':
            'no',
            'winbind enum groups':
            'no',
            'winbind nested groups':
            'yes',
            'winbind use default domain':
            'no',
            'winbind refresh tickets':
            'no',
            'idmap config *: backend':
            'tdb',
            'idmap config *: range':
            '0-65536',
            'idmap config {0}: backend'.format(workgroup):
            'rid',
            'idmap config {0}: range'.format(workgroup):
            '{0}-{1}'.format(self.uid_min, self.uid_max),
            'client use spnego':
            'yes',
            'allow trusted domains':
            'no',
            'client ldap sasl wrapping':
            'plain',
            'template shell':
            '/bin/sh',
            'template homedir':
            '/home/%U'
        }

        if enable:
            for k, v in params.items():
                logger.debug('Setting samba parameter "{0}" to "{1}"'.format(
                    k, v))
                cfg[k] = v
        else:
            for k in params:
                del cfg[k]

            params = {
                'server role':
                'auto',
                'workgroup':
                self.context.configstore.get('service.smb.workgroup'),
                'local master':
                yesno(self.context.configstore.get('service.smb.local_master'))
            }

            for k, v in params.items():
                logger.debug('Setting samba parameter "{0}" to "{1}"'.format(
                    k, v))
                cfg[k] = v

        #self.context.client.call_sync('service.reload', 'smb', 'reload')
        subprocess.call(['/usr/sbin/service', 'samba_server', 'restart'])
Exemplo n.º 9
0
def _init(dispatcher, plugin):
    plugin.register_schema_definition('ShareSmb', {
        'type': 'object',
        'additionalProperties': False,
        'properties': {
            '%type': {'enum': ['ShareSmb']},
            'comment': {'type': 'string'},
            'read_only': {'type': 'boolean'},
            'guest_ok': {'type': 'boolean'},
            'guest_only': {'type': 'boolean'},
            'browseable': {'type': 'boolean'},
            'recyclebin': {'type': 'boolean'},
            'show_hidden_files': {'type': 'boolean'},
            'previous_versions': {'type': 'boolean'},
            'home_share': {'type': 'boolean'},
            'full_audit_prefix': {'type': 'string'},
            'full_audit_priority': {'type': 'string'},
            'full_audit_failure': {'type': 'string'},
            'full_audit_success': {'type': 'string'},
            'case_sensitive': {'type': 'string', 'enum': ['AUTO', 'YES', 'NO']},
            'allocation_roundup_size': {'type': 'integer'},
            'ea_support': {'type': 'boolean'},
            'store_dos_attributes': {'type': 'boolean'},
            'map_archive': {'type': 'boolean'},
            'map_hidden': {'type': 'boolean'},
            'map_readonly': {'type': 'boolean'},
            'map_system': {'type': 'boolean'},
            'fruit_metadata': {'type': 'string', 'enum': ['STREAM', 'NETATALK']},
            'vfs_objects': {
                'type': 'array',
                'items': {'type': 'string'}
            },
            'hosts_allow': {
                'type': ['array', 'null'],
                'items': {'type': 'string'}
            },
            'hosts_deny': {
                'type': ['array', 'null'],
                'items': {'type': 'string'}
            },
            'users_allow': {
                'type': ['array', 'null'],
                'items': {'type': 'string'}
            },
            'groups_allow': {
                'type': ['array', 'null'],
                'items': {'type': 'string'}
            },
            'users_deny': {
                'type': ['array', 'null'],
                'items': {'type': 'string'}
            },
            'groups_deny': {
                'type': ['array', 'null'],
                'items': {'type': 'string'}
            }
        }
    })

    plugin.register_task_handler("share.smb.create", CreateSMBShareTask)
    plugin.register_task_handler("share.smb.update", UpdateSMBShareTask)
    plugin.register_task_handler("share.smb.delete", DeleteSMBShareTask)
    plugin.register_task_handler("share.smb.import", ImportSMBShareTask)
    plugin.register_task_handler("share.smb.terminate_connection", TerminateSMBConnectionTask)
    plugin.register_provider("share.smb", SMBSharesProvider)
    plugin.register_event_type('share.smb.changed')

    # Sync samba registry with our database
    smb_conf = smbconf.SambaConfig('registry')
    smb_conf.transaction_start()
    try:
        smb_conf.shares.clear()

        for s in dispatcher.datastore.query_stream('shares', ('type', '=', 'smb')):
            smb_share = smbconf.SambaShare()
            path = dispatcher.call_sync('share.translate_path', s['id'])
            convert_share(dispatcher, smb_share, path, s['enabled'], s.get('properties', {}))
            smb_conf.shares[s['name']] = smb_share
    except BaseException as err:
        logger.error('Failed to update samba registry: {0}'.format(err), exc_info=True)
        smb_conf.transaction_cancel()
    else:
        smb_conf.transaction_commit()
Exemplo n.º 10
0
def _init(dispatcher, plugin):
    plugin.register_schema_definition(
        'share-smb', {
            'type': 'object',
            'additionalProperties': False,
            'properties': {
                '%type': {
                    'enum': ['share-smb']
                },
                'comment': {
                    'type': 'string'
                },
                'read_only': {
                    'type': 'boolean'
                },
                'guest_ok': {
                    'type': 'boolean'
                },
                'guest_only': {
                    'type': 'boolean'
                },
                'browseable': {
                    'type': 'boolean'
                },
                'recyclebin': {
                    'type': 'boolean'
                },
                'show_hidden_files': {
                    'type': 'boolean'
                },
                'previous_versions': {
                    'type': 'boolean'
                },
                'vfs_objects': {
                    'type': 'array',
                    'items': {
                        'type': 'string'
                    }
                },
                'hosts_allow': {
                    'type': ['array', 'null'],
                    'items': {
                        'type': 'string'
                    }
                },
                'hosts_deny': {
                    'type': ['array', 'null'],
                    'items': {
                        'type': 'string'
                    }
                },
                'extra_parameters': {
                    'type': 'object',
                    'additionalProperties': {
                        'type': 'string'
                    }
                }
            }
        })

    plugin.register_task_handler("share.smb.create", CreateSMBShareTask)
    plugin.register_task_handler("share.smb.update", UpdateSMBShareTask)
    plugin.register_task_handler("share.smb.delete", DeleteSMBShareTask)
    plugin.register_task_handler("share.smb.import", ImportSMBShareTask)
    plugin.register_task_handler("share.smb.terminate_connection",
                                 TerminateSMBConnectionTask)
    plugin.register_provider("share.smb", SMBSharesProvider)
    plugin.register_event_type('share.smb.changed')

    # Sync samba registry with our database
    smb_conf = smbconf.SambaConfig('registry')
    smb_conf.shares.clear()

    for s in dispatcher.datastore.query('shares', ('type', '=', 'smb')):
        smb_share = smbconf.SambaShare()
        path = dispatcher.call_sync('share.translate_path', s['id'])
        convert_share(dispatcher, smb_share, path, s['enabled'],
                      s.get('properties', {}))
        smb_conf.shares[s['name']] = smb_share