]> git.pld-linux.org Git - packages/openssh.git/blob - openssh-lpk-4.3p1-0.3.7.patch
b856937f1cdfca7a3ccfb2fac36ef726 connect.c
[packages/openssh.git] / openssh-lpk-4.3p1-0.3.7.patch
1 diff -Nru -x Makefile -x 'buildpkg.*' -x opensshd.init -x 'ssh_prng_*' openssh-4.3p1/Makefile.in openssh-4.3p1-lpk/Makefile.in
2 --- openssh-4.3p1/Makefile.in   2006-01-01 09:47:05.000000000 +0100
3 +++ openssh-4.3p1-lpk/Makefile.in       2006-04-18 15:46:59.000000000 +0200
4 @@ -86,7 +86,7 @@
5         auth-krb5.o \
6         auth2-gss.o gss-serv.o gss-serv-krb5.o \
7         loginrec.o auth-pam.o auth-shadow.o auth-sia.o md5crypt.o \
8 -       audit.o audit-bsm.o
9 +       audit.o audit-bsm.o ldapauth.o
10  
11  MANPAGES       = scp.1.out ssh-add.1.out ssh-agent.1.out ssh-keygen.1.out ssh-keyscan.1.out ssh.1.out sshd.8.out sftp-server.8.out sftp.1.out ssh-rand-helper.8.out ssh-keysign.8.out sshd_config.5.out ssh_config.5.out
12  MANPAGES_IN    = scp.1 ssh-add.1 ssh-agent.1 ssh-keygen.1 ssh-keyscan.1 ssh.1 sshd.8 sftp-server.8 sftp.1 ssh-rand-helper.8 ssh-keysign.8 sshd_config.5 ssh_config.5
13 diff -Nru -x Makefile -x 'buildpkg.*' -x opensshd.init -x 'ssh_prng_*' openssh-4.3p1/README.lpk openssh-4.3p1-lpk/README.lpk
14 --- openssh-4.3p1/README.lpk    1970-01-01 01:00:00.000000000 +0100
15 +++ openssh-4.3p1-lpk/README.lpk        2006-04-18 15:46:59.000000000 +0200
16 @@ -0,0 +1,265 @@
17 +OpenSSH LDAP PUBLIC KEY PATCH 
18 +Copyright (c) 2003 Eric AUGE (eau@phear.org)
19 +All rights reserved.
20 +
21 +Redistribution and use in source and binary forms, with or without
22 +modification, are permitted provided that the following conditions
23 +are met:
24 +1. Redistributions of source code must retain the above copyright
25 +   notice, this list of conditions and the following disclaimer.
26 +2. Redistributions in binary form must reproduce the above copyright
27 +   notice, this list of conditions and the following disclaimer in the
28 +   documentation and/or other materials provided with the distribution.
29 +3. The name of the author may not be used to endorse or promote products
30 +   derived from this software without specific prior written permission.
31 +
32 +THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
33 +IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
34 +OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
35 +IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
36 +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
37 +NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
38 +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
39 +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
40 +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
41 +THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42 +
43 +purposes of this patch:
44 +
45 +This patch would help to have authentication centralization policy
46 +using ssh public key authentication.
47 +This patch could be an alternative to other "secure" authentication system
48 +working in a similar way (Kerberos, SecurID, etc...), except the fact 
49 +that it's based on OpenSSH and its public key abilities.
50 +
51 +>> FYI: <<
52 +'uid': means unix accounts existing on the current server
53 +'lpkServerGroup:' mean server group configured on the current server ('lpkServerGroup' in sshd_config)
54 +
55 +example schema:
56 +
57 +
58 +                                  server1 (uid: eau,rival,toto) (lpkServerGroup: unix)
59 +                ___________      /
60 +               /           \ --- - server3 (uid: eau, titi) (lpkServerGroup: unix)
61 +              | LDAP Server |    \
62 +             | eau  ,rival |     server2 (uid: rival, eau) (lpkServerGroup: unix)
63 +             | titi ,toto  |
64 +             | userx,....  |         server5 (uid: eau)  (lpkServerGroup: mail)
65 +               \___________/ \       /
66 +                              ----- - server4 (uid: eau, rival)  (no group configured)
67 +                                    \
68 +                                       etc...
69 +
70 +- WHAT WE NEED :
71 +
72 +  * configured LDAP server somewhere on the network (i.e. OpenLDAP)
73 +  * patched sshd (with this patch ;)
74 +  * LDAP user(/group) entry (look at users.ldif (& groups.ldif)):
75 +        User entry:
76 +       - attached to the 'ldapPublicKey' objectclass
77 +       - attached to the 'posixAccount' objectclass
78 +       - with a filled 'sshPublicKey' attribute 
79 +       Example:
80 +               dn: uid=eau,ou=users,dc=cuckoos,dc=net
81 +               objectclass: top
82 +               objectclass: person
83 +               objectclass: organizationalPerson
84 +               objectclass: posixAccount
85 +               objectclass: ldapPublicKey
86 +               description: Eric AUGE Account
87 +               userPassword: blah
88 +               cn: Eric AUGE
89 +               sn: Eric AUGE
90 +               uid: eau
91 +               uidNumber: 1034
92 +               gidNumber: 1
93 +               homeDirectory: /export/home/eau
94 +               sshPublicKey: ssh-dss AAAAB3...
95 +               sshPublicKey: ssh-dss AAAAM5...
96 +
97 +       Group entry:
98 +       - attached to the 'posixGroup' objectclass
99 +       - with a 'cn' groupname attribute
100 +       - with multiple 'memberUid' attributes filled with usernames allowed in this group
101 +       Example:
102 +               # few members
103 +               dn: cn=unix,ou=groups,dc=cuckoos,dc=net
104 +               objectclass: top
105 +               objectclass: posixGroup
106 +               description: Unix based servers group
107 +               cn: unix
108 +               gidNumber: 1002
109 +               memberUid: eau
110 +               memberUid: user1
111 +               memberUid: user2
112 +
113 +
114 +- HOW IT WORKS :
115 +
116 +  * without patch
117 +  If a user wants to authenticate to log in a server the sshd, will first look for authentication method allowed (RSAauth,kerberos,etc..)
118 +  and if RSAauth and tickets based auth fails, it will fallback to standard password authentication (if enabled).
119 +
120 +  * with the patch
121 +  If a user want to authenticate to log in a server, the sshd will first look for auth method including LDAP pubkey, if the ldappubkey options is enabled.
122 +  It will do an ldapsearch to get the public key directly from the LDAP instead of reading it from the server filesystem. 
123 +  (usually in $HOME/.ssh/authorized_keys)
124 +
125 +  If groups are enabled, it will also check if the user that wants to login is in the group of the server he is trying to log into.
126 +  If it fails, it falls back on RSA auth files ($HOME/.ssh/authorized_keys), etc.. and finally to standard password authentication (if enabled).
127 +
128 +  7 tokens are added to sshd_config :
129 +  # here is the new patched ldap related tokens
130 +  # entries in your LDAP must be posixAccount & strongAuthenticationUser & posixGroup
131 +  UseLPK yes                                                           # look the pub key into LDAP
132 +  LpkServers ldap://10.31.32.5/ ldap://10.31.32.4 ldap://10.31.32.3    # which LDAP server for users ? (URL format)
133 +  LpkUserDN  ou=users,dc=foobar,dc=net                                 # which base DN for users ?
134 +  LpkGroupDN ou=groups,dc=foobar,dc=net                                        # which base DN for groups ? 
135 +  LpkBindDN cn=manager,dc=foobar,dc=net                                        # which bind DN ?
136 +  LpkBindPw asecret                                                    # bind DN credidentials
137 +  LpkServerGroup agroupname                                            # the group the server is part of
138 +
139 +  Right now i'm using anonymous binding to get public keys, because getting public keys of someone doesn't impersonate him¸ but there is some
140 +  flaws you have to take care of.
141 +
142 +- HOW TO INSERT A USER/KEY INTO AN LDAP ENTRY
143 +
144 +  * my way (there is plenty :)
145 +  - create ldif file (i.e. users.ldif)
146 +  - cat ~/.ssh/id_dsa.pub OR cat ~/.ssh/id_rsa.pub OR cat ~/.ssh/identity.pub
147 +  - my way in 4 steps :
148 +  Example:
149 +
150 +  # you add this to the user entry in the LDIF file :
151 +  [...]
152 +  objectclass: posixAccount
153 +  objectclass: ldapPublicKey
154 +  [...]
155 +  sshPubliKey: ssh-dss AAAABDh12DDUR2...
156 +  [...]
157 +
158 +  # insert your entry and you're done :)
159 +  ldapadd -D balblabla -w bleh < file.ldif 
160 +  
161 +  all standard options can be present in the 'sshPublicKey' attribute.
162 +
163 +- WHY :
164 +
165 +  Simply because, i was looking for a way to centralize all sysadmins authentication, easily,  without completely using LDAP 
166 +  as authentication method (like pam_ldap etc..).  
167 +  
168 +  After looking into Kerberos, SecurID, and other centralized secure authentications systems, the use of RSA and LDAP to get 
169 +  public key for authentication allows us to control who has access to which server (the user needs an account and to be in 'strongAuthenticationUser'
170 +  objectclass within LDAP and part of the group the SSH server is in). 
171 +
172 +  Passwords update are no longer a nightmare for a server farm (key pair passphrase is stored on each user's box and private key is locally encrypted using his passphrase 
173 +  so each user can change it as much as he wants). 
174 +
175 +  Blocking a user account can be done directly from the LDAP (if sshd is using RSAAuth + ldap only).
176 +
177 +- RULES :  
178 +  Entry in the LDAP server must respect 'posixAccount' and 'ldapPublicKey' which are defined in core.schema. 
179 +  and the additionnal lpk.schema.
180 +
181 +  This patch could allow a smooth transition between standard auth (/etc/passwd) and complete LDAP based authentication 
182 +  (pamldap, nss_ldap, etc..).
183 +
184 +  This can be an alternative to other (old?/expensive?) authentication methods (Kerberos/SecurID/..).
185 +  
186 +  Referring to schema at the beginning of this file if user 'eau' is only in group 'unix'
187 +  'eau' would ONLY access 'server1', 'server2', 'server3' AND 'server4' BUT NOT 'server5'.
188 +  If you then modify the LDAP 'mail' group entry to add 'memberUid: eau' THEN user 'eau' would be able
189 +  to log in 'server5' (i hope you got the idea, my english is bad :).
190 +
191 +  Each server's sshd is patched and configured to ask the public key and the group infos in the LDAP
192 +  server.
193 +  When you want to allow a new user to have access to the server parc, you just add him an account on 
194 +  your servers, you add his public key into his entry on the LDAP server, it's done. 
195 +
196 +  Because sshds are looking public keys into the LDAP directly instead of a file ($HOME/.ssh/authorized_keys).
197 +
198 +  When the user needs to change his passphrase he can do it directly from his workstation by changing 
199 +  his own key set lock passphrase, and all servers are automatically aware.
200
201 +  With a CAREFUL LDAP server configuration you could allow a user to add/delete/modify his own entry himself
202 +  so he can add/modify/delete himself his public key when needed.
203 +
204 +­ FLAWS :
205 +  LDAP must be well configured, getting the public key of some user is not a problem, but if anonymous LDAP 
206 +  allow write to users dn, somebody could replace someuser's public key by its own and impersonate some 
207 +  of your users in all your server farm be VERY CAREFUL.
208 +  
209 +  MITM attack when sshd is requesting the public key, could lead to a compromise of your servers allowing login 
210 +  as the impersonnated user.
211 +
212 +  If LDAP server is down then, fallback on passwd auth.
213 +  
214 +  the ldap code part has not been well audited yet.
215 +
216 +- LDAP USER ENTRY EXAMPLES (LDIF Format, look in users.ldif)
217 +    --- CUT HERE ---
218 +    dn: uid=jdoe,ou=users,dc=foobar,dc=net
219 +    objectclass: top
220 +    objectclass: person
221 +    objectclass: organizationalPerson
222 +    objectclass: posixAccount
223 +    objectclass: ldapPublicKey
224 +    description: My account
225 +    cn: John Doe
226 +    sn: John Doe
227 +    uid: jdoe
228 +    uidNumber: 100
229 +    gidNumber: 100
230 +    homeDirectory: /home/jdoe
231 +    sshPublicKey: ssh-dss AAAAB3NzaC1kc3MAAAEBAOvL8pREUg9wSy/8+hQJ54YF3AXkB0OZrXB....
232 +    [...]
233 +    --- CUT HERE ---
234 +
235 +- LDAP GROUP ENTRY EXAMPLES (LDIF Format, look in groups.ldif)
236 +    --- CUT HERE ---
237 +    dn: cn=unix,ou=groups,dc=cuckoos,dc=net
238 +    objectclass: top
239 +    objectclass: posixGroup
240 +    description: Unix based servers group
241 +    cn: unix
242 +    gidNumber: 1002
243 +    memberUid: jdoe
244 +    memberUid: user1
245 +    memberUid: user2
246 +    [...]
247 +    --- CUT HERE ---
248 +
249 +>> FYI: << 
250 +Multiple 'sshPublicKey' in a user entry are allowed, as well as multiple 'memberUid' attributes in a group entry
251 +
252 +- COMPILING:
253 +  1. Apply the patch
254 +  2. ./configure --with-your-options --with-ldap=/prefix/to/ldap_libs_and_includes
255 +  3. make
256 +  4. it's done.
257 +
258 +- BLA :
259 +  I hope this could help, and i hope to be clear enough,, or give ideas.  questions/comments/improvements are welcome.
260 +  
261 +- TODO :
262 +  Redesign differently.
263 +
264 +- DOCS/LINK :
265 +  http://pacsec.jp/core05/psj05-barisani-en.pdf
266 +  http://fritz.potsdam.edu/projects/openssh-lpk/
267 +  http://fritz.potsdam.edu/projects/sshgate/
268 +  http://www.opendarwin.org/projects/openssh-lpk/files/examples/lpk-usrdoc.txt
269 +  http://lam.sf.net/ ( http://lam.sourceforge.net/documentation/supportedSchemas.htm )
270 +
271 +- CONTRIBUTORS/IDEAS/GREETS :
272 +  - Falk Siemonsmeier -> 3.7 patch port candidate
273 +  - Jacob Rief -> ideas (group && cleanups)
274 +  - Michael.Durchgraf@dregis.com -> Bugfixes thanks ;)
275 +  - frederic.peters@free.fr -> X509 keys LDAP patch (old)
276 +  - oink -> bugfixes
277 +  - finlay dobbie -> new fresh start with this guy :)
278 +
279 +- CONTACT :
280 +  - Eric AUGE <eau@phear.org>, <eau@opendarwin.org>
281 +  - Andrea Barisani <lcars@opendarwin.org>
282 diff -Nru -x Makefile -x 'buildpkg.*' -x opensshd.init -x 'ssh_prng_*' openssh-4.3p1/auth-rsa.c openssh-4.3p1-lpk/auth-rsa.c
283 --- openssh-4.3p1/auth-rsa.c    2005-06-17 04:59:35.000000000 +0200
284 +++ openssh-4.3p1-lpk/auth-rsa.c        2006-04-18 15:46:59.000000000 +0200
285 @@ -160,10 +160,96 @@
286         u_long linenum = 0;
287         struct stat st;
288         Key *key;
289 +#ifdef WITH_LDAP_PUBKEY
290 +       ldap_key_t * k;
291 +       unsigned int i = 0;
292 +#endif
293  
294         /* Temporarily use the user's uid. */
295         temporarily_use_uid(pw);
296  
297 +#ifdef WITH_LDAP_PUBKEY
298 +       /* here is the job */
299 +       key = key_new(KEY_RSA1);
300 +
301 +       if (options.lpk.on) {
302 +           debug("[LDAP] trying LDAP first uid=%s", pw->pw_name);
303 +           if ( ldap_ismember(&options.lpk, pw->pw_name) > 0) {
304 +               if ( (k = ldap_getuserkey(&options.lpk, pw->pw_name)) != NULL) {
305 +                   for (i = 0 ; i < k->num ; i++) {
306 +                       char *cp, *options = NULL;
307 +
308 +                       for (cp = k->keys[i]->bv_val; *cp == ' ' || *cp == '\t'; cp++)
309 +                           ;
310 +                       if (!*cp || *cp == '\n' || *cp == '#')
311 +                           continue;
312 +
313 +                       /*
314 +                       * Check if there are options for this key, and if so,
315 +                       * save their starting address and skip the option part
316 +                       * for now.  If there are no options, set the starting
317 +                       * address to NULL.
318 +                        */
319 +                       if (*cp < '0' || *cp > '9') {
320 +                           int quoted = 0;
321 +                           options = cp;
322 +                           for (; *cp && (quoted || (*cp != ' ' && *cp != '\t')); cp++) {
323 +                               if (*cp == '\\' && cp[1] == '"')
324 +                                   cp++;       /* Skip both */
325 +                               else if (*cp == '"')
326 +                                   quoted = !quoted;
327 +                           }
328 +                       } else
329 +                           options = NULL;
330 +
331 +                       /* Parse the key from the line. */
332 +                       if (hostfile_read_key(&cp, &bits, key) == 0) {
333 +                           debug("[LDAP] line %d: non ssh1 key syntax", i);
334 +                           continue;
335 +                       }
336 +                       /* cp now points to the comment part. */
337 +
338 +                       /* Check if the we have found the desired key (identified by its modulus). */
339 +                       if (BN_cmp(key->rsa->n, client_n) != 0)
340 +                           continue;
341 +
342 +                       /* check the real bits  */
343 +                       if (bits != (unsigned int)BN_num_bits(key->rsa->n))
344 +                           logit("[LDAP] Warning: ldap, line %lu: keysize mismatch: "
345 +                                   "actual %d vs. announced %d.", (unsigned long)i, BN_num_bits(key->rsa->n), bits);
346 +
347 +                       /* We have found the desired key. */
348 +                       /*
349 +                       * If our options do not allow this key to be used,
350 +                       * do not send challenge.
351 +                        */
352 +                       if (!auth_parse_options(pw, options, "[LDAP]", (unsigned long) i))
353 +                           continue;
354 +
355 +                       /* break out, this key is allowed */
356 +                       allowed = 1;
357 +
358 +                       /* add the return stuff etc... */
359 +                       /* Restore the privileged uid. */
360 +                       restore_uid();
361 +
362 +                       /* return key if allowed */
363 +                       if (allowed && rkey != NULL)
364 +                           *rkey = key;
365 +                       else
366 +                           key_free(key);
367 +
368 +                       ldap_keys_free(k);
369 +                       return (allowed);
370 +                   }
371 +               } else {
372 +                   logit("[LDAP] no keys found for '%s'!", pw->pw_name);
373 +               }
374 +           } else {
375 +               logit("[LDAP] '%s' is not in '%s'", pw->pw_name, options.lpk.sgroup);
376 +           }
377 +       }
378 +#endif
379         /* The authorized keys. */
380         file = authorized_keys_file(pw);
381         debug("trying public RSA key file %s", file);
382 diff -Nru -x Makefile -x 'buildpkg.*' -x opensshd.init -x 'ssh_prng_*' openssh-4.3p1/auth2-pubkey.c openssh-4.3p1-lpk/auth2-pubkey.c
383 --- openssh-4.3p1/auth2-pubkey.c        2004-12-11 03:39:50.000000000 +0100
384 +++ openssh-4.3p1-lpk/auth2-pubkey.c    2006-04-18 15:46:59.000000000 +0200
385 @@ -43,6 +43,10 @@
386  #include "monitor_wrap.h"
387  #include "misc.h"
388  
389 +#ifdef WITH_LDAP_PUBKEY
390 +#include "ldapauth.h"
391 +#endif
392 +
393  /* import */
394  extern ServerOptions options;
395  extern u_char *session_id2;
396 @@ -176,10 +180,79 @@
397         struct stat st;
398         Key *found;
399         char *fp;
400 +#ifdef WITH_LDAP_PUBKEY
401 +       ldap_key_t * k;
402 +       unsigned int i = 0;
403 +#endif
404  
405         /* Temporarily use the user's uid. */
406         temporarily_use_uid(pw);
407  
408 +#ifdef WITH_LDAP_PUBKEY
409 +       found_key = 0;
410 +       /* allocate a new key type */
411 +       found = key_new(key->type);
412
413 +       /* first check if the options is enabled, then try.. */
414 +       if (options.lpk.on) {
415 +           debug("[LDAP] trying LDAP first uid=%s",pw->pw_name);
416 +           if (ldap_ismember(&options.lpk, pw->pw_name) > 0) {
417 +               if ((k = ldap_getuserkey(&options.lpk, pw->pw_name)) != NULL) {
418 +                   /* Skip leading whitespace, empty and comment lines. */
419 +                   for (i = 0 ; i < k->num ; i++) {
420 +                       /* dont forget if multiple keys to reset options */
421 +                       char *cp, *options = NULL;
422 +
423 +                       for (cp = (char *)k->keys[i]->bv_val; *cp == ' ' || *cp == '\t'; cp++)
424 +                           ;
425 +                       if (!*cp || *cp == '\n' || *cp == '#')
426 +                           continue;
427 +
428 +                       if (key_read(found, &cp) != 1) {
429 +                           /* no key?  check if there are options for this key */
430 +                           int quoted = 0;
431 +                           debug2("[LDAP] user_key_allowed: check options: '%s'", cp);
432 +                           options = cp;
433 +                           for (; *cp && (quoted || (*cp != ' ' && *cp != '\t')); cp++) {
434 +                               if (*cp == '\\' && cp[1] == '"')
435 +                                   cp++;       /* Skip both */
436 +                               else if (*cp == '"')
437 +                                   quoted = !quoted;
438 +                           }
439 +                           /* Skip remaining whitespace. */
440 +                           for (; *cp == ' ' || *cp == '\t'; cp++)
441 +                               ;
442 +                           if (key_read(found, &cp) != 1) {
443 +                               debug2("[LDAP] user_key_allowed: advance: '%s'", cp);
444 +                               /* still no key?  advance to next line*/
445 +                               continue;
446 +                           }
447 +                       }
448 +
449 +                       if (key_equal(found, key) &&
450 +                               auth_parse_options(pw, options, file, linenum) == 1) {
451 +                           found_key = 1;
452 +                           debug("[LDAP] matching key found");
453 +                           fp = key_fingerprint(found, SSH_FP_MD5, SSH_FP_HEX);
454 +                           verbose("[LDAP] Found matching %s key: %s", key_type(found), fp);
455 +
456 +                           /* restoring memory */
457 +                           ldap_keys_free(k);
458 +                           xfree(fp);
459 +                           restore_uid();
460 +                           key_free(found);
461 +                           return found_key;
462 +                           break;
463 +                       }
464 +                   }/* end of LDAP for() */
465 +               } else {
466 +                   logit("[LDAP] no keys found for '%s'!", pw->pw_name);
467 +               }
468 +           } else {
469 +               logit("[LDAP] '%s' is not in '%s'", pw->pw_name, options.lpk.sgroup);
470 +           }
471 +       }
472 +#endif
473         debug("trying public key file %s", file);
474  
475         /* Fail quietly if file does not exist */
476 diff -Nru -x Makefile -x 'buildpkg.*' -x opensshd.init -x 'ssh_prng_*' openssh-4.3p1/config.h.in openssh-4.3p1-lpk/config.h.in
477 --- openssh-4.3p1/config.h.in   2006-02-01 12:33:49.000000000 +0100
478 +++ openssh-4.3p1-lpk/config.h.in       2006-04-18 15:46:59.000000000 +0200
479 @@ -476,6 +476,9 @@
480  /* Define to 1 if you have the <linux/if_tun.h> header file. */
481  #undef HAVE_LINUX_IF_TUN_H
482  
483 +/* Define if you want LDAP support */
484 +#undef WITH_LDAP_PUBKEY
485 +
486  /* Define if your libraries define login() */
487  #undef HAVE_LOGIN
488  
489 diff -Nru -x Makefile -x 'buildpkg.*' -x opensshd.init -x 'ssh_prng_*' openssh-4.3p1/configure openssh-4.3p1-lpk/configure
490 --- openssh-4.3p1/configure     2006-02-01 12:33:51.000000000 +0100
491 +++ openssh-4.3p1-lpk/configure 2006-04-18 15:46:59.000000000 +0200
492 @@ -876,6 +876,7 @@
493    --with-tcp-wrappers[=PATH] Enable tcpwrappers support (optionally in PATH)
494    --with-libedit[=PATH]   Enable libedit support for sftp
495    --with-audit=module     Enable EXPERIMENTAL audit support (modules=debug,bsm)
496 +  --with-ldap[=PATH]      Enable LDAP support (optionally in PATH)
497    --with-pam              Enable PAM support
498    --with-ssl-dir=PATH     Specify path to OpenSSL installation
499    --with-rand-helper      Use subprocess to gather strong randomness
500 @@ -11242,6 +11243,88 @@
501  
502  fi;
503  
504 +# Check whether user wants LDAP support
505 +LDAP_MSG="no"
506 +
507 +# Check whether --with-ldap or --without-ldap was given.
508 +if test "${with_ldap+set}" = set; then
509 +  withval="$with_ldap"
510 +
511 +               if test "x$withval" != "xno" ; then
512 +
513 +                       if test "x$withval" != "xyes" ; then
514 +                               CPPFLAGS="$CPPFLAGS -I${withval}/include"
515 +                               LDFLAGS="$LDFLAGS -L${withval}/lib"
516 +                       fi
517 +
518 +                       cat >>confdefs.h <<\_ACEOF
519 +#define WITH_LDAP_PUBKEY 1
520 +_ACEOF
521 +
522 +                       LIBS="-lldap $LIBS"
523 +                       LDAP_MSG="yes"
524 +
525 +                       echo "$as_me:$LINENO: checking for LDAP support" >&5
526 +echo $ECHO_N "checking for LDAP support... $ECHO_C" >&6
527 +                       cat >conftest.$ac_ext <<_ACEOF
528 +/* confdefs.h.  */
529 +_ACEOF
530 +cat confdefs.h >>conftest.$ac_ext
531 +cat >>conftest.$ac_ext <<_ACEOF
532 +/* end confdefs.h.  */
533 +#include <sys/types.h>
534 +                                #include <ldap.h>
535 +int
536 +main ()
537 +{
538 +(void)ldap_init(0, 0);
539 +  ;
540 +  return 0;
541 +}
542 +_ACEOF
543 +rm -f conftest.$ac_objext
544 +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
545 +  (eval $ac_compile) 2>conftest.er1
546 +  ac_status=$?
547 +  grep -v '^ *+' conftest.er1 >conftest.err
548 +  rm -f conftest.er1
549 +  cat conftest.err >&5
550 +  echo "$as_me:$LINENO: \$? = $ac_status" >&5
551 +  (exit $ac_status); } &&
552 +        { ac_try='test -z "$ac_c_werror_flag"
553 +                        || test ! -s conftest.err'
554 +  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
555 +  (eval $ac_try) 2>&5
556 +  ac_status=$?
557 +  echo "$as_me:$LINENO: \$? = $ac_status" >&5
558 +  (exit $ac_status); }; } &&
559 +        { ac_try='test -s conftest.$ac_objext'
560 +  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
561 +  (eval $ac_try) 2>&5
562 +  ac_status=$?
563 +  echo "$as_me:$LINENO: \$? = $ac_status" >&5
564 +  (exit $ac_status); }; }; then
565 +  echo "$as_me:$LINENO: result: yes" >&5
566 +echo "${ECHO_T}yes" >&6
567 +else
568 +  echo "$as_me: failed program was:" >&5
569 +sed 's/^/| /' conftest.$ac_ext >&5
570 +
571 +
572 +                                   echo "$as_me:$LINENO: result: no" >&5
573 +echo "${ECHO_T}no" >&6
574 +                                       { { echo "$as_me:$LINENO: error: ** Incomplete or missing ldap libraries **" >&5
575 +echo "$as_me: error: ** Incomplete or missing ldap libraries **" >&2;}
576 +   { (exit 1); exit 1; }; }
577 +
578 +
579 +fi
580 +rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
581 +               fi
582 +
583 +
584 +fi;
585 +
586  
587  
588  
589 @@ -28025,6 +28108,7 @@
590  echo "                 Smartcard support: $SCARD_MSG"
591  echo "                     S/KEY support: $SKEY_MSG"
592  echo "              TCP Wrappers support: $TCPW_MSG"
593 +echo "                      LDAP support: $LDAP_MSG"
594  echo "              MD5 password support: $MD5_MSG"
595  echo "                   libedit support: $LIBEDIT_MSG"
596  echo "       IP address in \$DISPLAY hack: $DISPLAY_HACK_MSG"
597 diff -Nru -x Makefile -x 'buildpkg.*' -x opensshd.init -x 'ssh_prng_*' openssh-4.3p1/configure.ac openssh-4.3p1-lpk/configure.ac
598 --- openssh-4.3p1/configure.ac  2006-01-29 14:22:39.000000000 +0100
599 +++ openssh-4.3p1-lpk/configure.ac      2006-04-18 15:46:59.000000000 +0200
600 @@ -1134,6 +1134,37 @@
601         esac ]
602  )
603  
604 +# Check whether user wants LDAP support
605 +LDAP_MSG="no"
606 +AC_ARG_WITH(ldap,
607 +       [  --with-ldap[[=PATH]]      Enable LDAP support (optionally in PATH)],
608 +       [
609 +               if test "x$withval" != "xno" ; then
610 +
611 +                       if test "x$withval" != "xyes" ; then
612 +                               CPPFLAGS="$CPPFLAGS -I${withval}/include"
613 +                               LDFLAGS="$LDFLAGS -L${withval}/lib"
614 +                       fi
615 +
616 +                       AC_DEFINE(WITH_LDAP_PUBKEY)
617 +                       LIBS="-lldap $LIBS"
618 +                       LDAP_MSG="yes"
619 +       
620 +                       AC_MSG_CHECKING([for LDAP support])
621 +                       AC_TRY_COMPILE(
622 +                               [#include <sys/types.h>
623 +                                #include <ldap.h>],
624 +                               [(void)ldap_init(0, 0);],
625 +                               [AC_MSG_RESULT(yes)],
626 +                               [
627 +                                   AC_MSG_RESULT(no) 
628 +                                       AC_MSG_ERROR([** Incomplete or missing ldap libraries **])
629 +                               ]
630 +               )
631 +               fi
632 +       ]
633 +)
634 +
635  dnl    Checks for library functions. Please keep in alphabetical order
636  AC_CHECK_FUNCS( \
637         arc4random \
638 @@ -3766,6 +3797,7 @@
639  echo "                 Smartcard support: $SCARD_MSG"
640  echo "                     S/KEY support: $SKEY_MSG"
641  echo "              TCP Wrappers support: $TCPW_MSG"
642 +echo "                      LDAP support: $LDAP_MSG"
643  echo "              MD5 password support: $MD5_MSG"
644  echo "                   libedit support: $LIBEDIT_MSG"
645  echo "       IP address in \$DISPLAY hack: $DISPLAY_HACK_MSG"
646 diff -Nru -x Makefile -x 'buildpkg.*' -x opensshd.init -x 'ssh_prng_*' openssh-4.3p1/ldapauth.c openssh-4.3p1-lpk/ldapauth.c
647 --- openssh-4.3p1/ldapauth.c    1970-01-01 01:00:00.000000000 +0100
648 +++ openssh-4.3p1-lpk/ldapauth.c        2006-04-18 15:46:59.000000000 +0200
649 @@ -0,0 +1,547 @@
650 +/* 
651 + * $Id$
652 + */
653 +
654 +/*
655 + *
656 + * Copyright (c) 2005, Eric AUGE <eau@phear.org>
657 + * All rights reserved.
658 + *
659 + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
660 + *
661 + * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
662 + * 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.
663 + * 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.
664 + *
665 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 
666 + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
667 + * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 
668 + * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
669 + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 
670 + * 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.
671 + *
672 + *
673 + */
674 +
675 +#include "includes.h"
676 +
677 +#ifdef WITH_LDAP_PUBKEY
678 +
679 +#include <stdio.h>
680 +#include <stdlib.h>
681 +#include <unistd.h>
682 +#include <string.h>
683 +
684 +#include "ldapauth.h"
685 +#include "log.h"
686 +
687 +static char *attrs[] = {
688 +    PUBKEYATTR,
689 +    NULL
690 +};
691 +
692 +/* filter building infos */
693 +#define FILTER_GROUP_PREFIX "(&(objectclass=posixGroup)"
694 +#define FILTER_OR_PREFIX "(|"
695 +#define FILTER_OR_SUFFIX ")"
696 +#define FILTER_CN_PREFIX "(cn="
697 +#define FILTER_CN_SUFFIX ")"
698 +#define FILTER_UID_FORMAT "(memberUid=%s)"
699 +#define FILTER_GROUP_SUFFIX ")"
700 +#define FILTER_GROUP_SIZE(group) (size_t) (strlen(group)+(ldap_count_group(group)*5)+52)
701 +
702 +/* just filter building stuff */
703 +#define REQUEST_GROUP_SIZE(filter, uid) (size_t) (strlen(filter)+strlen(uid)+1)
704 +#define REQUEST_GROUP(buffer, prefilter, pwname) \
705 +    buffer = (char *) calloc(REQUEST_GROUP_SIZE(prefilter, pwname), sizeof(char)); \
706 +    if (!buffer) { \
707 +        perror("calloc()"); \
708 +        return FAILURE; \
709 +    } \
710 +    snprintf(buffer, REQUEST_GROUP_SIZE(prefilter,pwname), prefilter, pwname)
711 +/*
712 +XXX OLD group building macros
713 +#define REQUEST_GROUP_SIZE(grp, uid) (size_t) (strlen(grp)+strlen(uid)+46)
714 +#define REQUEST_GROUP(buffer,pwname,grp) \
715 +    buffer = (char *) calloc(REQUEST_GROUP_SIZE(grp, pwname), sizeof(char)); \
716 +    if (!buffer) { \
717 +        perror("calloc()"); \
718 +        return FAILURE; \
719 +    } \
720 +    snprintf(buffer,REQUEST_GROUP_SIZE(grp,pwname),"(&(objectclass=posixGroup)(cn=%s)(memberUid=%s))",grp,pwname)
721 +    */
722 +
723 +#define REQUEST_USER_SIZE(uid) (size_t) (strlen(uid)+64)
724 +#define REQUEST_USER(buffer, pwname) \
725 +    buffer = (char *) calloc(REQUEST_USER_SIZE(pwname), sizeof(char)); \
726 +    if (!buffer) { \
727 +        perror("calloc()"); \
728 +        return NULL; \
729 +    } \
730 +    snprintf(buffer,REQUEST_USER_SIZE(pwname),"(&(objectclass=posixAccount)(objectclass=ldapPublicKey)(uid=%s))",pwname)
731 +
732 +/* some portable and working tokenizer, lame though */
733 +static int tokenize(char ** o, size_t size, char * input) {
734 +    unsigned int i = 0, num;
735 +    char * charset = " \t";
736 +    char * ptr = input;
737 +
738 +    /* leading white spaces are ignored */
739 +    num = strspn(ptr, charset);
740 +    ptr += num;
741 +
742 +    while ((num = strcspn(ptr, charset))) {
743 +        if (i < size-1) {
744 +            o[i++] = ptr;
745 +            ptr += num;
746 +            if (*ptr)
747 +                *ptr++ = '\0';
748 +        }
749 +    }
750 +    o[i] = NULL;
751 +    return SUCCESS;
752 +}
753 +
754 +void ldap_close(ldap_opt_t * ldap) {
755 +
756 +    if (!ldap)
757 +        return;
758 +
759 +    if ( ldap_unbind_ext(ldap->ld, NULL, NULL) < 0)
760 +       ldap_perror(ldap->ld, "ldap_unbind()");
761 +
762 +    ldap->ld = NULL;
763 +    FLAG_SET_DISCONNECTED(ldap->flags);
764 +
765 +    return;
766 +}
767 +
768 +/* init && bind */
769 +int ldap_connect(ldap_opt_t * ldap) {
770 +    int version = LDAP_VERSION3;
771 +
772 +    if (!ldap->servers)
773 +        return FAILURE;
774 +
775 +    /* Connection Init and setup */
776 +    ldap->ld = ldap_init(ldap->servers, LDAP_PORT);
777 +    if (!ldap->ld) {
778 +        ldap_perror(ldap->ld, "ldap_init()");
779 +        return FAILURE;
780 +    }
781 +
782 +    if ( ldap_set_option(ldap->ld, LDAP_OPT_PROTOCOL_VERSION, &version) != LDAP_OPT_SUCCESS) {
783 +        ldap_perror(ldap->ld, "ldap_set_option(LDAP_OPT_PROTOCOL_VERSION)");
784 +        return FAILURE;
785 +    }
786 +
787 +    /* Timeouts setup */
788 +    if (ldap_set_option(ldap->ld, LDAP_OPT_NETWORK_TIMEOUT, &ldap->b_timeout) != LDAP_SUCCESS) {
789 +        ldap_perror(ldap->ld, "ldap_set_option(LDAP_OPT_NETWORK_TIMEOUT)");
790 +    }
791 +    if (ldap_set_option(ldap->ld, LDAP_OPT_TIMEOUT, &ldap->s_timeout) != LDAP_SUCCESS) {
792 +        ldap_perror(ldap->ld, "ldap_set_option(LDAP_OPT_TIMEOUT)");
793 +    }
794 +
795 +    /* TLS support */
796 +    if ( (ldap->tls == -1) || (ldap->tls == 1) ) {
797 +        if (ldap_start_tls_s(ldap->ld, NULL, NULL ) != LDAP_SUCCESS) {
798 +            /* failed then reinit the initial connect */
799 +            ldap_perror(ldap->ld, "ldap_connect: (TLS) ldap_start_tls()");
800 +            if (ldap->tls == 1)
801 +                return FAILURE;
802 +
803 +            ldap->ld = ldap_init(ldap->servers, LDAP_PORT);
804 +            if (!ldap->ld) { 
805 +                ldap_perror(ldap->ld, "ldap_init()");
806 +                return FAILURE;
807 +            }
808 +
809 +            if ( ldap_set_option(ldap->ld, LDAP_OPT_PROTOCOL_VERSION, &version) != LDAP_OPT_SUCCESS) {
810 +                 ldap_perror(ldap->ld, "ldap_set_option()");
811 +                 return FAILURE;
812 +            }
813 +        }
814 +    }
815 +
816 +
817 +    if ( ldap_simple_bind_s(ldap->ld, ldap->binddn, ldap->bindpw) != LDAP_SUCCESS) {
818 +        ldap_perror(ldap->ld, "ldap_simple_bind_s()");
819 +        return FAILURE;
820 +    }
821 +
822 +    /* says it is connected */
823 +    FLAG_SET_CONNECTED(ldap->flags);
824 +
825 +    return SUCCESS;
826 +}
827 +
828 +/* must free allocated ressource */
829 +static char * ldap_build_host(char *host, int port) {
830 +    unsigned int size = strlen(host)+11;
831 +    char * h = (char *) calloc (size, sizeof(char));
832 +    int rc;
833 +    if (!h)
834 +         return NULL;
835 +
836 +    rc = snprintf(h, size, "%s:%d ", host, port);
837 +    if (rc == -1)
838 +        return NULL;
839 +    return h;
840 +}
841 +
842 +static int ldap_count_group(char * input) {
843 +    char * charset = " \t";
844 +    char * ptr = input;
845 +    unsigned int count = 0;
846 +    unsigned int num;
847 +
848 +    num = strspn(ptr, charset);
849 +    ptr += num;
850 +
851 +    while ((num = strcspn(ptr, charset))) {
852 +    count++;
853 +    ptr += num;
854 +    ptr++;
855 +    }
856 +
857 +    return count;
858 +}
859 +
860 +/* format filter */
861 +char * ldap_parse_groups(char * groups) {
862 +    unsigned int buffer_size = FILTER_GROUP_SIZE(groups);
863 +    char * buffer = (char *) calloc(buffer_size, sizeof(char));
864 +    char * g = NULL;
865 +    char * garray[32];
866 +    unsigned int i = 0;
867 +
868 +    if ((!groups)||(!buffer))
869 +        return NULL;
870 +
871 +    g = strdup(groups);
872 +    if (!g) {
873 +        free(buffer);
874 +        return NULL;
875 +    }
876 +
877 +    /* first separate into n tokens */
878 +    if ( tokenize(garray, sizeof(garray)/sizeof(*garray), g) < 0) {
879 +        free(g);
880 +        free(buffer);
881 +        return NULL;
882 +    }
883 +
884 +    /* build the final filter format */
885 +    strlcat(buffer, FILTER_GROUP_PREFIX, buffer_size);
886 +    strlcat(buffer, FILTER_OR_PREFIX, buffer_size);
887 +    i = 0;
888 +    while (garray[i]) {
889 +        strlcat(buffer, FILTER_CN_PREFIX, buffer_size);
890 +        strlcat(buffer, garray[i], buffer_size);
891 +        strlcat(buffer, FILTER_CN_SUFFIX, buffer_size);
892 +        i++;
893 +    }
894 +    strlcat(buffer, FILTER_OR_SUFFIX, buffer_size);
895 +    strlcat(buffer, FILTER_UID_FORMAT, buffer_size);
896 +    strlcat(buffer, FILTER_GROUP_SUFFIX, buffer_size);
897 +
898 +    free(g);
899 +    return buffer;
900 +}
901 +
902 +/* a bit dirty but leak free  */
903 +char * ldap_parse_servers(char * servers) {
904 +    char * s = NULL;
905 +    char * tmp = NULL, *urls[32];
906 +    unsigned int num = 0 , i = 0 , asize = 0;
907 +    LDAPURLDesc *urld[32];
908 +
909 +    if (!servers)
910 +        return NULL;
911 +
912 +    /* local copy of the arg */
913 +    s = strdup(servers);
914 +    if (!s)
915 +        return NULL;
916 +
917 +    /* first separate into URL tokens */
918 +    if ( tokenize(urls, sizeof(urls)/sizeof(*urls), s) < 0)
919 +        return NULL;
920 +
921 +    i = 0;
922 +    while (urls[i]) {
923 +        if ( ldap_is_ldap_url(urls[i]) ) {
924 +            if (ldap_url_parse(urls[i], &urld[i]) != 0)
925 +                return NULL;
926 +        }
927 +        i++;
928 +    }
929 +
930 +    /* now free(s) */
931 +    free (s);
932 +
933 +    /* how much memory do we need */
934 +    num = i;
935 +    for (i = 0 ; i < num ; i++)
936 +        asize += strlen(urld[i]->lud_host)+11;
937 +
938 +    /* alloc */
939 +    s = (char *) calloc( asize+1 , sizeof(char));
940 +    if (!s) {
941 +        for (i = 0 ; i < num ; i++)
942 +            ldap_free_urldesc(urld[i]);
943 +        return NULL;
944 +    }
945 +
946 +    /* then build the final host string */
947 +    for (i = 0 ; i < num ; i++) {
948 +        /* built host part */
949 +        tmp = ldap_build_host(urld[i]->lud_host, urld[i]->lud_port);
950 +        strncat(s, tmp, strlen(tmp));
951 +        ldap_free_urldesc(urld[i]);
952 +        free(tmp);
953 +    }
954 +
955 +    return s;
956 +}
957 +
958 +void ldap_options_print(ldap_opt_t * ldap) {
959 +    printf("ldap options:\n");
960 +    printf("servers: %s\n", ldap->servers);
961 +    if (ldap->u_basedn)
962 +        printf("user basedn: %s\n", ldap->u_basedn);
963 +    if (ldap->g_basedn)
964 +        printf("group basedn: %s\n", ldap->g_basedn);
965 +    if (ldap->binddn)
966 +        printf("binddn: %s\n", ldap->binddn);
967 +    if (ldap->bindpw)
968 +        printf("bindpw: %s\n", ldap->bindpw);
969 +    if (ldap->sgroup)
970 +        printf("group: %s\n", ldap->sgroup);
971 +}
972 +
973 +void ldap_options_free(ldap_opt_t * l) {
974 +    if (!l)
975 +        return;
976 +    if (l->servers)
977 +        free(l->servers);
978 +    if (l->u_basedn)
979 +        free(l->u_basedn);
980 +    if (l->g_basedn)
981 +        free(l->g_basedn);
982 +    if (l->binddn)
983 +        free(l->binddn);
984 +    if (l->bindpw)
985 +        free(l->bindpw);
986 +    if (l->sgroup)
987 +        free(l->sgroup);
988 +    if (l->fgroup)
989 +        free(l->fgroup);
990 +    if (l->l_conf)
991 +        free(l->l_conf);
992 +    free(l);
993 +}
994 +
995 +/* free keys */
996 +void ldap_keys_free(ldap_key_t * k) {
997 +    ldap_value_free_len(k->keys);
998 +    free(k);
999 +    return;
1000 +}
1001 +
1002 +ldap_key_t * ldap_getuserkey(ldap_opt_t *l, char * user) {
1003 +    ldap_key_t * k = (ldap_key_t *) calloc (1, sizeof(ldap_key_t));
1004 +    LDAPMessage *res, *e;
1005 +    char * filter;
1006 +    int i;
1007 +
1008 +    if ((!k) || (!l))
1009 +         return NULL;
1010 +
1011 +    /* Am i still connected ? RETRY n times */
1012 +    /* XXX TODO: setup some conf value for retrying */
1013 +    if (!(l->flags & FLAG_CONNECTED))
1014 +        for (i = 0 ; i < 2 ; i++)
1015 +            if (ldap_connect(l) == 0)
1016 +                break;
1017 +
1018 +    /* build  filter for LDAP request */
1019 +    REQUEST_USER(filter, user);
1020 +
1021 +    if ( ldap_search_st( l->ld,
1022 +        l->u_basedn,
1023 +        LDAP_SCOPE_SUBTREE,
1024 +        filter,
1025 +        attrs, 0, &l->s_timeout, &res ) != LDAP_SUCCESS) {
1026 +        
1027 +        ldap_perror(l->ld, "ldap_search_st()");
1028 +
1029 +        free(filter);
1030 +        free(k);
1031 +
1032 +        /* XXX error on search, timeout etc.. close ask for reconnect */
1033 +        ldap_close(l);
1034 +
1035 +        return NULL;
1036 +    } 
1037 +
1038 +    /* free */
1039 +    free(filter);
1040 +
1041 +    /* check if any results */
1042 +    i = ldap_count_entries(l->ld,res);
1043 +    if (i <= 0) {
1044 +        ldap_msgfree(res);
1045 +        free(k);
1046 +        return NULL;
1047 +    }
1048 +
1049 +    if (i > 1)
1050 +        printf("[LDAP] duplicate entries, using the FIRST entry returned\n");
1051 +
1052 +    e = ldap_first_entry(l->ld, res);
1053 +    k->keys = ldap_get_values_len(l->ld, e, PUBKEYATTR);
1054 +    k->num = ldap_count_values_len(k->keys);
1055 +
1056 +    ldap_msgfree(res);
1057 +    return k;
1058 +}
1059 +
1060 +
1061 +/* -1 if trouble
1062 +   0 if user is NOT member of current server group
1063 +   1 if user IS MEMBER of current server group 
1064 + */
1065 +int ldap_ismember(ldap_opt_t * l, char * user) {
1066 +    LDAPMessage *res;
1067 +    char * filter;
1068 +    int i;
1069 +
1070 +    if ((!l->sgroup) || !(l->g_basedn))
1071 +        return 1;
1072 +
1073 +    /* Am i still connected ? RETRY n times */
1074 +    /* XXX TODO: setup some conf value for retrying */
1075 +    if (!(l->flags & FLAG_CONNECTED)) 
1076 +        for (i = 0 ; i < 2 ; i++)
1077 +            if (ldap_connect(l) == 0)
1078 +                 break;
1079 +
1080 +    /* build filter for LDAP request */
1081 +    REQUEST_GROUP(filter, l->fgroup, user);
1082 +
1083 +    if (ldap_search_st( l->ld, 
1084 +        l->g_basedn,
1085 +        LDAP_SCOPE_SUBTREE,
1086 +        filter,
1087 +        NULL, 0, &l->s_timeout, &res) != LDAP_SUCCESS) {
1088 +    
1089 +        ldap_perror(l->ld, "ldap_search_st()");
1090 +
1091 +        free(filter);
1092 +
1093 +        /* XXX error on search, timeout etc.. close ask for reconnect */
1094 +        ldap_close(l);
1095 +
1096 +        return FAILURE;
1097 +    }
1098 +
1099 +    free(filter);
1100 +
1101 +    /* check if any results */
1102 +    if (ldap_count_entries(l->ld, res) > 0) {
1103 +        ldap_msgfree(res);
1104 +        return 1;
1105 +    }
1106 +
1107 +    ldap_msgfree(res);
1108 +    return 0;
1109 +}
1110 +
1111 +/*
1112 + * ldap.conf simple parser
1113 + * XXX TODO:  sanity checks
1114 + * must either
1115 + * - free the previous ldap_opt_before replacing entries
1116 + * - free each necessary previously parsed elements
1117 + * ret:
1118 + * -1 on FAILURE, 0 on SUCCESS
1119 + */
1120 +int ldap_parse_lconf(ldap_opt_t * l) {
1121 +    FILE * lcd; /* ldap.conf descriptor */
1122 +    char buf[BUFSIZ];
1123 +    char * s = NULL, * k = NULL, * v = NULL;
1124 +    int li, len;
1125 +
1126 +    lcd = fopen (l->l_conf, "r");
1127 +    if (lcd == NULL) {
1128 +        /* debug("Cannot open %s", l->l_conf); */
1129 +        perror("ldap_parse_lconf()");
1130 +        return FAILURE;
1131 +    }
1132 +    
1133 +    while (fgets (buf, sizeof (buf), lcd) != NULL) {
1134 +
1135 +        if (*buf == '\n' || *buf == '#')
1136 +            continue;
1137 +
1138 +        k = buf;
1139 +        v = k;
1140 +        while (*v != '\0' && *v != ' ' && *v != '\t')
1141 +            v++;
1142 +
1143 +        if (*v == '\0')
1144 +            continue;
1145 +
1146 +        *(v++) = '\0';
1147 +
1148 +        while (*v == ' ' || *v == '\t')
1149 +            v++;
1150 +
1151 +        li = strlen (v) - 1;
1152 +        while (v[li] == ' ' || v[li] == '\t' || v[li] == '\n')
1153 +            --li;
1154 +        v[li + 1] = '\0';
1155 +
1156 +        if (!strcasecmp (k, "uri")) {
1157 +            if ((l->servers = ldap_parse_servers(strdup (v))) == NULL) {
1158 +                fatal("error in ldap servers");
1159 +            return FAILURE;
1160 +            }
1161 +
1162 +        }
1163 +        else if (!strcasecmp (k, "base")) { 
1164 +            s = strchr (v, '?');
1165 +            if (s != NULL) {
1166 +                len = s - v;
1167 +                l->u_basedn = malloc (len + 1);
1168 +                strncpy (l->u_basedn, v, len);
1169 +                l->u_basedn[len] = '\0';
1170 +            } else {
1171 +                l->u_basedn = strdup (v);
1172 +            }
1173 +        }
1174 +        else if (!strcasecmp (k, "binddn")) {
1175 +            l->binddn = strdup (v);
1176 +        }
1177 +        else if (!strcasecmp (k, "bindpw")) {
1178 +            l->bindpw = strdup (v);
1179 +        }
1180 +        else if (!strcasecmp (k, "timelimit")) {
1181 +            l->s_timeout.tv_sec = atoi (v);
1182 +                }
1183 +        else if (!strcasecmp (k, "bind_timelimit")) {
1184 +            l->b_timeout.tv_sec = atoi (v);
1185 +        }
1186 +        else if (!strcasecmp (k, "ssl")) {
1187 +            if (!strcasecmp (v, "start_tls"))
1188 +                l->tls = 1;
1189 +        }
1190 +    }
1191 +
1192 +    fclose (lcd);
1193 +    return SUCCESS;
1194 +}
1195 +
1196 +#endif /* WITH_LDAP_PUBKEY */
1197 diff -Nru -x Makefile -x 'buildpkg.*' -x opensshd.init -x 'ssh_prng_*' openssh-4.3p1/ldapauth.h openssh-4.3p1-lpk/ldapauth.h
1198 --- openssh-4.3p1/ldapauth.h    1970-01-01 01:00:00.000000000 +0100
1199 +++ openssh-4.3p1-lpk/ldapauth.h        2006-04-18 15:46:59.000000000 +0200
1200 @@ -0,0 +1,119 @@
1201 +/*
1202 + * $Id$ 
1203 + */
1204 +
1205 +/*
1206 + *
1207 + * Copyright (c) 2005, Eric AUGE <eau@phear.org>
1208 + * All rights reserved.
1209 + *
1210 + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1211 + *
1212 + * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
1213 + * 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.
1214 + * 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.
1215 + *
1216 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 
1217 + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
1218 + * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 
1219 + * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
1220 + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 
1221 + * 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.
1222 + *
1223 + *
1224 + */
1225 +
1226 +#ifndef LDAPAUTH_H
1227 +#define LDAPAUTH_H
1228 +
1229 +#include <string.h>
1230 +#include <time.h>
1231 +#include <ldap.h>
1232 +#include <lber.h>
1233 +
1234 +/* tokens in use for config */
1235 +#define _DEFAULT_LPK_TOKEN "UseLPK"
1236 +#define _DEFAULT_SRV_TOKEN "LpkServers"
1237 +#define _DEFAULT_USR_TOKEN "LpkUserDN"
1238 +#define _DEFAULT_GRP_TOKEN "LpkGroupDN"
1239 +#define _DEFAULT_BDN_TOKEN "LpkBindDN"
1240 +#define _DEFAULT_BPW_TOKEN "LpkBindPw"
1241 +#define _DEFAULT_MYG_TOKEN "LpkServerGroup"
1242 +#define _DEFAULT_TLS_TOKEN "LpkForceTLS"
1243 +#define _DEFAULT_BTI_TOKEN "LpkBindTimelimit"
1244 +#define _DEFAULT_STI_TOKEN "LpkSearchTimelimit"
1245 +#define _DEFAULT_LDP_TOKEN "LpkLdapConf"
1246 +
1247 +/* default options */
1248 +#define _DEFAULT_LPK_ON 0
1249 +#define _DEFAULT_LPK_SERVERS NULL
1250 +#define _DEFAULT_LPK_UDN NULL
1251 +#define _DEFAULT_LPK_GDN NULL
1252 +#define _DEFAULT_LPK_BINDDN NULL
1253 +#define _DEFAULT_LPK_BINDPW NULL
1254 +#define _DEFAULT_LPK_SGROUP NULL
1255 +#define _DEFAULT_LPK_TLS -1
1256 +#define _DEFAULT_LPK_BTIMEOUT 10
1257 +#define _DEFAULT_LPK_STIMEOUT 10
1258 +#define _DEFAULT_LPK_LDP NULL
1259 +
1260 +/* flags */
1261 +#define FLAG_EMPTY         0x00000000
1262 +#define FLAG_CONNECTED     0x00000001
1263 +
1264 +/* flag macros */
1265 +#define FLAG_SET_EMPTY(x)              x&=(FLAG_EMPTY)
1266 +#define FLAG_SET_CONNECTED(x)          x|=(FLAG_CONNECTED)
1267 +#define FLAG_SET_DISCONNECTED(x)       x&=~(FLAG_CONNECTED)
1268 +
1269 +/* defines */
1270 +#define FAILURE -1
1271 +#define SUCCESS 0
1272 +#define PUBKEYATTR "sshPublicKey"
1273 +
1274 +/* 
1275 + *
1276 + * defined files path 
1277 + * (should be relocated to pathnames.h,
1278 + * if one day it's included within the tree) 
1279 + *
1280 + */
1281 +#define _PATH_LDAP_CONFIG_FILE "/etc/ldap.conf"
1282 +
1283 +/* structures */
1284 +typedef struct ldap_options {
1285 +    int on;                    /* Use it or NOT */
1286 +    LDAP * ld;                 /* LDAP file desc */
1287 +    char * servers;            /* parsed servers for ldaplib failover handling */
1288 +    char * u_basedn;           /* user basedn */
1289 +    char * g_basedn;           /* group basedn */
1290 +    char * binddn;             /* binddn */
1291 +    char * bindpw;             /* bind password */
1292 +    char * sgroup;             /* server group */
1293 +    char * fgroup;             /* group filter */
1294 +    char * l_conf;             /* use ldap.conf */
1295 +    int tls;                   /* TLS only */
1296 +    struct timeval b_timeout;   /* bind timeout */
1297 +    struct timeval s_timeout;   /* search timeout */
1298 +    unsigned int flags;                /* misc flags (reconnection, future use?) */
1299 +} ldap_opt_t;
1300 +
1301 +typedef struct ldap_keys {
1302 +    struct berval ** keys;     /* the public keys retrieved */
1303 +    unsigned int num;          /* number of keys */
1304 +} ldap_key_t;
1305 +
1306 +
1307 +/* function headers */
1308 +void ldap_close(ldap_opt_t *);
1309 +int ldap_connect(ldap_opt_t *);
1310 +char * ldap_parse_groups(char *);
1311 +char * ldap_parse_servers(char *);
1312 +void ldap_options_print(ldap_opt_t *);
1313 +void ldap_options_free(ldap_opt_t *);
1314 +void ldap_keys_free(ldap_key_t *);
1315 +int ldap_parse_lconf(ldap_opt_t *);
1316 +ldap_key_t * ldap_getuserkey(ldap_opt_t *, char *);
1317 +int ldap_ismember(ldap_opt_t *, char *);
1318 +
1319 +#endif
1320 diff -Nru -x Makefile -x 'buildpkg.*' -x opensshd.init -x 'ssh_prng_*' openssh-4.3p1/lpk-user-example.txt openssh-4.3p1-lpk/lpk-user-example.txt
1321 --- openssh-4.3p1/lpk-user-example.txt  1970-01-01 01:00:00.000000000 +0100
1322 +++ openssh-4.3p1-lpk/lpk-user-example.txt      2006-04-18 15:46:59.000000000 +0200
1323 @@ -0,0 +1,117 @@
1324 +
1325 +Post to ML -> User Made Quick Install Doc.
1326 +Contribution from John Lane <john@lane.uk.net>
1327 +
1328 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1329 +
1330 +OpenSSH LDAP keystore Patch
1331 +===========================
1332 +
1333 +NOTE: these notes are a transcript of a specific installation
1334 +      they work for me, your specifics may be different!
1335 +      from John Lane March 17th 2005         john@lane.uk.net
1336 +
1337 +This is a patch to OpenSSH 4.0p1 to allow it to obtain users' public keys
1338 +from their LDAP record as an alternative to ~/.ssh/authorized_keys.
1339 +
1340 +(Assuming here that necessary build stuff is in $BUILD)
1341 +
1342 +cd $BUILD/openssh-4.0p1
1343 +patch -Np1 -i $BUILD/openssh-lpk-4.0p1-0.3.patch
1344 +mkdir -p /var/empty &&
1345 +./configure --prefix=/usr --sysconfdir=/etc/ssh \
1346 +    --libexecdir=/usr/sbin --with-md5-passwords --with-pam \
1347 +    --with-libs="-lldap" --with-cppflags="-DWITH_LDAP_PUBKEY"
1348 +Now do.
1349 +make &&
1350 +make install
1351 +
1352 +Add the following config to /etc/ssh/ssh_config
1353 +UseLPK yes
1354 +LpkServers ldap://myhost.mydomain.com
1355 +LpkUserDN  ou=People,dc=mydomain,dc=com
1356 +
1357 +We need to tell sshd about the SSL keys during boot, as root's
1358 +environment does not exist at that time. Edit /etc/rc.d/init.d/sshd.
1359 +Change the startup code from this:
1360 +                echo "Starting SSH Server..."
1361 +                loadproc /usr/sbin/sshd
1362 +                ;;
1363 +to this:
1364 +                echo "Starting SSH Server..."
1365 +                LDAPRC="/root/.ldaprc" loadproc /usr/sbin/sshd
1366 +                ;;
1367 +
1368 +Re-start the sshd daemon:
1369 +/etc/rc.d/init.d/sshd restart
1370 +
1371 +Install the additional LDAP schema
1372 +cp $BUILD/openssh-lpk-0.2.schema  /etc/openldap/schema/openssh.schema
1373 +
1374 +Now add the openSSH LDAP schema to /etc/openldap/slapd.conf:
1375 +Add the following to the end of the existing block of schema includes
1376 +include         /etc/openldap/schema/openssh.schema
1377 +
1378 +Re-start the LDAP server:
1379 +/etc/rc.d/init.d/slapd restart
1380 +
1381 +To add one or more public keys to a user, eg "testuser" :
1382 +ldapsearch -x -W -Z -LLL -b "uid=testuser,ou=People,dc=mydomain,dc=com" -D
1383 +"uid=testuser,ou=People,dc=mydomain,dc=com" > /tmp/testuser
1384 +
1385 +append the following to this /tmp/testuser file
1386 +objectclass: ldapPublicKey
1387 +sshPublicKey: ssh-rsa
1388 +AAAAB3NzaC1yc2EAAAABJQAAAIB3dsrwqXqD7E4zYYrxwdDKBUQxKMioXy9pxFVai64kAPxjU9KS
1389 +qIo7QfkjslfsjflksjfldfkjsldfjLX/5zkzRmT28I5piGzunPv17S89z8XwSsuAoR1t86t+5dlI
1390 +7eZE/gVbn2UQkQq7+kdDTS2yXV6VnC52N/kKLG3ciBkBAw== General Purpose RSA Key
1391 +
1392 +Then do a modify:
1393 +ldapmodify -x -D "uid=testuser,ou=People,dc=mydomain,dc=com" -W -f
1394 +/tmp/testuser -Z
1395 +Enter LDAP Password:
1396 +modifying entry "uid=testuser,ou=People,dc=mydomain,dc=com"
1397 +And check the modify is ok:
1398 +ldapsearch -x -W -Z -b "uid=testuser,ou=People,dc=mydomain,dc=com" -D
1399 +"uid=testuser,ou=People,dc=mydomain,dc=com"
1400 +Enter LDAP Password:
1401 +# extended LDIF
1402 +#
1403 +# LDAPv3
1404 +# base <uid=testuser,ou=People,dc=mydomain,dc=com> with scope sub
1405 +# filter: (objectclass=*)
1406 +# requesting: ALL
1407 +#
1408 +
1409 +# testuser, People, mydomain.com
1410 +dn: uid=testuser,ou=People,dc=mydomain,dc=com
1411 +uid: testuser
1412 +cn: testuser
1413 +objectClass: account
1414 +objectClass: posixAccount
1415 +objectClass: top
1416 +objectClass: shadowAccount
1417 +objectClass: ldapPublicKey
1418 +shadowLastChange: 12757
1419 +shadowMax: 99999
1420 +shadowWarning: 7
1421 +loginShell: /bin/bash
1422 +uidNumber: 9999
1423 +gidNumber: 501
1424 +homeDirectory: /home/testuser
1425 +userPassword:: e1NTSEF9UDgwV1hnM1VjUDRJK0k1YnFiL1d4ZUJObXlZZ3Z3UTU=
1426 +sshPublicKey: ssh-rsa
1427 +AAAAB3NzaC1yc2EAAAABJQAAAIB3dsrwqXqD7E4zYYrxwdDKBUQxKMioXy9pxFVai64kAPxjU9KSqIo7QfkjslfsjflksjfldfkjsldfjLX/5zkzRmT28I5piGzunPv17S89z
1428 +8XwSsuAoR1t86t+5dlI7eZE/gVbn2UQkQq7+kdDTS2yXV6VnC52N/kKLG3ciBkBAw== General Purpose RSA Key
1429 +
1430 +# search result
1431 +search: 3
1432 +result: 0 Success
1433 +
1434 +# numResponses: 2
1435 +# numEntries: 1
1436 +
1437 +Now start a ssh session to user "testuser" from usual ssh client (e.g.
1438 +puTTY). Login should succeed.
1439 +
1440 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1441 diff -Nru -x Makefile -x 'buildpkg.*' -x opensshd.init -x 'ssh_prng_*' openssh-4.3p1/openssh-lpk.schema openssh-4.3p1-lpk/openssh-lpk.schema
1442 --- openssh-4.3p1/openssh-lpk.schema    1970-01-01 01:00:00.000000000 +0100
1443 +++ openssh-4.3p1-lpk/openssh-lpk.schema        2006-04-18 15:46:59.000000000 +0200
1444 @@ -0,0 +1,21 @@
1445 +#
1446 +# $Id$
1447 +#
1448 +# LDAP Public Key Patch schema for use with openssh-ldappubkey
1449 +# Author: Eric AUGE <eau@phear.org>
1450 +# 
1451 +# Based on the proposal of : Mark Ruijter
1452 +#
1453 +
1454 +
1455 +# octetString SYNTAX
1456 +attributetype ( 1.3.6.1.4.1.22054.500.1.1.1.13 NAME 'sshPublicKey' 
1457 +       DESC 'MANDATORY: OpenSSH Public key' 
1458 +       EQUALITY octetStringMatch
1459 +       SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )
1460 +
1461 +# printableString SYNTAX yes|no
1462 +objectclass ( 1.3.6.1.4.1.22054.500.1.1.2.0 NAME 'ldapPublicKey' SUP top AUXILIARY
1463 +       DESC 'MANDATORY: OpenSSH LPK objectclass'
1464 +       MUST ( sshPublicKey $ uid ) 
1465 +       )
1466 diff -Nru -x Makefile -x 'buildpkg.*' -x opensshd.init -x 'ssh_prng_*' openssh-4.3p1/servconf.c openssh-4.3p1-lpk/servconf.c
1467 --- openssh-4.3p1/servconf.c    2005-12-13 09:33:20.000000000 +0100
1468 +++ openssh-4.3p1-lpk/servconf.c        2006-04-18 15:46:59.000000000 +0200
1469 @@ -23,6 +23,10 @@
1470  #include "kex.h"
1471  #include "mac.h"
1472  
1473 +#ifdef WITH_LDAP_PUBKEY
1474 +#include "ldapauth.h"
1475 +#endif
1476 +
1477  static void add_listen_addr(ServerOptions *, char *, u_short);
1478  static void add_one_listen_addr(ServerOptions *, char *, u_short);
1479  
1480 @@ -102,6 +106,23 @@
1481         options->authorized_keys_file2 = NULL;
1482         options->num_accept_env = 0;
1483         options->permit_tun = -1;
1484 +#ifdef WITH_LDAP_PUBKEY
1485 +       /* XXX dirty */
1486 +       options->lpk.ld = NULL;
1487 +       options->lpk.on = -1;
1488 +       options->lpk.servers = NULL;
1489 +       options->lpk.u_basedn = NULL;
1490 +       options->lpk.g_basedn = NULL;
1491 +       options->lpk.binddn = NULL;
1492 +       options->lpk.bindpw = NULL;
1493 +       options->lpk.sgroup = NULL;
1494 +       options->lpk.fgroup = NULL;
1495 +       options->lpk.l_conf = NULL;
1496 +       options->lpk.tls = -1;
1497 +       options->lpk.b_timeout.tv_sec = 0;
1498 +       options->lpk.s_timeout.tv_sec = 0;
1499 +       options->lpk.flags = FLAG_EMPTY;
1500 +#endif
1501  
1502         /* Needs to be accessable in many places */
1503         use_privsep = -1;
1504 @@ -232,6 +253,30 @@
1505                 options->authorized_keys_file = _PATH_SSH_USER_PERMITTED_KEYS;
1506         if (options->permit_tun == -1)
1507                 options->permit_tun = SSH_TUNMODE_NO;
1508 +#ifdef WITH_LDAP_PUBKEY
1509 +       if (options->lpk.on == -1)
1510 +           options->lpk.on = _DEFAULT_LPK_ON;
1511 +       if (options->lpk.servers == NULL)
1512 +           options->lpk.servers = _DEFAULT_LPK_SERVERS;
1513 +       if (options->lpk.u_basedn == NULL)
1514 +           options->lpk.u_basedn = _DEFAULT_LPK_UDN;
1515 +       if (options->lpk.g_basedn == NULL)
1516 +           options->lpk.g_basedn = _DEFAULT_LPK_GDN;
1517 +       if (options->lpk.binddn == NULL)
1518 +           options->lpk.binddn = _DEFAULT_LPK_BINDDN;
1519 +       if (options->lpk.bindpw == NULL)
1520 +           options->lpk.bindpw = _DEFAULT_LPK_BINDPW;
1521 +       if (options->lpk.sgroup == NULL)
1522 +           options->lpk.sgroup = _DEFAULT_LPK_SGROUP;
1523 +       if (options->lpk.tls == -1)
1524 +           options->lpk.tls = _DEFAULT_LPK_TLS;
1525 +       if (options->lpk.b_timeout.tv_sec == 0)
1526 +           options->lpk.b_timeout.tv_sec = _DEFAULT_LPK_BTIMEOUT;
1527 +       if (options->lpk.s_timeout.tv_sec == 0)
1528 +           options->lpk.s_timeout.tv_sec = _DEFAULT_LPK_STIMEOUT;
1529 +       if (options->lpk.l_conf == NULL)
1530 +           options->lpk.l_conf = _DEFAULT_LPK_LDP;
1531 +#endif
1532  
1533         /* Turn privilege separation on by default */
1534         if (use_privsep == -1)
1535 @@ -276,6 +321,12 @@
1536         sGssAuthentication, sGssCleanupCreds, sAcceptEnv, sPermitTunnel,
1537         sUsePrivilegeSeparation,
1538         sDeprecated, sUnsupported
1539 +#ifdef WITH_LDAP_PUBKEY
1540 +       ,sLdapPublickey, sLdapServers, sLdapUserDN
1541 +       ,sLdapGroupDN, sBindDN, sBindPw, sMyGroup
1542 +       ,sForceTLS, sBindTimeout, sSearchTimeout
1543 +       ,sLdapConf
1544 +#endif
1545  } ServerOpCodes;
1546  
1547  /* Textual representation of the tokens. */
1548 @@ -374,6 +425,19 @@
1549         { "clientalivecountmax", sClientAliveCountMax },
1550         { "authorizedkeysfile", sAuthorizedKeysFile },
1551         { "authorizedkeysfile2", sAuthorizedKeysFile2 },
1552 +#ifdef WITH_LDAP_PUBKEY
1553 +       { _DEFAULT_LPK_TOKEN, sLdapPublickey },
1554 +       { _DEFAULT_SRV_TOKEN, sLdapServers },
1555 +       { _DEFAULT_USR_TOKEN, sLdapUserDN },
1556 +       { _DEFAULT_GRP_TOKEN, sLdapGroupDN },
1557 +       { _DEFAULT_BDN_TOKEN, sBindDN },
1558 +       { _DEFAULT_BPW_TOKEN, sBindPw },
1559 +       { _DEFAULT_MYG_TOKEN, sMyGroup },
1560 +       { _DEFAULT_TLS_TOKEN, sForceTLS },
1561 +       { _DEFAULT_BTI_TOKEN, sBindTimeout },
1562 +       { _DEFAULT_STI_TOKEN, sSearchTimeout },
1563 +       { _DEFAULT_LDP_TOKEN, sLdapConf },
1564 +#endif
1565         { "useprivilegeseparation", sUsePrivilegeSeparation},
1566         { "acceptenv", sAcceptEnv },
1567         { "permittunnel", sPermitTunnel },
1568 @@ -1001,6 +1065,116 @@
1569                 while (arg)
1570                     arg = strdelim(&cp);
1571                 break;
1572 +#ifdef WITH_LDAP_PUBKEY
1573 +       case sLdapPublickey:
1574 +               intptr = &options->lpk.on;
1575 +               goto parse_flag;
1576 +       case sLdapServers:
1577 +               /* arg = strdelim(&cp); */
1578 +               p = line;
1579 +               while(*p++);
1580 +               arg = p;
1581 +               if (!arg || *arg == '\0')
1582 +                   fatal("%s line %d: missing ldap server",filename,linenum);
1583 +               arg[strlen(arg)] = '\0';
1584 +               if ((options->lpk.servers = ldap_parse_servers(arg)) == NULL)
1585 +                   fatal("%s line %d: error in ldap servers", filename, linenum);
1586 +               memset(arg,0,strlen(arg));
1587 +               break;
1588 +       case sLdapUserDN:
1589 +               /* arg = strdelim(&cp); */
1590 +               p = line;
1591 +               while(*p++);
1592 +               arg = p;
1593 +               if (!arg || *arg == '\0')
1594 +                   fatal("%s line %d: missing ldap server",filename,linenum);
1595 +               arg[strlen(arg)] = '\0';
1596 +               options->lpk.u_basedn = xstrdup(arg);
1597 +               memset(arg,0,strlen(arg));
1598 +               break;
1599 +       case sLdapGroupDN:
1600 +               /* arg = strdelim(&cp); */
1601 +               p = line;
1602 +               while(*p++);
1603 +               arg = p;
1604 +               if (!arg || *arg == '\0')
1605 +                   fatal("%s line %d: missing ldap server",filename,linenum);
1606 +               arg[strlen(arg)] = '\0';
1607 +               options->lpk.g_basedn = xstrdup(arg);
1608 +               memset(arg,0,strlen(arg));
1609 +               break;
1610 +       case sBindDN:
1611 +               /* arg = strdelim(&cp); */
1612 +               p = line;
1613 +               while(*p++);
1614 +               arg = p;
1615 +               if (!arg || *arg == '\0')
1616 +                   fatal("%s line %d: missing binddn",filename,linenum);
1617 +               arg[strlen(arg)] = '\0';
1618 +               options->lpk.binddn = xstrdup(arg);
1619 +               memset(arg,0,strlen(arg));
1620 +               break;
1621 +       case sBindPw:
1622 +               /* arg = strdelim(&cp); */
1623 +               p = line;
1624 +               while(*p++);
1625 +               arg = p;
1626 +               if (!arg || *arg == '\0')
1627 +                   fatal("%s line %d: missing bindpw",filename,linenum);
1628 +               arg[strlen(arg)] = '\0';
1629 +               options->lpk.bindpw = xstrdup(arg);
1630 +               memset(arg,0,strlen(arg));
1631 +               break;
1632 +       case sMyGroup:
1633 +               p = line;
1634 +               while (*p++);
1635 +               arg = p;
1636 +               if (!arg || *arg == '\0')
1637 +                   fatal("%s line %d: missing groupname",filename, linenum);
1638 +               arg[strlen(arg)] = '\0';
1639 +               options->lpk.sgroup = xstrdup(arg);
1640 +               if (options->lpk.sgroup)
1641 +                   options->lpk.fgroup = ldap_parse_groups(options->lpk.sgroup);
1642 +               memset(arg,0,strlen(arg));
1643 +               break;
1644 +       case sForceTLS:
1645 +               intptr = &options->lpk.tls;
1646 +               arg = strdelim(&cp);
1647 +               if (!arg || *arg == '\0')
1648 +                       fatal("%s line %d: missing yes/no argument.",
1649 +                           filename, linenum);
1650 +               value = 0;      /* silence compiler */
1651 +               if (strcmp(arg, "yes") == 0)
1652 +                       value = 1;
1653 +               else if (strcmp(arg, "no") == 0)
1654 +                       value = 0;
1655 +               else if (strcmp(arg, "try") == 0)
1656 +                       value = -1;
1657 +               else
1658 +                       fatal("%s line %d: Bad yes/no argument: %s",
1659 +                               filename, linenum, arg);
1660 +               if (*intptr == -1)
1661 +                       *intptr = value;
1662 +               break;
1663 +       case sBindTimeout:
1664 +               intptr = (int *) &options->lpk.b_timeout.tv_sec;
1665 +               goto parse_int;
1666 +       case sSearchTimeout:
1667 +               intptr = (int *) &options->lpk.s_timeout.tv_sec;
1668 +               goto parse_int;
1669 +               break;
1670 +       case sLdapConf:
1671 +               /* arg = strdelim(&cp); */
1672 +               p = line;
1673 +               while (*p++);
1674 +               arg = p;
1675 +               if (!arg || *arg == '\0')
1676 +                   fatal("%s line %d: missing LpkLdapConf", filename, linenum);
1677 +               arg[strlen(arg)] = '\0';
1678 +               options->lpk.l_conf = xstrdup(arg);
1679 +               memset(arg, 0, strlen(arg));
1680 +               break;
1681 +#endif
1682  
1683         default:
1684                 fatal("%s line %d: Missing handler for opcode %s (%d)",
1685 diff -Nru -x Makefile -x 'buildpkg.*' -x opensshd.init -x 'ssh_prng_*' openssh-4.3p1/servconf.h openssh-4.3p1-lpk/servconf.h
1686 --- openssh-4.3p1/servconf.h    2005-12-13 09:29:03.000000000 +0100
1687 +++ openssh-4.3p1-lpk/servconf.h        2006-04-18 15:46:59.000000000 +0200
1688 @@ -18,6 +18,10 @@
1689  
1690  #include "buffer.h"
1691  
1692 +#ifdef WITH_LDAP_PUBKEY
1693 +#include "ldapauth.h"
1694 +#endif
1695 +
1696  #define MAX_PORTS              256     /* Max # ports. */
1697  
1698  #define MAX_ALLOW_USERS                256     /* Max # users on allow list. */
1699 @@ -137,6 +141,9 @@
1700         int     use_pam;                /* Enable auth via PAM */
1701  
1702         int     permit_tun;
1703 +#ifdef WITH_LDAP_PUBKEY
1704 +        ldap_opt_t lpk;
1705 +#endif
1706  }       ServerOptions;
1707  
1708  void    initialize_server_options(ServerOptions *);
1709 diff -Nru -x Makefile -x 'buildpkg.*' -x opensshd.init -x 'ssh_prng_*' openssh-4.3p1/sshd.c openssh-4.3p1-lpk/sshd.c
1710 --- openssh-4.3p1/sshd.c        2005-12-24 04:59:12.000000000 +0100
1711 +++ openssh-4.3p1-lpk/sshd.c    2006-04-18 15:46:59.000000000 +0200
1712 @@ -93,6 +93,10 @@
1713  int deny_severity = LOG_WARNING;
1714  #endif /* LIBWRAP */
1715  
1716 +#ifdef WITH_LDAP_PUBKEY
1717 +#include "ldapauth.h"
1718 +#endif
1719 +
1720  #ifndef O_NOCTTY
1721  #define O_NOCTTY       0
1722  #endif
1723 @@ -1089,6 +1093,16 @@
1724                 exit(1);
1725         }
1726  
1727 +#ifdef WITH_LDAP_PUBKEY
1728 +    /* ldap_options_print(&options.lpk); */
1729 +    /* XXX initialize/check ldap connection and set *LD */
1730 +    if (options.lpk.on) {
1731 +        if (options.lpk.l_conf && (ldap_parse_lconf(&options.lpk) < 0) )
1732 +            error("[LDAP] could not parse %s", options.lpk.l_conf);
1733 +        if (ldap_connect(&options.lpk) < 0)
1734 +            error("[LDAP] could not initialize ldap connection");
1735 +    }
1736 +#endif
1737         debug("sshd version %.100s", SSH_RELEASE);
1738  
1739         /* load private host keys */
1740 diff -Nru -x Makefile -x 'buildpkg.*' -x opensshd.init -x 'ssh_prng_*' openssh-4.3p1/sshd_config openssh-4.3p1-lpk/sshd_config
1741 --- openssh-4.3p1/sshd_config   2005-12-13 09:29:03.000000000 +0100
1742 +++ openssh-4.3p1-lpk/sshd_config       2006-04-18 15:49:45.000000000 +0200
1743 @@ -100,6 +100,20 @@
1744  
1745  # no default banner path
1746  #Banner /some/path
1747
1748 +# here are the new patched ldap related tokens
1749 +# entries in your LDAP must have posixAccount & ldapPublicKey objectclass
1750 +#UseLPK yes
1751 +#LpkLdapConf /etc/ldap.conf
1752 +#LpkServers  ldap://10.1.7.1 ldap://10.1.7.2
1753 +#LpkUserDN   ou=users,dc=phear,dc=org
1754 +#LpkGroupDN  ou=groups,dc=phear,dc=org
1755 +#LpkBindDN cn=Manager,dc=phear,dc=org
1756 +#LpkBindPw secret
1757 +#LpkServerGroup mail
1758 +#LpkForceTLS no
1759 +#LpkSearchTimelimit 3
1760 +#LpkBindTimelimit 3
1761  
1762  # override default of no subsystems
1763  Subsystem      sftp    /usr/libexec/sftp-server
1764 diff -Nru -x Makefile -x 'buildpkg.*' -x opensshd.init -x 'ssh_prng_*' openssh-4.3p1/sshd_config.5 openssh-4.3p1-lpk/sshd_config.5
1765 --- openssh-4.3p1/sshd_config.5 2006-01-03 08:47:31.000000000 +0100
1766 +++ openssh-4.3p1-lpk/sshd_config.5     2006-04-18 15:46:59.000000000 +0200
1767 @@ -777,6 +777,58 @@
1768  program.
1769  The default is
1770  .Pa /usr/X11R6/bin/xauth .
1771 +.It Cm UseLPK
1772 +Specifies whether LDAP public key retrieval must be used or not. It allow
1773 +an easy centralisation of public keys within an LDAP directory. The argument must be
1774 +.Dq yes
1775 +or
1776 +.Dq no .
1777 +.It Cm LpkLdapConf
1778 +Specifies whether LDAP Public keys should parse the specified ldap.conf file
1779 +instead of sshd_config Tokens. The argument must be a valid path to an ldap.conf
1780 +file like
1781 +.Pa /etc/ldap.conf
1782 +.It Cm LpkServers
1783 +Specifies LDAP one or more [:space:] separated server's url the following form may be used:
1784 +.Pp
1785 +LpkServers ldaps://127.0.0.1 ldap://127.0.0.2 ldap://127.0.0.3
1786 +.It Cm LpkUserDN
1787 +Specifies the LDAP user DN.
1788 +.Pp
1789 +LpkUserDN ou=users,dc=phear,dc=org
1790 +.It Cm LpkGroupDN
1791 +Specifies the LDAP groups DN.
1792 +.Pp
1793 +LpkGroupDN ou=groups,dc=phear,dc=org
1794 +.It Cm LpkBindDN
1795 +Specifies the LDAP bind DN to use if necessary.
1796 +.Pp
1797 +LpkBindDN cn=Manager,dc=phear,dc=org
1798 +.It Cm LpkBindPw
1799 +Specifies the LDAP bind credential. 
1800 +.Pp
1801 +LpkBindPw secret
1802 +.It Cm LpkServerGroup
1803 +Specifies one or more [:space:] separated group the server is part of. 
1804 +.Pp
1805 +LpkServerGroup unix mail prod
1806 +.It Cm LpkForceTLS
1807 +Specifies if the LDAP server connection must be tried, forced or not used. The argument must be 
1808 +.Dq yes
1809 +or
1810 +.Dq no
1811 +or
1812 +.Dq try .
1813 +.It Cm LpkSearchTimelimit
1814 +Sepcifies the search time limit before the search is considered over. value is
1815 +in seconds.
1816 +.Pp
1817 +LpkSearchTimelimit 3
1818 +.It Cm LpkBindTimelimit
1819 +Sepcifies the bind time limit before the connection is considered dead. value is
1820 +in seconds.
1821 +.Pp
1822 +LpkBindTimelimit 3
1823  .El
1824  .Ss Time Formats
1825  .Nm sshd
This page took 0.320062 seconds and 3 git commands to generate.