s/qmail 4.2.29a
Next generation secure email transport
Loading...
Searching...
No Matches
dnstlsa.c
Go to the documentation of this file.
1#include <unistd.h>
2#include "buffer.h"
3#include "stralloc.h"
4#include "dnsresolv.h"
5#include "dns.h"
6#include "exit.h"
7#include "logmsg.h"
8#include "getoptb.h"
9#include "str.h"
10#include "byte.h"
11
12#define WHO "dnstlsa"
13
14static stralloc cn = {0};
15static stralloc sa = {0};
16static stralloc out = {0};
17
18int main(int argc,char **argv)
19{
20 int r;
21 uint16 usage;
22 uint16 selector;
23 uint16 type;
24 char *port = "25";
25 char proto[7] = "._tcp.";
26 char *host;
27 unsigned char ch;
28 int opt;
29 int i, j, k;
30 int verbose = 0;
31
32 if (!argv[1])
33 logmsg(WHO,100,USAGE,"dnstlsa [-v] [-p port] [-u(dp)|-t(cp)] host (tcp on port 25 is default)" );
34
35 while ((opt = getopt(argc,argv,"vutp:")) != opteof) {
36 switch (opt) {
37 case 'p': port = optarg; break;
38 case 't': break;
39 case 'u': str_copy(proto,"._udp."); break;
40 case 'v': verbose = 1;
41 }
42 }
43 if (optind < argc)
44 host = argv[optind++];
45
46 if (!stralloc_copyb(&sa, "_",1)) logmsg(WHO,111,FATAL,"out of memory");
47 if (!stralloc_cats(&sa,port)) logmsg(WHO,111,FATAL,"out of memory");
48 if (!stralloc_cats(&sa,proto)) logmsg(WHO,111,FATAL,"out of memory");
49 if (!stralloc_cats(&sa,host)) logmsg(WHO,111,FATAL,"out of memory");
50
52 if (dns_cname(&cn,&sa) > 0)
53 { if ((r = dns_tlsa(&out,&cn)) < 0) _exit(1); }
54 else
55 if ((r = dns_tlsa(&out,&sa)) < 0) _exit(1);
56 if (!stralloc_0(&sa)) logmsg(WHO,111,FATAL,"out of memory");
57 if (verbose) logmsg(WHO,0,INFO,B("checking for TLSA records: ",sa.s,"\n"));
58
59 if (r > 0 && out.len > 4) {
60 for (i = 0; i <= out.len; i++) {
61 usage = (unsigned char) out.s[i];
62 selector = (unsigned char) out.s[i + 1];
63 type = (unsigned char) out.s[i + 2];
64
65 if (usage == 0) buffer_puts(buffer_1,"Usage: [0], ");
66 if (usage == 1) buffer_puts(buffer_1,"Usage: [1], ");
67 if (usage == 2) buffer_puts(buffer_1,"Usage: [2], ");
68 if (usage == 3) buffer_puts(buffer_1,"Usage: [3], ");
69
70 if (selector == 0) buffer_puts(buffer_1,"Selector: [0], ");
71 if (selector == 1) buffer_puts(buffer_1,"Selector: [1], ");
72
73 if (type == 0) buffer_puts(buffer_1,"Type: [0] "); // full cert
74 if (type == 1) buffer_puts(buffer_1,"Type: [1] "); // sha256
75 if (type == 2) buffer_puts(buffer_1,"Type: [2] "); // sha512
76
77 /* Staff of Ra
78 "(is) six kadams high." However, the builder (h)as
79 to subtract one kadam out of respect for the Hebrew God. */
80
81 for (j = i + 3, k = 0; j <= out.len; ++j) {
82 ch = (unsigned char) out.s[j];
83 if ((type == 1 && k == 32) || (type == 2 && k == 64)) {
84 buffer_putsflush(buffer_1,"\n");
85 i = j - 1; break;
86 } else {
87 buffer_put(buffer_1,"0123456789abcdef" + (ch >> 4),1);
88 buffer_put(buffer_1,"0123456789abcdef" + (ch & 0x0f),1);
89 k++;
90 }
91 }
92 }
93 }
94
95 _exit(0);
96}
int main()
Definition: chkshsgr.c:6
#define DNS_INIT
Definition: dns.h:12
int dns_tlsa(stralloc *out, const stralloc *fqdn)
Definition: dns_tlsa.c:41
stralloc out
Definition: dnscname.c:12
stralloc sa
Definition: dnscname.c:11
#define WHO
Definition: dnstlsa.c:12
void _exit()
char host[256]
Definition: hostname.c:5
void usage()
Definition: newinclude.c:24
stralloc selector
Definition: qmail-dksign.c:237
unsigned int port
int j
Definition: qmail-send.c:920
uint32_t k[64]
Definition: sha256.c:26