1 This is a forward-port of the OpenSSH LPK support patch.
3 It adds support for storing OpenSSH public keys in LDAP. It also supports
4 grouping of machines in the LDAP data to limit users to specific machines.
6 The latest homepage for the LPK project is:
7 http://code.google.com/p/openssh-lpk/
9 The 0.3.10 version of the patch includes a fix for 64-bit platforms, as
10 discovered by Gentoo, where the bind timeout and search timeout values were not
11 being parsed correctly: http://bugs.gentoo.org/210110
13 Forward-ported-from: openssh-lpk-5.1p1-0.3.9.patch
14 Signed-off-by: Robin H. Johnson <robbat2@gentoo.org>
16 diff -Nuar --exclude '*.orig' --exclude '*.rej' openssh-5.1p1.orig/auth2-pubkey.c openssh-5.1p1+lpk/auth2-pubkey.c
17 --- openssh-5.1p1.orig/auth2-pubkey.c 2008-07-03 19:54:25.000000000 -0700
18 +++ openssh-5.1p1+lpk/auth2-pubkey.c 2008-08-23 15:02:47.000000000 -0700
20 #include "monitor_wrap.h"
23 +#ifdef WITH_LDAP_PUBKEY
24 +#include "ldapauth.h"
28 extern ServerOptions options;
29 extern u_char *session_id2;
34 +#ifdef WITH_LDAP_PUBKEY
39 temporarily_use_uid(pw);
41 +#ifdef WITH_LDAP_PUBKEY
42 + /* here is the job */
43 + key = key_new(KEY_RSA1);
45 + if (options.lpk.on) {
46 + debug("[LDAP] trying LDAP first uid=%s", pw->pw_name);
47 + if ( ldap_ismember(&options.lpk, pw->pw_name) > 0) {
48 + if ( (k = ldap_getuserkey(&options.lpk, pw->pw_name)) != NULL) {
49 + for (i = 0 ; i < k->num ; i++) {
50 + char *cp, *options = NULL;
52 + for (cp = k->keys[i]->bv_val; *cp == ' ' || *cp == '\t'; cp++)
54 + if (!*cp || *cp == '\n' || *cp == '#')
58 + * Check if there are options for this key, and if so,
59 + * save their starting address and skip the option part
60 + * for now. If there are no options, set the starting
63 + if (*cp < '0' || *cp > '9') {
66 + for (; *cp && (quoted || (*cp != ' ' && *cp != '\t')); cp++) {
67 + if (*cp == '\\' && cp[1] == '"')
68 + cp++; /* Skip both */
69 + else if (*cp == '"')
75 + /* Parse the key from the line. */
76 + if (hostfile_read_key(&cp, &bits, key) == 0) {
77 + debug("[LDAP] line %d: non ssh1 key syntax", i);
80 + /* cp now points to the comment part. */
82 + /* Check if the we have found the desired key (identified by its modulus). */
83 + if (BN_cmp(key->rsa->n, client_n) != 0)
86 + /* check the real bits */
87 + if (bits != (unsigned int)BN_num_bits(key->rsa->n))
88 + logit("[LDAP] Warning: ldap, line %lu: keysize mismatch: "
89 + "actual %d vs. announced %d.", (unsigned long)i, BN_num_bits(key->rsa->n), bits);
91 + /* We have found the desired key. */
93 + * If our options do not allow this key to be used,
94 + * do not send challenge.
96 + if (!auth_parse_options(pw, options, "[LDAP]", (unsigned long) i))
99 + /* break out, this key is allowed */
102 + /* add the return stuff etc... */
103 + /* Restore the privileged uid. */
106 + /* return key if allowed */
107 + if (allowed && rkey != NULL)
116 + logit("[LDAP] no keys found for '%s'!", pw->pw_name);
119 + logit("[LDAP] '%s' is not in '%s'", pw->pw_name, options.lpk.sgroup);
124 + /* The authorized keys. */
125 for (i = 0; !allowed && i < options.num_authkeys_files; i++) {
126 file = expand_authorized_keys(
127 options.authorized_keys_files[i], pw);
128 diff -Nuar --exclude '*.orig' --exclude '*.rej' openssh-5.1p1.orig/auth-rsa.c openssh-5.1p1+lpk/auth-rsa.c
129 --- openssh-5.1p1.orig/auth-rsa.c 2008-07-02 05:37:30.000000000 -0700
130 +++ openssh-5.1p1+lpk/auth-rsa.c 2008-08-23 15:02:47.000000000 -0700
131 @@ -174,10 +174,96 @@
135 +#ifdef WITH_LDAP_PUBKEY
137 + unsigned int i = 0;
140 /* Temporarily use the user's uid. */
141 temporarily_use_uid(pw);
143 +#ifdef WITH_LDAP_PUBKEY
144 + /* here is the job */
145 + key = key_new(KEY_RSA1);
147 + if (options.lpk.on) {
148 + debug("[LDAP] trying LDAP first uid=%s", pw->pw_name);
149 + if ( ldap_ismember(&options.lpk, pw->pw_name) > 0) {
150 + if ( (k = ldap_getuserkey(&options.lpk, pw->pw_name)) != NULL) {
151 + for (i = 0 ; i < k->num ; i++) {
152 + char *cp, *options = NULL;
154 + for (cp = k->keys[i]->bv_val; *cp == ' ' || *cp == '\t'; cp++)
156 + if (!*cp || *cp == '\n' || *cp == '#')
160 + * Check if there are options for this key, and if so,
161 + * save their starting address and skip the option part
162 + * for now. If there are no options, set the starting
165 + if (*cp < '0' || *cp > '9') {
168 + for (; *cp && (quoted || (*cp != ' ' && *cp != '\t')); cp++) {
169 + if (*cp == '\\' && cp[1] == '"')
170 + cp++; /* Skip both */
171 + else if (*cp == '"')
177 + /* Parse the key from the line. */
178 + if (hostfile_read_key(&cp, &bits, key) == 0) {
179 + debug("[LDAP] line %d: non ssh1 key syntax", i);
182 + /* cp now points to the comment part. */
184 + /* Check if the we have found the desired key (identified by its modulus). */
185 + if (BN_cmp(key->rsa->n, client_n) != 0)
188 + /* check the real bits */
189 + if (bits != (unsigned int)BN_num_bits(key->rsa->n))
190 + logit("[LDAP] Warning: ldap, line %lu: keysize mismatch: "
191 + "actual %d vs. announced %d.", (unsigned long)i, BN_num_bits(key->rsa->n), bits);
193 + /* We have found the desired key. */
195 + * If our options do not allow this key to be used,
196 + * do not send challenge.
198 + if (!auth_parse_options(pw, options, "[LDAP]", (unsigned long) i))
201 + /* break out, this key is allowed */
204 + /* add the return stuff etc... */
205 + /* Restore the privileged uid. */
208 + /* return key if allowed */
209 + if (allowed && rkey != NULL)
218 + logit("[LDAP] no keys found for '%s'!", pw->pw_name);
221 + logit("[LDAP] '%s' is not in '%s'", pw->pw_name, options.lpk.sgroup);
225 /* The authorized keys. */
226 file = authorized_keys_file(pw);
227 debug("trying public RSA key file %s", file);
228 diff -Nuar --exclude '*.orig' --exclude '*.rej' openssh-5.1p1.orig/config.h.in openssh-5.1p1+lpk/config.h.in
229 --- openssh-5.1p1.orig/config.h.in 2008-07-21 01:30:49.000000000 -0700
230 +++ openssh-5.1p1+lpk/config.h.in 2008-08-23 15:02:47.000000000 -0700
232 /* Define to 1 if you have the <linux/if_tun.h> header file. */
233 #undef HAVE_LINUX_IF_TUN_H
235 +/* Define if you want LDAP support */
236 +#undef WITH_LDAP_PUBKEY
238 /* Define if your libraries define login() */
241 --- openssh-5.7p1/configure.orig 2011-01-22 11:29:11.000000000 +0200
242 +++ openssh-5.7p1/configure 2011-01-24 16:33:06.271393457 +0200
243 @@ -1348,6 +1348,7 @@
244 --with-tcp-wrappers[=PATH] Enable tcpwrappers support (optionally in PATH)
245 --with-libedit[=PATH] Enable libedit support for sftp
246 --with-audit=module Enable audit support (modules=debug,bsm,linux)
247 + --with-ldap[=PATH] Enable LDAP pubkey support (optionally in PATH)
248 --with-ssl-dir=PATH Specify path to OpenSSL installation
249 --without-openssl-header-check Disable OpenSSL version consistency check
250 --with-ssl-engine Enable OpenSSL (hardware) ENGINE support
251 @@ -12198,6 +12199,85 @@
255 +# Check whether user wants LDAP support
258 +# Check whether --with-ldap was given.
259 +if test "${with_ldap+set}" = set; then
260 + withval=$with_ldap;
261 + if test "x$withval" != "xno" ; then
263 + if test "x$withval" != "xyes" ; then
264 + CPPFLAGS="$CPPFLAGS -I${withval}/include"
265 + LDFLAGS="$LDFLAGS -L${withval}/lib"
269 +cat >>confdefs.h <<\_ACEOF
270 +#define WITH_LDAP_PUBKEY 1
273 + LIBS="-lldap $LIBS"
276 + { echo "$as_me:$LINENO: checking for LDAP support" >&5
277 +echo $ECHO_N "checking for LDAP support... $ECHO_C" >&6; }
278 + cat >conftest.$ac_ext <<_ACEOF
281 +cat confdefs.h >>conftest.$ac_ext
282 +cat >>conftest.$ac_ext <<_ACEOF
283 +/* end confdefs.h. */
284 +#include <sys/types.h>
289 +(void)ldap_init(0, 0);
294 +rm -f conftest.$ac_objext
295 +if { (ac_try="$ac_compile"
297 + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
298 + *) ac_try_echo=$ac_try;;
300 +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
301 + (eval "$ac_compile") 2>conftest.er1
303 + grep -v '^ *+' conftest.er1 >conftest.err
305 + cat conftest.err >&5
306 + echo "$as_me:$LINENO: \$? = $ac_status" >&5
307 + (exit $ac_status); } && {
308 + test -z "$ac_c_werror_flag" ||
309 + test ! -s conftest.err
310 + } && test -s conftest.$ac_objext; then
311 + { echo "$as_me:$LINENO: result: yes" >&5
312 +echo "${ECHO_T}yes" >&6; }
314 + echo "$as_me: failed program was:" >&5
315 +sed 's/^/| /' conftest.$ac_ext >&5
318 + { echo "$as_me:$LINENO: result: no" >&5
319 +echo "${ECHO_T}no" >&6; }
320 + { { echo "$as_me:$LINENO: error: ** Incomplete or missing ldap libraries **" >&5
321 +echo "$as_me: error: ** Incomplete or missing ldap libraries **" >&2;}
322 + { (exit 1); exit 1; }; }
327 +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
337 @@ -31970,6 +32050,7 @@
338 echo " Smartcard support: $SCARD_MSG"
339 echo " S/KEY support: $SKEY_MSG"
340 echo " TCP Wrappers support: $TCPW_MSG"
341 +echo " LDAP support: $LDAP_MSG"
342 echo " MD5 password support: $MD5_MSG"
343 echo " libedit support: $LIBEDIT_MSG"
344 echo " Solaris process contract support: $SPC_MSG"
345 diff -Nuar --exclude '*.orig' --exclude '*.rej' openssh-5.1p1.orig/configure.ac openssh-5.1p1+lpk/configure.ac
346 --- openssh-5.1p1.orig/configure.ac 2008-07-09 04:07:19.000000000 -0700
347 +++ openssh-5.1p1+lpk/configure.ac 2008-08-23 15:02:47.000000000 -0700
348 @@ -1299,6 +1299,37 @@
352 +# Check whether user wants LDAP support
355 + [ --with-ldap[[=PATH]] Enable LDAP pubkey support (optionally in PATH)],
357 + if test "x$withval" != "xno" ; then
359 + if test "x$withval" != "xyes" ; then
360 + CPPFLAGS="$CPPFLAGS -I${withval}/include"
361 + LDFLAGS="$LDFLAGS -L${withval}/lib"
364 + AC_DEFINE([WITH_LDAP_PUBKEY], 1, [Enable LDAP pubkey support])
365 + LIBS="-lldap $LIBS"
368 + AC_MSG_CHECKING([for LDAP support])
370 + [#include <sys/types.h>
371 + #include <ldap.h>],
372 + [(void)ldap_init(0, 0);],
373 + [AC_MSG_RESULT(yes)],
376 + AC_MSG_ERROR([** Incomplete or missing ldap libraries **])
383 dnl Checks for library functions. Please keep in alphabetical order
386 @@ -4137,6 +4168,7 @@
387 echo " Smartcard support: $SCARD_MSG"
388 echo " S/KEY support: $SKEY_MSG"
389 echo " TCP Wrappers support: $TCPW_MSG"
390 +echo " LDAP support: $LDAP_MSG"
391 echo " MD5 password support: $MD5_MSG"
392 echo " libedit support: $LIBEDIT_MSG"
393 echo " Solaris process contract support: $SPC_MSG"
394 diff -Nuar --exclude '*.orig' --exclude '*.rej' openssh-5.1p1.orig/ldapauth.c openssh-5.1p1+lpk/ldapauth.c
395 --- openssh-5.1p1.orig/ldapauth.c 1969-12-31 16:00:00.000000000 -0800
396 +++ openssh-5.1p1+lpk/ldapauth.c 2008-08-23 15:02:47.000000000 -0700
404 + * Copyright (c) 2005, Eric AUGE <eau@phear.org>
405 + * All rights reserved.
407 + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
409 + * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
410 + * 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.
411 + * 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.
413 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
414 + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
415 + * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
416 + * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
417 + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
418 + * 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.
423 +#include "includes.h"
425 +#ifdef WITH_LDAP_PUBKEY
432 +#include "ldapauth.h"
435 +static char *attrs[] = {
440 +/* filter building infos */
441 +#define FILTER_GROUP_PREFIX "(&(objectclass=posixGroup)"
442 +#define FILTER_OR_PREFIX "(|"
443 +#define FILTER_OR_SUFFIX ")"
444 +#define FILTER_CN_PREFIX "(cn="
445 +#define FILTER_CN_SUFFIX ")"
446 +#define FILTER_UID_FORMAT "(memberUid=%s)"
447 +#define FILTER_GROUP_SUFFIX ")"
448 +#define FILTER_GROUP_SIZE(group) (size_t) (strlen(group)+(ldap_count_group(group)*5)+52)
450 +/* just filter building stuff */
451 +#define REQUEST_GROUP_SIZE(filter, uid) (size_t) (strlen(filter)+strlen(uid)+1)
452 +#define REQUEST_GROUP(buffer, prefilter, pwname) \
453 + buffer = (char *) calloc(REQUEST_GROUP_SIZE(prefilter, pwname), sizeof(char)); \
455 + perror("calloc()"); \
458 + snprintf(buffer, REQUEST_GROUP_SIZE(prefilter,pwname), prefilter, pwname)
460 +XXX OLD group building macros
461 +#define REQUEST_GROUP_SIZE(grp, uid) (size_t) (strlen(grp)+strlen(uid)+46)
462 +#define REQUEST_GROUP(buffer,pwname,grp) \
463 + buffer = (char *) calloc(REQUEST_GROUP_SIZE(grp, pwname), sizeof(char)); \
465 + perror("calloc()"); \
468 + snprintf(buffer,REQUEST_GROUP_SIZE(grp,pwname),"(&(objectclass=posixGroup)(cn=%s)(memberUid=%s))",grp,pwname)
472 +XXX stock upstream version without extra filter support
473 +#define REQUEST_USER_SIZE(uid) (size_t) (strlen(uid)+64)
474 +#define REQUEST_USER(buffer, pwname) \
475 + buffer = (char *) calloc(REQUEST_USER_SIZE(pwname), sizeof(char)); \
477 + perror("calloc()"); \
480 + snprintf(buffer,REQUEST_USER_SIZE(pwname),"(&(objectclass=posixAccount)(objectclass=ldapPublicKey)(uid=%s))",pwname)
483 +#define REQUEST_USER_SIZE(uid, filter) (size_t) (strlen(uid)+64+(filter != NULL ? strlen(filter) : 0))
484 +#define REQUEST_USER(buffer, pwname, customfilter) \
485 + buffer = (char *) calloc(REQUEST_USER_SIZE(pwname, customfilter), sizeof(char)); \
487 + perror("calloc()"); \
490 + snprintf(buffer, REQUEST_USER_SIZE(pwname, customfilter), \
491 + "(&(objectclass=posixAccount)(objectclass=ldapPublicKey)(uid=%s)%s)", \
492 + pwname, (customfilter != NULL ? customfilter : ""))
494 +/* some portable and working tokenizer, lame though */
495 +static int tokenize(char ** o, size_t size, char * input) {
496 + unsigned int i = 0, num;
497 + const char * charset = " \t";
498 + char * ptr = input;
500 + /* leading white spaces are ignored */
501 + num = strspn(ptr, charset);
504 + while ((num = strcspn(ptr, charset))) {
516 +void ldap_close(ldap_opt_t * ldap) {
521 + if ( ldap_unbind_ext(ldap->ld, NULL, NULL) < 0)
522 + ldap_perror(ldap->ld, "ldap_unbind()");
525 + FLAG_SET_DISCONNECTED(ldap->flags);
531 +int ldap_connect(ldap_opt_t * ldap) {
532 + int version = LDAP_VERSION3;
534 + if (!ldap->servers)
537 + /* Connection Init and setup */
538 + ldap->ld = ldap_init(ldap->servers, LDAP_PORT);
540 + ldap_perror(ldap->ld, "ldap_init()");
544 + if ( ldap_set_option(ldap->ld, LDAP_OPT_PROTOCOL_VERSION, &version) != LDAP_OPT_SUCCESS) {
545 + ldap_perror(ldap->ld, "ldap_set_option(LDAP_OPT_PROTOCOL_VERSION)");
549 + /* Timeouts setup */
550 + if (ldap_set_option(ldap->ld, LDAP_OPT_NETWORK_TIMEOUT, &ldap->b_timeout) != LDAP_SUCCESS) {
551 + ldap_perror(ldap->ld, "ldap_set_option(LDAP_OPT_NETWORK_TIMEOUT)");
553 + if (ldap_set_option(ldap->ld, LDAP_OPT_TIMEOUT, &ldap->s_timeout) != LDAP_SUCCESS) {
554 + ldap_perror(ldap->ld, "ldap_set_option(LDAP_OPT_TIMEOUT)");
558 + if ( (ldap->tls == -1) || (ldap->tls == 1) ) {
559 + if (ldap_start_tls_s(ldap->ld, NULL, NULL ) != LDAP_SUCCESS) {
560 + /* failed then reinit the initial connect */
561 + ldap_perror(ldap->ld, "ldap_connect: (TLS) ldap_start_tls()");
562 + if (ldap->tls == 1)
565 + ldap->ld = ldap_init(ldap->servers, LDAP_PORT);
567 + ldap_perror(ldap->ld, "ldap_init()");
571 + if ( ldap_set_option(ldap->ld, LDAP_OPT_PROTOCOL_VERSION, &version) != LDAP_OPT_SUCCESS) {
572 + ldap_perror(ldap->ld, "ldap_set_option()");
579 + if ( ldap_simple_bind_s(ldap->ld, ldap->binddn, ldap->bindpw) != LDAP_SUCCESS) {
580 + ldap_perror(ldap->ld, "ldap_simple_bind_s()");
584 + /* says it is connected */
585 + FLAG_SET_CONNECTED(ldap->flags);
590 +/* must free allocated ressource */
591 +static char * ldap_build_host(char *host, int port) {
592 + unsigned int size = strlen(host)+11;
593 + char * h = (char *) calloc (size, sizeof(char));
598 + rc = snprintf(h, size, "%s:%d ", host, port);
604 +static int ldap_count_group(const char * input) {
605 + const char * charset = " \t";
606 + const char * ptr = input;
607 + unsigned int count = 0;
610 + num = strspn(ptr, charset);
613 + while ((num = strcspn(ptr, charset))) {
623 +char * ldap_parse_groups(const char * groups) {
624 + unsigned int buffer_size = FILTER_GROUP_SIZE(groups);
625 + char * buffer = (char *) calloc(buffer_size, sizeof(char));
628 + unsigned int i = 0;
630 + if ((!groups)||(!buffer))
633 + g = strdup(groups);
639 + /* first separate into n tokens */
640 + if ( tokenize(garray, sizeof(garray)/sizeof(*garray), g) < 0) {
646 + /* build the final filter format */
647 + strlcat(buffer, FILTER_GROUP_PREFIX, buffer_size);
648 + strlcat(buffer, FILTER_OR_PREFIX, buffer_size);
650 + while (garray[i]) {
651 + strlcat(buffer, FILTER_CN_PREFIX, buffer_size);
652 + strlcat(buffer, garray[i], buffer_size);
653 + strlcat(buffer, FILTER_CN_SUFFIX, buffer_size);
656 + strlcat(buffer, FILTER_OR_SUFFIX, buffer_size);
657 + strlcat(buffer, FILTER_UID_FORMAT, buffer_size);
658 + strlcat(buffer, FILTER_GROUP_SUFFIX, buffer_size);
664 +/* a bit dirty but leak free */
665 +char * ldap_parse_servers(const char * servers) {
667 + char * tmp = NULL, *urls[32];
668 + unsigned int num = 0 , i = 0 , asize = 0;
669 + LDAPURLDesc *urld[32];
674 + /* local copy of the arg */
675 + s = strdup(servers);
679 + /* first separate into URL tokens */
680 + if ( tokenize(urls, sizeof(urls)/sizeof(*urls), s) < 0)
685 + if (! ldap_is_ldap_url(urls[i]) ||
686 + (ldap_url_parse(urls[i], &urld[i]) != 0)) {
695 + /* how much memory do we need */
697 + for (i = 0 ; i < num ; i++)
698 + asize += strlen(urld[i]->lud_host)+11;
701 + s = (char *) calloc( asize+1 , sizeof(char));
703 + for (i = 0 ; i < num ; i++)
704 + ldap_free_urldesc(urld[i]);
708 + /* then build the final host string */
709 + for (i = 0 ; i < num ; i++) {
710 + /* built host part */
711 + tmp = ldap_build_host(urld[i]->lud_host, urld[i]->lud_port);
712 + strncat(s, tmp, strlen(tmp));
713 + ldap_free_urldesc(urld[i]);
720 +void ldap_options_print(ldap_opt_t * ldap) {
721 + debug("ldap options:");
722 + debug("servers: %s", ldap->servers);
723 + if (ldap->u_basedn)
724 + debug("user basedn: %s", ldap->u_basedn);
725 + if (ldap->g_basedn)
726 + debug("group basedn: %s", ldap->g_basedn);
728 + debug("binddn: %s", ldap->binddn);
730 + debug("bindpw: %s", ldap->bindpw);
732 + debug("group: %s", ldap->sgroup);
734 + debug("filter: %s", ldap->filter);
737 +void ldap_options_free(ldap_opt_t * l) {
762 +void ldap_keys_free(ldap_key_t * k) {
763 + ldap_value_free_len(k->keys);
768 +ldap_key_t * ldap_getuserkey(ldap_opt_t *l, const char * user) {
769 + ldap_key_t * k = (ldap_key_t *) calloc (1, sizeof(ldap_key_t));
770 + LDAPMessage *res, *e;
777 + /* Am i still connected ? RETRY n times */
778 + /* XXX TODO: setup some conf value for retrying */
779 + if (!(l->flags & FLAG_CONNECTED))
780 + for (i = 0 ; i < 2 ; i++)
781 + if (ldap_connect(l) == 0)
784 + /* quick check for attempts to be evil */
785 + if ((strchr(user, '(') != NULL) || (strchr(user, ')') != NULL) ||
786 + (strchr(user, '*') != NULL) || (strchr(user, '\\') != NULL))
789 + /* build filter for LDAP request */
790 + REQUEST_USER(filter, user, l->filter);
792 + if ( ldap_search_st( l->ld,
794 + LDAP_SCOPE_SUBTREE,
796 + attrs, 0, &l->s_timeout, &res ) != LDAP_SUCCESS) {
798 + ldap_perror(l->ld, "ldap_search_st()");
803 + /* XXX error on search, timeout etc.. close ask for reconnect */
812 + /* check if any results */
813 + i = ldap_count_entries(l->ld,res);
821 + debug("[LDAP] duplicate entries, using the FIRST entry returned");
823 + e = ldap_first_entry(l->ld, res);
824 + k->keys = ldap_get_values_len(l->ld, e, PUBKEYATTR);
825 + k->num = ldap_count_values_len(k->keys);
833 + 0 if user is NOT member of current server group
834 + 1 if user IS MEMBER of current server group
836 +int ldap_ismember(ldap_opt_t * l, const char * user) {
841 + if ((!l->sgroup) || !(l->g_basedn))
844 + /* Am i still connected ? RETRY n times */
845 + /* XXX TODO: setup some conf value for retrying */
846 + if (!(l->flags & FLAG_CONNECTED))
847 + for (i = 0 ; i < 2 ; i++)
848 + if (ldap_connect(l) == 0)
851 + /* quick check for attempts to be evil */
852 + if ((strchr(user, '(') != NULL) || (strchr(user, ')') != NULL) ||
853 + (strchr(user, '*') != NULL) || (strchr(user, '\\') != NULL))
856 + /* build filter for LDAP request */
857 + REQUEST_GROUP(filter, l->fgroup, user);
859 + if (ldap_search_st( l->ld,
861 + LDAP_SCOPE_SUBTREE,
863 + NULL, 0, &l->s_timeout, &res) != LDAP_SUCCESS) {
865 + ldap_perror(l->ld, "ldap_search_st()");
869 + /* XXX error on search, timeout etc.. close ask for reconnect */
877 + /* check if any results */
878 + if (ldap_count_entries(l->ld, res) > 0) {
888 + * ldap.conf simple parser
889 + * XXX TODO: sanity checks
891 + * - free the previous ldap_opt_before replacing entries
892 + * - free each necessary previously parsed elements
894 + * -1 on FAILURE, 0 on SUCCESS
896 +int ldap_parse_lconf(ldap_opt_t * l) {
897 + FILE * lcd; /* ldap.conf descriptor */
899 + char * s = NULL, * k = NULL, * v = NULL;
902 + lcd = fopen (l->l_conf, "r");
904 + /* debug("Cannot open %s", l->l_conf); */
905 + perror("ldap_parse_lconf()");
909 + while (fgets (buf, sizeof (buf), lcd) != NULL) {
911 + if (*buf == '\n' || *buf == '#')
916 + while (*v != '\0' && *v != ' ' && *v != '\t')
924 + while (*v == ' ' || *v == '\t')
927 + li = strlen (v) - 1;
928 + while (v[li] == ' ' || v[li] == '\t' || v[li] == '\n')
932 + if (!strcasecmp (k, "uri")) {
933 + if ((l->servers = ldap_parse_servers(v)) == NULL) {
934 + fatal("error in ldap servers");
939 + else if (!strcasecmp (k, "base")) {
940 + s = strchr (v, '?');
943 + l->u_basedn = malloc (len + 1);
944 + strncpy (l->u_basedn, v, len);
945 + l->u_basedn[len] = '\0';
947 + l->u_basedn = strdup (v);
950 + else if (!strcasecmp (k, "binddn")) {
951 + l->binddn = strdup (v);
953 + else if (!strcasecmp (k, "bindpw")) {
954 + l->bindpw = strdup (v);
956 + else if (!strcasecmp (k, "timelimit")) {
957 + l->s_timeout.tv_sec = atoi (v);
959 + else if (!strcasecmp (k, "bind_timelimit")) {
960 + l->b_timeout.tv_sec = atoi (v);
962 + else if (!strcasecmp (k, "ssl")) {
963 + if (!strcasecmp (v, "start_tls"))
972 +#endif /* WITH_LDAP_PUBKEY */
973 diff -Nuar --exclude '*.orig' --exclude '*.rej' openssh-5.1p1.orig/ldapauth.h openssh-5.1p1+lpk/ldapauth.h
974 --- openssh-5.1p1.orig/ldapauth.h 1969-12-31 16:00:00.000000000 -0800
975 +++ openssh-5.1p1+lpk/ldapauth.h 2008-08-23 15:02:47.000000000 -0700
983 + * Copyright (c) 2005, Eric AUGE <eau@phear.org>
984 + * All rights reserved.
986 + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
988 + * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
989 + * 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.
990 + * 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.
992 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
993 + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
994 + * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
995 + * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
996 + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
997 + * 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.
1005 +#define LDAP_DEPRECATED 1
1007 +#include <string.h>
1012 +/* tokens in use for config */
1013 +#define _DEFAULT_LPK_TOKEN "UseLPK"
1014 +#define _DEFAULT_SRV_TOKEN "LpkServers"
1015 +#define _DEFAULT_USR_TOKEN "LpkUserDN"
1016 +#define _DEFAULT_GRP_TOKEN "LpkGroupDN"
1017 +#define _DEFAULT_BDN_TOKEN "LpkBindDN"
1018 +#define _DEFAULT_BPW_TOKEN "LpkBindPw"
1019 +#define _DEFAULT_MYG_TOKEN "LpkServerGroup"
1020 +#define _DEFAULT_FIL_TOKEN "LpkFilter"
1021 +#define _DEFAULT_TLS_TOKEN "LpkForceTLS"
1022 +#define _DEFAULT_BTI_TOKEN "LpkBindTimelimit"
1023 +#define _DEFAULT_STI_TOKEN "LpkSearchTimelimit"
1024 +#define _DEFAULT_LDP_TOKEN "LpkLdapConf"
1026 +/* default options */
1027 +#define _DEFAULT_LPK_ON 0
1028 +#define _DEFAULT_LPK_SERVERS NULL
1029 +#define _DEFAULT_LPK_UDN NULL
1030 +#define _DEFAULT_LPK_GDN NULL
1031 +#define _DEFAULT_LPK_BINDDN NULL
1032 +#define _DEFAULT_LPK_BINDPW NULL
1033 +#define _DEFAULT_LPK_SGROUP NULL
1034 +#define _DEFAULT_LPK_FILTER NULL
1035 +#define _DEFAULT_LPK_TLS -1
1036 +#define _DEFAULT_LPK_BTIMEOUT 10
1037 +#define _DEFAULT_LPK_STIMEOUT 10
1038 +#define _DEFAULT_LPK_LDP NULL
1041 +#define FLAG_EMPTY 0x00000000
1042 +#define FLAG_CONNECTED 0x00000001
1045 +#define FLAG_SET_EMPTY(x) x&=(FLAG_EMPTY)
1046 +#define FLAG_SET_CONNECTED(x) x|=(FLAG_CONNECTED)
1047 +#define FLAG_SET_DISCONNECTED(x) x&=~(FLAG_CONNECTED)
1052 +#define PUBKEYATTR "sshPublicKey"
1056 + * defined files path
1057 + * (should be relocated to pathnames.h,
1058 + * if one day it's included within the tree)
1061 +#define _PATH_LDAP_CONFIG_FILE "/etc/ldap.conf"
1064 +typedef struct ldap_options {
1065 + int on; /* Use it or NOT */
1066 + LDAP * ld; /* LDAP file desc */
1067 + char * servers; /* parsed servers for ldaplib failover handling */
1068 + char * u_basedn; /* user basedn */
1069 + char * g_basedn; /* group basedn */
1070 + char * binddn; /* binddn */
1071 + char * bindpw; /* bind password */
1072 + char * sgroup; /* server group */
1073 + char * fgroup; /* group filter */
1074 + char * filter; /* additional filter */
1075 + char * l_conf; /* use ldap.conf */
1076 + int tls; /* TLS only */
1077 + struct timeval b_timeout; /* bind timeout */
1078 + struct timeval s_timeout; /* search timeout */
1079 + unsigned int flags; /* misc flags (reconnection, future use?) */
1082 +typedef struct ldap_keys {
1083 + struct berval ** keys; /* the public keys retrieved */
1084 + unsigned int num; /* number of keys */
1088 +/* function headers */
1089 +void ldap_close(ldap_opt_t *);
1090 +int ldap_connect(ldap_opt_t *);
1091 +char * ldap_parse_groups(const char *);
1092 +char * ldap_parse_servers(const char *);
1093 +void ldap_options_print(ldap_opt_t *);
1094 +void ldap_options_free(ldap_opt_t *);
1095 +void ldap_keys_free(ldap_key_t *);
1096 +int ldap_parse_lconf(ldap_opt_t *);
1097 +ldap_key_t * ldap_getuserkey(ldap_opt_t *, const char *);
1098 +int ldap_ismember(ldap_opt_t *, const char *);
1101 diff -Nuar --exclude '*.orig' --exclude '*.rej' openssh-5.1p1.orig/lpk-user-example.txt openssh-5.1p1+lpk/lpk-user-example.txt
1102 --- openssh-5.1p1.orig/lpk-user-example.txt 1969-12-31 16:00:00.000000000 -0800
1103 +++ openssh-5.1p1+lpk/lpk-user-example.txt 2008-08-23 15:02:47.000000000 -0700
1106 +Post to ML -> User Made Quick Install Doc.
1107 +Contribution from John Lane <john@lane.uk.net>
1109 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1111 +OpenSSH LDAP keystore Patch
1112 +===========================
1114 +NOTE: these notes are a transcript of a specific installation
1115 + they work for me, your specifics may be different!
1116 + from John Lane March 17th 2005 john@lane.uk.net
1118 +This is a patch to OpenSSH 4.0p1 to allow it to obtain users' public keys
1119 +from their LDAP record as an alternative to ~/.ssh/authorized_keys.
1121 +(Assuming here that necessary build stuff is in $BUILD)
1123 +cd $BUILD/openssh-4.0p1
1124 +patch -Np1 -i $BUILD/openssh-lpk-4.0p1-0.3.patch
1125 +mkdir -p /var/empty &&
1126 +./configure --prefix=/usr --sysconfdir=/etc/ssh \
1127 + --libexecdir=/usr/sbin --with-md5-passwords --with-pam \
1128 + --with-libs="-lldap" --with-cppflags="-DWITH_LDAP_PUBKEY"
1133 +Add the following config to /etc/ssh/ssh_config
1135 +LpkServers ldap://myhost.mydomain.com
1136 +LpkUserDN ou=People,dc=mydomain,dc=com
1138 +We need to tell sshd about the SSL keys during boot, as root's
1139 +environment does not exist at that time. Edit /etc/rc.d/init.d/sshd.
1140 +Change the startup code from this:
1141 + echo "Starting SSH Server..."
1142 + loadproc /usr/sbin/sshd
1145 + echo "Starting SSH Server..."
1146 + LDAPRC="/root/.ldaprc" loadproc /usr/sbin/sshd
1149 +Re-start the sshd daemon:
1150 +/etc/rc.d/init.d/sshd restart
1152 +Install the additional LDAP schema
1153 +cp $BUILD/openssh-lpk-0.2.schema /etc/openldap/schema/openssh.schema
1155 +Now add the openSSH LDAP schema to /etc/openldap/slapd.conf:
1156 +Add the following to the end of the existing block of schema includes
1157 +include /etc/openldap/schema/openssh.schema
1159 +Re-start the LDAP server:
1160 +/etc/rc.d/init.d/slapd restart
1162 +To add one or more public keys to a user, eg "testuser" :
1163 +ldapsearch -x -W -Z -LLL -b "uid=testuser,ou=People,dc=mydomain,dc=com" -D
1164 +"uid=testuser,ou=People,dc=mydomain,dc=com" > /tmp/testuser
1166 +append the following to this /tmp/testuser file
1167 +objectclass: ldapPublicKey
1168 +sshPublicKey: ssh-rsa
1169 +AAAAB3NzaC1yc2EAAAABJQAAAIB3dsrwqXqD7E4zYYrxwdDKBUQxKMioXy9pxFVai64kAPxjU9KS
1170 +qIo7QfkjslfsjflksjfldfkjsldfjLX/5zkzRmT28I5piGzunPv17S89z8XwSsuAoR1t86t+5dlI
1171 +7eZE/gVbn2UQkQq7+kdDTS2yXV6VnC52N/kKLG3ciBkBAw== General Purpose RSA Key
1174 +ldapmodify -x -D "uid=testuser,ou=People,dc=mydomain,dc=com" -W -f
1176 +Enter LDAP Password:
1177 +modifying entry "uid=testuser,ou=People,dc=mydomain,dc=com"
1178 +And check the modify is ok:
1179 +ldapsearch -x -W -Z -b "uid=testuser,ou=People,dc=mydomain,dc=com" -D
1180 +"uid=testuser,ou=People,dc=mydomain,dc=com"
1181 +Enter LDAP Password:
1185 +# base <uid=testuser,ou=People,dc=mydomain,dc=com> with scope sub
1186 +# filter: (objectclass=*)
1190 +# testuser, People, mydomain.com
1191 +dn: uid=testuser,ou=People,dc=mydomain,dc=com
1194 +objectClass: account
1195 +objectClass: posixAccount
1197 +objectClass: shadowAccount
1198 +objectClass: ldapPublicKey
1199 +shadowLastChange: 12757
1202 +loginShell: /bin/bash
1205 +homeDirectory: /home/testuser
1206 +userPassword:: e1NTSEF9UDgwV1hnM1VjUDRJK0k1YnFiL1d4ZUJObXlZZ3Z3UTU=
1207 +sshPublicKey: ssh-rsa
1208 +AAAAB3NzaC1yc2EAAAABJQAAAIB3dsrwqXqD7E4zYYrxwdDKBUQxKMioXy9pxFVai64kAPxjU9KSqIo7QfkjslfsjflksjfldfkjsldfjLX/5zkzRmT28I5piGzunPv17S89z
1209 +8XwSsuAoR1t86t+5dlI7eZE/gVbn2UQkQq7+kdDTS2yXV6VnC52N/kKLG3ciBkBAw== General Purpose RSA Key
1218 +Now start a ssh session to user "testuser" from usual ssh client (e.g.
1219 +puTTY). Login should succeed.
1221 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1222 --- openssh-5.7p1/Makefile.in.orig 2011-01-17 12:15:29.000000000 +0200
1223 +++ openssh-5.7p1/Makefile.in 2011-01-24 16:35:51.174726790 +0200
1225 auth2-gss.o gss-serv.o gss-serv-krb5.o \
1226 loginrec.o auth-pam.o auth-shadow.o auth-sia.o md5crypt.o \
1227 sftp-server.o sftp-common.o \
1228 - roaming_common.o roaming_serv.o
1229 + roaming_common.o roaming_serv.o ldapauth.o
1231 MANPAGES = moduli.5.out 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 ssh-pkcs11-helper.8.out sshd_config.5.out ssh_config.5.out
1232 MANPAGES_IN = moduli.5 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 ssh-pkcs11-helper.8 sshd_config.5 ssh_config.5
1233 diff -Nuar --exclude '*.orig' --exclude '*.rej' openssh-5.1p1.orig/openssh-lpk_openldap.schema openssh-5.1p1+lpk/openssh-lpk_openldap.schema
1234 --- openssh-5.1p1.orig/openssh-lpk_openldap.schema 1969-12-31 16:00:00.000000000 -0800
1235 +++ openssh-5.1p1+lpk/openssh-lpk_openldap.schema 2008-08-23 15:02:47.000000000 -0700
1238 +# LDAP Public Key Patch schema for use with openssh-ldappubkey
1239 +# Author: Eric AUGE <eau@phear.org>
1241 +# Based on the proposal of : Mark Ruijter
1245 +# octetString SYNTAX
1246 +attributetype ( 1.3.6.1.4.1.24552.500.1.1.1.13 NAME 'sshPublicKey'
1247 + DESC 'MANDATORY: OpenSSH Public key'
1248 + EQUALITY octetStringMatch
1249 + SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )
1251 +# printableString SYNTAX yes|no
1252 +objectclass ( 1.3.6.1.4.1.24552.500.1.1.2.0 NAME 'ldapPublicKey' SUP top AUXILIARY
1253 + DESC 'MANDATORY: OpenSSH LPK objectclass'
1254 + MUST ( sshPublicKey $ uid )
1256 diff -Nuar --exclude '*.orig' --exclude '*.rej' openssh-5.1p1.orig/openssh-lpk_sun.schema openssh-5.1p1+lpk/openssh-lpk_sun.schema
1257 --- openssh-5.1p1.orig/openssh-lpk_sun.schema 1969-12-31 16:00:00.000000000 -0800
1258 +++ openssh-5.1p1+lpk/openssh-lpk_sun.schema 2008-08-23 15:02:47.000000000 -0700
1261 +# LDAP Public Key Patch schema for use with openssh-ldappubkey
1262 +# Author: Eric AUGE <eau@phear.org>
1264 +# Schema for Sun Directory Server.
1265 +# Based on the original schema, modified by Stefan Fischer.
1270 +# octetString SYNTAX
1271 +attributeTypes: ( 1.3.6.1.4.1.24552.500.1.1.1.13 NAME 'sshPublicKey'
1272 + DESC 'MANDATORY: OpenSSH Public key'
1273 + EQUALITY octetStringMatch
1274 + SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )
1276 +# printableString SYNTAX yes|no
1277 +objectClasses: ( 1.3.6.1.4.1.24552.500.1.1.2.0 NAME 'ldapPublicKey' SUP top AUXILIARY
1278 + DESC 'MANDATORY: OpenSSH LPK objectclass'
1279 + MUST ( sshPublicKey $ uid )
1281 diff -Nuar --exclude '*.orig' --exclude '*.rej' openssh-5.1p1.orig/README.lpk openssh-5.1p1+lpk/README.lpk
1282 --- openssh-5.1p1.orig/README.lpk 1969-12-31 16:00:00.000000000 -0800
1283 +++ openssh-5.1p1+lpk/README.lpk 2008-08-23 15:02:47.000000000 -0700
1285 +OpenSSH LDAP PUBLIC KEY PATCH
1286 +Copyright (c) 2003 Eric AUGE (eau@phear.org)
1287 +All rights reserved.
1289 +Redistribution and use in source and binary forms, with or without
1290 +modification, are permitted provided that the following conditions
1292 +1. Redistributions of source code must retain the above copyright
1293 + notice, this list of conditions and the following disclaimer.
1294 +2. Redistributions in binary form must reproduce the above copyright
1295 + notice, this list of conditions and the following disclaimer in the
1296 + documentation and/or other materials provided with the distribution.
1297 +3. The name of the author may not be used to endorse or promote products
1298 + derived from this software without specific prior written permission.
1300 +THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1301 +IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1302 +OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1303 +IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
1304 +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
1305 +NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
1306 +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
1307 +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1308 +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
1309 +THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1311 +purposes of this patch:
1313 +This patch would help to have authentication centralization policy
1314 +using ssh public key authentication.
1315 +This patch could be an alternative to other "secure" authentication system
1316 +working in a similar way (Kerberos, SecurID, etc...), except the fact
1317 +that it's based on OpenSSH and its public key abilities.
1320 +'uid': means unix accounts existing on the current server
1321 +'lpkServerGroup:' mean server group configured on the current server ('lpkServerGroup' in sshd_config)
1326 + server1 (uid: eau,rival,toto) (lpkServerGroup: unix)
1328 + / \ --- - server3 (uid: eau, titi) (lpkServerGroup: unix)
1330 + | eau ,rival | server2 (uid: rival, eau) (lpkServerGroup: unix)
1332 + | userx,.... | server5 (uid: eau) (lpkServerGroup: mail)
1334 + ----- - server4 (uid: eau, rival) (no group configured)
1340 + * configured LDAP server somewhere on the network (i.e. OpenLDAP)
1341 + * patched sshd (with this patch ;)
1342 + * LDAP user(/group) entry (look at users.ldif (& groups.ldif)):
1344 + - attached to the 'ldapPublicKey' objectclass
1345 + - attached to the 'posixAccount' objectclass
1346 + - with a filled 'sshPublicKey' attribute
1348 + dn: uid=eau,ou=users,dc=cuckoos,dc=net
1350 + objectclass: person
1351 + objectclass: organizationalPerson
1352 + objectclass: posixAccount
1353 + objectclass: ldapPublicKey
1354 + description: Eric AUGE Account
1355 + userPassword: blah
1361 + homeDirectory: /export/home/eau
1362 + sshPublicKey: ssh-dss AAAAB3...
1363 + sshPublicKey: ssh-dss AAAAM5...
1366 + - attached to the 'posixGroup' objectclass
1367 + - with a 'cn' groupname attribute
1368 + - with multiple 'memberUid' attributes filled with usernames allowed in this group
1371 + dn: cn=unix,ou=groups,dc=cuckoos,dc=net
1373 + objectclass: posixGroup
1374 + description: Unix based servers group
1385 + If a user wants to authenticate to log in a server the sshd, will first look for authentication method allowed (RSAauth,kerberos,etc..)
1386 + and if RSAauth and tickets based auth fails, it will fallback to standard password authentication (if enabled).
1389 + 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.
1390 + It will do an ldapsearch to get the public key directly from the LDAP instead of reading it from the server filesystem.
1391 + (usually in $HOME/.ssh/authorized_keys)
1393 + 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.
1394 + If it fails, it falls back on RSA auth files ($HOME/.ssh/authorized_keys), etc.. and finally to standard password authentication (if enabled).
1396 + 7 tokens are added to sshd_config :
1397 + # here is the new patched ldap related tokens
1398 + # entries in your LDAP must be posixAccount & strongAuthenticationUser & posixGroup
1399 + UseLPK yes # look the pub key into LDAP
1400 + LpkServers ldap://10.31.32.5/ ldap://10.31.32.4 ldap://10.31.32.3 # which LDAP server for users ? (URL format)
1401 + LpkUserDN ou=users,dc=foobar,dc=net # which base DN for users ?
1402 + LpkGroupDN ou=groups,dc=foobar,dc=net # which base DN for groups ?
1403 + LpkBindDN cn=manager,dc=foobar,dc=net # which bind DN ?
1404 + LpkBindPw asecret # bind DN credidentials
1405 + LpkServerGroup agroupname # the group the server is part of
1407 + 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
1408 + flaws you have to take care of.
1410 +- HOW TO INSERT A USER/KEY INTO AN LDAP ENTRY
1412 + * my way (there is plenty :)
1413 + - create ldif file (i.e. users.ldif)
1414 + - cat ~/.ssh/id_dsa.pub OR cat ~/.ssh/id_rsa.pub OR cat ~/.ssh/identity.pub
1415 + - my way in 4 steps :
1418 + # you add this to the user entry in the LDIF file :
1420 + objectclass: posixAccount
1421 + objectclass: ldapPublicKey
1423 + sshPubliKey: ssh-dss AAAABDh12DDUR2...
1426 + # insert your entry and you're done :)
1427 + ldapadd -D balblabla -w bleh < file.ldif
1429 + all standard options can be present in the 'sshPublicKey' attribute.
1433 + Simply because, i was looking for a way to centralize all sysadmins authentication, easily, without completely using LDAP
1434 + as authentication method (like pam_ldap etc..).
1436 + After looking into Kerberos, SecurID, and other centralized secure authentications systems, the use of RSA and LDAP to get
1437 + public key for authentication allows us to control who has access to which server (the user needs an account and to be in 'strongAuthenticationUser'
1438 + objectclass within LDAP and part of the group the SSH server is in).
1440 + 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
1441 + so each user can change it as much as he wants).
1443 + Blocking a user account can be done directly from the LDAP (if sshd is using RSAAuth + ldap only).
1446 + Entry in the LDAP server must respect 'posixAccount' and 'ldapPublicKey' which are defined in core.schema.
1447 + and the additionnal lpk.schema.
1449 + This patch could allow a smooth transition between standard auth (/etc/passwd) and complete LDAP based authentication
1450 + (pamldap, nss_ldap, etc..).
1452 + This can be an alternative to other (old?/expensive?) authentication methods (Kerberos/SecurID/..).
1454 + Referring to schema at the beginning of this file if user 'eau' is only in group 'unix'
1455 + 'eau' would ONLY access 'server1', 'server2', 'server3' AND 'server4' BUT NOT 'server5'.
1456 + If you then modify the LDAP 'mail' group entry to add 'memberUid: eau' THEN user 'eau' would be able
1457 + to log in 'server5' (i hope you got the idea, my english is bad :).
1459 + Each server's sshd is patched and configured to ask the public key and the group infos in the LDAP
1461 + When you want to allow a new user to have access to the server parc, you just add him an account on
1462 + your servers, you add his public key into his entry on the LDAP server, it's done.
1464 + Because sshds are looking public keys into the LDAP directly instead of a file ($HOME/.ssh/authorized_keys).
1466 + When the user needs to change his passphrase he can do it directly from his workstation by changing
1467 + his own key set lock passphrase, and all servers are automatically aware.
1469 + With a CAREFUL LDAP server configuration you could allow a user to add/delete/modify his own entry himself
1470 + so he can add/modify/delete himself his public key when needed.
1473 + LDAP must be well configured, getting the public key of some user is not a problem, but if anonymous LDAP
1474 + allow write to users dn, somebody could replace someuser's public key by its own and impersonate some
1475 + of your users in all your server farm be VERY CAREFUL.
1477 + MITM attack when sshd is requesting the public key, could lead to a compromise of your servers allowing login
1478 + as the impersonnated user.
1480 + If LDAP server is down then, fallback on passwd auth.
1482 + the ldap code part has not been well audited yet.
1484 +- LDAP USER ENTRY EXAMPLES (LDIF Format, look in users.ldif)
1486 + dn: uid=jdoe,ou=users,dc=foobar,dc=net
1488 + objectclass: person
1489 + objectclass: organizationalPerson
1490 + objectclass: posixAccount
1491 + objectclass: ldapPublicKey
1492 + description: My account
1498 + homeDirectory: /home/jdoe
1499 + sshPublicKey: ssh-dss AAAAB3NzaC1kc3MAAAEBAOvL8pREUg9wSy/8+hQJ54YF3AXkB0OZrXB....
1503 +- LDAP GROUP ENTRY EXAMPLES (LDIF Format, look in groups.ldif)
1505 + dn: cn=unix,ou=groups,dc=cuckoos,dc=net
1507 + objectclass: posixGroup
1508 + description: Unix based servers group
1518 +Multiple 'sshPublicKey' in a user entry are allowed, as well as multiple 'memberUid' attributes in a group entry
1521 + 1. Apply the patch
1522 + 2. ./configure --with-your-options --with-ldap=/prefix/to/ldap_libs_and_includes
1527 + I hope this could help, and i hope to be clear enough,, or give ideas. questions/comments/improvements are welcome.
1530 + Redesign differently.
1533 + http://pacsec.jp/core05/psj05-barisani-en.pdf
1534 + http://fritz.potsdam.edu/projects/openssh-lpk/
1535 + http://fritz.potsdam.edu/projects/sshgate/
1536 + http://dev.inversepath.com/trac/openssh-lpk
1537 + http://lam.sf.net/ ( http://lam.sourceforge.net/documentation/supportedSchemas.htm )
1539 +- CONTRIBUTORS/IDEAS/GREETS :
1540 + - Falk Siemonsmeier.
1542 + - Michael Durchgraf.
1543 + - frederic peters.
1546 + - Robin H. Johnson.
1547 + - Adrian Bridgett.
1550 + - Eric AUGE <eau@phear.org>
1551 + - Andrea Barisani <andrea@inversepath.com>
1552 --- openssh-5.7p1/servconf.c.orig 2010-11-20 06:19:38.000000000 +0200
1553 +++ openssh-5.7p1/servconf.c 2011-01-24 16:38:27.381393458 +0200
1555 #include "channels.h"
1556 #include "groupaccess.h"
1558 +#ifdef WITH_LDAP_PUBKEY
1559 +#include "ldapauth.h"
1562 static void add_listen_addr(ServerOptions *, char *, int);
1563 static void add_one_listen_addr(ServerOptions *, char *, int);
1565 @@ -139,6 +143,24 @@
1566 options->authorized_principals_file = NULL;
1567 options->ip_qos_interactive = -1;
1568 options->ip_qos_bulk = -1;
1569 +#ifdef WITH_LDAP_PUBKEY
1571 + options->lpk.ld = NULL;
1572 + options->lpk.on = -1;
1573 + options->lpk.servers = NULL;
1574 + options->lpk.u_basedn = NULL;
1575 + options->lpk.g_basedn = NULL;
1576 + options->lpk.binddn = NULL;
1577 + options->lpk.bindpw = NULL;
1578 + options->lpk.sgroup = NULL;
1579 + options->lpk.filter = NULL;
1580 + options->lpk.fgroup = NULL;
1581 + options->lpk.l_conf = NULL;
1582 + options->lpk.tls = -1;
1583 + options->lpk.b_timeout.tv_sec = -1;
1584 + options->lpk.s_timeout.tv_sec = -1;
1585 + options->lpk.flags = FLAG_EMPTY;
1590 @@ -281,6 +303,32 @@
1591 options->ip_qos_interactive = IPTOS_LOWDELAY;
1592 if (options->ip_qos_bulk == -1)
1593 options->ip_qos_bulk = IPTOS_THROUGHPUT;
1594 +#ifdef WITH_LDAP_PUBKEY
1595 + if (options->lpk.on == -1)
1596 + options->lpk.on = _DEFAULT_LPK_ON;
1597 + if (options->lpk.servers == NULL)
1598 + options->lpk.servers = _DEFAULT_LPK_SERVERS;
1599 + if (options->lpk.u_basedn == NULL)
1600 + options->lpk.u_basedn = _DEFAULT_LPK_UDN;
1601 + if (options->lpk.g_basedn == NULL)
1602 + options->lpk.g_basedn = _DEFAULT_LPK_GDN;
1603 + if (options->lpk.binddn == NULL)
1604 + options->lpk.binddn = _DEFAULT_LPK_BINDDN;
1605 + if (options->lpk.bindpw == NULL)
1606 + options->lpk.bindpw = _DEFAULT_LPK_BINDPW;
1607 + if (options->lpk.sgroup == NULL)
1608 + options->lpk.sgroup = _DEFAULT_LPK_SGROUP;
1609 + if (options->lpk.filter == NULL)
1610 + options->lpk.filter = _DEFAULT_LPK_FILTER;
1611 + if (options->lpk.tls == -1)
1612 + options->lpk.tls = _DEFAULT_LPK_TLS;
1613 + if (options->lpk.b_timeout.tv_sec == -1)
1614 + options->lpk.b_timeout.tv_sec = _DEFAULT_LPK_BTIMEOUT;
1615 + if (options->lpk.s_timeout.tv_sec == -1)
1616 + options->lpk.s_timeout.tv_sec = _DEFAULT_LPK_STIMEOUT;
1617 + if (options->lpk.l_conf == NULL)
1618 + options->lpk.l_conf = _DEFAULT_LPK_LDP;
1621 /* Turn privilege separation on by default */
1622 if (use_privsep == -1)
1623 @@ -329,6 +377,12 @@
1624 sRevokedKeys, sTrustedUserCAKeys, sAuthorizedPrincipalsFile,
1625 sKexAlgorithms, sIPQoS,
1626 sDeprecated, sUnsupported
1627 +#ifdef WITH_LDAP_PUBKEY
1628 + ,sLdapPublickey, sLdapServers, sLdapUserDN
1629 + ,sLdapGroupDN, sBindDN, sBindPw, sMyGroup
1630 + ,sLdapFilter, sForceTLS, sBindTimeout
1631 + ,sSearchTimeout, sLdapConf
1635 #define SSHCFG_GLOBAL 0x01 /* allowed in main section of sshd_config */
1636 @@ -439,6 +493,20 @@
1637 { "clientalivecountmax", sClientAliveCountMax, SSHCFG_GLOBAL },
1638 { "authorizedkeysfile", sAuthorizedKeysFile, SSHCFG_ALL },
1639 { "authorizedkeysfile2", sAuthorizedKeysFile2, SSHCFG_ALL },
1640 +#ifdef WITH_LDAP_PUBKEY
1641 + { _DEFAULT_LPK_TOKEN, sLdapPublickey, SSHCFG_GLOBAL },
1642 + { _DEFAULT_SRV_TOKEN, sLdapServers, SSHCFG_GLOBAL },
1643 + { _DEFAULT_USR_TOKEN, sLdapUserDN, SSHCFG_GLOBAL },
1644 + { _DEFAULT_GRP_TOKEN, sLdapGroupDN, SSHCFG_GLOBAL },
1645 + { _DEFAULT_BDN_TOKEN, sBindDN, SSHCFG_GLOBAL },
1646 + { _DEFAULT_BPW_TOKEN, sBindPw, SSHCFG_GLOBAL },
1647 + { _DEFAULT_MYG_TOKEN, sMyGroup, SSHCFG_GLOBAL },
1648 + { _DEFAULT_FIL_TOKEN, sLdapFilter, SSHCFG_GLOBAL },
1649 + { _DEFAULT_TLS_TOKEN, sForceTLS, SSHCFG_GLOBAL },
1650 + { _DEFAULT_BTI_TOKEN, sBindTimeout, SSHCFG_GLOBAL },
1651 + { _DEFAULT_STI_TOKEN, sSearchTimeout, SSHCFG_GLOBAL },
1652 + { _DEFAULT_LDP_TOKEN, sLdapConf, SSHCFG_GLOBAL },
1654 { "useprivilegeseparation", sUsePrivilegeSeparation, SSHCFG_GLOBAL},
1655 { "acceptenv", sAcceptEnv, SSHCFG_GLOBAL },
1656 { "permittunnel", sPermitTunnel, SSHCFG_ALL },
1657 @@ -1411,6 +1479,107 @@
1659 arg = strdelim(&cp);
1661 +#ifdef WITH_LDAP_PUBKEY
1662 + case sLdapPublickey:
1663 + intptr = &options->lpk.on;
1665 + case sLdapServers:
1666 + /* arg = strdelim(&cp); */
1670 + if (!arg || *arg == '\0')
1671 + fatal("%s line %d: missing ldap server",filename,linenum);
1672 + arg[strlen(arg)] = '\0';
1673 + if ((options->lpk.servers = ldap_parse_servers(arg)) == NULL)
1674 + fatal("%s line %d: error in ldap servers", filename, linenum);
1675 + memset(arg,0,strlen(arg));
1679 + if (!arg || *arg == '\0')
1680 + fatal("%s line %d: missing ldap server",filename,linenum);
1681 + arg[strlen(arg)] = '\0';
1682 + options->lpk.u_basedn = xstrdup(arg);
1683 + memset(arg,0,strlen(arg));
1685 + case sLdapGroupDN:
1687 + if (!arg || *arg == '\0')
1688 + fatal("%s line %d: missing ldap server",filename,linenum);
1689 + arg[strlen(arg)] = '\0';
1690 + options->lpk.g_basedn = xstrdup(arg);
1691 + memset(arg,0,strlen(arg));
1695 + if (!arg || *arg == '\0')
1696 + fatal("%s line %d: missing binddn",filename,linenum);
1697 + arg[strlen(arg)] = '\0';
1698 + options->lpk.binddn = xstrdup(arg);
1699 + memset(arg,0,strlen(arg));
1703 + if (!arg || *arg == '\0')
1704 + fatal("%s line %d: missing bindpw",filename,linenum);
1705 + arg[strlen(arg)] = '\0';
1706 + options->lpk.bindpw = xstrdup(arg);
1707 + memset(arg,0,strlen(arg));
1711 + if (!arg || *arg == '\0')
1712 + fatal("%s line %d: missing groupname",filename, linenum);
1713 + arg[strlen(arg)] = '\0';
1714 + options->lpk.sgroup = xstrdup(arg);
1715 + if (options->lpk.sgroup)
1716 + options->lpk.fgroup = ldap_parse_groups(options->lpk.sgroup);
1717 + memset(arg,0,strlen(arg));
1721 + if (!arg || *arg == '\0')
1722 + fatal("%s line %d: missing filter",filename, linenum);
1723 + arg[strlen(arg)] = '\0';
1724 + options->lpk.filter = xstrdup(arg);
1725 + memset(arg,0,strlen(arg));
1728 + intptr = &options->lpk.tls;
1729 + arg = strdelim(&cp);
1730 + if (!arg || *arg == '\0')
1731 + fatal("%s line %d: missing yes/no argument.",
1732 + filename, linenum);
1733 + value = 0; /* silence compiler */
1734 + if (strcmp(arg, "yes") == 0)
1736 + else if (strcmp(arg, "no") == 0)
1738 + else if (strcmp(arg, "try") == 0)
1741 + fatal("%s line %d: Bad yes/no argument: %s",
1742 + filename, linenum, arg);
1743 + if (*intptr == -1)
1746 + case sBindTimeout:
1747 + intptr = (int *) &options->lpk.b_timeout.tv_sec;
1749 + case sSearchTimeout:
1750 + intptr = (int *) &options->lpk.s_timeout.tv_sec;
1755 + if (!arg || *arg == '\0')
1756 + fatal("%s line %d: missing LpkLdapConf", filename, linenum);
1757 + arg[strlen(arg)] = '\0';
1758 + options->lpk.l_conf = xstrdup(arg);
1759 + memset(arg, 0, strlen(arg));
1764 fatal("%s line %d: Missing handler for opcode %s (%d)",
1765 diff -Nuar --exclude '*.orig' --exclude '*.rej' openssh-5.1p1.orig/servconf.h openssh-5.1p1+lpk/servconf.h
1766 --- openssh-5.1p1.orig/servconf.h 2008-06-10 06:01:51.000000000 -0700
1767 +++ openssh-5.1p1+lpk/servconf.h 2008-08-23 15:02:47.000000000 -0700
1772 +#ifdef WITH_LDAP_PUBKEY
1773 +#include "ldapauth.h"
1776 #define MAX_PORTS 256 /* Max # ports. */
1778 #define MAX_ALLOW_USERS 256 /* Max # users on allow list. */
1780 int use_pam; /* Enable auth via PAM */
1783 +#ifdef WITH_LDAP_PUBKEY
1787 int num_permitted_opens;
1789 diff -Nuar --exclude '*.orig' --exclude '*.rej' openssh-5.1p1.orig/sshd.c openssh-5.1p1+lpk/sshd.c
1790 --- openssh-5.1p1.orig/sshd.c 2008-07-11 00:36:49.000000000 -0700
1791 +++ openssh-5.1p1+lpk/sshd.c 2008-08-23 15:02:47.000000000 -0700
1792 @@ -127,6 +127,10 @@
1794 #endif /* LIBWRAP */
1796 +#ifdef WITH_LDAP_PUBKEY
1797 +#include "ldapauth.h"
1803 @@ -1484,6 +1488,16 @@
1807 +#ifdef WITH_LDAP_PUBKEY
1808 + /* ldap_options_print(&options.lpk); */
1809 + /* XXX initialize/check ldap connection and set *LD */
1810 + if (options.lpk.on) {
1811 + if (options.lpk.l_conf && (ldap_parse_lconf(&options.lpk) < 0) )
1812 + error("[LDAP] could not parse %s", options.lpk.l_conf);
1813 + if (ldap_connect(&options.lpk) < 0)
1814 + error("[LDAP] could not initialize ldap connection");
1817 debug("sshd version %.100s", SSH_RELEASE);
1819 /* Store privilege separation user for later use if required. */
1820 diff -Nuar --exclude '*.orig' --exclude '*.rej' openssh-5.1p1.orig/sshd_config openssh-5.1p1+lpk/sshd_config
1821 --- openssh-5.1p1.orig/sshd_config 2008-07-02 05:35:43.000000000 -0700
1822 +++ openssh-5.1p1+lpk/sshd_config 2008-08-23 15:02:47.000000000 -0700
1823 @@ -109,6 +109,21 @@
1824 # no default banner path
1827 +# here are the new patched ldap related tokens
1828 +# entries in your LDAP must have posixAccount & ldapPublicKey objectclass
1830 +#LpkLdapConf /etc/ldap.conf
1831 +#LpkServers ldap://10.1.7.1/ ldap://10.1.7.2/
1832 +#LpkUserDN ou=users,dc=phear,dc=org
1833 +#LpkGroupDN ou=groups,dc=phear,dc=org
1834 +#LpkBindDN cn=Manager,dc=phear,dc=org
1836 +#LpkServerGroup mail
1837 +#LpkFilter (hostAccess=master.phear.org)
1839 +#LpkSearchTimelimit 3
1840 +#LpkBindTimelimit 3
1842 # override default of no subsystems
1843 Subsystem sftp /usr/libexec/sftp-server
1845 diff -Nuar --exclude '*.orig' --exclude '*.rej' openssh-5.1p1.orig/sshd_config.5 openssh-5.1p1+lpk/sshd_config.5
1846 --- openssh-5.1p1.orig/sshd_config.5 2008-07-02 05:35:43.000000000 -0700
1847 +++ openssh-5.1p1+lpk/sshd_config.5 2008-08-23 15:02:47.000000000 -0700
1848 @@ -1003,6 +1003,62 @@
1851 .Pa /usr/X11R6/bin/xauth .
1853 +Specifies whether LDAP public key retrieval must be used or not. It allow
1854 +an easy centralisation of public keys within an LDAP directory. The argument must be
1859 +Specifies whether LDAP Public keys should parse the specified ldap.conf file
1860 +instead of sshd_config Tokens. The argument must be a valid path to an ldap.conf
1864 +Specifies LDAP one or more [:space:] separated server's url the following form may be used:
1866 +LpkServers ldaps://127.0.0.1 ldap://127.0.0.2 ldap://127.0.0.3
1868 +Specifies the LDAP user DN.
1870 +LpkUserDN ou=users,dc=phear,dc=org
1872 +Specifies the LDAP groups DN.
1874 +LpkGroupDN ou=groups,dc=phear,dc=org
1876 +Specifies the LDAP bind DN to use if necessary.
1878 +LpkBindDN cn=Manager,dc=phear,dc=org
1880 +Specifies the LDAP bind credential.
1883 +.It Cm LpkServerGroup
1884 +Specifies one or more [:space:] separated group the server is part of.
1886 +LpkServerGroup unix mail prod
1888 +Specifies an additional LDAP filter to use for finding SSH keys
1890 +LpkFilter (hostAccess=master.phear.org)
1892 +Specifies if the LDAP server connection must be tried, forced or not used. The argument must be
1898 +.It Cm LpkSearchTimelimit
1899 +Sepcifies the search time limit before the search is considered over. value is
1902 +LpkSearchTimelimit 3
1903 +.It Cm LpkBindTimelimit
1904 +Sepcifies the bind time limit before the connection is considered dead. value is