msad 0.2.1__tar.gz → 0.3.2__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.
msad-0.3.2/.gitignore ADDED
@@ -0,0 +1,129 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ pip-wheel-metadata/
24
+ share/python-wheels/
25
+ *.egg-info/
26
+ .installed.cfg
27
+ *.egg
28
+ MANIFEST
29
+
30
+ # PyInstaller
31
+ # Usually these files are written by a python script from a template
32
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
33
+ *.manifest
34
+ *.spec
35
+
36
+ # Installer logs
37
+ pip-log.txt
38
+ pip-delete-this-directory.txt
39
+
40
+ # Unit test / coverage reports
41
+ htmlcov/
42
+ .tox/
43
+ .nox/
44
+ .coverage
45
+ .coverage.*
46
+ .cache
47
+ nosetests.xml
48
+ coverage.xml
49
+ *.cover
50
+ *.py,cover
51
+ .hypothesis/
52
+ .pytest_cache/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ target/
76
+
77
+ # Jupyter Notebook
78
+ .ipynb_checkpoints
79
+
80
+ # IPython
81
+ profile_default/
82
+ ipython_config.py
83
+
84
+ # pyenv
85
+ .python-version
86
+
87
+ # pipenv
88
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
89
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
90
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
91
+ # install all needed dependencies.
92
+ #Pipfile.lock
93
+
94
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow
95
+ __pypackages__/
96
+
97
+ # Celery stuff
98
+ celerybeat-schedule
99
+ celerybeat.pid
100
+
101
+ # SageMath parsed files
102
+ *.sage.py
103
+
104
+ # Environments
105
+ .env
106
+ .venv
107
+ env/
108
+ venv/
109
+ ENV/
110
+ env.bak/
111
+ venv.bak/
112
+
113
+ # Spyder project settings
114
+ .spyderproject
115
+ .spyproject
116
+
117
+ # Rope project settings
118
+ .ropeproject
119
+
120
+ # mkdocs documentation
121
+ /site
122
+
123
+ # mypy
124
+ .mypy_cache/
125
+ .dmypy.json
126
+ dmypy.json
127
+
128
+ # Pyre type checker
129
+ .pyre/
@@ -1,17 +1,16 @@
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
10
- 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
11
10
  Classifier: Operating System :: OS Independent
12
- Requires-Python: >=3.6
11
+ Classifier: Programming Language :: Python :: 3
12
+ Requires-Python: >=3.9
13
13
  Description-Content-Type: text/markdown
14
- License-File: LICENSE
15
14
 
16
15
  # msAD
17
16
 
@@ -23,13 +22,59 @@ msad is a library and command line tool for working with an Active Directory / L
23
22
  - change AD passwords
24
23
  - check if a user is disabled or locked, group membership
25
24
 
26
- ## Install
25
+
26
+ ## Usage
27
27
 
28
28
  ```bash
29
- pip install msad
29
+ msad --help
30
30
  ```
31
31
 
32
- ## Usage
32
+ ```text
33
+ COMMAND is one of the following:
34
+
35
+ add_member
36
+ Adds the user to a group (using DN or sAMAccountName)
37
+
38
+ change_password
39
+
40
+ check_user
41
+ Get some info about a user: is it locked? disabled? password expired?
42
+
43
+ group_flat_members
44
+ Extract all the (nested) members of a group
45
+
46
+ group_member
47
+ Check if the user is a member of a group (using DN or sAMAccountName)
48
+
49
+ group_members
50
+ Extract the direct members of a group
51
+
52
+ has_expired_password
53
+ Check is user has the expired password
54
+
55
+ has_never_expires_password
56
+ Check if a user has never expires password
57
+
58
+ is_disabled
59
+ Check if a user is disabled
60
+
61
+ is_locked
62
+ Check if the user is locked
63
+
64
+ remove_member
65
+ Remove the user from a group (using DN or sAMAccountName)
66
+
67
+ search
68
+
69
+ user_groups
70
+ Extract the list of groups of a user (using DN or sAMAccountName)
71
+
72
+ users
73
+ Find users inside AD. The filter can be the cn or userPrincipalName or samaccoutnname or mail to be searched. Can contain *
74
+
75
+ ```
76
+
77
+ ## Sample
33
78
 
34
79
  I find useful to add an alias in my ~/.bash_aliases
35
80
 
@@ -61,11 +106,9 @@ msad --out_format csv --attributes samaccountname,mail,sn,givenName group_flat_m
61
106
 
62
107
  ## License
63
108
 
64
- Copyright © 2021 Matteo Redaelli
109
+ Copyright © 2021 2022 Matteo Redaelli
65
110
 
66
111
  This program is free software: you can redistribute it and/or modify
67
112
  it under the terms of the GNU General Public License as published by
68
113
  the Free Software Foundation, either version 3 of the License, or
69
114
  (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,28 @@
1
+ [project]
2
+ name = "msad"
3
+ version = "0.3.2"
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.9"
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-files = ["LICENSE"]
17
+ #license-expression = "*"
18
+
19
+ [project.urls]
20
+ Homepage = "https://github.com/matteoredaelli/msad"
21
+ Issues = "https://github.com/matteoredaelli/msad/issues"
22
+
23
+ [project.scripts]
24
+ msad = "msad:command_line"
25
+
26
+ [build-system]
27
+ requires = ["hatchling >= 1.26"]
28
+ build-backend = "hatchling.build"
@@ -0,0 +1,4 @@
1
+ ldap3
2
+ gssapi
3
+ cryptography
4
+ fire
@@ -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):
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 +0,0 @@
1
-
@@ -1,3 +0,0 @@
1
- [console_scripts]
2
- msad = msad.command_line:main
3
-
@@ -1,2 +0,0 @@
1
- fire
2
- ldap3
@@ -1 +0,0 @@
1
- msad
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