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 1640266059SGregory Neil Shapiro SM_RCSID("@(#)$Id: sysexits.c,v 8.33 2001/09/11 04:05:17 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 40c2aa98e2SPeter Wemm /* now decode the other two field parts */ 41c2aa98e2SPeter Wemm if (*++dsncode == '.') 42c2aa98e2SPeter Wemm dsncode++; 43c2aa98e2SPeter Wemm code2 = atoi(dsncode); 44c2aa98e2SPeter Wemm while (*dsncode != '\0' && *dsncode != '.') 45c2aa98e2SPeter Wemm dsncode++; 46c2aa98e2SPeter Wemm if (*dsncode != '\0') 47c2aa98e2SPeter Wemm dsncode++; 48c2aa98e2SPeter Wemm code3 = atoi(dsncode); 49c2aa98e2SPeter Wemm 50c2aa98e2SPeter Wemm /* and do a nested switch to work them out */ 51c2aa98e2SPeter Wemm switch (code2) 52c2aa98e2SPeter Wemm { 53c2aa98e2SPeter Wemm case 0: /* Other or Undefined status */ 54c2aa98e2SPeter Wemm return EX_UNAVAILABLE; 55c2aa98e2SPeter Wemm 56c2aa98e2SPeter Wemm case 1: /* Address Status */ 57c2aa98e2SPeter Wemm switch (code3) 58c2aa98e2SPeter Wemm { 59c2aa98e2SPeter Wemm case 0: /* Other Address Status */ 60c2aa98e2SPeter Wemm return EX_DATAERR; 61c2aa98e2SPeter Wemm 62c2aa98e2SPeter Wemm case 1: /* Bad destination mailbox address */ 63c2aa98e2SPeter Wemm case 6: /* Mailbox has moved, No forwarding address */ 64c2aa98e2SPeter Wemm return EX_NOUSER; 65c2aa98e2SPeter Wemm 66c2aa98e2SPeter Wemm case 2: /* Bad destination system address */ 67c2aa98e2SPeter Wemm case 8: /* Bad senders system address */ 68c2aa98e2SPeter Wemm return EX_NOHOST; 69c2aa98e2SPeter Wemm 70c2aa98e2SPeter Wemm case 3: /* Bad destination mailbox address syntax */ 71c2aa98e2SPeter Wemm case 7: /* Bad senders mailbox address syntax */ 72c2aa98e2SPeter Wemm return EX_USAGE; 73c2aa98e2SPeter Wemm 74c2aa98e2SPeter Wemm case 4: /* Destination mailbox address ambiguous */ 75c2aa98e2SPeter Wemm return EX_UNAVAILABLE; 76c2aa98e2SPeter Wemm 77c2aa98e2SPeter Wemm case 5: /* Destination address valid */ 78c2aa98e2SPeter Wemm return EX_OK; 79c2aa98e2SPeter Wemm } 80c2aa98e2SPeter Wemm break; 81c2aa98e2SPeter Wemm 82c2aa98e2SPeter Wemm case 2: /* Mailbox Status */ 83c2aa98e2SPeter Wemm switch (code3) 84c2aa98e2SPeter Wemm { 85c2aa98e2SPeter Wemm case 0: /* Other or Undefined mailbox status */ 8606f25ae9SGregory Neil Shapiro case 1: /* Mailbox disabled, not accepting messages */ 87c2aa98e2SPeter Wemm case 2: /* Mailbox full */ 88c2aa98e2SPeter Wemm case 4: /* Mailing list expansion problem */ 89c2aa98e2SPeter Wemm return EX_UNAVAILABLE; 90c2aa98e2SPeter Wemm 91c2aa98e2SPeter Wemm case 3: /* Message length exceeds administrative lim */ 92c2aa98e2SPeter Wemm return EX_DATAERR; 93c2aa98e2SPeter Wemm } 94c2aa98e2SPeter Wemm break; 95c2aa98e2SPeter Wemm 96c2aa98e2SPeter Wemm case 3: /* System Status */ 97c2aa98e2SPeter Wemm return EX_OSERR; 98c2aa98e2SPeter Wemm 99c2aa98e2SPeter Wemm case 4: /* Network and Routing Status */ 100c2aa98e2SPeter Wemm switch (code3) 101c2aa98e2SPeter Wemm { 102c2aa98e2SPeter Wemm case 0: /* Other or undefined network or routing stat */ 103c2aa98e2SPeter Wemm return EX_IOERR; 104c2aa98e2SPeter Wemm 105c2aa98e2SPeter Wemm case 1: /* No answer from host */ 106c2aa98e2SPeter Wemm case 3: /* Routing server failure */ 107c2aa98e2SPeter Wemm case 5: /* Network congestion */ 108c2aa98e2SPeter Wemm return EX_TEMPFAIL; 109c2aa98e2SPeter Wemm 110c2aa98e2SPeter Wemm case 2: /* Bad connection */ 111c2aa98e2SPeter Wemm return EX_IOERR; 112c2aa98e2SPeter Wemm 113c2aa98e2SPeter Wemm case 4: /* Unable to route */ 114c2aa98e2SPeter Wemm return EX_PROTOCOL; 115c2aa98e2SPeter Wemm 116c2aa98e2SPeter Wemm case 6: /* Routing loop detected */ 117c2aa98e2SPeter Wemm return EX_CONFIG; 118c2aa98e2SPeter Wemm 119c2aa98e2SPeter Wemm case 7: /* Delivery time expired */ 120c2aa98e2SPeter Wemm return EX_UNAVAILABLE; 121c2aa98e2SPeter Wemm } 122c2aa98e2SPeter Wemm break; 123c2aa98e2SPeter Wemm 124c2aa98e2SPeter Wemm case 5: /* Protocol Status */ 125c2aa98e2SPeter Wemm return EX_PROTOCOL; 126c2aa98e2SPeter Wemm 127c2aa98e2SPeter Wemm case 6: /* Message Content or Media Status */ 128c2aa98e2SPeter Wemm return EX_UNAVAILABLE; 129c2aa98e2SPeter Wemm 130c2aa98e2SPeter Wemm case 7: /* Security Status */ 131c2aa98e2SPeter Wemm return EX_DATAERR; 132c2aa98e2SPeter Wemm } 133c2aa98e2SPeter Wemm return EX_CONFIG; 134c2aa98e2SPeter Wemm } 13540266059SGregory Neil Shapiro /* 13606f25ae9SGregory Neil Shapiro ** EXITSTAT -- convert EX_ value to error text. 13706f25ae9SGregory Neil Shapiro ** 13806f25ae9SGregory Neil Shapiro ** Parameters: 13906f25ae9SGregory Neil Shapiro ** excode -- rstatus which might consists of an EX_* value. 14006f25ae9SGregory Neil Shapiro ** 14106f25ae9SGregory Neil Shapiro ** Returns: 14206f25ae9SGregory Neil Shapiro ** The corresponding error text or the original string. 14306f25ae9SGregory Neil Shapiro */ 14406f25ae9SGregory Neil Shapiro 14506f25ae9SGregory Neil Shapiro char * 14606f25ae9SGregory Neil Shapiro exitstat(excode) 14706f25ae9SGregory Neil Shapiro char *excode; 14806f25ae9SGregory Neil Shapiro { 14906f25ae9SGregory Neil Shapiro char *c; 15006f25ae9SGregory Neil Shapiro int i; 15140266059SGregory Neil Shapiro char *exitmsg; 15206f25ae9SGregory Neil Shapiro 15306f25ae9SGregory Neil Shapiro if (excode == NULL || *excode == '\0') 15406f25ae9SGregory Neil Shapiro return excode; 15540266059SGregory Neil Shapiro i = (int) strtol(excode, &c, 10); 15640266059SGregory Neil Shapiro if (*c != '\0') 15706f25ae9SGregory Neil Shapiro return excode; 15840266059SGregory Neil Shapiro exitmsg = sm_sysexitmsg(i); 15940266059SGregory Neil Shapiro if (exitmsg != NULL) 16040266059SGregory Neil Shapiro return exitmsg; 16106f25ae9SGregory Neil Shapiro return excode; 16206f25ae9SGregory Neil Shapiro } 163