5 actx_copy_addr(krb5_context context, const krb5_address *inad, krb5_address **outad)
9 if (!(tmpad = (krb5_address *)malloc(sizeof(*tmpad))))
11 #ifdef HAVE_C_STRUCTURE_ASSIGNMENT
14 memcpy(tmpad, inad, sizeof(krb5_address));
16 if (!(tmpad->contents = (krb5_octet *)malloc(inad->length))) {
20 memcpy((char *)tmpad->contents, (char *)inad->contents, inad->length);
25 krb5_error_code KRB5_CALLCONV
26 krb5_auth_con_init(krb5_context context, krb5_auth_context *auth_context)
29 (krb5_auth_context)malloc(sizeof(struct _krb5_auth_context));
33 memset(*auth_context, 0, sizeof(struct _krb5_auth_context));
35 /* Default flags, do time not seq */
36 (*auth_context)->auth_context_flags =
37 KRB5_AUTH_CONTEXT_DO_TIME | KRB5_AUTH_CONN_INITIALIZED;
39 (*auth_context)->req_cksumtype = context->default_ap_req_sumtype;
40 (*auth_context)->safe_cksumtype = context->default_safe_sumtype;
41 (*auth_context)->magic = KV5M_AUTH_CONTEXT;
45 krb5_error_code KRB5_CALLCONV
46 krb5_auth_con_free(krb5_context context, krb5_auth_context auth_context)
48 if (auth_context->local_addr)
49 krb5_free_address(context, auth_context->local_addr);
50 if (auth_context->remote_addr)
51 krb5_free_address(context, auth_context->remote_addr);
52 if (auth_context->local_port)
53 krb5_free_address(context, auth_context->local_port);
54 if (auth_context->remote_port)
55 krb5_free_address(context, auth_context->remote_port);
56 if (auth_context->authentp)
57 krb5_free_authenticator(context, auth_context->authentp);
58 if (auth_context->keyblock)
59 krb5_free_keyblock(context, auth_context->keyblock);
60 if (auth_context->local_subkey)
61 krb5_free_keyblock(context, auth_context->local_subkey);
62 if (auth_context->remote_subkey)
63 krb5_free_keyblock(context, auth_context->remote_subkey);
64 if (auth_context->rcache)
65 krb5_rc_close(context, auth_context->rcache);
66 if (auth_context->permitted_etypes)
67 krb5_xfree(auth_context->permitted_etypes);
73 krb5_auth_con_setaddrs(krb5_context context, krb5_auth_context auth_context, krb5_address *local_addr, krb5_address *remote_addr)
75 krb5_error_code retval;
77 /* Free old addresses */
78 if (auth_context->local_addr)
79 (void) krb5_free_address(context, auth_context->local_addr);
80 if (auth_context->remote_addr)
81 (void) krb5_free_address(context, auth_context->remote_addr);
85 retval = actx_copy_addr(context,
87 &auth_context->local_addr);
89 auth_context->local_addr = NULL;
91 if (!retval && remote_addr)
92 retval = actx_copy_addr(context,
94 &auth_context->remote_addr);
96 auth_context->remote_addr = NULL;
101 krb5_error_code KRB5_CALLCONV
102 krb5_auth_con_getaddrs(krb5_context context, krb5_auth_context auth_context, krb5_address **local_addr, krb5_address **remote_addr)
104 krb5_error_code retval;
107 if (local_addr && auth_context->local_addr) {
108 retval = actx_copy_addr(context,
109 auth_context->local_addr,
112 if (!retval && (remote_addr) && auth_context->remote_addr) {
113 retval = actx_copy_addr(context,
114 auth_context->remote_addr,
120 krb5_error_code KRB5_CALLCONV
121 krb5_auth_con_setports(krb5_context context, krb5_auth_context auth_context, krb5_address *local_port, krb5_address *remote_port)
123 krb5_error_code retval;
125 /* Free old addresses */
126 if (auth_context->local_port)
127 (void) krb5_free_address(context, auth_context->local_port);
128 if (auth_context->remote_port)
129 (void) krb5_free_address(context, auth_context->remote_port);
133 retval = actx_copy_addr(context,
135 &auth_context->local_port);
137 auth_context->local_port = NULL;
139 if (!retval && remote_port)
140 retval = actx_copy_addr(context,
142 &auth_context->remote_port);
144 auth_context->remote_port = NULL;
151 * This function overloads the keyblock field. It is only useful prior to
152 * a krb5_rd_req_decode() call for user to user authentication where the
153 * server has the key and needs to use it to decrypt the incoming request.
154 * Once decrypted this key is no longer necessary and is then overwritten
155 * with the session key sent by the client.
157 krb5_error_code KRB5_CALLCONV
158 krb5_auth_con_setuseruserkey(krb5_context context, krb5_auth_context auth_context, krb5_keyblock *keyblock)
160 if (auth_context->keyblock)
161 krb5_free_keyblock(context, auth_context->keyblock);
162 return(krb5_copy_keyblock(context, keyblock, &(auth_context->keyblock)));
165 krb5_error_code KRB5_CALLCONV
166 krb5_auth_con_getkey(krb5_context context, krb5_auth_context auth_context, krb5_keyblock **keyblock)
168 if (auth_context->keyblock)
169 return krb5_copy_keyblock(context, auth_context->keyblock, keyblock);
174 krb5_error_code KRB5_CALLCONV
175 krb5_auth_con_getlocalsubkey(krb5_context context, krb5_auth_context auth_context, krb5_keyblock **keyblock)
177 if (auth_context->local_subkey)
178 return krb5_copy_keyblock(context,auth_context->local_subkey,keyblock);
183 krb5_error_code KRB5_CALLCONV
184 krb5_auth_con_getremotesubkey(krb5_context context, krb5_auth_context auth_context, krb5_keyblock **keyblock)
186 if (auth_context->remote_subkey)
187 return krb5_copy_keyblock(context,auth_context->remote_subkey,keyblock);
192 krb5_error_code KRB5_CALLCONV
193 krb5_auth_con_set_req_cksumtype(krb5_context context, krb5_auth_context auth_context, krb5_cksumtype cksumtype)
195 auth_context->req_cksumtype = cksumtype;
200 krb5_auth_con_set_safe_cksumtype(krb5_context context, krb5_auth_context auth_context, krb5_cksumtype cksumtype)
202 auth_context->safe_cksumtype = cksumtype;
206 krb5_error_code KRB5_CALLCONV
207 krb5_auth_con_getlocalseqnumber(krb5_context context, krb5_auth_context auth_context, krb5_int32 *seqnumber)
209 *seqnumber = auth_context->local_seq_number;
213 krb5_error_code KRB5_CALLCONV
214 krb5_auth_con_getauthenticator(krb5_context context, krb5_auth_context auth_context, krb5_authenticator **authenticator)
216 return (krb5_copy_authenticator(context, auth_context->authentp,
220 krb5_error_code KRB5_CALLCONV
221 krb5_auth_con_getremoteseqnumber(krb5_context context, krb5_auth_context auth_context, krb5_int32 *seqnumber)
223 *seqnumber = auth_context->remote_seq_number;
227 krb5_error_code KRB5_CALLCONV
228 krb5_auth_con_initivector(krb5_context context, krb5_auth_context auth_context)
232 if (auth_context->keyblock) {
235 if ((ret = krb5_c_block_size(context, auth_context->keyblock->enctype,
238 if ((auth_context->i_vector = (krb5_pointer)malloc(blocksize))) {
239 memset(auth_context->i_vector, 0, blocksize);
244 return EINVAL; /* XXX need an error for no keyblock */
248 krb5_auth_con_setivector(krb5_context context, krb5_auth_context auth_context, krb5_pointer ivector)
250 auth_context->i_vector = ivector;
255 krb5_auth_con_getivector(krb5_context context, krb5_auth_context auth_context, krb5_pointer *ivector)
257 *ivector = auth_context->i_vector;
261 krb5_error_code KRB5_CALLCONV
262 krb5_auth_con_setflags(krb5_context context, krb5_auth_context auth_context, krb5_int32 flags)
264 auth_context->auth_context_flags = flags;
268 krb5_error_code KRB5_CALLCONV
269 krb5_auth_con_getflags(krb5_context context, krb5_auth_context auth_context, krb5_int32 *flags)
271 *flags = auth_context->auth_context_flags;
275 krb5_error_code KRB5_CALLCONV
276 krb5_auth_con_setrcache(krb5_context context, krb5_auth_context auth_context, krb5_rcache rcache)
278 auth_context->rcache = rcache;
283 krb5_auth_con_getrcache(krb5_context context, krb5_auth_context auth_context, krb5_rcache *rcache)
285 *rcache = auth_context->rcache;
290 krb5_auth_con_setpermetypes(krb5_context context, krb5_auth_context auth_context, const krb5_enctype *permetypes)
292 krb5_enctype * newpe;
295 for (i=0; permetypes[i]; i++)
297 i++; /* include the zero */
299 if ((newpe = (krb5_enctype *) malloc(i*sizeof(krb5_enctype)))
303 if (auth_context->permitted_etypes)
304 krb5_xfree(auth_context->permitted_etypes);
306 auth_context->permitted_etypes = newpe;
308 memcpy(newpe, permetypes, i*sizeof(krb5_enctype));
314 krb5_auth_con_getpermetypes(krb5_context context, krb5_auth_context auth_context, krb5_enctype **permetypes)
316 krb5_enctype * newpe;
319 if (! auth_context->permitted_etypes) {
324 for (i=0; auth_context->permitted_etypes[i]; i++)
326 i++; /* include the zero */
328 if ((newpe = (krb5_enctype *) malloc(i*sizeof(krb5_enctype)))
334 memcpy(newpe, auth_context->permitted_etypes, i*sizeof(krb5_enctype));