Skip to content

Commit

Permalink
Fix ARTEST, make it a real program instead of a hack
Browse files Browse the repository at this point in the history
This might be a useful tool, but hiding it behind a define means it
gets out of sync very easily (which it had.)
  • Loading branch information
flowerysong committed Oct 27, 2024
1 parent 91a64be commit a75d024
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 81 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ All notable changes to this project will be documented in this file.
failure, as required by [RFC 8617 section 4.1.3](https://datatracker.ietf.org/doc/html/rfc8617#section-4.1.3).
- milter - `Authentication-Results` and `ARC-Authentication-Results` include
`header.oldest-pass` when appropriate.
- milter - An `ar-test` program for seeing how `Authentication-Results`
headers are parsed is built without making you jump through weird hoops.

### Fixed
- libopenarc - Seals on failed chains only cover the latest ARC header set,
Expand Down
9 changes: 9 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,15 @@ openarc_openarc_CFLAGS = $(PTHREAD_CFLAGS)
openarc_openarc_CPPFLAGS = -I$(srcdir)/libopenarc -I$(srcdir)/util $(OPENSSL_CFLAGS) $(LIBIDN2_CFLAGS) $(LIBMILTER_CPPFLAGS) $(LIBJANSSON_CFLAGS)
openarc_openarc_LDFLAGS = $(LIBMILTER_LDFLAGS) $(PTHREAD_CFLAGS)
openarc_openarc_LDADD = libopenarc/libopenarc.la $(LIBMILTER_LIBS) $(OPENSSL_LIBS) $(LIBIDN2_LIBS) $(PTHREAD_LIBS) $(LIBJANSSON_LIBS) $(LIBRESOLV)

noinst_PROGRAMS = openarc/ar-test

openarc_ar_test_SOURCES = \
openarc/openarc-ar.c \
openarc/openarc-ar.h \
openarc/ar-test.c

openarc_ar_test_CPPFLAGS = -I$(srcdir)/libopenarc -I$(srcdir)/util
endif

$(DIST_ARCHIVES).sha1: $(DIST_ARCHIVES)
Expand Down
79 changes: 79 additions & 0 deletions openarc/ar-test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
** Copyright (c) 2007-2009 Sendmail, Inc. and its suppliers.
** All rights reserved.
**
** Copyright (c) 2009, 2011-2014, 2016, 2017, The Trusted Domain Project.
** All rights reserved.
*/

#include "build-config.h"

/* system includes */
#include <string.h>
#include <sysexits.h>

/* openarc includes */
#include "openarc-ar.h"

int
main(int argc, char **argv)
{
int c;
int d;
int status;
char *p;
char *progname;
struct authres ar;
char buf[ARC_MAXHEADER + 2];
char *toks[1024];

progname = (p = strrchr(argv[0], '/')) == NULL ? argv[0] : p + 1;

if (argc != 2)
{
printf("%s: usage: %s header-value\n", progname, progname);
return EX_USAGE;
}

c = ares_tokenize(argv[1], buf, sizeof buf, toks, 1024);
for (d = 0; d < c; d++)
{
printf("token %d = '%s'\n", d, toks[d]);
}

printf("\n");

status = ares_parse(argv[1], &ar, NULL);
if (status == -1)
{
printf("%s: ares_parse() returned -1\n", progname);
return EX_OK;
}

printf("%d result%s found\n", ar.ares_count, ar.ares_count == 1 ? "" : "s");

printf("authserv-id '%s'\n", ar.ares_host);
printf("version '%s'\n", ar.ares_version);

for (c = 0; c < ar.ares_count; c++)
{
printf("result #%d, %d propert%s\n", c, ar.ares_result[c].result_props,
ar.ares_result[c].result_props == 1 ? "y" : "ies");

printf("\tmethod \"%s\"\n",
ares_getmethod(ar.ares_result[c].result_method));
printf("\tresult \"%s\"\n",
ares_getresult(ar.ares_result[c].result_result));
printf("\treason \"%s\"\n", ar.ares_result[c].result_reason);

for (d = 0; d < ar.ares_result[c].result_props; d++)
{
printf("\tproperty #%d\n", d);
printf("\t\tptype \"%s\"\n",
ares_getptype(ar.ares_result[c].result_ptype[d]));
printf("\t\tproperty \"%s\"\n",
ar.ares_result[c].result_property[d]);
printf("\t\tvalue \"%s\"\n", ar.ares_result[c].result_value[d]);
}
}
}
82 changes: 1 addition & 81 deletions openarc/openarc-ar.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
#include <string.h>
#include <sys/param.h>
#include <sys/types.h>
#ifdef ARTEST
#include <sysexits.h>
#endif /* ARTEST */

/* libbsd if found */
#ifdef USE_BSD_H
Expand Down Expand Up @@ -126,7 +123,7 @@ enum ar_parser_state
** pointers available.
*/

static int
int
ares_tokenize(const char *input,
char *outbuf,
size_t outbuflen,
Expand Down Expand Up @@ -857,80 +854,3 @@ ares_getptype(ares_ptype ptype)
{
return (const char *) ares_xconvert(ptypes, ptype);
}

#ifdef ARTEST
/*
** MAIN -- program mainline
**
** Parameters:
** argc, argv -- the usual
**
** Return value:
** EX_USAGE or EX_OK
*/

int
main(int argc, char **argv)
{
int c;
int d;
int status;
char *p;
char *progname;
struct authres ar;
u_char buf[ARC_MAXHEADER + 2];
u_char *toks[ARES_MAXTOKENS];

progname = (p = strrchr(argv[0], '/')) == NULL ? argv[0] : p + 1;

if (argc != 2)
{
printf("%s: usage: %s header-value\n", progname, progname);
return EX_USAGE;
}

c = ares_tokenize(((u_char **) argv)[1], buf, sizeof buf, toks,
ARES_MAXTOKENS);
for (d = 0; d < c; d++)
{
printf("token %d = '%s'\n", d, toks[d]);
}

printf("\n");

status = ares_parse(((u_char **) argv)[1], &ar, NULL);
if (status == -1)
{
printf("%s: ares_parse() returned -1\n", progname);
return EX_OK;
}

printf("%d result%s found\n", ar.ares_count, ar.ares_count == 1 ? "" : "s");

printf("authserv-id '%s'\n", ar.ares_host);
printf("version '%s'\n", ar.ares_version);

for (c = 0; c < ar.ares_count; c++)
{
printf("result #%d, %d propert%s\n", c, ar.ares_result[c].result_props,
ar.ares_result[c].result_props == 1 ? "y" : "ies");

printf("\tmethod \"%s\"\n",
ares_xconvert(methods, ar.ares_result[c].result_method));
printf("\tresult \"%s\"\n",
ares_xconvert(aresults, ar.ares_result[c].result_result));
printf("\treason \"%s\"\n", ar.ares_result[c].result_reason);
printf("\tcomment \"%s\"\n", ar.ares_result[c].result_comment);

for (d = 0; d < ar.ares_result[c].result_props; d++)
{
printf("\tproperty #%d\n", d);
printf("\t\tptype \"%s\"\n",
ares_xconvert(ptypes, ar.ares_result[c].result_ptype[d]));
printf("\t\tproperty \"%s\"\n",
ar.ares_result[c].result_property[d]);
printf("\t\tvalue \"%s\"\n", ar.ares_result[c].result_value[d]);
}
}
}
#endif /* ARTEST */
1 change: 1 addition & 0 deletions openarc/openarc-ar.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ struct authres
struct result ares_result[MAXARESULTS];
};

extern int ares_tokenize(const char *, char *, size_t, char **, int);
extern int ares_parse(const char *, struct authres *, const char *);
extern bool ares_istoken(const char *);

Expand Down

0 comments on commit a75d024

Please sign in to comment.