summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Denker <jsd@av8n.com>2012-08-03 22:03:33 -0700
committerJohn Denker <jsd@av8n.com>2012-12-02 11:55:48 -0700
commitc5a1da0c735c428a53596b31b32aae82a257c3bf (patch)
tree58bde4671ee61ebaef538950866aaa07b8c4f3b0
parent980c3a6b179be04eed463e8e04d22da18d915b48 (diff)
move spf_example here (from ~/hack)
-rw-r--r--tools/makefile7
-rw-r--r--tools/spf_config.h339
-rw-r--r--tools/spf_example.c200
3 files changed, 544 insertions, 2 deletions
diff --git a/tools/makefile b/tools/makefile
index 7d0afbf..8b31fdc 100644
--- a/tools/makefile
+++ b/tools/makefile
@@ -20,8 +20,8 @@ CFLAGS = -std=gnu++0x -Wall -g -I $(HOME)/lib/include
.SECONDARY : # do not remove any intermediate files
# sources for main programs that go in /var/qmail/bin
-qmain = pido.c hi-q.c skrewt.c hi-test.c mail-scan.c \
- greylist.c wripper.c ward.c
+qmain = pido.c hi-q.c skrewt.c hi-test.c mail-scan.c greylist.c \
+ wripper.c spf_example.c ward.c
qprogs = $(qmain:%.c=%)
@@ -46,6 +46,9 @@ beware_other = checkpassword.c spamc.c
all: $(qprogs) $(moreprogs) fixown2 ward
+spf_example : spf_example.o sepofra.o utils.o
+ $(CXX) $^ -lspf2 -o $@
+
show:
: --- $(qprogs) +++ $(moreprogs)
diff --git a/tools/spf_config.h b/tools/spf_config.h
new file mode 100644
index 0000000..d3ec977
--- /dev/null
+++ b/tools/spf_config.h
@@ -0,0 +1,339 @@
+/* config.h. Generated from config.h.in by configure. */
+/* config.h.in. Generated from configure.ac by autoheader. */
+
+/* Define to 1 if you have the <arpa/inet.h> header file. */
+#define HAVE_ARPA_INET_H 1
+
+/* Define to 1 if you have the <arpa/nameser.h> header file. */
+#define HAVE_ARPA_NAMESER_H 1
+
+/* Define to 1 if you have the declaration of `ns_t_invalid', and to 0 if you
+ don't. */
+#define HAVE_DECL_NS_T_INVALID 1
+
+/* Define to 1 if you have the declaration of `ns_t_spf', and to 0 if you
+ don't. */
+#define HAVE_DECL_NS_T_SPF 0
+
+/* Define to 1 if you have the declaration of `res_ndestroy', and to 0 if you
+ don't. */
+#define HAVE_DECL_RES_NDESTROY 0
+
+/* Define to 1 if you have the declaration of `res_ninit', and to 0 if you
+ don't. */
+#define HAVE_DECL_RES_NINIT 1
+
+/* Define to 1 if you have the <dlfcn.h> header file. */
+#define HAVE_DLFCN_H 1
+
+/* Define to 1 if you have the <errno.h> header file. */
+#define HAVE_ERRNO_H 1
+
+/* Define to 1 if you have the <fcntl.h> header file. */
+#define HAVE_FCNTL_H 1
+
+/* Define to 1 if you have the `fork' function. */
+#define HAVE_FORK 1
+
+/* Define to 1 if you have the `ftruncate' function. */
+#define HAVE_FTRUNCATE 1
+
+/* Define to 1 if you have the `gethostbyname' function. */
+#define HAVE_GETHOSTBYNAME 1
+
+/* Define to 1 if you have the `gethostname' function. */
+#define HAVE_GETHOSTNAME 1
+
+/* Define to 1 if you have the <getopt.h> header file. */
+#define HAVE_GETOPT_H 1
+
+/* Define to 1 if you have the `getopt_long_only' function. */
+#define HAVE_GETOPT_LONG_ONLY 1
+
+/* Define to 1 if you have the <grp.h> header file. */
+#define HAVE_GRP_H 1
+
+/* Define to 1 if you have the `inet_ntoa' function. */
+#define HAVE_INET_NTOA 1
+
+/* Define to 1 if you have the <inttypes.h> header file. */
+#define HAVE_INTTYPES_H 1
+
+/* Define to 1 if you have the `intl' library (-lintl). */
+/* #undef HAVE_LIBINTL */
+
+/* Define to 1 if you have the <libintl.h> header file. */
+#define HAVE_LIBINTL_H 1
+
+/* Define to 1 if you have the `nsl' library (-lnsl). */
+#define HAVE_LIBNSL 1
+
+/* Define to 1 if you have the `pthread' library (-lpthread). */
+#define HAVE_LIBPTHREAD 1
+
+/* Define to 1 if you have the `socket' library (-lsocket). */
+/* #undef HAVE_LIBSOCKET */
+
+/* Define to 1 if you have the <limits.h> header file. */
+#define HAVE_LIMITS_H 1
+
+/* Define to 1 if your system has a GNU libc compatible `malloc' function, and
+ to 0 otherwise. */
+#define HAVE_MALLOC 1
+
+/* Define to 1 if you have the <malloc.h> header file. */
+#define HAVE_MALLOC_H 1
+
+/* Define to 1 if you have the `memmove' function. */
+#define HAVE_MEMMOVE 1
+
+/* Define to 1 if you have the <memory.h> header file. */
+#define HAVE_MEMORY_H 1
+
+/* Define to 1 if you have the `memset' function. */
+#define HAVE_MEMSET 1
+
+/* Define to 1 if you have the <netdb.h> header file. */
+#define HAVE_NETDB_H 1
+
+/* Define to 1 if you have the <netinet/in.h> header file. */
+#define HAVE_NETINET_IN_H 1
+
+/* Define to 1 if you have the <nmemory.h> header file. */
+/* #undef HAVE_NMEMORY_H */
+
+/* Define to 1 if the system has the type `ns_type'. */
+#define HAVE_NS_TYPE 1
+
+/* Define to 1 if you have the <pthread.h> header file. */
+#define HAVE_PTHREAD_H 1
+
+/* Define to 1 if you have the <pwd.h> header file. */
+#define HAVE_PWD_H 1
+
+/* Define to 1 if your system has a GNU libc compatible `realloc' function,
+ and to 0 otherwise. */
+#define HAVE_REALLOC 1
+
+/* Define to 1 if you have the <resolv.h> header file. */
+#define HAVE_RESOLV_H 1
+
+/* Define to 1 if you have the `select' function. */
+#define HAVE_SELECT 1
+
+/* Define to 1 if you have the `socket' function. */
+#define HAVE_SOCKET 1
+
+/* Define to 1 if you have the <stdarg.h> header file. */
+#define HAVE_STDARG_H 1
+
+/* Define to 1 if you have the <stddef.h> header file. */
+#define HAVE_STDDEF_H 1
+
+/* Define to 1 if you have the <stdint.h> header file. */
+#define HAVE_STDINT_H 1
+
+/* Define to 1 if you have the <stdlib.h> header file. */
+#define HAVE_STDLIB_H 1
+
+/* Define to 1 if you have the `strcasecmp' function. */
+#define HAVE_STRCASECMP 1
+
+/* Define to 1 if you have the `strchr' function. */
+#define HAVE_STRCHR 1
+
+/* Define to 1 if you have the `strcspn' function. */
+#define HAVE_STRCSPN 1
+
+/* Define to 1 if you have the `strdup' function. */
+#define HAVE_STRDUP 1
+
+/* Define to 1 if you have the `strerror' function. */
+#define HAVE_STRERROR 1
+
+/* Define to 1 if you have the <strings.h> header file. */
+#define HAVE_STRINGS_H 1
+
+/* Define to 1 if you have the <string.h> header file. */
+#define HAVE_STRING_H 1
+
+/* Define to 1 if you have the `strncasecmp' function. */
+#define HAVE_STRNCASECMP 1
+
+/* Define to 1 if you have the `strrchr' function. */
+#define HAVE_STRRCHR 1
+
+/* Define to 1 if you have the `strspn' function. */
+#define HAVE_STRSPN 1
+
+/* Define to 1 if you have the `strstr' function. */
+#define HAVE_STRSTR 1
+
+/* Define to 1 if you have the `strtol' function. */
+#define HAVE_STRTOL 1
+
+/* Define to 1 if you have the `strtoul' function. */
+#define HAVE_STRTOUL 1
+
+/* Define to 1 if the system has the type `struct in6_addr'. */
+#define HAVE_STRUCT_IN6_ADDR 1
+
+/* Define to 1 if you have the <syslog.h> header file. */
+#define HAVE_SYSLOG_H 1
+
+/* Define to 1 if you have the <sys/param.h> header file. */
+#define HAVE_SYS_PARAM_H 1
+
+/* Define to 1 if you have the <sys/select.h> header file. */
+#define HAVE_SYS_SELECT_H 1
+
+/* Define to 1 if you have the <sys/socket.h> header file. */
+#define HAVE_SYS_SOCKET_H 1
+
+/* Define to 1 if you have the <sys/stat.h> header file. */
+#define HAVE_SYS_STAT_H 1
+
+/* Define to 1 if you have the <sys/time.h> header file. */
+#define HAVE_SYS_TIME_H 1
+
+/* Define to 1 if you have the <sys/types.h> header file. */
+#define HAVE_SYS_TYPES_H 1
+
+/* Define to 1 if you have <sys/wait.h> that is POSIX.1 compatible. */
+#define HAVE_SYS_WAIT_H 1
+
+/* Define to 1 if the system has the type `uint16_t'. */
+#define HAVE_UINT16_T 1
+
+/* Define to 1 if the system has the type `uint32_t'. */
+#define HAVE_UINT32_T 1
+
+/* Define to 1 if the system has the type `uint8_t'. */
+#define HAVE_UINT8_T 1
+
+/* Define to 1 if you have the <unistd.h> header file. */
+#define HAVE_UNISTD_H 1
+
+/* Define to 1 if the system has the type `u_char'. */
+#define HAVE_U_CHAR 1
+
+/* Define to 1 if the system has the type `u_int16_t'. */
+#define HAVE_U_INT16_T 1
+
+/* Define to 1 if the system has the type `u_int32_t'. */
+#define HAVE_U_INT32_T 1
+
+/* Define to 1 if the system has the type `u_int8_t'. */
+#define HAVE_U_INT8_T 1
+
+/* Define to 1 if you have the `vfork' function. */
+#define HAVE_VFORK 1
+
+/* Define to 1 if you have the <vfork.h> header file. */
+/* #undef HAVE_VFORK_H */
+
+/* Define to 1 if `fork' works. */
+#define HAVE_WORKING_FORK 1
+
+/* Define to 1 if `vfork' works. */
+#define HAVE_WORKING_VFORK 1
+
+/* Define to 1 if you have the `__ns_get16' function. */
+#define HAVE___NS_GET16 1
+
+/* Define to 1 if you have the `__ns_initparse' function. */
+/* #undef HAVE___NS_INITPARSE */
+
+/* Define to 1 if you have the `__ns_msg_getflag' function. */
+/* #undef HAVE___NS_MSG_GETFLAG */
+
+/* Define to 1 if you have the `__ns_name_uncompress' function. */
+/* #undef HAVE___NS_NAME_UNCOMPRESS */
+
+/* Name of package */
+#define PACKAGE "libspf2"
+
+/* Define to the address where bug reports for this package should be sent. */
+#define PACKAGE_BUGREPORT "libspf2@anarres.org"
+
+/* Define to the full name of this package. */
+#define PACKAGE_NAME "libspf2"
+
+/* Define to the full name and version of this package. */
+#define PACKAGE_STRING "libspf2 1.2.9"
+
+/* Define to the one symbol short name of this package. */
+#define PACKAGE_TARNAME "libspf2"
+
+/* Define to the version of this package. */
+#define PACKAGE_VERSION "1.2.9"
+
+/* Define as the return type of signal handlers (`int' or `void'). */
+#define RETSIGTYPE void
+
+/* Define to the type of arg 1 for `select'. */
+#define SELECT_TYPE_ARG1 int
+
+/* Define to the type of args 2, 3 and 4 for `select'. */
+#define SELECT_TYPE_ARG234 (fd_set *)
+
+/* Define to the type of arg 5 for `select'. */
+#define SELECT_TYPE_ARG5 (struct timeval *)
+
+/* Define to 1 if the `setpgrp' function takes no argument. */
+#define SETPGRP_VOID 1
+
+/* The size of `int', as computed by sizeof. */
+#define SIZEOF_INT 4
+
+/* Define to 1 if you have the ANSI C header files. */
+#define STDC_HEADERS 1
+
+/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */
+#define TIME_WITH_SYS_TIME 1
+
+/* Version number of package */
+#define VERSION "1.2.9"
+
+/* Define to 1 if your processor stores words with the most significant byte
+ first (like Motorola and SPARC, unlike Intel and VAX). */
+/* #undef WORDS_BIGENDIAN */
+
+/* Define to 1 if type `char' is unsigned and you are not using gcc. */
+#ifndef __CHAR_UNSIGNED__
+/* # undef __CHAR_UNSIGNED__ */
+#endif
+
+/* Define to empty if `const' does not conform to ANSI C. */
+/* #undef const */
+
+/* Define to `int' if <sys/types.h> doesn't define. */
+/* #undef gid_t */
+
+/* Define to `__inline__' or `__inline' if that's what the C compiler
+ calls it, or to nothing if 'inline' is not supported under any name. */
+#ifndef __cplusplus
+/* #undef inline */
+#endif
+
+/* Define to rpl_malloc if the replacement function should be used. */
+/* #undef malloc */
+
+/* Define to `int' if <sys/types.h> does not define. */
+/* #undef pid_t */
+
+/* Define to rpl_realloc if the replacement function should be used. */
+/* #undef realloc */
+
+/* Define to `unsigned int' if <sys/types.h> does not define. */
+/* #undef size_t */
+
+/* Define to `int' if <sys/types.h> doesn't define. */
+/* #undef uid_t */
+
+/* Define as `fork' if `vfork' does not work. */
+/* #undef vfork */
+
+/* Define to empty if the keyword `volatile' does not work. Warning: valid
+ code using `volatile' can become incorrect without. Disable with care. */
+/* #undef volatile */
diff --git a/tools/spf_example.c b/tools/spf_example.c
new file mode 100644
index 0000000..30a84d6
--- /dev/null
+++ b/tools/spf_example.c
@@ -0,0 +1,200 @@
+/*
+ * spf_example - An example program for how to use libspf2
+ *
+ */
+
+
+/*
+ * The libspf2 library uses the GNU autoconf system to help make
+ * the library more portable. The config.h file should have the
+ * HAVE_xxx defines that are appropriate for your system. Either use
+ * autconf to create it, or create it by hand.
+ */
+
+#include "utils.h"
+
+# include "spf_config.h" /* jsd: copied from somewhere */
+ /* not quite created by hand, */
+ /* but not now automatic, either */
+
+#ifdef STDC_HEADERS
+# include <stdio.h>
+# include <stdlib.h> /* malloc / free */
+#endif
+
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h> /* types (u_char .. etc..) */
+#endif
+
+#ifdef HAVE_INTTYPES_H
+#include <inttypes.h>
+#endif
+
+#ifdef HAVE_STRING_H
+# include <string.h> /* strstr / strdup */
+#else
+# ifdef HAVE_STRINGS_H
+# include <strings.h> /* strstr / strdup */
+# endif
+#endif
+
+#ifdef HAVE_SYS_SOCKET_H
+# include <sys/socket.h> /* inet_ functions / structs */
+#endif
+#ifdef HAVE_NETINET_IN_H
+# include <netinet/in.h> /* inet_ functions / structs */
+#endif
+#ifdef HAVE_ARPA_INET_H
+# include <arpa/inet.h> /* in_addr struct */
+#endif
+
+#ifdef HAVE_ARPA_NAMESER_H
+# include <arpa/nameser.h> /* DNS HEADER struct */
+#endif
+
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+#ifdef HAVE_GETOPT_H
+#include <getopt.h>
+#endif
+
+/*
+ * libspf2 public include files that are needed for this example
+ * program
+ */
+
+#include <string>
+#include <list>
+#include <iostream>
+#include <sstream>
+#include "sepofra.h"
+
+using namespace std;
+
+/*
+ * usage() just prints out the command line options for this program
+ */
+static void usage()
+{
+ fprintf(
+ stderr,
+ "Usage:\n"
+ " spf_example [options]\n"
+ "\n"
+ "Valid data options are:\n"
+ " -I <IP address> The IP address that is sending email\n"
+ " -F <email address> The email address used as the\n"
+ " envelope MAIL FROM. If no username (local\n"
+ " part) is given, 'postmaster' will be\n"
+ " assumed.\n"
+ " -T <email address> [optional] The email address used as\n"
+ " the envelope RCPT TO email address, for\n"
+ " secondary-MX checking.\n"
+ " -H <domain name> The domain name given on the SMTP HELO\n"
+ " command. This is only needed if the\n"
+ " -F option is not given.\n"
+ " -d increase debug level.\n"
+ " -d5 set debug level to 5.\n"
+ );
+}
+
+
+/*
+ * All the code is in the main routine, but most usages of libspf2
+ * would have the code spread around into various subrotines.
+ */
+
+int main( int argc, char *argv[] )
+{
+ sepofra my_spf;
+ int c;
+ int res = 0;
+
+ string opt_ip;
+ string opt_mailfrom;
+ string opt_helo;
+ string opt_rcpt_to;
+ int opt_debug = 0;
+
+ /*
+ * check the arguments
+ */
+
+ while (1)
+ {
+ c = getopt(argc, argv, "hI:F:H:T:d::" );
+
+ if (c == -1)
+ break;
+
+ switch (c)
+ {
+ case 'h':
+ usage();
+ exit(0);
+ case 'I':
+ opt_ip = trim(optarg);
+ break;
+
+ case 'F':
+ opt_mailfrom = trim(optarg, " \t\r\n<>");
+ break;
+
+ case 'H':
+ opt_helo = trim(optarg, " \t\r\n<>");
+ break;
+
+ case 'T':
+ opt_rcpt_to = optarg;
+ break;
+
+ case 0:
+ case '?':
+ goto helpout;
+ break;
+
+ case 'd':
+ if (optarg == NULL)
+ opt_debug++;
+ else
+ opt_debug = atoi( optarg );
+ break;
+
+ default:
+ fprintf( stderr, "Error: getopt returned character code 0%o ??\n", c);
+ }
+ }
+
+ if (optind != argc) {
+ fprintf(stderr, "extraneous verbiage: '%s'\n", argv[optind]);
+ goto helpout;
+ }
+ if (!opt_ip.length()){
+ fprintf(stderr, "Option -I 'IP.address' is required\n");
+ goto helpout;
+ }
+ if (!opt_helo.length()){
+ fprintf(stderr, "option '-H host.name' is required\n");
+ goto helpout;
+ }
+ if (!opt_mailfrom.length()){
+ fprintf(stderr, "option '-F mail@from' is required\n");
+ goto helpout;
+ }
+
+ try {
+ my_spf.check(opt_ip, opt_helo, opt_mailfrom, opt_rcpt_to, opt_debug);
+ cout << "*** " << my_spf.explain() << endl;
+ } catch (bad_thing foo) {
+ cout << "Caught bad thing: " << foo.what() << endl;
+ }
+ return 0;
+
+helpout:
+ fprintf(stderr, "for help try -h\n");
+ res = 255;
+ return res;
+
+}