summaryrefslogtreecommitdiff
path: root/src/dnstlsa.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/dnstlsa.c')
-rw-r--r--src/dnstlsa.c82
1 files changed, 42 insertions, 40 deletions
diff --git a/src/dnstlsa.c b/src/dnstlsa.c
index 9871fff..284f7d1 100644
--- a/src/dnstlsa.c
+++ b/src/dnstlsa.c
@@ -1,13 +1,15 @@
#include <unistd.h>
+
#include "buffer.h"
-#include "stralloc.h"
+#include "byte.h"
#include "dnsresolv.h"
-#include "dns.h"
#include "exit.h"
-#include "logmsg.h"
#include "getoptb.h"
+#include "logmsg.h"
#include "str.h"
-#include "byte.h"
+#include "stralloc.h"
+
+#include "dns.h"
#define WHO "dnstlsa"
@@ -15,7 +17,7 @@ static stralloc cn = {0};
static stralloc sa = {0};
static stralloc out = {0};
-int main(int argc,char **argv)
+int main(int argc, char **argv)
{
int r;
uint16 usage;
@@ -29,68 +31,68 @@ int main(int argc,char **argv)
int i, j, k;
int verbose = 0;
- if (!argv[1])
- logmsg(WHO,100,USAGE,"dnstlsa [-v] [-p port] [-u(dp)|-t(cp)] host (tcp on port 25 is default)" );
+ if (!argv[1])
+ logmsg(WHO, 100, USAGE, "dnstlsa [-v] [-p port] [-u(dp)|-t(cp)] host (tcp on port 25 is default)");
- while ((opt = getopt(argc,argv,"vutp:")) != opteof) {
+ while ((opt = getopt(argc, argv, "vutp:")) != opteof) {
switch (opt) {
case 'p': port = optarg; break;
case 't': break;
- case 'u': str_copy(proto,"._udp."); break;
+ case 'u': str_copy(proto, "._udp."); break;
case 'v': verbose = 1;
}
}
- if (optind < argc)
- host = argv[optind++];
+ if (optind < argc) host = argv[optind++];
- if (!stralloc_copyb(&sa, "_",1)) logmsg(WHO,111,FATAL,"out of memory");
- if (!stralloc_cats(&sa,port)) logmsg(WHO,111,FATAL,"out of memory");
- if (!stralloc_cats(&sa,proto)) logmsg(WHO,111,FATAL,"out of memory");
- if (!stralloc_cats(&sa,host)) logmsg(WHO,111,FATAL,"out of memory");
+ if (!stralloc_copyb(&sa, "_", 1)) logmsg(WHO, 111, FATAL, "out of memory");
+ if (!stralloc_cats(&sa, port)) logmsg(WHO, 111, FATAL, "out of memory");
+ if (!stralloc_cats(&sa, proto)) logmsg(WHO, 111, FATAL, "out of memory");
+ if (!stralloc_cats(&sa, host)) logmsg(WHO, 111, FATAL, "out of memory");
DNS_INIT
- if (dns_cname(&cn,&sa) > 0)
- { if ((r = dns_tlsa(&out,&cn)) < 0) _exit(1); }
- else
- if ((r = dns_tlsa(&out,&sa)) < 0) _exit(1);
- if (!stralloc_0(&sa)) logmsg(WHO,111,FATAL,"out of memory");
- if (verbose) logmsg(WHO,0,INFO,B("checking for TLSA records: ",sa.s,"\n"));
+ if (dns_cname(&cn, &sa) > 0) {
+ if ((r = dns_tlsa(&out, &cn)) < 0) _exit(1);
+ } else if ((r = dns_tlsa(&out, &sa)) < 0)
+ _exit(1);
+ if (!stralloc_0(&sa)) logmsg(WHO, 111, FATAL, "out of memory");
+ if (verbose) logmsg(WHO, 0, INFO, B("checking for TLSA records: ", sa.s, "\n"));
if (r > 0 && out.len > 4) {
for (i = 0; i <= out.len; i++) {
- usage = (unsigned char) out.s[i];
- selector = (unsigned char) out.s[i + 1];
- type = (unsigned char) out.s[i + 2];
+ usage = (unsigned char)out.s[i];
+ selector = (unsigned char)out.s[i + 1];
+ type = (unsigned char)out.s[i + 2];
- if (usage == 0) buffer_puts(buffer_1,"Usage: [0], ");
- if (usage == 1) buffer_puts(buffer_1,"Usage: [1], ");
- if (usage == 2) buffer_puts(buffer_1,"Usage: [2], ");
- if (usage == 3) buffer_puts(buffer_1,"Usage: [3], ");
+ if (usage == 0) buffer_puts(buffer_1, "Usage: [0], ");
+ if (usage == 1) buffer_puts(buffer_1, "Usage: [1], ");
+ if (usage == 2) buffer_puts(buffer_1, "Usage: [2], ");
+ if (usage == 3) buffer_puts(buffer_1, "Usage: [3], ");
- if (selector == 0) buffer_puts(buffer_1,"Selector: [0], ");
- if (selector == 1) buffer_puts(buffer_1,"Selector: [1], ");
+ if (selector == 0) buffer_puts(buffer_1, "Selector: [0], ");
+ if (selector == 1) buffer_puts(buffer_1, "Selector: [1], ");
- if (type == 0) buffer_puts(buffer_1,"Type: [0] "); // full cert
- if (type == 1) buffer_puts(buffer_1,"Type: [1] "); // sha256
- if (type == 2) buffer_puts(buffer_1,"Type: [2] "); // sha512
+ if (type == 0) buffer_puts(buffer_1, "Type: [0] "); // full cert
+ if (type == 1) buffer_puts(buffer_1, "Type: [1] "); // sha256
+ if (type == 2) buffer_puts(buffer_1, "Type: [2] "); // sha512
/* Staff of Ra
"(is) six kadams high." However, the builder (h)as
to subtract one kadam out of respect for the Hebrew God. */
for (j = i + 3, k = 0; j <= out.len; ++j) {
- ch = (unsigned char) out.s[j];
+ ch = (unsigned char)out.s[j];
if ((type == 1 && k == 32) || (type == 2 && k == 64)) {
- buffer_putsflush(buffer_1,"\n");
- i = j - 1; break;
- } else {
- buffer_put(buffer_1,"0123456789abcdef" + (ch >> 4),1);
- buffer_put(buffer_1,"0123456789abcdef" + (ch & 0x0f),1);
+ buffer_putsflush(buffer_1, "\n");
+ i = j - 1;
+ break;
+ } else {
+ buffer_put(buffer_1, "0123456789abcdef" + (ch >> 4), 1);
+ buffer_put(buffer_1, "0123456789abcdef" + (ch & 0x0f), 1);
k++;
}
}
}
}
-
+
_exit(0);
}