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