1 diff -Nru -x Makefile -x 'buildpkg.*' -x opensshd.init -x 'ssh_prng_*' openssh-4.1p1/Makefile.in openssh-4.1p1-lpk/Makefile.in
2 --- openssh-4.1p1/Makefile.in 2005-02-26 00:12:38.000000000 +0100
3 +++ openssh-4.1p1-lpk/Makefile.in 2005-07-07 18:14:03.000000000 +0200
6 auth2-gss.o gss-serv.o gss-serv-krb5.o \
7 loginrec.o auth-pam.o auth-shadow.o auth-sia.o md5crypt.o \
9 + audit.o audit-bsm.o ldapauth.o
11 MANPAGES = scp.1.out ssh-add.1.out ssh-agent.1.out ssh-keygen.1.out ssh-keyscan.1.out ssh.1.out sshd.8.out sftp-server.8.out sftp.1.out ssh-rand-helper.8.out ssh-keysign.8.out sshd_config.5.out ssh_config.5.out
12 MANPAGES_IN = scp.1 ssh-add.1 ssh-agent.1 ssh-keygen.1 ssh-keyscan.1 ssh.1 sshd.8 sftp-server.8 sftp.1 ssh-rand-helper.8 ssh-keysign.8 sshd_config.5 ssh_config.5
13 diff -Nru -x Makefile -x 'buildpkg.*' -x opensshd.init -x 'ssh_prng_*' openssh-4.1p1/README.lpk openssh-4.1p1-lpk/README.lpk
14 --- openssh-4.1p1/README.lpk 1970-01-01 01:00:00.000000000 +0100
15 +++ openssh-4.1p1-lpk/README.lpk 2005-07-07 18:14:03.000000000 +0200
17 +OpenSSH LDAP PUBLIC KEY PATCH
18 +Copyright (c) 2003 Eric AUGE (eau@phear.org)
21 +Redistribution and use in source and binary forms, with or without
22 +modification, are permitted provided that the following conditions
24 +1. Redistributions of source code must retain the above copyright
25 + notice, this list of conditions and the following disclaimer.
26 +2. Redistributions in binary form must reproduce the above copyright
27 + notice, this list of conditions and the following disclaimer in the
28 + documentation and/or other materials provided with the distribution.
29 +3. The name of the author may not be used to endorse or promote products
30 + derived from this software without specific prior written permission.
32 +THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
33 +IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
34 +OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
35 +IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
36 +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
37 +NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
38 +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
39 +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
40 +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
41 +THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
43 +purposes of this patch:
45 +This patch would help to have authentication centralization policy
46 +using ssh public key authentication.
47 +This patch could be an alternative to other "secure" authentication system
48 +working in a similar way (Kerberos, SecurID, etc...), except the fact
49 +that it's based on OpenSSH and its public key abilities.
52 +'uid': means unix accounts existing on the current server
53 +'lpkServerGroup:' mean server group configured on the current server ('lpkServerGroup' in sshd_config)
58 + server1 (uid: eau,rival,toto) (lpkServerGroup: unix)
60 + / \ --- - server3 (uid: eau, titi) (lpkServerGroup: unix)
62 + | eau ,rival | server2 (uid: rival, eau) (lpkServerGroup: unix)
64 + | userx,.... | server5 (uid: eau) (lpkServerGroup: mail)
66 + ----- - server4 (uid: eau, rival) (no group configured)
72 + * configured LDAP server somewhere on the network (i.e. OpenLDAP)
73 + * patched sshd (with this patch ;)
74 + * LDAP user(/group) entry (look at users.ldif (& groups.ldif)):
76 + - attached to the 'ldapPublicKey' objectclass
77 + - attached to the 'posixAccount' objectclass
78 + - with a filled 'sshPublicKey' attribute
80 + dn: uid=eau,ou=users,dc=cuckoos,dc=net
83 + objectclass: organizationalPerson
84 + objectclass: posixAccount
85 + objectclass: ldapPublicKey
86 + description: Eric AUGE Account
93 + homeDirectory: /export/home/eau
94 + sshPublicKey: ssh-dss AAAAB3...
95 + sshPublicKey: ssh-dss AAAAM5...
98 + - attached to the 'posixGroup' objectclass
99 + - with a 'cn' groupname attribute
100 + - with multiple 'memberUid' attributes filled with usernames allowed in this group
103 + dn: cn=unix,ou=groups,dc=cuckoos,dc=net
105 + objectclass: posixGroup
106 + description: Unix based servers group
117 + If a user wants to authenticate to log in a server the sshd, will first look for authentication method allowed (RSAauth,kerberos,etc..)
118 + and if RSAauth and tickets based auth fails, it will fallback to standard password authentication (if enabled).
121 + If a user want to authenticate to log in a server, the sshd will first look for auth method including LDAP pubkey, if the ldappubkey options is enabled.
122 + It will do an ldapsearch to get the public key directly from the LDAP instead of reading it from the server filesystem.
123 + (usually in $HOME/.ssh/authorized_keys)
125 + If groups are enabled, it will also check if the user that wants to login is in the group of the server he is trying to log into.
126 + If it fails, it falls back on RSA auth files ($HOME/.ssh/authorized_keys), etc.. and finally to standard password authentication (if enabled).
128 + 7 tokens are added to sshd_config :
129 + # here is the new patched ldap related tokens
130 + # entries in your LDAP must be posixAccount & strongAuthenticationUser & posixGroup
131 + UseLPK yes # look the pub key into LDAP
132 + LpkServers ldap://10.31.32.5/ ldap://10.31.32.4 ldap://10.31.32.3 # which LDAP server for users ? (URL format)
133 + LpkUserDN ou=users,dc=foobar,dc=net # which base DN for users ?
134 + LpkGroupDN ou=groups,dc=foobar,dc=net # which base DN for groups ?
135 + LpkBindDN cn=manager,dc=foobar,dc=net # which bind DN ?
136 + LpkBindPw asecret # bind DN credidentials
137 + LpkServerGroup agroupname # the group the server is part of
139 + Right now i'm using anonymous binding to get public keys, because getting public keys of someone doesn't impersonate him¸ but there is some
140 + flaws you have to take care of.
142 +- HOW TO INSERT A USER/KEY INTO AN LDAP ENTRY
144 + * my way (there is plenty :)
145 + - create ldif file (i.e. users.ldif)
146 + - cat ~/.ssh/id_dsa.pub OR cat ~/.ssh/id_rsa.pub OR cat ~/.ssh/identity.pub
147 + - my way in 4 steps :
150 + # you add this to the user entry in the LDIF file :
152 + objectclass: posixAccount
153 + objectclass: ldapPublicKey
155 + sshPubliKey: ssh-dss AAAABDh12DDUR2...
158 + # insert your entry and you're done :)
159 + ldapadd -D balblabla -w bleh < file.ldif
161 + all standard options can be present in the 'sshPublicKey' attribute.
165 + Simply because, i was looking for a way to centralize all sysadmins authentication, easily, without completely using LDAP
166 + as authentication method (like pam_ldap etc..).
168 + After looking into Kerberos, SecurID, and other centralized secure authentications systems, the use of RSA and LDAP to get
169 + public key for authentication allows us to control who has access to which server (the user needs an account and to be in 'strongAuthenticationUser'
170 + objectclass within LDAP and part of the group the SSH server is in).
172 + Passwords update are no longer a nightmare for a server farm (key pair passphrase is stored on each user's box and private key is locally encrypted using his passphrase
173 + so each user can change it as much as he wants).
175 + Blocking a user account can be done directly from the LDAP (if sshd is using RSAAuth + ldap only).
178 + Entry in the LDAP server must respect 'posixAccount' and 'ldapPublicKey' which are defined in core.schema.
179 + and the additionnal lpk.schema.
181 + This patch could allow a smooth transition between standard auth (/etc/passwd) and complete LDAP based authentication
182 + (pamldap, nss_ldap, etc..).
184 + This can be an alternative to other (old?/expensive?) authentication methods (Kerberos/SecurID/..).
186 + Referring to schema at the beginning of this file if user 'eau' is only in group 'unix'
187 + 'eau' would ONLY access 'server1', 'server2', 'server3' AND 'server4' BUT NOT 'server5'.
188 + If you then modify the LDAP 'mail' group entry to add 'memberUid: eau' THEN user 'eau' would be able
189 + to log in 'server5' (i hope you got the idea, my english is bad :).
191 + Each server's sshd is patched and configured to ask the public key and the group infos in the LDAP
193 + When you want to allow a new user to have access to the server parc, you just add him an account on
194 + your servers, you add his public key into his entry on the LDAP server, it's done.
196 + Because sshds are looking public keys into the LDAP directly instead of a file ($HOME/.ssh/authorized_keys).
198 + When the user needs to change his passphrase he can do it directly from his workstation by changing
199 + his own key set lock passphrase, and all servers are automatically aware.
201 + With a CAREFUL LDAP server configuration you could allow a user to add/delete/modify his own entry himself
202 + so he can add/modify/delete himself his public key when needed.
205 + LDAP must be well configured, getting the public key of some user is not a problem, but if anonymous LDAP
206 + allow write to users dn, somebody could replace someuser's public key by its own and impersonate some
207 + of your users in all your server farm be VERY CAREFUL.
209 + MITM attack when sshd is requesting the public key, could lead to a compromise of your servers allowing login
210 + as the impersonnated user.
212 + If LDAP server is down then, fallback on passwd auth.
214 + the ldap code part has not been well audited yet.
216 +- LDAP USER ENTRY EXAMPLES (LDIF Format, look in users.ldif)
218 + dn: uid=jdoe,ou=users,dc=foobar,dc=net
220 + objectclass: person
221 + objectclass: organizationalPerson
222 + objectclass: posixAccount
223 + objectclass: ldapPublicKey
224 + description: My account
230 + homeDirectory: /home/jdoe
231 + sshPublicKey: ssh-dss AAAAB3NzaC1kc3MAAAEBAOvL8pREUg9wSy/8+hQJ54YF3AXkB0OZrXB....
235 +- LDAP GROUP ENTRY EXAMPLES (LDIF Format, look in groups.ldif)
237 + dn: cn=unix,ou=groups,dc=cuckoos,dc=net
239 + objectclass: posixGroup
240 + description: Unix based servers group
250 +Multiple 'sshPublicKey' in a user entry are allowed, as well as multiple 'memberUid' attributes in a group entry
254 + 1. ./configure --with-your-options --with-libs="-lldap" --with-ldflags="-L/path/to/your/openldap/lib" --with-cppflags="-I/path/to/your/openldap/include -DWITH_LDAP_PUBKEY"
259 + I hope this could help, and i hope to be clear enough,, or give ideas. questions/comments/improvements are welcome.
262 + - filters in the LDAP URL so ppl can choose on others criteria as well
264 + - auto provisionning
265 + - new schema (snu@opendarwin.org idea)
267 +- CONTRIBUTORS/IDEAS/GREETS :
268 + - Falk Siemonsmeier -> 3.7 patch port candidate
269 + - Jacob Rief -> ideas (group && cleanups)
270 + - Michael.Durchgraf@dregis.com -> Bugfixes thanks ;)
271 + - frederic.peters@free.fr -> X509 keys LDAP patch (old)
273 + - finlay dobbie -> new fresh start with this guy :)
276 + - Eric AUGE <eau@phear.org>, <eau@opendarwin.org>
277 diff -Nru -x Makefile -x 'buildpkg.*' -x opensshd.init -x 'ssh_prng_*' openssh-4.1p1/auth-rsa.c openssh-4.1p1-lpk/auth-rsa.c
278 --- openssh-4.1p1/auth-rsa.c 2004-12-11 03:39:50.000000000 +0100
279 +++ openssh-4.1p1-lpk/auth-rsa.c 2005-07-07 18:14:03.000000000 +0200
280 @@ -160,10 +160,96 @@
284 +#ifdef WITH_LDAP_PUBKEY
289 /* Temporarily use the user's uid. */
290 temporarily_use_uid(pw);
292 +#ifdef WITH_LDAP_PUBKEY
293 + /* here is the job */
294 + key = key_new(KEY_RSA1);
296 + if (options.lpk.on) {
297 + debug("[LDAP] trying LDAP first uid=%s", pw->pw_name);
298 + if ( ldap_ismember(&options.lpk, pw->pw_name) > 0) {
299 + if ( (k = ldap_getuserkey(&options.lpk, pw->pw_name)) != NULL) {
300 + for (i = 0 ; i < k->num ; i++) {
301 + char *cp, *options = NULL;
303 + for (cp = k->keys[i]; *cp == ' ' || *cp == '\t'; cp++)
305 + if (!*cp || *cp == '\n' || *cp == '#')
309 + * Check if there are options for this key, and if so,
310 + * save their starting address and skip the option part
311 + * for now. If there are no options, set the starting
314 + if (*cp < '0' || *cp > '9') {
317 + for (; *cp && (quoted || (*cp != ' ' && *cp != '\t')); cp++) {
318 + if (*cp == '\\' && cp[1] == '"')
319 + cp++; /* Skip both */
320 + else if (*cp == '"')
326 + /* Parse the key from the line. */
327 + if (hostfile_read_key(&cp, &bits, key) == 0) {
328 + debug("[LDAP] line %d: non ssh1 key syntax", i);
331 + /* cp now points to the comment part. */
333 + /* Check if the we have found the desired key (identified by its modulus). */
334 + if (BN_cmp(key->rsa->n, client_n) != 0)
337 + /* check the real bits */
338 + if (bits != BN_num_bits(key->rsa->n))
339 + logit("[LDAP] Warning: ldap, line %lu: keysize mismatch: "
340 + "actual %d vs. announced %d.", (unsigned long)i, BN_num_bits(key->rsa->n), bits);
342 + /* We have found the desired key. */
344 + * If our options do not allow this key to be used,
345 + * do not send challenge.
347 + if (!auth_parse_options(pw, options, "[LDAP]", (unsigned long) i))
350 + /* break out, this key is allowed */
353 + /* add the return stuff etc... */
354 + /* Restore the privileged uid. */
357 + /* return key if allowed */
358 + if (allowed && rkey != NULL)
367 + logit("[LDAP] no keys found for '%s'!", pw->pw_name);
370 + logit("[LDAP] '%s' is not in '%s'", pw->pw_name, options.lpk.sgroup);
374 /* The authorized keys. */
375 file = authorized_keys_file(pw);
376 debug("trying public RSA key file %s", file);
377 diff -Nru -x Makefile -x 'buildpkg.*' -x opensshd.init -x 'ssh_prng_*' openssh-4.1p1/auth2-pubkey.c openssh-4.1p1-lpk/auth2-pubkey.c
378 --- openssh-4.1p1/auth2-pubkey.c 2004-12-11 03:39:50.000000000 +0100
379 +++ openssh-4.1p1-lpk/auth2-pubkey.c 2005-07-07 18:14:03.000000000 +0200
381 #include "monitor_wrap.h"
384 +#ifdef WITH_LDAP_PUBKEY
385 +#include "ldapauth.h"
389 extern ServerOptions options;
390 extern u_char *session_id2;
391 @@ -176,10 +180,79 @@
395 +#ifdef WITH_LDAP_PUBKEY
400 /* Temporarily use the user's uid. */
401 temporarily_use_uid(pw);
403 +#ifdef WITH_LDAP_PUBKEY
405 + /* allocate a new key type */
406 + found = key_new(key->type);
408 + /* first check if the options is enabled, then try.. */
409 + if (options.lpk.on) {
410 + debug("[LDAP] trying LDAP first uid=%s",pw->pw_name);
411 + if (ldap_ismember(&options.lpk, pw->pw_name) > 0) {
412 + if ((k = ldap_getuserkey(&options.lpk, pw->pw_name)) != NULL) {
413 + /* Skip leading whitespace, empty and comment lines. */
414 + for (i = 0 ; i < k->num ; i++) {
415 + /* dont forget if multiple keys to reset options */
416 + char *cp, *options = NULL;
418 + for (cp = (char *)k->keys[i]; *cp == ' ' || *cp == '\t'; cp++)
420 + if (!*cp || *cp == '\n' || *cp == '#')
423 + if (key_read(found, &cp) != 1) {
424 + /* no key? check if there are options for this key */
426 + debug2("[LDAP] user_key_allowed: check options: '%s'", cp);
428 + for (; *cp && (quoted || (*cp != ' ' && *cp != '\t')); cp++) {
429 + if (*cp == '\\' && cp[1] == '"')
430 + cp++; /* Skip both */
431 + else if (*cp == '"')
434 + /* Skip remaining whitespace. */
435 + for (; *cp == ' ' || *cp == '\t'; cp++)
437 + if (key_read(found, &cp) != 1) {
438 + debug2("[LDAP] user_key_allowed: advance: '%s'", cp);
439 + /* still no key? advance to next line*/
444 + if (key_equal(found, key) &&
445 + auth_parse_options(pw, options, file, linenum) == 1) {
447 + debug("[LDAP] matching key found");
448 + fp = key_fingerprint(found, SSH_FP_MD5, SSH_FP_HEX);
449 + verbose("[LDAP] Found matching %s key: %s", key_type(found), fp);
451 + /* restoring memory */
459 + }/* end of LDAP for() */
461 + logit("[LDAP] no keys found for '%s'!", pw->pw_name);
464 + logit("[LDAP] '%s' is not in '%s'", pw->pw_name, options.lpk.sgroup);
468 debug("trying public key file %s", file);
470 /* Fail quietly if file does not exist */
471 diff -Nru -x Makefile -x 'buildpkg.*' -x opensshd.init -x 'ssh_prng_*' openssh-4.1p1/config.h.in openssh-4.1p1-lpk/config.h.in
472 --- openssh-4.1p1/config.h.in 2005-05-25 14:26:09.000000000 +0200
473 +++ openssh-4.1p1-lpk/config.h.in 2005-07-07 18:14:03.000000000 +0200
475 /* Define if you want TCP Wrappers support */
478 +/* Define if you want LDAP support */
479 +#undef WITH_LDAP_PUBKEY
481 /* Define if your libraries define login() */
484 diff -Nru -x Makefile -x 'buildpkg.*' -x opensshd.init -x 'ssh_prng_*' openssh-4.1p1/configure openssh-4.1p1-lpk/configure
485 --- openssh-4.1p1/configure 2005-05-25 14:26:12.000000000 +0200
486 +++ openssh-4.1p1-lpk/configure 2005-07-07 18:14:35.000000000 +0200
488 --with-tcp-wrappers[=PATH] Enable tcpwrappers support (optionally in PATH)
489 --with-libedit[=PATH] Enable libedit support for sftp
490 --with-audit=module Enable EXPERIMENTAL audit support (modules=debug,bsm)
491 + --with-ldap[=PATH] Enable LDAP support (optionally in PATH)
492 --with-pam Enable PAM support
493 --with-ssl-dir=PATH Specify path to OpenSSL installation
494 --with-rand-helper Use subprocess to gather strong randomness
495 @@ -10521,6 +10522,88 @@
499 +# Check whether user wants LDAP support
502 +# Check whether --with-ldap or --without-ldap was given.
503 +if test "${with_ldap+set}" = set; then
504 + withval="$with_ldap"
506 + if test "x$withval" != "xno" ; then
508 + if test "x$withval" != "xyes" ; then
509 + CPPFLAGS="$CPPFLAGS -I${withval}/include"
510 + LDFLAGS="$LDFLAGS -L${withval}/lib"
513 + cat >>confdefs.h <<\_ACEOF
514 +#define WITH_LDAP_PUBKEY 1
517 + LIBS="-lldap $LIBS"
520 + echo "$as_me:$LINENO: checking for LDAP support" >&5
521 +echo $ECHO_N "checking for LDAP support... $ECHO_C" >&6
522 + cat >conftest.$ac_ext <<_ACEOF
525 +cat confdefs.h >>conftest.$ac_ext
526 +cat >>conftest.$ac_ext <<_ACEOF
527 +/* end confdefs.h. */
528 +#include <sys/types.h>
533 +(void)ldap_init(0, 0);
538 +rm -f conftest.$ac_objext
539 +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
540 + (eval $ac_compile) 2>conftest.er1
542 + grep -v '^ *+' conftest.er1 >conftest.err
544 + cat conftest.err >&5
545 + echo "$as_me:$LINENO: \$? = $ac_status" >&5
546 + (exit $ac_status); } &&
547 + { ac_try='test -z "$ac_c_werror_flag"
548 + || test ! -s conftest.err'
549 + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
550 + (eval $ac_try) 2>&5
552 + echo "$as_me:$LINENO: \$? = $ac_status" >&5
553 + (exit $ac_status); }; } &&
554 + { ac_try='test -s conftest.$ac_objext'
555 + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
556 + (eval $ac_try) 2>&5
558 + echo "$as_me:$LINENO: \$? = $ac_status" >&5
559 + (exit $ac_status); }; }; then
560 + echo "$as_me:$LINENO: result: yes" >&5
561 +echo "${ECHO_T}yes" >&6
563 + echo "$as_me: failed program was:" >&5
564 +sed 's/^/| /' conftest.$ac_ext >&5
567 + echo "$as_me:$LINENO: result: no" >&5
568 +echo "${ECHO_T}no" >&6
569 + { { echo "$as_me:$LINENO: error: ** Incomplete or missing ldap libraries **" >&5
570 +echo "$as_me: error: ** Incomplete or missing ldap libraries **" >&2;}
571 + { (exit 1); exit 1; }; }
575 +rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
584 @@ -26280,6 +26363,7 @@
585 echo " Smartcard support: $SCARD_MSG"
586 echo " S/KEY support: $SKEY_MSG"
587 echo " TCP Wrappers support: $TCPW_MSG"
588 +echo " LDAP support: $LDAP_MSG"
589 echo " MD5 password support: $MD5_MSG"
590 echo " libedit support: $LIBEDIT_MSG"
591 echo " IP address in \$DISPLAY hack: $DISPLAY_HACK_MSG"
592 diff -Nru -x Makefile -x 'buildpkg.*' -x opensshd.init -x 'ssh_prng_*' openssh-4.1p1/configure.ac openssh-4.1p1-lpk/configure.ac
593 --- openssh-4.1p1/configure.ac 2005-04-24 09:52:23.000000000 +0200
594 +++ openssh-4.1p1-lpk/configure.ac 2005-07-07 18:14:03.000000000 +0200
599 +# Check whether user wants LDAP support
602 + [ --with-ldap[[=PATH]] Enable LDAP support (optionally in PATH)],
604 + if test "x$withval" != "xno" ; then
606 + if test "x$withval" != "xyes" ; then
607 + CPPFLAGS="$CPPFLAGS -I${withval}/include"
608 + LDFLAGS="$LDFLAGS -L${withval}/lib"
611 + AC_DEFINE(WITH_LDAP_PUBKEY)
612 + LIBS="-lldap $LIBS"
615 + AC_MSG_CHECKING([for LDAP support])
617 + [#include <sys/types.h>
618 + #include <ldap.h>],
619 + [(void)ldap_init(0, 0);],
620 + [AC_MSG_RESULT(yes)],
623 + AC_MSG_ERROR([** Incomplete or missing ldap libraries **])
630 dnl Checks for library functions. Please keep in alphabetical order
632 arc4random __b64_ntop b64_ntop __b64_pton b64_pton bcopy \
633 @@ -3191,6 +3222,7 @@
634 echo " Smartcard support: $SCARD_MSG"
635 echo " S/KEY support: $SKEY_MSG"
636 echo " TCP Wrappers support: $TCPW_MSG"
637 +echo " LDAP support: $LDAP_MSG"
638 echo " MD5 password support: $MD5_MSG"
639 echo " libedit support: $LIBEDIT_MSG"
640 echo " IP address in \$DISPLAY hack: $DISPLAY_HACK_MSG"
641 diff -Nru -x Makefile -x 'buildpkg.*' -x opensshd.init -x 'ssh_prng_*' openssh-4.1p1/ldapauth.c openssh-4.1p1-lpk/ldapauth.c
642 --- openssh-4.1p1/ldapauth.c 1970-01-01 01:00:00.000000000 +0100
643 +++ openssh-4.1p1-lpk/ldapauth.c 2005-07-07 18:14:03.000000000 +0200
651 + * Copyright (c) 2005, Eric AUGE <eau@phear.org>
652 + * All rights reserved.
654 + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
656 + * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
657 + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
658 + * Neither the name of the phear.org nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
660 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
661 + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
662 + * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
663 + * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
664 + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
665 + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
670 +#include "includes.h"
672 +#ifdef WITH_LDAP_PUBKEY
679 +#include "ldapauth.h"
682 +static char *attrs[] = {
687 +/* filter building infos */
688 +#define FILTER_GROUP_PREFIX "(&(objectclass=posixGroup)"
689 +#define FILTER_OR_PREFIX "(|"
690 +#define FILTER_OR_SUFFIX ")"
691 +#define FILTER_CN_PREFIX "(cn="
692 +#define FILTER_CN_SUFFIX ")"
693 +#define FILTER_UID_FORMAT "(memberUid=%s)"
694 +#define FILTER_GROUP_SUFFIX ")"
695 +#define FILTER_GROUP_SIZE(group) (size_t) (strlen(group)+(ldap_count_group(group)*5)+52)
697 +/* just filter building stuff */
698 +#define REQUEST_GROUP_SIZE(filter, uid) (size_t) (strlen(filter)+strlen(uid)+1)
699 +#define REQUEST_GROUP(buffer, prefilter, pwname) \
700 + buffer = (char *) calloc(REQUEST_GROUP_SIZE(prefilter, pwname), sizeof(char)); \
702 + perror("calloc()"); \
705 + snprintf(buffer, REQUEST_GROUP_SIZE(prefilter,pwname), prefilter, pwname)
707 +XXX OLD group building macros
708 +#define REQUEST_GROUP_SIZE(grp, uid) (size_t) (strlen(grp)+strlen(uid)+46)
709 +#define REQUEST_GROUP(buffer,pwname,grp) \
710 + buffer = (char *) calloc(REQUEST_GROUP_SIZE(grp, pwname), sizeof(char)); \
712 + perror("calloc()"); \
715 + snprintf(buffer,REQUEST_GROUP_SIZE(grp,pwname),"(&(objectclass=posixGroup)(cn=%s)(memberUid=%s))",grp,pwname)
718 +#define REQUEST_USER_SIZE(uid) (size_t) (strlen(uid)+64)
719 +#define REQUEST_USER(buffer, pwname) \
720 + buffer = (char *) calloc(REQUEST_USER_SIZE(pwname), sizeof(char)); \
722 + perror("calloc()"); \
725 + snprintf(buffer,REQUEST_USER_SIZE(pwname),"(&(objectclass=posixAccount)(objectclass=ldapPublicKey)(uid=%s))",pwname)
727 +/* some portable and working tokenizer, lame though */
728 +static int tokenize(char ** o, size_t size, char * input) {
729 + unsigned int i = 0, num;
730 + char * charset = " \t";
731 + char * ptr = input;
733 + /* leading white spaces are ignored */
734 + num = strspn(ptr, charset);
737 + while ((num = strcspn(ptr, charset))) {
749 +void ldap_close(ldap_opt_t * ldap) {
754 + if ( ldap_unbind(ldap->ld) < 0)
755 + ldap_perror(ldap->ld, "ldap_unbind()");
758 + FLAG_SET_DISCONNECTED(ldap->flags);
764 +int ldap_connect(ldap_opt_t * ldap) {
765 + int version = LDAP_VERSION3;
767 + if (!ldap->servers)
770 + /* Connection Init and setup */
771 + ldap->ld = ldap_init(ldap->servers, LDAP_PORT);
773 + ldap_perror(ldap->ld, "ldap_init()");
777 + if ( ldap_set_option(ldap->ld, LDAP_OPT_PROTOCOL_VERSION, &version) != LDAP_OPT_SUCCESS) {
778 + ldap_perror(ldap->ld, "ldap_set_option(LDAP_OPT_PROTOCOL_VERSION)");
782 + /* Timeouts setup */
783 + if (ldap_set_option(ldap->ld, LDAP_OPT_NETWORK_TIMEOUT, &ldap->b_timeout) != LDAP_SUCCESS) {
784 + ldap_perror(ldap->ld, "ldap_set_option(LDAP_OPT_NETWORK_TIMEOUT)");
786 + if (ldap_set_option(ldap->ld, LDAP_OPT_TIMEOUT, &ldap->s_timeout) != LDAP_SUCCESS) {
787 + ldap_perror(ldap->ld, "ldap_set_option(LDAP_OPT_TIMEOUT)");
791 + if ( (ldap->tls == -1) || (ldap->tls == 1) ) {
792 + if (ldap_start_tls_s(ldap->ld, NULL, NULL ) != LDAP_SUCCESS) {
793 + /* failed then reinit the initial connect */
794 + ldap_perror(ldap->ld, "ldap_connect: (TLS) ldap_start_tls()");
795 + if (ldap->tls == 1)
798 + ldap->ld = ldap_init(ldap->servers, LDAP_PORT);
800 + ldap_perror(ldap->ld, "ldap_init()");
804 + if ( ldap_set_option(ldap->ld, LDAP_OPT_PROTOCOL_VERSION, &version) != LDAP_OPT_SUCCESS) {
805 + ldap_perror(ldap->ld, "ldap_set_option()");
812 + if ( ldap_simple_bind_s(ldap->ld, ldap->binddn, ldap->bindpw) != LDAP_SUCCESS) {
813 + ldap_perror(ldap->ld, "ldap_simple_bind_s()");
817 + /* says it is connected */
818 + FLAG_SET_CONNECTED(ldap->flags);
823 +/* must free allocated ressource */
824 +static char * ldap_build_host(char *host, int port) {
825 + unsigned int size = strlen(host)+11;
826 + char * h = (char *) calloc (size, sizeof(char));
831 + rc = snprintf(h, size, "%s:%d ", host, port);
837 +static int ldap_count_group(char * input) {
838 + char * charset = " \t";
839 + char * ptr = input;
840 + unsigned int count = 0;
843 + num = strspn(ptr, charset);
846 + while ((num = strcspn(ptr, charset))) {
856 +char * ldap_parse_groups(char * groups) {
857 + unsigned int buffer_size = FILTER_GROUP_SIZE(groups);
858 + char * buffer = (char *) calloc(buffer_size, sizeof(char));
861 + unsigned int i = 0;
863 + if ((!groups)||(!buffer))
866 + g = strdup(groups);
872 + /* first separate into n tokens */
873 + if ( tokenize(garray, sizeof(garray)/sizeof(*garray), g) < 0) {
879 + /* build the final filter format */
880 + strlcat(buffer, FILTER_GROUP_PREFIX, buffer_size);
881 + strlcat(buffer, FILTER_OR_PREFIX, buffer_size);
883 + while (garray[i]) {
884 + strlcat(buffer, FILTER_CN_PREFIX, buffer_size);
885 + strlcat(buffer, garray[i], buffer_size);
886 + strlcat(buffer, FILTER_CN_SUFFIX, buffer_size);
889 + strlcat(buffer, FILTER_OR_SUFFIX, buffer_size);
890 + strlcat(buffer, FILTER_UID_FORMAT, buffer_size);
891 + strlcat(buffer, FILTER_GROUP_SUFFIX, buffer_size);
897 +/* a bit dirty but leak free */
898 +char * ldap_parse_servers(char * servers) {
900 + char * tmp = NULL, *urls[32];
901 + unsigned int num = 0 , i = 0 , asize = 0;
902 + LDAPURLDesc *urld[32];
907 + /* local copy of the arg */
908 + s = strdup(servers);
912 + /* first separate into URL tokens */
913 + if ( tokenize(urls, sizeof(urls)/sizeof(*urls), s) < 0)
918 + if ( ldap_is_ldap_url(urls[i]) ) {
919 + if (ldap_url_parse(urls[i], &urld[i]) != 0)
928 + /* how much memory do we need */
930 + for (i = 0 ; i < num ; i++)
931 + asize += strlen(urld[i]->lud_host)+11;
934 + s = (char *) calloc( asize+1 , sizeof(char));
936 + for (i = 0 ; i < num ; i++)
937 + ldap_free_urldesc(urld[i]);
941 + /* then build the final host string */
942 + for (i = 0 ; i < num ; i++) {
943 + /* built host part */
944 + tmp = ldap_build_host(urld[i]->lud_host, urld[i]->lud_port);
945 + strncat(s, tmp, strlen(tmp));
946 + ldap_free_urldesc(urld[i]);
953 +void ldap_options_print(ldap_opt_t * ldap) {
954 + printf("ldap options:\n");
955 + printf("servers: %s\n", ldap->servers);
956 + if (ldap->u_basedn)
957 + printf("user basedn: %s\n", ldap->u_basedn);
958 + if (ldap->g_basedn)
959 + printf("group basedn: %s\n", ldap->g_basedn);
961 + printf("binddn: %s\n", ldap->binddn);
963 + printf("bindpw: %s\n", ldap->bindpw);
965 + printf("group: %s\n", ldap->sgroup);
968 +void ldap_options_free(ldap_opt_t * l) {
991 +void ldap_keys_free(ldap_key_t * k) {
992 + ldap_value_free(k->keys);
997 +ldap_key_t * ldap_getuserkey(ldap_opt_t *l, char * user) {
998 + ldap_key_t * k = (ldap_key_t *) calloc (1, sizeof(ldap_key_t));
999 + LDAPMessage *res, *e;
1006 + /* Am i still connected ? RETRY n times */
1007 + /* XXX TODO: setup some conf value for retrying */
1008 + if (!(l->flags & FLAG_CONNECTED))
1009 + for (i = 0 ; i < 2 ; i++)
1010 + if (ldap_connect(l) == 0)
1013 + /* build filter for LDAP request */
1014 + REQUEST_USER(filter, user);
1016 + if ( ldap_search_st( l->ld,
1018 + LDAP_SCOPE_SUBTREE,
1020 + attrs, 0, &l->s_timeout, &res ) != LDAP_SUCCESS) {
1022 + ldap_perror(l->ld, "ldap_search_st()");
1027 + /* XXX error on search, timeout etc.. close ask for reconnect */
1036 + /* check if any results */
1037 + i = ldap_count_entries(l->ld,res);
1039 + ldap_msgfree(res);
1045 + printf("[LDAP] duplicate entries, using the FIRST entry returned\n");
1047 + e = ldap_first_entry(l->ld, res);
1048 + k->keys = ldap_get_values(l->ld, e, PUBKEYATTR);
1049 + k->num = ldap_count_values(k->keys);
1051 + ldap_msgfree(res);
1057 + 0 if user is NOT member of current server group
1058 + 1 if user IS MEMBER of current server group
1060 +int ldap_ismember(ldap_opt_t * l, char * user) {
1065 + if ((!l->sgroup) || !(l->g_basedn))
1068 + /* Am i still connected ? RETRY n times */
1069 + /* XXX TODO: setup some conf value for retrying */
1070 + if (!(l->flags & FLAG_CONNECTED))
1071 + for (i = 0 ; i < 2 ; i++)
1072 + if (ldap_connect(l) == 0)
1075 + /* build filter for LDAP request */
1076 + REQUEST_GROUP(filter, l->fgroup, user);
1078 + if (ldap_search_st( l->ld,
1080 + LDAP_SCOPE_SUBTREE,
1082 + NULL, 0, &l->s_timeout, &res) != LDAP_SUCCESS) {
1084 + ldap_perror(l->ld, "ldap_search_st()");
1088 + /* XXX error on search, timeout etc.. close ask for reconnect */
1096 + /* check if any results */
1097 + if (ldap_count_entries(l->ld, res) > 0) {
1098 + ldap_msgfree(res);
1102 + ldap_msgfree(res);
1107 + * ldap.conf simple parser
1108 + * XXX TODO: sanity checks
1110 + * - free the previous ldap_opt_before replacing entries
1111 + * - free each necessary previously parsed elements
1113 + * -1 on FAILURE, 0 on SUCCESS
1115 +int ldap_parse_lconf(ldap_opt_t * l) {
1116 + FILE * lcd; /* ldap.conf descriptor */
1118 + char * s = NULL, * k = NULL, * v = NULL;
1121 + lcd = fopen (l->l_conf, "r");
1122 + if (lcd == NULL) {
1123 + /* debug("Cannot open %s", l->l_conf); */
1124 + perror("ldap_parse_lconf()");
1128 + while (fgets (buf, sizeof (buf), lcd) != NULL) {
1130 + if (*buf == '\n' || *buf == '#')
1135 + while (*v != '\0' && *v != ' ' && *v != '\t')
1143 + while (*v == ' ' || *v == '\t')
1146 + li = strlen (v) - 1;
1147 + while (v[li] == ' ' || v[li] == '\t' || v[li] == '\n')
1151 + if (!strcasecmp (k, "uri")) {
1152 + if ((l->servers = ldap_parse_servers(strdup (v))) == NULL) {
1153 + fatal("error in ldap servers");
1158 + else if (!strcasecmp (k, "base")) {
1159 + s = strchr (v, '?');
1162 + l->u_basedn = malloc (len + 1);
1163 + strncpy (l->u_basedn, v, len);
1164 + l->u_basedn[len] = '\0';
1166 + l->u_basedn = strdup (v);
1169 + else if (!strcasecmp (k, "binddn")) {
1170 + l->binddn = strdup (v);
1172 + else if (!strcasecmp (k, "bindpw")) {
1173 + l->bindpw = strdup (v);
1175 + else if (!strcasecmp (k, "timelimit")) {
1176 + l->s_timeout.tv_sec = atoi (v);
1178 + else if (!strcasecmp (k, "bind_timelimit")) {
1179 + l->b_timeout.tv_sec = atoi (v);
1181 + else if (!strcasecmp (k, "ssl")) {
1182 + if (!strcasecmp (v, "start_tls"))
1191 +#endif /* WITH_LDAP_PUBKEY */
1192 diff -Nru -x Makefile -x 'buildpkg.*' -x opensshd.init -x 'ssh_prng_*' openssh-4.1p1/ldapauth.h openssh-4.1p1-lpk/ldapauth.h
1193 --- openssh-4.1p1/ldapauth.h 1970-01-01 01:00:00.000000000 +0100
1194 +++ openssh-4.1p1-lpk/ldapauth.h 2005-07-07 18:14:03.000000000 +0200
1202 + * Copyright (c) 2005, Eric AUGE <eau@phear.org>
1203 + * All rights reserved.
1205 + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1207 + * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
1208 + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
1209 + * Neither the name of the phear.org nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
1211 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
1212 + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1213 + * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
1214 + * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
1215 + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
1216 + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1224 +#include <string.h>
1229 +/* tokens in use for config */
1230 +#define _DEFAULT_LPK_TOKEN "UseLPK"
1231 +#define _DEFAULT_SRV_TOKEN "LpkServers"
1232 +#define _DEFAULT_USR_TOKEN "LpkUserDN"
1233 +#define _DEFAULT_GRP_TOKEN "LpkGroupDN"
1234 +#define _DEFAULT_BDN_TOKEN "LpkBindDN"
1235 +#define _DEFAULT_BPW_TOKEN "LpkBindPw"
1236 +#define _DEFAULT_MYG_TOKEN "LpkServerGroup"
1237 +#define _DEFAULT_TLS_TOKEN "LpkForceTLS"
1238 +#define _DEFAULT_BTI_TOKEN "LpkBindTimelimit"
1239 +#define _DEFAULT_STI_TOKEN "LpkSearchTimelimit"
1240 +#define _DEFAULT_LDP_TOKEN "LpkLdapConf"
1242 +/* default options */
1243 +#define _DEFAULT_LPK_ON 0
1244 +#define _DEFAULT_LPK_SERVERS NULL
1245 +#define _DEFAULT_LPK_UDN NULL
1246 +#define _DEFAULT_LPK_GDN NULL
1247 +#define _DEFAULT_LPK_BINDDN NULL
1248 +#define _DEFAULT_LPK_BINDPW NULL
1249 +#define _DEFAULT_LPK_SGROUP NULL
1250 +#define _DEFAULT_LPK_TLS -1
1251 +#define _DEFAULT_LPK_BTIMEOUT 10
1252 +#define _DEFAULT_LPK_STIMEOUT 10
1253 +#define _DEFAULT_LPK_LDP NULL
1256 +#define FLAG_EMPTY 0x00000000
1257 +#define FLAG_CONNECTED 0x00000001
1260 +#define FLAG_SET_EMPTY(x) x&=(FLAG_EMPTY)
1261 +#define FLAG_SET_CONNECTED(x) x|=(FLAG_CONNECTED)
1262 +#define FLAG_SET_DISCONNECTED(x) x&=~(FLAG_CONNECTED)
1267 +#define PUBKEYATTR "sshPublicKey"
1271 + * defined files path
1272 + * (should be relocated to pathnames.h,
1273 + * if one day it's included within the tree)
1276 +#define _PATH_LDAP_CONFIG_FILE "/etc/ldap.conf"
1279 +typedef struct ldap_options {
1280 + int on; /* Use it or NOT */
1281 + LDAP * ld; /* LDAP file desc */
1282 + char * servers; /* parsed servers for ldaplib failover handling */
1283 + char * u_basedn; /* user basedn */
1284 + char * g_basedn; /* group basedn */
1285 + char * binddn; /* binddn */
1286 + char * bindpw; /* bind password */
1287 + char * sgroup; /* server group */
1288 + char * fgroup; /* group filter */
1289 + char * l_conf; /* use ldap.conf */
1290 + int tls; /* TLS only */
1291 + struct timeval b_timeout; /* bind timeout */
1292 + struct timeval s_timeout; /* search timeout */
1293 + unsigned int flags; /* misc flags (reconnection, future use?) */
1296 +typedef struct ldap_keys {
1297 + char ** keys; /* the public keys retrieved */
1298 + unsigned int num; /* number of keys */
1302 +/* function headers */
1303 +void ldap_close(ldap_opt_t *);
1304 +int ldap_connect(ldap_opt_t *);
1305 +char * ldap_parse_groups(char *);
1306 +char * ldap_parse_servers(char *);
1307 +void ldap_options_print(ldap_opt_t *);
1308 +void ldap_options_free(ldap_opt_t *);
1309 +void ldap_keys_free(ldap_key_t *);
1310 +int ldap_parse_lconf(ldap_opt_t *);
1311 +ldap_key_t * ldap_getuserkey(ldap_opt_t *, char *);
1312 +int ldap_ismember(ldap_opt_t *, char *);
1315 diff -Nru -x Makefile -x 'buildpkg.*' -x opensshd.init -x 'ssh_prng_*' openssh-4.1p1/lpk-user-example.txt openssh-4.1p1-lpk/lpk-user-example.txt
1316 --- openssh-4.1p1/lpk-user-example.txt 1970-01-01 01:00:00.000000000 +0100
1317 +++ openssh-4.1p1-lpk/lpk-user-example.txt 2005-07-07 18:14:03.000000000 +0200
1320 +Post to ML -> User Made Quick Install Doc.
1321 +Contribution from John Lane <john@lane.uk.net>
1323 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1325 +OpenSSH LDAP keystore Patch
1326 +===========================
1328 +NOTE: these notes are a transcript of a specific installation
1329 + they work for me, your specifics may be different!
1330 + from John Lane March 17th 2005 john@lane.uk.net
1332 +This is a patch to OpenSSH 4.0p1 to allow it to obtain users' public keys
1333 +from their LDAP record as an alternative to ~/.ssh/authorized_keys.
1335 +(Assuming here that necessary build stuff is in $BUILD)
1337 +cd $BUILD/openssh-4.0p1
1338 +patch -Np1 -i $BUILD/openssh-lpk-4.0p1-0.3.patch
1339 +mkdir -p /var/empty &&
1340 +./configure --prefix=/usr --sysconfdir=/etc/ssh \
1341 + --libexecdir=/usr/sbin --with-md5-passwords --with-pam \
1342 + --with-libs="-lldap" --with-cppflags="-DWITH_LDAP_PUBKEY"
1347 +Add the following config to /etc/ssh/ssh_config
1349 +LpkServers ldap://myhost.mydomain.com
1350 +LpkUserDN ou=People,dc=mydomain,dc=com
1352 +We need to tell sshd about the SSL keys during boot, as root's
1353 +environment does not exist at that time. Edit /etc/rc.d/init.d/sshd.
1354 +Change the startup code from this:
1355 + echo "Starting SSH Server..."
1356 + loadproc /usr/sbin/sshd
1359 + echo "Starting SSH Server..."
1360 + LDAPRC="/root/.ldaprc" loadproc /usr/sbin/sshd
1363 +Re-start the sshd daemon:
1364 +/etc/rc.d/init.d/sshd restart
1366 +Install the additional LDAP schema
1367 +cp $BUILD/openssh-lpk-0.2.schema /etc/openldap/schema/openssh.schema
1369 +Now add the openSSH LDAP schema to /etc/openldap/slapd.conf:
1370 +Add the following to the end of the existing block of schema includes
1371 +include /etc/openldap/schema/openssh.schema
1373 +Re-start the LDAP server:
1374 +/etc/rc.d/init.d/slapd restart
1376 +To add one or more public keys to a user, eg "testuser" :
1377 +ldapsearch -x -W -Z -LLL -b "uid=testuser,ou=People,dc=mydomain,dc=com" -D
1378 +"uid=testuser,ou=People,dc=mydomain,dc=com" > /tmp/testuser
1380 +append the following to this /tmp/testuser file
1381 +objectclass: ldapPublicKey
1382 +sshPublicKey: ssh-rsa
1383 +AAAAB3NzaC1yc2EAAAABJQAAAIB3dsrwqXqD7E4zYYrxwdDKBUQxKMioXy9pxFVai64kAPxjU9KS
1384 +qIo7QfkjslfsjflksjfldfkjsldfjLX/5zkzRmT28I5piGzunPv17S89z8XwSsuAoR1t86t+5dlI
1385 +7eZE/gVbn2UQkQq7+kdDTS2yXV6VnC52N/kKLG3ciBkBAw== General Purpose RSA Key
1388 +ldapmodify -x -D "uid=testuser,ou=People,dc=mydomain,dc=com" -W -f
1390 +Enter LDAP Password:
1391 +modifying entry "uid=testuser,ou=People,dc=mydomain,dc=com"
1392 +And check the modify is ok:
1393 +ldapsearch -x -W -Z -b "uid=testuser,ou=People,dc=mydomain,dc=com" -D
1394 +"uid=testuser,ou=People,dc=mydomain,dc=com"
1395 +Enter LDAP Password:
1399 +# base <uid=testuser,ou=People,dc=mydomain,dc=com> with scope sub
1400 +# filter: (objectclass=*)
1404 +# testuser, People, mydomain.com
1405 +dn: uid=testuser,ou=People,dc=mydomain,dc=com
1408 +objectClass: account
1409 +objectClass: posixAccount
1411 +objectClass: shadowAccount
1412 +objectClass: ldapPublicKey
1413 +shadowLastChange: 12757
1416 +loginShell: /bin/bash
1419 +homeDirectory: /home/testuser
1420 +userPassword:: e1NTSEF9UDgwV1hnM1VjUDRJK0k1YnFiL1d4ZUJObXlZZ3Z3UTU=
1421 +sshPublicKey: ssh-rsa
1422 +AAAAB3NzaC1yc2EAAAABJQAAAIB3dsrwqXqD7E4zYYrxwdDKBUQxKMioXy9pxFVai64kAPxjU9KSqIo7QfkjslfsjflksjfldfkjsldfjLX/5zkzRmT28I5piGzunPv17S89z
1423 +8XwSsuAoR1t86t+5dlI7eZE/gVbn2UQkQq7+kdDTS2yXV6VnC52N/kKLG3ciBkBAw== General Purpose RSA Key
1432 +Now start a ssh session to user "testuser" from usual ssh client (e.g.
1433 +puTTY). Login should succeed.
1435 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1436 diff -Nru -x Makefile -x 'buildpkg.*' -x opensshd.init -x 'ssh_prng_*' openssh-4.1p1/openssh-lpk.schema openssh-4.1p1-lpk/openssh-lpk.schema
1437 --- openssh-4.1p1/openssh-lpk.schema 1970-01-01 01:00:00.000000000 +0100
1438 +++ openssh-4.1p1-lpk/openssh-lpk.schema 2005-07-07 23:50:55.000000000 +0200
1443 +# LDAP Public Key Patch schema for use with openssh-ldappubkey
1444 +# Author: Eric AUGE <eau@phear.org>
1446 +# Based on the proposal of : Mark Ruijter
1450 +# octetString SYNTAX
1451 +attributetype ( 1.3.6.1.4.1.22054.500.1.1.1.13 NAME 'sshPublicKey'
1452 + DESC 'MANDATORY: OpenSSH Public key'
1453 + EQUALITY octetStringMatch
1454 + SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )
1456 +# printableString SYNTAX yes|no
1457 +objectclass ( 1.3.6.1.4.1.22054.500.1.1.2.0 NAME 'ldapPublicKey' SUP top AUXILIARY
1458 + DESC 'MANDATORY: OpenSSH LPK objectclass'
1459 + MUST ( sshPublicKey $ uid )
1461 diff -Nru -x Makefile -x 'buildpkg.*' -x opensshd.init -x 'ssh_prng_*' openssh-4.1p1/servconf.c openssh-4.1p1-lpk/servconf.c
1462 --- openssh-4.1p1/servconf.c 2005-03-14 13:08:12.000000000 +0100
1463 +++ openssh-4.1p1-lpk/servconf.c 2005-07-07 18:14:03.000000000 +0200
1468 +#ifdef WITH_LDAP_PUBKEY
1469 +#include "ldapauth.h"
1472 static void add_listen_addr(ServerOptions *, char *, u_short);
1473 static void add_one_listen_addr(ServerOptions *, char *, u_short);
1475 @@ -101,7 +105,23 @@
1476 options->authorized_keys_file = NULL;
1477 options->authorized_keys_file2 = NULL;
1478 options->num_accept_env = 0;
1480 +#ifdef WITH_LDAP_PUBKEY
1482 + options->lpk.ld = NULL;
1483 + options->lpk.on = -1;
1484 + options->lpk.servers = NULL;
1485 + options->lpk.u_basedn = NULL;
1486 + options->lpk.g_basedn = NULL;
1487 + options->lpk.binddn = NULL;
1488 + options->lpk.bindpw = NULL;
1489 + options->lpk.sgroup = NULL;
1490 + options->lpk.fgroup = NULL;
1491 + options->lpk.l_conf = NULL;
1492 + options->lpk.tls = -1;
1493 + options->lpk.b_timeout.tv_sec = 0;
1494 + options->lpk.s_timeout.tv_sec = 0;
1495 + options->lpk.flags = FLAG_EMPTY;
1497 /* Needs to be accessable in many places */
1500 @@ -229,7 +249,30 @@
1502 if (options->authorized_keys_file == NULL)
1503 options->authorized_keys_file = _PATH_SSH_USER_PERMITTED_KEYS;
1505 +#ifdef WITH_LDAP_PUBKEY
1506 + if (options->lpk.on == -1)
1507 + options->lpk.on = _DEFAULT_LPK_ON;
1508 + if (options->lpk.servers == NULL)
1509 + options->lpk.servers = _DEFAULT_LPK_SERVERS;
1510 + if (options->lpk.u_basedn == NULL)
1511 + options->lpk.u_basedn = _DEFAULT_LPK_UDN;
1512 + if (options->lpk.g_basedn == NULL)
1513 + options->lpk.g_basedn = _DEFAULT_LPK_GDN;
1514 + if (options->lpk.binddn == NULL)
1515 + options->lpk.binddn = _DEFAULT_LPK_BINDDN;
1516 + if (options->lpk.bindpw == NULL)
1517 + options->lpk.bindpw = _DEFAULT_LPK_BINDPW;
1518 + if (options->lpk.sgroup == NULL)
1519 + options->lpk.sgroup = _DEFAULT_LPK_SGROUP;
1520 + if (options->lpk.tls == -1)
1521 + options->lpk.tls = _DEFAULT_LPK_TLS;
1522 + if (options->lpk.b_timeout.tv_sec == 0)
1523 + options->lpk.b_timeout.tv_sec = _DEFAULT_LPK_BTIMEOUT;
1524 + if (options->lpk.s_timeout.tv_sec == 0)
1525 + options->lpk.s_timeout.tv_sec = _DEFAULT_LPK_STIMEOUT;
1526 + if (options->lpk.l_conf == NULL)
1527 + options->lpk.l_conf = _DEFAULT_LPK_LDP;
1529 /* Turn privilege separation on by default */
1530 if (use_privsep == -1)
1532 @@ -273,6 +316,12 @@
1533 sGssAuthentication, sGssCleanupCreds, sAcceptEnv,
1534 sUsePrivilegeSeparation,
1535 sDeprecated, sUnsupported
1536 +#ifdef WITH_LDAP_PUBKEY
1537 + ,sLdapPublickey, sLdapServers, sLdapUserDN
1538 + ,sLdapGroupDN, sBindDN, sBindPw, sMyGroup
1539 + ,sForceTLS, sBindTimeout, sSearchTimeout
1544 /* Textual representation of the tokens. */
1545 @@ -371,6 +420,19 @@
1546 { "clientalivecountmax", sClientAliveCountMax },
1547 { "authorizedkeysfile", sAuthorizedKeysFile },
1548 { "authorizedkeysfile2", sAuthorizedKeysFile2 },
1549 +#ifdef WITH_LDAP_PUBKEY
1550 + { _DEFAULT_LPK_TOKEN, sLdapPublickey },
1551 + { _DEFAULT_SRV_TOKEN, sLdapServers },
1552 + { _DEFAULT_USR_TOKEN, sLdapUserDN },
1553 + { _DEFAULT_GRP_TOKEN, sLdapGroupDN },
1554 + { _DEFAULT_BDN_TOKEN, sBindDN },
1555 + { _DEFAULT_BPW_TOKEN, sBindPw },
1556 + { _DEFAULT_MYG_TOKEN, sMyGroup },
1557 + { _DEFAULT_TLS_TOKEN, sForceTLS },
1558 + { _DEFAULT_BTI_TOKEN, sBindTimeout },
1559 + { _DEFAULT_STI_TOKEN, sSearchTimeout },
1560 + { _DEFAULT_LDP_TOKEN, sLdapConf },
1562 { "useprivilegeseparation", sUsePrivilegeSeparation},
1563 { "acceptenv", sAcceptEnv },
1564 { NULL, sBadOption }
1565 @@ -949,6 +1011,116 @@
1567 arg = strdelim(&cp);
1569 +#ifdef WITH_LDAP_PUBKEY
1570 + case sLdapPublickey:
1571 + intptr = &options->lpk.on;
1573 + case sLdapServers:
1574 + /* arg = strdelim(&cp); */
1578 + if (!arg || *arg == '\0')
1579 + fatal("%s line %d: missing ldap server",filename,linenum);
1580 + arg[strlen(arg)] = '\0';
1581 + if ((options->lpk.servers = ldap_parse_servers(arg)) == NULL)
1582 + fatal("%s line %d: error in ldap servers", filename, linenum);
1583 + memset(arg,0,strlen(arg));
1586 + /* arg = strdelim(&cp); */
1590 + if (!arg || *arg == '\0')
1591 + fatal("%s line %d: missing ldap server",filename,linenum);
1592 + arg[strlen(arg)] = '\0';
1593 + options->lpk.u_basedn = xstrdup(arg);
1594 + memset(arg,0,strlen(arg));
1596 + case sLdapGroupDN:
1597 + /* arg = strdelim(&cp); */
1601 + if (!arg || *arg == '\0')
1602 + fatal("%s line %d: missing ldap server",filename,linenum);
1603 + arg[strlen(arg)] = '\0';
1604 + options->lpk.g_basedn = xstrdup(arg);
1605 + memset(arg,0,strlen(arg));
1608 + /* arg = strdelim(&cp); */
1612 + if (!arg || *arg == '\0')
1613 + fatal("%s line %d: missing binddn",filename,linenum);
1614 + arg[strlen(arg)] = '\0';
1615 + options->lpk.binddn = xstrdup(arg);
1616 + memset(arg,0,strlen(arg));
1619 + /* arg = strdelim(&cp); */
1623 + if (!arg || *arg == '\0')
1624 + fatal("%s line %d: missing bindpw",filename,linenum);
1625 + arg[strlen(arg)] = '\0';
1626 + options->lpk.bindpw = xstrdup(arg);
1627 + memset(arg,0,strlen(arg));
1633 + if (!arg || *arg == '\0')
1634 + fatal("%s line %d: missing groupname",filename, linenum);
1635 + arg[strlen(arg)] = '\0';
1636 + options->lpk.sgroup = xstrdup(arg);
1637 + if (options->lpk.sgroup)
1638 + options->lpk.fgroup = ldap_parse_groups(options->lpk.sgroup);
1639 + memset(arg,0,strlen(arg));
1642 + intptr = &options->lpk.tls;
1643 + arg = strdelim(&cp);
1644 + if (!arg || *arg == '\0')
1645 + fatal("%s line %d: missing yes/no argument.",
1646 + filename, linenum);
1647 + value = 0; /* silence compiler */
1648 + if (strcmp(arg, "yes") == 0)
1650 + else if (strcmp(arg, "no") == 0)
1652 + else if (strcmp(arg, "try") == 0)
1655 + fatal("%s line %d: Bad yes/no argument: %s",
1656 + filename, linenum, arg);
1657 + if (*intptr == -1)
1660 + case sBindTimeout:
1661 + intptr = (int *) &options->lpk.b_timeout.tv_sec;
1663 + case sSearchTimeout:
1664 + intptr = (int *) &options->lpk.s_timeout.tv_sec;
1668 + /* arg = strdelim(&cp); */
1672 + if (!arg || *arg == '\0')
1673 + fatal("%s line %d: missing LpkLdapConf", filename, linenum);
1674 + arg[strlen(arg)] = '\0';
1675 + options->lpk.l_conf = xstrdup(arg);
1676 + memset(arg, 0, strlen(arg));
1681 fatal("%s line %d: Missing handler for opcode %s (%d)",
1682 diff -Nru -x Makefile -x 'buildpkg.*' -x opensshd.init -x 'ssh_prng_*' openssh-4.1p1/servconf.h openssh-4.1p1-lpk/servconf.h
1683 --- openssh-4.1p1/servconf.h 2005-01-20 00:57:56.000000000 +0100
1684 +++ openssh-4.1p1-lpk/servconf.h 2005-07-07 18:14:03.000000000 +0200
1689 +#ifdef WITH_LDAP_PUBKEY
1690 +#include "ldapauth.h"
1693 #define MAX_PORTS 256 /* Max # ports. */
1695 #define MAX_ALLOW_USERS 256 /* Max # users on allow list. */
1697 char *authorized_keys_file; /* File containing public keys */
1698 char *authorized_keys_file2;
1699 int use_pam; /* Enable auth via PAM */
1700 +#ifdef WITH_LDAP_PUBKEY
1705 void initialize_server_options(ServerOptions *);
1706 diff -Nru -x Makefile -x 'buildpkg.*' -x opensshd.init -x 'ssh_prng_*' openssh-4.1p1/sshd.c openssh-4.1p1-lpk/sshd.c
1707 --- openssh-4.1p1/sshd.c 2005-03-31 13:39:25.000000000 +0200
1708 +++ openssh-4.1p1-lpk/sshd.c 2005-07-07 18:14:03.000000000 +0200
1710 int deny_severity = LOG_WARNING;
1711 #endif /* LIBWRAP */
1713 +#ifdef WITH_LDAP_PUBKEY
1714 +#include "ldapauth.h"
1720 @@ -1076,6 +1080,16 @@
1724 +#ifdef WITH_LDAP_PUBKEY
1725 + /* ldap_options_print(&options.lpk); */
1726 + /* XXX initialize/check ldap connection and set *LD */
1727 + if (options.lpk.on) {
1728 + if (options.lpk.l_conf && (ldap_parse_lconf(&options.lpk) < 0) )
1729 + error("[LDAP] could not parse %s", options.lpk.l_conf);
1730 + if (ldap_connect(&options.lpk) < 0)
1731 + error("[LDAP] could not initialize ldap connection");
1734 debug("sshd version %.100s", SSH_RELEASE);
1736 /* load private host keys */
1737 diff -Nru -x Makefile -x 'buildpkg.*' -x opensshd.init -x 'ssh_prng_*' openssh-4.1p1/sshd_config openssh-4.1p1-lpk/sshd_config
1738 --- openssh-4.1p1/sshd_config 2005-01-20 00:57:56.000000000 +0100
1739 +++ openssh-4.1p1-lpk/sshd_config 2005-07-07 18:14:03.000000000 +0200
1742 # no default banner path
1745 +# here is the new patched ldap related tokens
1746 +# entries in your LDAP must have posixAccount & ldapPublicKey objectclass
1748 +#LpkLdapConf /etc/ldap.conf
1749 +#LpkServers ldap://127.0.0.4 ldap://127.0.0.3 ldap://127.0.0.1/
1750 +#LpkUserDN ou=users,dc=phear,dc=org
1751 +#LpkGroupDN ou=groups,dc=phear,dc=org
1752 +#LpkBindDN cn=Manager,dc=phear,dc=org
1754 +#LpkServerGroup mail
1756 +#LpkSearchTimelimit 3
1757 +#LpkBindTimelimit 3
1759 # override default of no subsystems
1760 Subsystem sftp /usr/libexec/sftp-server
1761 diff -Nru -x Makefile -x 'buildpkg.*' -x opensshd.init -x 'ssh_prng_*' openssh-4.1p1/sshd_config.5 openssh-4.1p1-lpk/sshd_config.5
1762 --- openssh-4.1p1/sshd_config.5 2005-03-31 13:33:51.000000000 +0200
1763 +++ openssh-4.1p1-lpk/sshd_config.5 2005-07-07 18:14:03.000000000 +0200
1764 @@ -760,6 +760,58 @@
1767 .Pa /usr/X11R6/bin/xauth .
1769 +Specifies whether LDAP public key retrieval must be used or not. It allow
1770 +an easy centralisation of public keys within an LDAP directory. The argument must be
1775 +Specifies whether LDAP Public keys should parse the specified ldap.conf file
1776 +instead of sshd_config Tokens. The argument must be a valid path to an ldap.conf
1780 +Specifies LDAP one or more [:space:] separated server's url the following form may be used:
1782 +LpkServers ldaps://127.0.0.1 ldap://127.0.0.2 ldap://127.0.0.3
1784 +Specifies the LDAP user DN.
1786 +LpkUserDN ou=users,dc=phear,dc=org
1788 +Specifies the LDAP groups DN.
1790 +LpkGroupDN ou=groups,dc=phear,dc=org
1792 +Specifies the LDAP bind DN to use if necessary.
1794 +LpkBindDN cn=Manager,dc=phear,dc=org
1796 +Specifies the LDAP bind credential.
1799 +.It Cm LpkServerGroup
1800 +Specifies one or more [:space:] separated group the server is part of.
1802 +LpkServerGroup unix mail prod
1804 +Specifies if the LDAP server connection must be tried, forced or not used. The argument must be
1810 +.It Cm LpkSearchTimelimit
1811 +Sepcifies the search time limit before the search is considered over. value is
1814 +LpkSearchTimelimit 3
1815 +.It Cm LpkBindTimelimit
1816 +Sepcifies the bind time limit before the connection is considered dead. value is