1*449108beSjmc.\" $OpenBSD: ldap.1,v 1.11 2021/02/10 06:52:05 jmc Exp $ 29107066aSreyk.\" 39107066aSreyk.\" Copyright (c) 2018 Reyk Floeter <reyk@openbsd.org> 49107066aSreyk.\" 59107066aSreyk.\" Permission to use, copy, modify, and distribute this software for any 69107066aSreyk.\" purpose with or without fee is hereby granted, provided that the above 79107066aSreyk.\" copyright notice and this permission notice appear in all copies. 89107066aSreyk.\" 99107066aSreyk.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 109107066aSreyk.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 119107066aSreyk.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 129107066aSreyk.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 139107066aSreyk.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 149107066aSreyk.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 159107066aSreyk.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 169107066aSreyk.\" 17*449108beSjmc.Dd $Mdocdate: February 10 2021 $ 186006b8eaSjmc.Dt LDAP 1 199107066aSreyk.Os 209107066aSreyk.Sh NAME 219107066aSreyk.Nm ldap 226006b8eaSjmc.Nd simple LDAP client 239107066aSreyk.Sh SYNOPSIS 249107066aSreyk.Nm ldap 2595259b0aSjmc.Cm search 269107066aSreyk.Op Fl LvWxZ 279107066aSreyk.Op Fl b Ar basedn 289107066aSreyk.Op Fl c Ar CAfile 299107066aSreyk.Op Fl D Ar binddn 309107066aSreyk.Op Fl H Ar host 319107066aSreyk.Op Fl l Ar timelimit 329107066aSreyk.Op Fl s Ar scope 339107066aSreyk.Op Fl w Ar secret 341f1da8f4Sreyk.Op Fl y Ar secretfile 359107066aSreyk.Op Fl z Ar sizelimit 3695259b0aSjmc.Op Ar filter 3795259b0aSjmc.Op Ar attributes ... 389107066aSreyk.Sh DESCRIPTION 399107066aSreykThe 409107066aSreyk.Nm 415b3b1932Sjmcutility is a simple LDAP client. 429107066aSreykIt queries an LDAP server to perform a command and outputs the results 439107066aSreykin the LDAP Data Interchange Format (LDIF). 449107066aSreyk.Bl -tag -width Ds 4595259b0aSjmc.It Cm search Ar options Oo Ar filter Oc Op Ar attributes ... 469107066aSreykPerform a directory search request. 479107066aSreykThe optional 489107066aSreyk.Ar filter 499107066aSreykargument specifies the LDAP filter for the directory search. 509107066aSreykThe default is 519107066aSreyk.Ar (objectClass=*) 529107066aSreykand the format must comply to the 539107066aSreyk.Dq String Representation of Search Filters 549107066aSreykas described in RFC 4515. 559107066aSreykIf one or more 569107066aSreyk.Ar attribute 579107066aSreykoptions are specified, 589107066aSreyk.Nm 599107066aSreykrestricts the output to the specified attributes. 609107066aSreyk.El 619107066aSreyk.Pp 629107066aSreykThe options are as follows: 639107066aSreyk.Bl -tag -width Ds 649107066aSreyk.It Fl b Ar basedn 659107066aSreykUse the specified distinguished name (dn) as the starting point for 669107066aSreykdirectory search requests. 679107066aSreyk.It Fl c Ar CAfile 689107066aSreykWhen TLS is enabled, load the CA bundle for certificate verification 699107066aSreykfrom the specified file. 709107066aSreykThe default is 719107066aSreyk.Pa /etc/ssl/cert.pem . 729107066aSreykIf the LDAP server uses a self-signed certificate, 739107066aSreykuse a file that contains the server certificate in PEM format, e.g. 749107066aSreyk.Pa /etc/ssl/ldapserver.example.com.crt . 759107066aSreyk.It Fl D Ar binddn 769107066aSreykUse the specified distinguished name to bind to the directory. 779107066aSreyk.It Fl H Ar host 789107066aSreykThe hostname of the LDAP server or an LDAP URL. 799107066aSreykThe LDAP URL is described in RFC 4516 with the following format: 809107066aSreyk.Pp 819107066aSreyk.Sm off 829107066aSreyk.Op Ar protocol No :// 839107066aSreyk.Ar host Op : Ar port 8495259b0aSjmc.Oo 8595259b0aSjmc.Li / Ar basedn 8695259b0aSjmc.Li ?\& Ar attribute , ... 8795259b0aSjmc.Li ?\& Ar scope 8895259b0aSjmc.Li ?\& Ar filter 899107066aSreyk.Oc 909107066aSreyk.Sm on 919107066aSreyk.Pp 9295259b0aSjmcThe default is 9395259b0aSjmc.Ar ldap://localhost:389/ . 9495259b0aSjmcEach of 9595259b0aSjmc.Ar basedn , attribute , scope 9695259b0aSjmcand 9795259b0aSjmc.Ar filter 9895259b0aSjmcmay be omitted, 9995259b0aSjmcbut the preceding 10095259b0aSjmc.Sq / 10195259b0aSjmcor 10295259b0aSjmc.Sq ?\& 10395259b0aSjmcis required if a subsequent field is non-empty. 10495259b0aSjmc.Pp 1059107066aSreykThe following protocols are supported: 1069107066aSreyk.Pp 1079107066aSreyk.Bl -tag -width "ldap+tls" -compact 1089107066aSreyk.It ldap 1099107066aSreykConnect with TCP in plain text. 1109107066aSreykThis is the default. 1119107066aSreyk.It ldaps 1129107066aSreykConnect with TLS. 1139107066aSreykThe default port is 636. 1149107066aSreyk.It ldap+tls 1159107066aSreykConnect with TCP and enable TLS using the StartTLS operation. 1169107066aSreykThis is the same as the 1179107066aSreyk.Fl Z 1189107066aSreykoption. 1199107066aSreyk.It ldapi 1209107066aSreykConnect to a UNIX-domain socket. 1216006b8eaSjmcThe host argument is required to be a URL-encoded path, for example 1229107066aSreyk.Ar ldapi://%2fvar%2frun%2fldapi 1239107066aSreykfor 1249107066aSreyk.Pa /var/run/ldapi . 1259107066aSreyk.El 1269107066aSreyk.It Fl L 1279107066aSreykOutput the directory search result in a standards-compliant version of 1289107066aSreykthe LDAP Data Interchange Format (LDIF). 1299107066aSreykThis encodes attribute values that include non-printable or UTF-8 1309107066aSreykcharacters in the Base64 format and wraps lines at a 79-character limit. 1319107066aSreykIf this option is not specified, 1329107066aSreyk.Nm 1339107066aSreykencodes 1349107066aSreyk.Dq unsafe 1359107066aSreykcharacters and newlines in a visual format using 1369107066aSreyk.Xr vis 3 1379107066aSreykinstead. 1389107066aSreyk.It Fl l Ar timelimit 1399107066aSreykRequest the server to abort the search request after 1409107066aSreyk.Ar timelimit 1419107066aSreykseconds. 142*449108beSjmcThe default value is 0 for no limit. 1439107066aSreyk.It Fl s Ar scope 1449107066aSreykSpecify the 1459107066aSreyk.Ar scope 1469107066aSreykto be either 1479107066aSreyk.Ic base , 1489107066aSreyk.Ic one , 1499107066aSreykor 1509107066aSreyk.Ic sub . 1519107066aSreykThe default is 1529107066aSreyk.Ic sub 1539107066aSreykfor subtree searches. 1549107066aSreyk.It Fl v 155*449108beSjmcProduce more verbose output. 1569107066aSreyk.It Fl W 1579107066aSreykPrompt for the bind secret with echo turned off. 1589107066aSreyk.It Fl w Ar secret 1599107066aSreykSpecify the bind secret on the command line. 1609107066aSreyk.It Fl x 1619107066aSreykUse simple authentication. 1629107066aSreykThis is the default as 1639107066aSreyk.Nm 1649107066aSreykdoes not support SASL authentication. 1651f1da8f4Sreyk.It Fl y Ar secretfile 1661f1da8f4SreykRead the bind secret from the first line of the specified file or from 1671f1da8f4Sreykstandard input if the 1681f1da8f4Sreyk.Ar secretfile 1691f1da8f4Sreykargument is 1701f1da8f4Sreyk.Sq - . 1711f1da8f4SreykThe file must not be world-readable if it is a regular file. 1729107066aSreyk.It Fl Z 1739107066aSreykEnable TLS using the StartTLS operation. 1749107066aSreyk.It Fl z Ar sizelimit 1759107066aSreykRequest the server to limit the search result to a maximum number of 1769107066aSreyk.Ar sizelimit 1779107066aSreykentries. 178*449108beSjmcThe default value is 0 for no limit. 1799107066aSreyk.El 1806006b8eaSjmc.Sh FILES 1816006b8eaSjmc.Bl -tag -width "/etc/ssl/cert.pemXXX" -compact 1826006b8eaSjmc.It Pa /etc/ssl/cert.pem 1836006b8eaSjmcDefault CA file. 1846006b8eaSjmc.El 1859107066aSreyk.Sh EXAMPLES 1869107066aSreykThe following script can be used with the 1879107066aSreyk.Ar AuthorizedKeysCommand 1889107066aSreykoption of 1899107066aSreyk.Xr sshd 8 : 1909107066aSreyk.Bd -literal -offset indent 1919107066aSreyk#!/bin/sh 1929107066aSreykldap search -D cn=Reader,dc=example,dc=com -w mypass123 \e 1939107066aSreyk -b ou=People,dc=example,dc=com \e 1949107066aSreyk -H ldapserver -c /etc/ssl/ldapserver.crt -Z \e 1959107066aSreyk "(&(objectClass=bsdAccount)(uid=$1))" sshPublicKey | \e 1969cf814cdSreyk sed 's/^sshPublicKey: //p;d;' 1979107066aSreykexit 0 1989107066aSreyk.Ed 1999107066aSreyk.Pp 2009107066aSreykAnd the related configuration in 2019107066aSreyk.Xr sshd_config 5 : 2029107066aSreyk.Bd -literal -offset indent 2039107066aSreykMatch Group ldapusers 2049107066aSreyk AuthorizedKeysCommand /etc/ssh/ldap-authorized_keys.sh 2059107066aSreyk AuthorizedKeysCommandUser _ldap 2069107066aSreyk.Ed 2079107066aSreyk.Sh SEE ALSO 2089107066aSreyk.Xr sshd_config 5 , 2099107066aSreyk.Xr ldapd 8 , 2109107066aSreyk.Xr sshd 8 2119107066aSreyk.Sh STANDARDS 2129107066aSreyk.Rs 2139107066aSreyk.%A G. Good 2149107066aSreyk.%D June 2000 2159107066aSreyk.%R RFC 2849 2169107066aSreyk.%T The LDAP Data Interchange Format (LDIF) - Technical Specification 2179107066aSreyk.Re 2189107066aSreyk.Pp 2199107066aSreyk.Rs 2209107066aSreyk.%A M. Smith, Ed. 2219107066aSreyk.%A T. Howes 2229107066aSreyk.%D June 2006 2239107066aSreyk.%R RFC 4515 2249107066aSreyk.%T Lightweight Directory Access Protocol (LDAP): String Representation of Search Filters 2259107066aSreyk.Re 2269107066aSreyk.Pp 2279107066aSreyk.Rs 2289107066aSreyk.%A M. Smith, Ed. 2299107066aSreyk.%A T. Howes 2309107066aSreyk.%D June 2006 2319107066aSreyk.%R RFC 4516 2329107066aSreyk.%T Lightweight Directory Access Protocol (LDAP): Uniform Resource Locator 2336006b8eaSjmc.Re 2340097d81bSrob.Sh HISTORY 2350097d81bSrobThe 2360097d81bSrob.Nm 2375b3b1932Sjmcutility first appeared in 2380097d81bSrob.Ox 6.4 . 2399107066aSreyk.Sh AUTHORS 2409107066aSreyk.An -nosplit 2419107066aSreykThe 2429107066aSreyk.Nm 2435b3b1932Sjmcutility was written by 2449107066aSreyk.An Reyk Floeter Aq Mt reyk@openbsd.org . 2459107066aSreyk.Sh CAVEATS 2465b3b1932SjmcSASL authentication is not supported. 2476006b8eaSjmcAuthentication should be performed using simple authentication over a 2489107066aSreykTLS connection. 249