Hallo, dies ist ein Test.
PWD: /www/data-lst1/unixsoft/unixsoft/kaempfer/.public_html
Running in File Mode
Relative path: ./../.././../../dig/../../../sbin/nscfg
Real path: /usr/sbin/nscfg
Zurück
#!/usr/bin/python3.11 -SE # # Copyright (c) 2011, 2023, Oracle and/or its affiliates. # """ nscfg - The Name Service Switch Administration tool. Use this CLI to manage name service switch configuration. """ import os import sys # # don't import site.py (-S), but do include the desired paths # Need to avoid unnecessary getpwuid calls in site.py # try: version = (sys.version_info.major, sys.version_info.minor) sys.path.append( '/usr/lib/python%s.%s/site-packages' % version) sys.path.append( '/usr/lib/python%s.%s/vendor-packages' % version) except Exception: pass import getopt import gettext import shutil import traceback import time import subprocess import optparse from nss import * from nss import _ # pylint workaround import nss.messages as msg import nss.nssscf as nssscf # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def nscfg_usage(): '''Defines parameters and options of the command nscfg.''' print(_(""" Usage: nscfg subcommand cmd_options subcommands: nscfg import [-fnvq] FMRI nscfg export [-nvq] FMRI nscfg unconfig [-vq] FMRI nscfg validate [-vq] FMRI nscfg adldap [-nvqu] """), file=sys.stderr) sys.exit(1) class NscfgOptionParser(optparse.OptionParser): def exit(self, status=0, msg=None): if msg: sys.stderr.write(msg) sys.exit(2) def print_usage(self, file=None): nscfg_usage() # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # Public Command Line functions described in nscfg(8) # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def import_cmd(opts): """ Function: import Description: Populate SMF FMRI properties from legacy Name Service Switch configuration files. Parameters: FMRI - A SMF FMRI representing a name service component Returns: 0 - Success 1 - Failure 3 - No Configuration """ op = NscfgOptionParser() op.add_option('-f', action='store_true', dest='force', default=False, help=optparse.SUPPRESS_HELP) op.add_option('-n', action='store_true', dest='nowrite', default=False, help=optparse.SUPPRESS_HELP) op.add_option('-v', action='count', dest='verbose', default=0, help=optparse.SUPPRESS_HELP) op.add_option('-q', action='store_true', dest='quiet', default=False, help=optparse.SUPPRESS_HELP) (opt, args) = op.parse_args(opts) if opt.quiet: msg.quiet() if len(args) != 1: msg.printMsg(msg.Msgs.NSCFG_ERR_OPT_ARGS, None, -1) nscfg_usage() fmri = args[0] obj = create_nss_object(fmri) if obj is None: msg.printMsg(msg.Msgs.NSCFG_ERR_ILL_FMRI, fmri, -1) return 1 if opt.verbose: obj.verbose(opt.verbose) if opt.nowrite: obj.nowrite() if obj.is_configured() and not opt.force: return 0 try: ret = obj.import_to_smf() if ret == 0: return 0 if ret > 0: msg.printMsg(msg.Msgs.NSCFG_ERR_NO_CONFIG, fmri, -1) return 3 except Exception: traceback.print_exc() msg.printMsg(msg.Msgs.NSCFG_ERR_IMPORT, fmri, -1) return 1 # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def export_cmd(opts): """ Function: export Description: Export SMF FMRI properties into legacy Name Service Switch files given an SMF FMRI. Parameters: FMRI - A SMF FMRI representing a name service component Returns: 0 - Success 1 - Failure 2 - No change necessary """ op = NscfgOptionParser() op.add_option('-n', action='store_true', dest='nowrite', default=False, help=optparse.SUPPRESS_HELP) op.add_option('-v', action='count', dest='verbose', default=0, help=optparse.SUPPRESS_HELP) op.add_option('-q', action='store_true', dest='quiet', default=False, help=optparse.SUPPRESS_HELP) (opt, args) = op.parse_args(opts) if opt.quiet: msg.quiet() if len(args) != 1: msg.printMsg(msg.Msgs.NSCFG_ERR_OPT_ARGS, None, -1) nscfg_usage() fmri = args[0] obj = create_nss_object(fmri) if obj is None: msg.printMsg(msg.Msgs.NSCFG_ERR_ILL_FMRI, fmri, -1) return 1 if opt.verbose: obj.verbose(opt.verbose) if opt.nowrite: return 0 try: if obj.is_populated(): ret = obj.export_from_smf() if ret == 0: return 0 if ret > 0: if opt.verbose: msg.printMsg(msg.Msgs.NSCFG_ERR_NO_CHANGE, fmri, -1) return 2 else: msg.printMsg(msg.Msgs.NSCFG_OUT_NO_CONFIG, fmri, -1) except Exception: # This should never happen, but if it does let's dump a stack # trace so we might be able to figure out what happened. traceback.print_exc() msg.printMsg(msg.Msgs.NSCFG_ERR_EXPORT, fmri, -1) return 2 # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def unconfig_cmd(opts): """ Function: unconfig Description: Unconfigure all SMF FMRI properties for the given SMF FMRI. Parameters: FMRI - A SMF FMRI representing a name service component Returns: 0 - Success 1 - Failure """ op = NscfgOptionParser() op.add_option('-n', action='store_true', dest='nowrite', default=False, help=optparse.SUPPRESS_HELP) op.add_option('-v', action='count', dest='verbose', default=0, help=optparse.SUPPRESS_HELP) op.add_option('-q', action='store_true', dest='quiet', default=False, help=optparse.SUPPRESS_HELP) (opt, args) = op.parse_args(opts) if opt.quiet: msg.quiet() if len(args) != 1: msg.printMsg(msg.Msgs.NSCFG_ERR_OPT_ARGS, None, -1) nscfg_usage() fmri = args[0] obj = create_nss_object(fmri) if obj is None: msg.printMsg(msg.Msgs.NSCFG_ERR_ILL_FMRI, fmri, -1) return 1 if opt.verbose: obj.verbose(opt.verbose) if opt.nowrite: return 0 try: ret = obj.unconfig_smf() if ret == 0: return 0 except Exception: traceback.print_exc() msg.printMsg(msg.Msgs.NSCFG_ERR_UNCONFIG, fmri, -1) return 1 # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def validate_cmd(opts): """ Function: validate Description: Validate the configuration of a given SMF FMRI. Parameters: FMRI - A SMF FMRI representing a name service component Returns: 0 - Success 1 - Failure """ op = NscfgOptionParser() op.add_option('-v', action='count', dest='verbose', default=0, help=optparse.SUPPRESS_HELP) op.add_option('-q', action='store_true', dest='quiet', default=False, help=optparse.SUPPRESS_HELP) (opt, args) = op.parse_args(opts) if opt.quiet: msg.quiet() if len(args) != 1: msg.printMsg(msg.Msgs.NSCFG_ERR_OPT_ARGS, None, -1) nscfg_usage() fmri = args[0] obj = create_nss_object(fmri) if obj is None: msg.printMsg(msg.Msgs.NSCFG_ERR_ILL_FMRI, fmri, -1) return 1 if opt.verbose: obj.verbose(opt.verbose) try: ret = obj.validate(num_tries=1) if ret is True: return 0 except Exception: traceback.print_exc() msg.printMsg(msg.Msgs.NSCFG_ERR_VALIDATE, fmri, -1) return 1 # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def upgrade_cmd(opts): """ Function: upgrade Description: Project private command to upgrade the configuration of a given SMF FMRI. To be used by the name-service/upgrade service only. Parameters: FMRI - A SMF FMRI representing a name service component Returns: 0 - Success 1 - Failure """ op = NscfgOptionParser() op.add_option('-v', action='count', dest='verbose', default=0, help=optparse.SUPPRESS_HELP) op.add_option('-q', action='store_true', dest='quiet', default=False, help=optparse.SUPPRESS_HELP) (opt, args) = op.parse_args(opts) if opt.quiet: msg.quiet() if len(args) != 1: msg.printMsg(msg.Msgs.NSCFG_ERR_OPT_ARGS, None, -1) nscfg_usage() fmri = args[0] obj = create_nss_object(fmri) if obj is None: msg.printMsg(msg.Msgs.NSCFG_ERR_ILL_FMRI, fmri, -1) return 1 if opt.verbose: obj.verbose(opt.verbose) try: obj.upgrade() except Exception: traceback.print_exc() return 0 # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def adldap_cmd(opts): """ Function: adldap Description: Verify configuration conditions and configure the name service switch to support LDAP using an AD as an LDAP server. Parameters: None Returns: 0 - Success 1 - Failure """ op = NscfgOptionParser() op.add_option('-v', action='count', dest='verbose', default=0, help=optparse.SUPPRESS_HELP) op.add_option('-q', action='store_true', dest='quiet', default=False, help=optparse.SUPPRESS_HELP) op.add_option('-n', action='store_true', dest='nowrite', default=False, help=optparse.SUPPRESS_HELP) op.add_option('-u', action='store_true', dest='unconfigure', default=False, help=optparse.SUPPRESS_HELP) op.add_option('-o', action='store', dest='file_name', default=None, help=optparse.SUPPRESS_HELP) (opt, args) = op.parse_args(opts) if opt.quiet: msg.quiet() if len(args) != 0: msg.printMsg(msg.Msgs.NSCFG_ERR_OPT_ARGS, None, -1) nscfg_usage() fmri = "adldap" obj = create_nss_object(fmri) if obj is None: msg.printMsg(msg.Msgs.NSCFG_ERR_ILL_FMRI, fmri, -1) return 1 if opt.verbose: obj.verbose(opt.verbose) if opt.unconfigure: obj.unconfigure_adldap(opt.nowrite) return 0 (verified, error) = obj.verify_prerequisites() if not verified: if opt.file_name: obj.output_error_xml(opt.file_name, error) else: msg.printMsg(msg.Msgs.NSCFG_MSG_FREE_FORMAT, error, -1) return 1 msg.printMsg(msg.Msgs.NSCFG_MSG_FREE_FORMAT, "Verification successful", -1) if opt.file_name: if not obj.output_configuration(opt.file_name): # But on write error, exit 1 msg.printMsg(msg.Msgs.NSCFG_ERR_CREATE, opt.file_name, -1) return 1 if opt.nowrite: return 0 msg.printMsg(msg.Msgs.NSCFG_MSG_FREE_FORMAT, "Configuring...", -1) try: obj.initialize_adldap() except nssscf.NssscfError as err: msg.printMsg(msg.Msgs.NSCFG_ERR_PREREQ, err.strerr, -1) return 1 return 0 # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # End of CLI public functions # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def parseCLI(cli_opts_args): """Parse command line interface arguments.""" if len(cli_opts_args) == 0: nscfg_usage() subcommand = cli_opts_args[0] opts_args = cli_opts_args[1:] if subcommand == "import": rc = import_cmd(opts_args) elif subcommand == "export": rc = export_cmd(opts_args) elif subcommand == "unconfig": rc = unconfig_cmd(opts_args) elif subcommand == "validate": rc = validate_cmd(opts_args) elif subcommand == "upgrade": rc = upgrade_cmd(opts_args) elif subcommand == "adldap": rc = adldap_cmd(opts_args) else: msg.printMsg(msg.Msgs.NSCFG_ERR_ILL_SUBCOMMAND, subcommand, -1) nscfg_usage() return rc # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def main(): """main function.""" gettext.install("solaris_cmd_nscfg", "/usr/lib/locale") return parseCLI(sys.argv[1:]) # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ if __name__ == "__main__": try: RC = main() except SystemExit as e: raise e except Exception: traceback.print_exc() sys.exit(1) sys.exit(RC)