1 /* 2 * Copyright (c) 1983, 1995 Eric P. Allman 3 * Copyright (c) 1988, 1993 4 * The Regents of the University of California. All rights reserved. 5 * 6 * %sccs.include.redist.c% 7 */ 8 9 #ifndef lint 10 static char sccsid[] = "@(#)conf.c 8.154 (Berkeley) 04/23/95"; 11 #endif /* not lint */ 12 13 # include "sendmail.h" 14 # include "pathnames.h" 15 # include <sys/ioctl.h> 16 # include <sys/param.h> 17 18 /* 19 ** CONF.C -- Sendmail Configuration Tables. 20 ** 21 ** Defines the configuration of this installation. 22 ** 23 ** Configuration Variables: 24 ** HdrInfo -- a table describing well-known header fields. 25 ** Each entry has the field name and some flags, 26 ** which are described in sendmail.h. 27 ** 28 ** Notes: 29 ** I have tried to put almost all the reasonable 30 ** configuration information into the configuration 31 ** file read at runtime. My intent is that anything 32 ** here is a function of the version of UNIX you 33 ** are running, or is really static -- for example 34 ** the headers are a superset of widely used 35 ** protocols. If you find yourself playing with 36 ** this file too much, you may be making a mistake! 37 */ 38 39 40 41 42 /* 43 ** Header info table 44 ** Final (null) entry contains the flags used for any other field. 45 ** 46 ** Not all of these are actually handled specially by sendmail 47 ** at this time. They are included as placeholders, to let 48 ** you know that "someday" I intend to have sendmail do 49 ** something with them. 50 */ 51 52 struct hdrinfo HdrInfo[] = 53 { 54 /* originator fields, most to least significant */ 55 "resent-sender", H_FROM|H_RESENT, 56 "resent-from", H_FROM|H_RESENT, 57 "resent-reply-to", H_FROM|H_RESENT, 58 "sender", H_FROM, 59 "from", H_FROM, 60 "reply-to", H_FROM, 61 "full-name", H_ACHECK, 62 "return-receipt-to", H_FROM|H_RECEIPTTO, 63 "errors-to", H_FROM|H_ERRORSTO, 64 65 /* destination fields */ 66 "to", H_RCPT, 67 "resent-to", H_RCPT|H_RESENT, 68 "cc", H_RCPT, 69 "resent-cc", H_RCPT|H_RESENT, 70 "bcc", H_RCPT|H_STRIPVAL, 71 "resent-bcc", H_RCPT|H_STRIPVAL|H_RESENT, 72 "apparently-to", H_RCPT, 73 74 /* message identification and control */ 75 "message-id", 0, 76 "resent-message-id", H_RESENT, 77 "message", H_EOH, 78 "text", H_EOH, 79 80 /* date fields */ 81 "date", 0, 82 "resent-date", H_RESENT, 83 84 /* trace fields */ 85 "received", H_TRACE|H_FORCE, 86 "x400-received", H_TRACE|H_FORCE, 87 "via", H_TRACE|H_FORCE, 88 "mail-from", H_TRACE|H_FORCE, 89 90 /* miscellaneous fields */ 91 "comments", H_FORCE, 92 "return-path", H_FORCE|H_ACHECK, 93 "content-transfer-encoding", H_CTE, 94 "content-type", H_CTYPE, 95 "content-length", H_ACHECK, 96 97 NULL, 0, 98 }; 99 100 101 102 /* 103 ** Location of system files/databases/etc. 104 */ 105 106 char *PidFile = _PATH_SENDMAILPID; /* stores daemon proc id */ 107 108 109 110 /* 111 ** Privacy values 112 */ 113 114 struct prival PrivacyValues[] = 115 { 116 "public", PRIV_PUBLIC, 117 "needmailhelo", PRIV_NEEDMAILHELO, 118 "needexpnhelo", PRIV_NEEDEXPNHELO, 119 "needvrfyhelo", PRIV_NEEDVRFYHELO, 120 "noexpn", PRIV_NOEXPN, 121 "novrfy", PRIV_NOVRFY, 122 "restrictmailq", PRIV_RESTRICTMAILQ, 123 "restrictqrun", PRIV_RESTRICTQRUN, 124 "authwarnings", PRIV_AUTHWARNINGS, 125 "noreceipts", PRIV_NORECEIPTS, 126 "goaway", PRIV_GOAWAY, 127 NULL, 0, 128 }; 129 130 131 132 /* 133 ** Miscellaneous stuff. 134 */ 135 136 int DtableSize = 50; /* max open files; reset in 4.2bsd */ 137 /* 138 ** SETDEFAULTS -- set default values 139 ** 140 ** Because of the way freezing is done, these must be initialized 141 ** using direct code. 142 ** 143 ** Parameters: 144 ** e -- the default envelope. 145 ** 146 ** Returns: 147 ** none. 148 ** 149 ** Side Effects: 150 ** Initializes a bunch of global variables to their 151 ** default values. 152 */ 153 154 #define DAYS * 24 * 60 * 60 155 156 void 157 setdefaults(e) 158 register ENVELOPE *e; 159 { 160 int i; 161 extern void inittimeouts(); 162 extern void setdefuser(); 163 extern void setupmaps(); 164 extern void setupmailers(); 165 166 SpaceSub = ' '; /* option B */ 167 QueueLA = 8; /* option x */ 168 RefuseLA = 12; /* option X */ 169 WkRecipFact = 30000L; /* option y */ 170 WkClassFact = 1800L; /* option z */ 171 WkTimeFact = 90000L; /* option Z */ 172 QueueFactor = WkRecipFact * 20; /* option q */ 173 FileMode = (RealUid != geteuid()) ? 0644 : 0600; 174 /* option F */ 175 DefUid = 1; /* option u */ 176 DefGid = 1; /* option g */ 177 CheckpointInterval = 10; /* option C */ 178 MaxHopCount = 25; /* option h */ 179 e->e_sendmode = SM_FORK; /* option d */ 180 e->e_errormode = EM_PRINT; /* option e */ 181 SevenBitInput = FALSE; /* option 7 */ 182 MaxMciCache = 1; /* option k */ 183 MciCacheTimeout = 300; /* option K */ 184 LogLevel = 9; /* option L */ 185 inittimeouts(NULL); /* option r */ 186 PrivacyFlags = 0; /* option p */ 187 MimeMode = MM_CVTMIME|MM_PASS8BIT; /* option 8 */ 188 for (i = 0; i < MAXTOCLASS; i++) 189 { 190 TimeOuts.to_q_return[i] = 5 DAYS; /* option T */ 191 TimeOuts.to_q_warning[i] = 0; /* option T */ 192 } 193 ServiceSwitchFile = "/etc/service.switch"; 194 setdefuser(); 195 setupmaps(); 196 setupmailers(); 197 } 198 199 200 /* 201 ** SETDEFUSER -- set/reset DefUser using DefUid (for initgroups()) 202 */ 203 204 void 205 setdefuser() 206 { 207 struct passwd *defpwent; 208 static char defuserbuf[40]; 209 210 DefUser = defuserbuf; 211 if ((defpwent = sm_getpwuid(DefUid)) != NULL) 212 strcpy(defuserbuf, defpwent->pw_name); 213 else 214 strcpy(defuserbuf, "nobody"); 215 } 216 /* 217 ** HOST_MAP_INIT -- initialize host class structures 218 */ 219 220 bool host_map_init __P((MAP *map, char *args)); 221 222 bool 223 host_map_init(map, args) 224 MAP *map; 225 char *args; 226 { 227 register char *p = args; 228 229 for (;;) 230 { 231 while (isascii(*p) && isspace(*p)) 232 p++; 233 if (*p != '-') 234 break; 235 switch (*++p) 236 { 237 case 'a': 238 map->map_app = ++p; 239 break; 240 } 241 while (*p != '\0' && !(isascii(*p) && isspace(*p))) 242 p++; 243 if (*p != '\0') 244 *p++ = '\0'; 245 } 246 if (map->map_app != NULL) 247 map->map_app = newstr(map->map_app); 248 return TRUE; 249 } 250 /* 251 ** SETUPMAILERS -- initialize default mailers 252 */ 253 254 void 255 setupmailers() 256 { 257 char buf[100]; 258 extern void makemailer(); 259 260 strcpy(buf, "prog, P=/bin/sh, F=lsoD, T=X-Unix, A=sh -c $u"); 261 makemailer(buf); 262 263 strcpy(buf, "*file*, P=/dev/null, F=lsDFMPEou, T=X-Unix, A=FILE"); 264 makemailer(buf); 265 266 strcpy(buf, "*include*, P=/dev/null, F=su, A=INCLUDE"); 267 makemailer(buf); 268 } 269 /* 270 ** SETUPMAPS -- set up map classes 271 */ 272 273 #define MAPDEF(name, ext, flags, parse, open, close, lookup, store) \ 274 { \ 275 extern bool parse __P((MAP *, char *)); \ 276 extern bool open __P((MAP *, int)); \ 277 extern void close __P((MAP *)); \ 278 extern char *lookup __P((MAP *, char *, char **, int *)); \ 279 extern void store __P((MAP *, char *, char *)); \ 280 s = stab(name, ST_MAPCLASS, ST_ENTER); \ 281 s->s_mapclass.map_cname = name; \ 282 s->s_mapclass.map_ext = ext; \ 283 s->s_mapclass.map_cflags = flags; \ 284 s->s_mapclass.map_parse = parse; \ 285 s->s_mapclass.map_open = open; \ 286 s->s_mapclass.map_close = close; \ 287 s->s_mapclass.map_lookup = lookup; \ 288 s->s_mapclass.map_store = store; \ 289 } 290 291 void 292 setupmaps() 293 { 294 register STAB *s; 295 296 #ifdef NEWDB 297 MAPDEF("hash", ".db", MCF_ALIASOK|MCF_REBUILDABLE, 298 map_parseargs, hash_map_open, db_map_close, 299 db_map_lookup, db_map_store); 300 301 MAPDEF("btree", ".db", MCF_ALIASOK|MCF_REBUILDABLE, 302 map_parseargs, bt_map_open, db_map_close, 303 db_map_lookup, db_map_store); 304 #endif 305 306 #ifdef NDBM 307 MAPDEF("dbm", ".dir", MCF_ALIASOK|MCF_REBUILDABLE, 308 map_parseargs, ndbm_map_open, ndbm_map_close, 309 ndbm_map_lookup, ndbm_map_store); 310 #endif 311 312 #ifdef NIS 313 MAPDEF("nis", NULL, MCF_ALIASOK, 314 map_parseargs, nis_map_open, null_map_close, 315 nis_map_lookup, null_map_store); 316 #endif 317 318 #ifdef NISPLUS 319 MAPDEF("nisplus", NULL, MCF_ALIASOK, 320 map_parseargs, nisplus_map_open, null_map_close, 321 nisplus_map_lookup, null_map_store); 322 #endif 323 324 #ifdef HESIOD 325 MAPDEF("hesiod", NULL, MCF_ALIASOK|MCF_ALIASONLY, 326 map_parseargs, null_map_open, null_map_close, 327 hes_map_lookup, null_map_store); 328 #endif 329 330 #ifdef NETINFO 331 MAPDEF("netinfo", NULL, MCF_ALIASOK, 332 map_parseargs, ni_map_open, null_map_close, 333 ni_map_lookup, null_map_store); 334 #endif 335 336 #if 0 337 MAPDEF("dns", NULL, 0, 338 dns_map_init, null_map_open, null_map_close, 339 dns_map_lookup, null_map_store); 340 #endif 341 342 #if NAMED_BIND 343 /* best MX DNS lookup */ 344 MAPDEF("bestmx", NULL, MCF_OPTFILE, 345 map_parseargs, null_map_open, null_map_close, 346 bestmx_map_lookup, null_map_store); 347 #endif 348 349 MAPDEF("host", NULL, 0, 350 host_map_init, null_map_open, null_map_close, 351 host_map_lookup, null_map_store); 352 353 MAPDEF("text", NULL, MCF_ALIASOK, 354 map_parseargs, text_map_open, null_map_close, 355 text_map_lookup, null_map_store); 356 357 MAPDEF("stab", NULL, MCF_ALIASOK|MCF_ALIASONLY, 358 map_parseargs, stab_map_open, null_map_close, 359 stab_map_lookup, stab_map_store); 360 361 MAPDEF("implicit", NULL, MCF_ALIASOK|MCF_ALIASONLY|MCF_REBUILDABLE, 362 map_parseargs, impl_map_open, impl_map_close, 363 impl_map_lookup, impl_map_store); 364 365 /* access to system passwd file */ 366 MAPDEF("user", NULL, MCF_OPTFILE, 367 map_parseargs, user_map_open, null_map_close, 368 user_map_lookup, null_map_store); 369 370 /* dequote map */ 371 MAPDEF("dequote", NULL, 0, 372 dequote_init, null_map_open, null_map_close, 373 dequote_map, null_map_store); 374 375 #ifdef USERDB 376 /* user database */ 377 MAPDEF("userdb", ".db", 0, 378 map_parseargs, null_map_open, null_map_close, 379 udb_map_lookup, null_map_store); 380 #endif 381 382 /* sequenced maps */ 383 MAPDEF("sequence", NULL, MCF_ALIASOK, 384 seq_map_parse, null_map_open, null_map_close, 385 seq_map_lookup, seq_map_store); 386 387 /* switched interface to sequenced maps */ 388 MAPDEF("switch", NULL, MCF_ALIASOK, 389 map_parseargs, switch_map_open, null_map_close, 390 seq_map_lookup, seq_map_store); 391 } 392 393 #undef MAPDEF 394 /* 395 ** INITHOSTMAPS -- initial host-dependent maps 396 ** 397 ** This should act as an interface to any local service switch 398 ** provided by the host operating system. 399 ** 400 ** Parameters: 401 ** none 402 ** 403 ** Returns: 404 ** none 405 ** 406 ** Side Effects: 407 ** Should define maps "host" and "users" as necessary 408 ** for this OS. If they are not defined, they will get 409 ** a default value later. It should check to make sure 410 ** they are not defined first, since it's possible that 411 ** the config file has provided an override. 412 */ 413 414 void 415 inithostmaps() 416 { 417 register int i; 418 int nmaps; 419 char *maptype[MAXMAPSTACK]; 420 short mapreturn[MAXMAPACTIONS]; 421 char buf[MAXLINE]; 422 423 /* 424 ** Set up default hosts maps. 425 */ 426 427 #if 0 428 nmaps = switch_map_find("hosts", maptype, mapreturn); 429 for (i = 0; i < nmaps; i++) 430 { 431 if (strcmp(maptype[i], "files") == 0 && 432 stab("hosts.files", ST_MAP, ST_FIND) == NULL) 433 { 434 strcpy(buf, "hosts.files text -k 0 -v 1 /etc/hosts"); 435 makemapentry(buf); 436 } 437 #if NAMED_BIND 438 else if (strcmp(maptype[i], "dns") == 0 && 439 stab("hosts.dns", ST_MAP, ST_FIND) == NULL) 440 { 441 strcpy(buf, "hosts.dns dns A"); 442 makemapentry(buf); 443 } 444 #endif 445 #ifdef NISPLUS 446 else if (strcmp(maptype[i], "nisplus") == 0 && 447 stab("hosts.nisplus", ST_MAP, ST_FIND) == NULL) 448 { 449 strcpy(buf, "hosts.nisplus nisplus -k name -v address -d hosts.org_dir"); 450 makemapentry(buf); 451 } 452 #endif 453 #ifdef NIS 454 else if (strcmp(maptype[i], "nis") == 0 && 455 stab("hosts.nis", ST_MAP, ST_FIND) == NULL) 456 { 457 strcpy(buf, "hosts.nis nis -d -k 0 -v 1 hosts.byname"); 458 makemapentry(buf); 459 } 460 #endif 461 } 462 #endif 463 464 /* 465 ** Make sure we have a host map. 466 */ 467 468 if (stab("host", ST_MAP, ST_FIND) == NULL) 469 { 470 /* user didn't initialize: set up host map */ 471 strcpy(buf, "host host"); 472 #if NAMED_BIND 473 if (ConfigLevel >= 2) 474 strcat(buf, " -a."); 475 #endif 476 makemapentry(buf); 477 } 478 479 /* 480 ** Set up default aliases maps 481 */ 482 483 nmaps = switch_map_find("aliases", maptype, mapreturn); 484 for (i = 0; i < nmaps; i++) 485 { 486 if (strcmp(maptype[i], "files") == 0 && 487 stab("aliases.files", ST_MAP, ST_FIND) == NULL) 488 { 489 strcpy(buf, "aliases.files implicit /etc/aliases"); 490 makemapentry(buf); 491 } 492 #ifdef NISPLUS 493 else if (strcmp(maptype[i], "nisplus") == 0 && 494 stab("aliases.nisplus", ST_MAP, ST_FIND) == NULL) 495 { 496 strcpy(buf, "aliases.nisplus nisplus -kalias -vexpansion -d mail_aliases.org_dir"); 497 makemapentry(buf); 498 } 499 #endif 500 #ifdef NIS 501 else if (strcmp(maptype[i], "nis") == 0 && 502 stab("aliases.nis", ST_MAP, ST_FIND) == NULL) 503 { 504 strcpy(buf, "aliases.nis nis -d mail.aliases"); 505 makemapentry(buf); 506 } 507 #endif 508 } 509 if (stab("aliases", ST_MAP, ST_FIND) == NULL) 510 { 511 strcpy(buf, "aliases switch aliases"); 512 makemapentry(buf); 513 } 514 strcpy(buf, "switch:aliases"); 515 setalias(buf); 516 517 #if 0 /* "user" map class is a better choice */ 518 /* 519 ** Set up default users maps. 520 */ 521 522 nmaps = switch_map_find("passwd", maptype, mapreturn); 523 for (i = 0; i < nmaps; i++) 524 { 525 if (strcmp(maptype[i], "files") == 0 && 526 stab("users.files", ST_MAP, ST_FIND) == NULL) 527 { 528 strcpy(buf, "users.files text -m -z: -k0 -v6 /etc/passwd"); 529 makemapentry(buf); 530 } 531 #ifdef NISPLUS 532 else if (strcmp(maptype[i], "nisplus") == 0 && 533 stab("users.nisplus", ST_MAP, ST_FIND) == NULL) 534 { 535 strcpy(buf, "users.nisplus nisplus -m -kname -vhome -d passwd.org_dir"); 536 makemapentry(buf); 537 } 538 #endif 539 #ifdef NIS 540 else if (strcmp(maptype[i], "nis") == 0 && 541 stab("users.nis", ST_MAP, ST_FIND) == NULL) 542 { 543 strcpy(buf, "users.nis nis -m -d passwd.byname"); 544 makemapentry(buf); 545 } 546 #endif 547 #ifdef HESIOD 548 else if (strcmp(maptype[i], "hesiod") == 0) && 549 stab("users.hesiod", ST_MAP, ST_FIND) == NULL) 550 { 551 strcpy(buf, "users.hesiod hesiod"); 552 makemapentry(buf); 553 } 554 #endif 555 } 556 if (stab("users", ST_MAP, ST_FIND) == NULL) 557 { 558 strcpy(buf, "users switch -m passwd"); 559 makemapentry(buf); 560 } 561 #endif 562 } 563 /* 564 ** SWITCH_MAP_FIND -- find the list of types associated with a map 565 ** 566 ** This is the system-dependent interface to the service switch. 567 ** 568 ** Parameters: 569 ** service -- the name of the service of interest. 570 ** maptype -- an out-array of strings containing the types 571 ** of access to use for this service. There can 572 ** be at most MAXMAPSTACK types for a single service. 573 ** mapreturn -- an out-array of return information bitmaps 574 ** for the map. 575 ** 576 ** Returns: 577 ** The number of map types filled in, or -1 for failure. 578 */ 579 580 #ifdef SOLARIS 581 # include <nsswitch.h> 582 #endif 583 584 #if defined(ultrix) || defined(__osf__) 585 # include <sys/svcinfo.h> 586 #endif 587 588 int 589 switch_map_find(service, maptype, mapreturn) 590 char *service; 591 char *maptype[MAXMAPSTACK]; 592 short mapreturn[MAXMAPACTIONS]; 593 { 594 register FILE *fp; 595 int svcno; 596 static char buf[MAXLINE]; 597 598 #ifdef SOLARIS 599 struct __nsw_switchconfig *nsw_conf; 600 enum __nsw_parse_err pserr; 601 struct __nsw_lookup *lk; 602 int nsw_rc; 603 static struct __nsw_lookup lkp0 = 604 { "files", {1, 0, 0, 0}, NULL, NULL }; 605 static struct __nsw_switchconfig lkp_default = 606 { 0, "sendmail", 3, &lkp0 }; 607 608 if ((nsw_conf = __nsw_getconfig(service, &pserr)) == NULL) 609 lk = lkp_default.lookups; 610 else 611 lk = nsw_conf->lookups; 612 svcno = 0; 613 while (lk != NULL) 614 { 615 maptype[svcno] = lk->service_name; 616 if (lk->actions[__NSW_NOTFOUND] == __NSW_RETURN) 617 mapreturn[MA_NOTFOUND] |= 1 << svcno; 618 if (lk->actions[__NSW_TRYAGAIN] == __NSW_RETURN) 619 mapreturn[MA_TRYAGAIN] |= 1 << svcno; 620 if (lk->actions[__NSW_UNAVAIL] == __NSW_RETURN) 621 mapreturn[MA_TRYAGAIN] |= 1 << svcno; 622 svcno++; 623 lk = lk->next; 624 } 625 return svcno; 626 #endif 627 628 #if defined(ultrix) || defined(__osf__) 629 struct svcinfo *svcinfo; 630 int svc; 631 632 svcinfo = getsvc(); 633 if (svcinfo == NULL) 634 goto punt; 635 if (strcmp(service, "hosts") == 0) 636 svc = SVC_HOSTS; 637 else if (strcmp(service, "aliases") == 0) 638 svc = SVC_ALIASES; 639 else if (strcmp(service, "passwd") == 0) 640 svc = SVC_PASSWD; 641 else 642 return -1; 643 for (svcno = 0; svcno < SVC_PATHSIZE; svcno++) 644 { 645 switch (svcinfo->svcpath[svc][svcno]) 646 { 647 case SVC_LOCAL: 648 maptype[svcno] = "files"; 649 break; 650 651 case SVC_YP: 652 maptype[svcno] = "nis"; 653 break; 654 655 case SVC_BIND: 656 maptype[svcno] = "dns"; 657 break; 658 659 #ifdef SVC_HESIOD 660 case SVC_HESIOD: 661 maptype[svcno] = "hesiod"; 662 break; 663 #endif 664 665 case SVC_LAST: 666 return svcno; 667 } 668 } 669 return svcno; 670 #endif 671 672 #if !defined(SOLARIS) && !defined(ultrix) && !defined(__osf__) 673 /* 674 ** Fall-back mechanism. 675 */ 676 677 svcno = 0; 678 fp = fopen(ServiceSwitchFile, "r"); 679 if (fp != NULL) 680 { 681 while (fgets(buf, sizeof buf, fp) != NULL) 682 { 683 register char *p; 684 685 p = strpbrk(buf, "#\n"); 686 if (p != NULL) 687 *p = '\0'; 688 p = strpbrk(buf, " \t"); 689 if (p != NULL) 690 *p++ = '\0'; 691 if (strcmp(buf, service) != 0) 692 continue; 693 694 /* got the right service -- extract data */ 695 do 696 { 697 while (isspace(*p)) 698 p++; 699 if (*p == '\0') 700 break; 701 maptype[svcno++] = p; 702 p = strpbrk(p, " \t"); 703 if (p != NULL) 704 *p++ = '\0'; 705 } while (p != NULL); 706 break; 707 } 708 fclose(fp); 709 return svcno; 710 } 711 #endif 712 713 /* if the service file doesn't work, use an absolute fallback */ 714 punt: 715 if (strcmp(service, "aliases") == 0) 716 { 717 maptype[svcno++] = "files"; 718 #ifdef AUTO_NIS_ALIASES 719 # ifdef NISPLUS 720 maptype[svcno++] = "nisplus"; 721 # endif 722 # ifdef NIS 723 maptype[svcno++] = "nis"; 724 # endif 725 #endif 726 return svcno; 727 } 728 if (strcmp(service, "hosts") == 0) 729 { 730 # if NAMED_BIND 731 maptype[svcno++] = "dns"; 732 # else 733 # if defined(sun) && !defined(BSD) && !defined(SOLARIS) 734 /* SunOS */ 735 maptype[svcno++] = "nis"; 736 # endif 737 # endif 738 maptype[svcno++] = "files"; 739 return svcno; 740 } 741 return -1; 742 } 743 /* 744 ** USERNAME -- return the user id of the logged in user. 745 ** 746 ** Parameters: 747 ** none. 748 ** 749 ** Returns: 750 ** The login name of the logged in user. 751 ** 752 ** Side Effects: 753 ** none. 754 ** 755 ** Notes: 756 ** The return value is statically allocated. 757 */ 758 759 char * 760 username() 761 { 762 static char *myname = NULL; 763 extern char *getlogin(); 764 register struct passwd *pw; 765 766 /* cache the result */ 767 if (myname == NULL) 768 { 769 myname = getlogin(); 770 if (myname == NULL || myname[0] == '\0') 771 { 772 pw = sm_getpwuid(RealUid); 773 if (pw != NULL) 774 myname = newstr(pw->pw_name); 775 } 776 else 777 { 778 uid_t uid = RealUid; 779 780 myname = newstr(myname); 781 if ((pw = sm_getpwnam(myname)) == NULL || 782 (uid != 0 && uid != pw->pw_uid)) 783 { 784 pw = sm_getpwuid(uid); 785 if (pw != NULL) 786 myname = newstr(pw->pw_name); 787 } 788 } 789 if (myname == NULL || myname[0] == '\0') 790 { 791 syserr("554 Who are you?"); 792 myname = "postmaster"; 793 } 794 } 795 796 return (myname); 797 } 798 /* 799 ** TTYPATH -- Get the path of the user's tty 800 ** 801 ** Returns the pathname of the user's tty. Returns NULL if 802 ** the user is not logged in or if s/he has write permission 803 ** denied. 804 ** 805 ** Parameters: 806 ** none 807 ** 808 ** Returns: 809 ** pathname of the user's tty. 810 ** NULL if not logged in or write permission denied. 811 ** 812 ** Side Effects: 813 ** none. 814 ** 815 ** WARNING: 816 ** Return value is in a local buffer. 817 ** 818 ** Called By: 819 ** savemail 820 */ 821 822 char * 823 ttypath() 824 { 825 struct stat stbuf; 826 register char *pathn; 827 extern char *ttyname(); 828 extern char *getlogin(); 829 830 /* compute the pathname of the controlling tty */ 831 if ((pathn = ttyname(2)) == NULL && (pathn = ttyname(1)) == NULL && 832 (pathn = ttyname(0)) == NULL) 833 { 834 errno = 0; 835 return (NULL); 836 } 837 838 /* see if we have write permission */ 839 if (stat(pathn, &stbuf) < 0 || !bitset(02, stbuf.st_mode)) 840 { 841 errno = 0; 842 return (NULL); 843 } 844 845 /* see if the user is logged in */ 846 if (getlogin() == NULL) 847 return (NULL); 848 849 /* looks good */ 850 return (pathn); 851 } 852 /* 853 ** CHECKCOMPAT -- check for From and To person compatible. 854 ** 855 ** This routine can be supplied on a per-installation basis 856 ** to determine whether a person is allowed to send a message. 857 ** This allows restriction of certain types of internet 858 ** forwarding or registration of users. 859 ** 860 ** If the hosts are found to be incompatible, an error 861 ** message should be given using "usrerr" and an EX_ code 862 ** should be returned. You can also set to->q_status to 863 ** a DSN-style status code. 864 ** 865 ** EF_NO_BODY_RETN can be set in e->e_flags to suppress the 866 ** body during the return-to-sender function; this should be done 867 ** on huge messages. This bit may already be set by the ESMTP 868 ** protocol. 869 ** 870 ** Parameters: 871 ** to -- the person being sent to. 872 ** 873 ** Returns: 874 ** an exit status 875 ** 876 ** Side Effects: 877 ** none (unless you include the usrerr stuff) 878 */ 879 880 int 881 checkcompat(to, e) 882 register ADDRESS *to; 883 register ENVELOPE *e; 884 { 885 # ifdef lint 886 if (to == NULL) 887 to++; 888 # endif /* lint */ 889 890 if (tTd(49, 1)) 891 printf("checkcompat(to=%s, from=%s)\n", 892 to->q_paddr, e->e_from.q_paddr); 893 894 # ifdef EXAMPLE_CODE 895 /* this code is intended as an example only */ 896 register STAB *s; 897 898 s = stab("arpa", ST_MAILER, ST_FIND); 899 if (s != NULL && strcmp(e->e_from.q_mailer->m_name, "local") != 0 && 900 to->q_mailer == s->s_mailer) 901 { 902 usrerr("553 No ARPA mail through this machine: see your system administration"); 903 /* e->e_flags |= EF_NO_BODY_RETN; to supress body on return */ 904 to->q_status = "5.7.1"; 905 return (EX_UNAVAILABLE); 906 } 907 # endif /* EXAMPLE_CODE */ 908 return (EX_OK); 909 } 910 /* 911 ** SETSIGNAL -- set a signal handler 912 ** 913 ** This is essentially old BSD "signal(3)". 914 */ 915 916 sigfunc_t 917 setsignal(sig, handler) 918 int sig; 919 sigfunc_t handler; 920 { 921 #if defined(SYS5SIGNALS) || defined(BSD4_3) || defined(_AUX_SOURCE) 922 return signal(sig, handler); 923 #else 924 struct sigaction n, o; 925 926 bzero(&n, sizeof n); 927 n.sa_handler = handler; 928 # ifdef SA_RESTART 929 n.sa_flags = SA_RESTART; 930 # endif 931 if (sigaction(sig, &n, &o) < 0) 932 return SIG_ERR; 933 return o.sa_handler; 934 #endif 935 } 936 /* 937 ** HOLDSIGS -- arrange to hold all signals 938 ** 939 ** Parameters: 940 ** none. 941 ** 942 ** Returns: 943 ** none. 944 ** 945 ** Side Effects: 946 ** Arranges that signals are held. 947 */ 948 949 void 950 holdsigs() 951 { 952 } 953 /* 954 ** RLSESIGS -- arrange to release all signals 955 ** 956 ** This undoes the effect of holdsigs. 957 ** 958 ** Parameters: 959 ** none. 960 ** 961 ** Returns: 962 ** none. 963 ** 964 ** Side Effects: 965 ** Arranges that signals are released. 966 */ 967 968 void 969 rlsesigs() 970 { 971 } 972 /* 973 ** INIT_MD -- do machine dependent initializations 974 ** 975 ** Systems that have global modes that should be set should do 976 ** them here rather than in main. 977 */ 978 979 #ifdef _AUX_SOURCE 980 # include <compat.h> 981 #endif 982 983 void 984 init_md(argc, argv) 985 int argc; 986 char **argv; 987 { 988 #ifdef _AUX_SOURCE 989 setcompat(getcompat() | COMPAT_BSDPROT); 990 #endif 991 992 #ifdef VENDOR_DEFAULT 993 VendorCode = VENDOR_DEFAULT; 994 #else 995 VendorCode = VENDOR_BERKELEY; 996 #endif 997 } 998 /* 999 ** INIT_VENDOR_MACROS -- vendor-dependent macro initializations 1000 ** 1001 ** Called once, on startup. 1002 ** 1003 ** Parameters: 1004 ** e -- the global envelope. 1005 ** 1006 ** Returns: 1007 ** none. 1008 ** 1009 ** Side Effects: 1010 ** vendor-dependent. 1011 */ 1012 1013 void 1014 init_vendor_macros(e) 1015 register ENVELOPE *e; 1016 { 1017 } 1018 /* 1019 ** GETLA -- get the current load average 1020 ** 1021 ** This code stolen from la.c. 1022 ** 1023 ** Parameters: 1024 ** none. 1025 ** 1026 ** Returns: 1027 ** The current load average as an integer. 1028 ** 1029 ** Side Effects: 1030 ** none. 1031 */ 1032 1033 /* try to guess what style of load average we have */ 1034 #define LA_ZERO 1 /* always return load average as zero */ 1035 #define LA_INT 2 /* read kmem for avenrun; interpret as long */ 1036 #define LA_FLOAT 3 /* read kmem for avenrun; interpret as float */ 1037 #define LA_SUBR 4 /* call getloadavg */ 1038 #define LA_MACH 5 /* MACH load averages (as on NeXT boxes) */ 1039 #define LA_SHORT 6 /* read kmem for avenrun; interpret as short */ 1040 #define LA_PROCSTR 7 /* read string ("1.17") from /proc/loadavg */ 1041 1042 /* do guesses based on general OS type */ 1043 #ifndef LA_TYPE 1044 # define LA_TYPE LA_ZERO 1045 #endif 1046 1047 #if (LA_TYPE == LA_INT) || (LA_TYPE == LA_FLOAT) || (LA_TYPE == LA_SHORT) 1048 1049 #include <nlist.h> 1050 1051 #ifdef IRIX64 1052 # define nlist nlist64 1053 #endif 1054 1055 #ifndef LA_AVENRUN 1056 # ifdef SYSTEM5 1057 # define LA_AVENRUN "avenrun" 1058 # else 1059 # define LA_AVENRUN "_avenrun" 1060 # endif 1061 #endif 1062 1063 /* _PATH_UNIX should be defined in <paths.h> */ 1064 #ifndef _PATH_UNIX 1065 # if defined(SYSTEM5) 1066 # define _PATH_UNIX "/unix" 1067 # else 1068 # define _PATH_UNIX "/vmunix" 1069 # endif 1070 #endif 1071 1072 struct nlist Nl[] = 1073 { 1074 { LA_AVENRUN }, 1075 #define X_AVENRUN 0 1076 { 0 }, 1077 }; 1078 1079 #ifndef FSHIFT 1080 # if defined(unixpc) 1081 # define FSHIFT 5 1082 # endif 1083 1084 # if defined(__alpha) || defined(IRIX) 1085 # define FSHIFT 10 1086 # endif 1087 1088 # if defined(_AIX3) 1089 # define FSHIFT 16 1090 # endif 1091 #endif 1092 1093 #ifndef FSHIFT 1094 # define FSHIFT 8 1095 #endif 1096 1097 #ifndef FSCALE 1098 # define FSCALE (1 << FSHIFT) 1099 #endif 1100 1101 getla() 1102 { 1103 static int kmem = -1; 1104 #if LA_TYPE == LA_INT 1105 long avenrun[3]; 1106 #else 1107 # if LA_TYPE == LA_SHORT 1108 short avenrun[3]; 1109 # else 1110 double avenrun[3]; 1111 # endif 1112 #endif 1113 extern off_t lseek(); 1114 extern int errno; 1115 1116 if (kmem < 0) 1117 { 1118 kmem = open("/dev/kmem", 0, 0); 1119 if (kmem < 0) 1120 { 1121 if (tTd(3, 1)) 1122 printf("getla: open(/dev/kmem): %s\n", 1123 errstring(errno)); 1124 return (-1); 1125 } 1126 (void) fcntl(kmem, F_SETFD, 1); 1127 #ifdef _AIX3 1128 if (knlist(Nl, 1, sizeof Nl[0]) < 0) 1129 #else 1130 if (nlist(_PATH_UNIX, Nl) < 0) 1131 #endif 1132 { 1133 if (tTd(3, 1)) 1134 printf("getla: nlist(%s): %s\n", _PATH_UNIX, 1135 errstring(errno)); 1136 return (-1); 1137 } 1138 if (Nl[X_AVENRUN].n_value == 0) 1139 { 1140 if (tTd(3, 1)) 1141 printf("getla: nlist(%s, %s) ==> 0\n", 1142 _PATH_UNIX, LA_AVENRUN); 1143 return (-1); 1144 } 1145 #ifdef NAMELISTMASK 1146 Nl[X_AVENRUN].n_value &= NAMELISTMASK; 1147 #endif 1148 } 1149 if (tTd(3, 20)) 1150 printf("getla: symbol address = %#x\n", Nl[X_AVENRUN].n_value); 1151 if (lseek(kmem, (off_t) Nl[X_AVENRUN].n_value, SEEK_SET) == -1 || 1152 read(kmem, (char *) avenrun, sizeof(avenrun)) < sizeof(avenrun)) 1153 { 1154 /* thank you Ian */ 1155 if (tTd(3, 1)) 1156 printf("getla: lseek or read: %s\n", errstring(errno)); 1157 return (-1); 1158 } 1159 #if (LA_TYPE == LA_INT) || (LA_TYPE == LA_SHORT) 1160 if (tTd(3, 5)) 1161 { 1162 printf("getla: avenrun = %d", avenrun[0]); 1163 if (tTd(3, 15)) 1164 printf(", %d, %d", avenrun[1], avenrun[2]); 1165 printf("\n"); 1166 } 1167 if (tTd(3, 1)) 1168 printf("getla: %d\n", (int) (avenrun[0] + FSCALE/2) >> FSHIFT); 1169 return ((int) (avenrun[0] + FSCALE/2) >> FSHIFT); 1170 #else 1171 if (tTd(3, 5)) 1172 { 1173 printf("getla: avenrun = %g", avenrun[0]); 1174 if (tTd(3, 15)) 1175 printf(", %g, %g", avenrun[1], avenrun[2]); 1176 printf("\n"); 1177 } 1178 if (tTd(3, 1)) 1179 printf("getla: %d\n", (int) (avenrun[0] +0.5)); 1180 return ((int) (avenrun[0] + 0.5)); 1181 #endif 1182 } 1183 1184 #else 1185 #if LA_TYPE == LA_SUBR 1186 1187 #ifdef DGUX 1188 1189 #include <sys/dg_sys_info.h> 1190 1191 int 1192 getla() 1193 { 1194 struct dg_sys_info_load_info load_info; 1195 1196 dg_sys_info((long *)&load_info, 1197 DG_SYS_INFO_LOAD_INFO_TYPE, DG_SYS_INFO_LOAD_VERSION_0); 1198 1199 if (tTd(3, 1)) 1200 printf("getla: %d\n", (int) (load_info.one_minute + 0.5)); 1201 1202 return((int) (load_info.one_minute + 0.5)); 1203 } 1204 1205 #else 1206 # ifdef __hpux 1207 1208 # include <sys/param.h> 1209 # include <sys/pstat.h> 1210 1211 int 1212 getla() 1213 { 1214 struct pst_dynamic pstd; 1215 1216 if (pstat_getdynamic(&pstd, sizeof(struct pst_dynamic), 1217 (size_t) 1 ,0) == -1) 1218 return 0; 1219 1220 if (tTd(3, 1)) 1221 printf("getla: %d\n", (int) (pstd.psd_avg_1_min + 0.5)); 1222 1223 return (int) (pstd.psd_avg_1_min + 0.5); 1224 } 1225 1226 # else 1227 1228 int 1229 getla() 1230 { 1231 double avenrun[3]; 1232 1233 if (getloadavg(avenrun, sizeof(avenrun) / sizeof(avenrun[0])) < 0) 1234 { 1235 if (tTd(3, 1)) 1236 perror("getla: getloadavg failed:"); 1237 return (-1); 1238 } 1239 if (tTd(3, 1)) 1240 printf("getla: %d\n", (int) (avenrun[0] +0.5)); 1241 return ((int) (avenrun[0] + 0.5)); 1242 } 1243 1244 # endif /* __hpux */ 1245 #endif /* DGUX */ 1246 #else 1247 #if LA_TYPE == LA_MACH 1248 1249 /* 1250 ** This has been tested on NEXTSTEP release 2.1/3.X. 1251 */ 1252 1253 #if defined(NX_CURRENT_COMPILER_RELEASE) && NX_CURRENT_COMPILER_RELEASE > NX_COMPILER_RELEASE_3_0 1254 # include <mach/mach.h> 1255 #else 1256 # include <mach.h> 1257 #endif 1258 1259 getla() 1260 { 1261 processor_set_t default_set; 1262 kern_return_t error; 1263 unsigned int info_count; 1264 struct processor_set_basic_info info; 1265 host_t host; 1266 1267 error = processor_set_default(host_self(), &default_set); 1268 if (error != KERN_SUCCESS) 1269 return -1; 1270 info_count = PROCESSOR_SET_BASIC_INFO_COUNT; 1271 if (processor_set_info(default_set, PROCESSOR_SET_BASIC_INFO, 1272 &host, (processor_set_info_t)&info, 1273 &info_count) != KERN_SUCCESS) 1274 { 1275 return -1; 1276 } 1277 return (int) (info.load_average + (LOAD_SCALE / 2)) / LOAD_SCALE; 1278 } 1279 1280 1281 #else 1282 #if LA_TYPE == LA_PROCSTR 1283 1284 /* 1285 ** Read /proc/loadavg for the load average. This is assumed to be 1286 ** in a format like "0.15 0.12 0.06". 1287 ** 1288 ** Initially intended for Linux. This has been in the kernel 1289 ** since at least 0.99.15. 1290 */ 1291 1292 # ifndef _PATH_LOADAVG 1293 # define _PATH_LOADAVG "/proc/loadavg" 1294 # endif 1295 1296 int 1297 getla() 1298 { 1299 double avenrun; 1300 register int result; 1301 FILE *fp; 1302 1303 fp = fopen(_PATH_LOADAVG, "r"); 1304 if (fp == NULL) 1305 { 1306 if (tTd(3, 1)) 1307 printf("getla: fopen(%s): %s\n", 1308 _PATH_LOADAVG, errstring(errno)); 1309 return -1; 1310 } 1311 result = fscanf(fp, "%lf", &avenrun); 1312 fclose(fp); 1313 if (result != 1) 1314 { 1315 if (tTd(3, 1)) 1316 printf("getla: fscanf() = %d: %s\n", 1317 result, errstring(errno)); 1318 return -1; 1319 } 1320 1321 if (tTd(3, 1)) 1322 printf("getla(): %.2f\n", avenrun); 1323 1324 return ((int) (avenrun + 0.5)); 1325 } 1326 1327 #else 1328 1329 getla() 1330 { 1331 if (tTd(3, 1)) 1332 printf("getla: ZERO\n"); 1333 return (0); 1334 } 1335 1336 #endif 1337 #endif 1338 #endif 1339 #endif 1340 1341 1342 /* 1343 * Copyright 1989 Massachusetts Institute of Technology 1344 * 1345 * Permission to use, copy, modify, distribute, and sell this software and its 1346 * documentation for any purpose is hereby granted without fee, provided that 1347 * the above copyright notice appear in all copies and that both that 1348 * copyright notice and this permission notice appear in supporting 1349 * documentation, and that the name of M.I.T. not be used in advertising or 1350 * publicity pertaining to distribution of the software without specific, 1351 * written prior permission. M.I.T. makes no representations about the 1352 * suitability of this software for any purpose. It is provided "as is" 1353 * without express or implied warranty. 1354 * 1355 * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL 1356 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T. 1357 * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 1358 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION 1359 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 1360 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 1361 * 1362 * Authors: Many and varied... 1363 */ 1364 1365 /* Non Apollo stuff removed by Don Lewis 11/15/93 */ 1366 #ifndef lint 1367 static char rcsid[] = "@(#)$Id: getloadavg.c,v 1.16 1991/06/21 12:51:15 paul Exp $"; 1368 #endif /* !lint */ 1369 1370 #ifdef apollo 1371 # undef volatile 1372 # include <apollo/base.h> 1373 1374 /* ARGSUSED */ 1375 int getloadavg( call_data ) 1376 caddr_t call_data; /* pointer to (double) return value */ 1377 { 1378 double *avenrun = (double *) call_data; 1379 int i; 1380 status_$t st; 1381 long loadav[3]; 1382 proc1_$get_loadav(loadav, &st); 1383 *avenrun = loadav[0] / (double) (1 << 16); 1384 return(0); 1385 } 1386 # endif /* apollo */ 1387 /* 1388 ** SHOULDQUEUE -- should this message be queued or sent? 1389 ** 1390 ** Compares the message cost to the load average to decide. 1391 ** 1392 ** Parameters: 1393 ** pri -- the priority of the message in question. 1394 ** ctime -- the message creation time. 1395 ** 1396 ** Returns: 1397 ** TRUE -- if this message should be queued up for the 1398 ** time being. 1399 ** FALSE -- if the load is low enough to send this message. 1400 ** 1401 ** Side Effects: 1402 ** none. 1403 */ 1404 1405 bool 1406 shouldqueue(pri, ctime) 1407 long pri; 1408 time_t ctime; 1409 { 1410 bool rval; 1411 1412 if (tTd(3, 30)) 1413 printf("shouldqueue: CurrentLA=%d, pri=%d: ", CurrentLA, pri); 1414 if (CurrentLA < QueueLA) 1415 { 1416 if (tTd(3, 30)) 1417 printf("FALSE (CurrentLA < QueueLA)\n"); 1418 return (FALSE); 1419 } 1420 if (CurrentLA >= RefuseLA) 1421 { 1422 if (tTd(3, 30)) 1423 printf("TRUE (CurrentLA >= RefuseLA)\n"); 1424 return (TRUE); 1425 } 1426 rval = pri > (QueueFactor / (CurrentLA - QueueLA + 1)); 1427 if (tTd(3, 30)) 1428 printf("%s (by calculation)\n", rval ? "TRUE" : "FALSE"); 1429 return rval; 1430 } 1431 /* 1432 ** REFUSECONNECTIONS -- decide if connections should be refused 1433 ** 1434 ** Parameters: 1435 ** none. 1436 ** 1437 ** Returns: 1438 ** TRUE if incoming SMTP connections should be refused 1439 ** (for now). 1440 ** FALSE if we should accept new work. 1441 ** 1442 ** Side Effects: 1443 ** none. 1444 */ 1445 1446 bool 1447 refuseconnections() 1448 { 1449 extern bool enoughspace(); 1450 1451 #ifdef XLA 1452 if (!xla_smtp_ok()) 1453 return TRUE; 1454 #endif 1455 1456 /* this is probably too simplistic */ 1457 return CurrentLA >= RefuseLA || !enoughspace(MinBlocksFree + 1); 1458 } 1459 /* 1460 ** SETPROCTITLE -- set process title for ps 1461 ** 1462 ** Parameters: 1463 ** fmt -- a printf style format string. 1464 ** a, b, c -- possible parameters to fmt. 1465 ** 1466 ** Returns: 1467 ** none. 1468 ** 1469 ** Side Effects: 1470 ** Clobbers argv of our main procedure so ps(1) will 1471 ** display the title. 1472 */ 1473 1474 #define SPT_NONE 0 /* don't use it at all */ 1475 #define SPT_REUSEARGV 1 /* cover argv with title information */ 1476 #define SPT_BUILTIN 2 /* use libc builtin */ 1477 #define SPT_PSTAT 3 /* use pstat(PSTAT_SETCMD, ...) */ 1478 #define SPT_PSSTRINGS 4 /* use PS_STRINGS->... */ 1479 #define SPT_WRITEUDOT 5 /* write u. area in kmem */ 1480 1481 #ifndef SPT_TYPE 1482 # define SPT_TYPE SPT_REUSEARGV 1483 #endif 1484 1485 #if SPT_TYPE != SPT_NONE && SPT_TYPE != SPT_BUILTIN 1486 1487 # if SPT_TYPE == SPT_PSTAT 1488 # include <sys/pstat.h> 1489 # endif 1490 # if SPT_TYPE == SPT_PSSTRINGS 1491 # include <machine/vmparam.h> 1492 # include <sys/exec.h> 1493 # ifndef PS_STRINGS /* hmmmm.... apparently not available after all */ 1494 # undef SPT_TYPE 1495 # define SPT_TYPE SPT_REUSEARGV 1496 # else 1497 # ifndef NKPDE /* FreeBSD 2.0 */ 1498 # define NKPDE 63 1499 typedef unsigned int *pt_entry_t; 1500 # endif 1501 # endif 1502 # endif 1503 1504 # if SPT_TYPE == SPT_PSSTRINGS 1505 # define SETPROC_STATIC static 1506 # else 1507 # define SETPROC_STATIC 1508 # endif 1509 1510 # ifndef SPT_PADCHAR 1511 # define SPT_PADCHAR ' ' 1512 # endif 1513 1514 #endif /* SPT_TYPE != SPT_NONE && SPT_TYPE != SPT_BUILTIN */ 1515 1516 #if SPT_TYPE != SPT_BUILTIN 1517 1518 /*VARARGS1*/ 1519 void 1520 # ifdef __STDC__ 1521 setproctitle(char *fmt, ...) 1522 # else 1523 setproctitle(fmt, va_alist) 1524 char *fmt; 1525 va_dcl 1526 # endif 1527 { 1528 # if SPT_TYPE != SPT_NONE 1529 register char *p; 1530 register int i; 1531 SETPROC_STATIC char buf[MAXLINE]; 1532 VA_LOCAL_DECL 1533 # if SPT_TYPE == SPT_PSTAT 1534 union pstun pst; 1535 # endif 1536 extern char **Argv; 1537 extern char *LastArgv; 1538 1539 p = buf; 1540 1541 /* print sendmail: heading for grep */ 1542 (void) strcpy(p, "sendmail: "); 1543 p += strlen(p); 1544 1545 /* print the argument string */ 1546 VA_START(fmt); 1547 (void) vsprintf(p, fmt, ap); 1548 VA_END; 1549 1550 i = strlen(buf); 1551 1552 # if SPT_TYPE == SPT_PSTAT 1553 pst.pst_command = buf; 1554 pstat(PSTAT_SETCMD, pst, i, 0, 0); 1555 # else 1556 # if SPT_TYPE == SPT_PSSTRINGS 1557 PS_STRINGS->ps_nargvstr = 1; 1558 PS_STRINGS->ps_argvstr = buf; 1559 # else 1560 if (i > LastArgv - Argv[0] - 2) 1561 { 1562 i = LastArgv - Argv[0] - 2; 1563 buf[i] = '\0'; 1564 } 1565 (void) strcpy(Argv[0], buf); 1566 p = &Argv[0][i]; 1567 while (p < LastArgv) 1568 *p++ = SPT_PADCHAR; 1569 Argv[1] = NULL; 1570 # endif /* SPT_TYPE == SPT_PSSTRINGS */ 1571 # endif /* SPT_TYPE == SPT_PSTAT */ 1572 # endif /* SPT_TYPE != SPT_NONE */ 1573 } 1574 1575 #endif /* SPT_TYPE != SPT_BUILTIN */ 1576 /* 1577 ** REAPCHILD -- pick up the body of my child, lest it become a zombie 1578 ** 1579 ** Parameters: 1580 ** sig -- the signal that got us here (unused). 1581 ** 1582 ** Returns: 1583 ** none. 1584 ** 1585 ** Side Effects: 1586 ** Picks up extant zombies. 1587 */ 1588 1589 void 1590 reapchild(sig) 1591 int sig; 1592 { 1593 int olderrno = errno; 1594 # ifdef HASWAITPID 1595 auto int status; 1596 int count; 1597 int pid; 1598 1599 count = 0; 1600 while ((pid = waitpid(-1, &status, WNOHANG)) > 0) 1601 { 1602 if (count++ > 1000) 1603 { 1604 #ifdef LOG 1605 syslog(LOG_ALERT, "reapchild: waitpid loop: pid=%d, status=%x", 1606 pid, status); 1607 #endif 1608 break; 1609 } 1610 } 1611 # else 1612 # ifdef WNOHANG 1613 union wait status; 1614 1615 while (wait3(&status, WNOHANG, (struct rusage *) NULL) > 0) 1616 continue; 1617 # else /* WNOHANG */ 1618 auto int status; 1619 1620 while (wait(&status) > 0) 1621 continue; 1622 # endif /* WNOHANG */ 1623 # endif 1624 # ifdef SYS5SIGNALS 1625 (void) setsignal(SIGCHLD, reapchild); 1626 # endif 1627 errno = olderrno; 1628 } 1629 /* 1630 ** UNSETENV -- remove a variable from the environment 1631 ** 1632 ** Not needed on newer systems. 1633 ** 1634 ** Parameters: 1635 ** name -- the string name of the environment variable to be 1636 ** deleted from the current environment. 1637 ** 1638 ** Returns: 1639 ** none. 1640 ** 1641 ** Globals: 1642 ** environ -- a pointer to the current environment. 1643 ** 1644 ** Side Effects: 1645 ** Modifies environ. 1646 */ 1647 1648 #ifndef HASUNSETENV 1649 1650 void 1651 unsetenv(name) 1652 char *name; 1653 { 1654 extern char **environ; 1655 register char **pp; 1656 int len = strlen(name); 1657 1658 for (pp = environ; *pp != NULL; pp++) 1659 { 1660 if (strncmp(name, *pp, len) == 0 && 1661 ((*pp)[len] == '=' || (*pp)[len] == '\0')) 1662 break; 1663 } 1664 1665 for (; *pp != NULL; pp++) 1666 *pp = pp[1]; 1667 } 1668 1669 #endif 1670 /* 1671 ** GETDTABLESIZE -- return number of file descriptors 1672 ** 1673 ** Only on non-BSD systems 1674 ** 1675 ** Parameters: 1676 ** none 1677 ** 1678 ** Returns: 1679 ** size of file descriptor table 1680 ** 1681 ** Side Effects: 1682 ** none 1683 */ 1684 1685 #ifdef SOLARIS 1686 # include <sys/resource.h> 1687 #endif 1688 1689 int 1690 getdtsize() 1691 { 1692 #ifdef RLIMIT_NOFILE 1693 struct rlimit rl; 1694 1695 if (getrlimit(RLIMIT_NOFILE, &rl) >= 0) 1696 return rl.rlim_cur; 1697 #endif 1698 1699 # ifdef HASGETDTABLESIZE 1700 return getdtablesize(); 1701 # else 1702 # ifdef _SC_OPEN_MAX 1703 return sysconf(_SC_OPEN_MAX); 1704 # else 1705 return NOFILE; 1706 # endif 1707 # endif 1708 } 1709 /* 1710 ** UNAME -- get the UUCP name of this system. 1711 */ 1712 1713 #ifndef HASUNAME 1714 1715 int 1716 uname(name) 1717 struct utsname *name; 1718 { 1719 FILE *file; 1720 char *n; 1721 1722 name->nodename[0] = '\0'; 1723 1724 /* try /etc/whoami -- one line with the node name */ 1725 if ((file = fopen("/etc/whoami", "r")) != NULL) 1726 { 1727 (void) fgets(name->nodename, NODE_LENGTH + 1, file); 1728 (void) fclose(file); 1729 n = strchr(name->nodename, '\n'); 1730 if (n != NULL) 1731 *n = '\0'; 1732 if (name->nodename[0] != '\0') 1733 return (0); 1734 } 1735 1736 /* try /usr/include/whoami.h -- has a #define somewhere */ 1737 if ((file = fopen("/usr/include/whoami.h", "r")) != NULL) 1738 { 1739 char buf[MAXLINE]; 1740 1741 while (fgets(buf, MAXLINE, file) != NULL) 1742 if (sscanf(buf, "#define sysname \"%*[^\"]\"", 1743 NODE_LENGTH, name->nodename) > 0) 1744 break; 1745 (void) fclose(file); 1746 if (name->nodename[0] != '\0') 1747 return (0); 1748 } 1749 1750 #ifdef TRUST_POPEN 1751 /* 1752 ** Popen is known to have security holes. 1753 */ 1754 1755 /* try uuname -l to return local name */ 1756 if ((file = popen("uuname -l", "r")) != NULL) 1757 { 1758 (void) fgets(name, NODE_LENGTH + 1, file); 1759 (void) pclose(file); 1760 n = strchr(name, '\n'); 1761 if (n != NULL) 1762 *n = '\0'; 1763 if (name->nodename[0] != '\0') 1764 return (0); 1765 } 1766 #endif 1767 1768 return (-1); 1769 } 1770 #endif /* HASUNAME */ 1771 /* 1772 ** INITGROUPS -- initialize groups 1773 ** 1774 ** Stub implementation for System V style systems 1775 */ 1776 1777 #ifndef HASINITGROUPS 1778 1779 initgroups(name, basegid) 1780 char *name; 1781 int basegid; 1782 { 1783 return 0; 1784 } 1785 1786 #endif 1787 /* 1788 ** SETSID -- set session id (for non-POSIX systems) 1789 */ 1790 1791 #ifndef HASSETSID 1792 1793 pid_t 1794 setsid __P ((void)) 1795 { 1796 #ifdef TIOCNOTTY 1797 int fd; 1798 1799 fd = open("/dev/tty", O_RDWR, 0); 1800 if (fd >= 0) 1801 { 1802 (void) ioctl(fd, (int) TIOCNOTTY, (char *) 0); 1803 (void) close(fd); 1804 } 1805 #endif /* TIOCNOTTY */ 1806 # ifdef SYS5SETPGRP 1807 return setpgrp(); 1808 # else 1809 return setpgid(0, getpid()); 1810 # endif 1811 } 1812 1813 #endif 1814 /* 1815 ** FSYNC -- dummy fsync 1816 */ 1817 1818 #ifdef NEEDFSYNC 1819 1820 fsync(fd) 1821 int fd; 1822 { 1823 # ifdef O_SYNC 1824 return fcntl(fd, F_SETFL, O_SYNC); 1825 # else 1826 /* nothing we can do */ 1827 return 0; 1828 # endif 1829 } 1830 1831 #endif 1832 /* 1833 ** DGUX_INET_ADDR -- inet_addr for DG/UX 1834 ** 1835 ** Data General DG/UX version of inet_addr returns a struct in_addr 1836 ** instead of a long. This patches things. Only needed on versions 1837 ** prior to 5.4.3. 1838 */ 1839 1840 #ifdef DGUX_5_4_2 1841 1842 #undef inet_addr 1843 1844 long 1845 dgux_inet_addr(host) 1846 char *host; 1847 { 1848 struct in_addr haddr; 1849 1850 haddr = inet_addr(host); 1851 return haddr.s_addr; 1852 } 1853 1854 #endif 1855 /* 1856 ** GETOPT -- for old systems or systems with bogus implementations 1857 */ 1858 1859 #ifdef NEEDGETOPT 1860 1861 /* 1862 * Copyright (c) 1985 Regents of the University of California. 1863 * All rights reserved. The Berkeley software License Agreement 1864 * specifies the terms and conditions for redistribution. 1865 */ 1866 1867 1868 /* 1869 ** this version hacked to add `atend' flag to allow state machine 1870 ** to reset if invoked by the program to scan args for a 2nd time 1871 */ 1872 1873 #if defined(LIBC_SCCS) && !defined(lint) 1874 static char sccsid[] = "@(#)getopt.c 4.3 (Berkeley) 3/9/86"; 1875 #endif /* LIBC_SCCS and not lint */ 1876 1877 #include <stdio.h> 1878 1879 /* 1880 * get option letter from argument vector 1881 */ 1882 #ifdef _CONVEX_SOURCE 1883 extern int optind, opterr, optopt; 1884 extern char *optarg; 1885 #else 1886 int opterr = 1; /* if error message should be printed */ 1887 int optind = 1; /* index into parent argv vector */ 1888 int optopt = 0; /* character checked for validity */ 1889 char *optarg = NULL; /* argument associated with option */ 1890 #endif 1891 1892 #define BADCH (int)'?' 1893 #define EMSG "" 1894 #define tell(s) if (opterr) {fputs(*nargv,stderr);fputs(s,stderr); \ 1895 fputc(optopt,stderr);fputc('\n',stderr);return(BADCH);} 1896 1897 getopt(nargc,nargv,ostr) 1898 int nargc; 1899 char *const *nargv; 1900 const char *ostr; 1901 { 1902 static char *place = EMSG; /* option letter processing */ 1903 static char atend = 0; 1904 register char *oli; /* option letter list index */ 1905 1906 if (atend) { 1907 atend = 0; 1908 place = EMSG; 1909 } 1910 if(!*place) { /* update scanning pointer */ 1911 if (optind >= nargc || *(place = nargv[optind]) != '-' || !*++place) { 1912 atend++; 1913 return(EOF); 1914 } 1915 if (*place == '-') { /* found "--" */ 1916 ++optind; 1917 atend++; 1918 return(EOF); 1919 } 1920 } /* option letter okay? */ 1921 if ((optopt = (int)*place++) == (int)':' || !(oli = strchr(ostr,optopt))) { 1922 if (!*place) ++optind; 1923 tell(": illegal option -- "); 1924 } 1925 if (*++oli != ':') { /* don't need argument */ 1926 optarg = NULL; 1927 if (!*place) ++optind; 1928 } 1929 else { /* need an argument */ 1930 if (*place) optarg = place; /* no white space */ 1931 else if (nargc <= ++optind) { /* no arg */ 1932 place = EMSG; 1933 tell(": option requires an argument -- "); 1934 } 1935 else optarg = nargv[optind]; /* white space */ 1936 place = EMSG; 1937 ++optind; 1938 } 1939 return(optopt); /* dump back option letter */ 1940 } 1941 1942 #endif 1943 /* 1944 ** VFPRINTF, VSPRINTF -- for old 4.3 BSD systems missing a real version 1945 */ 1946 1947 #ifdef NEEDVPRINTF 1948 1949 #define MAXARG 16 1950 1951 vfprintf(fp, fmt, ap) 1952 FILE * fp; 1953 char * fmt; 1954 char ** ap; 1955 { 1956 char * bp[MAXARG]; 1957 int i = 0; 1958 1959 while (*ap && i < MAXARG) 1960 bp[i++] = *ap++; 1961 fprintf(fp, fmt, bp[0], bp[1], bp[2], bp[3], 1962 bp[4], bp[5], bp[6], bp[7], 1963 bp[8], bp[9], bp[10], bp[11], 1964 bp[12], bp[13], bp[14], bp[15]); 1965 } 1966 1967 vsprintf(s, fmt, ap) 1968 char * s; 1969 char * fmt; 1970 char ** ap; 1971 { 1972 char * bp[MAXARG]; 1973 int i = 0; 1974 1975 while (*ap && i < MAXARG) 1976 bp[i++] = *ap++; 1977 sprintf(s, fmt, bp[0], bp[1], bp[2], bp[3], 1978 bp[4], bp[5], bp[6], bp[7], 1979 bp[8], bp[9], bp[10], bp[11], 1980 bp[12], bp[13], bp[14], bp[15]); 1981 } 1982 1983 #endif 1984 /* 1985 ** USERSHELLOK -- tell if a user's shell is ok for unrestricted use 1986 ** 1987 ** Parameters: 1988 ** shell -- the user's shell from /etc/passwd 1989 ** 1990 ** Returns: 1991 ** TRUE -- if it is ok to use this for unrestricted access. 1992 ** FALSE -- if the shell is restricted. 1993 */ 1994 1995 #if !HASGETUSERSHELL 1996 1997 # ifndef _PATH_SHELLS 1998 # define _PATH_SHELLS "/etc/shells" 1999 # endif 2000 2001 char *DefaultUserShells[] = 2002 { 2003 "/bin/sh", /* standard shell */ 2004 "/usr/bin/sh", 2005 "/bin/csh", /* C shell */ 2006 "/usr/bin/csh", 2007 #ifdef __hpux 2008 "/bin/rsh", /* restricted Bourne shell */ 2009 "/bin/ksh", /* Korn shell */ 2010 "/bin/rksh", /* restricted Korn shell */ 2011 "/bin/pam", 2012 "/usr/bin/keysh", /* key shell (extended Korn shell) */ 2013 "/bin/posix/sh", 2014 #endif 2015 #ifdef _AIX3 2016 "/bin/ksh", /* Korn shell */ 2017 "/usr/bin/ksh", 2018 "/bin/tsh", /* trusted shell */ 2019 "/usr/bin/tsh", 2020 "/bin/bsh", /* Bourne shell */ 2021 "/usr/bin/bsh", 2022 #endif 2023 NULL 2024 }; 2025 2026 #endif 2027 2028 #define WILDCARD_SHELL "/SENDMAIL/ANY/SHELL/" 2029 2030 bool 2031 usershellok(shell) 2032 char *shell; 2033 { 2034 #if HASGETUSERSHELL 2035 register char *p; 2036 extern char *getusershell(); 2037 2038 if (shell == NULL || shell[0] == '\0') 2039 return TRUE; 2040 2041 setusershell(); 2042 while ((p = getusershell()) != NULL) 2043 if (strcmp(p, shell) == 0 || strcmp(p, WILDCARD_SHELL) == 0) 2044 break; 2045 endusershell(); 2046 return p != NULL; 2047 #else 2048 register FILE *shellf; 2049 char buf[MAXLINE]; 2050 2051 if (shell == NULL || shell[0] == '\0') 2052 return TRUE; 2053 2054 shellf = fopen(_PATH_SHELLS, "r"); 2055 if (shellf == NULL) 2056 { 2057 /* no /etc/shells; see if it is one of the std shells */ 2058 char **d; 2059 2060 for (d = DefaultUserShells; *d != NULL; d++) 2061 { 2062 if (strcmp(shell, *d) == 0) 2063 return TRUE; 2064 } 2065 return FALSE; 2066 } 2067 2068 while (fgets(buf, sizeof buf, shellf) != NULL) 2069 { 2070 register char *p, *q; 2071 2072 p = buf; 2073 while (*p != '\0' && *p != '#' && *p != '/') 2074 p++; 2075 if (*p == '#' || *p == '\0') 2076 continue; 2077 q = p; 2078 while (*p != '\0' && *p != '#' && !isspace(*p)) 2079 p++; 2080 *p = '\0'; 2081 if (strcmp(shell, q) == 0 || strcmp(WILDCARD_SHELL, q) == 0) 2082 { 2083 fclose(shellf); 2084 return TRUE; 2085 } 2086 } 2087 fclose(shellf); 2088 return FALSE; 2089 #endif 2090 } 2091 /* 2092 ** FREESPACE -- see how much free space is on the queue filesystem 2093 ** 2094 ** Only implemented if you have statfs. 2095 ** 2096 ** Parameters: 2097 ** dir -- the directory in question. 2098 ** bsize -- a variable into which the filesystem 2099 ** block size is stored. 2100 ** 2101 ** Returns: 2102 ** The number of bytes free on the queue filesystem. 2103 ** -1 if the statfs call fails. 2104 ** 2105 ** Side effects: 2106 ** Puts the filesystem block size into bsize. 2107 */ 2108 2109 /* statfs types */ 2110 #define SFS_NONE 0 /* no statfs implementation */ 2111 #define SFS_USTAT 1 /* use ustat */ 2112 #define SFS_4ARGS 2 /* use four-argument statfs call */ 2113 #define SFS_VFS 3 /* use <sys/vfs.h> implementation */ 2114 #define SFS_MOUNT 4 /* use <sys/mount.h> implementation */ 2115 #define SFS_STATFS 5 /* use <sys/statfs.h> implementation */ 2116 #define SFS_STATVFS 6 /* use <sys/statvfs.h> implementation */ 2117 2118 #ifndef SFS_TYPE 2119 # define SFS_TYPE SFS_NONE 2120 #endif 2121 2122 #if SFS_TYPE == SFS_USTAT 2123 # include <ustat.h> 2124 #endif 2125 #if SFS_TYPE == SFS_4ARGS || SFS_TYPE == SFS_STATFS 2126 # include <sys/statfs.h> 2127 #endif 2128 #if SFS_TYPE == SFS_VFS 2129 # include <sys/vfs.h> 2130 #endif 2131 #if SFS_TYPE == SFS_MOUNT 2132 # include <sys/mount.h> 2133 #endif 2134 #if SFS_TYPE == SFS_STATVFS 2135 # include <sys/statvfs.h> 2136 #endif 2137 2138 long 2139 freespace(dir, bsize) 2140 char *dir; 2141 long *bsize; 2142 { 2143 #if SFS_TYPE != SFS_NONE 2144 # if SFS_TYPE == SFS_USTAT 2145 struct ustat fs; 2146 struct stat statbuf; 2147 # define FSBLOCKSIZE DEV_BSIZE 2148 # define SFS_BAVAIL f_tfree 2149 # else 2150 # if defined(ultrix) 2151 struct fs_data fs; 2152 # define SFS_BAVAIL fd_bfreen 2153 # define FSBLOCKSIZE 1024L 2154 # else 2155 # if SFS_TYPE == SFS_STATVFS 2156 struct statvfs fs; 2157 # define FSBLOCKSIZE fs.f_frsize 2158 # else 2159 struct statfs fs; 2160 # define FSBLOCKSIZE fs.f_bsize 2161 # endif 2162 # endif 2163 # endif 2164 # ifndef SFS_BAVAIL 2165 # define SFS_BAVAIL f_bavail 2166 # endif 2167 2168 # if SFS_TYPE == SFS_USTAT 2169 if (stat(dir, &statbuf) == 0 && ustat(statbuf.st_dev, &fs) == 0) 2170 # else 2171 # if SFS_TYPE == SFS_4ARGS 2172 if (statfs(dir, &fs, sizeof fs, 0) == 0) 2173 # else 2174 # if SFS_TYPE == SFS_STATVFS 2175 if (statvfs(dir, &fs) == 0) 2176 # else 2177 # if defined(ultrix) 2178 if (statfs(dir, &fs) > 0) 2179 # else 2180 if (statfs(dir, &fs) == 0) 2181 # endif 2182 # endif 2183 # endif 2184 # endif 2185 { 2186 if (bsize != NULL) 2187 *bsize = FSBLOCKSIZE; 2188 return (fs.SFS_BAVAIL); 2189 } 2190 #endif 2191 return (-1); 2192 } 2193 /* 2194 ** ENOUGHSPACE -- check to see if there is enough free space on the queue fs 2195 ** 2196 ** Only implemented if you have statfs. 2197 ** 2198 ** Parameters: 2199 ** msize -- the size to check against. If zero, we don't yet 2200 ** know how big the message will be, so just check for 2201 ** a "reasonable" amount. 2202 ** 2203 ** Returns: 2204 ** TRUE if there is enough space. 2205 ** FALSE otherwise. 2206 */ 2207 2208 bool 2209 enoughspace(msize) 2210 long msize; 2211 { 2212 long bfree, bsize; 2213 2214 if (MinBlocksFree <= 0 && msize <= 0) 2215 { 2216 if (tTd(4, 80)) 2217 printf("enoughspace: no threshold\n"); 2218 return TRUE; 2219 } 2220 2221 if ((bfree = freespace(QueueDir, &bsize)) >= 0) 2222 { 2223 if (tTd(4, 80)) 2224 printf("enoughspace: bavail=%ld, need=%ld\n", 2225 bfree, msize); 2226 2227 /* convert msize to block count */ 2228 msize = msize / bsize + 1; 2229 if (MinBlocksFree >= 0) 2230 msize += MinBlocksFree; 2231 2232 if (bfree < msize) 2233 { 2234 #ifdef LOG 2235 if (LogLevel > 0) 2236 syslog(LOG_ALERT, 2237 "%s: low on space (have %ld, %s needs %ld in %s)", 2238 CurEnv->e_id == NULL ? "[NOQUEUE]" : CurEnv->e_id, 2239 bfree, 2240 CurHostName == NULL ? "SMTP-DAEMON" : CurHostName, 2241 msize, QueueDir); 2242 #endif 2243 return FALSE; 2244 } 2245 } 2246 else if (tTd(4, 80)) 2247 printf("enoughspace failure: min=%ld, need=%ld: %s\n", 2248 MinBlocksFree, msize, errstring(errno)); 2249 return TRUE; 2250 } 2251 /* 2252 ** TRANSIENTERROR -- tell if an error code indicates a transient failure 2253 ** 2254 ** This looks at an errno value and tells if this is likely to 2255 ** go away if retried later. 2256 ** 2257 ** Parameters: 2258 ** err -- the errno code to classify. 2259 ** 2260 ** Returns: 2261 ** TRUE if this is probably transient. 2262 ** FALSE otherwise. 2263 */ 2264 2265 bool 2266 transienterror(err) 2267 int err; 2268 { 2269 switch (err) 2270 { 2271 case EIO: /* I/O error */ 2272 case ENXIO: /* Device not configured */ 2273 case EAGAIN: /* Resource temporarily unavailable */ 2274 case ENOMEM: /* Cannot allocate memory */ 2275 case ENODEV: /* Operation not supported by device */ 2276 case ENFILE: /* Too many open files in system */ 2277 case EMFILE: /* Too many open files */ 2278 case ENOSPC: /* No space left on device */ 2279 #ifdef ETIMEDOUT 2280 case ETIMEDOUT: /* Connection timed out */ 2281 #endif 2282 #ifdef ESTALE 2283 case ESTALE: /* Stale NFS file handle */ 2284 #endif 2285 #ifdef ENETDOWN 2286 case ENETDOWN: /* Network is down */ 2287 #endif 2288 #ifdef ENETUNREACH 2289 case ENETUNREACH: /* Network is unreachable */ 2290 #endif 2291 #ifdef ENETRESET 2292 case ENETRESET: /* Network dropped connection on reset */ 2293 #endif 2294 #ifdef ECONNABORTED 2295 case ECONNABORTED: /* Software caused connection abort */ 2296 #endif 2297 #ifdef ECONNRESET 2298 case ECONNRESET: /* Connection reset by peer */ 2299 #endif 2300 #ifdef ENOBUFS 2301 case ENOBUFS: /* No buffer space available */ 2302 #endif 2303 #ifdef ESHUTDOWN 2304 case ESHUTDOWN: /* Can't send after socket shutdown */ 2305 #endif 2306 #ifdef ECONNREFUSED 2307 case ECONNREFUSED: /* Connection refused */ 2308 #endif 2309 #ifdef EHOSTDOWN 2310 case EHOSTDOWN: /* Host is down */ 2311 #endif 2312 #ifdef EHOSTUNREACH 2313 case EHOSTUNREACH: /* No route to host */ 2314 #endif 2315 #ifdef EDQUOT 2316 case EDQUOT: /* Disc quota exceeded */ 2317 #endif 2318 #ifdef EPROCLIM 2319 case EPROCLIM: /* Too many processes */ 2320 #endif 2321 #ifdef EUSERS 2322 case EUSERS: /* Too many users */ 2323 #endif 2324 #ifdef EDEADLK 2325 case EDEADLK: /* Resource deadlock avoided */ 2326 #endif 2327 #ifdef EISCONN 2328 case EISCONN: /* Socket already connected */ 2329 #endif 2330 #ifdef EINPROGRESS 2331 case EINPROGRESS: /* Operation now in progress */ 2332 #endif 2333 #ifdef EALREADY 2334 case EALREADY: /* Operation already in progress */ 2335 #endif 2336 #ifdef EADDRINUSE 2337 case EADDRINUSE: /* Address already in use */ 2338 #endif 2339 #ifdef EADDRNOTAVAIL 2340 case EADDRNOTAVAIL: /* Can't assign requested address */ 2341 #endif 2342 #ifdef ETXTBSY 2343 case ETXTBSY: /* (Apollo) file locked */ 2344 #endif 2345 #if defined(ENOSR) && (!defined(ENOBUFS) || (ENOBUFS != ENOSR)) 2346 case ENOSR: /* Out of streams resources */ 2347 #endif 2348 return TRUE; 2349 } 2350 2351 /* nope, must be permanent */ 2352 return FALSE; 2353 } 2354 /* 2355 ** LOCKFILE -- lock a file using flock or (shudder) fcntl locking 2356 ** 2357 ** Parameters: 2358 ** fd -- the file descriptor of the file. 2359 ** filename -- the file name (for error messages). 2360 ** ext -- the filename extension. 2361 ** type -- type of the lock. Bits can be: 2362 ** LOCK_EX -- exclusive lock. 2363 ** LOCK_NB -- non-blocking. 2364 ** 2365 ** Returns: 2366 ** TRUE if the lock was acquired. 2367 ** FALSE otherwise. 2368 */ 2369 2370 bool 2371 lockfile(fd, filename, ext, type) 2372 int fd; 2373 char *filename; 2374 char *ext; 2375 int type; 2376 { 2377 # if !HASFLOCK 2378 int action; 2379 struct flock lfd; 2380 2381 if (ext == NULL) 2382 ext = ""; 2383 2384 bzero(&lfd, sizeof lfd); 2385 if (bitset(LOCK_UN, type)) 2386 lfd.l_type = F_UNLCK; 2387 else if (bitset(LOCK_EX, type)) 2388 lfd.l_type = F_WRLCK; 2389 else 2390 lfd.l_type = F_RDLCK; 2391 2392 if (bitset(LOCK_NB, type)) 2393 action = F_SETLK; 2394 else 2395 action = F_SETLKW; 2396 2397 if (tTd(55, 60)) 2398 printf("lockfile(%s%s, action=%d, type=%d): ", 2399 filename, ext, action, lfd.l_type); 2400 2401 if (fcntl(fd, action, &lfd) >= 0) 2402 { 2403 if (tTd(55, 60)) 2404 printf("SUCCESS\n"); 2405 return TRUE; 2406 } 2407 2408 if (tTd(55, 60)) 2409 printf("(%s) ", errstring(errno)); 2410 2411 /* 2412 ** On SunOS, if you are testing using -oQ/tmp/mqueue or 2413 ** -oA/tmp/aliases or anything like that, and /tmp is mounted 2414 ** as type "tmp" (that is, served from swap space), the 2415 ** previous fcntl will fail with "Invalid argument" errors. 2416 ** Since this is fairly common during testing, we will assume 2417 ** that this indicates that the lock is successfully grabbed. 2418 */ 2419 2420 if (errno == EINVAL) 2421 { 2422 if (tTd(55, 60)) 2423 printf("SUCCESS\n"); 2424 return TRUE; 2425 } 2426 2427 if (!bitset(LOCK_NB, type) || (errno != EACCES && errno != EAGAIN)) 2428 { 2429 int omode = -1; 2430 # ifdef F_GETFL 2431 int oerrno = errno; 2432 2433 (void) fcntl(fd, F_GETFL, &omode); 2434 errno = oerrno; 2435 # endif 2436 syserr("cannot lockf(%s%s, fd=%d, type=%o, omode=%o, euid=%d)", 2437 filename, ext, fd, type, omode, geteuid()); 2438 } 2439 # else 2440 if (ext == NULL) 2441 ext = ""; 2442 2443 if (tTd(55, 60)) 2444 printf("lockfile(%s%s, type=%o): ", filename, ext, type); 2445 2446 if (flock(fd, type) >= 0) 2447 { 2448 if (tTd(55, 60)) 2449 printf("SUCCESS\n"); 2450 return TRUE; 2451 } 2452 2453 if (tTd(55, 60)) 2454 printf("(%s) ", errstring(errno)); 2455 2456 if (!bitset(LOCK_NB, type) || errno != EWOULDBLOCK) 2457 { 2458 int omode = -1; 2459 # ifdef F_GETFL 2460 int oerrno = errno; 2461 2462 (void) fcntl(fd, F_GETFL, &omode); 2463 errno = oerrno; 2464 # endif 2465 syserr("cannot flock(%s%s, fd=%d, type=%o, omode=%o, euid=%d)", 2466 filename, ext, fd, type, omode, geteuid()); 2467 } 2468 # endif 2469 if (tTd(55, 60)) 2470 printf("FAIL\n"); 2471 return FALSE; 2472 } 2473 /* 2474 ** CHOWNSAFE -- tell if chown is "safe" (executable only by root) 2475 ** 2476 ** Parameters: 2477 ** fd -- the file descriptor to check. 2478 ** 2479 ** Returns: 2480 ** TRUE -- if only root can chown the file to an arbitrary 2481 ** user. 2482 ** FALSE -- if an arbitrary user can give away a file. 2483 */ 2484 2485 bool 2486 chownsafe(fd) 2487 int fd; 2488 { 2489 #ifdef __hpux 2490 char *s; 2491 int tfd; 2492 uid_t o_uid, o_euid; 2493 gid_t o_gid, o_egid; 2494 bool rval; 2495 struct stat stbuf; 2496 2497 o_uid = getuid(); 2498 o_euid = geteuid(); 2499 o_gid = getgid(); 2500 o_egid = getegid(); 2501 fstat(fd, &stbuf); 2502 setresuid(stbuf.st_uid, stbuf.st_uid, -1); 2503 setresgid(stbuf.st_gid, stbuf.st_gid, -1); 2504 s = tmpnam(NULL); 2505 tfd = open(s, O_RDONLY|O_CREAT, 0600); 2506 rval = fchown(tfd, DefUid, DefGid) != 0; 2507 close(tfd); 2508 unlink(s); 2509 setreuid(o_uid, o_euid); 2510 setresgid(o_gid, o_egid, -1); 2511 return rval; 2512 #else 2513 # ifdef _POSIX_CHOWN_RESTRICTED 2514 # if _POSIX_CHOWN_RESTRICTED == -1 2515 return FALSE; 2516 # else 2517 return TRUE; 2518 # endif 2519 # else 2520 # ifdef _PC_CHOWN_RESTRICTED 2521 int rval; 2522 2523 /* 2524 ** Some systems (e.g., SunOS) seem to have the call and the 2525 ** #define _PC_CHOWN_RESTRICTED, but don't actually implement 2526 ** the call. This heuristic checks for that. 2527 */ 2528 2529 errno = 0; 2530 rval = fpathconf(fd, _PC_CHOWN_RESTRICTED); 2531 if (errno == 0) 2532 return rval > 0; 2533 # endif 2534 # ifdef BSD 2535 return TRUE; 2536 # else 2537 return FALSE; 2538 # endif 2539 # endif 2540 #endif 2541 } 2542 /* 2543 ** RESETLIMITS -- reset system controlled resource limits 2544 ** 2545 ** This is to avoid denial-of-service attacks 2546 ** 2547 ** Parameters: 2548 ** none 2549 ** 2550 ** Returns: 2551 ** none 2552 */ 2553 2554 #if HASSETRLIMIT 2555 # include <sys/resource.h> 2556 #endif 2557 2558 void 2559 resetlimits() 2560 { 2561 #if HASSETRLIMIT 2562 struct rlimit lim; 2563 2564 lim.rlim_cur = lim.rlim_max = RLIM_INFINITY; 2565 (void) setrlimit(RLIMIT_CPU, &lim); 2566 (void) setrlimit(RLIMIT_FSIZE, &lim); 2567 #else 2568 # if HASULIMIT 2569 (void) ulimit(2, 0x3fffff); 2570 # endif 2571 #endif 2572 } 2573 /* 2574 ** GETCFNAME -- return the name of the .cf file. 2575 ** 2576 ** Some systems (e.g., NeXT) determine this dynamically. 2577 */ 2578 2579 char * 2580 getcfname() 2581 { 2582 int i; 2583 static char cbuf[200]; 2584 2585 if (ConfFile != NULL) 2586 return ConfFile; 2587 #ifdef NETINFO 2588 { 2589 extern char *ni_propval(); 2590 char *cflocation; 2591 2592 cflocation = ni_propval("/locations", NULL, "sendmail", 2593 "sendmail.cf", '\0'); 2594 if (cflocation != NULL) 2595 return cflocation; 2596 } 2597 #endif 2598 2599 /* 2600 ** Try sendmail.8.6.12.cf, then sendmail.8.6.cf, then 2601 ** sendmail.8.cf, and finally sendmail.cf. 2602 ** 2603 ** I suppose it should really try a search path here -- 2604 ** e.g., /etc/sendmail.cf, /etc/mail/sendmail.cf, 2605 ** /usr/lib/sendmail.cf, and so forth. 2606 */ 2607 2608 strcpy(cbuf, _PATH_SENDMAILCF); 2609 i = strlen(cbuf); 2610 if (strcmp(&cbuf[i - 3], ".cf") == 0) 2611 { 2612 char *p; 2613 extern char Version[]; 2614 2615 strcpy(&cbuf[i - 2], Version); 2616 p = strchr(&cbuf[i - 2], '/'); 2617 if (p != NULL) 2618 *p = '\0'; 2619 p = &cbuf[strlen(cbuf)]; 2620 do 2621 { 2622 int fd; 2623 2624 strcpy(p, ".cf"); 2625 if ((fd = open(cbuf, O_RDONLY, 0)) >= 0) 2626 { 2627 close(fd); 2628 return cbuf; 2629 } 2630 *p = '\0'; 2631 } while ((p = strrchr(&cbuf[i - 2], '.')) != NULL); 2632 } 2633 return _PATH_SENDMAILCF; 2634 } 2635 /* 2636 ** SETVENDOR -- process vendor code from V configuration line 2637 ** 2638 ** Parameters: 2639 ** vendor -- string representation of vendor. 2640 ** 2641 ** Returns: 2642 ** TRUE -- if ok. 2643 ** FALSE -- if vendor code could not be processed. 2644 ** 2645 ** Side Effects: 2646 ** It is reasonable to set mode flags here to tweak 2647 ** processing in other parts of the code if necessary. 2648 ** For example, if you are a vendor that uses $%y to 2649 ** indicate YP lookups, you could enable that here. 2650 */ 2651 2652 bool 2653 setvendor(vendor) 2654 char *vendor; 2655 { 2656 if (strcasecmp(vendor, "Berkeley") == 0) 2657 { 2658 VendorCode = VENDOR_BERKELEY; 2659 return TRUE; 2660 } 2661 2662 /* add vendor extensions here */ 2663 2664 #ifdef SUN_EXTENSIONS 2665 if (strcasecmp(vendor, "Sun") == 0) 2666 { 2667 VendorCode = VENDOR_SUN; 2668 return TRUE; 2669 } 2670 #endif 2671 2672 return FALSE; 2673 } 2674 /* 2675 ** STRTOL -- convert string to long integer 2676 ** 2677 ** For systems that don't have it in the C library. 2678 ** 2679 ** This is taken verbatim from the 4.4-Lite C library. 2680 */ 2681 2682 #ifdef NEEDSTRTOL 2683 2684 #if defined(LIBC_SCCS) && !defined(lint) 2685 static char sccsid[] = "@(#)strtol.c 8.1 (Berkeley) 6/4/93"; 2686 #endif /* LIBC_SCCS and not lint */ 2687 2688 #include <limits.h> 2689 2690 /* 2691 * Convert a string to a long integer. 2692 * 2693 * Ignores `locale' stuff. Assumes that the upper and lower case 2694 * alphabets and digits are each contiguous. 2695 */ 2696 2697 long 2698 strtol(nptr, endptr, base) 2699 const char *nptr; 2700 char **endptr; 2701 register int base; 2702 { 2703 register const char *s = nptr; 2704 register unsigned long acc; 2705 register int c; 2706 register unsigned long cutoff; 2707 register int neg = 0, any, cutlim; 2708 2709 /* 2710 * Skip white space and pick up leading +/- sign if any. 2711 * If base is 0, allow 0x for hex and 0 for octal, else 2712 * assume decimal; if base is already 16, allow 0x. 2713 */ 2714 do { 2715 c = *s++; 2716 } while (isspace(c)); 2717 if (c == '-') { 2718 neg = 1; 2719 c = *s++; 2720 } else if (c == '+') 2721 c = *s++; 2722 if ((base == 0 || base == 16) && 2723 c == '0' && (*s == 'x' || *s == 'X')) { 2724 c = s[1]; 2725 s += 2; 2726 base = 16; 2727 } 2728 if (base == 0) 2729 base = c == '0' ? 8 : 10; 2730 2731 /* 2732 * Compute the cutoff value between legal numbers and illegal 2733 * numbers. That is the largest legal value, divided by the 2734 * base. An input number that is greater than this value, if 2735 * followed by a legal input character, is too big. One that 2736 * is equal to this value may be valid or not; the limit 2737 * between valid and invalid numbers is then based on the last 2738 * digit. For instance, if the range for longs is 2739 * [-2147483648..2147483647] and the input base is 10, 2740 * cutoff will be set to 214748364 and cutlim to either 2741 * 7 (neg==0) or 8 (neg==1), meaning that if we have accumulated 2742 * a value > 214748364, or equal but the next digit is > 7 (or 8), 2743 * the number is too big, and we will return a range error. 2744 * 2745 * Set any if any `digits' consumed; make it negative to indicate 2746 * overflow. 2747 */ 2748 cutoff = neg ? -(unsigned long)LONG_MIN : LONG_MAX; 2749 cutlim = cutoff % (unsigned long)base; 2750 cutoff /= (unsigned long)base; 2751 for (acc = 0, any = 0;; c = *s++) { 2752 if (isdigit(c)) 2753 c -= '0'; 2754 else if (isalpha(c)) 2755 c -= isupper(c) ? 'A' - 10 : 'a' - 10; 2756 else 2757 break; 2758 if (c >= base) 2759 break; 2760 if (any < 0 || acc > cutoff || acc == cutoff && c > cutlim) 2761 any = -1; 2762 else { 2763 any = 1; 2764 acc *= base; 2765 acc += c; 2766 } 2767 } 2768 if (any < 0) { 2769 acc = neg ? LONG_MIN : LONG_MAX; 2770 errno = ERANGE; 2771 } else if (neg) 2772 acc = -acc; 2773 if (endptr != 0) 2774 *endptr = (char *)(any ? s - 1 : nptr); 2775 return (acc); 2776 } 2777 2778 #endif 2779 /* 2780 ** SM_GETHOSTBY{NAME,ADDR} -- compatibility routines for gethostbyXXX 2781 ** 2782 ** Some operating systems have wierd problems with the gethostbyXXX 2783 ** routines. For example, Solaris versions at least through 2.3 2784 ** don't properly deliver a canonical h_name field. This tries to 2785 ** work around these problems. 2786 */ 2787 2788 struct hostent * 2789 sm_gethostbyname(name) 2790 char *name; 2791 { 2792 #if defined(SOLARIS) && SOLARIS < 204 2793 extern int h_errno; 2794 2795 # if SOLARIS == 203 2796 static struct hostent hp; 2797 static char buf[1000]; 2798 extern struct hostent *_switch_gethostbyname_r(); 2799 2800 return _switch_gethostbyname_r(name, &hp, buf, sizeof(buf), &h_errno); 2801 # else 2802 extern struct hostent *__switch_gethostbyname(); 2803 2804 return __switch_gethostbyname(name); 2805 # endif 2806 #else 2807 return gethostbyname(name); 2808 #endif 2809 } 2810 2811 struct hostent * 2812 sm_gethostbyaddr(addr, len, type) 2813 char *addr; 2814 int len; 2815 int type; 2816 { 2817 #if defined(SOLARIS) && SOLARIS < 204 2818 extern int h_errno; 2819 2820 # if SOLARIS == 203 2821 static struct hostent hp; 2822 static char buf[1000]; 2823 extern struct hostent *_switch_gethostbyaddr_r(); 2824 2825 return _switch_gethostbyaddr_r(addr, len, type, &hp, buf, sizeof(buf), &h_errno); 2826 # else 2827 extern struct hostent *__switch_gethostbyaddr(); 2828 2829 return __switch_gethostbyaddr(addr, len, type); 2830 # endif 2831 #else 2832 return gethostbyaddr(addr, len, type); 2833 #endif 2834 } 2835 /* 2836 ** SM_GETPW{NAM,UID} -- wrapper for getpwnam and getpwuid 2837 */ 2838 2839 struct passwd * 2840 sm_getpwnam(user) 2841 char *user; 2842 { 2843 return getpwnam(user); 2844 } 2845 2846 struct passwd * 2847 sm_getpwuid(uid) 2848 uid_t uid; 2849 { 2850 return getpwuid(uid); 2851 } 2852 /* 2853 ** NI_PROPVAL -- netinfo property value lookup routine 2854 ** 2855 ** Parameters: 2856 ** keydir -- the Netinfo directory name in which to search 2857 ** for the key. 2858 ** keyprop -- the name of the property in which to find the 2859 ** property we are interested. Defaults to "name". 2860 ** keyval -- the value for which we are really searching. 2861 ** valprop -- the property name for the value in which we 2862 ** are interested. 2863 ** sepchar -- if non-nil, this can be multiple-valued, and 2864 ** we should return a string separated by this 2865 ** character. 2866 ** 2867 ** Returns: 2868 ** NULL -- if: 2869 ** 1. the directory is not found 2870 ** 2. the property name is not found 2871 ** 3. the property contains multiple values 2872 ** 4. some error occured 2873 ** else -- the location of the config file. 2874 ** 2875 ** Example: 2876 ** To search for an alias value, use: 2877 ** ni_propval("/aliases", "name", aliasname, "members", ',') 2878 ** 2879 ** Notes: 2880 ** Caller should free the return value of ni_proval 2881 */ 2882 2883 #ifdef NETINFO 2884 2885 # include <netinfo/ni.h> 2886 2887 # define LOCAL_NETINFO_DOMAIN "." 2888 # define PARENT_NETINFO_DOMAIN ".." 2889 # define MAX_NI_LEVELS 256 2890 2891 char * 2892 ni_propval(keydir, keyprop, keyval, valprop, sepchar) 2893 char *keydir; 2894 char *keyprop; 2895 char *keyval; 2896 char *valprop; 2897 char sepchar; 2898 { 2899 char *propval = NULL; 2900 int i; 2901 int j, alen; 2902 void *ni = NULL; 2903 void *lastni = NULL; 2904 ni_status nis; 2905 ni_id nid; 2906 ni_namelist ninl; 2907 register char *p; 2908 char keybuf[1024]; 2909 2910 /* 2911 ** Create the full key from the two parts. 2912 ** 2913 ** Note that directory can end with, e.g., "name=" to specify 2914 ** an alternate search property. 2915 */ 2916 2917 i = strlen(keydir) + strlen(keyval) + 2; 2918 if (keyprop != NULL) 2919 i += strlen(keyprop) + 1; 2920 if (i > sizeof keybuf) 2921 return NULL; 2922 strcpy(keybuf, keydir); 2923 strcat(keybuf, "/"); 2924 if (keyprop != NULL) 2925 { 2926 strcat(keybuf, keyprop); 2927 strcat(keybuf, "="); 2928 } 2929 strcat(keybuf, keyval); 2930 2931 /* 2932 ** If the passed directory and property name are found 2933 ** in one of netinfo domains we need to search (starting 2934 ** from the local domain moving all the way back to the 2935 ** root domain) set propval to the property's value 2936 ** and return it. 2937 */ 2938 2939 for (i = 0; i < MAX_NI_LEVELS; ++i) 2940 { 2941 if (i == 0) 2942 { 2943 nis = ni_open(NULL, LOCAL_NETINFO_DOMAIN, &ni); 2944 } 2945 else 2946 { 2947 if (lastni != NULL) 2948 ni_free(lastni); 2949 lastni = ni; 2950 nis = ni_open(lastni, PARENT_NETINFO_DOMAIN, &ni); 2951 } 2952 2953 /* 2954 ** Don't bother if we didn't get a handle on a 2955 ** proper domain. This is not necessarily an error. 2956 ** We would get a positive ni_status if, for instance 2957 ** we never found the directory or property and tried 2958 ** to open the parent of the root domain! 2959 */ 2960 2961 if (nis != 0) 2962 break; 2963 2964 /* 2965 ** Find the path to the server information. 2966 */ 2967 2968 if (ni_pathsearch(ni, &nid, keybuf) != 0) 2969 continue; 2970 2971 /* 2972 ** Find associated value information. 2973 */ 2974 2975 if (ni_lookupprop(ni, &nid, valprop, &ninl) != 0) 2976 continue; 2977 2978 /* 2979 ** See if we have an acceptable number of values. 2980 */ 2981 2982 if (ninl.ni_namelist_len <= 0) 2983 continue; 2984 2985 if (sepchar == '\0' && ninl.ni_namelist_len > 1) 2986 { 2987 ni_namelist_free(&ninl); 2988 continue; 2989 } 2990 2991 /* 2992 ** Calculate number of bytes needed and build result 2993 */ 2994 2995 alen = 1; 2996 for (j = 0; j < ninl.ni_namelist_len; j++) 2997 alen += strlen(ninl.ni_namelist_val[j]) + 1; 2998 propval = p = xalloc(alen); 2999 for (j = 0; j < ninl.ni_namelist_len; j++) 3000 { 3001 strcpy(p, ninl.ni_namelist_val[j]); 3002 p += strlen(p); 3003 *p++ = sepchar; 3004 } 3005 *--p = '\0'; 3006 3007 ni_namelist_free(&ninl); 3008 } 3009 3010 /* 3011 ** Clean up. 3012 */ 3013 3014 if (ni != NULL) 3015 ni_free(ni); 3016 if (lastni != NULL && ni != lastni) 3017 ni_free(lastni); 3018 3019 return propval; 3020 } 3021 3022 #endif /* NETINFO */ 3023 /* 3024 ** HARD_SYSLOG -- call syslog repeatedly until it works 3025 ** 3026 ** Needed on HP-UX, which apparently doesn't guarantee that 3027 ** syslog succeeds during interrupt handlers. 3028 */ 3029 3030 #ifdef __hpux 3031 3032 # define MAXSYSLOGTRIES 100 3033 # undef syslog 3034 3035 # ifdef __STDC__ 3036 hard_syslog(int pri, char *msg, ...) 3037 # else 3038 hard_syslog(pri, msg, va_alist) 3039 int pri; 3040 char *msg; 3041 va_dcl 3042 # endif 3043 { 3044 int i; 3045 char buf[SYSLOG_BUFSIZE * 2]; 3046 VA_LOCAL_DECL; 3047 3048 VA_START(msg); 3049 vsprintf(buf, msg, ap); 3050 VA_END; 3051 3052 for (i = MAXSYSLOGTRIES; --i >= 0 && syslog(pri, "%s", buf) < 0; ) 3053 continue; 3054 } 3055 3056 #endif 3057 /* 3058 ** LOCAL_HOSTNAME_LENGTH 3059 ** 3060 ** This is required to get sendmail to compile against BIND 4.9.x 3061 ** on Ultrix. 3062 */ 3063 3064 #if defined(ultrix) && NAMED_BIND 3065 3066 # include <resolv.h> 3067 # if __RES >= 19931104 3068 3069 int 3070 local_hostname_length(hostname) 3071 char *hostname; 3072 { 3073 int len_host, len_domain; 3074 3075 if (!*_res.defdname) 3076 res_init(); 3077 len_host = strlen(hostname); 3078 len_domain = strlen(_res.defdname); 3079 if (len_host > len_domain && 3080 (strcasecmp(hostname + len_host - len_domain,_res.defdname) == 0) && 3081 hostname[len_host - len_domain - 1] == '.') 3082 return len_host - len_domain - 1; 3083 else 3084 return 0; 3085 } 3086 3087 # endif 3088 #endif 3089 /* 3090 ** Compile-Time options 3091 */ 3092 3093 char *CompileOptions[] = 3094 { 3095 #if HESIOD 3096 "HESIOD", 3097 #endif 3098 #if LOG 3099 "LOG", 3100 #endif 3101 #if MATCHGECOS 3102 "MATCHGECOS", 3103 #endif 3104 #if NAMED_BIND 3105 "NAMED_BIND", 3106 #endif 3107 #if NDBM 3108 "NDBM", 3109 #endif 3110 #if NETINET 3111 "NETINET", 3112 #endif 3113 #if NETINFO 3114 "NETINFO", 3115 #endif 3116 #if NETISO 3117 "NETISO", 3118 #endif 3119 #if NETNS 3120 "NETNS", 3121 #endif 3122 #if NETUNIX 3123 "NETUNIX", 3124 #endif 3125 #if NETX25 3126 "NETX25", 3127 #endif 3128 #if NEWDB 3129 "NEWDB", 3130 #endif 3131 #if NIS 3132 "NIS", 3133 #endif 3134 #if SCANF 3135 "SCANF", 3136 #endif 3137 #if SUID_ROOT_FILES_OK 3138 "SUID_ROOT_FILES_OK", 3139 #endif 3140 #if USERDB 3141 "USERDB", 3142 #endif 3143 #if XDEBUG 3144 "XDEBUG", 3145 #endif 3146 #if XLA 3147 "XLA", 3148 #endif 3149 NULL 3150 }; 3151