Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/crypto/krb5/src/kdc/rtest.c
34878 views
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
krb5_context ctx;
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(&ctx);
75
if (kret) {
76
com_err(argv[0], kret, "while getting krb5 context");
77
exit(2);
78
}
79
80
ntrans.length = 0;
81
ntrans.data = 0;
82
83
otrans.length = strlen(argv[1]);
84
if (otrans.length)
85
otrans.data = (char *) malloc(otrans.length);
86
else
87
otrans.data = 0;
88
memcpy(otrans.data,argv[1], otrans.length);
89
90
tgs = make_princ(ctx, argv[2], argv[0]);
91
cl = make_princ(ctx, argv[3], argv[0]);
92
sv = make_princ(ctx, argv[4], argv[0]);
93
94
add_to_transited(&otrans,&ntrans,tgs,cl,sv);
95
96
printf("%s\n",ntrans.data);
97
98
/* Free up all memory so we can profile for leaks */
99
if (otrans.data)
100
free(otrans.data);
101
free(ntrans.data);
102
103
krb5_free_principal(ctx, tgs);
104
krb5_free_principal(ctx, cl);
105
krb5_free_principal(ctx, sv);
106
krb5_free_context(ctx);
107
108
exit(0);
109
}
110
111
void krb5_klog_syslog(void) {}
112
kdc_realm_t *
113
find_realm_data(struct server_handle *handle,
114
char *rname, krb5_ui_4 rsize)
115
{
116
return 0;
117
}
118
119