/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright (c) 1987-2000 by Sun Microsystems, Inc.
* All rights reserved.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Time management functions for auditreduce.
*/
#include "auditr.h"
#include <locale.h>
#include <libintl.h>
int derive_date(char *, struct tm *);
void derive_str(time_t, char *);
int parse_time(char *, int);
static int check_time(struct tm *);
static int days_in_year(int);
static char *do_invalid(void);
/*
* Array of days per month.
*/
static int days_month[] = {
31, 28, 31, 30, 31, 30,
31, 31, 30, 31, 30, 31 };
char *
do_invalid(void)
{
if (invalid_inter == NULL)
return (invalid_inter);
}
/*
* .func local_to_gm - local time to gm time.
* .desc Convert a local time to Greenwhich Mean Time.
* The local time is in the struct tm (time.h) format, which
* is easily got from an ASCII input format (10:30:33 Jan 3, 1983).
* It works by assuming that the given local time is a GMT time and
* then asking the system for the corresponding local time. It then
* takes the difference between those two as the correction for
* time zones and daylight savings time. This is accurate unless
* the time the user asked for is near a DST switch. Then a
* correction is applied - it is assumed that if we can produce
* a GMT that, when run through localtime(), is equivalent to the
* user's original input, we have an accurate GMT. The applied
* correction simply adjusts the GMT by the amount that the derived
* localtime was off. See?
* It should be noted that when there is DST there is one local hour
* a year when time occurs twice (in the fall) and one local hour a
* year when time never occurs (in the spring).
* memcpy() is used because the calls to gmtime() and localtime()
* return pointers to static structures that are overwritten at each
* call.
* .call ret = local_to_gm(tme).
* .arg tme - ptr to struct tm (see time.h) containing local time.
* .ret time_t - seconds since epoch of equivalent GMT.
*/
{
/*
* Get the input time in local and gmtime assuming the input
* was GMT (which it probably wasn't).
*/
/*
* Get the local and gmtime in seconds, from the above tm structures.
* Calculate difference between local and GMT.
*/
sizeof (ltime));
/*
* Now get a computed local time from the computed gmtime.
*/
save_gsecs = gsecs;
/*
* If the user given local time is != computed local time then
* we need to try a correction.
*/
/*
* Use the difference between give localtime and computed
* localtime as our correction.
*/
} else {
}
/*
* And try the comparison again...
*/
sizeof (ltime));
/*
* If the correction fails then we are on a DST line
* and the user-given local time never happened.
* Do the best we can.
*/
gsecs = save_gsecs;
}
}
return (gsecs);
}
/*
* .func tm_to_secs - convert to seconds.
* .desc Convert a tm time structure (time.h) into seconds since
* Jan 1, 1970 00:00:00. The time is assumed to be GMT and
* so no daylight savings time correction is applied. That
* is left up to the system calls (localtime(), gmtime()).
* .call ret = tm_to_secs(tme).
* .arg tme - ptr to tm structure.
* .ret time_t - number of seconds.
*/
{
int days = 0;
while (year > 1970) {
}
while (month > 0) {
days++;
}
}
return (num_sec);
}
/*
* .func check_time - check tm structure.
* .desc Check the time in a tm structure to see if all of the fields
* are within range.
* .call err = check_time(tme).
* .arg tme - ptr to struct tm (see time.h).
* .ret 0 - time is ok.
* .ret -1 - time had a problem (description in error_str).
*/
int
{
}
}
return (0);
else
return (-1);
}
/*
* .func parse_time.
* .desc Parse a user time from the command line. The user time is assumed
* to be local time.
* Supported formats currently are:
* 1. +xt - where x is a number and t is a type.
* types are - 's' second, 'm' minute, 'h' hour, and 'd' day.
* 2. yymmdd - yyyymmdd.
* yymmddhh - yyyymmddhh.
* yymmddhhmm - yyyymmddhhmm.
* yymmddhhmmss - yyyymmddhhmmss.
* .call err = parse_time(str, opt).
* .arg str - ptr to user input string.
* .arg opt - time option being processed.
* .ret 0 - succesful.
* .ret -1 - failure (error message in error_str).
*/
int
{
char *strxx;
long lnum;
/*
* If the strlen < 6 then in the "-b +2d" type of format.
*/
if (len < 6) {
if (*str++ != '+') {
do_invalid(), str);
return (-1);
}
if (opt != 'b') {
gettext("%s only allowed with 'b' option (%s)"),
do_invalid(), str);
return (-1);
}
if (m_after == 0) {
gettext("must have -a to use -b +nx form (%s)"),
str);
return (-1);
}
/*
* Find out what type of offset it is - 's' 'm' 'h' or 'd'.
* Make sure that the offset is all numbers.
*/
gettext("%s needs 'd', 'h', 'm', or 's' (%s)"),
do_invalid(), str);
return (-1);
} else {
*strxx = '\0';
}
gettext("%s non-numeric offset (%s)"),
do_invalid(), str);
return (-1);
}
factor = 60;
return (0);
}
/*
*/
return (-1);
/*
* For 'd' option clear out the hh:mm:ss to get to the start of the day.
* Then add one day's worth of seconds to get the 'b' time.
*/
if (opt == 'd') {
} else if (opt == 'a') {
} else if (opt == 'b') {
}
return (0);
}
/*
* .func derive_date.
* String is in one of these formats:
* [yy]yymmddhhmmss
* [yy]yymmddhhmm
* [yy]yymmddhh
* [yy]yymmdd
* .call ret = derive_date(str, tme).
* .arg str - ptr to input string.
* .arg tme - ptr to tm structure (time.h).
* .ret 0 - no errors in string.
* .ret -1 - errors in string (description in error_str).
*/
int
{
char *strs;
do_invalid(), str);
return (-1);
}
if (len % 2) {
do_invalid(), str);
return (-1);
}
/*
* May need larger string storage to add '19' or '20'.
*/
/*
* Get current time to see what century it is.
*/
sizeof (nowtime));
/*
* If the year does not begin with '19' or '20', then report
* an error and abort.
*/
return (-1);
}
return (-1);
}
/* unspecified values go to 0 */
}
}
}
}
/*
* .func derive_str - derive string.
* .desc Derive a string representation of a time for a filename.
* The output is in the 14 character format yyyymmddhhmmss.
* .call derive_str(clock, buf).
* .arg clock - seconds since epoch.
* .arg buf - place to put resultant string.
* .ret void.
*/
void
{
}
int
{
return (366);
return (365);
}