1 #pragma ident	"%Z%%M%	%I%	%E% SMI"
2 /*
3  * lib/krb5/krb/princ_comp.c
4  *
5  * Copyright 1990,1991 by the Massachusetts Institute of Technology.
6  * All Rights Reserved.
7  *
8  * Export of this software from the United States of America may
9  *   require a specific license from the United States Government.
10  *   It is the responsibility of any person or organization contemplating
11  *   export to obtain such a license before exporting.
12  *
13  * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
14  * distribute this software and its documentation for any purpose and
15  * without fee is hereby granted, provided that the above copyright
16  * notice appear in all copies and that both that copyright notice and
17  * this permission notice appear in supporting documentation, and that
18  * the name of M.I.T. not be used in advertising or publicity pertaining
19  * to distribution of the software without specific, written prior
20  * permission.  Furthermore if you modify this software you must label
21  * your software as modified software and not distribute it in such a
22  * fashion that it might be confused with the original M.I.T. software.
23  * M.I.T. makes no representations about the suitability of
24  * this software for any purpose.  It is provided "as is" without express
25  * or implied warranty.
26  *
27  *
28  * compare two principals, returning a krb5_boolean true if equal, false if
29  * not.
30  */
31 
32 #include <k5-int.h>
33 
34 /*ARGSUSED*/
35 krb5_boolean KRB5_CALLCONV
36 krb5_realm_compare(krb5_context context, krb5_const_principal princ1, krb5_const_principal princ2)
37 {
38     if (krb5_princ_realm(context, princ1)->length !=
39 	krb5_princ_realm(context, princ2)->length ||
40 	memcmp (krb5_princ_realm(context, princ1)->data,
41 	 	krb5_princ_realm(context, princ2)->data,
42 		krb5_princ_realm(context, princ2)->length))
43 	return FALSE;
44 
45     return TRUE;
46 }
47 
48 krb5_boolean KRB5_CALLCONV
49 krb5_principal_compare(krb5_context context, krb5_const_principal princ1, krb5_const_principal princ2)
50 {
51     register int i;
52     krb5_int32 nelem;
53 
54     nelem = krb5_princ_size(context, princ1);
55     if (nelem != krb5_princ_size(context, princ2))
56 	return FALSE;
57 
58     if (! krb5_realm_compare(context, princ1, princ2))
59 	return FALSE;
60 
61     for (i = 0; i < (int) nelem; i++) {
62 	register const krb5_data *p1 = krb5_princ_component(context, princ1, i);
63 	register const krb5_data *p2 = krb5_princ_component(context, princ2, i);
64 	if (p1->length != p2->length ||
65 	    memcmp(p1->data, p2->data, p1->length))
66 	    return FALSE;
67     }
68     return TRUE;
69 }
70