1 from twisted.python import usage, reflect
2 from ldaptor.protocols import pureldap
3 from ldaptor.protocols.ldap import distinguishedname
4
6 optParameters = ()
7 - def postOptions(self):
8 postOpt = {}
9 reflect.addMethodNamesToDict(self.__class__, postOpt, "postOptions_")
10 for name in postOpt.keys():
11 method = getattr(self, 'postOptions_'+name)
12 method()
13
16 """Service location, in the form BASEDN:HOST[:PORT]"""
17
18 if not self.opts.has_key('service-location'):
19 self.opts['service-location']={}
20
21 base, location = value.split(':', 1)
22 try:
23 dn = distinguishedname.DistinguishedName(base)
24 except distinguishedname.InvalidRelativeDistinguishedName, e:
25 raise usage.UsageError, str(e)
26
27 if not location:
28 raise usage.UsageError, "service-location must specify host"
29
30 if ':' in location:
31 host, port = location.split(':', 1)
32 else:
33 host, port = location, None
34
35 if not host:
36 host = None
37
38 if not port:
39 port = None
40
41 self.opts['service-location'][dn] = (host, port)
42
44 if not self.opts.has_key('service-location'):
45 self.opts['service-location']={}
46
48 optParameters = (
49 ('base', None, None,
50 "LDAP base dn"),
51 )
52
55
56 if self.opts['base'] is None:
57 raise usage.UsageError, "%s must be given" % 'base'
58
60 optParameters = (
61 ('scope', None, 'sub',
62 "LDAP search scope (one of base, one, sub)"),
63 )
64
66 synonyms = {
67 'base': 'baseObject',
68 'single': 'singleLevel',
69 'subtree': 'wholeSubtree',
70 'sub': 'wholeSubtree',
71 }
72 scope = self.opts['scope']
73 scope=synonyms.get(scope, scope)
74 try:
75 scope=getattr(pureldap, 'LDAP_SCOPE_'+scope)
76 except AttributeError:
77 raise usage.UsageError, "bad scope: %s" % scope
78 self.opts['scope'] = scope
79
81 optParameters = (
82 ('binddn', None, None,
83 "use Distinguished Name to bind to the directory"),
84 ('bind-auth-fd', None, None,
85 "read bind password from filedescriptor"),
86 )
87
89 val=self.opts['bind-auth-fd']
90 if val is not None:
91 try:
92 val = int(val)
93 except ValueError:
94 raise usage.UsageError, "%s value must be numeric" % 'bind-auth-fd'
95 self.opts['bind-auth-fd'] = val
96
99 if not self.opts['binddn']:
100 raise usage.UsageError, "%s must be given" % 'binddn'
101