s4-netlogon: implement dcesrv_netr_DsRAddressToSitenamesExW
[Samba/aatanasov.git] / source4 / setup / enableaccount
blob0ca5b39faaaa6bd997993099e8005dd65400db37
1 #!/usr/bin/python
3 # Enables an user account 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 sys.path.insert(0, "bin/python")
27 import samba.getopt as options
28 import optparse
30 from samba.auth import system_session
31 from samba.samdb import SamDB
33 parser = optparse.OptionParser("enableaccount [username] [options]")
34 sambaopts = options.SambaOptions(parser)
35 parser.add_option_group(sambaopts)
36 parser.add_option_group(options.VersionOptions(parser))
37 credopts = options.CredentialsOptions(parser)
38 parser.add_option_group(credopts)
39 parser.add_option("--filter", help="LDAP Filter to set password on", type=str)
41 opts, args = parser.parse_args()
43 filter = opts.filter
45 if (len(args) == 0) and (filter is None):
46 print "Either the username or '--filter' must be specified!"
47 parser.print_usage()
48 sys.exit(1)
50 if filter is None:
51 username = args[0]
52 filter = "(&(objectClass=user)(sAMAccountName=%s))" % (username)
54 lp = sambaopts.get_loadparm()
55 creds = credopts.get_credentials(lp)
57 samdb = SamDB(url=lp.get("sam database"), session_info=system_session(),
58 credentials=creds, lp=lp)
59 samdb.enable_account(filter)