xref: /illumos-gate/usr/src/lib/gss_mechs/mech_krb5/krb5/krb/addr_comp.c (revision 1da57d551424de5a9d469760be7c4b4d4f10a755)
1 /*
2  * lib/krb5/krb/addr_comp.c
3  *
4  * Copyright 1990 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.  Furthermore if you modify this software you must label
20  * your software as modified software and not distribute it in such a
21  * fashion that it might be confused with the original M.I.T. software.
22  * M.I.T. makes no representations about the suitability of
23  * this software for any purpose.  It is provided "as is" without express
24  * or implied warranty.
25  *
26  *
27  * krb5_address_compare()
28  */
29 
30 #include <k5-int.h>
31 
32 #ifdef KRB5_DEBUG
33 #include <sys/types.h>
34 #include <sys/socket.h>
35 #include <netinet/in.h>
36 #include <arpa/inet.h>
37 #endif
38 
39 /*
40  * If the two addresses are the same, return TRUE, else return FALSE
41  */
42 /*ARGSUSED*/
43 krb5_boolean KRB5_CALLCONV
krb5_address_compare(krb5_context context,krb5_const krb5_address * addr1,krb5_const krb5_address * addr2)44 krb5_address_compare(krb5_context context, krb5_const krb5_address *addr1,
45 	krb5_const krb5_address *addr2)
46 {
47     KRB5_LOG0(KRB5_INFO, "krb5_address_compare() start");
48 
49 #ifdef KRB5_DEBUG
50 {
51     char buf[256];
52     sa_family_t addr_fam;
53 
54     switch (addr1->addrtype) {
55 	case ADDRTYPE_INET:
56 	    addr_fam = AF_INET;
57 	    break;
58 	case ADDRTYPE_INET6:
59 	    addr_fam = AF_INET6;
60 	    break;
61     }
62     inet_ntop(addr_fam, addr1->contents, buf, sizeof(buf));
63     KRB5_LOG(KRB5_INFO, "krb5_address_compare() addr1=%s", buf);
64     KRB5_LOG(KRB5_INFO, "krb5_address_compare() addr1 type=%d",
65 	    addr1->addrtype);
66     KRB5_LOG(KRB5_INFO, "krb5_address_compare() addr1 length=%d",
67 	    addr1->length);
68 
69     switch (addr2->addrtype) {
70 	case ADDRTYPE_INET:
71 	    addr_fam = AF_INET;
72 	    break;
73 	case ADDRTYPE_INET6:
74 	    addr_fam = AF_INET6;
75 	    break;
76     }
77     inet_ntop(addr_fam, addr2->contents, buf, sizeof(buf));
78     KRB5_LOG(KRB5_INFO, "krb5_address_compare() addr2=%s", buf);
79     KRB5_LOG(KRB5_INFO, "krb5_address_compare() addr2 type=%d",
80 	    addr2->addrtype);
81     KRB5_LOG(KRB5_INFO, "krb5_address_compare() addr2 length=%d",
82 	    addr2->length);
83 }
84 #endif /* KRB5_DEBUG */
85 
86     if (addr1->addrtype != addr2->addrtype){
87 	KRB5_LOG0(KRB5_INFO, "krb5_address_compare() end FALSE"
88 		" (addrtype mismatch)");
89 	return(FALSE);
90     }
91 
92     if (addr1->length != addr2->length){
93 	KRB5_LOG0(KRB5_INFO, "krb5_address_compare() end FALSE"
94 		" (length mismatch)");
95 	return(FALSE);
96     }
97     if (memcmp((char *)addr1->contents, (char *)addr2->contents,
98 	       addr1->length)){
99 	KRB5_LOG0(KRB5_INFO, "krb5_address_compare() end FALSE"
100 		" (contents mismatch)");
101 	return FALSE;
102     }
103     else {
104 	KRB5_LOG0(KRB5_INFO, "krb5_address_compare() end TRUE");
105 	return TRUE;
106     }
107 }
108