msad 0.2.2__py3-none-any.whl → 0.3.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
msad/ad.py CHANGED
File without changes
msad/command_line.py CHANGED
File without changes
msad/search.py CHANGED
File without changes
msad/user.py CHANGED
File without changes
@@ -1,18 +1,16 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: msad
3
- Version: 0.2.2
4
- Summary: msad is a library and commandline for interacting with Active Directory
5
- Home-page: https://github.com/matteoredaelli/msad
6
- Author: Matteo Redaelli
7
- Author-email: matteo.redaelli@gmail.com
8
- License: GPL
9
- Classifier: Programming Language :: Python :: 3
3
+ Version: 0.3.2
4
+ Summary: msad is a commandline for interacting with Active Directory
5
+ Project-URL: Homepage, https://github.com/matteoredaelli/msad
6
+ Project-URL: Issues, https://github.com/matteoredaelli/msad/issues
7
+ Author-email: Matteo Redaelli <matteo.redaelli@gmail.com>
8
+ License-Expression: GPL-3.0-or-later
9
+ License-File: LICENSE
10
10
  Classifier: Operating System :: OS Independent
11
- Requires-Python: >=3.6
11
+ Classifier: Programming Language :: Python :: 3
12
+ Requires-Python: >=3.9
12
13
  Description-Content-Type: text/markdown
13
- License-File: LICENSE
14
- Requires-Dist: fire
15
- Requires-Dist: ldap3
16
14
 
17
15
  # msAD
18
16
 
