1
0
mirror of https://github.com/samba-team/samba.git synced 2025-08-15 13:49:28 +03:00

Revert "samba-tool: moved takes_optiongroups definition to Command base class"

This reverts commit f6fa868489.

This keeps the main command class fairly slim, and makes it a bit
more obvious where the arguments to run() are coming from.

Conflicts:

	source4/scripting/python/samba/netcmd/__init__.py
	source4/scripting/python/samba/netcmd/domain.py
	source4/scripting/python/samba/netcmd/gpo.py
	source4/scripting/python/samba/netcmd/newuser.py
	source4/scripting/python/samba/netcmd/testparm.py
	source4/scripting/python/samba/netcmd/user.py
	source4/scripting/python/samba/tests/samba_tool/__init__.py
This commit is contained in:
Jelmer Vernooij
2012-02-06 16:33:38 +01:00
parent d6b4701503
commit a0ff4c349c
17 changed files with 240 additions and 27 deletions

View File

@ -3,7 +3,6 @@
# Unix SMB/CIFS implementation.
# Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2009-2011
# Copyright (C) Theresa Halloran <theresahalloran@gmail.com> 2011
# Copyright (C) Giampaolo Lauria <lauria2@yahoo.com> 2011
#
# 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
@ -71,11 +70,7 @@ class Command(object):
synopsis = None
takes_args = []
takes_options = []
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"credopts": options.CredentialsOptions,
"versionopts": options.VersionOptions,
}
takes_optiongroups = {}
def __init__(self, outf=sys.stdout, errf=sys.stderr):
self.outf = outf

View File

@ -3,7 +3,6 @@
# 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
@ -35,6 +34,12 @@ class cmd_dbcheck(Command):
"""check local AD database for errors"""
synopsis = "%prog [<DN>] [options]"
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"versionopts": options.VersionOptions,
"credopts": options.CredentialsOptionsDouble,
}
takes_args = ["DN?"]
takes_options = [

View File

@ -5,7 +5,6 @@
# 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
@ -41,6 +40,12 @@ class cmd_delegation_show(Command):
synopsis = "%prog <accountname> [options]"
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"credopts": options.CredentialsOptions,
"versionopts": options.VersionOptions,
}
takes_args = ["accountname"]
def run(self, accountname, credopts=None, sambaopts=None, versionopts=None):
@ -80,6 +85,12 @@ class cmd_delegation_for_any_service(Command):
synopsis = "%prog <accountname> [(on|off)] [options]"
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):
@ -116,6 +127,12 @@ class cmd_delegation_for_any_protocol(Command):
synopsis = "%prog <accountname> [(on|off)] [options]"
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):
@ -152,6 +169,12 @@ class cmd_delegation_add_service(Command):
synopsis = "%prog <accountname> <principal> [options]"
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):
@ -189,6 +212,12 @@ class cmd_delegation_del_service(Command):
synopsis = "%prog <accountname> <principal> [options]"
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):

View File

