Back to index

opendkim  2.6.4
opendkim-testadsp.c
Go to the documentation of this file.
00001 /*
00002 **  Copyright (c) 2007, 2008 Sendmail, Inc. and its suppliers.
00003 **     All rights reserved.
00004 **
00005 **  Copyright (c) 2009, 2010 The OpenDKIM Project.  All rights reserved.
00006 **
00007 **  $Id: opendkim-testadsp.c,v 1.8 2010/06/19 15:29:12 cm-msk Exp $
00008 */
00009 
00010 #ifndef lint
00011 static char opendkim_testadsp_c_id[] = "@(#)$Id: opendkim-testadsp.c,v 1.8 2010/06/19 15:29:12 cm-msk Exp $";
00012 #endif /* !lint */
00013 
00014 /* system includes */
00015 #include <sys/types.h>
00016 #include <sys/stat.h>
00017 #include <stdlib.h>
00018 #include <fcntl.h>
00019 #include <errno.h>
00020 #include <stdio.h>
00021 #include <sysexits.h>
00022 #include <string.h>
00023 
00024 /* libopendkim includes */
00025 #include <dkim.h>
00026 #include <dkim-test.h>
00027 
00028 /* macros */
00029 #define       BUFRSZ        1024
00030 #define STRORNULL(x) ((x) == NULL ? "(null)" : (x))
00031 
00032 /* prototypes */
00033 int usage(void);
00034 
00035 /* globals */
00036 char *progname;
00037 
00038 /*
00039 **  USAGE -- print a usage message
00040 **
00041 **  Parameters:
00042 **     None.
00043 **
00044 **  Return value:
00045 **     EX_CONFIG
00046 */
00047 
00048 int
00049 usage(void)
00050 {
00051        fprintf(stderr, "%s: usage: %s domain [...]\n", progname, progname);
00052 
00053        return EX_CONFIG;
00054 }
00055 
00056 /*
00057 **  MAIN -- program mainline
00058 **
00059 **  Parameters:
00060 **     argc, argv -- the usual
00061 **
00062 **  Return value:
00063 **     Exit status.
00064 */
00065 
00066 int
00067 main(int argc, char **argv)
00068 {
00069        DKIM_STAT status;
00070        int i;
00071        dkim_policy_t pcode;
00072        int presult;
00073        DKIM_LIB *lib;
00074        char *p;
00075        const char *domain = NULL;
00076        char err[BUFRSZ];
00077 
00078        progname = (p = strrchr(argv[0], '/')) == NULL ? argv[0] : p + 1;
00079 
00080        lib = dkim_init(NULL, NULL);
00081        if (lib == NULL)
00082        {
00083               fprintf(stderr, "%s: dkim_init() failed\n", progname);
00084               return EX_OSERR;
00085        }
00086 
00087        if (argc == 1)
00088               return usage();
00089 
00090        for (i = 1; i < argc; i++)
00091        {
00092               domain = argv[i];
00093 
00094               status = dkim_test_adsp(lib, domain, &pcode, &presult,
00095                                       err, sizeof err);
00096 
00097               if (status != DKIM_STAT_OK)
00098               {
00099                      fprintf(stderr, "%s: %s: %s\n", progname, domain, err);
00100               }
00101               else
00102               {
00103                      fprintf(stdout,
00104                              "%s: %s:\n\tpolicy is \"%s\"\n\tpolicy result code is \"%s\"\n",
00105                              progname, domain,
00106                              STRORNULL(dkim_getpolicystr(pcode)),
00107                              STRORNULL(dkim_getpresultstr(presult)));
00108               }
00109        }
00110 
00111        (void) dkim_close(lib);
00112 
00113        return EX_OK;
00114 }