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