msad 0.2.1__tar.gz → 0.3.1__tar.gz

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.
@@ -1,17 +1,15 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: msad
3
- Version: 0.2.1
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
- Platform: UNKNOWN
3
+ Version: 0.3.1
4
+ Summary: msad is a commandline for interacting with Active Directory
5
+ Author-email: Matteo Redaelli <matteo.redaelli@gmail.com>
6
+ License-Expression: GPL-3.0-or-later
7
+ Project-URL: Homepage, https://github.com/matteoredaelli/msad
8
+ Project-URL: Issues, https://github.com/matteoredaelli/msad/issues
10
9
  Classifier: Programming Language :: Python :: 3
11
10
  Classifier: Operating System :: OS Independent
12
- Requires-Python: >=3.6
11
+ Requires-Python: >=3.8
13
12
  Description-Content-Type: text/markdown
14
- License-File: LICENSE
15
13
 
16
14
  # msAD
17
15
 
@@ -23,13 +21,59 @@ msad is a library and command line tool for working with an Active Directory / L
23
21
  - change AD passwords
24
22
  - check if a user is disabled or locked, group membership
25
23
 
26
- ## Install
24
+
25
+ ## Usage
27
26
 
28
27
  ```bash
29
- pip install msad
28
+ msad --help
30
29
  ```
31
30
 
32
- ## Usage
31
+ ```text
32
+ COMMAND is one of the following:
33
+
34
+ add_member
35
+ Adds the user to a group (using DN or sAMAccountName)
36
+
37
+ change_password
38
+
39
+ check_user
40
+ Get some info about a user: is it locked? disabled? password expired?
41
+
42
+ group_flat_members
43
+ Extract all the (nested) members of a group
44
+
45
+ group_member
46
+ Check if the user is a member of a group (using DN or sAMAccountName)
47
+
48
+ group_members
49
+ Extract the direct members of a group
50
+
51
+ has_expired_password
52
+ Check is user has the expired password
53
+
54
+ has_never_expires_password
55
+ Check if a user has never expires password
56
+
57
+ is_disabled
58
+ Check if a user is disabled
59
+
60
+ is_locked
61
+ Check if the user is locked
62
+
63
+ remove_member
64
+ Remove the user from a group (using DN or sAMAccountName)
65
+
66
+ search
67
+
68
+ user_groups
69
+ Extract the list of groups of a user (using DN or sAMAccountName)
70
+
71
+ users
72
+ Find users inside AD. The filter can be the cn or userPrincipalName or samaccoutnname or mail to be searched. Can contain *
73
+
74
+ ```
75
+
76
+ ## Sample
33
77
 
34
78
  I find useful to add an alias in my ~/.bash_aliases
35
79
 
@@ -61,11 +105,9 @@ msad --out_format csv --attributes samaccountname,mail,sn,givenName group_flat_m
61
105
 
62
106
  ## License
63
107
 
64
- Copyright © 2021 Matteo Redaelli
108
+ Copyright © 2021 2022 Matteo Redaelli
65
109
 
66
110
  This program is free software: you can redistribute it and/or modify
67
111
  it under the terms of the GNU General Public License as published by
68
112
  the Free Software Foundation, either version 3 of the License, or
69
113
  (at your option) any later version.
70
-
71
-
@@ -1,18 +1,3 @@
1
- Metadata-Version: 2.1
2
- Name: msad
3
- Version: 0.2.1
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
- Platform: UNKNOWN
10
- Classifier: Programming Language :: Python :: 3
11
- Classifier: Operating System :: OS Independent
12
- Requires-Python: >=3.6
13
- Description-Content-Type: text/markdown
14
- License-File: LICENSE
15
-
16
1
  # msAD
17
2
 
18
3
 
@@ -23,13 +8,59 @@ msad is a library and command line tool for working with an Active Directory / L
23
8
  - change AD passwords
24
9
  - check if a user is disabled or locked, group membership
25
10
 
26
- ## Install
11
+
12
+ ## Usage
27
13
 
28
14
  ```bash
29
- pip install msad
15
+ msad --help
30
16
  ```
31
17
 
32
- ## Usage
18
+ ```text
19
+ COMMAND is one of the following:
20
+
21
+ add_member
22
+ Adds the user to a group (using DN or sAMAccountName)
23
+
24
+ change_password
25
+
26
+ check_user
27
+ Get some info about a user: is it locked? disabled? password expired?
28
+
29
+ group_flat_members
30
+ Extract all the (nested) members of a group
31
+
32
+ group_member
33
+ Check if the user is a member of a group (using DN or sAMAccountName)
34
+
35
+ group_members
36
+ Extract the direct members of a group
37
+
38
+ has_expired_password
39
+ Check is user has the expired password
40
+
41
+ has_never_expires_password
42
+ Check if a user has never expires password
43
+
44
+ is_disabled
45
+ Check if a user is disabled
46
+
47
+ is_locked
48
+ Check if the user is locked
49
+
50
+ remove_member
51
+ Remove the user from a group (using DN or sAMAccountName)
52
+
53
+ search
54
+
55
+ user_groups
56
+ Extract the list of groups of a user (using DN or sAMAccountName)
57
+
58
+ users
59
+ Find users inside AD. The filter can be the cn or userPrincipalName or samaccoutnname or mail to be searched. Can contain *
60
+
61
+ ```
62
+
63
+ ## Sample
33
64
 
