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