xref: /minix3/crypto/external/bsd/heimdal/dist/lib/hdb/test_mkey.c (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc /*	$NetBSD: test_mkey.c,v 1.1.1.2 2014/04/24 12:45:28 pettai Exp $	*/
2ebfedea0SLionel Sambuc 
3ebfedea0SLionel Sambuc 
4ebfedea0SLionel Sambuc #include "hdb_locl.h"
5ebfedea0SLionel Sambuc #include <krb5/getarg.h>
6ebfedea0SLionel Sambuc #include <krb5/base64.h>
7ebfedea0SLionel Sambuc 
8ebfedea0SLionel Sambuc static char *mkey_file;
9ebfedea0SLionel Sambuc static int help_flag;
10ebfedea0SLionel Sambuc static int version_flag;
11ebfedea0SLionel Sambuc 
12ebfedea0SLionel Sambuc struct getargs args[] = {
13ebfedea0SLionel Sambuc     { "mkey-file",	0,      arg_string, &mkey_file },
14ebfedea0SLionel Sambuc     { "help",		'h',	arg_flag,   &help_flag },
15ebfedea0SLionel Sambuc     { "version",	0,	arg_flag,   &version_flag }
16ebfedea0SLionel Sambuc };
17ebfedea0SLionel Sambuc 
18ebfedea0SLionel Sambuc static int num_args = sizeof(args) / sizeof(args[0]);
19ebfedea0SLionel Sambuc 
20ebfedea0SLionel Sambuc int
main(int argc,char ** argv)21ebfedea0SLionel Sambuc main(int argc, char **argv)
22ebfedea0SLionel Sambuc {
23ebfedea0SLionel Sambuc     krb5_context context;
24ebfedea0SLionel Sambuc     int ret, o = 0;
25ebfedea0SLionel Sambuc 
26ebfedea0SLionel Sambuc     setprogname(argv[0]);
27ebfedea0SLionel Sambuc 
28ebfedea0SLionel Sambuc     if(getarg(args, num_args, argc, argv, &o))
29ebfedea0SLionel Sambuc 	krb5_std_usage(1, args, num_args);
30ebfedea0SLionel Sambuc 
31ebfedea0SLionel Sambuc     if(help_flag)
32ebfedea0SLionel Sambuc 	krb5_std_usage(0, args, num_args);
33ebfedea0SLionel Sambuc 
34ebfedea0SLionel Sambuc     if(version_flag){
35ebfedea0SLionel Sambuc 	print_version(NULL);
36ebfedea0SLionel Sambuc 	exit(0);
37ebfedea0SLionel Sambuc     }
38ebfedea0SLionel Sambuc 
39ebfedea0SLionel Sambuc     ret = krb5_init_context(&context);
40ebfedea0SLionel Sambuc     if (ret)
41ebfedea0SLionel Sambuc 	errx(1, "krb5_init_context failed: %d", ret);
42ebfedea0SLionel Sambuc 
43ebfedea0SLionel Sambuc     if (mkey_file) {
44ebfedea0SLionel Sambuc         hdb_master_key mkey;
45ebfedea0SLionel Sambuc 
46ebfedea0SLionel Sambuc 	ret = hdb_read_master_key(context, mkey_file, &mkey);
47ebfedea0SLionel Sambuc 	if (ret)
48ebfedea0SLionel Sambuc 	    krb5_err(context, 1, ret, "failed to read master key %s", mkey_file);
49ebfedea0SLionel Sambuc 
50ebfedea0SLionel Sambuc 	hdb_free_master_key(context, mkey);
51ebfedea0SLionel Sambuc     } else
52ebfedea0SLionel Sambuc       krb5_errx(context, 1, "no command option given");
53ebfedea0SLionel Sambuc 
54ebfedea0SLionel Sambuc     krb5_free_context(context);
55ebfedea0SLionel Sambuc 
56ebfedea0SLionel Sambuc     return 0;
57ebfedea0SLionel Sambuc }
58