34
65
  I find useful to add an alias in my ~/.bash_aliases
35
66
 
@@ -61,11 +92,9 @@ msad --out_format csv --attributes samaccountname,mail,sn,givenName group_flat_m
61
92
 
62
93
  ## License
63
94
 
64
- Copyright © 2021 Matteo Redaelli
95
+ Copyright © 2021 2022 Matteo Redaelli
65
96
 
66
97
  This program is free software: you can redistribute it and/or modify
67
98
  it under the terms of the GNU General Public License as published by
68
99
  the Free Software Foundation, either version 3 of the License, or
69
100
  (at your option) any later version.
70
-
71
-
@@ -0,0 +1,30 @@
1
+ [project]
2
+ name = "msad"
3
+ version = "0.3.1"
4
+ authors = [
5
+ { name="Matteo Redaelli", email="matteo.redaelli@gmail.com" },
6
+ ]
7
+ description = "msad is a commandline for interacting with Active Directory"
8
+ readme = "README.md"
9
+ requires-python = ">=3.8"
10
+ classifiers = [
11
+ "Programming Language :: Python :: 3",
12
+ "Operating System :: OS Independent",
13
+ ]
14
+ license = "GPL-3.0-or-later"
15
+ #license = {file = "LICENSE"}
16
+ #license-file = ["LICENSE"]
17
+ #license-expression = "*"
18
+
19
+ license-files = []
20
+
21
+ [project.urls]
22
+ Homepage = "https://github.com/matteoredaelli/msad"
23
+ Issues = "https://github.com/matteoredaelli/msad/issues"
24
+
25
+ [project.scripts]
26
+ msad = "msad:command_line"
27
+
28
+ [build-system]
29
+ requires = ["setuptools >= 78.1.0"]
30
+ build-backend = "setuptools.build_meta"
msad-0.3.1/setup.cfg ADDED
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -75,7 +75,8 @@ class AD:
75
75
  add/remove members to/from groups,
76
76
  change password
77
77
  check if a user is locked, disabled
78
- check if a user's password is expired"""
78
+ check if a user's password is expired
79
+ ..."""
79
80
 
80
81
  def __init__(
81
82
  self,
@@ -94,7 +95,9 @@ class AD:
94
95
  try:
95
96
  self._conn = _get_connection(host, port, use_ssl, sso, user, password)
96
97
  except:
97
- logging.error("Cannot loging to Active Directory. Bye")
98
+ logging.error(
99
+ f"Cannot login to Active Directory (host: {host}, port: {port}). Bye"
100
+ )
98
101
  sys.exit(1)
99
102
  self._attributes = attributes
100
103
  self._sep = sep
@@ -158,6 +161,9 @@ class AD:
158
161
  """Check if the user is locked"""
159
162
  return msad.user.is_locked(self._conn, self._search_base, user)
160
163
 
164
+ def password_changed_in_days(self, user):
165
+ return msad.user.password_changed_in_days(self._conn, self._search_base, user)
166
+
161
167
  def has_expired_password(self, user, max_age):
162
168
  """Check is user has the expired password"""
163
169
  return msad.has_expired_password(self._conn, self._search_base, user, max_age)
@@ -241,6 +247,10 @@ BANNER = """
241
247
  | | | | ___) |/ ___ \ | |_| |
242
248
  |_| |_||____//_/ \_\|____/
243
249
 
