Print this page
4853 illumos-gate is not lint-clean when built with openssl 1.0
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/openssl/libsunw_crypto/o_time.c
+++ new/usr/src/lib/openssl/libsunw_crypto/o_time.c
1 1 /* crypto/o_time.c -*- mode:C; c-file-style: "eay" -*- */
2 2 /* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
3 3 * project 2001.
4 4 */
5 5 /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
6 6 * project 2008.
7 7 */
8 8 /* ====================================================================
9 9 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
10 10 *
11 11 * Redistribution and use in source and binary forms, with or without
12 12 * modification, are permitted provided that the following conditions
13 13 * are met:
14 14 *
15 15 * 1. Redistributions of source code must retain the above copyright
16 16 * notice, this list of conditions and the following disclaimer.
17 17 *
18 18 * 2. Redistributions in binary form must reproduce the above copyright
19 19 * notice, this list of conditions and the following disclaimer in
20 20 * the documentation and/or other materials provided with the
21 21 * distribution.
22 22 *
23 23 * 3. All advertising materials mentioning features or use of this
24 24 * software must display the following acknowledgment:
25 25 * "This product includes software developed by the OpenSSL Project
26 26 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
27 27 *
28 28 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
29 29 * endorse or promote products derived from this software without
30 30 * prior written permission. For written permission, please contact
31 31 * licensing@OpenSSL.org.
32 32 *
33 33 * 5. Products derived from this software may not be called "OpenSSL"
34 34 * nor may "OpenSSL" appear in their names without prior written
35 35 * permission of the OpenSSL Project.
36 36 *
37 37 * 6. Redistributions of any form whatsoever must retain the following
38 38 * acknowledgment:
39 39 * "This product includes software developed by the OpenSSL Project
40 40 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
41 41 *
42 42 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
43 43 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44 44 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
45 45 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
46 46 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
47 47 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
48 48 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
49 49 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
50 50 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
51 51 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
52 52 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
53 53 * OF THE POSSIBILITY OF SUCH DAMAGE.
↓ open down ↓ |
53 lines elided |
↑ open up ↑ |
54 54 * ====================================================================
55 55 *
56 56 * This product includes cryptographic software written by Eric Young
57 57 * (eay@cryptsoft.com). This product includes software written by Tim
58 58 * Hudson (tjh@cryptsoft.com).
59 59 *
60 60 */
61 61
62 62 #include <openssl/e_os2.h>
63 63 #include <string.h>
64 -#include "o_time.h"
64 +#include <o_time.h>
65 65
66 66 #ifdef OPENSSL_SYS_VMS
67 67 # if __CRTL_VER >= 70000000 && \
68 68 (defined _POSIX_C_SOURCE || !defined _ANSI_C_SOURCE)
69 69 # define VMS_GMTIME_OK
70 70 # endif
71 71 # ifndef VMS_GMTIME_OK
72 72 # include <libdtdef.h>
73 73 # include <lib$routines.h>
74 74 # include <lnmdef.h>
75 75 # include <starlet.h>
76 76 # include <descrip.h>
77 77 # include <stdlib.h>
78 78 # endif /* ndef VMS_GMTIME_OK */
79 79 #endif
80 80
81 81 struct tm *OPENSSL_gmtime(const time_t *timer, struct tm *result)
82 82 {
83 83 struct tm *ts = NULL;
84 84
85 85 #if defined(OPENSSL_THREADS) && !defined(OPENSSL_SYS_WIN32) && !defined(OPENSSL_SYS_OS2) && (!defined(OPENSSL_SYS_VMS) || defined(gmtime_r)) && !defined(OPENSSL_SYS_MACOSX) && !defined(OPENSSL_SYS_SUNOS)
86 86 /* should return &data, but doesn't on some systems,
87 87 so we don't even look at the return value */
88 88 gmtime_r(timer,result);
89 89 ts = result;
90 90 #elif !defined(OPENSSL_SYS_VMS) || defined(VMS_GMTIME_OK)
91 91 ts = gmtime(timer);
92 92 if (ts == NULL)
93 93 return NULL;
94 94
95 95 memcpy(result, ts, sizeof(struct tm));
96 96 ts = result;
97 97 #endif
98 98 #if defined( OPENSSL_SYS_VMS) && !defined( VMS_GMTIME_OK)
99 99 if (ts == NULL)
100 100 {
101 101 static $DESCRIPTOR(tabnam,"LNM$DCL_LOGICAL");
102 102 static $DESCRIPTOR(lognam,"SYS$TIMEZONE_DIFFERENTIAL");
103 103 char logvalue[256];
104 104 unsigned int reslen = 0;
105 105 struct {
106 106 short buflen;
107 107 short code;
108 108 void *bufaddr;
109 109 unsigned int *reslen;
110 110 } itemlist[] = {
111 111 { 0, LNM$_STRING, 0, 0 },
112 112 { 0, 0, 0, 0 },
113 113 };
114 114 int status;
115 115 time_t t;
116 116
117 117 /* Get the value for SYS$TIMEZONE_DIFFERENTIAL */
118 118 itemlist[0].buflen = sizeof(logvalue);
119 119 itemlist[0].bufaddr = logvalue;
120 120 itemlist[0].reslen = &reslen;
121 121 status = sys$trnlnm(0, &tabnam, &lognam, 0, itemlist);
122 122 if (!(status & 1))
123 123 return NULL;
124 124 logvalue[reslen] = '\0';
125 125
126 126 t = *timer;
127 127
128 128 /* The following is extracted from the DEC C header time.h */
129 129 /*
130 130 ** Beginning in OpenVMS Version 7.0 mktime, time, ctime, strftime
131 131 ** have two implementations. One implementation is provided
132 132 ** for compatibility and deals with time in terms of local time,
133 133 ** the other __utc_* deals with time in terms of UTC.
134 134 */
135 135 /* We use the same conditions as in said time.h to check if we should
136 136 assume that t contains local time (and should therefore be adjusted)
137 137 or UTC (and should therefore be left untouched). */
138 138 #if __CRTL_VER < 70000000 || defined _VMS_V6_SOURCE
139 139 /* Get the numerical value of the equivalence string */
140 140 status = atoi(logvalue);
141 141
142 142 /* and use it to move time to GMT */
143 143 t -= status;
144 144 #endif
145 145
146 146 /* then convert the result to the time structure */
147 147
148 148 /* Since there was no gmtime_r() to do this stuff for us,
149 149 we have to do it the hard way. */
150 150 {
151 151 /* The VMS epoch is the astronomical Smithsonian date,
152 152 if I remember correctly, which is November 17, 1858.
153 153 Furthermore, time is measure in thenths of microseconds
154 154 and stored in quadwords (64 bit integers). unix_epoch
155 155 below is January 1st 1970 expressed as a VMS time. The
156 156 following code was used to get this number:
157 157
158 158 #include <stdio.h>
159 159 #include <stdlib.h>
160 160 #include <lib$routines.h>
161 161 #include <starlet.h>
162 162
163 163 main()
164 164 {
165 165 unsigned long systime[2];
166 166 unsigned short epoch_values[7] =
167 167 { 1970, 1, 1, 0, 0, 0, 0 };
168 168
169 169 lib$cvt_vectim(epoch_values, systime);
170 170
171 171 printf("%u %u", systime[0], systime[1]);
172 172 }
173 173 */
174 174 unsigned long unix_epoch[2] = { 1273708544, 8164711 };
175 175 unsigned long deltatime[2];
176 176 unsigned long systime[2];
177 177 struct vms_vectime
178 178 {
179 179 short year, month, day, hour, minute, second,
180 180 centi_second;
181 181 } time_values;
182 182 long operation;
183 183
184 184 /* Turn the number of seconds since January 1st 1970 to
185 185 an internal delta time.
186 186 Note that lib$cvt_to_internal_time() will assume
187 187 that t is signed, and will therefore break on 32-bit
188 188 systems some time in 2038.
189 189 */
190 190 operation = LIB$K_DELTA_SECONDS;
191 191 status = lib$cvt_to_internal_time(&operation,
192 192 &t, deltatime);
193 193
194 194 /* Add the delta time with the Unix epoch and we have
195 195 the current UTC time in internal format */
196 196 status = lib$add_times(unix_epoch, deltatime, systime);
197 197
198 198 /* Turn the internal time into a time vector */
199 199 status = sys$numtim(&time_values, systime);
200 200
201 201 /* Fill in the struct tm with the result */
202 202 result->tm_sec = time_values.second;
203 203 result->tm_min = time_values.minute;
204 204 result->tm_hour = time_values.hour;
205 205 result->tm_mday = time_values.day;
206 206 result->tm_mon = time_values.month - 1;
207 207 result->tm_year = time_values.year - 1900;
208 208
209 209 operation = LIB$K_DAY_OF_WEEK;
210 210 status = lib$cvt_from_internal_time(&operation,
211 211 &result->tm_wday, systime);
212 212 result->tm_wday %= 7;
213 213
214 214 operation = LIB$K_DAY_OF_YEAR;
215 215 status = lib$cvt_from_internal_time(&operation,
216 216 &result->tm_yday, systime);
217 217 result->tm_yday--;
218 218
219 219 result->tm_isdst = 0; /* There's no way to know... */
220 220
221 221 ts = result;
222 222 }
223 223 }
224 224 #endif
225 225 return ts;
226 226 }
227 227
228 228 /* Take a tm structure and add an offset to it. This avoids any OS issues
229 229 * with restricted date types and overflows which cause the year 2038
230 230 * problem.
231 231 */
232 232
233 233 #define SECS_PER_DAY (24 * 60 * 60)
234 234
235 235 static long date_to_julian(int y, int m, int d);
236 236 static void julian_to_date(long jd, int *y, int *m, int *d);
237 237
238 238 int OPENSSL_gmtime_adj(struct tm *tm, int off_day, long offset_sec)
239 239 {
240 240 int offset_hms, offset_day;
241 241 long time_jd;
242 242 int time_year, time_month, time_day;
243 243 /* split offset into days and day seconds */
244 244 offset_day = offset_sec / SECS_PER_DAY;
245 245 /* Avoid sign issues with % operator */
246 246 offset_hms = offset_sec - (offset_day * SECS_PER_DAY);
247 247 offset_day += off_day;
248 248 /* Add current time seconds to offset */
249 249 offset_hms += tm->tm_hour * 3600 + tm->tm_min * 60 + tm->tm_sec;
250 250 /* Adjust day seconds if overflow */
251 251 if (offset_hms >= SECS_PER_DAY)
252 252 {
253 253 offset_day++;
254 254 offset_hms -= SECS_PER_DAY;
255 255 }
256 256 else if (offset_hms < 0)
257 257 {
258 258 offset_day--;
259 259 offset_hms += SECS_PER_DAY;
260 260 }
261 261
262 262 /* Convert date of time structure into a Julian day number.
263 263 */
264 264
265 265 time_year = tm->tm_year + 1900;
266 266 time_month = tm->tm_mon + 1;
267 267 time_day = tm->tm_mday;
268 268
269 269 time_jd = date_to_julian(time_year, time_month, time_day);
270 270
271 271 /* Work out Julian day of new date */
272 272 time_jd += offset_day;
273 273
274 274 if (time_jd < 0)
275 275 return 0;
276 276
277 277 /* Convert Julian day back to date */
278 278
279 279 julian_to_date(time_jd, &time_year, &time_month, &time_day);
280 280
281 281 if (time_year < 1900 || time_year > 9999)
282 282 return 0;
283 283
284 284 /* Update tm structure */
285 285
286 286 tm->tm_year = time_year - 1900;
287 287 tm->tm_mon = time_month - 1;
288 288 tm->tm_mday = time_day;
289 289
290 290 tm->tm_hour = offset_hms / 3600;
291 291 tm->tm_min = (offset_hms / 60) % 60;
292 292 tm->tm_sec = offset_hms % 60;
293 293
294 294 return 1;
295 295
296 296 }
297 297
298 298 /* Convert date to and from julian day
299 299 * Uses Fliegel & Van Flandern algorithm
300 300 */
301 301 static long date_to_julian(int y, int m, int d)
302 302 {
303 303 return (1461 * (y + 4800 + (m - 14) / 12)) / 4 +
304 304 (367 * (m - 2 - 12 * ((m - 14) / 12))) / 12 -
305 305 (3 * ((y + 4900 + (m - 14) / 12) / 100)) / 4 +
306 306 d - 32075;
307 307 }
308 308
309 309 static void julian_to_date(long jd, int *y, int *m, int *d)
310 310 {
311 311 long L = jd + 68569;
312 312 long n = (4 * L) / 146097;
313 313 long i, j;
314 314
315 315 L = L - (146097 * n + 3) / 4;
316 316 i = (4000 * (L + 1)) / 1461001;
317 317 L = L - (1461 * i) / 4 + 31;
318 318 j = (80 * L) / 2447;
319 319 *d = L - (2447 * j) / 80;
320 320 L = j / 11;
321 321 *m = j + 2 - (12 * L);
322 322 *y = 100 * (n - 49) + i + L;
323 323 }
324 324
325 325 #ifdef OPENSSL_TIME_TEST
326 326
327 327 #include <stdio.h>
328 328
329 329 /* Time checking test code. Check times are identical for a wide range of
330 330 * offsets. This should be run on a machine with 64 bit time_t or it will
331 331 * trigger the very errors the routines fix.
332 332 */
333 333
334 334 int main(int argc, char **argv)
335 335 {
336 336 long offset;
337 337 for (offset = 0; offset < 1000000; offset++)
338 338 {
339 339 check_time(offset);
340 340 check_time(-offset);
341 341 check_time(offset * 1000);
342 342 check_time(-offset * 1000);
343 343 }
344 344 }
345 345
346 346 int check_time(long offset)
347 347 {
348 348 struct tm tm1, tm2;
349 349 time_t t1, t2;
350 350 time(&t1);
351 351 t2 = t1 + offset;
352 352 OPENSSL_gmtime(&t2, &tm2);
353 353 OPENSSL_gmtime(&t1, &tm1);
354 354 OPENSSL_gmtime_adj(&tm1, 0, offset);
355 355 if ((tm1.tm_year == tm2.tm_year) &&
356 356 (tm1.tm_mon == tm2.tm_mon) &&
357 357 (tm1.tm_mday == tm2.tm_mday) &&
358 358 (tm1.tm_hour == tm2.tm_hour) &&
359 359 (tm1.tm_min == tm2.tm_min) &&
360 360 (tm1.tm_sec == tm2.tm_sec))
361 361 return 1;
362 362 fprintf(stderr, "TIME ERROR!!\n");
363 363 fprintf(stderr, "Time1: %d/%d/%d, %d:%02d:%02d\n",
364 364 tm2.tm_mday, tm2.tm_mon + 1, tm2.tm_year + 1900,
365 365 tm2.tm_hour, tm2.tm_min, tm2.tm_sec);
366 366 fprintf(stderr, "Time2: %d/%d/%d, %d:%02d:%02d\n",
367 367 tm1.tm_mday, tm1.tm_mon + 1, tm1.tm_year + 1900,
368 368 tm1.tm_hour, tm1.tm_min, tm1.tm_sec);
369 369 return 0;
370 370 }
371 371
372 372 #endif
↓ open down ↓ |
298 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX