Back to index

opendkim  2.6.4
t-test143.c
Go to the documentation of this file.
00001 /*
00002 **  Copyright (c) 2005-2008 Sendmail, Inc. and its suppliers.
00003 **    All rights reserved.
00004 **
00005 **  Copyright (c) 2009, 2011, The OpenDKIM Project.  All rights reserved.
00006 */
00007 
00008 #ifndef lint
00009 static char t_test143_c_id[] = "@(#)$Id: t-test04.c,v 1.2 2009/12/08 19:14:27 cm-msk Exp $";
00010 #endif /* !lint */
00011 
00012 #include "build-config.h"
00013 
00014 /* system includes */
00015 #include <sys/types.h>
00016 #include <assert.h>
00017 #include <string.h>
00018 #include <stdio.h>
00019 #include <stdlib.h>
00020 
00021 #ifdef USE_GNUTLS
00022 # include <gnutls/gnutls.h>
00023 #endif /* USE_GNUTLS */
00024 
00025 /* libopendkim includes */
00026 #include "../dkim.h"
00027 #include "t-testdata.h"
00028 
00029 #define       MAXHEADER     4096
00030 
00031 #define SIG2 "v=1; a=rsa-sha1; c=relaxed/relaxed; d=example.com; s=test;\r\n\tt=1172620939; bh=Z9ONHHsBrKN0pbfrOu025VfbdR4=;\r\n\th=Received:Received:Received:From:To:Date:Subject:Message-ID;\r\n\tb=Jf+j2RDZRkpIF1KaL5ByhHFPWj5RMeX5764IVlwIc11equjQND51K9FfL5pyjXvwj\r\n\t FoFPW0PGJb3liej6iDDEHgYpXR4p5qqlGx/C1Q9gf/MQN/Xlkv6ZXgR38QnWAfZxh5\r\n\t N1f5xUg+SJb5yBDoXklG62IRdia1Hq9MuiGumrGM="
00032 
00033 /*
00034 **  MAIN -- program mainline
00035 **
00036 **  Parameters:
00037 **     The usual.
00038 **
00039 **  Return value:
00040 **     Exit status.
00041 */
00042 
00043 int
00044 main(int argc, char **argv)
00045 {
00046 #ifdef TEST_KEEP_FILES
00047        u_int flags;
00048 #endif /* TEST_KEEP_FILES */
00049        u_int nqi;
00050        u_int nsigs;
00051        DKIM_STAT status;
00052        DKIM *dkim;
00053        DKIM_LIB *lib;
00054        dkim_query_t qtype = DKIM_QUERY_FILE;
00055        DKIM_QUERYINFO **qi;
00056        DKIM_SIGINFO **sigs;
00057        unsigned char hdr[MAXHEADER + 1];
00058 
00059        printf("*** test DKIM_QUERYINFO routines\n");
00060 
00061 #ifdef USE_GNUTLS
00062        (void) gnutls_global_init();
00063 #endif /* USE_GNUTLS */
00064 
00065        /* instantiate the library */
00066        lib = dkim_init(NULL, NULL);
00067        assert(lib != NULL);
00068 
00069 #ifdef TEST_KEEP_FILES
00070        /* set flags */
00071        flags = (DKIM_LIBFLAGS_TMPFILES|DKIM_LIBFLAGS_KEEPFILES);
00072        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_FLAGS, &flags,
00073                            sizeof flags);
00074 #endif /* TEST_KEEP_FILES */
00075 
00076        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_QUERYMETHOD,
00077                            &qtype, sizeof qtype);
00078        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_QUERYINFO,
00079                            KEYFILE, strlen(KEYFILE));
00080 
00081        dkim = dkim_verify(lib, JOBID, NULL, &status);
00082        assert(dkim != NULL);
00083 
00084        snprintf(hdr, sizeof hdr, "%s: %s", DKIM_SIGNHEADER, SIG2);
00085        status = dkim_header(dkim, hdr, strlen(hdr));
00086        assert(status == DKIM_STAT_OK);
00087 
00088        status = dkim_header(dkim, HEADER01, strlen(HEADER01));
00089        assert(status == DKIM_STAT_OK);
00090 
00091        status = dkim_header(dkim, HEADER02, strlen(HEADER02));
00092        assert(status == DKIM_STAT_OK);
00093 
00094        status = dkim_header(dkim, HEADER03, strlen(HEADER03));
00095        assert(status == DKIM_STAT_OK);
00096 
00097        status = dkim_header(dkim, HEADER04, strlen(HEADER04));
00098        assert(status == DKIM_STAT_OK);
00099 
00100        status = dkim_header(dkim, HEADER05, strlen(HEADER05));
00101        assert(status == DKIM_STAT_OK);
00102 
00103        status = dkim_header(dkim, HEADER06, strlen(HEADER06));
00104        assert(status == DKIM_STAT_OK);
00105 
00106        status = dkim_header(dkim, HEADER07, strlen(HEADER07));
00107        assert(status == DKIM_STAT_OK);
00108 
00109        status = dkim_header(dkim, HEADER08, strlen(HEADER08));
00110        assert(status == DKIM_STAT_OK);
00111 
00112        status = dkim_header(dkim, HEADER09, strlen(HEADER09));
00113        assert(status == DKIM_STAT_OK);
00114 
00115        status = dkim_eoh(dkim);
00116        assert(status == DKIM_STAT_OK);
00117 
00118        status = dkim_getsiglist(dkim, &sigs, &nsigs);
00119        assert(status == DKIM_STAT_OK);
00120        assert(nsigs == 1);
00121 
00122        status = dkim_sig_getqueries(dkim, sigs[0], &qi, &nqi);
00123        assert(status == DKIM_STAT_OK);
00124        assert(nqi == 1);
00125        assert(strcmp(dkim_qi_getname(qi[0]),
00126                      "test._domainkey.example.com") == 0);
00127        assert(dkim_qi_gettype(qi[0]) == 16);
00128        free(qi[0]);
00129        free(qi);
00130 
00131        status = dkim_policy_getqueries(dkim, &qi, &nqi);
00132        assert(status == DKIM_STAT_OK);
00133        assert(nqi == 4);
00134        assert(strcmp(dkim_qi_getname(qi[0]),
00135                      "sendmail.com") == 0);
00136        assert(strcmp(dkim_qi_getname(qi[1]),
00137                      "sendmail.com") == 0);
00138        assert(strcmp(dkim_qi_getname(qi[2]),
00139                      "sendmail.com") == 0);
00140        assert(strcmp(dkim_qi_getname(qi[3]),
00141                      "_adsp._domainkey.sendmail.com") == 0);
00142        assert(dkim_qi_gettype(qi[0]) == 1);
00143        assert(dkim_qi_gettype(qi[1]) == 28);
00144        assert(dkim_qi_gettype(qi[2]) == 15);
00145        assert(dkim_qi_gettype(qi[3]) == 16);
00146        free(qi[0]);
00147        free(qi[1]);
00148        free(qi[2]);
00149        free(qi[3]);
00150        free(qi);
00151 
00152        status = dkim_free(dkim);
00153        assert(status == DKIM_STAT_OK);
00154 
00155        dkim_close(lib);
00156 
00157        return 0;
00158 }