xref: /netbsd-src/crypto/external/bsd/heimdal/dist/lib/hdb/test_hdbplugin.c (revision d3273b5b76f5afaafe308cead5511dbb8df8c5e9)
1*d3273b5bSchristos /*	$NetBSD: test_hdbplugin.c,v 1.2 2017/01/28 21:31:48 christos Exp $	*/
2b9d004c6Schristos 
3b9d004c6Schristos /*
4b9d004c6Schristos  * Copyright (c) 2013 Jeffrey Clark
5b9d004c6Schristos  * All rights reserved.
6b9d004c6Schristos  *
7b9d004c6Schristos  * Redistribution and use in source and binary forms, with or without
8b9d004c6Schristos  * modification, are permitted provided that the following conditions
9b9d004c6Schristos  * are met:
10b9d004c6Schristos  *
11b9d004c6Schristos  * 1. Redistributions of source code must retain the above copyright
12b9d004c6Schristos  *    notice, this list of conditions and the following disclaimer.
13b9d004c6Schristos  *
14b9d004c6Schristos  * 2. Redistributions in binary form must reproduce the above copyright
15b9d004c6Schristos  *    notice, this list of conditions and the following disclaimer in the
16b9d004c6Schristos  *    documentation and/or other materials provided with the distribution.
17b9d004c6Schristos  *
18b9d004c6Schristos  * 3. Neither the name of the Institute nor the names of its contributors
19b9d004c6Schristos  *    may be used to endorse or promote products derived from this software
20b9d004c6Schristos  *    without specific prior written permission.
21b9d004c6Schristos  *
22b9d004c6Schristos  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
23b9d004c6Schristos  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24b9d004c6Schristos  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25b9d004c6Schristos  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
26b9d004c6Schristos  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27b9d004c6Schristos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28b9d004c6Schristos  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29b9d004c6Schristos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30b9d004c6Schristos  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31b9d004c6Schristos  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32b9d004c6Schristos  * SUCH DAMAGE.
33b9d004c6Schristos  */
34b9d004c6Schristos 
35b9d004c6Schristos #include "hdb_locl.h"
36b9d004c6Schristos 
37b9d004c6Schristos struct hdb_called {
38b9d004c6Schristos     int create;
39b9d004c6Schristos     int init;
40b9d004c6Schristos     int fini;
41b9d004c6Schristos };
42b9d004c6Schristos struct hdb_called testresult;
43b9d004c6Schristos 
44b9d004c6Schristos static krb5_error_code
hdb_test_create(krb5_context context,struct HDB ** db,const char * arg)45b9d004c6Schristos hdb_test_create(krb5_context context, struct HDB **db, const char *arg)
46b9d004c6Schristos {
47b9d004c6Schristos 	testresult.create = 1;
48b9d004c6Schristos 	return 0;
49b9d004c6Schristos }
50b9d004c6Schristos 
51b9d004c6Schristos static krb5_error_code
hdb_test_init(krb5_context context,void ** ctx)52b9d004c6Schristos hdb_test_init(krb5_context context, void **ctx)
53b9d004c6Schristos {
54b9d004c6Schristos 	*ctx = NULL;
55b9d004c6Schristos 	testresult.init = 1;
56b9d004c6Schristos 	return 0;
57b9d004c6Schristos }
58b9d004c6Schristos 
hdb_test_fini(void * ctx)59b9d004c6Schristos static void hdb_test_fini(void *ctx)
60b9d004c6Schristos {
61b9d004c6Schristos 	testresult.fini = 1;
62b9d004c6Schristos }
63b9d004c6Schristos 
64b9d004c6Schristos struct hdb_method hdb_test =
65b9d004c6Schristos {
66b9d004c6Schristos #ifdef WIN32
67b9d004c6Schristos 	/* Not c99 */
68b9d004c6Schristos 	HDB_INTERFACE_VERSION,
69b9d004c6Schristos 	hdb_test_init,
70b9d004c6Schristos 	hdb_test_fini,
71b9d004c6Schristos 	"test",
72b9d004c6Schristos 	hdb_test_create
73b9d004c6Schristos #else
74b9d004c6Schristos 	.version = HDB_INTERFACE_VERSION,
75b9d004c6Schristos 	.init = hdb_test_init,
76b9d004c6Schristos 	.fini = hdb_test_fini,
77b9d004c6Schristos 	.prefix = "test",
78b9d004c6Schristos 	.create = hdb_test_create
79b9d004c6Schristos #endif
80b9d004c6Schristos };
81b9d004c6Schristos 
82b9d004c6Schristos int
main(int argc,char ** argv)83b9d004c6Schristos main(int argc, char **argv)
84b9d004c6Schristos {
85b9d004c6Schristos     krb5_error_code ret;
86b9d004c6Schristos     krb5_context context;
87b9d004c6Schristos     HDB *db;
88b9d004c6Schristos 
89b9d004c6Schristos     setprogname(argv[0]);
90b9d004c6Schristos 
91b9d004c6Schristos     ret = krb5_init_context(&context);
92b9d004c6Schristos     if (ret)
93b9d004c6Schristos 	errx(1, "krb5_init_contex");
94b9d004c6Schristos 
95b9d004c6Schristos     ret = krb5_plugin_register(context,
96b9d004c6Schristos 		    PLUGIN_TYPE_DATA, "hdb_test_interface",
97b9d004c6Schristos 		    &hdb_test);
98b9d004c6Schristos     if(ret) {
99b9d004c6Schristos 	    krb5_err(context, 1, ret, "krb5_plugin_register");
100b9d004c6Schristos     }
101b9d004c6Schristos 
102b9d004c6Schristos     ret = hdb_create(context, &db, "test:test&1234");
103b9d004c6Schristos     if(ret) {
104b9d004c6Schristos 	    krb5_err(context, 1, ret, "hdb_create");
105b9d004c6Schristos     }
106b9d004c6Schristos 
107b9d004c6Schristos     krb5_free_context(context);
108b9d004c6Schristos     return 0;
109b9d004c6Schristos }
110