Deleted Added
full compact
mbdb.c (90792) mbdb.c (94334)
1/*
2 * Copyright (c) 2001-2002 Sendmail, Inc. and its suppliers.
3 * All rights reserved.
4 *
5 * By using this file, you agree to the terms and conditions set
6 * forth in the LICENSE file which can be found at the top level of
7 * the sendmail distribution.
8 */
9
10#include <sm/gen.h>
1/*
2 * Copyright (c) 2001-2002 Sendmail, Inc. and its suppliers.
3 * All rights reserved.
4 *
5 * By using this file, you agree to the terms and conditions set
6 * forth in the LICENSE file which can be found at the top level of
7 * the sendmail distribution.
8 */
9
10#include <sm/gen.h>
11SM_RCSID("@(#)$Id: mbdb.c,v 1.28 2002/01/07 23:29:43 gshapiro Exp $")
11SM_RCSID("@(#)$Id: mbdb.c,v 1.36 2002/03/25 18:08:20 gshapiro Exp $")
12
13#include <sys/param.h>
14
15#include <ctype.h>
16#include <errno.h>
17#include <pwd.h>
18#include <stdlib.h>
19#include <setjmp.h>
20
21#include <sm/limits.h>
22#include <sm/conf.h>
23#include <sm/assert.h>
24#include <sm/bitops.h>
25#include <sm/errstring.h>
26#include <sm/heap.h>
27#include <sm/mbdb.h>
28#include <sm/string.h>
12
13#include <sys/param.h>
14
15#include <ctype.h>
16#include <errno.h>
17#include <pwd.h>
18#include <stdlib.h>
19#include <setjmp.h>
20
21#include <sm/limits.h>
22#include <sm/conf.h>
23#include <sm/assert.h>
24#include <sm/bitops.h>
25#include <sm/errstring.h>
26#include <sm/heap.h>
27#include <sm/mbdb.h>
28#include <sm/string.h>
29# ifdef EX_OK
30# undef EX_OK /* for SVr4.2 SMP */
31# endif /* EX_OK */
29#include <sm/sysexits.h>
30
31#if LDAPMAP
32# if _LDAP_EXAMPLE_
33# include <sm/ldap.h>
34# endif /* _LDAP_EXAMPLE_ */
35#endif /* LDAPMAP */
36

--- 165 unchanged lines hidden (view full) ---

202** user -- the login name of this user (for &).
203** buf -- place to put the result.
204** buflen -- length of buf.
205**
206** Returns:
207** none.
208*/
209
32#include <sm/sysexits.h>
33
34#if LDAPMAP
35# if _LDAP_EXAMPLE_
36# include <sm/ldap.h>
37# endif /* _LDAP_EXAMPLE_ */
38#endif /* LDAPMAP */
39

--- 165 unchanged lines hidden (view full) ---

