2011-10-14 01:36:10 +04:00
# Unix SMB/CIFS implementation.
# Copyright (C) Jelmer Vernooij <jelmer@samba.org> 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
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
""" The main samba-tool command implementation. """
2012-10-08 14:50:33 +04:00
from samba import getopt as options
2011-10-14 01:36:10 +04:00
from samba . netcmd import SuperCommand
2018-07-30 09:20:39 +03:00
2016-07-15 05:29:02 +03:00
class cache_loader ( dict ) :
"""
We only load subcommand tools if they are actually used .
This significantly reduces the amount of time spent starting up
samba - tool
"""
def __getitem__ ( self , attr ) :
item = dict . __getitem__ ( self , attr )
if item is None :
package = ' nettime ' if attr == ' time ' else attr
self [ attr ] = getattr ( __import__ ( ' samba.netcmd. %s ' % package ,
fromlist = [ ' cmd_ %s ' % attr ] ) ,
' cmd_ %s ' % attr ) ( )
return dict . __getitem__ ( self , attr )
2017-12-21 01:30:24 +03:00
def get ( self , attr , default = None ) :
try :
return self [ attr ]
except KeyError :
return default
2018-04-11 01:32:06 +03:00
def items ( self ) :
2016-07-15 05:29:02 +03:00
for key in self :
yield ( key , self [ key ] )
2011-10-14 01:36:10 +04:00
class cmd_sambatool ( SuperCommand ) :
""" Main samba administration tool. """
2012-10-08 14:50:33 +04:00
takes_optiongroups = {
" versionopts " : options . VersionOptions ,
2018-07-30 09:14:37 +03:00
}
2012-10-08 14:50:33 +04:00
2016-07-15 05:29:02 +03:00
subcommands = cache_loader ( )
2017-12-07 23:38:28 +03:00
subcommands [ " computer " ] = None
2019-03-19 19:55:37 +03:00
subcommands [ " contact " ] = None
2016-07-15 05:29:02 +03:00
subcommands [ " dbcheck " ] = None
subcommands [ " delegation " ] = None
subcommands [ " dns " ] = None
subcommands [ " domain " ] = None
subcommands [ " drs " ] = None
subcommands [ " dsacl " ] = None
2018-04-25 10:36:17 +03:00
subcommands [ " forest " ] = None
2016-07-15 05:29:02 +03:00
subcommands [ " fsmo " ] = None
subcommands [ " gpo " ] = None
subcommands [ " group " ] = None
subcommands [ " ldapcmp " ] = None
subcommands [ " ntacl " ] = None
subcommands [ " rodc " ] = None
2018-04-28 08:22:29 +03:00
subcommands [ " schema " ] = None
2016-07-15 05:29:02 +03:00
subcommands [ " sites " ] = None
subcommands [ " spn " ] = None
subcommands [ " testparm " ] = None
subcommands [ " time " ] = None
subcommands [ " user " ] = None
2017-11-16 14:31:11 +03:00
subcommands [ " ou " ] = None
2016-07-15 05:29:02 +03:00
subcommands [ " processes " ] = None
2017-08-10 02:57:24 +03:00
subcommands [ " visualize " ] = None
2022-09-08 01:00:36 +03:00
def samba_tool ( * args , * * kwargs ) :
""" A single function that runs samba-tool, returning an error code on
error , and None on success . """
2022-09-08 11:27:33 +03:00
try :
cmd , argv = cmd_sambatool ( ) . _resolve ( " samba-tool " , * args , * * kwargs )
ret = cmd . _run ( * argv )
except SystemExit as e :
ret = e . code
except Exception as e :
cmd . show_command_error ( e )
ret = 1
return ret