summaryrefslogtreecommitdiff
path: root/usr/src/cmd/sendmail/libsm
diff options
context:
space:
mode:
authorjbeck <none@none>2007-02-02 09:51:53 -0800
committerjbeck <none@none>2007-02-02 09:51:53 -0800
commit058561cbaa119a6f2659bc27ef343e1b47266bb2 (patch)
tree687468583b2d8b63c41a3a7e6d71caf610beeb26 /usr/src/cmd/sendmail/libsm
parent977046508bbcbc7faa3e0cc7a3c7bf15c2e5dc57 (diff)
downloadillumos-joyent-058561cbaa119a6f2659bc27ef343e1b47266bb2.tar.gz
PSARC 2007/068 - Sendmail 8.14
6520335 upgrade sendmail to 8.14
Diffstat (limited to 'usr/src/cmd/sendmail/libsm')
-rw-r--r--usr/src/cmd/sendmail/libsm/Makefile15
-rw-r--r--usr/src/cmd/sendmail/libsm/exc.c26
-rw-r--r--usr/src/cmd/sendmail/libsm/findfp.c9
-rw-r--r--usr/src/cmd/sendmail/libsm/flags.c9
-rw-r--r--usr/src/cmd/sendmail/libsm/ldap.c134
-rw-r--r--usr/src/cmd/sendmail/libsm/local.h4
-rw-r--r--usr/src/cmd/sendmail/libsm/memstat.c336
-rw-r--r--usr/src/cmd/sendmail/libsm/snprintf.c3
-rw-r--r--usr/src/cmd/sendmail/libsm/t-memstat.c99
-rw-r--r--usr/src/cmd/sendmail/libsm/t-qic.c237
-rw-r--r--usr/src/cmd/sendmail/libsm/util.c252
-rw-r--r--usr/src/cmd/sendmail/libsm/vfscanf.c6
12 files changed, 1057 insertions, 73 deletions
diff --git a/usr/src/cmd/sendmail/libsm/Makefile b/usr/src/cmd/sendmail/libsm/Makefile
index 5f82deb0ef..4eda2239b7 100644
--- a/usr/src/cmd/sendmail/libsm/Makefile
+++ b/usr/src/cmd/sendmail/libsm/Makefile
@@ -39,17 +39,18 @@ ARFLAGS= cq
OBJS= assert.o cf.o clock.o clrerr.o config.o debug.o errstring.o exc.o \
fclose.o feof.o ferror.o fflush.o fget.o findfp.o flags.o fopen.o \
fpos.o fprintf.o fpurge.o fput.o fread.o fscanf.o fseek.o fvwrite.o \
- fwalk.o fwrite.o get.o heap.o ldap.o makebuf.o match.o mbdb.o niprop.o \
- path.o put.o refill.o rewind.o rpool.o setvbuf.o sem.o shm.o signal.o \
- smstdio.o snprintf.o sscanf.o stdio.o strcasecmp.o strdup.o strerror.o \
- strexit.o string.o stringf.o strio.o strl.o strrevcmp.o strto.o test.o \
- ungetc.o vasprintf.o vfprintf.o vfscanf.o vprintf.o vsnprintf.o \
- wbuf.o wsetup.o xtrap.o
+ fwalk.o fwrite.o get.o heap.o ldap.o makebuf.o match.o mbdb.o \
+ memstat.o niprop.o path.o put.o refill.o rewind.o rpool.o setvbuf.o \
+ sem.o shm.o signal.o smstdio.o snprintf.o sscanf.o stdio.o \
+ strcasecmp.o strdup.o strerror.o strexit.o string.o stringf.o strio.o \
+ strl.o strrevcmp.o strto.o test.o ungetc.o util.o vasprintf.o \
+ vfprintf.o vfscanf.o vprintf.o vsnprintf.o wbuf.o wsetup.o xtrap.o
SRCS= $(OBJS:%.o=%.c)
TESTS= t-event t-exc t-rpool t-string t-smstdio t-match t-strio t-heap \
- t-fopen t-strl t-strrevcmp t-path t-float t-scanf t-sem t-shm
+ t-fopen t-strl t-strrevcmp t-path t-float t-scanf t-sem t-shm \
+ t-memstat t-qic
libsm= libsm.a
diff --git a/usr/src/cmd/sendmail/libsm/exc.c b/usr/src/cmd/sendmail/libsm/exc.c
index 42e4da7924..78fb1c0a98 100644
--- a/usr/src/cmd/sendmail/libsm/exc.c
+++ b/usr/src/cmd/sendmail/libsm/exc.c
@@ -11,7 +11,7 @@
#pragma ident "%Z%%M% %I% %E% SMI"
#include <sm/gen.h>
-SM_RCSID("@(#)$Id: exc.c,v 1.47.2.1 2003/12/05 22:44:17 ca Exp $")
+SM_RCSID("@(#)$Id: exc.c,v 1.49 2006/12/19 19:28:09 ca Exp $")
/*
** exception handling
@@ -231,7 +231,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;
@@ -421,26 +423,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/usr/src/cmd/sendmail/libsm/findfp.c b/usr/src/cmd/sendmail/libsm/findfp.c
index befb996a89..d78b5cb57f 100644
--- a/usr/src/cmd/sendmail/libsm/findfp.c
+++ b/usr/src/cmd/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.
@@ -15,7 +15,7 @@
#pragma ident "%Z%%M% %I% %E% SMI"
#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>
@@ -367,6 +367,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/usr/src/cmd/sendmail/libsm/flags.c b/usr/src/cmd/sendmail/libsm/flags.c
index 8e4ede9546..ad416eac9f 100644
--- a/usr/src/cmd/sendmail/libsm/flags.c
+++ b/usr/src/cmd/sendmail/libsm/flags.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000-2001, 2003 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.
@@ -15,11 +15,12 @@
#pragma ident "%Z%%M% %I% %E% SMI"
#include <sm/gen.h>
-SM_RCSID("@(#)$Id: flags.c,v 1.20.2.1 2003/09/03 18:51:56 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
@@ -33,9 +34,9 @@ SM_RCSID("@(#)$Id: flags.c,v 1.20.2.1 2003/09/03 18:51:56 ca Exp $")
int
sm_flags(flags)
- register int flags;
+ int flags;
{
- register int ret;
+ int ret;
switch(SM_IO_MODE(flags))
{
diff --git a/usr/src/cmd/sendmail/libsm/ldap.c b/usr/src/cmd/sendmail/libsm/ldap.c
index a9ef580e70..c4778f9b95 100644
--- a/usr/src/cmd/sendmail/libsm/ldap.c
+++ b/usr/src/cmd/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
@@ -9,8 +9,11 @@
#pragma ident "%Z%%M% %I% %E% SMI"
+/* 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>
@@ -97,6 +100,7 @@ sm_ldap_clear(lmap)
lmap->ldap_res = NULL;
lmap->ldap_next = NULL;
lmap->ldap_pid = 0;
+ lmap->ldap_multi_args = false;
}
/*
@@ -282,35 +286,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),
@@ -318,7 +354,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;
@@ -370,6 +407,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
**
@@ -482,29 +547,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);
}
/*
@@ -513,7 +578,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
@@ -523,21 +588,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;
}
@@ -550,10 +615,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);
@@ -562,8 +627,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;
}
@@ -1084,13 +1149,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/usr/src/cmd/sendmail/libsm/local.h b/usr/src/cmd/sendmail/libsm/local.h
index df2fec8900..63abc96638 100644
--- a/usr/src/cmd/sendmail/libsm/local.h
+++ b/usr/src/cmd/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 $
*/
#pragma ident "%Z%%M% %I% %E% SMI"
@@ -104,6 +104,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/usr/src/cmd/sendmail/libsm/memstat.c b/usr/src/cmd/sendmail/libsm/memstat.c
new file mode 100644
index 0000000000..f674622742
--- /dev/null
+++ b/usr/src/cmd/sendmail/libsm/memstat.c
@@ -0,0 +1,336 @@
+/*
+ * Copyright (c) 2005, 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.
+ */
+
+#pragma ident "%Z%%M% %I% %E% SMI"
+
+#include <sm/gen.h>
+SM_RCSID("@(#)$Id: memstat.c,v 1.5 2006/06/28 23:57:59 ca Exp $")
+
+#include <errno.h>
+#include <sm/misc.h>
+
+#if USESWAPCTL
+#include <sys/stat.h>
+#include <sys/swap.h>
+
+static long sc_page_size;
+
+/*
+** SM_MEMSTAT_OPEN -- open memory statistics
+**
+** Parameters:
+** none
+**
+** Results:
+** errno as error code, 0: ok
+*/
+
+int
+sm_memstat_open()
+{
+ sc_page_size = sysconf(_SC_PAGE_SIZE);
+ if (sc_page_size == -1)
+ return (errno != 0) ? errno : -1;
+ return 0;
+}
+
+/*
+** SM_MEMSTAT_CLOSE -- close memory statistics
+**
+** Parameters:
+** none
+**
+** Results:
+** errno as error code, 0: ok
+*/
+
+int
+sm_memstat_close()
+{
+ return 0;
+}
+
+/*
+** SM_MEMSTAT_GET -- get memory statistics
+**
+** Parameters:
+** resource -- resource to look up
+** pvalue -- (pointer to) memory statistics value (output)
+**
+** Results:
+** 0: success
+** !=0: error
+*/
+
+int
+sm_memstat_get(resource, pvalue)
+ char *resource;
+ long *pvalue;
+{
+ int r;
+ struct anoninfo ai;
+
+ r = swapctl(SC_AINFO, &ai);
+ if (r == -1)
+ return (errno != 0) ? errno : -1;
+ r = ai.ani_max - ai.ani_resv;
+ r *= sc_page_size >> 10;
+ *pvalue = r;
+ return 0;
+}
+
+#elif USEKSTAT
+
+#include <kstat.h>
+#include <sys/sysinfo.h>
+
+static kstat_ctl_t *kc;
+static kstat_t *kst;
+
+/*
+** SM_MEMSTAT_OPEN -- open memory statistics
+**
+** Parameters:
+** none
+**
+** Results:
+** errno as error code, 0: ok
+*/
+
+int
+sm_memstat_open()
+{
+ kstat_named_t *kn;
+
+ kc = kstat_open();
+ if (kc == NULL)
+ return (errno != 0) ? errno : -1;
+ kst = kstat_lookup(kc, "unix", 0,
+ (name != NULL) ? name : "system_pages");
+ if (kst == 0)
+ return (errno != 0) ? errno : -2;
+ return 0;
+}
+
+/*
+** SM_MEMSTAT_CLOSE -- close memory statistics
+**
+** Parameters:
+** none
+**
+** Results:
+** errno as error code, 0: ok
+*/
+
+int
+sm_memstat_close()
+{
+ int r;
+
+ if (kc == NULL)
+ return 0;
+ r = kstat_close(kc);
+ if (r != 0)
+ return (errno != 0) ? errno : -1;
+ return 0;
+}
+
+/*
+** SM_MEMSTAT_GET -- get memory statistics
+**
+** Parameters:
+** resource -- resource to look up
+** pvalue -- (pointer to) memory statistics value (output)
+**
+** Results:
+** 0: success
+** !=0: error
+*/
+
+int
+sm_memstat_get(resource, pvalue)
+ char *resource;
+ long *pvalue;
+{
+ int r;
+ kstat_named_t *kn;
+
+ if (kc == NULL || kst == NULL)
+ return -1;
+ if (kstat_read(kc, kst, NULL) == -1)
+ return (errno != 0) ? errno : -2;
+ kn = kstat_data_lookup(kst,
+ (resource != NULL) ? resource: "freemem");
+ if (kn == NULL)
+ return (errno != 0) ? errno : -3;
+ *pvalue = kn->value.ul;
+ return 0;
+}
+
+#elif USEPROCMEMINFO
+
+/*
+/proc/meminfo?
+ total: used: free: shared: buffers: cached:
+Mem: 261468160 252149760 9318400 0 3854336 109813760
+Swap: 1052794880 62185472 990609408
+MemTotal: 255340 kB
+MemFree: 9100 kB
+MemShared: 0 kB
+Buffers: 3764 kB
+Cached: 107240 kB
+Active: 104340 kB
+Inact_dirty: 4220 kB
+Inact_clean: 2444 kB
+Inact_target: 4092 kB
+HighTotal: 0 kB
+HighFree: 0 kB
+LowTotal: 255340 kB
+LowFree: 9100 kB
+SwapTotal: 1028120 kB
+SwapFree: 967392 kB
+*/
+
+#include <stdio.h>
+#include <string.h>
+static FILE *fp;
+
+/*
+** SM_MEMSTAT_OPEN -- open memory statistics
+**
+** Parameters:
+** none
+**
+** Results:
+** errno as error code, 0: ok
+*/
+
+int
+sm_memstat_open()
+{
+ fp = fopen("/proc/meminfo", "r");
+ return (fp != NULL) ? 0 : errno;
+}
+
+/*
+** SM_MEMSTAT_CLOSE -- close memory statistics
+**
+** Parameters:
+** none
+**
+** Results:
+** errno as error code, 0: ok
+*/
+
+int
+sm_memstat_close()
+{
+ if (fp != NULL)
+ {
+ fclose(fp);
+ fp = NULL;
+ }
+ return 0;
+}
+
+/*
+** SM_MEMSTAT_GET -- get memory statistics
+**
+** Parameters:
+** resource -- resource to look up
+** pvalue -- (pointer to) memory statistics value (output)
+**
+** Results:
+** 0: success
+** !=0: error
+*/
+
+int
+sm_memstat_get(resource, pvalue)
+ char *resource;
+ long *pvalue;
+{
+ int r;
+ size_t l;
+ char buf[80];
+
+ if (resource == NULL)
+ return EINVAL;
+ if (pvalue == NULL)
+ return EINVAL;
+ if (fp == NULL)
+ return -1; /* try to reopen? */
+ rewind(fp);
+ l = strlen(resource);
+ while (fgets(buf, sizeof(buf), fp) != NULL)
+ {
+ if (strncmp(buf, resource, l) == 0 && buf[l] == ':')
+ {
+ r = sscanf(buf + l + 1, "%ld", pvalue);
+ return (r > 0) ? 0 : -1;
+ }
+ }
+ return 0;
+}
+
+#else /* USEPROCMEMINFO */
+
+/*
+** SM_MEMSTAT_OPEN -- open memory statistics
+**
+** Parameters:
+** none
+**
+** Results:
+** errno as error code, 0: ok
+*/
+
+int
+sm_memstat_open()
+{
+ return -1;
+}
+
+/*
+** SM_MEMSTAT_CLOSE -- close memory statistics
+**
+** Parameters:
+** none
+**
+** Results:
+** errno as error code, 0: ok
+*/
+
+int
+sm_memstat_close()
+{
+ return 0;
+}
+
+/*
+** SM_MEMSTAT_GET -- get memory statistics
+**
+** Parameters:
+** resource -- resource to look up
+** pvalue -- (pointer to) memory statistics value (output)
+**
+** Results:
+** 0: success
+** !=0: error
+*/
+
+int
+sm_memstat_get(resource, pvalue)
+ char *resource;
+ long *pvalue;
+{
+ return -1;
+}
+
+#endif /* USEKSTAT */
diff --git a/usr/src/cmd/sendmail/libsm/snprintf.c b/usr/src/cmd/sendmail/libsm/snprintf.c
index c31f8cf227..7652661d90 100644
--- a/usr/src/cmd/sendmail/libsm/snprintf.c
+++ b/usr/src/cmd/sendmail/libsm/snprintf.c
@@ -15,10 +15,11 @@
#pragma ident "%Z%%M% %I% %E% SMI"
#include <sm/gen.h>
-SM_RCSID("@(#)$Id: snprintf.c,v 1.21 2001/03/02 23:53:41 ca 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/usr/src/cmd/sendmail/libsm/t-memstat.c b/usr/src/cmd/sendmail/libsm/t-memstat.c
new file mode 100644
index 0000000000..6174dbc885
--- /dev/null
+++ b/usr/src/cmd/sendmail/libsm/t-memstat.c
@@ -0,0 +1,99 @@
+/*
+ * Copyright (c) 2005, 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.
+ */
+
+#pragma ident "%Z%%M% %I% %E% SMI"
+
+#include <sm/gen.h>
+SM_IDSTR(id, "@(#)$Id: t-memstat.c,v 1.7 2006/06/28 23:57:59 ca Exp $")
+
+#include <sm/misc.h>
+
+/*
+** Simple test program for memstat
+*/
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <strings.h>
+#include <string.h>
+
+extern char *optarg;
+extern int optind;
+
+int
+main(argc, argv)
+ int argc;
+ char **argv;
+{
+ int r, r2, i, l, slp, sz;
+ long v;
+ char *resource;
+
+ l = 1;
+ sz = slp = 0;
+ resource = NULL;
+ while ((r = getopt(argc, argv, "l:m:r:s:")) != -1)
+ {
+ switch ((char) r)
+ {
+ case 'l':
+ l = strtol(optarg, NULL, 0);
+ break;
+
+ case 'm':
+ sz = strtol(optarg, NULL, 0);
+ break;
+
+ case 'r':
+ resource = strdup(optarg);
+ break;
+
+ case 's':
+ slp = strtol(optarg, NULL, 0);
+ break;
+
+ default:
+ break;
+ }
+ }
+
+ r = sm_memstat_open();
+ r2 = -1;
+ for (i = 0; i < l; i++)
+ {
+ char *mem;
+
+ r2 = sm_memstat_get(resource, &v);
+ if (slp > 0 && i + 1 < l && 0 == r)
+ {
+ printf("open=%d, memstat=%d, %s=%ld\n", r, r2,
+ resource != NULL ? resource : "default-value",
+ v);
+ sleep(slp);
+ if (sz > 0)
+ {
+ /*
+ ** Just allocate some memory to test the
+ ** values that are returned.
+ ** Note: this is a memory leak, but that
+ ** doesn't matter here.
+ */
+
+ mem = malloc(sz);
+ if (NULL == mem)
+ printf("malloc(%d) failed\n", sz);
+ }
+ }
+ }
+ printf("open=%d, memstat=%d, %s=%ld\n", r, r2,
+ resource != NULL ? resource : "default-value", v);
+ r = sm_memstat_close();
+ return r;
+}
diff --git a/usr/src/cmd/sendmail/libsm/t-qic.c b/usr/src/cmd/sendmail/libsm/t-qic.c
new file mode 100644
index 0000000000..33806caa16
--- /dev/null
+++ b/usr/src/cmd/sendmail/libsm/t-qic.c
@@ -0,0 +1,237 @@
+/*
+ * 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.
+ */
+
+#pragma ident "%Z%%M% %I% %E% SMI"
+
+#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/usr/src/cmd/sendmail/libsm/util.c b/usr/src/cmd/sendmail/libsm/util.c
new file mode 100644
index 0000000000..64f3ac1e4a
--- /dev/null
+++ b/usr/src/cmd/sendmail/libsm/util.c
@@ -0,0 +1,252 @@
+/*
+ * 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.
+ *
+ */
+
+#pragma ident "%Z%%M% %I% %E% SMI"
+
+#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/usr/src/cmd/sendmail/libsm/vfscanf.c b/usr/src/cmd/sendmail/libsm/vfscanf.c
index bed5ba34c3..5bf0ffbac2 100644
--- a/usr/src/cmd/sendmail/libsm/vfscanf.c
+++ b/usr/src/cmd/sendmail/libsm/vfscanf.c
@@ -15,7 +15,7 @@
#pragma ident "%Z%%M% %I% %E% SMI"
#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>
@@ -124,7 +124,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;