1 /* $NetBSD: mail_queue.h,v 1.2 2017/02/14 01:16:45 christos Exp $ */ 2 3 #ifndef _MAIL_QUEUE_H_INCLUDED_ 4 #define _MAIL_QUEUE_H_INCLUDED_ 5 6 /*++ 7 /* NAME 8 /* mail_queue 3h 9 /* SUMMARY 10 /* mail queue access 11 /* SYNOPSIS 12 /* #include <mail_queue.h> 13 /* DESCRIPTION 14 /* .nf 15 16 /* 17 * System library. 18 */ 19 #include <sys/time.h> 20 21 /* 22 * Utility library. 23 */ 24 #include <vstring.h> 25 #include <vstream.h> 26 27 /* 28 * Mail queue names. 29 */ 30 #define MAIL_QUEUE_MAILDROP "maildrop" 31 #define MAIL_QUEUE_HOLD "hold" 32 #define MAIL_QUEUE_INCOMING "incoming" 33 #define MAIL_QUEUE_ACTIVE "active" 34 #define MAIL_QUEUE_DEFERRED "deferred" 35 #define MAIL_QUEUE_TRACE "trace" 36 #define MAIL_QUEUE_DEFER "defer" 37 #define MAIL_QUEUE_BOUNCE "bounce" 38 #define MAIL_QUEUE_CORRUPT "corrupt" 39 #define MAIL_QUEUE_FLUSH "flush" 40 #define MAIL_QUEUE_SAVED "saved" 41 42 /* 43 * Queue file modes. 44 * 45 * 4.4BSD-like systems don't allow (sticky AND executable) together, so we use 46 * group read permission bits instead. These are more portable, but they 47 * also are more likely to be turned on by accident. It would not be the end 48 * of the world. 49 */ 50 #define MAIL_QUEUE_STAT_READY (S_IRUSR | S_IWUSR | S_IXUSR) 51 #define MAIL_QUEUE_STAT_CORRUPT (S_IRUSR) 52 #ifndef MAIL_QUEUE_STAT_UNTHROTTLE 53 #define MAIL_QUEUE_STAT_UNTHROTTLE (S_IRGRP) 54 #endif 55 56 extern struct VSTREAM *mail_queue_enter(const char *, mode_t, struct timeval *); 57 extern struct VSTREAM *mail_queue_open(const char *, const char *, int, mode_t); 58 extern int mail_queue_rename(const char *, const char *, const char *); 59 extern int mail_queue_remove(const char *, const char *); 60 extern const char *mail_queue_dir(VSTRING *, const char *, const char *); 61 extern const char *mail_queue_path(VSTRING *, const char *, const char *); 62 extern int mail_queue_mkdirs(const char *); 63 extern int mail_queue_name_ok(const char *); 64 extern int mail_queue_id_ok(const char *); 65 66 /* 67 * MQID - Mail Queue ID format definitions. Needed only by code that creates 68 * or parses queue ID strings. 69 */ 70 #ifdef MAIL_QUEUE_INTERNAL 71 72 /* 73 * System library. 74 */ 75 #include <errno.h> 76 77 /* 78 * Global library. 79 */ 80 #include <safe_ultostr.h> 81 82 /* 83 * The long non-repeating queue ID is encoded in an alphabet of 10 digits, 84 * 21 upper-case characters, and 21 or fewer lower-case characters. The 85 * alphabet is made "safe" by removing all the vowels (AEIOUaeiou). The ID 86 * is the concatenation of: 87 * 88 * - the time in seconds (base 52 encoded, six or more chars), 89 * 90 * - the time in microseconds (base 52 encoded, exactly four chars), 91 * 92 * - the 'z' character to separate the time and inode information, 93 * 94 * - the inode number (base 51 encoded so that it contains no 'z'). 95 */ 96 #define MQID_LG_SEC_BASE 52 /* seconds safe alphabet base */ 97 #define MQID_LG_SEC_PAD 6 /* seconds minumum field width */ 98 #define MQID_LG_USEC_BASE 52 /* microseconds safe alphabet base */ 99 #define MQID_LG_USEC_PAD 4 /* microseconds exact field width */ 100 #define MQID_LG_TIME_PAD (MQID_LG_SEC_PAD + MQID_LG_USEC_PAD) 101 #define MQID_LG_INUM_SEP 'z' /* time-inode separator */ 102 #define MQID_LG_INUM_BASE 51 /* inode safe alphabet base */ 103 #define MQID_LG_INUM_PAD 0 /* no padding needed */ 104 105 #define MQID_FIND_LG_INUM_SEPARATOR(cp, path) \ 106 (((cp) = strrchr((path), MQID_LG_INUM_SEP)) != 0 \ 107 && ((cp) - (path) >= MQID_LG_TIME_PAD)) 108 109 #define MQID_GET_INUM(path, inum, long_form, error) do { \ 110 char *_cp; \ 111 if (((long_form) = MQID_FIND_LG_INUM_SEPARATOR(_cp, (path))) != 0) { \ 112 MQID_LG_DECODE_INUM(_cp + 1, (inum), (error)); \ 113 } else { \ 114 MQID_SH_DECODE_INUM((path) + MQID_SH_USEC_PAD, (inum), (error)); \ 115 } \ 116 } while (0) 117 118 #define MQID_LG_ENCODE_SEC(buf, val) \ 119 MQID_LG_ENCODE((buf), (val), MQID_LG_SEC_BASE, MQID_LG_SEC_PAD) 120 121 #define MQID_LG_ENCODE_USEC(buf, val) \ 122 MQID_LG_ENCODE((buf), (val), MQID_LG_USEC_BASE, MQID_LG_USEC_PAD) 123 124 #define MQID_LG_ENCODE_INUM(buf, val) \ 125 MQID_LG_ENCODE((buf), (val), MQID_LG_INUM_BASE, MQID_LG_INUM_PAD) 126 127 #define MQID_LG_DECODE_USEC(str, ulval, error) \ 128 MQID_LG_DECODE((str), (ulval), MQID_LG_USEC_BASE, (error)) 129 130 #define MQID_LG_DECODE_INUM(str, ulval, error) \ 131 MQID_LG_DECODE((str), (ulval), MQID_LG_INUM_BASE, (error)) 132 133 #define MQID_LG_ENCODE(buf, val, base, padlen) \ 134 safe_ultostr((buf), (unsigned long) (val), (base), (padlen), '0') 135 136 #define MQID_LG_DECODE(str, ulval, base, error) do { \ 137 char *_end; \ 138 errno = 0; \ 139 (ulval) = safe_strtoul((str), &_end, (base)); \ 140 (error) = (*_end != 0 || ((ulval) == ULONG_MAX && errno == ERANGE)); \ 141 } while (0) 142 143 #define MQID_LG_GET_HEX_USEC(bp, zp) do { \ 144 int _error; \ 145 unsigned long _us_val; \ 146 vstring_strncpy((bp), (zp) - MQID_LG_USEC_PAD, MQID_LG_USEC_PAD); \ 147 MQID_LG_DECODE_USEC(STR(bp), _us_val, _error); \ 148 if (_error) \ 149 _us_val = 0; \ 150 (void) MQID_SH_ENCODE_USEC((bp), _us_val); \ 151 } while (0) 152 153 /* 154 * The short repeating queue ID is encoded in upper-case hexadecimal, and is 155 * the concatenation of: 156 * 157 * - the time in microseconds (exactly five chars), 158 * 159 * - the inode number. 160 */ 161 #define MQID_SH_USEC_PAD 5 /* microseconds exact field width */ 162 163 #define MQID_SH_ENCODE_USEC(buf, usec) \ 164 vstring_str(vstring_sprintf((buf), "%05X", (int) (usec))) 165 166 #define MQID_SH_ENCODE_INUM(buf, inum) \ 167 vstring_str(vstring_sprintf((buf), "%lX", (unsigned long) (inum))) 168 169 #define MQID_SH_DECODE_INUM(str, ulval, error) do { \ 170 char *_end; \ 171 errno = 0; \ 172 (ulval) = strtoul((str), &_end, 16); \ 173 (error) = (*_end != 0 || ((ulval) == ULONG_MAX && errno == ERANGE)); \ 174 } while (0) 175 176 #endif /* MAIL_QUEUE_INTERNAL */ 177 178 /* LICENSE 179 /* .ad 180 /* .fi 181 /* The Secure Mailer license must be distributed with this software. 182 /* AUTHOR(S) 183 /* Wietse Venema 184 /* IBM T.J. Watson Research 185 /* P.O. Box 704 186 /* Yorktown Heights, NY 10598, USA 187 /*--*/ 188 189 #endif /* _MAIL_QUEUE_H_INCLUDED_ */ 190