1 /* 2 * Copyright (c) 1998-2001 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 #include <sendmail.h> 15 16 SM_RCSID("@(#)$Id: sysexits.c,v 8.33 2001/09/11 04:05:17 gshapiro Exp $") 17 18 /* 19 ** DSNTOEXITSTAT -- convert DSN-style error code to EX_ style. 20 ** 21 ** Parameters: 22 ** dsncode -- the text of the DSN-style code. 23 ** 24 ** Returns: 25 ** The corresponding exit status. 26 */ 27 28 int 29 dsntoexitstat(dsncode) 30 char *dsncode; 31 { 32 int code2, code3; 33 34 /* first the easy cases.... */ 35 if (*dsncode == '2') 36 return EX_OK; 37 if (*dsncode == '4') 38 return EX_TEMPFAIL; 39 40 /* now decode the other two field parts */ 41 if (*++dsncode == '.') 42 dsncode++; 43 code2 = atoi(dsncode); 44 while (*dsncode != '\0' && *dsncode != '.') 45 dsncode++; 46 if (*dsncode != '\0') 47 dsncode++; 48 code3 = atoi(dsncode); 49 50 /* and do a nested switch to work them out */ 51 switch (code2) 52 { 53 case 0: /* Other or Undefined status */ 54 return EX_UNAVAILABLE; 55 56 case 1: /* Address Status */ 57 switch (code3) 58 { 59 case 0: /* Other Address Status */ 60 return EX_DATAERR; 61 62 case 1: /* Bad destination mailbox address */ 63 case 6: /* Mailbox has moved, No forwarding address */ 64 return EX_NOUSER; 65 66 case 2: /* Bad destination system address */ 67 case 8: /* Bad senders system address */ 68 return EX_NOHOST; 69 70 case 3: /* Bad destination mailbox address syntax */ 71 case 7: /* Bad senders mailbox address syntax */ 72 return EX_USAGE; 73 74 case 4: /* Destination mailbox address ambiguous */ 75 return EX_UNAVAILABLE; 76 77 case 5: /* Destination address valid */ 78 return EX_OK; 79 } 80 break; 81 82 case 2: /* Mailbox Status */ 83 switch (code3) 84 { 85 case 0: /* Other or Undefined mailbox status */ 86 case 1: /* Mailbox disabled, not accepting messages */ 87 case 2: /* Mailbox full */ 88 case 4: /* Mailing list expansion problem */ 89 return EX_UNAVAILABLE; 90 91 case 3: /* Message length exceeds administrative lim */ 92 return EX_DATAERR; 93 } 94 break; 95 96 case 3: /* System Status */ 97 return EX_OSERR; 98 99 case 4: /* Network and Routing Status */ 100 switch (code3) 101 { 102 case 0: /* Other or undefined network or routing stat */ 103 return EX_IOERR; 104 105 case 1: /* No answer from host */ 106 case 3: /* Routing server failure */ 107 case 5: /* Network congestion */ 108 return EX_TEMPFAIL; 109 110 case 2: /* Bad connection */ 111 return EX_IOERR; 112 113 case 4: /* Unable to route */ 114 return EX_PROTOCOL; 115 116 case 6: /* Routing loop detected */ 117 return EX_CONFIG; 118 119 case 7: /* Delivery time expired */ 120 return EX_UNAVAILABLE; 121 } 122 break; 123 124 case 5: /* Protocol Status */ 125 return EX_PROTOCOL; 126 127 case 6: /* Message Content or Media Status */ 128 return EX_UNAVAILABLE; 129 130 case 7: /* Security Status */ 131 return EX_DATAERR; 132 } 133 return EX_CONFIG; 134 } 135 /* 136 ** EXITSTAT -- convert EX_ value to error text. 137 ** 138 ** Parameters: 139 ** excode -- rstatus which might consists of an EX_* value. 140 ** 141 ** Returns: 142 ** The corresponding error text or the original string. 143 */ 144 145 char * 146 exitstat(excode) 147 char *excode; 148 { 149 char *c; 150 int i; 151 char *exitmsg; 152 153 if (excode == NULL || *excode == '\0') 154 return excode; 155 i = (int) strtol(excode, &c, 10); 156 if (*c != '\0') 157 return excode; 158 exitmsg = sm_sysexitmsg(i); 159 if (exitmsg != NULL) 160 return exitmsg; 161 return excode; 162 } 163