From: ian Date: Wed, 16 Mar 2005 21:28:51 +0000 (+0000) Subject: + * New adnsheloex client courtesy of Tony Finch (and copyright notices X-Git-Tag: before-srv-2006-04-04~14 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=adns.git;a=commitdiff_plain;h=849075a00676ad04776f4fe3902e23cc2d8f70a3 + * New adnsheloex client courtesy of Tony Finch (and copyright notices @@ -7,6 +7,8 @@ + * New adnsheloex client courtesy of Tony Finch (and copyright notices + updated). --- diff --git a/INSTALL b/INSTALL index 69f6ded..33a21f6 100644 --- a/INSTALL +++ b/INSTALL @@ -101,8 +101,8 @@ details for adns. It is Copyright (C) 1997-2000 Ian Jackson adns is - Copyright (C) 1997-2000 Ian Jackson - Copyright (C) 1999-2000 Tony Finch [1] + Copyright (C) 1997-2005 Ian Jackson + Copyright (C) 1999-2004 Tony Finch [1] Copyright (C) 1991 Massachusetts Institute of Technology [2] adns is free software; you can redistribute it and/or modify it under @@ -120,8 +120,9 @@ along with adns as the file COPYING; if not, email me at the address above or write to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -[1] Tony Finch holds the original copyright on client/adnslogres.c and - client/fanftest.c, and some modifications to those files. +[1] Tony Finch holds the original copyright on client/adnslogres.c, + client/adnsheloex.c and client/fanftest.c, and some modifications + to those files. [2] MIT hold the original copyright on the included install-sh, which came via GNU autoconf. diff --git a/LICENCE.WAIVERS b/LICENCE.WAIVERS index e13275f..5e7ee68 100644 --- a/LICENCE.WAIVERS +++ b/LICENCE.WAIVERS @@ -10,11 +10,11 @@ IMPORTANT NOTES --------------- * Not all of the code in adns was written by me. The programs - `fanftest' and `adnslogres' are (partially) copyright Tony Finch - and to that extent are not covered by the waivers. I believe - but - do not warrant - that the rest of adns is (at the time of writing, - 4th May 2004) entirely my work, but please check the copyright - notices on the individual files. + `fanftest', `adnslogres' and `adnsheloex' are (partially) copyright + Tony Finch and to that extent are not covered by the waivers. I + believe - but do not warrant - that the rest of adns is (at the + time of writing, 16th of March 2005) entirely my work, but please + check the copyright notices on the individual files. * These waivers apply only in the specified circumstances. diff --git a/Makefile.in b/Makefile.in index 18cf2fe..4ce3657 100644 --- a/Makefile.in +++ b/Makefile.in @@ -4,8 +4,8 @@ # Copyright (C) 1997-2000 Ian Jackson # # It is part of adns, which is -# Copyright (C) 1997-2000 Ian Jackson -# Copyright (C) 1999-2000 Tony Finch +# Copyright (C) 1997-2005 Ian Jackson +# Copyright (C) 1999-2004 Tony Finch # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/README b/README index aa31b0e..5711a58 100644 --- a/README +++ b/README @@ -130,7 +130,7 @@ References and related projects Copyright and licensing - adns is Copyright 1997-2001 Ian Jackson, Copyright 1999-2000 Tony + adns is Copyright 1997-2005 Ian Jackson, Copyright 1999-2004 Tony Finch, and Copyright (C) 1991 Massachusetts Institute of Technology. adns is free software; you can redistribute it and/or modify it under @@ -154,7 +154,7 @@ Copyright and licensing [23]GNU home page; [24]chiark home page; [25]site or mirror home page - This web page is Copyright (C)1996-2001 Ian Jackson. See the + This web page is Copyright (C)1996-2005 Ian Jackson. See the [26]Copyright/acknowledgements. Use any browser - [27]Campaign for a non-browser-specific WWW diff --git a/README.html b/README.html index fe0461d..3f6ab52 100644 --- a/README.html +++ b/README.html @@ -200,8 +200,8 @@ C++ by Jarle Aase.

Copyright and licensing

-adns is Copyright 1997-2001 Ian Jackson, Copyright -1999-2000 Tony Finch, and Copyright (C) 1991 Massachusetts Institute +adns is Copyright 1997-2005 Ian Jackson, Copyright +1999-2004 Tony Finch, and Copyright (C) 1991 Massachusetts Institute of Technology.

@@ -243,7 +243,7 @@ software by me. site or mirror home page

-This web page is Copyright (C)1996-2001 Ian Jackson. See the +This web page is Copyright (C)1996-2005 Ian Jackson. See the Copyright/acknowledgements.

diff --git a/acconfig.h b/acconfig.h index 1d0e671..9e42673 100644 --- a/acconfig.h +++ b/acconfig.h @@ -7,8 +7,8 @@ * Copyright (C) 1997-2000 Ian Jackson * * It is part of adns, which is - * Copyright (C) 1997-2000 Ian Jackson - * Copyright (C) 1999-2000 Tony Finch + * Copyright (C) 1997-2005 Ian Jackson + * Copyright (C) 1999-2004 Tony Finch * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/aclocal.m4 b/aclocal.m4 index 6c4099e..cb6e922 100644 --- a/aclocal.m4 +++ b/aclocal.m4 @@ -4,8 +4,8 @@ # Copyright (C) 1997-1999 Ian Jackson # # It is part of adns, which is -# Copyright (C) 1997-1999 Ian Jackson -# Copyright (C) 1999-2000 Tony Finch +# Copyright (C) 1997-2005 Ian Jackson +# Copyright (C) 1999-2004 Tony Finch # # This file is part of adns, which is Copyright (C) 1997-1999 Ian Jackson # diff --git a/changelog b/changelog index b36b68f..5f6085c 100644 --- a/changelog +++ b/changelog @@ -7,6 +7,8 @@ adns (1.2); urgency=medium * Added a TODO list item. * Add .PHONY: install to Makefile, to help people with demented fs's. * Darwin listed in INSTALL. + * New adnsheloex client courtesy of Tony Finch (and copyright notices + updated). -- diff --git a/client/.cvsignore b/client/.cvsignore index 45bcf1e..dc16cfb 100644 --- a/client/.cvsignore +++ b/client/.cvsignore @@ -3,6 +3,8 @@ adnstest adnstest_s adnslogres adnslogres_s +adnsheloex +adnsheloex_s adnshost adnshost_s adnsresfilter diff --git a/client/Makefile.in b/client/Makefile.in index 59a3582..462ca57 100644 --- a/client/Makefile.in +++ b/client/Makefile.in @@ -27,7 +27,7 @@ VPATH= @srcdir@ PROGS_SYSDEP= @PROGS_HAVE_TSEARCH@ ENABLE_DYNAMIC= @ENABLE_DYNAMIC@ -PROGRAMS= adnslogres adnshost $(PROGS_SYSDEP) +PROGRAMS= adnslogres adnsheloex adnshost $(PROGS_SYSDEP) PROGRAMS_LOCAL= fanftest adnstest PROGRAMS_ALL= $(PROGRAMS) $(PROGRAMS_LOCAL) diff --git a/client/adnsheloex.c b/client/adnsheloex.c new file mode 100644 index 0000000..6fff9a3 --- /dev/null +++ b/client/adnsheloex.c @@ -0,0 +1,301 @@ +/* + * adnsheloex.c + * - look up the A record of hosts in an Exim log that failed HELO verification + */ +/* + * This file is + * Copyright (C) 2004 Tony Finch + * + * It is part of adns, which is + * Copyright (C) 1997-2000 Ian Jackson + * Copyright (C) 1999-2004 Tony Finch + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * This file is by Tony Finch, based on adnslogres.c. + */ + +static const char * const cvsid = + "$Id$"; + +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "config.h" +#include "adns.h" +#include "client.h" + +#ifdef ADNS_REGRESS_TEST +# include "hredirect.h" +#endif + +/* maximum number of concurrent DNS queries */ +#define MAXMAXPENDING 64000 +#define DEFMAXPENDING 2000 + +/* maximum length of a line */ +#define MAXLINE 1024 + +/* option flags */ +#define OPT_DEBUG 1 +#define OPT_POLL 2 + +static const char *const progname= "adnsheloex"; +static const char *config_text; + +#define guard_null(str) ((str) ? (str) : "") + +#define sensible_ctype(type,ch) (type((unsigned char)(ch))) + /* isfoo() functions from ctype.h can't safely be fed char - blech ! */ + +static void msg(const char *fmt, ...) { + va_list al; + + fprintf(stderr, "%s: ", progname); + va_start(al,fmt); + vfprintf(stderr, fmt, al); + va_end(al); + fputc('\n',stderr); +} + +static void aargh(const char *cause) { + const char *why = strerror(errno); + if (!why) why = "Unknown error"; + msg("%s: %s (%d)", cause, why, errno); + exit(1); +} + +typedef struct logline { + struct logline *next; + char *start, *name, *rest, *addr; + adns_query query; +} logline; + +static logline *readline(FILE *inf, adns_state adns, int opts) { + static char buf[MAXLINE]; + char *str, *p, *q, *r; + logline *line; + + if (fgets(buf, MAXLINE, inf)) { + str= malloc(sizeof(*line) + strlen(buf) + 1); + if (!str) aargh("malloc"); + line= (logline*)str; + line->next= NULL; + line->start= str+sizeof(logline); + strcpy(line->start, buf); + line->name= line->rest= line->addr= NULL; + /* look for unverifiable HELO information matching the regex + H=[a-z0-9.- ]*[(][a-z0-9.-]*[)] [[][0-9.]*[]] */ + for (p= strchr(line->start, ' '); p; p= strchr(p+1, ' ')) { + if (!strncmp(p, " H=", 3)) { + r= strchr(p, '['); + if (!r) break; + q= strchr(p, ')'); + if (!q || q>r) break; + p= strchr(p, '('); + if (!p || p>q) break; + line->name= p+1; + line->rest= q; + line->addr= r+1; + break; + } + } + if (line->name) { + *line->rest= '\0'; + if (opts & OPT_DEBUG) + msg("submitting %s", line->name); + if (adns_submit(adns, line->name, adns_r_a, + adns_qf_quoteok_query|adns_qf_quoteok_cname|adns_qf_cname_loose, + NULL, &line->query)) + aargh("adns_submit"); + *line->rest= ')'; + } else { + if (opts & OPT_DEBUG) + msg("no query"); + line->query= NULL; + } + return line; + } + if (!feof(inf)) + aargh("fgets"); + return NULL; +} + +static void proclog(FILE *inf, FILE *outf, int maxpending, int opts) { + int eof, err, len; + adns_state adns; + adns_answer *answer; + logline *head, *tail, *line; + adns_initflags initflags; + + initflags= (opts & OPT_DEBUG) ? adns_if_debug : 0; + if (config_text) { + errno= adns_init_strcfg(&adns, initflags, stderr, config_text); + } else { + errno= adns_init(&adns, initflags, 0); + } + if (errno) aargh("adns_init"); + head= tail= readline(inf, adns, opts); + len= 1; eof= 0; + while (head) { + while (head) { + if (head->query) { + if (opts & OPT_DEBUG) + msg("%d in queue; checking %.*s", len, + head->rest-head->name, guard_null(head->name)); + if (eof || len >= maxpending) { + if (opts & OPT_POLL) + err= adns_wait_poll(adns, &head->query, &answer, NULL); + else + err= adns_wait(adns, &head->query, &answer, NULL); + } else { + err= adns_check(adns, &head->query, &answer, NULL); + } + if (err == EAGAIN) break; + if (err) { + fprintf(stderr, "%s: adns_wait/check: %s", progname, strerror(err)); + exit(1); + } + if (answer->status == adns_s_ok) { + const char *addr; + int ok = 0; + fprintf(outf, "%.*s", head->rest-head->start, head->start); + while(answer->nrrs--) { + addr= inet_ntoa(answer->rrs.inaddr[answer->nrrs]); + ok |= !strncmp(addr, head->addr, strlen(addr)); + fprintf(outf, " [%s]", addr); + } + fprintf(outf, "%s%s", ok ? " OK" : "", head->rest); + } else { + if (opts & OPT_DEBUG) + msg("query failed"); + fputs(head->start, outf); + } + free(answer); + len--; + } else { + if (opts & OPT_DEBUG) + msg("%d in queue; no query on this line", len); + fputs(head->start, outf); + } + line= head; head= head->next; + free(line); + } + if (!eof) { + line= readline(inf, adns, opts); + if (line) { + if (!head) head= line; + else tail->next= line; + tail= line; + if (line->query) len++; + } else { + eof= 1; + } + } + } + adns_finish(adns); +} + +static void printhelp(FILE *file) { + fputs("usage: adnsheloex [] []\n" + " adnsheloex --version|--help\n" + "options: -c set max number of outstanding queries\n" + " -p use poll(2) instead of select(2)\n" + " -d turn on debugging\n" + " -C use instead of contents of resolv.conf\n", + stdout); +} + +static void usage(void) { + printhelp(stderr); + exit(1); +} + +int main(int argc, char *argv[]) { + int c, opts, maxpending; + extern char *optarg; + FILE *inf; + + if (argv[1] && !strncmp(argv[1],"--",2)) { + if (!strcmp(argv[1],"--help")) { + printhelp(stdout); + } else if (!strcmp(argv[1],"--version")) { + fputs(VERSION_MESSAGE("adnsheloex"),stdout); + } else { + usage(); + } + if (ferror(stdout) || fclose(stdout)) { perror("stdout"); exit(1); } + exit(0); + } + + maxpending= DEFMAXPENDING; + opts= 0; + while ((c= getopt(argc, argv, "c:C:dp")) != -1) + switch (c) { + case 'c': + maxpending= atoi(optarg); + if (maxpending < 1 || maxpending > MAXMAXPENDING) { + fprintf(stderr, "%s: unfeasible concurrency %d\n", progname, maxpending); + exit(1); + } + break; + case 'C': + config_text= optarg; + break; + case 'd': + opts|= OPT_DEBUG; + break; + case 'p': + opts|= OPT_POLL; + break; + default: + usage(); + } + + argc-= optind; + argv+= optind; + + inf= NULL; + if (argc == 0) + inf= stdin; + else if (argc == 1) + inf= fopen(*argv, "r"); + else + usage(); + + if (!inf) + aargh("couldn't open input"); + + proclog(inf, stdout, maxpending, opts); + + if (fclose(inf)) + aargh("fclose input"); + if (fclose(stdout)) + aargh("fclose output"); + + return 0; +} diff --git a/configure.in b/configure.in index 096396d..b214040 100644 --- a/configure.in +++ b/configure.in @@ -4,8 +4,8 @@ # Copyright (C) 1997-2000 Ian Jackson # # It is part of adns, which is -# Copyright (C) 1997-2000 Ian Jackson -# Copyright (C) 1999-2000 Tony Finch +# Copyright (C) 1997-2005 Ian Jackson +# Copyright (C) 1999-2004 Tony Finch # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/settings.make.in b/settings.make.in index cfb44e0..3714d78 100644 --- a/settings.make.in +++ b/settings.make.in @@ -5,8 +5,8 @@ # Copyright (C) 1997-2000 Ian Jackson # # It is part of adns, which is -# Copyright (C) 1997-2000 Ian Jackson -# Copyright (C) 1999-2000 Tony Finch +# Copyright (C) 1997-2005 Ian Jackson +# Copyright (C) 1999-2004 Tony Finch # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by