2 * Copyright (c) 2000-2003, 2007 Proofpoint, Inc. and its suppliers.
5 * By using this file, you agree to the terms and conditions set
6 * forth in the LICENSE file which can be found at the top level of
7 * the sendmail distribution.
12 SM_RCSID("@(#)$Id: config.c,v 1.32 2013-11-22 20:51:42 ca Exp $")
16 #include <sm/string.h>
20 ** PUTENV -- emulation of putenv() in terms of setenv()
22 ** Not needed on Posix-compliant systems.
23 ** This doesn't have full Posix semantics, but it's good enough
27 ** env -- the environment to put.
30 ** 0 on success, < 0 on failure.
35 # if NEEDPUTENV == 2 /* no setenv(3) call available */
42 int matchlen, envlen = 0;
45 static bool first = true;
46 extern char **environ;
49 ** find out how much of str to match when searching
50 ** for a string to replace.
53 if ((tmp = strchr(str, '=')) == NULL || tmp == str)
54 matchlen = strlen(str);
56 matchlen = (int) (tmp - str);
60 ** Search for an existing string in the environment and find the
61 ** length of environ. If found, replace and exit.
64 for (current = environ; *current != NULL; current++)
68 if (strncmp(str, *current, matchlen) == 0)
70 /* found it, now insert the new version */
71 *current = (char *) str;
77 ** There wasn't already a slot so add space for a new slot.
78 ** If this is our first time through, use malloc(), else realloc().
83 newenv = (char **) sm_malloc(sizeof(char *) * (envlen + 2));
88 (void) memcpy(newenv, environ, sizeof(char *) * envlen);
92 newenv = (char **) sm_realloc((char *) environ,
93 sizeof(char *) * (envlen + 2));
98 /* actually add in the new entry */
100 environ[envlen] = (char *) str;
101 environ[envlen + 1] = NULL;
106 # else /* NEEDPUTENV == 2 */
116 p = strchr(env, '=');
120 if (l > sizeof nbuf - 1)
122 memmove(nbuf, env, l);
124 return setenv(nbuf, ++p, 1);
127 # endif /* NEEDPUTENV == 2 */
128 #endif /* NEEDPUTENV */
130 ** UNSETENV -- remove a variable from the environment
132 ** Not needed on newer systems.
135 ** name -- the string name of the environment variable to be
136 ** deleted from the current environment.
142 ** environ -- a pointer to the current environment.
154 extern char **environ;
156 int len = strlen(name);
158 for (pp = environ; *pp != NULL; pp++)
160 if (strncmp(name, *pp, len) == 0 &&
161 ((*pp)[len] == '=' || (*pp)[len] == '\0'))
165 for (; *pp != NULL; pp++)
169 #endif /* !HASUNSETENV */
171 char *SmCompileOptions[] =
173 #if SM_CONF_BROKEN_STRTOD
174 "SM_CONF_BROKEN_STRTOD",
179 #if SM_CONF_LDAP_INITIALIZE
180 "SM_CONF_LDAP_INITIALIZE",
182 #if SM_CONF_LDAP_MEMFREE
183 "SM_CONF_LDAP_MEMFREE",
200 #if SM_CONF_SETITIMER
203 #if SM_CONF_SIGSETJMP
209 #if SM_CONF_SHM_DELAY
215 #if SM_CONF_STDBOOL_H
223 /* XXX this is always enabled (for now) */
229 #if SM_CONF_SYS_CDEFS_H
230 "SM_CONF_SYS_CDEFS_H",
232 #if SM_CONF_SYSEXITS_H
233 "SM_CONF_SYSEXITS_H",
238 #if DO_NOT_USE_STRCPY
244 #if defined(SM_OS_NAME) && defined(__STDC__)
245 "SM_OS=sm_os_" SM_OS_NAME,