Example #1
0
    def user_apply(self):
        '''
        Run appliers for users.
        '''
        if is_root():
            for applier_name, applier_object in self.user_appliers.items():
                try:
                    applier_object.admin_context_apply()
                except Exception as exc:
                    logdata = dict()
                    logdata['applier'] = applier_name
                    logdata['exception'] = str(exc)
                    log('E19', logdata)

                try:
                    with_privileges(self.username, applier_object.user_context_apply)
                except Exception as exc:
                    logdata = dict()
                    logdata['applier'] = applier_name
                    logdata['exception'] = str(exc)
                    log('E20', logdata)
        else:
            for applier_name, applier_object in self.user_appliers.items():
                try:
                    applier_object.user_context_apply()
                except Exception as exc:
                    logdata = dict({'applier_name': applier_name, 'message': str(exc)})
                    log('E11', logdata)
Example #2
0
 def machine_apply(self):
     '''
     Run global appliers with administrator privileges.
     '''
     if not is_root():
         log('E13')
         return
     log('D16')
     for applier_name, applier_object in self.machine_appliers.items():
         try:
             applier_object.apply()
         except Exception as exc:
             logdata = dict()
             logdata['applier_name'] = applier_name
             logdata['msg'] = str(exc)
             log('E24', logdata)
Example #3
0
 def machine_apply(self):
     '''
     Run global appliers with administrator privileges.
     '''
     if not is_root():
         logging.error('Not sufficient privileges to run machine appliers')
         return
     logging.debug(slogm('Applying computer part of settings'))
     self.machine_appliers['systemd'].apply()
     self.machine_appliers['control'].apply()
     self.machine_appliers['polkit'].apply()
     self.machine_appliers['firefox'].apply()
     self.machine_appliers['chromium'].apply()
     self.machine_appliers['shortcuts'].apply()
     self.machine_appliers['gsettings'].apply()
     self.machine_appliers['cups'].apply()
Example #4
0
    def user_apply(self):
        '''
        Run appliers for users.
        '''
        if is_root():
            logging.debug(
                slogm('Running user appliers from administrator context'))
            self.user_appliers['shortcuts'].admin_context_apply()
            self.user_appliers['gsettings'].admin_context_apply()

            logging.debug(slogm('Running user appliers for user context'))
            with_privileges(self.username,
                            self.user_appliers['shortcuts'].user_context_apply)
            with_privileges(self.username,
                            self.user_appliers['gsettings'].user_context_apply)
        else:
            logging.debug(slogm('Running user appliers from user context'))
            self.user_appliers['shortcuts'].user_context_apply()
            self.user_appliers['gsettings'].user_context_apply()
Example #5
0
def determine_username(username=None):
    '''
    Checks if the specified username is valid in order to prevent
    unauthorized operations.
    '''
    name = username

    # If username is not set then it will be the name
    # of process owner.
    if not username:
        name = get_process_user()
        logdata = dict({'username': name})
        log('D2', logdata)

    if not username_match_uid(name):
        if not is_root():
            raise Exception('Current process UID does not match specified username')

    logdata = dict({'username': name})
    log('D15', logdata)

    return name
Example #6
0
def determine_username(username=None):
    '''
    Checks if the specified username is valid in order to prevent
    unauthorized operations.
    '''
    name = username

    # If username is not set then it will be the name
    # of process owner.
    if not username:
        name = get_process_user()
        logging.debug(
            slogm(
                'Username is not specified - will use username of current process'
            ))

    if not username_match_uid(name):
        if not is_root():
            raise Exception(
                'Current process UID does not match specified username')

    logging.debug(slogm('Username for frontend is set to {}'.format(name)))

    return name