1 /*        $NetBSD: tlsrpt_wrapper.h,v 1.2 2025/02/25 19:15:50 christos Exp $    */
2 
3 #ifndef _TLSRPT_WRAPPER_INCLUDED_
4 #define _TLSRPT_WRAPPER_INCLUDED_
5 
6 /*++
7 /* NAME
8 /*        tlsrpt_wrapper 3h
9 /* SUMMARY
10 /*        TLSRPT support for the SMTP and TLS protocol engines
11 /* SYNOPSIS
12 /*        #include <tlsrpt_wrapper.h>
13 /* DESCRIPTION
14 /* .nf
15 
16  /*
17   * System library.
18   */
19 #if defined(USE_TLS)
20 
21 #if defined(USE_TLSRPT)
22 
23 #include <tlsrpt.h>
24 
25  /*
26   * External interface, with convenient setters for each SMTP protocol engine
27   * stage. Many functions have multiple arguments of the same type. Include
28   * parameter names in function prototypes here, and in call sites include
29   * comments before parameter values, to prepare for future clang-tidy
30   * bugprone-argument-comment checks.
31   */
32 typedef struct TLSRPT_WRAPPER TLSRPT_WRAPPER;
33 
34 extern TLSRPT_WRAPPER *trw_create(const char *rpt_socket_name,
35                                                   const char *rpt_policy_domain,
36                                                   const char *rpt_policy_string,
37                                                   int skip_reused_hs);
38 extern void trw_free(TLSRPT_WRAPPER *trw);
39 extern void trw_set_tls_policy(TLSRPT_WRAPPER *trw,
40                                              tlsrpt_policy_type_t tls_policy_type,
41                                            const char *const * tls_policy_strings,
42                                              const char *tls_policy_domain,
43                                           const char *const * mx_policy_patterns);
44 extern void trw_set_tcp_connection(TLSRPT_WRAPPER *trw,
45                                                    const char *snd_mta_addr,
46                                                    const char *rcv_mta_name,
47                                                    const char *rcv_mta_addr);
48 extern void trw_set_ehlo_resp(TLSRPT_WRAPPER *trw,
49                                             const char *rcv_mta_ehlo);
50 extern int trw_report_failure(TLSRPT_WRAPPER *trw,
51                                             tlsrpt_failure_t policy_failure,
52                                             const char *additional_info,
53                                             const char *failure_reason);
54 extern int trw_report_success(TLSRPT_WRAPPER *trw);
55 extern int trw_is_reported(const TLSRPT_WRAPPER *trw);
56 extern int trw_is_skip_reused_hs(const TLSRPT_WRAPPER *trw);
57 
58  /*
59   * The internals declarations are also needed for functions that transmit
60   * and receive TLSRPT_WRAPPER objects.
61   */
62 #ifdef TLSRPT_WRAPPER_INTERNAL
63 
64  /*
65   * Utility library.
66   */
67 #include <argv.h>
68 
69 struct TLSRPT_WRAPPER {
70     /* Set with trw_create(). */
71     char   *rpt_socket_name;
72     char   *rpt_policy_domain;
73     char   *rpt_policy_string;
74     int     skip_reused_hs;
75     /* Set with trw_set_policy(). */
76     tlsrpt_policy_type_t tls_policy_type;
77     ARGV   *tls_policy_strings;
78     char   *tls_policy_domain;
79     ARGV   *mx_host_patterns;
80     /* Set with trw_set_tcp_connection(). */
81     char   *snd_mta_addr;
82     char   *rcv_mta_name;
83     char   *rcv_mta_addr;
84     /* Set with trw_set_ehlo_resp(). */
85     char   *rcv_mta_ehlo;
86     int     flags;
87 };
88 
89 #define TRW_FLAG_HAVE_TLS_POLICY (1<<0)
90 #define TRW_FLAG_HAVE_TCP_CONN          (1<<1)
91 #define TRW_FLAG_HAVE_EHLO_RESP         (1<<2)
92 #define TRW_FLAG_REPORTED     (1<<3)
93 
94 #define TRW_RPT_SOCKET_NAME   "rpt_socket_name"
95 #define TRW_RPT_POLICY_DOMAIN "rpt_policy_domain"
96 #define TRW_RPT_POLICY_STRING "rpt_policy_string"
97 #define TRW_SKIP_REUSED_HS    "skip_reused_hs"
98 #define TRW_TLS_POLICY_TYPE   "tls_policy_type"
99 #define TRW_TLS_POLICY_STRINGS          "tls_policy_strings"          /* XXX Not checked */
100 #define TRW_TLS_POLICY_DOMAIN "tls_policy_domain"
101 #define TRW_MX_HOST_PATTERNS  "mx_host_patterns"  /* XXX Not checked */
102 #define TRW_SRC_MTA_ADDR      "snd_mta_addr"
103 #define TRW_DST_MTA_NAME      "rcv_mta_name"
104 #define TRW_DST_MTA_ADDR      "rcv_mta_addr"
105 #define TRW_DST_MTA_EHLO      "rcv_mta_ehlo"      /* Optional */
106 #define TRW_FLAGS             "flags"
107 
108 #endif                                            /* TLSRPT_WRAPPER_INTERNAL */
109 
110 extern tlsrpt_policy_type_t convert_tlsrpt_policy_type(const char *policy_type);
111 extern tlsrpt_failure_t convert_tlsrpt_policy_failure(const char *policy_failure);
112 
113 #endif                                            /* USE_TLSRPT */
114 
115 extern int valid_tlsrpt_policy_type(const char *policy_type);
116 extern int valid_tlsrpt_policy_failure(const char *policy_failure);
117 
118 #endif                                            /* USE_TLS */
119 
120 /* LICENSE
121 /* .ad
122 /* .fi
123 /*        The Secure Mailer license must be distributed with this software.
124 /* AUTHOR(S)
125 /*        Wietse Venema
126 /*--*/
127 
128 #endif                                            /* _TLSRPT_WRAPPER_INCLUDED_ */
129