web2ldap  1.7.7
About: web2ldap is a full-featured web-based LDAPv3 client.
  Fossies Dox: web2ldap-1.7.7.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

nis.py
Go to the documentation of this file.
1# -*- coding: ascii -*-
2"""
3web2ldap plugin classes for schema elements defined in RFC2307
4"""
5
6import re
7from typing import Dict
8
9from ...web.forms import Field
10from ..searchform import SEARCH_OPT_IS_EQUAL
11from ..schema.syntaxes import (
12 DaysSinceEpoch,
13 DNSDomain,
14 DynamicValueSelectList,
15 IA5String,
16 Integer,
17 IPHostAddress,
18 IPServicePortNumber,
19 MacAddress,
20 SelectList,
21 syntax_registry,
22)
23
24
26 oid: str = '1.3.6.1.1.1.0.1'
27 desc: str = 'RFC2307 Boot Parameter'
28 pattern = None # just a stub, should be made stricter
29
30
32 oid: str = 'GidNumber-oid'
33 desc: str = 'RFC2307: An integer uniquely identifying a group in an administrative domain'
34 min_value = 0
35 max_value = 4294967295
36 ldap_url = 'ldap:///_?gidNumber,cn?sub?(objectClass=posixGroup)'
37
38 def _validate(self, attr_value: bytes) -> bool:
39 return Integer._validate(self, attr_value)
40
41 def display(self, vidx, links) -> str:
42 # Possibly display a link
43 ocs = self._entry.object_class_oid_set()
44 if 'posixAccount' in ocs or 'shadowAccount' in ocs:
45 return DynamicValueSelectList.display(self, vidx, links)
46 res = [Integer.display(self, vidx, False)]
47 if not links:
48 return res[0]
49 if 'posixGroup' in ocs:
50 title = 'Search primary group members'
51 searchform_params = [
52 ('dn', self._dn),
53 ('searchform_mode', 'adv'),
54 ('search_attr', 'objectClass'),
55 ('search_option', SEARCH_OPT_IS_EQUAL),
56 ('search_string', 'posixAccount'),
57 ('search_attr', 'gidNumber'),
58 ('search_option', SEARCH_OPT_IS_EQUAL),
59 ('search_string', self.av_u),
60 ]
61 else:
62 title = None
63 searchform_params = None
64 if title and searchform_params:
65 res.append(self._app.anchor(
66 'searchform', '»',
67 searchform_params,
68 title=title,
69 ))
70 return ' '.join(res)
71
72 def input_field(self) -> Field:
73 ocs = self._entry.object_class_oid_set()
74 if 'posixAccount' in ocs or 'shadowAccount' in ocs:
75 return DynamicValueSelectList.input_field(self)
76 return Integer.input_field(self)
77
78syntax_registry.reg_at(
79 GidNumber.oid, [
80 '1.3.6.1.1.1.1.1', # gidNumber
81 ]
82)
83
84
86 oid: str = 'MemberUID-oid'
87 desc: str = 'RFC2307 numerical UID of group member(s)'
88 ldap_url = None
89 #ldap_url = 'ldap:///_?uid,cn?sub?(objectClass=posixAccount)'
90
91 def __init__(self, app, dn: str, schema, attrType: str, attr_value: bytes, entry=None):
92 IA5String.__init__(self, app, dn, schema, attrType, attr_value, entry)
93 if self.ldap_url:
94 DynamicValueSelectList.__init__(self, app, dn, schema, attrType, attr_value, entry)
95
96 def _validate(self, attr_value: bytes) -> bool:
97 if self.ldap_url:
98 return DynamicValueSelectList._validate(self, attr_value)
99 return IA5String._validate(self, attr_value)
100
101 def input_field(self) -> Field:
102 if self.ldap_url:
103 return DynamicValueSelectList.input_field(self)
104 return IA5String.input_field(self)
105
106 def display(self, vidx, links) -> str:
107 res = [IA5String.display(self, vidx, False)]
108 if links:
109 res.append(self._app.anchor(
110 'searchform', '»',
111 [
112 ('dn', self._dn),
113 (
114 'filterstr', '(&(objectClass=posixAccount)(uid=%s))' % (
115 self._app.form.s2d(self.av_u)
116 )
117 ),
118 ('searchform_mode', 'exp'),
119 ],
120 title='Search for user entry',
121 ))
122 return ' '.join(res)
123
124syntax_registry.reg_at(
125 MemberUID.oid, [
126 '1.3.6.1.1.1.1.12', # memberUid
127 ]
128)
129
130
132 oid: str = '1.3.6.1.1.1.0.0'
133 desc: str = 'RFC2307 NIS Netgroup Triple'
134 pattern = re.compile(r'^\‍([a-z0-9.-]*,[a-z0-9.-]*,[a-z0-9.-]*\‍)$')
135
136
138 oid: str = 'UidNumber-oid'
139 desc: str = 'Numerical user ID for Posix systems'
140 min_value = 0
141 max_value = 4294967295
142
143syntax_registry.reg_at(
144 UidNumber.oid, [
145 '1.3.6.1.1.1.1.0', # uidNumber
146 ]
147)
148
149
151 oid: str = 'Shell-oid'
152 desc: str = 'Shell for user of Posix systems'
153 attr_value_dict: Dict[str, str] = {
154 '/bin/sh': 'Standard shell /bin/sh',
155 '/bin/bash': 'Bourne-Again SHell /bin/bash',
156 '/bin/csh': '/bin/csh',
157 '/bin/tcsh': '/bin/tcsh',
158 '/bin/ksh': 'Korn shell /bin/ksh',
159 '/bin/passwd': 'Password change /bin/passwd',
160 '/bin/true': '/bin/true',
161 '/bin/false': '/bin/false',
162 '/bin/zsh': 'Zsh /bin/zsh',
163 '/usr/bin/bash': 'Bourne-Again SHell /usr/bin/bash',
164 '/usr/bin/csh': '/usr/bin/csh',
165 '/usr/bin/tcsh': '/usr/bin/csh',
166 '/usr/bin/ksh': 'Korn shell /usr/bin/ksh',
167 '/usr/bin/zsh': 'Zsh /usr/bin/zsh',
168 '/usr/sbin/nologin': 'Login denied /usr/sbin/nologin',
169 }
170
171syntax_registry.reg_at(
172 Shell.oid, [
173 '1.3.6.1.1.1.1.4', # loginShell
174 ]
175)
176
177
179 oid: str = 'IpServiceProtocol-oid'
180 desc: str = 'RFC 2307: IP service protocol'
181
182 attr_value_dict: Dict[str, str] = {
183 'tcp': 'tcp',
184 'udp': 'udp',
185 }
186
187syntax_registry.reg_at(
188 IpServiceProtocol.oid, [
189 '1.3.6.1.1.1.1.16', # ipServiceProtocol
190 ]
191)
192
193
194syntax_registry.reg_at(
195 IPHostAddress.oid, [
196 '1.3.6.1.1.1.1.19', # ipHostNumber
197 '1.3.6.1.1.1.1.20', # ipNetworkNumber
198 ]
199)
200
201
202syntax_registry.reg_at(
203 DNSDomain.oid, [
204 '1.3.6.1.1.1.1.30', # nisDomain
205 ]
206)
207
208
209syntax_registry.reg_at(
210 DaysSinceEpoch.oid, [
211 '1.3.6.1.1.1.1.10', # shadowExpire
212 '1.3.6.1.1.1.1.5', # shadowLastChange
213 ]
214)
215
216
217syntax_registry.reg_at(
218 IPServicePortNumber.oid, [
219 '1.3.6.1.1.1.1.15', # ipServicePort
220 ]
221)
222
223
224syntax_registry.reg_at(
225 MacAddress.oid, [
226 '1.3.6.1.1.1.1.22', # macAddress
227 ]
228)
229
230
231# Register all syntax classes in this module
232syntax_registry.reg_syntaxes(__name__)
bool _validate(self, bytes attr_value)
Definition: nis.py:38
str display(self, vidx, links)
Definition: nis.py:41
bool _validate(self, bytes attr_value)
Definition: nis.py:96
str display(self, vidx, links)
Definition: nis.py:106
def __init__(self, app, str dn, schema, str attrType, bytes attr_value, entry=None)
Definition: nis.py:91