summaryrefslogtreecommitdiffstats
path: root/contrib/sendmail/libsm
diff options
context:
space:
mode:
authorgshapiro <gshapiro@FreeBSD.org>2010-01-26 04:41:15 +0000
committergshapiro <gshapiro@FreeBSD.org>2010-01-26 04:41:15 +0000
commit06af2946772550af5ad9eea974674de7bde4243b (patch)
tree6c6c3749a8b863bd3e7a5962fc9189f1a3e34f9c /contrib/sendmail/libsm
parentc1aec8d8e06eaf4b4e5066794fecde82622b6366 (diff)
downloadFreeBSD-src-06af2946772550af5ad9eea974674de7bde4243b.zip
FreeBSD-src-06af2946772550af5ad9eea974674de7bde4243b.tar.gz
Merge sendmail 8.14.4 to HEAD
MFC after: 4 days
Diffstat (limited to 'contrib/sendmail/libsm')
-rw-r--r--contrib/sendmail/libsm/debug.c31
-rw-r--r--contrib/sendmail/libsm/ldap.c33
-rw-r--r--contrib/sendmail/libsm/mbdb.c19
-rw-r--r--contrib/sendmail/libsm/sem.c46
-rw-r--r--contrib/sendmail/libsm/t-sem.c70
5 files changed, 179 insertions, 20 deletions
diff --git a/contrib/sendmail/libsm/debug.c b/contrib/sendmail/libsm/debug.c
index f9281fd..ea9cd84 100644
--- a/contrib/sendmail/libsm/debug.c
+++ b/contrib/sendmail/libsm/debug.c
@@ -8,7 +8,7 @@
*/
#include <sm/gen.h>
-SM_RCSID("@(#)$Id: debug.c,v 1.30 2004/08/03 20:10:26 ca Exp $")
+SM_RCSID("@(#)$Id: debug.c,v 1.32 2009/09/20 05:38:46 ca Exp $")
/*
** libsm debugging and tracing
@@ -17,6 +17,10 @@ SM_RCSID("@(#)$Id: debug.c,v 1.30 2004/08/03 20:10:26 ca Exp $")
#include <ctype.h>
#include <stdlib.h>
+#if _FFR_DEBUG_PID_TIME
+#include <unistd.h>
+#include <time.h>
+#endif /* _FFR_DEBUG_PID_TIME */
#include <setjmp.h>
#include <sm/io.h>
#include <sm/assert.h>
@@ -112,6 +116,11 @@ sm_debug_close()
** none.
*/
+#if _FFR_DEBUG_PID_TIME
+SM_DEBUG_T SmDBGPidTime = SM_DEBUG_INITIALIZER("sm_trace_pid_time",
+ "@(#)$Debug: sm_trace_pid_time - print pid and time in debug $");
+#endif /* _FFR_DEBUG_PID_TIME */
+
void
#if SM_VA_STD
sm_dprintf(char *fmt, ...)
@@ -125,6 +134,26 @@ sm_dprintf(fmt, va_alist)
if (SmDebugOutput == NULL)
return;
+#if _FFR_DEBUG_PID_TIME
+ /* note: this is ugly if the output isn't a full line! */
+ if (sm_debug_active(&SmDBGPidTime, 1))
+ {
+ static char str[32] = "[1900-00-00/00:00:00] ";
+ struct tm *tmp;
+ time_t currt;
+
+ currt = time((time_t *)0);
+ tmp = localtime(&currt);
+ snprintf(str, sizeof(str), "[%d-%02d-%02d/%02d:%02d:%02d] ",
+ 1900 + tmp->tm_year, /* HACK */
+ tmp->tm_mon + 1,
+ tmp->tm_mday,
+ tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
+ sm_io_fprintf(SmDebugOutput, SmDebugOutput->f_timeout,
+ "%ld: %s ", (long) getpid(), str);
+ }
+#endif /* _FFR_DEBUG_PID_TIME */
+
SM_VA_START(ap, fmt);
sm_io_vfprintf(SmDebugOutput, SmDebugOutput->f_timeout, fmt, ap);
SM_VA_END(ap);
diff --git a/contrib/sendmail/libsm/ldap.c b/contrib/sendmail/libsm/ldap.c
index 252e547..7ee57fc 100644
--- a/contrib/sendmail/libsm/ldap.c
+++ b/contrib/sendmail/libsm/ldap.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2001-2007 Sendmail, Inc. and its suppliers.
+ * Copyright (c) 2001-2009 Sendmail, Inc. and its suppliers.
* All rights reserved.
*
* By using this file, you agree to the terms and conditions set
@@ -11,7 +11,7 @@
#define LDAP_DEPRECATED 1
#include <sm/gen.h>
-SM_RCSID("@(#)$Id: ldap.c,v 1.80 2007/10/12 00:19:44 ca Exp $")
+SM_RCSID("@(#)$Id: ldap.c,v 1.83 2009/06/19 22:02:26 guenther Exp $")
#if LDAPMAP
# include <sys/types.h>
@@ -1099,7 +1099,21 @@ sm_ldap_results(lmap, msgid, flags, delim, rpool, result,
if (ret == 0)
save_errno = ETIMEDOUT;
else
- save_errno = sm_ldap_geterrno(lmap->ldap_ld);
+ {
+ int rc;
+
+ /*
+ ** We may have gotten an LDAP_RES_SEARCH_RESULT response
+ ** with an error inside it, so we have to extract that
+ ** with ldap_parse_result(). This can happen when talking
+ ** to an LDAP proxy whose backend has gone down.
+ */
+
+ save_errno = ldap_parse_result(lmap->ldap_ld, lmap->ldap_res,
+ &rc, NULL, NULL, NULL, NULL, 0);
+ if (save_errno == LDAP_SUCCESS)
+ save_errno = rc;
+ }
if (save_errno != LDAP_SUCCESS)
{
statp = EX_TEMPFAIL;
@@ -1370,9 +1384,16 @@ sm_ldap_setopts(ld, lmap)
ldap_set_option(ld, LDAP_OPT_REFERRALS, LDAP_OPT_OFF);
ldap_set_option(ld, LDAP_OPT_SIZELIMIT, &lmap->ldap_sizelimit);
ldap_set_option(ld, LDAP_OPT_TIMELIMIT, &lmap->ldap_timelimit);
-# if _FFR_LDAP_NETWORK_TIMEOUT && defined(LDAP_OPT_NETWORK_TIMEOUT)
- ldap_set_option(ld, LDAP_OPT_NETWORK_TIMEOUT, &lmap->ldap_networktmo);
-# endif /* _FFR_LDAP_NETWORK_TIMEOUT && defined(LDAP_OPT_NETWORK_TIMEOUT) */
+# if _FFR_LDAP_NETWORK_TIMEOUT && defined(LDAP_OPT_NETWORK_TIMEOUT)
+ if (lmap->ldap_networktmo > 0)
+ {
+ struct timeval tmo;
+
+ tmo.tv_sec = lmap->ldap_networktmo;
+ tmo.tv_usec = 0;
+ ldap_set_option(ld, LDAP_OPT_NETWORK_TIMEOUT, &tmo);
+ }
+# endif /* _FFR_LDAP_NETWORK_TIMEOUT && defined(LDAP_OPT_NETWORK_TIMEOUT) */
# ifdef LDAP_OPT_RESTART
ldap_set_option(ld, LDAP_OPT_RESTART, LDAP_OPT_ON);
# endif /* LDAP_OPT_RESTART */
diff --git a/contrib/sendmail/libsm/mbdb.c b/contrib/sendmail/libsm/mbdb.c
index ad0e7cc..3bb514d 100644
--- a/contrib/sendmail/libsm/mbdb.c
+++ b/contrib/sendmail/libsm/mbdb.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2001-2002 Sendmail, Inc. and its suppliers.
+ * Copyright (c) 2001-2003,2009 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: mbdb.c,v 1.40 2003/12/10 03:19:07 gshapiro Exp $")
+SM_RCSID("@(#)$Id: mbdb.c,v 1.41 2009/06/19 22:02:26 guenther Exp $")
#include <sys/param.h>
@@ -564,7 +564,20 @@ mbdb_ldap_lookup(name, user)
entry = ldap_first_entry(LDAPLMAP.ldap_ld, LDAPLMAP.ldap_res);
if (entry == NULL)
{
- save_errno = sm_ldap_geterrno(LDAPLMAP.ldap_ld);
+ int rc;
+
+ /*
+ ** We may have gotten an LDAP_RES_SEARCH_RESULT response
+ ** with an error inside it, so we have to extract that
+ ** with ldap_parse_result(). This can happen when talking
+ ** to an LDAP proxy whose backend has gone down.
+ */
+
+ save_errno = ldap_parse_result(LDAPLMAP.ldap_ld,
+ LDAPLMAP.ldap_res, &rc, NULL,
+ NULL, NULL, NULL, 0);
+ if (save_errno == LDAP_SUCCESS)
+ save_errno = rc;
if (save_errno == LDAP_SUCCESS)
{
errno = ENOENT;
diff --git a/contrib/sendmail/libsm/sem.c b/contrib/sendmail/libsm/sem.c
index 89394cb..83a54e3 100644
--- a/contrib/sendmail/libsm/sem.c
+++ b/contrib/sendmail/libsm/sem.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000-2001, 2005 Sendmail, Inc. and its suppliers.
+ * Copyright (c) 2000-2001, 2005, 2008 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_RCSID("@(#)$Id: sem.c,v 1.13 2005/08/12 20:39:59 ca Exp $")
+SM_RCSID("@(#)$Id: sem.c,v 1.14 2008/05/30 16:26:38 ca Exp $")
#if SM_CONF_SEM
# include <stdlib.h>
# include <unistd.h>
+# include <sm/string.h>
# include <sm/sem.h>
# include <sm/heap.h>
# include <errno.h>
@@ -200,4 +201,45 @@ sm_sem_get(semid, semnum)
return -1;
return semval;
}
+
+/*
+** SM_SEMSETOWNER -- set owner/group/mode of semaphores.
+**
+** Parameters:
+** semid -- id for semaphores.
+** uid -- uid to use
+** gid -- gid to use
+** mode -- mode to use
+**
+** Returns:
+** 0 on success.
+** < 0 on failure.
+*/
+
+int
+sm_semsetowner(semid, uid, gid, mode)
+ int semid;
+ uid_t uid;
+ gid_t gid;
+ mode_t mode;
+{
+ int r;
+ struct semid_ds semidds;
+ union semun {
+ int val;
+ struct semid_ds *buf;
+ ushort *array;
+ } arg;
+
+ memset(&semidds, 0, sizeof(semidds));
+ arg.buf = &semidds;
+ if ((r = semctl(semid, 1, IPC_STAT, arg)) < 0)
+ return r;
+ semidds.sem_perm.uid = uid;
+ semidds.sem_perm.gid = gid;
+ semidds.sem_perm.mode = mode;
+ if ((r = semctl(semid, 1, IPC_SET, arg)) < 0)
+ return r;
+ return 0;
+}
#endif /* SM_CONF_SEM */
diff --git a/contrib/sendmail/libsm/t-sem.c b/contrib/sendmail/libsm/t-sem.c
index 24d0563..662b4f6 100644
--- a/contrib/sendmail/libsm/t-sem.c
+++ b/contrib/sendmail/libsm/t-sem.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000-2001, 2005-2007 Sendmail, Inc. and its suppliers.
+ * Copyright (c) 2000-2001, 2005-2008 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.16 2007/03/21 23:22:10 ca Exp $")
+SM_RCSID("@(#)$Id: t-sem.c,v 1.17 2008/05/30 16:26:38 ca Exp $")
#include <stdio.h>
@@ -127,6 +127,20 @@ sem_cleanup(sig)
exit(EX_UNAVAILABLE);
}
+static int
+drop_priv(uid, gid)
+ uid_t uid;
+ gid_t gid;
+{
+ int r;
+
+ r = setgid(gid);
+ if (r != 0)
+ return r;
+ r = setuid(uid);
+ return r;
+}
+
/*
** SEMTEST -- test of semaphores
**
@@ -141,12 +155,23 @@ sem_cleanup(sig)
# define MAX_CNT 10
static int
-semtest(owner)
+semtest(owner, uid, gid)
int owner;
+ uid_t uid;
+ gid_t gid;
{
int semid, r;
int cnt = 0;
+ if (!owner && uid != 0)
+ {
+ r = drop_priv(uid, gid);
+ if (r < 0)
+ {
+ perror("drop_priv child failed");
+ return -1;
+ }
+ }
semid = sm_sem_start(T_SM_SEM_KEY, 1, 0, owner);
if (semid < 0)
{
@@ -156,6 +181,22 @@ semtest(owner)
if (owner)
{
+ if (uid != 0)
+ {
+ r = sm_semsetowner(semid, uid, gid, 0660);
+ if (r < 0)
+ {
+ perror("sm_semsetowner failed");
+ return -1;
+ }
+ r = drop_priv(uid, gid);
+ if (r < 0)
+ {
+ perror("drop_priv owner failed");
+ return -1;
+ }
+ }
+
/* just in case someone kills the program... */
semid_c = semid;
(void) sm_signal(SIGHUP, sem_cleanup);
@@ -281,18 +322,31 @@ main(argc, argv)
{
bool interactive = false;
bool owner = false;
- int ch;
- int r = 0;
+ int ch, r;
+ uid_t uid;
+ gid_t gid;
+
+ uid = 0;
+ gid = 0;
+ r = 0;
-# define OPTIONS "io"
+# define OPTIONS "iog:u:"
while ((ch = getopt(argc, argv, OPTIONS)) != -1)
{
switch ((char) ch)
{
+ case 'g':
+ gid = (gid_t)strtoul(optarg, 0, 0);
+ break;
+
case 'i':
interactive = true;
break;
+ case 'u':
+ uid = (uid_t)strtoul(optarg, 0, 0);
+ break;
+
case 'o':
owner = true;
break;
@@ -323,11 +377,11 @@ main(argc, argv)
{
/* give the parent the chance to setup data */
sleep(1);
- r = semtest(false);
+ r = semtest(false, uid, gid);
}
else
{
- r = semtest(true);
+ r = semtest(true, uid, gid);
}
SM_TEST(r == 0);
return sm_test_end();
OpenPOWER on IntegriCloud