Remove EAP support from GSSAPI plugin
[cyrus-sasl.git] / mac / mac_lib / yyy_mac_lib.c
1 /* $Id: yyy_mac_lib.c,v 1.3 2003/02/13 19:55:59 rjs3 Exp $
2  * Copyright (c) 1998-2003 Carnegie Mellon University.  All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer. 
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in
13  *    the documentation and/or other materials provided with the
14  *    distribution.
15  *
16  * 3. The name "Carnegie Mellon University" must not be used to
17  *    endorse or promote products derived from this software without
18  *    prior written permission. For permission or any other legal
19  *    details, please contact  
20  *      Office of Technology Transfer
21  *      Carnegie Mellon University
22  *      5000 Forbes Avenue
23  *      Pittsburgh, PA  15213-3890
24  *      (412) 268-4387, fax: (412) 268-7395
25  *      tech-transfer@andrew.cmu.edu
26  *
27  * 4. Redistributions of any form whatsoever must retain the following
28  *    acknowledgment:
29  *    "This product includes software developed by Computing Services
30  *     at Carnegie Mellon University (http://www.cmu.edu/computing/)."
31  *
32  * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
33  * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
34  * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
35  * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
36  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
37  * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
38  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
39  */
40 #include "sasl_mac_krb_locl.h"
41 #include <script.h>
42 #include <ToolUtils.h>
43
44 int krbONE=1;
45 int krb_debug;
46
47 int krb_get_config_bool(const char *variable)
48 {
49         /* return the value of the only config variable we know of */
50         if(strcmp(variable,"reverse_lsb_test")==0)
51                 return 0;
52         return 0;
53 }
54
55 /*
56  * compare two ip addresses
57  */
58 int krb_equiv(
59         u_int32_t a,
60         u_int32_t b)
61 {
62         if(a==0)
63                 return 1;
64         if(b==0)
65                 return 1;
66 #ifdef STRICT_ADDRESS_EQUIV
67         return a==b;
68 #else
69         return 1;
70 #endif
71 }
72
73 int abs(int x)
74 {
75   if(x>=0)
76         return x;
77   return -x;
78 }
79
80
81 /*
82  * from kerberos.c -- return the offset from gmt
83  */
84 static long getTimeZoneOffset(void )
85 {
86         MachineLocation         macLocation;
87         long                    gmtDelta;
88
89         macLocation.u.gmtDelta=0L;
90         ReadLocation(&macLocation);
91         gmtDelta=macLocation.u.gmtDelta & 0x00FFFFFF;
92         if (BitTst((void *)&gmtDelta,23L))
93                 gmtDelta |= 0xFF000000;
94         gmtDelta /= 3600L;
95         return(gmtDelta);
96 }
97
98 /*
99  * from kerberos.c -- convert mac time to unix time
100  */
101 static void mac_time_to_unix_time (unsigned long *time)
102 {
103         *time -= 66L * 365L * 24L * 60L * 60L + 17L * 60L * 60L * 24L + getTimeZoneOffset() * 60L * 60L;
104 }
105
106 /*
107  * return the current unix time
108  */
109 static unsigned long get_unix_time(void)
110 {
111         unsigned long result;
112         GetDateTime(&result);
113         mac_time_to_unix_time(&result);
114         return result;
115 }
116
117 /*
118  * printf a warning
119  */
120 void krb_warning(const char *fmt,...)
121 {
122 }
123
124 void krb_kdctimeofday (struct timeval *tv)
125 {
126         gettimeofday(tv,0);
127 }
128
129 int gettimeofday(struct timeval *tp, void *foo)
130 {
131         tp->tv_sec=get_unix_time();
132         tp->tv_usec=0;
133         return 0;
134 }
135
136 void swab(char *src, char *dst,int len)
137 {
138         while(len>=2) {
139                 char a;
140                 char b;
141                 a= *src++;
142                 b= *src++;
143                 len-=2;
144                 *dst++=b;
145                 *dst++=a;
146         }
147 }
148
149 char *inet_ntoa(unsigned long n)
150 {
151 #define BYTE0(xxx) ((int)((xxx)&0x0ff))
152         static char buf[32];
153         sprintf(buf,"%d.%d.%d.%d",
154                 BYTE0(n>>24),
155                 BYTE0(n>>16),
156                 BYTE0(n>>8),
157                 BYTE0(n));
158         return buf;
159 }
160
161 #ifdef RUBBISH
162 u_int32_t lsb_time(
163         time_t t,
164         struct sockaddr_in *src,
165         struct sockaddr_in *dst)
166 {
167         return 0;
168 }
169 #endif