outf = sys.stdout
errf = sys.stderr
- def usage(self, *args):
- parser, _ = self._create_parser()
+ def usage(self, prog, *args):
+ parser, _ = self._create_parser(prog)
parser.print_usage()
def show_command_error(self, e):
if force_traceback or samba.get_debug_level() >= 3:
traceback.print_tb(etraceback)
- def _create_parser(self):
- parser = optparse.OptionParser(usage=self.synopsis,
- description=self.full_description)
+ def _create_parser(self, prog):
+ parser = optparse.OptionParser(
+ usage=self.synopsis,
+ description=self.full_description,
+ prog=prog)
parser.add_options(self.takes_options)
optiongroups = {}
for name, optiongroup in self.takes_optiongroups.iteritems():
self.outf.write(text+"\n")
def _run(self, *argv):
- parser, optiongroups = self._create_parser()
+ parser, optiongroups = self._create_parser(argv[0])
opts, args = parser.parse_args(list(argv))
# Filter out options from option groups
args = args[1:]
def _run(self, myname, subcommand=None, *args):
if subcommand in self.subcommands:
- return self.subcommands[subcommand]._run(subcommand, *args)
+ return self.subcommands[subcommand]._run(
+ "%s %s" % (myname, subcommand), *args)
- if myname == "samba-tool":
- usage = "samba-tool <subcommand>"
- else:
- usage = "samba-tool %s <subcommand>" % myname
- self.outf.write("Usage: %s [options]\n" % usage)
+ self.usage(myname)
self.outf.write("Available subcommands:\n")
subcmds = self.subcommands.keys()
subcmds.sort()
if subcommand in [None]:
raise CommandError("You must specify a subcommand")
if subcommand in ['help', '-h', '--help']:
- self.outf.write("For more help on a specific subcommand, please type: %s (-h|--help)\n" % usage)
+ self.outf.write("For more help on a specific subcommand, please type: %s (-h|--help)\n" % myname)
return 0
raise CommandError("No such subcommand '%s'" % subcommand)
class CommandError(Exception):
- '''an exception class for samba-tool cmd errors'''
+ """An exception class for samba-tool Command errors."""
+
def __init__(self, message, inner_exception=None):
self.message = message
self.inner_exception = inner_exception
class cmd_dbcheck(Command):
"""check local AD database for errors"""
- synopsis = "%prog dbcheck [<DN>] [options]"
+ synopsis = "%prog [<DN>] [options]"
takes_args = ["DN?"]
)
-
class cmd_delegation_show(Command):
"""Show the delegation setting of an account."""
-
- synopsis = "%prog delegation show <accountname> [options]"
+
+ synopsis = "%prog show <accountname> [options]"
takes_args = ["accountname"]
self.outf.write("msDS-AllowedToDelegateTo: %s\n" % a)
-
class cmd_delegation_for_any_service(Command):
"""Set/unset UF_TRUSTED_FOR_DELEGATION for an account."""
- synopsis = "%prog delegation for-any-service <accountname> [(on|off)] [options]"
+ synopsis = "%prog <accountname> [(on|off)] [options]"
takes_args = ["accountname", "onoff"]
raise CommandError(err)
-
class cmd_delegation_for_any_protocol(Command):
"""Set/unset UF_TRUSTED_TO_AUTHENTICATE_FOR_DELEGATION (S4U2Proxy) for an account."""
- synopsis = "%prog delegation for-any-protocol <accountname> [(on|off)] [options]"
+ synopsis = "%prog <accountname> [(on|off)] [options]"
takes_args = ["accountname", "onoff"]
raise CommandError(err)
-
class cmd_delegation_add_service(Command):
"""Add a service principal as msDS-AllowedToDelegateTo"""
- synopsis = "%prog delegation add-service <accountname> <principal> [options]"
+ synopsis = "%prog <accountname> <principal> [options]"
takes_args = ["accountname", "principal"]
raise CommandError(err)
-
class cmd_delegation_del_service(Command):
"""Delete a service principal as msDS-AllowedToDelegateTo"""
- synopsis = "%prog delegation del-service <accountname> <principal> [options]"
+ synopsis = "%prog <accountname> <principal> [options]"
takes_args = ["accountname", "principal"]
raise CommandError(err)
-
class cmd_delegation(SuperCommand):
"""Delegation management"""
class cmd_domain_export_keytab(Command):
"""Dumps kerberos keys of the domain into a keytab"""
- synopsis = "%prog domain exportkeytab <keytab> [options]"
+ synopsis = "%prog <keytab> [options]"
takes_options = [
]
class cmd_domain_join(Command):
"""Joins domain as either member or backup domain controller *"""
- synopsis = "%prog domain join <dnsdomain> [DC|RODC|MEMBER|SUBDOMAIN] [options]"
+ synopsis = "%prog <dnsdomain> [DC|RODC|MEMBER|SUBDOMAIN] [options]"
takes_options = [
Option("--server", help="DC to join", type=str),
class cmd_domain_level(Command):
"""Raises domain and forest function levels"""
- synopsis = "%prog domain level (show|raise <options>) [options]"
+ synopsis = "%prog (show|raise <options>) [options]"
takes_options = [
Option("-H", "--URL", help="LDB URL for database or target server", type=str,
class cmd_domain_machinepassword(Command):
"""Gets a machine password out of our SAM"""
- synopsis = "%prog domain machinepassword <accountname> [options]"
+ synopsis = "%prog <accountname> [options]"
takes_args = ["secret"]
and maximum password age) on a Samba4 server.
"""
- synopsis = "%prog domain passwordsettings (show|set <options>) [options]"
+ synopsis = "%prog (show|set <options>) [options]"
takes_options = [
Option("-H", "--URL", help="LDB URL for database or target server", type=str,
samba3 testparm utility (with --testparm).
"""
- synopsis = "%prog domain samba3upgrade [options] <samba3_smb_conf>"
+ synopsis = "%prog [options] <samba3_smb_conf>"
takes_optiongroups = {
"sambaopts": options.SambaOptions,
class cmd_drs_showrepl(Command):
"""show replication status"""
- synopsis = "%prog drs showrepl [<DC>] [options]"
+ synopsis = "%prog [<DC>] [options]"
takes_args = ["DC?"]
class cmd_drs_kcc(Command):
"""trigger knowledge consistency center run"""
- synopsis = "%prog drs kcc [<DC>] [options]"
+ synopsis = "%prog [<DC>] [options]"
takes_args = ["DC?"]
class cmd_drs_replicate(Command):
"""replicate a naming context between two DCs"""
- synopsis = "%prog drs replicate <destinationDC> <sourceDC> <NC> [options]"
+ synopsis = "%prog <destinationDC> <sourceDC> <NC> [options]"
takes_args = ["DEST_DC", "SOURCE_DC", "NC"]
class cmd_drs_bind(Command):
"""show DRS capabilities of a server"""
- synopsis = "%prog drs bind [<DC>] [options]"
+ synopsis = "%prog [<DC>] [options]"
takes_args = ["DC?"]
class cmd_drs_options(Command):
"""query or change 'options' for NTDS Settings object of a domain controller"""
- synopsis = ("%prog drs options [<DC>] [options]")
+ synopsis = "%prog [<DC>] [options]"
takes_args = ["DC?"]
class cmd_dsacl_set(Command):
"""Modify access list on a directory object"""
- synopsis = "%prog dsacl set [options]"
+ synopsis = "%prog [options]"
car_help = """ The access control right to allow or deny """
takes_options = [
from samba.samdb import SamDB
-
class cmd_fsmo_seize(Command):
"""Seize the role"""
-
- synopsis = "%prog fsmo seize [options]"
+
+ synopsis = "%prog [options]"
takes_options = [
Option("-H", "--URL", help="LDB URL for database or target server", type=str,
def run(self, force=None, H=None, role=None,
credopts=None, sambaopts=None, versionopts=None):
-
+
lp = sambaopts.get_loadparm()
creds = credopts.get_credentials(lp, fallback_machine=True)
self.seize_role(role, samdb, force)
-
class cmd_fsmo_show(Command):
"""Show the roles"""
- synopsis = "%prog fsmo show [options]"
+ synopsis = "%prog [options]"
takes_options = [
Option("-H", "--URL", help="LDB URL for database or target server", type=str,
takes_args = []
- def run(self, H=None,
- credopts=None, sambaopts=None, versionopts=None):
+ def run(self, H=None, credopts=None, sambaopts=None, versionopts=None):
lp = sambaopts.get_loadparm()
creds = credopts.get_credentials(lp, fallback_machine=True)
self.message("PdcEmulationMasterRole owner: " + self.pdcEmulator)
self.message("DomainNamingMasterRole owner: " + self.namingMaster)
self.message("SchemaMasterRole owner: " + self.schemaMaster)
-
class cmd_fsmo_transfer(Command):
"""Transfer the role"""
- synopsis = "%prog fsmo transfer [options]"
+ synopsis = "%prog [options]"
takes_options = [
Option("-H", "--URL", help="LDB URL for database or target server", type=str,
self.transfer_role(role, samdb)
-
class cmd_fsmo(SuperCommand):
"""Flexible Single Master Operations (FSMO) roles management"""
class cmd_listall(Command):
"""list all GPOs"""
- synopsis = "%prog gpo listall [options]"
+ synopsis = "%prog [options]"
takes_options = [
Option("-H", "--URL", help="LDB URL for database or target server", type=str,
class cmd_list(Command):
"""list GPOs for an account"""
- synopsis = "%prog gpo list <username> [options]"
+ synopsis = "%prog <username> [options]"
- takes_args = [ 'username' ]
+ takes_args = ['username']
takes_options = [
- Option("-H", "--URL", help="LDB URL for database or target server", type=str,
- metavar="URL", dest="H")
+ Option("-H", "--URL", help="LDB URL for database or target server",
+ type=str, metavar="URL", dest="H")
]
def run(self, username, H=None, sambaopts=None, credopts=None, versionopts=None):
class cmd_show(Command):
"""Show information for a GPO"""
- synopsis = "%prog gpo show <gpo> [options]"
+ synopsis = "%prog <gpo> [options]"
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"credopts": options.CredentialsOptions,
}
- takes_args = [ 'gpo' ]
+ takes_args = ['gpo']
takes_options = [
Option("-H", help="LDB URL for database or target server", type=str)
class cmd_getlink(Command):
"""List GPO Links for a container"""
- synopsis = "%prog gpo getlink <container_dn> [options]"
+ synopsis = "%prog <container_dn> [options]"
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"credopts": options.CredentialsOptions,
}
- takes_args = [ 'container_dn' ]
+ takes_args = ['container_dn']
takes_options = [
Option("-H", help="LDB URL for database or target server", type=str)
class cmd_setlink(Command):
"""Add or Update a GPO link to a container"""
- synopsis = "%prog gpo setlink <container_dn> <gpo> [options]"
+ synopsis = "%prog <container_dn> <gpo> [options]"
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"credopts": options.CredentialsOptions,
}
- takes_args = [ 'container_dn', 'gpo' ]
+ takes_args = ['container_dn', 'gpo']
takes_options = [
Option("-H", help="LDB URL for database or target server", type=str),
class cmd_dellink(Command):
"""Delete GPO link from a container"""
- synopsis = "%prog gpo dellink <container_dn> <gpo> [options]"
+ synopsis = "%prog <container_dn> <gpo> [options]"
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"credopts": options.CredentialsOptions,
}
- takes_args = [ 'container_dn', 'gpo' ]
+ takes_args = ['container_dn', 'gpo']
takes_options = [
Option("-H", help="LDB URL for database or target server", type=str),
class cmd_getinheritance(Command):
"""Get inheritance flag for a container"""
- synopsis = "%prog gpo getinheritance <container_dn> [options]"
+ synopsis = "%prog <container_dn> [options]"
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"credopts": options.CredentialsOptions,
}
- takes_args = [ 'container_dn' ]
+ takes_args = ['container_dn']
takes_options = [
Option("-H", help="LDB URL for database or target server", type=str)
class cmd_setinheritance(Command):
"""Set inheritance flag on a container"""
- synopsis = "%prog gpo setinheritance <container_dn> <block|inherit> [options]"
+ synopsis = "%prog <container_dn> <block|inherit> [options]"
takes_optiongroups = {
"sambaopts": options.SambaOptions,
class cmd_fetch(Command):
"""Download a GPO"""
- synopsis = "%prog gpo fetch <gpo> [options]"
+ synopsis = "%prog <gpo> [options]"
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"credopts": options.CredentialsOptions,
}
- takes_args = [ 'gpo' ]
+ takes_args = ['gpo']
takes_options = [
Option("-H", help="LDB URL for database or target server", type=str),
class cmd_create(Command):
"""Create an empty GPO"""
- synopsis = "%prog gpo create <displayname> [options]"
+ synopsis = "%prog <displayname> [options]"
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"credopts": options.CredentialsOptions,
}
- takes_args = [ 'displayname' ]
+ takes_args = ['displayname']
takes_options = [
Option("-H", help="LDB URL for database or target server", type=str),
class cmd_group_add(Command):
"""Creates a new group"""
- synopsis = "%prog group add <groupname> [options]"
+ synopsis = "%prog <groupname> [options]"
takes_options = [
Option("-H", "--URL", help="LDB URL for database or target server", type=str,
class cmd_group_delete(Command):
"""Delete a group"""
- synopsis = "%prog group delete <groupname> [options]"
+ synopsis = "%prog <groupname> [options]"
takes_options = [
Option("-H", "--URL", help="LDB URL for database or target server", type=str,
class cmd_group_add_members(Command):
"""Add (comma-separated list of) group members"""
- synopsis = "%prog group addmembers <groupname> <listofmembers> [options]"
+ synopsis = "%prog <groupname> <listofmembers> [options]"
takes_options = [
Option("-H", "--URL", help="LDB URL for database or target server", type=str,
class cmd_group_remove_members(Command):
"""Remove (comma-separated list of) group members"""
- synopsis = "%prog group removemembers <groupname> <listofmembers> [options]"
+ synopsis = "%prog <groupname> <listofmembers> [options]"
takes_options = [
Option("-H", "--URL", help="LDB URL for database or target server", type=str,
class cmd_ldapcmp(Command):
"""compare two ldap databases"""
- synopsis = "%prog ldapcmp <URL1> <URL2> (domain|configuration|schema) [options]"
+ synopsis = "%prog <URL1> <URL2> (domain|configuration|schema) [options]"
takes_optiongroups = {
"sambaopts": options.SambaOptions,
class cmd_ntacl_set(Command):
"""Set ACLs on a file"""
- synopsis = "%prog set <acl> <file> [options]"
+ synopsis = "%prog <acl> <file> [options]"
takes_options = [
Option("--quiet", help="Be quiet", action="store_true"),
class cmd_ntacl_get(Command):
"""Set ACLs on a file"""
- synopsis = "%prog get <file> [options]"
+ synopsis = "%prog <file> [options]"
takes_options = [
Option("--as-sddl", help="Output ACL in the SDDL format", action="store_true"),
from samba.auth import system_session
import ldb
from samba.dcerpc import misc, drsuapi
-from samba.credentials import Credentials
from samba.drs_utils import drs_Replicate
-
class cmd_rodc_preload(Command):
"""Preload one account for an RODC"""
- synopsis = "%prog rodc preload (<SID>|<DN>|<accountname>) [options]"
+ synopsis = "%prog (<SID>|<DN>|<accountname>) [options]"
takes_options = [
Option("--server", help="DC to use", type=str),
)
-
class cmd_spn_list(Command):
"""List spns of a given user."""
- synopsis = "%prog spn list <user> [options]"
+ synopsis = "%prog <user> [options]"
takes_args = ["user"]
raise CommandError("User %s not found" % user)
-
class cmd_spn_add(Command):
"""Create a new spn."""
- synopsis = "%prog spn add <name> <user> [options]"
+ synopsis = "%prog <name> <user> [options]"
takes_options = [
Option("--force", help="Force the addition of the spn"\
raise CommandError("User %s not found" % user)
-
class cmd_spn_delete(Command):
"""Delete a spn."""
- synopsis = "%prog spn delete <name> [user] [options]"
+ synopsis = "%prog <name> [user] [options]"
takes_args = ["name", "user?"]
raise CommandError("Service principal %s not affected" % name)
-
class cmd_spn(SuperCommand):
"""Service Principal Name (SPN) management"""
class cmd_testparm(Command):
"""Syntax check the configuration file."""
- synopsis = "%prog testparm [options]"
+ synopsis = "%prog [options]"
takes_optiongroups = {
"sambaopts" : options.SambaOptions,
class cmd_time(Command):
"""Retrieve the time on a remote server"""
- synopsis = "%prog time [server-name] [options]"
+ synopsis = "%prog [server-name] [options]"
takes_args = ["server_name?"]
)
-
class cmd_user_add(Command):
"""Creates a new user"""
- synopsis = "%prog user add <username> [<password>] [options]"
+ synopsis = "%prog <username> [<password>] [options]"
takes_options = [
Option("-H", "--URL", help="LDB URL for database or target server", type=str,
class cmd_user_delete(Command):
"""Delete a user"""
- synopsis = "%prog user delete <username> [options]"
+ synopsis = "%prog <username> [options]"
takes_options = [
Option("-H", "--URL", help="LDB URL for database or target server", type=str,
class cmd_user_enable(Command):
"""Enables a user"""
- synopsis = "%prog user enable (<username>|--filter <filter>) [options]"
+ synopsis = "%prog (<username>|--filter <filter>) [options]"
takes_options = [
Option("-H", "--URL", help="LDB URL for database or target server", type=str,
class cmd_user_setexpiry(Command):
"""Sets the expiration of a user account"""
- synopsis = "%prog user setexpiry (<username>|--filter <filter>) [options]"
+ synopsis = "%prog (<username>|--filter <filter>) [options]"
takes_options = [
Option("-H", "--URL", help="LDB URL for database or target server", type=str,
class cmd_user_password(Command):
"""Change password for a user account (the one provided in authentication)"""
- synopsis = "%prog user password [options]"
+ synopsis = "%prog [options]"
takes_options = [
Option("--newpassword", help="New password", type=str),
class cmd_user_setpassword(Command):
"""(Re)sets the password of a user account"""
- synopsis = "%prog user setpassword (<username>|--filter <filter>) [options]"
+ synopsis = "%prog (<username>|--filter <filter>) [options]"
takes_options = [
Option("-H", "--URL", help="LDB URL for database or target server", type=str,
self.outf.write("Changed password OK\n")
-
class cmd_user(SuperCommand):
"""User management"""
CommandError
)
+
class cmd_vampire(Command):
"""Join and synchronise a remote AD domain to the local server"""
- synopsis = "%prog vampire [options] <domain>"
+ synopsis = "%prog [options] <domain>"
takes_options = [
Option("--target-dir", help="Target directory.", type=str),