diff --git a/docs-xml/manpages/samba-tool.8.xml b/docs-xml/manpages/samba-tool.8.xml index 9a40bb1bec4..220c42856ec 100644 --- a/docs-xml/manpages/samba-tool.8.xml +++ b/docs-xml/manpages/samba-tool.8.xml @@ -69,6 +69,13 @@ + + -A AUTHFILE|--authentication-file=AUTHFILE + + Authentication file + + + &cmdline.common.debug.client; diff --git a/python/samba/getopt.py b/python/samba/getopt.py index 7b8d2ef46c5..a22d0139e44 100644 --- a/python/samba/getopt.py +++ b/python/samba/getopt.py @@ -174,6 +174,10 @@ class CredentialsOptions(optparse.OptionGroup): action="callback", type=str, help="Kerberos Credentials cache", callback=self._set_krb5_ccache) + self._add_option("-A", "--authentication-file", metavar="AUTHFILE", + action="callback", type=str, + help="Authentication file", + callback=self._set_auth_file) # LEGACY self._add_option("-k", "--kerberos", metavar="KERBEROS", @@ -275,6 +279,29 @@ class CredentialsOptions(optparse.OptionGroup): self.creds.set_kerberos_state(MUST_USE_KERBEROS) self.creds.set_named_ccache(arg) + def _set_auth_file(self, option, opt_str, arg, parser): + auth_data = {} + try: + actions = { + 'username': self.creds.parse_string, + 'password': self.creds.set_password, + 'domain': self.creds.set_domain + } + with open(arg, mode='r') as fd: + for line in fd.readlines(): + key, val = map(str.strip, line.partition('=')[::2]) + if key in actions and val: + actions[key](val) + actions.pop(key, None) + + self.ask_for_password = False + self.machine_pass = False + except FileNotFoundError: + raise optparse.OptionValueError("file %r not found" % (arg,)) + except PermissionError: + raise optparse.OptionValueError("no permissions to read %r" % (arg,)) + + def get_credentials(self, lp, fallback_machine=False): """Obtain the credentials set on the command-line.