commit 22845837cc1b8397c859dc5e9d530c66a17f5dec
parent 02e0d456dafc376e3f2e3b94f651ce756e12e8da
Author: Ellenor Malik <ellenor@umbrellix.net>
Date: Thu, 6 Oct 2022 18:02:23 +0000
as it stands, this code is broken broken broken.
Diffstat:
4 files changed, 150 insertions(+), 91 deletions(-)
diff --git a/src/mxf-remote/errs.c b/src/mxf-remote/errs.c
@@ -7,6 +7,7 @@ extern buffer buffer_2_;
void out(const char *s) _HSC
if (buffer_puts(&buffer_2_,s) == -1) _exit(0);
+ buffer_flush(&buffer_2_);
}
void zero() _HSC
if (buffer_put(&buffer_2_,"\0",1) == -1) _exit(0);
@@ -144,7 +145,7 @@ void info_dbgs(const char *info) _HSC
void info_wtfs(const char *info) _HSC
out("I3.0.0 FYI: "); out(info); out(" referred me to errno: \"");
out(error_str(errno));
- out("\"");
+ out("\"\n");
return;
}
#else
diff --git a/src/mxf-remote/mxf-remote.c b/src/mxf-remote/mxf-remote.c
@@ -149,7 +149,7 @@ int run_fds (tain *deadline, tain *stamp)
struct pollfd *pfds = NULL; size_t pfdsiz = 0; size_t i = 0;
int pollret = 0;
HASH_ITER(hh, Descriptortab, des, tmp) {
- if (!pfdalloc_catpfd(&fds, &(des->fd))) temp_nomem();
+ if (!pfdalloc_catpfd(&fds, (des->fd))) temp_nomem();
des->fd.revents = 0;
++pfdsiz;
}
@@ -259,13 +259,16 @@ int protocols_init (protoAlloc *protos, char *protomaptext, size_t length)
case 0: continue; // it was an empty line
default : break;
}
+ fpos = -1;
lpos = 0;
field = 0;
comment = 0;
getroutes(&proto);
if (!stralloc_0(&(proto.app))) temp_nomem();
- if (proto.srvservice[0] != 0) if (!protoalloc_catp(protos, &proto)) temp_nomem();
+ buffer_puts(buffer_2, proto.srvservice[0] != 0 ? "srvservice[0] is not null\n" :"srvservice[0] is null\n");
+ if (proto.srvservice[0] != 0) if (!protoalloc_catp(protos, proto)) temp_nomem();
if (proto.slice > -1 && proto.slice < MAXSLICES) Slicemap[proto.slice] = protos->pt + protos->len-1;
+ buffer_puts(buffer_2, "reset\n");
memset(&proto, 0, sizeof(protocol_t));
proto.slice = -1;
break;
@@ -344,15 +347,14 @@ int protocols_init (protoAlloc *protos, char *protomaptext, size_t length)
buffer_puts(buffer_2, " field:");
s[fmt_ulong(s, field)] = 0;
buffer_puts(buffer_2, s);
- buffer_puts(buffer_2, " fpos:");
- s[fmt_ulong(s, fpos)] = 0;
- buffer_puts(buffer_2, s);
- buffer_puts(buffer_2, " ");
if (fpos == 0 && !(protomaptext[i] == '-')) proto.slice = 0; // reset slice to 0 as it is -1
- buffer_puts(buffer_2, s);
if (proto.slice != -1) { // a slice of -1 means we are not using a slice and this is a SRV only protocol
if (!(protomaptext[i] < '0' || protomaptext[i] > '9')) {
proto.slice = (proto.slice * 10) + (protomaptext[i] - '0');
+ s[fmt_ulong(s, proto.slice)] = 0;
+ buffer_puts(buffer_2, " slice:");
+ buffer_puts(buffer_2, s);
+ buffer_puts(buffer_2, " ");
} else {
info_dbgs("detected non-numeric character in slice number ");
out("it was ");
@@ -365,36 +367,44 @@ int protocols_init (protoAlloc *protos, char *protomaptext, size_t length)
case 3: // is TLS
switch (fpos) {
case 0: // we only care about char 1
- switch (protomaptext[i]) {
- case '0': case 'N': case 'n': case 'F':
- case 'f':
- proto.tls = 0;
- break;
- case '1': case 'Y': case 'y': case 'T':
- case 't':
- proto.tls = 1;
- default :
- // in default of a valid choice, we have no choice but to blow up.
- temp_control();
- }
+ if (
+ protomaptext[i] == '0'
+ || protomaptext[i] == 'n'
+ || protomaptext[i] == 'N'
+ || protomaptext[i] == 'f'
+ || protomaptext[i] == 'F'
+ ) proto.tls = 0;
+ else if (
+ protomaptext[i] == '1'
+ || protomaptext[i] == 'y'
+ || protomaptext[i] == 'Y'
+ || protomaptext[i] == 't'
+ || protomaptext[i] == 'T'
+ ) proto.tls = 1;
+ else temp_control();
+ // in default of a valid choice, we have no choice but to blow up.
default : break;
}
break;
case 4: // can TLS (irrelevant if is TLS)
switch (fpos + proto.tls) {
case 0: // we only care about char 1
- switch (protomaptext[i]) {
- case '0': case 'N': case 'n': case 'F':
- case 'f':
- proto.starttls = 0;
- break;
- case '1': case 'Y': case 'y': case 'T':
- case 't':
- proto.starttls = 1;
- default :
- // in default of a valid choice, we have no choice but to blow up.
- temp_control();
- }
+ if (
+ protomaptext[i] == '0'
+ || protomaptext[i] == 'n'
+ || protomaptext[i] == 'N'
+ || protomaptext[i] == 'f'
+ || protomaptext[i] == 'F'
+ ) proto.tls = 0;
+ else if (
+ protomaptext[i] == '1'
+ || protomaptext[i] == 'y'
+ || protomaptext[i] == 'Y'
+ || protomaptext[i] == 't'
+ || protomaptext[i] == 'T'
+ ) proto.tls = 1;
+ else temp_control();
+ // in default of a valid choice, we have no choice but to blow up.
default : break;
}
break;
@@ -406,7 +416,7 @@ int protocols_init (protoAlloc *protos, char *protomaptext, size_t length)
// the music is over. we're at the end of the file, on a partial line. hopefully app is at least an app we can try.
if (proto.app.len > 1) {
getroutes(&proto);
- if (!protoalloc_catp(protos, &proto)) return 0;
+ if (!protoalloc_catp(protos, proto)) return 0;
}
return 1;
}
@@ -514,9 +524,9 @@ void stopdns (skadns_t *dnsres) {
* They should not be thought of as "we definitely have our response"
* but as "we MAY have our response."
*/
-int dns_havea (skadns_t *dnsres, dnsq_t *dnsq, void* mxresultp, void* unused)
+int dns_havea (skadns_t *dnsres, dnsq_t *dnsq, void* mxresultp, void* protop)
{
- //protocol_t *proto = (protocol_t *)protop;
+ protocol_t *proto = (protocol_t *)protop;
mxresult_t *mxresult = (mxresult_t *)mxresultp;
//mxrAlloc *mxres = &(proto->mxresults);
//ipmxAlloc *ipmxres = &(mxres->ipmx);
@@ -526,35 +536,43 @@ int dns_havea (skadns_t *dnsres, dnsq_t *dnsq, void* mxresultp, void* unused)
char const *dnsresponse; int dnsresplen, i = 0;
s6dns_message_header_t dnsmh;
- if ((dnsresponse = skadns_packet(dnsres, dnsq->dnsq)) == NULL) temp_wtf("skadns_packet in dns_haveaaaa");
- if ((dnsresplen = skadns_packetlen(dnsres, dnsq->dnsq)) == -1) temp_wtf("skadns_packetlen in dns_haveaaaa"); // this should succeed if the above didn't fail
- if (dnsresplen < 12) { errno = EINVAL; temp_wtf("skadns_packetlen gave dns_haveaaaa less than even a header"); }
+ if ((dnsresponse = skadns_packet(dnsres, dnsq->dnsq)) == NULL) {
+ proto->lookupdone = 1;
+ info_wtfs("skadns_packet in dns_havea");
+ return FALSE;
+ }
+ if ((dnsresplen = skadns_packetlen(dnsres, dnsq->dnsq)) == -1) temp_wtf("skadns_packetlen in dns_havea"); // this should succeed if the above didn't fail
+ if (dnsresplen < 12) { errno = EINVAL; temp_wtf("skadns_packetlen gave dns_havea less than even a header"); }
// s6dns_message_header_unpack(dnsresponse, dnsmh);
- switch (s6dns_message_parse(&dnsmh, dnsresponse, dnsresplen, &s6dns_message_parse_answer_aaaa, &rrs)) {
+ switch (s6dns_message_parse(&dnsmh, dnsresponse, dnsresplen, &s6dns_message_parse_answer_a, &rrs)) {
case -1:
- temp_wtf("s6dns_message_parse in dns_haveaaaa - local error");
+ temp_wtf("s6dns_message_parse in dns_havea - local error");
break;
case 0:
- info_wtfs("s6dns_message_parse in dns_haveaaaa - rcode - maybe should continue");
+ info_wtfs("s6dns_message_parse in dns_havea - rcode - maybe should continue");
mxresult->lookupdone = 1;
mxresult->hasresults = 0;
+ proto->lookupdone = 1;
break;
case 1:
#ifdef REMOTEDEBUG
- info_dbgs("s6dns_message_parse in dns_haveaaaa - success no answer");
+ info_dbgs("s6dns_message_parse in dns_havea - success no answer");
#endif // REMOTEDEBUG
mxresult->lookupdone = 1;
mxresult->hasresults = 0;
+ proto->lookupdone = 1;
break;
case 2:
#ifdef REMOTEDEBUG
- info_dbgs("s6dns_message_parse in dns_haveaaaa - success answer");
+ info_dbgs("s6dns_message_parse in dns_havea - success answer");
#endif // REMOTEDEBUG
mxresult->lookupdone = 1;
mxresult->hasresults = 1;
+ proto->lookupdone = 1;
+ proto->hasresults = 1;
for (i = 0; i < rrs.len/4; ++i) {
memcpy(&(ipmx.ip.ip), (rrs.s + (i * 4)), 4);
- if (!ipmxalloc_catip(&(mxresult->ipmx), &ipmx)) temp_nomem();
+ if (!ipmxalloc_catip(&(mxresult->ipmx), ipmx)) temp_nomem();
if (ipisme(&ipmx)) mxresult->isme = 1;
memset(&ipmx, 0, sizeof(ipmx_t)); ipmx.ip.is6 = 0;
}
@@ -562,9 +580,9 @@ int dns_havea (skadns_t *dnsres, dnsq_t *dnsq, void* mxresultp, void* unused)
}
return TRUE;
}
-int dns_haveaaaa (skadns_t *dnsres, dnsq_t *dnsq, void* mxresultp, void* unused)
+int dns_haveaaaa (skadns_t *dnsres, dnsq_t *dnsq, void* mxresultp, void* protop)
{
- //protocol_t *proto = (protocol_t *)protop;
+ protocol_t *proto = (protocol_t *)protop;
mxresult_t *mxresult = (mxresult_t *)mxresultp;
//mxrAlloc *mxres = &(proto->mxresults);
//ipmxAlloc *ipmxres = &(mxres->ipmx);
@@ -574,7 +592,12 @@ int dns_haveaaaa (skadns_t *dnsres, dnsq_t *dnsq, void* mxresultp, void* unused)
char const *dnsresponse; int dnsresplen, i = 0;
s6dns_message_header_t dnsmh;
- if ((dnsresponse = skadns_packet(dnsres, dnsq->dnsq)) == NULL) temp_wtf("skadns_packet in dns_haveaaaa");
+ if ((dnsresponse = skadns_packet(dnsres, dnsq->dnsq)) == NULL) {
+ info_wtfs("skadns_packet in dns_haveaaaa");
+ proto->lookupdone = 1;
+ mxresult->lookupdone = 1;
+ return FALSE;
+ }
if ((dnsresplen = skadns_packetlen(dnsres, dnsq->dnsq)) == -1) temp_wtf("skadns_packetlen in dns_haveaaaa"); // this should succeed if the above didn't fail
if (dnsresplen < 12) { errno = EINVAL; temp_wtf("skadns_packetlen gave dns_haveaaaa less than even a header"); }
// s6dns_message_header_unpack(dnsresponse, dnsmh);
@@ -585,14 +608,14 @@ int dns_haveaaaa (skadns_t *dnsres, dnsq_t *dnsq, void* mxresultp, void* unused)
case 0:
info_wtfs("s6dns_message_parse in dns_haveaaaa - rcode - maybe should continue");
mxresult->lookupdone = 1;
- mxresult->hasresults = 0;
+ proto->lookupdone = 1;
break;
case 1:
#ifdef REMOTEDEBUG
info_dbgs("s6dns_message_parse in dns_haveaaaa - success no answer");
#endif // REMOTEDEBUG
mxresult->lookupdone = 1;
- mxresult->hasresults = 0;
+ proto->lookupdone = 1;
break;
case 2:
#ifdef REMOTEDEBUG
@@ -601,9 +624,11 @@ int dns_haveaaaa (skadns_t *dnsres, dnsq_t *dnsq, void* mxresultp, void* unused)
#ifdef SKALIBS_IPV6_ENABLED
mxresult->lookupdone = 1;
mxresult->hasresults = 1;
+ proto->lookupdone = 1;
+ proto->hasresults = 1;
for (i = 0; i < rrs.len/16; ++i) {
memcpy(&(ipmx.ip.ip), (rrs.s + (i * 16)), 16);
- if (!ipmxalloc_catip(&(mxresult->ipmx), &ipmx)) temp_nomem();
+ if (!ipmxalloc_catip(&(mxresult->ipmx), ipmx)) temp_nomem();
if (ipisme(&ipmx)) mxresult->isme = 1;
memset(&ipmx, 0, sizeof(ipmx_t)); ipmx.ip.is6 = 1;
}
@@ -619,12 +644,17 @@ int dns_havesrv (skadns_t *dnsres, dnsq_t *dnsq, void* protop, void* unused)
mxrAlloc *mxres = &(proto->mxresults);
mxresult_t mxr = MXRESULT_SRV_ZERO;
genalloc rrs = GENALLOC_ZERO;
- const char *dnsresponse; int dnsresplen, i = 0;
+ tain shortdl;
+ const char *dnsresponse; char ds[256]; int dnsresplen = 0, dsl = 0, i = 0;
s6dns_message_header_t dnsmh;
s6dns_message_rr_srv_t *rr = NULL;
uint16_t qid4, qid6;
- if ((dnsresponse = skadns_packet(dnsres, dnsq->dnsq)) == NULL) temp_wtf("skadns_packet in dns_havesrv");
+ if ((dnsresponse = skadns_packet(dnsres, dnsq->dnsq)) == NULL) {
+ info_wtfs("skadns_packet in dns_havesrv");
+ proto->lookupdone = 1;
+ return FALSE;
+ }
if ((dnsresplen = skadns_packetlen(dnsres, dnsq->dnsq)) == -1) temp_wtf("skadns_packetlen in dns_havesrv"); // this should succeed if the above didn't fail
if (dnsresplen < 12) { errno = EINVAL; temp_wtf("skadns_packetlen gave dns_havesrv less than even a header"); }
// s6dns_message_header_unpack(dnsresponse, dnsmh);
@@ -634,6 +664,7 @@ int dns_havesrv (skadns_t *dnsres, dnsq_t *dnsq, void* protop, void* unused)
break;
case 0:
info_wtfs("s6dns_message_parse in dns_havesrv - maybe should continue");
+ proto->lookupdone = 1;
break;
case 1:
#ifdef REMOTEDEBUG
@@ -649,28 +680,32 @@ int dns_havesrv (skadns_t *dnsres, dnsq_t *dnsq, void* protop, void* unused)
proto->lookupdone = 1;
proto->hasresults = 1;
for (i = 0; i < genalloc_len(s6dns_message_rr_srv_t, &rrs); ++i) {
- rr = (s6dns_message_rr_srv_t *)(rrs.s) + (i * sizeof(s6dns_message_rr_srv_t));
+// rr = (s6dns_message_rr_srv_t *)((rrs.s) + (i * sizeof(s6dns_message_rr_srv_t)));
+ rr = genalloc_s(s6dns_message_rr_srv_t, &rrs) + i;
mxr.lookupdone = TRUE;
mxr.port = rr->port;
mxr.prio = rr->priority;
mxr.weight = rr->weight;
- if (!stralloc_readyplus(&(mxr.name), rr->target.len+3)) temp_nomem();
- if (!(mxr.name.len = s6dns_domain_tostring(mxr.name.s, rr->target.len+3, &(rr->target)))) temp_wtf("s6dns_domain_tostring in dns_havesrv");
+ if (!(dsl = s6dns_domain_tostring(ds, 255, &(rr->target)))) temp_wtf("s6dns_domain_tostring in dns_havesrv");
+ if (!stralloc_readyplus(&(mxr.name), dsl)) temp_nomem();
+ if (!stralloc_copyb(&(mxr.name), ds, dsl)) temp_nomem();
+ if (!stralloc_0(&(mxr.name))) temp_nomem();
if (!tain_addsec(&Limit, &Stamp, Timeoutconnect)) temp_wtf("tain_addsec in dns_havesrv (Doctor?)");
- if (!tain_addsec(&Deadline, &Stamp, 1)) temp_wtf("tain_addsec in dns_havesrv (Doctor?)");
- if (!mxralloc_catmxr(mxres, &mxr)) temp_nomem();
+ if (!tain_addsec(&shortdl, &Stamp, Timeoutconnect)) temp_wtf("tain_addsec in dns_havesrv (Doctor?)");
+ if (!mxralloc_catmxr(mxres, mxr)) temp_nomem();
if (mxr.name.len > 1) { // No point if it's just a dot
- if (!skadns_send(&Dnsres, &qid4, &(rr->target), S6DNS_T_A, &Limit, &Deadline, &Stamp)) temp_wtf("skadns_send in dns_havesrv");
- if (!dnsq_add(qid4, &(mxres->mxr[(mxres->len)-1]), NULL, dns_havea)) temp_wtf("dnsq_add in dns_havesrv");
- if (!skadns_send(&Dnsres, &qid6, &(rr->target), S6DNS_T_AAAA, &Limit, &Deadline, &Stamp)) temp_wtf("skadns_send in dns_havesrv");
- if (!dnsq_add(qid6, &(mxres->mxr[(mxres->len)-1]), NULL, dns_haveaaaa)) temp_wtf("dnsq_add in dns_havesrv");
+ if (!skadns_send(&Dnsres, &qid4, &(rr->target), S6DNS_T_A, &Limit, &shortdl, &Stamp)) temp_wtf("skadns_send in dns_havesrv");
+ if (!dnsq_add(qid4, &(mxres->mxr[(mxres->len)-1]), proto, dns_havea)) temp_wtf("dnsq_add in dns_havesrv");
+ if (!skadns_send(&Dnsres, &qid6, &(rr->target), S6DNS_T_AAAA, &Limit, &shortdl, &Stamp)) temp_wtf("skadns_send in dns_havesrv");
+ if (!dnsq_add(qid6, &(mxres->mxr[(mxres->len)-1]), proto, dns_haveaaaa)) temp_wtf("dnsq_add in dns_havesrv");
}
- mxresult_t mxr = MXRESULT_SRV_ZERO;
+ memset(&mxr, 0, sizeof(mxresult_t));
}
break;
}
return TRUE;
}
+
int dns_havemx (skadns_t *dnsres, dnsq_t *dnsq, void* protop, void* unused)
{
// XX - should probably pass the whole protoalloc as protop
@@ -678,12 +713,16 @@ int dns_havemx (skadns_t *dnsres, dnsq_t *dnsq, void* protop, void* unused)
mxrAlloc *mxres = NULL;
mxresult_t mxr = MXRESULT_MX_ZERO;
genalloc rrs = GENALLOC_ZERO;
- char const *dnsresponse; int dnsresplen, i = 0;
+ tain shortdl;
+ char const *dnsresponse; char ds[256]; int dnsresplen = 0, dsl = 0, i = 0;
s6dns_message_header_t dnsmh;
s6dns_message_rr_mx_t *rr = NULL;
uint16_t qid4, qid6;
- if ((dnsresponse = skadns_packet(dnsres, dnsq->dnsq)) == NULL) temp_wtf("skadns_packet in dns_havemx");
+ if ((dnsresponse = skadns_packet(dnsres, dnsq->dnsq)) == NULL) {
+ info_wtfs("skadns_packet in dns_havemx");
+ return FALSE;
+ }
if ((dnsresplen = skadns_packetlen(dnsres, dnsq->dnsq)) == -1) temp_wtf("skadns_packetlen in dns_havemx"); // this should succeed if the above didn't fail
if (dnsresplen < 12) { errno = EINVAL; temp_wtf("skadns_packetlen gave dns_havemx less than even a header"); }
// s6dns_message_header_unpack(dnsresponse, dnsmh);
@@ -693,19 +732,20 @@ int dns_havemx (skadns_t *dnsres, dnsq_t *dnsq, void* protop, void* unused)
break;
case 0:
info_wtfs("s6dns_message_parse in dns_havemx - maybe should continue");
+ proto->lookupdone = 1;
break;
case 1:
#ifdef REMOTEDEBUG
buffer_puts(&buffer_2_, "Is6dns_message_parse in dns_havemx - success no answer\n");
#endif // REMOTEDEBUG
-
break;
case 2:
#ifdef REMOTEDEBUG
buffer_puts(&buffer_2_, "Is6dns_message_parse in dns_havemx - success answer\n");
#endif // REMOTEDEBUG
for (i = 0; i < genalloc_len(s6dns_message_rr_mx_t, &rrs); ++i) {
- rr = (s6dns_message_rr_mx_t *)(rrs.s) + (i * sizeof(s6dns_message_rr_mx_t));
+ //rr = (s6dns_message_rr_mx_t *)((rrs.s) + (i * sizeof(s6dns_message_rr_mx_t)));
+ rr = genalloc_s(s6dns_message_rr_mx_t, &rrs) + i;
mxr.lookupdone = TRUE;
if (_is_mxps(rr->preference)) {
if ((proto = Slicemap[_mxps_slice(rr->preference)]) == NULL) proto = Slicemap[NOMXPS_SLICE];
@@ -715,22 +755,27 @@ int dns_havemx (skadns_t *dnsres, dnsq_t *dnsq, void* protop, void* unused)
mxr.prio = rr->preference;
}
if (proto == NULL) {errno = EINVAL; temp_wtf("dns_havemx - postmanager has not configured a zero MXPS slice, and this is necessary.");}
+ proto->lookupdone = 1;
proto->hasresults = 1;
mxres = &(proto->mxresults);
mxr.port = proto->defport;
mxr.weight = 0;
- if (!stralloc_readyplus(&(mxr.name), rr->exchange.len+3)) temp_nomem();
- if (!(mxr.name.len = s6dns_domain_tostring(mxr.name.s, rr->exchange.len+3, &(rr->exchange)))) temp_wtf("s6dns_domain_tostring in dns_havemx");
+ if (!(dsl = s6dns_domain_tostring(ds, 255, &(rr->exchange)))) temp_wtf("s6dns_domain_tostring in dns_havemx");
+ ds[dsl] = 0;
+ if (!stralloc_readyplus(&(mxr.name), dsl+1)) temp_nomem();
+ if (!stralloc_copyb(&(mxr.name), ds, dsl)) temp_nomem();
+ if (!stralloc_0(&(mxr.name))) temp_nomem();
if (!tain_addsec(&Limit, &Stamp, Timeoutconnect)) temp_wtf("tain_addsec in dns_havemx (Doctor?)");
- if (!tain_addsec(&Deadline, &Stamp, 1)) temp_wtf("tain_addsec in dns_havemx (Doctor?)");
- if (!mxralloc_catmxr(mxres, &mxr)) temp_nomem();
+ if (!tain_addsec(&shortdl, &Stamp, Timeoutconnect)) temp_wtf("tain_addsec in dns_havemx (Doctor?)");
+ if (!mxralloc_catmxr(mxres, mxr)) temp_nomem();
if (mxr.name.len > 1) { // No point if it's just a dot, NPI.
- if (!skadns_send(&Dnsres, &qid4, &(rr->exchange), S6DNS_T_A, &Limit, &Deadline, &Stamp)) temp_wtf("skadns_send in dns_havemx");
- if (!dnsq_add(qid4, &(mxres->mxr[(mxres->len)-1]), NULL, dns_havea)) temp_wtf("dnsq_add in dns_havemx");
- if (!skadns_send(&Dnsres, &qid6, &(rr->exchange), S6DNS_T_AAAA, &Limit, &Deadline, &Stamp)) temp_wtf("skadns_send in dns_havemx");
- if (!dnsq_add(qid6, &(mxres->mxr[(mxres->len)-1]), NULL, dns_haveaaaa)) temp_wtf("dnsq_add in dns_havemx");
+ if (!skadns_send(&Dnsres, &qid4, &(rr->exchange), S6DNS_T_A, &Limit, &shortdl, &Stamp)) temp_wtf("skadns_send in dns_havemx");
+ if (!dnsq_add(qid4, &(mxres->mxr[(mxres->len)-1]), proto, dns_havea)) temp_wtf("dnsq_add in dns_havemx");
+ if (!skadns_send(&Dnsres, &qid6, &(rr->exchange), S6DNS_T_AAAA, &Limit, &shortdl, &Stamp)) temp_wtf("skadns_send in dns_havemx");
+ if (!dnsq_add(qid6, &(mxres->mxr[(mxres->len)-1]), proto, dns_haveaaaa)) temp_wtf("dnsq_add in dns_havemx");
}
- mxresult_t mxr = MXRESULT_MX_ZERO;
+ memset(&mxr, 0, sizeof(mxresult_t));
+ mxr.ismx = TRUE;
}
break;
}
@@ -833,7 +878,7 @@ int dns_wantip (protocol_t *proto, uint16_t port, char *relayhost)
if (!s6dns_domain_fromstring_noqualify_encode(&dnsdomain, domain.s, domain.len)) temp_wtf("s6dns_domain_fromstring_noqualify_encode in dns_wantip");
if (!tain_addsec(&Limit, &Stamp, Timeoutconnect)) temp_wtf("tain_addsec in dns_wantip (Doctor?)");
if (!tain_addsec(&Deadline, &Stamp, 1)) temp_wtf("tain_addsec in dns_wantip (Doctor?)");
- if (!mxralloc_catmxr(mxres, &mxr)) temp_nomem();
+ if (!mxralloc_catmxr(mxres, mxr)) temp_nomem();
if (!skadns_send(&Dnsres, &qid6, &dnsdomain, S6DNS_T_AAAA, &Limit, &Deadline, &Stamp)) temp_wtf("skadns_send in dns_wantip");
if (!dnsq_add(qid6, &(mxres->mxr[(mxres->len)-1]), NULL, dns_haveaaaa)) temp_wtf("dnsq_add in dns_wantip");
if (!skadns_send(&Dnsres, &qid4, &dnsdomain, S6DNS_T_A, &Limit, &Deadline, &Stamp)) temp_wtf("skadns_send in dns_wantip");
@@ -848,7 +893,7 @@ int lookupsdone (protocol_t *proto) {
int i = 0;
if (proto->lookupdone == 0) return FALSE;
for (i = 0; i < proto->mxresults.len; ++i) {
- mxr = (mxresult_t *)((proto->mxresults.mxr) + (i * sizeof(protocol_t)));
+ mxr = (mxresult_t *)((proto->mxresults.mxr) + (i * sizeof(mxresult_t)));
if (mxr->lookupdone == 0) return FALSE;
}
return TRUE; // if we have not returned false by now, all lookups are done
@@ -893,26 +938,35 @@ void printprotos () {
ipmx_t *ipmx = NULL;
char s[48]; int i = 0, j = 0; unsigned long l = 0;
memset(&s, 0, 48);
+ out("I3.0.0 ");
+ out("Protocol element count: ");
+ s[fmt_ulong(s, Protocols.len)] = 0;
+ out(s);
+ out(" Protocol element allocation count: ");
+ s[fmt_ulong(s, Protocols.a)] = 0;
+ out(s);
+ out("\n");
if (Protocols.len < 1) {
info_dbgs("3.3.0 No protocols on the protocol array!");
} else {
for (i = 0; i < Protocols.len; ++i) {
- proto = (protocol_t *)((Protocols.pt) + (i * sizeof(protocol_t)));
+ proto = (protocol_t *)&(Protocols.pt[i]);
+ // + (i * sizeof(protocol_t)));
out("I3.0.0 ");
out("Protocol element #");
- fmt_ulong(s, i);
+ s[fmt_ulong(s, i)] = 0;
out(s);
out(": \n srvservice: ");
out(proto->srvservice);
out("\n defport: ");
- fmt_uint(s, proto->defport);
+ s[fmt_uint(s, proto->defport)] = 0;
out(s);
if (proto->slice < 0)
out("\n no MXPS slice for this protocol");
else {
l = proto->slice;
out("\n slice: ");
- fmt_uint(s, l);
+ s[fmt_uint(s, l)] = 0;
out(s);
}
switch (proto->tls) {
@@ -952,13 +1006,13 @@ void printprotos () {
out("\n MX or SRVmail results exist");
for (j = 0; j < proto->mxresults.len; ++j) {
out("\n port: ");
- fmt_uint(s, proto->mxresults.mxr[j].port);
+ s[fmt_uint(s, proto->mxresults.mxr[j].port)] = 0;
out(s);
out(" prio: ");
- fmt_uint(s, proto->mxresults.mxr[j].prio);
+ s[fmt_uint(s, proto->mxresults.mxr[j].prio)] = 0;
out(s);
out(" weight: ");
- fmt_uint(s, proto->mxresults.mxr[j].weight);
+ s[fmt_uint(s, proto->mxresults.mxr[j].weight)] = 0;
out(s);
out(" SRV/MX: ");
out(proto->mxresults.mxr[j].ismx ? "MX" : "SRV");
@@ -985,6 +1039,7 @@ void printprotos () {
out("\n\n");
buffer_flush(buffer_2);
}
+ buffer_flush(buffer_2);
}
}
@@ -1105,12 +1160,13 @@ int main (int argcount, char **args)
// prio/wt dealt with
if (!stralloc_copys(&(rhmxr.name), relayhost)) temp_nomem();
if (!stralloc_0(&(rhmxr.name))) temp_nomem();
- if (!ipmxalloc_catip(&(rhmxr.ipmx), &ipmx)) temp_nomem();
+ if (!ipmxalloc_catip(&(rhmxr.ipmx), ipmx)) temp_nomem();
}
} else {
// our DNS volley
dns_wantsrv(proto, nprotos);
dns_wantmx(proto, nprotos);
+ out("regular DNS...\n");
}
tain_now(&Stamp);
@@ -1123,7 +1179,8 @@ int main (int argcount, char **args)
if (!tain_less(&Stamp, &Deadline)) {
errno = ETIMEDOUT;
skadns_end(&Dnsres);
- temp_wtf("DNS lookup event loop took too long - mostly orderly shutdown executed"); // cut...
+ info_wtfs("DNS lookup event loop took too long - mostly orderly shutdown executed"); // cut...
+ break;
}
} // should not run if lookupsdone_all already (SLIP relayhost)
diff --git a/src/mxf-remote/typeallocdefs.h b/src/mxf-remote/typeallocdefs.h
@@ -18,7 +18,7 @@ int ta_rplus(ta *x, size_t n);
int ta_ready(ta *x, size_t n);
#define TypeAlloc_append(ta,type,field,len,a,base,ta_rplus,ta_append) \
-int ta_append(ta *x, type *i);
+int ta_append(ta *x, type i);
#define TypeAlloc_appendentries(ta,type,field,len,a,base,ta_rplus,ta_cat) \
int ta_cat(ta *x, type *i, size_t n);
diff --git a/src/mxf-remote/typealloclib.h b/src/mxf-remote/typealloclib.h
@@ -4,6 +4,7 @@
/* de https://github.com/notqmail/notqmail */
//#include "alloc.h"
+#include <stdlib.h>
#include "error.h"
// needed from qmail
@@ -50,17 +51,17 @@ int ta_ready(ta *x, size_t n) \
{ return ta_ready ## plus_internal (x, n, 0); }
#define TypeAlloc_append(ta,type,field,len,a,base,ta_rplus,ta_append) \
-int ta_append(ta *x, type *i) \
-{ if (!ta_rplus(x,1)) return 0; x->field[x->len++] = *i; return 1; }
+int ta_append(ta *x, type i) \
+{ if (!ta_rplus(x,1)) return 0; x->field[x->len++] = i; return 1; }
#define TypeAlloc_appendentries(ta,type,field,len,a,base,ta_rplus,ta_cat) \
int ta_cat(ta *x, type *i, size_t n) \
-{ if (!ta_rplus(x,n)) return 0; for (int j = 0; j < n; ++j) x->field[x->len++] = *(i + j); return 1; }
+{ if (!ta_rplus(x,n)) return 0; for (size_t j = 0; j < n; ++j) x->field[x->len++] = *(i + j); return 1; }
// example usage -> ta_copy(saa, saa);
#define TypeAlloc_copy(ta,type,field,len,a,base,ta_ready,ta_copy) \
int ta_copy(ta *x, ta *y) \
-{ if (!ta_ready(x,y->len)) return 0; x->len = 0; for (int j = 0; j < y->len; ++j) x->field[x->len++] = *(y->field + j); return 1; }
+{ if (!ta_ready(x,y->len)) return 0; x->len = 0; for (size_t j = 0; j < y->len; ++j) x->field[x->len++] = *(y->field + j); return 1; }
#define TypeAlloc_free(ta,type,field,len,a,base,ta_free) \
int ta_free(ta *x) \