]>
Commit | Line | Data |
---|---|---|
61a2844b | 1 | /*-- |
2 | krb5_utils.c | |
3 | ||
4 | Abstract: | |
5 | ||
6 | ASN.1 encoder for the | |
7 | Kerberos Change Password Protocol (I-D) variant for Windows 2000 | |
8 | ||
9 | --*/ | |
10 | ||
11 | #include <krb5.h> | |
12 | #include <ldap.h> | |
13 | #ifdef _WIN32 | |
14 | #include "asn1_make.h" | |
15 | #endif | |
16 | #ifdef HAVE_CONFIG_H | |
17 | #include "config.h" | |
18 | #endif | |
19 | #define NEED_SOCKETS | |
20 | #ifndef _WIN32 | |
21 | #include <netdb.h> | |
22 | #include <sys/socket.h> | |
23 | #endif | |
24 | #include <stdio.h> | |
25 | #include <arpa/nameser.h> | |
26 | #include <resolv.h> | |
27 | #include "kpasswd.h" | |
28 | ||
29 | #ifndef KRB5_USE_INET | |
30 | #ifdef HAVE_NETINET_IN_H | |
31 | #define KRB5_USE_INET 1 | |
32 | #endif | |
33 | #endif | |
34 | ||
35 | #ifndef _WIN32 | |
36 | typedef krb5_octet asn1_octet; | |
37 | typedef krb5_error_code asn1_error_code; | |
38 | typedef struct code_buffer_rep { | |
39 | char *base, *bound, *next; | |
40 | } asn1buf; | |
41 | typedef enum { UNIVERSAL = 0x00, APPLICATION = 0x40, | |
42 | CONTEXT_SPECIFIC = 0x80, PRIVATE = 0xC0 } asn1_class; | |
43 | #endif | |
44 | ||
45 | static const char rcsid[] = "$Id$"; | |
46 | ||
47 | asn1_error_code asn1_encode_realm(asn1buf *buf, const krb5_principal val, | |
48 | int *retlen); | |
49 | asn1_error_code asn1_encode_principal_name(asn1buf *buf, | |
50 | const krb5_principal val, | |
51 | int *retlen); | |
52 | asn1_error_code asn1_encode_octetstring(asn1buf *buf, const int len, | |
53 | const asn1_octet *val, int *retlen); | |
54 | ||
55 | /* From src/lib/krb5/asn.1/krb5_encode.c */ | |
56 | ||
57 | /* setup() -- create and initialize bookkeeping variables | |
58 | retval: stores error codes returned from subroutines | |
59 | buf: the coding buffer | |
60 | length: length of the most-recently produced encoding | |
61 | sum: cumulative length of the entire encoding */ | |
62 | #define krb5_setup()\ | |
63 | asn1_error_code retval;\ | |
64 | asn1buf *buf=NULL;\ | |
65 | int length, sum=0;\ | |
66 | \ | |
67 | if(rep == NULL) return ASN1_MISSING_FIELD;\ | |
68 | \ | |
69 | retval = asn1buf_create(&buf);\ | |
70 | if(retval) return retval | |
71 | ||
72 | ||
73 | /* krb5_addfield -- add a field, or component, to the encoding */ | |
74 | #define krb5_addfield(value,tag,encoder)\ | |
75 | { retval = encoder(buf,value,&length);\ | |
76 | if(retval){\ | |
77 | asn1buf_destroy(&buf);\ | |
78 | return retval; }\ | |
79 | sum += length;\ | |
80 | retval = asn1_make_etag(buf,CONTEXT_SPECIFIC,tag,length,&length);\ | |
81 | if(retval){\ | |
82 | asn1buf_destroy(&buf);\ | |
83 | return retval; }\ | |
84 | sum += length; } | |
85 | ||
86 | /* krb5_addlenfield -- add a field whose length must be separately specified */ | |
87 | #define krb5_addlenfield(len,value,tag,encoder)\ | |
88 | { retval = encoder(buf,len,value,&length);\ | |
89 | if(retval){\ | |
90 | asn1buf_destroy(&buf);\ | |
91 | return retval; }\ | |
92 | sum += length;\ | |
93 | retval = asn1_make_etag(buf,CONTEXT_SPECIFIC,tag,length,&length);\ | |
94 | if(retval){\ | |
95 | asn1buf_destroy(&buf);\ | |
96 | return retval; }\ | |
97 | sum += length; } | |
98 | ||
99 | /* form a sequence (by adding a sequence header to the current encoding) */ | |
100 | #define krb5_makeseq()\ | |
101 | retval = asn1_make_sequence(buf,sum,&length);\ | |
102 | if(retval){\ | |
103 | asn1buf_destroy(&buf);\ | |
104 | return retval; }\ | |
105 | sum += length | |
106 | ||
107 | /* produce the final output and clean up the workspace */ | |
108 | #define krb5_cleanup()\ | |
109 | retval = asn12krb5_buf(buf,code);\ | |
110 | if(retval){\ | |
111 | asn1buf_destroy(&buf);\ | |
112 | return retval; }\ | |
113 | retval = asn1buf_destroy(&buf);\ | |
114 | if(retval){\ | |
115 | return retval; }\ | |
116 | \ | |
117 | return(0) | |
118 | ||
119 | krb5_error_code encode_krb5_setpw(const krb5_setpw *rep, | |
120 | krb5_data ** code) | |
121 | { | |
122 | krb5_setup(); | |
123 | ||
124 | if (rep->targprinc != NULL) | |
125 | { /* target principal name is OPTIONAL */ | |
126 | krb5_addfield(rep->targprinc,2,asn1_encode_realm); | |
127 | krb5_addfield(rep->targprinc,1,asn1_encode_principal_name); | |
128 | } | |
129 | krb5_addlenfield(rep->newpasswd.length, rep->newpasswd.data, | |
130 | 0, asn1_encode_octetstring); | |
131 | krb5_makeseq(); | |
132 | krb5_cleanup(); | |
133 | } | |
134 |