File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -47,13 +47,14 @@ def is_locked(user_name: str) -> bool:
4747 """Check if a given user has password in shadow db"""
4848
4949 try :
50- import warnings
51- with warnings .catch_warnings ():
52- warnings .filterwarnings ("ignore" ,category = DeprecationWarning )
53- import spwd
54- encrypted_password = spwd .getspnam (user_name )[1 ]
55- return encrypted_password == '*' or encrypted_password .startswith ('!' )
56- except (KeyError , PermissionError ):
50+ with open ('/etc/shadow' , 'r' ) as f :
51+ for line in f .readlines ():
52+ args = line .strip ().split (':' )
53+ if len (args ) < 2 :
54+ continue
55+ if args [0 ] == user_name :
56+ return len (args [1 ]) > 0 and args [1 ].startswith ('!' )
57+ except PermissionError :
5758 print ('Cannot access shadow database, ensure this script is run with sufficient permissions' )
5859 sys .exit (1 )
5960
You can’t perform that action at this time.
0 commit comments