122715Sdist /* 268839Seric * Copyright (c) 1983, 1995 Eric P. Allman 362532Sbostic * Copyright (c) 1988, 1993 462532Sbostic * The Regents of the University of California. All rights reserved. 533731Sbostic * 642829Sbostic * %sccs.include.redist.c% 733731Sbostic */ 822715Sdist 922715Sdist #ifndef lint 10*68849Seric static char sccsid[] = "@(#)sysexits.c 8.3 (Berkeley) 04/22/95"; 1133731Sbostic #endif /* not lint */ 1222715Sdist 1333930Sbostic #include <sysexits.h> 14297Seric 15575Seric /* 1658669Seric ** SYSEXITS.C -- error messages corresponding to sysexits.h 1758669Seric ** 1858669Seric ** If the first character of the string is a colon, interpolate 1958669Seric ** the current errno after the rest of the string. 2058669Seric */ 2158669Seric 2258669Seric char *SysExMsg[] = 2358669Seric { 2458669Seric /* 64 USAGE */ " 500 Bad usage", 2558669Seric /* 65 DATAERR */ " 501 Data format error", 2658669Seric /* 66 NOINPUT */ ":550 Cannot open input", 2758669Seric /* 67 NOUSER */ " 550 User unknown", 2858669Seric /* 68 NOHOST */ " 550 Host unknown", 2958669Seric /* 69 UNAVAILABLE */ " 554 Service unavailable", 3058669Seric /* 70 SOFTWARE */ ":554 Internal error", 3158669Seric /* 71 OSERR */ ":451 Operating system error", 3258669Seric /* 72 OSFILE */ ":554 System file missing", 3358669Seric /* 73 CANTCREAT */ ":550 Can't create output", 3458669Seric /* 74 IOERR */ ":451 I/O error", 3558669Seric /* 75 TEMPFAIL */ " 250 Deferred", 3658669Seric /* 76 PROTOCOL */ " 554 Remote protocol error", 3758669Seric /* 77 NOPERM */ ":550 Insufficient permission", 3858669Seric /* 78 CONFIG */ " 554 Local configuration error", 39297Seric }; 40297Seric 4133930Sbostic int N_SysEx = sizeof(SysExMsg) / sizeof(SysExMsg[0]); 42*68849Seric /* 43*68849Seric ** DSNTOEXITSTAT -- convert DSN-style error code to EX_ style. 44*68849Seric ** 45*68849Seric ** Parameters: 46*68849Seric ** dsncode -- the text of the DSN-style code. 47*68849Seric ** 48*68849Seric ** Returns: 49*68849Seric ** The corresponding exit status. 50*68849Seric */ 51*68849Seric 52*68849Seric int 53*68849Seric dsntoexitstat(dsncode) 54*68849Seric char *dsncode; 55*68849Seric { 56*68849Seric int code2, code3; 57*68849Seric 58*68849Seric /* first the easy cases.... */ 59*68849Seric if (*dsncode == '2') 60*68849Seric return EX_OK; 61*68849Seric if (*dsncode == '4') 62*68849Seric return EX_TEMPFAIL; 63*68849Seric 64*68849Seric /* now decode the other two field parts */ 65*68849Seric if (*++dsncode == '.') 66*68849Seric dsncode++; 67*68849Seric code2 = atoi(dsncode); 68*68849Seric while (*dsncode != '\0' && *dsncode != '.') 69*68849Seric dsncode++; 70*68849Seric if (*dsncode != '\0') 71*68849Seric dsncode++; 72*68849Seric code3 = atoi(dsncode); 73*68849Seric 74*68849Seric /* and do a nested switch to work them out */ 75*68849Seric switch (code2) 76*68849Seric { 77*68849Seric case 0: /* Other or Undefined status */ 78*68849Seric return EX_UNAVAILABLE; 79*68849Seric 80*68849Seric case 1: /* Address Status */ 81*68849Seric switch (code3) 82*68849Seric { 83*68849Seric case 0: /* Other Address Status */ 84*68849Seric return EX_DATAERR; 85*68849Seric 86*68849Seric case 1: /* Bad mailbox address */ 87*68849Seric case 6: /* Mailbox has moved, No forwarding address */ 88*68849Seric return EX_NOUSER; 89*68849Seric 90*68849Seric case 2: /* Bad system address */ 91*68849Seric return EX_NOHOST; 92*68849Seric 93*68849Seric case 3: /* Bad mailbox address syntax */ 94*68849Seric return EX_USAGE; 95*68849Seric 96*68849Seric case 4: /* Mailbox address ambiguous */ 97*68849Seric return EX_UNAVAILABLE; 98*68849Seric 99*68849Seric case 5: /* Address valid */ 100*68849Seric return EX_OK; 101*68849Seric } 102*68849Seric break; 103*68849Seric 104*68849Seric case 2: /* Mailbox Status */ 105*68849Seric switch (code3) 106*68849Seric { 107*68849Seric case 0: /* Other or Undefined mailbox status */ 108*68849Seric case 1: /* Mailbox disabled, not acccepting messages */ 109*68849Seric case 2: /* Mailbox full */ 110*68849Seric case 4: /* Mailing list expansion problem */ 111*68849Seric return EX_UNAVAILABLE; 112*68849Seric 113*68849Seric case 3: /* Message length exceeds administrative lim */ 114*68849Seric return EX_DATAERR; 115*68849Seric } 116*68849Seric break; 117*68849Seric 118*68849Seric case 3: /* System Status */ 119*68849Seric return EX_OSERR; 120*68849Seric 121*68849Seric case 4: /* Network and Routing Status */ 122*68849Seric switch (code3) 123*68849Seric { 124*68849Seric case 0: /* Other or undefined network or routing stat */ 125*68849Seric return EX_IOERR; 126*68849Seric 127*68849Seric case 1: /* No answer from host */ 128*68849Seric case 3: /* Routing server failure */ 129*68849Seric case 5: /* Network congestion */ 130*68849Seric return EX_TEMPFAIL; 131*68849Seric 132*68849Seric case 2: /* Bad connection */ 133*68849Seric return EX_IOERR; 134*68849Seric 135*68849Seric case 4: /* Unable to route */ 136*68849Seric return EX_PROTOCOL; 137*68849Seric 138*68849Seric case 6: /* Routing loop detected */ 139*68849Seric return EX_CONFIG; 140*68849Seric 141*68849Seric case 7: /* Delivery time expired */ 142*68849Seric return EX_UNAVAILABLE; 143*68849Seric } 144*68849Seric break; 145*68849Seric 146*68849Seric case 5: /* Protocol Status */ 147*68849Seric return EX_PROTOCOL; 148*68849Seric 149*68849Seric case 6: /* Message Content or Media Status */ 150*68849Seric return EX_UNAVAILABLE; 151*68849Seric 152*68849Seric case 7: /* Security Status */ 153*68849Seric return EX_DATAERR; 154*68849Seric } 155*68849Seric return EX_CONFIG; 156*68849Seric } 157