s4-make: add libds to etags/ctags source list
[Samba.git] / source4 / setup / setexpiry
blob2740326f2b493bef89434566e30534e812356e91
1 #!/usr/bin/python
3 # Sets the user password expiry on a Samba4 server
4 # Copyright Jelmer Vernooij 2008
6 # Based on the original in EJS:
7 # Copyright Andrew Tridgell 2005
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 3 of the License, or
12 # (at your option) any later version.
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program. If not, see <http://www.gnu.org/licenses/>.
23 import sys
25 # Find right directory when running from source tree
26 sys.path.insert(0, "bin/python")
28 import samba.getopt as options
29 import optparse
31 from samba.auth import system_session
32 from samba.samdb import SamDB
34 parser = optparse.OptionParser("setexpiry [username] [options]")
35 sambaopts = options.SambaOptions(parser)
36 parser.add_option_group(sambaopts)
37 parser.add_option_group(options.VersionOptions(parser))
38 credopts = options.CredentialsOptions(parser)
39 parser.add_option_group(credopts)
40 parser.add_option("-H", help="LDB URL for database or target server", type=str)
41 parser.add_option("--filter", help="LDAP Filter to set password on", type=str)
42 parser.add_option("--days", help="Days to expiry", type=int)
43 parser.add_option("--noexpiry", help="Password does never expire", action="store_true")
45 opts, args = parser.parse_args()
47 filter = opts.filter
49 if (len(args) == 0) and (filter is None):
50 print "Either the username or '--filter' must be specified!"
51 parser.print_usage()
52 sys.exit(1)
54 days = opts.days
55 if days is None:
56 days = 0
58 if filter is None:
59 username = args[0]
60 filter = "(&(objectClass=user)(sAMAccountName=%s))" % (username)
62 lp = sambaopts.get_loadparm()
63 creds = credopts.get_credentials(lp)
65 if opts.H is not None:
66 url = opts.H
67 else:
68 url = lp.get("sam database")
70 samdb = SamDB(url=url, session_info=system_session(), credentials=creds, lp=lp)
72 samdb.setexpiry(filter, days*24*3600, no_expiry_req=opts.noexpiry)