2 * Copyright (C) 1998 by the FundsXpress, INC.
6 * Export of this software from the United States of America may require
7 * a specific license from the United States Government. It is the
8 * responsibility of any person or organization contemplating export to
9 * obtain such a license before exporting.
11 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
12 * distribute this software and its documentation for any purpose and
13 * without fee is hereby granted, provided that the above copyright
14 * notice appear in all copies and that both that copyright notice and
15 * this permission notice appear in supporting documentation, and that
16 * the name of FundsXpress. not be used in advertising or publicity pertaining
17 * to distribution of the software without specific, written prior
18 * permission. FundsXpress makes no representations about the suitability of
19 * this software for any purpose. It is provided "as is" without express
20 * or implied warranty.
22 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
24 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27 #include <gssapiP_krb5.h>
29 /* from the token, flags is stored directly. nctypes/ctypes is
30 allocated and returns the length and list of ctypes in the token.
31 noptions/options lists all the options which the caller cares
32 about. Those which are present in the token are filled in; the
33 order and length are not changed. If an error is returned, the
34 option list is in an indeterminate state. */
37 kg2_parse_token(minor_status
, ptr
, token_length
, flags
, nctypes
, ctypes
,
38 noptions
, options
, kmsg
, mic
)
39 OM_uint32
*minor_status
;
43 int *nctypes
; /* OUT */
44 krb5_cksumtype
**ctypes
; /* OUT */
46 struct kg2_option
*options
; /* INOUT */
59 *flags
= (ptr
[0]<<24) | (ptr
[1]<<16) | (ptr
[2]<<8) | ptr
[3];
63 /* read out the token list */
67 field_length
= (ptr
[0]<<8) | ptr
[1];
71 *nctypes
= field_length
;
75 return(GSS_S_DEFECTIVE_TOKEN
);
78 if ((*ctypes
= (krb5_cksumtype
*)
79 malloc((*nctypes
) * sizeof(krb5_cksumtype
))) == NULL
) {
80 *minor_status
= ENOMEM
;
81 return(GSS_S_FAILURE
);
84 for (i
=0; i
<field_length
; i
++) {
88 (*ctypes
)[i
] = (krb5_cksumtype
) ((ptr
[0]<<24) | (ptr
[1]<<16) |
89 (ptr
[2]<<8) | ptr
[3]);
97 opt_id
= (ptr
[0]<<8) | ptr
[1];
98 field_length
= (ptr
[2]<<8) | ptr
[3];
102 if (token_length
< field_length
)
105 for (i
=0; i
<noptions
; i
++) {
106 if (options
[i
].option_id
= opt_id
) {
107 options
[i
].length
= field_length
;
108 options
[i
].data
= ptr
;
114 token_length
-= field_length
;
117 if (token_length
< 2)
119 field_length
= (ptr
[0]<<8) | ptr
[1];
123 if (token_length
< field_length
)
126 kmsg
->length
= field_length
;
127 kmsg
->data
= (char *) ptr
;
130 token_length
-= field_length
;
132 /* if there's anything left, assume it's a mic. the mic isn't
133 necessarily present */
135 if (mic
&& token_length
) {
136 if (token_length
< 2)
138 field_length
= (ptr
[0]<<8) | ptr
[1];
142 if (token_length
< field_length
)
145 mic
->length
= field_length
;
146 mic
->data
= (char *) ptr
;
149 token_length
-= field_length
;
152 mic
->data
= (char *) ptr
;
158 return(GSS_S_COMPLETE
);
164 return(GSS_S_DEFECTIVE_TOKEN
);
167 /* nc1/c1 will be modified to contain the intersection of the
171 kg2_intersect_ctypes(nc1
, c1
, nc2
, c2
)
175 const krb5_cksumtype
*c2
;
182 for (i
=0; i
<*nc1
; i
++) {
183 /* first, check to make sure that c1[i] isn't a duplicate in c1 */
189 /* check if c1[i] is in c2. If it is, keep it by swapping
190 it into c1[count] and incrementing count. If count < i, then
191 that field has already been looked at and skipped as
192 not intersecting, which is ok. */
194 for (j
=0; j
<nc2
; j
++)
197 if ((j
<nc2
) && (count
!= i
)) {