diff options
Diffstat (limited to 'contrib/sendmail/src/map.c')
-rw-r--r-- | contrib/sendmail/src/map.c | 317 |
1 files changed, 167 insertions, 150 deletions
diff --git a/contrib/sendmail/src/map.c b/contrib/sendmail/src/map.c index 510b7c9..4248fd9 100644 --- a/contrib/sendmail/src/map.c +++ b/contrib/sendmail/src/map.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998-2006 Sendmail, Inc. and its suppliers. + * Copyright (c) 1998-2007 Sendmail, Inc. and its suppliers. * All rights reserved. * Copyright (c) 1992, 1995-1997 Eric P. Allman. All rights reserved. * Copyright (c) 1992, 1993 @@ -13,7 +13,7 @@ #include <sendmail.h> -SM_RCSID("@(#)$Id: map.c,v 8.696 2007/04/03 21:33:14 ca Exp $") +SM_RCSID("@(#)$Id: map.c,v 8.699 2007/10/10 00:06:45 ca Exp $") #if LDAPMAP # include <sm/ldap.h> @@ -3567,10 +3567,17 @@ ldapmap_lookup(map, name, av, statp) if (VendorCode == VENDOR_SUN && strcmp(map->map_mname, "aliases.ldap") == 0) { - char answer[MAXNAME + 1]; int rc; +#if defined(GETLDAPALIASBYNAME_VERSION) && (GETLDAPALIASBYNAME_VERSION >= 2) + extern char *__getldapaliasbyname(); + char *answer; + + answer = __getldapaliasbyname(name, &rc); +#else + char answer[MAXNAME + 1]; rc = __getldapaliasbyname(name, answer, sizeof(answer)); +#endif if (rc != 0) { if (tTd(38, 20)) @@ -3587,6 +3594,9 @@ ldapmap_lookup(map, name, av, statp) result = map_rewrite(map, name, strlen(name), NULL); else result = map_rewrite(map, answer, strlen(answer), av); +#if defined(GETLDAPALIASBYNAME_VERSION) && (GETLDAPALIASBYNAME_VERSION >= 2) + free(answer); +#endif return result; } #endif /* defined(SUN_EXTENSIONS) && defined(SUN_SIMPLIFIED_LDAP) && ... */ @@ -3965,17 +3975,16 @@ ldapmap_parseargs(map, args) break; switch (*++p) { - case 'N': - map->map_mflags |= MF_INCLNULL; - map->map_mflags &= ~MF_TRY0NULL; + case 'A': + map->map_mflags |= MF_APPEND; break; - case 'O': - map->map_mflags &= ~MF_TRY1NULL; + case 'a': + map->map_app = ++p; break; - case 'o': - map->map_mflags |= MF_OPTIONAL; + case 'D': + map->map_mflags |= MF_DEFER; break; case 'f': @@ -3986,16 +3995,25 @@ ldapmap_parseargs(map, args) map->map_mflags |= MF_MATCHONLY; break; - case 'A': - map->map_mflags |= MF_APPEND; + case 'N': + map->map_mflags |= MF_INCLNULL; + map->map_mflags &= ~MF_TRY0NULL; + break; + + case 'O': + map->map_mflags &= ~MF_TRY1NULL; + break; + + case 'o': + map->map_mflags |= MF_OPTIONAL; break; case 'q': map->map_mflags |= MF_KEEPQUOTES; break; - case 'a': - map->map_app = ++p; + case 'S': + map->map_spacesub = *++p; break; case 'T': @@ -4006,14 +4024,6 @@ ldapmap_parseargs(map, args) map->map_mflags |= MF_NODEFER; break; - case 'S': - map->map_spacesub = *++p; - break; - - case 'D': - map->map_mflags |= MF_DEFER; - break; - case 'z': if (*++p != '\\') map->map_coldelim = *p; @@ -4036,25 +4046,68 @@ ldapmap_parseargs(map, args) break; /* Start of ldapmap specific args */ - case 'V': - if (*++p != '\\') - lmap->ldap_attrsep = *p; - else - { - switch (*++p) - { - case 'n': - lmap->ldap_attrsep = '\n'; - break; + case '1': + map->map_mflags |= MF_SINGLEMATCH; + break; - case 't': - lmap->ldap_attrsep = '\t'; - break; +# if _FFR_LDAP_SINGLEDN + case '2': + map->map_mflags |= MF_SINGLEDN; + break; +# endif /* _FFR_LDAP_SINGLEDN */ - default: - lmap->ldap_attrsep = '\\'; - } + case 'b': /* search base */ + while (isascii(*++p) && isspace(*p)) + continue; + lmap->ldap_base = p; + break; + +# if _FFR_LDAP_NETWORK_TIMEOUT + case 'c': /* network (connect) timeout */ + while (isascii(*++p) && isspace(*p)) + continue; + lmap->ldap_networktmo.tv_sec = atoi(p); + break; +# endif /* _FFR_LDAP_NETWORK_TIMEOUT */ + + case 'd': /* Dn to bind to server as */ + while (isascii(*++p) && isspace(*p)) + continue; + lmap->ldap_binddn = p; + break; + + case 'H': /* Use LDAP URI */ +# if !USE_LDAP_INIT + syserr("Must compile with -DUSE_LDAP_INIT to use LDAP URIs (-H) in map %s", + map->map_mname); + return false; +# else /* !USE_LDAP_INIT */ + if (lmap->ldap_host != NULL) + { + syserr("Can not specify both an LDAP host and an LDAP URI in map %s", + map->map_mname); + return false; } + while (isascii(*++p) && isspace(*p)) + continue; + lmap->ldap_uri = p; + break; +# endif /* !USE_LDAP_INIT */ + + case 'h': /* ldap host */ + while (isascii(*++p) && isspace(*p)) + continue; + if (lmap->ldap_uri != NULL) + { + syserr("Can not specify both an LDAP host and an LDAP URI in map %s", + map->map_mname); + return false; + } + lmap->ldap_host = p; + break; + + case 'K': + lmap->ldap_multi_args = true; break; case 'k': /* search field */ @@ -4063,22 +4116,69 @@ ldapmap_parseargs(map, args) lmap->ldap_filter = p; break; - case 'v': /* attr to return */ + case 'l': /* time limit */ while (isascii(*++p) && isspace(*p)) continue; - lmap->ldap_attr[0] = p; - lmap->ldap_attr[1] = NULL; + lmap->ldap_timelimit = atoi(p); + lmap->ldap_timeout.tv_sec = lmap->ldap_timelimit; break; - case '1': - map->map_mflags |= MF_SINGLEMATCH; + case 'M': /* Method for binding */ + while (isascii(*++p) && isspace(*p)) + continue; + + if (sm_strncasecmp(p, "LDAP_AUTH_", 10) == 0) + p += 10; + + for (lam = LDAPAuthMethods; + lam != NULL && lam->lam_name != NULL; lam++) + { + if (sm_strncasecmp(p, lam->lam_name, + strlen(lam->lam_name)) == 0) + break; + } + if (lam->lam_name != NULL) + lmap->ldap_method = lam->lam_code; + else + { + /* bad config line */ + if (!bitset(MCF_OPTFILE, + map->map_class->map_cflags)) + { + char *ptr; + + if ((ptr = strchr(p, ' ')) != NULL) + *ptr = '\0'; + syserr("Method for binding must be [none|simple|krbv4] (not %s) in map %s", + p, map->map_mname); + if (ptr != NULL) + *ptr = ' '; + return false; + } + } break; -# if _FFR_LDAP_SINGLEDN - case '2': - map->map_mflags |= MF_SINGLEDN; + case 'n': /* retrieve attribute names only */ + lmap->ldap_attrsonly = LDAPMAP_TRUE; + break; + + /* + ** This is a string that is dependent on the + ** method used defined by 'M'. + */ + + case 'P': /* Secret password for binding */ + while (isascii(*++p) && isspace(*p)) + continue; + lmap->ldap_secret = p; + secretread = false; + break; + + case 'p': /* ldap port */ + while (isascii(*++p) && isspace(*p)) + continue; + lmap->ldap_port = atoi(p); break; -# endif /* _FFR_LDAP_SINGLEDN */ /* args stolen from ldapsearch.c */ case 'R': /* don't auto chase referrals */ @@ -4089,10 +4189,6 @@ ldapmap_parseargs(map, args) # endif /* LDAP_REFERRALS */ break; - case 'n': /* retrieve attribute names only */ - lmap->ldap_attrsonly = LDAPMAP_TRUE; - break; - case 'r': /* alias dereferencing */ while (isascii(*++p) && isspace(*p)) continue; @@ -4163,114 +4259,33 @@ ldapmap_parseargs(map, args) } break; - case 'h': /* ldap host */ - while (isascii(*++p) && isspace(*p)) - continue; - if (lmap->ldap_uri != NULL) - { - syserr("Can not specify both an LDAP host and an LDAP URI in map %s", - map->map_mname); - return false; - } - lmap->ldap_host = p; - break; - - case 'b': /* search base */ - while (isascii(*++p) && isspace(*p)) - continue; - lmap->ldap_base = p; - break; - - case 'p': /* ldap port */ - while (isascii(*++p) && isspace(*p)) - continue; - lmap->ldap_port = atoi(p); - break; - - case 'l': /* time limit */ - while (isascii(*++p) && isspace(*p)) - continue; - lmap->ldap_timelimit = atoi(p); - lmap->ldap_timeout.tv_sec = lmap->ldap_timelimit; - break; - - case 'Z': - while (isascii(*++p) && isspace(*p)) - continue; - lmap->ldap_sizelimit = atoi(p); - break; - - case 'd': /* Dn to bind to server as */ - while (isascii(*++p) && isspace(*p)) - continue; - lmap->ldap_binddn = p; - break; - - case 'M': /* Method for binding */ - while (isascii(*++p) && isspace(*p)) - continue; - - if (sm_strncasecmp(p, "LDAP_AUTH_", 10) == 0) - p += 10; - - for (lam = LDAPAuthMethods; - lam != NULL && lam->lam_name != NULL; lam++) - { - if (sm_strncasecmp(p, lam->lam_name, - strlen(lam->lam_name)) == 0) - break; - } - if (lam->lam_name != NULL) - lmap->ldap_method = lam->lam_code; + case 'V': + if (*++p != '\\') + lmap->ldap_attrsep = *p; else { - /* bad config line */ - if (!bitset(MCF_OPTFILE, - map->map_class->map_cflags)) + switch (*++p) { - char *ptr; + case 'n': + lmap->ldap_attrsep = '\n'; + break; - if ((ptr = strchr(p, ' ')) != NULL) - *ptr = '\0'; - syserr("Method for binding must be [none|simple|krbv4] (not %s) in map %s", - p, map->map_mname); - if (ptr != NULL) - *ptr = ' '; - return false; + case 't': + lmap->ldap_attrsep = '\t'; + break; + + default: + lmap->ldap_attrsep = '\\'; } } - break; - /* - ** This is a string that is dependent on the - ** method used defined above. - */ - - case 'P': /* Secret password for binding */ - while (isascii(*++p) && isspace(*p)) - continue; - lmap->ldap_secret = p; - secretread = false; - break; - - case 'H': /* Use LDAP URI */ -# if !USE_LDAP_INIT - syserr("Must compile with -DUSE_LDAP_INIT to use LDAP URIs (-H) in map %s", - map->map_mname); - return false; -# else /* !USE_LDAP_INIT */ - if (lmap->ldap_host != NULL) - { - syserr("Can not specify both an LDAP host and an LDAP URI in map %s", - map->map_mname); - return false; - } + case 'v': /* attr to return */ while (isascii(*++p) && isspace(*p)) continue; - lmap->ldap_uri = p; + lmap->ldap_attr[0] = p; + lmap->ldap_attr[1] = NULL; break; -# endif /* !USE_LDAP_INIT */ case 'w': /* -w should be for passwd, -P should be for version */ @@ -4297,8 +4312,10 @@ ldapmap_parseargs(map, args) # endif /* LDAP_VERSION_MIN */ break; - case 'K': - lmap->ldap_multi_args = true; + case 'Z': + while (isascii(*++p) && isspace(*p)) + continue; + lmap->ldap_sizelimit = atoi(p); break; default: |