@@ -0,0 +1,11 @@
1
+ msad/__init__.py,sha256=DJ6egXlvzOK_k0XlN7BpmMRuwu4MM7eQoxLE0Ou-sLI,63
2
+ msad/ad.py,sha256=C3dknAgRY6Jnotk0RgPSye7uzNxUd-7B3oGloGR674E,5679
3
+ msad/command_line.py,sha256=6JB_rcYsd7UKVgUWmIdMJxMJ5oKmE_KshX7WYe5b5P0,8500
4
+ msad/group.py,sha256=TKIDEzQEBugux2imt81YX1byRtz31W_qZRXADfoHSbU,3448
5
+ msad/search.py,sha256=sQfvaaWX6yMKNk5nCPH6yQb2_54LjaEJuXc8FGOhrIo,3383
6
+ msad/user.py,sha256=oWpoAHcgTMsFf3RXr0wSECONZkJfsIXC3EZTx16BqiY,4466
7
+ msad-0.3.2.dist-info/METADATA,sha256=HToUhExPoVR6f4v3ud3EPK875e7lPyOm-9WqMXHaHHI,3044
8
+ msad-0.3.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
9
+ msad-0.3.2.dist-info/entry_points.txt,sha256=9AD9I3SgdhEqJqQcdrxUbFYTgFdPob1AUmEocQQYj8c,43
10
+ msad-0.3.2.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
11
+ msad-0.3.2.dist-info/RECORD,,
@@ -1,5 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.41.0)
2
+ Generator: hatchling 1.27.0
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
-
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ msad = msad:command_line
@@ -1,240 +0,0 @@
1
- #!/usr/bin/env python3
2
-
3
- # msad - Active Directory tool
4
- # Copyright (C) 2020 - matteo.redaelli@gmail.com
5
-
6
- # This program is free software: you can redistribute it and/or modify
7
- # it under the terms of the GNU General Public License as published by
8
- # the Free Software Foundation, either version 3 of the License, or
9
- # (at your option) any later version.
10
-
11
- # This program is distributed in the hope that it will be useful,
12
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- # GNU General Public License for more details.
15
-
16
- # You should have received a copy of the GNU General Public License
17
- # along with this program. If not, see <https://www.gnu.org/licenses/>
18
-
19
- import logging
20
- import os
21
- import datetime
22
- import sys
23
- import msad
24
- import fire
25
- import ldap3
26
- import ssl
27
- import json
28
- from typing import List, Tuple, Dict
29
- import pprint
30
-
31
-
32
- def _json_converter(o):
33
- if isinstance(o, datetime.datetime):
34
- return o.__str__()
35
- elif isinstance(o, list):
36
- return ";".join(o)
37
- # else return o
38
-
39
-
40
- def _get_connection_krb(host, port, use_ssl):
41
- tls = ldap3.Tls(validate=ssl.CERT_NONE, version=ssl.PROTOCOL_TLSv1_2)
42
- server = ldap3.Server(host, port=port, use_ssl=use_ssl, tls=tls)
43
-
44
- conn = ldap3.Connection(
45
- server,
46
- authentication=ldap3.SASL,
47
- sasl_mechanism=ldap3.KERBEROS,
48
- auto_bind=False,
49
- )
50
- # conn.bind()
51
- return conn
52
-
53
-
54
- def _get_connection_user_pwd(host, port, use_ssl, user, password):
55
- server = ldap3.Server(host, port, use_ssl)
56
-
57
- conn = ldap3.Connection(server, user=user, password=password, auto_bind=False)
58
- # conn.bind()
59
- return conn
60
-
61
-
62
- def _get_connection(host, port, use_ssl, sso, user, password):
63
- if user and password:
64
- conn = _get_connection_user_pwd(host, port, use_ssl, user, password)
65
- else:
66
- conn = _get_connection_krb(host, port, use_ssl)
67
-
68
- conn.bind()
69
- return conn
70
-
71
-
72
- class AD:
73
- """*msad* is command line tool for Active Directory. With it you can
74
- search objects,
75
- add/remove members to/from groups,
76
- change password
77
- check if a user is locked, disabled
78
- check if a user's password is expired"""
79
-
80
- def __init__(
81
- self,
82
- host,
83
- port,
84
- use_ssl=True,
85
- sso=True,
86
- user=None,
87
- password=None,
88
- search_base=None,
89
- limit=0,
90
- attributes=None,
91
- out_format="json",
92
- sep=";",
93
- ):
94
- try:
95
- self._conn = _get_connection(host, port, use_ssl, sso, user, password)
96
- except:
97
- logging.error("Cannot loging to Active Directory. Bye")
98
- sys.exit(1)
99
- self._attributes = attributes
100
- self._sep = sep
101
- self._search_base = search_base
102
- self._limit = limit
103
- self._out_format = out_format
104
-
105
- def change_password(self, user_name=None, user_dn=None):
106
- return msad.user.change_password(
107
- self._conn, self._search_base, user_name, user_dn
108
- )
109
-
110
- def search(self, search_filter):
111
- self._conn.search(
112
- self._search_base,
113
- search_filter,
114
- size_limit=self._limit,
115
- attributes=self._attributes,
116
- )
117
- return self.pprint(self._conn.response)
118
-
119
- def pprint(self, ldapresult):
120
- result = ""
121
- return ldapresult
122
- if not ldapresult:
123
- logging.warning("Empty ldap object: cannot pprint it")
124
- return ""
125
- for obj in ldapresult:
126
- if self._out_format == "json":
127
- result = json.dumps(dict(obj), default=_json_converter) + "\n"
128
- elif self._out_format == "csv":
129
- result = self._sep.join(obj.values())
130
- else:
131
- result += str(obj)
132
- # else:
133
- # result= result + obj
134
- return result
135
-
136
- def users(self, user):
137
- """Search users inside AD
138
- filter: is the cn or userPrincipalName or samaccoutnname or mail to be searched. Can contain *
139
- """
140
- result = msad.users(
141
- self._conn, self._search_base, user, attributes=self._attributes
142
- )
143
- return self.pprint(result)
144
-
145
- def is_disabled(self, user):
146
- """Check if a user is disabled"""
147
- return msad.user.is_disabled(self._conn, self._search_base, user)
148
-
149
- def is_locked(self, user):
150
- """Locked user?"""
151
- return msad.user.is_locked(self._conn, self._search_base, user)
152
-
153
- def has_expired_password(self, user, max_age):
154
- """user with expired password?"""
155
- return msad.has_expired_password(self._conn, self._search_base, user, max_age)
156
-
157
- def has_never_expires_password(self, user):
158
- """user with never exires password?"""
159
- return msad.has_never_expires_password(self._conn, self._search_base, user)
160
-
161
- def check_user(self, user, max_age, groups=[]):
162
- """Get info about a user"""
163
- return msad.check_user(self._conn, self._search_base, user, max_age, groups)
164
-
165
- def group_flat_members(self, search_base, group_name=None, group_dn=None):
166
- result = msad.group_flat_members(
167
- self._conn, search_base, self._limit, group_name, group_dn
168
- )
169
- return result ## self.pprint(result)
170
-
171
- def group_members(self, group_name=None, group_dn=None):
172
- """Get members od a group"""
173
- if group_name is None and group_dn is None:
174
- logging.error("group_name or group_dn must be entered")
175
- return None
176
- result = msad.group_members(self._conn, self._search_base, group_name, group_dn)
177
- return self.pprint(result)
178
-
179
- def add_member(self, group_name=None, group_dn=None, user_name=None, user_dn=None):
180
- """Adding a user to a group"""
181
- return msad.add_member(
182
- conn=self._conn,
183
- search_base=self._search_base,
184
- group_name=group_name,
185
- group_dn=group_dn,
186
- user_name=user_name,
187
- user_dn=user_dn,
188
- )
189
-
190
- def user_groups(self, user_name=None, user_dn=None):
191
- """groups of a user"""
192
- return msad.user.user_groups(
193
- self._conn, self._search_base, self._limit, user_name, user_dn
194
- )
195
-
196
- def remove_member(
197
- self, group_name=None, group_dn=None, user_name=None, user_dn=None
198
- ):
199
- """Remove a user from a group"""
200
- return msad.remove_member(
201
- conn=self._conn,
202
- search_base=self._search_base,
203
- group_name=group_name,
204
- group_dn=group_dn,
205
- user_name=user_name,
206
- user_dn=user_dn,
207
- )
208
-
209
- def group_member(
210
- self, group_name=None, group_dn=None, user_name=None, user_dn=None
211
- ):
212
- """group membership"""
213
- return msad.group_member(
214
- conn=self._conn,
215
- search_base=self._search_base,
216
- group_name=group_name,
217
- group_dn=group_dn,
218
- user_name=user_name,
219
- user_dn=user_dn,
220
- )
221
-
222
-
223
- BANNER = """
224
- _ ____
225
- / \ | _ \
226
- / _ \ | | | |
227
- / ___ \| |_| |
228
- /_/ \_\____/
229
-
230
- """
231
-
232
-
233
- def main():
234
- """main"""
235
- logging.basicConfig(level=os.environ.get("LOGLEVEL", "INFO"))
236
- fire.Fire(AD)
237
-
238
-
239
- if __name__ == "__main__":
240
- main()
@@ -1,13 +0,0 @@
1
- msad/__init__.py,sha256=DJ6egXlvzOK_k0XlN7BpmMRuwu4MM7eQoxLE0Ou-sLI,63
2
- msad/ad.py,sha256=C3dknAgRY6Jnotk0RgPSye7uzNxUd-7B3oGloGR674E,5679
3
- msad/command_line.py,sha256=6JB_rcYsd7UKVgUWmIdMJxMJ5oKmE_KshX7WYe5b5P0,8500
4
- msad/flycheck_command_line.py,sha256=y3BhrYoxAf_TodcJ-qECL8bAlZpKqtGAjBHkhz11Q8Y,7210
5
- msad/group.py,sha256=TKIDEzQEBugux2imt81YX1byRtz31W_qZRXADfoHSbU,3448
6
- msad/search.py,sha256=sQfvaaWX6yMKNk5nCPH6yQb2_54LjaEJuXc8FGOhrIo,3383
7
- msad/user.py,sha256=oWpoAHcgTMsFf3RXr0wSECONZkJfsIXC3EZTx16BqiY,4466
8
- msad-0.2.2.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
9
- msad-0.2.2.dist-info/METADATA,sha256=WxTAjU-PLd_4mvu7xSZ1ekc_8mV2jjq7-pcF2ViIPVE,3000
10
- msad-0.2.2.dist-info/WHEEL,sha256=AtBG6SXL3KF_v0NxLf0ehyVOh0cold-JbJYXNGorC6Q,92
11
- msad-0.2.2.dist-info/entry_points.txt,sha256=s9wIVNQKKBX5Y6KaYj0STVIZ66mBsseHaamXjshIw7Y,48
12
- msad-0.2.2.dist-info/top_level.txt,sha256=C7oAqQ8Om9puxF81wzyl_8arBV2pCoQY26VctYxij1M,5
13
- msad-0.2.2.dist-info/RECORD,,
@@ -1,2 +0,0 @@
1
- [console_scripts]
2
- msad = msad.command_line:main
@@ -1 +0,0 @@
1
- msad