Windows global stuff:
[krb5.git] / src / lib / krb5 / krb / auth_con.c
1
2 #include "k5-int.h"
3 #include "auth_con.h"
4
5 krb5_error_code
6 krb5_auth_con_init(context, auth_context)
7     krb5_context          context;
8     krb5_auth_context  ** auth_context;
9 {
10     if (*auth_context = (krb5_auth_context *)malloc(sizeof(krb5_auth_context))){
11         memset(*auth_context, 0, sizeof(krb5_auth_context));
12
13         /* Default flags, do time not seq */
14         (*auth_context)->auth_context_flags = 
15           KRB5_AUTH_CONTEXT_DO_TIME |  KRB5_AUTH_CONN_INITIALIZED;
16
17         (*auth_context)->cksumtype = CKSUMTYPE_RSA_MD4_DES;
18         /* (*auth_context)->cksumtype = CKSUMTYPE_CRC32; */
19         return 0;
20     }
21     return ENOMEM;
22 }
23
24 krb5_error_code
25 krb5_auth_con_free(context, auth_context)
26     krb5_context          context;
27     krb5_auth_context   * auth_context;
28 {
29     if (auth_context->authentp) 
30         krb5_free_authenticator(context, auth_context->authentp);
31     if (auth_context->keyblock) 
32         krb5_free_keyblock(context, auth_context->keyblock);
33     if (auth_context->local_subkey) 
34         krb5_free_keyblock(context, auth_context->local_subkey);
35     if (auth_context->remote_subkey) 
36         krb5_free_keyblock(context, auth_context->remote_subkey);
37     free(auth_context);
38     return 0;
39 }
40
41 krb5_error_code
42 krb5_auth_con_setaddrs(context, auth_context, local_addr, remote_addr)
43     krb5_context          context;
44     krb5_auth_context   * auth_context;
45     krb5_address        * local_addr;
46     krb5_address        * remote_addr;
47 {
48     auth_context->remote_addr = remote_addr;
49     auth_context->local_addr = local_addr;
50     return 0;
51 }
52
53 /* XXX this call is a hack. Fixed when I do the servers. */
54 krb5_error_code
55 krb5_auth_con_setkey(context, auth_context, keyblock)
56     krb5_context          context;
57     krb5_auth_context   * auth_context;
58     krb5_keyblock       * keyblock;             
59 {
60     if (auth_context->keyblock)
61         krb5_free_keyblock(context, auth_context->keyblock);
62     return(krb5_copy_keyblock(context, keyblock, &(auth_context->keyblock)));
63 }
64
65 /*
66  * This function overloads the keyblock field. It is only useful prior to
67  * a krb5_rd_req_decode() call for user to user authentication where the
68  * server has the key and needs to use it to decrypt the incoming request.
69  * Once decrypted this key is no longer necessary and is then overwritten
70  * with the session key sent by the client.
71  */
72 krb5_error_code
73 krb5_auth_con_setuseruserkey(context, auth_context, keyblock)
74     krb5_context          context;
75     krb5_auth_context   * auth_context;
76     krb5_keyblock       * keyblock;             
77 {
78     if (auth_context->keyblock)
79         krb5_free_keyblock(context, auth_context->keyblock);
80     return(krb5_copy_keyblock(context, keyblock, &(auth_context->keyblock)));
81 }
82
83 krb5_error_code
84 krb5_auth_con_getkey(context, auth_context, keyblock)
85     krb5_context          context;
86     krb5_auth_context   * auth_context;
87     krb5_keyblock      ** keyblock;             
88 {
89     if (auth_context->keyblock)
90         return krb5_copy_keyblock(context, auth_context->keyblock, keyblock);
91     *keyblock = NULL;
92     return 0;
93 }
94
95 krb5_error_code
96 krb5_auth_con_getlocalsubkey(context, auth_context, keyblock)
97     krb5_context          context;
98     krb5_auth_context   * auth_context;
99     krb5_keyblock      ** keyblock;             
100 {
101     if (auth_context->local_subkey)
102         return krb5_copy_keyblock(context,auth_context->local_subkey,keyblock);
103     *keyblock = NULL;
104     return 0;
105 }
106
107 krb5_error_code
108 krb5_auth_con_getremotesubkey(context, auth_context, keyblock)
109     krb5_context          context;
110     krb5_auth_context   * auth_context;
111     krb5_keyblock      ** keyblock;             
112 {
113     if (auth_context->remote_subkey)
114         return krb5_copy_keyblock(context,auth_context->remote_subkey,keyblock);
115     *keyblock = NULL;
116     return 0;
117 }
118
119 krb5_error_code
120 krb5_auth_con_setcksumtype(context, auth_context, cksumtype)
121     krb5_context          context;
122     krb5_auth_context   * auth_context;
123     krb5_cksumtype        cksumtype;            
124 {
125     auth_context->cksumtype = cksumtype;
126     return 0;
127 }
128
129 krb5_error_code
130 krb5_auth_con_getlocalseqnumber(context, auth_context, seqnumber)
131     krb5_context          context;
132     krb5_auth_context   * auth_context;
133     krb5_int32          * seqnumber;            
134 {
135     *seqnumber = auth_context->local_seq_number;
136     return 0;
137 }
138
139 krb5_error_code
140 krb5_auth_con_getauthenticator(context, auth_context, authenticator)
141     krb5_context          context;
142     krb5_auth_context   * auth_context;
143     krb5_authenticator ** authenticator;                
144 {
145     return (krb5_copy_authenticator(context, auth_context->authentp,
146                                     authenticator));
147 }
148
149 krb5_error_code
150 krb5_auth_con_getremoteseqnumber(context, auth_context, seqnumber)
151     krb5_context          context;
152     krb5_auth_context   * auth_context;
153     krb5_int32          * seqnumber;            
154 {
155     *seqnumber = auth_context->remote_seq_number;
156     return 0;
157 }
158
159 krb5_error_code
160 krb5_auth_con_initivector(context, auth_context)
161     krb5_context          context;
162     krb5_auth_context   * auth_context;
163 {
164     if (auth_context->keyblock) {
165         int size = krb5_keytype_array[auth_context->keyblock->keytype]->
166                       system->block_length;
167
168         if (auth_context->i_vector = (krb5_pointer)malloc(size)) {
169             memset(auth_context->i_vector, 0, size);
170             return 0;
171         }
172         return ENOMEM;
173     }
174     return EINVAL; /* XXX need an error for no keyblock */
175 }
176
177 krb5_error_code
178 krb5_auth_con_setivector(context, auth_context, ivector)
179     krb5_context          context;
180     krb5_auth_context   * auth_context;
181     krb5_pointer          ivector;
182 {
183     auth_context->i_vector = ivector;
184     return 0;
185 }
186
187 krb5_error_code
188 krb5_auth_con_getivector(context, auth_context, ivector)
189     krb5_context          context;
190     krb5_auth_context   * auth_context;
191     krb5_pointer        * ivector;
192 {
193     *ivector = auth_context->i_vector;
194     return 0;
195 }
196
197 krb5_error_code
198 krb5_auth_con_setflags(context, auth_context, flags)
199     krb5_context          context;
200     krb5_auth_context   * auth_context;
201     krb5_int32            flags;
202 {
203     auth_context->auth_context_flags = flags;
204     return 0;
205 }
206
207 krb5_error_code
208 krb5_auth_con_setrcache(context, auth_context, rcache)
209     krb5_context          context;
210     krb5_auth_context   * auth_context;
211     krb5_rcache           rcache;
212 {
213     auth_context->rcache = rcache;
214     return 0;
215 }
216