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