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 the user's uid. */
40 temporarily_use_uid(pw);
42 +#ifdef WITH_LDAP_PUBKEY
44 + /* allocate a new key type */
45 + found = key_new(key->type);
47 + /* first check if the options is enabled, then try.. */
48 + if (options.lpk.on) {
49 + debug("[LDAP] trying LDAP first uid=%s",pw->pw_name);
50 + if (ldap_ismember(&options.lpk, pw->pw_name) > 0) {
51 + if ((k = ldap_getuserkey(&options.lpk, pw->pw_name)) != NULL) {
52 + /* Skip leading whitespace, empty and comment lines. */
53 + for (i = 0 ; i < k->num ; i++) {
54 + /* dont forget if multiple keys to reset options */
55 + char *cp, *options = NULL;
57 + for (cp = (char *)k->keys[i]->bv_val; *cp == ' ' || *cp == '\t'; cp++)
59 + if (!*cp || *cp == '\n' || *cp == '#')
62 + if (key_read(found, &cp) != 1) {
63 + /* no key? check if there are options for this key */
65 + debug2("[LDAP] user_key_allowed: check options: '%s'", cp);
67 + for (; *cp && (quoted || (*cp != ' ' && *cp != '\t')); cp++) {
68 + if (*cp == '\\' && cp[1] == '"')
69 + cp++; /* Skip both */
70 + else if (*cp == '"')
73 + /* Skip remaining whitespace. */
74 + for (; *cp == ' ' || *cp == '\t'; cp++)
76 + if (key_read(found, &cp) != 1) {
77 + debug2("[LDAP] user_key_allowed: advance: '%s'", cp);
78 + /* still no key? advance to next line*/
83 + if (key_equal(found, key) &&
84 + auth_parse_options(pw, options, file, linenum) == 1) {
86 + debug("[LDAP] matching key found");
87 + fp = key_fingerprint(found, SSH_FP_MD5, SSH_FP_HEX);
88 + verbose("[LDAP] Found matching %s key: %s", key_type(found), fp);
90 + /* restoring memory */
98 + }/* end of LDAP for() */
100 + logit("[LDAP] no keys found for '%s'!", pw->pw_name);
103 + logit("[LDAP] '%s' is not in '%s'", pw->pw_name, options.lpk.sgroup);
107 debug("trying public key file %s", file);
108 f = auth_openkeyfile(file, pw, options.strict_modes);
110 diff -Nuar --exclude '*.orig' --exclude '*.rej' openssh-5.1p1.orig/auth-rsa.c openssh-5.1p1+lpk/auth-rsa.c
111 --- openssh-5.1p1.orig/auth-rsa.c 2008-07-02 05:37:30.000000000 -0700
112 +++ openssh-5.1p1+lpk/auth-rsa.c 2008-08-23 15:02:47.000000000 -0700
113 @@ -174,10 +174,96 @@
117 +#ifdef WITH_LDAP_PUBKEY
119 + unsigned int i = 0;
122 /* Temporarily use the user's uid. */
123 temporarily_use_uid(pw);
125 +#ifdef WITH_LDAP_PUBKEY
126 + /* here is the job */
127 + key = key_new(KEY_RSA1);
129 + if (options.lpk.on) {
130 + debug("[LDAP] trying LDAP first uid=%s", pw->pw_name);
131 + if ( ldap_ismember(&options.lpk, pw->pw_name) > 0) {
132 + if ( (k = ldap_getuserkey(&options.lpk, pw->pw_name)) != NULL) {
133 + for (i = 0 ; i < k->num ; i++) {
134 + char *cp, *options = NULL;
136 + for (cp = k->keys[i]->bv_val; *cp == ' ' || *cp == '\t'; cp++)
138 + if (!*cp || *cp == '\n' || *cp == '#')
142 + * Check if there are options for this key, and if so,
143 + * save their starting address and skip the option part
144 + * for now. If there are no options, set the starting
147 + if (*cp < '0' || *cp > '9') {
150 + for (; *cp && (quoted || (*cp != ' ' && *cp != '\t')); cp++) {
151 + if (*cp == '\\' && cp[1] == '"')
152 + cp++; /* Skip both */
153 + else if (*cp == '"')
159 + /* Parse the key from the line. */
160 + if (hostfile_read_key(&cp, &bits, key) == 0) {
161 + debug("[LDAP] line %d: non ssh1 key syntax", i);
164 + /* cp now points to the comment part. */
166 + /* Check if the we have found the desired key (identified by its modulus). */
167 + if (BN_cmp(key->rsa->n, client_n) != 0)
170 + /* check the real bits */
171 + if (bits != (unsigned int)BN_num_bits(key->rsa->n))
172 + logit("[LDAP] Warning: ldap, line %lu: keysize mismatch: "
173 + "actual %d vs. announced %d.", (unsigned long)i, BN_num_bits(key->rsa->n), bits);
175 + /* We have found the desired key. */
177 + * If our options do not allow this key to be used,
178 + * do not send challenge.
180 + if (!auth_parse_options(pw, options, "[LDAP]", (unsigned long) i))
183 + /* break out, this key is allowed */
186 + /* add the return stuff etc... */
187 + /* Restore the privileged uid. */
190 + /* return key if allowed */
191 + if (allowed && rkey != NULL)
200 + logit("[LDAP] no keys found for '%s'!", pw->pw_name);
203 + logit("[LDAP] '%s' is not in '%s'", pw->pw_name, options.lpk.sgroup);
207 /* The authorized keys. */
208 file = authorized_keys_file(pw);
209 debug("trying public RSA key file %s", file);
210 diff -Nuar --exclude '*.orig' --exclude '*.rej' openssh-5.1p1.orig/config.h.in openssh-5.1p1+lpk/config.h.in
211 --- openssh-5.1p1.orig/config.h.in 2008-07-21 01:30:49.000000000 -0700
212 +++ openssh-5.1p1+lpk/config.h.in 2008-08-23 15:02:47.000000000 -0700
214 /* Define to 1 if you have the <linux/if_tun.h> header file. */
215 #undef HAVE_LINUX_IF_TUN_H
217 +/* Define if you want LDAP support */
218 +#undef WITH_LDAP_PUBKEY
220 /* Define if your libraries define login() */
223 --- openssh-5.7p1/configure.orig 2011-01-22 11:29:11.000000000 +0200
224 +++ openssh-5.7p1/configure 2011-01-24 16:33:06.271393457 +0200
225 @@ -1348,6 +1348,7 @@
226 --with-tcp-wrappers[=PATH] Enable tcpwrappers support (optionally in PATH)
227 --with-libedit[=PATH] Enable libedit support for sftp
228 --with-audit=module Enable audit support (modules=debug,bsm,linux)
229 + --with-ldap[=PATH] Enable LDAP pubkey support (optionally in PATH)
230 --with-ssl-dir=PATH Specify path to OpenSSL installation
231 --without-openssl-header-check Disable OpenSSL version consistency check
232 --with-ssl-engine Enable OpenSSL (hardware) ENGINE support
233 @@ -12198,6 +12199,85 @@
237 +# Check whether user wants LDAP support
240 +# Check whether --with-ldap was given.
241 +if test "${with_ldap+set}" = set; then
242 + withval=$with_ldap;
243 + if test "x$withval" != "xno" ; then
245 + if test "x$withval" != "xyes" ; then
246 + CPPFLAGS="$CPPFLAGS -I${withval}/include"
247 + LDFLAGS="$LDFLAGS -L${withval}/lib"
251 +cat >>confdefs.h <<\_ACEOF
252 +#define WITH_LDAP_PUBKEY 1
255 + LIBS="-lldap $LIBS"
258 + { echo "$as_me:$LINENO: checking for LDAP support" >&5
259 +echo $ECHO_N "checking for LDAP support... $ECHO_C" >&6; }
260 + cat >conftest.$ac_ext <<_ACEOF
263 +cat confdefs.h >>conftest.$ac_ext
264 +cat >>conftest.$ac_ext <<_ACEOF
265 +/* end confdefs.h. */
266 +#include <sys/types.h>
271 +(void)ldap_init(0, 0);
276 +rm -f conftest.$ac_objext
277 +if { (ac_try="$ac_compile"
279 + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
280 + *) ac_try_echo=$ac_try;;
282 +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
283 + (eval "$ac_compile") 2>conftest.er1
285 + grep -v '^ *+' conftest.er1 >conftest.err
287 + cat conftest.err >&5
288 + echo "$as_me:$LINENO: \$? = $ac_status" >&5
289 + (exit $ac_status); } && {
290 + test -z "$ac_c_werror_flag" ||
291 + test ! -s conftest.err
292 + } && test -s conftest.$ac_objext; then
293 + { echo "$as_me:$LINENO: result: yes" >&5
294 +echo "${ECHO_T}yes" >&6; }
296 + echo "$as_me: failed program was:" >&5
297 +sed 's/^/| /' conftest.$ac_ext >&5
300 + { echo "$as_me:$LINENO: result: no" >&5
301 +echo "${ECHO_T}no" >&6; }
302 + { { echo "$as_me:$LINENO: error: ** Incomplete or missing ldap libraries **" >&5
303 +echo "$as_me: error: ** Incomplete or missing ldap libraries **" >&2;}
304 + { (exit 1); exit 1; }; }
309 +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
319 @@ -31970,6 +32050,7 @@
320 echo " Smartcard support: $SCARD_MSG"
321 echo " S/KEY support: $SKEY_MSG"
322 echo " TCP Wrappers support: $TCPW_MSG"
323 +echo " LDAP support: $LDAP_MSG"
324 echo " MD5 password support: $MD5_MSG"
325 echo " libedit support: $LIBEDIT_MSG"
326 echo " Solaris process contract support: $SPC_MSG"
327 diff -Nuar --exclude '*.orig' --exclude '*.rej' openssh-5.1p1.orig/configure.ac openssh-5.1p1+lpk/configure.ac
328 --- openssh-5.1p1.orig/configure.ac 2008-07-09 04:07:19.000000000 -0700
329 +++ openssh-5.1p1+lpk/configure.ac 2008-08-23 15:02:47.000000000 -0700
330 @@ -1299,6 +1299,37 @@
334 +# Check whether user wants LDAP support
337 + [ --with-ldap[[=PATH]] Enable LDAP pubkey support (optionally in PATH)],
339 + if test "x$withval" != "xno" ; then
341 + if test "x$withval" != "xyes" ; then
342 + CPPFLAGS="$CPPFLAGS -I${withval}/include"
343 + LDFLAGS="$LDFLAGS -L${withval}/lib"
346 + AC_DEFINE([WITH_LDAP_PUBKEY], 1, [Enable LDAP pubkey support])
347 + LIBS="-lldap $LIBS"
350 + AC_MSG_CHECKING([for LDAP support])
352 + [#include <sys/types.h>
353 + #include <ldap.h>],
354 + [(void)ldap_init(0, 0);],
355 + [AC_MSG_RESULT(yes)],
358 + AC_MSG_ERROR([** Incomplete or missing ldap libraries **])
365 dnl Checks for library functions. Please keep in alphabetical order
368 @@ -4137,6 +4168,7 @@
369 echo " Smartcard support: $SCARD_MSG"
370 echo " S/KEY support: $SKEY_MSG"
371 echo " TCP Wrappers support: $TCPW_MSG"
372 +echo " LDAP support: $LDAP_MSG"
373 echo " MD5 password support: $MD5_MSG"
374 echo " libedit support: $LIBEDIT_MSG"
375 echo " Solaris process contract support: $SPC_MSG"
376 diff -Nuar --exclude '*.orig' --exclude '*.rej' openssh-5.1p1.orig/ldapauth.c openssh-5.1p1+lpk/ldapauth.c
377 --- openssh-5.1p1.orig/ldapauth.c 1969-12-31 16:00:00.000000000 -0800
378 +++ openssh-5.1p1+lpk/ldapauth.c 2008-08-23 15:02:47.000000000 -0700
386 + * Copyright (c) 2005, Eric AUGE <eau@phear.org>
387 + * All rights reserved.
389 + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
391 + * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
392 + * 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.
393 + * 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.
395 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
396 + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
397 + * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
398 + * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
399 + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
400 + * 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.
405 +#include "includes.h"
407 +#ifdef WITH_LDAP_PUBKEY
414 +#include "ldapauth.h"
417 +static char *attrs[] = {
422 +/* filter building infos */
423 +#define FILTER_GROUP_PREFIX "(&(objectclass=posixGroup)"
424 +#define FILTER_OR_PREFIX "(|"
425 +#define FILTER_OR_SUFFIX ")"
426 +#define FILTER_CN_PREFIX "(cn="
427 +#define FILTER_CN_SUFFIX ")"
428 +#define FILTER_UID_FORMAT "(memberUid=%s)"
429 +#define FILTER_GROUP_SUFFIX ")"
430 +#define FILTER_GROUP_SIZE(group) (size_t) (strlen(group)+(ldap_count_group(group)*5)+52)
432 +/* just filter building stuff */
433 +#define REQUEST_GROUP_SIZE(filter, uid) (size_t) (strlen(filter)+strlen(uid)+1)
434 +#define REQUEST_GROUP(buffer, prefilter, pwname) \
435 + buffer = (char *) calloc(REQUEST_GROUP_SIZE(prefilter, pwname), sizeof(char)); \
437 + perror("calloc()"); \
440 + snprintf(buffer, REQUEST_GROUP_SIZE(prefilter,pwname), prefilter, pwname)
442 +XXX OLD group building macros
443 +#define REQUEST_GROUP_SIZE(grp, uid) (size_t) (strlen(grp)+strlen(uid)+46)
444 +#define REQUEST_GROUP(buffer,pwname,grp) \
445 + buffer = (char *) calloc(REQUEST_GROUP_SIZE(grp, pwname), sizeof(char)); \
447 + perror("calloc()"); \
450 + snprintf(buffer,REQUEST_GROUP_SIZE(grp,pwname),"(&(objectclass=posixGroup)(cn=%s)(memberUid=%s))",grp,pwname)
454 +XXX stock upstream version without extra filter support
455 +#define REQUEST_USER_SIZE(uid) (size_t) (strlen(uid)+64)
456 +#define REQUEST_USER(buffer, pwname) \
457 + buffer = (char *) calloc(REQUEST_USER_SIZE(pwname), sizeof(char)); \
459 + perror("calloc()"); \
462 + snprintf(buffer,REQUEST_USER_SIZE(pwname),"(&(objectclass=posixAccount)(objectclass=ldapPublicKey)(uid=%s))",pwname)
465 +#define REQUEST_USER_SIZE(uid, filter) (size_t) (strlen(uid)+64+(filter != NULL ? strlen(filter) : 0))
466 +#define REQUEST_USER(buffer, pwname, customfilter) \
467 + buffer = (char *) calloc(REQUEST_USER_SIZE(pwname, customfilter), sizeof(char)); \
469 + perror("calloc()"); \
472 + snprintf(buffer, REQUEST_USER_SIZE(pwname, customfilter), \
473 + "(&(objectclass=posixAccount)(objectclass=ldapPublicKey)(uid=%s)%s)", \
474 + pwname, (customfilter != NULL ? customfilter : ""))
476 +/* some portable and working tokenizer, lame though */
477 +static int tokenize(char ** o, size_t size, char * input) {
478 + unsigned int i = 0, num;
479 + const char * charset = " \t";
480 + char * ptr = input;
482 + /* leading white spaces are ignored */
483 + num = strspn(ptr, charset);
486 + while ((num = strcspn(ptr, charset))) {
498 +void ldap_close(ldap_opt_t * ldap) {
503 + if ( ldap_unbind_ext(ldap->ld, NULL, NULL) < 0)
504 + ldap_perror(ldap->ld, "ldap_unbind()");
507 + FLAG_SET_DISCONNECTED(ldap->flags);
513 +int ldap_connect(ldap_opt_t * ldap) {
514 + int version = LDAP_VERSION3;
516 + if (!ldap->servers)
519 + /* Connection Init and setup */
520 + ldap->ld = ldap_init(ldap->servers, LDAP_PORT);
522 + ldap_perror(ldap->ld, "ldap_init()");
526 + if ( ldap_set_option(ldap->ld, LDAP_OPT_PROTOCOL_VERSION, &version) != LDAP_OPT_SUCCESS) {
527 + ldap_perror(ldap->ld, "ldap_set_option(LDAP_OPT_PROTOCOL_VERSION)");
531 + /* Timeouts setup */
532 + if (ldap_set_option(ldap->ld, LDAP_OPT_NETWORK_TIMEOUT, &ldap->b_timeout) != LDAP_SUCCESS) {
533 + ldap_perror(ldap->ld, "ldap_set_option(LDAP_OPT_NETWORK_TIMEOUT)");
535 + if (ldap_set_option(ldap->ld, LDAP_OPT_TIMEOUT, &ldap->s_timeout) != LDAP_SUCCESS) {
536 + ldap_perror(ldap->ld, "ldap_set_option(LDAP_OPT_TIMEOUT)");
540 + if ( (ldap->tls == -1) || (ldap->tls == 1) ) {
541 + if (ldap_start_tls_s(ldap->ld, NULL, NULL ) != LDAP_SUCCESS) {
542 + /* failed then reinit the initial connect */
543 + ldap_perror(ldap->ld, "ldap_connect: (TLS) ldap_start_tls()");
544 + if (ldap->tls == 1)
547 + ldap->ld = ldap_init(ldap->servers, LDAP_PORT);
549 + ldap_perror(ldap->ld, "ldap_init()");
553 + if ( ldap_set_option(ldap->ld, LDAP_OPT_PROTOCOL_VERSION, &version) != LDAP_OPT_SUCCESS) {
554 + ldap_perror(ldap->ld, "ldap_set_option()");
561 + if ( ldap_simple_bind_s(ldap->ld, ldap->binddn, ldap->bindpw) != LDAP_SUCCESS) {
562 + ldap_perror(ldap->ld, "ldap_simple_bind_s()");
566 + /* says it is connected */
567 + FLAG_SET_CONNECTED(ldap->flags);
572 +/* must free allocated ressource */
573 +static char * ldap_build_host(char *host, int port) {
574 + unsigned int size = strlen(host)+11;
575 + char * h = (char *) calloc (size, sizeof(char));
580 + rc = snprintf(h, size, "%s:%d ", host, port);
586 +static int ldap_count_group(const char * input) {
587 + const char * charset = " \t";
588 + const char * ptr = input;
589 + unsigned int count = 0;
592 + num = strspn(ptr, charset);
595 + while ((num = strcspn(ptr, charset))) {
605 +char * ldap_parse_groups(const char * groups) {
606 + unsigned int buffer_size = FILTER_GROUP_SIZE(groups);
607 + char * buffer = (char *) calloc(buffer_size, sizeof(char));
610 + unsigned int i = 0;
612 + if ((!groups)||(!buffer))
615 + g = strdup(groups);
621 + /* first separate into n tokens */
622 + if ( tokenize(garray, sizeof(garray)/sizeof(*garray), g) < 0) {
628 + /* build the final filter format */
629 + strlcat(buffer, FILTER_GROUP_PREFIX, buffer_size);
630 + strlcat(buffer, FILTER_OR_PREFIX, buffer_size);
632 + while (garray[i]) {
633 + strlcat(buffer, FILTER_CN_PREFIX, buffer_size);
634 + strlcat(buffer, garray[i], buffer_size);
635 + strlcat(buffer, FILTER_CN_SUFFIX, buffer_size);
638 + strlcat(buffer, FILTER_OR_SUFFIX, buffer_size);
639 + strlcat(buffer, FILTER_UID_FORMAT, buffer_size);
640 + strlcat(buffer, FILTER_GROUP_SUFFIX, buffer_size);
646 +/* a bit dirty but leak free */
647 +char * ldap_parse_servers(const char * servers) {
649 + char * tmp = NULL, *urls[32];
650 + unsigned int num = 0 , i = 0 , asize = 0;
651 + LDAPURLDesc *urld[32];
656 + /* local copy of the arg */
657 + s = strdup(servers);
661 + /* first separate into URL tokens */
662 + if ( tokenize(urls, sizeof(urls)/sizeof(*urls), s) < 0)
667 + if (! ldap_is_ldap_url(urls[i]) ||
668 + (ldap_url_parse(urls[i], &urld[i]) != 0)) {
677 + /* how much memory do we need */
679 + for (i = 0 ; i < num ; i++)
680 + asize += strlen(urld[i]->lud_host)+11;
683 + s = (char *) calloc( asize+1 , sizeof(char));
685 + for (i = 0 ; i < num ; i++)
686 + ldap_free_urldesc(urld[i]);
690 + /* then build the final host string */
691 + for (i = 0 ; i < num ; i++) {
692 + /* built host part */
693 + tmp = ldap_build_host(urld[i]->lud_host, urld[i]->lud_port);
694 + strncat(s, tmp, strlen(tmp));
695 + ldap_free_urldesc(urld[i]);
702 +void ldap_options_print(ldap_opt_t * ldap) {
703 + debug("ldap options:");
704 + debug("servers: %s", ldap->servers);
705 + if (ldap->u_basedn)
706 + debug("user basedn: %s", ldap->u_basedn);
707 + if (ldap->g_basedn)
708 + debug("group basedn: %s", ldap->g_basedn);
710 + debug("binddn: %s", ldap->binddn);
712 + debug("bindpw: %s", ldap->bindpw);
714 + debug("group: %s", ldap->sgroup);
716 + debug("filter: %s", ldap->filter);
719 +void ldap_options_free(ldap_opt_t * l) {
744 +void ldap_keys_free(ldap_key_t * k) {
745 + ldap_value_free_len(k->keys);
750 +ldap_key_t * ldap_getuserkey(ldap_opt_t *l, const char * user) {
751 + ldap_key_t * k = (ldap_key_t *) calloc (1, sizeof(ldap_key_t));
752 + LDAPMessage *res, *e;
759 + /* Am i still connected ? RETRY n times */
760 + /* XXX TODO: setup some conf value for retrying */
761 + if (!(l->flags & FLAG_CONNECTED))
762 + for (i = 0 ; i < 2 ; i++)
763 + if (ldap_connect(l) == 0)
766 + /* quick check for attempts to be evil */
767 + if ((strchr(user, '(') != NULL) || (strchr(user, ')') != NULL) ||
768 + (strchr(user, '*') != NULL) || (strchr(user, '\\') != NULL))
771 + /* build filter for LDAP request */
772 + REQUEST_USER(filter, user, l->filter);
774 + if ( ldap_search_st( l->ld,
776 + LDAP_SCOPE_SUBTREE,
778 + attrs, 0, &l->s_timeout, &res ) != LDAP_SUCCESS) {
780 + ldap_perror(l->ld, "ldap_search_st()");
785 + /* XXX error on search, timeout etc.. close ask for reconnect */
794 + /* check if any results */
795 + i = ldap_count_entries(l->ld,res);
803 + debug("[LDAP] duplicate entries, using the FIRST entry returned");
805 + e = ldap_first_entry(l->ld, res);
806 + k->keys = ldap_get_values_len(l->ld, e, PUBKEYATTR);
807 + k->num = ldap_count_values_len(k->keys);
815 + 0 if user is NOT member of current server group
816 + 1 if user IS MEMBER of current server group
818 +int ldap_ismember(ldap_opt_t * l, const char * user) {
823 + if ((!l->sgroup) || !(l->g_basedn))
826 + /* Am i still connected ? RETRY n times */
827 + /* XXX TODO: setup some conf value for retrying */
828 + if (!(l->flags & FLAG_CONNECTED))
829 + for (i = 0 ; i < 2 ; i++)
830 + if (ldap_connect(l) == 0)
833 + /* quick check for attempts to be evil */
834 + if ((strchr(user, '(') != NULL) || (strchr(user, ')') != NULL) ||
835 + (strchr(user, '*') != NULL) || (strchr(user, '\\') != NULL))
838 + /* build filter for LDAP request */
839 + REQUEST_GROUP(filter, l->fgroup, user);
841 + if (ldap_search_st( l->ld,
843 + LDAP_SCOPE_SUBTREE,
845 + NULL, 0, &l->s_timeout, &res) != LDAP_SUCCESS) {
847 + ldap_perror(l->ld, "ldap_search_st()");
851 + /* XXX error on search, timeout etc.. close ask for reconnect */
859 + /* check if any results */
860 + if (ldap_count_entries(l->ld, res) > 0) {
870 + * ldap.conf simple parser
871 + * XXX TODO: sanity checks
873 + * - free the previous ldap_opt_before replacing entries
874 + * - free each necessary previously parsed elements
876 + * -1 on FAILURE, 0 on SUCCESS
878 +int ldap_parse_lconf(ldap_opt_t * l) {
879 + FILE * lcd; /* ldap.conf descriptor */
881 + char * s = NULL, * k = NULL, * v = NULL;
884 + lcd = fopen (l->l_conf, "r");
886 + /* debug("Cannot open %s", l->l_conf); */
887 + perror("ldap_parse_lconf()");
891 + while (fgets (buf, sizeof (buf), lcd) != NULL) {
893 + if (*buf == '\n' || *buf == '#')
898 + while (*v != '\0' && *v != ' ' && *v != '\t')
906 + while (*v == ' ' || *v == '\t')
909 + li = strlen (v) - 1;
910 + while (v[li] == ' ' || v[li] == '\t' || v[li] == '\n')
914 + if (!strcasecmp (k, "uri")) {
915 + if ((l->servers = ldap_parse_servers(v)) == NULL) {
916 + fatal("error in ldap servers");
921 + else if (!strcasecmp (k, "base")) {
922 + s = strchr (v, '?');
925 + l->u_basedn = malloc (len + 1);
926 + strncpy (l->u_basedn, v, len);
927 + l->u_basedn[len] = '\0';
929 + l->u_basedn = strdup (v);
932 + else if (!strcasecmp (k, "binddn")) {
933 + l->binddn = strdup (v);
935 + else if (!strcasecmp (k, "bindpw")) {
936 + l->bindpw = strdup (v);
938 + else if (!strcasecmp (k, "timelimit")) {
939 + l->s_timeout.tv_sec = atoi (v);
941 + else if (!strcasecmp (k, "bind_timelimit")) {
942 + l->b_timeout.tv_sec = atoi (v);
944 + else if (!strcasecmp (k, "ssl")) {
945 + if (!strcasecmp (v, "start_tls"))
954 +#endif /* WITH_LDAP_PUBKEY */
955 diff -Nuar --exclude '*.orig' --exclude '*.rej' openssh-5.1p1.orig/ldapauth.h openssh-5.1p1+lpk/ldapauth.h
956 --- openssh-5.1p1.orig/ldapauth.h 1969-12-31 16:00:00.000000000 -0800
957 +++ openssh-5.1p1+lpk/ldapauth.h 2008-08-23 15:02:47.000000000 -0700
965 + * Copyright (c) 2005, Eric AUGE <eau@phear.org>
966 + * All rights reserved.
968 + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
970 + * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
971 + * 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.
972 + * 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.
974 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
975 + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
976 + * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
977 + * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
978 + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
979 + * 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.
987 +#define LDAP_DEPRECATED 1
994 +/* tokens in use for config */
995 +#define _DEFAULT_LPK_TOKEN "UseLPK"
996 +#define _DEFAULT_SRV_TOKEN "LpkServers"
997 +#define _DEFAULT_USR_TOKEN "LpkUserDN"
998 +#define _DEFAULT_GRP_TOKEN "LpkGroupDN"
999 +#define _DEFAULT_BDN_TOKEN "LpkBindDN"
1000 +#define _DEFAULT_BPW_TOKEN "LpkBindPw"
1001 +#define _DEFAULT_MYG_TOKEN "LpkServerGroup"
1002 +#define _DEFAULT_FIL_TOKEN "LpkFilter"
1003 +#define _DEFAULT_TLS_TOKEN "LpkForceTLS"
1004 +#define _DEFAULT_BTI_TOKEN "LpkBindTimelimit"
1005 +#define _DEFAULT_STI_TOKEN "LpkSearchTimelimit"
1006 +#define _DEFAULT_LDP_TOKEN "LpkLdapConf"
1008 +/* default options */
1009 +#define _DEFAULT_LPK_ON 0
1010 +#define _DEFAULT_LPK_SERVERS NULL
1011 +#define _DEFAULT_LPK_UDN NULL
1012 +#define _DEFAULT_LPK_GDN NULL
1013 +#define _DEFAULT_LPK_BINDDN NULL
1014 +#define _DEFAULT_LPK_BINDPW NULL
1015 +#define _DEFAULT_LPK_SGROUP NULL
1016 +#define _DEFAULT_LPK_FILTER NULL
1017 +#define _DEFAULT_LPK_TLS -1
1018 +#define _DEFAULT_LPK_BTIMEOUT 10
1019 +#define _DEFAULT_LPK_STIMEOUT 10
1020 +#define _DEFAULT_LPK_LDP NULL
1023 +#define FLAG_EMPTY 0x00000000
1024 +#define FLAG_CONNECTED 0x00000001
1027 +#define FLAG_SET_EMPTY(x) x&=(FLAG_EMPTY)
1028 +#define FLAG_SET_CONNECTED(x) x|=(FLAG_CONNECTED)
1029 +#define FLAG_SET_DISCONNECTED(x) x&=~(FLAG_CONNECTED)
1034 +#define PUBKEYATTR "sshPublicKey"
1038 + * defined files path
1039 + * (should be relocated to pathnames.h,
1040 + * if one day it's included within the tree)
1043 +#define _PATH_LDAP_CONFIG_FILE "/etc/ldap.conf"
1046 +typedef struct ldap_options {
1047 + int on; /* Use it or NOT */
1048 + LDAP * ld; /* LDAP file desc */
1049 + char * servers; /* parsed servers for ldaplib failover handling */
1050 + char * u_basedn; /* user basedn */
1051 + char * g_basedn; /* group basedn */
1052 + char * binddn; /* binddn */
1053 + char * bindpw; /* bind password */
1054 + char * sgroup; /* server group */
1055 + char * fgroup; /* group filter */
1056 + char * filter; /* additional filter */
1057 + char * l_conf; /* use ldap.conf */
1058 + int tls; /* TLS only */
1059 + struct timeval b_timeout; /* bind timeout */
1060 + struct timeval s_timeout; /* search timeout */
1061 + unsigned int flags; /* misc flags (reconnection, future use?) */
1064 +typedef struct ldap_keys {
1065 + struct berval ** keys; /* the public keys retrieved */
1066 + unsigned int num; /* number of keys */
1070 +/* function headers */
1071 +void ldap_close(ldap_opt_t *);
1072 +int ldap_connect(ldap_opt_t *);
1073 +char * ldap_parse_groups(const char *);
1074 +char * ldap_parse_servers(const char *);
1075 +void ldap_options_print(ldap_opt_t *);
1076 +void ldap_options_free(ldap_opt_t *);
1077 +void ldap_keys_free(ldap_key_t *);
1078 +int ldap_parse_lconf(ldap_opt_t *);
1079 +ldap_key_t * ldap_getuserkey(ldap_opt_t *, const char *);
1080 +int ldap_ismember(ldap_opt_t *, const char *);
1083 diff -Nuar --exclude '*.orig' --exclude '*.rej' openssh-5.1p1.orig/lpk-user-example.txt openssh-5.1p1+lpk/lpk-user-example.txt
1084 --- openssh-5.1p1.orig/lpk-user-example.txt 1969-12-31 16:00:00.000000000 -0800
1085 +++ openssh-5.1p1+lpk/lpk-user-example.txt 2008-08-23 15:02:47.000000000 -0700
1088 +Post to ML -> User Made Quick Install Doc.
1089 +Contribution from John Lane <john@lane.uk.net>
1091 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1093 +OpenSSH LDAP keystore Patch
1094 +===========================
1096 +NOTE: these notes are a transcript of a specific installation
1097 + they work for me, your specifics may be different!
1098 + from John Lane March 17th 2005 john@lane.uk.net
1100 +This is a patch to OpenSSH 4.0p1 to allow it to obtain users' public keys
1101 +from their LDAP record as an alternative to ~/.ssh/authorized_keys.
1103 +(Assuming here that necessary build stuff is in $BUILD)
1105 +cd $BUILD/openssh-4.0p1
1106 +patch -Np1 -i $BUILD/openssh-lpk-4.0p1-0.3.patch
1107 +mkdir -p /var/empty &&
1108 +./configure --prefix=/usr --sysconfdir=/etc/ssh \
1109 + --libexecdir=/usr/sbin --with-md5-passwords --with-pam \
1110 + --with-libs="-lldap" --with-cppflags="-DWITH_LDAP_PUBKEY"
1115 +Add the following config to /etc/ssh/ssh_config
1117 +LpkServers ldap://myhost.mydomain.com
1118 +LpkUserDN ou=People,dc=mydomain,dc=com
1120 +We need to tell sshd about the SSL keys during boot, as root's
1121 +environment does not exist at that time. Edit /etc/rc.d/init.d/sshd.
1122 +Change the startup code from this:
1123 + echo "Starting SSH Server..."
1124 + loadproc /usr/sbin/sshd
1127 + echo "Starting SSH Server..."
1128 + LDAPRC="/root/.ldaprc" loadproc /usr/sbin/sshd
1131 +Re-start the sshd daemon:
1132 +/etc/rc.d/init.d/sshd restart
1134 +Install the additional LDAP schema
1135 +cp $BUILD/openssh-lpk-0.2.schema /etc/openldap/schema/openssh.schema
1137 +Now add the openSSH LDAP schema to /etc/openldap/slapd.conf:
1138 +Add the following to the end of the existing block of schema includes
1139 +include /etc/openldap/schema/openssh.schema
1141 +Re-start the LDAP server:
1142 +/etc/rc.d/init.d/slapd restart
1144 +To add one or more public keys to a user, eg "testuser" :
1145 +ldapsearch -x -W -Z -LLL -b "uid=testuser,ou=People,dc=mydomain,dc=com" -D
1146 +"uid=testuser,ou=People,dc=mydomain,dc=com" > /tmp/testuser
1148 +append the following to this /tmp/testuser file
1149 +objectclass: ldapPublicKey
1150 +sshPublicKey: ssh-rsa
1151 +AAAAB3NzaC1yc2EAAAABJQAAAIB3dsrwqXqD7E4zYYrxwdDKBUQxKMioXy9pxFVai64kAPxjU9KS
1152 +qIo7QfkjslfsjflksjfldfkjsldfjLX/5zkzRmT28I5piGzunPv17S89z8XwSsuAoR1t86t+5dlI
1153 +7eZE/gVbn2UQkQq7+kdDTS2yXV6VnC52N/kKLG3ciBkBAw== General Purpose RSA Key
1156 +ldapmodify -x -D "uid=testuser,ou=People,dc=mydomain,dc=com" -W -f
1158 +Enter LDAP Password:
1159 +modifying entry "uid=testuser,ou=People,dc=mydomain,dc=com"
1160 +And check the modify is ok:
1161 +ldapsearch -x -W -Z -b "uid=testuser,ou=People,dc=mydomain,dc=com" -D
1162 +"uid=testuser,ou=People,dc=mydomain,dc=com"
1163 +Enter LDAP Password:
1167 +# base <uid=testuser,ou=People,dc=mydomain,dc=com> with scope sub
1168 +# filter: (objectclass=*)
1172 +# testuser, People, mydomain.com
1173 +dn: uid=testuser,ou=People,dc=mydomain,dc=com
1176 +objectClass: account
1177 +objectClass: posixAccount
1179 +objectClass: shadowAccount
1180 +objectClass: ldapPublicKey
1181 +shadowLastChange: 12757
1184 +loginShell: /bin/bash
1187 +homeDirectory: /home/testuser
1188 +userPassword:: e1NTSEF9UDgwV1hnM1VjUDRJK0k1YnFiL1d4ZUJObXlZZ3Z3UTU=
1189 +sshPublicKey: ssh-rsa
1190 +AAAAB3NzaC1yc2EAAAABJQAAAIB3dsrwqXqD7E4zYYrxwdDKBUQxKMioXy9pxFVai64kAPxjU9KSqIo7QfkjslfsjflksjfldfkjsldfjLX/5zkzRmT28I5piGzunPv17S89z
1191 +8XwSsuAoR1t86t+5dlI7eZE/gVbn2UQkQq7+kdDTS2yXV6VnC52N/kKLG3ciBkBAw== General Purpose RSA Key
1200 +Now start a ssh session to user "testuser" from usual ssh client (e.g.
1201 +puTTY). Login should succeed.
1203 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1204 --- openssh-5.7p1/Makefile.in.orig 2011-01-17 12:15:29.000000000 +0200
1205 +++ openssh-5.7p1/Makefile.in 2011-01-24 16:35:51.174726790 +0200
1207 auth2-gss.o gss-serv.o gss-serv-krb5.o \
1208 loginrec.o auth-pam.o auth-shadow.o auth-sia.o md5crypt.o \
1209 sftp-server.o sftp-common.o \
1210 - roaming_common.o roaming_serv.o
1211 + roaming_common.o roaming_serv.o ldapauth.o
1213 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
1214 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
1215 diff -Nuar --exclude '*.orig' --exclude '*.rej' openssh-5.1p1.orig/openssh-lpk_openldap.schema openssh-5.1p1+lpk/openssh-lpk_openldap.schema
1216 --- openssh-5.1p1.orig/openssh-lpk_openldap.schema 1969-12-31 16:00:00.000000000 -0800
1217 +++ openssh-5.1p1+lpk/openssh-lpk_openldap.schema 2008-08-23 15:02:47.000000000 -0700
1220 +# LDAP Public Key Patch schema for use with openssh-ldappubkey
1221 +# Author: Eric AUGE <eau@phear.org>
1223 +# Based on the proposal of : Mark Ruijter
1227 +# octetString SYNTAX
1228 +attributetype ( 1.3.6.1.4.1.24552.500.1.1.1.13 NAME 'sshPublicKey'
1229 + DESC 'MANDATORY: OpenSSH Public key'
1230 + EQUALITY octetStringMatch
1231 + SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )
1233 +# printableString SYNTAX yes|no
1234 +objectclass ( 1.3.6.1.4.1.24552.500.1.1.2.0 NAME 'ldapPublicKey' SUP top AUXILIARY
1235 + DESC 'MANDATORY: OpenSSH LPK objectclass'
1236 + MUST ( sshPublicKey $ uid )
1238 diff -Nuar --exclude '*.orig' --exclude '*.rej' openssh-5.1p1.orig/openssh-lpk_sun.schema openssh-5.1p1+lpk/openssh-lpk_sun.schema
1239 --- openssh-5.1p1.orig/openssh-lpk_sun.schema 1969-12-31 16:00:00.000000000 -0800
1240 +++ openssh-5.1p1+lpk/openssh-lpk_sun.schema 2008-08-23 15:02:47.000000000 -0700
1243 +# LDAP Public Key Patch schema for use with openssh-ldappubkey
1244 +# Author: Eric AUGE <eau@phear.org>
1246 +# Schema for Sun Directory Server.
1247 +# Based on the original schema, modified by Stefan Fischer.
1252 +# octetString SYNTAX
1253 +attributeTypes: ( 1.3.6.1.4.1.24552.500.1.1.1.13 NAME 'sshPublicKey'
1254 + DESC 'MANDATORY: OpenSSH Public key'
1255 + EQUALITY octetStringMatch
1256 + SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )
1258 +# printableString SYNTAX yes|no
1259 +objectClasses: ( 1.3.6.1.4.1.24552.500.1.1.2.0 NAME 'ldapPublicKey' SUP top AUXILIARY
1260 + DESC 'MANDATORY: OpenSSH LPK objectclass'
1261 + MUST ( sshPublicKey $ uid )
1263 diff -Nuar --exclude '*.orig' --exclude '*.rej' openssh-5.1p1.orig/README.lpk openssh-5.1p1+lpk/README.lpk
1264 --- openssh-5.1p1.orig/README.lpk 1969-12-31 16:00:00.000000000 -0800
1265 +++ openssh-5.1p1+lpk/README.lpk 2008-08-23 15:02:47.000000000 -0700
1267 +OpenSSH LDAP PUBLIC KEY PATCH
1268 +Copyright (c) 2003 Eric AUGE (eau@phear.org)
1269 +All rights reserved.
1271 +Redistribution and use in source and binary forms, with or without
1272 +modification, are permitted provided that the following conditions
1274 +1. Redistributions of source code must retain the above copyright
1275 + notice, this list of conditions and the following disclaimer.
1276 +2. Redistributions in binary form must reproduce the above copyright
1277 + notice, this list of conditions and the following disclaimer in the
1278 + documentation and/or other materials provided with the distribution.
1279 +3. The name of the author may not be used to endorse or promote products
1280 + derived from this software without specific prior written permission.
1282 +THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1283 +IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1284 +OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1285 +IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
1286 +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
1287 +NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
1288 +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
1289 +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1290 +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
1291 +THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1293 +purposes of this patch:
1295 +This patch would help to have authentication centralization policy
1296 +using ssh public key authentication.
1297 +This patch could be an alternative to other "secure" authentication system
1298 +working in a similar way (Kerberos, SecurID, etc...), except the fact
1299 +that it's based on OpenSSH and its public key abilities.
1302 +'uid': means unix accounts existing on the current server
1303 +'lpkServerGroup:' mean server group configured on the current server ('lpkServerGroup' in sshd_config)
1308 + server1 (uid: eau,rival,toto) (lpkServerGroup: unix)
1310 + / \ --- - server3 (uid: eau, titi) (lpkServerGroup: unix)
1312 + | eau ,rival | server2 (uid: rival, eau) (lpkServerGroup: unix)
1314 + | userx,.... | server5 (uid: eau) (lpkServerGroup: mail)
1316 + ----- - server4 (uid: eau, rival) (no group configured)
1322 + * configured LDAP server somewhere on the network (i.e. OpenLDAP)
1323 + * patched sshd (with this patch ;)
1324 + * LDAP user(/group) entry (look at users.ldif (& groups.ldif)):
1326 + - attached to the 'ldapPublicKey' objectclass
1327 + - attached to the 'posixAccount' objectclass
1328 + - with a filled 'sshPublicKey' attribute
1330 + dn: uid=eau,ou=users,dc=cuckoos,dc=net
1332 + objectclass: person
1333 + objectclass: organizationalPerson
1334 + objectclass: posixAccount
1335 + objectclass: ldapPublicKey
1336 + description: Eric AUGE Account
1337 + userPassword: blah
1343 + homeDirectory: /export/home/eau
1344 + sshPublicKey: ssh-dss AAAAB3...
1345 + sshPublicKey: ssh-dss AAAAM5...
1348 + - attached to the 'posixGroup' objectclass
1349 + - with a 'cn' groupname attribute
1350 + - with multiple 'memberUid' attributes filled with usernames allowed in this group
1353 + dn: cn=unix,ou=groups,dc=cuckoos,dc=net
1355 + objectclass: posixGroup
1356 + description: Unix based servers group
1367 + If a user wants to authenticate to log in a server the sshd, will first look for authentication method allowed (RSAauth,kerberos,etc..)
1368 + and if RSAauth and tickets based auth fails, it will fallback to standard password authentication (if enabled).
1371 + 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.
1372 + It will do an ldapsearch to get the public key directly from the LDAP instead of reading it from the server filesystem.
1373 + (usually in $HOME/.ssh/authorized_keys)
1375 + 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.
1376 + If it fails, it falls back on RSA auth files ($HOME/.ssh/authorized_keys), etc.. and finally to standard password authentication (if enabled).
1378 + 7 tokens are added to sshd_config :
1379 + # here is the new patched ldap related tokens
1380 + # entries in your LDAP must be posixAccount & strongAuthenticationUser & posixGroup
1381 + UseLPK yes # look the pub key into LDAP
1382 + LpkServers ldap://10.31.32.5/ ldap://10.31.32.4 ldap://10.31.32.3 # which LDAP server for users ? (URL format)
1383 + LpkUserDN ou=users,dc=foobar,dc=net # which base DN for users ?
1384 + LpkGroupDN ou=groups,dc=foobar,dc=net # which base DN for groups ?
1385 + LpkBindDN cn=manager,dc=foobar,dc=net # which bind DN ?
1386 + LpkBindPw asecret # bind DN credidentials
1387 + LpkServerGroup agroupname # the group the server is part of
1389 + 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
1390 + flaws you have to take care of.
1392 +- HOW TO INSERT A USER/KEY INTO AN LDAP ENTRY
1394 + * my way (there is plenty :)
1395 + - create ldif file (i.e. users.ldif)
1396 + - cat ~/.ssh/id_dsa.pub OR cat ~/.ssh/id_rsa.pub OR cat ~/.ssh/identity.pub
1397 + - my way in 4 steps :
1400 + # you add this to the user entry in the LDIF file :
1402 + objectclass: posixAccount
1403 + objectclass: ldapPublicKey
1405 + sshPubliKey: ssh-dss AAAABDh12DDUR2...
1408 + # insert your entry and you're done :)
1409 + ldapadd -D balblabla -w bleh < file.ldif
1411 + all standard options can be present in the 'sshPublicKey' attribute.
1415 + Simply because, i was looking for a way to centralize all sysadmins authentication, easily, without completely using LDAP
1416 + as authentication method (like pam_ldap etc..).
1418 + After looking into Kerberos, SecurID, and other centralized secure authentications systems, the use of RSA and LDAP to get
1419 + public key for authentication allows us to control who has access to which server (the user needs an account and to be in 'strongAuthenticationUser'
1420 + objectclass within LDAP and part of the group the SSH server is in).
1422 + 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
1423 + so each user can change it as much as he wants).
1425 + Blocking a user account can be done directly from the LDAP (if sshd is using RSAAuth + ldap only).
1428 + Entry in the LDAP server must respect 'posixAccount' and 'ldapPublicKey' which are defined in core.schema.
1429 + and the additionnal lpk.schema.
1431 + This patch could allow a smooth transition between standard auth (/etc/passwd) and complete LDAP based authentication
1432 + (pamldap, nss_ldap, etc..).
1434 + This can be an alternative to other (old?/expensive?) authentication methods (Kerberos/SecurID/..).
1436 + Referring to schema at the beginning of this file if user 'eau' is only in group 'unix'
1437 + 'eau' would ONLY access 'server1', 'server2', 'server3' AND 'server4' BUT NOT 'server5'.
1438 + If you then modify the LDAP 'mail' group entry to add 'memberUid: eau' THEN user 'eau' would be able
1439 + to log in 'server5' (i hope you got the idea, my english is bad :).
1441 + Each server's sshd is patched and configured to ask the public key and the group infos in the LDAP
1443 + When you want to allow a new user to have access to the server parc, you just add him an account on
1444 + your servers, you add his public key into his entry on the LDAP server, it's done.
1446 + Because sshds are looking public keys into the LDAP directly instead of a file ($HOME/.ssh/authorized_keys).
1448 + When the user needs to change his passphrase he can do it directly from his workstation by changing
1449 + his own key set lock passphrase, and all servers are automatically aware.
1451 + With a CAREFUL LDAP server configuration you could allow a user to add/delete/modify his own entry himself
1452 + so he can add/modify/delete himself his public key when needed.
1455 + LDAP must be well configured, getting the public key of some user is not a problem, but if anonymous LDAP
1456 + allow write to users dn, somebody could replace someuser's public key by its own and impersonate some
1457 + of your users in all your server farm be VERY CAREFUL.
1459 + MITM attack when sshd is requesting the public key, could lead to a compromise of your servers allowing login
1460 + as the impersonnated user.
1462 + If LDAP server is down then, fallback on passwd auth.
1464 + the ldap code part has not been well audited yet.
1466 +- LDAP USER ENTRY EXAMPLES (LDIF Format, look in users.ldif)
1468 + dn: uid=jdoe,ou=users,dc=foobar,dc=net
1470 + objectclass: person
1471 + objectclass: organizationalPerson
1472 + objectclass: posixAccount
1473 + objectclass: ldapPublicKey
1474 + description: My account
1480 + homeDirectory: /home/jdoe
1481 + sshPublicKey: ssh-dss AAAAB3NzaC1kc3MAAAEBAOvL8pREUg9wSy/8+hQJ54YF3AXkB0OZrXB....
1485 +- LDAP GROUP ENTRY EXAMPLES (LDIF Format, look in groups.ldif)
1487 + dn: cn=unix,ou=groups,dc=cuckoos,dc=net
1489 + objectclass: posixGroup
1490 + description: Unix based servers group
1500 +Multiple 'sshPublicKey' in a user entry are allowed, as well as multiple 'memberUid' attributes in a group entry
1503 + 1. Apply the patch
1504 + 2. ./configure --with-your-options --with-ldap=/prefix/to/ldap_libs_and_includes
1509 + I hope this could help, and i hope to be clear enough,, or give ideas. questions/comments/improvements are welcome.
1512 + Redesign differently.
1515 + http://pacsec.jp/core05/psj05-barisani-en.pdf
1516 + http://fritz.potsdam.edu/projects/openssh-lpk/
1517 + http://fritz.potsdam.edu/projects/sshgate/
1518 + http://dev.inversepath.com/trac/openssh-lpk
1519 + http://lam.sf.net/ ( http://lam.sourceforge.net/documentation/supportedSchemas.htm )
1521 +- CONTRIBUTORS/IDEAS/GREETS :
1522 + - Falk Siemonsmeier.
1524 + - Michael Durchgraf.
1525 + - frederic peters.
1528 + - Robin H. Johnson.
1529 + - Adrian Bridgett.
1532 + - Eric AUGE <eau@phear.org>
1533 + - Andrea Barisani <andrea@inversepath.com>
1534 --- openssh-5.7p1/servconf.c.orig 2010-11-20 06:19:38.000000000 +0200
1535 +++ openssh-5.7p1/servconf.c 2011-01-24 16:38:27.381393458 +0200
1537 #include "channels.h"
1538 #include "groupaccess.h"
1540 +#ifdef WITH_LDAP_PUBKEY
1541 +#include "ldapauth.h"
1544 static void add_listen_addr(ServerOptions *, char *, int);
1545 static void add_one_listen_addr(ServerOptions *, char *, int);
1547 @@ -139,6 +143,24 @@
1548 options->authorized_principals_file = NULL;
1549 options->ip_qos_interactive = -1;
1550 options->ip_qos_bulk = -1;
1551 +#ifdef WITH_LDAP_PUBKEY
1553 + options->lpk.ld = NULL;
1554 + options->lpk.on = -1;
1555 + options->lpk.servers = NULL;
1556 + options->lpk.u_basedn = NULL;
1557 + options->lpk.g_basedn = NULL;
1558 + options->lpk.binddn = NULL;
1559 + options->lpk.bindpw = NULL;
1560 + options->lpk.sgroup = NULL;
1561 + options->lpk.filter = NULL;
1562 + options->lpk.fgroup = NULL;
1563 + options->lpk.l_conf = NULL;
1564 + options->lpk.tls = -1;
1565 + options->lpk.b_timeout.tv_sec = -1;
1566 + options->lpk.s_timeout.tv_sec = -1;
1567 + options->lpk.flags = FLAG_EMPTY;
1572 @@ -281,6 +303,32 @@
1573 options->ip_qos_interactive = IPTOS_LOWDELAY;
1574 if (options->ip_qos_bulk == -1)
1575 options->ip_qos_bulk = IPTOS_THROUGHPUT;
1576 +#ifdef WITH_LDAP_PUBKEY
1577 + if (options->lpk.on == -1)
1578 + options->lpk.on = _DEFAULT_LPK_ON;
1579 + if (options->lpk.servers == NULL)
1580 + options->lpk.servers = _DEFAULT_LPK_SERVERS;
1581 + if (options->lpk.u_basedn == NULL)
1582 + options->lpk.u_basedn = _DEFAULT_LPK_UDN;
1583 + if (options->lpk.g_basedn == NULL)
1584 + options->lpk.g_basedn = _DEFAULT_LPK_GDN;
1585 + if (options->lpk.binddn == NULL)
1586 + options->lpk.binddn = _DEFAULT_LPK_BINDDN;
1587 + if (options->lpk.bindpw == NULL)
1588 + options->lpk.bindpw = _DEFAULT_LPK_BINDPW;
1589 + if (options->lpk.sgroup == NULL)
1590 + options->lpk.sgroup = _DEFAULT_LPK_SGROUP;
1591 + if (options->lpk.filter == NULL)
1592 + options->lpk.filter = _DEFAULT_LPK_FILTER;
1593 + if (options->lpk.tls == -1)
1594 + options->lpk.tls = _DEFAULT_LPK_TLS;
1595 + if (options->lpk.b_timeout.tv_sec == -1)
1596 + options->lpk.b_timeout.tv_sec = _DEFAULT_LPK_BTIMEOUT;
1597 + if (options->lpk.s_timeout.tv_sec == -1)
1598 + options->lpk.s_timeout.tv_sec = _DEFAULT_LPK_STIMEOUT;
1599 + if (options->lpk.l_conf == NULL)
1600 + options->lpk.l_conf = _DEFAULT_LPK_LDP;
1603 /* Turn privilege separation on by default */
1604 if (use_privsep == -1)
1605 @@ -329,6 +377,12 @@
1606 sRevokedKeys, sTrustedUserCAKeys, sAuthorizedPrincipalsFile,
1607 sKexAlgorithms, sIPQoS,
1608 sDeprecated, sUnsupported
1609 +#ifdef WITH_LDAP_PUBKEY
1610 + ,sLdapPublickey, sLdapServers, sLdapUserDN
1611 + ,sLdapGroupDN, sBindDN, sBindPw, sMyGroup
1612 + ,sLdapFilter, sForceTLS, sBindTimeout
1613 + ,sSearchTimeout, sLdapConf
1617 #define SSHCFG_GLOBAL 0x01 /* allowed in main section of sshd_config */
1618 @@ -439,6 +493,20 @@
1619 { "clientalivecountmax", sClientAliveCountMax, SSHCFG_GLOBAL },
1620 { "authorizedkeysfile", sAuthorizedKeysFile, SSHCFG_ALL },
1621 { "authorizedkeysfile2", sAuthorizedKeysFile2, SSHCFG_ALL },
1622 +#ifdef WITH_LDAP_PUBKEY
1623 + { _DEFAULT_LPK_TOKEN, sLdapPublickey, SSHCFG_GLOBAL },
1624 + { _DEFAULT_SRV_TOKEN, sLdapServers, SSHCFG_GLOBAL },
1625 + { _DEFAULT_USR_TOKEN, sLdapUserDN, SSHCFG_GLOBAL },
1626 + { _DEFAULT_GRP_TOKEN, sLdapGroupDN, SSHCFG_GLOBAL },
1627 + { _DEFAULT_BDN_TOKEN, sBindDN, SSHCFG_GLOBAL },
1628 + { _DEFAULT_BPW_TOKEN, sBindPw, SSHCFG_GLOBAL },
1629 + { _DEFAULT_MYG_TOKEN, sMyGroup, SSHCFG_GLOBAL },
1630 + { _DEFAULT_FIL_TOKEN, sLdapFilter, SSHCFG_GLOBAL },
1631 + { _DEFAULT_TLS_TOKEN, sForceTLS, SSHCFG_GLOBAL },
1632 + { _DEFAULT_BTI_TOKEN, sBindTimeout, SSHCFG_GLOBAL },
1633 + { _DEFAULT_STI_TOKEN, sSearchTimeout, SSHCFG_GLOBAL },
1634 + { _DEFAULT_LDP_TOKEN, sLdapConf, SSHCFG_GLOBAL },
1636 { "useprivilegeseparation", sUsePrivilegeSeparation, SSHCFG_GLOBAL},
1637 { "acceptenv", sAcceptEnv, SSHCFG_GLOBAL },
1638 { "permittunnel", sPermitTunnel, SSHCFG_ALL },
1639 @@ -1411,6 +1479,107 @@
1641 arg = strdelim(&cp);
1643 +#ifdef WITH_LDAP_PUBKEY
1644 + case sLdapPublickey:
1645 + intptr = &options->lpk.on;
1647 + case sLdapServers:
1648 + /* arg = strdelim(&cp); */
1652 + if (!arg || *arg == '\0')
1653 + fatal("%s line %d: missing ldap server",filename,linenum);
1654 + arg[strlen(arg)] = '\0';
1655 + if ((options->lpk.servers = ldap_parse_servers(arg)) == NULL)
1656 + fatal("%s line %d: error in ldap servers", filename, linenum);
1657 + memset(arg,0,strlen(arg));
1661 + if (!arg || *arg == '\0')
1662 + fatal("%s line %d: missing ldap server",filename,linenum);
1663 + arg[strlen(arg)] = '\0';
1664 + options->lpk.u_basedn = xstrdup(arg);
1665 + memset(arg,0,strlen(arg));
1667 + case sLdapGroupDN:
1669 + if (!arg || *arg == '\0')
1670 + fatal("%s line %d: missing ldap server",filename,linenum);
1671 + arg[strlen(arg)] = '\0';
1672 + options->lpk.g_basedn = xstrdup(arg);
1673 + memset(arg,0,strlen(arg));
1677 + if (!arg || *arg == '\0')
1678 + fatal("%s line %d: missing binddn",filename,linenum);
1679 + arg[strlen(arg)] = '\0';
1680 + options->lpk.binddn = xstrdup(arg);
1681 + memset(arg,0,strlen(arg));
1685 + if (!arg || *arg == '\0')
1686 + fatal("%s line %d: missing bindpw",filename,linenum);
1687 + arg[strlen(arg)] = '\0';
1688 + options->lpk.bindpw = xstrdup(arg);
1689 + memset(arg,0,strlen(arg));
1693 + if (!arg || *arg == '\0')
1694 + fatal("%s line %d: missing groupname",filename, linenum);
1695 + arg[strlen(arg)] = '\0';
1696 + options->lpk.sgroup = xstrdup(arg);
1697 + if (options->lpk.sgroup)
1698 + options->lpk.fgroup = ldap_parse_groups(options->lpk.sgroup);
1699 + memset(arg,0,strlen(arg));
1703 + if (!arg || *arg == '\0')
1704 + fatal("%s line %d: missing filter",filename, linenum);
1705 + arg[strlen(arg)] = '\0';
1706 + options->lpk.filter = xstrdup(arg);
1707 + memset(arg,0,strlen(arg));
1710 + intptr = &options->lpk.tls;
1711 + arg = strdelim(&cp);
1712 + if (!arg || *arg == '\0')
1713 + fatal("%s line %d: missing yes/no argument.",
1714 + filename, linenum);
1715 + value = 0; /* silence compiler */
1716 + if (strcmp(arg, "yes") == 0)
1718 + else if (strcmp(arg, "no") == 0)
1720 + else if (strcmp(arg, "try") == 0)
1723 + fatal("%s line %d: Bad yes/no argument: %s",
1724 + filename, linenum, arg);
1725 + if (*intptr == -1)
1728 + case sBindTimeout:
1729 + intptr = (int *) &options->lpk.b_timeout.tv_sec;
1731 + case sSearchTimeout:
1732 + intptr = (int *) &options->lpk.s_timeout.tv_sec;
1737 + if (!arg || *arg == '\0')
1738 + fatal("%s line %d: missing LpkLdapConf", filename, linenum);
1739 + arg[strlen(arg)] = '\0';
1740 + options->lpk.l_conf = xstrdup(arg);
1741 + memset(arg, 0, strlen(arg));
1746 fatal("%s line %d: Missing handler for opcode %s (%d)",
1747 diff -Nuar --exclude '*.orig' --exclude '*.rej' openssh-5.1p1.orig/servconf.h openssh-5.1p1+lpk/servconf.h
1748 --- openssh-5.1p1.orig/servconf.h 2008-06-10 06:01:51.000000000 -0700
1749 +++ openssh-5.1p1+lpk/servconf.h 2008-08-23 15:02:47.000000000 -0700
1754 +#ifdef WITH_LDAP_PUBKEY
1755 +#include "ldapauth.h"
1758 #define MAX_PORTS 256 /* Max # ports. */
1760 #define MAX_ALLOW_USERS 256 /* Max # users on allow list. */
1762 int use_pam; /* Enable auth via PAM */
1765 +#ifdef WITH_LDAP_PUBKEY
1769 int num_permitted_opens;
1771 diff -Nuar --exclude '*.orig' --exclude '*.rej' openssh-5.1p1.orig/sshd.c openssh-5.1p1+lpk/sshd.c
1772 --- openssh-5.1p1.orig/sshd.c 2008-07-11 00:36:49.000000000 -0700
1773 +++ openssh-5.1p1+lpk/sshd.c 2008-08-23 15:02:47.000000000 -0700
1774 @@ -127,6 +127,10 @@
1776 #endif /* LIBWRAP */
1778 +#ifdef WITH_LDAP_PUBKEY
1779 +#include "ldapauth.h"
1785 @@ -1484,6 +1488,16 @@
1789 +#ifdef WITH_LDAP_PUBKEY
1790 + /* ldap_options_print(&options.lpk); */
1791 + /* XXX initialize/check ldap connection and set *LD */
1792 + if (options.lpk.on) {
1793 + if (options.lpk.l_conf && (ldap_parse_lconf(&options.lpk) < 0) )
1794 + error("[LDAP] could not parse %s", options.lpk.l_conf);
1795 + if (ldap_connect(&options.lpk) < 0)
1796 + error("[LDAP] could not initialize ldap connection");
1799 debug("sshd version %.100s", SSH_RELEASE);
1801 /* Store privilege separation user for later use if required. */
1802 diff -Nuar --exclude '*.orig' --exclude '*.rej' openssh-5.1p1.orig/sshd_config openssh-5.1p1+lpk/sshd_config
1803 --- openssh-5.1p1.orig/sshd_config 2008-07-02 05:35:43.000000000 -0700
1804 +++ openssh-5.1p1+lpk/sshd_config 2008-08-23 15:02:47.000000000 -0700
1805 @@ -109,6 +109,21 @@
1806 # no default banner path
1809 +# here are the new patched ldap related tokens
1810 +# entries in your LDAP must have posixAccount & ldapPublicKey objectclass
1812 +#LpkLdapConf /etc/ldap.conf
1813 +#LpkServers ldap://10.1.7.1/ ldap://10.1.7.2/
1814 +#LpkUserDN ou=users,dc=phear,dc=org
1815 +#LpkGroupDN ou=groups,dc=phear,dc=org
1816 +#LpkBindDN cn=Manager,dc=phear,dc=org
1818 +#LpkServerGroup mail
1819 +#LpkFilter (hostAccess=master.phear.org)
1821 +#LpkSearchTimelimit 3
1822 +#LpkBindTimelimit 3
1824 # override default of no subsystems
1825 Subsystem sftp /usr/libexec/sftp-server
1827 diff -Nuar --exclude '*.orig' --exclude '*.rej' openssh-5.1p1.orig/sshd_config.5 openssh-5.1p1+lpk/sshd_config.5
1828 --- openssh-5.1p1.orig/sshd_config.5 2008-07-02 05:35:43.000000000 -0700
1829 +++ openssh-5.1p1+lpk/sshd_config.5 2008-08-23 15:02:47.000000000 -0700
1830 @@ -1003,6 +1003,62 @@
1833 .Pa /usr/X11R6/bin/xauth .
1835 +Specifies whether LDAP public key retrieval must be used or not. It allow
1836 +an easy centralisation of public keys within an LDAP directory. The argument must be
1841 +Specifies whether LDAP Public keys should parse the specified ldap.conf file
1842 +instead of sshd_config Tokens. The argument must be a valid path to an ldap.conf
1846 +Specifies LDAP one or more [:space:] separated server's url the following form may be used:
1848 +LpkServers ldaps://127.0.0.1 ldap://127.0.0.2 ldap://127.0.0.3
1850 +Specifies the LDAP user DN.
1852 +LpkUserDN ou=users,dc=phear,dc=org
1854 +Specifies the LDAP groups DN.
1856 +LpkGroupDN ou=groups,dc=phear,dc=org
1858 +Specifies the LDAP bind DN to use if necessary.
1860 +LpkBindDN cn=Manager,dc=phear,dc=org
1862 +Specifies the LDAP bind credential.
1865 +.It Cm LpkServerGroup
1866 +Specifies one or more [:space:] separated group the server is part of.
1868 +LpkServerGroup unix mail prod
1870 +Specifies an additional LDAP filter to use for finding SSH keys
1872 +LpkFilter (hostAccess=master.phear.org)
1874 +Specifies if the LDAP server connection must be tried, forced or not used. The argument must be
1880 +.It Cm LpkSearchTimelimit
1881 +Sepcifies the search time limit before the search is considered over. value is
1884 +LpkSearchTimelimit 3
1885 +.It Cm LpkBindTimelimit
1886 +Sepcifies the bind time limit before the connection is considered dead. value is