1/*++
2/* NAME
3/*	smtpd_xforward 3
4/* SUMMARY
5/*	maintain XCLIENT information
6/* SYNOPSIS
7/*	#include "smtpd.h"
8/*
9/*	void	smtpd_xforward_init(state)
10/*	SMTPD_STATE *state;
11/*
12/*	void	smtpd_xforward_preset(state)
13/*	SMTPD_STATE *state;
14/*
15/*	void	smtpd_xforward_reset(state)
16/*	SMTPD_STATE *state;
17/* DESCRIPTION
18/*	smtpd_xforward_init() zeroes the attributes for storage of
19/*	XFORWARD command parameters.
20/*
21/*	smtpd_xforward_preset() takes the result from smtpd_xforward_init()
22/*	and sets all fields to the same "unknown" value that regular
23/*	client attributes would have.
24/*
25/*	smtpd_xforward_reset() restores the state from smtpd_xforward_init().
26/* LICENSE
27/* .ad
28/* .fi
29/*	The Secure Mailer license must be distributed with this software.
30/* AUTHOR(S)
31/*	Wietse Venema
32/*	IBM T.J. Watson Research
33/*	P.O. Box 704
34/*	Yorktown Heights, NY 10598, USA
35/*--*/
36
37/* System library. */
38
39#include <sys_defs.h>
40
41/* Utility library. */
42
43#include <mymalloc.h>
44#include <msg.h>
45
46/* Global library. */
47
48#include <mail_proto.h>
49
50/* Application-specific. */
51
52#include <smtpd.h>
53
54/* smtpd_xforward_init - initialize xforward attributes */
55
56void    smtpd_xforward_init(SMTPD_STATE *state)
57{
58    state->xforward.flags = 0;
59    state->xforward.name = 0;
60    state->xforward.addr = 0;
61    state->xforward.port = 0;
62    state->xforward.namaddr = 0;
63    state->xforward.protocol = 0;
64    state->xforward.helo_name = 0;
65    state->xforward.ident = 0;
66    state->xforward.domain = 0;
67}
68
69/* smtpd_xforward_preset - set xforward attributes to "unknown" */
70
71void    smtpd_xforward_preset(SMTPD_STATE *state)
72{
73
74    /*
75     * Sanity checks.
76     */
77    if (state->xforward.flags)
78	msg_panic("smtpd_xforward_preset: bad flags: 0x%x",
79		  state->xforward.flags);
80
81    /*
82     * This is a temporary solution. Unknown forwarded attributes get the
83     * same values as unknown normal attributes, so that we don't break
84     * assumptions in pre-existing code.
85     */
86    state->xforward.flags = SMTPD_STATE_XFORWARD_INIT;
87    state->xforward.name = mystrdup(CLIENT_NAME_UNKNOWN);
88    state->xforward.addr = mystrdup(CLIENT_ADDR_UNKNOWN);
89    state->xforward.port = mystrdup(CLIENT_PORT_UNKNOWN);
90    state->xforward.namaddr = mystrdup(CLIENT_NAMADDR_UNKNOWN);
91    state->xforward.rfc_addr = mystrdup(CLIENT_ADDR_UNKNOWN);
92    /* Leave helo at zero. */
93    state->xforward.protocol = mystrdup(CLIENT_PROTO_UNKNOWN);
94    /* Leave ident at zero. */
95    /* Leave domain context at zero. */
96}
97
98/* smtpd_xforward_reset - reset xforward attributes */
99
100void    smtpd_xforward_reset(SMTPD_STATE *state)
101{
102#define FREE_AND_WIPE(s) { if (s) myfree(s); s = 0; }
103
104    state->xforward.flags = 0;
105    FREE_AND_WIPE(state->xforward.name);
106    FREE_AND_WIPE(state->xforward.addr);
107    FREE_AND_WIPE(state->xforward.port);
108    FREE_AND_WIPE(state->xforward.namaddr);
109    FREE_AND_WIPE(state->xforward.rfc_addr);
110    FREE_AND_WIPE(state->xforward.protocol);
111    FREE_AND_WIPE(state->xforward.helo_name);
112    FREE_AND_WIPE(state->xforward.ident);
113    FREE_AND_WIPE(state->xforward.domain);
114}
115