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