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*68859Seric static char sccsid[] = "@(#)sysexits.c 8.4 (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]); 4268849Seric /* 4368849Seric ** DSNTOEXITSTAT -- convert DSN-style error code to EX_ style. 4468849Seric ** 4568849Seric ** Parameters: 4668849Seric ** dsncode -- the text of the DSN-style code. 4768849Seric ** 4868849Seric ** Returns: 4968849Seric ** The corresponding exit status. 5068849Seric */ 5168849Seric 5268849Seric int 5368849Seric dsntoexitstat(dsncode) 5468849Seric char *dsncode; 5568849Seric { 5668849Seric int code2, code3; 5768849Seric 5868849Seric /* first the easy cases.... */ 5968849Seric if (*dsncode == '2') 6068849Seric return EX_OK; 6168849Seric if (*dsncode == '4') 6268849Seric return EX_TEMPFAIL; 6368849Seric 6468849Seric /* now decode the other two field parts */ 6568849Seric if (*++dsncode == '.') 6668849Seric dsncode++; 6768849Seric code2 = atoi(dsncode); 6868849Seric while (*dsncode != '\0' && *dsncode != '.') 6968849Seric dsncode++; 7068849Seric if (*dsncode != '\0') 7168849Seric dsncode++; 7268849Seric code3 = atoi(dsncode); 7368849Seric 7468849Seric /* and do a nested switch to work them out */ 7568849Seric switch (code2) 7668849Seric { 7768849Seric case 0: /* Other or Undefined status */ 7868849Seric return EX_UNAVAILABLE; 7968849Seric 8068849Seric case 1: /* Address Status */ 8168849Seric switch (code3) 8268849Seric { 8368849Seric case 0: /* Other Address Status */ 8468849Seric return EX_DATAERR; 8568849Seric 86*68859Seric case 1: /* Bad destination mailbox address */ 8768849Seric case 6: /* Mailbox has moved, No forwarding address */ 8868849Seric return EX_NOUSER; 8968849Seric 90*68859Seric case 2: /* Bad destination system address */ 91*68859Seric case 8: /* Bad senders system address */ 9268849Seric return EX_NOHOST; 9368849Seric 94*68859Seric case 3: /* Bad destination mailbox address syntax */ 95*68859Seric case 7: /* Bad senders mailbox address syntax */ 9668849Seric return EX_USAGE; 9768849Seric 98*68859Seric case 4: /* Destination mailbox address ambiguous */ 9968849Seric return EX_UNAVAILABLE; 10068849Seric 101*68859Seric case 5: /* Destination address valid */ 10268849Seric return EX_OK; 10368849Seric } 10468849Seric break; 10568849Seric 10668849Seric case 2: /* Mailbox Status */ 10768849Seric switch (code3) 10868849Seric { 10968849Seric case 0: /* Other or Undefined mailbox status */ 11068849Seric case 1: /* Mailbox disabled, not acccepting messages */ 11168849Seric case 2: /* Mailbox full */ 11268849Seric case 4: /* Mailing list expansion problem */ 11368849Seric return EX_UNAVAILABLE; 11468849Seric 11568849Seric case 3: /* Message length exceeds administrative lim */ 11668849Seric return EX_DATAERR; 11768849Seric } 11868849Seric break; 11968849Seric 12068849Seric case 3: /* System Status */ 12168849Seric return EX_OSERR; 12268849Seric 12368849Seric case 4: /* Network and Routing Status */ 12468849Seric switch (code3) 12568849Seric { 12668849Seric case 0: /* Other or undefined network or routing stat */ 12768849Seric return EX_IOERR; 12868849Seric 12968849Seric case 1: /* No answer from host */ 13068849Seric case 3: /* Routing server failure */ 13168849Seric case 5: /* Network congestion */ 13268849Seric return EX_TEMPFAIL; 13368849Seric 13468849Seric case 2: /* Bad connection */ 13568849Seric return EX_IOERR; 13668849Seric 13768849Seric case 4: /* Unable to route */ 13868849Seric return EX_PROTOCOL; 13968849Seric 14068849Seric case 6: /* Routing loop detected */ 14168849Seric return EX_CONFIG; 14268849Seric 14368849Seric case 7: /* Delivery time expired */ 14468849Seric return EX_UNAVAILABLE; 14568849Seric } 14668849Seric break; 14768849Seric 14868849Seric case 5: /* Protocol Status */ 14968849Seric return EX_PROTOCOL; 15068849Seric 15168849Seric case 6: /* Message Content or Media Status */ 15268849Seric return EX_UNAVAILABLE; 15368849Seric 15468849Seric case 7: /* Security Status */ 15568849Seric return EX_DATAERR; 15668849Seric } 15768849Seric return EX_CONFIG; 15868849Seric } 159