The option groups should be defined at the Command base class level as they are in common across all samba-tool commands.
Major move advantages:
1. more OOP approach
2. enforcing consistency across commands
3. avoiding the need of declaring for every new command
Signed-off-by: Andrew Tridgell <tridge@samba.org>
# Unix SMB/CIFS implementation.
# Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2009
# Copyright (C) Theresa Halloran <theresahalloran@gmail.com> 2011
+# Copyright Giampaolo Lauria 2011 <lauria2@yahoo.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
takes_args = []
takes_options = []
- takes_optiongroups = {}
+ takes_optiongroups = {
+ "sambaopts": options.SambaOptions,
+ "credopts": options.CredentialsOptions,
+ "versionopts": options.VersionOptions,
+ }
def _create_parser(self):
parser = optparse.OptionParser(self.synopsis)
# Samba4 AD database checker
#
# Copyright (C) Andrew Tridgell 2011
+# Copyright Giampaolo Lauria 2011 <lauria2@yahoo.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
"""check local AD database for errors"""
synopsis = "dbcheck <DN> [options]"
- takes_optiongroups = {
- "sambaopts": options.SambaOptions,
- "versionopts": options.VersionOptions,
- "credopts": options.CredentialsOptionsDouble,
- }
-
takes_args = ["DN?"]
takes_options = [
# Copyright Matthieu Patou mat@samba.org 2010
# Copyright Stefan Metzmacher metze@samba.org 2011
# Copyright Bjoern Baumbach bb@sernet.de 2011
+# Copyright Giampaolo Lauria 2011 <lauria2@yahoo.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
"""Show the delegation setting of an account."""
synopsis = "%prog delegation show <accountname>"
- takes_optiongroups = {
- "sambaopts": options.SambaOptions,
- "credopts": options.CredentialsOptions,
- "versionopts": options.VersionOptions,
- }
-
takes_args = ["accountname"]
def run(self, accountname, credopts=None, sambaopts=None, versionopts=None):
"""Set/unset UF_TRUSTED_FOR_DELEGATION for an account."""
synopsis = "%prog delegation for-any-service <accountname> on|off"
- takes_optiongroups = {
- "sambaopts": options.SambaOptions,
- "credopts": options.CredentialsOptions,
- "versionopts": options.VersionOptions,
- }
-
takes_args = ["accountname", "onoff"]
def run(self, accountname, onoff, credopts=None, sambaopts=None, versionopts=None):
"""Set/unset UF_TRUSTED_TO_AUTHENTICATE_FOR_DELEGATION (S4U2Proxy) for an account."""
synopsis = "%prog delegation for-any-protocol <accountname> on|off"
- takes_optiongroups = {
- "sambaopts": options.SambaOptions,
- "credopts": options.CredentialsOptions,
- "versionopts": options.VersionOptions,
- }
-
takes_args = ["accountname", "onoff"]
def run(self, accountname, onoff, credopts=None, sambaopts=None, versionopts=None):
"""Add a service principal as msDS-AllowedToDelegateTo"""
synopsis = "%prog delegation add-service <accountname> <principal>"
- takes_optiongroups = {
- "sambaopts": options.SambaOptions,
- "credopts": options.CredentialsOptions,
- "versionopts": options.VersionOptions,
- }
-
takes_args = ["accountname", "principal"]
def run(self, accountname, principal, credopts=None, sambaopts=None, versionopts=None):
"""Add a service principal as msDS-AllowedToDelegateTo"""
synopsis = "%prog delegation del-service <accountname> <principal>"
- takes_optiongroups = {
- "sambaopts": options.SambaOptions,
- "credopts": options.CredentialsOptions,
- "versionopts": options.VersionOptions,
- }
-
takes_args = ["accountname", "principal"]
def run(self, accountname, principal, credopts=None, sambaopts=None, versionopts=None):
"""Dumps kerberos keys of the domain into a keytab"""
synopsis = "%prog domain dumpkeys <keytab>"
- takes_optiongroups = {
- "sambaopts": options.SambaOptions,
- "credopts": options.CredentialsOptions,
- "versionopts": options.VersionOptions,
- }
-
takes_options = [
]
synopsis = "%prog domain join <dnsdomain> [DC | RODC | MEMBER] [options]"
- takes_optiongroups = {
- "sambaopts": options.SambaOptions,
- "versionopts": options.VersionOptions,
- "credopts": options.CredentialsOptions,
- }
-
takes_options = [
Option("--server", help="DC to join", type=str),
Option("--site", help="site to join", type=str),
synopsis = "%prog domain level (show | raise <options>)"
- takes_optiongroups = {
- "sambaopts": options.SambaOptions,
- "credopts": options.CredentialsOptions,
- "versionopts": options.VersionOptions,
- }
-
takes_options = [
Option("-H", help="LDB URL for database or target server", type=str),
Option("--quiet", help="Be quiet", action="store_true"),
synopsis = "%prog domain machinepassword <accountname>"
- takes_optiongroups = {
- "sambaopts": options.SambaOptions,
- "versionopts": options.VersionOptions,
- "credopts": options.CredentialsOptions,
- }
-
takes_args = ["secret"]
def run(self, secret, sambaopts=None, credopts=None, versionopts=None):
synopsis = "%prog domain passwordsettings (show | set <options>)"
- takes_optiongroups = {
- "sambaopts": options.SambaOptions,
- "versionopts": options.VersionOptions,
- "credopts": options.CredentialsOptions,
- }
-
takes_options = [
Option("-H", help="LDB URL for database or target server", type=str),
Option("--quiet", help="Be quiet", action="store_true"),
# implement samba_tool drs commands
#
# Copyright Andrew Tridgell 2010
+# Copyright Giampaolo Lauria 2011 <lauria2@yahoo.com>
#
# based on C implementation by Kamen Mazdrashki <kamen.mazdrashki@postpath.com>
#
synopsis = "%prog drs showrepl <DC>"
- takes_optiongroups = {
- "sambaopts": options.SambaOptions,
- "versionopts": options.VersionOptions,
- "credopts": options.CredentialsOptions,
- }
-
takes_args = ["DC?"]
def print_neighbour(self, n):
synopsis = "%prog drs kcc <DC>"
- takes_optiongroups = {
- "sambaopts": options.SambaOptions,
- "versionopts": options.VersionOptions,
- "credopts": options.CredentialsOptions,
- }
-
takes_args = ["DC?"]
def run(self, DC=None, sambaopts=None,
synopsis = "%prog drs replicate <DEST_DC> <SOURCE_DC> <NC>"
- takes_optiongroups = {
- "sambaopts": options.SambaOptions,
- "versionopts": options.VersionOptions,
- "credopts": options.CredentialsOptions,
- }
-
takes_args = ["DEST_DC", "SOURCE_DC", "NC"]
takes_options = [
synopsis = "%prog drs bind <DC>"
- takes_optiongroups = {
- "sambaopts": options.SambaOptions,
- "versionopts": options.VersionOptions,
- "credopts": options.CredentialsOptions,
- }
-
takes_args = ["DC?"]
def run(self, DC=None, sambaopts=None,
" [--dsa-option={+|-}IS_GC | {+|-}DISABLE_INBOUND_REPL"
" |{+|-}DISABLE_OUTBOUND_REPL | {+|-}DISABLE_NTDSCONN_XLATE]")
- takes_optiongroups = {
- "sambaopts": options.SambaOptions,
- "versionopts": options.VersionOptions,
- "credopts": options.CredentialsOptions,
- }
-
takes_args = ["DC?"]
takes_options = [
# Manipulate ACLs on directory objects
#
# Copyright (C) Nadezhda Ivanova <nivanova@samba.org> 2010
+# Copyright Giampaolo Lauria 2011 <lauria2@yahoo.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
synopsis = "set --objectdn=objectdn --car=control right --action=[deny|allow] --trusteedn=trustee-dn"
car_help = """ The access control right to allow or deny """
- takes_optiongroups = {
- "sambaopts": options.SambaOptions,
- "credopts": options.CredentialsOptions,
- "versionopts": options.VersionOptions,
- }
-
takes_options = [
Option("--host", help="LDB URL for database or target server",
type=str),
#
# Copyright Nadezhda Ivanova 2009
# Copyright Jelmer Vernooij 2009
+# Copyright Giampaolo Lauria 2011 <lauria2@yahoo.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
synopsis = "(show | transfer <options> | seize <options>)"
- takes_optiongroups = {
- "sambaopts": options.SambaOptions,
- "credopts": options.CredentialsOptions,
- "versionopts": options.VersionOptions,
- }
-
takes_options = [
Option("--url", help="LDB URL for database or target server", type=str),
Option("--force", help="Force seizing of the role without attempting to transfer first.", action="store_true"),
# implement samba_tool gpo commands
#
# Copyright Andrew Tridgell 2010
+# Copyright Giampaolo Lauria 2011 <lauria2@yahoo.com>
#
# based on C implementation by Guenther Deschner and Wilco Baan Hofman
#
synopsis = "%prog gpo listall"
- takes_optiongroups = {
- "sambaopts": options.SambaOptions,
- "versionopts": options.VersionOptions,
- "credopts": options.CredentialsOptions,
- }
-
takes_options = [
Option("-H", help="LDB URL for database or target server", type=str)
]
synopsis = "%prog gpo list <username>"
- takes_optiongroups = {
- "sambaopts": options.SambaOptions,
- "versionopts": options.VersionOptions,
- "credopts": options.CredentialsOptions,
- }
-
takes_args = [ 'username' ]
takes_options = [
#
# Based on the original in EJS:
# Copyright Andrew Tridgell 2005
+# Copyright Giampaolo Lauria 2011 <lauria2@yahoo.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
synopsis = "%prog group add [options] <groupname>"
- takes_optiongroups = {
- "sambaopts": options.SambaOptions,
- "versionopts": options.VersionOptions,
- "credopts": options.CredentialsOptions,
- }
-
takes_options = [
Option("-H", help="LDB URL for database or target server", type=str),
Option("--groupou",
synopsis = "%prog group delete <groupname>"
- takes_optiongroups = {
- "sambaopts": options.SambaOptions,
- "versionopts": options.VersionOptions,
- "credopts": options.CredentialsOptions,
- }
-
takes_options = [
Option("-H", help="LDB URL for database or target server", type=str),
]
synopsis = "%prog group addmembers <groupname> <listofmembers>"
- takes_optiongroups = {
- "sambaopts": options.SambaOptions,
- "versionopts": options.VersionOptions,
- "credopts": options.CredentialsOptions,
- }
-
takes_options = [
Option("-H", help="LDB URL for database or target server", type=str),
]
synopsis = "%prog group removemembers <groupname> <listofmembers>"
- takes_optiongroups = {
- "sambaopts": options.SambaOptions,
- "versionopts": options.VersionOptions,
- "credopts": options.CredentialsOptions,
- }
-
takes_options = [
Option("-H", help="LDB URL for database or target server", type=str),
]
# above partitions.
# Copyright (C) Zahari Zahariev <zahari.zahariev@postpath.com> 2009, 2010
+# Copyright Giampaolo Lauria 2011 <lauria2@yahoo.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
"""compare two ldap databases"""
synopsis = "ldapcmp URL1 URL2 <domain|configuration|schema> [options]"
- takes_optiongroups = {
- "sambaopts": options.SambaOptions,
- "versionopts": options.VersionOptions,
- "credopts": options.CredentialsOptionsDouble,
- }
-
takes_args = ["URL1", "URL2", "context1?", "context2?", "context3?"]
takes_options = [
#
# Copyright (C) Matthieu Patou <mat@matws.net> 2010
# Copyright (C) Nadezhda Ivanova <nivanova@samba.org> 2010
+# Copyright Giampaolo Lauria 2011 <lauria2@yahoo.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
#
# Based on the original in EJS:
# Copyright Andrew Tridgell 2005
+# Copyright Giampaolo Lauria 2011 <lauria2@yahoo.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
synopsis = "newuser [options] <username> [<password>]"
- takes_optiongroups = {
- "sambaopts": options.SambaOptions,
- "versionopts": options.VersionOptions,
- "credopts": options.CredentialsOptions,
- }
-
takes_options = [
Option("-H", help="LDB URL for database or target server", type=str),
Option("--must-change-at-next-login",
# Manipulate file NT ACLs
#
# Copyright Matthieu Patou 2010 <mat@matws.net>
+# Copyright Giampaolo Lauria 2011 <lauria2@yahoo.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
"""Set ACLs on a file"""
synopsis = "%prog set <acl> <file> [--xattr-backend=native|tdb] [--eadb-file=file] [options]"
- takes_optiongroups = {
- "sambaopts": options.SambaOptions,
- "credopts": options.CredentialsOptions,
- "versionopts": options.VersionOptions,
- }
-
takes_options = [
Option("--quiet", help="Be quiet", action="store_true"),
Option("--xattr-backend", type="choice", help="xattr backend type (native fs or tdb)",
"""Set ACLs on a file"""
synopsis = "%prog get <file> [--as-sddl] [--xattr-backend=native|tdb] [--eadb-file=file] [options]"
- takes_optiongroups = {
- "sambaopts": options.SambaOptions,
- "credopts": options.CredentialsOptions,
- "versionopts": options.VersionOptions,
- }
-
takes_options = [
Option("--as-sddl", help="Output ACL in the SDDL format", action="store_true"),
Option("--xattr-backend", type="choice", help="xattr backend type (native fs or tdb)",
# rodc related commands
#
# Copyright Andrew Tridgell 2010
+# Copyright Giampaolo Lauria 2011 <lauria2@yahoo.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
synopsis = "%prog rodc preload <SID|DN|accountname>"
- takes_optiongroups = {
- "sambaopts": options.SambaOptions,
- "versionopts": options.VersionOptions,
- "credopts": options.CredentialsOptions,
- }
-
takes_options = [
Option("--server", help="DC to use", type=str),
]
# spn management
#
# Copyright Matthieu Patou mat@samba.org 2010
+# Copyright Giampaolo Lauria 2011 <lauria2@yahoo.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
"""List spns of a given user."""
synopsis = "%prog spn list <user>"
- takes_optiongroups = {
- "sambaopts": options.SambaOptions,
- "credopts": options.CredentialsOptions,
- "versionopts": options.VersionOptions,
- }
-
takes_args = ["user"]
def run(self, user, credopts=None, sambaopts=None, versionopts=None):
"""Create a new spn."""
synopsis = "%prog spn add [--force] <name> <user>"
- takes_optiongroups = {
- "sambaopts": options.SambaOptions,
- "credopts": options.CredentialsOptions,
- "versionopts": options.VersionOptions,
- }
takes_options = [
Option("--force", help="Force the addition of the spn"\
" even it exists already", action="store_true"),
"""Delete a spn."""
synopsis = "%prog spn delete <name> [user]"
- takes_optiongroups = {
- "sambaopts": options.SambaOptions,
- "credopts": options.CredentialsOptions,
- "versionopts": options.VersionOptions,
- }
-
takes_args = ["name", "user?"]
def run(self, name, user=None, credopts=None, sambaopts=None, versionopts=None):
# Unix SMB/CIFS implementation.
# Test validity of smb.conf
# Copyright (C) Karl Auer 1993, 1994-1998
+# Copyright Giampaolo Lauria 2011 <lauria2@yahoo.com>
#
# Extensively modified by Andrew Tridgell, 1995
# Converted to popt by Jelmer Vernooij (jelmer@nl.linux.org), 2002
synopsis = ""
- takes_optiongroups = {
- "sambaopts": options.SambaOptions,
- "versionopts": options.VersionOptions
- }
-
takes_options = [
Option("--section-name", type=str,
help="Limit testparm to a named section"),
# time
#
# Copyright Jelmer Vernooij 2010 <jelmer@samba.org>
+# Copyright Giampaolo Lauria 2011 <lauria2@yahoo.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
"""Retrieve the time on a remote server [server connection needed]"""
synopsis = "%prog time <server-name>"
- takes_optiongroups = {
- "sambaopts": options.SambaOptions,
- "credopts": options.CredentialsOptions,
- "versionopts": options.VersionOptions,
- }
-
takes_args = ["server_name?"]
def run(self, server_name=None, credopts=None, sambaopts=None, versionopts=None):
#
# Copyright Jelmer Vernooij 2010 <jelmer@samba.org>
# Copyright Theresa Halloran 2011 <theresahalloran@gmail.com>
+# Copyright Giampaolo Lauria 2011 <lauria2@yahoo.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
"""Create a new user."""
synopsis = "%prog user add <name> [<password>]"
- takes_optiongroups = {
- "sambaopts": options.SambaOptions,
- "credopts": options.CredentialsOptions,
- "versionopts": options.VersionOptions,
- }
-
takes_args = ["name", "password?"]
def run(self, name, password=None, credopts=None, sambaopts=None, versionopts=None):
"""Delete a user."""
synopsis = "%prog user delete <name>"
- takes_optiongroups = {
- "sambaopts": options.SambaOptions,
- "credopts": options.CredentialsOptions,
- "versionopts": options.VersionOptions,
- }
-
takes_args = ["name"]
def run(self, name, credopts=None, sambaopts=None, versionopts=None):
synopsis = "%prog user enable <username> [options]"
-
- takes_optiongroups = {
- "sambaopts": options.SambaOptions,
- "versionopts": options.VersionOptions,
- "credopts": options.CredentialsOptions,
- }
-
takes_options = [
Option("-H", help="LDB URL for database or target server", type=str),
Option("--filter", help="LDAP Filter to set password on", type=str),
synopsis = "%prog user setexpiry <username> [options]"
- takes_optiongroups = {
- "sambaopts": options.SambaOptions,
- "versionopts": options.VersionOptions,
- "credopts": options.CredentialsOptions,
- }
-
takes_options = [
Option("-H", help="LDB URL for database or target server", type=str),
Option("--filter", help="LDAP Filter to set password on", type=str),
synopsis = "%prog user setpassword [username] [options]"
- takes_optiongroups = {
- "sambaopts": options.SambaOptions,
- "versionopts": options.VersionOptions,
- "credopts": options.CredentialsOptions,
- }
-
takes_options = [
Option("-H", help="LDB URL for database or target server", type=str),
Option("--filter", help="LDAP Filter to set password on", type=str),
# Vampire
#
# Copyright Jelmer Vernooij 2010 <jelmer@samba.org>
+# Copyright Giampaolo Lauria 2011 <lauria2@yahoo.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
"""Join and synchronise a remote AD domain to the local server [server connection needed]"""
synopsis = "%prog vampire [options] <domain>"
- takes_optiongroups = {
- "sambaopts": options.SambaOptions,
- "credopts": options.CredentialsOptions,
- "versionopts": options.VersionOptions,
- }
-
takes_options = [
Option("--target-dir", help="Target directory.", type=str),
Option("--force", help="force run", action='store_true', default=False),