205** user -- the login name of this user (for &).
206** buf -- place to put the result.
207** buflen -- length of buf.
208**
209** Returns:
210** none.
211*/
212
213#if _FFR_HANDLE_ISO8859_GECOS
214static char Latin1ToASCII[128] =
215{
216 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
217 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 33,
218 99, 80, 36, 89, 124, 36, 34, 99, 97, 60, 45, 45, 114, 45, 111, 42,
219 50, 51, 39, 117, 80, 46, 44, 49, 111, 62, 42, 42, 42, 63, 65, 65,
220 65, 65, 65, 65, 65, 67, 69, 69, 69, 69, 73, 73, 73, 73, 68, 78, 79,
221 79, 79, 79, 79, 88, 79, 85, 85, 85, 85, 89, 80, 66, 97, 97, 97, 97,
222 97, 97, 97, 99, 101, 101, 101, 101, 105, 105, 105, 105, 100, 110,
223 111, 111, 111, 111, 111, 47, 111, 117, 117, 117, 117, 121, 112, 121
224};
225#endif /* _FFR_HANDLE_ISO8859_GECOS */
226
210void
211sm_pwfullname(gecos, user, buf, buflen)
212 register char *gecos;
213 char *user;
214 char *buf;
215 size_t buflen;
216{
217 register char *p;

--- 14 unchanged lines hidden (view full) ---

232 if (*p == '&')
233 {
234 /* interpolate full name */
235 (void) sm_strlcpy(bp, user, buflen - (bp - buf));
236 *bp = toupper(*bp);
237 bp += strlen(bp);
238 }
239 else
227void
228sm_pwfullname(gecos, user, buf, buflen)
229 register char *gecos;
230 char *user;
231 char *buf;
232 size_t buflen;
233{
234 register char *p;

--- 14 unchanged lines hidden (view full) ---

249 if (*p == '&')
250 {
251 /* interpolate full name */
252 (void) sm_strlcpy(bp, user, buflen - (bp - buf));
253 *bp = toupper(*bp);
254 bp += strlen(bp);
255 }
256 else
240 *bp++ = *p;
257 {
258#if _FFR_HANDLE_ISO8859_GECOS
259 if ((unsigned char) *p >= 128)
260 *bp++ = Latin1ToASCII[(unsigned char) *p - 128];
261 else
262#endif /* _FFR_HANDLE_ISO8859_GECOS */
263 *bp++ = *p;
264 }
241 }
242 *bp = '\0';
243}
244
245/*
246** /etc/passwd implementation.
247*/
248

--- 155 unchanged lines hidden (view full) ---

404*/
405
406static int
407mbdb_ldap_initialize(arg)
408 char *arg;
409{
410 sm_ldap_clear(&LDAPLMAP);
411 LDAPLMAP.ldap_base = MBDB_DEFAULT_LDAP_BASEDN;
265 }
266 *bp = '\0';
267}
268
269/*
270** /etc/passwd implementation.
271*/
272

--- 155 unchanged lines hidden (view full) ---

428*/
429
430static int
431mbdb_ldap_initialize(arg)
432 char *arg;
433{
434 sm_ldap_clear(&LDAPLMAP);
435 LDAPLMAP.ldap_base = MBDB_DEFAULT_LDAP_BASEDN;
412 LDAPLMAP.ldap_host = MBDB_DEFAULT_LDAP_SERVER;
436 LDAPLMAP.ldap_target = MBDB_DEFAULT_LDAP_SERVER;
413 LDAPLMAP.ldap_filter = MBDB_LDAP_FILTER;
414
415 /* Only want one match */
416 LDAPLMAP.ldap_sizelimit = 1;
417
437 LDAPLMAP.ldap_filter = MBDB_LDAP_FILTER;
438
439 /* Only want one match */
440 LDAPLMAP.ldap_sizelimit = 1;
441
418 /* interpolate new ldap_base and ldap_host from arg if given */
442 /* interpolate new ldap_base and ldap_target from arg if given */
419 if (arg != NULL && *arg != '\0')
420 {
421 char *new;
422 char *sep;
423 size_t len;
424
425 len = strlen(arg) + 1;
426 new = sm_malloc(len);
427 if (new == NULL)
428 return EX_TEMPFAIL;
429 (void) sm_strlcpy(new, arg, len);
430 sep = strrchr(new, '@');
431 if (sep != NULL)
432 {
433 *sep++ = '\0';
443 if (arg != NULL && *arg != '\0')
444 {
445 char *new;
446 char *sep;
447 size_t len;
448
449 len = strlen(arg) + 1;
450 new = sm_malloc(len);
451 if (new == NULL)
452 return EX_TEMPFAIL;
453 (void) sm_strlcpy(new, arg, len);
454 sep = strrchr(new, '@');
455 if (sep != NULL)
456 {
457 *sep++ = '\0';
434 LDAPLMAP.ldap_host = sep;
458 LDAPLMAP.ldap_target = sep;
435 }
436 LDAPLMAP.ldap_base = new;
437 }
438
439 /* No connection yet, connect */
440 if (!sm_ldap_start(MBDB_LDAP_LABEL, &LDAPLMAP))
441 return EX_UNAVAILABLE;
442 return EX_OK;

--- 120 unchanged lines hidden (view full) ---

563 char **vals;
564
565 vals = ldap_get_values(LDAPLMAP.ldap_ld, entry, attr);
566 if (vals == NULL)
567 {
568 errno = sm_ldap_geterrno(LDAPLMAP.ldap_ld);
569 if (errno == LDAP_SUCCESS)
570 {
459 }
460 LDAPLMAP.ldap_base = new;
461 }
462
463 /* No connection yet, connect */
464 if (!sm_ldap_start(MBDB_LDAP_LABEL, &LDAPLMAP))
465 return EX_UNAVAILABLE;
466 return EX_OK;

--- 120 unchanged lines hidden (view full) ---

587 char **vals;
588
589 vals = ldap_get_values(LDAPLMAP.ldap_ld, entry, attr);
590 if (vals == NULL)
591 {
592 errno = sm_ldap_geterrno(LDAPLMAP.ldap_ld);
593 if (errno == LDAP_SUCCESS)
594 {
571# if USING_NETSCAPE_LDAP
572 ldap_memfree(attr);
595 ldap_memfree(attr);
573# endif /* USING_NETSCAPE_LDAP */
574 continue;
575 }
576
577 /* Must be an error */
578 errno += E_LDAPBASE;
579 ret = EX_TEMPFAIL;
580 goto abort;
581 }

--- 83 unchanged lines hidden (view full) ---

665 goto skip;
666 }
667 user->mbdb_gid = atoi(vals[0]);
668 need &= ~NEED_GID;
669 }
670
671skip:
672 ldap_value_free(vals);
596 continue;
597 }
598
599 /* Must be an error */
600 errno += E_LDAPBASE;
601 ret = EX_TEMPFAIL;
602 goto abort;
603 }

