config.c revision 95154
1/* 2 * Copyright (c) 2000-2001 Sendmail, Inc. and its suppliers. 3 * All rights reserved. 4 * 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. 8 * 9 */ 10 11#include <sm/gen.h> 12SM_RCSID("@(#)$Id: config.c,v 1.1.1.2 2002/04/10 03:04:55 gshapiro Exp $") 13 14#include <stdlib.h> 15#include <sm/heap.h> 16#include <sm/string.h> 17#include <sm/conf.h> 18 19/* 20** PUTENV -- emulation of putenv() in terms of setenv() 21** 22** Not needed on Posix-compliant systems. 23** This doesn't have full Posix semantics, but it's good enough 24** for sendmail. 25** 26** Parameter: 27** env -- the environment to put. 28** 29** Returns: 30** 0 on success, < 0 on failure. 31*/ 32 33#if NEEDPUTENV 34 35# if NEEDPUTENV == 2 /* no setenv(3) call available */ 36 37int 38putenv(str) 39 char *str; 40{ 41 char **current; 42 int matchlen, envlen = 0; 43 char *tmp; 44 char **newenv; 45 static bool first = true; 46 extern char **environ; 47 48 /* 49 ** find out how much of str to match when searching 50 ** for a string to replace. 51 */ 52 53 if ((tmp = strchr(str, '=')) == NULL || tmp == str) 54 matchlen = strlen(str); 55 else 56 matchlen = (int) (tmp - str); 57 ++matchlen; 58 59 /* 60 ** Search for an existing string in the environment and find the 61 ** length of environ. If found, replace and exit. 62 */ 63 64 for (current = environ; *current != NULL; current++) 65 { 66 ++envlen; 67 68 if (strncmp(str, *current, matchlen) == 0) 69 { 70 /* found it, now insert the new version */ 71 *current = (char *) str; 72 return 0; 73 } 74 } 75 76 /* 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(). 79 */ 80 81 if (first) 82 { 83 newenv = (char **) sm_malloc(sizeof(char *) * (envlen + 2)); 84 if (newenv == NULL) 85 return -1; 86 87 first = false; 88 (void) memcpy(newenv, environ, sizeof(char *) * envlen); 89 } 90 else 91 { 92 newenv = (char **) sm_realloc((char *) environ, 93 sizeof(char *) * (envlen + 2)); 94 if (newenv == NULL) 95 return -1; 96 } 97 98 /* actually add in the new entry */ 99 environ = newenv; 100 environ[envlen] = (char *) str; 101 environ[envlen + 1] = NULL; 102 103 return 0; 104} 105 106# else /* NEEDPUTENV == 2 */ 107 108int 109putenv(env) 110 char *env; 111{ 112 char *p; 113 int l; 114 char nbuf[100]; 115 116 p = strchr(env, '='); 117 if (p == NULL) 118 return 0; 119 l = p - env; 120 if (l > sizeof nbuf - 1) 121 l = sizeof nbuf - 1; 122 memmove(nbuf, env, l); 123 nbuf[l] = '\0'; 124 return setenv(nbuf, ++p, 1); 125} 126 127# endif /* NEEDPUTENV == 2 */ 128#endif /* NEEDPUTENV */ 129/* 130** UNSETENV -- remove a variable from the environment 131** 132** Not needed on newer systems. 133** 134** Parameters: 135** name -- the string name of the environment variable to be 136** deleted from the current environment. 137** 138** Returns: 139** none. 140** 141** Globals: 142** environ -- a pointer to the current environment. 143** 144** Side Effects: 145** Modifies environ. 146*/ 147 148#if !HASUNSETENV 149 150void 151unsetenv(name) 152 char *name; 153{ 154 extern char **environ; 155 register char **pp; 156 int len = strlen(name); 157 158 for (pp = environ; *pp != NULL; pp++) 159 { 160 if (strncmp(name, *pp, len) == 0 && 161 ((*pp)[len] == '=' || (*pp)[len] == '\0')) 162 break; 163 } 164 165 for (; *pp != NULL; pp++) 166 *pp = pp[1]; 167} 168 169#endif /* !HASUNSETENV */ 170 171char *SmCompileOptions[] = 172{ 173#if SM_CONF_BROKEN_STRTOD 174 "SM_CONF_BROKEN_STRTOD", 175#endif /* SM_CONF_BROKEN_STRTOD */ 176#if SM_CONF_GETOPT 177 "SM_CONF_GETOPT", 178#endif /* SM_CONF_GETOPT */ 179#if SM_CONF_LDAP_MEMFREE 180 "SM_CONF_LDAP_MEMFREE", 181#endif /* SM_CONF_LDAP_MEMFREE */ 182#if SM_CONF_LONGLONG 183 "SM_CONF_LONGLONG", 184#endif /* SM_CONF_LONGLONG */ 185#if SM_CONF_MEMCHR 186 "SM_CONF_MEMCHR", 187#endif /* SM_CONF_MEMCHR */ 188#if SM_CONF_MSG 189 "SM_CONF_MSG", 190#endif /* SM_CONF_MSG */ 191#if SM_CONF_QUAD_T 192 "SM_CONF_QUAD_T", 193#endif /* SM_CONF_QUAD_T */ 194#if SM_CONF_SEM 195 "SM_CONF_SEM", 196#endif /* SM_CONF_SEM */ 197#if SM_CONF_SETITIMER 198 "SM_CONF_SETITIMER", 199#endif /* SM_CONF_SETITIMER */ 200#if SM_CONF_SHM 201 "SM_CONF_SHM", 202#endif /* SM_CONF_SHM */ 203#if SM_CONF_SHM_DELAY 204 "SM_CONF_SHM_DELAY", 205#endif /* SM_CONF_SHM_DELAY */ 206#if SM_CONF_SSIZE_T 207 "SM_CONF_SSIZE_T", 208#endif /* SM_CONF_SSIZE_T */ 209#if SM_CONF_STDBOOL_H 210 "SM_CONF_STDBOOL_H", 211#endif /* SM_CONF_STDBOOL_H */ 212#if SM_CONF_STDDEF_H 213 "SM_CONF_STDDEF_H", 214#endif /* SM_CONF_STDDEF_H */ 215 216#if 0 217/* XXX this is always enabled (for now) */ 218#if SM_CONF_STRL 219 "SM_CONF_STRL", 220#endif /* SM_CONF_STRL */ 221#endif /* 0 */ 222 223#if SM_CONF_SYS_CDEFS_H 224 "SM_CONF_SYS_CDEFS_H", 225#endif /* SM_CONF_SYS_CDEFS_H */ 226#if SM_CONF_SYSEXITS_H 227 "SM_CONF_SYSEXITS_H", 228#endif /* SM_CONF_SYSEXITS_H */ 229#if SM_CONF_UID_GID 230 "SM_CONF_UID_GID", 231#endif /* SM_CONF_UID_GID */ 232#if SM_HEAP_CHECK 233 "SM_HEAP_CHECK", 234#endif /* SM_HEAP_CHECK */ 235#if defined(SM_OS_NAME) && defined(__STDC__) 236 "SM_OS=sm_os_" SM_OS_NAME, 237#endif /* defined(SM_OS_NAME) && defined(__STDC__) */ 238#if SM_VA_STD 239 "SM_VA_STD", 240#endif /* SM_VA_STD */ 241 NULL 242}; 243