3 # Samba-specific bits for optparse
4 # Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 from credentials import Credentials, AUTO_USE_KERBEROS, DONT_USE_KERBEROS, MUST_USE_KERBEROS
23 class SambaOptions(optparse.OptionGroup):
24 def __init__(self, parser):
25 optparse.OptionGroup.__init__(self, parser, "Samba Common Options")
26 self.add_option("-s", "--configfile", action="callback",
27 type=str, metavar="FILE", help="Configuration file",
28 callback=self._load_configfile)
29 self._configfile = None
31 def get_loadparm_path(self):
32 return self._configfile
34 def _load_configfile(self, option, opt_str, arg, parser):
35 self._configfile = arg
37 def get_loadparm(self):
40 if self._configfile is not None:
41 lp.load(self._configfile)
42 elif os.getenv("SMB_CONF_PATH") is not None:
43 lp.load(os.getenv("SMB_CONF_PATH"))
48 class VersionOptions(optparse.OptionGroup):
49 def __init__(self, parser):
50 optparse.OptionGroup.__init__(self, parser, "Version Options")
53 class CredentialsOptions(optparse.OptionGroup):
54 def __init__(self, parser):
56 optparse.OptionGroup.__init__(self, parser, "Credentials Options")
57 self.add_option("--simple-bind-dn", metavar="DN", action="callback",
58 callback=self._set_simple_bind_dn, type=str,
59 help="DN to use for a simple bind")
60 self.add_option("--password", metavar="PASSWORD", action="callback",
61 help="Password", type=str, callback=self._set_password)
62 self.add_option("-U", "--username", metavar="USERNAME",
63 action="callback", type=str,
64 help="Username", callback=self._parse_username)
65 self.add_option("-W", "--workgroup", metavar="WORKGROUP",
66 action="callback", type=str,
67 help="Workgroup", callback=self._parse_workgroup)
68 self.add_option("-N", "--no-pass", action="store_true",
69 help="Don't ask for a password")
70 self.add_option("-k", "--kerberos", metavar="KERBEROS",
71 action="callback", type=str,
72 help="Use Kerberos", callback=self._set_kerberos)
73 self.creds = Credentials()
75 def _parse_username(self, option, opt_str, arg, parser):
76 self.creds.parse_string(arg)
78 def _parse_workgroup(self, option, opt_str, arg, parser):
79 self.creds.set_domain(arg)
81 def _set_password(self, option, opt_str, arg, parser):
82 self.creds.set_password(arg)
84 def _set_kerberos(self, option, opt_str, arg, parser):
85 if bool(arg) or arg.lower() == "yes":
86 self.creds.set_kerberos_state(MUST_USE_KERBEROS)
88 self.creds.set_kerberos_state(DONT_USE_KERBEROS)
90 def _set_simple_bind_dn(self, option, opt_str, arg, parser):
91 self.creds.set_bind_dn(arg)
93 def get_credentials(self, lp):
96 self.creds.set_cmdline_callbacks()