masqmail

annotate src/masqmail.h @ 127:05fe7500149d

refactored SMTP_HELO and SMTP_EHLO cases
author meillo@marmaro.de
date Tue, 06 Jul 2010 08:18:10 +0200
parents c678d0342451
children 5b621742b2e7
rev   line source
meillo@0 1 /* MasqMail
meillo@0 2 Copyright (C) 1999-2001 Oliver Kurth
meillo@0 3
meillo@0 4 This program is free software; you can redistribute it and/or modify
meillo@0 5 it under the terms of the GNU General Public License as published by
meillo@0 6 the Free Software Foundation; either version 2 of the License, or
meillo@0 7 (at your option) any later version.
meillo@0 8
meillo@0 9 This program is distributed in the hope that it will be useful,
meillo@0 10 but WITHOUT ANY WARRANTY; without even the implied warranty of
meillo@0 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
meillo@0 12 GNU General Public License for more details.
meillo@0 13
meillo@0 14 You should have received a copy of the GNU General Public License
meillo@0 15 along with this program; if not, write to the Free Software
meillo@0 16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
meillo@0 17 */
meillo@0 18 #include <config.h>
meillo@0 19
meillo@0 20 #include <stdio.h>
meillo@0 21 #include <stdarg.h>
meillo@0 22 #include <errno.h>
meillo@0 23 #include <stdlib.h>
meillo@0 24 #include <string.h>
meillo@0 25 #include <ctype.h>
meillo@0 26 #include <unistd.h>
meillo@0 27 #include <pwd.h>
meillo@0 28 #include <sys/types.h>
meillo@0 29 #include <sys/socket.h>
meillo@0 30 #include <netinet/in.h>
meillo@0 31 #include <time.h>
meillo@0 32 #include <sys/time.h>
meillo@0 33 #include <netinet/in.h>
meillo@0 34 #include <arpa/inet.h>
meillo@0 35 #include <netdb.h>
meillo@0 36 #include <syslog.h>
meillo@0 37 #include <signal.h>
meillo@0 38 #include <fcntl.h>
meillo@0 39
meillo@0 40 #include <glib.h>
meillo@0 41
meillo@0 42 #ifdef ENABLE_IDENT
meillo@0 43 #include "libident/ident.h"
meillo@0 44 #endif
meillo@0 45
meillo@0 46 #include "lookup.h"
meillo@0 47
meillo@10 48 typedef struct _interface {
meillo@10 49 gchar *address;
meillo@10 50 gint port;
meillo@0 51 } interface;
meillo@0 52
meillo@0 53 #define ADDR_FLAG_DELIVERED 0x01
meillo@0 54 #define ADDR_FLAG_DEFERED 0x02
meillo@0 55 #define ADDR_FLAG_FAILED 0x04
meillo@0 56 #define ADDR_FLAG_LAST_ROUTE 0x40
meillo@0 57 #define ADDR_FLAG_NOEXPAND 0x80
meillo@0 58
meillo@10 59 typedef struct _address {
meillo@10 60 gchar *address;
meillo@10 61 gchar *local_part;
meillo@10 62 gchar *domain;
meillo@10 63 gint flags;
meillo@10 64 GList *children;
meillo@10 65 struct _address *parent;
meillo@0 66 } address;
meillo@0 67
meillo@0 68 #define addr_mark_delivered(addr) { addr->flags |= ADDR_FLAG_DELIVERED; }
meillo@0 69 #define addr_unmark_delivered(addr) { addr->flags &= ~ADDR_FLAG_DELIVERED; }
meillo@0 70 #define addr_is_delivered(addr) ((addr->flags & ADDR_FLAG_DELIVERED) != 0 )
meillo@0 71
meillo@0 72 #define addr_mark_defered(addr) { addr->flags |= ADDR_FLAG_DEFERED; }
meillo@0 73 #define addr_unmark_defered(addr) { addr->flags &= ~ADDR_FLAG_DEFERED; }
meillo@0 74 #define addr_is_defered(addr) ((addr->flags & ADDR_FLAG_DEFERED) != 0 )
meillo@0 75
meillo@0 76 #define addr_mark_failed(addr) { addr->flags |= ADDR_FLAG_FAILED; }
meillo@0 77 #define addr_unmark_failed(addr) { addr->flags &= ~ADDR_FLAG_FAILED; }
meillo@0 78 #define addr_is_failed(addr) ((addr->flags & ADDR_FLAG_FAILED) != 0 )
meillo@0 79
meillo@10 80 typedef struct _connect_route {
meillo@10 81 gchar *name;
meillo@10 82 gchar *filename;
meillo@0 83
meillo@10 84 gchar *protocol;
meillo@0 85
meillo@10 86 gboolean is_local_net;
meillo@10 87 gboolean last_route;
meillo@0 88
meillo@10 89 GList *allowed_return_paths;
meillo@10 90 GList *not_allowed_return_paths;
meillo@10 91 GList *allowed_mail_locals;
meillo@10 92 GList *not_allowed_mail_locals;
meillo@10 93 GList *allowed_rcpt_domains;
meillo@10 94 GList *not_allowed_rcpt_domains;
meillo@0 95
meillo@10 96 interface *mail_host;
meillo@10 97 gchar *wrapper;
meillo@10 98 gboolean connect_error_fail;
meillo@0 99
meillo@10 100 gchar *helo_name;
meillo@10 101 gboolean do_correct_helo;
meillo@10 102 gboolean do_pipelining;
meillo@0 103
meillo@10 104 gchar *set_h_from_domain;
meillo@10 105 gchar *set_h_reply_to_domain;
meillo@10 106 gchar *set_return_path_domain;
meillo@0 107
meillo@10 108 GList *map_h_from_addresses;
meillo@10 109 GList *map_h_reply_to_addresses;
meillo@10 110 GList *map_h_mail_followup_to_addresses;
meillo@10 111 GList *map_return_path_addresses;
meillo@0 112
meillo@10 113 gboolean expand_h_sender_domain;
meillo@10 114 gboolean expand_h_sender_address;
meillo@0 115
meillo@10 116 GList *resolve_list;
meillo@0 117
meillo@10 118 gchar *auth_name;
meillo@10 119 gchar *auth_login;
meillo@10 120 gchar *auth_secret;
meillo@0 121
meillo@10 122 gchar *pop3_login;
meillo@0 123
meillo@10 124 gchar *pipe;
meillo@10 125
meillo@10 126 gboolean pipe_fromline;
meillo@10 127 gboolean pipe_fromhack;
meillo@0 128 } connect_route;
meillo@0 129
meillo@10 130 typedef struct _get_conf {
meillo@10 131 gchar *protocol;
meillo@10 132 gchar *server_name;
meillo@10 133 guint server_port;
meillo@10 134 gchar *wrapper;
meillo@10 135 gchar *login_user;
meillo@10 136 gchar *login_pass;
meillo@10 137 address *address;
meillo@10 138 address *return_path;
meillo@10 139 gboolean do_keep;
meillo@10 140 gboolean do_uidl;
meillo@10 141 gboolean do_uidl_dele;
meillo@10 142 gint max_size;
meillo@10 143 gboolean max_size_delete;
meillo@10 144 gint max_count;
meillo@0 145
meillo@10 146 GList *resolve_list;
meillo@0 147
meillo@0 148 } get_conf;
meillo@0 149
meillo@10 150 typedef struct _masqmail_conf {
meillo@10 151 gint mail_uid;
meillo@10 152 gint mail_gid;
meillo@0 153
meillo@10 154 gint orig_uid;
meillo@10 155 gint orig_gid;
meillo@0 156
meillo@10 157 gboolean run_as_user;
meillo@0 158
meillo@10 159 gchar *mail_dir;
meillo@10 160 gchar *lock_dir;
meillo@10 161 gchar *spool_dir;
meillo@10 162 gchar *log_dir;
meillo@0 163
meillo@10 164 gint debug_level;
meillo@10 165 gboolean use_syslog;
meillo@10 166 guint log_max_pri;
meillo@0 167
meillo@10 168 gchar *host_name;
meillo@10 169 GList *local_hosts;
meillo@10 170 GList *local_addresses;
meillo@10 171 GList *not_local_addresses;
meillo@10 172 GList *local_nets;
meillo@10 173 GList *listen_addresses;
meillo@0 174
meillo@10 175 guint remote_port;
meillo@0 176
meillo@117 177 /* ANSI C defines unsigned long to be at least 32bit
meillo@117 178 i.e. ca. 4GB max; that should be enough. */
meillo@117 179 gulong max_msg_size;
meillo@117 180
meillo@10 181 gboolean do_save_envelope_to;
meillo@0 182
meillo@10 183 gboolean defer_all;
meillo@10 184 gboolean do_relay;
meillo@0 185
meillo@10 186 GList *ident_trusted_nets;
meillo@0 187
meillo@10 188 gboolean do_queue;
meillo@0 189
meillo@10 190 gboolean do_verbose;
meillo@0 191
meillo@10 192 gchar *mbox_default;
meillo@10 193 GList *mbox_users;
meillo@10 194 GList *mda_users;
meillo@10 195 GList *maildir_users;
meillo@0 196
meillo@10 197 gchar *mda;
meillo@10 198 gboolean mda_fromline;
meillo@10 199 gboolean mda_fromhack;
meillo@0 200
meillo@10 201 gboolean pipe_fromline;
meillo@10 202 gboolean pipe_fromhack;
meillo@0 203
meillo@10 204 gchar *alias_file;
meillo@10 205 int (*alias_local_cmp) (const char *, const char *);
meillo@0 206
meillo@10 207 GList *local_net_routes;
meillo@10 208 GList *connect_routes; /* list of pairs which point to lists */
meillo@0 209
meillo@10 210 gchar *online_detect;
meillo@10 211 gchar *online_file;
meillo@10 212 gchar *online_pipe;
meillo@10 213 interface *mserver_iface;
meillo@0 214
meillo@10 215 GList *get_names;
meillo@10 216 GList *online_gets; /* list of pairs which point to lists */
meillo@0 217
meillo@10 218 gchar *errmsg_file;
meillo@10 219 gchar *warnmsg_file;
meillo@10 220 GList *warn_intervals;
meillo@10 221 gint max_defer_time;
meillo@0 222
meillo@10 223 gchar *log_user;
meillo@0 224 } masqmail_conf;
meillo@0 225
meillo@0 226 extern masqmail_conf conf;
meillo@0 227
meillo@10 228 typedef struct _table_pair {
meillo@10 229 gchar *key;
meillo@10 230 gpointer *value;
meillo@0 231 } table_pair;
meillo@0 232
meillo@0 233
meillo@10 234 typedef enum _prot_id {
meillo@10 235 PROT_LOCAL = 0,
meillo@10 236 PROT_BSMTP,
meillo@10 237 PROT_SMTP,
meillo@10 238 PROT_ESMTP,
meillo@10 239 PROT_POP3,
meillo@10 240 PROT_APOP,
meillo@10 241 PROT_NUM
meillo@10 242 } prot_id;
meillo@0 243
meillo@0 244 extern gchar *prot_names[];
meillo@0 245
meillo@10 246 typedef enum _header_id {
meillo@10 247 HEAD_FROM = 0,
meillo@10 248 HEAD_SENDER,
meillo@10 249 HEAD_TO,
meillo@10 250 HEAD_CC,
meillo@10 251 HEAD_BCC,
meillo@10 252 HEAD_DATE,
meillo@10 253 HEAD_MESSAGE_ID,
meillo@10 254 HEAD_REPLY_TO,
meillo@10 255 HEAD_SUBJECT,
meillo@10 256 HEAD_RETURN_PATH,
meillo@10 257 HEAD_ENVELOPE_TO,
meillo@10 258 HEAD_RECEIVED,
meillo@10 259 HEAD_NUM_IDS,
meillo@10 260 HEAD_STATUS,
meillo@10 261 HEAD_UNKNOWN = HEAD_NUM_IDS,
meillo@10 262 HEAD_NONE = -1,
meillo@10 263 } header_id;
meillo@0 264
meillo@10 265 typedef struct _header_name {
meillo@10 266 gchar *header;
meillo@10 267 header_id id;
meillo@10 268 } header_name;
meillo@0 269
meillo@10 270 typedef struct _header {
meillo@10 271 header_id id;
meillo@10 272 gchar *header;
meillo@10 273 gchar *value;
meillo@10 274 } header;
meillo@0 275
meillo@0 276
meillo@10 277 typedef struct _message {
meillo@10 278 gchar *uid;
meillo@0 279
meillo@10 280 gchar *received_host;
meillo@10 281 prot_id received_prot;
meillo@10 282 gchar *ident;
meillo@10 283 gint transfer_id; /* for multiple messages per transfer */
meillo@0 284
meillo@10 285 address *return_path;
meillo@10 286 GList *rcpt_list;
meillo@10 287 GList *non_rcpt_list;
meillo@0 288
meillo@10 289 GList *hdr_list;
meillo@10 290 GList *data_list;
meillo@0 291
meillo@10 292 gint data_size;
meillo@10 293 time_t received_time;
meillo@10 294 time_t warned_time;
meillo@0 295
meillo@10 296 gchar *full_sender_name;
meillo@10 297 } message;
meillo@0 298
meillo@10 299 typedef struct _msg_out {
meillo@10 300 message *msg;
meillo@0 301
meillo@10 302 address *return_path;
meillo@10 303 GList *rcpt_list;
meillo@0 304
meillo@10 305 GList *hdr_list;
meillo@10 306 GList *xtra_hdr_list;
meillo@10 307 } msg_out;
meillo@10 308
meillo@10 309 typedef struct _msgout_perhost {
meillo@10 310 gchar *host;
meillo@10 311 GList *msgout_list;
meillo@0 312 } msgout_perhost;
meillo@0 313
meillo@0 314 /* flags for accept() */
meillo@109 315 #define ACC_DEL_RCPTS 0x02 /* -t option, delete rcpts that were given as cmd args */
meillo@10 316 #define ACC_RCPT_FROM_HEAD 0x08 /* -t option, get rcpts from headers */
meillo@110 317 #define ACC_DOT_IGNORE 0x10 /* a dot on a line itself does not end the message (-oi option) */
meillo@10 318 #define ACC_MAIL_FROM_HEAD 0x40 /* get return path from header */
meillo@10 319 #define ACC_NODOT_RELAX 0x80 /* do not be picky if message ist not terminated by a dot on a line */
meillo@10 320 #define ACC_SAVE_ENVELOPE_TO 0x0100 /* save an existent Envelope-to header as X-Orig-Envelope-to */
meillo@0 321
meillo@0 322 #define DLVR_LOCAL 0x01
meillo@0 323 #define DLVR_LAN 0x02
meillo@0 324 #define DLVR_ONLINE 0x04
meillo@0 325 #define DLVR_ALL (DLVR_LOCAL|DLVR_LAN|DLVR_ONLINE)
meillo@0 326
meillo@0 327 /* transport flags */
meillo@0 328 #define MSGSTR_FROMLINE 0x01
meillo@0 329 #define MSGSTR_FROMHACK 0x02
meillo@0 330
meillo@10 331 typedef enum _accept_error {
meillo@10 332 AERR_OK = 0,
meillo@10 333 AERR_TIMEOUT,
meillo@10 334 AERR_EOF,
meillo@10 335 AERR_OVERFLOW,
meillo@10 336 AERR_SYNTAX,
meillo@10 337 AERR_NOSPOOL,
meillo@10 338 AERR_NORCPT,
meillo@117 339 AERR_SIZE, /* max msg size exeeded (SMTP SIZE) */
meillo@10 340 AERR_UNKNOWN
meillo@10 341 } accept_error;
meillo@0 342
meillo@0 343 #define BUF_LEN 1024
meillo@0 344 #define MAX_ADDRESS 256
meillo@0 345 #define MAX_DATALINE 4096
meillo@0 346
meillo@10 347 typedef enum _smtp_cmd_id {
meillo@10 348 SMTP_HELO = 0,
meillo@10 349 SMTP_EHLO,
meillo@10 350 SMTP_MAIL_FROM,
meillo@10 351 SMTP_RCPT_TO,
meillo@10 352 SMTP_DATA,
meillo@10 353 SMTP_QUIT,
meillo@10 354 SMTP_RSET,
meillo@10 355 SMTP_NOOP,
meillo@10 356 SMTP_HELP,
meillo@10 357 SMTP_NUM_IDS,
meillo@10 358 SMTP_EOF = -1,
meillo@10 359 SMTP_ERROR = -2,
meillo@0 360 } smtp_cmd_id;
meillo@0 361
meillo@10 362 typedef struct _smtp_cmd {
meillo@10 363 smtp_cmd_id id;
meillo@10 364 gchar *cmd;
meillo@0 365 } smtp_cmd;
meillo@0 366
meillo@10 367 typedef struct _smtp_connection {
meillo@10 368 gchar *remote_host;
meillo@0 369
meillo@10 370 prot_id prot;
meillo@10 371 gint next_id;
meillo@0 372
meillo@10 373 gboolean helo_seen;
meillo@10 374 gboolean from_seen;
meillo@10 375 gboolean rcpt_seen;
meillo@10 376
meillo@10 377 message *msg;
meillo@10 378 } smtp_connection;
meillo@0 379
meillo@0 380 /* alias.c*/
meillo@10 381 gboolean addr_is_local(address * addr);
meillo@10 382 GList *alias_expand(GList * alias_table, GList * rcpt_list, GList * non_rcpt_list);
meillo@0 383
meillo@0 384 /* child.c */
meillo@0 385 int child(const char *command);
meillo@0 386
meillo@0 387 /* conf.c */
meillo@0 388 void init_conf();
meillo@10 389 gboolean read_conf(gchar * filename);
meillo@10 390 connect_route *read_route(gchar * filename, gboolean is_local_net);
meillo@10 391 GList *read_route_list(GList * rf_list, gboolean is_local_net);
meillo@10 392 void destroy_route(connect_route * r);
meillo@10 393 void destroy_route_list(GList * list);
meillo@10 394 get_conf *read_get_conf(gchar * filename);
meillo@10 395 void destroy_get_conf(get_conf * gc);
meillo@0 396 connect_route *create_local_route();
meillo@0 397
meillo@0 398 /* expand.c */
meillo@10 399 GList *var_table_rcpt(GList * var_table, address * rcpt);
meillo@10 400 GList *var_table_msg(GList * var_table, message * msg);
meillo@10 401 GList *var_table_conf(GList * var_table);
meillo@10 402 gint expand(GList * var_list, gchar * format, gchar * result, gint result_len);
meillo@0 403
meillo@0 404 /* message.c */
meillo@0 405 message *create_message(void);
meillo@10 406 void destroy_message(message * msg);
meillo@10 407 void destroy_msg_list(GList * msg_list);
meillo@10 408 void msg_free_data(message * msg);
meillo@10 409 gint msg_calc_size(message * msg, gboolean is_smtp);
meillo@0 410
meillo@10 411 msg_out *create_msg_out(message * msg);
meillo@10 412 msg_out *clone_msg_out(msg_out * msgout_orig);
meillo@10 413 GList *create_msg_out_list(GList * msg_list);
meillo@10 414 void destroy_msg_out(msg_out * msgout);
meillo@10 415 void destroy_msg_out_list(GList * msgout_list);
meillo@0 416
meillo@0 417 /* address.c */
meillo@10 418 address *create_address(gchar * path, gboolean is_rfc821);
meillo@10 419 address *create_address_qualified(gchar * path, gboolean is_rfc821, gchar * domain);
meillo@10 420 address *create_address_pipe(gchar * path);
meillo@10 421 void destroy_address(address * addr);
meillo@10 422 address *copy_modify_address(const address * orig, gchar * l_part, gchar * dom);
meillo@0 423 #define copy_address(addr) copy_modify_address(addr, NULL, NULL)
meillo@10 424 gboolean addr_isequal(address * addr1, address * addr2);
meillo@10 425 gboolean addr_isequal_parent(address * addr1, address * addr2);
meillo@10 426 address *addr_find_ancestor(address * addr);
meillo@10 427 gboolean addr_is_delivered_children(address * addr);
meillo@10 428 gboolean addr_is_finished_children(address * addr);
meillo@10 429 gchar *addr_string(address * addr);
meillo@10 430 gint addr_match(address * addr1, address * addr2);
meillo@0 431
meillo@0 432 /* accept.c */
meillo@10 433 accept_error accept_message(FILE * in, message * msg, guint flags);
meillo@10 434 accept_error accept_message_prepare(message * msg, guint flags);
meillo@0 435
meillo@0 436 /* header.c */
meillo@0 437 gchar *rec_timestamp();
meillo@10 438 GList *find_header(GList * hdr_list, header_id id, gchar * hdr_str);
meillo@10 439 void header_unfold(header * hdr);
meillo@10 440 void header_fold(header * hdr);
meillo@10 441 header *create_header(header_id id, gchar * fmt, ...);
meillo@10 442 void destroy_header(header * hdr);
meillo@10 443 header *copy_header(header * hdr);
meillo@10 444 header *get_header(gchar * line);
meillo@0 445
meillo@0 446 /* smtp_in.c */
meillo@10 447 void smtp_in(FILE * in, FILE * out, gchar * remote_host, gchar * ident);
meillo@0 448
meillo@0 449 /* listen.c */
meillo@10 450 void listen_port(GList * addr_list, gint qival, char *argv[]);
meillo@0 451
meillo@0 452 /* parse.c */
meillo@10 453 gboolean split_address(const gchar * path, gchar ** local_part, gchar ** domain, gboolean is_rfc821);
meillo@10 454 gboolean parse_address_rfc822(gchar * string, gchar ** local_begin, gchar ** local_end, gchar ** domain_begin, gchar ** domain_end, gchar ** address_end);
meillo@10 455 gboolean parse_address_rfc821(gchar * string, gchar ** local_begin, gchar ** local_end, gchar ** domain_begin, gchar ** domain_end, gchar ** address_end);
meillo@10 456 address *_create_address(gchar * string, gchar ** end, gboolean is_rfc821);
meillo@10 457 address *create_address_rfc821(gchar * string, gchar ** end);
meillo@10 458 address *create_address_rfc822(gchar * string, gchar ** end);
meillo@10 459 GList *addr_list_append_rfc822(GList * addr_list, gchar * string, gchar * domain);
meillo@10 460 gboolean addr_isequal(address * addr1, address * addr2);
meillo@0 461
meillo@0 462 /* connect.c */
meillo@10 463 mxip_addr *connect_hostlist(int *psockfd, gchar * host, guint port, GList * addr_list);
meillo@10 464 mxip_addr *connect_resolvelist(int *psockfd, gchar * host, guint port, GList * res_funcs);
meillo@0 465
meillo@0 466 /* deliver.c */
meillo@10 467 void msg_rcptlist_local(GList * rcpt_list, GList **, GList **);
meillo@10 468 gboolean deliver_local(msg_out * msgout);
meillo@10 469 gboolean deliver_msglist_host(connect_route * route, GList * msg_list, gchar * host, GList * res_list);
meillo@10 470 gboolean deliver_route_msgout_list(connect_route * route, GList * msgout_list);
meillo@10 471 gboolean deliver_route_msg_list(connect_route * route, GList * msgout_list);
meillo@10 472 gboolean deliver_finish(msg_out * msgout);
meillo@10 473 gboolean deliver_finish_list(GList * msgout_list);
meillo@10 474 gboolean deliver_msg_list(GList * msg_list, guint flags);
meillo@10 475 gboolean deliver(message * msg);
meillo@0 476
meillo@0 477 /* fail_msg.c */
meillo@10 478 gboolean fail_msg(message * msg, gchar * template, GList * failed_rcpts, gchar * err_fmt, va_list args);
meillo@10 479 gboolean warn_msg(message * msg, gchar * template, GList * failed_rcpts, gchar * err_fmt, va_list args);
meillo@0 480
meillo@0 481 /* get.c */
meillo@10 482 gboolean get_from_file(gchar * fname);
meillo@10 483 gboolean get_from_name(gchar * name);
meillo@0 484 gboolean get_all(void);
meillo@0 485 void get_online(void);
meillo@0 486 void get_daemon(gint gival, char *argv[]);
meillo@10 487 gboolean pop_before_smtp(gchar * fname);
meillo@0 488
meillo@0 489 /* interface.c */
meillo@10 490 gboolean init_sockaddr(struct sockaddr_in *name, interface * iface);
meillo@10 491 int make_server_socket(interface * iface);
meillo@0 492
meillo@0 493 /* local.c */
meillo@10 494 gboolean append_file(message * msg, GList * hdr_list, gchar * user);
meillo@10 495 gboolean maildir_out(message * msg, GList * hdr_list, gchar * user, guint flags);
meillo@10 496 gboolean pipe_out(message * msg, GList * hdr_list, address * rcpt, gchar * cmd, guint flags);
meillo@0 497
meillo@0 498 /* log.c */
meillo@0 499 gchar *ext_strerror(int err);
meillo@0 500 gboolean logopen(void);
meillo@0 501 void logclose(void);
meillo@0 502 void vlogwrite(int pri, const char *fmt, va_list args);
meillo@0 503 void logwrite(int pri, const char *fmt, ...);
meillo@0 504 void debugf(const char *fmt, ...);
meillo@0 505 void vdebugf(const char *fmt, va_list args);
meillo@0 506 void maillog(const char *fmt, ...);
meillo@0 507
meillo@0 508 /* spool.c */
meillo@10 509 gboolean spool_read_data(message * msg);
meillo@10 510 gboolean spool_read_data(message * msg);
meillo@10 511 message *msg_spool_read(gchar * uid, gboolean do_readdata);
meillo@10 512 gboolean spool_write(message * msg, gboolean do_writedata);
meillo@10 513 gboolean spool_lock(gchar * uid);
meillo@10 514 gboolean spool_unlock(gchar * uid);
meillo@10 515 gboolean spool_delete_all(message * msg);
meillo@0 516
meillo@0 517 /* queue.c */
meillo@0 518 GList *read_queue(gboolean do_readdata);
meillo@0 519 gboolean queue_run(void);
meillo@0 520 gboolean queue_run_online(void);
meillo@0 521 void queue_list(void);
meillo@10 522 gboolean queue_delete(gchar * uid);
meillo@0 523
meillo@0 524 /* online.c */
meillo@0 525 gchar *detect_online();
meillo@10 526 void set_online_name(gchar * name);
meillo@0 527
meillo@0 528 /* permissions.c */
meillo@0 529 gboolean is_ingroup(uid_t uid, gid_t gid);
meillo@10 530 void set_euidgid(gint uid, gint gid, uid_t * old_uid, gid_t * old_gid);
meillo@10 531 void set_identity(uid_t old_uid, gchar * task_name);
meillo@0 532
meillo@0 533 /* rewrite.c */
meillo@10 534 gboolean set_address_header_domain(header * hdr, gchar * domain);
meillo@10 535 gboolean map_address_header(header * hdr, GList * table);
meillo@0 536
meillo@0 537 /* route.c */
meillo@10 538 msgout_perhost *create_msgout_perhost(gchar * host);
meillo@10 539 void destroy_msgout_perhost(msgout_perhost * mo_ph);
meillo@10 540 void rewrite_headers(msg_out * msgout, connect_route * route);
meillo@10 541 void rcptlist_with_one_of_hostlist(GList * rcpt_list, GList * host_list, GList **, GList **);
meillo@10 542 void rcptlist_with_addr_is_local(GList * rcpt_list, GList ** p_rcpt_list, GList ** p_non_rcpt_list);
meillo@10 543 gboolean route_strip_msgout(connect_route * route, msg_out * msgout);
meillo@10 544 msg_out *route_prepare_msgout(connect_route * route, msg_out * msgout);
meillo@10 545 GList *route_msgout_list(connect_route * route, GList * msgout_list);
meillo@10 546 gboolean route_is_allowed_return_path(connect_route * route, address * ret_path);
meillo@10 547 gboolean route_is_allowed_mail_local(connect_route * route, address * ret_path);
meillo@10 548 void msg_rcptlist_route(connect_route * route, GList * rcpt_list, GList ** p_rcpt_list, GList ** p_non_rcpt_list);
meillo@0 549
meillo@0 550 /* tables.c */
meillo@10 551 table_pair *create_pair(gchar * key, gpointer value);
meillo@10 552 table_pair *create_pair_string(gchar * key, gpointer value);
meillo@10 553 table_pair *parse_table_pair(gchar * line, char delim);
meillo@10 554 gpointer *table_find_func(GList * table_list, gchar * key, int (*cmp_func) (const char *, const char *));
meillo@10 555 gpointer *table_find(GList * table_list, gchar * key);
meillo@10 556 gpointer *table_find_case(GList * table_list, gchar * key);
meillo@10 557 gpointer *table_find_fnmatch(GList * table_list, gchar * key);
meillo@10 558 GList *table_read(gchar * fname, gchar delim);
meillo@10 559 void destroy_table(GList * table);
meillo@0 560
meillo@0 561 /* timeival.c */
meillo@10 562 gint time_interval(gchar * str, gint * pos);
meillo@0 563
meillo@0 564 /* permissions.c */
meillo@0 565 gboolean is_privileged_user(uid_t uid);
meillo@0 566
meillo@0 567 /* other things */
meillo@0 568
meillo@0 569 #define foreach(list, node)\
meillo@0 570 for((node) = g_list_first(list);\
meillo@0 571 (node);\
meillo@0 572 (node) = g_list_next(node))
meillo@0 573
meillo@0 574 #ifdef ENABLE_DEBUG
meillo@0 575 #define DEBUG(level) if(level <= conf.debug_level)
meillo@0 576 #else
meillo@0 577 /* hopefully the compiler optmizes this away... */
meillo@0 578 #define DEBUG(level) if(0)
meillo@0 579 #endif
meillo@0 580
meillo@0 581 #define LOG_VERBOSE 0x100
meillo@0 582
meillo@0 583 #ifndef HAVE_GETLINE
meillo@0 584 #define getline(buf, size, file) getdelim(buf, size, '\n', file)
meillo@0 585 #endif
meillo@0 586
meillo@0 587 #ifndef HAVE_FDATASYNC
meillo@0 588 #define fdatasync(fd) fsync(fd)
meillo@0 589 #endif
meillo@0 590
meillo@0 591 #ifndef CONF_DIR
meillo@0 592 #define CONF_DIR "/etc/masqmail"
meillo@0 593 #endif
meillo@0 594
meillo@0 595 #define CONF_FILE CONF_DIR"/masqmail.conf"
meillo@0 596
meillo@0 597 #define PIDFILEDIR "/var/run/masqmail/"
meillo@0 598
meillo@0 599 #ifndef va_copy
meillo@0 600 #ifdef __va_copy
meillo@0 601 #define va_copy(ap1, ap2) __va_copy(ap1, ap2)
meillo@0 602 #else
meillo@0 603 #define va_copy(ap1, ap2) G_VA_COPY(ap1, ap2)
meillo@0 604 #endif
meillo@0 605 #endif
meillo@0 606
meillo@0 607 /* *BSD needs this: */
meillo@0 608 extern char **environ;