1*67b9b338Schristos /* $NetBSD: smtp_state.c,v 1.3 2022/10/08 16:12:49 christos Exp $ */ 241fbaed0Stron 341fbaed0Stron /*++ 441fbaed0Stron /* NAME 541fbaed0Stron /* smtp_state 3 641fbaed0Stron /* SUMMARY 741fbaed0Stron /* initialize/cleanup shared state 841fbaed0Stron /* SYNOPSIS 941fbaed0Stron /* #include "smtp.h" 1041fbaed0Stron /* 1141fbaed0Stron /* SMTP_STATE *smtp_state_alloc() 1241fbaed0Stron /* 1341fbaed0Stron /* void smtp_state_free(state) 1441fbaed0Stron /* SMTP_STATE *state; 1541fbaed0Stron /* DESCRIPTION 1641fbaed0Stron /* smtp_state_init() initializes the shared state, and allocates 1741fbaed0Stron /* memory for buffers etc. 1841fbaed0Stron /* 1941fbaed0Stron /* smtp_cleanup() destroys memory allocated by smtp_state_init(). 2041fbaed0Stron /* STANDARDS 2141fbaed0Stron /* DIAGNOSTICS 2241fbaed0Stron /* BUGS 2341fbaed0Stron /* SEE ALSO 2441fbaed0Stron /* LICENSE 2541fbaed0Stron /* .ad 2641fbaed0Stron /* .fi 2741fbaed0Stron /* The Secure Mailer license must be distributed with this software. 2841fbaed0Stron /* AUTHOR(S) 2941fbaed0Stron /* Wietse Venema 3041fbaed0Stron /* IBM T.J. Watson Research 3141fbaed0Stron /* P.O. Box 704 3241fbaed0Stron /* Yorktown Heights, NY 10598, USA 33*67b9b338Schristos /* 34*67b9b338Schristos /* Wietse Venema 35*67b9b338Schristos /* Google, Inc. 36*67b9b338Schristos /* 111 8th Avenue 37*67b9b338Schristos /* New York, NY 10011, USA 3841fbaed0Stron /*--*/ 3941fbaed0Stron 4041fbaed0Stron /* System library. */ 4141fbaed0Stron 4241fbaed0Stron #include <sys_defs.h> 4341fbaed0Stron 4441fbaed0Stron /* Utility library. */ 4541fbaed0Stron 4641fbaed0Stron #include <mymalloc.h> 4741fbaed0Stron #include <vstring.h> 4841fbaed0Stron #include <msg.h> 4941fbaed0Stron 5041fbaed0Stron /* Global library. */ 5141fbaed0Stron 5241fbaed0Stron #include <mail_params.h> 53*67b9b338Schristos #include <debug_peer.h> 5441fbaed0Stron 5541fbaed0Stron /* Application-specific. */ 5641fbaed0Stron 5741fbaed0Stron #include "smtp.h" 5841fbaed0Stron #include "smtp_sasl.h" 5941fbaed0Stron 6041fbaed0Stron /* smtp_state_alloc - initialize */ 6141fbaed0Stron smtp_state_alloc(void)6241fbaed0StronSMTP_STATE *smtp_state_alloc(void) 6341fbaed0Stron { 6441fbaed0Stron SMTP_STATE *state = (SMTP_STATE *) mymalloc(sizeof(*state)); 6541fbaed0Stron 6641fbaed0Stron state->misc_flags = 0; 6741fbaed0Stron state->src = 0; 6841fbaed0Stron state->service = 0; 6941fbaed0Stron state->request = 0; 7041fbaed0Stron state->session = 0; 7141fbaed0Stron state->status = 0; 7241fbaed0Stron state->space_left = 0; 7316d67a18Stron state->iterator->request_nexthop = vstring_alloc(100); 7416d67a18Stron state->iterator->dest = vstring_alloc(100); 7516d67a18Stron state->iterator->host = vstring_alloc(100); 7616d67a18Stron state->iterator->addr = vstring_alloc(100); 7716d67a18Stron state->iterator->saved_dest = vstring_alloc(100); 7841fbaed0Stron if (var_smtp_cache_conn) { 7941fbaed0Stron state->dest_label = vstring_alloc(10); 8041fbaed0Stron state->dest_prop = vstring_alloc(10); 8141fbaed0Stron state->endp_label = vstring_alloc(10); 8241fbaed0Stron state->endp_prop = vstring_alloc(10); 8341fbaed0Stron state->cache_used = htable_create(1); 8441fbaed0Stron } else { 8541fbaed0Stron state->dest_label = 0; 8641fbaed0Stron state->dest_prop = 0; 8741fbaed0Stron state->endp_label = 0; 8841fbaed0Stron state->endp_prop = 0; 8941fbaed0Stron state->cache_used = 0; 9041fbaed0Stron } 9141fbaed0Stron state->why = dsb_create(); 92*67b9b338Schristos state->debug_peer_per_nexthop = 0; 93*67b9b338Schristos state->logged_line_length_limit = 0; 9441fbaed0Stron return (state); 9541fbaed0Stron } 9641fbaed0Stron 9741fbaed0Stron /* smtp_state_free - destroy state */ 9841fbaed0Stron smtp_state_free(SMTP_STATE * state)9941fbaed0Stronvoid smtp_state_free(SMTP_STATE *state) 10041fbaed0Stron { 10116d67a18Stron #ifdef USE_TLS 10216d67a18Stron /* The TLS policy cache lifetime is one delivery. */ 10316d67a18Stron smtp_tls_policy_cache_flush(); 10416d67a18Stron #endif 10516d67a18Stron vstring_free(state->iterator->request_nexthop); 10616d67a18Stron vstring_free(state->iterator->dest); 10716d67a18Stron vstring_free(state->iterator->host); 10816d67a18Stron vstring_free(state->iterator->addr); 10916d67a18Stron vstring_free(state->iterator->saved_dest); 11041fbaed0Stron if (state->dest_label) 11141fbaed0Stron vstring_free(state->dest_label); 11241fbaed0Stron if (state->dest_prop) 11341fbaed0Stron vstring_free(state->dest_prop); 11441fbaed0Stron if (state->endp_label) 11541fbaed0Stron vstring_free(state->endp_label); 11641fbaed0Stron if (state->endp_prop) 11741fbaed0Stron vstring_free(state->endp_prop); 11841fbaed0Stron if (state->cache_used) 119e262b48eSchristos htable_free(state->cache_used, (void (*) (void *)) 0); 12041fbaed0Stron if (state->why) 12141fbaed0Stron dsb_free(state->why); 122*67b9b338Schristos if (state->debug_peer_per_nexthop) 123*67b9b338Schristos debug_peer_restore(); 12441fbaed0Stron 125e262b48eSchristos myfree((void *) state); 12641fbaed0Stron } 127