@ -76,6 +76,12 @@ class cmd_domain_export_keytab(Command):
synopsis = "%prog <keytab> [options]"
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"credopts": options.CredentialsOptions,
"versionopts": options.VersionOptions,
}
takes_options = [
Option("--principal", help="extract only this principal", type=str),
]
@ -118,6 +124,12 @@ class cmd_domain_join(Command):
synopsis = "%prog <dnsdomain> [DC|RODC|MEMBER|SUBDOMAIN] [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),
@ -407,7 +419,7 @@ class cmd_domain_demote(Command):
except ldb.LdbError, l:
pass
print "Demote successfull"
self.outf.write("Demote successfull\n")
@ -416,6 +428,12 @@ class cmd_domain_level(Command):
synopsis = "%prog (show|raise <options>) [options]"
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"credopts": options.CredentialsOptions,
"versionopts": options.VersionOptions,
}
takes_options = [
Option("-H", "--URL", help="LDB URL for database or target server", type=str,
metavar="URL", dest="H"),
@ -609,7 +627,6 @@ class cmd_domain_level(Command):
raise CommandError("invalid argument: '%s' (choose from 'show', 'raise')" % subcommand)
class cmd_domain_passwordsettings(Command):
"""Sets password settings
@ -619,6 +636,12 @@ class cmd_domain_passwordsettings(Command):
synopsis = "%prog (show|set <options>) [options]"
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"versionopts": options.VersionOptions,
"credopts": options.CredentialsOptions,
}
takes_options = [
Option("-H", "--URL", help="LDB URL for database or target server", type=str,
metavar="URL", dest="H"),

View File

@ -3,7 +3,6 @@
# 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>
#
@ -87,6 +86,12 @@ class cmd_drs_showrepl(Command):
synopsis = "%prog [<DC>] [options]"
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"versionopts": options.VersionOptions,
"credopts": options.CredentialsOptions,
}
takes_args = ["DC?"]
def print_neighbour(self, n):
@ -192,6 +197,12 @@ class cmd_drs_kcc(Command):
synopsis = "%prog [<DC>] [options]"
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"versionopts": options.VersionOptions,
"credopts": options.CredentialsOptions,
}
takes_args = ["DC?"]
def run(self, DC=None, sambaopts=None,
@ -255,6 +266,12 @@ class cmd_drs_replicate(Command):
synopsis = "%prog <destinationDC> <sourceDC> <NC> [options]"
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"versionopts": options.VersionOptions,
"credopts": options.CredentialsOptions,
}
takes_args = ["DEST_DC", "SOURCE_DC", "NC"]
takes_options = [
@ -325,6 +342,12 @@ class cmd_drs_bind(Command):
synopsis = "%prog [<DC>] [options]"
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"versionopts": options.VersionOptions,
"credopts": options.CredentialsOptions,
}
takes_args = ["DC?"]
def run(self, DC=None, sambaopts=None,
@ -418,6 +441,12 @@ class cmd_drs_options(Command):
synopsis = "%prog [<DC>] [options]"
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"versionopts": options.VersionOptions,
"credopts": options.CredentialsOptions,
}
takes_args = ["DC?"]
takes_options = [

View File

@ -3,7 +3,6 @@
# 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
@ -53,6 +52,12 @@ class cmd_dsacl_set(Command):
synopsis = "%prog [options]"
car_help = """ The access control right to allow or deny """
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"credopts": options.CredentialsOptions,
"versionopts": options.VersionOptions,
}
takes_options = [
Option("-H", "--URL", help="LDB URL for database or target server",
type=str, metavar="URL", dest="H"),

View File

@ -4,7 +4,6 @@
#
# 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
@ -39,6 +38,12 @@ class cmd_fsmo_seize(Command):
synopsis = "%prog [options]"
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"credopts": options.CredentialsOptions,
"versionopts": options.VersionOptions,
}
takes_options = [
Option("-H", "--URL", help="LDB URL for database or target server", type=str,
metavar="URL", dest="H"),

View File

@ -3,7 +3,6 @@
# implement samba_tool gpo commands
#
# Copyright Andrew Tridgell 2010
# Copyright Giampaolo Lauria 2011 <lauria2@yahoo.com>
# Copyright Amitay Isaacs 2011 <amitay@gmail.com>
#
# based on C implementation by Guenther Deschner and Wilco Baan Hofman
@ -241,6 +240,12 @@ class cmd_listall(Command):
synopsis = "%prog [options]"
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"versionopts": options.VersionOptions,
"credopts": options.CredentialsOptions,
}
takes_options = [
Option("-H", "--URL", help="LDB URL for database or target server", type=str,
metavar="URL", dest="H")
@ -273,6 +278,11 @@ class cmd_list(Command):
synopsis = "%prog <username> [options]"
takes_args = ['username']
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"versionopts": options.VersionOptions,
"credopts": options.CredentialsOptions,
}
takes_options = [
Option("-H", "--URL", help="LDB URL for database or target server",

View File

@ -5,7 +5,6 @@
#
# 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
@ -69,6 +68,12 @@ Example2 adds a new distribution group to the local server. The command is run
synopsis = "%prog <groupname> [options]"
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"versionopts": options.VersionOptions,
"credopts": options.CredentialsOptions,
}
takes_options = [
Option("-H", "--URL", help="LDB URL for database or target server", type=str,
metavar="URL", dest="H"),
@ -131,6 +136,12 @@ Example2 deletes group Group2 from the local server. The command is run under r
synopsis = "%prog <groupname> [options]"
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"versionopts": options.VersionOptions,
"credopts": options.CredentialsOptions,
}
takes_options = [
Option("-H", "--URL", help="LDB URL for database or target server", type=str,
metavar="URL", dest="H"),
@ -173,6 +184,12 @@ Example2 shows how to add a single user account, User2, to the supergroup AD gro
synopsis = "%prog <groupname> <listofmembers> [options]"
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"versionopts": options.VersionOptions,
"credopts": options.CredentialsOptions,
}
takes_options = [
Option("-H", "--URL", help="LDB URL for database or target server", type=str,
metavar="URL", dest="H"),
@ -217,6 +234,12 @@ Example2 shows how to remove a single user account, User2, from the supergroup A
synopsis = "%prog <groupname> <listofmembers> [options]"
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"versionopts": options.VersionOptions,
"credopts": options.CredentialsOptions,
}
takes_options = [
Option("-H", "--URL", help="LDB URL for database or target server", type=str,
metavar="URL", dest="H"),

View File

@ -8,7 +8,6 @@
# 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
@ -863,6 +862,12 @@ class cmd_ldapcmp(Command):
"credopts": options.CredentialsOptionsDouble,
}
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"versionopts": options.VersionOptions,
"credopts": options.CredentialsOptionsDouble,
}
takes_args = ["URL1", "URL2", "context1?", "context2?", "context3?"]
takes_options = [

View File

@ -3,7 +3,6 @@
# 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
@ -44,6 +43,12 @@ class cmd_ntacl_set(Command):
synopsis = "%prog <acl> <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)",
@ -80,6 +85,12 @@ class cmd_ntacl_get(Command):
"""Set ACLs on a file"""
synopsis = "%prog <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)",

View File

@ -3,7 +3,6 @@
# 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
@ -33,6 +32,12 @@ class cmd_rodc_preload(Command):
synopsis = "%prog (<SID>|<DN>|<accountname>) [options]"
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"versionopts": options.VersionOptions,
"credopts": options.CredentialsOptions,
}
takes_options = [
Option("--server", help="DC to use", type=str),
]

View File

@ -3,7 +3,6 @@
# 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
@ -38,6 +37,12 @@ class cmd_spn_list(Command):
synopsis = "%prog <user> [options]"
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"credopts": options.CredentialsOptions,
"versionopts": options.VersionOptions,
}
takes_args = ["user"]
def run(self, user, credopts=None, sambaopts=None, versionopts=None):
@ -75,6 +80,11 @@ class cmd_spn_add(Command):
synopsis = "%prog <name> <user> [options]"
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"),
@ -129,6 +139,12 @@ class cmd_spn_delete(Command):
synopsis = "%prog <name> [user] [options]"
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):

View File

@ -4,7 +4,6 @@
# Unix SMB/CIFS implementation.
# Test validity of smb.conf
# Copyright (C) 2010-2011 Jelmer Vernooij <jelmer@samba.org>
# Copyright (C) Giampaolo Lauria 2011 <lauria2@yahoo.com>
#
# Based on the original in C:
# Copyright (C) Karl Auer 1993, 1994-1998
@ -51,6 +50,11 @@ class cmd_testparm(Command):
"versionopts": options.VersionOptions
}
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"versionopts": options.VersionOptions
}
takes_options = [
Option("--section-name", type=str,
help="Limit testparm to a named section"),

View File

@ -3,7 +3,6 @@
# 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
@ -44,6 +43,12 @@ Example2 return the date and time of the local server.
"""
synopsis = "%prog [server-name] [options]"
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):

