def run(self, params={}): formatter = ADUtils() conn = self.connection.conn query = params.get('search_filter') query = query.replace("\\>=", ">=") query = query.replace("\\<=", "<=") # find pars of `(` `)` pairs = formatter.find_parentheses_pairs(query) # replace ( and ) when they are part of a name rather than a search parameter escaped_query = formatter.escape_brackets_for_query(query, pairs) self.logger.info(f"Escaped query: {escaped_query}") attributes = params.get(Input.ATTRIBUTES) if not attributes: attributes = [ ldap3.ALL_ATTRIBUTES, ldap3.ALL_OPERATIONAL_ATTRIBUTES ] conn.search(search_base=params.get('search_base'), search_filter=escaped_query, attributes=attributes) result_list_json = conn.response_to_json() result_list_object = json.loads(result_list_json) entries = result_list_object["entries"] return {Output.RESULTS: entries, Output.COUNT: len(entries)}
def run(self, params={}): formatter = ADUtils() conn = self.connection.conn dn = params.get('distinguished_name') dn, search_base = formatter.format_dn(dn) self.logger.info(f'Escaped DN {dn}') pairs = formatter.find_parentheses_pairs(dn) self.logger.info(pairs) # replace ( and ) when they are part of a name rather than a search parameter if pairs: dn = formatter.escape_brackets_for_query(dn, pairs) self.logger.info(f'Search DN {dn}') conn.search(search_base=search_base, search_filter=f'(distinguishedName={dn})', attributes=['userAccountControl']) results = conn.response dn_test = [d['dn'] for d in results if 'dn' in d] try: dn_test[0] except Exception as ex: self.logger.error('The DN ' + dn + ' was not found') raise PluginException(cause="The DN was not found", assistance="The DN " + dn + " was not found") from ex user_list = [d['attributes'] for d in results if 'attributes' in d] user_control = user_list[0] try: account_status = user_control['userAccountControl'] except Exception as ex: self.logger.error('The DN ' + dn + ' is not a user') raise PluginException(cause="The DN is not a user", assistance="The DN " + dn + " is not a user") from ex user_account_flag = 2 account_status = account_status | user_account_flag conn.modify( dn, {'userAccountControl': [(MODIFY_REPLACE, [account_status])]}) result = conn.result output = result['description'] if result['result'] == 0: return {'success': True} self.logger.error('failed: error message %s' % output) return {'success': False}
def run(self, params={}): formatter = ADUtils() conn = self.connection.conn dn = params.get(Input.DISTINGUISHED_NAME) attribute = params.get(Input.ATTRIBUTE_TO_MODIFY) attribute_value = params.get(Input.ATTRIBUTE_VALUE) dn, search_base = formatter.format_dn(dn) self.logger.info(f"Escaped DN {dn}") pairs = formatter.find_parentheses_pairs(dn) # replace ( and ) when they are part of a name rather than a search parameter if pairs: dn = formatter.escape_brackets_for_query(dn) self.logger.info(dn) # Check that the distinguishedName is valid conn.search( search_base=search_base, search_filter=f"(distinguishedName={dn})", attributes=[ALL_ATTRIBUTES, ALL_OPERATIONAL_ATTRIBUTES], ) result = conn.response_to_json() result_list_object = loads(result) entries = result_list_object["entries"] dn_test = [d["dn"] for d in entries if "dn" in d] if len(dn_test) == 0: self.logger.error("The DN " + dn + " was not found") raise PluginException(cause="The DN was not found.", assistance="The DN " + dn + " was not found") # Update attribute dn = formatter.unescape_asterisk(dn) conn.modify(dn, {attribute: [(MODIFY_REPLACE, [attribute_value])]}) result = conn.result output = result["description"] if result["result"] == 0: return {Output.SUCCESS: True} self.logger.error("failed: error message %s" % output) return {Output.SUCCESS: False}