1 /* backend.h -- IMAP server proxy for Cyrus Murder 2 * 3 * Copyright (c) 1994-2008 Carnegie Mellon University. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in 14 * the documentation and/or other materials provided with the 15 * distribution. 16 * 17 * 3. The name "Carnegie Mellon University" must not be used to 18 * endorse or promote products derived from this software without 19 * prior written permission. For permission or any legal 20 * details, please contact 21 * Carnegie Mellon University 22 * Center for Technology Transfer and Enterprise Creation 23 * 4615 Forbes Avenue 24 * Suite 302 25 * Pittsburgh, PA 15213 26 * (412) 268-7393, fax: (412) 268-7395 27 * innovation@andrew.cmu.edu 28 * 29 * 4. Redistributions of any form whatsoever must retain the following 30 * acknowledgment: 31 * "This product includes software developed by Computing Services 32 * at Carnegie Mellon University (http://www.cmu.edu/computing/)." 33 * 34 * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO 35 * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 36 * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE 37 * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 38 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN 39 * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 40 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 41 */ 42 43 #ifndef _INCLUDED_BACKEND_H 44 #define _INCLUDED_BACKEND_H 45 46 #include "global.h" 47 #include "mboxlist.h" 48 #include "prot.h" 49 #include "protocol.h" 50 #include "tls.h" 51 52 /* Functionality to bring up/down connections to backend servers */ 53 54 struct backend_cap_params { 55 unsigned long capa; 56 char *params; /* each BAR from FOO=BAR, in order, space separated */ 57 }; 58 59 struct backend { 60 char hostname[MAX_PARTITION_LEN]; 61 char banner[2048]; 62 struct sockaddr_storage addr; 63 int sock; 64 65 /* protocol we're speaking */ 66 struct protocol_t *prot; 67 68 /* service-specific context */ 69 void *context; 70 71 /* only used by imapd and nntpd */ 72 struct protstream *clientin; /* input stream from client to proxy */ 73 struct backend **current, **inbox; /* pointers to current/inbox be ptrs */ 74 struct prot_waitevent *timeout; /* event for idle timeout */ 75 76 sasl_conn_t *saslconn; 77 sasl_callback_t *sasl_cb; 78 sasl_ssf_t ext_ssf; 79 #ifdef HAVE_SSL 80 SSL *tlsconn; 81 SSL_SESSION *tlssess; 82 #endif /* HAVE_SSL */ 83 84 unsigned long capability; 85 int num_cap_params; 86 struct backend_cap_params *cap_params; 87 88 struct buf last_result; 89 struct protstream *in; /* from the be server to me, the proxy */ 90 struct protstream *out; /* to the be server */ 91 }; 92 93 /* if cache is NULL, returns a new struct backend, otherwise returns 94 * cache on success (and returns NULL on failure, but leaves cache alone) */ 95 struct backend *backend_connect(struct backend *cache, const char *server, 96 struct protocol_t *prot, const char *userid, 97 sasl_callback_t *cb, const char **auth_status, 98 int logfd); 99 int backend_starttls( struct backend *s, 100 struct tls_cmd_t *tls_cmd, 101 const char *c_cert_file, 102 const char *c_key_file); 103 104 int backend_ping(struct backend *s, const char *userid); 105 void backend_disconnect(struct backend *s); 106 char *intersect_mechlists(char *config, char *server); 107 char *backend_get_cap_params(const struct backend *, unsigned long capa); 108 109 #define CAPA(s, c) ((s)->capability & (c)) 110 111 #endif /* _INCLUDED_BACKEND_H */ 112