author | Davor Ocelic <docelic@crystallabs.io> |
Mon, 06 May 2019 21:58:29 +0200 | |
changeset 119 | a6c211de24f0 |
parent 118 | 2d7f16eff198 |
child 120 | 7f804e1f903c |
permissions | -rwxr-xr-x |
0 | 1 |
#!/usr/bin/env perl |
2 |
# vim: set nosta noet ts=4 sw=4: |
|
3 |
# |
|
99
2a7a3072d76c
Add LICENSE file for packaging, bump copyright.
Mahlon E. Smith <mahlon@martini.nu>
parents:
95
diff
changeset
|
4 |
# Copyright (c) 2006-2019, Mahlon E. Smith <mahlon@martini.nu> |
0 | 5 |
# All rights reserved. |
6 |
# Redistribution and use in source and binary forms, with or without |
|
7 |
# modification, are permitted provided that the following conditions are met: |
|
8 |
# |
|
9 |
# * Redistributions of source code must retain the above copyright |
|
10 |
# notice, this list of conditions and the following disclaimer. |
|
6
46dfe9d6f368
Update documentation, now that multiline edits work. Minor other
Mahlon E. Smith <mahlon@laika.com>
parents:
5
diff
changeset
|
11 |
# |
0 | 12 |
# * Redistributions in binary form must reproduce the above copyright |
13 |
# notice, this list of conditions and the following disclaimer in the |
|
14 |
# documentation and/or other materials provided with the distribution. |
|
6
46dfe9d6f368
Update documentation, now that multiline edits work. Minor other
Mahlon E. Smith <mahlon@laika.com>
parents:
5
diff
changeset
|
15 |
# |
0 | 16 |
# * Neither the name of Mahlon E. Smith nor the names of his |
17 |
# contributors may be used to endorse or promote products derived |
|
18 |
# from this software without specific prior written permission. |
|
19 |
# |
|
20 |
# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY |
|
21 |
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
22 |
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
|
23 |
# DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY |
|
24 |
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
|
25 |
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
|
26 |
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
|
27 |
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
28 |
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
|
29 |
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
30 |
||
31 |
=head1 NAME |
|
32 |
||
10
664bbe3dcd44
Follow regular man page conventions. Patch from
Mahlon E. Smith <mahlon@laika.com>
parents:
9
diff
changeset
|
33 |
Shelldap - A program for interacting with an LDAP server via a shell-like interface |
0 | 34 |
|
10
664bbe3dcd44
Follow regular man page conventions. Patch from
Mahlon E. Smith <mahlon@laika.com>
parents:
9
diff
changeset
|
35 |
=head1 DESCRIPTION |
664bbe3dcd44
Follow regular man page conventions. Patch from
Mahlon E. Smith <mahlon@laika.com>
parents:
9
diff
changeset
|
36 |
|
664bbe3dcd44
Follow regular man page conventions. Patch from
Mahlon E. Smith <mahlon@laika.com>
parents:
9
diff
changeset
|
37 |
Shelldap /LDAP::Shell is a program for interacting with an LDAP server via a shell-like |
0 | 38 |
interface. |
39 |
||
40 |
This is not meant to be an exhaustive LDAP editing and browsing |
|
41 |
interface, but rather an intuitive shell for performing basic LDAP |
|
42 |
tasks quickly and with minimal effort. |
|
43 |
||
44 |
=head1 SYNPOSIS |
|
45 |
||
3
0f815f3daaf7
Add options to support ssl key verification when connecting with TLS.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
46 |
shelldap --server example.net [--help] |
0 | 47 |
|
48 |
=head1 FEATURES |
|
49 |
||
50 |
- Upon successful authenticated binding, credential information is |
|
51 |
auto-cached to ~/.shelldap.rc -- future loads require no command line |
|
52 |
flags. |
|
53 |
||
54 |
- Custom 'description maps' for entry listings. (See the 'list' command.) |
|
55 |
||
56 |
- History and autocomplete via readline, if installed. |
|
57 |
||
58 |
- Automatic reconnection attempts if the connection is lost with the |
|
59 |
LDAP server. |
|
60 |
||
51
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
61 |
- Basic schema introspection for quick reference. |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
62 |
|
0 | 63 |
- It feels like a semi-crippled shell, making LDAP browsing and editing |
64 |
at least halfway pleasurable. |
|
65 |
||
66 |
=head1 OPTIONS |
|
67 |
||
68 |
All command line options follow getopts long conventions. |
|
69 |
||
70 |
shelldap --server example.net --basedn dc=your,o=company |
|
71 |
||
72 |
You may also optionally create a ~/.shelldap.rc file with command line |
|
73 |
defaults. This file should be valid YAML. (This file is generated |
|
74 |
automatically on a successful bind auth.) |
|
75 |
||
76 |
Example: |
|
77 |
||
78 |
server: ldap.example.net |
|
79 |
binddn: cn=Manager,dc=your,o=company |
|
80 |
bindpass: xxxxxxxxx |
|
81 |
basedn: dc=your,o=company |
|
82 |
tls: yes |
|
3
0f815f3daaf7
Add options to support ssl key verification when connecting with TLS.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
83 |
tls_cacert: /etc/ssl/certs/cacert.pem |
0f815f3daaf7
Add options to support ssl key verification when connecting with TLS.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
84 |
tls_cert: ~/.ssl/client.cert.pem |
0f815f3daaf7
Add options to support ssl key verification when connecting with TLS.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
85 |
tls_key: ~/.ssl/private/client.key.pem |
0 | 86 |
|
87 |
=over 4 |
|
88 |
||
50 | 89 |
=item B<configfile> |
90 |
||
91 |
Optional. Use an alternate configuration file, instead of the |
|
92 |
default ~/.shelldap.rc. |
|
93 |
||
94 |
--configfile /tmp/alternate-config.yml |
|
95 |
-f /tmp/alternate-config.yml |
|
96 |
||
51
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
97 |
This config file overrides values found in the default config, so |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
98 |
you can easily have separate config files for connecting to your |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
99 |
cn=monitor or cn=log overlays (for example.) |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
100 |
|
50 | 101 |
=back |
102 |
||
103 |
=over 4 |
|
104 |
||
0 | 105 |
=item B<server> |
106 |
||
107 |
Required. The LDAP server to connect to. This can be a hostname, IP |
|
108 |
address, or a URI. |
|
109 |
||
110 |
--server ldaps://ldap.example.net |
|
19
18e71da965ff
Add documentation for the additional short flags.
Mahlon E. Smith <mahlon@martini.nu>
parents:
18
diff
changeset
|
111 |
-H ldaps://ldap.example.net |
117
eb1bcbaf9763
Improve accepted command line options
Davor Ocelic <docelic@crystallabs.io>
parents:
116
diff
changeset
|
112 |
-h hostname_or_IP |
0 | 113 |
|
114 |
=back |
|
115 |
||
116 |
=over 4 |
|
117 |
||
118 |
=item B<binddn> |
|
119 |
||
120 |
The full dn of a user to authenticate as. If not specified, defaults to |
|
121 |
an anonymous bind. You will be prompted for a password. |
|
122 |
||
123 |
--binddn cn=Manager,dc=your,o=company |
|
19
18e71da965ff
Add documentation for the additional short flags.
Mahlon E. Smith <mahlon@martini.nu>
parents:
18
diff
changeset
|
124 |
-D cn=Manager,dc=your,o=company |
0 | 125 |
|
126 |
=back |
|
127 |
||
128 |
=over 4 |
|
129 |
||
130 |
=item B<basedn> |
|
131 |
||
132 |
The directory 'root' of your LDAP server. If omitted, shelldap will |
|
133 |
try and ask the server for a sane default. |
|
134 |
||
135 |
--basedn dc=your,o=company |
|
19
18e71da965ff
Add documentation for the additional short flags.
Mahlon E. Smith <mahlon@martini.nu>
parents:
18
diff
changeset
|
136 |
-b dc=your,o=company |
0 | 137 |
|
138 |
=back |
|
139 |
||
140 |
=over 4 |
|
141 |
||
92
a1aa55019077
Optionally use the server side pager control for search results.
Mahlon E. Smith <mahlon@martini.nu>
parents:
91
diff
changeset
|
142 |
=item B<paginate> |
a1aa55019077
Optionally use the server side pager control for search results.
Mahlon E. Smith <mahlon@martini.nu>
parents:
91
diff
changeset
|
143 |
|
a1aa55019077
Optionally use the server side pager control for search results.
Mahlon E. Smith <mahlon@martini.nu>
parents:
91
diff
changeset
|
144 |
Integer. If enabled, shelldap will attempt to use server side |
a1aa55019077
Optionally use the server side pager control for search results.
Mahlon E. Smith <mahlon@martini.nu>
parents:
91
diff
changeset
|
145 |
pagination to build listings. Note: if you're using this to avoid |
a1aa55019077
Optionally use the server side pager control for search results.
Mahlon E. Smith <mahlon@martini.nu>
parents:
91
diff
changeset
|
146 |
sizelimit errors, you'll likely need server configuration to raise the |
a1aa55019077
Optionally use the server side pager control for search results.
Mahlon E. Smith <mahlon@martini.nu>
parents:
91
diff
changeset
|
147 |
limits for paginated results. |
a1aa55019077
Optionally use the server side pager control for search results.
Mahlon E. Smith <mahlon@martini.nu>
parents:
91
diff
changeset
|
148 |
|
115
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
149 |
--paginate 100 |
92
a1aa55019077
Optionally use the server side pager control for search results.
Mahlon E. Smith <mahlon@martini.nu>
parents:
91
diff
changeset
|
150 |
|
a1aa55019077
Optionally use the server side pager control for search results.
Mahlon E. Smith <mahlon@martini.nu>
parents:
91
diff
changeset
|
151 |
=back |
a1aa55019077
Optionally use the server side pager control for search results.
Mahlon E. Smith <mahlon@martini.nu>
parents:
91
diff
changeset
|
152 |
|
a1aa55019077
Optionally use the server side pager control for search results.
Mahlon E. Smith <mahlon@martini.nu>
parents:
91
diff
changeset
|
153 |
=over 4 |
a1aa55019077
Optionally use the server side pager control for search results.
Mahlon E. Smith <mahlon@martini.nu>
parents:
91
diff
changeset
|
154 |
|
42
b8c6d4e8f828
Add a flag to force a password prompt, so you can override credentials
Mahlon E. Smith <mahlon@laika.com>
parents:
41
diff
changeset
|
155 |
=item B<promptpass> |
b8c6d4e8f828
Add a flag to force a password prompt, so you can override credentials
Mahlon E. Smith <mahlon@laika.com>
parents:
41
diff
changeset
|
156 |
|
b8c6d4e8f828
Add a flag to force a password prompt, so you can override credentials
Mahlon E. Smith <mahlon@laika.com>
parents:
41
diff
changeset
|
157 |
Force password prompting. Useful to temporarily override cached |
b8c6d4e8f828
Add a flag to force a password prompt, so you can override credentials
Mahlon E. Smith <mahlon@laika.com>
parents:
41
diff
changeset
|
158 |
credentials. |
b8c6d4e8f828
Add a flag to force a password prompt, so you can override credentials
Mahlon E. Smith <mahlon@laika.com>
parents:
41
diff
changeset
|
159 |
|
b8c6d4e8f828
Add a flag to force a password prompt, so you can override credentials
Mahlon E. Smith <mahlon@laika.com>
parents:
41
diff
changeset
|
160 |
=back |
b8c6d4e8f828
Add a flag to force a password prompt, so you can override credentials
Mahlon E. Smith <mahlon@laika.com>
parents:
41
diff
changeset
|
161 |
|
66
5a0c99ca0c0d
Fix the pod so it can build without complaint under perl 5.20, bump to
Mahlon E. Smith <mahlon@martini.nu>
parents:
64
diff
changeset
|
162 |
=over 4 |
5a0c99ca0c0d
Fix the pod so it can build without complaint under perl 5.20, bump to
Mahlon E. Smith <mahlon@martini.nu>
parents:
64
diff
changeset
|
163 |
|
62
ed8253b3105a
Add quick documentation blurb for SASL mechanisms. Make SASL
Mahlon E. Smith <mahlon@laika.com>
parents:
61
diff
changeset
|
164 |
=item B<sasl> |
ed8253b3105a
Add quick documentation blurb for SASL mechanisms. Make SASL
Mahlon E. Smith <mahlon@laika.com>
parents:
61
diff
changeset
|
165 |
|
ed8253b3105a
Add quick documentation blurb for SASL mechanisms. Make SASL
Mahlon E. Smith <mahlon@laika.com>
parents:
61
diff
changeset
|
166 |
A space separated list of SASL mechanisms. Requires the Authen::SASL |
ed8253b3105a
Add quick documentation blurb for SASL mechanisms. Make SASL
Mahlon E. Smith <mahlon@laika.com>
parents:
61
diff
changeset
|
167 |
module. |
ed8253b3105a
Add quick documentation blurb for SASL mechanisms. Make SASL
Mahlon E. Smith <mahlon@laika.com>
parents:
61
diff
changeset
|
168 |
|
117
eb1bcbaf9763
Improve accepted command line options
Davor Ocelic <docelic@crystallabs.io>
parents:
116
diff
changeset
|
169 |
--sasl 'PLAIN CRAM-MD5 GSSAPI' |
62
ed8253b3105a
Add quick documentation blurb for SASL mechanisms. Make SASL
Mahlon E. Smith <mahlon@laika.com>
parents:
61
diff
changeset
|
170 |
|
ed8253b3105a
Add quick documentation blurb for SASL mechanisms. Make SASL
Mahlon E. Smith <mahlon@laika.com>
parents:
61
diff
changeset
|
171 |
=back |
ed8253b3105a
Add quick documentation blurb for SASL mechanisms. Make SASL
Mahlon E. Smith <mahlon@laika.com>
parents:
61
diff
changeset
|
172 |
|
42
b8c6d4e8f828
Add a flag to force a password prompt, so you can override credentials
Mahlon E. Smith <mahlon@laika.com>
parents:
41
diff
changeset
|
173 |
=over 4 |
b8c6d4e8f828
Add a flag to force a password prompt, so you can override credentials
Mahlon E. Smith <mahlon@laika.com>
parents:
41
diff
changeset
|
174 |
|
b8c6d4e8f828
Add a flag to force a password prompt, so you can override credentials
Mahlon E. Smith <mahlon@laika.com>
parents:
41
diff
changeset
|
175 |
=item B<tls> |
0 | 176 |
|
177 |
Enables TLS over what would normally be an insecure connection. |
|
178 |
Requires server side support. |
|
179 |
||
3
0f815f3daaf7
Add options to support ssl key verification when connecting with TLS.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
180 |
=item B<tls_cacert> |
0f815f3daaf7
Add options to support ssl key verification when connecting with TLS.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
181 |
|
0f815f3daaf7
Add options to support ssl key verification when connecting with TLS.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
182 |
Specify CA Certificate to trust. |
0f815f3daaf7
Add options to support ssl key verification when connecting with TLS.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
183 |
|
0f815f3daaf7
Add options to support ssl key verification when connecting with TLS.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
184 |
--tls_cacert /etc/ssl/certs/cacert.pem |
0f815f3daaf7
Add options to support ssl key verification when connecting with TLS.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
185 |
|
0f815f3daaf7
Add options to support ssl key verification when connecting with TLS.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
186 |
=item B<tls_cert> |
0f815f3daaf7
Add options to support ssl key verification when connecting with TLS.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
187 |
|
0f815f3daaf7
Add options to support ssl key verification when connecting with TLS.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
188 |
The TLS client certificate. |
0f815f3daaf7
Add options to support ssl key verification when connecting with TLS.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
189 |
|
0f815f3daaf7
Add options to support ssl key verification when connecting with TLS.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
190 |
--tls_cert ~/.ssl/client.cert.pem |
0f815f3daaf7
Add options to support ssl key verification when connecting with TLS.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
191 |
|
0f815f3daaf7
Add options to support ssl key verification when connecting with TLS.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
192 |
=item B<tls_key> |
0f815f3daaf7
Add options to support ssl key verification when connecting with TLS.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
193 |
|
0f815f3daaf7
Add options to support ssl key verification when connecting with TLS.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
194 |
The TLS client key. Not specifying a key will connect via TLS without |
0f815f3daaf7
Add options to support ssl key verification when connecting with TLS.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
195 |
key verification. |
0f815f3daaf7
Add options to support ssl key verification when connecting with TLS.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
196 |
|
0f815f3daaf7
Add options to support ssl key verification when connecting with TLS.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
197 |
--tls_key ~/.ssl/private/client.key.pem |
0f815f3daaf7
Add options to support ssl key verification when connecting with TLS.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
198 |
|
0 | 199 |
=back |
200 |
||
201 |
=over 4 |
|
202 |
||
203 |
=item B<cacheage> |
|
204 |
||
205 |
Set the time to cache directory lookups in seconds. |
|
206 |
||
207 |
By default, directory lookups are cached for 300 seconds, to speed |
|
208 |
autocomplete up when changing between different basedns. |
|
209 |
||
210 |
Modifications to the directory automatically reset the cache. Directory |
|
211 |
listings are not cached. (This is just used for autocomplete.) Set it |
|
212 |
to 0 to disable caching completely. |
|
213 |
||
214 |
=back |
|
215 |
||
216 |
=over 4 |
|
217 |
||
218 |
=item B<timeout> |
|
219 |
||
220 |
Set the maximum time an LDAP operation can take before it is cancelled. |
|
221 |
||
222 |
=back |
|
223 |
||
224 |
=over 4 |
|
225 |
||
226 |
=item B<debug> |
|
227 |
||
228 |
Print extra operational info out, and backtrace on fatal error. |
|
229 |
||
230 |
=back |
|
231 |
||
37 | 232 |
=over 4 |
233 |
||
234 |
=item B<version> |
|
235 |
||
236 |
Display the version number. |
|
237 |
||
238 |
=back |
|
239 |
||
0 | 240 |
=head1 SHELL COMMANDS |
241 |
||
242 |
=over 4 |
|
243 |
||
115
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
244 |
=head2 alias |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
245 |
|
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
246 |
Define or display aliases. |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
247 |
|
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
248 |
Without arguments, `alias' prints the list of aliases in the reusable |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
249 |
form `alias NAME=VALUE' on standard output. |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
250 |
|
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
251 |
Otherwise, an alias is defined for each NAME whose VALUE is given. |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
252 |
A trailing space in VALUE causes the next word to be checked for |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
253 |
alias substitution when the alias is expanded. |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
254 |
|
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
255 |
alias |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
256 |
alias ll=ls -al |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
257 |
alias ll |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
258 |
alias show=cat |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
259 |
alias cmd1=command 'arg with spaces' |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
260 |
alias cmd2='command ' |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
261 |
alias cmd2=command 'with_arg ' |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
262 |
|
103
20752fcf201c
Improve 'help' command
Davor Ocelic <docelic@crystallabs.io>
parents:
102
diff
changeset
|
263 |
=head2 cat |
0 | 264 |
|
109
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
265 |
Print contents of LDAP entry to STDOUT in LDIF format. |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
266 |
|
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
267 |
Globbing is supported. Specify either full DN, or a RDN. |
105
e7e850a1540c
Improve command descriptions
Davor Ocelic <docelic@crystallabs.io>
parents:
104
diff
changeset
|
268 |
RDNs are local to the current search base ('cwd' in shell terms). If RDN is '.' or missing, |
e7e850a1540c
Improve command descriptions
Davor Ocelic <docelic@crystallabs.io>
parents:
104
diff
changeset
|
269 |
it defaults to the current search base. |
e7e850a1540c
Improve command descriptions
Davor Ocelic <docelic@crystallabs.io>
parents:
104
diff
changeset
|
270 |
You may additionally add a list of attributes to display (e.g. use '+' for operational |
e7e850a1540c
Improve command descriptions
Davor Ocelic <docelic@crystallabs.io>
parents:
104
diff
changeset
|
271 |
attributes or provide a specific space-separated list). Default list of attributes is ['*'] |
e7e850a1540c
Improve command descriptions
Davor Ocelic <docelic@crystallabs.io>
parents:
104
diff
changeset
|
272 |
and this default list can be changed using 'attributes' config key or --attributes cmdline |
e7e850a1540c
Improve command descriptions
Davor Ocelic <docelic@crystallabs.io>
parents:
104
diff
changeset
|
273 |
option. |
0 | 274 |
|
275 |
cat uid=mahlon |
|
276 |
cat ou=* |
|
277 |
cat uid=mahlon,ou=People,dc=example,o=company |
|
278 |
cat uid=mahlon + userPassword |
|
279 |
||
115
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
280 |
=head2 configfile |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
281 |
|
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
282 |
Load or save config file. |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
283 |
|
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
284 |
If no config file is specified as argument to 'load', the default search list is: |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
285 |
|
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
286 |
$HOME/.shelldap.rc |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
287 |
/usr/local/etc/shelldap.conf |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
288 |
/etc/shelldap.conf |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
289 |
|
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
290 |
If no config file is specified as argument to 'save', the default path is |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
291 |
$HOME/.shelldap.rc. |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
292 |
|
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
293 |
configfile load |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
294 |
configfile load /path/to/config |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
295 |
configfile save |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
296 |
configfile save /path/to/config |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
297 |
|
103
20752fcf201c
Improve 'help' command
Davor Ocelic <docelic@crystallabs.io>
parents:
102
diff
changeset
|
298 |
=head2 less |
72
39e9f802eb40
Add a 'less' command, that does the same as cat, but uses a pager.
Dennis Kaarsemaker <dennis.kaarsemaker@booking.com>
parents:
71
diff
changeset
|
299 |
|
109
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
300 |
Like 'cat', but use configured pager to paginate output. |
72
39e9f802eb40
Add a 'less' command, that does the same as cat, but uses a pager.
Dennis Kaarsemaker <dennis.kaarsemaker@booking.com>
parents:
71
diff
changeset
|
301 |
|
103
20752fcf201c
Improve 'help' command
Davor Ocelic <docelic@crystallabs.io>
parents:
102
diff
changeset
|
302 |
=head2 cd |
0 | 303 |
|
109
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
304 |
Change the working directory (LDAP search base). |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
305 |
|
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
306 |
Translated to LDAP, this changes the current basedn. |
0 | 307 |
All commands after a 'cd' operate within the new basedn. |
308 |
||
105
e7e850a1540c
Improve command descriptions
Davor Ocelic <docelic@crystallabs.io>
parents:
104
diff
changeset
|
309 |
cd change to 'home' (binddn if any, or basedn) |
e7e850a1540c
Improve command descriptions
Davor Ocelic <docelic@crystallabs.io>
parents:
104
diff
changeset
|
310 |
cd ~ change to 'home' (binddn if any, or basedn) |
33
057fefab56b0
Repair broken path behavior, remove unneeded #path_to_dn 'relative'
Mahlon E. Smith <mahlon@martini.nu>
parents:
32
diff
changeset
|
311 |
cd - change to previous node |
057fefab56b0
Repair broken path behavior, remove unneeded #path_to_dn 'relative'
Mahlon E. Smith <mahlon@martini.nu>
parents:
32
diff
changeset
|
312 |
cd ou=People change to explicit path below current node |
057fefab56b0
Repair broken path behavior, remove unneeded #path_to_dn 'relative'
Mahlon E. Smith <mahlon@martini.nu>
parents:
32
diff
changeset
|
313 |
cd .. change to parent node |
057fefab56b0
Repair broken path behavior, remove unneeded #path_to_dn 'relative'
Mahlon E. Smith <mahlon@martini.nu>
parents:
32
diff
changeset
|
314 |
cd ../../ou=Groups change to node ou=Groups, which is a sibling |
057fefab56b0
Repair broken path behavior, remove unneeded #path_to_dn 'relative'
Mahlon E. Smith <mahlon@martini.nu>
parents:
32
diff
changeset
|
315 |
to the current node's grandparent |
0 | 316 |
|
105
e7e850a1540c
Improve command descriptions
Davor Ocelic <docelic@crystallabs.io>
parents:
104
diff
changeset
|
317 |
Since LDAP doesn't limit what can be a container object, you can 'cd' into |
e7e850a1540c
Improve command descriptions
Davor Ocelic <docelic@crystallabs.io>
parents:
104
diff
changeset
|
318 |
any entry. Many commands then work on '.' or default to '.', meaning |
0 | 319 |
"wherever I currently am." |
320 |
||
321 |
cd uid=mahlon |
|
322 |
cat . |
|
105
e7e850a1540c
Improve command descriptions
Davor Ocelic <docelic@crystallabs.io>
parents:
104
diff
changeset
|
323 |
cat |
0 | 324 |
|
103
20752fcf201c
Improve 'help' command
Davor Ocelic <docelic@crystallabs.io>
parents:
102
diff
changeset
|
325 |
=head2 clear |
0 | 326 |
|
109
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
327 |
Clear the terminal screen. |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
328 |
|
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
329 |
Clears screen similar to 'clear' or Ctrl+l on the shell command line. |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
330 |
|
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
331 |
Ctrl+l alias is also supported. |
0 | 332 |
|
103
20752fcf201c
Improve 'help' command
Davor Ocelic <docelic@crystallabs.io>
parents:
102
diff
changeset
|
333 |
=head2 copy |
0 | 334 |
|
109
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
335 |
Copy an entry. |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
336 |
|
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
337 |
All copies are relative to the |
105
e7e850a1540c
Improve command descriptions
Davor Ocelic <docelic@crystallabs.io>
parents:
104
diff
changeset
|
338 |
current basedn unless a full DN is specified. All attributes are |
e7e850a1540c
Improve command descriptions
Davor Ocelic <docelic@crystallabs.io>
parents:
104
diff
changeset
|
339 |
copied and then an LDAP moddn() is performed. |
0 | 340 |
|
341 |
copy uid=mahlon uid=bob |
|
342 |
copy uid=mahlon ou=Others,dc=example,o=company |
|
343 |
copy uid=mahlon,ou=People,dc=example,o=company uid=mahlon,ou=Others,dc=example,o=company |
|
344 |
||
103
20752fcf201c
Improve 'help' command
Davor Ocelic <docelic@crystallabs.io>
parents:
102
diff
changeset
|
345 |
=head2 create |
0 | 346 |
|
109
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
347 |
Create an entry. |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
348 |
|
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
349 |
Arguments are space separated objectClass |
0 | 350 |
names. Possible objectClasses are derived automatically from the |
351 |
server, and will tab-complete. |
|
352 |
||
353 |
After the classes are specified, an editor will launch. Required |
|
354 |
attributes are listed first, then optional attributes. Optionals are |
|
355 |
commented out. After the editor exits, the resulting LDIF is validated |
|
356 |
and added to the LDAP directory. |
|
357 |
||
358 |
create top person organizationalPerson inetOrgPerson posixAccount |
|
359 |
||
103
20752fcf201c
Improve 'help' command
Davor Ocelic <docelic@crystallabs.io>
parents:
102
diff
changeset
|
360 |
=head2 delete |
0 | 361 |
|
109
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
362 |
Remove an entry. |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
363 |
|
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
364 |
Globbing is supported. |
67
86e3374a40a3
Add 'rm' for a fully qualified DN, instead of only working with RDN.
Mahlon E. Smith <mahlon@laika.com>
parents:
62
diff
changeset
|
365 |
All deletes are sanity-prompted. The -v flag prints the entries out |
86e3374a40a3
Add 'rm' for a fully qualified DN, instead of only working with RDN.
Mahlon E. Smith <mahlon@laika.com>
parents:
62
diff
changeset
|
366 |
for review before delete. |
0 | 367 |
|
368 |
delete uid=mahlon |
|
369 |
delete uid=ma* |
|
67
86e3374a40a3
Add 'rm' for a fully qualified DN, instead of only working with RDN.
Mahlon E. Smith <mahlon@laika.com>
parents:
62
diff
changeset
|
370 |
rm -v uid=mahlon,ou=People,dc=example,o=company l=office |
0 | 371 |
|
103
20752fcf201c
Improve 'help' command
Davor Ocelic <docelic@crystallabs.io>
parents:
102
diff
changeset
|
372 |
=head2 edit |
0 | 373 |
|
109
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
374 |
Edit an entry in an external editor. |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
375 |
|
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
376 |
After the editor exits, the |
0 | 377 |
resulting LDIF is sanity checked, and changes are written to the LDAP |
378 |
directory. |
|
379 |
||
380 |
edit uid=mahlon |
|
381 |
||
103
20752fcf201c
Improve 'help' command
Davor Ocelic <docelic@crystallabs.io>
parents:
102
diff
changeset
|
382 |
=head2 env |
0 | 383 |
|
109
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
384 |
Print values of configurable shelldap variables. |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
385 |
|
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
386 |
This is a subset of all variables configurable via shelldap config |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
387 |
file and/or its command line options. |
0 | 388 |
|
103
20752fcf201c
Improve 'help' command
Davor Ocelic <docelic@crystallabs.io>
parents:
102
diff
changeset
|
389 |
=head2 grep |
0 | 390 |
|
109
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
391 |
Search using LDAP filters and return matching DN results. |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
392 |
|
0 | 393 |
The search string must be a valid LDAP filter. |
394 |
||
395 |
grep uid=mahlon |
|
396 |
grep uid=mahlon ou=People |
|
397 |
grep -r (&(uid=mahlon)(objectClass=*)) |
|
398 |
||
103
20752fcf201c
Improve 'help' command
Davor Ocelic <docelic@crystallabs.io>
parents:
102
diff
changeset
|
399 |
=head2 inspect |
51
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
400 |
|
109
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
401 |
View schema and flags for an entry or objectClass. |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
402 |
|
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
403 |
It also includes the most common flags for the objectClass |
51
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
404 |
attributes. |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
405 |
|
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
406 |
inspect uid=mahlon |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
407 |
inspect posixAccount organizationalUnit |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
408 |
inspect _schema |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
409 |
|
91
80ec00959fbd
Fix spelling errors
Salvatore Bonaccorso <carnil@debian.org>
parents:
87
diff
changeset
|
410 |
The output is a list of found objectClasses, their schema hierarchy |
51
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
411 |
(up to 'top'), whether or not they are a structural class, and then |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
412 |
a merged list of all valid attributes for the given objectClasses. |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
413 |
Attributes are marked as either required or optional, and whether |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
414 |
they allow multiple values or not. |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
415 |
|
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
416 |
If you ask for the special "_schema" object, the raw server schema |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
417 |
is dumped to screen. |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
418 |
|
103
20752fcf201c
Improve 'help' command
Davor Ocelic <docelic@crystallabs.io>
parents:
102
diff
changeset
|
419 |
=head2 list |
0 | 420 |
|
109
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
421 |
List directory contents. |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
422 |
|
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
423 |
Globbing is supported. |
0 | 424 |
|
425 |
ls -l |
|
426 |
ls -lR uid=mahlon |
|
427 |
list uid=m* |
|
428 |
||
36
2e78218b8045
Small documentation fixes, add better verbosity when saving connection
Mahlon E. Smith <mahlon@martini.nu>
parents:
35
diff
changeset
|
429 |
In 'long' mode, descriptions are listed as well, if they exist. |
2e78218b8045
Small documentation fixes, add better verbosity when saving connection
Mahlon E. Smith <mahlon@martini.nu>
parents:
35
diff
changeset
|
430 |
There are some default 'long listing' mappings for common objectClass |
2e78218b8045
Small documentation fixes, add better verbosity when saving connection
Mahlon E. Smith <mahlon@martini.nu>
parents:
35
diff
changeset
|
431 |
types. You can additionally specify your own mappings in your |
2e78218b8045
Small documentation fixes, add better verbosity when saving connection
Mahlon E. Smith <mahlon@martini.nu>
parents:
35
diff
changeset
|
432 |
.shelldap.rc, like so: |
0 | 433 |
|
434 |
... |
|
435 |
descmaps: |
|
436 |
objectClass: attributename |
|
437 |
posixAccount: gecos |
|
438 |
posixGroup: gidNumber |
|
439 |
ipHost: ipHostNumber |
|
440 |
||
103
20752fcf201c
Improve 'help' command
Davor Ocelic <docelic@crystallabs.io>
parents:
102
diff
changeset
|
441 |
=head2 mkdir |
0 | 442 |
|
109
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
443 |
Create a new 'organizationalUnit' LDAP entry. |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
444 |
|
115
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
445 |
mkdir containername |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
446 |
mkdir ou=whatever |
0 | 447 |
|
103
20752fcf201c
Improve 'help' command
Davor Ocelic <docelic@crystallabs.io>
parents:
102
diff
changeset
|
448 |
=head2 move |
0 | 449 |
|
109
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
450 |
Move (rename) entry. |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
451 |
|
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
452 |
Usage is identical to B<copy>. |
0 | 453 |
|
103
20752fcf201c
Improve 'help' command
Davor Ocelic <docelic@crystallabs.io>
parents:
102
diff
changeset
|
454 |
=head2 passwd |
0 | 455 |
|
109
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
456 |
Change user password. |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
457 |
|
0 | 458 |
If supported server side, change the password for a specified entry. |
459 |
The entry must have a 'userPassword' attribute. |
|
460 |
||
461 |
passwd uid=mahlon |
|
462 |
||
103
20752fcf201c
Improve 'help' command
Davor Ocelic <docelic@crystallabs.io>
parents:
102
diff
changeset
|
463 |
=head2 pwd |
0 | 464 |
|
109
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
465 |
Print name of current/working LDAP search base. |
0 | 466 |
|
103
20752fcf201c
Improve 'help' command
Davor Ocelic <docelic@crystallabs.io>
parents:
102
diff
changeset
|
467 |
=head2 setenv |
0 | 468 |
|
109
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
469 |
Change or define shelldap variable. |
0 | 470 |
|
471 |
setenv debug 1 |
|
472 |
export debug=1 |
|
473 |
||
115
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
474 |
=head2 unalias |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
475 |
|
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
476 |
Remove each NAME from the list of defined aliases. |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
477 |
|
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
478 |
alias ll=ls -al |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
479 |
alias |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
480 |
unalias ll |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
481 |
unalias ll ls |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
482 |
alias |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
483 |
|
103
20752fcf201c
Improve 'help' command
Davor Ocelic <docelic@crystallabs.io>
parents:
102
diff
changeset
|
484 |
=head2 whoami |
0 | 485 |
|
109
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
486 |
Print current bind DN. |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
487 |
|
0 | 488 |
Show current auth credentials. Unless you specified a binddn, this |
489 |
will just show an anonymous bind. |
|
490 |
||
491 |
=back |
|
492 |
||
493 |
=head1 TODO |
|
494 |
||
495 |
Referral support. Currently, if you try to write to a replicant slave, |
|
496 |
you'll just get a referral. It would be nice if shelldap automatically |
|
497 |
tried to follow it. |
|
498 |
||
499 |
For now, it only makes sense to connect to a master if you plan on doing |
|
500 |
any writes. |
|
501 |
||
105
e7e850a1540c
Improve command descriptions
Davor Ocelic <docelic@crystallabs.io>
parents:
104
diff
changeset
|
502 |
Add ability for command definitions in cmd_map to contain default |
e7e850a1540c
Improve command descriptions
Davor Ocelic <docelic@crystallabs.io>
parents:
104
diff
changeset
|
503 |
arguments passed to functions. |
e7e850a1540c
Improve command descriptions
Davor Ocelic <docelic@crystallabs.io>
parents:
104
diff
changeset
|
504 |
|
e7e850a1540c
Improve command descriptions
Davor Ocelic <docelic@crystallabs.io>
parents:
104
diff
changeset
|
505 |
Then add ability to define custom commands/aliases in config file. |
e7e850a1540c
Improve command descriptions
Davor Ocelic <docelic@crystallabs.io>
parents:
104
diff
changeset
|
506 |
|
e7e850a1540c
Improve command descriptions
Davor Ocelic <docelic@crystallabs.io>
parents:
104
diff
changeset
|
507 |
Split 'inspect' into separate commands, one working on files/entries, |
e7e850a1540c
Improve command descriptions
Davor Ocelic <docelic@crystallabs.io>
parents:
104
diff
changeset
|
508 |
and one working on objectclasses. This way, autocompleter for both commands |
e7e850a1540c
Improve command descriptions
Davor Ocelic <docelic@crystallabs.io>
parents:
104
diff
changeset
|
509 |
will be reasonable, unlike now. |
e7e850a1540c
Improve command descriptions
Davor Ocelic <docelic@crystallabs.io>
parents:
104
diff
changeset
|
510 |
|
0 | 511 |
=head1 BUGS / LIMITATIONS |
512 |
||
6
46dfe9d6f368
Update documentation, now that multiline edits work. Minor other
Mahlon E. Smith <mahlon@laika.com>
parents:
5
diff
changeset
|
513 |
There is no support for editing binary data. If you need to edit base64 |
46dfe9d6f368
Update documentation, now that multiline edits work. Minor other
Mahlon E. Smith <mahlon@laika.com>
parents:
5
diff
changeset
|
514 |
stuff, just feed it to the regular ldapmodify/ldapadd/etc tools. |
0 | 515 |
|
516 |
=head1 AUTHOR |
|
517 |
||
518 |
Mahlon E. Smith <mahlon@martini.nu> |
|
519 |
||
520 |
=cut |
|
521 |
||
522 |
package LDAP::Shell; |
|
523 |
use strict; |
|
524 |
use warnings; |
|
108
24340fdef276
Properly handle Ctrl+C; add '?' and 'man' aliases; don't import symbols
Davor Ocelic <docelic@crystallabs.io>
parents:
107
diff
changeset
|
525 |
use Term::ReadKey qw//; |
24340fdef276
Properly handle Ctrl+C; add '?' and 'man' aliases; don't import symbols
Davor Ocelic <docelic@crystallabs.io>
parents:
107
diff
changeset
|
526 |
use Term::Shell qw//; |
24340fdef276
Properly handle Ctrl+C; add '?' and 'man' aliases; don't import symbols
Davor Ocelic <docelic@crystallabs.io>
parents:
107
diff
changeset
|
527 |
use Digest::MD5 qw//; |
48
fe27dfe5179e
More robust path for connection retries. Show optional, unused
Mahlon E. Smith <mahlon@laika.com>
parents:
46
diff
changeset
|
528 |
use Net::LDAP qw/ |
fe27dfe5179e
More robust path for connection retries. Show optional, unused
Mahlon E. Smith <mahlon@laika.com>
parents:
46
diff
changeset
|
529 |
LDAP_SUCCESS |
fe27dfe5179e
More robust path for connection retries. Show optional, unused
Mahlon E. Smith <mahlon@laika.com>
parents:
46
diff
changeset
|
530 |
LDAP_SERVER_DOWN |
fe27dfe5179e
More robust path for connection retries. Show optional, unused
Mahlon E. Smith <mahlon@laika.com>
parents:
46
diff
changeset
|
531 |
LDAP_OPERATIONS_ERROR |
fe27dfe5179e
More robust path for connection retries. Show optional, unused
Mahlon E. Smith <mahlon@laika.com>
parents:
46
diff
changeset
|
532 |
LDAP_TIMELIMIT_EXCEEDED |
fe27dfe5179e
More robust path for connection retries. Show optional, unused
Mahlon E. Smith <mahlon@laika.com>
parents:
46
diff
changeset
|
533 |
LDAP_BUSY |
fe27dfe5179e
More robust path for connection retries. Show optional, unused
Mahlon E. Smith <mahlon@laika.com>
parents:
46
diff
changeset
|
534 |
LDAP_UNAVAILABLE |
fe27dfe5179e
More robust path for connection retries. Show optional, unused
Mahlon E. Smith <mahlon@laika.com>
parents:
46
diff
changeset
|
535 |
LDAP_OTHER |
fe27dfe5179e
More robust path for connection retries. Show optional, unused
Mahlon E. Smith <mahlon@laika.com>
parents:
46
diff
changeset
|
536 |
LDAP_TIMEOUT |
fe27dfe5179e
More robust path for connection retries. Show optional, unused
Mahlon E. Smith <mahlon@laika.com>
parents:
46
diff
changeset
|
537 |
LDAP_NO_MEMORY |
93
4c7843b9a047
Make password extension usage consistent with pager control.
Mahlon E. Smith <mahlon@martini.nu>
parents:
92
diff
changeset
|
538 |
LDAP_EXTENSION_PASSWORD_MODIFY |
92
a1aa55019077
Optionally use the server side pager control for search results.
Mahlon E. Smith <mahlon@martini.nu>
parents:
91
diff
changeset
|
539 |
LDAP_CONNECT_ERROR |
a1aa55019077
Optionally use the server side pager control for search results.
Mahlon E. Smith <mahlon@martini.nu>
parents:
91
diff
changeset
|
540 |
LDAP_CONTROL_PAGED /; |
33
057fefab56b0
Repair broken path behavior, remove unneeded #path_to_dn 'relative'
Mahlon E. Smith <mahlon@martini.nu>
parents:
32
diff
changeset
|
541 |
use Net::LDAP::Util qw/ canonical_dn ldap_explode_dn /; |
108
24340fdef276
Properly handle Ctrl+C; add '?' and 'man' aliases; don't import symbols
Davor Ocelic <docelic@crystallabs.io>
parents:
107
diff
changeset
|
542 |
use Net::LDAP::LDIF qw//; |
24340fdef276
Properly handle Ctrl+C; add '?' and 'man' aliases; don't import symbols
Davor Ocelic <docelic@crystallabs.io>
parents:
107
diff
changeset
|
543 |
use Net::LDAP::Extension::SetPassword qw//; |
24340fdef276
Properly handle Ctrl+C; add '?' and 'man' aliases; don't import symbols
Davor Ocelic <docelic@crystallabs.io>
parents:
107
diff
changeset
|
544 |
use Net::LDAP::Control::Paged qw//; |
24340fdef276
Properly handle Ctrl+C; add '?' and 'man' aliases; don't import symbols
Davor Ocelic <docelic@crystallabs.io>
parents:
107
diff
changeset
|
545 |
use Data::Dumper qw//; |
24340fdef276
Properly handle Ctrl+C; add '?' and 'man' aliases; don't import symbols
Davor Ocelic <docelic@crystallabs.io>
parents:
107
diff
changeset
|
546 |
use File::Temp qw//; |
24340fdef276
Properly handle Ctrl+C; add '?' and 'man' aliases; don't import symbols
Davor Ocelic <docelic@crystallabs.io>
parents:
107
diff
changeset
|
547 |
use Algorithm::Diff qw//; |
0 | 548 |
use Carp 'confess'; |
108
24340fdef276
Properly handle Ctrl+C; add '?' and 'man' aliases; don't import symbols
Davor Ocelic <docelic@crystallabs.io>
parents:
107
diff
changeset
|
549 |
use POSIX qw//; |
109
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
550 |
use Tie::IxHash qw//; |
118
2d7f16eff198
Use local implementation of slurp()
Davor Ocelic <docelic@crystallabs.io>
parents:
117
diff
changeset
|
551 |
use Fatal qw/open/; |
0 | 552 |
use base 'Term::Shell'; |
553 |
||
554 |
my $conf = $main::conf; |
|
555 |
||
556 |
# make 'die' backtrace in debug mode |
|
557 |
$SIG{'__DIE__'} = \&Carp::confess if $conf->{'debug'}; |
|
558 |
||
559 |
||
109
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
560 |
|
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
561 |
######################################################################## |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
562 |
### Term::Shell Fixes |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
563 |
######################################################################## |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
564 |
|
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
565 |
# Term::Shell function add_handlers() is implemented in an incorrect way. |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
566 |
# We reimplement the method here to fix its problems. |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
567 |
|
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
568 |
# In add_handlers, we split searching for aliases in a separate loop, |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
569 |
# because otherwise not all aliases are registered before we look them |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
570 |
# up. |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
571 |
sub add_handlers |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
572 |
{ |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
573 |
my $o = shift; |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
574 |
for my $hnd (@_) |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
575 |
{ |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
576 |
next unless $hnd =~ /^(run|help|smry|comp|catch|alias)_/o; |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
577 |
my $t = $1; |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
578 |
my $a = substr( $hnd, length($t) + 1 ); |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
579 |
|
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
580 |
# Add on the prefix and suffix if the command is defined |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
581 |
if ( length $a ) |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
582 |
{ |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
583 |
substr( $a, 0, 0 ) = $o->cmd_prefix; |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
584 |
$a .= $o->cmd_suffix; |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
585 |
} |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
586 |
$o->{handlers}{$a}{$t} = $hnd; |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
587 |
} |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
588 |
for my $hnd (@_) |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
589 |
{ |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
590 |
next unless $hnd =~ /^(run|help|smry|comp|catch|alias)_/o; |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
591 |
my $t = $1; |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
592 |
my $a = substr( $hnd, length($t) + 1 ); |
112
32f396697fb3
Add missing block to Term::Shell fix
Davor Ocelic <docelic@crystallabs.io>
parents:
111
diff
changeset
|
593 |
|
32f396697fb3
Add missing block to Term::Shell fix
Davor Ocelic <docelic@crystallabs.io>
parents:
111
diff
changeset
|
594 |
# Add on the prefix and suffix if the command is defined |
32f396697fb3
Add missing block to Term::Shell fix
Davor Ocelic <docelic@crystallabs.io>
parents:
111
diff
changeset
|
595 |
if ( length $a ) |
32f396697fb3
Add missing block to Term::Shell fix
Davor Ocelic <docelic@crystallabs.io>
parents:
111
diff
changeset
|
596 |
{ |
32f396697fb3
Add missing block to Term::Shell fix
Davor Ocelic <docelic@crystallabs.io>
parents:
111
diff
changeset
|
597 |
substr( $a, 0, 0 ) = $o->cmd_prefix; |
32f396697fb3
Add missing block to Term::Shell fix
Davor Ocelic <docelic@crystallabs.io>
parents:
111
diff
changeset
|
598 |
$a .= $o->cmd_suffix; |
32f396697fb3
Add missing block to Term::Shell fix
Davor Ocelic <docelic@crystallabs.io>
parents:
111
diff
changeset
|
599 |
} |
109
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
600 |
|
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
601 |
if ( $o->has_aliases($a) ) |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
602 |
{ |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
603 |
my @a = $o->get_aliases($a); |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
604 |
for my $alias (@a) |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
605 |
{ |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
606 |
substr( $alias, 0, 0 ) = $o->cmd_prefix; |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
607 |
$alias .= $o->cmd_suffix; |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
608 |
$o->{handlers}{$alias}{$t} = $hnd; |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
609 |
} |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
610 |
} |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
611 |
} |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
612 |
} |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
613 |
|
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
614 |
|
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
615 |
|
50 | 616 |
######################################################################## |
617 |
### U T I L I T Y F U N C T I O N S |
|
618 |
######################################################################## |
|
619 |
||
620 |
### Initial shell behaviors. |
|
621 |
### |
|
0 | 622 |
sub init |
623 |
{ |
|
624 |
my $self = shift; |
|
625 |
$self->{'API'}->{'match_uniq'} = 0; |
|
626 |
||
50 | 627 |
$self->{'editor'} = $conf->{'editor'} || $ENV{'EDITOR'} || 'vi'; |
73
b3b840a4b56c
Minor style cleanups, version bump.
Mahlon E. Smith <mahlon@laika.com>
parents:
72
diff
changeset
|
628 |
$self->{'pager'} = $conf->{'pager'} || $ENV{'PAGER'} || 'less'; |
116
6a0b1209dafa
Support arrays/hashes in 'env' (WIP)
Davor Ocelic <docelic@crystallabs.io>
parents:
115
diff
changeset
|
629 |
$self->{'env'} = [ qw/ debug cacheage timeout attributes / ]; |
0 | 630 |
|
631 |
# let autocomplete work with the '=' character |
|
632 |
my $term = $self->term(); |
|
633 |
$term->Attribs->{'basic_word_break_characters'} =~ s/=//m; |
|
634 |
$term->Attribs->{'completer_word_break_characters'} =~ s/=//m; |
|
635 |
||
636 |
# read in history |
|
637 |
eval { |
|
638 |
$term->history_truncate_file("$ENV{'HOME'}/.shelldap_history", 50); |
|
639 |
$term->ReadHistory("$ENV{'HOME'}/.shelldap_history"); |
|
640 |
}; |
|
641 |
||
50 | 642 |
# gather metadata from the LDAP server |
57
85cc85d0c1b1
Catch a case where the LDAP object is defined, but in a state that
Mahlon E. Smith <mahlon@laika.com>
parents:
56
diff
changeset
|
643 |
$self->{'root_dse'} = $self->ldap->root_dse() or |
85cc85d0c1b1
Catch a case where the LDAP object is defined, but in a state that
Mahlon E. Smith <mahlon@laika.com>
parents:
56
diff
changeset
|
644 |
die "Unable to retrieve LDAP server information. (Doublecheck connection arguments.)\n"; |
50 | 645 |
$self->{'schema'} = $self->ldap->schema(); |
646 |
||
647 |
# get an initial list of all objectClasses |
|
648 |
$self->{'objectclasses'} = []; |
|
649 |
foreach my $o ( $self->{'schema'}->all_objectclasses() ) { |
|
650 |
push @{ $self->{'objectclasses'} }, $o->{'name'}; |
|
651 |
} |
|
652 |
||
0 | 653 |
if ( $conf->{'debug'} ) { |
17
669085d93aa3
simplify over-complex call of N:L:E->get_value()
Peter Marschall <peter@adpm.de>
parents:
16
diff
changeset
|
654 |
my @versions = $self->{'root_dse'}->get_value('supportedLDAPVersion'); |
0 | 655 |
print "Connected to $conf->{'server'}\n"; |
656 |
print "Supported LDAP version: ", ( join ', ', @versions ), "\n"; |
|
117
eb1bcbaf9763
Improve accepted command line options
Davor Ocelic <docelic@crystallabs.io>
parents:
116
diff
changeset
|
657 |
print "Cipher in use: ", $self->ldap()->cipher() || '', "\n"; |
0 | 658 |
} |
659 |
||
92
a1aa55019077
Optionally use the server side pager control for search results.
Mahlon E. Smith <mahlon@martini.nu>
parents:
91
diff
changeset
|
660 |
# check for the pagination extension on the server early, and bail |
a1aa55019077
Optionally use the server side pager control for search results.
Mahlon E. Smith <mahlon@martini.nu>
parents:
91
diff
changeset
|
661 |
# if necessary. |
a1aa55019077
Optionally use the server side pager control for search results.
Mahlon E. Smith <mahlon@martini.nu>
parents:
91
diff
changeset
|
662 |
if ( $conf->{'paginate'} && $conf->{'paginate'} =~ /^\d+$/ && $conf->{'paginate'} > 0 ) { |
93
4c7843b9a047
Make password extension usage consistent with pager control.
Mahlon E. Smith <mahlon@martini.nu>
parents:
92
diff
changeset
|
663 |
unless ( $self->{'root_dse'}->supported_control(LDAP_CONTROL_PAGED) ) { |
4c7843b9a047
Make password extension usage consistent with pager control.
Mahlon E. Smith <mahlon@martini.nu>
parents:
92
diff
changeset
|
664 |
die "Server pagination is enabled, but the server doesn't seem to support it.\n"; |
4c7843b9a047
Make password extension usage consistent with pager control.
Mahlon E. Smith <mahlon@martini.nu>
parents:
92
diff
changeset
|
665 |
} |
92
a1aa55019077
Optionally use the server side pager control for search results.
Mahlon E. Smith <mahlon@martini.nu>
parents:
91
diff
changeset
|
666 |
} |
a1aa55019077
Optionally use the server side pager control for search results.
Mahlon E. Smith <mahlon@martini.nu>
parents:
91
diff
changeset
|
667 |
else { |
a1aa55019077
Optionally use the server side pager control for search results.
Mahlon E. Smith <mahlon@martini.nu>
parents:
91
diff
changeset
|
668 |
$conf->{'paginate'} = undef; |
a1aa55019077
Optionally use the server side pager control for search results.
Mahlon E. Smith <mahlon@martini.nu>
parents:
91
diff
changeset
|
669 |
} |
a1aa55019077
Optionally use the server side pager control for search results.
Mahlon E. Smith <mahlon@martini.nu>
parents:
91
diff
changeset
|
670 |
|
50 | 671 |
# try an initial search and bail early if it doesn't work. (bad baseDN?) |
0 | 672 |
my $s = $self->search(); |
673 |
die "LDAP baseDN error: ", $s->{'message'}, "\n" if $s->{'code'}; |
|
674 |
||
50 | 675 |
# okay, now do an initial population of 'cwd' for autocomplete. |
0 | 676 |
$self->update_entries(); |
677 |
||
678 |
# whew, okay. Update prompt, wait for input! |
|
679 |
$self->update_prompt(); |
|
680 |
||
681 |
return; |
|
682 |
} |
|
683 |
||
684 |
||
50 | 685 |
### Return an LDAP connection handle, creating it if necessary. |
686 |
### |
|
0 | 687 |
sub ldap |
688 |
{ |
|
689 |
my $self = shift; |
|
50 | 690 |
my $rv; |
0 | 691 |
|
692 |
# use cached connection object if it exists |
|
693 |
return $self->{'ldap'} if $self->{'ldap'}; |
|
694 |
||
695 |
# fill in potentially missing info |
|
696 |
die "No server specified.\n" unless $conf->{'server'}; |
|
15
f6157d378459
Exit with a nicer error message if IO::Socket::SSL isn't installed,
Mahlon E. Smith <mahlon@martini.nu>
parents:
14
diff
changeset
|
697 |
|
f6157d378459
Exit with a nicer error message if IO::Socket::SSL isn't installed,
Mahlon E. Smith <mahlon@martini.nu>
parents:
14
diff
changeset
|
698 |
# Emit a nicer error message if IO::Socket::SSL is |
f6157d378459
Exit with a nicer error message if IO::Socket::SSL isn't installed,
Mahlon E. Smith <mahlon@martini.nu>
parents:
14
diff
changeset
|
699 |
# not installed and Net::LDAP decides it is required. |
f6157d378459
Exit with a nicer error message if IO::Socket::SSL isn't installed,
Mahlon E. Smith <mahlon@martini.nu>
parents:
14
diff
changeset
|
700 |
# |
f6157d378459
Exit with a nicer error message if IO::Socket::SSL isn't installed,
Mahlon E. Smith <mahlon@martini.nu>
parents:
14
diff
changeset
|
701 |
if ( $conf->{'tls'} || $conf->{'server'} =~ m|ldaps://| ) { |
87
475aff91675b
eval optional modules in blocks instead of strings.
Mahlon E. Smith <mahlon@martini.nu>
parents:
84
diff
changeset
|
702 |
eval { require IO::Socket::SSL; }; |
15
f6157d378459
Exit with a nicer error message if IO::Socket::SSL isn't installed,
Mahlon E. Smith <mahlon@martini.nu>
parents:
14
diff
changeset
|
703 |
die qq{IO::Socket::SSL not installed, but is required for SSL or TLS connections. |
f6157d378459
Exit with a nicer error message if IO::Socket::SSL isn't installed,
Mahlon E. Smith <mahlon@martini.nu>
parents:
14
diff
changeset
|
704 |
You may try connecting insecurely, or install the module and try again.\n} if $@; |
f6157d378459
Exit with a nicer error message if IO::Socket::SSL isn't installed,
Mahlon E. Smith <mahlon@martini.nu>
parents:
14
diff
changeset
|
705 |
} |
f6157d378459
Exit with a nicer error message if IO::Socket::SSL isn't installed,
Mahlon E. Smith <mahlon@martini.nu>
parents:
14
diff
changeset
|
706 |
|
117
eb1bcbaf9763
Improve accepted command line options
Davor Ocelic <docelic@crystallabs.io>
parents:
116
diff
changeset
|
707 |
if ($conf->{'binddn'}) { |
eb1bcbaf9763
Improve accepted command line options
Davor Ocelic <docelic@crystallabs.io>
parents:
116
diff
changeset
|
708 |
if($conf->{'promptpass'}) { |
eb1bcbaf9763
Improve accepted command line options
Davor Ocelic <docelic@crystallabs.io>
parents:
116
diff
changeset
|
709 |
# Prompt for a password after disabling local echo. |
eb1bcbaf9763
Improve accepted command line options
Davor Ocelic <docelic@crystallabs.io>
parents:
116
diff
changeset
|
710 |
# |
eb1bcbaf9763
Improve accepted command line options
Davor Ocelic <docelic@crystallabs.io>
parents:
116
diff
changeset
|
711 |
print "Bind password: "; |
eb1bcbaf9763
Improve accepted command line options
Davor Ocelic <docelic@crystallabs.io>
parents:
116
diff
changeset
|
712 |
Term::ReadKey::ReadMode 2; |
eb1bcbaf9763
Improve accepted command line options
Davor Ocelic <docelic@crystallabs.io>
parents:
116
diff
changeset
|
713 |
chomp( $conf->{'bindpass'} = <STDIN> ); |
eb1bcbaf9763
Improve accepted command line options
Davor Ocelic <docelic@crystallabs.io>
parents:
116
diff
changeset
|
714 |
Term::ReadKey::ReadMode 0; |
eb1bcbaf9763
Improve accepted command line options
Davor Ocelic <docelic@crystallabs.io>
parents:
116
diff
changeset
|
715 |
print "\n"; |
eb1bcbaf9763
Improve accepted command line options
Davor Ocelic <docelic@crystallabs.io>
parents:
116
diff
changeset
|
716 |
} elsif($conf->{'pass'}) { |
eb1bcbaf9763
Improve accepted command line options
Davor Ocelic <docelic@crystallabs.io>
parents:
116
diff
changeset
|
717 |
$conf->{'bindpass'} = $conf->{'pass'} |
eb1bcbaf9763
Improve accepted command line options
Davor Ocelic <docelic@crystallabs.io>
parents:
116
diff
changeset
|
718 |
} elsif($conf->{'passfile'}) { |
118
2d7f16eff198
Use local implementation of slurp()
Davor Ocelic <docelic@crystallabs.io>
parents:
117
diff
changeset
|
719 |
chomp( $conf->{'bindpass'} = slurp($conf->{'passfile'})); |
117
eb1bcbaf9763
Improve accepted command line options
Davor Ocelic <docelic@crystallabs.io>
parents:
116
diff
changeset
|
720 |
} |
0 | 721 |
} |
722 |
||
50 | 723 |
# make the connection |
117
eb1bcbaf9763
Improve accepted command line options
Davor Ocelic <docelic@crystallabs.io>
parents:
116
diff
changeset
|
724 |
my $ldap = Net::LDAP->new( $conf->{'server'}, $conf->{port} ? ('port' => $conf->{port}) : ()) |
eb1bcbaf9763
Improve accepted command line options
Davor Ocelic <docelic@crystallabs.io>
parents:
116
diff
changeset
|
725 |
or die "Unable to connect to LDAP server '$conf->{'server'}' port ${\( $conf->{port} || 'default' )}: $!\n"; |
3
0f815f3daaf7
Add options to support ssl key verification when connecting with TLS.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
726 |
|
0f815f3daaf7
Add options to support ssl key verification when connecting with TLS.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
727 |
# secure connection options |
15
f6157d378459
Exit with a nicer error message if IO::Socket::SSL isn't installed,
Mahlon E. Smith <mahlon@martini.nu>
parents:
14
diff
changeset
|
728 |
# |
f6157d378459
Exit with a nicer error message if IO::Socket::SSL isn't installed,
Mahlon E. Smith <mahlon@martini.nu>
parents:
14
diff
changeset
|
729 |
if ( $conf->{'tls'} ) { |
3
0f815f3daaf7
Add options to support ssl key verification when connecting with TLS.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
730 |
if ( $conf->{'tls_key'} ) { |
0f815f3daaf7
Add options to support ssl key verification when connecting with TLS.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
731 |
$ldap->start_tls( |
0f815f3daaf7
Add options to support ssl key verification when connecting with TLS.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
732 |
verify => 'require', |
0f815f3daaf7
Add options to support ssl key verification when connecting with TLS.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
733 |
cafile => $conf->{'tls_cacert'}, |
0f815f3daaf7
Add options to support ssl key verification when connecting with TLS.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
734 |
clientcert => $conf->{'tls_cert'}, |
0f815f3daaf7
Add options to support ssl key verification when connecting with TLS.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
735 |
clientkey => $conf->{'tls_key'}, |
0f815f3daaf7
Add options to support ssl key verification when connecting with TLS.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
736 |
keydecrypt => sub { |
0f815f3daaf7
Add options to support ssl key verification when connecting with TLS.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
737 |
print "Key Passphrase: "; |
0f815f3daaf7
Add options to support ssl key verification when connecting with TLS.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
738 |
Term::ReadKey::ReadMode 2; |
50 | 739 |
chomp( my $secret = <STDIN> ); |
3
0f815f3daaf7
Add options to support ssl key verification when connecting with TLS.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
740 |
Term::ReadKey::ReadMode 0; |
0f815f3daaf7
Add options to support ssl key verification when connecting with TLS.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
741 |
print "\n"; |
0f815f3daaf7
Add options to support ssl key verification when connecting with TLS.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
742 |
return $secret; |
0f815f3daaf7
Add options to support ssl key verification when connecting with TLS.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
743 |
}); |
0f815f3daaf7
Add options to support ssl key verification when connecting with TLS.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
744 |
} |
0f815f3daaf7
Add options to support ssl key verification when connecting with TLS.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
745 |
else { |
0f815f3daaf7
Add options to support ssl key verification when connecting with TLS.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
746 |
$ldap->start_tls( verify => 'none' ); |
0f815f3daaf7
Add options to support ssl key verification when connecting with TLS.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
747 |
} |
0f815f3daaf7
Add options to support ssl key verification when connecting with TLS.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
748 |
} |
0 | 749 |
|
87
475aff91675b
eval optional modules in blocks instead of strings.
Mahlon E. Smith <mahlon@martini.nu>
parents:
84
diff
changeset
|
750 |
undef $@; eval { require Authen::SASL; }; |
62
ed8253b3105a
Add quick documentation blurb for SASL mechanisms. Make SASL
Mahlon E. Smith <mahlon@laika.com>
parents:
61
diff
changeset
|
751 |
my ( $sasl, $sasl_conn ); |
84
ef002a0b0867
Fix anonymous binds when SASL is not used.
Mahlon E. Smith <mahlon@martini.nu>
parents:
82
diff
changeset
|
752 |
my $has_sasl = ! $@; |
ef002a0b0867
Fix anonymous binds when SASL is not used.
Mahlon E. Smith <mahlon@martini.nu>
parents:
82
diff
changeset
|
753 |
my $use_sasl = $has_sasl && $conf->{'sasl'}; |
ef002a0b0867
Fix anonymous binds when SASL is not used.
Mahlon E. Smith <mahlon@martini.nu>
parents:
82
diff
changeset
|
754 |
|
ef002a0b0867
Fix anonymous binds when SASL is not used.
Mahlon E. Smith <mahlon@martini.nu>
parents:
82
diff
changeset
|
755 |
die "SASL requested, but library is not installed. Please install Authen::SASL and try again.\n" if $conf->{'sasl'} && ! $has_sasl; |
ef002a0b0867
Fix anonymous binds when SASL is not used.
Mahlon E. Smith <mahlon@martini.nu>
parents:
82
diff
changeset
|
756 |
|
ef002a0b0867
Fix anonymous binds when SASL is not used.
Mahlon E. Smith <mahlon@martini.nu>
parents:
82
diff
changeset
|
757 |
if ( $use_sasl ) { |
61
e3bd30b95695
Add simple SASL support. Patch from Michael Raitza <spacefrogg-devel@meterriblecrew.net>.
Mahlon E. Smith <mahlon@laika.com>
parents:
60
diff
changeset
|
758 |
my $serv = $conf->{'server'}; |
e3bd30b95695
Add simple SASL support. Patch from Michael Raitza <spacefrogg-devel@meterriblecrew.net>.
Mahlon E. Smith <mahlon@laika.com>
parents:
60
diff
changeset
|
759 |
$serv =~ s!^ldap[si]?://!!; |
62
ed8253b3105a
Add quick documentation blurb for SASL mechanisms. Make SASL
Mahlon E. Smith <mahlon@laika.com>
parents:
61
diff
changeset
|
760 |
$sasl = Authen::SASL->new( mechanism => $conf->{'sasl'} ); |
84
ef002a0b0867
Fix anonymous binds when SASL is not used.
Mahlon E. Smith <mahlon@martini.nu>
parents:
82
diff
changeset
|
761 |
$sasl_conn = $sasl->client_new( 'ldap', $serv ); |
61
e3bd30b95695
Add simple SASL support. Patch from Michael Raitza <spacefrogg-devel@meterriblecrew.net>.
Mahlon E. Smith <mahlon@laika.com>
parents:
60
diff
changeset
|
762 |
} |
84
ef002a0b0867
Fix anonymous binds when SASL is not used.
Mahlon E. Smith <mahlon@martini.nu>
parents:
82
diff
changeset
|
763 |
|
62
ed8253b3105a
Add quick documentation blurb for SASL mechanisms. Make SASL
Mahlon E. Smith <mahlon@laika.com>
parents:
61
diff
changeset
|
764 |
# bind with sasl |
ed8253b3105a
Add quick documentation blurb for SASL mechanisms. Make SASL
Mahlon E. Smith <mahlon@laika.com>
parents:
61
diff
changeset
|
765 |
# |
84
ef002a0b0867
Fix anonymous binds when SASL is not used.
Mahlon E. Smith <mahlon@martini.nu>
parents:
82
diff
changeset
|
766 |
if ( $sasl_conn ) { |
ef002a0b0867
Fix anonymous binds when SASL is not used.
Mahlon E. Smith <mahlon@martini.nu>
parents:
82
diff
changeset
|
767 |
$rv = $ldap->bind( $conf->{'binddn'}, |
61
e3bd30b95695
Add simple SASL support. Patch from Michael Raitza <spacefrogg-devel@meterriblecrew.net>.
Mahlon E. Smith <mahlon@laika.com>
parents:
60
diff
changeset
|
768 |
password => $conf->{'bindpass'}, |
84
ef002a0b0867
Fix anonymous binds when SASL is not used.
Mahlon E. Smith <mahlon@martini.nu>
parents:
82
diff
changeset
|
769 |
sasl => $sasl_conn |
62
ed8253b3105a
Add quick documentation blurb for SASL mechanisms. Make SASL
Mahlon E. Smith <mahlon@laika.com>
parents:
61
diff
changeset
|
770 |
); |
ed8253b3105a
Add quick documentation blurb for SASL mechanisms. Make SASL
Mahlon E. Smith <mahlon@laika.com>
parents:
61
diff
changeset
|
771 |
} |
ed8253b3105a
Add quick documentation blurb for SASL mechanisms. Make SASL
Mahlon E. Smith <mahlon@laika.com>
parents:
61
diff
changeset
|
772 |
|
ed8253b3105a
Add quick documentation blurb for SASL mechanisms. Make SASL
Mahlon E. Smith <mahlon@laika.com>
parents:
61
diff
changeset
|
773 |
# simple bind as an authenticated dn |
ed8253b3105a
Add quick documentation blurb for SASL mechanisms. Make SASL
Mahlon E. Smith <mahlon@laika.com>
parents:
61
diff
changeset
|
774 |
# |
ed8253b3105a
Add quick documentation blurb for SASL mechanisms. Make SASL
Mahlon E. Smith <mahlon@laika.com>
parents:
61
diff
changeset
|
775 |
elsif ( $conf->{'binddn'} ) { |
84
ef002a0b0867
Fix anonymous binds when SASL is not used.
Mahlon E. Smith <mahlon@martini.nu>
parents:
82
diff
changeset
|
776 |
$rv = $ldap->bind( $conf->{'binddn'}, |
62
ed8253b3105a
Add quick documentation blurb for SASL mechanisms. Make SASL
Mahlon E. Smith <mahlon@laika.com>
parents:
61
diff
changeset
|
777 |
password => $conf->{'bindpass'} |
ed8253b3105a
Add quick documentation blurb for SASL mechanisms. Make SASL
Mahlon E. Smith <mahlon@laika.com>
parents:
61
diff
changeset
|
778 |
); |
ed8253b3105a
Add quick documentation blurb for SASL mechanisms. Make SASL
Mahlon E. Smith <mahlon@laika.com>
parents:
61
diff
changeset
|
779 |
} |
ed8253b3105a
Add quick documentation blurb for SASL mechanisms. Make SASL
Mahlon E. Smith <mahlon@laika.com>
parents:
61
diff
changeset
|
780 |
|
50 | 781 |
# bind anonymously |
62
ed8253b3105a
Add quick documentation blurb for SASL mechanisms. Make SASL
Mahlon E. Smith <mahlon@laika.com>
parents:
61
diff
changeset
|
782 |
# |
ed8253b3105a
Add quick documentation blurb for SASL mechanisms. Make SASL
Mahlon E. Smith <mahlon@laika.com>
parents:
61
diff
changeset
|
783 |
else { |
84
ef002a0b0867
Fix anonymous binds when SASL is not used.
Mahlon E. Smith <mahlon@martini.nu>
parents:
82
diff
changeset
|
784 |
$rv = $sasl_conn ? $ldap->bind( sasl => $sasl_conn ) : $ldap->bind(); |
0 | 785 |
} |
786 |
||
787 |
my $err = $rv->error(); |
|
57
85cc85d0c1b1
Catch a case where the LDAP object is defined, but in a state that
Mahlon E. Smith <mahlon@laika.com>
parents:
56
diff
changeset
|
788 |
$self->debug( |
85cc85d0c1b1
Catch a case where the LDAP object is defined, but in a state that
Mahlon E. Smith <mahlon@laika.com>
parents:
56
diff
changeset
|
789 |
"Bind as " . |
84
ef002a0b0867
Fix anonymous binds when SASL is not used.
Mahlon E. Smith <mahlon@martini.nu>
parents:
82
diff
changeset
|
790 |
( $conf->{'binddn'} ? $conf->{'binddn'} : 'anonymous' ) . |
ef002a0b0867
Fix anonymous binds when SASL is not used.
Mahlon E. Smith <mahlon@martini.nu>
parents:
82
diff
changeset
|
791 |
" to " . $conf->{'server'} . ": $err\n" |
57
85cc85d0c1b1
Catch a case where the LDAP object is defined, but in a state that
Mahlon E. Smith <mahlon@laika.com>
parents:
56
diff
changeset
|
792 |
); |
85cc85d0c1b1
Catch a case where the LDAP object is defined, but in a state that
Mahlon E. Smith <mahlon@laika.com>
parents:
56
diff
changeset
|
793 |
|
0 | 794 |
if ( $rv->code() ) { |
50 | 795 |
$err .= " (try the --tls flag?)" if $err =~ /confidentiality required/i; |
84
ef002a0b0867
Fix anonymous binds when SASL is not used.
Mahlon E. Smith <mahlon@martini.nu>
parents:
82
diff
changeset
|
796 |
$err .= "\n" . $sasl->error if $sasl_conn && defined( $sasl->error ); |
0 | 797 |
die "LDAP bind error: $err\n"; |
798 |
} |
|
799 |
||
57
85cc85d0c1b1
Catch a case where the LDAP object is defined, but in a state that
Mahlon E. Smith <mahlon@laika.com>
parents:
56
diff
changeset
|
800 |
# Offer to cache authentication info. |
85cc85d0c1b1
Catch a case where the LDAP object is defined, but in a state that
Mahlon E. Smith <mahlon@laika.com>
parents:
56
diff
changeset
|
801 |
# If we enter this conditional, we have successfully authed with the server |
85cc85d0c1b1
Catch a case where the LDAP object is defined, but in a state that
Mahlon E. Smith <mahlon@laika.com>
parents:
56
diff
changeset
|
802 |
# (non anonymous), and we haven't cached anything in the past. |
15
f6157d378459
Exit with a nicer error message if IO::Socket::SSL isn't installed,
Mahlon E. Smith <mahlon@martini.nu>
parents:
14
diff
changeset
|
803 |
# |
50 | 804 |
if ( $conf->{'binddn'} && ! -e $conf->{'configfile'} ) { |
805 |
print "Would you like to cache your connection information? [Yn]: "; |
|
0 | 806 |
chomp( my $response = <STDIN> ); |
807 |
unless ( $response =~ /^n/i ) { |
|
102
e92cb378144d
Fix precedence of command line arguments
Davor Ocelic <docelic@crystallabs.io>
parents:
101
diff
changeset
|
808 |
main::save_config($conf->{configfile}); |
50 | 809 |
print "Connection info cached to $conf->{'configfile'}.\n"; |
0 | 810 |
} |
811 |
} |
|
812 |
||
813 |
$self->{'ldap'} = $ldap; |
|
814 |
return $ldap; |
|
815 |
} |
|
816 |
||
50 | 817 |
|
818 |
### Return a new LDIF object, suitable for populating with |
|
819 |
### a Net::LDAP::Entry. |
|
820 |
### |
|
0 | 821 |
sub ldif |
822 |
{ |
|
823 |
my $self = shift; |
|
824 |
my $use_temp = shift; |
|
825 |
||
99
2a7a3072d76c
Add LICENSE file for packaging, bump copyright.
Mahlon E. Smith <mahlon@martini.nu>
parents:
95
diff
changeset
|
826 |
my $raw = qr/(^jpegPhoto|;binary)/; |
2a7a3072d76c
Add LICENSE file for packaging, bump copyright.
Mahlon E. Smith <mahlon@martini.nu>
parents:
95
diff
changeset
|
827 |
|
0 | 828 |
# create tmpfile and link ldif object with it |
49
57df728cdb77
Alter the default wrap width for LDIF to expand to the terminal size,
Mahlon E. Smith <mahlon@laika.com>
parents:
48
diff
changeset
|
829 |
# |
0 | 830 |
if ( $use_temp ) { |
831 |
my ( undef, $fname ) = |
|
76
589332cac30b
Use the system tempdir instead of hardcoding /tmp.
Mahlon E. Smith <mahlon@laika.com>
parents:
73
diff
changeset
|
832 |
File::Temp::tempfile( 'shelldap_XXXXXXXX', SUFFIX => '.ldif', TMPDIR => 1, UNLINK => 1 ); |
99
2a7a3072d76c
Add LICENSE file for packaging, bump copyright.
Mahlon E. Smith <mahlon@martini.nu>
parents:
95
diff
changeset
|
833 |
$self->{'ldif'} = Net::LDAP::LDIF->new( $fname, 'w', sort => 1, wrap => 0, raw => $raw ); |
0 | 834 |
$self->{'ldif_fname'} = $fname; |
835 |
} |
|
836 |
||
837 |
# ldif -> stdout |
|
73
b3b840a4b56c
Minor style cleanups, version bump.
Mahlon E. Smith <mahlon@laika.com>
parents:
72
diff
changeset
|
838 |
# |
0 | 839 |
else { |
99
2a7a3072d76c
Add LICENSE file for packaging, bump copyright.
Mahlon E. Smith <mahlon@martini.nu>
parents:
95
diff
changeset
|
840 |
$self->{'ldif'} = Net::LDAP::LDIF->new( \*STDOUT, 'w', sort => 1, wrap => $self->wrapsize, raw => $raw ); |
0 | 841 |
} |
842 |
||
843 |
return $self->{'ldif'}; |
|
844 |
} |
|
845 |
||
50 | 846 |
|
847 |
### Return an Entry object from an LDIF filename, or undef if there was an error. |
|
848 |
### |
|
0 | 849 |
sub load_ldif |
850 |
{ |
|
851 |
my $self = shift; |
|
50 | 852 |
my $ldif = Net::LDAP::LDIF->new( shift(), 'r' ); |
0 | 853 |
|
854 |
return unless $ldif; |
|
855 |
||
856 |
my $e; |
|
857 |
eval { $e = $ldif->read_entry(); }; |
|
858 |
||
859 |
return if $@; |
|
860 |
return $e; |
|
861 |
} |
|
862 |
||
50 | 863 |
|
864 |
### Given a filename, return an md5 checksum. |
|
865 |
### |
|
0 | 866 |
sub chksum |
867 |
{ |
|
868 |
my $self = shift; |
|
869 |
my $file = shift or return; |
|
870 |
||
871 |
my $md5 = Digest::MD5->new(); |
|
118
2d7f16eff198
Use local implementation of slurp()
Davor Ocelic <docelic@crystallabs.io>
parents:
117
diff
changeset
|
872 |
open F, $file; |
0 | 873 |
my $hash = $md5->addfile( *F )->hexdigest(); |
874 |
close F; |
|
875 |
||
876 |
return $hash; |
|
877 |
} |
|
878 |
||
50 | 879 |
|
51
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
880 |
### Find and return the current terminal width. |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
881 |
### |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
882 |
sub wrapsize |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
883 |
{ |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
884 |
my $self = shift; |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
885 |
|
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
886 |
my $wrap = $conf->{'wrap'}; |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
887 |
eval { |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
888 |
my $rows; |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
889 |
my $term = Term::ReadLine->new( 1 ); |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
890 |
( $rows, $wrap ) = $term->get_screen_size() unless $wrap; |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
891 |
}; |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
892 |
|
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
893 |
$wrap ||= 78; |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
894 |
return $wrap; |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
895 |
} |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
896 |
|
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
897 |
|
50 | 898 |
### Used by Term::Shell to generate the prompt. |
899 |
### |
|
0 | 900 |
sub prompt_str |
901 |
{ |
|
902 |
my $self = shift; |
|
903 |
return $self->{'prompt'}; |
|
904 |
} |
|
50 | 905 |
|
906 |
||
907 |
### Display the current working entry as the prompt, |
|
908 |
### truncating if necessary. |
|
909 |
### |
|
0 | 910 |
sub update_prompt |
911 |
{ |
|
912 |
my $self = shift; |
|
913 |
my $base = $self->base(); |
|
914 |
||
915 |
if ( length $base > 50 ) { |
|
916 |
my $cwd_dn = $1 if $base =~ /^(.*?),/; |
|
917 |
$self->{'prompt'} = "... $cwd_dn > "; |
|
918 |
} |
|
919 |
else { |
|
920 |
my $prompt = $base; |
|
921 |
$prompt =~ s/$conf->{'basedn'}/~/; |
|
922 |
$self->{'prompt'} = "$prompt > "; |
|
923 |
} |
|
924 |
return; |
|
925 |
} |
|
926 |
||
50 | 927 |
|
928 |
### Prompt the user to re-edit their LDIF on error. |
|
929 |
### Returns true if the user wants to do so. |
|
930 |
### |
|
931 |
sub prompt_edit_again |
|
932 |
{ |
|
933 |
my $self = shift; |
|
934 |
print "Edit again? [Yn]: "; |
|
935 |
chomp( my $ans = <STDIN> ); |
|
936 |
return $ans !~ /^n/i; |
|
937 |
} |
|
938 |
||
939 |
||
940 |
### Return the basedn of the LDAP connection, being either explicitly |
|
941 |
### configured or determined automatically from server metadata. |
|
942 |
### |
|
0 | 943 |
sub base |
944 |
{ |
|
945 |
my $self = shift; |
|
946 |
$self->{'base'} ||= $conf->{'basedn'}; |
|
947 |
||
948 |
# try and determine base automatically from rootDSE |
|
949 |
# |
|
950 |
unless ( $self->{'base'} ) { |
|
20
d956658803b8
use sane way to get a default basedn: RootDSe's namingContexts
Peter Marschall <peter@adpm.de>
parents:
19
diff
changeset
|
951 |
my @namingContexts = $self->{'root_dse'}->get_value('namingContexts'); |
d956658803b8
use sane way to get a default basedn: RootDSe's namingContexts
Peter Marschall <peter@adpm.de>
parents:
19
diff
changeset
|
952 |
$conf->{'basedn'} = $namingContexts[0]; |
d956658803b8
use sane way to get a default basedn: RootDSe's namingContexts
Peter Marschall <peter@adpm.de>
parents:
19
diff
changeset
|
953 |
$self->{'base'} = $namingContexts[0]; |
0 | 954 |
} |
23 | 955 |
if ( $_[0] ) { |
956 |
my $base = canonical_dn( $_[0], casefold => 'none' ); |
|
957 |
$self->{'base'} = $base if $base; |
|
0 | 958 |
} |
959 |
return $self->{'base'}; |
|
960 |
} |
|
961 |
||
50 | 962 |
|
963 |
### Returns true if the specified dn is valid on this LDAP server. |
|
964 |
### |
|
0 | 965 |
sub is_valid_dn |
966 |
{ |
|
967 |
my $self = shift; |
|
968 |
my $dn = shift or return 0; |
|
969 |
||
970 |
my $r = $self->search({ base => $dn }); |
|
16
a2e3faa3d2fc
use symbolic LDAP error codes instead of numbers
Peter Marschall <peter@adpm.de>
parents:
15
diff
changeset
|
971 |
return $r->{'code'} == LDAP_SUCCESS ? 1 : 0; |
0 | 972 |
} |
973 |
||
50 | 974 |
|
73
b3b840a4b56c
Minor style cleanups, version bump.
Mahlon E. Smith <mahlon@laika.com>
parents:
72
diff
changeset
|
975 |
### Emit LDIF to the terminal. |
b3b840a4b56c
Minor style cleanups, version bump.
Mahlon E. Smith <mahlon@laika.com>
parents:
72
diff
changeset
|
976 |
### |
b3b840a4b56c
Minor style cleanups, version bump.
Mahlon E. Smith <mahlon@laika.com>
parents:
72
diff
changeset
|
977 |
sub display |
b3b840a4b56c
Minor style cleanups, version bump.
Mahlon E. Smith <mahlon@laika.com>
parents:
72
diff
changeset
|
978 |
{ |
b3b840a4b56c
Minor style cleanups, version bump.
Mahlon E. Smith <mahlon@laika.com>
parents:
72
diff
changeset
|
979 |
my $self = shift; |
b3b840a4b56c
Minor style cleanups, version bump.
Mahlon E. Smith <mahlon@laika.com>
parents:
72
diff
changeset
|
980 |
my $dn = shift; |
b3b840a4b56c
Minor style cleanups, version bump.
Mahlon E. Smith <mahlon@laika.com>
parents:
72
diff
changeset
|
981 |
my @attrs = @{;shift}; |
b3b840a4b56c
Minor style cleanups, version bump.
Mahlon E. Smith <mahlon@laika.com>
parents:
72
diff
changeset
|
982 |
my $use_pager = shift; |
b3b840a4b56c
Minor style cleanups, version bump.
Mahlon E. Smith <mahlon@laika.com>
parents:
72
diff
changeset
|
983 |
|
b3b840a4b56c
Minor style cleanups, version bump.
Mahlon E. Smith <mahlon@laika.com>
parents:
72
diff
changeset
|
984 |
unless ( $dn ) { |
106
94d941f13a5a
Make 'cat' default to '.' (cwd) instead of requiring argument
Davor Ocelic <docelic@crystallabs.io>
parents:
105
diff
changeset
|
985 |
$dn = '.' |
73
b3b840a4b56c
Minor style cleanups, version bump.
Mahlon E. Smith <mahlon@laika.com>
parents:
72
diff
changeset
|
986 |
} |
b3b840a4b56c
Minor style cleanups, version bump.
Mahlon E. Smith <mahlon@laika.com>
parents:
72
diff
changeset
|
987 |
|
b3b840a4b56c
Minor style cleanups, version bump.
Mahlon E. Smith <mahlon@laika.com>
parents:
72
diff
changeset
|
988 |
# support '.' |
b3b840a4b56c
Minor style cleanups, version bump.
Mahlon E. Smith <mahlon@laika.com>
parents:
72
diff
changeset
|
989 |
$dn = $self->base() if $dn eq '.'; |
b3b840a4b56c
Minor style cleanups, version bump.
Mahlon E. Smith <mahlon@laika.com>
parents:
72
diff
changeset
|
990 |
|
b3b840a4b56c
Minor style cleanups, version bump.
Mahlon E. Smith <mahlon@laika.com>
parents:
72
diff
changeset
|
991 |
# support globbing |
b3b840a4b56c
Minor style cleanups, version bump.
Mahlon E. Smith <mahlon@laika.com>
parents:
72
diff
changeset
|
992 |
# |
b3b840a4b56c
Minor style cleanups, version bump.
Mahlon E. Smith <mahlon@laika.com>
parents:
72
diff
changeset
|
993 |
my $s; |
b3b840a4b56c
Minor style cleanups, version bump.
Mahlon E. Smith <mahlon@laika.com>
parents:
72
diff
changeset
|
994 |
if ( $dn eq '*' ) { |
b3b840a4b56c
Minor style cleanups, version bump.
Mahlon E. Smith <mahlon@laika.com>
parents:
72
diff
changeset
|
995 |
$s = $self->search({ |
b3b840a4b56c
Minor style cleanups, version bump.
Mahlon E. Smith <mahlon@laika.com>
parents:
72
diff
changeset
|
996 |
scope => 'one', |
b3b840a4b56c
Minor style cleanups, version bump.
Mahlon E. Smith <mahlon@laika.com>
parents:
72
diff
changeset
|
997 |
vals => 1, |
b3b840a4b56c
Minor style cleanups, version bump.
Mahlon E. Smith <mahlon@laika.com>
parents:
72
diff
changeset
|
998 |
attrs => \@attrs |
b3b840a4b56c
Minor style cleanups, version bump.
Mahlon E. Smith <mahlon@laika.com>
parents:
72
diff
changeset
|
999 |
}); |
b3b840a4b56c
Minor style cleanups, version bump.
Mahlon E. Smith <mahlon@laika.com>
parents:
72
diff
changeset
|
1000 |
} |
b3b840a4b56c
Minor style cleanups, version bump.
Mahlon E. Smith <mahlon@laika.com>
parents:
72
diff
changeset
|
1001 |
elsif ( $dn =~ /\*/ ) { |
b3b840a4b56c
Minor style cleanups, version bump.
Mahlon E. Smith <mahlon@laika.com>
parents:
72
diff
changeset
|
1002 |
$s = $self->search({ |
b3b840a4b56c
Minor style cleanups, version bump.
Mahlon E. Smith <mahlon@laika.com>
parents:
72
diff
changeset
|
1003 |
scope => 'one', |
b3b840a4b56c
Minor style cleanups, version bump.
Mahlon E. Smith <mahlon@laika.com>
parents:
72
diff
changeset
|
1004 |
vals => 1, |
b3b840a4b56c
Minor style cleanups, version bump.
Mahlon E. Smith <mahlon@laika.com>
parents:
72
diff
changeset
|
1005 |
filter => $dn, |
b3b840a4b56c
Minor style cleanups, version bump.
Mahlon E. Smith <mahlon@laika.com>
parents:
72
diff
changeset
|
1006 |
attrs => \@attrs |
b3b840a4b56c
Minor style cleanups, version bump.
Mahlon E. Smith <mahlon@laika.com>
parents:
72
diff
changeset
|
1007 |
}); |
b3b840a4b56c
Minor style cleanups, version bump.
Mahlon E. Smith <mahlon@laika.com>
parents:
72
diff
changeset
|
1008 |
} |
b3b840a4b56c
Minor style cleanups, version bump.
Mahlon E. Smith <mahlon@laika.com>
parents:
72
diff
changeset
|
1009 |
|
b3b840a4b56c
Minor style cleanups, version bump.
Mahlon E. Smith <mahlon@laika.com>
parents:
72
diff
changeset
|
1010 |
# absolute/relative dn |
b3b840a4b56c
Minor style cleanups, version bump.
Mahlon E. Smith <mahlon@laika.com>
parents:
72
diff
changeset
|
1011 |
# |
b3b840a4b56c
Minor style cleanups, version bump.
Mahlon E. Smith <mahlon@laika.com>
parents:
72
diff
changeset
|
1012 |
else { |
b3b840a4b56c
Minor style cleanups, version bump.
Mahlon E. Smith <mahlon@laika.com>
parents:
72
diff
changeset
|
1013 |
$dn = $self->path_to_dn( $dn ); |
b3b840a4b56c
Minor style cleanups, version bump.
Mahlon E. Smith <mahlon@laika.com>
parents:
72
diff
changeset
|
1014 |
$s = $self->search({ |
b3b840a4b56c
Minor style cleanups, version bump.
Mahlon E. Smith <mahlon@laika.com>
parents:
72
diff
changeset
|
1015 |
base => $dn, |
b3b840a4b56c
Minor style cleanups, version bump.
Mahlon E. Smith <mahlon@laika.com>
parents:
72
diff
changeset
|
1016 |
vals => 1, |
b3b840a4b56c
Minor style cleanups, version bump.
Mahlon E. Smith <mahlon@laika.com>
parents:
72
diff
changeset
|
1017 |
attrs => \@attrs |
b3b840a4b56c
Minor style cleanups, version bump.
Mahlon E. Smith <mahlon@laika.com>
parents:
72
diff
changeset
|
1018 |
}); |
b3b840a4b56c
Minor style cleanups, version bump.
Mahlon E. Smith <mahlon@laika.com>
parents:
72
diff
changeset
|
1019 |
} |
b3b840a4b56c
Minor style cleanups, version bump.
Mahlon E. Smith <mahlon@laika.com>
parents:
72
diff
changeset
|
1020 |
|
b3b840a4b56c
Minor style cleanups, version bump.
Mahlon E. Smith <mahlon@laika.com>
parents:
72
diff
changeset
|
1021 |
# emit error, if any |
b3b840a4b56c
Minor style cleanups, version bump.
Mahlon E. Smith <mahlon@laika.com>
parents:
72
diff
changeset
|
1022 |
# |
b3b840a4b56c
Minor style cleanups, version bump.
Mahlon E. Smith <mahlon@laika.com>
parents:
72
diff
changeset
|
1023 |
if ( $s->{'code'} ) { |
b3b840a4b56c
Minor style cleanups, version bump.
Mahlon E. Smith <mahlon@laika.com>
parents:
72
diff
changeset
|
1024 |
print $s->{'message'} . "\n"; |
b3b840a4b56c
Minor style cleanups, version bump.
Mahlon E. Smith <mahlon@laika.com>
parents:
72
diff
changeset
|
1025 |
return; |
b3b840a4b56c
Minor style cleanups, version bump.
Mahlon E. Smith <mahlon@laika.com>
parents:
72
diff
changeset
|
1026 |
} |
b3b840a4b56c
Minor style cleanups, version bump.
Mahlon E. Smith <mahlon@laika.com>
parents:
72
diff
changeset
|
1027 |
|
b3b840a4b56c
Minor style cleanups, version bump.
Mahlon E. Smith <mahlon@laika.com>
parents:
72
diff
changeset
|
1028 |
# display to stdout or pager |
b3b840a4b56c
Minor style cleanups, version bump.
Mahlon E. Smith <mahlon@laika.com>
parents:
72
diff
changeset
|
1029 |
# |
b3b840a4b56c
Minor style cleanups, version bump.
Mahlon E. Smith <mahlon@laika.com>
parents:
72
diff
changeset
|
1030 |
my $ldif = $self->ldif( $use_pager ); |
b3b840a4b56c
Minor style cleanups, version bump.
Mahlon E. Smith <mahlon@laika.com>
parents:
72
diff
changeset
|
1031 |
foreach my $e ( @{ $s->{'entries'} } ) { |
b3b840a4b56c
Minor style cleanups, version bump.
Mahlon E. Smith <mahlon@laika.com>
parents:
72
diff
changeset
|
1032 |
$ldif->write_entry( $e ); |
b3b840a4b56c
Minor style cleanups, version bump.
Mahlon E. Smith <mahlon@laika.com>
parents:
72
diff
changeset
|
1033 |
} |
82
57a1335691e5
Allow the period character when moving an entry by full DN.
Mahlon E. Smith <mahlon@martini.nu>
parents:
81
diff
changeset
|
1034 |
if ( $use_pager ) { |
73
b3b840a4b56c
Minor style cleanups, version bump.
Mahlon E. Smith <mahlon@laika.com>
parents:
72
diff
changeset
|
1035 |
system( $self->{'pager'}, $self->{'ldif_fname'} ); |
b3b840a4b56c
Minor style cleanups, version bump.
Mahlon E. Smith <mahlon@laika.com>
parents:
72
diff
changeset
|
1036 |
unlink $self->{'ldif_fname'}; |
b3b840a4b56c
Minor style cleanups, version bump.
Mahlon E. Smith <mahlon@laika.com>
parents:
72
diff
changeset
|
1037 |
} |
b3b840a4b56c
Minor style cleanups, version bump.
Mahlon E. Smith <mahlon@laika.com>
parents:
72
diff
changeset
|
1038 |
return; |
b3b840a4b56c
Minor style cleanups, version bump.
Mahlon E. Smith <mahlon@laika.com>
parents:
72
diff
changeset
|
1039 |
} |
b3b840a4b56c
Minor style cleanups, version bump.
Mahlon E. Smith <mahlon@laika.com>
parents:
72
diff
changeset
|
1040 |
|
b3b840a4b56c
Minor style cleanups, version bump.
Mahlon E. Smith <mahlon@laika.com>
parents:
72
diff
changeset
|
1041 |
|
92
a1aa55019077
Optionally use the server side pager control for search results.
Mahlon E. Smith <mahlon@martini.nu>
parents:
91
diff
changeset
|
1042 |
### Perform an LDAP search, optionally with the server side pager |
a1aa55019077
Optionally use the server side pager control for search results.
Mahlon E. Smith <mahlon@martini.nu>
parents:
91
diff
changeset
|
1043 |
### control. |
50 | 1044 |
### |
1045 |
### Returns a hashref containing the return code and |
|
1046 |
### an arrayref of Net::LDAP::Entry objects. |
|
1047 |
### |
|
0 | 1048 |
sub search |
1049 |
{ |
|
1050 |
my $self = shift; |
|
1051 |
my $opts = shift || {}; |
|
92
a1aa55019077
Optionally use the server side pager control for search results.
Mahlon E. Smith <mahlon@martini.nu>
parents:
91
diff
changeset
|
1052 |
my $controls = []; |
0 | 1053 |
|
1054 |
$opts->{'base'} ||= $self->base(), |
|
1055 |
$opts->{'filter'} ||= '(objectClass=*)'; |
|
1056 |
$opts->{'scope'} ||= 'base'; |
|
1057 |
||
92
a1aa55019077
Optionally use the server side pager control for search results.
Mahlon E. Smith <mahlon@martini.nu>
parents:
91
diff
changeset
|
1058 |
my $pager; |
a1aa55019077
Optionally use the server side pager control for search results.
Mahlon E. Smith <mahlon@martini.nu>
parents:
91
diff
changeset
|
1059 |
if ( $conf->{'paginate'} ) { |
a1aa55019077
Optionally use the server side pager control for search results.
Mahlon E. Smith <mahlon@martini.nu>
parents:
91
diff
changeset
|
1060 |
$pager = Net::LDAP::Control::Paged->new( size => $conf->{'paginate'} ); |
a1aa55019077
Optionally use the server side pager control for search results.
Mahlon E. Smith <mahlon@martini.nu>
parents:
91
diff
changeset
|
1061 |
push( @$controls, $pager ); |
a1aa55019077
Optionally use the server side pager control for search results.
Mahlon E. Smith <mahlon@martini.nu>
parents:
91
diff
changeset
|
1062 |
} |
a1aa55019077
Optionally use the server side pager control for search results.
Mahlon E. Smith <mahlon@martini.nu>
parents:
91
diff
changeset
|
1063 |
|
48
fe27dfe5179e
More robust path for connection retries. Show optional, unused
Mahlon E. Smith <mahlon@laika.com>
parents:
46
diff
changeset
|
1064 |
my $search = sub { |
fe27dfe5179e
More robust path for connection retries. Show optional, unused
Mahlon E. Smith <mahlon@laika.com>
parents:
46
diff
changeset
|
1065 |
return $self->ldap->search( |
43
b8836c9018fb
Attempt to retry the operation on failure.
Mahlon E. Smith <mahlon@laika.com>
parents:
42
diff
changeset
|
1066 |
base => $opts->{'base'}, |
b8836c9018fb
Attempt to retry the operation on failure.
Mahlon E. Smith <mahlon@laika.com>
parents:
42
diff
changeset
|
1067 |
filter => $opts->{'filter'}, |
b8836c9018fb
Attempt to retry the operation on failure.
Mahlon E. Smith <mahlon@laika.com>
parents:
42
diff
changeset
|
1068 |
scope => $opts->{'scope'}, |
b8836c9018fb
Attempt to retry the operation on failure.
Mahlon E. Smith <mahlon@laika.com>
parents:
42
diff
changeset
|
1069 |
timelimit => $conf->{'timeout'}, |
b8836c9018fb
Attempt to retry the operation on failure.
Mahlon E. Smith <mahlon@laika.com>
parents:
42
diff
changeset
|
1070 |
typesonly => ! $opts->{'vals'}, |
92
a1aa55019077
Optionally use the server side pager control for search results.
Mahlon E. Smith <mahlon@martini.nu>
parents:
91
diff
changeset
|
1071 |
attrs => $opts->{'attrs'} || ['*'], |
a1aa55019077
Optionally use the server side pager control for search results.
Mahlon E. Smith <mahlon@martini.nu>
parents:
91
diff
changeset
|
1072 |
control => $controls |
43
b8836c9018fb
Attempt to retry the operation on failure.
Mahlon E. Smith <mahlon@laika.com>
parents:
42
diff
changeset
|
1073 |
); |
48
fe27dfe5179e
More robust path for connection retries. Show optional, unused
Mahlon E. Smith <mahlon@laika.com>
parents:
46
diff
changeset
|
1074 |
}; |
43
b8836c9018fb
Attempt to retry the operation on failure.
Mahlon E. Smith <mahlon@laika.com>
parents:
42
diff
changeset
|
1075 |
|
92
a1aa55019077
Optionally use the server side pager control for search results.
Mahlon E. Smith <mahlon@martini.nu>
parents:
91
diff
changeset
|
1076 |
my $s; |
a1aa55019077
Optionally use the server side pager control for search results.
Mahlon E. Smith <mahlon@martini.nu>
parents:
91
diff
changeset
|
1077 |
my $entries = []; |
a1aa55019077
Optionally use the server side pager control for search results.
Mahlon E. Smith <mahlon@martini.nu>
parents:
91
diff
changeset
|
1078 |
my $token = '-'; |
a1aa55019077
Optionally use the server side pager control for search results.
Mahlon E. Smith <mahlon@martini.nu>
parents:
91
diff
changeset
|
1079 |
|
a1aa55019077
Optionally use the server side pager control for search results.
Mahlon E. Smith <mahlon@martini.nu>
parents:
91
diff
changeset
|
1080 |
if ( $conf->{'paginate'} ) { |
a1aa55019077
Optionally use the server side pager control for search results.
Mahlon E. Smith <mahlon@martini.nu>
parents:
91
diff
changeset
|
1081 |
while( $token ) { |
a1aa55019077
Optionally use the server side pager control for search results.
Mahlon E. Smith <mahlon@martini.nu>
parents:
91
diff
changeset
|
1082 |
$s = $self->with_retry( $search ); |
a1aa55019077
Optionally use the server side pager control for search results.
Mahlon E. Smith <mahlon@martini.nu>
parents:
91
diff
changeset
|
1083 |
push( @$entries, $s->entries() ); |
a1aa55019077
Optionally use the server side pager control for search results.
Mahlon E. Smith <mahlon@martini.nu>
parents:
91
diff
changeset
|
1084 |
|
a1aa55019077
Optionally use the server side pager control for search results.
Mahlon E. Smith <mahlon@martini.nu>
parents:
91
diff
changeset
|
1085 |
my $page_response = $s->control( LDAP_CONTROL_PAGED ) or last; |
a1aa55019077
Optionally use the server side pager control for search results.
Mahlon E. Smith <mahlon@martini.nu>
parents:
91
diff
changeset
|
1086 |
$token = $page_response->cookie; |
a1aa55019077
Optionally use the server side pager control for search results.
Mahlon E. Smith <mahlon@martini.nu>
parents:
91
diff
changeset
|
1087 |
$pager->cookie( $token ); |
a1aa55019077
Optionally use the server side pager control for search results.
Mahlon E. Smith <mahlon@martini.nu>
parents:
91
diff
changeset
|
1088 |
} |
a1aa55019077
Optionally use the server side pager control for search results.
Mahlon E. Smith <mahlon@martini.nu>
parents:
91
diff
changeset
|
1089 |
} |
a1aa55019077
Optionally use the server side pager control for search results.
Mahlon E. Smith <mahlon@martini.nu>
parents:
91
diff
changeset
|
1090 |
else { |
a1aa55019077
Optionally use the server side pager control for search results.
Mahlon E. Smith <mahlon@martini.nu>
parents:
91
diff
changeset
|
1091 |
$s = $self->with_retry( $search ); |
a1aa55019077
Optionally use the server side pager control for search results.
Mahlon E. Smith <mahlon@martini.nu>
parents:
91
diff
changeset
|
1092 |
$entries = [ $s->entries() ]; |
a1aa55019077
Optionally use the server side pager control for search results.
Mahlon E. Smith <mahlon@martini.nu>
parents:
91
diff
changeset
|
1093 |
} |
a1aa55019077
Optionally use the server side pager control for search results.
Mahlon E. Smith <mahlon@martini.nu>
parents:
91
diff
changeset
|
1094 |
|
0 | 1095 |
my $rv = { |
50 | 1096 |
code => $s->code(), |
92
a1aa55019077
Optionally use the server side pager control for search results.
Mahlon E. Smith <mahlon@martini.nu>
parents:
91
diff
changeset
|
1097 |
message => $s->error() |
0 | 1098 |
}; |
1099 |
||
92
a1aa55019077
Optionally use the server side pager control for search results.
Mahlon E. Smith <mahlon@martini.nu>
parents:
91
diff
changeset
|
1100 |
if ( $opts->{'scope'} eq 'base' ) { |
a1aa55019077
Optionally use the server side pager control for search results.
Mahlon E. Smith <mahlon@martini.nu>
parents:
91
diff
changeset
|
1101 |
$rv->{'entries'} = [ $s->shift_entry() ] |
a1aa55019077
Optionally use the server side pager control for search results.
Mahlon E. Smith <mahlon@martini.nu>
parents:
91
diff
changeset
|
1102 |
} |
a1aa55019077
Optionally use the server side pager control for search results.
Mahlon E. Smith <mahlon@martini.nu>
parents:
91
diff
changeset
|
1103 |
else { |
a1aa55019077
Optionally use the server side pager control for search results.
Mahlon E. Smith <mahlon@martini.nu>
parents:
91
diff
changeset
|
1104 |
$rv->{'entries'} = $entries; |
a1aa55019077
Optionally use the server side pager control for search results.
Mahlon E. Smith <mahlon@martini.nu>
parents:
91
diff
changeset
|
1105 |
} |
0 | 1106 |
|
1107 |
return $rv; |
|
1108 |
} |
|
1109 |
||
50 | 1110 |
|
1111 |
### Maintain the cache of possible autocomplete values for |
|
1112 |
### the current DN. |
|
1113 |
### |
|
0 | 1114 |
sub update_entries |
1115 |
{ |
|
1116 |
my $self = shift; |
|
1117 |
my %opts = @_; |
|
1118 |
my $base = lc( $self->base() ); |
|
1119 |
||
50 | 1120 |
my $s = $opts{'search'} || $self->search({ scope => 'one', base => $base }); |
0 | 1121 |
|
1122 |
$self->{'cwd_entries'} = []; |
|
1123 |
return if $s->{'code'}; |
|
1124 |
||
1125 |
# setup cache object |
|
1126 |
$self->{'cache'} ||= {}; |
|
1127 |
$self->{'cache'}->{ $base } ||= {}; |
|
1128 |
$self->{'cache'}->{ $base } = {} if $opts{'clearcache'}; |
|
1129 |
my $cache = $self->{'cache'}->{ $base }; |
|
1130 |
||
1131 |
my $now = time(); |
|
1132 |
if ( ! exists $cache->{'entries'} |
|
1133 |
or $now - $cache->{'timestamp'} > $conf->{'cacheage'} ) |
|
1134 |
{ |
|
1135 |
$self->debug("Caching entries for $base\n"); |
|
1136 |
foreach my $e ( @{ $s->{'entries'} } ) { |
|
1137 |
my $dn = $e->dn(); |
|
1138 |
my $rdn = $dn; |
|
1139 |
$rdn =~ s/,$base//i; # remove base from display |
|
1140 |
push @{ $self->{'cwd_entries'} }, $rdn; |
|
1141 |
} |
|
1142 |
$cache->{'timestamp'} = $now; |
|
1143 |
$cache->{'entries'} = $self->{'cwd_entries'}; |
|
1144 |
} |
|
1145 |
else { |
|
1146 |
$self->debug("Using cached lookups for $base\n"); |
|
1147 |
} |
|
1148 |
||
1149 |
$self->{'cwd_entries'} = $cache->{'entries'}; |
|
1150 |
return; |
|
1151 |
} |
|
1152 |
||
50 | 1153 |
|
1154 |
### Roughly convert a given path to a DN. |
|
1155 |
### |
|
1156 |
### Additionally support: |
|
1157 |
### parent '..' |
|
1158 |
### current '.' |
|
1159 |
### last '-' |
|
1160 |
### home '~' |
|
1161 |
### |
|
1162 |
### Synopsis: $dn = $self->path_to_dn( $path ); |
|
1163 |
### |
|
30
e4b4b0968107
add method path_to_dn() to convert a given "path" to a DN
Peter Marschall <peter@adpm.de>
parents:
29
diff
changeset
|
1164 |
sub path_to_dn |
e4b4b0968107
add method path_to_dn() to convert a given "path" to a DN
Peter Marschall <peter@adpm.de>
parents:
29
diff
changeset
|
1165 |
{ |
33
057fefab56b0
Repair broken path behavior, remove unneeded #path_to_dn 'relative'
Mahlon E. Smith <mahlon@martini.nu>
parents:
32
diff
changeset
|
1166 |
my $self = shift; |
057fefab56b0
Repair broken path behavior, remove unneeded #path_to_dn 'relative'
Mahlon E. Smith <mahlon@martini.nu>
parents:
32
diff
changeset
|
1167 |
my $path = shift; |
057fefab56b0
Repair broken path behavior, remove unneeded #path_to_dn 'relative'
Mahlon E. Smith <mahlon@martini.nu>
parents:
32
diff
changeset
|
1168 |
my %flags = @_; |
057fefab56b0
Repair broken path behavior, remove unneeded #path_to_dn 'relative'
Mahlon E. Smith <mahlon@martini.nu>
parents:
32
diff
changeset
|
1169 |
my $curbase = $self->base(); |
30
e4b4b0968107
add method path_to_dn() to convert a given "path" to a DN
Peter Marschall <peter@adpm.de>
parents:
29
diff
changeset
|
1170 |
|
46
f0616455056d
Fix the uninitialized $path value errors I erroneously introduced on
Mahlon E. Smith <mahlon@laika.com>
parents:
44
diff
changeset
|
1171 |
# support empty 'cd' or 'cd ~' going to root |
f0616455056d
Fix the uninitialized $path value errors I erroneously introduced on
Mahlon E. Smith <mahlon@laika.com>
parents:
44
diff
changeset
|
1172 |
return $conf->{'basedn'} if ! $path || $path eq '~'; |
f0616455056d
Fix the uninitialized $path value errors I erroneously introduced on
Mahlon E. Smith <mahlon@laika.com>
parents:
44
diff
changeset
|
1173 |
|
30
e4b4b0968107
add method path_to_dn() to convert a given "path" to a DN
Peter Marschall <peter@adpm.de>
parents:
29
diff
changeset
|
1174 |
# return current base DN |
33
057fefab56b0
Repair broken path behavior, remove unneeded #path_to_dn 'relative'
Mahlon E. Smith <mahlon@martini.nu>
parents:
32
diff
changeset
|
1175 |
return $curbase if $path eq '.'; |
057fefab56b0
Repair broken path behavior, remove unneeded #path_to_dn 'relative'
Mahlon E. Smith <mahlon@martini.nu>
parents:
32
diff
changeset
|
1176 |
|
057fefab56b0
Repair broken path behavior, remove unneeded #path_to_dn 'relative'
Mahlon E. Smith <mahlon@martini.nu>
parents:
32
diff
changeset
|
1177 |
# support 'cd -' |
057fefab56b0
Repair broken path behavior, remove unneeded #path_to_dn 'relative'
Mahlon E. Smith <mahlon@martini.nu>
parents:
32
diff
changeset
|
1178 |
return $self->{'previous_base'} if $path eq '-'; |
30
e4b4b0968107
add method path_to_dn() to convert a given "path" to a DN
Peter Marschall <peter@adpm.de>
parents:
29
diff
changeset
|
1179 |
|
33
057fefab56b0
Repair broken path behavior, remove unneeded #path_to_dn 'relative'
Mahlon E. Smith <mahlon@martini.nu>
parents:
32
diff
changeset
|
1180 |
# relative path, upwards |
057fefab56b0
Repair broken path behavior, remove unneeded #path_to_dn 'relative'
Mahlon E. Smith <mahlon@martini.nu>
parents:
32
diff
changeset
|
1181 |
# |
057fefab56b0
Repair broken path behavior, remove unneeded #path_to_dn 'relative'
Mahlon E. Smith <mahlon@martini.nu>
parents:
32
diff
changeset
|
1182 |
if ( $path =~ /^\.\./o ) { |
30
e4b4b0968107
add method path_to_dn() to convert a given "path" to a DN
Peter Marschall <peter@adpm.de>
parents:
29
diff
changeset
|
1183 |
# support '..' (possibly iterated and as prefix to a DN) |
33
057fefab56b0
Repair broken path behavior, remove unneeded #path_to_dn 'relative'
Mahlon E. Smith <mahlon@martini.nu>
parents:
32
diff
changeset
|
1184 |
my @base = @{ ldap_explode_dn($curbase, casefold => 'none') }; |
30
e4b4b0968107
add method path_to_dn() to convert a given "path" to a DN
Peter Marschall <peter@adpm.de>
parents:
29
diff
changeset
|
1185 |
|
e4b4b0968107
add method path_to_dn() to convert a given "path" to a DN
Peter Marschall <peter@adpm.de>
parents:
29
diff
changeset
|
1186 |
# deal with leading .., |
50 | 1187 |
# |
33
057fefab56b0
Repair broken path behavior, remove unneeded #path_to_dn 'relative'
Mahlon E. Smith <mahlon@martini.nu>
parents:
32
diff
changeset
|
1188 |
while ( $path =~ /^\.\./ ) { |
057fefab56b0
Repair broken path behavior, remove unneeded #path_to_dn 'relative'
Mahlon E. Smith <mahlon@martini.nu>
parents:
32
diff
changeset
|
1189 |
shift( @base ) if @base; |
30
e4b4b0968107
add method path_to_dn() to convert a given "path" to a DN
Peter Marschall <peter@adpm.de>
parents:
29
diff
changeset
|
1190 |
$path =~ s/^\.\.//; |
33
057fefab56b0
Repair broken path behavior, remove unneeded #path_to_dn 'relative'
Mahlon E. Smith <mahlon@martini.nu>
parents:
32
diff
changeset
|
1191 |
last if $path !~ /[,\/]\s*/; |
057fefab56b0
Repair broken path behavior, remove unneeded #path_to_dn 'relative'
Mahlon E. Smith <mahlon@martini.nu>
parents:
32
diff
changeset
|
1192 |
$path =~ s/[,\/]\s*//; |
30
e4b4b0968107
add method path_to_dn() to convert a given "path" to a DN
Peter Marschall <peter@adpm.de>
parents:
29
diff
changeset
|
1193 |
} |
e4b4b0968107
add method path_to_dn() to convert a given "path" to a DN
Peter Marschall <peter@adpm.de>
parents:
29
diff
changeset
|
1194 |
|
33
057fefab56b0
Repair broken path behavior, remove unneeded #path_to_dn 'relative'
Mahlon E. Smith <mahlon@martini.nu>
parents:
32
diff
changeset
|
1195 |
# append the new dn to the node if one was specified: |
057fefab56b0
Repair broken path behavior, remove unneeded #path_to_dn 'relative'
Mahlon E. Smith <mahlon@martini.nu>
parents:
32
diff
changeset
|
1196 |
# cd ../../cn=somewhere vs |
057fefab56b0
Repair broken path behavior, remove unneeded #path_to_dn 'relative'
Mahlon E. Smith <mahlon@martini.nu>
parents:
32
diff
changeset
|
1197 |
# cd ../../ |
057fefab56b0
Repair broken path behavior, remove unneeded #path_to_dn 'relative'
Mahlon E. Smith <mahlon@martini.nu>
parents:
32
diff
changeset
|
1198 |
# |
057fefab56b0
Repair broken path behavior, remove unneeded #path_to_dn 'relative'
Mahlon E. Smith <mahlon@martini.nu>
parents:
32
diff
changeset
|
1199 |
my $newbase_root = canonical_dn( \@base, casefold => 'none' ); |
057fefab56b0
Repair broken path behavior, remove unneeded #path_to_dn 'relative'
Mahlon E. Smith <mahlon@martini.nu>
parents:
32
diff
changeset
|
1200 |
$path = $path ? $path . ',' . $newbase_root : $newbase_root; |
30
e4b4b0968107
add method path_to_dn() to convert a given "path" to a DN
Peter Marschall <peter@adpm.de>
parents:
29
diff
changeset
|
1201 |
} |
e4b4b0968107
add method path_to_dn() to convert a given "path" to a DN
Peter Marschall <peter@adpm.de>
parents:
29
diff
changeset
|
1202 |
|
33
057fefab56b0
Repair broken path behavior, remove unneeded #path_to_dn 'relative'
Mahlon E. Smith <mahlon@martini.nu>
parents:
32
diff
changeset
|
1203 |
# attach the base if it isn't already there (this takes care of |
057fefab56b0
Repair broken path behavior, remove unneeded #path_to_dn 'relative'
Mahlon E. Smith <mahlon@martini.nu>
parents:
32
diff
changeset
|
1204 |
# deeper relative nodes and absolutes) |
057fefab56b0
Repair broken path behavior, remove unneeded #path_to_dn 'relative'
Mahlon E. Smith <mahlon@martini.nu>
parents:
32
diff
changeset
|
1205 |
# |
057fefab56b0
Repair broken path behavior, remove unneeded #path_to_dn 'relative'
Mahlon E. Smith <mahlon@martini.nu>
parents:
32
diff
changeset
|
1206 |
else { |
057fefab56b0
Repair broken path behavior, remove unneeded #path_to_dn 'relative'
Mahlon E. Smith <mahlon@martini.nu>
parents:
32
diff
changeset
|
1207 |
$path = "$path," . $curbase unless $path =~ /$curbase/; |
057fefab56b0
Repair broken path behavior, remove unneeded #path_to_dn 'relative'
Mahlon E. Smith <mahlon@martini.nu>
parents:
32
diff
changeset
|
1208 |
} |
057fefab56b0
Repair broken path behavior, remove unneeded #path_to_dn 'relative'
Mahlon E. Smith <mahlon@martini.nu>
parents:
32
diff
changeset
|
1209 |
|
057fefab56b0
Repair broken path behavior, remove unneeded #path_to_dn 'relative'
Mahlon E. Smith <mahlon@martini.nu>
parents:
32
diff
changeset
|
1210 |
return $path; |
30
e4b4b0968107
add method path_to_dn() to convert a given "path" to a DN
Peter Marschall <peter@adpm.de>
parents:
29
diff
changeset
|
1211 |
} |
e4b4b0968107
add method path_to_dn() to convert a given "path" to a DN
Peter Marschall <peter@adpm.de>
parents:
29
diff
changeset
|
1212 |
|
50 | 1213 |
|
1214 |
### Given an array ref of shell-like globs, |
|
1215 |
### create and return a Net::LDAP::Filter object. |
|
1216 |
### |
|
0 | 1217 |
sub make_filter |
1218 |
{ |
|
1219 |
my $self = shift; |
|
1220 |
my $globs = shift or return; |
|
1221 |
||
1222 |
return unless ref $globs eq 'ARRAY'; |
|
1223 |
return unless scalar @$globs; |
|
1224 |
||
1225 |
my $filter; |
|
28
d42bd1b087a1
make_filter: cope with filters that are already parenthesized
Peter Marschall <peter@adpm.de>
parents:
27
diff
changeset
|
1226 |
$filter = join('', map { (/^\(.*\)$/o) ? $_ : "($_)" } @$globs); |
d42bd1b087a1
make_filter: cope with filters that are already parenthesized
Peter Marschall <peter@adpm.de>
parents:
27
diff
changeset
|
1227 |
$filter = '(|' . $filter . ')' if (scalar(@$globs) > 1); |
50 | 1228 |
$filter = Net::LDAP::Filter->new( $filter ); |
0 | 1229 |
|
1230 |
if ( $filter ) { |
|
50 | 1231 |
$self->debug( 'Filter parsed as: ' . $filter->as_string() . "\n" ); |
0 | 1232 |
} |
1233 |
else { |
|
1234 |
print "Error parsing filter.\n"; |
|
1235 |
return; |
|
1236 |
} |
|
1237 |
||
1238 |
return $filter; |
|
1239 |
} |
|
1240 |
||
27
7d170d1bc17b
run_list: new argument syntax: [<options>] [<filter>] [<attributes>]
Peter Marschall <peter@adpm.de>
parents:
26
diff
changeset
|
1241 |
|
50 | 1242 |
### Given an arrayref of objectClasses, pull a complete list of |
1243 |
### required and optional attrbutes. Returns two arrayrefs. |
|
1244 |
### |
|
1245 |
sub fetch_attributes |
|
1246 |
{ |
|
1247 |
my $self = shift; |
|
1248 |
my $ocs = shift or return [], []; |
|
1249 |
||
1250 |
my ( %seen, @must_attr, @may_attr ); |
|
1251 |
foreach my $oc ( sort @{$ocs} ) { |
|
1252 |
||
1253 |
# required |
|
1254 |
my @must = $self->{'schema'}->must( $oc ); |
|
1255 |
foreach my $attr ( sort { $a->{'name'} cmp $b->{'name'} } @must ) { |
|
1256 |
next if $attr->{'name'} =~ /^objectclass$/i; |
|
1257 |
next if $seen{ $attr->{'name'} }; |
|
1258 |
push @must_attr, $attr->{'name'}; |
|
1259 |
$seen{ $attr->{'name'} }++; |
|
1260 |
} |
|
1261 |
||
1262 |
# optional |
|
1263 |
my @may = $self->{'schema'}->may( $oc ); |
|
1264 |
foreach my $attr ( sort { $a->{'name'} cmp $b->{'name'} } @may ) { |
|
1265 |
next if $attr->{'name'} =~ /^objectclass$/i; |
|
1266 |
next if $seen{ $attr->{'name'} }; |
|
1267 |
push @may_attr, $attr->{'name'}; |
|
1268 |
$seen{ $attr->{'name'} }++; |
|
1269 |
} |
|
1270 |
} |
|
1271 |
||
1272 |
return \@must_attr, \@may_attr; |
|
1273 |
} |
|
1274 |
||
1275 |
||
1276 |
### Check whether a given string can be used directly as |
|
1277 |
### an LDAP search filter. |
|
1278 |
### |
|
1279 |
### Synopsis: $yesNo = $self->is_valid_filter($string); |
|
1280 |
### |
|
27
7d170d1bc17b
run_list: new argument syntax: [<options>] [<filter>] [<attributes>]
Peter Marschall <peter@adpm.de>
parents:
26
diff
changeset
|
1281 |
sub is_valid_filter |
7d170d1bc17b
run_list: new argument syntax: [<options>] [<filter>] [<attributes>]
Peter Marschall <peter@adpm.de>
parents:
26
diff
changeset
|
1282 |
{ |
34
40c3719c87d4
fix 'ls -R' output, minor style cleanup
Mahlon E. Smith <mahlon@martini.nu>
parents:
33
diff
changeset
|
1283 |
my $self = shift; |
27
7d170d1bc17b
run_list: new argument syntax: [<options>] [<filter>] [<attributes>]
Peter Marschall <peter@adpm.de>
parents:
26
diff
changeset
|
1284 |
my $filter = shift or return; |
7d170d1bc17b
run_list: new argument syntax: [<options>] [<filter>] [<attributes>]
Peter Marschall <peter@adpm.de>
parents:
26
diff
changeset
|
1285 |
|
34
40c3719c87d4
fix 'ls -R' output, minor style cleanup
Mahlon E. Smith <mahlon@martini.nu>
parents:
33
diff
changeset
|
1286 |
return Net::LDAP::Filter->new( $filter ) ? 1 : 0; |
27
7d170d1bc17b
run_list: new argument syntax: [<options>] [<filter>] [<attributes>]
Peter Marschall <peter@adpm.de>
parents:
26
diff
changeset
|
1287 |
} |
7d170d1bc17b
run_list: new argument syntax: [<options>] [<filter>] [<attributes>]
Peter Marschall <peter@adpm.de>
parents:
26
diff
changeset
|
1288 |
|
34
40c3719c87d4
fix 'ls -R' output, minor style cleanup
Mahlon E. Smith <mahlon@martini.nu>
parents:
33
diff
changeset
|
1289 |
|
50 | 1290 |
### Call code in subref $action, if there's any connection related errors, |
1291 |
### try it one additional time before giving up. This should take care of |
|
1292 |
### most server disconnects due to timeout and other generic connection |
|
1293 |
### errors, and will attempt to transparently re-establish a connection. |
|
1294 |
### |
|
48
fe27dfe5179e
More robust path for connection retries. Show optional, unused
Mahlon E. Smith <mahlon@laika.com>
parents:
46
diff
changeset
|
1295 |
sub with_retry |
fe27dfe5179e
More robust path for connection retries. Show optional, unused
Mahlon E. Smith <mahlon@laika.com>
parents:
46
diff
changeset
|
1296 |
{ |
fe27dfe5179e
More robust path for connection retries. Show optional, unused
Mahlon E. Smith <mahlon@laika.com>
parents:
46
diff
changeset
|
1297 |
my $self = shift; |
fe27dfe5179e
More robust path for connection retries. Show optional, unused
Mahlon E. Smith <mahlon@laika.com>
parents:
46
diff
changeset
|
1298 |
my $action = shift; |
fe27dfe5179e
More robust path for connection retries. Show optional, unused
Mahlon E. Smith <mahlon@laika.com>
parents:
46
diff
changeset
|
1299 |
|
fe27dfe5179e
More robust path for connection retries. Show optional, unused
Mahlon E. Smith <mahlon@laika.com>
parents:
46
diff
changeset
|
1300 |
my $rv = $action->(); |
fe27dfe5179e
More robust path for connection retries. Show optional, unused
Mahlon E. Smith <mahlon@laika.com>
parents:
46
diff
changeset
|
1301 |
if ( $rv->code() == LDAP_OPERATIONS_ERROR || |
fe27dfe5179e
More robust path for connection retries. Show optional, unused
Mahlon E. Smith <mahlon@laika.com>
parents:
46
diff
changeset
|
1302 |
$rv->code() == LDAP_TIMELIMIT_EXCEEDED || |
fe27dfe5179e
More robust path for connection retries. Show optional, unused
Mahlon E. Smith <mahlon@laika.com>
parents:
46
diff
changeset
|
1303 |
$rv->code() == LDAP_BUSY || |
fe27dfe5179e
More robust path for connection retries. Show optional, unused
Mahlon E. Smith <mahlon@laika.com>
parents:
46
diff
changeset
|
1304 |
$rv->code() == LDAP_UNAVAILABLE || |
fe27dfe5179e
More robust path for connection retries. Show optional, unused
Mahlon E. Smith <mahlon@laika.com>
parents:
46
diff
changeset
|
1305 |
$rv->code() == LDAP_OTHER || |
fe27dfe5179e
More robust path for connection retries. Show optional, unused
Mahlon E. Smith <mahlon@laika.com>
parents:
46
diff
changeset
|
1306 |
$rv->code() == LDAP_SERVER_DOWN || |
fe27dfe5179e
More robust path for connection retries. Show optional, unused
Mahlon E. Smith <mahlon@laika.com>
parents:
46
diff
changeset
|
1307 |
$rv->code() == LDAP_TIMEOUT || |
fe27dfe5179e
More robust path for connection retries. Show optional, unused
Mahlon E. Smith <mahlon@laika.com>
parents:
46
diff
changeset
|
1308 |
$rv->code() == LDAP_NO_MEMORY || |
fe27dfe5179e
More robust path for connection retries. Show optional, unused
Mahlon E. Smith <mahlon@laika.com>
parents:
46
diff
changeset
|
1309 |
$rv->code() == LDAP_CONNECT_ERROR ) { |
fe27dfe5179e
More robust path for connection retries. Show optional, unused
Mahlon E. Smith <mahlon@laika.com>
parents:
46
diff
changeset
|
1310 |
|
fe27dfe5179e
More robust path for connection retries. Show optional, unused
Mahlon E. Smith <mahlon@laika.com>
parents:
46
diff
changeset
|
1311 |
$self->debug( "Error ". $rv->code() . ", retrying.\n" ); |
fe27dfe5179e
More robust path for connection retries. Show optional, unused
Mahlon E. Smith <mahlon@laika.com>
parents:
46
diff
changeset
|
1312 |
$self->{'ldap'} = undef; |
fe27dfe5179e
More robust path for connection retries. Show optional, unused
Mahlon E. Smith <mahlon@laika.com>
parents:
46
diff
changeset
|
1313 |
$rv = $action->(); |
fe27dfe5179e
More robust path for connection retries. Show optional, unused
Mahlon E. Smith <mahlon@laika.com>
parents:
46
diff
changeset
|
1314 |
} |
fe27dfe5179e
More robust path for connection retries. Show optional, unused
Mahlon E. Smith <mahlon@laika.com>
parents:
46
diff
changeset
|
1315 |
|
fe27dfe5179e
More robust path for connection retries. Show optional, unused
Mahlon E. Smith <mahlon@laika.com>
parents:
46
diff
changeset
|
1316 |
return $rv; |
fe27dfe5179e
More robust path for connection retries. Show optional, unused
Mahlon E. Smith <mahlon@laika.com>
parents:
46
diff
changeset
|
1317 |
} |
fe27dfe5179e
More robust path for connection retries. Show optional, unused
Mahlon E. Smith <mahlon@laika.com>
parents:
46
diff
changeset
|
1318 |
|
fe27dfe5179e
More robust path for connection retries. Show optional, unused
Mahlon E. Smith <mahlon@laika.com>
parents:
46
diff
changeset
|
1319 |
|
50 | 1320 |
### little. yellow. different. better. |
1321 |
### |
|
0 | 1322 |
sub debug |
1323 |
{ |
|
1324 |
my $self = shift; |
|
1325 |
return unless $conf->{'debug'}; |
|
1326 |
print "\e[33m"; |
|
1327 |
print shift(); |
|
1328 |
print "\e[0m"; |
|
1329 |
return; |
|
1330 |
} |
|
1331 |
||
50 | 1332 |
|
1333 |
### Autocomplete values: Returns cached children entries. |
|
1334 |
### |
|
110
dbceec51da98
Fix autocompleter for all commands.
Davor Ocelic <docelic@crystallabs.io>
parents:
109
diff
changeset
|
1335 |
sub autocomplete_from_cwd |
0 | 1336 |
{ |
1337 |
my $self = shift; |
|
110
dbceec51da98
Fix autocompleter for all commands.
Davor Ocelic <docelic@crystallabs.io>
parents:
109
diff
changeset
|
1338 |
my $word = quotemeta shift; |
dbceec51da98
Fix autocompleter for all commands.
Davor Ocelic <docelic@crystallabs.io>
parents:
109
diff
changeset
|
1339 |
return grep {/^$word/} @{ $self->{'cwd_entries'} }; |
0 | 1340 |
} |
1341 |
||
50 | 1342 |
|
1343 |
### Autocomplete values: Returns previously set shelldap environment values. |
|
1344 |
### |
|
110
dbceec51da98
Fix autocompleter for all commands.
Davor Ocelic <docelic@crystallabs.io>
parents:
109
diff
changeset
|
1345 |
sub autocomplete_from_env |
0 | 1346 |
{ |
1347 |
my $self = shift; |
|
110
dbceec51da98
Fix autocompleter for all commands.
Davor Ocelic <docelic@crystallabs.io>
parents:
109
diff
changeset
|
1348 |
my $word = quotemeta shift; |
dbceec51da98
Fix autocompleter for all commands.
Davor Ocelic <docelic@crystallabs.io>
parents:
109
diff
changeset
|
1349 |
return grep {/^$word/} @{ $self->{'env'} }; |
0 | 1350 |
} |
1351 |
||
50 | 1352 |
|
1353 |
### Autocomplete values: Returns all objectClasses as defined |
|
1354 |
### by the LDAP server. |
|
1355 |
### |
|
110
dbceec51da98
Fix autocompleter for all commands.
Davor Ocelic <docelic@crystallabs.io>
parents:
109
diff
changeset
|
1356 |
sub autocomplete_from_objectclasses |
0 | 1357 |
{ |
1358 |
my $self = shift; |
|
110
dbceec51da98
Fix autocompleter for all commands.
Davor Ocelic <docelic@crystallabs.io>
parents:
109
diff
changeset
|
1359 |
my $word = quotemeta shift; |
dbceec51da98
Fix autocompleter for all commands.
Davor Ocelic <docelic@crystallabs.io>
parents:
109
diff
changeset
|
1360 |
return grep {/^$word/} @{ $self->{'objectclasses'} }; |
0 | 1361 |
} |
1362 |
||
50 | 1363 |
|
51
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
1364 |
### Autocomplete values: Returns all objectClasses as defined |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
1365 |
### by the LDAP server, along with current children DNs. |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
1366 |
### |
110
dbceec51da98
Fix autocompleter for all commands.
Davor Ocelic <docelic@crystallabs.io>
parents:
109
diff
changeset
|
1367 |
sub autocomplete_from_objectclasses_and_cwd |
51
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
1368 |
{ |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
1369 |
my $self = shift; |
110
dbceec51da98
Fix autocompleter for all commands.
Davor Ocelic <docelic@crystallabs.io>
parents:
109
diff
changeset
|
1370 |
my $word = quotemeta shift; |
dbceec51da98
Fix autocompleter for all commands.
Davor Ocelic <docelic@crystallabs.io>
parents:
109
diff
changeset
|
1371 |
return grep {/^$word/} ('_schema', @{ $self->{'objectclasses'} }, @{ $self->{'cwd_entries'} }); |
51
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
1372 |
} |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
1373 |
|
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
1374 |
|
50 | 1375 |
### Given an $arrayref, remove LDIF continuation wrapping in place, |
1376 |
### effectively making each entry a single line for LCS comparisons. |
|
1377 |
### |
|
1378 |
sub unwrap_line { |
|
1379 |
my $self = shift; |
|
5
78b2a48e07db
Combine multiple lines into a single one before displaying LDIF. Patch
Mahlon E. Smith <mahlon@laika.com>
parents:
4
diff
changeset
|
1380 |
my $array = shift; |
78b2a48e07db
Combine multiple lines into a single one before displaying LDIF. Patch
Mahlon E. Smith <mahlon@laika.com>
parents:
4
diff
changeset
|
1381 |
|
6
46dfe9d6f368
Update documentation, now that multiline edits work. Minor other
Mahlon E. Smith <mahlon@laika.com>
parents:
5
diff
changeset
|
1382 |
my $i = 1; |
46dfe9d6f368
Update documentation, now that multiline edits work. Minor other
Mahlon E. Smith <mahlon@laika.com>
parents:
5
diff
changeset
|
1383 |
while ( $i < scalar(@$array) ) { |
46dfe9d6f368
Update documentation, now that multiline edits work. Minor other
Mahlon E. Smith <mahlon@laika.com>
parents:
5
diff
changeset
|
1384 |
if ( $array->[$i] =~ /^\s/ ) { |
46dfe9d6f368
Update documentation, now that multiline edits work. Minor other
Mahlon E. Smith <mahlon@laika.com>
parents:
5
diff
changeset
|
1385 |
$array->[ $i - 1 ] =~ s/\n$//; |
46dfe9d6f368
Update documentation, now that multiline edits work. Minor other
Mahlon E. Smith <mahlon@laika.com>
parents:
5
diff
changeset
|
1386 |
$array->[ $i ] =~ s/^\s//; |
46dfe9d6f368
Update documentation, now that multiline edits work. Minor other
Mahlon E. Smith <mahlon@laika.com>
parents:
5
diff
changeset
|
1387 |
splice( @$array, $i - 1, 2, $array->[$i - 1] . $array->[$i] ); |
46dfe9d6f368
Update documentation, now that multiline edits work. Minor other
Mahlon E. Smith <mahlon@laika.com>
parents:
5
diff
changeset
|
1388 |
} |
46dfe9d6f368
Update documentation, now that multiline edits work. Minor other
Mahlon E. Smith <mahlon@laika.com>
parents:
5
diff
changeset
|
1389 |
else { |
46dfe9d6f368
Update documentation, now that multiline edits work. Minor other
Mahlon E. Smith <mahlon@laika.com>
parents:
5
diff
changeset
|
1390 |
$i++; |
5
78b2a48e07db
Combine multiple lines into a single one before displaying LDIF. Patch
Mahlon E. Smith <mahlon@laika.com>
parents:
4
diff
changeset
|
1391 |
} |
78b2a48e07db
Combine multiple lines into a single one before displaying LDIF. Patch
Mahlon E. Smith <mahlon@laika.com>
parents:
4
diff
changeset
|
1392 |
} |
78b2a48e07db
Combine multiple lines into a single one before displaying LDIF. Patch
Mahlon E. Smith <mahlon@laika.com>
parents:
4
diff
changeset
|
1393 |
} |
78b2a48e07db
Combine multiple lines into a single one before displaying LDIF. Patch
Mahlon E. Smith <mahlon@laika.com>
parents:
4
diff
changeset
|
1394 |
|
6
46dfe9d6f368
Update documentation, now that multiline edits work. Minor other
Mahlon E. Smith <mahlon@laika.com>
parents:
5
diff
changeset
|
1395 |
|
81
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1396 |
### Given an LDAP Entry object $e, an array reference to it's LDIF original |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1397 |
### content, and another array reference to updated LDIF content, run an LCS |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1398 |
### comparison, modifying the Entry object in place. |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1399 |
### |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1400 |
sub diff { |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1401 |
my $self = shift; |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1402 |
my $e = shift; |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1403 |
my $orig = shift; |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1404 |
my $new = shift; |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1405 |
|
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1406 |
$self->unwrap_line( $orig ); |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1407 |
$self->unwrap_line( $new ); |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1408 |
|
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1409 |
# parser subref |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1410 |
# |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1411 |
my $parse = sub { |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1412 |
my $line = shift || $_; |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1413 |
return if $line =~ /^\#/; # ignore comments |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1414 |
my ( $attr, $val ) = ( $1, $2 ) if $line =~ /^(.+?): (.*)$/; |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1415 |
return unless $attr; |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1416 |
return if index($attr, ':') != -1; # ignore base64 |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1417 |
return ( $attr, $val ); |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1418 |
}; |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1419 |
|
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1420 |
my $diff = Algorithm::Diff->new( $orig, $new ); |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1421 |
HUNK: |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1422 |
while ( $diff->Next() ) { |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1423 |
next if $diff->Same(); |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1424 |
my $diff_bit = $diff->Diff(); |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1425 |
my %seen_attr; |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1426 |
|
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1427 |
# attr removal hunk |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1428 |
# |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1429 |
if ( $diff_bit == 1 ) { |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1430 |
foreach ( $diff->Items(1) ) { |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1431 |
my ( $attr, $val ) = $parse->( $_ ) or next; |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1432 |
$self->debug("DELETE: $_"); |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1433 |
$e->delete( $attr => [ $val ] ); |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1434 |
} |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1435 |
} |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1436 |
|
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1437 |
# attr insertion hunk |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1438 |
# |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1439 |
if ( $diff_bit == 2 ) { |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1440 |
foreach ( $diff->Items(2) ) { |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1441 |
my ( $attr, $val ) = $parse->( $_ ) or next; |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1442 |
$self->debug("INSERT: $_"); |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1443 |
$e->add( $attr => $val ); |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1444 |
} |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1445 |
} |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1446 |
|
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1447 |
# attr change hunk |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1448 |
# |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1449 |
if ( $diff_bit == 3 ) { |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1450 |
|
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1451 |
# modification to existing line |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1452 |
# |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1453 |
foreach ( $diff->Items(2) ) { |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1454 |
my ( $attr, $val ) = $parse->( $_ ) or next; |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1455 |
$self->debug("MODIFY: $_"); |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1456 |
|
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1457 |
my $cur_vals = $e->get_value( $attr, asref => 1 ) || []; |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1458 |
my $cur_valcount = scalar @$cur_vals; |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1459 |
next if $cur_valcount == 0; # should have been an 'add' |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1460 |
|
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1461 |
# replace immediately |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1462 |
# |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1463 |
if ( $cur_valcount == 1 ) { |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1464 |
$e->replace( $attr => $val ); |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1465 |
} |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1466 |
else { |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1467 |
|
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1468 |
# retain attributes that allow multiples, so updating |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1469 |
# one attribute doesn't inadvertently remove others with |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1470 |
# the same name. |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1471 |
# |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1472 |
next if $seen_attr{ $attr }; |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1473 |
my @new_vals; |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1474 |
foreach my $line ( @$new ) { |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1475 |
my ( $new_attr, $new_val ) = $parse->( $line ) or next; |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1476 |
next unless $new_attr eq $attr; |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1477 |
$seen_attr{ $attr }++; |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1478 |
push @new_vals, $new_val; |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1479 |
} |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1480 |
|
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1481 |
$e->replace( $attr => \@new_vals ); |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1482 |
} |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1483 |
} |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1484 |
|
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1485 |
# deletion within the same hunk |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1486 |
# |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1487 |
foreach ( $diff->Items(1) ) { |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1488 |
my ( $attr, $val ) = $parse->( $_ ) or next; |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1489 |
my $cur_vals = $e->get_value( $attr, asref => 1 ) || []; |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1490 |
my $cur_valcount = scalar @$cur_vals; |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1491 |
|
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1492 |
next if $cur_valcount == 1; |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1493 |
next if $seen_attr{ $attr }; |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1494 |
$self->debug("DELETE: $_"); |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1495 |
$e->delete( $attr => [ $val ] ); |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1496 |
} |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1497 |
} |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1498 |
} |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1499 |
} |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1500 |
|
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1501 |
|
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
1502 |
|
50 | 1503 |
######################################################################## |
1504 |
### S H E L L M E T H O D S |
|
1505 |
######################################################################## |
|
0 | 1506 |
|
104 | 1507 |
# alias_or_command => [ real_command_name, completion_function ] |
1508 |
# |
|
109
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
1509 |
tie my %cmd_map, 'Tie::IxHash'; |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
1510 |
%cmd_map = ( |
110
dbceec51da98
Fix autocompleter for all commands.
Davor Ocelic <docelic@crystallabs.io>
parents:
109
diff
changeset
|
1511 |
# Real commands: |
115
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1512 |
'alias' => [ undef ], |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1513 |
'configfile'=> [ undef ], |
109
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
1514 |
'whoami' => [ undef ], |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
1515 |
'pwd' => [ undef ], |
110
dbceec51da98
Fix autocompleter for all commands.
Davor Ocelic <docelic@crystallabs.io>
parents:
109
diff
changeset
|
1516 |
'list' => [ undef, 'autocomplete_from_cwd' ], |
dbceec51da98
Fix autocompleter for all commands.
Davor Ocelic <docelic@crystallabs.io>
parents:
109
diff
changeset
|
1517 |
'grep' => [ undef, 'autocomplete_from_cwd' ], |
dbceec51da98
Fix autocompleter for all commands.
Davor Ocelic <docelic@crystallabs.io>
parents:
109
diff
changeset
|
1518 |
'edit' => [ undef, 'autocomplete_from_cwd' ], |
dbceec51da98
Fix autocompleter for all commands.
Davor Ocelic <docelic@crystallabs.io>
parents:
109
diff
changeset
|
1519 |
'delete' => [ undef, 'autocomplete_from_cwd' ], |
dbceec51da98
Fix autocompleter for all commands.
Davor Ocelic <docelic@crystallabs.io>
parents:
109
diff
changeset
|
1520 |
'copy' => [ undef, 'autocomplete_from_cwd' ], |
dbceec51da98
Fix autocompleter for all commands.
Davor Ocelic <docelic@crystallabs.io>
parents:
109
diff
changeset
|
1521 |
'cat' => [ undef, 'autocomplete_from_cwd' ], |
dbceec51da98
Fix autocompleter for all commands.
Davor Ocelic <docelic@crystallabs.io>
parents:
109
diff
changeset
|
1522 |
'move' => [ undef, 'autocomplete_from_cwd' ], |
dbceec51da98
Fix autocompleter for all commands.
Davor Ocelic <docelic@crystallabs.io>
parents:
109
diff
changeset
|
1523 |
'less' => [ undef, 'autocomplete_from_cwd' ], |
dbceec51da98
Fix autocompleter for all commands.
Davor Ocelic <docelic@crystallabs.io>
parents:
109
diff
changeset
|
1524 |
'cd' => [ undef, 'autocomplete_from_cwd' ], |
dbceec51da98
Fix autocompleter for all commands.
Davor Ocelic <docelic@crystallabs.io>
parents:
109
diff
changeset
|
1525 |
'create' => [ undef, 'autocomplete_from_objectclasses' ], |
dbceec51da98
Fix autocompleter for all commands.
Davor Ocelic <docelic@crystallabs.io>
parents:
109
diff
changeset
|
1526 |
'setenv' => [ undef, 'autocomplete_from_env' ], |
109
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
1527 |
'passwd' => [ undef ], |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
1528 |
'clear' => [ undef ], |
110
dbceec51da98
Fix autocompleter for all commands.
Davor Ocelic <docelic@crystallabs.io>
parents:
109
diff
changeset
|
1529 |
'env' => [ undef, 'autocomplete_from_env' ], |
104 | 1530 |
#'help' => [ undef ], |
109
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
1531 |
'mkdir' => [ undef ], |
110
dbceec51da98
Fix autocompleter for all commands.
Davor Ocelic <docelic@crystallabs.io>
parents:
109
diff
changeset
|
1532 |
'inspect' => [ undef, 'autocomplete_from_objectclasses_and_cwd' ], |
115
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1533 |
'unalias' => [ undef ], |
110
dbceec51da98
Fix autocompleter for all commands.
Davor Ocelic <docelic@crystallabs.io>
parents:
109
diff
changeset
|
1534 |
|
dbceec51da98
Fix autocompleter for all commands.
Davor Ocelic <docelic@crystallabs.io>
parents:
109
diff
changeset
|
1535 |
# Aliases: |
104 | 1536 |
'id' => [ 'whoami' ], |
110
dbceec51da98
Fix autocompleter for all commands.
Davor Ocelic <docelic@crystallabs.io>
parents:
109
diff
changeset
|
1537 |
'ls' => [ 'list' ], |
dbceec51da98
Fix autocompleter for all commands.
Davor Ocelic <docelic@crystallabs.io>
parents:
109
diff
changeset
|
1538 |
'search' => [ 'grep' ], |
dbceec51da98
Fix autocompleter for all commands.
Davor Ocelic <docelic@crystallabs.io>
parents:
109
diff
changeset
|
1539 |
'vi' => [ 'edit' ], |
dbceec51da98
Fix autocompleter for all commands.
Davor Ocelic <docelic@crystallabs.io>
parents:
109
diff
changeset
|
1540 |
'rm' => [ 'delete'], |
dbceec51da98
Fix autocompleter for all commands.
Davor Ocelic <docelic@crystallabs.io>
parents:
109
diff
changeset
|
1541 |
'cp' => [ 'copy' ], |
dbceec51da98
Fix autocompleter for all commands.
Davor Ocelic <docelic@crystallabs.io>
parents:
109
diff
changeset
|
1542 |
'read' => [ 'read' ], |
dbceec51da98
Fix autocompleter for all commands.
Davor Ocelic <docelic@crystallabs.io>
parents:
109
diff
changeset
|
1543 |
'mv' => [ 'move' ], |
dbceec51da98
Fix autocompleter for all commands.
Davor Ocelic <docelic@crystallabs.io>
parents:
109
diff
changeset
|
1544 |
'touch' => [ 'create' ], |
dbceec51da98
Fix autocompleter for all commands.
Davor Ocelic <docelic@crystallabs.io>
parents:
109
diff
changeset
|
1545 |
'export' => [ 'setenv'], |
108
24340fdef276
Properly handle Ctrl+C; add '?' and 'man' aliases; don't import symbols
Davor Ocelic <docelic@crystallabs.io>
parents:
107
diff
changeset
|
1546 |
'?' => [ 'help' ], |
24340fdef276
Properly handle Ctrl+C; add '?' and 'man' aliases; don't import symbols
Davor Ocelic <docelic@crystallabs.io>
parents:
107
diff
changeset
|
1547 |
'man' => [ 'help' ], |
104 | 1548 |
); |
1549 |
||
1550 |
||
50 | 1551 |
### Term::Shell hook. |
1552 |
### Write history for each command, print shell debug actions. |
|
1553 |
### |
|
0 | 1554 |
sub precmd |
1555 |
{ |
|
1556 |
my $self = shift; |
|
1557 |
my ( $handler, $cmd, $args ) = @_; |
|
1558 |
||
1559 |
my $term = $self->term(); |
|
1560 |
eval { $term->WriteHistory("$ENV{'HOME'}/.shelldap_history"); }; |
|
1561 |
||
1562 |
$self->debug( "$$cmd (" . ( join ' ', @$args ) . "), calling '$$handler'\n" ); |
|
1563 |
return; |
|
1564 |
} |
|
1565 |
||
50 | 1566 |
|
115
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1567 |
### Display or define aliases. |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1568 |
### |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1569 |
sub run_alias |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1570 |
{ |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1571 |
my $self = shift; |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1572 |
my $cmd_alias = shift; |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1573 |
|
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1574 |
# If $cmd_alias is empty, user requested printing of known aliases |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1575 |
unless($cmd_alias) { |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1576 |
while(my($alias,$cmd_args) = each %{$conf->{alias}}) { |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1577 |
print "alias $alias=${\( join ' ', map { $_=~ /\s/ ? \"'$_'\" : $_} @{$cmd_args})}\n"; |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1578 |
} |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1579 |
return |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1580 |
|
119
a6c211de24f0
Support separating aliases by space too
Davor Ocelic <docelic@crystallabs.io>
parents:
118
diff
changeset
|
1581 |
# If there is argument but without = or space, user wanted to print specific alias |
a6c211de24f0
Support separating aliases by space too
Davor Ocelic <docelic@crystallabs.io>
parents:
118
diff
changeset
|
1582 |
} elsif($cmd_alias !~ /[=\s]/ and !@_) { |
115
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1583 |
my $alias = $cmd_alias; |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1584 |
my $cmd_args = $conf->{alias}{$alias}; |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1585 |
unless( $cmd_args) { |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1586 |
print "alias: $alias: not found\n"; |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1587 |
} else { |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1588 |
print "alias $alias=${\( join ', ', map {\"'$_'\"} @{$cmd_args})}\n"; |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1589 |
} |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1590 |
return |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1591 |
|
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1592 |
# There is argument with =, so the line is a new alias definition |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1593 |
} else { |
119
a6c211de24f0
Support separating aliases by space too
Davor Ocelic <docelic@crystallabs.io>
parents:
118
diff
changeset
|
1594 |
my($alias, $command) = ($cmd_alias =~ m/^(\S+?)[=\s]?(.*)$/); |
a6c211de24f0
Support separating aliases by space too
Davor Ocelic <docelic@crystallabs.io>
parents:
118
diff
changeset
|
1595 |
unless( $alias) { |
a6c211de24f0
Support separating aliases by space too
Davor Ocelic <docelic@crystallabs.io>
parents:
118
diff
changeset
|
1596 |
print "Invalid syntax.\n"; |
a6c211de24f0
Support separating aliases by space too
Davor Ocelic <docelic@crystallabs.io>
parents:
118
diff
changeset
|
1597 |
return |
a6c211de24f0
Support separating aliases by space too
Davor Ocelic <docelic@crystallabs.io>
parents:
118
diff
changeset
|
1598 |
} |
115
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1599 |
$command = $cmd_map{$command}[0] if $cmd_map{$command} and $cmd_map{$command}[0]; |
119
a6c211de24f0
Support separating aliases by space too
Davor Ocelic <docelic@crystallabs.io>
parents:
118
diff
changeset
|
1600 |
$conf->{alias}{$alias} = [ $command ? $command : (), @_ ]; |
115
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1601 |
} |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1602 |
} |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1603 |
|
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1604 |
# Remove alias |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1605 |
sub run_unalias |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1606 |
{ |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1607 |
my $self = shift; |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1608 |
for my $alias(@_) { |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1609 |
unless( $conf->{alias}{$alias}) { |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1610 |
print "alias: $alias: not found\n"; |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1611 |
} else { |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1612 |
delete $conf->{alias}{$alias}; |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1613 |
} |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1614 |
} |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1615 |
return |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1616 |
} |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1617 |
|
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1618 |
# Run aliased command when alias is entered |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1619 |
sub catch_run { |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1620 |
my $self = shift; |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1621 |
my @cmdline; |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1622 |
|
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1623 |
unless( $conf->{alias}{$_[0]}) { |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1624 |
print $self->msg_unknown_cmd($_[0]); |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1625 |
return |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1626 |
} |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1627 |
|
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1628 |
my $done = 0; |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1629 |
while(my $arg = $_[0]) { |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1630 |
my @alias = @{$conf->{alias}{$arg} or last}; |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1631 |
|
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1632 |
if($alias[-1] !~ s/\s+$//) { |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1633 |
$done++ |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1634 |
} |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1635 |
push @cmdline, @alias; |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1636 |
shift; |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1637 |
last if $done; |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1638 |
} |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1639 |
|
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1640 |
push @cmdline, @_; |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1641 |
|
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1642 |
$self->run(@cmdline); |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1643 |
} |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1644 |
|
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1645 |
|
50 | 1646 |
### Display an entry as LDIF to the terminal. |
1647 |
### |
|
0 | 1648 |
sub run_cat |
1649 |
{ |
|
1650 |
my $self = shift; |
|
1651 |
my $dn = shift; |
|
101
cb4de2ecc7ab
Allow default attributes to be set via config and cmdline
Davor Ocelic <docelic@crystallabs.io>
parents:
99
diff
changeset
|
1652 |
my @attrs = (@_) ? @_ : @{$conf->{'attributes'}}; |
0 | 1653 |
|
73
b3b840a4b56c
Minor style cleanups, version bump.
Mahlon E. Smith <mahlon@laika.com>
parents:
72
diff
changeset
|
1654 |
$self->display( $dn, \@attrs, 0 ); |
72
39e9f802eb40
Add a 'less' command, that does the same as cat, but uses a pager.
Dennis Kaarsemaker <dennis.kaarsemaker@booking.com>
parents:
71
diff
changeset
|
1655 |
} |
39e9f802eb40
Add a 'less' command, that does the same as cat, but uses a pager.
Dennis Kaarsemaker <dennis.kaarsemaker@booking.com>
parents:
71
diff
changeset
|
1656 |
|
73
b3b840a4b56c
Minor style cleanups, version bump.
Mahlon E. Smith <mahlon@laika.com>
parents:
72
diff
changeset
|
1657 |
|
115
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1658 |
### Load or save config |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1659 |
### |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1660 |
sub run_configfile |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1661 |
{ |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1662 |
my $self = shift; |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1663 |
my $action = shift; |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1664 |
my $filepath = shift; |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1665 |
|
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1666 |
unless ( $action and $action =~ /^(?:load|save)$/) { |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1667 |
print "No action specified; use 'load' or 'save'.\n"; |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1668 |
return; |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1669 |
} |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1670 |
|
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1671 |
if( $action eq 'load') { |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1672 |
main::load_config($filepath); |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1673 |
print "Loaded.\n"; |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1674 |
} elsif( $action eq 'save') { |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1675 |
main::save_config($filepath); |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1676 |
print "Saved.\n"; |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1677 |
} |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1678 |
} |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1679 |
|
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
1680 |
|
73
b3b840a4b56c
Minor style cleanups, version bump.
Mahlon E. Smith <mahlon@laika.com>
parents:
72
diff
changeset
|
1681 |
### Display an entry as LDIF to the terminal with external pagination. |
b3b840a4b56c
Minor style cleanups, version bump.
Mahlon E. Smith <mahlon@laika.com>
parents:
72
diff
changeset
|
1682 |
### |
72
39e9f802eb40
Add a 'less' command, that does the same as cat, but uses a pager.
Dennis Kaarsemaker <dennis.kaarsemaker@booking.com>
parents:
71
diff
changeset
|
1683 |
sub run_less |
39e9f802eb40
Add a 'less' command, that does the same as cat, but uses a pager.
Dennis Kaarsemaker <dennis.kaarsemaker@booking.com>
parents:
71
diff
changeset
|
1684 |
{ |
39e9f802eb40
Add a 'less' command, that does the same as cat, but uses a pager.
Dennis Kaarsemaker <dennis.kaarsemaker@booking.com>
parents:
71
diff
changeset
|
1685 |
my $self = shift; |
39e9f802eb40
Add a 'less' command, that does the same as cat, but uses a pager.
Dennis Kaarsemaker <dennis.kaarsemaker@booking.com>
parents:
71
diff
changeset
|
1686 |
my $dn = shift; |
39e9f802eb40
Add a 'less' command, that does the same as cat, but uses a pager.
Dennis Kaarsemaker <dennis.kaarsemaker@booking.com>
parents:
71
diff
changeset
|
1687 |
my @attrs = (@_) ? @_ : ('*'); |
39e9f802eb40
Add a 'less' command, that does the same as cat, but uses a pager.
Dennis Kaarsemaker <dennis.kaarsemaker@booking.com>
parents:
71
diff
changeset
|
1688 |
|
73
b3b840a4b56c
Minor style cleanups, version bump.
Mahlon E. Smith <mahlon@laika.com>
parents:
72
diff
changeset
|
1689 |
$self->display( $dn, \@attrs, 1 ); |
0 | 1690 |
} |
1691 |
||
50 | 1692 |
|
1693 |
### Change shelldap's idea of a current working 'directory', |
|
1694 |
### by adjusting the current default basedn for all searches. |
|
1695 |
### |
|
0 | 1696 |
sub run_cd |
1697 |
{ |
|
1698 |
my $self = shift; |
|
41
3e7c107f8b93
Take only second argument for run_{cd,edit,mkdir}
Salvatore Bonaccorso <carnil@debian.org>
parents:
40
diff
changeset
|
1699 |
my $newbase = shift; |
0 | 1700 |
|
30
e4b4b0968107
add method path_to_dn() to convert a given "path" to a DN
Peter Marschall <peter@adpm.de>
parents:
29
diff
changeset
|
1701 |
# convert given path to a DN |
33
057fefab56b0
Repair broken path behavior, remove unneeded #path_to_dn 'relative'
Mahlon E. Smith <mahlon@martini.nu>
parents:
32
diff
changeset
|
1702 |
$newbase = $self->path_to_dn( $newbase ); |
057fefab56b0
Repair broken path behavior, remove unneeded #path_to_dn 'relative'
Mahlon E. Smith <mahlon@martini.nu>
parents:
32
diff
changeset
|
1703 |
|
0 | 1704 |
unless ( $self->is_valid_dn( $newbase ) ) { |
1705 |
print "No such object\n"; |
|
1706 |
return; |
|
1707 |
} |
|
1708 |
||
1709 |
# store old base |
|
1710 |
$self->{'previous_base'} = $self->base(); |
|
1711 |
||
1712 |
# update new base |
|
1713 |
$self->base( $newbase ); |
|
1714 |
||
1715 |
# get new 'cwd' listing |
|
26
68318d115f6c
fix attribute lists for LDAP queries
Peter Marschall <peter@adpm.de>
parents:
25
diff
changeset
|
1716 |
my $s = $self->search({ scope => 'one', attrs => [ '1.1' ] }); |
0 | 1717 |
if ( $s->{'code'} ) { |
1718 |
print "$s->{'message'}\n"; |
|
1719 |
return; |
|
1720 |
} |
|
1721 |
$self->update_entries( search => $s ); |
|
1722 |
||
1723 |
# reflect cwd change in prompt |
|
1724 |
$self->update_prompt(); |
|
1725 |
return; |
|
1726 |
} |
|
1727 |
||
50 | 1728 |
|
1729 |
### Simply clear the screen. |
|
1730 |
### |
|
0 | 1731 |
sub run_clear |
1732 |
{ |
|
1733 |
my $self = shift; |
|
50 | 1734 |
system( 'clear' ); |
0 | 1735 |
return; |
1736 |
} |
|
1737 |
||
50 | 1738 |
|
1739 |
### Fetch the source DN entry, modify it's DN data |
|
1740 |
### and write it back to the directory. |
|
1741 |
### |
|
0 | 1742 |
sub run_copy |
1743 |
{ |
|
1744 |
my $self = shift; |
|
1745 |
my ( $s_dn, $d_dn ) = @_; |
|
1746 |
||
1747 |
unless ( $s_dn ) { |
|
50 | 1748 |
print "No source DN provided.\n"; |
0 | 1749 |
return; |
1750 |
} |
|
1751 |
unless ( $d_dn ) { |
|
50 | 1752 |
print "No destination DN provided.\n"; |
0 | 1753 |
return; |
1754 |
} |
|
1755 |
||
31
a3a710f720dd
run_cat: convert to using path_to_dn()
Peter Marschall <peter@adpm.de>
parents:
30
diff
changeset
|
1756 |
# convert given source path to DN |
33
057fefab56b0
Repair broken path behavior, remove unneeded #path_to_dn 'relative'
Mahlon E. Smith <mahlon@martini.nu>
parents:
32
diff
changeset
|
1757 |
$s_dn = $self->path_to_dn( $s_dn ); |
31
a3a710f720dd
run_cat: convert to using path_to_dn()
Peter Marschall <peter@adpm.de>
parents:
30
diff
changeset
|
1758 |
|
50 | 1759 |
# sanity check source |
1760 |
# |
|
0 | 1761 |
my $s = $self->search({ base => $s_dn, vals => 1 }); |
16
a2e3faa3d2fc
use symbolic LDAP error codes instead of numbers
Peter Marschall <peter@adpm.de>
parents:
15
diff
changeset
|
1762 |
unless ( $s->{'code'} == LDAP_SUCCESS ) { |
0 | 1763 |
print "No such object\n"; |
1764 |
return; |
|
1765 |
} |
|
1766 |
||
50 | 1767 |
# see if we're copying the entry to a nonexistent path |
1768 |
# |
|
0 | 1769 |
my ( $new_dn, $old_dn ); |
60
f90f7ff0b146
Fix the DN regexp to include dashes. Patch from Mike Hix <m@hix.io>.
Mahlon E. Smith <mahlon@laika.com>
parents:
58
diff
changeset
|
1770 |
( $d_dn, $new_dn ) = ( $1, $2 ) if $d_dn =~ /^([\-\w=]+),(.*)$/; |
50 | 1771 |
if ( $new_dn ) { # absolute |
0 | 1772 |
unless ( $self->is_valid_dn( $new_dn ) ) { |
1773 |
print "Invalid destination.\n"; |
|
1774 |
return; |
|
1775 |
} |
|
1776 |
} |
|
50 | 1777 |
else { # relative |
0 | 1778 |
$new_dn = $self->base(); |
1779 |
} |
|
60
f90f7ff0b146
Fix the DN regexp to include dashes. Patch from Mike Hix <m@hix.io>.
Mahlon E. Smith <mahlon@laika.com>
parents:
58
diff
changeset
|
1780 |
$old_dn = $1 if $s_dn =~ /^[\-\w=]+,(.*)$/; |
0 | 1781 |
|
50 | 1782 |
# get the source entry object |
0 | 1783 |
my $e = ${ $s->{'entries'} }[0]; |
1784 |
$e->dn( $s_dn ); |
|
1785 |
||
1786 |
# add changes in new entry instead of modifying existing |
|
50 | 1787 |
$e->changetype( 'add' ); |
0 | 1788 |
$e->dn( "$d_dn,$new_dn" ); |
1789 |
||
1790 |
# get the unique attribute from the dn for modification |
|
1791 |
# perhaps there is a better way to do this...? |
|
1792 |
# |
|
1793 |
my ( $uniqkey, $uniqval ) = ( $1, $2 ) |
|
60
f90f7ff0b146
Fix the DN regexp to include dashes. Patch from Mike Hix <m@hix.io>.
Mahlon E. Smith <mahlon@laika.com>
parents:
58
diff
changeset
|
1794 |
if $d_dn =~ /^([\-\.\w]+)(?:\s+)?=(?:\s+)?([\-\.\s\w]+),?/; |
0 | 1795 |
unless ( $uniqkey && $uniqval ) { |
50 | 1796 |
print "Unable to parse unique values from RDN.\n"; |
0 | 1797 |
return; |
1798 |
} |
|
1799 |
$e->replace( $uniqkey => $uniqval ); |
|
1800 |
||
50 | 1801 |
# update (which will actually create the new entry) |
1802 |
# |
|
1803 |
my $update = sub { return $e->update($self->ldap()) }; |
|
1804 |
my $rv = $self->with_retry( $update ); |
|
1805 |
print $rv->error(), "\n"; |
|
0 | 1806 |
|
1807 |
# clear caches |
|
50 | 1808 |
# |
0 | 1809 |
$self->{'cache'}->{ $new_dn } = {} if $new_dn; |
1810 |
$self->{'cache'}->{ $old_dn } = {} if $old_dn; |
|
1811 |
$self->update_entries( clearcache => 1 ); |
|
1812 |
return; |
|
1813 |
} |
|
1814 |
||
50 | 1815 |
|
1816 |
### Create a new entry from scratch, using attributes from |
|
1817 |
### what the server's schema says is available from the specified |
|
1818 |
### (optional) objectClass list. Populate a new LDIF file and |
|
1819 |
### present an editor to the user. |
|
1820 |
### |
|
0 | 1821 |
sub run_create |
1822 |
{ |
|
1823 |
my $self = shift; |
|
1824 |
my @ocs = @_; |
|
1825 |
||
50 | 1826 |
# manually generate some boilerplate LDIF. |
0 | 1827 |
# |
50 | 1828 |
unless ( $self->{'create_file'} ) { |
1829 |
my $fh; |
|
1830 |
||
1831 |
( $fh, $self->{'create_file'} ) = |
|
58
94b64bbf93cf
Automatically use ldif syntax highlighting for editors that understand
Mahlon E. Smith <mahlon@laika.com>
parents:
57
diff
changeset
|
1832 |
File::Temp::tempfile( 'shelldap_XXXXXXXX', SUFFIX => '.ldif', DIR => '/tmp', UNLINK => 1 ); |
0 | 1833 |
|
50 | 1834 |
# first print out the dn and object classes. |
1835 |
# |
|
1836 |
print $fh 'dn: ???,', $self->base(), "\n"; |
|
1837 |
foreach my $oc ( sort @ocs ) { |
|
1838 |
print $fh "objectClass: $oc\n"; |
|
0 | 1839 |
} |
1840 |
||
50 | 1841 |
# gather and print attributes for requested objectClasses |
1842 |
# |
|
1843 |
my ( $must_attr, $may_attr ) = $self->fetch_attributes( \@ocs ); |
|
1844 |
print $fh "$_: \n" foreach @{ $must_attr }; |
|
1845 |
print $fh "# $_: \n" foreach @{ $may_attr }; |
|
1846 |
close $fh; |
|
0 | 1847 |
} |
1848 |
||
50 | 1849 |
# checksum the file. |
1850 |
# |
|
1851 |
my $hash_orig = $self->chksum( $self->{'create_file'} ); |
|
1852 |
system( $self->{'editor'}, $self->{'create_file'} ) && die "Unable to launch editor: $!\n"; |
|
0 | 1853 |
|
50 | 1854 |
# detect a total lack of change |
1855 |
# |
|
1856 |
if ( $hash_orig eq $self->chksum($self->{'create_file'}) ) { |
|
0 | 1857 |
print "Entry not modified.\n"; |
50 | 1858 |
unlink $self->{'create_file'}; |
1859 |
$self->{'create_file'} = undef; |
|
0 | 1860 |
return; |
1861 |
} |
|
1862 |
||
1863 |
# load in LDIF |
|
50 | 1864 |
# |
1865 |
my $ldif = Net::LDAP::LDIF->new( $self->{'create_file'}, 'r', onerror => 'warn' ); |
|
1866 |
my $e = $ldif->read_entry(); |
|
0 | 1867 |
unless ( $e ) { |
1868 |
print "Unable to parse LDIF.\n"; |
|
50 | 1869 |
unlink $self->{'create_file'}; |
1870 |
$self->{'create_file'} = undef; |
|
0 | 1871 |
return; |
1872 |
} |
|
50 | 1873 |
|
1874 |
# create the new entry. |
|
1875 |
# |
|
0 | 1876 |
$e->changetype('add'); |
48
fe27dfe5179e
More robust path for connection retries. Show optional, unused
Mahlon E. Smith <mahlon@laika.com>
parents:
46
diff
changeset
|
1877 |
my $create = sub { return $e->update($self->ldap()) }; |
fe27dfe5179e
More robust path for connection retries. Show optional, unused
Mahlon E. Smith <mahlon@laika.com>
parents:
46
diff
changeset
|
1878 |
my $rv = $self->with_retry( $create ); |
0 | 1879 |
print $rv->error(), "\n"; |
1880 |
||
50 | 1881 |
if ( $rv->code() != LDAP_SUCCESS && $self->prompt_edit_again() ) { |
1882 |
return $self->run_create(); |
|
1883 |
} |
|
0 | 1884 |
|
50 | 1885 |
$self->update_entries( clearcache => 1 ); |
1886 |
unlink $self->{'create_file'}; |
|
1887 |
$self->{'create_file'} = undef; |
|
0 | 1888 |
return; |
1889 |
} |
|
1890 |
||
50 | 1891 |
|
1892 |
### Remove an entry (or entries) from the LDAP directory. |
|
1893 |
### |
|
0 | 1894 |
sub run_delete |
1895 |
{ |
|
1896 |
my $self = shift; |
|
67
86e3374a40a3
Add 'rm' for a fully qualified DN, instead of only working with RDN.
Mahlon E. Smith <mahlon@laika.com>
parents:
62
diff
changeset
|
1897 |
my @args = @_; |
86e3374a40a3
Add 'rm' for a fully qualified DN, instead of only working with RDN.
Mahlon E. Smith <mahlon@laika.com>
parents:
62
diff
changeset
|
1898 |
my @matches; |
86e3374a40a3
Add 'rm' for a fully qualified DN, instead of only working with RDN.
Mahlon E. Smith <mahlon@laika.com>
parents:
62
diff
changeset
|
1899 |
my $s; |
86e3374a40a3
Add 'rm' for a fully qualified DN, instead of only working with RDN.
Mahlon E. Smith <mahlon@laika.com>
parents:
62
diff
changeset
|
1900 |
my $verbose; |
86e3374a40a3
Add 'rm' for a fully qualified DN, instead of only working with RDN.
Mahlon E. Smith <mahlon@laika.com>
parents:
62
diff
changeset
|
1901 |
|
86e3374a40a3
Add 'rm' for a fully qualified DN, instead of only working with RDN.
Mahlon E. Smith <mahlon@laika.com>
parents:
62
diff
changeset
|
1902 |
unless ( scalar @args ) { |
0 | 1903 |
print "No dn specified.\n"; |
1904 |
return; |
|
1905 |
} |
|
1906 |
||
67
86e3374a40a3
Add 'rm' for a fully qualified DN, instead of only working with RDN.
Mahlon E. Smith <mahlon@laika.com>
parents:
62
diff
changeset
|
1907 |
# Flags. |
86e3374a40a3
Add 'rm' for a fully qualified DN, instead of only working with RDN.
Mahlon E. Smith <mahlon@laika.com>
parents:
62
diff
changeset
|
1908 |
# |
86e3374a40a3
Add 'rm' for a fully qualified DN, instead of only working with RDN.
Mahlon E. Smith <mahlon@laika.com>
parents:
62
diff
changeset
|
1909 |
if ( $args[0] =~ /^\-v/ ) { |
86e3374a40a3
Add 'rm' for a fully qualified DN, instead of only working with RDN.
Mahlon E. Smith <mahlon@laika.com>
parents:
62
diff
changeset
|
1910 |
$verbose = 1; |
86e3374a40a3
Add 'rm' for a fully qualified DN, instead of only working with RDN.
Mahlon E. Smith <mahlon@laika.com>
parents:
62
diff
changeset
|
1911 |
shift @args; |
6
46dfe9d6f368
Update documentation, now that multiline edits work. Minor other
Mahlon E. Smith <mahlon@laika.com>
parents:
5
diff
changeset
|
1912 |
} |
67
86e3374a40a3
Add 'rm' for a fully qualified DN, instead of only working with RDN.
Mahlon E. Smith <mahlon@laika.com>
parents:
62
diff
changeset
|
1913 |
|
86e3374a40a3
Add 'rm' for a fully qualified DN, instead of only working with RDN.
Mahlon E. Smith <mahlon@laika.com>
parents:
62
diff
changeset
|
1914 |
# Separate real args from filter arguments. |
86e3374a40a3
Add 'rm' for a fully qualified DN, instead of only working with RDN.
Mahlon E. Smith <mahlon@laika.com>
parents:
62
diff
changeset
|
1915 |
# |
86e3374a40a3
Add 'rm' for a fully qualified DN, instead of only working with RDN.
Mahlon E. Smith <mahlon@laika.com>
parents:
62
diff
changeset
|
1916 |
foreach my $dn ( @args ) { |
86e3374a40a3
Add 'rm' for a fully qualified DN, instead of only working with RDN.
Mahlon E. Smith <mahlon@laika.com>
parents:
62
diff
changeset
|
1917 |
if ( $dn eq '*' ) { |
86e3374a40a3
Add 'rm' for a fully qualified DN, instead of only working with RDN.
Mahlon E. Smith <mahlon@laika.com>
parents:
62
diff
changeset
|
1918 |
$s = $self->search({ scope => 'one' }); |
86e3374a40a3
Add 'rm' for a fully qualified DN, instead of only working with RDN.
Mahlon E. Smith <mahlon@laika.com>
parents:
62
diff
changeset
|
1919 |
map { push @matches, $_ } @{ $s->{'entries'} } if $s->{'code'} == LDAP_SUCCESS; |
86e3374a40a3
Add 'rm' for a fully qualified DN, instead of only working with RDN.
Mahlon E. Smith <mahlon@laika.com>
parents:
62
diff
changeset
|
1920 |
} |
86e3374a40a3
Add 'rm' for a fully qualified DN, instead of only working with RDN.
Mahlon E. Smith <mahlon@laika.com>
parents:
62
diff
changeset
|
1921 |
|
86e3374a40a3
Add 'rm' for a fully qualified DN, instead of only working with RDN.
Mahlon E. Smith <mahlon@laika.com>
parents:
62
diff
changeset
|
1922 |
# Search by filter |
86e3374a40a3
Add 'rm' for a fully qualified DN, instead of only working with RDN.
Mahlon E. Smith <mahlon@laika.com>
parents:
62
diff
changeset
|
1923 |
# |
86e3374a40a3
Add 'rm' for a fully qualified DN, instead of only working with RDN.
Mahlon E. Smith <mahlon@laika.com>
parents:
62
diff
changeset
|
1924 |
else { |
86e3374a40a3
Add 'rm' for a fully qualified DN, instead of only working with RDN.
Mahlon E. Smith <mahlon@laika.com>
parents:
62
diff
changeset
|
1925 |
|
86e3374a40a3
Add 'rm' for a fully qualified DN, instead of only working with RDN.
Mahlon E. Smith <mahlon@laika.com>
parents:
62
diff
changeset
|
1926 |
my $filter = $self->make_filter( [$dn] ) or next; |
86e3374a40a3
Add 'rm' for a fully qualified DN, instead of only working with RDN.
Mahlon E. Smith <mahlon@laika.com>
parents:
62
diff
changeset
|
1927 |
$s = $self->search({ scope => 'one', filter => $filter }); |
86e3374a40a3
Add 'rm' for a fully qualified DN, instead of only working with RDN.
Mahlon E. Smith <mahlon@laika.com>
parents:
62
diff
changeset
|
1928 |
if ( scalar @{$s->{'entries'}} != 0 ) { |
86e3374a40a3
Add 'rm' for a fully qualified DN, instead of only working with RDN.
Mahlon E. Smith <mahlon@laika.com>
parents:
62
diff
changeset
|
1929 |
map { push @matches, $_ } @{ $s->{'entries'} } if $s->{'code'} == LDAP_SUCCESS; |
86e3374a40a3
Add 'rm' for a fully qualified DN, instead of only working with RDN.
Mahlon E. Smith <mahlon@laika.com>
parents:
62
diff
changeset
|
1930 |
} |
86e3374a40a3
Add 'rm' for a fully qualified DN, instead of only working with RDN.
Mahlon E. Smith <mahlon@laika.com>
parents:
62
diff
changeset
|
1931 |
|
86e3374a40a3
Add 'rm' for a fully qualified DN, instead of only working with RDN.
Mahlon E. Smith <mahlon@laika.com>
parents:
62
diff
changeset
|
1932 |
# Search by exact DN. |
86e3374a40a3
Add 'rm' for a fully qualified DN, instead of only working with RDN.
Mahlon E. Smith <mahlon@laika.com>
parents:
62
diff
changeset
|
1933 |
# |
86e3374a40a3
Add 'rm' for a fully qualified DN, instead of only working with RDN.
Mahlon E. Smith <mahlon@laika.com>
parents:
62
diff
changeset
|
1934 |
else { |
86e3374a40a3
Add 'rm' for a fully qualified DN, instead of only working with RDN.
Mahlon E. Smith <mahlon@laika.com>
parents:
62
diff
changeset
|
1935 |
$dn = $self->path_to_dn( $dn ); |
86e3374a40a3
Add 'rm' for a fully qualified DN, instead of only working with RDN.
Mahlon E. Smith <mahlon@laika.com>
parents:
62
diff
changeset
|
1936 |
$s = $self->search({ base => $dn, vals => 0 }); |
86e3374a40a3
Add 'rm' for a fully qualified DN, instead of only working with RDN.
Mahlon E. Smith <mahlon@laika.com>
parents:
62
diff
changeset
|
1937 |
my $e = ${ $s->{'entries'} }[0]; |
86e3374a40a3
Add 'rm' for a fully qualified DN, instead of only working with RDN.
Mahlon E. Smith <mahlon@laika.com>
parents:
62
diff
changeset
|
1938 |
push @matches, $e if $s->{'code'} == LDAP_SUCCESS; |
86e3374a40a3
Add 'rm' for a fully qualified DN, instead of only working with RDN.
Mahlon E. Smith <mahlon@laika.com>
parents:
62
diff
changeset
|
1939 |
} |
86e3374a40a3
Add 'rm' for a fully qualified DN, instead of only working with RDN.
Mahlon E. Smith <mahlon@laika.com>
parents:
62
diff
changeset
|
1940 |
} |
86e3374a40a3
Add 'rm' for a fully qualified DN, instead of only working with RDN.
Mahlon E. Smith <mahlon@laika.com>
parents:
62
diff
changeset
|
1941 |
} |
86e3374a40a3
Add 'rm' for a fully qualified DN, instead of only working with RDN.
Mahlon E. Smith <mahlon@laika.com>
parents:
62
diff
changeset
|
1942 |
|
86e3374a40a3
Add 'rm' for a fully qualified DN, instead of only working with RDN.
Mahlon E. Smith <mahlon@laika.com>
parents:
62
diff
changeset
|
1943 |
# Unique the matchset for a consistent count, keyed by DN. |
86e3374a40a3
Add 'rm' for a fully qualified DN, instead of only working with RDN.
Mahlon E. Smith <mahlon@laika.com>
parents:
62
diff
changeset
|
1944 |
# |
86e3374a40a3
Add 'rm' for a fully qualified DN, instead of only working with RDN.
Mahlon E. Smith <mahlon@laika.com>
parents:
62
diff
changeset
|
1945 |
my @uniq_matches = keys %{{ map { $_->dn => 1 } @matches }}; |
86e3374a40a3
Add 'rm' for a fully qualified DN, instead of only working with RDN.
Mahlon E. Smith <mahlon@laika.com>
parents:
62
diff
changeset
|
1946 |
|
86e3374a40a3
Add 'rm' for a fully qualified DN, instead of only working with RDN.
Mahlon E. Smith <mahlon@laika.com>
parents:
62
diff
changeset
|
1947 |
my $mcount = scalar @uniq_matches; |
86e3374a40a3
Add 'rm' for a fully qualified DN, instead of only working with RDN.
Mahlon E. Smith <mahlon@laika.com>
parents:
62
diff
changeset
|
1948 |
if ( $mcount == 0 ) { |
86e3374a40a3
Add 'rm' for a fully qualified DN, instead of only working with RDN.
Mahlon E. Smith <mahlon@laika.com>
parents:
62
diff
changeset
|
1949 |
print "Nothing matched.\n"; |
0 | 1950 |
return; |
1951 |
} |
|
1952 |
||
67
86e3374a40a3
Add 'rm' for a fully qualified DN, instead of only working with RDN.
Mahlon E. Smith <mahlon@laika.com>
parents:
62
diff
changeset
|
1953 |
if ( $verbose ) { |
86e3374a40a3
Add 'rm' for a fully qualified DN, instead of only working with RDN.
Mahlon E. Smith <mahlon@laika.com>
parents:
62
diff
changeset
|
1954 |
print "* $_\n" foreach @uniq_matches; |
86e3374a40a3
Add 'rm' for a fully qualified DN, instead of only working with RDN.
Mahlon E. Smith <mahlon@laika.com>
parents:
62
diff
changeset
|
1955 |
} |
86e3374a40a3
Add 'rm' for a fully qualified DN, instead of only working with RDN.
Mahlon E. Smith <mahlon@laika.com>
parents:
62
diff
changeset
|
1956 |
|
86e3374a40a3
Add 'rm' for a fully qualified DN, instead of only working with RDN.
Mahlon E. Smith <mahlon@laika.com>
parents:
62
diff
changeset
|
1957 |
print "About to remove $mcount item(s). Are you sure? [Ny]: "; |
0 | 1958 |
chomp( my $resp = <STDIN> ); |
1959 |
return unless $resp =~ /^y/i; |
|
67
86e3374a40a3
Add 'rm' for a fully qualified DN, instead of only working with RDN.
Mahlon E. Smith <mahlon@laika.com>
parents:
62
diff
changeset
|
1960 |
|
86e3374a40a3
Add 'rm' for a fully qualified DN, instead of only working with RDN.
Mahlon E. Smith <mahlon@laika.com>
parents:
62
diff
changeset
|
1961 |
my %seen; |
86e3374a40a3
Add 'rm' for a fully qualified DN, instead of only working with RDN.
Mahlon E. Smith <mahlon@laika.com>
parents:
62
diff
changeset
|
1962 |
foreach my $e ( @matches ) { |
0 | 1963 |
my $dn = $e->dn(); |
67
86e3374a40a3
Add 'rm' for a fully qualified DN, instead of only working with RDN.
Mahlon E. Smith <mahlon@laika.com>
parents:
62
diff
changeset
|
1964 |
next if $seen{ $dn }; |
0 | 1965 |
my $rv = $self->ldap->delete( $dn ); |
67
86e3374a40a3
Add 'rm' for a fully qualified DN, instead of only working with RDN.
Mahlon E. Smith <mahlon@laika.com>
parents:
62
diff
changeset
|
1966 |
$seen{ $dn }++; |
0 | 1967 |
print "$dn: ", $rv->error(), "\n"; |
1968 |
} |
|
1969 |
||
1970 |
$self->update_entries( clearcache => 1 ); |
|
1971 |
return; |
|
1972 |
} |
|
1973 |
||
50 | 1974 |
|
1975 |
### Fetch an entry from the directory, write it out to disk |
|
1976 |
### as LDIF, launch an editor, then compare changes and write |
|
1977 |
### it back to the directory. |
|
1978 |
### |
|
0 | 1979 |
sub run_edit |
1980 |
{ |
|
1981 |
my $self = shift; |
|
41
3e7c107f8b93
Take only second argument for run_{cd,edit,mkdir}
Salvatore Bonaccorso <carnil@debian.org>
parents:
40
diff
changeset
|
1982 |
my $dn = shift; |
0 | 1983 |
|
1984 |
unless ( $dn ) { |
|
1985 |
print "No dn provided.\n"; |
|
1986 |
return; |
|
1987 |
} |
|
1988 |
||
31
a3a710f720dd
run_cat: convert to using path_to_dn()
Peter Marschall <peter@adpm.de>
parents:
30
diff
changeset
|
1989 |
# convert given path to DN |
33
057fefab56b0
Repair broken path behavior, remove unneeded #path_to_dn 'relative'
Mahlon E. Smith <mahlon@martini.nu>
parents:
32
diff
changeset
|
1990 |
$dn = $self->path_to_dn( $dn ); |
0 | 1991 |
|
50 | 1992 |
# sanity check |
1993 |
# |
|
0 | 1994 |
my $s = $self->search({ base => $dn, vals => 1 }); |
50 | 1995 |
unless ( $s->{'code'} == LDAP_SUCCESS ) { |
0 | 1996 |
print $s->{'message'} . "\n"; |
1997 |
return; |
|
1998 |
} |
|
1999 |
||
50 | 2000 |
# fetch entry. |
0 | 2001 |
my $e = ${ $s->{'entries'} }[0]; |
50 | 2002 |
$e->changetype( 'modify' ); |
2003 |
||
2004 |
# write it out to disk. |
|
2005 |
# |
|
2006 |
unless( $self->{'edit_again'} ) { |
|
2007 |
my $ldif = $self->ldif(1); |
|
2008 |
$ldif->write_entry( $e ); |
|
2009 |
$ldif->done(); # force sync |
|
2010 |
} |
|
0 | 2011 |
|
2012 |
# load it into an array for potential comparison |
|
118
2d7f16eff198
Use local implementation of slurp()
Davor Ocelic <docelic@crystallabs.io>
parents:
117
diff
changeset
|
2013 |
open LDIF, "$self->{'ldif_fname'}"; |
6
46dfe9d6f368
Update documentation, now that multiline edits work. Minor other
Mahlon E. Smith <mahlon@laika.com>
parents:
5
diff
changeset
|
2014 |
my @orig_ldif = <LDIF>; |
0 | 2015 |
close LDIF; |
2016 |
||
50 | 2017 |
# append optional, unused attributes as comments for fast reference. |
48
fe27dfe5179e
More robust path for connection retries. Show optional, unused
Mahlon E. Smith <mahlon@laika.com>
parents:
46
diff
changeset
|
2018 |
# |
50 | 2019 |
unless ( $self->{'edit_again'} ) { |
2020 |
my %current_attrs = map { $_ => 1 } $e->attributes(); |
|
2021 |
my ( $must_attr, $may_attr ) = $self->fetch_attributes( $e->get_value('objectClass', asref => 1) ); |
|
2022 |
||
2023 |
open LDIF, ">> $self->{'ldif_fname'}"; |
|
2024 |
foreach my $opt_attr ( sort { $a cmp $b } @{$may_attr} ) { |
|
2025 |
next if $current_attrs{ $opt_attr }; |
|
2026 |
print LDIF "# " . $opt_attr . ":\n"; |
|
48
fe27dfe5179e
More robust path for connection retries. Show optional, unused
Mahlon E. Smith <mahlon@laika.com>
parents:
46
diff
changeset
|
2027 |
} |
50 | 2028 |
close LDIF; |
48
fe27dfe5179e
More robust path for connection retries. Show optional, unused
Mahlon E. Smith <mahlon@laika.com>
parents:
46
diff
changeset
|
2029 |
} |
fe27dfe5179e
More robust path for connection retries. Show optional, unused
Mahlon E. Smith <mahlon@laika.com>
parents:
46
diff
changeset
|
2030 |
|
0 | 2031 |
# checksum it, then open it in an editor |
50 | 2032 |
# |
2033 |
my $hash_orig = $self->chksum( $self->{'ldif_fname'} ); |
|
81
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
2034 |
my @edit_args = split /\s+/, $self->{'editor'}; |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
2035 |
push @edit_args, $self->{'ldif_fname'}; |
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
2036 |
system( @edit_args ) && die "Unable to launch editor: $!\n"; |
0 | 2037 |
|
2038 |
# detect a total lack of change |
|
50 | 2039 |
# |
2040 |
if ( $hash_orig eq $self->chksum($self->{'ldif_fname'}) ) { |
|
0 | 2041 |
print "Entry not modified.\n"; |
2042 |
unlink $self->{'ldif_fname'}; |
|
54
0cc20d93ff50
Fix for edge case Diff::LCS traversals. Also ensure re-edit state is
Mahlon E. Smith <mahlon@laika.com>
parents:
51
diff
changeset
|
2043 |
$self->{'edit_again'} = undef; |
0 | 2044 |
return; |
2045 |
} |
|
2046 |
||
2047 |
# check changes for basic LDIF validity |
|
50 | 2048 |
# |
2049 |
while( ! $self->load_ldif($self->{'ldif_fname'}) ) { |
|
0 | 2050 |
print "Unable to parse LDIF.\n"; |
50 | 2051 |
if ( $self->prompt_edit_again() ) { |
2052 |
system( $self->{'editor'}, $self->{'ldif_fname'} ); |
|
2053 |
} |
|
2054 |
else { |
|
2055 |
unlink $self->{'ldif_fname'}; |
|
54
0cc20d93ff50
Fix for edge case Diff::LCS traversals. Also ensure re-edit state is
Mahlon E. Smith <mahlon@laika.com>
parents:
51
diff
changeset
|
2056 |
$self->{'edit_again'} = undef; |
50 | 2057 |
return; |
2058 |
} |
|
0 | 2059 |
} |
2060 |
||
2061 |
# load changes into a new array for comparison |
|
50 | 2062 |
# |
118
2d7f16eff198
Use local implementation of slurp()
Davor Ocelic <docelic@crystallabs.io>
parents:
117
diff
changeset
|
2063 |
open LDIF, "$self->{'ldif_fname'}"; |
6
46dfe9d6f368
Update documentation, now that multiline edits work. Minor other
Mahlon E. Smith <mahlon@laika.com>
parents:
5
diff
changeset
|
2064 |
my @new_ldif = <LDIF>; |
0 | 2065 |
close LDIF; |
2066 |
||
81
c39a13f112b6
Break LCS diffing to its own function. Minor style tweaks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
80
diff
changeset
|
2067 |
$self->diff( $e, \@orig_ldif, \@new_ldif ); |
0 | 2068 |
|
48
fe27dfe5179e
More robust path for connection retries. Show optional, unused
Mahlon E. Smith <mahlon@laika.com>
parents:
46
diff
changeset
|
2069 |
my $update = sub { return $e->update( $self->ldap ); }; |
fe27dfe5179e
More robust path for connection retries. Show optional, unused
Mahlon E. Smith <mahlon@laika.com>
parents:
46
diff
changeset
|
2070 |
my $rv = $self->with_retry( $update ); |
0 | 2071 |
print $rv->error(), "\n"; |
2072 |
||
50 | 2073 |
if ( $rv->code() != LDAP_SUCCESS && $self->prompt_edit_again() ) { |
2074 |
$self->{'edit_again'} = 1; |
|
2075 |
return $self->run_edit( $dn ); |
|
2076 |
} |
|
2077 |
||
2078 |
unlink $self->{'ldif_fname'}; |
|
2079 |
$self->{'edit_again'} = undef; |
|
0 | 2080 |
return; |
2081 |
} |
|
2082 |
||
50 | 2083 |
|
2084 |
### Display current tunable runtime settings. |
|
2085 |
### |
|
0 | 2086 |
sub run_env |
2087 |
{ |
|
2088 |
my $self = shift; |
|
2089 |
||
116
6a0b1209dafa
Support arrays/hashes in 'env' (WIP)
Davor Ocelic <docelic@crystallabs.io>
parents:
115
diff
changeset
|
2090 |
print YAML::Syck::Dump( { map { $_, $conf->{$_}} sort @{ $self->{'env'}} } ); |
6a0b1209dafa
Support arrays/hashes in 'env' (WIP)
Davor Ocelic <docelic@crystallabs.io>
parents:
115
diff
changeset
|
2091 |
print "\n" |
0 | 2092 |
} |
2093 |
||
50 | 2094 |
|
2095 |
### Alter settings. |
|
2096 |
### |
|
2097 |
sub run_setenv |
|
2098 |
{ |
|
2099 |
my $self = shift; |
|
2100 |
my ( $key, $val ) = @_; |
|
2101 |
||
2102 |
( $key, $val ) = split /=/, $key if $key && ! defined $val; |
|
2103 |
return unless $key && defined $val; |
|
2104 |
$key = lc $key; |
|
2105 |
||
2106 |
$conf->{$key} = $val; |
|
2107 |
return; |
|
2108 |
} |
|
2109 |
||
2110 |
||
2111 |
### Search across the directory and display matching entries. |
|
2112 |
### |
|
0 | 2113 |
sub run_grep |
2114 |
{ |
|
2115 |
my $self = shift; |
|
2116 |
my ( $recurse, $filter, $base ) = @_; |
|
2117 |
||
2118 |
# set 'recursion' |
|
2119 |
unless ( $recurse && $recurse =~ /\-r|recurse/ ) { |
|
2120 |
# shift args to the left |
|
2121 |
( $recurse, $filter, $base ) = ( undef, $recurse, $filter ); |
|
2122 |
} |
|
2123 |
||
2124 |
$filter = Net::LDAP::Filter->new( $filter ); |
|
2125 |
unless ( $filter ) { |
|
2126 |
print "Invalid search filter.\n"; |
|
2127 |
return; |
|
2128 |
} |
|
2129 |
||
2130 |
# support '*' |
|
2131 |
$base = $self->base() if ! $base or $base eq '*'; |
|
2132 |
||
2133 |
unless ( $base ) { |
|
2134 |
print "No search base specified.\n"; |
|
2135 |
return; |
|
2136 |
} |
|
33
057fefab56b0
Repair broken path behavior, remove unneeded #path_to_dn 'relative'
Mahlon E. Smith <mahlon@martini.nu>
parents:
32
diff
changeset
|
2137 |
|
31
a3a710f720dd
run_cat: convert to using path_to_dn()
Peter Marschall <peter@adpm.de>
parents:
30
diff
changeset
|
2138 |
# convert base path to DN |
33
057fefab56b0
Repair broken path behavior, remove unneeded #path_to_dn 'relative'
Mahlon E. Smith <mahlon@martini.nu>
parents:
32
diff
changeset
|
2139 |
$base = $self->path_to_dn( $base ); |
0 | 2140 |
|
2141 |
$self->debug("Filter parsed as: " . $filter->as_string() . "\n"); |
|
2142 |
||
50 | 2143 |
my $s = $self->search({ |
2144 |
scope => $recurse ? 'sub' : 'one', |
|
2145 |
base => $base, |
|
2146 |
filter => $filter |
|
2147 |
}); |
|
0 | 2148 |
|
2149 |
foreach my $e ( @{ $s->{'entries'} } ) { |
|
2150 |
my $dn = $e->dn(); |
|
2151 |
print "$dn\n"; |
|
2152 |
} |
|
2153 |
||
2154 |
return; |
|
2155 |
} |
|
2156 |
||
50 | 2157 |
|
2158 |
### Generate and display a list of LDAP entries, relative to the current |
|
2159 |
### location the command was run from. |
|
2160 |
### |
|
0 | 2161 |
sub run_list |
2162 |
{ |
|
34
40c3719c87d4
fix 'ls -R' output, minor style cleanup
Mahlon E. Smith <mahlon@martini.nu>
parents:
33
diff
changeset
|
2163 |
my $self = shift; |
40c3719c87d4
fix 'ls -R' output, minor style cleanup
Mahlon E. Smith <mahlon@martini.nu>
parents:
33
diff
changeset
|
2164 |
my @args = @_; |
27
7d170d1bc17b
run_list: new argument syntax: [<options>] [<filter>] [<attributes>]
Peter Marschall <peter@adpm.de>
parents:
26
diff
changeset
|
2165 |
my @attrs = (); |
34
40c3719c87d4
fix 'ls -R' output, minor style cleanup
Mahlon E. Smith <mahlon@martini.nu>
parents:
33
diff
changeset
|
2166 |
my $filter; |
40c3719c87d4
fix 'ls -R' output, minor style cleanup
Mahlon E. Smith <mahlon@martini.nu>
parents:
33
diff
changeset
|
2167 |
|
40c3719c87d4
fix 'ls -R' output, minor style cleanup
Mahlon E. Smith <mahlon@martini.nu>
parents:
33
diff
changeset
|
2168 |
# flag booleans |
114
35b7143830e8
With ls -l, print file type ('-' or 'd') as first field of output
Davor Ocelic <docelic@crystallabs.io>
parents:
113
diff
changeset
|
2169 |
my ( $recurse, $long, $all ); |
27
7d170d1bc17b
run_list: new argument syntax: [<options>] [<filter>] [<attributes>]
Peter Marschall <peter@adpm.de>
parents:
26
diff
changeset
|
2170 |
|
7d170d1bc17b
run_list: new argument syntax: [<options>] [<filter>] [<attributes>]
Peter Marschall <peter@adpm.de>
parents:
26
diff
changeset
|
2171 |
# parse arguments: [ <option> ...] [<filter> ...] [<attribute> ...] |
50 | 2172 |
# |
34
40c3719c87d4
fix 'ls -R' output, minor style cleanup
Mahlon E. Smith <mahlon@martini.nu>
parents:
33
diff
changeset
|
2173 |
if ( scalar @args ) { |
27
7d170d1bc17b
run_list: new argument syntax: [<options>] [<filter>] [<attributes>]
Peter Marschall <peter@adpm.de>
parents:
26
diff
changeset
|
2174 |
# options: support '-l' or '-R' listings |
34
40c3719c87d4
fix 'ls -R' output, minor style cleanup
Mahlon E. Smith <mahlon@martini.nu>
parents:
33
diff
changeset
|
2175 |
if ( $args[0] =~ /^\-(\w+)/o ) { |
40c3719c87d4
fix 'ls -R' output, minor style cleanup
Mahlon E. Smith <mahlon@martini.nu>
parents:
33
diff
changeset
|
2176 |
my $flags = $1; |
40c3719c87d4
fix 'ls -R' output, minor style cleanup
Mahlon E. Smith <mahlon@martini.nu>
parents:
33
diff
changeset
|
2177 |
$recurse = $flags =~ /R/; |
40c3719c87d4
fix 'ls -R' output, minor style cleanup
Mahlon E. Smith <mahlon@martini.nu>
parents:
33
diff
changeset
|
2178 |
$long = $flags =~ /l/; |
114
35b7143830e8
With ls -l, print file type ('-' or 'd') as first field of output
Davor Ocelic <docelic@crystallabs.io>
parents:
113
diff
changeset
|
2179 |
$all = $flags =~ /a/; |
34
40c3719c87d4
fix 'ls -R' output, minor style cleanup
Mahlon E. Smith <mahlon@martini.nu>
parents:
33
diff
changeset
|
2180 |
shift( @args ); |
27
7d170d1bc17b
run_list: new argument syntax: [<options>] [<filter>] [<attributes>]
Peter Marschall <peter@adpm.de>
parents:
26
diff
changeset
|
2181 |
} |
0 | 2182 |
|
27
7d170d1bc17b
run_list: new argument syntax: [<options>] [<filter>] [<attributes>]
Peter Marschall <peter@adpm.de>
parents:
26
diff
changeset
|
2183 |
my @filters; |
7d170d1bc17b
run_list: new argument syntax: [<options>] [<filter>] [<attributes>]
Peter Marschall <peter@adpm.de>
parents:
26
diff
changeset
|
2184 |
|
7d170d1bc17b
run_list: new argument syntax: [<options>] [<filter>] [<attributes>]
Peter Marschall <peter@adpm.de>
parents:
26
diff
changeset
|
2185 |
# get filter elements from argument list |
50 | 2186 |
# |
34
40c3719c87d4
fix 'ls -R' output, minor style cleanup
Mahlon E. Smith <mahlon@martini.nu>
parents:
33
diff
changeset
|
2187 |
while ( @args && $self->is_valid_filter($args[0]) ) { |
40c3719c87d4
fix 'ls -R' output, minor style cleanup
Mahlon E. Smith <mahlon@martini.nu>
parents:
33
diff
changeset
|
2188 |
push( @filters, shift(@args) ); |
0 | 2189 |
} |
27
7d170d1bc17b
run_list: new argument syntax: [<options>] [<filter>] [<attributes>]
Peter Marschall <peter@adpm.de>
parents:
26
diff
changeset
|
2190 |
|
50 | 2191 |
# No filter for display? Default to all entries. |
34
40c3719c87d4
fix 'ls -R' output, minor style cleanup
Mahlon E. Smith <mahlon@martini.nu>
parents:
33
diff
changeset
|
2192 |
push( @filters, '(objectClass=*)' ) unless scalar @filters; |
0 | 2193 |
|
27
7d170d1bc17b
run_list: new argument syntax: [<options>] [<filter>] [<attributes>]
Peter Marschall <peter@adpm.de>
parents:
26
diff
changeset
|
2194 |
# construct OR'ed filter from filter elements |
0 | 2195 |
$filter = $self->make_filter( \@filters ); |
27
7d170d1bc17b
run_list: new argument syntax: [<options>] [<filter>] [<attributes>]
Peter Marschall <peter@adpm.de>
parents:
26
diff
changeset
|
2196 |
|
7d170d1bc17b
run_list: new argument syntax: [<options>] [<filter>] [<attributes>]
Peter Marschall <peter@adpm.de>
parents:
26
diff
changeset
|
2197 |
# remaining arguments must be attributes |
34
40c3719c87d4
fix 'ls -R' output, minor style cleanup
Mahlon E. Smith <mahlon@martini.nu>
parents:
33
diff
changeset
|
2198 |
push( @attrs, @args ); |
0 | 2199 |
} |
2200 |
||
34
40c3719c87d4
fix 'ls -R' output, minor style cleanup
Mahlon E. Smith <mahlon@martini.nu>
parents:
33
diff
changeset
|
2201 |
# Get all attributes if none are specified, and we're in long-list mode. |
40c3719c87d4
fix 'ls -R' output, minor style cleanup
Mahlon E. Smith <mahlon@martini.nu>
parents:
33
diff
changeset
|
2202 |
push( @attrs, '*' ) if $long && ! scalar @attrs; |
0 | 2203 |
|
4
5a65bc849363
Append a trailing slash to entries that contain other entries. Thanks
Mahlon E. Smith <mahlon@martini.nu>
parents:
3
diff
changeset
|
2204 |
my $s = $self->search({ |
5a65bc849363
Append a trailing slash to entries that contain other entries. Thanks
Mahlon E. Smith <mahlon@martini.nu>
parents:
3
diff
changeset
|
2205 |
scope => $recurse ? 'sub' : 'one', |
5a65bc849363
Append a trailing slash to entries that contain other entries. Thanks
Mahlon E. Smith <mahlon@martini.nu>
parents:
3
diff
changeset
|
2206 |
vals => 1, |
5a65bc849363
Append a trailing slash to entries that contain other entries. Thanks
Mahlon E. Smith <mahlon@martini.nu>
parents:
3
diff
changeset
|
2207 |
filter => $filter, |
27
7d170d1bc17b
run_list: new argument syntax: [<options>] [<filter>] [<attributes>]
Peter Marschall <peter@adpm.de>
parents:
26
diff
changeset
|
2208 |
attrs => [ @attrs, 'hasSubordinates' ] |
4
5a65bc849363
Append a trailing slash to entries that contain other entries. Thanks
Mahlon E. Smith <mahlon@martini.nu>
parents:
3
diff
changeset
|
2209 |
}); |
0 | 2210 |
if ( $s->{'code'} ) { |
2211 |
print "$s->{'message'}\n"; |
|
2212 |
return; |
|
2213 |
} |
|
2214 |
||
2215 |
# if an entry doesn't have a description field, |
|
2216 |
# try and show some nice defaults for ls -l ! |
|
2217 |
# |
|
2218 |
# objectClass -> Attribute to show |
|
2219 |
# |
|
2220 |
my %descs = %{ |
|
2221 |
$conf->{'descmaps'} |
|
2222 |
|| { |
|
2223 |
posixAccount => 'gecos', |
|
2224 |
posixGroup => 'gidNumber', |
|
4
5a65bc849363
Append a trailing slash to entries that contain other entries. Thanks
Mahlon E. Smith <mahlon@martini.nu>
parents:
3
diff
changeset
|
2225 |
ipHost => 'ipHostNumber', |
0 | 2226 |
} |
2227 |
}; |
|
2228 |
||
2229 |
# iterate and print |
|
2230 |
# |
|
2231 |
my $dn_count = 0; |
|
34
40c3719c87d4
fix 'ls -R' output, minor style cleanup
Mahlon E. Smith <mahlon@martini.nu>
parents:
33
diff
changeset
|
2232 |
my $base = $self->base(); |
0 | 2233 |
foreach my $e ( sort { $a->dn() cmp $b->dn() } @{ $s->{'entries'} } ) { |
27
7d170d1bc17b
run_list: new argument syntax: [<options>] [<filter>] [<attributes>]
Peter Marschall <peter@adpm.de>
parents:
26
diff
changeset
|
2234 |
my $dn = $e->dn(); |
114
35b7143830e8
With ls -l, print file type ('-' or 'd') as first field of output
Davor Ocelic <docelic@crystallabs.io>
parents:
113
diff
changeset
|
2235 |
|
35b7143830e8
With ls -l, print file type ('-' or 'd') as first field of output
Davor Ocelic <docelic@crystallabs.io>
parents:
113
diff
changeset
|
2236 |
# Later, turn this into '.' and '..' display |
35b7143830e8
With ls -l, print file type ('-' or 'd') as first field of output
Davor Ocelic <docelic@crystallabs.io>
parents:
113
diff
changeset
|
2237 |
unless($all) { |
35b7143830e8
With ls -l, print file type ('-' or 'd') as first field of output
Davor Ocelic <docelic@crystallabs.io>
parents:
113
diff
changeset
|
2238 |
next if lc( $dn ) eq lc( $base ); |
35b7143830e8
With ls -l, print file type ('-' or 'd') as first field of output
Davor Ocelic <docelic@crystallabs.io>
parents:
113
diff
changeset
|
2239 |
} |
27
7d170d1bc17b
run_list: new argument syntax: [<options>] [<filter>] [<attributes>]
Peter Marschall <peter@adpm.de>
parents:
26
diff
changeset
|
2240 |
|
34
40c3719c87d4
fix 'ls -R' output, minor style cleanup
Mahlon E. Smith <mahlon@martini.nu>
parents:
33
diff
changeset
|
2241 |
if ( ! $long ) { |
40c3719c87d4
fix 'ls -R' output, minor style cleanup
Mahlon E. Smith <mahlon@martini.nu>
parents:
33
diff
changeset
|
2242 |
# strip the current base from the dn, if we're recursing and not in long mode |
40c3719c87d4
fix 'ls -R' output, minor style cleanup
Mahlon E. Smith <mahlon@martini.nu>
parents:
33
diff
changeset
|
2243 |
if ( $recurse ) { |
40c3719c87d4
fix 'ls -R' output, minor style cleanup
Mahlon E. Smith <mahlon@martini.nu>
parents:
33
diff
changeset
|
2244 |
$dn =~ s/,$base//oi; |
40c3719c87d4
fix 'ls -R' output, minor style cleanup
Mahlon E. Smith <mahlon@martini.nu>
parents:
33
diff
changeset
|
2245 |
# only show RDN unless -l was given |
115
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
2246 |
} else { |
34
40c3719c87d4
fix 'ls -R' output, minor style cleanup
Mahlon E. Smith <mahlon@martini.nu>
parents:
33
diff
changeset
|
2247 |
$dn = canonical_dn( [shift(@{ldap_explode_dn($dn, casefold => 'none')})], casefold => 'none' ) |
40c3719c87d4
fix 'ls -R' output, minor style cleanup
Mahlon E. Smith <mahlon@martini.nu>
parents:
33
diff
changeset
|
2248 |
} |
40c3719c87d4
fix 'ls -R' output, minor style cleanup
Mahlon E. Smith <mahlon@martini.nu>
parents:
33
diff
changeset
|
2249 |
} |
4
5a65bc849363
Append a trailing slash to entries that contain other entries. Thanks
Mahlon E. Smith <mahlon@martini.nu>
parents:
3
diff
changeset
|
2250 |
|
114
35b7143830e8
With ls -l, print file type ('-' or 'd') as first field of output
Davor Ocelic <docelic@crystallabs.io>
parents:
113
diff
changeset
|
2251 |
my $type = '-'; # Assume the entry is a leaf |
35b7143830e8
With ls -l, print file type ('-' or 'd') as first field of output
Davor Ocelic <docelic@crystallabs.io>
parents:
113
diff
changeset
|
2252 |
|
4
5a65bc849363
Append a trailing slash to entries that contain other entries. Thanks
Mahlon E. Smith <mahlon@martini.nu>
parents:
3
diff
changeset
|
2253 |
# if this entry is a container for other entries, append a |
5a65bc849363
Append a trailing slash to entries that contain other entries. Thanks
Mahlon E. Smith <mahlon@martini.nu>
parents:
3
diff
changeset
|
2254 |
# trailing slash. |
114
35b7143830e8
With ls -l, print file type ('-' or 'd') as first field of output
Davor Ocelic <docelic@crystallabs.io>
parents:
113
diff
changeset
|
2255 |
if( $e->get_value('hasSubordinates') && $e->get_value('hasSubordinates') eq 'TRUE') { |
35b7143830e8
With ls -l, print file type ('-' or 'd') as first field of output
Davor Ocelic <docelic@crystallabs.io>
parents:
113
diff
changeset
|
2256 |
$dn .= '/'; |
35b7143830e8
With ls -l, print file type ('-' or 'd') as first field of output
Davor Ocelic <docelic@crystallabs.io>
parents:
113
diff
changeset
|
2257 |
$type = 'd' |
35b7143830e8
With ls -l, print file type ('-' or 'd') as first field of output
Davor Ocelic <docelic@crystallabs.io>
parents:
113
diff
changeset
|
2258 |
} |
0 | 2259 |
|
34
40c3719c87d4
fix 'ls -R' output, minor style cleanup
Mahlon E. Smith <mahlon@martini.nu>
parents:
33
diff
changeset
|
2260 |
# additional arguments/attributes were given; show their values |
40c3719c87d4
fix 'ls -R' output, minor style cleanup
Mahlon E. Smith <mahlon@martini.nu>
parents:
33
diff
changeset
|
2261 |
# |
40c3719c87d4
fix 'ls -R' output, minor style cleanup
Mahlon E. Smith <mahlon@martini.nu>
parents:
33
diff
changeset
|
2262 |
if ( scalar @args ) { |
114
35b7143830e8
With ls -l, print file type ('-' or 'd') as first field of output
Davor Ocelic <docelic@crystallabs.io>
parents:
113
diff
changeset
|
2263 |
my @line = ( $type, $dn ); |
0 | 2264 |
|
34
40c3719c87d4
fix 'ls -R' output, minor style cleanup
Mahlon E. Smith <mahlon@martini.nu>
parents:
33
diff
changeset
|
2265 |
foreach my $attr ( @args ) { |
40c3719c87d4
fix 'ls -R' output, minor style cleanup
Mahlon E. Smith <mahlon@martini.nu>
parents:
33
diff
changeset
|
2266 |
my @vals = $e->get_value( $attr ); |
114
35b7143830e8
With ls -l, print file type ('-' or 'd') as first field of output
Davor Ocelic <docelic@crystallabs.io>
parents:
113
diff
changeset
|
2267 |
push( @line, join(',', @vals) ); |
27
7d170d1bc17b
run_list: new argument syntax: [<options>] [<filter>] [<attributes>]
Peter Marschall <peter@adpm.de>
parents:
26
diff
changeset
|
2268 |
} |
0 | 2269 |
|
114
35b7143830e8
With ls -l, print file type ('-' or 'd') as first field of output
Davor Ocelic <docelic@crystallabs.io>
parents:
113
diff
changeset
|
2270 |
print join( "\t", @line )."\n"; |
35b7143830e8
With ls -l, print file type ('-' or 'd') as first field of output
Davor Ocelic <docelic@crystallabs.io>
parents:
113
diff
changeset
|
2271 |
|
27
7d170d1bc17b
run_list: new argument syntax: [<options>] [<filter>] [<attributes>]
Peter Marschall <peter@adpm.de>
parents:
26
diff
changeset
|
2272 |
} |
50 | 2273 |
|
2274 |
# show descriptions |
|
2275 |
# |
|
0 | 2276 |
else { |
114
35b7143830e8
With ls -l, print file type ('-' or 'd') as first field of output
Davor Ocelic <docelic@crystallabs.io>
parents:
113
diff
changeset
|
2277 |
my $line = "$type $dn"; |
35b7143830e8
With ls -l, print file type ('-' or 'd') as first field of output
Davor Ocelic <docelic@crystallabs.io>
parents:
113
diff
changeset
|
2278 |
|
34
40c3719c87d4
fix 'ls -R' output, minor style cleanup
Mahlon E. Smith <mahlon@martini.nu>
parents:
33
diff
changeset
|
2279 |
my $desc = $e->get_value( 'description' ); |
27
7d170d1bc17b
run_list: new argument syntax: [<options>] [<filter>] [<attributes>]
Peter Marschall <peter@adpm.de>
parents:
26
diff
changeset
|
2280 |
if ( $desc ) { |
7d170d1bc17b
run_list: new argument syntax: [<options>] [<filter>] [<attributes>]
Peter Marschall <peter@adpm.de>
parents:
26
diff
changeset
|
2281 |
$desc =~ s/\n.*//s; # 1st line only |
114
35b7143830e8
With ls -l, print file type ('-' or 'd') as first field of output
Davor Ocelic <docelic@crystallabs.io>
parents:
113
diff
changeset
|
2282 |
$line .= " ($desc)"; |
35b7143830e8
With ls -l, print file type ('-' or 'd') as first field of output
Davor Ocelic <docelic@crystallabs.io>
parents:
113
diff
changeset
|
2283 |
} else { |
35b7143830e8
With ls -l, print file type ('-' or 'd') as first field of output
Davor Ocelic <docelic@crystallabs.io>
parents:
113
diff
changeset
|
2284 |
# no desc? Try and infer something useful |
35b7143830e8
With ls -l, print file type ('-' or 'd') as first field of output
Davor Ocelic <docelic@crystallabs.io>
parents:
113
diff
changeset
|
2285 |
# to display. |
35b7143830e8
With ls -l, print file type ('-' or 'd') as first field of output
Davor Ocelic <docelic@crystallabs.io>
parents:
113
diff
changeset
|
2286 |
# |
0 | 2287 |
|
27
7d170d1bc17b
run_list: new argument syntax: [<options>] [<filter>] [<attributes>]
Peter Marschall <peter@adpm.de>
parents:
26
diff
changeset
|
2288 |
# pull objectClasses, hash for lookup speed |
48
fe27dfe5179e
More robust path for connection retries. Show optional, unused
Mahlon E. Smith <mahlon@laika.com>
parents:
46
diff
changeset
|
2289 |
my @oc = $e->get_value( 'objectClass' ); |
27
7d170d1bc17b
run_list: new argument syntax: [<options>] [<filter>] [<attributes>]
Peter Marschall <peter@adpm.de>
parents:
26
diff
changeset
|
2290 |
my %ochash; |
7d170d1bc17b
run_list: new argument syntax: [<options>] [<filter>] [<attributes>]
Peter Marschall <peter@adpm.de>
parents:
26
diff
changeset
|
2291 |
map { $ochash{$_} = 1 } @oc; |
7d170d1bc17b
run_list: new argument syntax: [<options>] [<filter>] [<attributes>]
Peter Marschall <peter@adpm.de>
parents:
26
diff
changeset
|
2292 |
|
7d170d1bc17b
run_list: new argument syntax: [<options>] [<filter>] [<attributes>]
Peter Marschall <peter@adpm.de>
parents:
26
diff
changeset
|
2293 |
foreach my $d_listing ( sort keys %descs ) { |
7d170d1bc17b
run_list: new argument syntax: [<options>] [<filter>] [<attributes>]
Peter Marschall <peter@adpm.de>
parents:
26
diff
changeset
|
2294 |
if ( exists $ochash{ $d_listing } ) { |
7d170d1bc17b
run_list: new argument syntax: [<options>] [<filter>] [<attributes>]
Peter Marschall <peter@adpm.de>
parents:
26
diff
changeset
|
2295 |
my $str = $e->get_value( $descs{ $d_listing }, asref => 1 ); |
114
35b7143830e8
With ls -l, print file type ('-' or 'd') as first field of output
Davor Ocelic <docelic@crystallabs.io>
parents:
113
diff
changeset
|
2296 |
$line .= ' (' . (join ', ', @$str) . ')' if $str && scalar @$str; |
27
7d170d1bc17b
run_list: new argument syntax: [<options>] [<filter>] [<attributes>]
Peter Marschall <peter@adpm.de>
parents:
26
diff
changeset
|
2297 |
} |
7d170d1bc17b
run_list: new argument syntax: [<options>] [<filter>] [<attributes>]
Peter Marschall <peter@adpm.de>
parents:
26
diff
changeset
|
2298 |
next; |
0 | 2299 |
} |
2300 |
} |
|
114
35b7143830e8
With ls -l, print file type ('-' or 'd') as first field of output
Davor Ocelic <docelic@crystallabs.io>
parents:
113
diff
changeset
|
2301 |
print "$line\n"; |
0 | 2302 |
} |
2303 |
$dn_count++; |
|
2304 |
} |
|
2305 |
||
2306 |
print "\n$dn_count " . |
|
2307 |
( $dn_count == 1 ? 'object.' : 'objects.') . |
|
2308 |
"\n" if $long; |
|
2309 |
return; |
|
2310 |
} |
|
2311 |
||
50 | 2312 |
|
2313 |
### Create a new organizationalUnit entry. |
|
2314 |
### |
|
0 | 2315 |
sub run_mkdir |
2316 |
{ |
|
2317 |
my $self = shift; |
|
41
3e7c107f8b93
Take only second argument for run_{cd,edit,mkdir}
Salvatore Bonaccorso <carnil@debian.org>
parents:
40
diff
changeset
|
2318 |
my $dir = shift; |
0 | 2319 |
|
2320 |
unless ( $dir ) { |
|
2321 |
print "No 'directory' provided.\n"; |
|
2322 |
return; |
|
2323 |
} |
|
2324 |
||
38
12f279ef4f9d
Backout the additional objectClasses patch for mkdir: same behavior can
Mahlon E. Smith <mahlon@martini.nu>
parents:
37
diff
changeset
|
2325 |
# normalize name, if it is not yet a legal DN |
12f279ef4f9d
Backout the additional objectClasses patch for mkdir: same behavior can
Mahlon E. Smith <mahlon@martini.nu>
parents:
37
diff
changeset
|
2326 |
$dir = 'ou=' . $dir unless canonical_dn( $dir ); |
0 | 2327 |
|
38
12f279ef4f9d
Backout the additional objectClasses patch for mkdir: same behavior can
Mahlon E. Smith <mahlon@martini.nu>
parents:
37
diff
changeset
|
2328 |
# convert given path to full DN |
12f279ef4f9d
Backout the additional objectClasses patch for mkdir: same behavior can
Mahlon E. Smith <mahlon@martini.nu>
parents:
37
diff
changeset
|
2329 |
$dir = $self->path_to_dn( $dir ); |
29
bd95c3aea253
mkdir: support more objectclasses
Peter Marschall <peter@adpm.de>
parents:
28
diff
changeset
|
2330 |
|
bd95c3aea253
mkdir: support more objectclasses
Peter Marschall <peter@adpm.de>
parents:
28
diff
changeset
|
2331 |
# get RDN: naming attributes (lower-case) and their values |
38
12f279ef4f9d
Backout the additional objectClasses patch for mkdir: same behavior can
Mahlon E. Smith <mahlon@martini.nu>
parents:
37
diff
changeset
|
2332 |
my %rdn = %{ shift(@{ ldap_explode_dn($dir, casefold => 'lower') }) }; |
0 | 2333 |
|
38
12f279ef4f9d
Backout the additional objectClasses patch for mkdir: same behavior can
Mahlon E. Smith <mahlon@martini.nu>
parents:
37
diff
changeset
|
2334 |
# add |
48
fe27dfe5179e
More robust path for connection retries. Show optional, unused
Mahlon E. Smith <mahlon@laika.com>
parents:
46
diff
changeset
|
2335 |
my $mkdir = sub { |
fe27dfe5179e
More robust path for connection retries. Show optional, unused
Mahlon E. Smith <mahlon@laika.com>
parents:
46
diff
changeset
|
2336 |
return $self->ldap()->add( $dir, attr => [ |
fe27dfe5179e
More robust path for connection retries. Show optional, unused
Mahlon E. Smith <mahlon@laika.com>
parents:
46
diff
changeset
|
2337 |
objectClass => [ 'top', 'organizationalUnit' ], %rdn |
fe27dfe5179e
More robust path for connection retries. Show optional, unused
Mahlon E. Smith <mahlon@laika.com>
parents:
46
diff
changeset
|
2338 |
]); |
fe27dfe5179e
More robust path for connection retries. Show optional, unused
Mahlon E. Smith <mahlon@laika.com>
parents:
46
diff
changeset
|
2339 |
}; |
0 | 2340 |
|
48
fe27dfe5179e
More robust path for connection retries. Show optional, unused
Mahlon E. Smith <mahlon@laika.com>
parents:
46
diff
changeset
|
2341 |
my $rv = $self->with_retry( $mkdir ); |
fe27dfe5179e
More robust path for connection retries. Show optional, unused
Mahlon E. Smith <mahlon@laika.com>
parents:
46
diff
changeset
|
2342 |
|
fe27dfe5179e
More robust path for connection retries. Show optional, unused
Mahlon E. Smith <mahlon@laika.com>
parents:
46
diff
changeset
|
2343 |
print $rv->error(), "\n"; |
0 | 2344 |
$self->update_entries( clearcache => 1 ); |
2345 |
return; |
|
2346 |
} |
|
2347 |
||
50 | 2348 |
|
2349 |
### Alter an entry's DN. |
|
2350 |
### |
|
0 | 2351 |
sub run_move |
2352 |
{ |
|
2353 |
my $self = shift; |
|
2354 |
my ( $s_dn, $d_dn ) = @_; |
|
2355 |
||
2356 |
unless ( $s_dn ) { |
|
2357 |
print "No source dn provided.\n"; |
|
2358 |
return; |
|
2359 |
} |
|
2360 |
unless ( $d_dn ) { |
|
2361 |
print "No destination dn provided.\n"; |
|
2362 |
return; |
|
2363 |
} |
|
2364 |
||
31
a3a710f720dd
run_cat: convert to using path_to_dn()
Peter Marschall <peter@adpm.de>
parents:
30
diff
changeset
|
2365 |
# convert given source path to DN |
33
057fefab56b0
Repair broken path behavior, remove unneeded #path_to_dn 'relative'
Mahlon E. Smith <mahlon@martini.nu>
parents:
32
diff
changeset
|
2366 |
$s_dn = $self->path_to_dn( $s_dn ); |
31
a3a710f720dd
run_cat: convert to using path_to_dn()
Peter Marschall <peter@adpm.de>
parents:
30
diff
changeset
|
2367 |
|
0 | 2368 |
unless ( $self->is_valid_dn( $s_dn ) ) { |
2369 |
print "No such object\n"; |
|
2370 |
return; |
|
2371 |
} |
|
2372 |
||
2373 |
# see if we're moving the entry to a totally new path |
|
2374 |
my ( $new_dn, $old_dn ); |
|
82
57a1335691e5
Allow the period character when moving an entry by full DN.
Mahlon E. Smith <mahlon@martini.nu>
parents:
81
diff
changeset
|
2375 |
( $d_dn, $new_dn ) = ( $1, $2 ) if $d_dn =~ /^([\.\-\w=]+),(.*)$/; |
57a1335691e5
Allow the period character when moving an entry by full DN.
Mahlon E. Smith <mahlon@martini.nu>
parents:
81
diff
changeset
|
2376 |
$old_dn = $1 if $s_dn =~ /^[\.\-\w=]+,(.*)$/; |
0 | 2377 |
|
48
fe27dfe5179e
More robust path for connection retries. Show optional, unused
Mahlon E. Smith <mahlon@laika.com>
parents:
46
diff
changeset
|
2378 |
my $moddn = sub { |
fe27dfe5179e
More robust path for connection retries. Show optional, unused
Mahlon E. Smith <mahlon@laika.com>
parents:
46
diff
changeset
|
2379 |
return $self->ldap()->moddn( |
fe27dfe5179e
More robust path for connection retries. Show optional, unused
Mahlon E. Smith <mahlon@laika.com>
parents:
46
diff
changeset
|
2380 |
$s_dn, |
fe27dfe5179e
More robust path for connection retries. Show optional, unused
Mahlon E. Smith <mahlon@laika.com>
parents:
46
diff
changeset
|
2381 |
newrdn => $d_dn, |
fe27dfe5179e
More robust path for connection retries. Show optional, unused
Mahlon E. Smith <mahlon@laika.com>
parents:
46
diff
changeset
|
2382 |
deleteoldrdn => 1, |
fe27dfe5179e
More robust path for connection retries. Show optional, unused
Mahlon E. Smith <mahlon@laika.com>
parents:
46
diff
changeset
|
2383 |
newsuperior => $new_dn |
fe27dfe5179e
More robust path for connection retries. Show optional, unused
Mahlon E. Smith <mahlon@laika.com>
parents:
46
diff
changeset
|
2384 |
); |
fe27dfe5179e
More robust path for connection retries. Show optional, unused
Mahlon E. Smith <mahlon@laika.com>
parents:
46
diff
changeset
|
2385 |
}; |
fe27dfe5179e
More robust path for connection retries. Show optional, unused
Mahlon E. Smith <mahlon@laika.com>
parents:
46
diff
changeset
|
2386 |
my $rv = $self->with_retry( $moddn ); |
0 | 2387 |
print $rv->error(), "\n"; |
2388 |
||
2389 |
# clear caches |
|
2390 |
$self->{'cache'}->{ $new_dn } = {} if $new_dn; |
|
2391 |
$self->{'cache'}->{ $old_dn } = {} if $old_dn; |
|
2392 |
$self->update_entries( clearcache => 1 ); |
|
2393 |
return; |
|
2394 |
} |
|
2395 |
||
50 | 2396 |
|
2397 |
### Change the 'userPassword' attribute of an entry, if |
|
2398 |
### supported by the LDAP server. |
|
2399 |
### |
|
0 | 2400 |
sub run_passwd |
2401 |
{ |
|
2402 |
my $self = shift; |
|
2403 |
my $dn = shift || $self->base(); |
|
2404 |
||
2405 |
$self->{'root_dse'} ||= $self->ldap->root_dse(); |
|
2406 |
||
93
4c7843b9a047
Make password extension usage consistent with pager control.
Mahlon E. Smith <mahlon@martini.nu>
parents:
92
diff
changeset
|
2407 |
unless ( $self->{'root_dse'}->supported_extension(LDAP_EXTENSION_PASSWORD_MODIFY) ) { |
0 | 2408 |
print "Sorry, password changes not supported by LDAP server.\n"; |
2409 |
return; |
|
2410 |
} |
|
2411 |
||
31
a3a710f720dd
run_cat: convert to using path_to_dn()
Peter Marschall <peter@adpm.de>
parents:
30
diff
changeset
|
2412 |
# convert given path to DN |
40
c6a3abc56c74
Fix bug introduced in rev:a3a710f720dd with passwd arguments.
Mahlon E. Smith <mahlon@martini.nu>
parents:
38
diff
changeset
|
2413 |
$dn = $self->path_to_dn( $dn ); |
0 | 2414 |
|
2415 |
my $s = $self->search( { base => $dn, scope => 'base' } ); |
|
2416 |
if ( $s->{'code'} ) { |
|
2417 |
print $s->{'message'}, "\n"; |
|
2418 |
return; |
|
2419 |
} |
|
2420 |
my $e = ${ $s->{'entries'} }[0]; |
|
2421 |
||
2422 |
unless ( $e->exists('userPassword') ) { |
|
2423 |
print "No userPassword attribute for $dn\n"; |
|
2424 |
return; |
|
2425 |
} |
|
2426 |
||
2427 |
print "Changing password for $dn\n"; |
|
2428 |
Term::ReadKey::ReadMode 2; |
|
2429 |
print "Enter new password: "; |
|
2430 |
chomp( my $pw = <STDIN> ); |
|
2431 |
print "\nRetype new password: "; |
|
2432 |
chomp( my $pw2 = <STDIN> ); |
|
2433 |
print "\n"; |
|
2434 |
Term::ReadKey::ReadMode 0; |
|
2435 |
||
2436 |
if ( $pw ne $pw2 ) { |
|
2437 |
print "Sorry, passwords do not match.\n"; |
|
2438 |
return; |
|
2439 |
} |
|
2440 |
||
50 | 2441 |
my $setpw = sub { return $self->ldap->set_password( user => $dn, newpasswd => $pw ); }; |
2442 |
my $rv = $self->with_retry( $setpw ); |
|
0 | 2443 |
|
16
a2e3faa3d2fc
use symbolic LDAP error codes instead of numbers
Peter Marschall <peter@adpm.de>
parents:
15
diff
changeset
|
2444 |
if ( $rv->code() == LDAP_SUCCESS ) { |
0 | 2445 |
print "Password updated successfully.\n"; |
48
fe27dfe5179e
More robust path for connection retries. Show optional, unused
Mahlon E. Smith <mahlon@laika.com>
parents:
46
diff
changeset
|
2446 |
} |
fe27dfe5179e
More robust path for connection retries. Show optional, unused
Mahlon E. Smith <mahlon@laika.com>
parents:
46
diff
changeset
|
2447 |
else { |
0 | 2448 |
print "Password error: " . $rv->error() . "\n"; |
2449 |
} |
|
2450 |
||
2451 |
return; |
|
2452 |
} |
|
2453 |
||
50 | 2454 |
|
2455 |
### Display the current working "directory". |
|
2456 |
### |
|
0 | 2457 |
sub run_pwd |
2458 |
{ |
|
2459 |
my $self = shift; |
|
2460 |
print $self->base() . "\n"; |
|
2461 |
return; |
|
2462 |
} |
|
2463 |
||
2464 |
||
50 | 2465 |
### Display the currently bound user. |
2466 |
### |
|
0 | 2467 |
sub run_whoami |
2468 |
{ |
|
2469 |
my $self = shift; |
|
57
85cc85d0c1b1
Catch a case where the LDAP object is defined, but in a state that
Mahlon E. Smith <mahlon@laika.com>
parents:
56
diff
changeset
|
2470 |
my $msg = ( $conf->{'binddn'} || 'anonymous bind' ) . ' (' . $conf->{'server'} . ')'; |
85cc85d0c1b1
Catch a case where the LDAP object is defined, but in a state that
Mahlon E. Smith <mahlon@laika.com>
parents:
56
diff
changeset
|
2471 |
print "$msg\n"; |
0 | 2472 |
return; |
2473 |
} |
|
2474 |
||
50 | 2475 |
|
51
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2476 |
### Show basic information for an entry (DN) or list of objectClasses. |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2477 |
### |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2478 |
### structural/auxillary classes |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2479 |
### required attributes |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2480 |
### optional attributes |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2481 |
### |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2482 |
sub run_inspect |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2483 |
{ |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2484 |
my $self = shift; |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2485 |
my @ocs = @_; |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2486 |
my $dn = $ocs[0]; |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2487 |
my ( $must_attr, $may_attr ); |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2488 |
|
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2489 |
unless ( $dn ) { |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2490 |
print "No DN or objectClass(es) provided.\n"; |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2491 |
return; |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2492 |
} |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2493 |
|
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2494 |
# "Magic" argument that dumps all raw schema information. |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2495 |
# |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2496 |
if ( $dn eq '_schema' ) { |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2497 |
$self->{'schema'}->dump(); |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2498 |
return; |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2499 |
} |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2500 |
|
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2501 |
# one argument -- if it successfully resolves to a valid DN, fetch |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2502 |
# the objectClass list from it. |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2503 |
# |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2504 |
if ( scalar @ocs == 1 ) { |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2505 |
$dn = $self->base() if $dn eq '.'; |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2506 |
$dn = $self->path_to_dn( $dn ); |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2507 |
|
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2508 |
my $s = $self->search({ base => $dn, vals => 1, attrs => ['objectClass'] }); |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2509 |
if ( $s->{'code'} == LDAP_SUCCESS ) { |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2510 |
my $e = ${ $s->{'entries'} }[0]; |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2511 |
@ocs = $e->get_value('objectClass'); |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2512 |
} |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2513 |
} |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2514 |
|
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2515 |
# get the complete attributes list. |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2516 |
# |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2517 |
( $must_attr, $may_attr ) = $self->fetch_attributes( \@ocs ); |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2518 |
my %must = map { $_ => 1 } @{$must_attr}; |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2519 |
|
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2520 |
# Output objectClass chains and flags. |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2521 |
# |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2522 |
print "ObjectClasses:\n"; |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2523 |
foreach my $oc ( sort @ocs ) { |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2524 |
my @sups = $self->findall_supers( $oc ); |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2525 |
|
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2526 |
my @oc_chain = ( $oc, @sups ); |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2527 |
my @oc_out; |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2528 |
|
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2529 |
foreach my $oc ( @oc_chain ) { |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2530 |
my $oc_obj = $self->{'schema'}->objectclass( $oc ); |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2531 |
next unless $oc_obj; |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2532 |
|
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2533 |
$oc = $oc . ' (' . 'structural' . ')' if $oc_obj->{'structural'}; |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2534 |
push( @oc_out, $oc ); |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2535 |
} |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2536 |
|
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2537 |
print " " . join( ' --> ', @oc_out ) . "\n" if scalar @oc_out; |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2538 |
} |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2539 |
|
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2540 |
# Output attributes and flags. |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2541 |
# |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2542 |
print "\nAttributes:\n"; |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2543 |
foreach my $attr ( sort (@{$must_attr}, @{$may_attr}) ) { |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2544 |
my @flaglist; |
107
3e31beb6c845
Do not sort flaglist twice
Davor Ocelic <docelic@crystallabs.io>
parents:
106
diff
changeset
|
2545 |
|
3e31beb6c845
Do not sort flaglist twice
Davor Ocelic <docelic@crystallabs.io>
parents:
106
diff
changeset
|
2546 |
push ( @flaglist, $must{$attr} ? 'required' : 'optional' ); |
3e31beb6c845
Do not sort flaglist twice
Davor Ocelic <docelic@crystallabs.io>
parents:
106
diff
changeset
|
2547 |
|
51
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2548 |
if ( $self->{'schema'}->attribute( $attr )->{'single-value'} ) { |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2549 |
push ( @flaglist, 'single-value' ); |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2550 |
} |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2551 |
else { |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2552 |
push ( @flaglist, 'multivalue' ); |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2553 |
} |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2554 |
|
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2555 |
my $flags = ''; |
107
3e31beb6c845
Do not sort flaglist twice
Davor Ocelic <docelic@crystallabs.io>
parents:
106
diff
changeset
|
2556 |
$flags = (' (' . join( ', ', @flaglist ) . ')') if scalar @flaglist > 0; |
51
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2557 |
|
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2558 |
printf( " %s%s\n", $attr, $flags ); |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2559 |
} |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2560 |
|
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2561 |
print "\n"; |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2562 |
return; |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2563 |
} |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2564 |
|
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2565 |
|
104 | 2566 |
### Inject various autocomplete and alias routines into the symbol table. |
2567 |
### |
|
2568 |
{ no strict 'refs'; |
|
109
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
2569 |
local $| = 1; |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
2570 |
my %aliases; |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
2571 |
|
111
252611c8d283
Make aliases be auto-detected and inserted into help texts.
Davor Ocelic <docelic@crystallabs.io>
parents:
110
diff
changeset
|
2572 |
# In first pass, only identify aliases. |
104 | 2573 |
while(my($cmd, $data) = each %cmd_map ) { |
110
dbceec51da98
Fix autocompleter for all commands.
Davor Ocelic <docelic@crystallabs.io>
parents:
109
diff
changeset
|
2574 |
# If command is an alias, it is enough to mark it as such. |
104 | 2575 |
if( $$data[0]) { |
109
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
2576 |
$aliases{$$data[0]} ||= []; |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
2577 |
push @{$aliases{$$data[0]}}, $cmd; |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
2578 |
|
110
dbceec51da98
Fix autocompleter for all commands.
Davor Ocelic <docelic@crystallabs.io>
parents:
109
diff
changeset
|
2579 |
# If it is a real command, let's do more work. |
111
252611c8d283
Make aliases be auto-detected and inserted into help texts.
Davor Ocelic <docelic@crystallabs.io>
parents:
110
diff
changeset
|
2580 |
} |
252611c8d283
Make aliases be auto-detected and inserted into help texts.
Davor Ocelic <docelic@crystallabs.io>
parents:
110
diff
changeset
|
2581 |
} |
252611c8d283
Make aliases be auto-detected and inserted into help texts.
Davor Ocelic <docelic@crystallabs.io>
parents:
110
diff
changeset
|
2582 |
|
252611c8d283
Make aliases be auto-detected and inserted into help texts.
Davor Ocelic <docelic@crystallabs.io>
parents:
110
diff
changeset
|
2583 |
# In second pass, deal with non-aliases. |
252611c8d283
Make aliases be auto-detected and inserted into help texts.
Davor Ocelic <docelic@crystallabs.io>
parents:
110
diff
changeset
|
2584 |
while(my($cmd, $data) = each %cmd_map ) { |
252611c8d283
Make aliases be auto-detected and inserted into help texts.
Davor Ocelic <docelic@crystallabs.io>
parents:
110
diff
changeset
|
2585 |
if( !$$data[0]) { |
110
dbceec51da98
Fix autocompleter for all commands.
Davor Ocelic <docelic@crystallabs.io>
parents:
109
diff
changeset
|
2586 |
# If completer is defined, set it. |
dbceec51da98
Fix autocompleter for all commands.
Davor Ocelic <docelic@crystallabs.io>
parents:
109
diff
changeset
|
2587 |
if( $$data[1]) { |
dbceec51da98
Fix autocompleter for all commands.
Davor Ocelic <docelic@crystallabs.io>
parents:
109
diff
changeset
|
2588 |
my $comp_sub = "comp_$cmd"; |
dbceec51da98
Fix autocompleter for all commands.
Davor Ocelic <docelic@crystallabs.io>
parents:
109
diff
changeset
|
2589 |
*$comp_sub = \&{$$data[1]} |
dbceec51da98
Fix autocompleter for all commands.
Davor Ocelic <docelic@crystallabs.io>
parents:
109
diff
changeset
|
2590 |
} |
109
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
2591 |
|
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
2592 |
# Define help and summary functions for the command: |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
2593 |
my $pod = ''; open my $io, '>', \$pod; |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
2594 |
Pod::Usage::pod2usage( -exitval => 'NOEXIT', -verbose => 99, -sections => "SHELL COMMANDS/${\( quotemeta $cmd )}", -output => \*$io ); |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
2595 |
my @pod = split /\n/, $pod; |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
2596 |
my $summary = $pod[1]; |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
2597 |
if($summary) { |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
2598 |
$summary =~ s/^\s+//s; |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
2599 |
$summary =~ s/\s+$//s; |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
2600 |
$summary =~ s/\s+/ /s; |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
2601 |
} |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
2602 |
my $help = join "\n", @pod; |
111
252611c8d283
Make aliases be auto-detected and inserted into help texts.
Davor Ocelic <docelic@crystallabs.io>
parents:
110
diff
changeset
|
2603 |
if( $aliases{$cmd}) { |
252611c8d283
Make aliases be auto-detected and inserted into help texts.
Davor Ocelic <docelic@crystallabs.io>
parents:
110
diff
changeset
|
2604 |
local $" = ', '; |
252611c8d283
Make aliases be auto-detected and inserted into help texts.
Davor Ocelic <docelic@crystallabs.io>
parents:
110
diff
changeset
|
2605 |
$help .= "\n\n Aliases: @{$aliases{$cmd}}\n" |
252611c8d283
Make aliases be auto-detected and inserted into help texts.
Davor Ocelic <docelic@crystallabs.io>
parents:
110
diff
changeset
|
2606 |
} |
109
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
2607 |
|
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
2608 |
my $helpfunc = sub { "$help\n" }; |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
2609 |
*{"help_$cmd"} = \&$helpfunc; |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
2610 |
|
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
2611 |
my $summfunc = sub { $summary }; |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
2612 |
*{"smry_$cmd"} = \&$summfunc; |
104 | 2613 |
} |
109
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
2614 |
} |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
2615 |
|
111
252611c8d283
Make aliases be auto-detected and inserted into help texts.
Davor Ocelic <docelic@crystallabs.io>
parents:
110
diff
changeset
|
2616 |
# In third pass, actually register found aliases. |
109
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
2617 |
while(my($cmd,$aliases) = each %aliases) { |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
2618 |
my $aliasfunc = sub { @$aliases }; |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
2619 |
*{"alias_$cmd"} = \&$aliasfunc; |
104 | 2620 |
} |
2621 |
} |
|
2622 |
||
2623 |
||
91
80ec00959fbd
Fix spelling errors
Salvatore Bonaccorso <carnil@debian.org>
parents:
87
diff
changeset
|
2624 |
### Recursively walk an objectClass hierarchy, returning an array |
51
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2625 |
### of inheritence. |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2626 |
### |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2627 |
sub findall_supers |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2628 |
{ |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2629 |
my $self = shift; |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2630 |
my $oc = shift or return; |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2631 |
my @found; |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2632 |
|
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2633 |
foreach my $sup ( $self->{'schema'}->superclass($oc) ) { |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2634 |
push( @found, $sup ); |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2635 |
push( @found, $self->findall_supers( $sup ) ); |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2636 |
} |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2637 |
|
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2638 |
return @found; |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2639 |
} |
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2640 |
|
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2641 |
|
27bbe75233a3
Add the "inspect" command, which provides some quick reference for
Mahlon E. Smith <mahlon@laika.com>
parents:
50
diff
changeset
|
2642 |
|
50 | 2643 |
######################################################################## |
2644 |
### M A I N |
|
2645 |
######################################################################## |
|
0 | 2646 |
|
2647 |
package main; |
|
2648 |
use strict; |
|
2649 |
use warnings; |
|
2650 |
||
2651 |
$0 = 'shelldap'; |
|
94 | 2652 |
my $VERSION = '1.4.0'; |
0 | 2653 |
|
117
eb1bcbaf9763
Improve accepted command line options
Davor Ocelic <docelic@crystallabs.io>
parents:
116
diff
changeset
|
2654 |
use Getopt::Long qw(:config no_ignore_case); |
eb1bcbaf9763
Improve accepted command line options
Davor Ocelic <docelic@crystallabs.io>
parents:
116
diff
changeset
|
2655 |
use YAML::Syck qw//; |
eb1bcbaf9763
Improve accepted command line options
Davor Ocelic <docelic@crystallabs.io>
parents:
116
diff
changeset
|
2656 |
use Pod::Usage qw//; |
87
475aff91675b
eval optional modules in blocks instead of strings.
Mahlon E. Smith <mahlon@martini.nu>
parents:
84
diff
changeset
|
2657 |
eval { require Term::ReadLine::Gnu; }; |
0 | 2658 |
warn qq{Term::ReadLine::Gnu not installed. |
2659 |
Continuing, but shelldap is of limited usefulness without it.\n\n} if $@; |
|
2660 |
||
2661 |
# get config - rc file first, command line overrides |
|
2662 |
use vars '$conf'; |
|
2663 |
$conf = load_config() || {}; |
|
2664 |
Getopt::Long::GetOptions( |
|
2665 |
$conf, |
|
117
eb1bcbaf9763
Improve accepted command line options
Davor Ocelic <docelic@crystallabs.io>
parents:
116
diff
changeset
|
2666 |
'server|h|H=s', |
eb1bcbaf9763
Improve accepted command line options
Davor Ocelic <docelic@crystallabs.io>
parents:
116
diff
changeset
|
2667 |
'port|p=s', |
50 | 2668 |
'configfile|f=s', |
18
db47ba64ebda
accept short option names for some options
Peter Marschall <peter@adpm.de>
parents:
17
diff
changeset
|
2669 |
'binddn|D=s', |
db47ba64ebda
accept short option names for some options
Peter Marschall <peter@adpm.de>
parents:
17
diff
changeset
|
2670 |
'basedn|b=s', |
0 | 2671 |
'cacheage=i', |
116
6a0b1209dafa
Support arrays/hashes in 'env' (WIP)
Davor Ocelic <docelic@crystallabs.io>
parents:
115
diff
changeset
|
2672 |
'cmdline_attributes|attributes=s@', |
92
a1aa55019077
Optionally use the server side pager control for search results.
Mahlon E. Smith <mahlon@martini.nu>
parents:
91
diff
changeset
|
2673 |
'paginate=i', |
117
eb1bcbaf9763
Improve accepted command line options
Davor Ocelic <docelic@crystallabs.io>
parents:
116
diff
changeset
|
2674 |
'promptpass|W!', |
eb1bcbaf9763
Improve accepted command line options
Davor Ocelic <docelic@crystallabs.io>
parents:
116
diff
changeset
|
2675 |
'pass|w=s', |
eb1bcbaf9763
Improve accepted command line options
Davor Ocelic <docelic@crystallabs.io>
parents:
116
diff
changeset
|
2676 |
'passfile|y=s', |
0 | 2677 |
'timeout=i', |
62
ed8253b3105a
Add quick documentation blurb for SASL mechanisms. Make SASL
Mahlon E. Smith <mahlon@laika.com>
parents:
61
diff
changeset
|
2678 |
'sasl|Y=s', |
117
eb1bcbaf9763
Improve accepted command line options
Davor Ocelic <docelic@crystallabs.io>
parents:
116
diff
changeset
|
2679 |
'simple|x!' => sub { |
eb1bcbaf9763
Improve accepted command line options
Davor Ocelic <docelic@crystallabs.io>
parents:
116
diff
changeset
|
2680 |
my($opt,$arg) = @_; |
eb1bcbaf9763
Improve accepted command line options
Davor Ocelic <docelic@crystallabs.io>
parents:
116
diff
changeset
|
2681 |
$conf->{sasl} = $arg ? undef : 'PLAIN CRAM-MD5 GSSAPI' |
eb1bcbaf9763
Improve accepted command line options
Davor Ocelic <docelic@crystallabs.io>
parents:
116
diff
changeset
|
2682 |
}, |
3
0f815f3daaf7
Add options to support ssl key verification when connecting with TLS.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
2683 |
'tls_cacert=s', |
0f815f3daaf7
Add options to support ssl key verification when connecting with TLS.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
2684 |
'tls_cert=s', |
0f815f3daaf7
Add options to support ssl key verification when connecting with TLS.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
2685 |
'tls_key=s', |
117
eb1bcbaf9763
Improve accepted command line options
Davor Ocelic <docelic@crystallabs.io>
parents:
116
diff
changeset
|
2686 |
'tls|Z|ZZ!', |
eb1bcbaf9763
Improve accepted command line options
Davor Ocelic <docelic@crystallabs.io>
parents:
116
diff
changeset
|
2687 |
'debug|v', |
eb1bcbaf9763
Improve accepted command line options
Davor Ocelic <docelic@crystallabs.io>
parents:
116
diff
changeset
|
2688 |
'version', |
0 | 2689 |
help => sub { |
109
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
2690 |
Pod::Usage::pod2usage( |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
2691 |
-verbose => 1, |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
2692 |
-message => "\n$0 command line flags\n" . '-' x 65 |
d37c6197818f
Multiple help-related changes
Davor Ocelic <docelic@crystallabs.io>
parents:
108
diff
changeset
|
2693 |
); |
0 | 2694 |
} |
2695 |
); |
|
2696 |
||
37 | 2697 |
# show version |
2698 |
if ( $conf->{'version'} ) { |
|
50 | 2699 |
print "$0 $VERSION\n"; |
37 | 2700 |
exit( 0 ); |
2701 |
} |
|
2702 |
||
50 | 2703 |
# additional/different config file? |
2704 |
# |
|
2705 |
if ( $conf->{'configfile'} ) { |
|
2706 |
my $more_conf = load_config( $conf->{'configfile'} ); |
|
2707 |
while ( my ($k, $v) = each %{$conf} ) { $conf->{ $k } = $v } |
|
2708 |
} |
|
2709 |
||
2710 |
||
0 | 2711 |
# defaults |
50 | 2712 |
$conf->{'configfile'} ||= "$ENV{'HOME'}/.shelldap.rc"; |
101
cb4de2ecc7ab
Allow default attributes to be set via config and cmdline
Davor Ocelic <docelic@crystallabs.io>
parents:
99
diff
changeset
|
2713 |
$conf->{'cacheage'} ||= 300; |
cb4de2ecc7ab
Allow default attributes to be set via config and cmdline
Davor Ocelic <docelic@crystallabs.io>
parents:
99
diff
changeset
|
2714 |
$conf->{'timeout'} ||= 10; |
cb4de2ecc7ab
Allow default attributes to be set via config and cmdline
Davor Ocelic <docelic@crystallabs.io>
parents:
99
diff
changeset
|
2715 |
$conf->{'attributes'} ||= ['*']; |
0 | 2716 |
|
116
6a0b1209dafa
Support arrays/hashes in 'env' (WIP)
Davor Ocelic <docelic@crystallabs.io>
parents:
115
diff
changeset
|
2717 |
# Allow command line option --attributes to override settings from |
6a0b1209dafa
Support arrays/hashes in 'env' (WIP)
Davor Ocelic <docelic@crystallabs.io>
parents:
115
diff
changeset
|
2718 |
# config file. |
6a0b1209dafa
Support arrays/hashes in 'env' (WIP)
Davor Ocelic <docelic@crystallabs.io>
parents:
115
diff
changeset
|
2719 |
if($conf->{'cmdline_attributes'}) { |
6a0b1209dafa
Support arrays/hashes in 'env' (WIP)
Davor Ocelic <docelic@crystallabs.io>
parents:
115
diff
changeset
|
2720 |
$conf->{'attributes'} = $conf->{'cmdline_attributes'} |
6a0b1209dafa
Support arrays/hashes in 'env' (WIP)
Davor Ocelic <docelic@crystallabs.io>
parents:
115
diff
changeset
|
2721 |
} |
108
24340fdef276
Properly handle Ctrl+C; add '?' and 'man' aliases; don't import symbols
Davor Ocelic <docelic@crystallabs.io>
parents:
107
diff
changeset
|
2722 |
|
24340fdef276
Properly handle Ctrl+C; add '?' and 'man' aliases; don't import symbols
Davor Ocelic <docelic@crystallabs.io>
parents:
107
diff
changeset
|
2723 |
# create and enter shell loop while also handling Ctrl+C correctly. |
24340fdef276
Properly handle Ctrl+C; add '?' and 'man' aliases; don't import symbols
Davor Ocelic <docelic@crystallabs.io>
parents:
107
diff
changeset
|
2724 |
my $shell = LDAP::Shell->new; |
24340fdef276
Properly handle Ctrl+C; add '?' and 'man' aliases; don't import symbols
Davor Ocelic <docelic@crystallabs.io>
parents:
107
diff
changeset
|
2725 |
my $sigset = POSIX::SigSet->new(); |
24340fdef276
Properly handle Ctrl+C; add '?' and 'man' aliases; don't import symbols
Davor Ocelic <docelic@crystallabs.io>
parents:
107
diff
changeset
|
2726 |
sub ctrl_c_handler { |
24340fdef276
Properly handle Ctrl+C; add '?' and 'man' aliases; don't import symbols
Davor Ocelic <docelic@crystallabs.io>
parents:
107
diff
changeset
|
2727 |
print "\n"; |
24340fdef276
Properly handle Ctrl+C; add '?' and 'man' aliases; don't import symbols
Davor Ocelic <docelic@crystallabs.io>
parents:
107
diff
changeset
|
2728 |
$shell->term->on_new_line; |
24340fdef276
Properly handle Ctrl+C; add '?' and 'man' aliases; don't import symbols
Davor Ocelic <docelic@crystallabs.io>
parents:
107
diff
changeset
|
2729 |
$shell->term->replace_line('', 0); |
24340fdef276
Properly handle Ctrl+C; add '?' and 'man' aliases; don't import symbols
Davor Ocelic <docelic@crystallabs.io>
parents:
107
diff
changeset
|
2730 |
$shell->term->redisplay; |
24340fdef276
Properly handle Ctrl+C; add '?' and 'man' aliases; don't import symbols
Davor Ocelic <docelic@crystallabs.io>
parents:
107
diff
changeset
|
2731 |
} |
24340fdef276
Properly handle Ctrl+C; add '?' and 'man' aliases; don't import symbols
Davor Ocelic <docelic@crystallabs.io>
parents:
107
diff
changeset
|
2732 |
my $sigaction = POSIX::SigAction->new( \&ctrl_c_handler, $sigset, 0); |
24340fdef276
Properly handle Ctrl+C; add '?' and 'man' aliases; don't import symbols
Davor Ocelic <docelic@crystallabs.io>
parents:
107
diff
changeset
|
2733 |
my $old_action = POSIX::SigAction->new; |
24340fdef276
Properly handle Ctrl+C; add '?' and 'man' aliases; don't import symbols
Davor Ocelic <docelic@crystallabs.io>
parents:
107
diff
changeset
|
2734 |
POSIX::sigaction(&POSIX::SIGINT, $sigaction, $old_action); # save default one |
0 | 2735 |
$shell->cmdloop(); |
108
24340fdef276
Properly handle Ctrl+C; add '?' and 'man' aliases; don't import symbols
Davor Ocelic <docelic@crystallabs.io>
parents:
107
diff
changeset
|
2736 |
POSIX::sigaction(&POSIX::SIGINT, $old_action); # restore default one |
24340fdef276
Properly handle Ctrl+C; add '?' and 'man' aliases; don't import symbols
Davor Ocelic <docelic@crystallabs.io>
parents:
107
diff
changeset
|
2737 |
|
0 | 2738 |
|
50 | 2739 |
### load YAML config into global conf. |
2740 |
### |
|
0 | 2741 |
sub load_config |
2742 |
{ |
|
50 | 2743 |
my $confpath = shift; |
0 | 2744 |
my ( $d, $data ); |
2745 |
||
50 | 2746 |
unless ( $confpath ) { |
2747 |
my @confs = ( |
|
2748 |
"$ENV{'HOME'}/.shelldap.rc", |
|
2749 |
'/usr/local/etc/shelldap.conf', |
|
2750 |
'/etc/shelldap.conf', |
|
2751 |
); |
|
2752 |
foreach ( @confs ) { |
|
2753 |
if ( -e $_ ) { |
|
2754 |
$confpath = $_; |
|
2755 |
last; |
|
2756 |
} |
|
0 | 2757 |
} |
2758 |
} |
|
2759 |
$confpath or return undef; |
|
2760 |
||
118
2d7f16eff198
Use local implementation of slurp()
Davor Ocelic <docelic@crystallabs.io>
parents:
117
diff
changeset
|
2761 |
open YAML, $confpath; |
0 | 2762 |
do { |
2763 |
local $/ = undef; |
|
2764 |
$data = <YAML>; # slurp! |
|
2765 |
}; |
|
2766 |
close YAML; |
|
2767 |
||
2768 |
eval { $conf = YAML::Syck::Load( $data ) }; |
|
3
0f815f3daaf7
Add options to support ssl key verification when connecting with TLS.
Mahlon E. Smith <mahlon@martini.nu>
parents:
1
diff
changeset
|
2769 |
die "Invalid YAML in $confpath\n" if $@; |
0 | 2770 |
|
102
e92cb378144d
Fix precedence of command line arguments
Davor Ocelic <docelic@crystallabs.io>
parents:
101
diff
changeset
|
2771 |
# remove reference to itself, if somehow it got dumped |
e92cb378144d
Fix precedence of command line arguments
Davor Ocelic <docelic@crystallabs.io>
parents:
101
diff
changeset
|
2772 |
# into YAML. |
e92cb378144d
Fix precedence of command line arguments
Davor Ocelic <docelic@crystallabs.io>
parents:
101
diff
changeset
|
2773 |
if( $conf->{configfile} and ($confpath eq $conf->{configfile})) { |
e92cb378144d
Fix precedence of command line arguments
Davor Ocelic <docelic@crystallabs.io>
parents:
101
diff
changeset
|
2774 |
delete $conf->{'configfile'} |
e92cb378144d
Fix precedence of command line arguments
Davor Ocelic <docelic@crystallabs.io>
parents:
101
diff
changeset
|
2775 |
} |
e92cb378144d
Fix precedence of command line arguments
Davor Ocelic <docelic@crystallabs.io>
parents:
101
diff
changeset
|
2776 |
|
115
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
2777 |
$conf->{alias} ||= {}; |
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
2778 |
|
0 | 2779 |
return $conf; |
2780 |
} |
|
2781 |
||
102
e92cb378144d
Fix precedence of command line arguments
Davor Ocelic <docelic@crystallabs.io>
parents:
101
diff
changeset
|
2782 |
### dump YAML config into conf file while making sure that |
e92cb378144d
Fix precedence of command line arguments
Davor Ocelic <docelic@crystallabs.io>
parents:
101
diff
changeset
|
2783 |
### name of configfile itself is not dumped if it is equal |
e92cb378144d
Fix precedence of command line arguments
Davor Ocelic <docelic@crystallabs.io>
parents:
101
diff
changeset
|
2784 |
### to the file being written. |
e92cb378144d
Fix precedence of command line arguments
Davor Ocelic <docelic@crystallabs.io>
parents:
101
diff
changeset
|
2785 |
### |
e92cb378144d
Fix precedence of command line arguments
Davor Ocelic <docelic@crystallabs.io>
parents:
101
diff
changeset
|
2786 |
sub save_config |
e92cb378144d
Fix precedence of command line arguments
Davor Ocelic <docelic@crystallabs.io>
parents:
101
diff
changeset
|
2787 |
{ |
115
5ace587c3ea3
Add alias, unalias, configfile
Davor Ocelic <docelic@crystallabs.io>
parents:
114
diff
changeset
|
2788 |
my $confpath = (shift) || "$ENV{'HOME'}/.shelldap.rc"; |
102
e92cb378144d
Fix precedence of command line arguments
Davor Ocelic <docelic@crystallabs.io>
parents:
101
diff
changeset
|
2789 |
|
113
ce001854d4b8
Improve save_config()
Davor Ocelic <docelic@crystallabs.io>
parents:
112
diff
changeset
|
2790 |
# This check is currently unnecessary because the comparison will always |
ce001854d4b8
Improve save_config()
Davor Ocelic <docelic@crystallabs.io>
parents:
112
diff
changeset
|
2791 |
# be true, but is left here for effect of least surprise in the future. |
ce001854d4b8
Improve save_config()
Davor Ocelic <docelic@crystallabs.io>
parents:
112
diff
changeset
|
2792 |
if( defined($conf->{'configfile'}) and ($confpath eq $conf->{'configfile'})) { |
ce001854d4b8
Improve save_config()
Davor Ocelic <docelic@crystallabs.io>
parents:
112
diff
changeset
|
2793 |
delete $conf->{'configfile'} |
102
e92cb378144d
Fix precedence of command line arguments
Davor Ocelic <docelic@crystallabs.io>
parents:
101
diff
changeset
|
2794 |
} |
e92cb378144d
Fix precedence of command line arguments
Davor Ocelic <docelic@crystallabs.io>
parents:
101
diff
changeset
|
2795 |
|
113
ce001854d4b8
Improve save_config()
Davor Ocelic <docelic@crystallabs.io>
parents:
112
diff
changeset
|
2796 |
YAML::Syck::DumpFile( $confpath, $conf ); |
ce001854d4b8
Improve save_config()
Davor Ocelic <docelic@crystallabs.io>
parents:
112
diff
changeset
|
2797 |
chmod 0600, $confpath; |
102
e92cb378144d
Fix precedence of command line arguments
Davor Ocelic <docelic@crystallabs.io>
parents:
101
diff
changeset
|
2798 |
|
e92cb378144d
Fix precedence of command line arguments
Davor Ocelic <docelic@crystallabs.io>
parents:
101
diff
changeset
|
2799 |
return 1; |
e92cb378144d
Fix precedence of command line arguments
Davor Ocelic <docelic@crystallabs.io>
parents:
101
diff
changeset
|
2800 |
} |
e92cb378144d
Fix precedence of command line arguments
Davor Ocelic <docelic@crystallabs.io>
parents:
101
diff
changeset
|
2801 |
|
118
2d7f16eff198
Use local implementation of slurp()
Davor Ocelic <docelic@crystallabs.io>
parents:
117
diff
changeset
|
2802 |
sub slurp |
2d7f16eff198
Use local implementation of slurp()
Davor Ocelic <docelic@crystallabs.io>
parents:
117
diff
changeset
|
2803 |
{ |
2d7f16eff198
Use local implementation of slurp()
Davor Ocelic <docelic@crystallabs.io>
parents:
117
diff
changeset
|
2804 |
open my $fh, '<:encoding(UTF-8)', $_[0]; |
2d7f16eff198
Use local implementation of slurp()
Davor Ocelic <docelic@crystallabs.io>
parents:
117
diff
changeset
|
2805 |
local $/; |
2d7f16eff198
Use local implementation of slurp()
Davor Ocelic <docelic@crystallabs.io>
parents:
117
diff
changeset
|
2806 |
my $ret = <$fh>; |
2d7f16eff198
Use local implementation of slurp()
Davor Ocelic <docelic@crystallabs.io>
parents:
117
diff
changeset
|
2807 |
close $fh; |
2d7f16eff198
Use local implementation of slurp()
Davor Ocelic <docelic@crystallabs.io>
parents:
117
diff
changeset
|
2808 |
return $ret; |
2d7f16eff198
Use local implementation of slurp()
Davor Ocelic <docelic@crystallabs.io>
parents:
117
diff
changeset
|
2809 |
}; |
2d7f16eff198
Use local implementation of slurp()
Davor Ocelic <docelic@crystallabs.io>
parents:
117
diff
changeset
|
2810 |
|
50 | 2811 |
### EOF |
0 | 2812 |