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 samba.getopt as options
25 from samba.auth import system_session
26 from samba.netcmd import Command, CommandError, Option
27 from samba.samdb import SamDB
29 class cmd_enableaccount(Command):
32 synopsis = "enableaccount [username] [options]"
34 takes_optiongroups = {
35 "sambaopts": options.SambaOptions,
36 "versionopts": options.VersionOptions,
37 "credopts": options.CredentialsOptions,
41 Option("-H", help="LDB URL for database or target server", type=str),
42 Option("--filter", help="LDAP Filter to set password on", type=str),
45 takes_args = ["username?"]
47 def run(self, username=None, sambaopts=None, credopts=None,
48 versionopts=None, filter=None, H=None):
49 if username is None and filter is None:
50 raise CommandError("Either the username or '--filter' must be specified!")
53 filter = "(&(objectClass=user)(sAMAccountName=%s))" % (username)
55 lp = sambaopts.get_loadparm()
56 creds = credopts.get_credentials(lp)
58 samdb = SamDB(url=H, session_info=system_session(),
59 credentials=creds, lp=lp)
60 samdb.enable_account(filter)