View File

@ -4,7 +4,6 @@
#
# 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
@ -21,12 +20,15 @@
#
import samba.getopt as options
import sys, ldb
import ldb
from getpass import getpass
from samba.auth import system_session
from samba.samdb import SamDB
from samba import gensec, generate_random_password
from samba import dsdb
from samba import (
dsdb,
gensec,
generate_random_password,
)
from samba.net import Net
from samba.netcmd import (
@ -100,6 +102,12 @@ Example3 shows how to create a new user in the OrgUnit organizational unit.
takes_args = ["username", "password?"]
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"credopts": options.CredentialsOptions,
"versionopts": options.VersionOptions,
}
def run(self, username, password=None, credopts=None, sambaopts=None,
versionopts=None, H=None, must_change_at_next_login=False, random_password=False,
use_username_as_cn=False, userou=None, surname=None, given_name=None, initials=None,
@ -163,6 +171,7 @@ sudo samba-tool user delete User2
Example2 shows how to delete a user in the domain against the local server. sudo is used so a user may run the command as root.
<<<<<<< HEAD
"""
synopsis = "%prog <username> [options]"
@ -172,9 +181,13 @@ Example2 shows how to delete a user in the domain against the local server. su
]
takes_args = ["username"]
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"credopts": options.CredentialsOptions,
"versionopts": options.VersionOptions,
}
def run(self, username, credopts=None, sambaopts=None, versionopts=None, H=None):
lp = sambaopts.get_loadparm()
creds = credopts.get_credentials(lp, fallback_machine=True)
@ -197,6 +210,12 @@ class cmd_user_list(Command):
metavar="URL", dest="H"),
]
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"credopts": options.CredentialsOptions,
"versionopts": options.VersionOptions,
}
def run(self, sambaopts=None, credopts=None, versionopts=None, H=None):
lp = sambaopts.get_loadparm()
creds = credopts.get_credentials(lp, fallback_machine=True)
@ -250,6 +269,13 @@ Example3 shows how to enable a user in the domain against a local LDAP server.
"""
synopsis = "%prog (<username>|--filter <filter>) [options]"
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"versionopts": options.VersionOptions,
"credopts": options.CredentialsOptions,
}
takes_options = [
Option("-H", "--URL", help="LDB URL for database or target server", type=str,
metavar="URL", dest="H"),
@ -341,6 +367,12 @@ Example4 shows how to set the account expiration so that it will never expire.
"""
synopsis = "%prog (<username>|--filter <filter>) [options]"
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"versionopts": options.VersionOptions,
"credopts": options.CredentialsOptions,
}
takes_options = [
Option("-H", "--URL", help="LDB URL for database or target server", type=str,
metavar="URL", dest="H"),
@ -442,6 +474,12 @@ Example3 shows how an administrator would reset TestUser3 user's password to pas
"""
synopsis = "%prog (<username>|--filter <filter>) [options]"
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"versionopts": options.VersionOptions,
"credopts": options.CredentialsOptions,
}
takes_options = [
Option("-H", "--URL", help="LDB URL for database or target server", type=str,
metavar="URL", dest="H"),

View File

@ -3,7 +3,6 @@
# 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
@ -35,6 +34,12 @@ class cmd_vampire(Command):
"""Join and synchronise a remote AD domain to the local server"""
synopsis = "%prog [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),