Exemple #1
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
Exemple #2
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]
        })
Exemple #3
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
Exemple #4
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()
Exemple #5
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