250
+ https://github.com/matteoredaelli/msad
251
+
252
+ https://pypi.org/project/msad/
253
+
244
254
  """
245
255
 
246
256
 
@@ -70,24 +70,20 @@ def has_never_expires_password(conn, search_base, user):
70
70
  return True if len(result) == 1 else None
71
71
 
72
72
 
73
- def password_changed_in_days(conn, search_base, user):
73
+ def password_changed_in_days(conn, search_base, user, limit=1000):
74
74
  search_filter = f"(samaccountname={user})"
75
75
  result = search(
76
- conn, search_base, search_filter, limit=1, attributes=["pwdLastSet"]
76
+ conn, search_base, search_filter, limit=limit, attributes=["sAMAccountName","pwdLastSet"]
77
77
  )
78
78
 
79
79
  if len(result) == 0:
80
80
  return None
81
- result = result[0]["pwdLastSet"]
82
- logging.info(f"Password changed at {result}")
81
+
83
82
  now = datetime.datetime.now()
83
+ result = [ {"sAMAccountName": u["sAMAccountName"],
84
+ "days": (now - u["pwdLastSet"].replace(tzinfo=None)).days} for u in result]
84
85
 
85
- if result == 0:
86
- return True
87
- else:
88
- delta = now - result.replace(tzinfo=None)
89
- days = delta.days
90
- return days
86
+ return result
91
87
 
92
88
 
93
89
  def has_expired_password(conn, search_base, user, max_age):
@@ -0,0 +1,113 @@
1
+ Metadata-Version: 2.4
2
+ Name: msad
3
+ Version: 0.3.1
4
+ Summary: msad is a commandline for interacting with Active Directory
5
+ Author-email: Matteo Redaelli <matteo.redaelli@gmail.com>
6
+ License-Expression: GPL-3.0-or-later
7
+ Project-URL: Homepage, https://github.com/matteoredaelli/msad
8
+ Project-URL: Issues, https://github.com/matteoredaelli/msad/issues
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.8
12
+ Description-Content-Type: text/markdown
13
+
14
+ # msAD
15
+
16
+
17
+ msad is a library and command line tool for working with an Active Directory / LDAP server. It can be used for:
18
+ - search objects (users, groups, computers,..)
19
+ - search group members
20
+ - add/remove members to/from AD groups using DN or sAMaccoutName
21
+ - change AD passwords
22
+ - check if a user is disabled or locked, group membership
23
+
24
+
25
+ ## Usage
26
+
27
+ ```bash
28
+ msad --help
29
+ ```
30
+
31
+ ```text
32
+ COMMAND is one of the following:
33
+
34
+ add_member
35
+ Adds the user to a group (using DN or sAMAccountName)
36
+
37
+ change_password
38
+
39
+ check_user
40
+ Get some info about a user: is it locked? disabled? password expired?
41
+
42
+ group_flat_members
43
+ Extract all the (nested) members of a group
44
+
45
+ group_member
46
+ Check if the user is a member of a group (using DN or sAMAccountName)
47
+
48
+ group_members
49
+ Extract the direct members of a group
50
+
51
+ has_expired_password
52
+ Check is user has the expired password
53
+
54
+ has_never_expires_password
55
+ Check if a user has never expires password
56
+
57
+ is_disabled
58
+ Check if a user is disabled
59
+
60
+ is_locked
61
+ Check if the user is locked
62
+
63
+ remove_member
64
+ Remove the user from a group (using DN or sAMAccountName)
65
+
66
+ search
67
+
68
+ user_groups
69
+ Extract the list of groups of a user (using DN or sAMAccountName)
70
+
71
+ users
72
+ Find users inside AD. The filter can be the cn or userPrincipalName or samaccoutnname or mail to be searched. Can contain *
73
+
74
+ ```
75
+
76
+ ## Sample
77
+
78
+ I find useful to add an alias in my ~/.bash_aliases
79
+
80
+ ```bash
81
+ alias msad='/usr/local/bin/msad --host=dmc1it.group.redaelli.org --port=636 --search_base dc=group,dc=redaelli,dc=org'
82
+ ```
83
+
84
+ Retreive info about a user
85
+
86
+ ```bash
87
+ msad check_user matteo 90 \[qliksense_analyzer,qliksense_professional\] 2>/dev/null
88
+ ```
89
+
90
+ ```json
91
+ {"is_disabled": false}
92
+ {"is_locked": false}
93
+ {"has_never_expires_password": false}
94
+ {"has_expired_password": false}
95
+ {"membership_qliksense_analyzer": false}
96
+ {"membership_qliksense_professional": true}
97
+ ```
98
+
99
+ Getting nested group members (it is a pages search, it can retreive more than 1000 users)
100
+
101
+ ```bash
102
+ msad --out_format csv --attributes samaccountname,mail,sn,givenName group_flat_members "dc=group,dc=redaelli,dc=org" --group_name "qliksense_admin"
103
+ ```
104
+
105
+
106
+ ## License
107
+
108
+ Copyright © 2021 2022 Matteo Redaelli
109
+
110
+ This program is free software: you can redistribute it and/or modify
111
+ it under the terms of the GNU General Public License as published by
112
+ the Free Software Foundation, either version 3 of the License, or
113
+ (at your option) any later version.
@@ -0,0 +1,14 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ src/msad/__init__.py
5
+ src/msad/ad.py
6
+ src/msad/command_line.py
7
+ src/msad/group.py
8
+ src/msad/search.py
9
+ src/msad/user.py
10
+ src/msad.egg-info/PKG-INFO
11
+ src/msad.egg-info/SOURCES.txt
12
+ src/msad.egg-info/dependency_links.txt
13
+ src/msad.egg-info/entry_points.txt
14
+ src/msad.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ msad = msad:command_line
msad-0.2.1/README.md DELETED
@@ -1,54 +0,0 @@
1
- # msAD
2
-
3
-
4
- msad is a library and command line tool for working with an Active Directory / LDAP server. It can be used for:
5
- - search objects (users, groups, computers,..)
6
- - search group members
7
- - add/remove members to/from AD groups using DN or sAMaccoutName
8
- - change AD passwords
9
- - check if a user is disabled or locked, group membership
10
-
11
- ## Install
12
-
13
- ```bash
14
- pip install msad
15
- ```
16
-
17
- ## Usage
18
-
19
- I find useful to add an alias in my ~/.bash_aliases
20
-
21
- ```bash
22
- alias msad='/usr/local/bin/msad --host=dmc1it.group.redaelli.org --port=636 --search_base dc=group,dc=redaelli,dc=org'
23
- ```
24
-
25
- Retreive info about a user
26
-
27
- ```bash
28
- msad check_user matteo 90 \[qliksense_analyzer,qliksense_professional\] 2>/dev/null
29
- ```
30
-
31
- ```json
32
- {"is_disabled": false}
33
- {"is_locked": false}
34
- {"has_never_expires_password": false}
35
- {"has_expired_password": false}
36
- {"membership_qliksense_analyzer": false}
37
- {"membership_qliksense_professional": true}
38
- ```
39
-
40
- Getting nested group members (it is a pages search, it can retreive more than 1000 users)
41
-
42
- ```bash
43
- msad --out_format csv --attributes samaccountname,mail,sn,givenName group_flat_members "dc=group,dc=redaelli,dc=org" --group_name "qliksense_admin"
44
- ```
45
-
46
-
47
- ## License
48
-
49
- Copyright © 2021 Matteo Redaelli
50
-
51
- This program is free software: you can redistribute it and/or modify
52
- it under the terms of the GNU General Public License as published by
53
- the Free Software Foundation, either version 3 of the License, or
54
- (at your option) any later version.
@@ -1,16 +0,0 @@
1
- LICENSE
2
- README.md
3
- setup.cfg
4
- setup.py
5
- msad/__init__.py
6
- msad/ad.py
7
- msad/command_line.py
8
- msad/group.py
9
- msad/search.py
10
- msad/user.py
11
- msad.egg-info/PKG-INFO
12
- msad.egg-info/SOURCES.txt
13
- msad.egg-info/dependency_links.txt
14
- msad.egg-info/entry_points.txt
15
- msad.egg-info/requires.txt
16
- msad.egg-info/top_level.txt
@@ -1,3 +0,0 @@
1
- [console_scripts]
2
- msad = msad.command_line:main
3
-
@@ -1,2 +0,0 @@
1
- fire
2
- ldap3
msad-0.2.1/setup.cfg DELETED
@@ -1,8 +0,0 @@
1
- [metadata]
2
- description-file = README.md
3
- license_files = LICENSE
4
-
5
- [egg_info]
6
- tag_build =
7
- tag_date = 0
8
-
msad-0.2.1/setup.py DELETED
@@ -1,41 +0,0 @@
1
- # Copyright (c) 2021 Matteo Redaelli
2
- #
3
- # This program is free software: you can redistribute it and/or modify
4
- # it under the terms of the GNU General Public License as published by
5
- # the Free Software Foundation, either version 3 of the License, or
6
- # (at your option) any later version.
7
- #
8
- # This program is distributed in the hope that it will be useful,
9
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
- # GNU General Public License for more details.
12
- #
13
- # You should have received a copy of the GNU General Public License
14
- # along with this program. If not, see <https://www.gnu.org/licenses/>.
15
-
16
- import setuptools
17
-
18
- with open("README.md", "r") as fh:
19
- long_description = fh.read()
20
-
21
- setuptools.setup(
22
- name="msad",
23
- version="0.2.1",
24
- author="Matteo Redaelli",
25
- author_email="matteo.redaelli@gmail.com",
26
- description="msad is a library and commandline for interacting with Active Directory",
27
- long_description=long_description,
28
- long_description_content_type="text/markdown",
29
- url="https://github.com/matteoredaelli/msad",
30
- packages=setuptools.find_packages(),
31
- license="GPL",
32
- entry_points={
33
- "console_scripts": ["msad=msad.command_line:main"],
34
- },
35
- classifiers=[
36
- "Programming Language :: Python :: 3",
37
- "Operating System :: OS Independent",
38
- ],
39
- install_requires=["ldap3", "fire"],
40
- python_requires=">=3.6",
41
- )
File without changes
File without changes
File without changes
File without changes
File without changes