1 /* $OpenBSD: queue_null.c,v 1.1 2013/01/26 09:37:23 gilles Exp $ */ 2 3 /* 4 * Copyright (c) 2012 Eric Faurot <eric@openbsd.org> 5 * 6 * Permission to use, copy, modify, and distribute this software for any 7 * purpose with or without fee is hereby granted, provided that the above 8 * copyright notice and this permission notice appear in all copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 */ 18 19 #include <sys/types.h> 20 #include <sys/queue.h> 21 #include <sys/tree.h> 22 #include <sys/param.h> 23 #include <sys/socket.h> 24 #include <sys/stat.h> 25 26 #include <ctype.h> 27 #include <err.h> 28 #include <errno.h> 29 #include <event.h> 30 #include <fcntl.h> 31 #include <imsg.h> 32 #include <inttypes.h> 33 #include <libgen.h> 34 #include <pwd.h> 35 #include <stdio.h> 36 #include <stdlib.h> 37 #include <string.h> 38 #include <time.h> 39 #include <unistd.h> 40 41 #include "smtpd.h" 42 #include "log.h" 43 44 static int queue_null_init(int); 45 static int queue_null_message(enum queue_op, uint32_t *); 46 static int queue_null_envelope(enum queue_op , uint64_t *, char *, size_t); 47 48 struct queue_backend queue_backend_null = { 49 queue_null_init, 50 queue_null_message, 51 queue_null_envelope, 52 }; 53 54 static int devnull; 55 56 static int 57 queue_null_init(int server) 58 { 59 60 devnull = open("/dev/null", O_WRONLY, 0777); 61 if (devnull == -1) { 62 log_warn("open"); 63 return (0); 64 } 65 66 return (1); 67 } 68 69 static int 70 queue_null_message(enum queue_op qop, uint32_t *msgid) 71 { 72 switch (qop) { 73 case QOP_CREATE: 74 *msgid = queue_generate_msgid(); 75 return (1); 76 case QOP_DELETE: 77 case QOP_COMMIT: 78 return (1); 79 case QOP_FD_R: 80 return (-1); 81 case QOP_FD_RW: 82 return dup(devnull); 83 case QOP_CORRUPT: 84 return (0); 85 default: 86 fatalx("queue_null_message: unsupported operation."); 87 } 88 89 return (0); 90 } 91 92 static int 93 queue_null_envelope(enum queue_op qop, uint64_t *evpid, char *buf, size_t len) 94 { 95 uint32_t msgid; 96 97 if (qop == QOP_WALK) 98 return (-1); 99 100 switch (qop) { 101 case QOP_CREATE: 102 msgid = evpid_to_msgid(*evpid); 103 *evpid = queue_generate_evpid(msgid); 104 return (1); 105 case QOP_DELETE: 106 return (1); 107 case QOP_LOAD: 108 return (0); 109 case QOP_UPDATE: 110 return (1); 111 default: 112 fatalx("queue_null_envelope: unsupported operation."); 113 } 114 115 return (0); 116 } 117