Back to index

opendkim  2.6.6
t-test117.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_test117_c_id[] = "@(#)$Id: t-test117.c,v 1.3 2010/07/23 01:54:29 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-internal.h"
00027 #include "t-testdata.h"
00028 
00029 #define       MAXHEADER     4096
00030 
00031 #define SIG2 "v=1; a=rsa-sha1; c=relaxed/simple; d=example.com; s=test;\r\n\tt=1172620939; bh=ll/0h2aWgG+D3ewmE4Y3pY7Ukz8=; h=Received:Received:\r\n\t Received:From:To:Date:Subject:Message-ID; b=bj9kVUbnBYfe9sVzH9lT45\r\n\tTFKO3eQnDbXLfgmgu/b5QgxcnhT9ojnV2IAM4KUO8+hOo5sDEu5Co/0GASH0vHpSV4P\r\n\t377Iwew3FxvLpHsVbVKgXzoKD4QSbHRpWNxyL6LypaaqFa96YqjXuYXr0vpb88hticn\r\n\t6I16//WThMz8fMU="
00032 
00033 char *senderhdrs[] =
00034 {
00035        "from",
00036        "sender",
00037        NULL
00038 };
00039 
00040 /*
00041 **  MAIN -- program mainline
00042 **
00043 **  Parameters:
00044 **     The usual.
00045 **
00046 **  Return value:
00047 **     Exit status.
00048 */
00049 
00050 int
00051 main(int argc, char **argv)
00052 {
00053 #ifdef TEST_KEEP_FILES
00054        u_int flags;
00055 #endif /* TEST_KEEP_FILES */
00056        u_int test_uint;
00057        u_int timeout;
00058        uint64_t fixed_time;
00059        uint64_t test_time;
00060        DKIM_STAT status;
00061        DKIM *dkim;
00062        DKIM_LIB *lib;
00063        char **testarray;
00064        dkim_query_t qtype = DKIM_QUERY_FILE;
00065        unsigned char hdr[MAXHEADER + 1];
00066        char path[MAXPATHLEN + 1];
00067        char *td = NULL;
00068 
00069        printf("*** general utility functions\n");
00070 
00071 #ifdef USE_GNUTLS
00072        (void) gnutls_global_init();
00073 #endif /* USE_GNUTLS */
00074 
00075        /* instantiate the library */
00076        lib = dkim_init(NULL, NULL);
00077        assert(lib != NULL);
00078 
00079 #ifdef TEST_KEEP_FILES
00080        /* set flags */
00081        flags = (DKIM_LIBFLAGS_TMPFILES|DKIM_LIBFLAGS_KEEPFILES);
00082        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_FLAGS, &flags,
00083                            sizeof flags);
00084 #endif /* TEST_KEEP_FILES */
00085 
00086        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_QUERYMETHOD,
00087                            &qtype, sizeof qtype);
00088        (void) dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_QUERYINFO,
00089                            KEYFILE, strlen(KEYFILE));
00090 
00091        /* exercise some dkim_options() stuff */
00092        status = dkim_options(lib, DKIM_OP_GETOPT, DKIM_OPTS_TMPDIR,
00093                              path, sizeof path);
00094        assert(status == DKIM_STAT_OK);
00095        td = getenv("DKIM_TMPDIR");
00096        if (td == NULL || td[0] == '\0')
00097               td = DEFTMPDIR;
00098        assert(strcmp(path, td) == 0);
00099 
00100        fixed_time = 1172620939;
00101        status = dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_FIXEDTIME,
00102                              &fixed_time, sizeof fixed_time);
00103        assert(status == DKIM_STAT_OK);
00104        status = dkim_options(lib, DKIM_OP_GETOPT, DKIM_OPTS_FIXEDTIME,
00105                              &test_time, sizeof test_time);
00106        assert(status == DKIM_STAT_OK);
00107        assert(test_time == fixed_time);
00108 
00109        fixed_time = 300;
00110        status = dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_SIGNATURETTL,
00111                              &fixed_time, sizeof fixed_time);
00112        assert(status == DKIM_STAT_OK);
00113        status = dkim_options(lib, DKIM_OP_GETOPT, DKIM_OPTS_SIGNATURETTL,
00114                              &test_time, sizeof test_time);
00115        assert(status == DKIM_STAT_OK);
00116        assert(test_time == fixed_time);
00117 
00118        fixed_time = 600;
00119        status = dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_CLOCKDRIFT,
00120                              &fixed_time, sizeof fixed_time);
00121        assert(status == DKIM_STAT_OK);
00122        status = dkim_options(lib, DKIM_OP_GETOPT, DKIM_OPTS_CLOCKDRIFT,
00123                              &test_time, sizeof test_time);
00124        assert(status == DKIM_STAT_OK);
00125        assert(test_time == fixed_time);
00126 
00127        timeout = 5;
00128        status = dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_TIMEOUT,
00129                              &timeout, sizeof timeout);
00130        assert(status == DKIM_STAT_OK);
00131        status = dkim_options(lib, DKIM_OP_GETOPT, DKIM_OPTS_TIMEOUT,
00132                              &test_uint, sizeof test_uint);
00133        assert(status == DKIM_STAT_OK);
00134        assert(test_uint == timeout);
00135 
00136        status = dkim_options(lib, DKIM_OP_SETOPT, DKIM_OPTS_SENDERHDRS,
00137                              senderhdrs, sizeof (char **));
00138        assert(status == DKIM_STAT_OK);
00139        status = dkim_options(lib, DKIM_OP_GETOPT, DKIM_OPTS_SENDERHDRS,
00140                              &testarray, sizeof (char **));
00141        assert(status == DKIM_STAT_OK);
00142        assert(strcmp(testarray[0], senderhdrs[0]) == 0);
00143        assert(strcmp(testarray[1], senderhdrs[1]) == 0);
00144        assert(testarray[2] == NULL);
00145 
00146        dkim = dkim_verify(lib, JOBID, NULL, &status);
00147        assert(dkim != NULL);
00148 
00149        snprintf(hdr, sizeof hdr, "%s: %s", DKIM_SIGNHEADER, SIG2);
00150        status = dkim_header(dkim, hdr, strlen(hdr));
00151        assert(status == DKIM_STAT_OK);
00152 
00153        status = dkim_header(dkim, HEADER01, strlen(HEADER01));
00154        assert(status == DKIM_STAT_OK);
00155 
00156        status = dkim_header(dkim, HEADER02, strlen(HEADER02));
00157        assert(status == DKIM_STAT_OK);
00158 
00159        status = dkim_header(dkim, HEADER03, strlen(HEADER03));
00160        assert(status == DKIM_STAT_OK);
00161 
00162        status = dkim_header(dkim, HEADER04, strlen(HEADER04));
00163        assert(status == DKIM_STAT_OK);
00164 
00165        status = dkim_header(dkim, HEADER05, strlen(HEADER05));
00166        assert(status == DKIM_STAT_OK);
00167 
00168        status = dkim_header(dkim, HEADER06, strlen(HEADER06));
00169        assert(status == DKIM_STAT_OK);
00170 
00171        status = dkim_header(dkim, HEADER07, strlen(HEADER07));
00172        assert(status == DKIM_STAT_OK);
00173 
00174        status = dkim_header(dkim, HEADER08, strlen(HEADER08));
00175        assert(status == DKIM_STAT_OK);
00176 
00177        status = dkim_header(dkim, HEADER09, strlen(HEADER09));
00178        assert(status == DKIM_STAT_OK);
00179 
00180        status = dkim_eoh(dkim);
00181        assert(status == DKIM_STAT_OK);
00182 
00183        status = dkim_body(dkim, BODY00, strlen(BODY00));
00184        assert(status == DKIM_STAT_OK);
00185 
00186        status = dkim_body(dkim, BODY01, strlen(BODY01));
00187        assert(status == DKIM_STAT_OK);
00188 
00189        status = dkim_body(dkim, BODY01A, strlen(BODY01A));
00190        assert(status == DKIM_STAT_OK);
00191        status = dkim_body(dkim, BODY01B, strlen(BODY01B));
00192        assert(status == DKIM_STAT_OK);
00193        status = dkim_body(dkim, BODY01C, strlen(BODY01C));
00194        assert(status == DKIM_STAT_OK);
00195        status = dkim_body(dkim, BODY01D, strlen(BODY01D));
00196        assert(status == DKIM_STAT_OK);
00197        status = dkim_body(dkim, BODY01E, strlen(BODY01E));
00198        assert(status == DKIM_STAT_OK);
00199 
00200        status = dkim_body(dkim, BODY02, strlen(BODY02));
00201        assert(status == DKIM_STAT_OK);
00202 
00203        status = dkim_body(dkim, BODY03, strlen(BODY03));
00204        assert(status == DKIM_STAT_OK);
00205 
00206        status = dkim_body(dkim, BODY04, strlen(BODY04));
00207        assert(status == DKIM_STAT_OK);
00208 
00209        status = dkim_body(dkim, BODY03, strlen(BODY03));
00210        assert(status == DKIM_STAT_OK);
00211 
00212        status = dkim_body(dkim, BODY03, strlen(BODY03));
00213        assert(status == DKIM_STAT_OK);
00214 
00215        status = dkim_body(dkim, BODY05, strlen(BODY05));
00216        assert(status == DKIM_STAT_OK);
00217 
00218        status = dkim_body(dkim, BODY03, strlen(BODY03));
00219        assert(status == DKIM_STAT_OK);
00220 
00221        status = dkim_body(dkim, BODY03, strlen(BODY03));
00222        assert(status == DKIM_STAT_OK);
00223 
00224        status = dkim_eom(dkim, NULL);
00225        assert(status == DKIM_STAT_OK);
00226 
00227        assert(dkim_getmode(dkim) == DKIM_MODE_VERIFY);
00228        assert(strcmp(dkim_getuser(dkim), USER) == 0);
00229        assert(strcmp(dkim_getdomain(dkim), DOMAIN2) == 0);
00230        assert(dkim_geterror(dkim) == NULL);
00231 
00232        status = dkim_free(dkim);
00233        assert(status == DKIM_STAT_OK);
00234 
00235        dkim_close(lib);
00236 
00237        return 0;
00238 }