Example #1
0
            if not self.datastore.exists('groups', ('id', '=', i)):
                gid = i
                break

        if not gid:
            raise RpcException(errno.ENOSPC, 'No free GIDs available')

        return gid


@description("Create an user in the system")
@accepts(h.all_of(
    h.ref('user'),
    h.required('username', 'group'),
    h.forbidden('builtin', 'logged-in', 'sessions'),
    h.object({'password': {'type': 'string'}}),
    h.any_of(
        h.required('password'),
        h.required('unixhash', 'smbhash'),
        h.required('password_disabled')),
))
class UserCreateTask(Task):
    def describe(self, user):
        return "Adding user {0}".format(user['username'])

    def verify(self, user):

        errors = []

        for code, message in check_unixname(user['username']):
            errors.append(('name', code, message))
Example #2
0
        return name


@description("Deletes interface")
@accepts(str)
class DeleteInterfaceTask(Task):
    def verify(self, name):
        raise NotImplementedError()

    def run(self, name):
        raise NotImplementedError()


@description("Alters network interface configuration")
@accepts(str, h.all_of(h.ref('network-interface'), h.forbidden('id', 'type')))
class ConfigureInterfaceTask(Task):
    def verify(self, name, updated_fields):
        if not self.datastore.exists('network.interfaces', ('id', '=', name)):
            raise VerifyException(errno.ENOENT,
                                  'Interface {0} does not exist'.format(name))

        return ['system']

    def run(self, name, updated_fields):
        if updated_fields.get('dhcp'):
            # Check for DHCP inconsistencies
            # 1. Check whether DHCP is enabled on other interfaces
            # 2. Check whether DHCP configures default route and/or DNS server addresses
            dhcp_used = self.datastore.exists('network.interfaces',
                                              ('dhcp', '=', True),
Example #3
0
from dispatcher.rpc import SchemaHelper as h
from lib.system import system, SubprocessException

logger = logging.getLogger('NTPPlugin')


@description("Provides access to NTP Servers configuration")
class NTPServersProvider(Provider):
    @query('ntp-server')
    def query(self, filter=None, params=None):
        return self.datastore.query('ntpservers', *(filter or []), **(params or {}))


@description("Adds new NTP Server")
@accepts(h.all_of(
    h.ref('ntp-server'),
    h.required('address'),
), bool)
class NTPServerCreateTask(Task):
    def describe(self, ntp):
        return "Creating NTP Server {0}".format(ntp['address'])

    def verify(self, ntp, force=False):

        errors = []

        try:
            system('ntpdate', '-q', ntp['address'])
        except SubprocessException:
            if not force:
                errors.append((
                    'address',
Example #4
0
                result.append(p.metadata['method'])

        return result

    @description("Returns list of clients connected to particular share")
    def get_connected_clients(self, share_name):
        share = self.datastore.get_by_id('shares', share_name)
        if not share:
            raise RpcException(errno.ENOENT, 'Share not found')

        return self.dispatcher.call_sync('shares.{0}.get_connected_clients'.format(share['type']), share_name)


@description("Creates new share")
@accepts(h.all_of(
    h.ref('share'),
    h.required('id', 'type', 'target')
))
class CreateShareTask(Task):
    def verify(self, share):
        return ['system']

    def run(self, share):
        self.join_subtasks(self.run_subtask('share.{0}.create'.format(share['type']), share))


@description("Updates existing share")
@accepts(str, h.ref('share'))
class UpdateShareTask(Task):
    def verify(self, name, updated_fields):
        share = self.datastore.get_by_id('shares', name)
        if not share:
Example #5
0
    except SubprocessException as e:
        # sysctl module compatibility
        raise OSError(str(e.err))


@description("Provides access to OS tunables")
class TunablesProvider(Provider):
    @query('tunable')
    def query(self, filter=None, params=None):
        return self.datastore.query('tunables', *(filter or []),
                                    **(params or {}))


@description("Adds Tunable")
@accepts(h.all_of(
    h.ref('tunable'),
    h.required('var', 'value', 'type'),
))
class TunableCreateTask(Task):
    def describe(self, tunable):
        return "Creating Tunable {0}".format(tunable['var'])

    def verify(self, tunable):

        errors = []
        if self.datastore.exists('tunables', ('var', '=', tunable['var'])):
            errors.append(
                ('var', errno.EEXIST, 'This variable already exists.'))

        if '"' in tunable['value'] or "'" in tunable['value']:
            errors.append(('value', errno.EINVAL, 'Quotes are not allowed'))
Example #6
0
            if certificate.get('csr'):
                certificate['csr_path'] = os.path.join(
                    cert_path, '{0}.csr'.format(certificate['name']))

            return certificate

        return self.datastore.query('crypto.certificates',
                                    *(filter or []),
                                    callback=extend,
                                    **(params or {}))


@accepts(
    h.all_of(
        h.ref('crypto-certificate'),
        h.required('signedby', 'name', 'country', 'state', 'city',
                   'organization', 'email', 'common'),
    ))
class CertificateInternalCreateTask(Task):
    def verify(self, certificate):

        errors = []

        if self.datastore.exists('crypto.certificates',
                                 ('name', '=', certificate['name'])):
            errors.append(('name', errno.EEXIST,
                           'Certificate with given name already exists'))

        if not self.datastore.exists('crypto.certificates',
                                     ('id', '=', certificate['signedby'])):
            errors.append(('signedby', errno.EEXIST,
Example #7
0
        fd.close()
        generate_disk_cache(self.dispatcher, disk)

    def get_status(self):
        if not self.started:
            return TaskStatus(0, 'Erasing disk...')

        return TaskStatus(self.remaining / self.mediasize, 'Erasing disk...')


@description("Configures online disk parameters")
@accepts(str,
         h.all_of(
             h.ref('disk'),
             h.no(
                 h.required('name', 'serial', 'path', 'id', 'mediasize',
                            'status'))))
class DiskConfigureTask(Task):
    def verify(self, id, updated_fields):
        disk = self.datastore.get_by_id('disks', id)

        if not disk:
            raise VerifyException(errno.ENOENT,
                                  'Disk {0} not found'.format(id))

        if not self.dispatcher.call_sync('disks.is_online', disk['path']):
            raise VerifyException(errno.EINVAL,
                                  'Cannot configure offline disk')

        return ['disk:{0}'.format(disk['path'])]
Example #8
0
                gid = i
                break

        if not gid:
            raise RpcException(errno.ENOSPC, 'No free GIDs available')

        return gid


@description("Create an user in the system")
@accepts(
    h.all_of(
        h.ref('user'),
        h.required('username', 'group'),
        h.forbidden('builtin', 'logged-in', 'sessions'),
        h.object({'password': {
            'type': 'string'
        }}),
        h.any_of(h.required('password'), h.required('unixhash', 'smbhash'),
                 h.required('password_disabled')),
    ))
class UserCreateTask(Task):
    def describe(self, user):
        return "Adding user {0}".format(user['username'])

    def verify(self, user):

        errors = []

        for code, message in check_unixname(user['username']):
            errors.append(('name', code, message))
Example #9
0
        fd.close()
        generate_disk_cache(self.dispatcher, disk)

    def get_status(self):
        if not self.started:
            return TaskStatus(0, 'Erasing disk...')

        return TaskStatus(self.remaining / self.mediasize, 'Erasing disk...')


@description("Configures online disk parameters")
@accepts(
    str,
    h.all_of(
        h.ref('disk'),
        h.no(h.required('name', 'serial', 'path', 'id', 'mediasize', 'status'))
    )
)
class DiskConfigureTask(Task):
    def verify(self, id, updated_fields):
        disk = self.datastore.get_by_id('disks', id)

        if not disk:
            raise VerifyException(errno.ENOENT, 'Disk {0} not found'.format(id))

        if not self.dispatcher.call_sync('disks.is_online', disk['path']):
            raise VerifyException(errno.EINVAL, 'Cannot configure offline disk')

        return ['disk:{0}'.format(disk['path'])]

    def run(self, id, updated_fields):
Example #10
0
                    cert_path, '{0}.key'.format(certificate['name']))
                # Load and dump private key to make sure its in desired format
                # This is code ported from 9.3 and must be reviewed as it may very well be useless
                certificate['privatekey'] = export_privatekey(certificate['privatekey'])

            if certificate.get('csr'):
                certificate['csr_path'] = os.path.join(
                    cert_path, '{0}.csr'.format(certificate['name']))

            return certificate

        return self.datastore.query('crypto.certificates', *(filter or []), callback=extend, **(params or {}))


@accepts(h.all_of(
    h.ref('crypto-certificate'),
    h.required('signedby', 'name', 'country', 'state', 'city', 'organization', 'email', 'common'),
))
class CertificateInternalCreateTask(Task):
    def verify(self, certificate):

        errors = []

        if self.datastore.exists('crypto.certificates', ('name', '=', certificate['name'])):
            errors.append(('name', errno.EEXIST, 'Certificate with given name already exists'))

        if not self.datastore.exists('crypto.certificates', ('id', '=', certificate['signedby'])):
            errors.append(('signedby', errno.EEXIST, 'Signing certificate does not exists'))

        if '"' in certificate['name']:
            errors.append(
                ('name', errno.EINVAL, 'You cannot issue a certificate with a `"` in its name'))
Example #11
0
        system('sysctl', '{0}={1}'.format(name, str(value)))
    except SubprocessException as e:
        # sysctl module compatibility
        raise OSError(str(e.err))


@description("Provides access to OS tunables")
class TunablesProvider(Provider):
    @query('tunable')
    def query(self, filter=None, params=None):
        return self.datastore.query('tunables', *(filter or []), **(params or {}))


@description("Adds Tunable")
@accepts(h.all_of(
    h.ref('tunable'),
    h.required('var', 'value', 'type'),
))
class TunableCreateTask(Task):
    def describe(self, tunable):
        return "Creating Tunable {0}".format(tunable['var'])

    def verify(self, tunable):

        errors = []
        if self.datastore.exists('tunables', ('var', '=', tunable['var'])):
            errors.append(('var', errno.EEXIST, 'This variable already exists.'))

        if '"' in tunable['value'] or "'" in tunable['value']:
            errors.append(('value', errno.EINVAL, 'Quotes are not allowed'))

        if tunable['type'] in ('LOADER', 'RC') and not VAR_LOADER_RC_RE.match(tunable['var']):
Example #12
0
        return name


@description("Deletes interface")
@accepts(str)
class DeleteInterfaceTask(Task):
    def verify(self, name):
        raise NotImplementedError()

    def run(self, name):
        raise NotImplementedError()


@description("Alters network interface configuration")
@accepts(str, h.all_of(
    h.ref('network-interface'),
    h.forbidden('id', 'type')
))
class ConfigureInterfaceTask(Task):
    def verify(self, name, updated_fields):
        if not self.datastore.exists('network.interfaces', ('id', '=', name)):
            raise VerifyException(errno.ENOENT, 'Interface {0} does not exist'.format(name))

        return ['system']

    def run(self, name, updated_fields):
        if updated_fields.get('dhcp'):
            # Check for DHCP inconsistencies
            # 1. Check whether DHCP is enabled on other interfaces
            # 2. Check whether DHCP configures default route and/or DNS server addresses
            dhcp_used = self.datastore.exists('network.interfaces', ('dhcp', '=', True), ('id' '!=', name))
            dhcp_global = self.dispatcher.configstore.get('network.dhcp.assign_gateway') or \