--- 83 unchanged lines hidden (view full) ---

687 goto skip;
688 }
689 user->mbdb_gid = atoi(vals[0]);
690 need &= ~NEED_GID;
691 }
692
693skip:
694 ldap_value_free(vals);
673# if USING_NETSCAPE_LDAP
674 ldap_memfree(attr);
695 ldap_memfree(attr);
675# endif /* USING_NETSCAPE_LDAP */
676 }
677
678 errno = sm_ldap_geterrno(LDAPLMAP.ldap_ld);
679
680 /*
681 ** We check errno != LDAP_DECODING_ERROR since
682 ** OpenLDAP 1.X has a very ugly *undocumented*
683 ** hack of returning this error code from

--- 10 unchanged lines hidden (view full) ---

694 ret = EX_TEMPFAIL;
695 goto abort;
696 }
697
698 abort:
699 save_errno = errno;
700 if (attr != NULL)
701 {
696 }
697
698 errno = sm_ldap_geterrno(LDAPLMAP.ldap_ld);
699
700 /*
701 ** We check errno != LDAP_DECODING_ERROR since
702 ** OpenLDAP 1.X has a very ugly *undocumented*
703 ** hack of returning this error code from

--- 10 unchanged lines hidden (view full) ---

714 ret = EX_TEMPFAIL;
715 goto abort;
716 }
717
718 abort:
719 save_errno = errno;
720 if (attr != NULL)
721 {
702# if USING_NETSCAPE_LDAP
703 ldap_memfree(attr);
722 ldap_memfree(attr);
704# endif /* USING_NETSCAPE_LDAP */
705 attr = NULL;
706 }
707 if (LDAPLMAP.ldap_res != NULL)
708 {
709 ldap_msgfree(LDAPLMAP.ldap_res);
710 LDAPLMAP.ldap_res = NULL;
711 }
712 if (ret == EX_OK)

--- 34 unchanged lines hidden ---
723 attr = NULL;
724 }
725 if (LDAPLMAP.ldap_res != NULL)
726 {
727 ldap_msgfree(LDAPLMAP.ldap_res);
728 LDAPLMAP.ldap_res = NULL;
729 }
730 if (ret == EX_OK)

--- 34 unchanged lines hidden ---