summaryrefslogtreecommitdiffstats
path: root/contrib/sendmail/libsm
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/sendmail/libsm')
-rw-r--r--contrib/sendmail/libsm/Makefile4
-rw-r--r--contrib/sendmail/libsm/Makefile.m456
-rw-r--r--contrib/sendmail/libsm/config.c13
-rw-r--r--contrib/sendmail/libsm/exc.c26
-rw-r--r--contrib/sendmail/libsm/exc.html4
-rw-r--r--contrib/sendmail/libsm/findfp.c9
-rw-r--r--contrib/sendmail/libsm/flags.c9
-rw-r--r--contrib/sendmail/libsm/ldap.c134
-rw-r--r--contrib/sendmail/libsm/local.h4
-rw-r--r--contrib/sendmail/libsm/memstat.c7
-rw-r--r--contrib/sendmail/libsm/snprintf.c3
-rw-r--r--contrib/sendmail/libsm/t-memstat.c21
-rw-r--r--contrib/sendmail/libsm/t-qic.c235
-rw-r--r--contrib/sendmail/libsm/t-sem.c10
-rw-r--r--contrib/sendmail/libsm/util.c250
-rw-r--r--contrib/sendmail/libsm/vfscanf.c6
16 files changed, 686 insertions, 105 deletions
diff --git a/contrib/sendmail/libsm/Makefile b/contrib/sendmail/libsm/Makefile
index c6c1a29..e7b64ca 100644
--- a/contrib/sendmail/libsm/Makefile
+++ b/contrib/sendmail/libsm/Makefile
@@ -1,4 +1,4 @@
-# $Id: Makefile,v 1.1 2000/03/27 19:26:48 dmoen Exp $
+# $Id: Makefile,v 1.2 2006/08/16 21:06:30 ca Exp $
SHELL= /bin/sh
BUILD= ./Build
@@ -10,6 +10,8 @@ clean: FRC
$(SHELL) $(BUILD) $(OPTIONS) $@
install: FRC
$(SHELL) $(BUILD) $(OPTIONS) $@
+check: FRC
+ $(SHELL) $(BUILD) $(OPTIONS) $@
fresh: FRC
$(SHELL) $(BUILD) $(OPTIONS) -c
diff --git a/contrib/sendmail/libsm/Makefile.m4 b/contrib/sendmail/libsm/Makefile.m4
index 1bd3cab..da5dd55 100644
--- a/contrib/sendmail/libsm/Makefile.m4
+++ b/contrib/sendmail/libsm/Makefile.m4
@@ -1,38 +1,44 @@
-dnl $Id: Makefile.m4,v 1.70 2005/12/22 18:31:11 ca Exp $
+dnl $Id: Makefile.m4,v 1.72 2006/08/16 21:06:31 ca Exp $
define(`confREQUIRE_LIBUNIX')
include(confBUILDTOOLSDIR`/M4/switch.m4')
define(`confREQUIRE_LIBSM', `true')
+define(`confREQUIRE_SM_OS_H', `true')
PREPENDDEF(`confENVDEF', `confMAPDEF')
bldPRODUCT_START(`library', `libsm')
-define(`bldSOURCES', ` assert.c debug.c errstring.c exc.c heap.c match.c rpool.c strdup.c strerror.c strl.c clrerr.c fclose.c feof.c ferror.c fflush.c fget.c fpos.c findfp.c flags.c fopen.c fprintf.c fpurge.c fput.c fread.c fscanf.c fseek.c fvwrite.c fwalk.c fwrite.c get.c makebuf.c put.c refill.c rewind.c setvbuf.c smstdio.c snprintf.c sscanf.c stdio.c strio.c ungetc.c vasprintf.c vfprintf.c vfscanf.c vprintf.c vsnprintf.c wbuf.c wsetup.c string.c stringf.c xtrap.c strto.c test.c path.c strcasecmp.c strrevcmp.c signal.c clock.c config.c shm.c sem.c mbdb.c strexit.c cf.c ldap.c niprop.c mpeix.c memstat.c ')
+define(`bldSOURCES', ` assert.c debug.c errstring.c exc.c heap.c match.c rpool.c strdup.c strerror.c strl.c clrerr.c fclose.c feof.c ferror.c fflush.c fget.c fpos.c findfp.c flags.c fopen.c fprintf.c fpurge.c fput.c fread.c fscanf.c fseek.c fvwrite.c fwalk.c fwrite.c get.c makebuf.c put.c refill.c rewind.c setvbuf.c smstdio.c snprintf.c sscanf.c stdio.c strio.c ungetc.c vasprintf.c vfprintf.c vfscanf.c vprintf.c vsnprintf.c wbuf.c wsetup.c string.c stringf.c xtrap.c strto.c test.c path.c strcasecmp.c strrevcmp.c signal.c clock.c config.c shm.c sem.c mbdb.c strexit.c cf.c ldap.c niprop.c mpeix.c memstat.c util.c ')
bldPRODUCT_END
dnl msg.c
dnl syslogio.c
-include(confBUILDTOOLSDIR`/M4/'bldM4_TYPE_DIR`/sm-test.m4')
-smtest(`t-event', `run')
-smtest(`t-exc', `run')
-smtest(`t-rpool', `run')
-smtest(`t-string', `run')
-smtest(`t-smstdio', `run')
-smtest(`t-match', `run')
-smtest(`t-strio', `run')
-smtest(`t-heap', `run')
-smtest(`t-fopen', `run')
-smtest(`t-strl', `run')
-smtest(`t-strrevcmp', `run')
-smtest(`t-types', `run')
-smtest(`t-path', `run')
-smtest(`t-float', `run')
-smtest(`t-scanf', `run')
-smtest(`t-shm', `run')
-smtest(`t-sem', `run')
-dnl smtest(`t-msg', `run')
-smtest(`t-cf')
-smtest(`b-strcmp')
+define(`confCHECK_LIBS',`libsm.a')dnl
+include(confBUILDTOOLSDIR`/M4/'bldM4_TYPE_DIR`/check.m4')
+smcheck(`t-event', `compile-run')
+smcheck(`t-exc', `compile-run')
+smcheck(`t-rpool', `compile-run')
+smcheck(`t-string', `compile-run')
+smcheck(`t-smstdio', `compile-run')
+smcheck(`t-match', `compile-run')
+smcheck(`t-strio', `compile-run')
+smcheck(`t-heap', `compile-run')
+smcheck(`t-fopen', `compile-run')
+smcheck(`t-strl', `compile-run')
+smcheck(`t-strrevcmp', `compile-run')
+smcheck(`t-types', `compile-run')
+smcheck(`t-path', `compile-run')
+smcheck(`t-float', `compile-run')
+smcheck(`t-scanf', `compile-run')
+smcheck(`t-shm', `compile-run')
+smcheck(`t-sem', `compile-run')
+dnl smcheck(`t-msg', `compile-run')
+smcheck(`t-cf')
+smcheck(`b-strcmp')
dnl SM_CONF_STRL cannot be turned off
-dnl smtest(`b-strl')
-smtest(`t-memstat')
+dnl smcheck(`b-strl')
+smcheck(`t-memstat')
+
+smcheck(`t-qic', `compile-run')
+divert(bldTARGETS_SECTION)
+divert(0)
bldFINISH
diff --git a/contrib/sendmail/libsm/config.c b/contrib/sendmail/libsm/config.c
index a5e1327..c96a738 100644
--- a/contrib/sendmail/libsm/config.c
+++ b/contrib/sendmail/libsm/config.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000-2003 Sendmail, Inc. and its suppliers.
+ * Copyright (c) 2000-2003, 2007 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: config.c,v 1.30 2003/12/10 03:19:07 gshapiro Exp $")
+SM_RCSID("@(#)$Id: config.c,v 1.31 2007/03/14 21:21:49 ca Exp $")
#include <stdlib.h>
#include <sm/heap.h>
@@ -247,5 +247,14 @@ char *SmCompileOptions[] =
#if SM_VA_STD
"SM_VA_STD",
#endif /* SM_VA_STD */
+#if USEKSTAT
+ "USEKSTAT",
+#endif /* USEKSTAT */
+#if USEPROCMEMINFO
+ "USEPROCMEMINFO",
+#endif /* USEPROCMEMINFO */
+#if USESWAPCTL
+ "USESWAPCTL",
+#endif /* USESWAPCTL */
NULL
};
diff --git a/contrib/sendmail/libsm/exc.c b/contrib/sendmail/libsm/exc.c
index 26ad020..0bcf17a 100644
--- a/contrib/sendmail/libsm/exc.c
+++ b/contrib/sendmail/libsm/exc.c
@@ -9,7 +9,7 @@
*/
#include <sm/gen.h>
-SM_RCSID("@(#)$Id: exc.c,v 1.48 2003/12/05 22:45:24 ca Exp $")
+SM_RCSID("@(#)$Id: exc.c,v 1.49 2006/12/19 19:28:09 ca Exp $")
/*
** exception handling
@@ -229,7 +229,9 @@ const SM_EXC_TYPE_T SmEtypeErr =
** an out-of-memory exception so that exc is not leaked.
*/
-SM_EXC_T *
+static SM_EXC_T *sm_exc_vnew_x __P((const SM_EXC_TYPE_T *, va_list SM_NONVOLATILE));
+
+static SM_EXC_T *
sm_exc_vnew_x(etype, ap)
const SM_EXC_TYPE_T *etype;
va_list SM_NONVOLATILE ap;
@@ -419,26 +421,6 @@ sm_exc_new_x(etype, va_alist)
}
/*
-** SM_ADDREF -- Add a reference to an exception object.
-**
-** Parameters:
-** exc -- exception object.
-**
-** Returns:
-** exc itself.
-*/
-
-SM_EXC_T *
-sm_addref(exc)
- SM_EXC_T *exc;
-{
- SM_REQUIRE_ISA(exc, SmExcMagic);
- if (exc->exc_refcount != 0)
- ++exc->exc_refcount;
- return exc;
-}
-
-/*
** SM_EXC_FREE -- Destroy a reference to an exception object.
**
** Parameters:
diff --git a/contrib/sendmail/libsm/exc.html b/contrib/sendmail/libsm/exc.html
index a299036..669ebe2 100644
--- a/contrib/sendmail/libsm/exc.html
+++ b/contrib/sendmail/libsm/exc.html
@@ -8,7 +8,7 @@
<center>
<h1> libsm : Exception Handling </h1>
- <br> $Id: exc.html,v 1.12 2001/02/13 21:21:25 gshapiro Exp $
+ <br> $Id: exc.html,v 1.13 2006/06/20 17:18:16 ca Exp $
</center>
<h2> Introduction </h2>
@@ -28,7 +28,7 @@ Here are the basic concepts:
<p>
<li>
Errors are not represented by a single integer error code,
- because that you can't represent everything that an error handler
+ because then you can't represent everything that an error handler
might need to know about an error by a single integer.
Instead, errors are represented by exception objects.
An exception object contains an exception code and an array
diff --git a/contrib/sendmail/libsm/findfp.c b/contrib/sendmail/libsm/findfp.c
index 115ed22..1658929 100644
--- a/contrib/sendmail/libsm/findfp.c
+++ b/contrib/sendmail/libsm/findfp.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000-2002 Sendmail, Inc. and its suppliers.
+ * Copyright (c) 2000-2002, 2006 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: findfp.c,v 1.66 2002/02/20 02:40:24 ca Exp $")
+SM_RCSID("@(#)$Id: findfp.c,v 1.67 2006/08/28 21:24:46 ca Exp $")
#include <stdlib.h>
#include <unistd.h>
#include <sys/param.h>
@@ -365,6 +365,11 @@ sm_io_getinfo(fp, what, valp)
switch (what)
{
case SM_IO_WHAT_VECTORS:
+ if (valp == NULL)
+ {
+ errno = EINVAL;
+ return -1;
+ }
/* This is the "generic" available for all */
v->f_close = fp->f_close;
diff --git a/contrib/sendmail/libsm/flags.c b/contrib/sendmail/libsm/flags.c
index 94ecd5c..97c38fa 100644
--- a/contrib/sendmail/libsm/flags.c
+++ b/contrib/sendmail/libsm/flags.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000-2001, 2004 Sendmail, Inc. and its suppliers.
+ * Copyright (c) 2000-2001, 2004, 2006 Sendmail, Inc. and its suppliers.
* All rights reserved.
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -13,11 +13,12 @@
*/
#include <sm/gen.h>
-SM_RCSID("@(#)$Id: flags.c,v 1.22 2004/03/03 19:20:29 ca Exp $")
+SM_RCSID("@(#)$Id: flags.c,v 1.23 2006/12/19 19:44:23 ca Exp $")
#include <sys/types.h>
#include <sys/file.h>
#include <errno.h>
#include <sm/io.h>
+#include "local.h"
/*
** SM_FLAGS -- translate external (user) flags into internal flags
@@ -31,9 +32,9 @@ SM_RCSID("@(#)$Id: flags.c,v 1.22 2004/03/03 19:20:29 ca Exp $")
int
sm_flags(flags)
- register int flags;
+ int flags;
{
- register int ret;
+ int ret;
switch(SM_IO_MODE(flags))
{
diff --git a/contrib/sendmail/libsm/ldap.c b/contrib/sendmail/libsm/ldap.c
index 76e91b3..83b7644 100644
--- a/contrib/sendmail/libsm/ldap.c
+++ b/contrib/sendmail/libsm/ldap.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2001-2005 Sendmail, Inc. and its suppliers.
+ * Copyright (c) 2001-2006 Sendmail, Inc. and its suppliers.
* All rights reserved.
*
* By using this file, you agree to the terms and conditions set
@@ -7,8 +7,11 @@
* the sendmail distribution.
*/
+/* some "deprecated" calls are used, e.g., ldap_get_values() */
+#define LDAP_DEPRECATED 1
+
#include <sm/gen.h>
-SM_RCSID("@(#)$Id: ldap.c,v 1.67 2005/12/14 00:08:03 ca Exp $")
+SM_RCSID("@(#)$Id: ldap.c,v 1.78 2006/08/30 22:56:59 ca Exp $")
#if LDAPMAP
# include <sys/types.h>
@@ -95,6 +98,7 @@ sm_ldap_clear(lmap)
lmap->ldap_res = NULL;
lmap->ldap_next = NULL;
lmap->ldap_pid = 0;
+ lmap->ldap_multi_args = false;
}
/*
@@ -280,35 +284,67 @@ ldaptimeout(unused)
}
/*
-** SM_LDAP_SEARCH -- initiate LDAP search
+** SM_LDAP_SEARCH_M -- initiate multi-key LDAP search
**
** Initiate an LDAP search, return the msgid.
** The calling function must collect the results.
**
** Parameters:
** lmap -- LDAP map information
-** key -- key to substitute in LDAP filter
+** argv -- key vector of substitutions in LDAP filter
+** NOTE: argv must have SM_LDAP_ARGS elements to prevent
+** out of bound array references
**
** Returns:
-** -1 on failure, msgid on success
+** <0 on failure (SM_LDAP_ERR*), msgid on success
**
*/
int
-sm_ldap_search(lmap, key)
+sm_ldap_search_m(lmap, argv)
SM_LDAP_STRUCT *lmap;
- char *key;
+ char **argv;
{
int msgid;
char *fp, *p, *q;
char filter[LDAPMAP_MAX_FILTER + 1];
- /* substitute key into filter, perhaps multiple times */
+ SM_REQUIRE(lmap != NULL);
+ SM_REQUIRE(argv != NULL);
+ SM_REQUIRE(argv[0] != NULL);
+
memset(filter, '\0', sizeof filter);
fp = filter;
p = lmap->ldap_filter;
while ((q = strchr(p, '%')) != NULL)
{
+ char *key;
+
+ if (lmap->ldap_multi_args)
+ {
+#if SM_LDAP_ARGS < 10
+# ERROR _SM_LDAP_ARGS must be 10
+#endif /* SM_LDAP_ARGS < 10 */
+ if (q[1] == 's')
+ key = argv[0];
+ else if (q[1] >= '0' && q[1] <= '9')
+ {
+ key = argv[q[1] - '0'];
+ if (key == NULL)
+ {
+# if SM_LDAP_ERROR_ON_MISSING_ARGS
+ return SM_LDAP_ERR_ARG_MISS;
+# else /* SM_LDAP_ERROR_ON_MISSING_ARGS */
+ key = "";
+# endif /* SM_LDAP_ERROR_ON_MISSING_ARGS */
+ }
+ }
+ else
+ key = NULL;
+ }
+ else
+ key = argv[0];
+
if (q[1] == 's')
{
(void) sm_snprintf(fp, SPACELEFT(filter, fp),
@@ -316,7 +352,8 @@ sm_ldap_search(lmap, key)
fp += strlen(fp);
p = q + 2;
}
- else if (q[1] == '0')
+ else if (q[1] == '0' ||
+ (lmap->ldap_multi_args && q[1] >= '0' && q[1] <= '9'))
{
char *k = key;
@@ -368,6 +405,34 @@ sm_ldap_search(lmap, key)
}
/*
+** SM_LDAP_SEARCH -- initiate LDAP search
+**
+** Initiate an LDAP search, return the msgid.
+** The calling function must collect the results.
+** Note this is just a wrapper into sm_ldap_search_m()
+**
+** Parameters:
+** lmap -- LDAP map information
+** key -- key to substitute in LDAP filter
+**
+** Returns:
+** <0 on failure, msgid on success
+**
+*/
+
+int
+sm_ldap_search(lmap, key)
+ SM_LDAP_STRUCT *lmap;
+ char *key;
+{
+ char *argv[SM_LDAP_ARGS];
+
+ memset(argv, '\0', sizeof argv);
+ argv[0] = key;
+ return sm_ldap_search_m(lmap, argv);
+}
+
+/*
** SM_LDAP_HAS_OBJECTCLASS -- determine if an LDAP entry is part of a
** particular objectClass
**
@@ -480,29 +545,29 @@ sm_ldap_add_recurse(top, item, type, rpool)
{
/* 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;
+ (*top)->lrl_cnt = 0;
+ (*top)->lrl_size = 0;
+ (*top)->lrl_data = NULL;
}
- if ((*top)->lr_cnt >= (*top)->lr_size)
+ if ((*top)->lrl_cnt >= (*top)->lrl_size)
{
/* Grow the list of SM_LDAP_RECURSE_ENTRY ptrs */
- olddata = (*top)->lr_data;
- if ((*top)->lr_size == 0)
+ olddata = (*top)->lrl_data;
+ if ((*top)->lrl_size == 0)
{
oldsizeb = 0;
- (*top)->lr_size = 256;
+ (*top)->lrl_size = 256;
}
else
{
- oldsizeb = (*top)->lr_size * sizeof *((*top)->lr_data);
- (*top)->lr_size *= 2;
+ oldsizeb = (*top)->lrl_size * sizeof *((*top)->lrl_data);
+ (*top)->lrl_size *= 2;
}
- (*top)->lr_data = sm_rpool_malloc_x(rpool,
- (*top)->lr_size * sizeof *((*top)->lr_data));
+ (*top)->lrl_data = sm_rpool_malloc_x(rpool,
+ (*top)->lrl_size * sizeof *((*top)->lrl_data));
if (oldsizeb > 0)
- memcpy((*top)->lr_data, olddata, oldsizeb);
+ memcpy((*top)->lrl_data, olddata, oldsizeb);
}
/*
@@ -511,7 +576,7 @@ sm_ldap_add_recurse(top, item, type, rpool)
*/
n = 0;
- m = (*top)->lr_cnt - 1;
+ m = (*top)->lrl_cnt - 1;
if (m < 0)
insertat = 0;
else
@@ -521,21 +586,21 @@ sm_ldap_add_recurse(top, item, type, rpool)
{
p = (m + n) / 2;
- rc = sm_strcasecmp(item, (*top)->lr_data[p]->lr_search);
+ rc = sm_strcasecmp(item, (*top)->lrl_data[p]->lr_search);
if (rc == 0)
- rc = type - (*top)->lr_data[p]->lr_type;
+ rc = type - (*top)->lrl_data[p]->lr_type;
if (rc < 0)
m = p - 1;
else if (rc > 0)
n = p + 1;
else
- return (*top)->lr_data[p];
+ return (*top)->lrl_data[p];
if (m == -1)
insertat = 0;
- else if (n >= (*top)->lr_cnt)
- insertat = (*top)->lr_cnt;
+ else if (n >= (*top)->lrl_cnt)
+ insertat = (*top)->lrl_cnt;
else if (m < n)
insertat = m + 1;
}
@@ -548,10 +613,10 @@ sm_ldap_add_recurse(top, item, type, rpool)
newe = sm_rpool_malloc_x(rpool, sizeof *newe);
if (newe != NULL)
{
- moveb = ((*top)->lr_cnt - insertat) * sizeof *((*top)->lr_data);
+ moveb = ((*top)->lrl_cnt - insertat) * sizeof *((*top)->lrl_data);
if (moveb > 0)
- memmove(&((*top)->lr_data[insertat + 1]),
- &((*top)->lr_data[insertat]),
+ memmove(&((*top)->lrl_data[insertat + 1]),
+ &((*top)->lrl_data[insertat]),
moveb);
newe->lr_search = sm_rpool_strdup_x(rpool, item);
@@ -560,8 +625,8 @@ sm_ldap_add_recurse(top, item, type, rpool)
newe->lr_attrs = NULL;
newe->lr_done = false;
- ((*top)->lr_data)[insertat] = newe;
- (*top)->lr_cnt++;
+ ((*top)->lrl_data)[insertat] = newe;
+ (*top)->lrl_cnt++;
}
return newe;
}
@@ -1082,13 +1147,14 @@ sm_ldap_results(lmap, msgid, flags, delim, rpool, result,
** will be expanded by the top level.
*/
- for (rlidx = 0; recurse != NULL && rlidx < recurse->lr_cnt; rlidx++)
+ for (rlidx = 0; recurse != NULL && rlidx < recurse->lrl_cnt;
+ rlidx++)
{
int newflags;
int sid;
int status;
- rl = recurse->lr_data[rlidx];
+ rl = recurse->lrl_data[rlidx];
newflags = flags;
if (rl->lr_done)
diff --git a/contrib/sendmail/libsm/local.h b/contrib/sendmail/libsm/local.h
index 7c7798e..b0625a5 100644
--- a/contrib/sendmail/libsm/local.h
+++ b/contrib/sendmail/libsm/local.h
@@ -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.57 2006/02/28 18:48:25 ca Exp $
+ * $Id: local.h,v 1.58 2006/12/19 19:44:23 ca Exp $
*/
/*
@@ -102,6 +102,8 @@ extern const char SmFileMagic[];
#define sm_io_flockfile(fp) ((void) 0)
#define sm_io_funlockfile(fp) ((void) 0)
+int sm_flags __P((int));
+
#ifndef FDSET_CAST
# define FDSET_CAST /* empty cast for fd_set arg to select */
#endif
diff --git a/contrib/sendmail/libsm/memstat.c b/contrib/sendmail/libsm/memstat.c
index 6c2a4d1..80391d7 100644
--- a/contrib/sendmail/libsm/memstat.c
+++ b/contrib/sendmail/libsm/memstat.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005 Sendmail, Inc. and its suppliers.
+ * Copyright (c) 2005-2007 Sendmail, Inc. and its suppliers.
* All rights reserved.
*
* By using this file, you agree to the terms and conditions set
@@ -8,9 +8,10 @@
*/
#include <sm/gen.h>
-SM_RCSID("@(#)$Id: memstat.c,v 1.4 2005/12/10 00:38:48 ca Exp $")
+SM_RCSID("@(#)$Id: memstat.c,v 1.6 2007/03/20 23:26:12 ca Exp $")
#include <errno.h>
+#include <sm/misc.h>
#if USESWAPCTL
#include <sys/stat.h>
@@ -265,6 +266,8 @@ sm_memstat_get(resource, pvalue)
return -1; /* try to reopen? */
rewind(fp);
l = strlen(resource);
+ if (l >= sizeof(buf))
+ return EINVAL;
while (fgets(buf, sizeof(buf), fp) != NULL)
{
if (strncmp(buf, resource, l) == 0 && buf[l] == ':')
diff --git a/contrib/sendmail/libsm/snprintf.c b/contrib/sendmail/libsm/snprintf.c
index 5ee3006..cdb7688 100644
--- a/contrib/sendmail/libsm/snprintf.c
+++ b/contrib/sendmail/libsm/snprintf.c
@@ -13,10 +13,11 @@
*/
#include <sm/gen.h>
-SM_RCSID("@(#)$Id: snprintf.c,v 1.23 2001/09/11 04:04:49 gshapiro Exp $")
+SM_RCSID("@(#)$Id: snprintf.c,v 1.24 2006/10/12 21:50:10 ca Exp $")
#include <limits.h>
#include <sm/varargs.h>
#include <sm/io.h>
+#include <sm/string.h>
#include "local.h"
/*
diff --git a/contrib/sendmail/libsm/t-memstat.c b/contrib/sendmail/libsm/t-memstat.c
index b3bd918..3bfe394 100644
--- a/contrib/sendmail/libsm/t-memstat.c
+++ b/contrib/sendmail/libsm/t-memstat.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2006 Sendmail, Inc. and its suppliers.
+ * Copyright (c) 2005-2007 Sendmail, Inc. and its suppliers.
* All rights reserved.
*
* By using this file, you agree to the terms and conditions set
@@ -8,7 +8,9 @@
*/
#include <sm/gen.h>
-SM_IDSTR(id, "@(#)$Id: t-memstat.c,v 1.6 2006/03/27 22:34:47 ca Exp $")
+SM_IDSTR(id, "@(#)$Id: t-memstat.c,v 1.9 2007/03/14 21:41:09 ca Exp $")
+
+#include <sm/misc.h>
/*
** Simple test program for memstat
@@ -23,6 +25,18 @@ SM_IDSTR(id, "@(#)$Id: t-memstat.c,v 1.6 2006/03/27 22:34:47 ca Exp $")
extern char *optarg;
extern int optind;
+void
+usage(prg)
+ char *prg;
+{
+ fprintf(stderr, "usage: %s [options]\n", prg);
+ fprintf(stderr, "options:\n");
+ fprintf(stderr, "-l n loop n times\n");
+ fprintf(stderr, "-m n allocate n bytes per iteration\n");
+ fprintf(stderr, "-r name use name as resource to query\n");
+ fprintf(stderr, "-s n sleep n seconds per iteration\n");
+}
+
int
main(argc, argv)
int argc;
@@ -56,7 +70,8 @@ main(argc, argv)
break;
default:
- break;
+ usage(argv[0]);
+ exit(1);
}
}
diff --git a/contrib/sendmail/libsm/t-qic.c b/contrib/sendmail/libsm/t-qic.c
new file mode 100644
index 0000000..8a8e0c8
--- /dev/null
+++ b/contrib/sendmail/libsm/t-qic.c
@@ -0,0 +1,235 @@
+/*
+ * Copyright (c) 2006 Sendmail, Inc. and its suppliers.
+ * All rights reserved.
+ *
+ * By using this file, you agree to the terms and conditions set
+ * forth in the LICENSE file which can be found at the top level of
+ * the sendmail distribution.
+ */
+
+#include <sm/gen.h>
+SM_IDSTR(id, "@(#)$Id: t-qic.c,v 1.9 2006/08/24 21:26:13 ca Exp $")
+
+#include <stdio.h>
+#include <sm/sendmail.h>
+#include <sm/assert.h>
+#include <sm/heap.h>
+#include <sm/string.h>
+#include <sm/test.h>
+
+extern bool SmTestVerbose;
+
+
+void
+show_diff(s1, s2)
+ const char *s1;
+ const char *s2;
+{
+ int i;
+
+ for (i = 0; s1[i] != '\0' && s2[i] != '\0'; i++)
+ {
+ if (s1[i] != s2[i])
+ {
+ fprintf(stderr, "i=%d, s1[]=%u, s2[]=%u\n",
+ i, (unsigned char) s1[i],
+ (unsigned char) s2[i]);
+ return;
+ }
+ }
+ if (s1[i] != s2[i])
+ {
+ fprintf(stderr, "i=%d, s1[]=%u, s2[]=%u\n",
+ i, (unsigned char) s1[i], (unsigned char) s2[i]);
+ }
+}
+
+char *quote_unquote __P((char *, char *, int, int));
+
+char *
+quote_unquote(in, out, outlen, exp)
+ char *in;
+ char *out;
+ int outlen;
+ int exp;
+{
+ char *obp, *bp;
+ char line_back[1024];
+ char line_in[1024];
+ int cmp;
+
+ sm_strlcpy(line_in, in, sizeof(line_in));
+ obp = quote_internal_chars(in, out, &outlen);
+ bp = str2prt(line_in);
+ dequote_internal_chars(obp, line_back, sizeof(line_back));
+ cmp = strcmp(line_in, line_back);
+ SM_TEST(exp == cmp);
+ if (cmp != exp && !SmTestVerbose)
+ {
+ fprintf(stderr, "in: %s\n", bp);
+ bp = str2prt(line_back);
+ fprintf(stderr, "out:%s\n", bp);
+ fprintf(stderr, "cmp=%d\n", cmp);
+ show_diff(in, line_back);
+ }
+ if (SmTestVerbose)
+ {
+ fprintf(stderr, "%s -> ", bp);
+ bp = str2prt(obp);
+ fprintf(stderr, "%s\n", bp);
+ fprintf(stderr, "cmp=%d\n", cmp);
+ }
+ return obp;
+}
+
+struct sm_qic_S
+{
+ char *qic_in;
+ char *qic_out;
+ int qic_exp;
+};
+
+typedef struct sm_qic_S sm_qic_T;
+
+
+int
+main(argc, argv)
+ int argc;
+ char *argv[];
+{
+ char line_in[1024], line[256], line_out[32], *obp;
+ int i, los, cmp;
+ sm_qic_T inout[] = {
+ { "", "", 0 }
+ , { "abcdef", "abcdef", 0 }
+ , { "01234567890123456789", "01234567890123456789", 0 }
+ , { "01234567890123456789\001", "01234567890123456789\001",
+ 0 }
+ , { "012345\2067890123456789", "012345\377\2067890123456789",
+ 0 }
+ , { "\377", "\377\377", 0 }
+ , { "\240", "\240", 0 }
+ , { "\220", "\377\220", 0 }
+ , { "\240\220", "\240\377\220", 0 }
+ , { "\377\377", "\377\377\377\377", 0 }
+ , { "\377a\377b", "\377\377a\377\377b", 0 }
+ , { "\376a\377b", "\376a\377\377b", 0 }
+ , { "\200\201\202\203\204\205\206\207\210\211\212\213\214\215\216\217\220\221\222\223\224\225\226\227\230\231\232\233\234\235\236\237\240",
+ "\377\200\377\201\377\202\377\203\377\204\377\205\377\206\377\207\377\210\377\211\377\212\377\213\377\214\377\215\377\216\377\217\377\220\377\221\377\222\377\223\377\224\377\225\377\226\377\227\377\230\377\231\377\232\377\233\377\234\377\235\377\236\377\237\240",
+ 0 }
+ , { NULL, NULL, 0 }
+ };
+
+ sm_test_begin(argc, argv, "test meta quoting");
+ for (i = 0; i < sizeof(line_out); i++)
+ line_out[i] = '\0';
+ for (i = 0; i < sizeof(line_in); i++)
+ line_in[i] = '\0';
+ for (i = 0; i < sizeof(line_in) / 2; i++)
+ {
+ char ch;
+
+ ch = 0200 + i;
+ if ('\0' == ch)
+ ch = '0';
+ line_in[i] = ch;
+ }
+ los = sizeof(line_out) / 2;
+ obp = quote_unquote(line_in, line_out, los, 0);
+ if (obp != line_out)
+ SM_FREE(obp);
+
+ for (i = 0; i < sizeof(line_in); i++)
+ line_in[i] = '\0';
+ for (i = 0; i < sizeof(line_in) / 2; i++)
+ {
+ char ch;
+
+ ch = 0200 + i;
+ if ('\0' == ch)
+ ch = '0';
+ line_in[i] = ch;
+ }
+ los = sizeof(line_in);
+ obp = quote_unquote(line_in, line_in, los, 0);
+ if (obp != line_in)
+ SM_FREE(obp);
+
+ for (i = 0; inout[i].qic_in != NULL; i++)
+ {
+ los = sizeof(line_out) / 2;
+ obp = quote_unquote(inout[i].qic_in, line_out, los,
+ inout[i].qic_exp);
+ cmp = strcmp(inout[i].qic_out, obp);
+ SM_TEST(inout[i].qic_exp == cmp);
+ if (inout[i].qic_exp != cmp && !SmTestVerbose)
+ {
+ char *bp;
+
+ bp = str2prt(obp);
+ fprintf(stderr, "got: %s\n", bp);
+ bp = str2prt(inout[i].qic_out);
+ fprintf(stderr, "exp:%s\n", bp);
+ fprintf(stderr, "cmp=%d\n", cmp);
+ show_diff(inout[i].qic_in, inout[i].qic_out);
+ }
+ if (obp != line_out)
+ SM_FREE(obp);
+ }
+
+ /* use same buffer for in and out */
+ for (i = 0; inout[i].qic_in != NULL; i++)
+ {
+ bool same;
+
+ same = strcmp(inout[i].qic_in, inout[i].qic_out) == 0;
+ los = sm_strlcpy(line, inout[i].qic_in, sizeof(line));
+ SM_TEST(los + 1 < sizeof(line));
+ ++los;
+ obp = quote_unquote(line, line, los, inout[i].qic_exp);
+ cmp = strcmp(inout[i].qic_out, obp);
+ SM_TEST(inout[i].qic_exp == cmp);
+ if (inout[i].qic_exp != cmp && !SmTestVerbose)
+ {
+ char *bp;
+
+ bp = str2prt(obp);
+ fprintf(stderr, "got: %s\n", bp);
+ bp = str2prt(inout[i].qic_out);
+ fprintf(stderr, "exp:%s\n", bp);
+ fprintf(stderr, "cmp=%d\n", cmp);
+ show_diff(inout[i].qic_in, inout[i].qic_out);
+ }
+ if (obp != line)
+ {
+ SM_TEST(!same);
+ if (same)
+ show_diff(obp, inout[i].qic_out);
+ SM_FREE(obp);
+ }
+ }
+
+ /* use NULL buffer for out */
+ for (i = 0; inout[i].qic_in != NULL; i++)
+ {
+ los = 0;
+ obp = quote_unquote(inout[i].qic_in, NULL, los,
+ inout[i].qic_exp);
+ SM_TEST(obp != NULL);
+ cmp = strcmp(inout[i].qic_out, obp);
+ SM_TEST(inout[i].qic_exp == cmp);
+ if (inout[i].qic_exp != cmp && !SmTestVerbose)
+ {
+ char *bp;
+
+ bp = str2prt(obp);
+ fprintf(stderr, "got: %s\n", bp);
+ bp = str2prt(inout[i].qic_out);
+ fprintf(stderr, "exp:%s\n", bp);
+ fprintf(stderr, "cmp=%d\n", cmp);
+ show_diff(inout[i].qic_in, inout[i].qic_out);
+ }
+ }
+
+ return sm_test_end();
+}
diff --git a/contrib/sendmail/libsm/t-sem.c b/contrib/sendmail/libsm/t-sem.c
index cba784a..24d0563 100644
--- a/contrib/sendmail/libsm/t-sem.c
+++ b/contrib/sendmail/libsm/t-sem.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000-2001, 2005-2006 Sendmail, Inc. and its suppliers.
+ * Copyright (c) 2000-2001, 2005-2007 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-sem.c,v 1.15 2006/03/13 20:40:43 msk Exp $")
+SM_RCSID("@(#)$Id: t-sem.c,v 1.16 2007/03/21 23:22:10 ca Exp $")
#include <stdio.h>
@@ -22,6 +22,8 @@ SM_RCSID("@(#)$Id: t-sem.c,v 1.15 2006/03/13 20:40:43 msk Exp $")
# include <sm/test.h>
# include <sm/sem.h>
+# define T_SM_SEM_KEY (4321L)
+
static void
delay(t, s)
int t;
@@ -58,7 +60,7 @@ seminter(owner)
int semid;
int t;
- semid = sm_sem_start(SM_SEM_KEY, SM_NSEM, 0, owner);
+ semid = sm_sem_start(T_SM_SEM_KEY, SM_NSEM, 0, owner);
if (semid < 0)
{
perror("sm_sem_start failed");
@@ -145,7 +147,7 @@ semtest(owner)
int semid, r;
int cnt = 0;
- semid = sm_sem_start(SM_SEM_KEY, 1, 0, owner);
+ semid = sm_sem_start(T_SM_SEM_KEY, 1, 0, owner);
if (semid < 0)
{
perror("sm_sem_start failed");
diff --git a/contrib/sendmail/libsm/util.c b/contrib/sendmail/libsm/util.c
new file mode 100644
index 0000000..2b99a49
--- /dev/null
+++ b/contrib/sendmail/libsm/util.c
@@ -0,0 +1,250 @@
+/*
+ * Copyright (c) 2006 Sendmail, Inc. and its suppliers.
+ * All rights reserved.
+ *
+ * By using this file, you agree to the terms and conditions set
+ * forth in the LICENSE file which can be found at the top level of
+ * the sendmail distribution.
+ *
+ */
+
+#include <sm/gen.h>
+
+SM_RCSID("@(#)$Id: util.c,v 1.9 2006/08/30 18:35:51 ca Exp $")
+#include <sm/setjmp.h>
+#include <sm/conf.h>
+#include <sm/assert.h>
+#include <sm/heap.h>
+#include <sm/string.h>
+#include <sm/sendmail.h>
+#include <ctype.h>
+
+/*
+** STR2PRT -- convert "unprintable" characters in a string to \oct
+**
+** Parameters:
+** s -- string to convert
+**
+** Returns:
+** converted string.
+** This is a static local buffer, string must be copied
+** before this function is called again!
+*/
+
+char *
+str2prt(s)
+ char *s;
+{
+ int l;
+ char c, *h;
+ bool ok;
+ static int len = 0;
+ static char *buf = NULL;
+
+ if (s == NULL)
+ return NULL;
+ ok = true;
+ for (h = s, l = 1; *h != '\0'; h++, l++)
+ {
+ if (*h == '\\')
+ {
+ ++l;
+ ok = false;
+ }
+ else if (!(isascii(*h) && isprint(*h)))
+ {
+ l += 3;
+ ok = false;
+ }
+ }
+ if (ok)
+ return s;
+ if (l > len)
+ {
+ char *nbuf = sm_pmalloc_x(l);
+
+ if (buf != NULL)
+ sm_free(buf);
+ len = l;
+ buf = nbuf;
+ }
+ for (h = buf; *s != '\0' && l > 0; s++, l--)
+ {
+ c = *s;
+ if (isascii(c) && isprint(c) && c != '\\')
+ {
+ *h++ = c;
+ }
+ else
+ {
+ *h++ = '\\';
+ --l;
+ switch (c)
+ {
+ case '\\':
+ *h++ = '\\';
+ break;
+ case '\t':
+ *h++ = 't';
+ break;
+ case '\n':
+ *h++ = 'n';
+ break;
+ case '\r':
+ *h++ = 'r';
+ break;
+ default:
+ SM_ASSERT(l >= 2);
+ (void) sm_snprintf(h, l, "%03o",
+ (unsigned int)((unsigned char) c));
+
+ /*
+ ** XXX since l is unsigned this may
+ ** wrap around if the calculation is screwed
+ ** up...
+ */
+
+ l -= 2;
+ h += 3;
+ break;
+ }
+ }
+ }
+ *h = '\0';
+ buf[len - 1] = '\0';
+ return buf;
+}
+
+/*
+** QUOTE_INTERNAL_CHARS -- do quoting of internal characters
+**
+** Necessary to make sure that we don't have metacharacters such
+** as the internal versions of "$*" or "$&" in a string.
+** The input and output pointers can be the same.
+**
+** Parameters:
+** ibp -- a pointer to the string to translate
+** obp -- a pointer to an output buffer
+** bsp -- pointer to the length of the output buffer
+**
+** Returns:
+** A possibly new bp (if the buffer needed to grow); if
+** it is different, *bsp will updated to the size of
+** the new buffer and the caller is responsible for
+** freeing the memory.
+*/
+
+#define SM_MM_QUOTE(ch) (((ch) & 0377) == METAQUOTE || (((ch) & 0340) == 0200))
+
+char *
+quote_internal_chars(ibp, obp, bsp)
+ char *ibp;
+ char *obp;
+ int *bsp;
+{
+ char *ip, *op;
+ int bufused, olen;
+ bool buffer_same, needs_quoting;
+
+ buffer_same = ibp == obp;
+ needs_quoting = false;
+
+ /* determine length of output string (starts at 1 for trailing '\0') */
+ for (ip = ibp, olen = 1; *ip != '\0'; ip++, olen++)
+ {
+ if (SM_MM_QUOTE(*ip))
+ {
+ olen++;
+ needs_quoting = true;
+ }
+ }
+
+ /* is the output buffer big enough? */
+ if (olen > *bsp)
+ {
+ obp = sm_malloc_x(olen);
+ buffer_same = false;
+ *bsp = olen;
+ }
+
+ /*
+ ** shortcut: no change needed?
+ ** Note: we don't check this first as some bozo may use the same
+ ** buffers but restrict the size of the output buffer to less
+ ** than the length of the input buffer in which case we need to
+ ** allocate a new buffer.
+ */
+
+ if (!needs_quoting)
+ {
+ if (!buffer_same)
+ {
+ bufused = sm_strlcpy(obp, ibp, *bsp);
+ SM_ASSERT(bufused <= olen);
+ }
+ return obp;
+ }
+
+ if (buffer_same)
+ {
+ obp = sm_malloc_x(olen);
+ buffer_same = false;
+ *bsp = olen;
+ }
+
+ for (ip = ibp, op = obp, bufused = 0; *ip != '\0'; ip++)
+ {
+ if (SM_MM_QUOTE(*ip))
+ {
+ SM_ASSERT(bufused < olen);
+ op[bufused++] = METAQUOTE;
+ }
+ SM_ASSERT(bufused < olen);
+ op[bufused++] = *ip;
+ }
+ op[bufused] = '\0';
+ return obp;
+}
+
+/*
+** DEQUOTE_INTERNAL_CHARS -- undo the effect of quote_internal_chars
+**
+** Parameters:
+** ibp -- a pointer to the string to be translated.
+** obp -- a pointer to the output buffer. Can be the
+** same as ibp.
+** obs -- the size of the output buffer.
+**
+** Returns:
+** number of character added to obp
+*/
+
+int
+dequote_internal_chars(ibp, obp, obs)
+ char *ibp;
+ char *obp;
+ int obs;
+{
+ char *ip, *op;
+ int len;
+ bool quoted;
+
+ quoted = false;
+ len = 0;
+ for (ip = ibp, op = obp; *ip != '\0'; ip++)
+ {
+ if ((*ip & 0377) == METAQUOTE && !quoted)
+ {
+ quoted = true;
+ continue;
+ }
+ if (op < &obp[obs - 1])
+ {
+ *op++ = *ip;
+ ++len;
+ }
+ quoted = false;
+ }
+ *op = '\0';
+ return len;
+}
diff --git a/contrib/sendmail/libsm/vfscanf.c b/contrib/sendmail/libsm/vfscanf.c
index 235ee42..8701ef7 100644
--- a/contrib/sendmail/libsm/vfscanf.c
+++ b/contrib/sendmail/libsm/vfscanf.c
@@ -13,7 +13,7 @@
*/
#include <sm/gen.h>
-SM_IDSTR(id, "@(#)$Id: vfscanf.c,v 1.53 2005/06/14 23:07:20 ca Exp $")
+SM_IDSTR(id, "@(#)$Id: vfscanf.c,v 1.54 2006/10/12 22:03:52 ca Exp $")
#include <ctype.h>
#include <stdlib.h>
@@ -122,7 +122,9 @@ sm_vfscanf(fp, timeout, fmt0, ap)
int nassigned; /* number of fields assigned */
int nread; /* number of characters consumed from fp */
int base; /* base argument to strtoll/strtoull */
- ULONGLONG_T (*ccfn)(); /* conversion function (strtoll/strtoull) */
+
+ /* conversion function (strtoll/strtoull) */
+ ULONGLONG_T (*ccfn) __P((const char *, char **, int));
char ccltab[256]; /* character class table for %[...] */
char buf[BUF]; /* buffer for numeric conversions */
SM_EVENT *evt = NULL;
OpenPOWER on IntegriCloud