sys.exit(1)
return l
-def do_one_user(lc, user, ticket):
- u = UDLdap.Account(user)
- if not u.account_status() == 'active':
+def do_one_user(lc, user, ticket, status):
+ try:
+ u = UDLdap.Account.from_search(lc, BaseDn, user)
+ except IndexError, e:
+ sys.stderr.write("Cannot instantiate account from LDAP: %s"%(str(e)))
+ return
+ if not u['accountStatus'] == 'active':
sys.stderr.write('%s: Account is not active, skipping. (details: %s)\n'%(user, u.verbose_status()))
return
- print '%s: Setting to retiring:'%(user)
+ print '%s: Setting to %s:'%(user, status)
set = {}
set['userPassword'] = '{crypt}*LK*'
set['shadowLastChange'] = str(int(time.time()/24/60/60))
set['shadowExpire'] = '1'
- set['accountStatus'] = 'retiring %s'%(time.strftime('%Y-%m-%d'))
+ set['accountStatus'] = '%s %s'%(status, time.strftime('%Y-%m-%d'))
if not ticket is None:
set['accountComment'] = "RT#%s"%(ticket)
help="Do not actually change anything.")
parser.add_option("-r", "--rt-ticket", dest="ticket", metavar="ticket#",
help="Ticket number for accountComment.")
+parser.add_option("-s", "--status", dest="status", metavar="status",
+ default='retiring',
+ help="Set status to <status> (default: retiring).")
(options, args) = parser.parse_args()
lc = connect(options.admin)
for user in args:
- do_one_user(lc, user, options.ticket)
+ do_one_user(lc, user, options.ticket, options.status)
# vim:set et: