Allow clearpolicy restriction for kadmin addprinc
[krb5.git] / src / kdc / rtest.c
1 /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /* kdc/rtest.c */
3 /*
4  * Copyright 1991 by the Massachusetts Institute of Technology.
5  * All Rights Reserved.
6  *
7  * Export of this software from the United States of America may
8  *   require a specific license from the United States Government.
9  *   It is the responsibility of any person or organization contemplating
10  *   export to obtain such a license before exporting.
11  *
12  * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
13  * distribute this software and its documentation for any purpose and
14  * without fee is hereby granted, provided that the above copyright
15  * notice appear in all copies and that both that copyright notice and
16  * this permission notice appear in supporting documentation, and that
17  * the name of M.I.T. not be used in advertising or publicity pertaining
18  * to distribution of the software without specific, written prior
19  * permission.  Furthermore if you modify this software you must label
20  * your software as modified software and not distribute it in such a
21  * fashion that it might be confused with the original M.I.T. software.
22  * M.I.T. makes no representations about the suitability of
23  * this software for any purpose.  It is provided "as is" without express
24  * or implied warranty.
25  */
26
27 #include "k5-int.h"
28 #include <stdio.h>
29 #include "kdc_util.h"
30 #include "extern.h"
31
32 void krb5_klog_syslog(void);
33
34 static krb5_principal
35 make_princ(krb5_context ctx, const char *str, const char *prog)
36 {
37     krb5_principal ret;
38     char *dat;
39
40     if(!(ret = (krb5_principal) malloc(sizeof(krb5_principal_data)))) {
41         com_err(prog, ENOMEM, "while allocating principal data");
42         exit(3);
43     }
44     memset(ret, 0, sizeof(krb5_principal_data));
45
46     /* We do not include the null... */
47     if(!(dat = (char *) malloc(strlen(str)))) {
48         com_err(prog, ENOMEM, "while allocating principal realm data");
49         exit(3);
50     }
51     memcpy(dat, str, strlen(str));
52     krb5_princ_set_realm_data(ctx, ret, dat);
53     krb5_princ_set_realm_length(ctx, ret, strlen(str));
54
55     return ret;
56 }
57
58 int
59 main(int argc, char **argv)
60 {
61     krb5_data otrans;
62     krb5_data ntrans;
63     krb5_principal tgs, cl, sv;
64     krb5_error_code kret;
65     kdc_realm_t     kdc_realm;
66
67     if (argc < 4) {
68         fprintf(stderr, "not enough args\n");
69         exit(1);
70     }
71
72
73     /* Get a context */
74     kret = krb5int_init_context_kdc(&kdc_realm.realm_context);
75     if (kret) {
76         com_err(argv[0], kret, "while getting krb5 context");
77         exit(2);
78     }
79     /* Needed so kdc_context will work */
80     kdc_active_realm = &kdc_realm;
81
82     ntrans.length = 0;
83     ntrans.data = 0;
84
85     otrans.length = strlen(argv[1]);
86     if (otrans.length)
87         otrans.data = (char *) malloc(otrans.length);
88     else
89         otrans.data = 0;
90     memcpy(otrans.data,argv[1], otrans.length);
91
92     tgs = make_princ(kdc_context, argv[2], argv[0]);
93     cl  = make_princ(kdc_context, argv[3], argv[0]);
94     sv  = make_princ(kdc_context, argv[4], argv[0]);
95
96     add_to_transited(&otrans,&ntrans,tgs,cl,sv);
97
98     printf("%s\n",ntrans.data);
99
100     /* Free up all memory so we can profile for leaks */
101     if (otrans.data)
102         free(otrans.data);
103     free(ntrans.data);
104
105     krb5_free_principal(kdc_realm.realm_context, tgs);
106     krb5_free_principal(kdc_realm.realm_context, cl);
107     krb5_free_principal(kdc_realm.realm_context, sv);
108     krb5_free_context(kdc_realm.realm_context);
109
110     exit(0);
111 }
112
113 void krb5_klog_syslog(void) {}
114 kdc_realm_t *find_realm_data (char *rname, krb5_ui_4 rsize) { return 0; }