Skip to content

Commit a75d024

Browse files
committed
Fix ARTEST, make it a real program instead of a hack
This might be a useful tool, but hiding it behind a define means it gets out of sync very easily (which it had.)
1 parent 91a64be commit a75d024

File tree

5 files changed

+92
-81
lines changed

5 files changed

+92
-81
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ All notable changes to this project will be documented in this file.
3131
failure, as required by [RFC 8617 section 4.1.3](https://datatracker.ietf.org/doc/html/rfc8617#section-4.1.3).
3232
- milter - `Authentication-Results` and `ARC-Authentication-Results` include
3333
`header.oldest-pass` when appropriate.
34+
- milter - An `ar-test` program for seeing how `Authentication-Results`
35+
headers are parsed is built without making you jump through weird hoops.
3436

3537
### Fixed
3638
- libopenarc - Seals on failed chains only cover the latest ARC header set,

Makefile.am

+9
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,15 @@ openarc_openarc_CFLAGS = $(PTHREAD_CFLAGS)
9191
openarc_openarc_CPPFLAGS = -I$(srcdir)/libopenarc -I$(srcdir)/util $(OPENSSL_CFLAGS) $(LIBIDN2_CFLAGS) $(LIBMILTER_CPPFLAGS) $(LIBJANSSON_CFLAGS)
9292
openarc_openarc_LDFLAGS = $(LIBMILTER_LDFLAGS) $(PTHREAD_CFLAGS)
9393
openarc_openarc_LDADD = libopenarc/libopenarc.la $(LIBMILTER_LIBS) $(OPENSSL_LIBS) $(LIBIDN2_LIBS) $(PTHREAD_LIBS) $(LIBJANSSON_LIBS) $(LIBRESOLV)
94+
95+
noinst_PROGRAMS = openarc/ar-test
96+
97+
openarc_ar_test_SOURCES = \
98+
openarc/openarc-ar.c \
99+
openarc/openarc-ar.h \
100+
openarc/ar-test.c
101+
102+
openarc_ar_test_CPPFLAGS = -I$(srcdir)/libopenarc -I$(srcdir)/util
94103
endif
95104

96105
$(DIST_ARCHIVES).sha1: $(DIST_ARCHIVES)

openarc/ar-test.c

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
** Copyright (c) 2007-2009 Sendmail, Inc. and its suppliers.
3+
** All rights reserved.
4+
**
5+
** Copyright (c) 2009, 2011-2014, 2016, 2017, The Trusted Domain Project.
6+
** All rights reserved.
7+
*/
8+
9+
#include "build-config.h"
10+
11+
/* system includes */
12+
#include <string.h>
13+
#include <sysexits.h>
14+
15+
/* openarc includes */
16+
#include "openarc-ar.h"
17+
18+
int
19+
main(int argc, char **argv)
20+
{
21+
int c;
22+
int d;
23+
int status;
24+
char *p;
25+
char *progname;
26+
struct authres ar;
27+
char buf[ARC_MAXHEADER + 2];
28+
char *toks[1024];
29+
30+
progname = (p = strrchr(argv[0], '/')) == NULL ? argv[0] : p + 1;
31+
32+
if (argc != 2)
33+
{
34+
printf("%s: usage: %s header-value\n", progname, progname);
35+
return EX_USAGE;
36+
}
37+
38+
c = ares_tokenize(argv[1], buf, sizeof buf, toks, 1024);
39+
for (d = 0; d < c; d++)
40+
{
41+
printf("token %d = '%s'\n", d, toks[d]);
42+
}
43+
44+
printf("\n");
45+
46+
status = ares_parse(argv[1], &ar, NULL);
47+
if (status == -1)
48+
{
49+
printf("%s: ares_parse() returned -1\n", progname);
50+
return EX_OK;
51+
}
52+
53+
printf("%d result%s found\n", ar.ares_count, ar.ares_count == 1 ? "" : "s");
54+
55+
printf("authserv-id '%s'\n", ar.ares_host);
56+
printf("version '%s'\n", ar.ares_version);
57+
58+
for (c = 0; c < ar.ares_count; c++)
59+
{
60+
printf("result #%d, %d propert%s\n", c, ar.ares_result[c].result_props,
61+
ar.ares_result[c].result_props == 1 ? "y" : "ies");
62+
63+
printf("\tmethod \"%s\"\n",
64+
ares_getmethod(ar.ares_result[c].result_method));
65+
printf("\tresult \"%s\"\n",
66+
ares_getresult(ar.ares_result[c].result_result));
67+
printf("\treason \"%s\"\n", ar.ares_result[c].result_reason);
68+
69+
for (d = 0; d < ar.ares_result[c].result_props; d++)
70+
{
71+
printf("\tproperty #%d\n", d);
72+
printf("\t\tptype \"%s\"\n",
73+
ares_getptype(ar.ares_result[c].result_ptype[d]));
74+
printf("\t\tproperty \"%s\"\n",
75+
ar.ares_result[c].result_property[d]);
76+
printf("\t\tvalue \"%s\"\n", ar.ares_result[c].result_value[d]);
77+
}
78+
}
79+
}

openarc/openarc-ar.c

+1-81
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@
1515
#include <string.h>
1616
#include <sys/param.h>
1717
#include <sys/types.h>
18-
#ifdef ARTEST
19-
#include <sysexits.h>
20-
#endif /* ARTEST */
2118

2219
/* libbsd if found */
2320
#ifdef USE_BSD_H
@@ -126,7 +123,7 @@ enum ar_parser_state
126123
** pointers available.
127124
*/
128125

129-
static int
126+
int
130127
ares_tokenize(const char *input,
131128
char *outbuf,
132129
size_t outbuflen,
@@ -857,80 +854,3 @@ ares_getptype(ares_ptype ptype)
857854
{
858855
return (const char *) ares_xconvert(ptypes, ptype);
859856
}
860-
861-
#ifdef ARTEST
862-
/*
863-
** MAIN -- program mainline
864-
**
865-
** Parameters:
866-
** argc, argv -- the usual
867-
**
868-
** Return value:
869-
** EX_USAGE or EX_OK
870-
*/
871-
872-
int
873-
main(int argc, char **argv)
874-
{
875-
int c;
876-
int d;
877-
int status;
878-
char *p;
879-
char *progname;
880-
struct authres ar;
881-
u_char buf[ARC_MAXHEADER + 2];
882-
u_char *toks[ARES_MAXTOKENS];
883-
884-
progname = (p = strrchr(argv[0], '/')) == NULL ? argv[0] : p + 1;
885-
886-
if (argc != 2)
887-
{
888-
printf("%s: usage: %s header-value\n", progname, progname);
889-
return EX_USAGE;
890-
}
891-
892-
c = ares_tokenize(((u_char **) argv)[1], buf, sizeof buf, toks,
893-
ARES_MAXTOKENS);
894-
for (d = 0; d < c; d++)
895-
{
896-
printf("token %d = '%s'\n", d, toks[d]);
897-
}
898-
899-
printf("\n");
900-
901-
status = ares_parse(((u_char **) argv)[1], &ar, NULL);
902-
if (status == -1)
903-
{
904-
printf("%s: ares_parse() returned -1\n", progname);
905-
return EX_OK;
906-
}
907-
908-
printf("%d result%s found\n", ar.ares_count, ar.ares_count == 1 ? "" : "s");
909-
910-
printf("authserv-id '%s'\n", ar.ares_host);
911-
printf("version '%s'\n", ar.ares_version);
912-
913-
for (c = 0; c < ar.ares_count; c++)
914-
{
915-
printf("result #%d, %d propert%s\n", c, ar.ares_result[c].result_props,
916-
ar.ares_result[c].result_props == 1 ? "y" : "ies");
917-
918-
printf("\tmethod \"%s\"\n",
919-
ares_xconvert(methods, ar.ares_result[c].result_method));
920-
printf("\tresult \"%s\"\n",
921-
ares_xconvert(aresults, ar.ares_result[c].result_result));
922-
printf("\treason \"%s\"\n", ar.ares_result[c].result_reason);
923-
printf("\tcomment \"%s\"\n", ar.ares_result[c].result_comment);
924-
925-
for (d = 0; d < ar.ares_result[c].result_props; d++)
926-
{
927-
printf("\tproperty #%d\n", d);
928-
printf("\t\tptype \"%s\"\n",
929-
ares_xconvert(ptypes, ar.ares_result[c].result_ptype[d]));
930-
printf("\t\tproperty \"%s\"\n",
931-
ar.ares_result[c].result_property[d]);
932-
printf("\t\tvalue \"%s\"\n", ar.ares_result[c].result_value[d]);
933-
}
934-
}
935-
}
936-
#endif /* ARTEST */

openarc/openarc-ar.h

+1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ struct authres
9191
struct result ares_result[MAXARESULTS];
9292
};
9393

94+
extern int ares_tokenize(const char *, char *, size_t, char **, int);
9495
extern int ares_parse(const char *, struct authres *, const char *);
9596
extern bool ares_istoken(const char *);
9697

0 commit comments

Comments
 (0)