diff options
Diffstat (limited to 'contrib/sendmail/libsm')
-rw-r--r-- | contrib/sendmail/libsm/README | 5 | ||||
-rw-r--r-- | contrib/sendmail/libsm/clock.c | 13 | ||||
-rw-r--r-- | contrib/sendmail/libsm/config.c | 5 | ||||
-rw-r--r-- | contrib/sendmail/libsm/debug.html | 6 | ||||
-rw-r--r-- | contrib/sendmail/libsm/fclose.c | 7 | ||||
-rw-r--r-- | contrib/sendmail/libsm/findfp.c | 11 | ||||
-rw-r--r-- | contrib/sendmail/libsm/ldap.c | 524 | ||||
-rw-r--r-- | contrib/sendmail/libsm/local.h | 22 | ||||
-rw-r--r-- | contrib/sendmail/libsm/mbdb.c | 40 | ||||
-rw-r--r-- | contrib/sendmail/libsm/smstdio.c | 21 | ||||
-rw-r--r-- | contrib/sendmail/libsm/sscanf.c | 3 | ||||
-rw-r--r-- | contrib/sendmail/libsm/stdio.c | 51 | ||||
-rw-r--r-- | contrib/sendmail/libsm/strio.c | 53 | ||||
-rw-r--r-- | contrib/sendmail/libsm/strl.c | 7 | ||||
-rw-r--r-- | contrib/sendmail/libsm/t-event.c | 8 | ||||
-rw-r--r-- | contrib/sendmail/libsm/t-fopen.c | 8 | ||||
-rw-r--r-- | contrib/sendmail/libsm/t-shm.c | 7 | ||||
-rw-r--r-- | contrib/sendmail/libsm/t-types.c | 4 | ||||
-rw-r--r-- | contrib/sendmail/libsm/vsscanf.c | 5 | ||||
-rw-r--r-- | contrib/sendmail/libsm/wsetup.c | 8 |
20 files changed, 561 insertions, 247 deletions
diff --git a/contrib/sendmail/libsm/README b/contrib/sendmail/libsm/README index ffd43cabd363..d75d55f8ea87 100644 --- a/contrib/sendmail/libsm/README +++ b/contrib/sendmail/libsm/README @@ -5,7 +5,7 @@ # forth in the LICENSE file which can be found at the top level of # the sendmail distribution. # -# $Id: README,v 1.20 2002/01/09 18:05:39 ca Exp $ +# $Id: README,v 1.21 2002/01/23 17:30:48 gshapiro Exp $ # Libsm is a library of generally useful C abstractions. @@ -109,6 +109,9 @@ SM_CONF_BROKEN_STRTOD SM_CONF_GETOPT Set to 1 if your operating system does not include getopt(3). +SM_CONF_LDAP_MEMFREE + Set to 1 if your LDAP client libraries include ldap_memfree(3). + SM_IO_MAX_BUF_FILE Set this to a useful buffer size for regular files if stat(2) does not return a value for st_blksize that is the diff --git a/contrib/sendmail/libsm/clock.c b/contrib/sendmail/libsm/clock.c index eed1ded9ef4e..ada9689980af 100644 --- a/contrib/sendmail/libsm/clock.c +++ b/contrib/sendmail/libsm/clock.c @@ -12,7 +12,7 @@ */ #include <sm/gen.h> -SM_RCSID("@(#)$Id: clock.c,v 1.34 2001/11/05 18:33:20 ca Exp $") +SM_RCSID("@(#)$Id: clock.c,v 1.35 2002/03/22 18:34:38 gshapiro Exp $") #include <unistd.h> #include <time.h> #include <errno.h> @@ -160,6 +160,8 @@ sm_sigsafe_seteventm(intvl, func, arg) timersub(&SmEventQueue->ev_time, &now, &itime.it_value); itime.it_interval.tv_sec = 0; itime.it_interval.tv_usec = 0; + if (itime.it_value.tv_sec < 0) + itime.it_value.tv_sec = 0; if (itime.it_value.tv_sec == 0 && itime.it_value.tv_usec == 0) itime.it_value.tv_usec = 1000; (void) setitimer(ITIMER_REAL, &itime, NULL); @@ -412,6 +414,11 @@ sm_tick(sig) &clr.it_value); clr.it_interval.tv_sec = 0; clr.it_interval.tv_usec = 0; + if (clr.it_value.tv_sec < 0) + clr.it_value.tv_sec = 0; + if (clr.it_value.tv_sec == 0 && + clr.it_value.tv_usec == 0) + clr.it_value.tv_usec = 1000; (void) setitimer(ITIMER_REAL, &clr, NULL); } else @@ -452,6 +459,10 @@ sm_tick(sig) timersub(&SmEventQueue->ev_time, &now, &clr.it_value); clr.it_interval.tv_sec = 0; clr.it_interval.tv_usec = 0; + if (clr.it_value.tv_sec < 0) + clr.it_value.tv_sec = 0; + if (clr.it_value.tv_sec == 0 && clr.it_value.tv_usec == 0) + clr.it_value.tv_usec = 1000; (void) setitimer(ITIMER_REAL, &clr, NULL); #else /* SM_CONF_SETITIMER */ (void) alarm((unsigned) (SmEventQueue->ev_time - now)); diff --git a/contrib/sendmail/libsm/config.c b/contrib/sendmail/libsm/config.c index 064539d6c996..53cbe3dca4ef 100644 --- a/contrib/sendmail/libsm/config.c +++ b/contrib/sendmail/libsm/config.c @@ -9,7 +9,7 @@ */ #include <sm/gen.h> -SM_RCSID("@(#)$Id: config.c,v 1.26 2001/12/14 00:26:18 ca Exp $") +SM_RCSID("@(#)$Id: config.c,v 1.27 2002/01/23 17:30:48 gshapiro Exp $") #include <stdlib.h> #include <sm/heap.h> @@ -176,6 +176,9 @@ char *SmCompileOptions[] = #if SM_CONF_GETOPT "SM_CONF_GETOPT", #endif /* SM_CONF_GETOPT */ +#if SM_CONF_LDAP_MEMFREE + "SM_CONF_LDAP_MEMFREE", +#endif /* SM_CONF_LDAP_MEMFREE */ #if SM_CONF_LONGLONG "SM_CONF_LONGLONG", #endif /* SM_CONF_LONGLONG */ diff --git a/contrib/sendmail/libsm/debug.html b/contrib/sendmail/libsm/debug.html index 41fa124f7920..a9b184af7c05 100644 --- a/contrib/sendmail/libsm/debug.html +++ b/contrib/sendmail/libsm/debug.html @@ -8,7 +8,7 @@ <center> <h1> libsm : Debugging and Tracing </h1> - <br> $Id: debug.html,v 1.8 2000/12/08 21:41:41 ca Exp $ + <br> $Id: debug.html,v 1.9 2002/02/02 16:50:56 ca Exp $ </center> <h2> Introduction </h2> @@ -59,10 +59,6 @@ For example, does all of the above. </dl> -<p> -For sendmail 9.x, I propose to drop support for numeric debug categories, -and just use named debug categories. - <h2> Synopsis </h2> <pre> diff --git a/contrib/sendmail/libsm/fclose.c b/contrib/sendmail/libsm/fclose.c index c1099f87200a..2de1413196a3 100644 --- a/contrib/sendmail/libsm/fclose.c +++ b/contrib/sendmail/libsm/fclose.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000-2001 Sendmail, Inc. and its suppliers. + * Copyright (c) 2000-2002 Sendmail, Inc. and its suppliers. * All rights reserved. * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. @@ -13,7 +13,7 @@ */ #include <sm/gen.h> -SM_RCSID("@(#)$Id: fclose.c,v 1.41 2001/09/11 04:04:48 gshapiro Exp $") +SM_RCSID("@(#)$Id: fclose.c,v 1.42 2002/02/01 02:28:00 ca Exp $") #include <errno.h> #include <stdlib.h> #include <sys/time.h> @@ -86,6 +86,7 @@ sm_io_close(fp, timeout) SM_REQUIRE_ISA(fp, SmFileMagic); + /* XXX this won't be reached if above macro is active */ if (fp->sm_magic == NULL) { /* not open! */ @@ -140,8 +141,6 @@ sm_io_close(fp, timeout) } if (HASUB(fp)) FREEUB(fp); - if (HASLB(fp)) - FREELB(fp); fp->f_flags = 0; /* clear flags */ fp->sm_magic = NULL; /* Release this SM_FILE_T for reuse. */ fp->f_r = fp->f_w = 0; /* Mess up if reaccessed. */ diff --git a/contrib/sendmail/libsm/findfp.c b/contrib/sendmail/libsm/findfp.c index a2ec20c94c22..115ed22fa85b 100644 --- a/contrib/sendmail/libsm/findfp.c +++ b/contrib/sendmail/libsm/findfp.c @@ -13,7 +13,7 @@ */ #include <sm/gen.h> -SM_RCSID("@(#)$Id: findfp.c,v 1.62 2002/01/11 16:33:03 ca Exp $") +SM_RCSID("@(#)$Id: findfp.c,v 1.66 2002/02/20 02:40:24 ca Exp $") #include <stdlib.h> #include <unistd.h> #include <sys/param.h> @@ -47,7 +47,7 @@ SM_FILE_T SmFtStdiofd_def = SM_TIME_BLOCK, "stdiofd" }; /* A string file type */ -SM_FILE_T _SmFtString_def = +SM_FILE_T SmFtString_def = {SmFileMagic, 0, 0, 0, (SMRW|SMNBF), -1, {0, 0}, 0, 0, 0, sm_strclose, sm_strread, sm_strseek, sm_strwrite, sm_stropen, sm_strsetinfo, sm_strgetinfo, SM_TIME_FOREVER, @@ -119,9 +119,9 @@ sm_moreglue_x(n) register struct sm_glue *g; register SM_FILE_T *p; - g = (struct sm_glue *) sm_pmalloc_x(sizeof(*g) + ALIGNBYTES + + g = (struct sm_glue *) sm_pmalloc_x(sizeof(*g) + SM_ALIGN_BITS + n * sizeof(SM_FILE_T)); - p = (SM_FILE_T *) ALIGN(g + 1); + p = (SM_FILE_T *) SM_ALIGN(g + 1); g->gl_next = NULL; g->gl_niobs = n; g->gl_iobs = p; @@ -194,13 +194,10 @@ found: fp->f_setinfo = t->f_setinfo; /* assign setinfo function */ fp->f_getinfo = t->f_getinfo; /* assign getinfo function */ fp->f_type = t->f_type; /* file type */ - fp->f_self = fp; /* self reference for future use */ fp->f_ub.smb_base = NULL; /* no ungetc buffer */ fp->f_ub.smb_size = 0; /* no size for no ungetc buffer */ - fp->f_lb.smb_base = NULL; /* no line buffer */ - fp->f_lb.smb_size = 0; /* no size for no line buffer */ if (fp->f_timeout == SM_TIME_DEFAULT) fp->f_timeout = SM_TIME_FOREVER; else diff --git a/contrib/sendmail/libsm/ldap.c b/contrib/sendmail/libsm/ldap.c index a431511e079d..3e85a87664e0 100644 --- a/contrib/sendmail/libsm/ldap.c +++ b/contrib/sendmail/libsm/ldap.c @@ -8,7 +8,7 @@ */ #include <sm/gen.h> -SM_RCSID("@(#)$Id: ldap.c,v 1.18 2002/01/11 22:06:51 gshapiro Exp $") +SM_RCSID("@(#)$Id: ldap.c,v 1.44 2002/02/22 21:54:02 gshapiro Exp $") #if LDAPMAP # include <sys/types.h> @@ -24,6 +24,9 @@ SM_RCSID("@(#)$Id: ldap.c,v 1.18 2002/01/11 22:06:51 gshapiro Exp $") # include <sm/errstring.h> # include <sm/ldap.h> # include <sm/string.h> +# ifdef EX_OK +# undef EX_OK /* for SVr4.2 SMP */ +# endif /* EX_OK */ # include <sm/sysexits.h> SM_DEBUG_T SmLDAPTrace = SM_DEBUG_INITIALIZER("sm_trace_ldap", @@ -49,8 +52,14 @@ sm_ldap_clear(lmap) if (lmap == NULL) return; - lmap->ldap_host = NULL; + lmap->ldap_target = NULL; lmap->ldap_port = LDAP_PORT; +#if _FFR_LDAP_URI + lmap->ldap_uri = false; +#endif /* _FFR_LDAP_URI */ +# if _FFR_LDAP_SETVERSION + lmap->ldap_version = 0; +# endif /* _FFR_LDAP_SETVERSION */ lmap->ldap_deref = LDAP_DEREF_NEVER; lmap->ldap_timelimit = LDAP_NO_LIMIT; lmap->ldap_sizelimit = LDAP_NO_LIMIT; @@ -72,8 +81,8 @@ sm_ldap_clear(lmap) lmap->ldap_filter = NULL; lmap->ldap_attr[0] = NULL; #if _FFR_LDAP_RECURSION - lmap->ldap_attr_type[0] = LDAPMAP_ATTR_NORMAL; - lmap->ldap_attr_final[0] = NULL; + lmap->ldap_attr_type[0] = SM_LDAP_ATTR_NONE; + lmap->ldap_attr_needobjclass[0] = NULL; #endif /* _FFR_LDAP_RECURSION */ lmap->ldap_res = NULL; lmap->ldap_next = NULL; @@ -132,11 +141,16 @@ sm_ldap_start(name, lmap) if (sm_debug_active(&SmLDAPTrace, 9)) sm_dprintf("ldapmap_start(%s, %d)\n", - lmap->ldap_host == NULL ? "localhost" : lmap->ldap_host, + lmap->ldap_target == NULL ? "localhost" : lmap->ldap_target, lmap->ldap_port); # if USE_LDAP_INIT - ld = ldap_init(lmap->ldap_host, lmap->ldap_port); +# if _FFR_LDAP_URI + if (lmap->ldap_uri) + errno = ldap_initialize(&ld, lmap->ldap_target); + else +# endif /* _FFR_LDAP_URI */ + ld = ldap_init(lmap->ldap_target, lmap->ldap_port); save_errno = errno; # else /* USE_LDAP_INIT */ /* @@ -146,7 +160,7 @@ sm_ldap_start(name, lmap) */ SM_LDAP_SETTIMEOUT(lmap->ldap_timeout.tv_sec); - ld = ldap_open(lmap->ldap_host, lmap->ldap_port); + ld = ldap_open(lmap->ldap_target, lmap->ldap_port); save_errno = errno; /* clear the event if it has not sprung */ @@ -297,8 +311,8 @@ sm_ldap_search(lmap, key) sm_dprintf("ldap search filter=%s\n", filter); lmap->ldap_res = NULL; - msgid = ldap_search(lmap->ldap_ld, lmap->ldap_base, lmap->ldap_scope, - filter, + msgid = ldap_search(lmap->ldap_ld, lmap->ldap_base, + lmap->ldap_scope, filter, (lmap->ldap_attr[0] == NULL ? NULL : lmap->ldap_attr), lmap->ldap_attrsonly); @@ -307,6 +321,66 @@ sm_ldap_search(lmap, key) # if _FFR_LDAP_RECURSION /* +** SM_LDAP_HAS_OBJECTCLASS -- determine if an LDAP entry is part of a +** particular objectClass +** +** Parameters: +** lmap -- pointer to SM_LDAP_STRUCT in use +** entry -- current LDAP entry struct +** ocvalue -- particular objectclass in question. +** may be of form (fee|foo|fum) meaning +** any entry can be part of either fee, +** foo or fum objectclass +** +** Returns: +** true if item has that objectClass +*/ + +static bool +sm_ldap_has_objectclass(lmap, entry, ocvalue) + SM_LDAP_STRUCT *lmap; + LDAPMessage *entry; + char *ocvalue; +{ + char **vals = NULL; + int i; + + if (ocvalue == NULL) + return false; + + vals = ldap_get_values(lmap->ldap_ld, entry, "objectClass"); + if (vals == NULL) + return false; + + for (i = 0; vals[i] != NULL; i++) + { + char *p; + char *q; + + p = q = ocvalue; + while (*p != '\0') + { + while (*p != '\0' && *p != '|') + p++; + + if ((p - q) == strlen(vals[i]) && + sm_strncasecmp(vals[i], q, p - q) == 0) + { + ldap_value_free(vals); + return true; + } + + while (*p == '|') + p++; + q = p; + } + } + + ldap_value_free(vals); + return false; +} + +/* ** SM_LDAP_RESULTS -- return results from an LDAP lookup in result ** ** Parameters: @@ -322,7 +396,7 @@ sm_ldap_search(lmap, key) ** status (sysexit) */ -# define LDAPMAP_ERROR_CLEANUP() \ +# define SM_LDAP_ERROR_CLEANUP() \ { \ if (lmap->ldap_res != NULL) \ { \ @@ -332,58 +406,138 @@ sm_ldap_search(lmap, key) (void) ldap_abandon(lmap->ldap_ld, msgid); \ } -static int -ldapmap_add_recurse(top, item, type, rpool) +static SM_LDAP_RECURSE_ENTRY * +sm_ldap_add_recurse(top, item, type, rpool) SM_LDAP_RECURSE_LIST **top; char *item; int type; SM_RPOOL_T *rpool; { - SM_LDAP_RECURSE_LIST *p; - SM_LDAP_RECURSE_LIST *last; + int n; + int m; + int p; + int insertat; + int moveb; + int oldsizeb; + int rc; + SM_LDAP_RECURSE_ENTRY *newe; + SM_LDAP_RECURSE_ENTRY **olddata; + + /* + ** This code will maintain a list of + ** SM_LDAP_RECURSE_ENTRY structures + ** in ascending order. + */ + + if (*top == NULL) + { + /* Allocate an initial SM_LDAP_RECURSE_LIST struct */ + *top = sm_rpool_malloc_x(rpool, sizeof **top); + (*top)->lr_cnt = 0; + (*top)->lr_size = 0; + (*top)->lr_data = NULL; + } - last = NULL; - for (p = *top; p != NULL; p = p->lr_next) + if ((*top)->lr_cnt >= (*top)->lr_size) { - if (strcasecmp(item, p->lr_search) == 0 && - type == p->lr_type) + /* Grow the list of SM_LDAP_RECURSE_ENTRY ptrs */ + olddata = (*top)->lr_data; + if ((*top)->lr_size == 0) { - /* already on list */ - return 1; + oldsizeb = 0; + (*top)->lr_size = 256; } - last = p; + else + { + oldsizeb = (*top)->lr_size * sizeof *((*top)->lr_data); + (*top)->lr_size *= 2; + } + (*top)->lr_data = sm_rpool_malloc_x(rpool, + (*top)->lr_size * sizeof *((*top)->lr_data)); + if (oldsizeb > 0) + memcpy((*top)->lr_data, olddata, oldsizeb); } - /* not on list, add it */ - p = sm_rpool_malloc_x(rpool, sizeof *p); - p->lr_search = sm_rpool_strdup_x(rpool, item); - p->lr_type = type; - p->lr_next = NULL; - if (last == NULL) - *top = p; + /* + ** Binary search/insert item:type into list. + ** Return current entry pointer if already exists. + */ + + n = 0; + m = (*top)->lr_cnt - 1; + if (m < 0) + insertat = 0; else - last->lr_next = p; - return 0; + insertat = -1; + + while (insertat == -1) + { + p = (m + n) / 2; + + rc = sm_strcasecmp(item, (*top)->lr_data[p]->lr_search); + if (rc == 0) + rc = type - (*top)->lr_data[p]->lr_type; + + if (rc < 0) + m = p - 1; + else if (rc > 0) + n = p + 1; + else + return (*top)->lr_data[p]; + + if (m == -1) + insertat = 0; + else if (n >= (*top)->lr_cnt) + insertat = (*top)->lr_cnt; + else if (m < n) + insertat = m + 1; + } + + /* + ** Not found in list, make room + ** at insert point and add it. + */ + + newe = sm_rpool_malloc_x(rpool, sizeof *newe); + if (newe != NULL) + { + moveb = ((*top)->lr_cnt - insertat) * sizeof *((*top)->lr_data); + if (moveb > 0) + memmove(&((*top)->lr_data[insertat + 1]), + &((*top)->lr_data[insertat]), + moveb); + + newe->lr_search = sm_rpool_strdup_x(rpool, item); + newe->lr_type = type; + newe->lr_done = false; + + ((*top)->lr_data)[insertat] = newe; + (*top)->lr_cnt++; + } + return newe; } int -sm_ldap_results(lmap, msgid, flags, delim, rpool, result, recurse) +sm_ldap_results(lmap, msgid, flags, delim, rpool, result, + resultln, resultsz, recurse) SM_LDAP_STRUCT *lmap; int msgid; int flags; - char delim; + int delim; SM_RPOOL_T *rpool; char **result; + int *resultln; + int *resultsz; SM_LDAP_RECURSE_LIST *recurse; { bool toplevel; int i; - int entries = 0; int statp; int vsize; int ret; int save_errno; char *p; + SM_LDAP_RECURSE_ENTRY *rl; /* Are we the top top level of the search? */ toplevel = (recurse == NULL); @@ -397,20 +551,8 @@ sm_ldap_results(lmap, msgid, flags, delim, rpool, result, recurse) { LDAPMessage *entry; - if (bitset(SM_LDAP_SINGLEMATCH, flags)) - { - entries += ldap_count_entries(lmap->ldap_ld, - lmap->ldap_res); - if (entries > 1) - { - LDAPMAP_ERROR_CLEANUP(); - errno = ENOENT; - return EX_NOTFOUND; - } - } - /* If we don't want multiple values and we have one, break */ - if (delim == '\0' && *result != NULL) + if ((char) delim == '\0' && *result != NULL) break; /* Cycle through all entries */ @@ -438,23 +580,24 @@ sm_ldap_results(lmap, msgid, flags, delim, rpool, result, recurse) { save_errno = sm_ldap_geterrno(lmap->ldap_ld); save_errno += E_LDAPBASE; - LDAPMAP_ERROR_CLEANUP(); + SM_LDAP_ERROR_CLEANUP(); errno = save_errno; return EX_OSERR; } - switch (ldapmap_add_recurse(&recurse, dn, - LDAPMAP_ATTR_NORMAL, - rpool)) + rl = sm_ldap_add_recurse(&recurse, dn, + SM_LDAP_ATTR_DN, + rpool); + + if (rl == NULL) { - case -1: - /* error adding */ ldap_memfree(dn); - LDAPMAP_ERROR_CLEANUP(); + SM_LDAP_ERROR_CLEANUP(); errno = ENOMEM; return EX_OSERR; - - case 1: + } + else if (rl->lr_done) + { /* already on list, skip it */ ldap_memfree(dn); continue; @@ -479,27 +622,54 @@ sm_ldap_results(lmap, msgid, flags, delim, rpool, result, recurse) { char *tmp, *vp_tmp; int type; + char *needobjclass = NULL; + type = SM_LDAP_ATTR_NONE; for (i = 0; lmap->ldap_attr[i] != NULL; i++) { if (sm_strcasecmp(lmap->ldap_attr[i], attr) == 0) { type = lmap->ldap_attr_type[i]; + needobjclass = lmap->ldap_attr_needobjclass[i]; break; } } - if (lmap->ldap_attr[i] == NULL) + + if (bitset(SM_LDAP_USE_ALLATTR, flags) && + type == SM_LDAP_ATTR_NONE) + { + /* URL lookups specify attrs to use */ + type = SM_LDAP_ATTR_NORMAL; + needobjclass = NULL; + } + + if (type == SM_LDAP_ATTR_NONE) { /* attribute not requested */ -# if USING_NETSCAPE_LDAP ldap_memfree(attr); -# endif /* USING_NETSCAPE_LDAP */ - LDAPMAP_ERROR_CLEANUP(); + SM_LDAP_ERROR_CLEANUP(); errno = EFAULT; return EX_SOFTWARE; } + /* + ** For recursion on a particular attribute, + ** we may need to see if this entry is + ** part of a particular objectclass. + ** Also, ignore objectClass attribute. + ** Otherwise we just ignore this attribute. + */ + + if (type == SM_LDAP_ATTR_OBJCLASS || + (needobjclass != NULL && + !sm_ldap_has_objectclass(lmap, entry, + needobjclass))) + { + ldap_memfree(attr); + continue; + } + if (lmap->ldap_attrsonly == LDAPMAP_FALSE) { vals = ldap_get_values(lmap->ldap_ld, @@ -510,18 +680,14 @@ sm_ldap_results(lmap, msgid, flags, delim, rpool, result, recurse) save_errno = sm_ldap_geterrno(lmap->ldap_ld); if (save_errno == LDAP_SUCCESS) { -# if USING_NETSCAPE_LDAP ldap_memfree(attr); -# endif /* USING_NETSCAPE_LDAP */ continue; } /* Must be an error */ save_errno += E_LDAPBASE; -# if USING_NETSCAPE_LDAP ldap_memfree(attr); -# endif /* USING_NETSCAPE_LDAP */ - LDAPMAP_ERROR_CLEANUP(); + SM_LDAP_ERROR_CLEANUP(); errno = save_errno; return EX_TEMPFAIL; } @@ -548,10 +714,7 @@ sm_ldap_results(lmap, msgid, flags, delim, rpool, result, recurse) { if (lmap->ldap_attrsonly == LDAPMAP_FALSE) ldap_value_free(vals); - -# if USING_NETSCAPE_LDAP ldap_memfree(attr); -# endif /* USING_NETSCAPE_LDAP */ continue; } @@ -560,24 +723,36 @@ sm_ldap_results(lmap, msgid, flags, delim, rpool, result, recurse) ** return first found. */ - if (delim == '\0') + if ((char) delim == '\0') { + if (*result != NULL) + { + /* already have a value */ + break; + } + + if (bitset(SM_LDAP_SINGLEMATCH, + flags) && + *result != NULL) + { + /* only wanted one match */ + SM_LDAP_ERROR_CLEANUP(); + errno = ENOENT; + return EX_NOTFOUND; + } + if (lmap->ldap_attrsonly == LDAPMAP_TRUE) { *result = sm_rpool_strdup_x(rpool, attr); -# if USING_NETSCAPE_LDAP ldap_memfree(attr); -# endif /* USING_NETSCAPE_LDAP */ break; } if (vals[0] == NULL) { ldap_value_free(vals); -# if USING_NETSCAPE_LDAP ldap_memfree(attr); -# endif /* USING_NETSCAPE_LDAP */ continue; } @@ -596,9 +771,7 @@ sm_ldap_results(lmap, msgid, flags, delim, rpool, result, recurse) sm_strlcpy(*result, vals[0], vsize); ldap_value_free(vals); -# if USING_NETSCAPE_LDAP ldap_memfree(attr); -# endif /* USING_NETSCAPE_LDAP */ break; } @@ -610,94 +783,137 @@ sm_ldap_results(lmap, msgid, flags, delim, rpool, result, recurse) attr); else { + if (bitset(SM_LDAP_SINGLEMATCH, + flags) && + *result != NULL) + { + /* only wanted one match */ + SM_LDAP_ERROR_CLEANUP(); + errno = ENOENT; + return EX_NOTFOUND; + } + vsize = strlen(*result) + strlen(attr) + 2; tmp = sm_rpool_malloc_x(rpool, vsize); (void) sm_snprintf(tmp, vsize, "%s%c%s", - *result, delim, + *result, (char) delim, attr); *result = tmp; } -# if USING_NETSCAPE_LDAP ldap_memfree(attr); -# endif /* USING_NETSCAPE_LDAP */ continue; } /* - ** If there is more than one, - ** munge then into a map_coldelim - ** separated string + ** If there is more than one, munge then + ** into a map_coldelim separated string. + ** If we are recursing we may have an entry + ** with no 'normal' values to put in the + ** string. + ** This is not an error. */ + if (type == SM_LDAP_ATTR_NORMAL && + bitset(SM_LDAP_SINGLEMATCH, flags) && + *result != NULL) + { + /* only wanted one match */ + SM_LDAP_ERROR_CLEANUP(); + errno = ENOENT; + return EX_NOTFOUND; + } + vsize = 0; for (i = 0; vals[i] != NULL; i++) { - if (type == LDAPMAP_ATTR_DN || - type == LDAPMAP_ATTR_FILTER || - type == LDAPMAP_ATTR_URL) + if (type == SM_LDAP_ATTR_DN || + type == SM_LDAP_ATTR_FILTER || + type == SM_LDAP_ATTR_URL) { - if (ldapmap_add_recurse(&recurse, + /* add to recursion */ + if (sm_ldap_add_recurse(&recurse, vals[i], - type) < 0) + type, + rpool) == NULL) { - LDAPMAP_ERROR_CLEANUP(); + SM_LDAP_ERROR_CLEANUP(); errno = ENOMEM; return EX_OSERR; } - } - if (type != LDAPMAP_ATTR_NORMAL) - { -# if USING_NETSCAPE_LDAP - ldap_memfree(attr); -# endif /* USING_NETSCAPE_LDAP */ continue; } + vsize += strlen(vals[i]) + 1; if (lmap->ldap_attrsep != '\0') vsize += strlen(attr) + 1; } - vp_tmp = sm_rpool_malloc_x(rpool, vsize); - *vp_tmp = '\0'; - p = vp_tmp; - for (i = 0; vals[i] != NULL; i++) + /* + ** Create/Append to string any normal + ** attribute values. Otherwise, just free + ** memory and move on to the next + ** attribute in this entry. + */ + + if (type == SM_LDAP_ATTR_NORMAL && vsize > 0) { - if (lmap->ldap_attrsep != '\0') + char *pe; + + /* Grow result string if needed */ + if ((*resultln + vsize) >= *resultsz) { - p += sm_strlcpy(p, attr, - vsize - (p - vp_tmp)); - *p++ = lmap->ldap_attrsep; + while ((*resultln + vsize) >= *resultsz) + { + if (*resultsz == 0) + *resultsz = 1024; + else + *resultsz *= 2; + } + + vp_tmp = sm_rpool_malloc_x(rpool, *resultsz); + *vp_tmp = '\0'; + + if (*result != NULL) + sm_strlcpy(vp_tmp, + *result, + *resultsz); + *result = vp_tmp; } - p += sm_strlcpy(p, vals[i], - vsize - (p - vp_tmp)); - if (p >= vp_tmp + vsize) + + p = *result + *resultln; + pe = *result + *resultsz; + + for (i = 0; vals[i] != NULL; i++) { - /* Internal error: buffer too small for LDAP values */ - LDAPMAP_ERROR_CLEANUP(); - errno = ENOMEM; - return EX_OSERR; + if (*resultln > 0) + *p++ = (char) delim; + + if (lmap->ldap_attrsep != '\0') + { + p += sm_strlcpy(p, attr, + pe - p); + if (p < pe) + *p++ = lmap->ldap_attrsep; + } + + p += sm_strlcpy(p, vals[i], + pe - p); + *resultln = p - (*result); + if (p >= pe) + { + /* Internal error: buffer too small for LDAP values */ + SM_LDAP_ERROR_CLEANUP(); + errno = ENOMEM; + return EX_OSERR; + } } - if (vals[i + 1] != NULL) - *p++ = delim; } ldap_value_free(vals); -# if USING_NETSCAPE_LDAP ldap_memfree(attr); -# endif /* USING_NETSCAPE_LDAP */ - if (*result == NULL) - { - *result = vp_tmp; - continue; - } - vsize = strlen(*result) + strlen(vp_tmp) + 2; - tmp = sm_rpool_malloc_x(rpool, vsize); - (void) sm_snprintf(tmp, vsize, "%s%c%s", - *result, delim, vp_tmp); - *result = tmp; } save_errno = sm_ldap_geterrno(lmap->ldap_ld); @@ -715,13 +931,16 @@ sm_ldap_results(lmap, msgid, flags, delim, rpool, result, recurse) { /* Must be an error */ save_errno += E_LDAPBASE; - LDAPMAP_ERROR_CLEANUP(); + SM_LDAP_ERROR_CLEANUP(); errno = save_errno; return EX_TEMPFAIL; } + /* mark this DN as done */ + rl->lr_done = true; + /* We don't want multiple values and we have one */ - if (delim == '\0' && *result != NULL) + if ((char) delim == '\0' && *result != NULL) break; } save_errno = sm_ldap_geterrno(lmap->ldap_ld); @@ -730,7 +949,7 @@ sm_ldap_results(lmap, msgid, flags, delim, rpool, result, recurse) { /* Must be an error */ save_errno += E_LDAPBASE; - LDAPMAP_ERROR_CLEANUP(); + SM_LDAP_ERROR_CLEANUP(); errno = save_errno; return EX_TEMPFAIL; } @@ -754,13 +973,18 @@ sm_ldap_results(lmap, msgid, flags, delim, rpool, result, recurse) #endif /* LDAP_SERVER_DOWN */ case LDAP_TIMEOUT: case LDAP_UNAVAILABLE: - /* server disappeared, try reopen on next search */ + + /* + ** server disappeared, + ** try reopen on next search + */ + statp = EX_RESTART; break; } save_errno += E_LDAPBASE; } - LDAPMAP_ERROR_CLEANUP(); + SM_LDAP_ERROR_CLEANUP(); errno = save_errno; return statp; } @@ -773,7 +997,7 @@ sm_ldap_results(lmap, msgid, flags, delim, rpool, result, recurse) if (toplevel) { - SM_LDAP_RECURSE_LIST *rl; + int rlidx; /* ** Spin through the built-up recurse list at the top @@ -784,42 +1008,50 @@ sm_ldap_results(lmap, msgid, flags, delim, rpool, result, recurse) ** will be expanded by the top level. */ - for (rl = recurse; rl != NULL; rl = rl->lr_next) + for (rlidx = 0; recurse != NULL && rlidx < recurse->lr_cnt; rlidx++) { + int newflags; int sid; int status; - if (rl->lr_type == LDAPMAP_ATTR_NORMAL) + rl = recurse->lr_data[rlidx]; + + newflags = flags; + if (rl->lr_done) { /* already expanded */ continue; } - else if (rl->lr_type == LDAPMAP_ATTR_DN) + + if (rl->lr_type == SM_LDAP_ATTR_DN) { /* do DN search */ sid = ldap_search(lmap->ldap_ld, rl->lr_search, lmap->ldap_scope, "(objectClass=*)", - lmap->ldap_attr_final, + (lmap->ldap_attr[0] == NULL ? + NULL : lmap->ldap_attr), lmap->ldap_attrsonly); } - else if (rl->lr_type == LDAPMAP_ATTR_FILTER) + else if (rl->lr_type == SM_LDAP_ATTR_FILTER) { /* do new search */ sid = ldap_search(lmap->ldap_ld, lmap->ldap_base, lmap->ldap_scope, rl->lr_search, - lmap->ldap_attr_final, + (lmap->ldap_attr[0] == NULL ? + NULL : lmap->ldap_attr), lmap->ldap_attrsonly); } - else if (rl->lr_type == LDAPMAP_ATTR_URL) + else if (rl->lr_type == SM_LDAP_ATTR_URL) { /* do new URL search */ sid = ldap_url_search(lmap->ldap_ld, rl->lr_search, lmap->ldap_attrsonly); + newflags |= SM_LDAP_USE_ALLATTR; } else { @@ -840,7 +1072,12 @@ sm_ldap_results(lmap, msgid, flags, delim, rpool, result, recurse) #endif /* LDAP_SERVER_DOWN */ case LDAP_TIMEOUT: case LDAP_UNAVAILABLE: - /* server disappeared, try reopen on next search */ + + /* + ** server disappeared, + ** try reopen on next search + */ + statp = EX_RESTART; break; } @@ -848,8 +1085,9 @@ sm_ldap_results(lmap, msgid, flags, delim, rpool, result, recurse) return statp; } - status = sm_ldap_results(lmap, sid, flags, delim, - rpool, result, recurse); + status = sm_ldap_results(lmap, sid, newflags, delim, + rpool, result, resultln, + resultsz, recurse); save_errno = errno; if (status != EX_OK && status != EX_NOTFOUND) { @@ -858,7 +1096,10 @@ sm_ldap_results(lmap, msgid, flags, delim, rpool, result, recurse) } /* Mark as done */ - rl->lr_type = LDAPMAP_ATTR_NORMAL; + rl->lr_done = true; + + /* Reset rlidx as new items may have been added */ + rlidx = -1; } } return statp; @@ -907,6 +1148,13 @@ sm_ldap_setopts(ld, lmap) SM_LDAP_STRUCT *lmap; { # if USE_LDAP_SET_OPTION +# if _FFR_LDAP_SETVERSION + if (lmap->ldap_version != 0) + { + ldap_set_option(ld, LDAP_OPT_PROTOCOL_VERSION, + &lmap->ldap_version); + } +# endif /* _FFR_LDAP_SETVERSION */ ldap_set_option(ld, LDAP_OPT_DEREF, &lmap->ldap_deref); if (bitset(LDAP_OPT_REFERRALS, lmap->ldap_options)) ldap_set_option(ld, LDAP_OPT_REFERRALS, LDAP_OPT_ON); diff --git a/contrib/sendmail/libsm/local.h b/contrib/sendmail/libsm/local.h index f97859e1c7cb..943321363c22 100644 --- a/contrib/sendmail/libsm/local.h +++ b/contrib/sendmail/libsm/local.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000-2001 Sendmail, Inc. and its suppliers. + * Copyright (c) 2000-2002 Sendmail, Inc. and its suppliers. * All rights reserved. * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. @@ -11,7 +11,7 @@ * forth in the LICENSE file which can be found at the top level of * the sendmail distribution. * - * $Id: local.h,v 1.48 2001/05/14 20:42:29 gshapiro Exp $ + * $Id: local.h,v 1.51 2002/02/20 02:40:24 ca Exp $ */ /* @@ -132,25 +132,9 @@ extern bool Sm_IO_DidInit; (fp)->f_ub.smb_base = NULL; \ } -/* Test for an fgetln() buffer. */ -#define HASLB(fp) ((fp)->f_lb.smb_base != NULL) -#define FREELB(fp) \ -{ \ - sm_free((char *)(fp)->f_lb.smb_base); \ - (fp)->f_lb.smb_base = NULL; \ -} - -struct sm_io_obj -{ - int file; -}; - extern const char SmFileMagic[]; -#ifndef ALIGNBYTES -# define ALIGNBYTES (sizeof(long) - 1) -# define ALIGN(p) (((unsigned long)(p) + ALIGNBYTES) & ~ALIGNBYTES) -#endif /* ALIGNBYTES */ +#define SM_ALIGN(p) (((unsigned long)(p) + SM_ALIGN_BITS) & ~SM_ALIGN_BITS) #define sm_io_flockfile(fp) ((void) 0) #define sm_io_funlockfile(fp) ((void) 0) diff --git a/contrib/sendmail/libsm/mbdb.c b/contrib/sendmail/libsm/mbdb.c index fcb51170afba..b2254a32f135 100644 --- a/contrib/sendmail/libsm/mbdb.c +++ b/contrib/sendmail/libsm/mbdb.c @@ -8,7 +8,7 @@ */ #include <sm/gen.h> -SM_RCSID("@(#)$Id: mbdb.c,v 1.28 2002/01/07 23:29:43 gshapiro Exp $") +SM_RCSID("@(#)$Id: mbdb.c,v 1.36 2002/03/25 18:08:20 gshapiro Exp $") #include <sys/param.h> @@ -26,6 +26,9 @@ SM_RCSID("@(#)$Id: mbdb.c,v 1.28 2002/01/07 23:29:43 gshapiro Exp $") #include <sm/heap.h> #include <sm/mbdb.h> #include <sm/string.h> +# ifdef EX_OK +# undef EX_OK /* for SVr4.2 SMP */ +# endif /* EX_OK */ #include <sm/sysexits.h> #if LDAPMAP @@ -207,6 +210,20 @@ sm_mbdb_frompw(user, pw) ** none. */ +#if _FFR_HANDLE_ISO8859_GECOS +static char Latin1ToASCII[128] = +{ + 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, + 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 33, + 99, 80, 36, 89, 124, 36, 34, 99, 97, 60, 45, 45, 114, 45, 111, 42, + 50, 51, 39, 117, 80, 46, 44, 49, 111, 62, 42, 42, 42, 63, 65, 65, + 65, 65, 65, 65, 65, 67, 69, 69, 69, 69, 73, 73, 73, 73, 68, 78, 79, + 79, 79, 79, 79, 88, 79, 85, 85, 85, 85, 89, 80, 66, 97, 97, 97, 97, + 97, 97, 97, 99, 101, 101, 101, 101, 105, 105, 105, 105, 100, 110, + 111, 111, 111, 111, 111, 47, 111, 117, 117, 117, 117, 121, 112, 121 +}; +#endif /* _FFR_HANDLE_ISO8859_GECOS */ + void sm_pwfullname(gecos, user, buf, buflen) register char *gecos; @@ -237,7 +254,14 @@ sm_pwfullname(gecos, user, buf, buflen) bp += strlen(bp); } else - *bp++ = *p; + { +#if _FFR_HANDLE_ISO8859_GECOS + if ((unsigned char) *p >= 128) + *bp++ = Latin1ToASCII[(unsigned char) *p - 128]; + else +#endif /* _FFR_HANDLE_ISO8859_GECOS */ + *bp++ = *p; + } } *bp = '\0'; } @@ -409,13 +433,13 @@ mbdb_ldap_initialize(arg) { sm_ldap_clear(&LDAPLMAP); LDAPLMAP.ldap_base = MBDB_DEFAULT_LDAP_BASEDN; - LDAPLMAP.ldap_host = MBDB_DEFAULT_LDAP_SERVER; + LDAPLMAP.ldap_target = MBDB_DEFAULT_LDAP_SERVER; LDAPLMAP.ldap_filter = MBDB_LDAP_FILTER; /* Only want one match */ LDAPLMAP.ldap_sizelimit = 1; - /* interpolate new ldap_base and ldap_host from arg if given */ + /* interpolate new ldap_base and ldap_target from arg if given */ if (arg != NULL && *arg != '\0') { char *new; @@ -431,7 +455,7 @@ mbdb_ldap_initialize(arg) if (sep != NULL) { *sep++ = '\0'; - LDAPLMAP.ldap_host = sep; + LDAPLMAP.ldap_target = sep; } LDAPLMAP.ldap_base = new; } @@ -568,9 +592,7 @@ mbdb_ldap_lookup(name, user) errno = sm_ldap_geterrno(LDAPLMAP.ldap_ld); if (errno == LDAP_SUCCESS) { -# if USING_NETSCAPE_LDAP ldap_memfree(attr); -# endif /* USING_NETSCAPE_LDAP */ continue; } @@ -670,9 +692,7 @@ mbdb_ldap_lookup(name, user) skip: ldap_value_free(vals); -# if USING_NETSCAPE_LDAP ldap_memfree(attr); -# endif /* USING_NETSCAPE_LDAP */ } errno = sm_ldap_geterrno(LDAPLMAP.ldap_ld); @@ -699,9 +719,7 @@ skip: save_errno = errno; if (attr != NULL) { -# if USING_NETSCAPE_LDAP ldap_memfree(attr); -# endif /* USING_NETSCAPE_LDAP */ attr = NULL; } if (LDAPLMAP.ldap_res != NULL) diff --git a/contrib/sendmail/libsm/smstdio.c b/contrib/sendmail/libsm/smstdio.c index 758c93685e69..879fcd25f400 100644 --- a/contrib/sendmail/libsm/smstdio.c +++ b/contrib/sendmail/libsm/smstdio.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000-2001 Sendmail, Inc. and its suppliers. + * Copyright (c) 2000-2002 Sendmail, Inc. and its suppliers. * All rights reserved. * * By using this file, you agree to the terms and conditions set @@ -8,11 +8,12 @@ */ #include <sm/gen.h> -SM_IDSTR(id, "@(#)$Id: smstdio.c,v 1.29 2001/09/11 04:04:49 gshapiro Exp $") +SM_IDSTR(id, "@(#)$Id: smstdio.c,v 1.32 2002/02/23 20:18:36 gshapiro Exp $") #include <unistd.h> #include <stdio.h> #include <fcntl.h> #include <errno.h> +#include <sys/stat.h> #include <sm/assert.h> #include <sm/io.h> #include <sm/string.h> @@ -264,6 +265,22 @@ sm_stdiogetinfo(fp, what, valp) { switch (what) { + case SM_IO_WHAT_SIZE: + { + int fd; + struct stat st; + + if (fp->f_cookie == NULL) + setup(fp); + fd = fileno((FILE *) fp->f_cookie); + if (fd < 0) + return -1; + if (fstat(fd, &st) == 0) + return st.st_size; + else + return -1; + } + case SM_IO_WHAT_MODE: default: errno = EINVAL; diff --git a/contrib/sendmail/libsm/sscanf.c b/contrib/sendmail/libsm/sscanf.c index 178e76be94f4..168bcfdddd69 100644 --- a/contrib/sendmail/libsm/sscanf.c +++ b/contrib/sendmail/libsm/sscanf.c @@ -13,7 +13,7 @@ */ #include <sm/gen.h> -SM_RCSID("@(#)$Id: sscanf.c,v 1.24 2001/09/11 04:04:49 gshapiro Exp $") +SM_RCSID("@(#)$Id: sscanf.c,v 1.25 2002/02/01 02:28:00 ca Exp $") #include <string.h> #include <sm/varargs.h> #include <sm/io.h> @@ -93,7 +93,6 @@ sm_io_sscanf(str, fmt, va_alist) fake.f_type = "sm_io_sscanf:fake"; fake.f_flushfp = NULL; fake.f_ub.smb_base = NULL; - fake.f_lb.smb_base = NULL; fake.f_timeout = SM_TIME_FOREVER; fake.f_timeoutstate = SM_TIME_BLOCK; SM_VA_START(ap, fmt); diff --git a/contrib/sendmail/libsm/stdio.c b/contrib/sendmail/libsm/stdio.c index e688fb96ed9d..c3ab72d0124b 100644 --- a/contrib/sendmail/libsm/stdio.c +++ b/contrib/sendmail/libsm/stdio.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000-2001 Sendmail, Inc. and its suppliers. + * Copyright (c) 2000-2002 Sendmail, Inc. and its suppliers. * All rights reserved. * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. @@ -13,7 +13,7 @@ */ #include <sm/gen.h> -SM_RCSID("@(#)$Id: stdio.c,v 1.52 2001/09/18 21:45:23 gshapiro Exp $") +SM_RCSID("@(#)$Id: stdio.c,v 1.56 2002/04/03 21:55:15 ca Exp $") #include <unistd.h> #include <errno.h> #include <fcntl.h> @@ -338,24 +338,31 @@ sm_stdgetinfo(fp, what, valp) case SM_IO_WHAT_FD: return fp->f_file; + case SM_IO_WHAT_SIZE: + { + struct stat st; + + if (fstat(fp->f_file, &st) == 0) + return st.st_size; + else + return -1; + } + case SM_IO_IS_READABLE: - { - fd_set readfds; - struct timeval timeout; - - FD_ZERO(&readfds); - SM_FD_SET(fp->f_file, &readfds); - timeout.tv_sec = 0; - timeout.tv_usec = 0; - if (select(fp->f_file + 1, - FDSET_CAST &readfds, - NULL, - NULL, - &timeout) > 0 && - SM_FD_ISSET(fp->f_file, &readfds)) - return 1; - return 0; - } + { + fd_set readfds; + struct timeval timeout; + + FD_ZERO(&readfds); + SM_FD_SET(fp->f_file, &readfds); + timeout.tv_sec = 0; + timeout.tv_usec = 0; + if (select(fp->f_file + 1, FDSET_CAST &readfds, + NULL, NULL, &timeout) > 0 && + SM_FD_ISSET(fp->f_file, &readfds)) + return 1; + return 0; + } default: errno = EINVAL; @@ -364,19 +371,19 @@ sm_stdgetinfo(fp, what, valp) } /* -** SM_STDFDOPEN -- open file by primative 'fd' rather than pathname +** SM_STDFDOPEN -- open file by primitive 'fd' rather than pathname ** ** I/O function to handle fdopen() stdio equivalence. The rest of ** the functions are the same as the sm_stdopen() above. ** ** Parameters: ** fp -- the file pointer to be associated with the open -** name -- the primative file descriptor for association +** name -- the primitive file descriptor for association ** flags -- indicates type of access methods ** rpool -- ignored ** ** Results: -** Success: primative file descriptor value +** Success: primitive file descriptor value ** Failure: -1 and sets errno */ diff --git a/contrib/sendmail/libsm/strio.c b/contrib/sendmail/libsm/strio.c index 203d192bd3f6..2b7e9d0cfe96 100644 --- a/contrib/sendmail/libsm/strio.c +++ b/contrib/sendmail/libsm/strio.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000-2001 Sendmail, Inc. and its suppliers. + * Copyright (c) 2000-2002 Sendmail, Inc. and its suppliers. * All rights reserved. * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. @@ -13,7 +13,7 @@ */ #include <sm/gen.h> -SM_IDSTR(id, "@(#)$Id: strio.c,v 1.40 2001/09/11 04:04:49 gshapiro Exp $") +SM_IDSTR(id, "@(#)$Id: strio.c,v 1.42 2002/02/11 23:05:50 gshapiro Exp $") #include <stdlib.h> #include <unistd.h> #include <fcntl.h> @@ -31,11 +31,12 @@ SM_IDSTR(id, "@(#)$Id: strio.c,v 1.40 2001/09/11 04:04:49 gshapiro Exp $") struct sm_str_obj { - char *strio_base; - char *strio_end; - size_t strio_size; - size_t strio_offset; - int strio_flags; + char *strio_base; + char *strio_end; + size_t strio_size; + size_t strio_offset; + int strio_flags; + const void *strio_rpool; }; typedef struct sm_str_obj SM_STR_OBJ_T; @@ -109,7 +110,7 @@ sm_strread(fp, buf, n) ** ** Parameters: ** fp -- the file pointer -** buf -- location of data for writting +** buf -- location of data for writing ** n -- number of bytes to write ** ** Returns: @@ -200,8 +201,8 @@ reseek: ** ** Parameters: ** fp -- file pointer open to be associated with -** info -- flags for methods of access (was mode) -** flags -- ignored +** info -- initial contents (NULL for none) +** flags -- flags for methods of access (was mode) ** rpool -- resource pool to use memory from (if applicable) ** ** Results: @@ -217,24 +218,23 @@ sm_stropen(fp, info, flags, rpool) const void *rpool; { register SM_STR_OBJ_T *s; - int *strmode = (int *) info; #if SM_RPOOL s = sm_rpool_malloc_x(rpool, sizeof(SM_STR_OBJ_T)); #else /* SM_RPOOL */ s = sm_malloc(sizeof(SM_STR_OBJ_T)); if (s == NULL) - { - errno = ENOMEM; return -1; - } #endif /* SM_RPOOL */ fp->f_cookie = s; + s->strio_rpool = rpool; s->strio_offset = 0; - s->strio_base = 0; + s->strio_size = 0; + s->strio_base = NULL; s->strio_end = 0; - switch (*strmode) + + switch (flags) { case SM_IO_RDWR: s->strio_flags = SMRW; @@ -246,11 +246,32 @@ sm_stropen(fp, info, flags, rpool) s->strio_flags = SMWR; break; case SM_IO_APPEND: + if (s->strio_rpool == NULL) + sm_free(s); + errno = EINVAL; return -1; default: + if (s->strio_rpool == NULL) + sm_free(s); errno = EINVAL; return -1; } + + if (info != NULL) + { + s->strio_base = sm_strdup_x(info); + if (s->strio_base == NULL) + { + int save_errno = errno; + + if (s->strio_rpool == NULL) + sm_free(s); + errno = save_errno; + return -1; + } + s->strio_size = strlen(info); + s->strio_end = s->strio_base + s->strio_size; + } return 0; } diff --git a/contrib/sendmail/libsm/strl.c b/contrib/sendmail/libsm/strl.c index fbf6c063d859..ec9a81be266c 100644 --- a/contrib/sendmail/libsm/strl.c +++ b/contrib/sendmail/libsm/strl.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999-2001 Sendmail, Inc. and its suppliers. + * Copyright (c) 1999-2002 Sendmail, Inc. and its suppliers. * All rights reserved. * * By using this file, you agree to the terms and conditions set @@ -9,7 +9,7 @@ */ #include <sm/gen.h> -SM_RCSID("@(#)$Id: strl.c,v 1.29 2001/10/03 16:09:32 ca Exp $") +SM_RCSID("@(#)$Id: strl.c,v 1.31 2002/01/20 01:41:25 gshapiro Exp $") #include <sm/config.h> #include <sm/string.h> @@ -229,6 +229,7 @@ sm_strlcpyn(dst, len, n, va_alist) i = 0; while (n-- > 0) i += strlen(SM_VA_ARG(ap, char *)); + SM_VA_END(ap); return i; } @@ -251,9 +252,11 @@ sm_strlcpyn(dst, len, n, va_alist) j += strlen(str + i); while (n-- > 0) j += strlen(SM_VA_ARG(ap, char *)); + SM_VA_END(ap); return j; } } + SM_VA_END(ap); dst[j] = '\0'; /* terminate dst; there is space since j < len */ return j; diff --git a/contrib/sendmail/libsm/t-event.c b/contrib/sendmail/libsm/t-event.c index b562da7ae185..3da8789a2941 100644 --- a/contrib/sendmail/libsm/t-event.c +++ b/contrib/sendmail/libsm/t-event.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001 Sendmail, Inc. and its suppliers. + * Copyright (c) 2001-2002 Sendmail, Inc. and its suppliers. * All rights reserved. * * By using this file, you agree to the terms and conditions set @@ -8,13 +8,13 @@ */ #include <sm/gen.h> -SM_RCSID("@(#)$Id: t-event.c,v 1.7 2001/09/11 04:04:49 gshapiro Exp $") +SM_RCSID("@(#)$Id: t-event.c,v 1.9 2002/03/19 00:26:21 ca Exp $") #include <stdio.h> #include <stdlib.h> #include <unistd.h> -#include <sys/wait.h> +# include <sys/wait.h> #if SM_CONF_SETITIMER # include <sys/time.h> #endif /* SM_CONF_SETITIMER */ @@ -51,7 +51,7 @@ main(argc, argv) SM_EVENT *ev; sm_test_begin(argc, argv, "test event handling"); - fprintf(stdout, "this test may hang. If there is no output within twelve seconds, abort it\nand recompile with -DSM_CONF_SETITIMER=%d\n", + fprintf(stdout, "This test may hang. If there is no output within twelve seconds, abort it\nand recompile with -DSM_CONF_SETITIMER=%d\n", SM_CONF_SETITIMER == 0 ? 1 : 0); sleep(1); SM_TEST(1 == 1); diff --git a/contrib/sendmail/libsm/t-fopen.c b/contrib/sendmail/libsm/t-fopen.c index 4fbbc29e6b77..2d3839a34d9a 100644 --- a/contrib/sendmail/libsm/t-fopen.c +++ b/contrib/sendmail/libsm/t-fopen.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000-2001 Sendmail, Inc. and its suppliers. + * Copyright (c) 2000-2002 Sendmail, Inc. and its suppliers. * All rights reserved. * * By using this file, you agree to the terms and conditions set @@ -8,7 +8,7 @@ */ #include <sm/gen.h> -SM_IDSTR(id, "@(#)$Id: t-fopen.c,v 1.8 2001/09/11 04:04:49 gshapiro Exp $") +SM_IDSTR(id, "@(#)$Id: t-fopen.c,v 1.9 2002/02/06 23:57:45 ca Exp $") #include <fcntl.h> #include <sm/io.h> @@ -20,6 +20,7 @@ main(argc, argv) int argc; char *argv[]; { + int m, r; SM_FILE_T *out; sm_test_begin(argc, argv, "test sm_io_fopen"); @@ -28,6 +29,9 @@ main(argc, argv) if (out != NULL) { (void) sm_io_fprintf(out, SM_TIME_DEFAULT, "foo\n"); + r = sm_io_getinfo(out, SM_IO_WHAT_MODE, &m); + SM_TEST(r == 0); + SM_TEST(m == SM_IO_WRONLY); sm_io_close(out, SM_TIME_DEFAULT); } return sm_test_end(); diff --git a/contrib/sendmail/libsm/t-shm.c b/contrib/sendmail/libsm/t-shm.c index a739ad10b3b0..5da07c1e369b 100644 --- a/contrib/sendmail/libsm/t-shm.c +++ b/contrib/sendmail/libsm/t-shm.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000-2001 Sendmail, Inc. and its suppliers. + * Copyright (c) 2000-2002 Sendmail, Inc. and its suppliers. * All rights reserved. * * By using this file, you agree to the terms and conditions set @@ -8,7 +8,7 @@ */ #include <sm/gen.h> -SM_RCSID("@(#)$Id: t-shm.c,v 1.17 2001/09/11 04:04:49 gshapiro Exp $") +SM_RCSID("@(#)$Id: t-shm.c,v 1.18 2002/01/31 04:11:41 ca Exp $") #include <stdio.h> @@ -230,6 +230,7 @@ main(argc, argv) else { pid_t pid; + extern int SmTestNumErrors; if ((pid = fork()) < 0) { @@ -250,6 +251,8 @@ main(argc, argv) (void) wait(&status); } SM_TEST(r == 0); + if (SmTestNumErrors > 0) + printf("add -DSM_CONF_SHM=0 to confENVDEF in devtools/Site/site.config.m4\nand start over.\n"); return sm_test_end(); } return r; diff --git a/contrib/sendmail/libsm/t-types.c b/contrib/sendmail/libsm/t-types.c index b1adb0cc3652..cb07f67571bf 100644 --- a/contrib/sendmail/libsm/t-types.c +++ b/contrib/sendmail/libsm/t-types.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000-2001 Sendmail, Inc. and its suppliers. + * Copyright (c) 2000-2002 Sendmail, Inc. and its suppliers. * All rights reserved. * * By using this file, you agree to the terms and conditions set @@ -8,7 +8,7 @@ */ #include <sm/gen.h> -SM_IDSTR(id, "@(#)$Id: t-types.c,v 1.16 2001/09/11 04:04:49 gshapiro Exp $") +SM_IDSTR(id, "@(#)$Id: t-types.c,v 1.18 2002/03/13 17:29:53 gshapiro Exp $") #include <sm/limits.h> #include <sm/io.h> diff --git a/contrib/sendmail/libsm/vsscanf.c b/contrib/sendmail/libsm/vsscanf.c index 3de2224795c7..498f44992e45 100644 --- a/contrib/sendmail/libsm/vsscanf.c +++ b/contrib/sendmail/libsm/vsscanf.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000-2001 Sendmail, Inc. and its suppliers. + * Copyright (c) 2000-2002 Sendmail, Inc. and its suppliers. * All rights reserved. * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. @@ -13,7 +13,7 @@ */ #include <sm/gen.h> -SM_RCSID("@(#)$Id: vsscanf.c,v 1.22 2001/09/11 04:04:49 gshapiro Exp $") +SM_RCSID("@(#)$Id: vsscanf.c,v 1.23 2002/02/01 02:28:00 ca Exp $") #include <string.h> #include <sm/io.h> @@ -77,7 +77,6 @@ sm_vsscanf(str, fmt, ap) fake.f_bf.smb_size = fake.f_r = strlen(str); fake.f_read = sm_eofread; fake.f_ub.smb_base = NULL; - fake.f_lb.smb_base = NULL; fake.f_close = NULL; fake.f_open = NULL; fake.f_write = NULL; diff --git a/contrib/sendmail/libsm/wsetup.c b/contrib/sendmail/libsm/wsetup.c index 16b1b0e715e0..400553e17c8c 100644 --- a/contrib/sendmail/libsm/wsetup.c +++ b/contrib/sendmail/libsm/wsetup.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000-2001 Sendmail, Inc. and its suppliers. + * Copyright (c) 2000-2002 Sendmail, Inc. and its suppliers. * All rights reserved. * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. @@ -13,14 +13,14 @@ */ #include <sm/gen.h> -SM_RCSID("@(#)$Id: wsetup.c,v 1.19 2001/09/11 04:04:49 gshapiro Exp $") +SM_RCSID("@(#)$Id: wsetup.c,v 1.20 2002/02/07 18:02:45 ca Exp $") #include <stdlib.h> #include <errno.h> #include <sm/io.h> #include "local.h" /* -** SM_WSETUP -- check writting is safe +** SM_WSETUP -- check writing is safe ** ** Various output routines call wsetup to be sure it is safe to write, ** because either flags does not include SMMWR, or buf is NULL. @@ -55,6 +55,8 @@ sm_wsetup(fp) /* clobber any ungetc data */ if (HASUB(fp)) FREEUB(fp); + + /* discard read buffer */ fp->f_flags &= ~(SMRD|SMFEOF); fp->f_r = 0; fp->f_p = fp->f_bf.smb_base; |