1 /* $NetBSD: cleanup_strerror.c,v 1.2 2022/10/08 16:12:45 christos Exp $ */ 2 3 /*++ 4 /* NAME 5 /* cleanup_strerror 3 6 /* SUMMARY 7 /* cleanup status code to string 8 /* SYNOPSIS 9 /* #include <cleanup_user.h> 10 /* 11 /* typedef struct { 12 /* .in +4 13 /* const unsigned status; /* cleanup status */ 14 /* const int smtp; /* RFC 821 */ 15 /* const char *dsn; /* RFC 3463 */ 16 /* const char *text; /* free text */ 17 /* .in -4 18 /* } CLEANUP_STAT_DETAIL; 19 /* 20 /* const char *cleanup_strerror(code) 21 /* int code; 22 /* 23 /* const CLEANUP_STAT_DETAIL *cleanup_stat_detail(code) 24 /* int code; 25 /* DESCRIPTION 26 /* cleanup_strerror() maps a status code returned by the \fIcleanup\fR 27 /* service to printable string. 28 /* The result is for read purposes only. 29 /* 30 /* cleanup_stat_detail() returns a pointer to structure with 31 /* assorted information. 32 /* DIAGNOSTICS: 33 /* Panic: unknown status. 34 /* LICENSE 35 /* .ad 36 /* .fi 37 /* The Secure Mailer license must be distributed with this software. 38 /* AUTHOR(S) 39 /* Wietse Venema 40 /* IBM T.J. Watson Research 41 /* P.O. Box 704 42 /* Yorktown Heights, NY 10598, USA 43 /* 44 /* Wietse Venema 45 /* Google, Inc. 46 /* 111 8th Avenue 47 /* New York, NY 10011, USA 48 /*--*/ 49 50 /* System library. */ 51 52 #include <sys_defs.h> 53 54 /* Utility library. */ 55 56 #include <vstring.h> 57 #include <msg.h> 58 59 /* Global library. */ 60 61 #include <cleanup_user.h> 62 63 /* 64 * Mapping from status code to printable string. One message may suffer from 65 * multiple errors, to it is important to list the most severe errors first, 66 * because cleanup_strerror() can report only one error. 67 */ 68 static const CLEANUP_STAT_DETAIL cleanup_stat_map[] = { 69 CLEANUP_STAT_DEFER, 451, "4.7.1", "service unavailable", 70 CLEANUP_STAT_PROXY, 451, "4.3.0", "queue file write error", 71 CLEANUP_STAT_BAD, 451, "4.3.0", "internal protocol error", 72 CLEANUP_STAT_RCPT, 550, "5.1.0", "no recipients specified", 73 CLEANUP_STAT_HOPS, 554, "5.4.0", "too many hops", 74 CLEANUP_STAT_SIZE, 552, "5.3.4", "message file too big", 75 CLEANUP_STAT_CONT, 550, "5.7.1", "message content rejected", 76 CLEANUP_STAT_WRITE, 451, "4.3.0", "queue file write error", 77 CLEANUP_STAT_NOPERM, 550, "5.7.1", "service denied", 78 }; 79 80 static CLEANUP_STAT_DETAIL cleanup_stat_success = { 81 CLEANUP_STAT_OK, 250, "2.0.0", "Success", 82 }; 83 84 /* cleanup_strerror - map status code to printable string */ 85 86 const char *cleanup_strerror(unsigned status) 87 { 88 unsigned i; 89 90 if (status == CLEANUP_STAT_OK) 91 return ("Success"); 92 93 for (i = 0; i < sizeof(cleanup_stat_map) / sizeof(cleanup_stat_map[0]); i++) 94 if (cleanup_stat_map[i].status & status) 95 return (cleanup_stat_map[i].text); 96 97 msg_panic("cleanup_strerror: unknown status %u", status); 98 } 99 100 /* cleanup_stat_detail - map status code to table entry with assorted data */ 101 102 const CLEANUP_STAT_DETAIL *cleanup_stat_detail(unsigned status) 103 { 104 unsigned i; 105 106 if (status == CLEANUP_STAT_OK) 107 return (&cleanup_stat_success); 108 109 for (i = 0; i < sizeof(cleanup_stat_map) / sizeof(cleanup_stat_map[0]); i++) 110 if (cleanup_stat_map[i].status & status) 111 return (cleanup_stat_map + i); 112 113 msg_panic("cleanup_stat_detail: unknown status %u", status); 114 } 115