1c2aa98e2SPeter Wemm /* 240266059SGregory Neil Shapiro * Copyright (c) 1998-2001 Sendmail, Inc. and its suppliers. 306f25ae9SGregory Neil Shapiro * All rights reserved. 4c2aa98e2SPeter Wemm * Copyright (c) 1983, 1995-1997 Eric P. Allman. All rights reserved. 5c2aa98e2SPeter Wemm * Copyright (c) 1988, 1993 6c2aa98e2SPeter Wemm * The Regents of the University of California. All rights reserved. 7c2aa98e2SPeter Wemm * 8c2aa98e2SPeter Wemm * By using this file, you agree to the terms and conditions set 9c2aa98e2SPeter Wemm * forth in the LICENSE file which can be found at the top level of 10c2aa98e2SPeter Wemm * the sendmail distribution. 11c2aa98e2SPeter Wemm * 12c2aa98e2SPeter Wemm */ 13c2aa98e2SPeter Wemm 1406f25ae9SGregory Neil Shapiro #include <sendmail.h> 15c2aa98e2SPeter Wemm 1613bd1963SGregory Neil Shapiro SM_RCSID("@(#)$Id: sysexits.c,v 8.33.4.1 2002/09/09 02:42:37 gshapiro Exp $") 1740266059SGregory Neil Shapiro 18c2aa98e2SPeter Wemm /* 19c2aa98e2SPeter Wemm ** DSNTOEXITSTAT -- convert DSN-style error code to EX_ style. 20c2aa98e2SPeter Wemm ** 21c2aa98e2SPeter Wemm ** Parameters: 22c2aa98e2SPeter Wemm ** dsncode -- the text of the DSN-style code. 23c2aa98e2SPeter Wemm ** 24c2aa98e2SPeter Wemm ** Returns: 25c2aa98e2SPeter Wemm ** The corresponding exit status. 26c2aa98e2SPeter Wemm */ 27c2aa98e2SPeter Wemm 28c2aa98e2SPeter Wemm int 29c2aa98e2SPeter Wemm dsntoexitstat(dsncode) 30c2aa98e2SPeter Wemm char *dsncode; 31c2aa98e2SPeter Wemm { 32c2aa98e2SPeter Wemm int code2, code3; 33c2aa98e2SPeter Wemm 34c2aa98e2SPeter Wemm /* first the easy cases.... */ 35c2aa98e2SPeter Wemm if (*dsncode == '2') 36c2aa98e2SPeter Wemm return EX_OK; 37c2aa98e2SPeter Wemm if (*dsncode == '4') 38c2aa98e2SPeter Wemm return EX_TEMPFAIL; 39c2aa98e2SPeter Wemm 4013bd1963SGregory Neil Shapiro /* reject other illegal values */ 4113bd1963SGregory Neil Shapiro if (*dsncode != '5') 4213bd1963SGregory Neil Shapiro return EX_CONFIG; 4313bd1963SGregory Neil Shapiro 44c2aa98e2SPeter Wemm /* now decode the other two field parts */ 45c2aa98e2SPeter Wemm if (*++dsncode == '.') 46c2aa98e2SPeter Wemm dsncode++; 47c2aa98e2SPeter Wemm code2 = atoi(dsncode); 48c2aa98e2SPeter Wemm while (*dsncode != '\0' && *dsncode != '.') 49c2aa98e2SPeter Wemm dsncode++; 50c2aa98e2SPeter Wemm if (*dsncode != '\0') 51c2aa98e2SPeter Wemm dsncode++; 52c2aa98e2SPeter Wemm code3 = atoi(dsncode); 53c2aa98e2SPeter Wemm 54c2aa98e2SPeter Wemm /* and do a nested switch to work them out */ 55c2aa98e2SPeter Wemm switch (code2) 56c2aa98e2SPeter Wemm { 57c2aa98e2SPeter Wemm case 0: /* Other or Undefined status */ 58c2aa98e2SPeter Wemm return EX_UNAVAILABLE; 59c2aa98e2SPeter Wemm 60c2aa98e2SPeter Wemm case 1: /* Address Status */ 61c2aa98e2SPeter Wemm switch (code3) 62c2aa98e2SPeter Wemm { 63c2aa98e2SPeter Wemm case 0: /* Other Address Status */ 64c2aa98e2SPeter Wemm return EX_DATAERR; 65c2aa98e2SPeter Wemm 66c2aa98e2SPeter Wemm case 1: /* Bad destination mailbox address */ 67c2aa98e2SPeter Wemm case 6: /* Mailbox has moved, No forwarding address */ 68c2aa98e2SPeter Wemm return EX_NOUSER; 69c2aa98e2SPeter Wemm 70c2aa98e2SPeter Wemm case 2: /* Bad destination system address */ 71c2aa98e2SPeter Wemm case 8: /* Bad senders system address */ 72c2aa98e2SPeter Wemm return EX_NOHOST; 73c2aa98e2SPeter Wemm 74c2aa98e2SPeter Wemm case 3: /* Bad destination mailbox address syntax */ 75c2aa98e2SPeter Wemm case 7: /* Bad senders mailbox address syntax */ 76c2aa98e2SPeter Wemm return EX_USAGE; 77c2aa98e2SPeter Wemm 78c2aa98e2SPeter Wemm case 4: /* Destination mailbox address ambiguous */ 79c2aa98e2SPeter Wemm return EX_UNAVAILABLE; 80c2aa98e2SPeter Wemm 81c2aa98e2SPeter Wemm case 5: /* Destination address valid */ 8213bd1963SGregory Neil Shapiro /* According to RFC1893, this can't happen */ 8313bd1963SGregory Neil Shapiro return EX_CONFIG; 84c2aa98e2SPeter Wemm } 85c2aa98e2SPeter Wemm break; 86c2aa98e2SPeter Wemm 87c2aa98e2SPeter Wemm case 2: /* Mailbox Status */ 88c2aa98e2SPeter Wemm switch (code3) 89c2aa98e2SPeter Wemm { 90c2aa98e2SPeter Wemm case 0: /* Other or Undefined mailbox status */ 9106f25ae9SGregory Neil Shapiro case 1: /* Mailbox disabled, not accepting messages */ 92c2aa98e2SPeter Wemm case 2: /* Mailbox full */ 93c2aa98e2SPeter Wemm case 4: /* Mailing list expansion problem */ 94c2aa98e2SPeter Wemm return EX_UNAVAILABLE; 95c2aa98e2SPeter Wemm 96c2aa98e2SPeter Wemm case 3: /* Message length exceeds administrative lim */ 97c2aa98e2SPeter Wemm return EX_DATAERR; 98c2aa98e2SPeter Wemm } 99c2aa98e2SPeter Wemm break; 100c2aa98e2SPeter Wemm 101c2aa98e2SPeter Wemm case 3: /* System Status */ 102c2aa98e2SPeter Wemm return EX_OSERR; 103c2aa98e2SPeter Wemm 104c2aa98e2SPeter Wemm case 4: /* Network and Routing Status */ 105c2aa98e2SPeter Wemm switch (code3) 106c2aa98e2SPeter Wemm { 107c2aa98e2SPeter Wemm case 0: /* Other or undefined network or routing stat */ 108c2aa98e2SPeter Wemm return EX_IOERR; 109c2aa98e2SPeter Wemm 110c2aa98e2SPeter Wemm case 1: /* No answer from host */ 111c2aa98e2SPeter Wemm case 3: /* Routing server failure */ 112c2aa98e2SPeter Wemm case 5: /* Network congestion */ 113c2aa98e2SPeter Wemm return EX_TEMPFAIL; 114c2aa98e2SPeter Wemm 115c2aa98e2SPeter Wemm case 2: /* Bad connection */ 116c2aa98e2SPeter Wemm return EX_IOERR; 117c2aa98e2SPeter Wemm 118c2aa98e2SPeter Wemm case 4: /* Unable to route */ 119c2aa98e2SPeter Wemm return EX_PROTOCOL; 120c2aa98e2SPeter Wemm 121c2aa98e2SPeter Wemm case 6: /* Routing loop detected */ 122c2aa98e2SPeter Wemm return EX_CONFIG; 123c2aa98e2SPeter Wemm 124c2aa98e2SPeter Wemm case 7: /* Delivery time expired */ 125c2aa98e2SPeter Wemm return EX_UNAVAILABLE; 126c2aa98e2SPeter Wemm } 127c2aa98e2SPeter Wemm break; 128c2aa98e2SPeter Wemm 129c2aa98e2SPeter Wemm case 5: /* Protocol Status */ 130c2aa98e2SPeter Wemm return EX_PROTOCOL; 131c2aa98e2SPeter Wemm 132c2aa98e2SPeter Wemm case 6: /* Message Content or Media Status */ 133c2aa98e2SPeter Wemm return EX_UNAVAILABLE; 134c2aa98e2SPeter Wemm 135c2aa98e2SPeter Wemm case 7: /* Security Status */ 136c2aa98e2SPeter Wemm return EX_DATAERR; 137c2aa98e2SPeter Wemm } 13813bd1963SGregory Neil Shapiro return EX_UNAVAILABLE; 139c2aa98e2SPeter Wemm } 14040266059SGregory Neil Shapiro /* 14106f25ae9SGregory Neil Shapiro ** EXITSTAT -- convert EX_ value to error text. 14206f25ae9SGregory Neil Shapiro ** 14306f25ae9SGregory Neil Shapiro ** Parameters: 14406f25ae9SGregory Neil Shapiro ** excode -- rstatus which might consists of an EX_* value. 14506f25ae9SGregory Neil Shapiro ** 14606f25ae9SGregory Neil Shapiro ** Returns: 14706f25ae9SGregory Neil Shapiro ** The corresponding error text or the original string. 14806f25ae9SGregory Neil Shapiro */ 14906f25ae9SGregory Neil Shapiro 15006f25ae9SGregory Neil Shapiro char * 15106f25ae9SGregory Neil Shapiro exitstat(excode) 15206f25ae9SGregory Neil Shapiro char *excode; 15306f25ae9SGregory Neil Shapiro { 15406f25ae9SGregory Neil Shapiro char *c; 15506f25ae9SGregory Neil Shapiro int i; 15640266059SGregory Neil Shapiro char *exitmsg; 15706f25ae9SGregory Neil Shapiro 15806f25ae9SGregory Neil Shapiro if (excode == NULL || *excode == '\0') 15906f25ae9SGregory Neil Shapiro return excode; 16040266059SGregory Neil Shapiro i = (int) strtol(excode, &c, 10); 16140266059SGregory Neil Shapiro if (*c != '\0') 16206f25ae9SGregory Neil Shapiro return excode; 16340266059SGregory Neil Shapiro exitmsg = sm_sysexitmsg(i); 16440266059SGregory Neil Shapiro if (exitmsg != NULL) 16540266059SGregory Neil Shapiro return exitmsg; 16606f25ae9SGregory Neil Shapiro return excode; 16706f25ae9SGregory Neil Shapiro } 168