1 /* 2 * Copyright (c) 1998-2007 Sendmail, Inc. and its suppliers. 3 * All rights reserved. 4 * Copyright (c) 1983, 1995-1997 Eric P. Allman. All rights reserved. 5 * Copyright (c) 1988, 1993 6 * The Regents of the University of California. All rights reserved. 7 * 8 * By using this file, you agree to the terms and conditions set 9 * forth in the LICENSE file which can be found at the top level of 10 * the sendmail distribution. 11 * 12 */ 13 14 /* 15 * Copyright 1999-2006 Sun Microsystems, Inc. All rights reserved. 16 * Use is subject to license terms. 17 */ 18 19 #pragma ident "%Z%%M% %I% %E% SMI" 20 21 #include <sendmail.h> 22 23 SM_RCSID("@(#)$Id: conf.c,v 8.1136 2007/10/10 00:06:45 ca Exp $") 24 SM_IDSTR(i2, "%W% (Sun) %G%") 25 26 #include <sm/sendmail.h> 27 #include <sendmail/pathnames.h> 28 #if NEWDB 29 # include "sm/bdb.h" 30 #endif /* NEWDB */ 31 32 #include <daemon.h> 33 #include "map.h" 34 35 #ifdef DEC 36 # if NETINET6 37 /* for the IPv6 device lookup */ 38 # define _SOCKADDR_LEN 39 # include <macros.h> 40 # endif /* NETINET6 */ 41 #endif /* DEC */ 42 43 # include <sys/ioctl.h> 44 # include <sys/param.h> 45 46 #include <limits.h> 47 #if NETINET || NETINET6 48 # include <arpa/inet.h> 49 #endif /* NETINET || NETINET6 */ 50 #if HASULIMIT && defined(HPUX11) 51 # include <ulimit.h> 52 #endif /* HASULIMIT && defined(HPUX11) */ 53 54 static void setupmaps __P((void)); 55 static void setupmailers __P((void)); 56 static void setupqueues __P((void)); 57 static int get_num_procs_online __P((void)); 58 static int add_hostnames __P((SOCKADDR *)); 59 60 #if NETINET6 && NEEDSGETIPNODE 61 static struct hostent *getipnodebyname __P((char *, int, int, int *)); 62 static struct hostent *getipnodebyaddr __P((char *, int, int, int *)); 63 #endif /* NETINET6 && NEEDSGETIPNODE */ 64 65 66 /* 67 ** CONF.C -- Sendmail Configuration Tables. 68 ** 69 ** Defines the configuration of this installation. 70 ** 71 ** Configuration Variables: 72 ** HdrInfo -- a table describing well-known header fields. 73 ** Each entry has the field name and some flags, 74 ** which are described in sendmail.h. 75 ** 76 ** Notes: 77 ** I have tried to put almost all the reasonable 78 ** configuration information into the configuration 79 ** file read at runtime. My intent is that anything 80 ** here is a function of the version of UNIX you 81 ** are running, or is really static -- for example 82 ** the headers are a superset of widely used 83 ** protocols. If you find yourself playing with 84 ** this file too much, you may be making a mistake! 85 */ 86 87 88 /* 89 ** Header info table 90 ** Final (null) entry contains the flags used for any other field. 91 ** 92 ** Not all of these are actually handled specially by sendmail 93 ** at this time. They are included as placeholders, to let 94 ** you know that "someday" I intend to have sendmail do 95 ** something with them. 96 */ 97 98 struct hdrinfo HdrInfo[] = 99 { 100 /* originator fields, most to least significant */ 101 { "resent-sender", H_FROM|H_RESENT, NULL }, 102 { "resent-from", H_FROM|H_RESENT, NULL }, 103 { "resent-reply-to", H_FROM|H_RESENT, NULL }, 104 { "sender", H_FROM, NULL }, 105 { "from", H_FROM, NULL }, 106 { "reply-to", H_FROM, NULL }, 107 { "errors-to", H_FROM|H_ERRORSTO, NULL }, 108 { "full-name", H_ACHECK, NULL }, 109 { "return-receipt-to", H_RECEIPTTO, NULL }, 110 { "delivery-receipt-to", H_RECEIPTTO, NULL }, 111 { "disposition-notification-to", H_FROM, NULL }, 112 113 /* destination fields */ 114 { "to", H_RCPT, NULL }, 115 { "resent-to", H_RCPT|H_RESENT, NULL }, 116 { "cc", H_RCPT, NULL }, 117 { "resent-cc", H_RCPT|H_RESENT, NULL }, 118 { "bcc", H_RCPT|H_BCC, NULL }, 119 { "resent-bcc", H_RCPT|H_BCC|H_RESENT, NULL }, 120 { "apparently-to", H_RCPT, NULL }, 121 122 /* message identification and control */ 123 { "message-id", 0, NULL }, 124 { "resent-message-id", H_RESENT, NULL }, 125 { "message", H_EOH, NULL }, 126 { "text", H_EOH, NULL }, 127 128 /* date fields */ 129 { "date", 0, NULL }, 130 { "resent-date", H_RESENT, NULL }, 131 132 /* trace fields */ 133 { "received", H_TRACE|H_FORCE, NULL }, 134 { "x400-received", H_TRACE|H_FORCE, NULL }, 135 { "via", H_TRACE|H_FORCE, NULL }, 136 { "mail-from", H_TRACE|H_FORCE, NULL }, 137 138 /* miscellaneous fields */ 139 { "comments", H_FORCE|H_ENCODABLE, NULL }, 140 { "return-path", H_FORCE|H_ACHECK|H_BINDLATE, NULL }, 141 { "content-transfer-encoding", H_CTE, NULL }, 142 { "content-type", H_CTYPE, NULL }, 143 { "content-length", H_ACHECK, NULL }, 144 { "subject", H_ENCODABLE, NULL }, 145 { "x-authentication-warning", H_FORCE, NULL }, 146 147 { NULL, 0, NULL } 148 }; 149 150 151 152 /* 153 ** Privacy values 154 */ 155 156 struct prival PrivacyValues[] = 157 { 158 { "public", PRIV_PUBLIC }, 159 { "needmailhelo", PRIV_NEEDMAILHELO }, 160 { "needexpnhelo", PRIV_NEEDEXPNHELO }, 161 { "needvrfyhelo", PRIV_NEEDVRFYHELO }, 162 { "noexpn", PRIV_NOEXPN }, 163 { "novrfy", PRIV_NOVRFY }, 164 { "restrictexpand", PRIV_RESTRICTEXPAND }, 165 { "restrictmailq", PRIV_RESTRICTMAILQ }, 166 { "restrictqrun", PRIV_RESTRICTQRUN }, 167 { "noetrn", PRIV_NOETRN }, 168 { "noverb", PRIV_NOVERB }, 169 { "authwarnings", PRIV_AUTHWARNINGS }, 170 { "noreceipts", PRIV_NORECEIPTS }, 171 { "nobodyreturn", PRIV_NOBODYRETN }, 172 { "goaway", PRIV_GOAWAY }, 173 { "noactualrecipient", PRIV_NOACTUALRECIPIENT }, 174 { NULL, 0 } 175 }; 176 177 /* 178 ** DontBlameSendmail values 179 */ 180 181 struct dbsval DontBlameSendmailValues[] = 182 { 183 { "safe", DBS_SAFE }, 184 { "assumesafechown", DBS_ASSUMESAFECHOWN }, 185 { "groupwritabledirpathsafe", DBS_GROUPWRITABLEDIRPATHSAFE }, 186 { "groupwritableforwardfilesafe", 187 DBS_GROUPWRITABLEFORWARDFILESAFE }, 188 { "groupwritableincludefilesafe", 189 DBS_GROUPWRITABLEINCLUDEFILESAFE }, 190 { "groupwritablealiasfile", DBS_GROUPWRITABLEALIASFILE }, 191 { "worldwritablealiasfile", DBS_WORLDWRITABLEALIASFILE }, 192 { "forwardfileinunsafedirpath", DBS_FORWARDFILEINUNSAFEDIRPATH }, 193 { "includefileinunsafedirpath", DBS_INCLUDEFILEINUNSAFEDIRPATH }, 194 { "mapinunsafedirpath", DBS_MAPINUNSAFEDIRPATH }, 195 { "linkedaliasfileinwritabledir", 196 DBS_LINKEDALIASFILEINWRITABLEDIR }, 197 { "linkedclassfileinwritabledir", 198 DBS_LINKEDCLASSFILEINWRITABLEDIR }, 199 { "linkedforwardfileinwritabledir", 200 DBS_LINKEDFORWARDFILEINWRITABLEDIR }, 201 { "linkedincludefileinwritabledir", 202 DBS_LINKEDINCLUDEFILEINWRITABLEDIR }, 203 { "linkedmapinwritabledir", DBS_LINKEDMAPINWRITABLEDIR }, 204 { "linkedserviceswitchfileinwritabledir", 205 DBS_LINKEDSERVICESWITCHFILEINWRITABLEDIR }, 206 { "filedeliverytohardlink", DBS_FILEDELIVERYTOHARDLINK }, 207 { "filedeliverytosymlink", DBS_FILEDELIVERYTOSYMLINK }, 208 { "writemaptohardlink", DBS_WRITEMAPTOHARDLINK }, 209 { "writemaptosymlink", DBS_WRITEMAPTOSYMLINK }, 210 { "writestatstohardlink", DBS_WRITESTATSTOHARDLINK }, 211 { "writestatstosymlink", DBS_WRITESTATSTOSYMLINK }, 212 { "forwardfileingroupwritabledirpath", 213 DBS_FORWARDFILEINGROUPWRITABLEDIRPATH }, 214 { "includefileingroupwritabledirpath", 215 DBS_INCLUDEFILEINGROUPWRITABLEDIRPATH }, 216 { "classfileinunsafedirpath", DBS_CLASSFILEINUNSAFEDIRPATH }, 217 { "errorheaderinunsafedirpath", DBS_ERRORHEADERINUNSAFEDIRPATH }, 218 { "helpfileinunsafedirpath", DBS_HELPFILEINUNSAFEDIRPATH }, 219 { "forwardfileinunsafedirpathsafe", 220 DBS_FORWARDFILEINUNSAFEDIRPATHSAFE }, 221 { "includefileinunsafedirpathsafe", 222 DBS_INCLUDEFILEINUNSAFEDIRPATHSAFE }, 223 { "runprograminunsafedirpath", DBS_RUNPROGRAMINUNSAFEDIRPATH }, 224 { "runwritableprogram", DBS_RUNWRITABLEPROGRAM }, 225 { "nonrootsafeaddr", DBS_NONROOTSAFEADDR }, 226 { "truststickybit", DBS_TRUSTSTICKYBIT }, 227 { "dontwarnforwardfileinunsafedirpath", 228 DBS_DONTWARNFORWARDFILEINUNSAFEDIRPATH }, 229 { "insufficiententropy", DBS_INSUFFICIENTENTROPY }, 230 { "groupreadablesasldbfile", DBS_GROUPREADABLESASLDBFILE }, 231 { "groupwritablesasldbfile", DBS_GROUPWRITABLESASLDBFILE }, 232 { "groupwritableforwardfile", DBS_GROUPWRITABLEFORWARDFILE }, 233 { "groupwritableincludefile", DBS_GROUPWRITABLEINCLUDEFILE }, 234 { "worldwritableforwardfile", DBS_WORLDWRITABLEFORWARDFILE }, 235 { "worldwritableincludefile", DBS_WORLDWRITABLEINCLUDEFILE }, 236 { "groupreadablekeyfile", DBS_GROUPREADABLEKEYFILE }, 237 #if _FFR_GROUPREADABLEAUTHINFOFILE 238 { "groupreadableadefaultauthinfofile", 239 DBS_GROUPREADABLEAUTHINFOFILE }, 240 #endif /* _FFR_GROUPREADABLEAUTHINFOFILE */ 241 { NULL, 0 } 242 }; 243 244 /* 245 ** Miscellaneous stuff. 246 */ 247 248 int DtableSize = 50; /* max open files; reset in 4.2bsd */ 249 /* 250 ** SETDEFAULTS -- set default values 251 ** 252 ** Some of these must be initialized using direct code since they 253 ** depend on run-time values. So let's do all of them this way. 254 ** 255 ** Parameters: 256 ** e -- the default envelope. 257 ** 258 ** Returns: 259 ** none. 260 ** 261 ** Side Effects: 262 ** Initializes a bunch of global variables to their 263 ** default values. 264 */ 265 266 #define MINUTES * 60 267 #define HOURS * 60 MINUTES 268 #define DAYS * 24 HOURS 269 270 #ifndef MAXRULERECURSION 271 # define MAXRULERECURSION 50 /* max ruleset recursion depth */ 272 #endif /* ! MAXRULERECURSION */ 273 274 void 275 setdefaults(e) 276 register ENVELOPE *e; 277 { 278 int i; 279 int numprocs; 280 struct passwd *pw; 281 282 numprocs = get_num_procs_online(); 283 SpaceSub = ' '; /* option B */ 284 QueueLA = 8 * numprocs; /* option x */ 285 RefuseLA = 12 * numprocs; /* option X */ 286 WkRecipFact = 30000L; /* option y */ 287 WkClassFact = 1800L; /* option z */ 288 WkTimeFact = 90000L; /* option Z */ 289 QueueFactor = WkRecipFact * 20; /* option q */ 290 QueueMode = QM_NORMAL; /* what queue items to act upon */ 291 FileMode = (RealUid != geteuid()) ? 0644 : 0600; 292 /* option F */ 293 QueueFileMode = (RealUid != geteuid()) ? 0644 : 0600; 294 /* option QueueFileMode */ 295 296 if (((pw = sm_getpwnam("mailnull")) != NULL && pw->pw_uid != 0) || 297 ((pw = sm_getpwnam("sendmail")) != NULL && pw->pw_uid != 0) || 298 ((pw = sm_getpwnam("daemon")) != NULL && pw->pw_uid != 0)) 299 { 300 DefUid = pw->pw_uid; /* option u */ 301 DefGid = pw->pw_gid; /* option g */ 302 DefUser = newstr(pw->pw_name); 303 } 304 else 305 { 306 DefUid = 1; /* option u */ 307 DefGid = 1; /* option g */ 308 setdefuser(); 309 } 310 TrustedUid = 0; 311 if (tTd(37, 4)) 312 sm_dprintf("setdefaults: DefUser=%s, DefUid=%d, DefGid=%d\n", 313 DefUser != NULL ? DefUser : "<1:1>", 314 (int) DefUid, (int) DefGid); 315 CheckpointInterval = 10; /* option C */ 316 MaxHopCount = 25; /* option h */ 317 set_delivery_mode(SM_FORK, e); /* option d */ 318 e->e_errormode = EM_PRINT; /* option e */ 319 e->e_qgrp = NOQGRP; 320 e->e_qdir = NOQDIR; 321 e->e_xfqgrp = NOQGRP; 322 e->e_xfqdir = NOQDIR; 323 e->e_ctime = curtime(); 324 SevenBitInput = false; /* option 7 */ 325 MaxMciCache = 1; /* option k */ 326 MciCacheTimeout = 5 MINUTES; /* option K */ 327 LogLevel = 9; /* option L */ 328 #if MILTER 329 MilterLogLevel = -1; 330 #endif /* MILTER */ 331 inittimeouts(NULL, false); /* option r */ 332 PrivacyFlags = PRIV_PUBLIC; /* option p */ 333 MeToo = true; /* option m */ 334 SendMIMEErrors = true; /* option f */ 335 SuperSafe = SAFE_REALLY; /* option s */ 336 clrbitmap(DontBlameSendmail); /* DontBlameSendmail option */ 337 #if MIME8TO7 338 MimeMode = MM_CVTMIME|MM_PASS8BIT; /* option 8 */ 339 #else /* MIME8TO7 */ 340 MimeMode = MM_PASS8BIT; 341 #endif /* MIME8TO7 */ 342 for (i = 0; i < MAXTOCLASS; i++) 343 { 344 TimeOuts.to_q_return[i] = 5 DAYS; /* option T */ 345 TimeOuts.to_q_warning[i] = 0; /* option T */ 346 } 347 ServiceSwitchFile = "/etc/mail/service.switch"; 348 ServiceCacheMaxAge = (time_t) 10; 349 HostsFile = _PATH_HOSTS; 350 PidFile = newstr(_PATH_SENDMAILPID); 351 MustQuoteChars = "@,;:\\()[].'"; 352 MciInfoTimeout = 30 MINUTES; 353 MaxRuleRecursion = MAXRULERECURSION; 354 MaxAliasRecursion = 10; 355 MaxMacroRecursion = 10; 356 ColonOkInAddr = true; 357 DontLockReadFiles = true; 358 DontProbeInterfaces = DPI_PROBEALL; 359 DoubleBounceAddr = "postmaster"; 360 MaxHeadersLength = MAXHDRSLEN; 361 MaxMimeHeaderLength = MAXLINE; 362 MaxMimeFieldLength = MaxMimeHeaderLength / 2; 363 MaxForwardEntries = 0; 364 FastSplit = 1; 365 MaxNOOPCommands = MAXNOOPCOMMANDS; 366 #if SASL 367 AuthMechanisms = newstr(AUTH_MECHANISMS); 368 AuthRealm = NULL; 369 MaxSLBits = INT_MAX; 370 #endif /* SASL */ 371 #if STARTTLS 372 TLS_Srv_Opts = TLS_I_SRV; 373 #endif /* STARTTLS */ 374 #ifdef HESIOD_INIT 375 HesiodContext = NULL; 376 #endif /* HESIOD_INIT */ 377 #if NETINET6 378 /* Detect if IPv6 is available at run time */ 379 i = socket(AF_INET6, SOCK_STREAM, 0); 380 if (i >= 0) 381 { 382 InetMode = AF_INET6; 383 (void) close(i); 384 } 385 else 386 InetMode = AF_INET; 387 #else /* NETINET6 */ 388 InetMode = AF_INET; 389 #endif /* NETINET6 */ 390 ControlSocketName = NULL; 391 memset(&ConnectOnlyTo, '\0', sizeof(ConnectOnlyTo)); 392 DataFileBufferSize = 4096; 393 XscriptFileBufferSize = 4096; 394 for (i = 0; i < MAXRWSETS; i++) 395 RuleSetNames[i] = NULL; 396 #if MILTER 397 InputFilters[0] = NULL; 398 #endif /* MILTER */ 399 RejectLogInterval = 3 HOURS; 400 #if REQUIRES_DIR_FSYNC 401 RequiresDirfsync = true; 402 #endif /* REQUIRES_DIR_FSYNC */ 403 ConnectionRateWindowSize = 60; 404 setupmaps(); 405 setupqueues(); 406 setupmailers(); 407 setupheaders(); 408 } 409 410 411 /* 412 ** SETDEFUSER -- set/reset DefUser using DefUid (for initgroups()) 413 */ 414 415 void 416 setdefuser() 417 { 418 struct passwd *defpwent; 419 static char defuserbuf[40]; 420 421 DefUser = defuserbuf; 422 defpwent = sm_getpwuid(DefUid); 423 (void) sm_strlcpy(defuserbuf, 424 (defpwent == NULL || defpwent->pw_name == NULL) 425 ? "nobody" : defpwent->pw_name, 426 sizeof(defuserbuf)); 427 if (tTd(37, 4)) 428 sm_dprintf("setdefuser: DefUid=%d, DefUser=%s\n", 429 (int) DefUid, DefUser); 430 } 431 /* 432 ** SETUPQUEUES -- initialize default queues 433 ** 434 ** The mqueue QUEUE structure gets filled in after readcf() but 435 ** we need something to point to now for the mailer setup, 436 ** which use "mqueue" as default queue. 437 */ 438 439 static void 440 setupqueues() 441 { 442 char buf[100]; 443 444 MaxRunnersPerQueue = 1; 445 (void) sm_strlcpy(buf, "mqueue, P=/var/spool/mqueue", sizeof(buf)); 446 makequeue(buf, false); 447 } 448 /* 449 ** SETUPMAILERS -- initialize default mailers 450 */ 451 452 static void 453 setupmailers() 454 { 455 char buf[100]; 456 457 (void) sm_strlcpy(buf, "prog, P=/bin/sh, F=lsouDq9, T=X-Unix/X-Unix/X-Unix, A=sh -c \201u", 458 sizeof(buf)); 459 makemailer(buf); 460 461 (void) sm_strlcpy(buf, "*file*, P=[FILE], F=lsDFMPEouq9, T=X-Unix/X-Unix/X-Unix, A=FILE \201u", 462 sizeof(buf)); 463 makemailer(buf); 464 465 (void) sm_strlcpy(buf, "*include*, P=/dev/null, F=su, A=INCLUDE \201u", 466 sizeof(buf)); 467 makemailer(buf); 468 initerrmailers(); 469 } 470 /* 471 ** SETUPMAPS -- set up map classes 472 */ 473 474 #define MAPDEF(name, ext, flags, parse, open, close, lookup, store) \ 475 { \ 476 extern bool parse __P((MAP *, char *)); \ 477 extern bool open __P((MAP *, int)); \ 478 extern void close __P((MAP *)); \ 479 extern char *lookup __P((MAP *, char *, char **, int *)); \ 480 extern void store __P((MAP *, char *, char *)); \ 481 s = stab(name, ST_MAPCLASS, ST_ENTER); \ 482 s->s_mapclass.map_cname = name; \ 483 s->s_mapclass.map_ext = ext; \ 484 s->s_mapclass.map_cflags = flags; \ 485 s->s_mapclass.map_parse = parse; \ 486 s->s_mapclass.map_open = open; \ 487 s->s_mapclass.map_close = close; \ 488 s->s_mapclass.map_lookup = lookup; \ 489 s->s_mapclass.map_store = store; \ 490 } 491 492 static void 493 setupmaps() 494 { 495 register STAB *s; 496 497 #if NEWDB 498 # if DB_VERSION_MAJOR > 1 499 int major_v, minor_v, patch_v; 500 501 (void) db_version(&major_v, &minor_v, &patch_v); 502 if (major_v != DB_VERSION_MAJOR || minor_v != DB_VERSION_MINOR) 503 { 504 errno = 0; 505 syserr("Berkeley DB version mismatch: compiled against %d.%d.%d, run-time linked against %d.%d.%d", 506 DB_VERSION_MAJOR, DB_VERSION_MINOR, DB_VERSION_PATCH, 507 major_v, minor_v, patch_v); 508 } 509 # endif /* DB_VERSION_MAJOR > 1 */ 510 511 MAPDEF("hash", ".db", MCF_ALIASOK|MCF_REBUILDABLE, 512 map_parseargs, hash_map_open, db_map_close, 513 db_map_lookup, db_map_store); 514 515 MAPDEF("btree", ".db", MCF_ALIASOK|MCF_REBUILDABLE, 516 map_parseargs, bt_map_open, db_map_close, 517 db_map_lookup, db_map_store); 518 #endif /* NEWDB */ 519 520 #if NDBM 521 MAPDEF("dbm", ".dir", MCF_ALIASOK|MCF_REBUILDABLE, 522 map_parseargs, ndbm_map_open, ndbm_map_close, 523 ndbm_map_lookup, ndbm_map_store); 524 #endif /* NDBM */ 525 526 #if NIS 527 MAPDEF("nis", NULL, MCF_ALIASOK, 528 map_parseargs, nis_map_open, null_map_close, 529 nis_map_lookup, null_map_store); 530 #endif /* NIS */ 531 532 #if NISPLUS 533 MAPDEF("nisplus", NULL, MCF_ALIASOK, 534 map_parseargs, nisplus_map_open, null_map_close, 535 nisplus_map_lookup, null_map_store); 536 #endif /* NISPLUS */ 537 538 #if LDAPMAP 539 MAPDEF("ldap", NULL, MCF_ALIASOK|MCF_NOTPERSIST, 540 ldapmap_parseargs, ldapmap_open, ldapmap_close, 541 ldapmap_lookup, null_map_store); 542 #endif /* LDAPMAP */ 543 544 #if PH_MAP 545 MAPDEF("ph", NULL, MCF_NOTPERSIST, 546 ph_map_parseargs, ph_map_open, ph_map_close, 547 ph_map_lookup, null_map_store); 548 #endif /* PH_MAP */ 549 550 #if MAP_NSD 551 /* IRIX 6.5 nsd support */ 552 MAPDEF("nsd", NULL, MCF_ALIASOK, 553 map_parseargs, null_map_open, null_map_close, 554 nsd_map_lookup, null_map_store); 555 #endif /* MAP_NSD */ 556 557 #if HESIOD 558 MAPDEF("hesiod", NULL, MCF_ALIASOK|MCF_ALIASONLY, 559 map_parseargs, hes_map_open, hes_map_close, 560 hes_map_lookup, null_map_store); 561 #endif /* HESIOD */ 562 563 #if NETINFO 564 MAPDEF("netinfo", NULL, MCF_ALIASOK, 565 map_parseargs, ni_map_open, null_map_close, 566 ni_map_lookup, null_map_store); 567 #endif /* NETINFO */ 568 569 #if 0 570 MAPDEF("dns", NULL, 0, 571 dns_map_init, null_map_open, null_map_close, 572 dns_map_lookup, null_map_store); 573 #endif /* 0 */ 574 575 #if NAMED_BIND 576 # if DNSMAP 577 # if _FFR_DNSMAP_ALIASABLE 578 MAPDEF("dns", NULL, MCF_ALIASOK, 579 dns_map_parseargs, dns_map_open, null_map_close, 580 dns_map_lookup, null_map_store); 581 # else /* _FFR_DNSMAP_ALIASABLE */ 582 MAPDEF("dns", NULL, 0, 583 dns_map_parseargs, dns_map_open, null_map_close, 584 dns_map_lookup, null_map_store); 585 # endif /* _FFR_DNSMAP_ALIASABLE */ 586 # endif /* DNSMAP */ 587 #endif /* NAMED_BIND */ 588 589 #if NAMED_BIND 590 /* best MX DNS lookup */ 591 MAPDEF("bestmx", NULL, MCF_OPTFILE, 592 map_parseargs, null_map_open, null_map_close, 593 bestmx_map_lookup, null_map_store); 594 #endif /* NAMED_BIND */ 595 596 MAPDEF("host", NULL, 0, 597 host_map_init, null_map_open, null_map_close, 598 host_map_lookup, null_map_store); 599 600 MAPDEF("text", NULL, MCF_ALIASOK, 601 map_parseargs, text_map_open, null_map_close, 602 text_map_lookup, null_map_store); 603 604 MAPDEF("stab", NULL, MCF_ALIASOK|MCF_ALIASONLY, 605 map_parseargs, stab_map_open, null_map_close, 606 stab_map_lookup, stab_map_store); 607 608 MAPDEF("implicit", NULL, MCF_ALIASOK|MCF_ALIASONLY|MCF_REBUILDABLE, 609 map_parseargs, impl_map_open, impl_map_close, 610 impl_map_lookup, impl_map_store); 611 612 /* access to system passwd file */ 613 MAPDEF("user", NULL, MCF_OPTFILE, 614 map_parseargs, user_map_open, null_map_close, 615 user_map_lookup, null_map_store); 616 617 /* dequote map */ 618 MAPDEF("dequote", NULL, 0, 619 dequote_init, null_map_open, null_map_close, 620 dequote_map, null_map_store); 621 622 #if MAP_REGEX 623 MAPDEF("regex", NULL, 0, 624 regex_map_init, null_map_open, null_map_close, 625 regex_map_lookup, null_map_store); 626 #endif /* MAP_REGEX */ 627 628 #if USERDB 629 /* user database */ 630 MAPDEF("userdb", ".db", 0, 631 map_parseargs, null_map_open, null_map_close, 632 udb_map_lookup, null_map_store); 633 #endif /* USERDB */ 634 635 /* arbitrary programs */ 636 MAPDEF("program", NULL, MCF_ALIASOK, 637 map_parseargs, null_map_open, null_map_close, 638 prog_map_lookup, null_map_store); 639 640 /* sequenced maps */ 641 MAPDEF("sequence", NULL, MCF_ALIASOK, 642 seq_map_parse, null_map_open, null_map_close, 643 seq_map_lookup, seq_map_store); 644 645 /* switched interface to sequenced maps */ 646 MAPDEF("switch", NULL, MCF_ALIASOK, 647 map_parseargs, switch_map_open, null_map_close, 648 seq_map_lookup, seq_map_store); 649 650 /* null map lookup -- really for internal use only */ 651 MAPDEF("null", NULL, MCF_ALIASOK|MCF_OPTFILE, 652 map_parseargs, null_map_open, null_map_close, 653 null_map_lookup, null_map_store); 654 655 /* syslog map -- logs information to syslog */ 656 MAPDEF("syslog", NULL, 0, 657 syslog_map_parseargs, null_map_open, null_map_close, 658 syslog_map_lookup, null_map_store); 659 660 /* macro storage map -- rulesets can set macros */ 661 MAPDEF("macro", NULL, 0, 662 dequote_init, null_map_open, null_map_close, 663 macro_map_lookup, null_map_store); 664 665 /* arithmetic map -- add/subtract/compare */ 666 MAPDEF("arith", NULL, 0, 667 dequote_init, null_map_open, null_map_close, 668 arith_map_lookup, null_map_store); 669 670 #if SOCKETMAP 671 /* arbitrary daemons */ 672 MAPDEF("socket", NULL, MCF_ALIASOK, 673 map_parseargs, socket_map_open, socket_map_close, 674 socket_map_lookup, null_map_store); 675 #endif /* SOCKETMAP */ 676 677 #if _FFR_DPRINTF_MAP 678 /* dprintf map -- logs information to syslog */ 679 MAPDEF("dprintf", NULL, 0, 680 dprintf_map_parseargs, null_map_open, null_map_close, 681 dprintf_map_lookup, null_map_store); 682 #endif /* _FFR_DPRINTF_MAP */ 683 684 if (tTd(38, 2)) 685 { 686 /* bogus map -- always return tempfail */ 687 MAPDEF("bogus", NULL, MCF_ALIASOK|MCF_OPTFILE, 688 map_parseargs, null_map_open, null_map_close, 689 bogus_map_lookup, null_map_store); 690 } 691 } 692 693 #undef MAPDEF 694 /* 695 ** INITHOSTMAPS -- initial host-dependent maps 696 ** 697 ** This should act as an interface to any local service switch 698 ** provided by the host operating system. 699 ** 700 ** Parameters: 701 ** none 702 ** 703 ** Returns: 704 ** none 705 ** 706 ** Side Effects: 707 ** Should define maps "host" and "users" as necessary 708 ** for this OS. If they are not defined, they will get 709 ** a default value later. It should check to make sure 710 ** they are not defined first, since it's possible that 711 ** the config file has provided an override. 712 */ 713 714 void 715 inithostmaps() 716 { 717 register int i; 718 int nmaps; 719 char *maptype[MAXMAPSTACK]; 720 short mapreturn[MAXMAPACTIONS]; 721 char buf[MAXLINE]; 722 723 /* 724 ** Make sure we have a host map. 725 */ 726 727 if (stab("host", ST_MAP, ST_FIND) == NULL) 728 { 729 /* user didn't initialize: set up host map */ 730 (void) sm_strlcpy(buf, "host host", sizeof(buf)); 731 #if NAMED_BIND 732 if (ConfigLevel >= 2) 733 (void) sm_strlcat(buf, " -a. -D", sizeof(buf)); 734 #endif /* NAMED_BIND */ 735 (void) makemapentry(buf); 736 } 737 738 /* 739 ** Set up default aliases maps 740 */ 741 742 nmaps = switch_map_find("aliases", maptype, mapreturn); 743 for (i = 0; i < nmaps; i++) 744 { 745 if (strcmp(maptype[i], "files") == 0 && 746 stab("aliases.files", ST_MAP, ST_FIND) == NULL) 747 { 748 (void) sm_strlcpy(buf, "aliases.files null", 749 sizeof(buf)); 750 (void) makemapentry(buf); 751 } 752 #if NISPLUS 753 else if (strcmp(maptype[i], "nisplus") == 0 && 754 stab("aliases.nisplus", ST_MAP, ST_FIND) == NULL) 755 { 756 (void) sm_strlcpy(buf, "aliases.nisplus nisplus -kalias -vexpansion mail_aliases.org_dir", 757 sizeof(buf)); 758 (void) makemapentry(buf); 759 } 760 #endif /* NISPLUS */ 761 #if NIS 762 else if (strcmp(maptype[i], "nis") == 0 && 763 stab("aliases.nis", ST_MAP, ST_FIND) == NULL) 764 { 765 (void) sm_strlcpy(buf, "aliases.nis nis mail.aliases", 766 sizeof(buf)); 767 (void) makemapentry(buf); 768 } 769 #endif /* NIS */ 770 #if NETINFO 771 else if (strcmp(maptype[i], "netinfo") == 0 && 772 stab("aliases.netinfo", ST_MAP, ST_FIND) == NULL) 773 { 774 (void) sm_strlcpy(buf, "aliases.netinfo netinfo -z, /aliases", 775 sizeof(buf)); 776 (void) makemapentry(buf); 777 } 778 #endif /* NETINFO */ 779 #if HESIOD 780 else if (strcmp(maptype[i], "hesiod") == 0 && 781 stab("aliases.hesiod", ST_MAP, ST_FIND) == NULL) 782 { 783 (void) sm_strlcpy(buf, "aliases.hesiod hesiod aliases", 784 sizeof(buf)); 785 (void) makemapentry(buf); 786 } 787 #endif /* HESIOD */ 788 #if LDAPMAP && defined(SUN_EXTENSIONS) && \ 789 defined(SUN_SIMPLIFIED_LDAP) && HASLDAPGETALIASBYNAME 790 else if (strcmp(maptype[i], "ldap") == 0 && 791 stab("aliases.ldap", ST_MAP, ST_FIND) == NULL) 792 { 793 (void) strlcpy(buf, "aliases.ldap ldap -b . -h localhost -k mail=%0 -v mailgroup", 794 sizeof buf); 795 (void) makemapentry(buf); 796 } 797 #endif /* LDAPMAP && defined(SUN_EXTENSIONS) && ... */ 798 } 799 if (stab("aliases", ST_MAP, ST_FIND) == NULL) 800 { 801 (void) sm_strlcpy(buf, "aliases switch aliases", sizeof(buf)); 802 (void) makemapentry(buf); 803 } 804 } 805 806 /* 807 ** SWITCH_MAP_FIND -- find the list of types associated with a map 808 ** 809 ** This is the system-dependent interface to the service switch. 810 ** 811 ** Parameters: 812 ** service -- the name of the service of interest. 813 ** maptype -- an out-array of strings containing the types 814 ** of access to use for this service. There can 815 ** be at most MAXMAPSTACK types for a single service. 816 ** mapreturn -- an out-array of return information bitmaps 817 ** for the map. 818 ** 819 ** Returns: 820 ** The number of map types filled in, or -1 for failure. 821 ** 822 ** Side effects: 823 ** Preserves errno so nothing in the routine clobbers it. 824 */ 825 826 #if defined(SOLARIS) || (defined(sony_news) && defined(__svr4)) 827 # define _USE_SUN_NSSWITCH_ 828 #endif /* defined(SOLARIS) || (defined(sony_news) && defined(__svr4)) */ 829 830 #if _FFR_HPUX_NSSWITCH 831 # ifdef __hpux 832 # define _USE_SUN_NSSWITCH_ 833 # endif /* __hpux */ 834 #endif /* _FFR_HPUX_NSSWITCH */ 835 836 #ifdef _USE_SUN_NSSWITCH_ 837 # include <nsswitch.h> 838 #endif /* _USE_SUN_NSSWITCH_ */ 839 840 #if defined(ultrix) || (defined(__osf__) && defined(__alpha)) 841 # define _USE_DEC_SVC_CONF_ 842 #endif /* defined(ultrix) || (defined(__osf__) && defined(__alpha)) */ 843 844 #ifdef _USE_DEC_SVC_CONF_ 845 # include <sys/svcinfo.h> 846 #endif /* _USE_DEC_SVC_CONF_ */ 847 848 int 849 switch_map_find(service, maptype, mapreturn) 850 char *service; 851 char *maptype[MAXMAPSTACK]; 852 short mapreturn[MAXMAPACTIONS]; 853 { 854 int svcno = 0; 855 int save_errno = errno; 856 857 #ifdef _USE_SUN_NSSWITCH_ 858 struct __nsw_switchconfig *nsw_conf; 859 enum __nsw_parse_err pserr; 860 struct __nsw_lookup *lk; 861 static struct __nsw_lookup lkp0 = 862 { "files", {1, 0, 0, 0}, NULL, NULL }; 863 static struct __nsw_switchconfig lkp_default = 864 { 0, "sendmail", 3, &lkp0 }; 865 866 for (svcno = 0; svcno < MAXMAPACTIONS; svcno++) 867 mapreturn[svcno] = 0; 868 869 if ((nsw_conf = __nsw_getconfig(service, &pserr)) == NULL) 870 lk = lkp_default.lookups; 871 else 872 lk = nsw_conf->lookups; 873 svcno = 0; 874 while (lk != NULL && svcno < MAXMAPSTACK) 875 { 876 maptype[svcno] = lk->service_name; 877 if (lk->actions[__NSW_NOTFOUND] == __NSW_RETURN) 878 mapreturn[MA_NOTFOUND] |= 1 << svcno; 879 if (lk->actions[__NSW_TRYAGAIN] == __NSW_RETURN) 880 mapreturn[MA_TRYAGAIN] |= 1 << svcno; 881 if (lk->actions[__NSW_UNAVAIL] == __NSW_RETURN) 882 mapreturn[MA_TRYAGAIN] |= 1 << svcno; 883 svcno++; 884 lk = lk->next; 885 } 886 errno = save_errno; 887 return svcno; 888 #endif /* _USE_SUN_NSSWITCH_ */ 889 890 #ifdef _USE_DEC_SVC_CONF_ 891 struct svcinfo *svcinfo; 892 int svc; 893 894 for (svcno = 0; svcno < MAXMAPACTIONS; svcno++) 895 mapreturn[svcno] = 0; 896 897 svcinfo = getsvc(); 898 if (svcinfo == NULL) 899 goto punt; 900 if (strcmp(service, "hosts") == 0) 901 svc = SVC_HOSTS; 902 else if (strcmp(service, "aliases") == 0) 903 svc = SVC_ALIASES; 904 else if (strcmp(service, "passwd") == 0) 905 svc = SVC_PASSWD; 906 else 907 { 908 errno = save_errno; 909 return -1; 910 } 911 for (svcno = 0; svcno < SVC_PATHSIZE && svcno < MAXMAPSTACK; svcno++) 912 { 913 switch (svcinfo->svcpath[svc][svcno]) 914 { 915 case SVC_LOCAL: 916 maptype[svcno] = "files"; 917 break; 918 919 case SVC_YP: 920 maptype[svcno] = "nis"; 921 break; 922 923 case SVC_BIND: 924 maptype[svcno] = "dns"; 925 break; 926 927 # ifdef SVC_HESIOD 928 case SVC_HESIOD: 929 maptype[svcno] = "hesiod"; 930 break; 931 # endif /* SVC_HESIOD */ 932 933 case SVC_LAST: 934 errno = save_errno; 935 return svcno; 936 } 937 } 938 errno = save_errno; 939 return svcno; 940 #endif /* _USE_DEC_SVC_CONF_ */ 941 942 #if !defined(_USE_SUN_NSSWITCH_) && !defined(_USE_DEC_SVC_CONF_) 943 /* 944 ** Fall-back mechanism. 945 */ 946 947 STAB *st; 948 static time_t servicecachetime; /* time service switch was cached */ 949 time_t now = curtime(); 950 951 for (svcno = 0; svcno < MAXMAPACTIONS; svcno++) 952 mapreturn[svcno] = 0; 953 954 if ((now - servicecachetime) > (time_t) ServiceCacheMaxAge) 955 { 956 /* (re)read service switch */ 957 register SM_FILE_T *fp; 958 long sff = SFF_REGONLY|SFF_OPENASROOT|SFF_NOLOCK; 959 960 if (!bitnset(DBS_LINKEDSERVICESWITCHFILEINWRITABLEDIR, 961 DontBlameSendmail)) 962 sff |= SFF_NOWLINK; 963 964 if (ConfigFileRead) 965 servicecachetime = now; 966 fp = safefopen(ServiceSwitchFile, O_RDONLY, 0, sff); 967 if (fp != NULL) 968 { 969 char buf[MAXLINE]; 970 971 while (sm_io_fgets(fp, SM_TIME_DEFAULT, buf, 972 sizeof(buf)) != NULL) 973 { 974 register char *p; 975 976 p = strpbrk(buf, "#\n"); 977 if (p != NULL) 978 *p = '\0'; 979 p = strpbrk(buf, " \t"); 980 if (p != NULL) 981 *p++ = '\0'; 982 if (buf[0] == '\0') 983 continue; 984 if (p == NULL) 985 { 986 sm_syslog(LOG_ERR, NOQID, 987 "Bad line on %.100s: %.100s", 988 ServiceSwitchFile, 989 buf); 990 continue; 991 } 992 while (isspace(*p)) 993 p++; 994 if (*p == '\0') 995 continue; 996 997 /* 998 ** Find/allocate space for this service entry. 999 ** Space for all of the service strings 1000 ** are allocated at once. This means 1001 ** that we only have to free the first 1002 ** one to free all of them. 1003 */ 1004 1005 st = stab(buf, ST_SERVICE, ST_ENTER); 1006 if (st->s_service[0] != NULL) 1007 sm_free((void *) st->s_service[0]); /* XXX */ 1008 p = newstr(p); 1009 for (svcno = 0; svcno < MAXMAPSTACK; ) 1010 { 1011 if (*p == '\0') 1012 break; 1013 st->s_service[svcno++] = p; 1014 p = strpbrk(p, " \t"); 1015 if (p == NULL) 1016 break; 1017 *p++ = '\0'; 1018 while (isspace(*p)) 1019 p++; 1020 } 1021 if (svcno < MAXMAPSTACK) 1022 st->s_service[svcno] = NULL; 1023 } 1024 (void) sm_io_close(fp, SM_TIME_DEFAULT); 1025 } 1026 } 1027 1028 /* look up entry in cache */ 1029 st = stab(service, ST_SERVICE, ST_FIND); 1030 if (st != NULL && st->s_service[0] != NULL) 1031 { 1032 /* extract data */ 1033 svcno = 0; 1034 while (svcno < MAXMAPSTACK) 1035 { 1036 maptype[svcno] = st->s_service[svcno]; 1037 if (maptype[svcno++] == NULL) 1038 break; 1039 } 1040 errno = save_errno; 1041 return --svcno; 1042 } 1043 #endif /* !defined(_USE_SUN_NSSWITCH_) && !defined(_USE_DEC_SVC_CONF_) */ 1044 1045 #if !defined(_USE_SUN_NSSWITCH_) 1046 /* if the service file doesn't work, use an absolute fallback */ 1047 # ifdef _USE_DEC_SVC_CONF_ 1048 punt: 1049 # endif /* _USE_DEC_SVC_CONF_ */ 1050 for (svcno = 0; svcno < MAXMAPACTIONS; svcno++) 1051 mapreturn[svcno] = 0; 1052 svcno = 0; 1053 if (strcmp(service, "aliases") == 0) 1054 { 1055 maptype[svcno++] = "files"; 1056 # if defined(AUTO_NETINFO_ALIASES) && defined (NETINFO) 1057 maptype[svcno++] = "netinfo"; 1058 # endif /* defined(AUTO_NETINFO_ALIASES) && defined (NETINFO) */ 1059 # ifdef AUTO_NIS_ALIASES 1060 # if NISPLUS 1061 maptype[svcno++] = "nisplus"; 1062 # endif /* NISPLUS */ 1063 # if NIS 1064 maptype[svcno++] = "nis"; 1065 # endif /* NIS */ 1066 # endif /* AUTO_NIS_ALIASES */ 1067 errno = save_errno; 1068 return svcno; 1069 } 1070 if (strcmp(service, "hosts") == 0) 1071 { 1072 # if NAMED_BIND 1073 maptype[svcno++] = "dns"; 1074 # else /* NAMED_BIND */ 1075 # if defined(sun) && !defined(BSD) 1076 /* SunOS */ 1077 maptype[svcno++] = "nis"; 1078 # endif /* defined(sun) && !defined(BSD) */ 1079 # endif /* NAMED_BIND */ 1080 # if defined(AUTO_NETINFO_HOSTS) && defined (NETINFO) 1081 maptype[svcno++] = "netinfo"; 1082 # endif /* defined(AUTO_NETINFO_HOSTS) && defined (NETINFO) */ 1083 maptype[svcno++] = "files"; 1084 errno = save_errno; 1085 return svcno; 1086 } 1087 errno = save_errno; 1088 return -1; 1089 #endif /* !defined(_USE_SUN_NSSWITCH_) */ 1090 } 1091 /* 1092 ** USERNAME -- return the user id of the logged in user. 1093 ** 1094 ** Parameters: 1095 ** none. 1096 ** 1097 ** Returns: 1098 ** The login name of the logged in user. 1099 ** 1100 ** Side Effects: 1101 ** none. 1102 ** 1103 ** Notes: 1104 ** The return value is statically allocated. 1105 */ 1106 1107 char * 1108 username() 1109 { 1110 static char *myname = NULL; 1111 extern char *getlogin(); 1112 register struct passwd *pw; 1113 1114 /* cache the result */ 1115 if (myname == NULL) 1116 { 1117 myname = getlogin(); 1118 if (myname == NULL || myname[0] == '\0') 1119 { 1120 pw = sm_getpwuid(RealUid); 1121 if (pw != NULL) 1122 myname = pw->pw_name; 1123 } 1124 else 1125 { 1126 uid_t uid = RealUid; 1127 1128 if ((pw = sm_getpwnam(myname)) == NULL || 1129 (uid != 0 && uid != pw->pw_uid)) 1130 { 1131 pw = sm_getpwuid(uid); 1132 if (pw != NULL) 1133 myname = pw->pw_name; 1134 } 1135 } 1136 if (myname == NULL || myname[0] == '\0') 1137 { 1138 syserr("554 5.3.0 Who are you?"); 1139 myname = "postmaster"; 1140 } 1141 else if (strpbrk(myname, ",;:/|\"\\") != NULL) 1142 myname = addquotes(myname, NULL); 1143 else 1144 myname = sm_pstrdup_x(myname); 1145 } 1146 return myname; 1147 } 1148 /* 1149 ** TTYPATH -- Get the path of the user's tty 1150 ** 1151 ** Returns the pathname of the user's tty. Returns NULL if 1152 ** the user is not logged in or if s/he has write permission 1153 ** denied. 1154 ** 1155 ** Parameters: 1156 ** none 1157 ** 1158 ** Returns: 1159 ** pathname of the user's tty. 1160 ** NULL if not logged in or write permission denied. 1161 ** 1162 ** Side Effects: 1163 ** none. 1164 ** 1165 ** WARNING: 1166 ** Return value is in a local buffer. 1167 ** 1168 ** Called By: 1169 ** savemail 1170 */ 1171 1172 char * 1173 ttypath() 1174 { 1175 struct stat stbuf; 1176 register char *pathn; 1177 extern char *ttyname(); 1178 extern char *getlogin(); 1179 1180 /* compute the pathname of the controlling tty */ 1181 if ((pathn = ttyname(2)) == NULL && (pathn = ttyname(1)) == NULL && 1182 (pathn = ttyname(0)) == NULL) 1183 { 1184 errno = 0; 1185 return NULL; 1186 } 1187 1188 /* see if we have write permission */ 1189 if (stat(pathn, &stbuf) < 0 || !bitset(S_IWOTH, stbuf.st_mode)) 1190 { 1191 errno = 0; 1192 return NULL; 1193 } 1194 1195 /* see if the user is logged in */ 1196 if (getlogin() == NULL) 1197 return NULL; 1198 1199 /* looks good */ 1200 return pathn; 1201 } 1202 /* 1203 ** CHECKCOMPAT -- check for From and To person compatible. 1204 ** 1205 ** This routine can be supplied on a per-installation basis 1206 ** to determine whether a person is allowed to send a message. 1207 ** This allows restriction of certain types of internet 1208 ** forwarding or registration of users. 1209 ** 1210 ** If the hosts are found to be incompatible, an error 1211 ** message should be given using "usrerr" and an EX_ code 1212 ** should be returned. You can also set to->q_status to 1213 ** a DSN-style status code. 1214 ** 1215 ** EF_NO_BODY_RETN can be set in e->e_flags to suppress the 1216 ** body during the return-to-sender function; this should be done 1217 ** on huge messages. This bit may already be set by the ESMTP 1218 ** protocol. 1219 ** 1220 ** Parameters: 1221 ** to -- the person being sent to. 1222 ** 1223 ** Returns: 1224 ** an exit status 1225 ** 1226 ** Side Effects: 1227 ** none (unless you include the usrerr stuff) 1228 */ 1229 1230 int 1231 checkcompat(to, e) 1232 register ADDRESS *to; 1233 register ENVELOPE *e; 1234 { 1235 if (tTd(49, 1)) 1236 sm_dprintf("checkcompat(to=%s, from=%s)\n", 1237 to->q_paddr, e->e_from.q_paddr); 1238 1239 #ifdef EXAMPLE_CODE 1240 /* this code is intended as an example only */ 1241 register STAB *s; 1242 1243 s = stab("arpa", ST_MAILER, ST_FIND); 1244 if (s != NULL && strcmp(e->e_from.q_mailer->m_name, "local") != 0 && 1245 to->q_mailer == s->s_mailer) 1246 { 1247 usrerr("553 No ARPA mail through this machine: see your system administration"); 1248 /* e->e_flags |= EF_NO_BODY_RETN; to suppress body on return */ 1249 to->q_status = "5.7.1"; 1250 return EX_UNAVAILABLE; 1251 } 1252 #endif /* EXAMPLE_CODE */ 1253 return EX_OK; 1254 } 1255 1256 #ifdef SUN_EXTENSIONS 1257 static void 1258 init_md_sun() 1259 { 1260 struct stat sbuf; 1261 1262 /* Check for large file descriptor */ 1263 if (fstat(fileno(stdin), &sbuf) < 0) 1264 { 1265 if (errno == EOVERFLOW) 1266 { 1267 perror("stdin"); 1268 exit(EX_NOINPUT); 1269 } 1270 } 1271 } 1272 #endif /* SUN_EXTENSIONS */ 1273 1274 /* 1275 ** INIT_MD -- do machine dependent initializations 1276 ** 1277 ** Systems that have global modes that should be set should do 1278 ** them here rather than in main. 1279 */ 1280 1281 #ifdef _AUX_SOURCE 1282 # include <compat.h> 1283 #endif /* _AUX_SOURCE */ 1284 1285 #if SHARE_V1 1286 # include <shares.h> 1287 #endif /* SHARE_V1 */ 1288 1289 void 1290 init_md(argc, argv) 1291 int argc; 1292 char **argv; 1293 { 1294 #ifdef _AUX_SOURCE 1295 setcompat(getcompat() | COMPAT_BSDPROT); 1296 #endif /* _AUX_SOURCE */ 1297 1298 #ifdef SUN_EXTENSIONS 1299 init_md_sun(); 1300 #endif /* SUN_EXTENSIONS */ 1301 1302 #if _CONVEX_SOURCE 1303 /* keep gethostby*() from stripping the local domain name */ 1304 set_domain_trim_off(); 1305 #endif /* _CONVEX_SOURCE */ 1306 #if defined(__QNX__) && !defined(__QNXNTO__) 1307 /* 1308 ** Due to QNX's network distributed nature, you can target a tcpip 1309 ** stack on a different node in the qnx network; this patch lets 1310 ** this feature work. The __sock_locate() must be done before the 1311 ** environment is clear. 1312 */ 1313 __sock_locate(); 1314 #endif /* __QNX__ */ 1315 #if SECUREWARE || defined(_SCO_unix_) 1316 set_auth_parameters(argc, argv); 1317 1318 # ifdef _SCO_unix_ 1319 /* 1320 ** This is required for highest security levels (the kernel 1321 ** won't let it call set*uid() or run setuid binaries without 1322 ** it). It may be necessary on other SECUREWARE systems. 1323 */ 1324 1325 if (getluid() == -1) 1326 setluid(0); 1327 # endif /* _SCO_unix_ */ 1328 #endif /* SECUREWARE || defined(_SCO_unix_) */ 1329 1330 1331 #ifdef VENDOR_DEFAULT 1332 VendorCode = VENDOR_DEFAULT; 1333 #else /* VENDOR_DEFAULT */ 1334 VendorCode = VENDOR_BERKELEY; 1335 #endif /* VENDOR_DEFAULT */ 1336 } 1337 /* 1338 ** INIT_VENDOR_MACROS -- vendor-dependent macro initializations 1339 ** 1340 ** Called once, on startup. 1341 ** 1342 ** Parameters: 1343 ** e -- the global envelope. 1344 ** 1345 ** Returns: 1346 ** none. 1347 ** 1348 ** Side Effects: 1349 ** vendor-dependent. 1350 */ 1351 1352 void 1353 init_vendor_macros(e) 1354 register ENVELOPE *e; 1355 { 1356 } 1357 /* 1358 ** GETLA -- get the current load average 1359 ** 1360 ** This code stolen from la.c. 1361 ** 1362 ** Parameters: 1363 ** none. 1364 ** 1365 ** Returns: 1366 ** The current load average as an integer. 1367 ** 1368 ** Side Effects: 1369 ** none. 1370 */ 1371 1372 /* try to guess what style of load average we have */ 1373 #define LA_ZERO 1 /* always return load average as zero */ 1374 #define LA_INT 2 /* read kmem for avenrun; interpret as long */ 1375 #define LA_FLOAT 3 /* read kmem for avenrun; interpret as float */ 1376 #define LA_SUBR 4 /* call getloadavg */ 1377 #define LA_MACH 5 /* MACH load averages (as on NeXT boxes) */ 1378 #define LA_SHORT 6 /* read kmem for avenrun; interpret as short */ 1379 #define LA_PROCSTR 7 /* read string ("1.17") from /proc/loadavg */ 1380 #define LA_READKSYM 8 /* SVR4: use MIOC_READKSYM ioctl call */ 1381 #define LA_DGUX 9 /* special DGUX implementation */ 1382 #define LA_HPUX 10 /* special HPUX implementation */ 1383 #define LA_IRIX6 11 /* special IRIX 6.2 implementation */ 1384 #define LA_KSTAT 12 /* special Solaris kstat(3k) implementation */ 1385 #define LA_DEVSHORT 13 /* read short from a device */ 1386 #define LA_ALPHAOSF 14 /* Digital UNIX (OSF/1 on Alpha) table() call */ 1387 #define LA_PSET 15 /* Solaris per-processor-set load average */ 1388 #define LA_LONGLONG 17 /* read kmem for avenrun; interpret as long long */ 1389 1390 /* do guesses based on general OS type */ 1391 #ifndef LA_TYPE 1392 # define LA_TYPE LA_ZERO 1393 #endif /* ! LA_TYPE */ 1394 1395 #ifndef FSHIFT 1396 # if defined(unixpc) 1397 # define FSHIFT 5 1398 # endif /* defined(unixpc) */ 1399 1400 # if defined(__alpha) || defined(IRIX) 1401 # define FSHIFT 10 1402 # endif /* defined(__alpha) || defined(IRIX) */ 1403 1404 #endif /* ! FSHIFT */ 1405 1406 #ifndef FSHIFT 1407 # define FSHIFT 8 1408 #endif /* ! FSHIFT */ 1409 1410 #ifndef FSCALE 1411 # define FSCALE (1 << FSHIFT) 1412 #endif /* ! FSCALE */ 1413 1414 #ifndef LA_AVENRUN 1415 # ifdef SYSTEM5 1416 # define LA_AVENRUN "avenrun" 1417 # else /* SYSTEM5 */ 1418 # define LA_AVENRUN "_avenrun" 1419 # endif /* SYSTEM5 */ 1420 #endif /* ! LA_AVENRUN */ 1421 1422 /* _PATH_KMEM should be defined in <paths.h> */ 1423 #ifndef _PATH_KMEM 1424 # define _PATH_KMEM "/dev/kmem" 1425 #endif /* ! _PATH_KMEM */ 1426 1427 #if (LA_TYPE == LA_INT) || (LA_TYPE == LA_FLOAT) || (LA_TYPE == LA_SHORT) || (LA_TYPE == LA_LONGLONG) 1428 1429 # include <nlist.h> 1430 1431 /* _PATH_UNIX should be defined in <paths.h> */ 1432 # ifndef _PATH_UNIX 1433 # if defined(SYSTEM5) 1434 # define _PATH_UNIX "/unix" 1435 # else /* defined(SYSTEM5) */ 1436 # define _PATH_UNIX "/vmunix" 1437 # endif /* defined(SYSTEM5) */ 1438 # endif /* ! _PATH_UNIX */ 1439 1440 # ifdef _AUX_SOURCE 1441 struct nlist Nl[2]; 1442 # else /* _AUX_SOURCE */ 1443 struct nlist Nl[] = 1444 { 1445 { LA_AVENRUN }, 1446 { 0 }, 1447 }; 1448 # endif /* _AUX_SOURCE */ 1449 # define X_AVENRUN 0 1450 1451 int 1452 getla() 1453 { 1454 int j; 1455 static int kmem = -1; 1456 # if LA_TYPE == LA_INT 1457 long avenrun[3]; 1458 # else /* LA_TYPE == LA_INT */ 1459 # if LA_TYPE == LA_SHORT 1460 short avenrun[3]; 1461 # else 1462 # if LA_TYPE == LA_LONGLONG 1463 long long avenrun[3]; 1464 # else /* LA_TYPE == LA_LONGLONG */ 1465 double avenrun[3]; 1466 # endif /* LA_TYPE == LA_LONGLONG */ 1467 # endif /* LA_TYPE == LA_SHORT */ 1468 # endif /* LA_TYPE == LA_INT */ 1469 extern off_t lseek(); 1470 1471 if (kmem < 0) 1472 { 1473 # ifdef _AUX_SOURCE 1474 (void) sm_strlcpy(Nl[X_AVENRUN].n_name, LA_AVENRUN, 1475 sizeof(Nl[X_AVENRUN].n_name)); 1476 Nl[1].n_name[0] = '\0'; 1477 # endif /* _AUX_SOURCE */ 1478 1479 # if defined(_AIX3) || defined(_AIX4) 1480 if (knlist(Nl, 1, sizeof(Nl[0])) < 0) 1481 # else /* defined(_AIX3) || defined(_AIX4) */ 1482 if (nlist(_PATH_UNIX, Nl) < 0) 1483 # endif /* defined(_AIX3) || defined(_AIX4) */ 1484 { 1485 if (tTd(3, 1)) 1486 sm_dprintf("getla: nlist(%s): %s\n", _PATH_UNIX, 1487 sm_errstring(errno)); 1488 return -1; 1489 } 1490 if (Nl[X_AVENRUN].n_value == 0) 1491 { 1492 if (tTd(3, 1)) 1493 sm_dprintf("getla: nlist(%s, %s) ==> 0\n", 1494 _PATH_UNIX, LA_AVENRUN); 1495 return -1; 1496 } 1497 # ifdef NAMELISTMASK 1498 Nl[X_AVENRUN].n_value &= NAMELISTMASK; 1499 # endif /* NAMELISTMASK */ 1500 1501 kmem = open(_PATH_KMEM, 0, 0); 1502 if (kmem < 0) 1503 { 1504 if (tTd(3, 1)) 1505 sm_dprintf("getla: open(/dev/kmem): %s\n", 1506 sm_errstring(errno)); 1507 return -1; 1508 } 1509 if ((j = fcntl(kmem, F_GETFD, 0)) < 0 || 1510 fcntl(kmem, F_SETFD, j | FD_CLOEXEC) < 0) 1511 { 1512 if (tTd(3, 1)) 1513 sm_dprintf("getla: fcntl(/dev/kmem, FD_CLOEXEC): %s\n", 1514 sm_errstring(errno)); 1515 (void) close(kmem); 1516 kmem = -1; 1517 return -1; 1518 } 1519 } 1520 if (tTd(3, 20)) 1521 sm_dprintf("getla: symbol address = %#lx\n", 1522 (unsigned long) Nl[X_AVENRUN].n_value); 1523 if (lseek(kmem, (off_t) Nl[X_AVENRUN].n_value, SEEK_SET) == -1 || 1524 read(kmem, (char *) avenrun, sizeof(avenrun)) < sizeof(avenrun)) 1525 { 1526 /* thank you Ian */ 1527 if (tTd(3, 1)) 1528 sm_dprintf("getla: lseek or read: %s\n", 1529 sm_errstring(errno)); 1530 return -1; 1531 } 1532 # if (LA_TYPE == LA_INT) || (LA_TYPE == LA_SHORT) || (LA_TYPE == LA_LONGLONG) 1533 if (tTd(3, 5)) 1534 { 1535 # if LA_TYPE == LA_SHORT 1536 sm_dprintf("getla: avenrun = %d", avenrun[0]); 1537 if (tTd(3, 15)) 1538 sm_dprintf(", %d, %d", avenrun[1], avenrun[2]); 1539 # else /* LA_TYPE == LA_SHORT */ 1540 # if LA_TYPE == LA_LONGLONG 1541 sm_dprintf("getla: avenrun = %lld", avenrun[0]); 1542 if (tTd(3, 15)) 1543 sm_dprintf(", %lld, %lld", avenrun[1], avenrun[2]); 1544 # else /* LA_TYPE == LA_LONGLONG */ 1545 sm_dprintf("getla: avenrun = %ld", avenrun[0]); 1546 if (tTd(3, 15)) 1547 sm_dprintf(", %ld, %ld", avenrun[1], avenrun[2]); 1548 # endif /* LA_TYPE == LA_LONGLONG */ 1549 # endif /* LA_TYPE == LA_SHORT */ 1550 sm_dprintf("\n"); 1551 } 1552 if (tTd(3, 1)) 1553 sm_dprintf("getla: %d\n", 1554 (int) (avenrun[0] + FSCALE/2) >> FSHIFT); 1555 return ((int) (avenrun[0] + FSCALE/2) >> FSHIFT); 1556 # else /* (LA_TYPE == LA_INT) || (LA_TYPE == LA_SHORT) || (LA_TYPE == LA_LONGLONG) */ 1557 if (tTd(3, 5)) 1558 { 1559 sm_dprintf("getla: avenrun = %g", avenrun[0]); 1560 if (tTd(3, 15)) 1561 sm_dprintf(", %g, %g", avenrun[1], avenrun[2]); 1562 sm_dprintf("\n"); 1563 } 1564 if (tTd(3, 1)) 1565 sm_dprintf("getla: %d\n", (int) (avenrun[0] +0.5)); 1566 return ((int) (avenrun[0] + 0.5)); 1567 # endif /* (LA_TYPE == LA_INT) || (LA_TYPE == LA_SHORT) || (LA_TYPE == LA_LONGLONG) */ 1568 } 1569 1570 #endif /* (LA_TYPE == LA_INT) || (LA_TYPE == LA_FLOAT) || (LA_TYPE == LA_SHORT) || (LA_TYPE == LA_LONGLONG) */ 1571 1572 #if LA_TYPE == LA_READKSYM 1573 1574 # include <sys/ksym.h> 1575 1576 int 1577 getla() 1578 { 1579 int j; 1580 static int kmem = -1; 1581 long avenrun[3]; 1582 struct mioc_rksym mirk; 1583 1584 if (kmem < 0) 1585 { 1586 kmem = open("/dev/kmem", 0, 0); 1587 if (kmem < 0) 1588 { 1589 if (tTd(3, 1)) 1590 sm_dprintf("getla: open(/dev/kmem): %s\n", 1591 sm_errstring(errno)); 1592 return -1; 1593 } 1594 if ((j = fcntl(kmem, F_GETFD, 0)) < 0 || 1595 fcntl(kmem, F_SETFD, j | FD_CLOEXEC) < 0) 1596 { 1597 if (tTd(3, 1)) 1598 sm_dprintf("getla: fcntl(/dev/kmem, FD_CLOEXEC): %s\n", 1599 sm_errstring(errno)); 1600 (void) close(kmem); 1601 kmem = -1; 1602 return -1; 1603 } 1604 } 1605 mirk.mirk_symname = LA_AVENRUN; 1606 mirk.mirk_buf = avenrun; 1607 mirk.mirk_buflen = sizeof(avenrun); 1608 if (ioctl(kmem, MIOC_READKSYM, &mirk) < 0) 1609 { 1610 if (tTd(3, 1)) 1611 sm_dprintf("getla: ioctl(MIOC_READKSYM) failed: %s\n", 1612 sm_errstring(errno)); 1613 return -1; 1614 } 1615 if (tTd(3, 5)) 1616 { 1617 sm_dprintf("getla: avenrun = %d", avenrun[0]); 1618 if (tTd(3, 15)) 1619 sm_dprintf(", %d, %d", avenrun[1], avenrun[2]); 1620 sm_dprintf("\n"); 1621 } 1622 if (tTd(3, 1)) 1623 sm_dprintf("getla: %d\n", 1624 (int) (avenrun[0] + FSCALE/2) >> FSHIFT); 1625 return ((int) (avenrun[0] + FSCALE/2) >> FSHIFT); 1626 } 1627 1628 #endif /* LA_TYPE == LA_READKSYM */ 1629 1630 #if LA_TYPE == LA_DGUX 1631 1632 # include <sys/dg_sys_info.h> 1633 1634 int 1635 getla() 1636 { 1637 struct dg_sys_info_load_info load_info; 1638 1639 dg_sys_info((long *)&load_info, 1640 DG_SYS_INFO_LOAD_INFO_TYPE, DG_SYS_INFO_LOAD_VERSION_0); 1641 1642 if (tTd(3, 1)) 1643 sm_dprintf("getla: %d\n", (int) (load_info.one_minute + 0.5)); 1644 1645 return ((int) (load_info.one_minute + 0.5)); 1646 } 1647 1648 #endif /* LA_TYPE == LA_DGUX */ 1649 1650 #if LA_TYPE == LA_HPUX 1651 1652 /* forward declarations to keep gcc from complaining */ 1653 struct pst_dynamic; 1654 struct pst_status; 1655 struct pst_static; 1656 struct pst_vminfo; 1657 struct pst_diskinfo; 1658 struct pst_processor; 1659 struct pst_lv; 1660 struct pst_swapinfo; 1661 1662 # include <sys/param.h> 1663 # include <sys/pstat.h> 1664 1665 int 1666 getla() 1667 { 1668 struct pst_dynamic pstd; 1669 1670 if (pstat_getdynamic(&pstd, sizeof(struct pst_dynamic), 1671 (size_t) 1, 0) == -1) 1672 return 0; 1673 1674 if (tTd(3, 1)) 1675 sm_dprintf("getla: %d\n", (int) (pstd.psd_avg_1_min + 0.5)); 1676 1677 return (int) (pstd.psd_avg_1_min + 0.5); 1678 } 1679 1680 #endif /* LA_TYPE == LA_HPUX */ 1681 1682 #if LA_TYPE == LA_SUBR 1683 1684 int 1685 getla() 1686 { 1687 double avenrun[3]; 1688 1689 if (getloadavg(avenrun, sizeof(avenrun) / sizeof(avenrun[0])) < 0) 1690 { 1691 if (tTd(3, 1)) 1692 sm_dprintf("getla: getloadavg failed: %s", 1693 sm_errstring(errno)); 1694 return -1; 1695 } 1696 if (tTd(3, 1)) 1697 sm_dprintf("getla: %d\n", (int) (avenrun[0] +0.5)); 1698 return ((int) (avenrun[0] + 0.5)); 1699 } 1700 1701 #endif /* LA_TYPE == LA_SUBR */ 1702 1703 #if LA_TYPE == LA_MACH 1704 1705 /* 1706 ** This has been tested on NEXTSTEP release 2.1/3.X. 1707 */ 1708 1709 # if defined(NX_CURRENT_COMPILER_RELEASE) && NX_CURRENT_COMPILER_RELEASE > NX_COMPILER_RELEASE_3_0 1710 # include <mach/mach.h> 1711 # else /* defined(NX_CURRENT_COMPILER_RELEASE) && NX_CURRENT_COMPILER_RELEASE > NX_COMPILER_RELEASE_3_0 */ 1712 # include <mach.h> 1713 # endif /* defined(NX_CURRENT_COMPILER_RELEASE) && NX_CURRENT_COMPILER_RELEASE > NX_COMPILER_RELEASE_3_0 */ 1714 1715 int 1716 getla() 1717 { 1718 processor_set_t default_set; 1719 kern_return_t error; 1720 unsigned int info_count; 1721 struct processor_set_basic_info info; 1722 host_t host; 1723 1724 error = processor_set_default(host_self(), &default_set); 1725 if (error != KERN_SUCCESS) 1726 { 1727 if (tTd(3, 1)) 1728 sm_dprintf("getla: processor_set_default failed: %s", 1729 sm_errstring(errno)); 1730 return -1; 1731 } 1732 info_count = PROCESSOR_SET_BASIC_INFO_COUNT; 1733 if (processor_set_info(default_set, PROCESSOR_SET_BASIC_INFO, 1734 &host, (processor_set_info_t)&info, 1735 &info_count) != KERN_SUCCESS) 1736 { 1737 if (tTd(3, 1)) 1738 sm_dprintf("getla: processor_set_info failed: %s", 1739 sm_errstring(errno)); 1740 return -1; 1741 } 1742 if (tTd(3, 1)) 1743 sm_dprintf("getla: %d\n", 1744 (int) ((info.load_average + (LOAD_SCALE / 2)) / 1745 LOAD_SCALE)); 1746 return (int) (info.load_average + (LOAD_SCALE / 2)) / LOAD_SCALE; 1747 } 1748 1749 #endif /* LA_TYPE == LA_MACH */ 1750 1751 #if LA_TYPE == LA_PROCSTR 1752 # if SM_CONF_BROKEN_STRTOD 1753 ERROR: This OS has most likely a broken strtod() implemenentation. 1754 ERROR: The function is required for getla(). 1755 ERROR: Check the compilation options _LA_PROCSTR and 1756 ERROR: _SM_CONF_BROKEN_STRTOD (without the leading _). 1757 # endif /* SM_CONF_BROKEN_STRTOD */ 1758 1759 /* 1760 ** Read /proc/loadavg for the load average. This is assumed to be 1761 ** in a format like "0.15 0.12 0.06". 1762 ** 1763 ** Initially intended for Linux. This has been in the kernel 1764 ** since at least 0.99.15. 1765 */ 1766 1767 # ifndef _PATH_LOADAVG 1768 # define _PATH_LOADAVG "/proc/loadavg" 1769 # endif /* ! _PATH_LOADAVG */ 1770 1771 int 1772 getla() 1773 { 1774 double avenrun; 1775 register int result; 1776 SM_FILE_T *fp; 1777 1778 fp = sm_io_open(SmFtStdio, SM_TIME_DEFAULT, _PATH_LOADAVG, SM_IO_RDONLY, 1779 NULL); 1780 if (fp == NULL) 1781 { 1782 if (tTd(3, 1)) 1783 sm_dprintf("getla: sm_io_open(%s): %s\n", 1784 _PATH_LOADAVG, sm_errstring(errno)); 1785 return -1; 1786 } 1787 result = sm_io_fscanf(fp, SM_TIME_DEFAULT, "%lf", &avenrun); 1788 (void) sm_io_close(fp, SM_TIME_DEFAULT); 1789 if (result != 1) 1790 { 1791 if (tTd(3, 1)) 1792 sm_dprintf("getla: sm_io_fscanf() = %d: %s\n", 1793 result, sm_errstring(errno)); 1794 return -1; 1795 } 1796 1797 if (tTd(3, 1)) 1798 sm_dprintf("getla(): %.2f\n", avenrun); 1799 1800 return ((int) (avenrun + 0.5)); 1801 } 1802 1803 #endif /* LA_TYPE == LA_PROCSTR */ 1804 1805 #if LA_TYPE == LA_IRIX6 1806 1807 # include <sys/sysmp.h> 1808 1809 # ifdef _UNICOSMP 1810 # define CAST_SYSMP(x) (x) 1811 # else /* _UNICOSMP */ 1812 # define CAST_SYSMP(x) ((x) & 0x7fffffff) 1813 # endif /* _UNICOSMP */ 1814 1815 int 1816 getla(void) 1817 { 1818 int j; 1819 static int kmem = -1; 1820 int avenrun[3]; 1821 1822 if (kmem < 0) 1823 { 1824 kmem = open(_PATH_KMEM, 0, 0); 1825 if (kmem < 0) 1826 { 1827 if (tTd(3, 1)) 1828 sm_dprintf("getla: open(%s): %s\n", _PATH_KMEM, 1829 sm_errstring(errno)); 1830 return -1; 1831 } 1832 if ((j = fcntl(kmem, F_GETFD, 0)) < 0 || 1833 fcntl(kmem, F_SETFD, j | FD_CLOEXEC) < 0) 1834 { 1835 if (tTd(3, 1)) 1836 sm_dprintf("getla: fcntl(/dev/kmem, FD_CLOEXEC): %s\n", 1837 sm_errstring(errno)); 1838 (void) close(kmem); 1839 kmem = -1; 1840 return -1; 1841 } 1842 } 1843 1844 if (lseek(kmem, CAST_SYSMP(sysmp(MP_KERNADDR, MPKA_AVENRUN)), SEEK_SET) 1845 == -1 || 1846 read(kmem, (char *) avenrun, sizeof(avenrun)) < sizeof(avenrun)) 1847 { 1848 if (tTd(3, 1)) 1849 sm_dprintf("getla: lseek or read: %s\n", 1850 sm_errstring(errno)); 1851 return -1; 1852 } 1853 if (tTd(3, 5)) 1854 { 1855 sm_dprintf("getla: avenrun = %ld", (long int) avenrun[0]); 1856 if (tTd(3, 15)) 1857 sm_dprintf(", %ld, %ld", 1858 (long int) avenrun[1], (long int) avenrun[2]); 1859 sm_dprintf("\n"); 1860 } 1861 1862 if (tTd(3, 1)) 1863 sm_dprintf("getla: %d\n", 1864 (int) (avenrun[0] + FSCALE/2) >> FSHIFT); 1865 return ((int) (avenrun[0] + FSCALE/2) >> FSHIFT); 1866 1867 } 1868 #endif /* LA_TYPE == LA_IRIX6 */ 1869 1870 #if LA_TYPE == LA_KSTAT 1871 1872 # include <kstat.h> 1873 1874 int 1875 getla() 1876 { 1877 static kstat_ctl_t *kc = NULL; 1878 static kstat_t *ksp = NULL; 1879 kstat_named_t *ksn; 1880 int la; 1881 1882 if (kc == NULL) /* if not initialized before */ 1883 kc = kstat_open(); 1884 if (kc == NULL) 1885 { 1886 if (tTd(3, 1)) 1887 sm_dprintf("getla: kstat_open(): %s\n", 1888 sm_errstring(errno)); 1889 return -1; 1890 } 1891 if (ksp == NULL) 1892 ksp = kstat_lookup(kc, "unix", 0, "system_misc"); 1893 if (ksp == NULL) 1894 { 1895 if (tTd(3, 1)) 1896 sm_dprintf("getla: kstat_lookup(): %s\n", 1897 sm_errstring(errno)); 1898 return -1; 1899 } 1900 if (kstat_read(kc, ksp, NULL) < 0) 1901 { 1902 if (tTd(3, 1)) 1903 sm_dprintf("getla: kstat_read(): %s\n", 1904 sm_errstring(errno)); 1905 return -1; 1906 } 1907 ksn = (kstat_named_t *) kstat_data_lookup(ksp, "avenrun_1min"); 1908 la = ((double) ksn->value.ul + FSCALE/2) / FSCALE; 1909 /* kstat_close(kc); /o do not close for fast access */ 1910 return la; 1911 } 1912 1913 #endif /* LA_TYPE == LA_KSTAT */ 1914 1915 #if LA_TYPE == LA_DEVSHORT 1916 1917 /* 1918 ** Read /dev/table/avenrun for the load average. This should contain 1919 ** three shorts for the 1, 5, and 15 minute loads. We only read the 1920 ** first, since that's all we care about. 1921 ** 1922 ** Intended for SCO OpenServer 5. 1923 */ 1924 1925 # ifndef _PATH_AVENRUN 1926 # define _PATH_AVENRUN "/dev/table/avenrun" 1927 # endif /* ! _PATH_AVENRUN */ 1928 1929 int 1930 getla() 1931 { 1932 static int afd = -1; 1933 short avenrun; 1934 int loadav; 1935 int r; 1936 1937 errno = EBADF; 1938 1939 if (afd == -1 || lseek(afd, 0L, SEEK_SET) == -1) 1940 { 1941 if (errno != EBADF) 1942 return -1; 1943 afd = open(_PATH_AVENRUN, O_RDONLY|O_SYNC); 1944 if (afd < 0) 1945 { 1946 sm_syslog(LOG_ERR, NOQID, 1947 "can't open %s: %s", 1948 _PATH_AVENRUN, sm_errstring(errno)); 1949 return -1; 1950 } 1951 } 1952 1953 r = read(afd, &avenrun, sizeof(avenrun)); 1954 1955 if (tTd(3, 5)) 1956 sm_dprintf("getla: avenrun = %d\n", avenrun); 1957 loadav = (int) (avenrun + FSCALE/2) >> FSHIFT; 1958 if (tTd(3, 1)) 1959 sm_dprintf("getla: %d\n", loadav); 1960 return loadav; 1961 } 1962 1963 #endif /* LA_TYPE == LA_DEVSHORT */ 1964 1965 #if LA_TYPE == LA_ALPHAOSF 1966 struct rtentry; 1967 struct mbuf; 1968 # include <sys/table.h> 1969 1970 int 1971 getla() 1972 { 1973 int ave = 0; 1974 struct tbl_loadavg tab; 1975 1976 if (table(TBL_LOADAVG, 0, &tab, 1, sizeof(tab)) == -1) 1977 { 1978 if (tTd(3, 1)) 1979 sm_dprintf("getla: table %s\n", sm_errstring(errno)); 1980 return -1; 1981 } 1982 1983 if (tTd(3, 1)) 1984 sm_dprintf("getla: scale = %d\n", tab.tl_lscale); 1985 1986 if (tab.tl_lscale) 1987 ave = ((tab.tl_avenrun.l[2] + (tab.tl_lscale/2)) / 1988 tab.tl_lscale); 1989 else 1990 ave = (int) (tab.tl_avenrun.d[2] + 0.5); 1991 1992 if (tTd(3, 1)) 1993 sm_dprintf("getla: %d\n", ave); 1994 1995 return ave; 1996 } 1997 1998 #endif /* LA_TYPE == LA_ALPHAOSF */ 1999 2000 #if LA_TYPE == LA_PSET 2001 2002 int 2003 getla() 2004 { 2005 double avenrun[3]; 2006 2007 if (pset_getloadavg(PS_MYID, avenrun, 2008 sizeof(avenrun) / sizeof(avenrun[0])) < 0) 2009 { 2010 if (tTd(3, 1)) 2011 sm_dprintf("getla: pset_getloadavg failed: %s", 2012 sm_errstring(errno)); 2013 return -1; 2014 } 2015 if (tTd(3, 1)) 2016 sm_dprintf("getla: %d\n", (int) (avenrun[0] +0.5)); 2017 return ((int) (avenrun[0] + 0.5)); 2018 } 2019 2020 #endif /* LA_TYPE == LA_PSET */ 2021 2022 #if LA_TYPE == LA_ZERO 2023 2024 int 2025 getla() 2026 { 2027 if (tTd(3, 1)) 2028 sm_dprintf("getla: ZERO\n"); 2029 return 0; 2030 } 2031 2032 #endif /* LA_TYPE == LA_ZERO */ 2033 2034 /* 2035 * Copyright 1989 Massachusetts Institute of Technology 2036 * 2037 * Permission to use, copy, modify, distribute, and sell this software and its 2038 * documentation for any purpose is hereby granted without fee, provided that 2039 * the above copyright notice appear in all copies and that both that 2040 * copyright notice and this permission notice appear in supporting 2041 * documentation, and that the name of M.I.T. not be used in advertising or 2042 * publicity pertaining to distribution of the software without specific, 2043 * written prior permission. M.I.T. makes no representations about the 2044 * suitability of this software for any purpose. It is provided "as is" 2045 * without express or implied warranty. 2046 * 2047 * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL 2048 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T. 2049 * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 2050 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION 2051 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 2052 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 2053 * 2054 * Authors: Many and varied... 2055 */ 2056 2057 /* Non Apollo stuff removed by Don Lewis 11/15/93 */ 2058 #ifndef lint 2059 SM_UNUSED(static char rcsid[]) = "@(#)$OrigId: getloadavg.c,v 1.16 1991/06/21 12:51:15 paul Exp $"; 2060 #endif /* ! lint */ 2061 2062 #ifdef apollo 2063 # undef volatile 2064 # include <apollo/base.h> 2065 2066 /* ARGSUSED */ 2067 int getloadavg( call_data ) 2068 caddr_t call_data; /* pointer to (double) return value */ 2069 { 2070 double *avenrun = (double *) call_data; 2071 int i; 2072 status_$t st; 2073 long loadav[3]; 2074 2075 proc1_$get_loadav(loadav, &st); 2076 *avenrun = loadav[0] / (double) (1 << 16); 2077 return 0; 2078 } 2079 #endif /* apollo */ 2080 /* 2081 ** SM_GETLA -- get the current load average 2082 ** 2083 ** Parameters: 2084 ** none 2085 ** 2086 ** Returns: 2087 ** none 2088 ** 2089 ** Side Effects: 2090 ** Set CurrentLA to the current load average. 2091 ** Set {load_avg} in GlobalMacros to the current load average. 2092 */ 2093 2094 void 2095 sm_getla() 2096 { 2097 char labuf[8]; 2098 2099 CurrentLA = getla(); 2100 (void) sm_snprintf(labuf, sizeof(labuf), "%d", CurrentLA); 2101 macdefine(&GlobalMacros, A_TEMP, macid("{load_avg}"), labuf); 2102 } 2103 /* 2104 ** SHOULDQUEUE -- should this message be queued or sent? 2105 ** 2106 ** Compares the message cost to the load average to decide. 2107 ** 2108 ** Note: Do NOT change this API! It is documented in op.me 2109 ** and theoretically the user can change this function... 2110 ** 2111 ** Parameters: 2112 ** pri -- the priority of the message in question. 2113 ** ct -- the message creation time (unused, but see above). 2114 ** 2115 ** Returns: 2116 ** true -- if this message should be queued up for the 2117 ** time being. 2118 ** false -- if the load is low enough to send this message. 2119 ** 2120 ** Side Effects: 2121 ** none. 2122 */ 2123 2124 /* ARGSUSED1 */ 2125 bool 2126 shouldqueue(pri, ct) 2127 long pri; 2128 time_t ct; 2129 { 2130 bool rval; 2131 #if _FFR_MEMSTAT 2132 long memfree; 2133 #endif /* _FFR_MEMSTAT */ 2134 2135 if (tTd(3, 30)) 2136 sm_dprintf("shouldqueue: CurrentLA=%d, pri=%ld: ", 2137 CurrentLA, pri); 2138 2139 #if _FFR_MEMSTAT 2140 if (QueueLowMem > 0 && 2141 sm_memstat_get(MemoryResource, &memfree) >= 0 && 2142 memfree < QueueLowMem) 2143 { 2144 if (tTd(3, 30)) 2145 sm_dprintf("true (memfree=%ld < QueueLowMem=%ld)\n", 2146 memfree, QueueLowMem); 2147 return true; 2148 } 2149 #endif /* _FFR_MEMSTAT */ 2150 if (CurrentLA < QueueLA) 2151 { 2152 if (tTd(3, 30)) 2153 sm_dprintf("false (CurrentLA < QueueLA)\n"); 2154 return false; 2155 } 2156 rval = pri > (QueueFactor / (CurrentLA - QueueLA + 1)); 2157 if (tTd(3, 30)) 2158 sm_dprintf("%s (by calculation)\n", rval ? "true" : "false"); 2159 return rval; 2160 } 2161 2162 /* 2163 ** REFUSECONNECTIONS -- decide if connections should be refused 2164 ** 2165 ** Parameters: 2166 ** e -- the current envelope. 2167 ** dn -- number of daemon. 2168 ** active -- was this daemon actually active? 2169 ** 2170 ** Returns: 2171 ** true if incoming SMTP connections should be refused 2172 ** (for now). 2173 ** false if we should accept new work. 2174 ** 2175 ** Side Effects: 2176 ** Sets process title when it is rejecting connections. 2177 */ 2178 2179 bool 2180 refuseconnections(e, dn, active) 2181 ENVELOPE *e; 2182 int dn; 2183 bool active; 2184 { 2185 static time_t lastconn[MAXDAEMONS]; 2186 static int conncnt[MAXDAEMONS]; 2187 static time_t firstrejtime[MAXDAEMONS]; 2188 static time_t nextlogtime[MAXDAEMONS]; 2189 int limit; 2190 #if _FFR_MEMSTAT 2191 long memfree; 2192 #endif /* _FFR_MEMSTAT */ 2193 2194 #if XLA 2195 if (!xla_smtp_ok()) 2196 return true; 2197 #endif /* XLA */ 2198 2199 SM_ASSERT(dn >= 0); 2200 SM_ASSERT(dn < MAXDAEMONS); 2201 if (ConnRateThrottle > 0) 2202 { 2203 time_t now; 2204 2205 now = curtime(); 2206 if (active) 2207 { 2208 if (now != lastconn[dn]) 2209 { 2210 lastconn[dn] = now; 2211 conncnt[dn] = 1; 2212 } 2213 else if (conncnt[dn]++ > ConnRateThrottle) 2214 { 2215 #define D_MSG_CRT "deferring connections on daemon %s: %d per second" 2216 /* sleep to flatten out connection load */ 2217 sm_setproctitle(true, e, D_MSG_CRT, 2218 Daemons[dn].d_name, 2219 ConnRateThrottle); 2220 if (LogLevel > 8) 2221 sm_syslog(LOG_INFO, NOQID, D_MSG_CRT, 2222 Daemons[dn].d_name, 2223 ConnRateThrottle); 2224 (void) sleep(1); 2225 } 2226 } 2227 else if (now != lastconn[dn]) 2228 conncnt[dn] = 0; 2229 } 2230 2231 2232 #if _FFR_MEMSTAT 2233 if (RefuseLowMem > 0 && 2234 sm_memstat_get(MemoryResource, &memfree) >= 0 && 2235 memfree < RefuseLowMem) 2236 { 2237 # define R_MSG_LM "rejecting connections on daemon %s: free memory: %ld" 2238 sm_setproctitle(true, e, R_MSG_LM, Daemons[dn].d_name, memfree); 2239 if (LogLevel > 8) 2240 sm_syslog(LOG_NOTICE, NOQID, R_MSG_LM, 2241 Daemons[dn].d_name, memfree); 2242 return true; 2243 } 2244 #endif /* _FFR_MEMSTAT */ 2245 sm_getla(); 2246 limit = (Daemons[dn].d_refuseLA != DPO_NOTSET) ? 2247 Daemons[dn].d_refuseLA : RefuseLA; 2248 if (limit > 0 && CurrentLA >= limit) 2249 { 2250 time_t now; 2251 2252 # define R_MSG_LA "rejecting connections on daemon %s: load average: %d" 2253 # define R2_MSG_LA "have been rejecting connections on daemon %s for %s" 2254 sm_setproctitle(true, e, R_MSG_LA, Daemons[dn].d_name, 2255 CurrentLA); 2256 if (LogLevel > 8) 2257 sm_syslog(LOG_NOTICE, NOQID, R_MSG_LA, 2258 Daemons[dn].d_name, CurrentLA); 2259 now = curtime(); 2260 if (firstrejtime[dn] == 0) 2261 { 2262 firstrejtime[dn] = now; 2263 nextlogtime[dn] = now + RejectLogInterval; 2264 } 2265 else if (nextlogtime[dn] < now) 2266 { 2267 sm_syslog(LOG_ERR, NOQID, R2_MSG_LA, Daemons[dn].d_name, 2268 pintvl(now - firstrejtime[dn], true)); 2269 nextlogtime[dn] = now + RejectLogInterval; 2270 } 2271 return true; 2272 } 2273 else 2274 firstrejtime[dn] = 0; 2275 2276 limit = (Daemons[dn].d_delayLA != DPO_NOTSET) ? 2277 Daemons[dn].d_delayLA : DelayLA; 2278 if (limit > 0 && CurrentLA >= limit) 2279 { 2280 time_t now; 2281 static time_t log_delay = (time_t) 0; 2282 2283 # define MIN_DELAY_LOG 90 /* wait before logging this again */ 2284 # define D_MSG_LA "delaying connections on daemon %s: load average=%d >= %d" 2285 /* sleep to flatten out connection load */ 2286 sm_setproctitle(true, e, D_MSG_LA, Daemons[dn].d_name, limit); 2287 if (LogLevel > 8 && (now = curtime()) > log_delay) 2288 { 2289 sm_syslog(LOG_INFO, NOQID, D_MSG_LA, 2290 Daemons[dn].d_name, CurrentLA, limit); 2291 log_delay = now + MIN_DELAY_LOG; 2292 } 2293 (void) sleep(1); 2294 } 2295 2296 limit = (Daemons[dn].d_maxchildren != DPO_NOTSET) ? 2297 Daemons[dn].d_maxchildren : MaxChildren; 2298 if (limit > 0 && CurChildren >= limit) 2299 { 2300 proc_list_probe(); 2301 if (CurChildren >= limit) 2302 { 2303 #define R_MSG_CHILD "rejecting connections on daemon %s: %d children, max %d" 2304 sm_setproctitle(true, e, R_MSG_CHILD, 2305 Daemons[dn].d_name, CurChildren, 2306 limit); 2307 if (LogLevel > 8) 2308 sm_syslog(LOG_INFO, NOQID, R_MSG_CHILD, 2309 Daemons[dn].d_name, CurChildren, 2310 limit); 2311 return true; 2312 } 2313 } 2314 return false; 2315 } 2316 2317 /* 2318 ** SETPROCTITLE -- set process title for ps 2319 ** 2320 ** Parameters: 2321 ** fmt -- a printf style format string. 2322 ** a, b, c -- possible parameters to fmt. 2323 ** 2324 ** Returns: 2325 ** none. 2326 ** 2327 ** Side Effects: 2328 ** Clobbers argv of our main procedure so ps(1) will 2329 ** display the title. 2330 */ 2331 2332 #define SPT_NONE 0 /* don't use it at all */ 2333 #define SPT_REUSEARGV 1 /* cover argv with title information */ 2334 #define SPT_BUILTIN 2 /* use libc builtin */ 2335 #define SPT_PSTAT 3 /* use pstat(PSTAT_SETCMD, ...) */ 2336 #define SPT_PSSTRINGS 4 /* use PS_STRINGS->... */ 2337 #define SPT_SYSMIPS 5 /* use sysmips() supported by NEWS-OS 6 */ 2338 #define SPT_SCO 6 /* write kernel u. area */ 2339 #define SPT_CHANGEARGV 7 /* write our own strings into argv[] */ 2340 2341 #ifndef SPT_TYPE 2342 # define SPT_TYPE SPT_REUSEARGV 2343 #endif /* ! SPT_TYPE */ 2344 2345 2346 #if SPT_TYPE != SPT_NONE && SPT_TYPE != SPT_BUILTIN 2347 2348 # if SPT_TYPE == SPT_PSTAT 2349 # include <sys/pstat.h> 2350 # endif /* SPT_TYPE == SPT_PSTAT */ 2351 # if SPT_TYPE == SPT_PSSTRINGS 2352 # include <machine/vmparam.h> 2353 # include <sys/exec.h> 2354 # ifndef PS_STRINGS /* hmmmm.... apparently not available after all */ 2355 # undef SPT_TYPE 2356 # define SPT_TYPE SPT_REUSEARGV 2357 # else /* ! PS_STRINGS */ 2358 # ifndef NKPDE /* FreeBSD 2.0 */ 2359 # define NKPDE 63 2360 typedef unsigned int *pt_entry_t; 2361 # endif /* ! NKPDE */ 2362 # endif /* ! PS_STRINGS */ 2363 # endif /* SPT_TYPE == SPT_PSSTRINGS */ 2364 2365 # if SPT_TYPE == SPT_PSSTRINGS || SPT_TYPE == SPT_CHANGEARGV 2366 # define SETPROC_STATIC static 2367 # else /* SPT_TYPE == SPT_PSSTRINGS || SPT_TYPE == SPT_CHANGEARGV */ 2368 # define SETPROC_STATIC 2369 # endif /* SPT_TYPE == SPT_PSSTRINGS || SPT_TYPE == SPT_CHANGEARGV */ 2370 2371 # if SPT_TYPE == SPT_SYSMIPS 2372 # include <sys/sysmips.h> 2373 # include <sys/sysnews.h> 2374 # endif /* SPT_TYPE == SPT_SYSMIPS */ 2375 2376 # if SPT_TYPE == SPT_SCO 2377 # include <sys/immu.h> 2378 # include <sys/dir.h> 2379 # include <sys/user.h> 2380 # include <sys/fs/s5param.h> 2381 # if PSARGSZ > MAXLINE 2382 # define SPT_BUFSIZE PSARGSZ 2383 # endif /* PSARGSZ > MAXLINE */ 2384 # endif /* SPT_TYPE == SPT_SCO */ 2385 2386 # ifndef SPT_PADCHAR 2387 # define SPT_PADCHAR ' ' 2388 # endif /* ! SPT_PADCHAR */ 2389 2390 #endif /* SPT_TYPE != SPT_NONE && SPT_TYPE != SPT_BUILTIN */ 2391 2392 #ifndef SPT_BUFSIZE 2393 # define SPT_BUFSIZE MAXLINE 2394 #endif /* ! SPT_BUFSIZE */ 2395 2396 #if _FFR_SPT_ALIGN 2397 2398 /* 2399 ** It looks like the Compaq Tru64 5.1A now aligns argv and envp to 2400 ** 64 bit alignment, so unless each piece of argv and envp is a multiple 2401 ** of 8 bytes (including terminating NULL), initsetproctitle() won't use 2402 ** any of the space beyond argv[0]. Be sure to set SPT_ALIGN_SIZE if 2403 ** you use this FFR. 2404 */ 2405 2406 # ifdef SPT_ALIGN_SIZE 2407 # define SPT_ALIGN(x, align) (((((x) + SPT_ALIGN_SIZE) >> (align)) << (align)) - 1) 2408 # else /* SPT_ALIGN_SIZE */ 2409 # define SPT_ALIGN(x, align) (x) 2410 # endif /* SPT_ALIGN_SIZE */ 2411 #else /* _FFR_SPT_ALIGN */ 2412 # define SPT_ALIGN(x, align) (x) 2413 #endif /* _FFR_SPT_ALIGN */ 2414 2415 /* 2416 ** Pointers for setproctitle. 2417 ** This allows "ps" listings to give more useful information. 2418 */ 2419 2420 static char **Argv = NULL; /* pointer to argument vector */ 2421 static char *LastArgv = NULL; /* end of argv */ 2422 #if SPT_TYPE != SPT_BUILTIN 2423 static void setproctitle __P((const char *, ...)); 2424 #endif /* SPT_TYPE != SPT_BUILTIN */ 2425 2426 void 2427 initsetproctitle(argc, argv, envp) 2428 int argc; 2429 char **argv; 2430 char **envp; 2431 { 2432 register int i; 2433 int align; 2434 extern char **environ; 2435 2436 /* 2437 ** Move the environment so setproctitle can use the space at 2438 ** the top of memory. 2439 */ 2440 2441 if (envp != NULL) 2442 { 2443 for (i = 0; envp[i] != NULL; i++) 2444 continue; 2445 environ = (char **) xalloc(sizeof(char *) * (i + 1)); 2446 for (i = 0; envp[i] != NULL; i++) 2447 environ[i] = newstr(envp[i]); 2448 environ[i] = NULL; 2449 } 2450 2451 /* 2452 ** Save start and extent of argv for setproctitle. 2453 */ 2454 2455 Argv = argv; 2456 2457 /* 2458 ** Determine how much space we can use for setproctitle. 2459 ** Use all contiguous argv and envp pointers starting at argv[0] 2460 */ 2461 2462 align = -1; 2463 # if _FFR_SPT_ALIGN 2464 # ifdef SPT_ALIGN_SIZE 2465 for (i = SPT_ALIGN_SIZE; i > 0; i >>= 1) 2466 align++; 2467 # endif /* SPT_ALIGN_SIZE */ 2468 # endif /* _FFR_SPT_ALIGN */ 2469 2470 for (i = 0; i < argc; i++) 2471 { 2472 if (i == 0 || LastArgv + 1 == argv[i]) 2473 LastArgv = argv[i] + SPT_ALIGN(strlen(argv[i]), align); 2474 } 2475 for (i = 0; LastArgv != NULL && envp != NULL && envp[i] != NULL; i++) 2476 { 2477 if (LastArgv + 1 == envp[i]) 2478 LastArgv = envp[i] + SPT_ALIGN(strlen(envp[i]), align); 2479 } 2480 } 2481 2482 #if SPT_TYPE != SPT_BUILTIN 2483 2484 /*VARARGS1*/ 2485 static void 2486 # ifdef __STDC__ 2487 setproctitle(const char *fmt, ...) 2488 # else /* __STDC__ */ 2489 setproctitle(fmt, va_alist) 2490 const char *fmt; 2491 va_dcl 2492 # endif /* __STDC__ */ 2493 { 2494 # if SPT_TYPE != SPT_NONE 2495 register int i; 2496 register char *p; 2497 SETPROC_STATIC char buf[SPT_BUFSIZE]; 2498 SM_VA_LOCAL_DECL 2499 # if SPT_TYPE == SPT_PSTAT 2500 union pstun pst; 2501 # endif /* SPT_TYPE == SPT_PSTAT */ 2502 # if SPT_TYPE == SPT_SCO 2503 int j; 2504 off_t seek_off; 2505 static int kmem = -1; 2506 static pid_t kmempid = -1; 2507 struct user u; 2508 # endif /* SPT_TYPE == SPT_SCO */ 2509 2510 p = buf; 2511 2512 /* print sendmail: heading for grep */ 2513 (void) sm_strlcpy(p, "sendmail: ", SPACELEFT(buf, p)); 2514 p += strlen(p); 2515 2516 /* print the argument string */ 2517 SM_VA_START(ap, fmt); 2518 (void) sm_vsnprintf(p, SPACELEFT(buf, p), fmt, ap); 2519 SM_VA_END(ap); 2520 2521 i = (int) strlen(buf); 2522 if (i < 0) 2523 return; 2524 2525 # if SPT_TYPE == SPT_PSTAT 2526 pst.pst_command = buf; 2527 pstat(PSTAT_SETCMD, pst, i, 0, 0); 2528 # endif /* SPT_TYPE == SPT_PSTAT */ 2529 # if SPT_TYPE == SPT_PSSTRINGS 2530 PS_STRINGS->ps_nargvstr = 1; 2531 PS_STRINGS->ps_argvstr = buf; 2532 # endif /* SPT_TYPE == SPT_PSSTRINGS */ 2533 # if SPT_TYPE == SPT_SYSMIPS 2534 sysmips(SONY_SYSNEWS, NEWS_SETPSARGS, buf); 2535 # endif /* SPT_TYPE == SPT_SYSMIPS */ 2536 # if SPT_TYPE == SPT_SCO 2537 if (kmem < 0 || kmempid != CurrentPid) 2538 { 2539 if (kmem >= 0) 2540 (void) close(kmem); 2541 kmem = open(_PATH_KMEM, O_RDWR, 0); 2542 if (kmem < 0) 2543 return; 2544 if ((j = fcntl(kmem, F_GETFD, 0)) < 0 || 2545 fcntl(kmem, F_SETFD, j | FD_CLOEXEC) < 0) 2546 { 2547 (void) close(kmem); 2548 kmem = -1; 2549 return; 2550 } 2551 kmempid = CurrentPid; 2552 } 2553 buf[PSARGSZ - 1] = '\0'; 2554 seek_off = UVUBLK + (off_t) u.u_psargs - (off_t) &u; 2555 if (lseek(kmem, (off_t) seek_off, SEEK_SET) == seek_off) 2556 (void) write(kmem, buf, PSARGSZ); 2557 # endif /* SPT_TYPE == SPT_SCO */ 2558 # if SPT_TYPE == SPT_REUSEARGV 2559 if (LastArgv == NULL) 2560 return; 2561 2562 if (i > LastArgv - Argv[0] - 2) 2563 { 2564 i = LastArgv - Argv[0] - 2; 2565 buf[i] = '\0'; 2566 } 2567 (void) sm_strlcpy(Argv[0], buf, i + 1); 2568 p = &Argv[0][i]; 2569 while (p < LastArgv) 2570 *p++ = SPT_PADCHAR; 2571 Argv[1] = NULL; 2572 # endif /* SPT_TYPE == SPT_REUSEARGV */ 2573 # if SPT_TYPE == SPT_CHANGEARGV 2574 Argv[0] = buf; 2575 Argv[1] = 0; 2576 # endif /* SPT_TYPE == SPT_CHANGEARGV */ 2577 # endif /* SPT_TYPE != SPT_NONE */ 2578 } 2579 2580 #endif /* SPT_TYPE != SPT_BUILTIN */ 2581 /* 2582 ** SM_SETPROCTITLE -- set process task and set process title for ps 2583 ** 2584 ** Possibly set process status and call setproctitle() to 2585 ** change the ps display. 2586 ** 2587 ** Parameters: 2588 ** status -- whether or not to store as process status 2589 ** e -- the current envelope. 2590 ** fmt -- a printf style format string. 2591 ** a, b, c -- possible parameters to fmt. 2592 ** 2593 ** Returns: 2594 ** none. 2595 */ 2596 2597 /*VARARGS2*/ 2598 void 2599 #ifdef __STDC__ 2600 sm_setproctitle(bool status, ENVELOPE *e, const char *fmt, ...) 2601 #else /* __STDC__ */ 2602 sm_setproctitle(status, e, fmt, va_alist) 2603 bool status; 2604 ENVELOPE *e; 2605 const char *fmt; 2606 va_dcl 2607 #endif /* __STDC__ */ 2608 { 2609 char buf[SPT_BUFSIZE]; 2610 SM_VA_LOCAL_DECL 2611 2612 /* print the argument string */ 2613 SM_VA_START(ap, fmt); 2614 (void) sm_vsnprintf(buf, sizeof(buf), fmt, ap); 2615 SM_VA_END(ap); 2616 2617 if (status) 2618 proc_list_set(CurrentPid, buf); 2619 2620 if (ProcTitlePrefix != NULL) 2621 { 2622 char prefix[SPT_BUFSIZE]; 2623 2624 expand(ProcTitlePrefix, prefix, sizeof(prefix), e); 2625 setproctitle("%s: %s", prefix, buf); 2626 } 2627 else 2628 setproctitle("%s", buf); 2629 } 2630 /* 2631 ** WAITFOR -- wait for a particular process id. 2632 ** 2633 ** Parameters: 2634 ** pid -- process id to wait for. 2635 ** 2636 ** Returns: 2637 ** status of pid. 2638 ** -1 if pid never shows up. 2639 ** 2640 ** Side Effects: 2641 ** none. 2642 */ 2643 2644 int 2645 waitfor(pid) 2646 pid_t pid; 2647 { 2648 int st; 2649 pid_t i; 2650 2651 do 2652 { 2653 errno = 0; 2654 i = sm_wait(&st); 2655 if (i > 0) 2656 proc_list_drop(i, st, NULL); 2657 } while ((i >= 0 || errno == EINTR) && i != pid); 2658 if (i < 0) 2659 return -1; 2660 return st; 2661 } 2662 /* 2663 ** SM_WAIT -- wait 2664 ** 2665 ** Parameters: 2666 ** status -- pointer to status (return value) 2667 ** 2668 ** Returns: 2669 ** pid 2670 */ 2671 2672 pid_t 2673 sm_wait(status) 2674 int *status; 2675 { 2676 # ifdef WAITUNION 2677 union wait st; 2678 # else /* WAITUNION */ 2679 auto int st; 2680 # endif /* WAITUNION */ 2681 pid_t i; 2682 # if defined(ISC_UNIX) || defined(_SCO_unix_) 2683 int savesig; 2684 # endif /* defined(ISC_UNIX) || defined(_SCO_unix_) */ 2685 2686 # if defined(ISC_UNIX) || defined(_SCO_unix_) 2687 savesig = sm_releasesignal(SIGCHLD); 2688 # endif /* defined(ISC_UNIX) || defined(_SCO_unix_) */ 2689 i = wait(&st); 2690 # if defined(ISC_UNIX) || defined(_SCO_unix_) 2691 if (savesig > 0) 2692 sm_blocksignal(SIGCHLD); 2693 # endif /* defined(ISC_UNIX) || defined(_SCO_unix_) */ 2694 # ifdef WAITUNION 2695 *status = st.w_status; 2696 # else /* WAITUNION */ 2697 *status = st; 2698 # endif /* WAITUNION */ 2699 return i; 2700 } 2701 /* 2702 ** REAPCHILD -- pick up the body of my child, lest it become a zombie 2703 ** 2704 ** Parameters: 2705 ** sig -- the signal that got us here (unused). 2706 ** 2707 ** Returns: 2708 ** none. 2709 ** 2710 ** Side Effects: 2711 ** Picks up extant zombies. 2712 ** Control socket exits may restart/shutdown daemon. 2713 ** 2714 ** NOTE: THIS CAN BE CALLED FROM A SIGNAL HANDLER. DO NOT ADD 2715 ** ANYTHING TO THIS ROUTINE UNLESS YOU KNOW WHAT YOU ARE 2716 ** DOING. 2717 */ 2718 2719 /* ARGSUSED0 */ 2720 SIGFUNC_DECL 2721 reapchild(sig) 2722 int sig; 2723 { 2724 int save_errno = errno; 2725 int st; 2726 pid_t pid; 2727 # if HASWAITPID 2728 auto int status; 2729 int count; 2730 2731 count = 0; 2732 while ((pid = waitpid(-1, &status, WNOHANG)) > 0) 2733 { 2734 st = status; 2735 if (count++ > 1000) 2736 break; 2737 # else /* HASWAITPID */ 2738 # ifdef WNOHANG 2739 union wait status; 2740 2741 while ((pid = wait3(&status, WNOHANG, (struct rusage *) NULL)) > 0) 2742 { 2743 st = status.w_status; 2744 # else /* WNOHANG */ 2745 auto int status; 2746 2747 /* 2748 ** Catch one zombie -- we will be re-invoked (we hope) if there 2749 ** are more. Unreliable signals probably break this, but this 2750 ** is the "old system" situation -- waitpid or wait3 are to be 2751 ** strongly preferred. 2752 */ 2753 2754 if ((pid = wait(&status)) > 0) 2755 { 2756 st = status; 2757 # endif /* WNOHANG */ 2758 # endif /* HASWAITPID */ 2759 /* Drop PID and check if it was a control socket child */ 2760 proc_list_drop(pid, st, NULL); 2761 } 2762 FIX_SYSV_SIGNAL(sig, reapchild); 2763 errno = save_errno; 2764 return SIGFUNC_RETURN; 2765 } 2766 /* 2767 ** GETDTABLESIZE -- return number of file descriptors 2768 ** 2769 ** Only on non-BSD systems 2770 ** 2771 ** Parameters: 2772 ** none 2773 ** 2774 ** Returns: 2775 ** size of file descriptor table 2776 ** 2777 ** Side Effects: 2778 ** none 2779 */ 2780 2781 #ifdef SOLARIS 2782 # include <sys/resource.h> 2783 #endif /* SOLARIS */ 2784 2785 int 2786 getdtsize() 2787 { 2788 # ifdef RLIMIT_NOFILE 2789 struct rlimit rl; 2790 2791 if (getrlimit(RLIMIT_NOFILE, &rl) >= 0) 2792 return rl.rlim_cur; 2793 # endif /* RLIMIT_NOFILE */ 2794 2795 # if HASGETDTABLESIZE 2796 return getdtablesize(); 2797 # else /* HASGETDTABLESIZE */ 2798 # ifdef _SC_OPEN_MAX 2799 return sysconf(_SC_OPEN_MAX); 2800 # else /* _SC_OPEN_MAX */ 2801 return NOFILE; 2802 # endif /* _SC_OPEN_MAX */ 2803 # endif /* HASGETDTABLESIZE */ 2804 } 2805 /* 2806 ** UNAME -- get the UUCP name of this system. 2807 */ 2808 2809 #if !HASUNAME 2810 2811 int 2812 uname(name) 2813 struct utsname *name; 2814 { 2815 SM_FILE_T *file; 2816 char *n; 2817 2818 name->nodename[0] = '\0'; 2819 2820 /* try /etc/whoami -- one line with the node name */ 2821 if ((file = sm_io_open(SmFtStdio, SM_TIME_DEFAULT, "/etc/whoami", 2822 SM_IO_RDONLY, NULL)) != NULL) 2823 { 2824 (void) sm_io_fgets(file, SM_TIME_DEFAULT, name->nodename, 2825 NODE_LENGTH + 1); 2826 (void) sm_io_close(file, SM_TIME_DEFAULT); 2827 n = strchr(name->nodename, '\n'); 2828 if (n != NULL) 2829 *n = '\0'; 2830 if (name->nodename[0] != '\0') 2831 return 0; 2832 } 2833 2834 /* try /usr/include/whoami.h -- has a #define somewhere */ 2835 if ((file = sm_io_open(SmFtStdio, SM_TIME_DEFAULT, 2836 "/usr/include/whoami.h", SM_IO_RDONLY, NULL)) 2837 != NULL) 2838 { 2839 char buf[MAXLINE]; 2840 2841 while (sm_io_fgets(file, SM_TIME_DEFAULT, 2842 buf, sizeof(buf)) != NULL) 2843 { 2844 if (sm_io_sscanf(buf, "#define sysname \"%*[^\"]\"", 2845 NODE_LENGTH, name->nodename) > 0) 2846 break; 2847 } 2848 (void) sm_io_close(file, SM_TIME_DEFAULT); 2849 if (name->nodename[0] != '\0') 2850 return 0; 2851 } 2852 2853 return -1; 2854 } 2855 #endif /* !HASUNAME */ 2856 /* 2857 ** INITGROUPS -- initialize groups 2858 ** 2859 ** Stub implementation for System V style systems 2860 */ 2861 2862 #if !HASINITGROUPS 2863 2864 initgroups(name, basegid) 2865 char *name; 2866 int basegid; 2867 { 2868 return 0; 2869 } 2870 2871 #endif /* !HASINITGROUPS */ 2872 /* 2873 ** SETGROUPS -- set group list 2874 ** 2875 ** Stub implementation for systems that don't have group lists 2876 */ 2877 2878 #ifndef NGROUPS_MAX 2879 2880 int 2881 setgroups(ngroups, grouplist) 2882 int ngroups; 2883 GIDSET_T grouplist[]; 2884 { 2885 return 0; 2886 } 2887 2888 #endif /* ! NGROUPS_MAX */ 2889 /* 2890 ** SETSID -- set session id (for non-POSIX systems) 2891 */ 2892 2893 #if !HASSETSID 2894 2895 pid_t 2896 setsid __P ((void)) 2897 { 2898 # ifdef TIOCNOTTY 2899 int fd; 2900 2901 fd = open("/dev/tty", O_RDWR, 0); 2902 if (fd >= 0) 2903 { 2904 (void) ioctl(fd, TIOCNOTTY, (char *) 0); 2905 (void) close(fd); 2906 } 2907 # endif /* TIOCNOTTY */ 2908 # ifdef SYS5SETPGRP 2909 return setpgrp(); 2910 # else /* SYS5SETPGRP */ 2911 return setpgid(0, CurrentPid); 2912 # endif /* SYS5SETPGRP */ 2913 } 2914 2915 #endif /* !HASSETSID */ 2916 /* 2917 ** FSYNC -- dummy fsync 2918 */ 2919 2920 #if NEEDFSYNC 2921 2922 fsync(fd) 2923 int fd; 2924 { 2925 # ifdef O_SYNC 2926 return fcntl(fd, F_SETFL, O_SYNC); 2927 # else /* O_SYNC */ 2928 /* nothing we can do */ 2929 return 0; 2930 # endif /* O_SYNC */ 2931 } 2932 2933 #endif /* NEEDFSYNC */ 2934 /* 2935 ** DGUX_INET_ADDR -- inet_addr for DG/UX 2936 ** 2937 ** Data General DG/UX version of inet_addr returns a struct in_addr 2938 ** instead of a long. This patches things. Only needed on versions 2939 ** prior to 5.4.3. 2940 */ 2941 2942 #ifdef DGUX_5_4_2 2943 2944 # undef inet_addr 2945 2946 long 2947 dgux_inet_addr(host) 2948 char *host; 2949 { 2950 struct in_addr haddr; 2951 2952 haddr = inet_addr(host); 2953 return haddr.s_addr; 2954 } 2955 2956 #endif /* DGUX_5_4_2 */ 2957 /* 2958 ** GETOPT -- for old systems or systems with bogus implementations 2959 */ 2960 2961 #if !SM_CONF_GETOPT 2962 2963 /* 2964 * Copyright (c) 1985 Regents of the University of California. 2965 * All rights reserved. The Berkeley software License Agreement 2966 * specifies the terms and conditions for redistribution. 2967 */ 2968 2969 2970 /* 2971 ** this version hacked to add `atend' flag to allow state machine 2972 ** to reset if invoked by the program to scan args for a 2nd time 2973 */ 2974 2975 # if defined(LIBC_SCCS) && !defined(lint) 2976 static char sccsid[] = "@(#)getopt.c 4.3 (Berkeley) 3/9/86"; 2977 # endif /* defined(LIBC_SCCS) && !defined(lint) */ 2978 2979 /* 2980 ** get option letter from argument vector 2981 */ 2982 # ifdef _CONVEX_SOURCE 2983 extern int optind, opterr, optopt; 2984 extern char *optarg; 2985 # else /* _CONVEX_SOURCE */ 2986 int opterr = 1; /* if error message should be printed */ 2987 int optind = 1; /* index into parent argv vector */ 2988 int optopt = 0; /* character checked for validity */ 2989 char *optarg = NULL; /* argument associated with option */ 2990 # endif /* _CONVEX_SOURCE */ 2991 2992 # define BADCH (int)'?' 2993 # define EMSG "" 2994 # define tell(s) if (opterr) \ 2995 {sm_io_fputs(smioerr, SM_TIME_DEFAULT, *nargv); \ 2996 (void) sm_io_fputs(smioerr, SM_TIME_DEFAULT, s); \ 2997 (void) sm_io_putc(smioerr, SM_TIME_DEFAULT, optopt); \ 2998 (void) sm_io_putc(smioerr, SM_TIME_DEFAULT, '\n'); \ 2999 return BADCH;} 3000 3001 int 3002 getopt(nargc,nargv,ostr) 3003 int nargc; 3004 char *const *nargv; 3005 const char *ostr; 3006 { 3007 static char *place = EMSG; /* option letter processing */ 3008 static char atend = 0; 3009 register char *oli = NULL; /* option letter list index */ 3010 3011 if (atend) { 3012 atend = 0; 3013 place = EMSG; 3014 } 3015 if(!*place) { /* update scanning pointer */ 3016 if (optind >= nargc || *(place = nargv[optind]) != '-' || !*++place) { 3017 atend++; 3018 return -1; 3019 } 3020 if (*place == '-') { /* found "--" */ 3021 ++optind; 3022 atend++; 3023 return -1; 3024 } 3025 } /* option letter okay? */ 3026 if ((optopt = (int)*place++) == (int)':' || !(oli = strchr(ostr,optopt))) { 3027 if (!*place) ++optind; 3028 tell(": illegal option -- "); 3029 } 3030 if (oli && *++oli != ':') { /* don't need argument */ 3031 optarg = NULL; 3032 if (!*place) ++optind; 3033 } 3034 else { /* need an argument */ 3035 if (*place) optarg = place; /* no white space */ 3036 else if (nargc <= ++optind) { /* no arg */ 3037 place = EMSG; 3038 tell(": option requires an argument -- "); 3039 } 3040 else optarg = nargv[optind]; /* white space */ 3041 place = EMSG; 3042 ++optind; 3043 } 3044 return optopt; /* dump back option letter */ 3045 } 3046 3047 #endif /* !SM_CONF_GETOPT */ 3048 /* 3049 ** USERSHELLOK -- tell if a user's shell is ok for unrestricted use 3050 ** 3051 ** Parameters: 3052 ** user -- the name of the user we are checking. 3053 ** shell -- the user's shell from /etc/passwd 3054 ** 3055 ** Returns: 3056 ** true -- if it is ok to use this for unrestricted access. 3057 ** false -- if the shell is restricted. 3058 */ 3059 3060 #if !HASGETUSERSHELL 3061 3062 # ifndef _PATH_SHELLS 3063 # define _PATH_SHELLS "/etc/shells" 3064 # endif /* ! _PATH_SHELLS */ 3065 3066 # if defined(_AIX3) || defined(_AIX4) 3067 # include <userconf.h> 3068 # if _AIX4 >= 40200 3069 # include <userpw.h> 3070 # endif /* _AIX4 >= 40200 */ 3071 # include <usersec.h> 3072 # endif /* defined(_AIX3) || defined(_AIX4) */ 3073 3074 static char *DefaultUserShells[] = 3075 { 3076 "/bin/sh", /* standard shell */ 3077 # ifdef MPE 3078 "/SYS/PUB/CI", 3079 # else /* MPE */ 3080 "/usr/bin/sh", 3081 "/bin/csh", /* C shell */ 3082 "/usr/bin/csh", 3083 # endif /* MPE */ 3084 # ifdef __hpux 3085 # ifdef V4FS 3086 "/usr/bin/rsh", /* restricted Bourne shell */ 3087 "/usr/bin/ksh", /* Korn shell */ 3088 "/usr/bin/rksh", /* restricted Korn shell */ 3089 "/usr/bin/pam", 3090 "/usr/bin/keysh", /* key shell (extended Korn shell) */ 3091 "/usr/bin/posix/sh", 3092 # else /* V4FS */ 3093 "/bin/rsh", /* restricted Bourne shell */ 3094 "/bin/ksh", /* Korn shell */ 3095 "/bin/rksh", /* restricted Korn shell */ 3096 "/bin/pam", 3097 "/usr/bin/keysh", /* key shell (extended Korn shell) */ 3098 "/bin/posix/sh", 3099 "/sbin/sh", 3100 # endif /* V4FS */ 3101 # endif /* __hpux */ 3102 # if defined(_AIX3) || defined(_AIX4) 3103 "/bin/ksh", /* Korn shell */ 3104 "/usr/bin/ksh", 3105 "/bin/tsh", /* trusted shell */ 3106 "/usr/bin/tsh", 3107 "/bin/bsh", /* Bourne shell */ 3108 "/usr/bin/bsh", 3109 # endif /* defined(_AIX3) || defined(_AIX4) */ 3110 # if defined(__svr4__) || defined(__svr5__) 3111 "/bin/ksh", /* Korn shell */ 3112 "/usr/bin/ksh", 3113 # endif /* defined(__svr4__) || defined(__svr5__) */ 3114 # ifdef sgi 3115 "/sbin/sh", /* SGI's shells really live in /sbin */ 3116 "/usr/bin/sh", 3117 "/sbin/bsh", /* classic Bourne shell */ 3118 "/bin/bsh", 3119 "/usr/bin/bsh", 3120 "/sbin/csh", /* standard csh */ 3121 "/bin/csh", 3122 "/usr/bin/csh", 3123 "/sbin/jsh", /* classic Bourne shell w/ job control*/ 3124 "/bin/jsh", 3125 "/usr/bin/jsh", 3126 "/bin/ksh", /* Korn shell */ 3127 "/sbin/ksh", 3128 "/usr/bin/ksh", 3129 "/sbin/tcsh", /* Extended csh */ 3130 "/bin/tcsh", 3131 "/usr/bin/tcsh", 3132 # endif /* sgi */ 3133 NULL 3134 }; 3135 3136 #endif /* !HASGETUSERSHELL */ 3137 3138 #define WILDCARD_SHELL "/SENDMAIL/ANY/SHELL/" 3139 3140 bool 3141 usershellok(user, shell) 3142 char *user; 3143 char *shell; 3144 { 3145 # if HASGETUSERSHELL 3146 register char *p; 3147 extern char *getusershell(); 3148 3149 if (shell == NULL || shell[0] == '\0' || wordinclass(user, 't') || 3150 ConfigLevel <= 1) 3151 return true; 3152 3153 setusershell(); 3154 while ((p = getusershell()) != NULL) 3155 if (strcmp(p, shell) == 0 || strcmp(p, WILDCARD_SHELL) == 0) 3156 break; 3157 endusershell(); 3158 return p != NULL; 3159 # else /* HASGETUSERSHELL */ 3160 # if USEGETCONFATTR 3161 auto char *v; 3162 # endif /* USEGETCONFATTR */ 3163 register SM_FILE_T *shellf; 3164 char buf[MAXLINE]; 3165 3166 if (shell == NULL || shell[0] == '\0' || wordinclass(user, 't') || 3167 ConfigLevel <= 1) 3168 return true; 3169 3170 # if USEGETCONFATTR 3171 /* 3172 ** Naturally IBM has a "better" idea..... 3173 ** 3174 ** What a crock. This interface isn't documented, it is 3175 ** considered part of the security library (-ls), and it 3176 ** only works if you are running as root (since the list 3177 ** of valid shells is obviously a source of great concern). 3178 ** I recommend that you do NOT define USEGETCONFATTR, 3179 ** especially since you are going to have to set up an 3180 ** /etc/shells anyhow to handle the cases where getconfattr 3181 ** fails. 3182 */ 3183 3184 if (getconfattr(SC_SYS_LOGIN, SC_SHELLS, &v, SEC_LIST) == 0 && v != NULL) 3185 { 3186 while (*v != '\0') 3187 { 3188 if (strcmp(v, shell) == 0 || strcmp(v, WILDCARD_SHELL) == 0) 3189 return true; 3190 v += strlen(v) + 1; 3191 } 3192 return false; 3193 } 3194 # endif /* USEGETCONFATTR */ 3195 3196 shellf = sm_io_open(SmFtStdio, SM_TIME_DEFAULT, _PATH_SHELLS, 3197 SM_IO_RDONLY, NULL); 3198 if (shellf == NULL) 3199 { 3200 /* no /etc/shells; see if it is one of the std shells */ 3201 char **d; 3202 3203 if (errno != ENOENT && LogLevel > 3) 3204 sm_syslog(LOG_ERR, NOQID, 3205 "usershellok: cannot open %s: %s", 3206 _PATH_SHELLS, sm_errstring(errno)); 3207 3208 for (d = DefaultUserShells; *d != NULL; d++) 3209 { 3210 if (strcmp(shell, *d) == 0) 3211 return true; 3212 } 3213 return false; 3214 } 3215 3216 while (sm_io_fgets(shellf, SM_TIME_DEFAULT, buf, sizeof(buf)) != NULL) 3217 { 3218 register char *p, *q; 3219 3220 p = buf; 3221 while (*p != '\0' && *p != '#' && *p != '/') 3222 p++; 3223 if (*p == '#' || *p == '\0') 3224 continue; 3225 q = p; 3226 while (*p != '\0' && *p != '#' && !(isascii(*p) && isspace(*p))) 3227 p++; 3228 *p = '\0'; 3229 if (strcmp(shell, q) == 0 || strcmp(WILDCARD_SHELL, q) == 0) 3230 { 3231 (void) sm_io_close(shellf, SM_TIME_DEFAULT); 3232 return true; 3233 } 3234 } 3235 (void) sm_io_close(shellf, SM_TIME_DEFAULT); 3236 return false; 3237 # endif /* HASGETUSERSHELL */ 3238 } 3239 /* 3240 ** FREEDISKSPACE -- see how much free space is on the queue filesystem 3241 ** 3242 ** Only implemented if you have statfs. 3243 ** 3244 ** Parameters: 3245 ** dir -- the directory in question. 3246 ** bsize -- a variable into which the filesystem 3247 ** block size is stored. 3248 ** 3249 ** Returns: 3250 ** The number of blocks free on the queue filesystem. 3251 ** -1 if the statfs call fails. 3252 ** 3253 ** Side effects: 3254 ** Puts the filesystem block size into bsize. 3255 */ 3256 3257 /* statfs types */ 3258 # define SFS_NONE 0 /* no statfs implementation */ 3259 # define SFS_USTAT 1 /* use ustat */ 3260 # define SFS_4ARGS 2 /* use four-argument statfs call */ 3261 # define SFS_VFS 3 /* use <sys/vfs.h> implementation */ 3262 # define SFS_MOUNT 4 /* use <sys/mount.h> implementation */ 3263 # define SFS_STATFS 5 /* use <sys/statfs.h> implementation */ 3264 # define SFS_STATVFS 6 /* use <sys/statvfs.h> implementation */ 3265 3266 # ifndef SFS_TYPE 3267 # define SFS_TYPE SFS_NONE 3268 # endif /* ! SFS_TYPE */ 3269 3270 # if SFS_TYPE == SFS_USTAT 3271 # include <ustat.h> 3272 # endif /* SFS_TYPE == SFS_USTAT */ 3273 # if SFS_TYPE == SFS_4ARGS || SFS_TYPE == SFS_STATFS 3274 # include <sys/statfs.h> 3275 # endif /* SFS_TYPE == SFS_4ARGS || SFS_TYPE == SFS_STATFS */ 3276 # if SFS_TYPE == SFS_VFS 3277 # include <sys/vfs.h> 3278 # endif /* SFS_TYPE == SFS_VFS */ 3279 # if SFS_TYPE == SFS_MOUNT 3280 # include <sys/mount.h> 3281 # endif /* SFS_TYPE == SFS_MOUNT */ 3282 # if SFS_TYPE == SFS_STATVFS 3283 # include <sys/statvfs.h> 3284 # endif /* SFS_TYPE == SFS_STATVFS */ 3285 3286 long 3287 freediskspace(dir, bsize) 3288 const char *dir; 3289 long *bsize; 3290 { 3291 # if SFS_TYPE == SFS_NONE 3292 if (bsize != NULL) 3293 *bsize = 4096L; 3294 3295 /* assume free space is plentiful */ 3296 return (long) LONG_MAX; 3297 # else /* SFS_TYPE == SFS_NONE */ 3298 # if SFS_TYPE == SFS_USTAT 3299 struct ustat fs; 3300 struct stat statbuf; 3301 # define FSBLOCKSIZE DEV_BSIZE 3302 # define SFS_BAVAIL f_tfree 3303 # else /* SFS_TYPE == SFS_USTAT */ 3304 # if defined(ultrix) 3305 struct fs_data fs; 3306 # define SFS_BAVAIL fd_bfreen 3307 # define FSBLOCKSIZE 1024L 3308 # else /* defined(ultrix) */ 3309 # if SFS_TYPE == SFS_STATVFS 3310 struct statvfs fs; 3311 # define FSBLOCKSIZE fs.f_frsize 3312 # else /* SFS_TYPE == SFS_STATVFS */ 3313 struct statfs fs; 3314 # define FSBLOCKSIZE fs.f_bsize 3315 # endif /* SFS_TYPE == SFS_STATVFS */ 3316 # endif /* defined(ultrix) */ 3317 # endif /* SFS_TYPE == SFS_USTAT */ 3318 # ifndef SFS_BAVAIL 3319 # define SFS_BAVAIL f_bavail 3320 # endif /* ! SFS_BAVAIL */ 3321 3322 # if SFS_TYPE == SFS_USTAT 3323 if (stat(dir, &statbuf) == 0 && ustat(statbuf.st_dev, &fs) == 0) 3324 # else /* SFS_TYPE == SFS_USTAT */ 3325 # if SFS_TYPE == SFS_4ARGS 3326 if (statfs(dir, &fs, sizeof(fs), 0) == 0) 3327 # else /* SFS_TYPE == SFS_4ARGS */ 3328 # if SFS_TYPE == SFS_STATVFS 3329 if (statvfs(dir, &fs) == 0) 3330 # else /* SFS_TYPE == SFS_STATVFS */ 3331 # if defined(ultrix) 3332 if (statfs(dir, &fs) > 0) 3333 # else /* defined(ultrix) */ 3334 if (statfs(dir, &fs) == 0) 3335 # endif /* defined(ultrix) */ 3336 # endif /* SFS_TYPE == SFS_STATVFS */ 3337 # endif /* SFS_TYPE == SFS_4ARGS */ 3338 # endif /* SFS_TYPE == SFS_USTAT */ 3339 { 3340 if (bsize != NULL) 3341 *bsize = FSBLOCKSIZE; 3342 if (fs.SFS_BAVAIL <= 0) 3343 return 0; 3344 else if (fs.SFS_BAVAIL > LONG_MAX) 3345 return (long) LONG_MAX; 3346 else 3347 return (long) fs.SFS_BAVAIL; 3348 } 3349 return -1; 3350 # endif /* SFS_TYPE == SFS_NONE */ 3351 } 3352 /* 3353 ** ENOUGHDISKSPACE -- is there enough free space on the queue file systems? 3354 ** 3355 ** Parameters: 3356 ** msize -- the size to check against. If zero, we don't yet 3357 ** know how big the message will be, so just check for 3358 ** a "reasonable" amount. 3359 ** e -- envelope, or NULL -- controls logging 3360 ** 3361 ** Returns: 3362 ** true if in every queue group there is at least one 3363 ** queue directory whose file system contains enough free space. 3364 ** false otherwise. 3365 ** 3366 ** Side Effects: 3367 ** If there is not enough disk space and e != NULL 3368 ** then sm_syslog is called. 3369 */ 3370 3371 bool 3372 enoughdiskspace(msize, e) 3373 long msize; 3374 ENVELOPE *e; 3375 { 3376 int i; 3377 3378 if (MinBlocksFree <= 0 && msize <= 0) 3379 { 3380 if (tTd(4, 80)) 3381 sm_dprintf("enoughdiskspace: no threshold\n"); 3382 return true; 3383 } 3384 3385 filesys_update(); 3386 for (i = 0; i < NumQueue; ++i) 3387 { 3388 if (pickqdir(Queue[i], msize, e) < 0) 3389 return false; 3390 } 3391 return true; 3392 } 3393 /* 3394 ** TRANSIENTERROR -- tell if an error code indicates a transient failure 3395 ** 3396 ** This looks at an errno value and tells if this is likely to 3397 ** go away if retried later. 3398 ** 3399 ** Parameters: 3400 ** err -- the errno code to classify. 3401 ** 3402 ** Returns: 3403 ** true if this is probably transient. 3404 ** false otherwise. 3405 */ 3406 3407 bool 3408 transienterror(err) 3409 int err; 3410 { 3411 switch (err) 3412 { 3413 case EIO: /* I/O error */ 3414 case ENXIO: /* Device not configured */ 3415 case EAGAIN: /* Resource temporarily unavailable */ 3416 case ENOMEM: /* Cannot allocate memory */ 3417 case ENODEV: /* Operation not supported by device */ 3418 case ENFILE: /* Too many open files in system */ 3419 case EMFILE: /* Too many open files */ 3420 case ENOSPC: /* No space left on device */ 3421 case ETIMEDOUT: /* Connection timed out */ 3422 #ifdef ESTALE 3423 case ESTALE: /* Stale NFS file handle */ 3424 #endif /* ESTALE */ 3425 #ifdef ENETDOWN 3426 case ENETDOWN: /* Network is down */ 3427 #endif /* ENETDOWN */ 3428 #ifdef ENETUNREACH 3429 case ENETUNREACH: /* Network is unreachable */ 3430 #endif /* ENETUNREACH */ 3431 #ifdef ENETRESET 3432 case ENETRESET: /* Network dropped connection on reset */ 3433 #endif /* ENETRESET */ 3434 #ifdef ECONNABORTED 3435 case ECONNABORTED: /* Software caused connection abort */ 3436 #endif /* ECONNABORTED */ 3437 #ifdef ECONNRESET 3438 case ECONNRESET: /* Connection reset by peer */ 3439 #endif /* ECONNRESET */ 3440 #ifdef ENOBUFS 3441 case ENOBUFS: /* No buffer space available */ 3442 #endif /* ENOBUFS */ 3443 #ifdef ESHUTDOWN 3444 case ESHUTDOWN: /* Can't send after socket shutdown */ 3445 #endif /* ESHUTDOWN */ 3446 #ifdef ECONNREFUSED 3447 case ECONNREFUSED: /* Connection refused */ 3448 #endif /* ECONNREFUSED */ 3449 #ifdef EHOSTDOWN 3450 case EHOSTDOWN: /* Host is down */ 3451 #endif /* EHOSTDOWN */ 3452 #ifdef EHOSTUNREACH 3453 case EHOSTUNREACH: /* No route to host */ 3454 #endif /* EHOSTUNREACH */ 3455 #ifdef EDQUOT 3456 case EDQUOT: /* Disc quota exceeded */ 3457 #endif /* EDQUOT */ 3458 #ifdef EPROCLIM 3459 case EPROCLIM: /* Too many processes */ 3460 #endif /* EPROCLIM */ 3461 #ifdef EUSERS 3462 case EUSERS: /* Too many users */ 3463 #endif /* EUSERS */ 3464 #ifdef EDEADLK 3465 case EDEADLK: /* Resource deadlock avoided */ 3466 #endif /* EDEADLK */ 3467 #ifdef EISCONN 3468 case EISCONN: /* Socket already connected */ 3469 #endif /* EISCONN */ 3470 #ifdef EINPROGRESS 3471 case EINPROGRESS: /* Operation now in progress */ 3472 #endif /* EINPROGRESS */ 3473 #ifdef EALREADY 3474 case EALREADY: /* Operation already in progress */ 3475 #endif /* EALREADY */ 3476 #ifdef EADDRINUSE 3477 case EADDRINUSE: /* Address already in use */ 3478 #endif /* EADDRINUSE */ 3479 #ifdef EADDRNOTAVAIL 3480 case EADDRNOTAVAIL: /* Can't assign requested address */ 3481 #endif /* EADDRNOTAVAIL */ 3482 #ifdef ETXTBSY 3483 case ETXTBSY: /* (Apollo) file locked */ 3484 #endif /* ETXTBSY */ 3485 #if defined(ENOSR) && (!defined(ENOBUFS) || (ENOBUFS != ENOSR)) 3486 case ENOSR: /* Out of streams resources */ 3487 #endif /* defined(ENOSR) && (!defined(ENOBUFS) || (ENOBUFS != ENOSR)) */ 3488 #ifdef ENOLCK 3489 case ENOLCK: /* No locks available */ 3490 #endif /* ENOLCK */ 3491 case E_SM_OPENTIMEOUT: /* PSEUDO: open timed out */ 3492 return true; 3493 } 3494 3495 /* nope, must be permanent */ 3496 return false; 3497 } 3498 /* 3499 ** LOCKFILE -- lock a file using flock or (shudder) fcntl locking 3500 ** 3501 ** Parameters: 3502 ** fd -- the file descriptor of the file. 3503 ** filename -- the file name (for error messages). 3504 ** ext -- the filename extension. 3505 ** type -- type of the lock. Bits can be: 3506 ** LOCK_EX -- exclusive lock. 3507 ** LOCK_NB -- non-blocking. 3508 ** LOCK_UN -- unlock. 3509 ** 3510 ** Returns: 3511 ** true if the lock was acquired. 3512 ** false otherwise. 3513 */ 3514 3515 bool 3516 lockfile(fd, filename, ext, type) 3517 int fd; 3518 char *filename; 3519 char *ext; 3520 int type; 3521 { 3522 int i; 3523 int save_errno; 3524 # if !HASFLOCK 3525 int action; 3526 struct flock lfd; 3527 3528 if (ext == NULL) 3529 ext = ""; 3530 3531 memset(&lfd, '\0', sizeof(lfd)); 3532 if (bitset(LOCK_UN, type)) 3533 lfd.l_type = F_UNLCK; 3534 else if (bitset(LOCK_EX, type)) 3535 lfd.l_type = F_WRLCK; 3536 else 3537 lfd.l_type = F_RDLCK; 3538 3539 if (bitset(LOCK_NB, type)) 3540 action = F_SETLK; 3541 else 3542 action = F_SETLKW; 3543 3544 if (tTd(55, 60)) 3545 sm_dprintf("lockfile(%s%s, action=%d, type=%d): ", 3546 filename, ext, action, lfd.l_type); 3547 3548 while ((i = fcntl(fd, action, &lfd)) < 0 && errno == EINTR) 3549 continue; 3550 if (i >= 0) 3551 { 3552 if (tTd(55, 60)) 3553 sm_dprintf("SUCCESS\n"); 3554 return true; 3555 } 3556 save_errno = errno; 3557 3558 if (tTd(55, 60)) 3559 sm_dprintf("(%s) ", sm_errstring(save_errno)); 3560 3561 /* 3562 ** On SunOS, if you are testing using -oQ/tmp/mqueue or 3563 ** -oA/tmp/aliases or anything like that, and /tmp is mounted 3564 ** as type "tmp" (that is, served from swap space), the 3565 ** previous fcntl will fail with "Invalid argument" errors. 3566 ** Since this is fairly common during testing, we will assume 3567 ** that this indicates that the lock is successfully grabbed. 3568 */ 3569 3570 if (save_errno == EINVAL) 3571 { 3572 if (tTd(55, 60)) 3573 sm_dprintf("SUCCESS\n"); 3574 return true; 3575 } 3576 3577 if (!bitset(LOCK_NB, type) || 3578 (save_errno != EACCES && save_errno != EAGAIN)) 3579 { 3580 int omode = fcntl(fd, F_GETFL, 0); 3581 uid_t euid = geteuid(); 3582 3583 errno = save_errno; 3584 syserr("cannot lockf(%s%s, fd=%d, type=%o, omode=%o, euid=%d)", 3585 filename, ext, fd, type, omode, euid); 3586 dumpfd(fd, true, true); 3587 } 3588 # else /* !HASFLOCK */ 3589 if (ext == NULL) 3590 ext = ""; 3591 3592 if (tTd(55, 60)) 3593 sm_dprintf("lockfile(%s%s, type=%o): ", filename, ext, type); 3594 3595 while ((i = flock(fd, type)) < 0 && errno == EINTR) 3596 continue; 3597 if (i >= 0) 3598 { 3599 if (tTd(55, 60)) 3600 sm_dprintf("SUCCESS\n"); 3601 return true; 3602 } 3603 save_errno = errno; 3604 3605 if (tTd(55, 60)) 3606 sm_dprintf("(%s) ", sm_errstring(save_errno)); 3607 3608 if (!bitset(LOCK_NB, type) || save_errno != EWOULDBLOCK) 3609 { 3610 int omode = fcntl(fd, F_GETFL, 0); 3611 uid_t euid = geteuid(); 3612 3613 errno = save_errno; 3614 syserr("cannot flock(%s%s, fd=%d, type=%o, omode=%o, euid=%d)", 3615 filename, ext, fd, type, omode, euid); 3616 dumpfd(fd, true, true); 3617 } 3618 # endif /* !HASFLOCK */ 3619 if (tTd(55, 60)) 3620 sm_dprintf("FAIL\n"); 3621 errno = save_errno; 3622 return false; 3623 } 3624 /* 3625 ** CHOWNSAFE -- tell if chown is "safe" (executable only by root) 3626 ** 3627 ** Unfortunately, given that we can't predict other systems on which 3628 ** a remote mounted (NFS) filesystem will be mounted, the answer is 3629 ** almost always that this is unsafe. 3630 ** 3631 ** Note also that many operating systems have non-compliant 3632 ** implementations of the _POSIX_CHOWN_RESTRICTED variable and the 3633 ** fpathconf() routine. According to IEEE 1003.1-1990, if 3634 ** _POSIX_CHOWN_RESTRICTED is defined and not equal to -1, then 3635 ** no non-root process can give away the file. However, vendors 3636 ** don't take NFS into account, so a comfortable value of 3637 ** _POSIX_CHOWN_RESTRICTED tells us nothing. 3638 ** 3639 ** Also, some systems (e.g., IRIX 6.2) return 1 from fpathconf() 3640 ** even on files where chown is not restricted. Many systems get 3641 ** this wrong on NFS-based filesystems (that is, they say that chown 3642 ** is restricted [safe] on NFS filesystems where it may not be, since 3643 ** other systems can access the same filesystem and do file giveaway; 3644 ** only the NFS server knows for sure!) Hence, it is important to 3645 ** get the value of SAFENFSPATHCONF correct -- it should be defined 3646 ** _only_ after testing (see test/t_pathconf.c) a system on an unsafe 3647 ** NFS-based filesystem to ensure that you can get meaningful results. 3648 ** If in doubt, assume unsafe! 3649 ** 3650 ** You may also need to tweak IS_SAFE_CHOWN -- it should be a 3651 ** condition indicating whether the return from pathconf indicates 3652 ** that chown is safe (typically either > 0 or >= 0 -- there isn't 3653 ** even any agreement about whether a zero return means that a file 3654 ** is or is not safe). It defaults to "> 0". 3655 ** 3656 ** If the parent directory is safe (writable only by owner back 3657 ** to the root) then we can relax slightly and trust fpathconf 3658 ** in more circumstances. This is really a crock -- if this is an 3659 ** NFS mounted filesystem then we really know nothing about the 3660 ** underlying implementation. However, most systems pessimize and 3661 ** return an error (EINVAL or EOPNOTSUPP) on NFS filesystems, which 3662 ** we interpret as unsafe, as we should. Thus, this heuristic gets 3663 ** us into a possible problem only on systems that have a broken 3664 ** pathconf implementation and which are also poorly configured 3665 ** (have :include: files in group- or world-writable directories). 3666 ** 3667 ** Parameters: 3668 ** fd -- the file descriptor to check. 3669 ** safedir -- set if the parent directory is safe. 3670 ** 3671 ** Returns: 3672 ** true -- if the chown(2) operation is "safe" -- that is, 3673 ** only root can chown the file to an arbitrary user. 3674 ** false -- if an arbitrary user can give away a file. 3675 */ 3676 3677 #ifndef IS_SAFE_CHOWN 3678 # define IS_SAFE_CHOWN > 0 3679 #endif /* ! IS_SAFE_CHOWN */ 3680 3681 bool 3682 chownsafe(fd, safedir) 3683 int fd; 3684 bool safedir; 3685 { 3686 # if (!defined(_POSIX_CHOWN_RESTRICTED) || _POSIX_CHOWN_RESTRICTED != -1) && \ 3687 (defined(_PC_CHOWN_RESTRICTED) || defined(_GNU_TYPES_H)) 3688 int rval; 3689 3690 /* give the system administrator a chance to override */ 3691 if (bitnset(DBS_ASSUMESAFECHOWN, DontBlameSendmail)) 3692 return true; 3693 3694 /* 3695 ** Some systems (e.g., SunOS) seem to have the call and the 3696 ** #define _PC_CHOWN_RESTRICTED, but don't actually implement 3697 ** the call. This heuristic checks for that. 3698 */ 3699 3700 errno = 0; 3701 rval = fpathconf(fd, _PC_CHOWN_RESTRICTED); 3702 # if SAFENFSPATHCONF 3703 return errno == 0 && rval IS_SAFE_CHOWN; 3704 # else /* SAFENFSPATHCONF */ 3705 return safedir && errno == 0 && rval IS_SAFE_CHOWN; 3706 # endif /* SAFENFSPATHCONF */ 3707 # else /* (!defined(_POSIX_CHOWN_RESTRICTED) || _POSIX_CHOWN_RESTRICTED != -1) && ... */ 3708 return bitnset(DBS_ASSUMESAFECHOWN, DontBlameSendmail); 3709 # endif /* (!defined(_POSIX_CHOWN_RESTRICTED) || _POSIX_CHOWN_RESTRICTED != -1) && ... */ 3710 } 3711 /* 3712 ** RESETLIMITS -- reset system controlled resource limits 3713 ** 3714 ** This is to avoid denial-of-service attacks 3715 ** 3716 ** Parameters: 3717 ** none 3718 ** 3719 ** Returns: 3720 ** none 3721 */ 3722 3723 #if HASSETRLIMIT 3724 # ifdef RLIMIT_NEEDS_SYS_TIME_H 3725 # include <sm/time.h> 3726 # endif /* RLIMIT_NEEDS_SYS_TIME_H */ 3727 # include <sys/resource.h> 3728 #endif /* HASSETRLIMIT */ 3729 3730 void 3731 resetlimits() 3732 { 3733 #if HASSETRLIMIT 3734 struct rlimit lim; 3735 3736 lim.rlim_cur = lim.rlim_max = RLIM_INFINITY; 3737 (void) setrlimit(RLIMIT_CPU, &lim); 3738 (void) setrlimit(RLIMIT_FSIZE, &lim); 3739 # ifdef RLIMIT_NOFILE 3740 lim.rlim_cur = lim.rlim_max = FD_SETSIZE; 3741 (void) setrlimit(RLIMIT_NOFILE, &lim); 3742 # endif /* RLIMIT_NOFILE */ 3743 #else /* HASSETRLIMIT */ 3744 # if HASULIMIT 3745 (void) ulimit(2, 0x3fffff); 3746 (void) ulimit(4, FD_SETSIZE); 3747 # endif /* HASULIMIT */ 3748 #endif /* HASSETRLIMIT */ 3749 errno = 0; 3750 } 3751 /* 3752 ** SETVENDOR -- process vendor code from V configuration line 3753 ** 3754 ** Parameters: 3755 ** vendor -- string representation of vendor. 3756 ** 3757 ** Returns: 3758 ** true -- if ok. 3759 ** false -- if vendor code could not be processed. 3760 ** 3761 ** Side Effects: 3762 ** It is reasonable to set mode flags here to tweak 3763 ** processing in other parts of the code if necessary. 3764 ** For example, if you are a vendor that uses $%y to 3765 ** indicate YP lookups, you could enable that here. 3766 */ 3767 3768 bool 3769 setvendor(vendor) 3770 char *vendor; 3771 { 3772 if (sm_strcasecmp(vendor, "Berkeley") == 0) 3773 { 3774 VendorCode = VENDOR_BERKELEY; 3775 return true; 3776 } 3777 3778 /* add vendor extensions here */ 3779 3780 #ifdef SUN_EXTENSIONS 3781 if (sm_strcasecmp(vendor, "Sun") == 0) 3782 { 3783 VendorCode = VENDOR_SUN; 3784 return true; 3785 } 3786 #endif /* SUN_EXTENSIONS */ 3787 #ifdef DEC 3788 if (sm_strcasecmp(vendor, "Digital") == 0) 3789 { 3790 VendorCode = VENDOR_DEC; 3791 return true; 3792 } 3793 #endif /* DEC */ 3794 3795 #if defined(VENDOR_NAME) && defined(VENDOR_CODE) 3796 if (sm_strcasecmp(vendor, VENDOR_NAME) == 0) 3797 { 3798 VendorCode = VENDOR_CODE; 3799 return true; 3800 } 3801 #endif /* defined(VENDOR_NAME) && defined(VENDOR_CODE) */ 3802 3803 return false; 3804 } 3805 /* 3806 ** GETVENDOR -- return vendor name based on vendor code 3807 ** 3808 ** Parameters: 3809 ** vendorcode -- numeric representation of vendor. 3810 ** 3811 ** Returns: 3812 ** string containing vendor name. 3813 */ 3814 3815 char * 3816 getvendor(vendorcode) 3817 int vendorcode; 3818 { 3819 #if defined(VENDOR_NAME) && defined(VENDOR_CODE) 3820 /* 3821 ** Can't have the same switch case twice so need to 3822 ** handle VENDOR_CODE outside of switch. It might 3823 ** match one of the existing VENDOR_* codes. 3824 */ 3825 3826 if (vendorcode == VENDOR_CODE) 3827 return VENDOR_NAME; 3828 #endif /* defined(VENDOR_NAME) && defined(VENDOR_CODE) */ 3829 3830 switch (vendorcode) 3831 { 3832 case VENDOR_BERKELEY: 3833 return "Berkeley"; 3834 3835 case VENDOR_SUN: 3836 return "Sun"; 3837 3838 case VENDOR_HP: 3839 return "HP"; 3840 3841 case VENDOR_IBM: 3842 return "IBM"; 3843 3844 case VENDOR_SENDMAIL: 3845 return "Sendmail"; 3846 3847 default: 3848 return "Unknown"; 3849 } 3850 } 3851 /* 3852 ** VENDOR_PRE_DEFAULTS, VENDOR_POST_DEFAULTS -- set vendor-specific defaults 3853 ** 3854 ** Vendor_pre_defaults is called before reading the configuration 3855 ** file; vendor_post_defaults is called immediately after. 3856 ** 3857 ** Parameters: 3858 ** e -- the global environment to initialize. 3859 ** 3860 ** Returns: 3861 ** none. 3862 */ 3863 3864 #if SHARE_V1 3865 int DefShareUid; /* default share uid to run as -- unused??? */ 3866 #endif /* SHARE_V1 */ 3867 3868 void 3869 vendor_pre_defaults(e) 3870 ENVELOPE *e; 3871 { 3872 #if SHARE_V1 3873 /* OTHERUID is defined in shares.h, do not be alarmed */ 3874 DefShareUid = OTHERUID; 3875 #endif /* SHARE_V1 */ 3876 #if defined(SUN_EXTENSIONS) && defined(SUN_DEFAULT_VALUES) 3877 sun_pre_defaults(e); 3878 #endif /* defined(SUN_EXTENSIONS) && defined(SUN_DEFAULT_VALUES) */ 3879 #ifdef apollo 3880 /* 3881 ** stupid domain/os can't even open 3882 ** /etc/mail/sendmail.cf without this 3883 */ 3884 3885 sm_setuserenv("ISP", NULL); 3886 sm_setuserenv("SYSTYPE", NULL); 3887 #endif /* apollo */ 3888 } 3889 3890 3891 void 3892 vendor_post_defaults(e) 3893 ENVELOPE *e; 3894 { 3895 #ifdef __QNX__ 3896 /* Makes sure the SOCK environment variable remains */ 3897 sm_setuserenv("SOCK", NULL); 3898 #endif /* __QNX__ */ 3899 #if defined(SUN_EXTENSIONS) && defined(SUN_DEFAULT_VALUES) 3900 sun_post_defaults(e); 3901 #endif /* defined(SUN_EXTENSIONS) && defined(SUN_DEFAULT_VALUES) */ 3902 } 3903 /* 3904 ** VENDOR_DAEMON_SETUP -- special vendor setup needed for daemon mode 3905 */ 3906 3907 void 3908 vendor_daemon_setup(e) 3909 ENVELOPE *e; 3910 { 3911 #if HASSETLOGIN 3912 (void) setlogin(RunAsUserName); 3913 #endif /* HASSETLOGIN */ 3914 #if SECUREWARE 3915 if (getluid() != -1) 3916 { 3917 usrerr("Daemon cannot have LUID"); 3918 finis(false, true, EX_USAGE); 3919 } 3920 #endif /* SECUREWARE */ 3921 } 3922 /* 3923 ** VENDOR_SET_UID -- do setup for setting a user id 3924 ** 3925 ** This is called when we are still root. 3926 ** 3927 ** Parameters: 3928 ** uid -- the uid we are about to become. 3929 ** 3930 ** Returns: 3931 ** none. 3932 */ 3933 3934 void 3935 vendor_set_uid(uid) 3936 UID_T uid; 3937 { 3938 /* 3939 ** We need to setup the share groups (lnodes) 3940 ** and add auditing information (luid's) 3941 ** before we loose our ``root''ness. 3942 */ 3943 #if SHARE_V1 3944 if (setupshares(uid, syserr) != 0) 3945 syserr("Unable to set up shares"); 3946 #endif /* SHARE_V1 */ 3947 #if SECUREWARE 3948 (void) setup_secure(uid); 3949 #endif /* SECUREWARE */ 3950 } 3951 /* 3952 ** VALIDATE_CONNECTION -- check connection for rationality 3953 ** 3954 ** If the connection is rejected, this routine should log an 3955 ** appropriate message -- but should never issue any SMTP protocol. 3956 ** 3957 ** Parameters: 3958 ** sap -- a pointer to a SOCKADDR naming the peer. 3959 ** hostname -- the name corresponding to sap. 3960 ** e -- the current envelope. 3961 ** 3962 ** Returns: 3963 ** error message from rejection. 3964 ** NULL if not rejected. 3965 */ 3966 3967 #if TCPWRAPPERS 3968 # include <tcpd.h> 3969 3970 /* tcpwrappers does no logging, but you still have to declare these -- ugh */ 3971 int allow_severity = LOG_INFO; 3972 int deny_severity = LOG_NOTICE; 3973 #endif /* TCPWRAPPERS */ 3974 3975 char * 3976 validate_connection(sap, hostname, e) 3977 SOCKADDR *sap; 3978 char *hostname; 3979 ENVELOPE *e; 3980 { 3981 #if TCPWRAPPERS 3982 char *host; 3983 char *addr; 3984 extern int hosts_ctl(); 3985 #endif /* TCPWRAPPERS */ 3986 3987 if (tTd(48, 3)) 3988 sm_dprintf("validate_connection(%s, %s)\n", 3989 hostname, anynet_ntoa(sap)); 3990 3991 connection_rate_check(sap, e); 3992 if (rscheck("check_relay", hostname, anynet_ntoa(sap), 3993 e, RSF_RMCOMM|RSF_COUNT, 3, NULL, NOQID, NULL) != EX_OK) 3994 { 3995 static char reject[BUFSIZ*2]; 3996 extern char MsgBuf[]; 3997 3998 if (tTd(48, 4)) 3999 sm_dprintf(" ... validate_connection: BAD (rscheck)\n"); 4000 4001 if (strlen(MsgBuf) >= 3) 4002 (void) sm_strlcpy(reject, MsgBuf, sizeof(reject)); 4003 else 4004 (void) sm_strlcpy(reject, "Access denied", sizeof(reject)); 4005 4006 return reject; 4007 } 4008 4009 #if TCPWRAPPERS 4010 if (hostname[0] == '[' && hostname[strlen(hostname) - 1] == ']') 4011 host = "unknown"; 4012 else 4013 host = hostname; 4014 addr = anynet_ntoa(sap); 4015 4016 # if NETINET6 4017 /* TCP/Wrappers don't want the IPv6: protocol label */ 4018 if (addr != NULL && sm_strncasecmp(addr, "IPv6:", 5) == 0) 4019 addr += 5; 4020 # endif /* NETINET6 */ 4021 4022 if (!hosts_ctl("sendmail", host, addr, STRING_UNKNOWN)) 4023 { 4024 if (tTd(48, 4)) 4025 sm_dprintf(" ... validate_connection: BAD (tcpwrappers)\n"); 4026 if (LogLevel > 3) 4027 sm_syslog(LOG_NOTICE, e->e_id, 4028 "tcpwrappers (%s, %s) rejection", 4029 host, addr); 4030 return "Access denied"; 4031 } 4032 #endif /* TCPWRAPPERS */ 4033 if (tTd(48, 4)) 4034 sm_dprintf(" ... validate_connection: OK\n"); 4035 return NULL; 4036 } 4037 4038 /* 4039 ** STRTOL -- convert string to long integer 4040 ** 4041 ** For systems that don't have it in the C library. 4042 ** 4043 ** This is taken verbatim from the 4.4-Lite C library. 4044 */ 4045 4046 #if NEEDSTRTOL 4047 4048 # if defined(LIBC_SCCS) && !defined(lint) 4049 static char sccsid[] = "@(#)strtol.c 8.1 (Berkeley) 6/4/93"; 4050 # endif /* defined(LIBC_SCCS) && !defined(lint) */ 4051 4052 /* 4053 ** Convert a string to a long integer. 4054 ** 4055 ** Ignores `locale' stuff. Assumes that the upper and lower case 4056 ** alphabets and digits are each contiguous. 4057 */ 4058 4059 long 4060 strtol(nptr, endptr, base) 4061 const char *nptr; 4062 char **endptr; 4063 register int base; 4064 { 4065 register const char *s = nptr; 4066 register unsigned long acc; 4067 register int c; 4068 register unsigned long cutoff; 4069 register int neg = 0, any, cutlim; 4070 4071 /* 4072 ** Skip white space and pick up leading +/- sign if any. 4073 ** If base is 0, allow 0x for hex and 0 for octal, else 4074 ** assume decimal; if base is already 16, allow 0x. 4075 */ 4076 do { 4077 c = *s++; 4078 } while (isspace(c)); 4079 if (c == '-') { 4080 neg = 1; 4081 c = *s++; 4082 } else if (c == '+') 4083 c = *s++; 4084 if ((base == 0 || base == 16) && 4085 c == '0' && (*s == 'x' || *s == 'X')) { 4086 c = s[1]; 4087 s += 2; 4088 base = 16; 4089 } 4090 if (base == 0) 4091 base = c == '0' ? 8 : 10; 4092 4093 /* 4094 ** Compute the cutoff value between legal numbers and illegal 4095 ** numbers. That is the largest legal value, divided by the 4096 ** base. An input number that is greater than this value, if 4097 ** followed by a legal input character, is too big. One that 4098 ** is equal to this value may be valid or not; the limit 4099 ** between valid and invalid numbers is then based on the last 4100 ** digit. For instance, if the range for longs is 4101 ** [-2147483648..2147483647] and the input base is 10, 4102 ** cutoff will be set to 214748364 and cutlim to either 4103 ** 7 (neg==0) or 8 (neg==1), meaning that if we have accumulated 4104 ** a value > 214748364, or equal but the next digit is > 7 (or 8), 4105 ** the number is too big, and we will return a range error. 4106 ** 4107 ** Set any if any `digits' consumed; make it negative to indicate 4108 ** overflow. 4109 */ 4110 cutoff = neg ? -(unsigned long) LONG_MIN : LONG_MAX; 4111 cutlim = cutoff % (unsigned long) base; 4112 cutoff /= (unsigned long) base; 4113 for (acc = 0, any = 0;; c = *s++) { 4114 if (isdigit(c)) 4115 c -= '0'; 4116 else if (isalpha(c)) 4117 c -= isupper(c) ? 'A' - 10 : 'a' - 10; 4118 else 4119 break; 4120 if (c >= base) 4121 break; 4122 if (any < 0 || acc > cutoff || acc == cutoff && c > cutlim) 4123 any = -1; 4124 else { 4125 any = 1; 4126 acc *= base; 4127 acc += c; 4128 } 4129 } 4130 if (any < 0) { 4131 acc = neg ? LONG_MIN : LONG_MAX; 4132 errno = ERANGE; 4133 } else if (neg) 4134 acc = -acc; 4135 if (endptr != 0) 4136 *endptr = (char *)(any ? s - 1 : nptr); 4137 return acc; 4138 } 4139 4140 #endif /* NEEDSTRTOL */ 4141 /* 4142 ** STRSTR -- find first substring in string 4143 ** 4144 ** Parameters: 4145 ** big -- the big (full) string. 4146 ** little -- the little (sub) string. 4147 ** 4148 ** Returns: 4149 ** A pointer to the first instance of little in big. 4150 ** big if little is the null string. 4151 ** NULL if little is not contained in big. 4152 */ 4153 4154 #if NEEDSTRSTR 4155 4156 char * 4157 strstr(big, little) 4158 char *big; 4159 char *little; 4160 { 4161 register char *p = big; 4162 int l; 4163 4164 if (*little == '\0') 4165 return big; 4166 l = strlen(little); 4167 4168 while ((p = strchr(p, *little)) != NULL) 4169 { 4170 if (strncmp(p, little, l) == 0) 4171 return p; 4172 p++; 4173 } 4174 return NULL; 4175 } 4176 4177 #endif /* NEEDSTRSTR */ 4178 /* 4179 ** SM_GETHOSTBY{NAME,ADDR} -- compatibility routines for gethostbyXXX 4180 ** 4181 ** Some operating systems have wierd problems with the gethostbyXXX 4182 ** routines. For example, Solaris versions at least through 2.3 4183 ** don't properly deliver a canonical h_name field. This tries to 4184 ** work around these problems. 4185 ** 4186 ** Support IPv6 as well as IPv4. 4187 */ 4188 4189 #if NETINET6 && NEEDSGETIPNODE 4190 4191 # ifndef AI_DEFAULT 4192 # define AI_DEFAULT 0 /* dummy */ 4193 # endif /* ! AI_DEFAULT */ 4194 # ifndef AI_ADDRCONFIG 4195 # define AI_ADDRCONFIG 0 /* dummy */ 4196 # endif /* ! AI_ADDRCONFIG */ 4197 # ifndef AI_V4MAPPED 4198 # define AI_V4MAPPED 0 /* dummy */ 4199 # endif /* ! AI_V4MAPPED */ 4200 # ifndef AI_ALL 4201 # define AI_ALL 0 /* dummy */ 4202 # endif /* ! AI_ALL */ 4203 4204 static struct hostent * 4205 getipnodebyname(name, family, flags, err) 4206 char *name; 4207 int family; 4208 int flags; 4209 int *err; 4210 { 4211 bool resv6 = true; 4212 struct hostent *h; 4213 4214 if (family == AF_INET6) 4215 { 4216 /* From RFC2133, section 6.1 */ 4217 resv6 = bitset(RES_USE_INET6, _res.options); 4218 _res.options |= RES_USE_INET6; 4219 } 4220 SM_SET_H_ERRNO(0); 4221 h = gethostbyname(name); 4222 if (!resv6) 4223 _res.options &= ~RES_USE_INET6; 4224 *err = h_errno; 4225 return h; 4226 } 4227 4228 static struct hostent * 4229 getipnodebyaddr(addr, len, family, err) 4230 char *addr; 4231 int len; 4232 int family; 4233 int *err; 4234 { 4235 struct hostent *h; 4236 4237 SM_SET_H_ERRNO(0); 4238 h = gethostbyaddr(addr, len, family); 4239 *err = h_errno; 4240 return h; 4241 } 4242 4243 void 4244 freehostent(h) 4245 struct hostent *h; 4246 { 4247 /* 4248 ** Stub routine -- if they don't have getipnodeby*(), 4249 ** they probably don't have the free routine either. 4250 */ 4251 4252 return; 4253 } 4254 #endif /* NETINET6 && NEEDSGETIPNODE */ 4255 4256 struct hostent * 4257 sm_gethostbyname(name, family) 4258 char *name; 4259 int family; 4260 { 4261 int save_errno; 4262 struct hostent *h = NULL; 4263 #if (SOLARIS > 10000 && SOLARIS < 20400) || (defined(SOLARIS) && SOLARIS < 204) || (defined(sony_news) && defined(__svr4)) 4264 # if SOLARIS == 20300 || SOLARIS == 203 4265 static struct hostent hp; 4266 static char buf[1000]; 4267 extern struct hostent *_switch_gethostbyname_r(); 4268 4269 if (tTd(61, 10)) 4270 sm_dprintf("_switch_gethostbyname_r(%s)... ", name); 4271 h = _switch_gethostbyname_r(name, &hp, buf, sizeof(buf), &h_errno); 4272 save_errno = errno; 4273 # else /* SOLARIS == 20300 || SOLARIS == 203 */ 4274 extern struct hostent *__switch_gethostbyname(); 4275 4276 if (tTd(61, 10)) 4277 sm_dprintf("__switch_gethostbyname(%s)... ", name); 4278 h = __switch_gethostbyname(name); 4279 save_errno = errno; 4280 # endif /* SOLARIS == 20300 || SOLARIS == 203 */ 4281 #else /* (SOLARIS > 10000 && SOLARIS < 20400) || (defined(SOLARIS) && SOLARIS < 204) || (defined(sony_news) && defined(__svr4)) */ 4282 int nmaps; 4283 # if NETINET6 4284 int flags = AI_DEFAULT|AI_ALL; 4285 int err; 4286 # endif /* NETINET6 */ 4287 char *maptype[MAXMAPSTACK]; 4288 short mapreturn[MAXMAPACTIONS]; 4289 char hbuf[MAXNAME]; 4290 4291 if (tTd(61, 10)) 4292 sm_dprintf("sm_gethostbyname(%s, %d)... ", name, family); 4293 4294 # if NETINET6 4295 # if ADDRCONFIG_IS_BROKEN 4296 flags &= ~AI_ADDRCONFIG; 4297 # endif /* ADDRCONFIG_IS_BROKEN */ 4298 h = getipnodebyname(name, family, flags, &err); 4299 SM_SET_H_ERRNO(err); 4300 # else /* NETINET6 */ 4301 h = gethostbyname(name); 4302 # endif /* NETINET6 */ 4303 4304 save_errno = errno; 4305 if (h == NULL) 4306 { 4307 if (tTd(61, 10)) 4308 sm_dprintf("failure\n"); 4309 4310 nmaps = switch_map_find("hosts", maptype, mapreturn); 4311 while (--nmaps >= 0) 4312 { 4313 if (strcmp(maptype[nmaps], "nis") == 0 || 4314 strcmp(maptype[nmaps], "files") == 0) 4315 break; 4316 } 4317 4318 if (nmaps >= 0) 4319 { 4320 /* try short name */ 4321 if (strlen(name) > sizeof(hbuf) - 1) 4322 { 4323 errno = save_errno; 4324 return NULL; 4325 } 4326 (void) sm_strlcpy(hbuf, name, sizeof(hbuf)); 4327 (void) shorten_hostname(hbuf); 4328 4329 /* if it hasn't been shortened, there's no point */ 4330 if (strcmp(hbuf, name) != 0) 4331 { 4332 if (tTd(61, 10)) 4333 sm_dprintf("sm_gethostbyname(%s, %d)... ", 4334 hbuf, family); 4335 4336 # if NETINET6 4337 h = getipnodebyname(hbuf, family, flags, &err); 4338 SM_SET_H_ERRNO(err); 4339 save_errno = errno; 4340 # else /* NETINET6 */ 4341 h = gethostbyname(hbuf); 4342 save_errno = errno; 4343 # endif /* NETINET6 */ 4344 } 4345 } 4346 } 4347 #endif /* (SOLARIS > 10000 && SOLARIS < 20400) || (defined(SOLARIS) && SOLARIS < 204) || (defined(sony_news) && defined(__svr4)) */ 4348 if (tTd(61, 10)) 4349 { 4350 if (h == NULL) 4351 sm_dprintf("failure\n"); 4352 else 4353 { 4354 sm_dprintf("%s\n", h->h_name); 4355 if (tTd(61, 11)) 4356 { 4357 #if NETINET6 4358 struct in6_addr ia6; 4359 char buf6[INET6_ADDRSTRLEN]; 4360 #else /* NETINET6 */ 4361 struct in_addr ia; 4362 #endif /* NETINET6 */ 4363 size_t i; 4364 4365 if (h->h_aliases != NULL) 4366 for (i = 0; h->h_aliases[i] != NULL; 4367 i++) 4368 sm_dprintf("\talias: %s\n", 4369 h->h_aliases[i]); 4370 for (i = 0; h->h_addr_list[i] != NULL; i++) 4371 { 4372 char *addr; 4373 4374 #if NETINET6 4375 memmove(&ia6, h->h_addr_list[i], 4376 IN6ADDRSZ); 4377 addr = anynet_ntop(&ia6, 4378 buf6, sizeof(buf6)); 4379 #else /* NETINET6 */ 4380 memmove(&ia, h->h_addr_list[i], 4381 INADDRSZ); 4382 addr = (char *) inet_ntoa(ia); 4383 #endif /* NETINET6 */ 4384 if (addr != NULL) 4385 sm_dprintf("\taddr: %s\n", addr); 4386 } 4387 } 4388 } 4389 } 4390 errno = save_errno; 4391 return h; 4392 } 4393 4394 struct hostent * 4395 sm_gethostbyaddr(addr, len, type) 4396 char *addr; 4397 int len; 4398 int type; 4399 { 4400 struct hostent *hp; 4401 4402 #if NETINET6 4403 if (type == AF_INET6 && 4404 IN6_IS_ADDR_UNSPECIFIED((struct in6_addr *) addr)) 4405 { 4406 /* Avoid reverse lookup for IPv6 unspecified address */ 4407 SM_SET_H_ERRNO(HOST_NOT_FOUND); 4408 return NULL; 4409 } 4410 #endif /* NETINET6 */ 4411 4412 #if (SOLARIS > 10000 && SOLARIS < 20400) || (defined(SOLARIS) && SOLARIS < 204) 4413 # if SOLARIS == 20300 || SOLARIS == 203 4414 { 4415 static struct hostent he; 4416 static char buf[1000]; 4417 extern struct hostent *_switch_gethostbyaddr_r(); 4418 4419 hp = _switch_gethostbyaddr_r(addr, len, type, &he, 4420 buf, sizeof(buf), &h_errno); 4421 } 4422 # else /* SOLARIS == 20300 || SOLARIS == 203 */ 4423 { 4424 extern struct hostent *__switch_gethostbyaddr(); 4425 4426 hp = __switch_gethostbyaddr(addr, len, type); 4427 } 4428 # endif /* SOLARIS == 20300 || SOLARIS == 203 */ 4429 #else /* (SOLARIS > 10000 && SOLARIS < 20400) || (defined(SOLARIS) && SOLARIS < 204) */ 4430 # if NETINET6 4431 { 4432 int err; 4433 4434 hp = getipnodebyaddr(addr, len, type, &err); 4435 SM_SET_H_ERRNO(err); 4436 } 4437 # else /* NETINET6 */ 4438 hp = gethostbyaddr(addr, len, type); 4439 # endif /* NETINET6 */ 4440 #endif /* (SOLARIS > 10000 && SOLARIS < 20400) || (defined(SOLARIS) && SOLARIS < 204) */ 4441 return hp; 4442 } 4443 /* 4444 ** SM_GETPW{NAM,UID} -- wrapper for getpwnam and getpwuid 4445 */ 4446 4447 struct passwd * 4448 sm_getpwnam(user) 4449 char *user; 4450 { 4451 #ifdef _AIX4 4452 extern struct passwd *_getpwnam_shadow(const char *, const int); 4453 4454 return _getpwnam_shadow(user, 0); 4455 #else /* _AIX4 */ 4456 return getpwnam(user); 4457 #endif /* _AIX4 */ 4458 } 4459 4460 struct passwd * 4461 sm_getpwuid(uid) 4462 UID_T uid; 4463 { 4464 #if defined(_AIX4) && 0 4465 extern struct passwd *_getpwuid_shadow(const int, const int); 4466 4467 return _getpwuid_shadow(uid,0); 4468 #else /* defined(_AIX4) && 0 */ 4469 return getpwuid(uid); 4470 #endif /* defined(_AIX4) && 0 */ 4471 } 4472 /* 4473 ** SECUREWARE_SETUP_SECURE -- Convex SecureWare setup 4474 ** 4475 ** Set up the trusted computing environment for C2 level security 4476 ** under SecureWare. 4477 ** 4478 ** Parameters: 4479 ** uid -- uid of the user to initialize in the TCB 4480 ** 4481 ** Returns: 4482 ** none 4483 ** 4484 ** Side Effects: 4485 ** Initialized the user in the trusted computing base 4486 */ 4487 4488 #if SECUREWARE 4489 4490 # include <sys/security.h> 4491 # include <prot.h> 4492 4493 void 4494 secureware_setup_secure(uid) 4495 UID_T uid; 4496 { 4497 int rc; 4498 4499 if (getluid() != -1) 4500 return; 4501 4502 if ((rc = set_secure_info(uid)) != SSI_GOOD_RETURN) 4503 { 4504 switch (rc) 4505 { 4506 case SSI_NO_PRPW_ENTRY: 4507 syserr("No protected passwd entry, uid = %d", 4508 (int) uid); 4509 break; 4510 4511 case SSI_LOCKED: 4512 syserr("Account has been disabled, uid = %d", 4513 (int) uid); 4514 break; 4515 4516 case SSI_RETIRED: 4517 syserr("Account has been retired, uid = %d", 4518 (int) uid); 4519 break; 4520 4521 case SSI_BAD_SET_LUID: 4522 syserr("Could not set LUID, uid = %d", (int) uid); 4523 break; 4524 4525 case SSI_BAD_SET_PRIVS: 4526 syserr("Could not set kernel privs, uid = %d", 4527 (int) uid); 4528 4529 default: 4530 syserr("Unknown return code (%d) from set_secure_info(%d)", 4531 rc, (int) uid); 4532 break; 4533 } 4534 finis(false, true, EX_NOPERM); 4535 } 4536 } 4537 #endif /* SECUREWARE */ 4538 /* 4539 ** ADD_HOSTNAMES -- Add a hostname to class 'w' based on IP address 4540 ** 4541 ** Add hostnames to class 'w' based on the IP address read from 4542 ** the network interface. 4543 ** 4544 ** Parameters: 4545 ** sa -- a pointer to a SOCKADDR containing the address 4546 ** 4547 ** Returns: 4548 ** 0 if successful, -1 if host lookup fails. 4549 */ 4550 4551 static int 4552 add_hostnames(sa) 4553 SOCKADDR *sa; 4554 { 4555 struct hostent *hp; 4556 char **ha; 4557 char hnb[MAXHOSTNAMELEN]; 4558 4559 /* lookup name with IP address */ 4560 switch (sa->sa.sa_family) 4561 { 4562 #if NETINET 4563 case AF_INET: 4564 hp = sm_gethostbyaddr((char *) &sa->sin.sin_addr, 4565 sizeof(sa->sin.sin_addr), 4566 sa->sa.sa_family); 4567 break; 4568 #endif /* NETINET */ 4569 4570 #if NETINET6 4571 case AF_INET6: 4572 hp = sm_gethostbyaddr((char *) &sa->sin6.sin6_addr, 4573 sizeof(sa->sin6.sin6_addr), 4574 sa->sa.sa_family); 4575 break; 4576 #endif /* NETINET6 */ 4577 4578 default: 4579 /* Give warning about unsupported family */ 4580 if (LogLevel > 3) 4581 sm_syslog(LOG_WARNING, NOQID, 4582 "Unsupported address family %d: %.100s", 4583 sa->sa.sa_family, anynet_ntoa(sa)); 4584 return -1; 4585 } 4586 4587 if (hp == NULL) 4588 { 4589 int save_errno = errno; 4590 4591 if (LogLevel > 3 && 4592 #if NETINET6 4593 !(sa->sa.sa_family == AF_INET6 && 4594 IN6_IS_ADDR_LINKLOCAL(&sa->sin6.sin6_addr)) && 4595 #endif /* NETINET6 */ 4596 true) 4597 sm_syslog(LOG_WARNING, NOQID, 4598 "gethostbyaddr(%.100s) failed: %d", 4599 anynet_ntoa(sa), 4600 #if NAMED_BIND 4601 h_errno 4602 #else /* NAMED_BIND */ 4603 -1 4604 #endif /* NAMED_BIND */ 4605 ); 4606 errno = save_errno; 4607 return -1; 4608 } 4609 4610 /* save its cname */ 4611 if (!wordinclass((char *) hp->h_name, 'w')) 4612 { 4613 setclass('w', (char *) hp->h_name); 4614 if (tTd(0, 4)) 4615 sm_dprintf("\ta.k.a.: %s\n", hp->h_name); 4616 4617 if (sm_snprintf(hnb, sizeof(hnb), "[%s]", hp->h_name) < 4618 sizeof(hnb) 4619 && !wordinclass((char *) hnb, 'w')) 4620 setclass('w', hnb); 4621 } 4622 else 4623 { 4624 if (tTd(0, 43)) 4625 sm_dprintf("\ta.k.a.: %s (already in $=w)\n", hp->h_name); 4626 } 4627 4628 /* save all it aliases name */ 4629 for (ha = hp->h_aliases; ha != NULL && *ha != NULL; ha++) 4630 { 4631 if (!wordinclass(*ha, 'w')) 4632 { 4633 setclass('w', *ha); 4634 if (tTd(0, 4)) 4635 sm_dprintf("\ta.k.a.: %s\n", *ha); 4636 if (sm_snprintf(hnb, sizeof(hnb), 4637 "[%s]", *ha) < sizeof(hnb) && 4638 !wordinclass((char *) hnb, 'w')) 4639 setclass('w', hnb); 4640 } 4641 else 4642 { 4643 if (tTd(0, 43)) 4644 sm_dprintf("\ta.k.a.: %s (already in $=w)\n", 4645 *ha); 4646 } 4647 } 4648 #if NETINET6 4649 freehostent(hp); 4650 #endif /* NETINET6 */ 4651 return 0; 4652 } 4653 /* 4654 ** LOAD_IF_NAMES -- load interface-specific names into $=w 4655 ** 4656 ** Parameters: 4657 ** none. 4658 ** 4659 ** Returns: 4660 ** none. 4661 ** 4662 ** Side Effects: 4663 ** Loads $=w with the names of all the interfaces. 4664 */ 4665 4666 #if !NETINET 4667 # define SIOCGIFCONF_IS_BROKEN 1 /* XXX */ 4668 #endif /* !NETINET */ 4669 4670 #if defined(SIOCGIFCONF) && !SIOCGIFCONF_IS_BROKEN 4671 struct rtentry; 4672 struct mbuf; 4673 # ifndef SUNOS403 4674 # include <sm/time.h> 4675 # endif /* ! SUNOS403 */ 4676 # if (_AIX4 >= 40300) && !defined(_NET_IF_H) 4677 # undef __P 4678 # endif /* (_AIX4 >= 40300) && !defined(_NET_IF_H) */ 4679 # include <net/if.h> 4680 #endif /* defined(SIOCGIFCONF) && !SIOCGIFCONF_IS_BROKEN */ 4681 4682 void 4683 load_if_names() 4684 { 4685 # if NETINET6 && defined(SIOCGLIFCONF) 4686 # ifdef __hpux 4687 4688 /* 4689 ** Unfortunately, HP has changed all of the structures, 4690 ** making life difficult for implementors. 4691 */ 4692 4693 # define lifconf if_laddrconf 4694 # define lifc_len iflc_len 4695 # define lifc_buf iflc_buf 4696 # define lifreq if_laddrreq 4697 # define lifr_addr iflr_addr 4698 # define lifr_name iflr_name 4699 # define lifr_flags iflr_flags 4700 # define ss_family sa_family 4701 # undef SIOCGLIFNUM 4702 # endif /* __hpux */ 4703 4704 int s; 4705 int i; 4706 size_t len; 4707 int numifs; 4708 char *buf; 4709 struct lifconf lifc; 4710 # ifdef SIOCGLIFNUM 4711 struct lifnum lifn; 4712 # endif /* SIOCGLIFNUM */ 4713 4714 s = socket(InetMode, SOCK_DGRAM, 0); 4715 if (s == -1) 4716 return; 4717 4718 /* get the list of known IP address from the kernel */ 4719 # ifdef __hpux 4720 i = ioctl(s, SIOCGIFNUM, (char *) &numifs); 4721 # endif /* __hpux */ 4722 # ifdef SIOCGLIFNUM 4723 lifn.lifn_family = AF_UNSPEC; 4724 lifn.lifn_flags = 0; 4725 i = ioctl(s, SIOCGLIFNUM, (char *)&lifn); 4726 numifs = lifn.lifn_count; 4727 # endif /* SIOCGLIFNUM */ 4728 4729 # if defined(__hpux) || defined(SIOCGLIFNUM) 4730 if (i < 0) 4731 { 4732 /* can't get number of interfaces -- fall back */ 4733 if (tTd(0, 4)) 4734 sm_dprintf("SIOCGLIFNUM failed: %s\n", 4735 sm_errstring(errno)); 4736 numifs = -1; 4737 } 4738 else if (tTd(0, 42)) 4739 sm_dprintf("system has %d interfaces\n", numifs); 4740 if (numifs < 0) 4741 # endif /* defined(__hpux) || defined(SIOCGLIFNUM) */ 4742 numifs = MAXINTERFACES; 4743 4744 if (numifs <= 0) 4745 { 4746 (void) close(s); 4747 return; 4748 } 4749 4750 len = lifc.lifc_len = numifs * sizeof(struct lifreq); 4751 buf = lifc.lifc_buf = xalloc(lifc.lifc_len); 4752 # ifndef __hpux 4753 lifc.lifc_family = AF_UNSPEC; 4754 lifc.lifc_flags = 0; 4755 # endif /* ! __hpux */ 4756 if (ioctl(s, SIOCGLIFCONF, (char *)&lifc) < 0) 4757 { 4758 if (tTd(0, 4)) 4759 sm_dprintf("SIOCGLIFCONF failed: %s\n", 4760 sm_errstring(errno)); 4761 (void) close(s); 4762 sm_free(buf); 4763 return; 4764 } 4765 4766 /* scan the list of IP address */ 4767 if (tTd(0, 40)) 4768 sm_dprintf("scanning for interface specific names, lifc_len=%ld\n", 4769 (long) len); 4770 4771 for (i = 0; i < len && i >= 0; ) 4772 { 4773 int flags; 4774 struct lifreq *ifr = (struct lifreq *)&buf[i]; 4775 SOCKADDR *sa = (SOCKADDR *) &ifr->lifr_addr; 4776 int af = ifr->lifr_addr.ss_family; 4777 char *addr; 4778 char *name; 4779 struct in6_addr ia6; 4780 struct in_addr ia; 4781 # ifdef SIOCGLIFFLAGS 4782 struct lifreq ifrf; 4783 # endif /* SIOCGLIFFLAGS */ 4784 char ip_addr[256]; 4785 char buf6[INET6_ADDRSTRLEN]; 4786 4787 /* 4788 ** We must close and recreate the socket each time 4789 ** since we don't know what type of socket it is now 4790 ** (each status function may change it). 4791 */ 4792 4793 (void) close(s); 4794 4795 s = socket(af, SOCK_DGRAM, 0); 4796 if (s == -1) 4797 { 4798 sm_free(buf); /* XXX */ 4799 return; 4800 } 4801 4802 /* 4803 ** If we don't have a complete ifr structure, 4804 ** don't try to use it. 4805 */ 4806 4807 if ((len - i) < sizeof(*ifr)) 4808 break; 4809 4810 # ifdef BSD4_4_SOCKADDR 4811 if (sa->sa.sa_len > sizeof(ifr->lifr_addr)) 4812 i += sizeof(ifr->lifr_name) + sa->sa.sa_len; 4813 else 4814 # endif /* BSD4_4_SOCKADDR */ 4815 # ifdef DEC 4816 /* fix for IPv6 size differences */ 4817 i += sizeof(ifr->ifr_name) + 4818 max(sizeof(ifr->ifr_addr), ifr->ifr_addr.sa_len); 4819 # else /* DEC */ 4820 i += sizeof(*ifr); 4821 # endif /* DEC */ 4822 4823 if (tTd(0, 20)) 4824 sm_dprintf("%s\n", anynet_ntoa(sa)); 4825 4826 if (af != AF_INET && af != AF_INET6) 4827 continue; 4828 4829 # ifdef SIOCGLIFFLAGS 4830 memset(&ifrf, '\0', sizeof(struct lifreq)); 4831 (void) sm_strlcpy(ifrf.lifr_name, ifr->lifr_name, 4832 sizeof(ifrf.lifr_name)); 4833 if (ioctl(s, SIOCGLIFFLAGS, (char *) &ifrf) < 0) 4834 { 4835 if (tTd(0, 4)) 4836 sm_dprintf("SIOCGLIFFLAGS failed: %s\n", 4837 sm_errstring(errno)); 4838 continue; 4839 } 4840 4841 name = ifr->lifr_name; 4842 flags = ifrf.lifr_flags; 4843 4844 if (tTd(0, 41)) 4845 sm_dprintf("\tflags: %lx\n", (unsigned long) flags); 4846 4847 if (!bitset(IFF_UP, flags)) 4848 continue; 4849 # endif /* SIOCGLIFFLAGS */ 4850 4851 ip_addr[0] = '\0'; 4852 4853 /* extract IP address from the list*/ 4854 switch (af) 4855 { 4856 case AF_INET6: 4857 # ifdef __KAME__ 4858 /* convert into proper scoped address */ 4859 if ((IN6_IS_ADDR_LINKLOCAL(&sa->sin6.sin6_addr) || 4860 IN6_IS_ADDR_SITELOCAL(&sa->sin6.sin6_addr)) && 4861 sa->sin6.sin6_scope_id == 0) 4862 { 4863 struct in6_addr *ia6p; 4864 4865 ia6p = &sa->sin6.sin6_addr; 4866 sa->sin6.sin6_scope_id = ntohs(ia6p->s6_addr[3] | 4867 ((unsigned int)ia6p->s6_addr[2] << 8)); 4868 ia6p->s6_addr[2] = ia6p->s6_addr[3] = 0; 4869 } 4870 # endif /* __KAME__ */ 4871 ia6 = sa->sin6.sin6_addr; 4872 if (IN6_IS_ADDR_UNSPECIFIED(&ia6)) 4873 { 4874 addr = anynet_ntop(&ia6, buf6, sizeof(buf6)); 4875 message("WARNING: interface %s is UP with %s address", 4876 name, addr == NULL ? "(NULL)" : addr); 4877 continue; 4878 } 4879 4880 /* save IP address in text from */ 4881 addr = anynet_ntop(&ia6, buf6, sizeof(buf6)); 4882 if (addr != NULL) 4883 (void) sm_snprintf(ip_addr, sizeof(ip_addr), 4884 "[%.*s]", 4885 (int) sizeof(ip_addr) - 3, 4886 addr); 4887 break; 4888 4889 case AF_INET: 4890 ia = sa->sin.sin_addr; 4891 if (ia.s_addr == INADDR_ANY || 4892 ia.s_addr == INADDR_NONE) 4893 { 4894 message("WARNING: interface %s is UP with %s address", 4895 name, inet_ntoa(ia)); 4896 continue; 4897 } 4898 4899 /* save IP address in text from */ 4900 (void) sm_snprintf(ip_addr, sizeof(ip_addr), "[%.*s]", 4901 (int) sizeof(ip_addr) - 3, inet_ntoa(ia)); 4902 break; 4903 } 4904 4905 if (*ip_addr == '\0') 4906 continue; 4907 4908 if (!wordinclass(ip_addr, 'w')) 4909 { 4910 setclass('w', ip_addr); 4911 if (tTd(0, 4)) 4912 sm_dprintf("\ta.k.a.: %s\n", ip_addr); 4913 } 4914 4915 # ifdef SIOCGLIFFLAGS 4916 /* skip "loopback" interface "lo" */ 4917 if (DontProbeInterfaces == DPI_SKIPLOOPBACK && 4918 bitset(IFF_LOOPBACK, flags)) 4919 continue; 4920 # endif /* SIOCGLIFFLAGS */ 4921 (void) add_hostnames(sa); 4922 } 4923 sm_free(buf); /* XXX */ 4924 (void) close(s); 4925 # else /* NETINET6 && defined(SIOCGLIFCONF) */ 4926 # if defined(SIOCGIFCONF) && !SIOCGIFCONF_IS_BROKEN 4927 int s; 4928 int i; 4929 struct ifconf ifc; 4930 int numifs; 4931 4932 s = socket(AF_INET, SOCK_DGRAM, 0); 4933 if (s == -1) 4934 return; 4935 4936 /* get the list of known IP address from the kernel */ 4937 # if defined(SIOCGIFNUM) && !SIOCGIFNUM_IS_BROKEN 4938 if (ioctl(s, SIOCGIFNUM, (char *) &numifs) < 0) 4939 { 4940 /* can't get number of interfaces -- fall back */ 4941 if (tTd(0, 4)) 4942 sm_dprintf("SIOCGIFNUM failed: %s\n", 4943 sm_errstring(errno)); 4944 numifs = -1; 4945 } 4946 else if (tTd(0, 42)) 4947 sm_dprintf("system has %d interfaces\n", numifs); 4948 if (numifs < 0) 4949 # endif /* defined(SIOCGIFNUM) && !SIOCGIFNUM_IS_BROKEN */ 4950 numifs = MAXINTERFACES; 4951 4952 if (numifs <= 0) 4953 { 4954 (void) close(s); 4955 return; 4956 } 4957 ifc.ifc_len = numifs * sizeof(struct ifreq); 4958 ifc.ifc_buf = xalloc(ifc.ifc_len); 4959 if (ioctl(s, SIOCGIFCONF, (char *)&ifc) < 0) 4960 { 4961 if (tTd(0, 4)) 4962 sm_dprintf("SIOCGIFCONF failed: %s\n", 4963 sm_errstring(errno)); 4964 (void) close(s); 4965 return; 4966 } 4967 4968 /* scan the list of IP address */ 4969 if (tTd(0, 40)) 4970 sm_dprintf("scanning for interface specific names, ifc_len=%d\n", 4971 ifc.ifc_len); 4972 4973 for (i = 0; i < ifc.ifc_len && i >= 0; ) 4974 { 4975 int af; 4976 struct ifreq *ifr = (struct ifreq *) &ifc.ifc_buf[i]; 4977 SOCKADDR *sa = (SOCKADDR *) &ifr->ifr_addr; 4978 # if NETINET6 4979 char *addr; 4980 struct in6_addr ia6; 4981 # endif /* NETINET6 */ 4982 struct in_addr ia; 4983 # ifdef SIOCGIFFLAGS 4984 struct ifreq ifrf; 4985 # endif /* SIOCGIFFLAGS */ 4986 char ip_addr[256]; 4987 # if NETINET6 4988 char buf6[INET6_ADDRSTRLEN]; 4989 # endif /* NETINET6 */ 4990 4991 /* 4992 ** If we don't have a complete ifr structure, 4993 ** don't try to use it. 4994 */ 4995 4996 if ((ifc.ifc_len - i) < sizeof(*ifr)) 4997 break; 4998 4999 # ifdef BSD4_4_SOCKADDR 5000 if (sa->sa.sa_len > sizeof(ifr->ifr_addr)) 5001 i += sizeof(ifr->ifr_name) + sa->sa.sa_len; 5002 else 5003 # endif /* BSD4_4_SOCKADDR */ 5004 i += sizeof(*ifr); 5005 5006 if (tTd(0, 20)) 5007 sm_dprintf("%s\n", anynet_ntoa(sa)); 5008 5009 af = ifr->ifr_addr.sa_family; 5010 if (af != AF_INET 5011 # if NETINET6 5012 && af != AF_INET6 5013 # endif /* NETINET6 */ 5014 ) 5015 continue; 5016 5017 # ifdef SIOCGIFFLAGS 5018 memset(&ifrf, '\0', sizeof(struct ifreq)); 5019 (void) sm_strlcpy(ifrf.ifr_name, ifr->ifr_name, 5020 sizeof(ifrf.ifr_name)); 5021 (void) ioctl(s, SIOCGIFFLAGS, (char *) &ifrf); 5022 if (tTd(0, 41)) 5023 sm_dprintf("\tflags: %lx\n", 5024 (unsigned long) ifrf.ifr_flags); 5025 # define IFRFREF ifrf 5026 # else /* SIOCGIFFLAGS */ 5027 # define IFRFREF (*ifr) 5028 # endif /* SIOCGIFFLAGS */ 5029 5030 if (!bitset(IFF_UP, IFRFREF.ifr_flags)) 5031 continue; 5032 5033 ip_addr[0] = '\0'; 5034 5035 /* extract IP address from the list*/ 5036 switch (af) 5037 { 5038 case AF_INET: 5039 ia = sa->sin.sin_addr; 5040 if (ia.s_addr == INADDR_ANY || 5041 ia.s_addr == INADDR_NONE) 5042 { 5043 message("WARNING: interface %s is UP with %s address", 5044 ifr->ifr_name, inet_ntoa(ia)); 5045 continue; 5046 } 5047 5048 /* save IP address in text from */ 5049 (void) sm_snprintf(ip_addr, sizeof(ip_addr), "[%.*s]", 5050 (int) sizeof(ip_addr) - 3, 5051 inet_ntoa(ia)); 5052 break; 5053 5054 # if NETINET6 5055 case AF_INET6: 5056 # ifdef __KAME__ 5057 /* convert into proper scoped address */ 5058 if ((IN6_IS_ADDR_LINKLOCAL(&sa->sin6.sin6_addr) || 5059 IN6_IS_ADDR_SITELOCAL(&sa->sin6.sin6_addr)) && 5060 sa->sin6.sin6_scope_id == 0) 5061 { 5062 struct in6_addr *ia6p; 5063 5064 ia6p = &sa->sin6.sin6_addr; 5065 sa->sin6.sin6_scope_id = ntohs(ia6p->s6_addr[3] | 5066 ((unsigned int)ia6p->s6_addr[2] << 8)); 5067 ia6p->s6_addr[2] = ia6p->s6_addr[3] = 0; 5068 } 5069 # endif /* __KAME__ */ 5070 ia6 = sa->sin6.sin6_addr; 5071 if (IN6_IS_ADDR_UNSPECIFIED(&ia6)) 5072 { 5073 addr = anynet_ntop(&ia6, buf6, sizeof(buf6)); 5074 message("WARNING: interface %s is UP with %s address", 5075 ifr->ifr_name, 5076 addr == NULL ? "(NULL)" : addr); 5077 continue; 5078 } 5079 5080 /* save IP address in text from */ 5081 addr = anynet_ntop(&ia6, buf6, sizeof(buf6)); 5082 if (addr != NULL) 5083 (void) sm_snprintf(ip_addr, sizeof(ip_addr), 5084 "[%.*s]", 5085 (int) sizeof(ip_addr) - 3, 5086 addr); 5087 break; 5088 5089 # endif /* NETINET6 */ 5090 } 5091 5092 if (ip_addr[0] == '\0') 5093 continue; 5094 5095 if (!wordinclass(ip_addr, 'w')) 5096 { 5097 setclass('w', ip_addr); 5098 if (tTd(0, 4)) 5099 sm_dprintf("\ta.k.a.: %s\n", ip_addr); 5100 } 5101 5102 /* skip "loopback" interface "lo" */ 5103 if (DontProbeInterfaces == DPI_SKIPLOOPBACK && 5104 bitset(IFF_LOOPBACK, IFRFREF.ifr_flags)) 5105 continue; 5106 5107 (void) add_hostnames(sa); 5108 } 5109 sm_free(ifc.ifc_buf); /* XXX */ 5110 (void) close(s); 5111 # undef IFRFREF 5112 # endif /* defined(SIOCGIFCONF) && !SIOCGIFCONF_IS_BROKEN */ 5113 # endif /* NETINET6 && defined(SIOCGLIFCONF) */ 5114 } 5115 /* 5116 ** ISLOOPBACK -- is socket address in the loopback net? 5117 ** 5118 ** Parameters: 5119 ** sa -- socket address. 5120 ** 5121 ** Returns: 5122 ** true -- is socket address in the loopback net? 5123 ** false -- otherwise 5124 ** 5125 */ 5126 5127 bool 5128 isloopback(sa) 5129 SOCKADDR sa; 5130 { 5131 #if NETINET6 5132 if (IN6_IS_ADDR_LOOPBACK(&sa.sin6.sin6_addr)) 5133 return true; 5134 #else /* NETINET6 */ 5135 /* XXX how to correctly extract IN_LOOPBACKNET part? */ 5136 if (((ntohl(sa.sin.sin_addr.s_addr) & IN_CLASSA_NET) 5137 >> IN_CLASSA_NSHIFT) == IN_LOOPBACKNET) 5138 return true; 5139 #endif /* NETINET6 */ 5140 return false; 5141 } 5142 /* 5143 ** GET_NUM_PROCS_ONLINE -- return the number of processors currently online 5144 ** 5145 ** Parameters: 5146 ** none. 5147 ** 5148 ** Returns: 5149 ** The number of processors online. 5150 */ 5151 5152 static int 5153 get_num_procs_online() 5154 { 5155 int nproc = 0; 5156 5157 #ifdef USESYSCTL 5158 # if defined(CTL_HW) && defined(HW_NCPU) 5159 size_t sz; 5160 int mib[2]; 5161 5162 mib[0] = CTL_HW; 5163 mib[1] = HW_NCPU; 5164 sz = (size_t) sizeof(nproc); 5165 (void) sysctl(mib, 2, &nproc, &sz, NULL, 0); 5166 # endif /* defined(CTL_HW) && defined(HW_NCPU) */ 5167 #else /* USESYSCTL */ 5168 # ifdef _SC_NPROCESSORS_ONLN 5169 nproc = (int) sysconf(_SC_NPROCESSORS_ONLN); 5170 # else /* _SC_NPROCESSORS_ONLN */ 5171 # ifdef __hpux 5172 # include <sys/pstat.h> 5173 struct pst_dynamic psd; 5174 5175 if (pstat_getdynamic(&psd, sizeof(psd), (size_t)1, 0) != -1) 5176 nproc = psd.psd_proc_cnt; 5177 # endif /* __hpux */ 5178 # endif /* _SC_NPROCESSORS_ONLN */ 5179 #endif /* USESYSCTL */ 5180 5181 if (nproc <= 0) 5182 nproc = 1; 5183 return nproc; 5184 } 5185 /* 5186 ** SM_CLOSEFROM -- close file descriptors 5187 ** 5188 ** Parameters: 5189 ** lowest -- first fd to close 5190 ** highest -- last fd + 1 to close 5191 ** 5192 ** Returns: 5193 ** none 5194 */ 5195 5196 void 5197 sm_closefrom(lowest, highest) 5198 int lowest, highest; 5199 { 5200 #if HASCLOSEFROM 5201 closefrom(lowest); 5202 #else /* HASCLOSEFROM */ 5203 int i; 5204 5205 for (i = lowest; i < highest; i++) 5206 (void) close(i); 5207 #endif /* HASCLOSEFROM */ 5208 } 5209 #if HASFDWALK 5210 /* 5211 ** CLOSEFD_WALK -- walk fd's arranging to close them 5212 ** Callback for fdwalk() 5213 ** 5214 ** Parameters: 5215 ** lowest -- first fd to arrange to be closed 5216 ** fd -- fd to arrange to be closed 5217 ** 5218 ** Returns: 5219 ** zero 5220 */ 5221 5222 static int 5223 closefd_walk(lowest, fd) 5224 void *lowest; 5225 int fd; 5226 { 5227 if (fd >= *(int *)lowest) 5228 (void) fcntl(fd, F_SETFD, FD_CLOEXEC); 5229 return 0; 5230 } 5231 #endif /* HASFDWALK */ 5232 /* 5233 ** SM_CLOSE_ON_EXEC -- arrange for file descriptors to be closed 5234 ** 5235 ** Parameters: 5236 ** lowest -- first fd to arrange to be closed 5237 ** highest -- last fd + 1 to arrange to be closed 5238 ** 5239 ** Returns: 5240 ** none 5241 */ 5242 5243 void 5244 sm_close_on_exec(highest, lowest) 5245 int highest, lowest; 5246 { 5247 #if HASFDWALK 5248 (void) fdwalk(closefd_walk, &lowest); 5249 #else /* HASFDWALK */ 5250 int i, j; 5251 5252 for (i = lowest; i < highest; i++) 5253 { 5254 if ((j = fcntl(i, F_GETFD, 0)) != -1) 5255 (void) fcntl(i, F_SETFD, j | FD_CLOEXEC); 5256 } 5257 #endif /* HASFDWALK */ 5258 } 5259 /* 5260 ** SEED_RANDOM -- seed the random number generator 5261 ** 5262 ** Parameters: 5263 ** none 5264 ** 5265 ** Returns: 5266 ** none 5267 */ 5268 5269 void 5270 seed_random() 5271 { 5272 #if HASSRANDOMDEV 5273 srandomdev(); 5274 #else /* HASSRANDOMDEV */ 5275 long seed; 5276 struct timeval t; 5277 5278 seed = (long) CurrentPid; 5279 if (gettimeofday(&t, NULL) >= 0) 5280 seed += t.tv_sec + t.tv_usec; 5281 5282 # if HASRANDOM 5283 (void) srandom(seed); 5284 # else /* HASRANDOM */ 5285 (void) srand((unsigned int) seed); 5286 # endif /* HASRANDOM */ 5287 #endif /* HASSRANDOMDEV */ 5288 } 5289 /* 5290 ** SM_SYSLOG -- syslog wrapper to keep messages under SYSLOG_BUFSIZE 5291 ** 5292 ** Parameters: 5293 ** level -- syslog level 5294 ** id -- envelope ID or NULL (NOQUEUE) 5295 ** fmt -- format string 5296 ** arg... -- arguments as implied by fmt. 5297 ** 5298 ** Returns: 5299 ** none 5300 */ 5301 5302 /* VARARGS3 */ 5303 void 5304 #ifdef __STDC__ 5305 sm_syslog(int level, const char *id, const char *fmt, ...) 5306 #else /* __STDC__ */ 5307 sm_syslog(level, id, fmt, va_alist) 5308 int level; 5309 const char *id; 5310 const char *fmt; 5311 va_dcl 5312 #endif /* __STDC__ */ 5313 { 5314 char *buf; 5315 size_t bufsize; 5316 char *begin, *end; 5317 int save_errno; 5318 int seq = 1; 5319 int idlen; 5320 char buf0[MAXLINE]; 5321 char *newstring; 5322 extern int SyslogPrefixLen; 5323 SM_VA_LOCAL_DECL 5324 5325 save_errno = errno; 5326 if (id == NULL) 5327 id = "NOQUEUE"; 5328 idlen = strlen(id) + SyslogPrefixLen; 5329 5330 buf = buf0; 5331 bufsize = sizeof(buf0); 5332 5333 for (;;) 5334 { 5335 int n; 5336 5337 /* print log message into buf */ 5338 SM_VA_START(ap, fmt); 5339 n = sm_vsnprintf(buf, bufsize, fmt, ap); 5340 SM_VA_END(ap); 5341 SM_ASSERT(n > 0); 5342 if (n < bufsize) 5343 break; 5344 5345 /* String too small, redo with correct size */ 5346 bufsize = n + 1; 5347 if (buf != buf0) 5348 { 5349 sm_free(buf); 5350 buf = NULL; 5351 } 5352 buf = sm_malloc_x(bufsize); 5353 } 5354 5355 /* clean up buf after it has been expanded with args */ 5356 newstring = str2prt(buf); 5357 if ((strlen(newstring) + idlen + 1) < SYSLOG_BUFSIZE) 5358 { 5359 #if LOG 5360 if (*id == '\0') 5361 { 5362 if (tTd(89, 8)) 5363 sm_dprintf("%s\n", newstring); 5364 else 5365 syslog(level, "%s", newstring); 5366 } 5367 else 5368 { 5369 if (tTd(89, 8)) 5370 sm_dprintf("%s: %s\n", id, newstring); 5371 else 5372 syslog(level, "%s: %s", id, newstring); 5373 } 5374 #else /* LOG */ 5375 /*XXX should do something more sensible */ 5376 if (*id == '\0') 5377 (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT, "%s\n", 5378 newstring); 5379 else 5380 (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT, 5381 "%s: %s\n", id, newstring); 5382 #endif /* LOG */ 5383 if (buf != buf0) 5384 sm_free(buf); 5385 errno = save_errno; 5386 return; 5387 } 5388 5389 /* 5390 ** additional length for splitting: " ..." + 3, where 3 is magic to 5391 ** have some data for the next entry. 5392 */ 5393 5394 #define SL_SPLIT 7 5395 5396 begin = newstring; 5397 idlen += 5; /* strlen("[999]"), see below */ 5398 while (*begin != '\0' && 5399 (strlen(begin) + idlen) > SYSLOG_BUFSIZE) 5400 { 5401 char save; 5402 5403 if (seq >= 999) 5404 { 5405 /* Too many messages */ 5406 break; 5407 } 5408 end = begin + SYSLOG_BUFSIZE - idlen - SL_SPLIT; 5409 while (end > begin) 5410 { 5411 /* Break on comma or space */ 5412 if (*end == ',' || *end == ' ') 5413 { 5414 end++; /* Include separator */ 5415 break; 5416 } 5417 end--; 5418 } 5419 /* No separator, break midstring... */ 5420 if (end == begin) 5421 end = begin + SYSLOG_BUFSIZE - idlen - SL_SPLIT; 5422 save = *end; 5423 *end = 0; 5424 #if LOG 5425 if (tTd(89, 8)) 5426 sm_dprintf("%s[%d]: %s ...\n", id, seq++, begin); 5427 else 5428 syslog(level, "%s[%d]: %s ...", id, seq++, begin); 5429 #else /* LOG */ 5430 (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT, 5431 "%s[%d]: %s ...\n", id, seq++, begin); 5432 #endif /* LOG */ 5433 *end = save; 5434 begin = end; 5435 } 5436 if (seq >= 999) 5437 { 5438 #if LOG 5439 if (tTd(89, 8)) 5440 sm_dprintf("%s[%d]: log terminated, too many parts\n", 5441 id, seq); 5442 else 5443 syslog(level, "%s[%d]: log terminated, too many parts", 5444 id, seq); 5445 #else /* LOG */ 5446 (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT, 5447 "%s[%d]: log terminated, too many parts\n", id, seq); 5448 #endif /* LOG */ 5449 } 5450 else if (*begin != '\0') 5451 { 5452 #if LOG 5453 if (tTd(89, 8)) 5454 sm_dprintf("%s[%d]: %s\n", id, seq, begin); 5455 else 5456 syslog(level, "%s[%d]: %s", id, seq, begin); 5457 #else /* LOG */ 5458 (void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT, 5459 "%s[%d]: %s\n", id, seq, begin); 5460 #endif /* LOG */ 5461 } 5462 if (buf != buf0) 5463 sm_free(buf); 5464 errno = save_errno; 5465 } 5466 /* 5467 ** HARD_SYSLOG -- call syslog repeatedly until it works 5468 ** 5469 ** Needed on HP-UX, which apparently doesn't guarantee that 5470 ** syslog succeeds during interrupt handlers. 5471 */ 5472 5473 #if defined(__hpux) && !defined(HPUX11) 5474 5475 # define MAXSYSLOGTRIES 100 5476 # undef syslog 5477 # ifdef V4FS 5478 # define XCNST const 5479 # define CAST (const char *) 5480 # else /* V4FS */ 5481 # define XCNST 5482 # define CAST 5483 # endif /* V4FS */ 5484 5485 void 5486 # ifdef __STDC__ 5487 hard_syslog(int pri, XCNST char *msg, ...) 5488 # else /* __STDC__ */ 5489 hard_syslog(pri, msg, va_alist) 5490 int pri; 5491 XCNST char *msg; 5492 va_dcl 5493 # endif /* __STDC__ */ 5494 { 5495 int i; 5496 char buf[SYSLOG_BUFSIZE]; 5497 SM_VA_LOCAL_DECL 5498 5499 SM_VA_START(ap, msg); 5500 (void) sm_vsnprintf(buf, sizeof(buf), msg, ap); 5501 SM_VA_END(ap); 5502 5503 for (i = MAXSYSLOGTRIES; --i >= 0 && syslog(pri, CAST "%s", buf) < 0; ) 5504 continue; 5505 } 5506 5507 # undef CAST 5508 #endif /* defined(__hpux) && !defined(HPUX11) */ 5509 #if NEEDLOCAL_HOSTNAME_LENGTH 5510 /* 5511 ** LOCAL_HOSTNAME_LENGTH 5512 ** 5513 ** This is required to get sendmail to compile against BIND 4.9.x 5514 ** on Ultrix. 5515 ** 5516 ** Unfortunately, a Compaq Y2K patch kit provides it without 5517 ** bumping __RES in /usr/include/resolv.h so we can't automatically 5518 ** figure out whether it is needed. 5519 */ 5520 5521 int 5522 local_hostname_length(hostname) 5523 char *hostname; 5524 { 5525 size_t len_host, len_domain; 5526 5527 if (!*_res.defdname) 5528 res_init(); 5529 len_host = strlen(hostname); 5530 len_domain = strlen(_res.defdname); 5531 if (len_host > len_domain && 5532 (sm_strcasecmp(hostname + len_host - len_domain, 5533 _res.defdname) == 0) && 5534 hostname[len_host - len_domain - 1] == '.') 5535 return len_host - len_domain - 1; 5536 else 5537 return 0; 5538 } 5539 #endif /* NEEDLOCAL_HOSTNAME_LENGTH */ 5540 5541 #if NEEDLINK 5542 /* 5543 ** LINK -- clone a file 5544 ** 5545 ** Some OS's lacks link() and hard links. Since sendmail is using 5546 ** link() as an efficient way to clone files, this implementation 5547 ** will simply do a file copy. 5548 ** 5549 ** NOTE: This link() replacement is not a generic replacement as it 5550 ** does not handle all of the semantics of the real link(2). 5551 ** 5552 ** Parameters: 5553 ** source -- pathname of existing file. 5554 ** target -- pathname of link (clone) to be created. 5555 ** 5556 ** Returns: 5557 ** 0 -- success. 5558 ** -1 -- failure, see errno for details. 5559 */ 5560 5561 int 5562 link(source, target) 5563 const char *source; 5564 const char *target; 5565 { 5566 int save_errno; 5567 int sff; 5568 int src = -1, dst = -1; 5569 ssize_t readlen; 5570 ssize_t writelen; 5571 char buf[BUFSIZ]; 5572 struct stat st; 5573 5574 sff = SFF_REGONLY|SFF_OPENASROOT; 5575 if (DontLockReadFiles) 5576 sff |= SFF_NOLOCK; 5577 5578 /* Open the original file */ 5579 src = safeopen((char *)source, O_RDONLY, 0, sff); 5580 if (src < 0) 5581 goto fail; 5582 5583 /* Obtain the size and the mode */ 5584 if (fstat(src, &st) < 0) 5585 goto fail; 5586 5587 /* Create the duplicate copy */ 5588 sff &= ~SFF_NOLOCK; 5589 sff |= SFF_CREAT; 5590 dst = safeopen((char *)target, O_CREAT|O_EXCL|O_WRONLY, 5591 st.st_mode, sff); 5592 if (dst < 0) 5593 goto fail; 5594 5595 /* Copy all of the bytes one buffer at a time */ 5596 while ((readlen = read(src, &buf, sizeof(buf))) > 0) 5597 { 5598 ssize_t left = readlen; 5599 char *p = buf; 5600 5601 while (left > 0 && 5602 (writelen = write(dst, p, (size_t) left)) >= 0) 5603 { 5604 left -= writelen; 5605 p += writelen; 5606 } 5607 if (writelen < 0) 5608 break; 5609 } 5610 5611 /* Any trouble reading? */ 5612 if (readlen < 0 || writelen < 0) 5613 goto fail; 5614 5615 /* Close the input file */ 5616 if (close(src) < 0) 5617 { 5618 src = -1; 5619 goto fail; 5620 } 5621 src = -1; 5622 5623 /* Close the output file */ 5624 if (close(dst) < 0) 5625 { 5626 /* don't set dst = -1 here so we unlink the file */ 5627 goto fail; 5628 } 5629 5630 /* Success */ 5631 return 0; 5632 5633 fail: 5634 save_errno = errno; 5635 if (src >= 0) 5636 (void) close(src); 5637 if (dst >= 0) 5638 { 5639 (void) unlink(target); 5640 (void) close(dst); 5641 } 5642 errno = save_errno; 5643 return -1; 5644 } 5645 #endif /* NEEDLINK */ 5646 5647 /* 5648 ** Compile-Time options 5649 */ 5650 5651 char *CompileOptions[] = 5652 { 5653 #if ALLOW_255 5654 "ALLOW_255", 5655 #endif /* ALLOW_255 */ 5656 #if NAMED_BIND 5657 # if DNSMAP 5658 "DNSMAP", 5659 # endif /* DNSMAP */ 5660 #endif /* NAMED_BIND */ 5661 #if EGD 5662 "EGD", 5663 #endif /* EGD */ 5664 #if HESIOD 5665 "HESIOD", 5666 #endif /* HESIOD */ 5667 #if HES_GETMAILHOST 5668 "HES_GETMAILHOST", 5669 #endif /* HES_GETMAILHOST */ 5670 #if LDAPMAP 5671 "LDAPMAP", 5672 #endif /* LDAPMAP */ 5673 #if LDAP_REFERRALS 5674 "LDAP_REFERRALS", 5675 #endif /* LDAP_REFERRALS */ 5676 #if LOG 5677 "LOG", 5678 #endif /* LOG */ 5679 #if MAP_NSD 5680 "MAP_NSD", 5681 #endif /* MAP_NSD */ 5682 #if MAP_REGEX 5683 "MAP_REGEX", 5684 #endif /* MAP_REGEX */ 5685 #if MATCHGECOS 5686 "MATCHGECOS", 5687 #endif /* MATCHGECOS */ 5688 #if MILTER 5689 "MILTER", 5690 #endif /* MILTER */ 5691 #if MIME7TO8 5692 "MIME7TO8", 5693 #endif /* MIME7TO8 */ 5694 #if MIME7TO8_OLD 5695 "MIME7TO8_OLD", 5696 #endif /* MIME7TO8_OLD */ 5697 #if MIME8TO7 5698 "MIME8TO7", 5699 #endif /* MIME8TO7 */ 5700 #if NAMED_BIND 5701 "NAMED_BIND", 5702 #endif /* NAMED_BIND */ 5703 #if NDBM 5704 "NDBM", 5705 #endif /* NDBM */ 5706 #if NETINET 5707 "NETINET", 5708 #endif /* NETINET */ 5709 #if NETINET6 5710 "NETINET6", 5711 #endif /* NETINET6 */ 5712 #if NETINFO 5713 "NETINFO", 5714 #endif /* NETINFO */ 5715 #if NETISO 5716 "NETISO", 5717 #endif /* NETISO */ 5718 #if NETNS 5719 "NETNS", 5720 #endif /* NETNS */ 5721 #if NETUNIX 5722 "NETUNIX", 5723 #endif /* NETUNIX */ 5724 #if NETX25 5725 "NETX25", 5726 #endif /* NETX25 */ 5727 #if NEWDB 5728 "NEWDB", 5729 #endif /* NEWDB */ 5730 #if NIS 5731 "NIS", 5732 #endif /* NIS */ 5733 #if NISPLUS 5734 "NISPLUS", 5735 #endif /* NISPLUS */ 5736 #if NO_DH 5737 "NO_DH", 5738 #endif /* NO_DH */ 5739 #if PH_MAP 5740 "PH_MAP", 5741 #endif /* PH_MAP */ 5742 #ifdef PICKY_HELO_CHECK 5743 "PICKY_HELO_CHECK", 5744 #endif /* PICKY_HELO_CHECK */ 5745 #if PIPELINING 5746 "PIPELINING", 5747 #endif /* PIPELINING */ 5748 #if SASL 5749 # if SASL >= 20000 5750 "SASLv2", 5751 # else /* SASL >= 20000 */ 5752 "SASL", 5753 # endif /* SASL >= 20000 */ 5754 #endif /* SASL */ 5755 #if SCANF 5756 "SCANF", 5757 #endif /* SCANF */ 5758 #if SM_LDAP_ERROR_ON_MISSING_ARGS 5759 "SM_LDAP_ERROR_ON_MISSING_ARGS", 5760 #endif /* SM_LDAP_ERROR_ON_MISSING_ARGS */ 5761 #if SMTPDEBUG 5762 "SMTPDEBUG", 5763 #endif /* SMTPDEBUG */ 5764 #if SOCKETMAP 5765 "SOCKETMAP", 5766 #endif /* SOCKETMAP */ 5767 #if STARTTLS 5768 "STARTTLS", 5769 #endif /* STARTTLS */ 5770 #if SUID_ROOT_FILES_OK 5771 "SUID_ROOT_FILES_OK", 5772 #endif /* SUID_ROOT_FILES_OK */ 5773 #if TCPWRAPPERS 5774 "TCPWRAPPERS", 5775 #endif /* TCPWRAPPERS */ 5776 #if TLS_NO_RSA 5777 "TLS_NO_RSA", 5778 #endif /* TLS_NO_RSA */ 5779 #if TLS_VRFY_PER_CTX 5780 "TLS_VRFY_PER_CTX", 5781 #endif /* TLS_VRFY_PER_CTX */ 5782 #if USERDB 5783 "USERDB", 5784 #endif /* USERDB */ 5785 #if USE_LDAP_INIT 5786 "USE_LDAP_INIT", 5787 #endif /* USE_LDAP_INIT */ 5788 #if USE_TTYPATH 5789 "USE_TTYPATH", 5790 #endif /* USE_TTYPATH */ 5791 #if XDEBUG 5792 "XDEBUG", 5793 #endif /* XDEBUG */ 5794 #if XLA 5795 "XLA", 5796 #endif /* XLA */ 5797 NULL 5798 }; 5799 5800 5801 /* 5802 ** OS compile options. 5803 */ 5804 5805 char *OsCompileOptions[] = 5806 { 5807 #if ADDRCONFIG_IS_BROKEN 5808 "ADDRCONFIG_IS_BROKEN", 5809 #endif /* ADDRCONFIG_IS_BROKEN */ 5810 #ifdef AUTO_NETINFO_HOSTS 5811 "AUTO_NETINFO_HOSTS", 5812 #endif /* AUTO_NETINFO_HOSTS */ 5813 #ifdef AUTO_NIS_ALIASES 5814 "AUTO_NIS_ALIASES", 5815 #endif /* AUTO_NIS_ALIASES */ 5816 #if BROKEN_RES_SEARCH 5817 "BROKEN_RES_SEARCH", 5818 #endif /* BROKEN_RES_SEARCH */ 5819 #ifdef BSD4_4_SOCKADDR 5820 "BSD4_4_SOCKADDR", 5821 #endif /* BSD4_4_SOCKADDR */ 5822 #if BOGUS_O_EXCL 5823 "BOGUS_O_EXCL", 5824 #endif /* BOGUS_O_EXCL */ 5825 #if DEC_OSF_BROKEN_GETPWENT 5826 "DEC_OSF_BROKEN_GETPWENT", 5827 #endif /* DEC_OSF_BROKEN_GETPWENT */ 5828 #if FAST_PID_RECYCLE 5829 "FAST_PID_RECYCLE", 5830 #endif /* FAST_PID_RECYCLE */ 5831 #if HASCLOSEFROM 5832 "HASCLOSEFROM", 5833 #endif /* HASCLOSEFROM */ 5834 #if HASFCHOWN 5835 "HASFCHOWN", 5836 #endif /* HASFCHOWN */ 5837 #if HASFCHMOD 5838 "HASFCHMOD", 5839 #endif /* HASFCHMOD */ 5840 #if HASFDWALK 5841 "HASFDWALK", 5842 #endif /* HASFDWALK */ 5843 #if HASFLOCK 5844 "HASFLOCK", 5845 #endif /* HASFLOCK */ 5846 #if HASGETDTABLESIZE 5847 "HASGETDTABLESIZE", 5848 #endif /* HASGETDTABLESIZE */ 5849 #if HASGETUSERSHELL 5850 "HASGETUSERSHELL", 5851 #endif /* HASGETUSERSHELL */ 5852 #if HASINITGROUPS 5853 "HASINITGROUPS", 5854 #endif /* HASINITGROUPS */ 5855 #if HASLDAPGETALIASBYNAME 5856 "HASLDAPGETALIASBYNAME", 5857 #endif /* HASLDAPGETALIASBYNAME */ 5858 #if HASLSTAT 5859 "HASLSTAT", 5860 #endif /* HASLSTAT */ 5861 #if HASNICE 5862 "HASNICE", 5863 #endif /* HASNICE */ 5864 #if HASRANDOM 5865 "HASRANDOM", 5866 #endif /* HASRANDOM */ 5867 #if HASRRESVPORT 5868 "HASRRESVPORT", 5869 #endif /* HASRRESVPORT */ 5870 #if HASSETEGID 5871 "HASSETEGID", 5872 #endif /* HASSETEGID */ 5873 #if HASSETLOGIN 5874 "HASSETLOGIN", 5875 #endif /* HASSETLOGIN */ 5876 #if HASSETREGID 5877 "HASSETREGID", 5878 #endif /* HASSETREGID */ 5879 #if HASSETRESGID 5880 "HASSETRESGID", 5881 #endif /* HASSETRESGID */ 5882 #if HASSETREUID 5883 "HASSETREUID", 5884 #endif /* HASSETREUID */ 5885 #if HASSETRLIMIT 5886 "HASSETRLIMIT", 5887 #endif /* HASSETRLIMIT */ 5888 #if HASSETSID 5889 "HASSETSID", 5890 #endif /* HASSETSID */ 5891 #if HASSETUSERCONTEXT 5892 "HASSETUSERCONTEXT", 5893 #endif /* HASSETUSERCONTEXT */ 5894 #if HASSETVBUF 5895 "HASSETVBUF", 5896 #endif /* HASSETVBUF */ 5897 #if HAS_ST_GEN 5898 "HAS_ST_GEN", 5899 #endif /* HAS_ST_GEN */ 5900 #if HASSRANDOMDEV 5901 "HASSRANDOMDEV", 5902 #endif /* HASSRANDOMDEV */ 5903 #if HASURANDOMDEV 5904 "HASURANDOMDEV", 5905 #endif /* HASURANDOMDEV */ 5906 #if HASSTRERROR 5907 "HASSTRERROR", 5908 #endif /* HASSTRERROR */ 5909 #if HASULIMIT 5910 "HASULIMIT", 5911 #endif /* HASULIMIT */ 5912 #if HASUNAME 5913 "HASUNAME", 5914 #endif /* HASUNAME */ 5915 #if HASUNSETENV 5916 "HASUNSETENV", 5917 #endif /* HASUNSETENV */ 5918 #if HASWAITPID 5919 "HASWAITPID", 5920 #endif /* HASWAITPID */ 5921 #if IDENTPROTO 5922 "IDENTPROTO", 5923 #endif /* IDENTPROTO */ 5924 #if IP_SRCROUTE 5925 "IP_SRCROUTE", 5926 #endif /* IP_SRCROUTE */ 5927 #if O_EXLOCK && HASFLOCK && !BOGUS_O_EXCL 5928 "LOCK_ON_OPEN", 5929 #endif /* O_EXLOCK && HASFLOCK && !BOGUS_O_EXCL */ 5930 #if MILTER_NO_NAGLE 5931 "MILTER_NO_NAGLE ", 5932 #endif /* MILTER_NO_NAGLE */ 5933 #if NEEDFSYNC 5934 "NEEDFSYNC", 5935 #endif /* NEEDFSYNC */ 5936 #if NEEDLINK 5937 "NEEDLINK", 5938 #endif /* NEEDLINK */ 5939 #if NEEDLOCAL_HOSTNAME_LENGTH 5940 "NEEDLOCAL_HOSTNAME_LENGTH", 5941 #endif /* NEEDLOCAL_HOSTNAME_LENGTH */ 5942 #if NEEDSGETIPNODE 5943 "NEEDSGETIPNODE", 5944 #endif /* NEEDSGETIPNODE */ 5945 #if NEEDSTRSTR 5946 "NEEDSTRSTR", 5947 #endif /* NEEDSTRSTR */ 5948 #if NEEDSTRTOL 5949 "NEEDSTRTOL", 5950 #endif /* NEEDSTRTOL */ 5951 #ifdef NO_GETSERVBYNAME 5952 "NO_GETSERVBYNAME", 5953 #endif /* NO_GETSERVBYNAME */ 5954 #if NOFTRUNCATE 5955 "NOFTRUNCATE", 5956 #endif /* NOFTRUNCATE */ 5957 #if REQUIRES_DIR_FSYNC 5958 "REQUIRES_DIR_FSYNC", 5959 #endif /* REQUIRES_DIR_FSYNC */ 5960 #if RLIMIT_NEEDS_SYS_TIME_H 5961 "RLIMIT_NEEDS_SYS_TIME_H", 5962 #endif /* RLIMIT_NEEDS_SYS_TIME_H */ 5963 #if SAFENFSPATHCONF 5964 "SAFENFSPATHCONF", 5965 #endif /* SAFENFSPATHCONF */ 5966 #if SECUREWARE 5967 "SECUREWARE", 5968 #endif /* SECUREWARE */ 5969 #if SHARE_V1 5970 "SHARE_V1", 5971 #endif /* SHARE_V1 */ 5972 #if SIOCGIFCONF_IS_BROKEN 5973 "SIOCGIFCONF_IS_BROKEN", 5974 #endif /* SIOCGIFCONF_IS_BROKEN */ 5975 #if SIOCGIFNUM_IS_BROKEN 5976 "SIOCGIFNUM_IS_BROKEN", 5977 #endif /* SIOCGIFNUM_IS_BROKEN */ 5978 #if SNPRINTF_IS_BROKEN 5979 "SNPRINTF_IS_BROKEN", 5980 #endif /* SNPRINTF_IS_BROKEN */ 5981 #if SO_REUSEADDR_IS_BROKEN 5982 "SO_REUSEADDR_IS_BROKEN", 5983 #endif /* SO_REUSEADDR_IS_BROKEN */ 5984 #if SYS5SETPGRP 5985 "SYS5SETPGRP", 5986 #endif /* SYS5SETPGRP */ 5987 #if SYSTEM5 5988 "SYSTEM5", 5989 #endif /* SYSTEM5 */ 5990 #if USE_DOUBLE_FORK 5991 "USE_DOUBLE_FORK", 5992 #endif /* USE_DOUBLE_FORK */ 5993 #if USE_ENVIRON 5994 "USE_ENVIRON", 5995 #endif /* USE_ENVIRON */ 5996 #if USE_SA_SIGACTION 5997 "USE_SA_SIGACTION", 5998 #endif /* USE_SA_SIGACTION */ 5999 #if USE_SIGLONGJMP 6000 "USE_SIGLONGJMP", 6001 #endif /* USE_SIGLONGJMP */ 6002 #if USEGETCONFATTR 6003 "USEGETCONFATTR", 6004 #endif /* USEGETCONFATTR */ 6005 #if USESETEUID 6006 "USESETEUID", 6007 #endif /* USESETEUID */ 6008 #ifdef USESYSCTL 6009 "USESYSCTL", 6010 #endif /* USESYSCTL */ 6011 #if USING_NETSCAPE_LDAP 6012 "USING_NETSCAPE_LDAP", 6013 #endif /* USING_NETSCAPE_LDAP */ 6014 #ifdef WAITUNION 6015 "WAITUNION", 6016 #endif /* WAITUNION */ 6017 NULL 6018 }; 6019 6020 /* 6021 ** FFR compile options. 6022 */ 6023 6024 char *FFRCompileOptions[] = 6025 { 6026 #if _FFR_ADDR_TYPE_MODES 6027 /* more info in {addr_type}, requires m4 changes! */ 6028 "_FFR_ADDR_TYPE_MODES", 6029 #endif /* _FFR_ADDR_TYPE_MODES */ 6030 #if _FFR_ALLOW_SASLINFO 6031 /* DefaultAuthInfo can be specified by user. */ 6032 /* DefaultAuthInfo doesn't really work in 8.13 anymore. */ 6033 "_FFR_ALLOW_SASLINFO", 6034 #endif /* _FFR_ALLOW_SASLINFO */ 6035 #if _FFR_BESTMX_BETTER_TRUNCATION 6036 /* Better truncation of list of MX records for dns map. */ 6037 "_FFR_BESTMX_BETTER_TRUNCATION", 6038 #endif /* _FFR_BESTMX_BETTER_TRUNCATION */ 6039 #if _FFR_CATCH_BROKEN_MTAS 6040 /* Deal with MTAs that send a reply during the DATA phase. */ 6041 "_FFR_CATCH_BROKEN_MTAS", 6042 #endif /* _FFR_CATCH_BROKEN_MTAS */ 6043 #if _FFR_CHK_QUEUE 6044 /* Stricter checks about queue directory permissions. */ 6045 "_FFR_CHK_QUEUE", 6046 #endif /* _FFR_CHK_QUEUE */ 6047 #if _FFR_CLIENT_SIZE 6048 /* Don't try to send mail if its size exceeds SIZE= of server. */ 6049 "_FFR_CLIENT_SIZE", 6050 #endif /* _FFR_CLIENT_SIZE */ 6051 #if _FFR_CRLPATH 6052 /* CRLPath; needs documentation; Al Smith */ 6053 "_FFR_CRLPATH", 6054 #endif /* _FFR_CRLPATH */ 6055 #if _FFR_DAEMON_NETUNIX 6056 /* Allow local (not just TCP) socket connection to server. */ 6057 "_FFR_DAEMON_NETUNIX", 6058 #endif /* _FFR_DAEMON_NETUNIX */ 6059 #if _FFR_DEPRECATE_MAILER_FLAG_I 6060 /* What it says :-) */ 6061 "_FFR_DEPRECATE_MAILER_FLAG_I", 6062 #endif /* _FFR_DEPRECATE_MAILER_FLAG_I */ 6063 #if _FFR_DM_ONE 6064 /* deliver first TA in background, then queue */ 6065 "_FFR_DM_ONE", 6066 #endif /* _FFR_DM_ONE */ 6067 #if _FFR_DIGUNIX_SAFECHOWN 6068 /* Properly set SAFECHOWN (include/sm/conf.h) for Digital UNIX */ 6069 /* Problem noted by Anne Bennett of Concordia University */ 6070 "_FFR_DIGUNIX_SAFECHOWN", 6071 #endif /* _FFR_DIGUNIX_SAFECHOWN */ 6072 #if _FFR_DNSMAP_ALIASABLE 6073 /* Allow dns map type to be used for aliases. */ 6074 /* Don Lewis of TDK */ 6075 "_FFR_DNSMAP_ALIASABLE", 6076 #endif /* _FFR_DNSMAP_ALIASABLE */ 6077 #if _FFR_DONTLOCKFILESFORREAD_OPTION 6078 /* Enable DontLockFilesForRead option. */ 6079 "_FFR_DONTLOCKFILESFORREAD_OPTION", 6080 #endif /* _FFR_DONTLOCKFILESFORREAD_OPTION */ 6081 #if _FFR_DOTTED_USERNAMES 6082 /* Allow usernames with '.' */ 6083 "_FFR_DOTTED_USERNAMES", 6084 #endif /* _FFR_DOTTED_USERNAMES */ 6085 #if _FFR_DPO_CS 6086 /* 6087 ** Make DaemonPortOptions case sensitive. 6088 ** For some unknown reasons the code converted every option 6089 ** to uppercase (first letter only, as that's the only one that 6090 ** is actually checked). This prevented all new lower case options 6091 ** from working... 6092 ** The documentation doesn't say anything about case (in)sensitivity, 6093 ** which means it should be case sensitive by default, 6094 ** but it's not a good idea to change this within a patch release, 6095 ** so let's delay this to 8.15. 6096 */ 6097 6098 "_FFR_DPO_CS", 6099 #endif /* _FFR_DPO_CS */ 6100 #if _FFR_DPRINTF_MAP 6101 /* dprintf map for logging */ 6102 "_FFR_DPRINTF_MAP", 6103 #endif /* _FFR_DPRINTF_MAP */ 6104 #if _FFR_DROP_TRUSTUSER_WARNING 6105 /* 6106 ** Don't issue this warning: 6107 ** "readcf: option TrustedUser may cause problems on systems 6108 ** which do not support fchown() if UseMSP is not set. 6109 */ 6110 6111 "_FFR_DROP_TRUSTUSER_WARNING", 6112 #endif /* _FFR_DROP_TRUSTUSER_WARNING */ 6113 #if _FFR_EIGHT_BIT_ADDR_OK 6114 /* EightBitAddrOK: allow 8-bit e-mail addresses */ 6115 "_FFR_EIGHT_BIT_ADDR_OK", 6116 #endif /* _FFR_EIGHT_BIT_ADDR_OK */ 6117 #if _FFR_EXTRA_MAP_CHECK 6118 /* perform extra checks on $( $) in R lines */ 6119 "_FFR_EXTRA_MAP_CHECK", 6120 #endif /* _FFR_EXTRA_MAP_CHECK */ 6121 #if _FFR_GETHBN_ExFILE 6122 /* 6123 ** According to Motonori Nakamura some gethostbyname() 6124 ** implementations (TurboLinux?) may (temporarily) fail 6125 ** due to a lack of file discriptors. Enabling this FFR 6126 ** will check errno for EMFILE and ENFILE and in case of a match 6127 ** cause a temporary error instead of a permanent error. 6128 ** The right solution is of course to file a bug against those 6129 ** systems such that they actually set h_errno = TRY_AGAIN. 6130 */ 6131 6132 "_FFR_GETHBN_ExFILE", 6133 #endif /* _FFR_GETHBN_ExFILE */ 6134 #if _FFR_FIX_DASHT 6135 /* 6136 ** If using -t, force not sending to argv recipients, even 6137 ** if they are mentioned in the headers. 6138 */ 6139 6140 "_FFR_FIX_DASHT", 6141 #endif /* _FFR_FIX_DASHT */ 6142 #if _FFR_FORWARD_SYSERR 6143 /* Cause a "syserr" if forward file isn't "safe". */ 6144 "_FFR_FORWARD_SYSERR", 6145 #endif /* _FFR_FORWARD_SYSERR */ 6146 #if _FFR_GEN_ORCPT 6147 /* Generate a ORCPT DSN arg if not already provided */ 6148 "_FFR_GEN_ORCPT", 6149 #endif /* _FFR_GEN_ORCPT */ 6150 #if _FFR_GROUPREADABLEAUTHINFOFILE 6151 /* Allow group readable DefaultAuthInfo file. */ 6152 "_FFR_GROUPREADABLEAUTHINFOFILE", 6153 #endif /* _FFR_GROUPREADABLEAUTHINFOFILE */ 6154 #if _FFR_HANDLE_ISO8859_GECOS 6155 /* 6156 ** Allow ISO 8859 characters in GECOS field: replace them 6157 ** ith ASCII "equivalent". 6158 */ 6159 6160 /* Peter Eriksson of Linkopings universitet */ 6161 "_FFR_HANDLE_ISO8859_GECOS", 6162 #endif /* _FFR_HANDLE_ISO8859_GECOS */ 6163 #if _FFR_HPUX_NSSWITCH 6164 /* Use nsswitch on HP-UX */ 6165 "_FFR_HPUX_NSSWITCH", 6166 #endif /* _FFR_HPUX_NSSWITCH */ 6167 #if _FFR_IGNORE_BOGUS_ADDR 6168 /* Ignore addresses for which prescan() failed */ 6169 "_FFR_IGNORE_BOGUS_ADDR", 6170 #endif /* _FFR_IGNORE_BOGUS_ADDR */ 6171 #if _FFR_IGNORE_EXT_ON_HELO 6172 /* Ignore extensions offered in response to HELO */ 6173 "_FFR_IGNORE_EXT_ON_HELO", 6174 #endif /* _FFR_IGNORE_EXT_ON_HELO */ 6175 #if _FFR_MAXDATASIZE 6176 /* 6177 ** It is possible that a header is larger than MILTER_CHUNK_SIZE, 6178 ** hence this shouldn't be used as limit for milter communication. 6179 ** see also libmilter/comm.c 6180 ** Gurusamy Sarathy of ActiveState 6181 */ 6182 6183 "_FFR_MAXDATASIZE", 6184 #endif /* _FFR_MAXDATASIZE */ 6185 #if _FFR_MAX_FORWARD_ENTRIES 6186 /* Try to limit number of .forward entries */ 6187 /* (doesn't work) */ 6188 /* Randall S. Winchester of the University of Maryland */ 6189 "_FFR_MAX_FORWARD_ENTRIES", 6190 #endif /* _FFR_MAX_FORWARD_ENTRIES */ 6191 #if _FFR_MAX_SLEEP_TIME 6192 /* Limit sleep(2) time in libsm/clock.c */ 6193 "_FFR_MAX_SLEEP_TIME", 6194 #endif /* _FFR_MAX_SLEEP_TIME */ 6195 #if _FFR_MEMSTAT 6196 /* Check free memory */ 6197 "_FFR_MEMSTAT", 6198 #endif /* _FFR_MEMSTAT */ 6199 #if _FFR_MILTER_CHECK 6200 "_FFR_MILTER_CHECK", 6201 #endif /* _FFR_MILTER_CHECK */ 6202 #if _FFR_MILTER_CONVERT_ALL_LF_TO_CRLF 6203 /* 6204 ** milter_body() uses the same conversion algorithm as putbody() 6205 ** to translate the "local" df format (\n) to SMTP format (\r\n). 6206 ** However, putbody() and mime8to7() use different conversion 6207 ** algorithms. 6208 ** If the input date does not follow the SMTP standard 6209 ** (e.g., if it has "naked \r"s), then the output from putbody() 6210 ** and mime8to7() will most likely be different. 6211 ** By turning on this FFR milter_body() will try to "imitate" 6212 ** mime8to7(). 6213 ** Note: there is no (simple) way to deal with both conversions 6214 ** in a consistent manner. Moreover, as the "GiGo" principle applies, 6215 ** it's not really worth to fix it. 6216 */ 6217 6218 "_FFR_MILTER_CONVERT_ALL_LF_TO_CRLF", 6219 #endif /* _FFR_MILTER_CONVERT_ALL_LF_TO_CRLF */ 6220 #if _FFR_MILTER_CHECK_REJECTIONS_TOO 6221 /* 6222 ** Also send RCPTs that are rejected by check_rcpt to a milter 6223 ** (if requested during option negotiation). 6224 */ 6225 6226 "_FFR_MILTER_CHECK_REJECTIONS_TOO", 6227 #endif /* _FFR_MILTER_CHECK_REJECTIONS_TOO */ 6228 #if _FFR_MIME7TO8_OLD 6229 /* Old mime7to8 code, the new is broken for at least one example. */ 6230 "_FFR_MIME7TO8_OLD", 6231 #endif /* _FFR_MAX_SLEEP_TIME */ 6232 #if _FFR_MORE_MACROS 6233 /* allow more long macro names ("unprintable" characters). */ 6234 "_FFR_MORE_MACROS", 6235 #endif /* _FFR_MORE_MACROS */ 6236 #if _FFR_MSG_ACCEPT 6237 /* allow to override "Message accepted for delivery" */ 6238 "_FFR_MSG_ACCEPT", 6239 #endif /* _FFR_MSG_ACCEPT */ 6240 #if _FFR_NODELAYDSN_ON_HOLD 6241 /* Do not issue a DELAY DSN for mailers that use the hold flag. */ 6242 /* Steven Pitzl */ 6243 "_FFR_NODELAYDSN_ON_HOLD", 6244 #endif /* _FFR_NODELAYDSN_ON_HOLD */ 6245 #if _FFR_NO_PIPE 6246 /* Disable PIPELINING, delay client if used. */ 6247 "_FFR_NO_PIPE", 6248 #endif /* _FFR_NO_PIPE */ 6249 #if _FFR_LDAP_NETWORK_TIMEOUT 6250 /* set LDAP_OPT_NETWORK_TIMEOUT if available (-c) */ 6251 "_FFR_LDAP_NETWORK_TIMEOUT", 6252 #endif /* _FFR_LDAP_NETWORK_TIMEOUT */ 6253 #if _FFR_LOG_NTRIES 6254 /* log ntries=, from Nik Clayton of FreeBSD */ 6255 "_FFR_LOG_NTRIES", 6256 #endif /* _FFR_LOG_NTRIES */ 6257 #if _FFR_QF_PARANOIA 6258 "_FFR_QF_PARANOIA", 6259 #endif /* _FFR_QF_PARANOIA */ 6260 #if _FFR_QUEUEDELAY 6261 /* Exponential queue delay; disabled in 8.13 since it isn't used. */ 6262 "_FFR_QUEUEDELAY", 6263 #endif /* _FFR_QUEUEDELAY */ 6264 #if _FFR_QUEUE_GROUP_SORTORDER 6265 /* Allow QueueSortOrder per queue group. */ 6266 /* XXX: Still need to actually use qgrp->qg_sortorder */ 6267 "_FFR_QUEUE_GROUP_SORTORDER", 6268 #endif /* _FFR_QUEUE_GROUP_SORTORDER */ 6269 #if _FFR_QUEUE_MACRO 6270 /* Define {queue} macro. */ 6271 "_FFR_QUEUE_MACRO", 6272 #endif /* _FFR_QUEUE_MACRO */ 6273 #if _FFR_QUEUE_RUN_PARANOIA 6274 /* Additional checks when doing queue runs; interval of checks */ 6275 "_FFR_QUEUE_RUN_PARANOIA", 6276 #endif /* _FFR_QUEUE_RUN_PARANOIA */ 6277 #if _FFR_QUEUE_SCHED_DBG 6278 /* Debug output for the queue scheduler. */ 6279 "_FFR_QUEUE_SCHED_DBG", 6280 #endif /* _FFR_QUEUE_SCHED_DBG */ 6281 #if _FFR_REDIRECTEMPTY 6282 /* 6283 ** envelope <> can't be sent to mailing lists, only owner- 6284 ** send spam of this type to owner- of the list 6285 ** ---- to stop spam from going to mailing lists. 6286 */ 6287 6288 "_FFR_REDIRECTEMPTY", 6289 #endif /* _FFR_REDIRECTEMPTY */ 6290 #if _FFR_RESET_MACRO_GLOBALS 6291 /* Allow macro 'j' to be set dynamically via rulesets. */ 6292 "_FFR_RESET_MACRO_GLOBALS", 6293 #endif /* _FFR_RESET_MACRO_GLOBALS */ 6294 #if _FFR_RHS 6295 /* Random shuffle for queue sorting. */ 6296 "_FFR_RHS", 6297 #endif /* _FFR_RHS */ 6298 #if _FFR_RUNPQG 6299 /* 6300 ** allow -qGqueue_group -qp to work, i.e., 6301 ** restrict a persistent queue runner to a queue group. 6302 */ 6303 6304 "_FFR_RUNPQG", 6305 #endif /* _FFR_RUNPQG */ 6306 #if _FFR_SESSID 6307 /* session id (for logging) */ 6308 "_FFR_SESSID", 6309 #endif /* _FFR_SESSID */ 6310 #if _FFR_SHM_STATUS 6311 /* Donated code (unused). */ 6312 "_FFR_SHM_STATUS", 6313 #endif /* _FFR_SHM_STATUS */ 6314 #if _FFR_LDAP_SINGLEDN 6315 /* 6316 ** The LDAP database map code in Sendmail 8.12.10, when 6317 ** given the -1 switch, would match only a single DN, 6318 ** but was able to return multiple attributes for that 6319 ** DN. In Sendmail 8.13 this "bug" was corrected to 6320 ** only return if exactly one attribute matched. 6321 ** 6322 ** Unfortunately, our configuration uses the former 6323 ** behaviour. Attached is a relatively simple patch 6324 ** to 8.13.4 which adds a -2 switch (for lack of a 6325 ** better option) which returns the single dn/multiple 6326 ** attributes. 6327 ** 6328 ** Jeffrey T. Eaton, Carnegie-Mellon University 6329 */ 6330 6331 "_FFR_LDAP_SINGLEDN", 6332 #endif /* _FFR_LDAP_SINGLEDN */ 6333 #if _FFR_SKIP_DOMAINS 6334 /* process every N'th domain instead of every N'th message */ 6335 "_FFR_SKIP_DOMAINS", 6336 #endif /* _FFR_SKIP_DOMAINS */ 6337 #if _FFR_SLEEP_USE_SELECT 6338 /* Use select(2) in libsm/clock.c to emulate sleep(2) */ 6339 "_FFR_SLEEP_USE_SELECT ", 6340 #endif /* _FFR_SLEEP_USE_SELECT */ 6341 #if _FFR_SPT_ALIGN 6342 /* 6343 ** It looks like the Compaq Tru64 5.1A now aligns argv and envp to 64 6344 ** bit alignment, so unless each piece of argv and envp is a multiple 6345 ** of 8 bytes (including terminating NULL), initsetproctitle() won't 6346 ** use any of the space beyond argv[0]. Be sure to set SPT_ALIGN_SIZE 6347 ** if you use this FFR. 6348 */ 6349 6350 /* Chris Adams of HiWAAY Informations Services */ 6351 "_FFR_SPT_ALIGN", 6352 #endif /* _FFR_SPT_ALIGN */ 6353 #if _FFR_SS_PER_DAEMON 6354 /* SuperSafe per DaemonPortOptions: 'T' (better letter?) */ 6355 "_FFR_SS_PER_DAEMON", 6356 #endif /* _FFR_SS_PER_DAEMON */ 6357 #if _FFR_TIMERS 6358 /* Donated code (unused). */ 6359 "_FFR_TIMERS", 6360 #endif /* _FFR_TIMERS */ 6361 #if _FFR_TLS_1 6362 /* More STARTTLS options, e.g., secondary certs. */ 6363 "_FFR_TLS_1", 6364 #endif /* _FFR_TLS_1 */ 6365 #if _FFR_TRUSTED_QF 6366 /* 6367 ** If we don't own the file mark it as unsafe. 6368 ** However, allow TrustedUser to own it as well 6369 ** in case TrustedUser manipulates the queue. 6370 */ 6371 6372 "_FFR_TRUSTED_QF", 6373 #endif /* _FFR_TRUSTED_QF */ 6374 #if _FFR_USE_SEM_LOCKING 6375 "_FFR_USE_SEM_LOCKING", 6376 #endif /* _FFR_USE_SEM_LOCKING */ 6377 #if _FFR_USE_SETLOGIN 6378 /* Use setlogin() */ 6379 /* Peter Philipp */ 6380 "_FFR_USE_SETLOGIN", 6381 #endif /* _FFR_USE_SETLOGIN */ 6382 NULL 6383 }; 6384 6385