1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
/*
* $Source$
* $Author$
*
* Copyright 1990 by the Massachusetts Institute of Technology.
*
* For copying and distribution information, please see the file
* <krb5/copyright.h>.
*
* encoding glue routines.
*/
#if !defined(lint) && !defined(SABER)
static char rcsid_encode_c[] =
"$Id$";
#endif /* lint || saber */
#include <krb5/copyright.h>
#include <isode/psap.h>
#include "KRB5-types.h"
#include <krb5/krb5.h>
#include "encode.h"
#include "asn1defs.h"
#include <krb5/ext-proto.h>
#include <stdio.h>
krb5_error_code
krb5_encode_generic(input, data_out, encoder, translator, free_translation)
const krb5_pointer input;
register krb5_data **data_out;
int (*encoder) PROTOTYPE((PE *, int, int, char *, krb5_pointer));
krb5_pointer (*translator) PROTOTYPE((krb5_pointer, int * ));
void (*free_translation) PROTOTYPE((krb5_pointer ));
{
krb5_pointer isode_out;
PE pe;
PS ps;
char encode_buf[BUFSIZ];
krb5_error_code error;
if (!(isode_out = (*translator)(input, &error)))
return(error);
if (!(ps = ps_alloc(str_open))) {
free_translation(isode_out);
return(ENOMEM);
}
if (str_setup(ps, encode_buf, sizeof(encode_buf), 1) != OK) {
error = ps->ps_errno + ISODE_50_PS_ERR_NONE;
errout:
ps_free(ps);
free_translation(isode_out);
return(error);
}
if ((*encoder)(&pe, 0, 0, 0, isode_out)) {
error = ENOMEM;
goto errout;
}
*data_out = (krb5_data *)malloc(sizeof(**data_out));
if (!*data_out) {
error = ENOMEM;
goto errout;
}
if (((*data_out)->length = ps_get_abs(pe)) > sizeof(encode_buf)) {
abort(); /* xxx */
}
(*data_out)->data = malloc(ps_get_abs(pe));
if (!(*data_out)->data) {
error = ENOMEM;
free((char *)*data_out);
*data_out = 0;
goto errout;
}
if (pe2ps(ps, pe) != OK || ps_flush(ps) != OK) {
error = ps->ps_errno + ISODE_50_PS_ERR_NONE;
free((*data_out)->data);
free((char *)*data_out);
*data_out = 0;
goto errout;
}
bcopy(encode_buf, (*data_out)->data, (*data_out)->length);
ps_free(ps);
pe_free(pe);
free_translation(isode_out);
return(0);
}
|