Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
unlockAccount.py58 linesDownload Raw Back to microsoft
1"""
2"""
3
4# Created on 2016.11.01
5#
6# Author: Giovanni Cannata
7#
8# Copyright 2015 - 2020 Giovanni Cannata
9#
10# This file is part of ldap3.
11#
12# ldap3 is free software: you can redistribute it and/or modify
13# it under the terms of the GNU Lesser General Public License as published
14# by the Free Software Foundation, either version 3 of the License, or
15# (at your option) any later version.
16#
17# ldap3 is distributed in the hope that it will be useful,
18# but WITHOUT ANY WARRANTY; without even the implied warranty of
19# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20# GNU Lesser General Public License for more details.
21#
22# You should have received a copy of the GNU Lesser General Public License
23# along with ldap3 in the COPYING and COPYING.LESSER files.
24# If not, see <http://www.gnu.org/licenses/>.
25
26
27from ... import MODIFY_REPLACE
28from ...utils.log import log, log_enabled, PROTOCOL
29from ...core.results import RESULT_SUCCESS
30from ...utils.dn import safe_dn
31
32
33def ad_unlock_account(connection, user_dn, controls=None):
34    if connection.check_names:
35        user_dn = safe_dn(user_dn)
36    result = connection.modify(user_dn, {'lockoutTime': [(MODIFY_REPLACE, ['0'])]}, controls)
37
38    if not connection.strategy.sync:
39        _, result = connection.get_response(result)
40    else:
41        if connection.strategy.thread_safe:
42            _, result, _, _ = result
43        else:
44            result = connection.result
45
46    # change successful, returns True
47    if result['result'] == RESULT_SUCCESS:
48        return True
49
50    # change was not successful, raises exception if raise_exception = True in connection or returns the operation result, error code is in result['result']
51    if connection.raise_exceptions:
52        from ...core.exceptions import LDAPOperationResult
53        if log_enabled(PROTOCOL):
54            log(PROTOCOL, 'operation result <%s> for <%s>', result, connection)
55        raise LDAPOperationResult(result=result['result'], description=result['description'], dn=result['dn'], message=result['message'], response_type=result['type'])
56
57    return result
58 
codekingpro/portable-devtools · Team Ai