1 #include "OpenDMARC.hpp"
6 u_char
* uc(char const* cp
)
8 return reinterpret_cast<u_char
*>(const_cast<char*>((cp
)));
15 #define PUBLIC_SUFFIX_LIST_DAT "public_suffix_list.dat"
17 auto const our_list
{osutil::get_config_dir() / PUBLIC_SUFFIX_LIST_DAT
};
18 if (fs::exists(our_list
))
22 fs::path
{"/usr/share/publicsuffix/" PUBLIC_SUFFIX_LIST_DAT
}};
23 if (fs::exists(sys_list
))
26 LOG(FATAL
) << "can't find " PUBLIC_SUFFIX_LIST_DAT
;
29 lib_
= {.tld_type
= OPENDMARC_TLD_TYPE_MOZILLA
};
31 CHECK_LT(path
.string().length(), sizeof(lib_
.tld_source_file
));
32 strcpy(reinterpret_cast<char*>(lib_
.tld_source_file
), path
.string().c_str());
34 auto const status
= opendmarc_policy_library_init(&lib_
);
35 CHECK_EQ(status
, DMARC_PARSE_OKAY
) << opendmarc_policy_status_to_str(status
);
38 lib::~lib() { opendmarc_policy_library_shutdown(&lib_
); }
43 opendmarc_policy_connect_shutdown(pctx_
);
48 void policy::connect(char const* ip
)
51 auto const is_ipv6
= IP6::is_address(ip
);
52 pctx_
= CHECK_NOTNULL(opendmarc_policy_connect_init(uc(ip
), is_ipv6
));
55 bool policy::store_from_domain(char const* from_domain
)
57 CHECK_NOTNULL(from_domain
);
59 opendmarc_policy_store_from_domain(pctx_
, uc(from_domain
));
60 if (status
!= DMARC_PARSE_OKAY
) {
61 LOG(WARNING
) << "from_domain == " << from_domain
;
62 LOG(WARNING
) << opendmarc_policy_status_to_str(status
);
68 bool policy::store_dkim(char const* d_equal_domain
,
69 char const* d_selector
,
71 char const* human_result
)
73 CHECK_NOTNULL(d_equal_domain
);
74 CHECK_NOTNULL(human_result
);
75 LOG(INFO
) << "d_equal_domain == " << d_equal_domain
;
76 auto const status
= opendmarc_policy_store_dkim(
77 pctx_
, uc(d_selector
), uc(d_equal_domain
), dkim_result
, uc(human_result
));
78 if (status
!= DMARC_PARSE_OKAY
) {
79 LOG(WARNING
) << "d_equal_domain == " << d_equal_domain
;
80 LOG(WARNING
) << opendmarc_policy_status_to_str(status
);
86 bool policy::store_spf(char const* domain
,
89 char const* human_readable
)
91 CHECK_NOTNULL(domain
);
92 CHECK_NOTNULL(human_readable
);
93 auto const status
= opendmarc_policy_store_spf(pctx_
, uc(domain
), result
,
94 origin
, uc(human_readable
));
95 if (status
!= DMARC_PARSE_OKAY
) {
96 LOG(WARNING
) << "domain == " << domain
;
97 LOG(WARNING
) << opendmarc_policy_status_to_str(status
);
103 bool policy::query_dmarc(char const* domain
)
105 CHECK_NOTNULL(domain
);
106 auto const status
= opendmarc_policy_query_dmarc(pctx_
, uc(domain
));
107 if (status
!= DMARC_PARSE_OKAY
) {
108 LOG(WARNING
) << domain
<< ": " << opendmarc_policy_status_to_str(status
);
114 advice
policy::get_advice()
116 auto const status
= opendmarc_get_policy_to_enforce(pctx_
);
119 case DMARC_PARSE_ERROR_NULL_CTX
:
120 LOG(WARNING
) << "NULL pctx value";
123 case DMARC_FROM_DOMAIN_ABSENT
:
124 LOG(WARNING
) << "no From: domain";
127 case DMARC_POLICY_ABSENT
: return advice::NONE
;
128 case DMARC_POLICY_PASS
: return advice::ACCEPT
;
129 case DMARC_POLICY_REJECT
: return advice::REJECT
;
130 case DMARC_POLICY_QUARANTINE
: return advice::QUARANTINE
;
131 case DMARC_POLICY_NONE
: return advice::NONE
;
134 LOG(FATAL
) << "unknown status";
137 } // namespace OpenDMARC