Permalink
Browse files

Added methods to shadow to set max days, min days, warn days, and ina…

…ctive days.
  • Loading branch information...
1 parent 357a288 commit 889d5d2facd3fbcebb7f3ac3fed0d21643800682 Jacob Albretsen committed May 8, 2012
Showing with 69 additions and 0 deletions.
  1. +69 −0 salt/modules/shadow.py
@@ -47,6 +47,57 @@ def info(name):
'expire': ''}
return ret
+def set_inactdays(name, inactdays):
+ '''
+ Set the number of days of inactivity after a password has expired before the account is locked. See man chage.
+
+ CLI Example::
+
+ salt '*' shadow.set_inactdays username 7
+ '''
+ pre_info = info(name)
+ if inactdays == pre_info['inact']:
+ return True
+ cmd = 'chage -I {0} {1}'.format(inactdays, name)
+ __salt__['cmd.run'](cmd)
+ post_info = info(name)
+ if post_info['inact'] != pre_info['inact']:
+ return post_info['inact'] == inactdays
+
+def set_maxdays(name, maxdays):
+ '''
+ Set the maximum number of days during which a password is valid. See man chage.
+
+ CLI Example::
+
+ salt '*' shadow.set_maxdays username 90
+ '''
+ pre_info = info(name)
+ if maxdays == pre_info['max']:
+ return True
+ cmd = 'chage -M {0} {1}'.format(maxdays, name)
+ __salt__['cmd.run'](cmd)
+ post_info = info(name)
+ if post_info['max'] != pre_info['max']:
+ return post_info['max'] == maxdays
+
+def set_mindays(name, mindays):
+ '''
+ Set the minimum number of days between password changes. See man chage.
+
+ CLI Example::
+
+ salt '*' shadow.set_mindays username 7
+ '''
+ pre_info = info(name)
+ if mindays == pre_info['min']:
+ return True
+ cmd = 'chage -m {0} {1}'.format(mindays, name)
+ __salt__['cmd.run'](cmd)
+ post_info = info(name)
+ if post_info['min'] != pre_info['min']:
+ return post_info['min'] == mindays
+ return False
def set_password(name, password):
'''
@@ -74,3 +125,21 @@ def set_password(name, password):
open(s_file, 'w+').writelines(lines)
uinfo = info(name)
return uinfo['pwd'] == password
+
+def set_warndays(name, warndays):
+ '''
+ Set the number of days of warning before a password change is required. See man chage.
+
+ CLI Example::
+
+ salt '*' shadow.set_warndays username 7
+ '''
+ pre_info = info(name)
+ if warndays == pre_info['warn']:
+ return True
+ cmd = 'chage -W {0} {1}'.format(warndays, name)
+ __salt__['cmd.run'](cmd)
+ post_info = info(name)
+ if post_info['warn'] != pre_info['warn']:
+ return post_info['warn'] == warndays
+ return False

0 comments on commit 889d5d2

Please sign in to comment.