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 None:
43 lp.load(self._configfile)
46 class VersionOptions(optparse.OptionGroup):
47 def __init__(self, parser):
48 optparse.OptionGroup.__init__(self, parser, "Version Options")
51 class CredentialsOptions(optparse.OptionGroup):
52 def __init__(self, parser):
54 optparse.OptionGroup.__init__(self, parser, "Credentials Options")
55 self.add_option("--simple-bind-dn", metavar="DN", action="callback",
56 callback=self._set_simple_bind_dn, type=str,
57 help="DN to use for a simple bind")
58 self.add_option("--password", metavar="PASSWORD", action="callback",
59 help="Password", type=str, callback=self._set_password)
60 self.add_option("-U", "--username", metavar="USERNAME",
61 action="callback", type=str,
62 help="Username", callback=self._parse_username)
63 self.add_option("-W", "--workgroup", metavar="WORKGROUP",
64 action="callback", type=str,
65 help="Workgroup", callback=self._parse_workgroup)
66 self.add_option("-N", "--no-pass", action="store_true",
67 help="Don't ask for a password")
68 self.add_option("-k", "--kerberos", metavar="KERBEROS",
69 action="callback", type=str,
70 help="Use Kerberos", callback=self._set_kerberos)
71 self.creds = Credentials()
73 def _parse_username(self, option, opt_str, arg, parser):
74 self.creds.parse_string(arg)
76 def _parse_workgroup(self, option, opt_str, arg, parser):
77 self.creds.set_domain(arg)
79 def _set_password(self, option, opt_str, arg, parser):
80 self.creds.set_password(arg)
82 def _set_kerberos(self, option, opt_str, arg, parser):
83 if bool(arg) or arg.lower() == "yes":
84 self.creds.set_kerberos_state(MUST_USE_KERBEROS)
86 self.creds.set_kerberos_state(DONT_USE_KERBEROS)
88 def _set_simple_bind_dn(self, option, opt_str, arg, parser):
89 self.creds.set_bind_dn(arg)
91 def get_credentials(self, lp):
94 self.creds.set_cmdline_callbacks()