From 58734631b4233ec08b7a262587e400792f31f185 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 31 May 1996 15:13:29 +0000 Subject: Lots of changes! - add faq info on NT printer handling - add "delete readonly" option to help rcs users - add stuff to man pages on new printer options - add "proxy name resolution" option - add "command string" -c option to smbclient (thanks Ken) - split time functions into time.c - rearrange the quotas stuff a bit and fix some bugs - complete rehash of the time handling code thanks to Paul Eggert - fix nmblookup output a bit - add plp print queue parsing from Bertrand Wallrich (This used to be commit 635b56f19c817527c52e9bbde31faa6a8a47777b) --- source3/lib/time.c | 495 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 495 insertions(+) create mode 100644 source3/lib/time.c (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c new file mode 100644 index 0000000000..0b6e6df9b0 --- /dev/null +++ b/source3/lib/time.c @@ -0,0 +1,495 @@ +/* + Unix SMB/Netbios implementation. + Version 1.9. + time handling functions + Copyright (C) Andrew Tridgell 1992-1995 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + +/* + This stuff was largely rewritten by Paul Eggert + in May 1996 + */ + + +int serverzone=0; +int extra_time_offset = 0; + +extern int DEBUGLEVEL; + +#ifndef CHAR_BIT +#define CHAR_BIT 8 +#endif + +#ifndef TIME_T_MIN +#define TIME_T_MIN (0 < (time_t) -1 ? (time_t) 0 \ + : ~ (time_t) 0 << (sizeof (time_t) * CHAR_BIT - 1)) +#endif +#ifndef TIME_T_MAX +#define TIME_T_MAX (~ (time_t) 0 - TIME_T_MIN) +#endif + + + +/******************************************************************* +a gettimeofday wrapper +********************************************************************/ +void GetTimeOfDay(struct timeval *tval) +{ +#ifdef GETTIMEOFDAY1 + gettimeofday(tval); +#else + gettimeofday(tval,NULL); +#endif +} + +#define TM_YEAR_BASE 1900 + +/******************************************************************* +yield the difference between *A and *B, in seconds, ignoring leap seconds +********************************************************************/ +static int tm_diff(struct tm *a, struct tm *b) +{ + int ay = a->tm_year + (TM_YEAR_BASE - 1); + int by = b->tm_year + (TM_YEAR_BASE - 1); + int intervening_leap_days = + (ay/4 - by/4) - (ay/100 - by/100) + (ay/400 - by/400); + int years = ay - by; + int days = 365*years + intervening_leap_days + (a->tm_yday - b->tm_yday); + int hours = 24*days + (a->tm_hour - b->tm_hour); + int minutes = 60*hours + (a->tm_min - b->tm_min); + int seconds = 60*minutes + (a->tm_sec - b->tm_sec); + return seconds; +} + +/******************************************************************* + return the UTC offset in seconds west of UTC + ******************************************************************/ +static int TimeZone(time_t t) +{ + struct tm tm_utc = *(gmtime(&t)); + return tm_diff(&tm_utc,localtime(&t)); +} + + +/******************************************************************* +init the time differences +********************************************************************/ +void TimeInit(void) +{ + serverzone = TimeZone(time(NULL)); + DEBUG(4,("Serverzone is %d\n",serverzone)); +} + + +/******************************************************************* +return the same value as TimeZone, but it should be more efficient. + +We keep a table of DST offsets to prevent calling localtime() on each +call of this function. This saves a LOT of time on many unixes. + +Updated by Paul Eggert +********************************************************************/ +static int TimeZoneFaster(time_t t) +{ + static struct dst_table {time_t start,end; int zone;} *dst_table = NULL; + static int table_size = 0; + int i; + int zone = 0; + + if (t == 0) t = time(NULL); + + /* Tunis has a 8 day DST region, we need to be careful ... */ +#define MAX_DST_WIDTH (365*24*60*60) +#define MAX_DST_SKIP (7*24*60*60) + + for (i=0;i= dst_table[i].start && t <= dst_table[i].end) break; + + if (i MAX_DST_SKIP*2) + t = dst_table[i].start - MAX_DST_SKIP; + else + t = low + (dst_table[i].start-low)/2; + if (TimeZone(t) == zone) + dst_table[i].start = t; + else + low = t; + } + + high = low + MAX_DST_WIDTH/2; + if (high < t) + high = TIME_T_MAX; + + while (high-60*60 > dst_table[i].end) { + if (high - dst_table[i].end > MAX_DST_SKIP*2) + t = dst_table[i].end + MAX_DST_SKIP; + else + t = high - (high-dst_table[i].end)/2; + if (TimeZone(t) == zone) + dst_table[i].end = t; + else + high = t; + } +#if 0 + DEBUG(1,("Added DST entry from %s ", + asctime(localtime(&dst_table[i].start)))); + DEBUG(1,("to %s (%d)\n",asctime(localtime(&dst_table[i].end)), + dst_table[i].zone)); +#endif + } + } + return zone; +} + +/**************************************************************************** + return the UTC offset in seconds west of UTC, adjusted for extra time offset + **************************************************************************/ +int TimeDiff(time_t t) +{ + return TimeZoneFaster(t) + 60*extra_time_offset; +} + + +/**************************************************************************** + return the UTC offset in seconds west of UTC, adjusted for extra time + offset, for a local time value. If ut = lt + LocTimeDiff(lt), then + lt = ut - TimeDiff(ut), but the converse does not necessarily hold near + daylight savings transitions because some local times are ambiguous. + LocTimeDiff(t) equals TimeDiff(t) except near daylight savings transitions. + +**************************************************************************/ +static int LocTimeDiff(time_t lte) +{ + time_t lt = lte - 60*extra_time_offset; + int d = TimeZoneFaster(lt); + time_t t = lt + d; + + /* if overflow occurred, ignore all the adjustments so far */ + if (((lte < lt) ^ (extra_time_offset < 0)) | ((t < lt) ^ (d < 0))) + t = lte; + + /* now t should be close enough to the true UTC to yield the right answer */ + return TimeDiff(t); +} + + +/**************************************************************************** +try to optimise the localtime call, it can be quite expenive on some machines +****************************************************************************/ +struct tm *LocalTime(time_t *t) +{ + time_t t2 = *t; + + t2 -= TimeDiff(t2); + + return(gmtime(&t2)); +} + + +#define TIME_FIXUP_CONSTANT (369.0*365.25*24*60*60-(3.0*24*60*60+6.0*60*60)) + +/**************************************************************************** +interpret an 8 byte "filetime" structure to a time_t +It's originally in "100ns units since jan 1st 1601" + +It appears to be kludge-GMT (at least for file listings). This means +its the GMT you get by taking a localtime and adding the +serverzone. This is NOT the same as GMT in some cases. This routine +converts this to real GMT. +****************************************************************************/ +time_t interpret_long_date(char *p) +{ + double d; + time_t ret; + uint32 tlow,thigh; + tlow = IVAL(p,0); + thigh = IVAL(p,4); + + if (thigh == 0) return(0); + + d = ((double)thigh)*4.0*(double)(1<<30); + d += (tlow&0xFFF00000); + d *= 1.0e-7; + + /* now adjust by 369 years to make the secs since 1970 */ + d -= TIME_FIXUP_CONSTANT; + + if (!(TIME_T_MIN <= d && d <= TIME_T_MAX)) + return(0); + + ret = (time_t)(d+0.5); + + /* this takes us from kludge-GMT to real GMT */ + ret -= serverzone; + ret += LocTimeDiff(ret); + + return(ret); +} + + +/**************************************************************************** +put a 8 byte filetime from a time_t +This takes real GMT as input and converts to kludge-GMT +****************************************************************************/ +void put_long_date(char *p,time_t t) +{ + uint32 tlow,thigh; + double d; + + if (t==0) { + SIVAL(p,0,0); SIVAL(p,4,0); + return; + } + + /* this converts GMT to kludge-GMT */ + t -= TimeDiff(t) - serverzone; + + d = (double) (t); + + d += TIME_FIXUP_CONSTANT; + + d *= 1.0e7; + + thigh = (uint32)(d * (1.0/(4.0*(double)(1<<30)))); + tlow = (uint32)(d - ((double)thigh)*4.0*(double)(1<<30)); + + SIVAL(p,0,tlow); + SIVAL(p,4,thigh); +} + + +/**************************************************************************** +check if it's a null mtime +****************************************************************************/ +static BOOL null_mtime(time_t mtime) +{ + if (mtime == 0 || mtime == 0xFFFFFFFF || mtime == (time_t)-1) + return(True); + return(False); +} + +/******************************************************************* + create a 16 bit dos packed date +********************************************************************/ +static uint16 make_dos_date1(time_t unixdate,struct tm *t) +{ + uint16 ret=0; + ret = (((unsigned)(t->tm_mon+1)) >> 3) | ((t->tm_year-80) << 1); + ret = ((ret&0xFF)<<8) | (t->tm_mday | (((t->tm_mon+1) & 0x7) << 5)); + return(ret); +} + +/******************************************************************* + create a 16 bit dos packed time +********************************************************************/ +static uint16 make_dos_time1(time_t unixdate,struct tm *t) +{ + uint16 ret=0; + ret = ((((unsigned)t->tm_min >> 3)&0x7) | (((unsigned)t->tm_hour) << 3)); + ret = ((ret&0xFF)<<8) | ((t->tm_sec/2) | ((t->tm_min & 0x7) << 5)); + return(ret); +} + +/******************************************************************* + create a 32 bit dos packed date/time from some parameters + This takes a GMT time and returns a packed localtime structure +********************************************************************/ +static uint32 make_dos_date(time_t unixdate) +{ + struct tm *t; + uint32 ret=0; + + t = LocalTime(&unixdate); + + ret = make_dos_date1(unixdate,t); + ret = ((ret&0xFFFF)<<16) | make_dos_time1(unixdate,t); + + return(ret); +} + +/******************************************************************* +put a dos date into a buffer (time/date format) +This takes GMT time and puts local time in the buffer +********************************************************************/ +void put_dos_date(char *buf,int offset,time_t unixdate) +{ + uint32 x = make_dos_date(unixdate); + SIVAL(buf,offset,x); +} + +/******************************************************************* +put a dos date into a buffer (date/time format) +This takes GMT time and puts local time in the buffer +********************************************************************/ +void put_dos_date2(char *buf,int offset,time_t unixdate) +{ + uint32 x = make_dos_date(unixdate); + x = ((x&0xFFFF)<<16) | ((x&0xFFFF0000)>>16); + SIVAL(buf,offset,x); +} + +/******************************************************************* +put a dos 32 bit "unix like" date into a buffer. This routine takes +GMT and converts it to LOCAL time before putting it (most SMBs assume +localtime for this sort of date) +********************************************************************/ +void put_dos_date3(char *buf,int offset,time_t unixdate) +{ + if (!null_mtime(unixdate)) + unixdate -= TimeDiff(unixdate); + SIVAL(buf,offset,unixdate); +} + +/******************************************************************* + interpret a 32 bit dos packed date/time to some parameters +********************************************************************/ +static void interpret_dos_date(uint32 date,int *year,int *month,int *day,int *hour,int *minute,int *second) +{ + uint32 p0,p1,p2,p3; + + p0=date&0xFF; p1=((date&0xFF00)>>8)&0xFF; + p2=((date&0xFF0000)>>16)&0xFF; p3=((date&0xFF000000)>>24)&0xFF; + + *second = 2*(p0 & 0x1F); + *minute = ((p0>>5)&0xFF) + ((p1&0x7)<<3); + *hour = (p1>>3)&0xFF; + *day = (p2&0x1F); + *month = ((p2>>5)&0xFF) + ((p3&0x1)<<3) - 1; + *year = ((p3>>1)&0xFF) + 80; +} + +/******************************************************************* + create a unix date (int GMT) from a dos date (which is actually in + localtime) +********************************************************************/ +time_t make_unix_date(void *date_ptr) +{ + uint32 dos_date=0; + struct tm t; + time_t ret; + + dos_date = IVAL(date_ptr,0); + + if (dos_date == 0) return(0); + + interpret_dos_date(dos_date,&t.tm_year,&t.tm_mon, + &t.tm_mday,&t.tm_hour,&t.tm_min,&t.tm_sec); + t.tm_isdst = -1; + + /* mktime() also does the local to GMT time conversion for us */ + ret = mktime(&t); + + return(ret); +} + +/******************************************************************* +like make_unix_date() but the words are reversed +********************************************************************/ +time_t make_unix_date2(void *date_ptr) +{ + uint32 x,x2; + + x = IVAL(date_ptr,0); + x2 = ((x&0xFFFF)<<16) | ((x&0xFFFF0000)>>16); + SIVAL(&x,0,x2); + + return(make_unix_date((void *)&x)); +} + +/******************************************************************* + create a unix GMT date from a dos date in 32 bit "unix like" format + these generally arrive as localtimes, with corresponding DST + ******************************************************************/ +time_t make_unix_date3(void *date_ptr) +{ + time_t t = IVAL(date_ptr,0); + if (!null_mtime(t)) + t += LocTimeDiff(t); + return(t); +} + +/**************************************************************************** +set the time on a file +****************************************************************************/ +BOOL set_filetime(char *fname,time_t mtime) +{ + struct utimbuf times; + + if (null_mtime(mtime)) return(True); + + times.modtime = times.actime = mtime; + + if (sys_utime(fname,×)) { + DEBUG(4,("set_filetime(%s) failed: %s\n",fname,strerror(errno))); + } + + return(True); +} + + +/**************************************************************************** + return the date and time as a string +****************************************************************************/ +char *timestring(void ) +{ + static char TimeBuf[100]; + time_t t = time(NULL); + struct tm *tm = LocalTime(&t); + +#ifdef NO_STRFTIME + strcpy(TimeBuf, asctime(tm)); +#elif defined(CLIX) || defined(CONVEX) + strftime(TimeBuf,100,"%m/%d/%y %I:%M:%S %p",tm); +#elif defined(AMPM) + strftime(TimeBuf,100,"%D %r",tm); +#elif defined(TZ_TIME) + { + int zone = TimeDiff(t); + int absZoneMinutes = (zone<0 ? -zone : zone) / 60; + size_t len = strftime(TimeBuf,sizeof(TimeBuf)-6,"%D %T",tm); + sprintf(TimeBuf+len," %c%02d%02d", + zone<0?'+':'-',absZoneMinutes/60,absZoneMinutes%60); + } +#else + strftime(TimeBuf,100,"%D %T",tm); +#endif + return(TimeBuf); +} + -- cgit From b9ae225b28f4707609e6436dad4be7ebdd7e181f Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 6 Jun 1996 11:43:09 +0000 Subject: - added interface.c and removed all the references to myip, bcast_ip and Netmask, instead replacing them with calls to routines in interface.c - got rid of old MAXINT define - added code to ensure we only return one entry for each name in the ipc enum routines - added new_only option to add_netbios_entry() to prevent overwriting of important names - minor time handling fixup (This used to be commit 7ed71b73ae745da099072eee36fc2700d1d91407) --- source3/lib/time.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index 0b6e6df9b0..efcda804c4 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -142,6 +142,10 @@ static int TimeZoneFaster(time_t t) if (t < low) low = TIME_T_MIN; + high = t + MAX_DST_WIDTH/2; + if (high < t) + high = TIME_T_MAX; + /* widen the new entry using two bisection searches */ while (low+60*60 < dst_table[i].start) { if (dst_table[i].start - low > MAX_DST_SKIP*2) @@ -154,10 +158,6 @@ static int TimeZoneFaster(time_t t) low = t; } - high = low + MAX_DST_WIDTH/2; - if (high < t) - high = TIME_T_MAX; - while (high-60*60 > dst_table[i].end) { if (high - dst_table[i].end > MAX_DST_SKIP*2) t = dst_table[i].end + MAX_DST_SKIP; -- cgit From 89f6150ffec4b4215ecddd764269bda325c7147b Mon Sep 17 00:00:00 2001 From: Samba Release Account Date: Fri, 7 Mar 1997 17:22:27 +0000 Subject: Fix fro signed/unsigned problem with TIME_T_MIN from Anatoly V. Grabar jra@cygnus.com (This used to be commit ed7e3a9347c93cf5736132f93d43472a3809c80e) --- source3/lib/time.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index efcda804c4..215c28a210 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -37,7 +37,7 @@ extern int DEBUGLEVEL; #endif #ifndef TIME_T_MIN -#define TIME_T_MIN (0 < (time_t) -1 ? (time_t) 0 \ +#define TIME_T_MIN ((time_t)0 < (time_t) -1 ? (time_t) 0 \ : ~ (time_t) 0 << (sizeof (time_t) * CHAR_BIT - 1)) #endif #ifndef TIME_T_MAX -- cgit From 0f1f0ceb9519368188f695e18e2341ccfd1b2d15 Mon Sep 17 00:00:00 2001 From: Samba Release Account Date: Thu, 8 May 1997 01:14:17 +0000 Subject: 'The mother of all checkins' :-). Jeremy Allison (jallison@whistle.com) Wed May 7 1997: Update for 1.9.17alpha1 release - 'browsefix release' designed to make browsing across subnets work. byteorder.h: Updated copyright to 1997. charcnv.c: Updated copyright to 1997. charset.c Updated copyright to 1997. charset.h Updated copyright to 1997. client.c Updated copyright to 1997. clientutil.c Updated copyright to 1997. dir.c Updated copyright to 1997. fault.c Updated copyright to 1997. includes.h Updated copyright to 1997. interface.c Updated copyright to 1997. ipc.c Updated copyright to 1997. kanji.c Updated copyright to 1997. kanji.h Updated copyright to 1997. loadparm.c Updated copyright to 1997. locking.c Updated copyright to 1997. mangle.c Updated copyright to 1997. message.c Updated copyright to 1997. nameannounce.c Made use of WINS subnet explicit. Added reset_announce_timer() so announcement can be made immediately when we become a master. Expanded code to do sync with dmb. namebrowse.c Removed redundent checks for AM_MASTER in sync code. Made use of WINS subnet explicit. namedbname.c Made use of WINS subnet explicit. namedbresp.c Made use of WINS subnet explicit. namedbserver.c Made use of WINS subnet explicit. namedbsubnet.c Explicitly add workgroup to WINS subnet when we become a dmb. Made use of WINS subnet explicit. namedbwork.c Made use of WINS subnet explicit. Removed redundent check_work_servertype() function. nameelect.c Explicitly add workgroup to WINS subnet when we become a master browser. Made use of WINS subnet explicit. namelogon.c Updated copyright to 1997. namepacket.c Updated copyright to 1997. namequery.c Updated copyright to 1997. nameresp.c Made use of WINS subnet explicit. Made nmbd fail if configured as master browser and one exists already. nameserv.c Made use of WINS subnet explicit. Remove redundent logon server and domain master code. nameserv.h Add emumerate subnet macros. nameservreply.c Made use of WINS subnet explicit. nameservresp.c Updated copyright to 1997. namework.c Made use of WINS subnet explicit. Updated code to add sync browser entries to add subnet parameter. nmbd.c Added sanity check for misconfigured nmbd. nmblib.c Updated copyright to 1997. nmblookup.c Updated copyright to 1997. nmbsync.c Removed redundent AM_ANY_MASTER check. params.c Updated copyright to 1997. password.c Updated copyright to 1997. pipes.c Updated copyright to 1997. predict.c Updated copyright to 1997. printing.c Updated copyright to 1997. proto.h Changed protos for new nmbd code. quotas.c Updated copyright to 1997. replace.c Updated copyright to 1997. reply.c Updated copyright to 1997. server.c Updated copyright to 1997. shmem.c Updated copyright to 1997. smb.h Updated copyright to 1997. smbencrypt.c Updated copyright to 1997. smbpasswd.c Updated copyright to 1997. smbrun.c Updated copyright to 1997. status.c Updated copyright to 1997. system.c Updated copyright to 1997. testparm.c Updated copyright to 1997. testprns.c Updated copyright to 1997. time.c Updated copyright to 1997. trans2.c Updated copyright to 1997. trans2.h Updated copyright to 1997. uid.c Updated copyright to 1997. username.c Updated copyright to 1997. util.c Updated copyright to 1997. version.h Changed to 1.9.17alpha1. (This used to be commit cf23a155a1315f50d488794a2caf88402bf3e3e6) --- source3/lib/time.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index 215c28a210..d16552b61e 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -2,7 +2,7 @@ Unix SMB/Netbios implementation. Version 1.9. time handling functions - Copyright (C) Andrew Tridgell 1992-1995 + Copyright (C) Andrew Tridgell 1992-1997 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by -- cgit From cef59090bb2fd3f8a9efd1a453cb90264b891d58 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 26 Sep 1997 18:55:29 +0000 Subject: Adding Andrews buffer overflow fixes into the main branch. Jeremy (jallison@whistle.com) (This used to be commit e7eb1f044d3101679dc7a118820ea5efe0cd837c) --- source3/lib/time.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index d16552b61e..4f688d2214 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -469,12 +469,12 @@ BOOL set_filetime(char *fname,time_t mtime) ****************************************************************************/ char *timestring(void ) { - static char TimeBuf[100]; + static fstring TimeBuf; time_t t = time(NULL); struct tm *tm = LocalTime(&t); #ifdef NO_STRFTIME - strcpy(TimeBuf, asctime(tm)); + fstrcpy(TimeBuf, asctime(tm)); #elif defined(CLIX) || defined(CONVEX) strftime(TimeBuf,100,"%m/%d/%y %I:%M:%S %p",tm); #elif defined(AMPM) -- cgit From 79f4fb52c1ed56fd843f81b4eb0cdd2991d4d0f4 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 20 Oct 1997 18:52:04 +0000 Subject: loadparm.c: Changed 'interfaces only' parameter to 'bind interfaces only'. Added 'dos filetimes' parameter for UTIME fix. locking_shm.c: Fixed typo (sorry Andrew :-). namepacket.c: Changed lp_interfaces_only() to lp_bind_interfaces_only(). proto.h: The usual. reply.c: Made filetime calls use new file_utime call (wrapper for sys_utime). server.c: Made filetime calls use new file_utime call (wrapper for sys_utime). system.c: Added Andrew's sanity checks to times in sys_utime(). time.c: Moved set_filetime() to server.c. Made null_mtime() global. trans2.c: Made filetime calls use new file_utime call (wrapper for sys_utime). Jeremy (jallison@whistle.com) (This used to be commit 41a1d81c112a82ad2ae1b3c4ee81051f133ce1ed) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source3/lib/time.c | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index 4f688d2214..ad6b04484c 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -298,7 +298,7 @@ void put_long_date(char *p,time_t t) /**************************************************************************** check if it's a null mtime ****************************************************************************/ -static BOOL null_mtime(time_t mtime) +BOOL null_mtime(time_t mtime) { if (mtime == 0 || mtime == 0xFFFFFFFF || mtime == (time_t)-1) return(True); @@ -445,25 +445,6 @@ time_t make_unix_date3(void *date_ptr) return(t); } -/**************************************************************************** -set the time on a file -****************************************************************************/ -BOOL set_filetime(char *fname,time_t mtime) -{ - struct utimbuf times; - - if (null_mtime(mtime)) return(True); - - times.modtime = times.actime = mtime; - - if (sys_utime(fname,×)) { - DEBUG(4,("set_filetime(%s) failed: %s\n",fname,strerror(errno))); - } - - return(True); -} - - /**************************************************************************** return the date and time as a string ****************************************************************************/ -- cgit From 3670f3d9c0f1f96995eef8113fd9b433789ef844 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 6 Nov 1997 13:45:50 +0000 Subject: change from %D to %m/%d/%Y in timestring(). This doesn't really matter as it is only for logging but it will prevent people from writing in to say that we are not y2k compliant after running auto-diagnostic tests. (This used to be commit b4e55cd4765085fc2465c6ff757094e05eabc51e) --- source3/lib/time.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index ad6b04484c..4eb508115d 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -457,19 +457,19 @@ char *timestring(void ) #ifdef NO_STRFTIME fstrcpy(TimeBuf, asctime(tm)); #elif defined(CLIX) || defined(CONVEX) - strftime(TimeBuf,100,"%m/%d/%y %I:%M:%S %p",tm); + strftime(TimeBuf,100,"%m/%d/%Y %I:%M:%S %p",tm); #elif defined(AMPM) - strftime(TimeBuf,100,"%D %r",tm); + strftime(TimeBuf,100,"%m/%d/%Y %r",tm); #elif defined(TZ_TIME) { int zone = TimeDiff(t); int absZoneMinutes = (zone<0 ? -zone : zone) / 60; - size_t len = strftime(TimeBuf,sizeof(TimeBuf)-6,"%D %T",tm); + size_t len = strftime(TimeBuf,sizeof(TimeBuf)-6,"%m/%d/%Y %T",tm); sprintf(TimeBuf+len," %c%02d%02d", zone<0?'+':'-',absZoneMinutes/60,absZoneMinutes%60); } #else - strftime(TimeBuf,100,"%D %T",tm); + strftime(TimeBuf,100,"%m/%d/%Y %T",tm); #endif return(TimeBuf); } -- cgit From e8f3f79aa583bfe2996ae62bc899913275311281 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 21 Nov 1997 04:57:37 +0000 Subject: use LocTimeDiff() not TimeDiff() to ensure that longdate conversion is consistent (this is really just a cosmetic change) (This used to be commit 30b84bb68bfbfb022decc36c1b4869a39a06e556) --- source3/lib/time.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index 4eb508115d..bab80ad621 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -74,6 +74,7 @@ static int tm_diff(struct tm *a, struct tm *b) int hours = 24*days + (a->tm_hour - b->tm_hour); int minutes = 60*hours + (a->tm_min - b->tm_min); int seconds = 60*minutes + (a->tm_sec - b->tm_sec); + return seconds; } @@ -279,7 +280,7 @@ void put_long_date(char *p,time_t t) } /* this converts GMT to kludge-GMT */ - t -= TimeDiff(t) - serverzone; + t -= LocTimeDiff(t) - serverzone; d = (double) (t); -- cgit From 2b8247dd09124650cce41f06f9aeb2ac89862d0b Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 3 Dec 1997 03:46:43 +0000 Subject: add a warning if the timezone is not a multiple of 1 minute. This should catch broken timezone files in slackware linux. (This used to be commit ce37bd9dcaeaf0c5e97845954342762ebaf43b10) --- source3/lib/time.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index bab80ad621..5fc6595b6f 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -94,6 +94,11 @@ init the time differences void TimeInit(void) { serverzone = TimeZone(time(NULL)); + + if ((serverzone % 60) != 0) { + DEBUG(1,("WARNING: Your timezone is not a multiple of 1 minute.\n")); + } + DEBUG(4,("Serverzone is %d\n",serverzone)); } -- cgit From 55f400bd84f26027f5ec9b7fa06b22895de7557c Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 22 Jan 1998 13:27:43 +0000 Subject: This is *not* a big change (although it looks like one). This is merely updating the Copyright statements from 1997 to 1998. It's a once a year thing :-). NO OTHER CHANGES WERE MADE. Jeremy. (This used to be commit b9c16977231efb274e08856f7f3f4408dad6d96c) --- source3/lib/time.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index 5fc6595b6f..5e6d01215f 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -2,7 +2,7 @@ Unix SMB/Netbios implementation. Version 1.9. time handling functions - Copyright (C) Andrew Tridgell 1992-1997 + Copyright (C) Andrew Tridgell 1992-1998 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by -- cgit From 4f650dab6f867bda2beeeda71b2b97e75834853f Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 24 Jan 1998 08:49:21 +0000 Subject: Added get_create_time() function to time.c. This gets the minimum timestamp associated with a file. reply.c and trans2.c then return this as the create time. Designed to fix problems with VC++ and others. Jeremy. (This used to be commit e3d5f6196d6eff707c78941696a368216e2a7410) --- source3/lib/time.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index 5e6d01215f..f60af60c7a 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -480,3 +480,22 @@ char *timestring(void ) return(TimeBuf); } +/**************************************************************************** + return the best approximation to a 'create time' under UNIX from a stat + structure. +****************************************************************************/ + +time_t get_create_time(struct stat *st) +{ + time_t ret = MIN(st->st_ctime, st->st_mtime); + time_t ret1 = MIN(ret, st->st_atime); + + if(ret1 != (time_t)0) + return ret1; + + /* + * One of ctime, mtime or atime was zero (probably atime). + * Just return MIN(ctime, mtime). + */ + return ret; +} -- cgit From 5546e28e69b1a43dbb48e024e233d8ebf7fa667a Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 7 Feb 1998 12:15:20 +0000 Subject: A small raft of changes, I will sync up with 1.9.18 also. chgpasswd.c: Fixed typo in debug message. includes.h: Fix include for aix. kanji.c: Added cap_to_sj as inverse of sj_to_cap. loadparm.c: local.h: password.c: Added code for "networkstation user login" parameter. - patch from Rob Nielsen . printing.c: Added further aix printing fixes. reply.c: Changed access time fetch to a function. trans2.c: Changed access time fetch to a function. time.c: Changed access time fetch to a function. server.c: Made NT redirector workaround final. util.c: Added debug for write_socket failing. Jeremy. (This used to be commit a031404623c22d62f8de035be2239f609af08112) --- source3/lib/time.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index f60af60c7a..62a7016994 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -499,3 +499,14 @@ time_t get_create_time(struct stat *st) */ return ret; } + +/**************************************************************************** + return the 'access time' under UNIX from a stat structure. + This function exists to allow modifications to be done depending + on what we want to return. Just return the normal atime (for now). +****************************************************************************/ + +time_t get_access_time(struct stat *st) +{ + return st->st_atime; +} -- cgit From 99e11e171e40703271ad2a7934708cee66b0bb82 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 11 Feb 1998 11:07:14 +0000 Subject: Makefile: Added AIX 3.2.5. loadparm.c: Added "win95 bug compatibility" parameter. local.h: Replaced MAX_OPEN_FILES back to 100 from 10 (oops). reply.c: Fixed ulogoff check against uid - changed to vuid. server.c: Changed file struct save of uid - changed to vuid. smb.h: Changed id in struct current_user to vuid. Changed file struct uid to vuid. time.c: Added "win95 bug compatibility" atime -> mtime return. trans2.c: Added "win95 bug compatibility" fixes. uid.c: Changed id in struct current_user to vuid - added checks to set/reset it. util.c: Added code to expand environment variables. version.h : still at 1.9.18 (head branch doesn't matter too much at present). Jeremy. (This used to be commit adc903bcf59ad1664babd7f1d43675d3a75bfbc9) --- source3/lib/time.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index 62a7016994..81e3dcfd8f 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -508,5 +508,8 @@ time_t get_create_time(struct stat *st) time_t get_access_time(struct stat *st) { - return st->st_atime; + if (lp_win95_bug_compatibility()) + return st->st_mtime; + else + return st->st_atime; } -- cgit From 2beada804a238534628398f62fe4ed9e8d2c3efd Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 13 Feb 1998 07:11:58 +0000 Subject: Ding-dong the witch is dead, the witch is dead...... This is the checkin that fixes the infamous Visual C++ 'file has changed' bug. I feel *SO* good about that :-). charset.c: Added (void) to fix Herb's fussy compiler. loadparm.c: Removed "win95 bug compatibility" (didn't like it much anyway :-). Added "dos filetime resolution" instead. reply.c: Added the 2 second timestamp resolution fix that the song above is about. time.c: Removed unneeded get_access_time() function. trans2.c : Removed unneeded "win95 bug compatibility" code. Jeremy. (This used to be commit 10d628e4aeaecc573de27e251fec7b91844cba40) --- source3/lib/time.c | 14 -------------- 1 file changed, 14 deletions(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index 81e3dcfd8f..f60af60c7a 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -499,17 +499,3 @@ time_t get_create_time(struct stat *st) */ return ret; } - -/**************************************************************************** - return the 'access time' under UNIX from a stat structure. - This function exists to allow modifications to be done depending - on what we want to return. Just return the normal atime (for now). -****************************************************************************/ - -time_t get_access_time(struct stat *st) -{ - if (lp_win95_bug_compatibility()) - return st->st_mtime; - else - return st->st_atime; -} -- cgit From 49a5dd09b9aaba81fa217c9d41fce5e1f90c054b Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Mar 1998 04:56:58 +0000 Subject: added Date and Expires headers in the mini web server so clients know what they can cache. (This used to be commit b6055e40bb91775a29b756640d95910a6f19814f) --- source3/lib/time.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index f60af60c7a..c5584fd143 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -451,6 +451,21 @@ time_t make_unix_date3(void *date_ptr) return(t); } + +/*************************************************************************** +return a HTTP/1.0 time string + ***************************************************************************/ +char *http_timestring(time_t t) +{ + static char buf[40]; + struct tm *tm = LocalTime(&t); + + strftime(buf, sizeof(buf)-1, "%a, %d %b %Y %H:%M:%S %Z", tm); + return buf; +} + + + /**************************************************************************** return the date and time as a string ****************************************************************************/ -- cgit From c54af0f8b20e3f93c59da6a817920e1de6c4a870 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 16 Mar 1998 20:59:47 +0000 Subject: Adding the same change as was added to 1.9.18 branch to add the "name resolve order" parameter. source/Makefile: Re-ordered link for name resolve order code. source/clientgen.c: source/clientutil.c: Added calls to resolve_name(). source/includes.h: Added HPUX zombie fix. source/loadparm.c: Added new name resolve order parameter. source/namequery.c: Re-wrote to include parsing of lmhosts file, new resolve_name() function requested by John. source/nmbd.c: Tell resolve_name not to do WINS lookups if we are the WINS server. source/nmbd_lmhosts.c: Call lmhosts parsing functions in namequery.c source/password.c: Call resolve_name() to lookup security=server name. source/reply.c: source/time.c: source/trans2.c: "fake directory create times" fix from Jim Hague - hague@research.canon.com.au. source/util.c: Removed isalnum() test in Get_Hostname() that seems to cause problems on many systems. Jeremy. (This used to be commit 7f118970da7c43eaddcf92dc056d3e849f1e7d5c) --- source3/lib/time.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index c5584fd143..050b4725a7 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -500,10 +500,15 @@ char *timestring(void ) structure. ****************************************************************************/ -time_t get_create_time(struct stat *st) +time_t get_create_time(struct stat *st,BOOL fake_dirs) { - time_t ret = MIN(st->st_ctime, st->st_mtime); - time_t ret1 = MIN(ret, st->st_atime); + time_t ret, ret1; + + if(S_ISDIR(st->st_mode) && fake_dirs) + return (time_t)315493200L; /* 1/1/1980 */ + + ret = MIN(st->st_ctime, st->st_mtime); + ret1 = MIN(ret, st->st_atime); if(ret1 != (time_t)0) return ret1; -- cgit From 612cbb6a6039c2cafb3de5e644f23a2a26d6c645 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 2 Apr 1998 01:01:24 +0000 Subject: Patch from Chris Maltby . His comments follow: + improvement to smbtar to allow exclusion/inclusion of system and hidden files, and to generate a listing of what has been archived in a format useful for automated backup systems. + add the "Softq" spooling system to samba's printing capabilities. + I have "fixed" the intrusion of US style dates into samba reporting as well. The format yyyy/mm/dd is not only uunambiguous, but also has the benefit of making lexicographic sorts work correctly. Jeremy. (This used to be commit f9dacd1d8b89fccad859c0c6bc7a492823eb4b06) --- source3/lib/time.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index 050b4725a7..716f5d62cc 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -478,19 +478,19 @@ char *timestring(void ) #ifdef NO_STRFTIME fstrcpy(TimeBuf, asctime(tm)); #elif defined(CLIX) || defined(CONVEX) - strftime(TimeBuf,100,"%m/%d/%Y %I:%M:%S %p",tm); + strftime(TimeBuf,100,"%Y/%m/%d %I:%M:%S %p",tm); #elif defined(AMPM) - strftime(TimeBuf,100,"%m/%d/%Y %r",tm); + strftime(TimeBuf,100,"%Y/%m/%d %r",tm); #elif defined(TZ_TIME) { int zone = TimeDiff(t); int absZoneMinutes = (zone<0 ? -zone : zone) / 60; - size_t len = strftime(TimeBuf,sizeof(TimeBuf)-6,"%m/%d/%Y %T",tm); + size_t len = strftime(TimeBuf,sizeof(TimeBuf)-6,"%Y/%m/%d %T",tm); sprintf(TimeBuf+len," %c%02d%02d", zone<0?'+':'-',absZoneMinutes/60,absZoneMinutes%60); } #else - strftime(TimeBuf,100,"%m/%d/%Y %T",tm); + strftime(TimeBuf,100,"%Y/%m/%d %T",tm); #endif return(TimeBuf); } -- cgit From f888868f46a5418bac9ab528497136c152895305 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 12 May 1998 00:55:32 +0000 Subject: This is a security audit change of the main source. It removed all ocurrences of the following functions : sprintf strcpy strcat The replacements are slprintf, safe_strcpy and safe_strcat. It should not be possible to use code in Samba that uses sprintf, strcpy or strcat, only the safe_equivalents. Once Andrew has fixed the slprintf implementation then this code will be moved back to the 1.9.18 code stream. Jeremy. (This used to be commit 2d774454005f0b54e5684cf618da7060594dfcbb) --- source3/lib/time.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index 716f5d62cc..f5c40f0ba0 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -486,7 +486,7 @@ char *timestring(void ) int zone = TimeDiff(t); int absZoneMinutes = (zone<0 ? -zone : zone) / 60; size_t len = strftime(TimeBuf,sizeof(TimeBuf)-6,"%Y/%m/%d %T",tm); - sprintf(TimeBuf+len," %c%02d%02d", + slprintf(TimeBuf+len, sizeof(fstring) - len - 1, " %c%02d%02d", zone<0?'+':'-',absZoneMinutes/60,absZoneMinutes%60); } #else -- cgit From 3c77f88d455ca10ec406d3afdb68dcdf458c8760 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 29 May 1998 19:18:43 +0000 Subject: Added Paul Eggerts LocalTime patch. Jeremy. (This used to be commit 6721c28ea6bdb5210836352bb5ffc43d787907fa) --- source3/lib/time.c | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index f5c40f0ba0..1b2347a45b 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -79,12 +79,20 @@ static int tm_diff(struct tm *a, struct tm *b) } /******************************************************************* - return the UTC offset in seconds west of UTC + return the UTC offset in seconds west of UTC, or 0 if it cannot be determined ******************************************************************/ static int TimeZone(time_t t) { - struct tm tm_utc = *(gmtime(&t)); - return tm_diff(&tm_utc,localtime(&t)); + struct tm *tm = gmtime(&t); + struct tm tm_utc; + if (!tm) + return 0; + tm_utc = *tm; + tm = localtime(&t); + if (!tm) + return 0; + return tm_diff(&tm_utc,tm); + } @@ -217,7 +225,7 @@ static int LocTimeDiff(time_t lte) /**************************************************************************** -try to optimise the localtime call, it can be quite expenive on some machines +try to optimise the localtime call, it can be quite expensive on some machines ****************************************************************************/ struct tm *LocalTime(time_t *t) { @@ -343,6 +351,8 @@ static uint32 make_dos_date(time_t unixdate) uint32 ret=0; t = LocalTime(&unixdate); + if (!t) + return 0xFFFFFFFF; ret = make_dos_date1(unixdate,t); ret = ((ret&0xFFFF)<<16) | make_dos_time1(unixdate,t); @@ -457,11 +467,18 @@ return a HTTP/1.0 time string ***************************************************************************/ char *http_timestring(time_t t) { - static char buf[40]; - struct tm *tm = LocalTime(&t); + static fstring buf; + struct tm *tm = LocalTime(&t); - strftime(buf, sizeof(buf)-1, "%a, %d %b %Y %H:%M:%S %Z", tm); - return buf; + if (!tm) + slprintf(buf,sizeof(buf)-1,"%ld seconds since the Epoch",(long)t); + else +#ifdef NO_STRFTIME + fstrcpy(buf, asctime(tm)); +#else /* NO_STRFTIME */ + strftime(buf, sizeof(buf)-1, "%a, %d %b %Y %H:%M:%S %Z", tm); +#endif /* NO_STRFTIME */ + return buf; } @@ -475,6 +492,9 @@ char *timestring(void ) time_t t = time(NULL); struct tm *tm = LocalTime(&t); + if (!tm) + slprintf(TimeBuf,sizeof(TimeBuf)-1,"%ld seconds since the Epoch",(long)t); + else #ifdef NO_STRFTIME fstrcpy(TimeBuf, asctime(tm)); #elif defined(CLIX) || defined(CONVEX) -- cgit From 1829528d1fb2b87c726341aaf8d69d1190f83d6b Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 30 Jun 1998 21:19:40 +0000 Subject: nttrans.c: More code towards NT protocol. smb.h: More code towards NT protocol. time.c: Fix for sco bug. Jeremy. (This used to be commit e53f4396ead540bcf9ecd18f3253e49216404a1b) --- source3/lib/time.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index 1b2347a45b..c73d219120 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -253,9 +253,13 @@ time_t interpret_long_date(char *p) double d; time_t ret; uint32 tlow,thigh; + /* The next two lines are a fix needed for the + broken SCO compiler. JRA. */ + time_t l_time_min = TIME_T_MIN; + time_t l_time_max = TIME_T_MAX; + tlow = IVAL(p,0); thigh = IVAL(p,4); - if (thigh == 0) return(0); d = ((double)thigh)*4.0*(double)(1<<30); @@ -265,7 +269,7 @@ time_t interpret_long_date(char *p) /* now adjust by 369 years to make the secs since 1970 */ d -= TIME_FIXUP_CONSTANT; - if (!(TIME_T_MIN <= d && d <= TIME_T_MAX)) + if (!(l_time_min <= d && d <= l_time_max)) return(0); ret = (time_t)(d+0.5); -- cgit From 64578c0589a3a741f81fb55c16eeb882128da00b Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 29 Jul 1998 03:08:05 +0000 Subject: merge from the autoconf2 branch to the main branch (This used to be commit 3bda7ac417107a7b01d91805ca71c4330657ed21) --- source3/lib/time.c | 47 ++++++++++++++++++----------------------------- 1 file changed, 18 insertions(+), 29 deletions(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index c73d219120..6eacf2a5ed 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -51,10 +51,10 @@ a gettimeofday wrapper ********************************************************************/ void GetTimeOfDay(struct timeval *tval) { -#ifdef GETTIMEOFDAY1 - gettimeofday(tval); +#ifdef HAVE_GETTIMEOFDAY_TZ + gettimeofday(tval,NULL); #else - gettimeofday(tval,NULL); + gettimeofday(tval); #endif } @@ -477,11 +477,11 @@ char *http_timestring(time_t t) if (!tm) slprintf(buf,sizeof(buf)-1,"%ld seconds since the Epoch",(long)t); else -#ifdef NO_STRFTIME +#ifndef HAVE_STRFTIME fstrcpy(buf, asctime(tm)); -#else /* NO_STRFTIME */ +#else /* !HAVE_STRFTIME */ strftime(buf, sizeof(buf)-1, "%a, %d %b %Y %H:%M:%S %Z", tm); -#endif /* NO_STRFTIME */ +#endif /* !HAVE_STRFTIME */ return buf; } @@ -492,31 +492,20 @@ char *http_timestring(time_t t) ****************************************************************************/ char *timestring(void ) { - static fstring TimeBuf; - time_t t = time(NULL); - struct tm *tm = LocalTime(&t); - - if (!tm) - slprintf(TimeBuf,sizeof(TimeBuf)-1,"%ld seconds since the Epoch",(long)t); - else -#ifdef NO_STRFTIME - fstrcpy(TimeBuf, asctime(tm)); -#elif defined(CLIX) || defined(CONVEX) - strftime(TimeBuf,100,"%Y/%m/%d %I:%M:%S %p",tm); -#elif defined(AMPM) - strftime(TimeBuf,100,"%Y/%m/%d %r",tm); -#elif defined(TZ_TIME) - { - int zone = TimeDiff(t); - int absZoneMinutes = (zone<0 ? -zone : zone) / 60; - size_t len = strftime(TimeBuf,sizeof(TimeBuf)-6,"%Y/%m/%d %T",tm); - slprintf(TimeBuf+len, sizeof(fstring) - len - 1, " %c%02d%02d", - zone<0?'+':'-',absZoneMinutes/60,absZoneMinutes%60); - } + static fstring TimeBuf; + time_t t = time(NULL); + struct tm *tm = LocalTime(&t); + + if (!tm) { + slprintf(TimeBuf,sizeof(TimeBuf)-1,"%ld seconds since the Epoch",(long)t); + } else { +#ifdef HAVE_STRFTIME + strftime(TimeBuf,100,"%Y/%m/%d %T",tm); #else - strftime(TimeBuf,100,"%Y/%m/%d %T",tm); + fstrcpy(TimeBuf, asctime(tm)); #endif - return(TimeBuf); + } + return(TimeBuf); } /**************************************************************************** -- cgit From 18556274139cc5a00593471bd745354d98a35303 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 1 Sep 1998 20:11:54 +0000 Subject: More abstraction of file system data types, to move to a 64 bit file interface for the NT SMB's. Created a new define, SMB_STRUCT_STAT that currently is defined to be struct stat - this wil change to a user defined type containing 64 bit info when the correct wrappers are written for 64 bit stat(), fstat() and lstat() calls. Also changed all sys_xxxx() calls that were previously just wrappers to the same call prefixed by a dos_to_unix() call into dos_xxxx() calls. This makes it explicit when a pathname translation is being done, and when it is not. Now, all sys_xxx() calls are meant to be wrappers to mask OS differences, and not silently converting filenames on the fly. Jeremy. (This used to be commit 28aa182dbffaa4ffd86047e608400de4b26e80eb) --- source3/lib/time.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index 6eacf2a5ed..7b7ca51204 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -513,7 +513,7 @@ char *timestring(void ) structure. ****************************************************************************/ -time_t get_create_time(struct stat *st,BOOL fake_dirs) +time_t get_create_time(SMB_STRUCT_STAT *st,BOOL fake_dirs) { time_t ret, ret1; -- cgit From 6fb5804b28adffbbcb45b84e485e09d9d2ddddea Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Fri, 25 Sep 1998 22:20:05 +0000 Subject: added in samr commands. assistance in returning the missing functions, automatically removed because they were "unused", would be appreciated. (This used to be commit d0f7b0d915973ccb85409af3d6d951a716cd66d2) --- source3/lib/time.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index 7b7ca51204..89a83ebfc1 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -236,6 +236,17 @@ struct tm *LocalTime(time_t *t) return(gmtime(&t2)); } +/**************************************************************************** +take an NTTIME structure, containing high / low time. convert to unix time. +lkclXXXX this may need 2 SIVALs not a memcpy. we'll see... +****************************************************************************/ +time_t interpret_nt_time(NTTIME *t) +{ + char data[8]; + memcpy(data, t, sizeof(data)); + return interpret_long_date(data); +} + #define TIME_FIXUP_CONSTANT (369.0*365.25*24*60*60-(3.0*24*60*60+6.0*60*60)) @@ -532,3 +543,4 @@ time_t get_create_time(SMB_STRUCT_STAT *st,BOOL fake_dirs) */ return ret; } + -- cgit From cf3a9741dc7427efb97eff09a3c197a906ce6767 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 28 Sep 1998 21:43:48 +0000 Subject: Changes to test in configure if capabilities are enabled on a system. Changes to get Samba to compile cleanly with the IRIX compiler with the options : -fullwarn -woff 1209,1174 (the -woff options are to turn off warnings about unused function parameters and controlling loop expressions being constants). Split prototype generation as we hit a limit in IRIX nawk. Removed "." code in smbd/filename.c (yet again :-). Jeremy. (This used to be commit e0567433bd72aec17bf5a54cc292701095d25f09) --- source3/lib/time.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index 89a83ebfc1..529f0ceb44 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -470,7 +470,7 @@ time_t make_unix_date2(void *date_ptr) ******************************************************************/ time_t make_unix_date3(void *date_ptr) { - time_t t = IVAL(date_ptr,0); + time_t t = (time_t)IVAL(date_ptr,0); if (!null_mtime(t)) t += LocTimeDiff(t); return(t); -- cgit From 6a60602036105df68ba2756235058f64c42caa92 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 6 Oct 1998 03:20:43 +0000 Subject: remove unused arguments from some static functions. (This used to be commit a9e0e5895a671910f315d9e45eca4fe419d815e5) --- source3/lib/time.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index 529f0ceb44..ea96654108 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -337,7 +337,7 @@ BOOL null_mtime(time_t mtime) /******************************************************************* create a 16 bit dos packed date ********************************************************************/ -static uint16 make_dos_date1(time_t unixdate,struct tm *t) +static uint16 make_dos_date1(struct tm *t) { uint16 ret=0; ret = (((unsigned)(t->tm_mon+1)) >> 3) | ((t->tm_year-80) << 1); @@ -348,7 +348,7 @@ static uint16 make_dos_date1(time_t unixdate,struct tm *t) /******************************************************************* create a 16 bit dos packed time ********************************************************************/ -static uint16 make_dos_time1(time_t unixdate,struct tm *t) +static uint16 make_dos_time1(struct tm *t) { uint16 ret=0; ret = ((((unsigned)t->tm_min >> 3)&0x7) | (((unsigned)t->tm_hour) << 3)); @@ -369,8 +369,8 @@ static uint32 make_dos_date(time_t unixdate) if (!t) return 0xFFFFFFFF; - ret = make_dos_date1(unixdate,t); - ret = ((ret&0xFFFF)<<16) | make_dos_time1(unixdate,t); + ret = make_dos_date1(t); + ret = ((ret&0xFFFF)<<16) | make_dos_time1(t); return(ret); } -- cgit From 1e1c2ec93c204e6fd3ebba6dfb11e4fbc136e10c Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Tue, 10 Nov 1998 19:05:00 +0000 Subject: rpcclient registry commands. (This used to be commit 36fcb4a6e643a05d06a2a273d74318fee7f2c647) --- source3/lib/time.c | 79 +++++++++++++++++++++++++++++------------------------- 1 file changed, 42 insertions(+), 37 deletions(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index ea96654108..3cea1a3e14 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -236,18 +236,6 @@ struct tm *LocalTime(time_t *t) return(gmtime(&t2)); } -/**************************************************************************** -take an NTTIME structure, containing high / low time. convert to unix time. -lkclXXXX this may need 2 SIVALs not a memcpy. we'll see... -****************************************************************************/ -time_t interpret_nt_time(NTTIME *t) -{ - char data[8]; - memcpy(data, t, sizeof(data)); - return interpret_long_date(data); -} - - #define TIME_FIXUP_CONSTANT (369.0*365.25*24*60*60-(3.0*24*60*60+6.0*60*60)) /**************************************************************************** @@ -259,22 +247,19 @@ its the GMT you get by taking a localtime and adding the serverzone. This is NOT the same as GMT in some cases. This routine converts this to real GMT. ****************************************************************************/ -time_t interpret_long_date(char *p) +time_t nt_time_to_unix(NTTIME *nt) { double d; time_t ret; - uint32 tlow,thigh; /* The next two lines are a fix needed for the broken SCO compiler. JRA. */ time_t l_time_min = TIME_T_MIN; time_t l_time_max = TIME_T_MAX; - tlow = IVAL(p,0); - thigh = IVAL(p,4); - if (thigh == 0) return(0); + if (nt->high == 0) return(0); - d = ((double)thigh)*4.0*(double)(1<<30); - d += (tlow&0xFFF00000); + d = ((double)nt->high)*4.0*(double)(1<<30); + d += (nt->low&0xFFF00000); d *= 1.0e-7; /* now adjust by 369 years to make the secs since 1970 */ @@ -293,37 +278,57 @@ time_t interpret_long_date(char *p) } + +/**************************************************************************** +interprets an nt time into a unix time_t +****************************************************************************/ +time_t interpret_long_date(char *p) +{ + NTTIME nt; + nt.low = IVAL(p,0); + nt.high = IVAL(p,4); + return nt_time_to_unix(&nt); +} + /**************************************************************************** put a 8 byte filetime from a time_t This takes real GMT as input and converts to kludge-GMT ****************************************************************************/ -void put_long_date(char *p,time_t t) +void unix_to_nt_time(NTTIME *nt, time_t t) { - uint32 tlow,thigh; - double d; + double d; - if (t==0) { - SIVAL(p,0,0); SIVAL(p,4,0); - return; - } - - /* this converts GMT to kludge-GMT */ - t -= LocTimeDiff(t) - serverzone; + if (t==0) + { + nt->low = 0; + nt->high = 0; + return; + } - d = (double) (t); + /* this converts GMT to kludge-GMT */ + t -= LocTimeDiff(t) - serverzone; - d += TIME_FIXUP_CONSTANT; + d = (double)(t); + d += TIME_FIXUP_CONSTANT; + d *= 1.0e7; - d *= 1.0e7; + nt->high = (uint32)(d * (1.0/(4.0*(double)(1<<30)))); + nt->low = (uint32)(d - ((double)nt->high)*4.0*(double)(1<<30)); +} - thigh = (uint32)(d * (1.0/(4.0*(double)(1<<30)))); - tlow = (uint32)(d - ((double)thigh)*4.0*(double)(1<<30)); - SIVAL(p,0,tlow); - SIVAL(p,4,thigh); +/**************************************************************************** +take an NTTIME structure, containing high / low time. convert to unix time. +lkclXXXX this may need 2 SIVALs not a memcpy. we'll see... +****************************************************************************/ +void put_long_date(char *p,time_t t) +{ + NTTIME nt; + unix_to_nt_time(&nt, t); + SIVAL(p, 0, nt.low); + SIVAL(p, 4, nt.high); } - /**************************************************************************** check if it's a null mtime ****************************************************************************/ -- cgit From 90b708473887ac11ca81f5a056ae5d2c854cf616 Mon Sep 17 00:00:00 2001 From: Matthew Chapman Date: Mon, 1 Feb 1999 02:36:24 +0000 Subject: Added init_nt_time function which initialises an NTTIME to -1. (This used to be commit e1e3875057bed830fdc0aaa9c85f04a1479fd64a) --- source3/lib/time.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index 3cea1a3e14..85f6006389 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -298,13 +298,6 @@ void unix_to_nt_time(NTTIME *nt, time_t t) { double d; - if (t==0) - { - nt->low = 0; - nt->high = 0; - return; - } - /* this converts GMT to kludge-GMT */ t -= LocTimeDiff(t) - serverzone; @@ -316,6 +309,15 @@ void unix_to_nt_time(NTTIME *nt, time_t t) nt->low = (uint32)(d - ((double)nt->high)*4.0*(double)(1<<30)); } +/**************************************************************************** +initialise an NTTIME to -1, which means "unknown" or "don't expire" +****************************************************************************/ + +void init_nt_time(NTTIME *nt) +{ + nt->high = 0x7FFFFFFF; + nt->low = 0xFFFFFFFF; +} /**************************************************************************** take an NTTIME structure, containing high / low time. convert to unix time. -- cgit From c6e3fc5838aacde454c4b16436532455c4dd8ecf Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Mon, 8 Nov 1999 20:58:06 +0000 Subject: const feeding frenzy (This used to be commit e0eb390ab3e2a0cce191e78ea4ff90d088a8895c) --- source3/lib/time.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index 85f6006389..c332b906a0 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -247,7 +247,7 @@ its the GMT you get by taking a localtime and adding the serverzone. This is NOT the same as GMT in some cases. This routine converts this to real GMT. ****************************************************************************/ -time_t nt_time_to_unix(NTTIME *nt) +time_t nt_time_to_unix(const NTTIME *nt) { double d; time_t ret; -- cgit From 3db52feb1f3b2c07ce0b06ad4a7099fa6efe3fc7 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 13 Dec 1999 13:27:58 +0000 Subject: first pass at updating head branch to be to be the same as the SAMBA_2_0 branch (This used to be commit 453a822a76780063dff23526c35408866d0c0154) --- source3/lib/time.c | 68 ++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 51 insertions(+), 17 deletions(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index c332b906a0..5fd260e5c9 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -247,7 +247,7 @@ its the GMT you get by taking a localtime and adding the serverzone. This is NOT the same as GMT in some cases. This routine converts this to real GMT. ****************************************************************************/ -time_t nt_time_to_unix(const NTTIME *nt) +time_t nt_time_to_unix(NTTIME *nt) { double d; time_t ret; @@ -298,6 +298,13 @@ void unix_to_nt_time(NTTIME *nt, time_t t) { double d; + if (t==0) + { + nt->low = 0; + nt->high = 0; + return; + } + /* this converts GMT to kludge-GMT */ t -= LocTimeDiff(t) - serverzone; @@ -309,15 +316,6 @@ void unix_to_nt_time(NTTIME *nt, time_t t) nt->low = (uint32)(d - ((double)nt->high)*4.0*(double)(1<<30)); } -/**************************************************************************** -initialise an NTTIME to -1, which means "unknown" or "don't expire" -****************************************************************************/ - -void init_nt_time(NTTIME *nt) -{ - nt->high = 0x7FFFFFFF; - nt->low = 0xFFFFFFFF; -} /**************************************************************************** take an NTTIME structure, containing high / low time. convert to unix time. @@ -506,21 +504,57 @@ char *http_timestring(time_t t) /**************************************************************************** - return the date and time as a string + Return the date and time as a string ****************************************************************************/ -char *timestring(void ) + +char *timestring(BOOL hires) { static fstring TimeBuf; - time_t t = time(NULL); - struct tm *tm = LocalTime(&t); + struct timeval tp; + time_t t; + struct tm *tm; + if (hires) { + GetTimeOfDay(&tp); + t = (time_t)tp.tv_sec; + } else { + t = time(NULL); + } + tm = LocalTime(&t); if (!tm) { - slprintf(TimeBuf,sizeof(TimeBuf)-1,"%ld seconds since the Epoch",(long)t); + if (hires) { + slprintf(TimeBuf, + sizeof(TimeBuf)-1, + "%ld.%06ld seconds since the Epoch", + (long)tp.tv_sec, + (long)tp.tv_usec); + } else { + slprintf(TimeBuf, + sizeof(TimeBuf)-1, + "%ld seconds since the Epoch", + (long)t); + } } else { #ifdef HAVE_STRFTIME - strftime(TimeBuf,100,"%Y/%m/%d %T",tm); + if (hires) { + strftime(TimeBuf,sizeof(TimeBuf)-1,"%Y/%m/%d %H:%M:%S",tm); + slprintf(TimeBuf+strlen(TimeBuf), + sizeof(TimeBuf)-1 - strlen(TimeBuf), + ".%06ld", + (long)tp.tv_usec); + } else { + strftime(TimeBuf,100,"%Y/%m/%d %H:%M:%S",tm); + } #else - fstrcpy(TimeBuf, asctime(tm)); + if (hires)() { + slprintf(TimeBuf, + sizeof(TimeBuf)-1, + "%s.%06ld", + asctime(tm), + (long)tp.tv_usec); + } else { + fstrcpy(TimeBuf, asctime(tm)); + } #endif } return(TimeBuf); -- cgit From 321091ad2093b5de40ffcd5e20e7fb26a30636e1 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 15 Mar 2000 18:00:30 +0000 Subject: Fix from NAKAJI Hiroyuki for a trailing '\n\ in asctime. Jeremy. (This used to be commit 87df97c9365a185e4ea6bac7b832b8cf38144624) --- source3/lib/time.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index 5fd260e5c9..3ac5a2a0b5 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -495,6 +495,8 @@ char *http_timestring(time_t t) else #ifndef HAVE_STRFTIME fstrcpy(buf, asctime(tm)); + if(buf[strlen(buf)-1] == '\n') + buf[strlen(buf)-1] = 0; #else /* !HAVE_STRFTIME */ strftime(buf, sizeof(buf)-1, "%a, %d %b %Y %H:%M:%S %Z", tm); #endif /* !HAVE_STRFTIME */ -- cgit From 8f1620125dcb9c29c223f4efb6485528ece70f11 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 22 Mar 2000 19:03:12 +0000 Subject: acconfig.h configure configure.in: Added check for UT_SYSLEN for utmp code. include/byteorder.h: Added alignment macros. include/nameserv.h: Added defines for msg_type field options - from rfc1002. lib/time.c: Typo fix. lib/util_unistr.c: Updates from UNICODE branch. printing/nt_printing.c: bzero -> memset. smbd/connection.c: Added check for UT_SYSLEN for utmp code. Other fixes : Rollback of unapproved commit from Luke. Please *ask* next time before doing large changes to HEAD. Jeremy. (This used to be commit f02999dbf7971b4ea05050d7206205d7737a78b2) --- source3/lib/time.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index 3ac5a2a0b5..c7ccb79bfb 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -548,7 +548,7 @@ char *timestring(BOOL hires) strftime(TimeBuf,100,"%Y/%m/%d %H:%M:%S",tm); } #else - if (hires)() { + if (hires) { slprintf(TimeBuf, sizeof(TimeBuf)-1, "%s.%06ld", -- cgit From 0dcbafe2b97035df779f2e0742a130c4c79e3241 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Tue, 21 Nov 2000 05:55:16 +0000 Subject: Another large patch for the passdb rewrite. o added BOOL own_memory flag in SAM_ACCOUNT so we could use static memory for string pointer assignment or allocate a new string o added a reference TDB passdb backend. This is only a reference and should not be used in production because - RID's are generated using the same algorithm as with smbpasswd - a TDB can only have one key (w/o getting into problems) and we need three. Therefore the pdb_sam-getpwuid() and pdb_getsampwrid() functions are interative searches :-( we need transaction support, multiple indexes, and a nice open source DBM. The Berkeley DB (from sleepycat.com seems to fit this criteria now) o added a new parameter "private dir" as many places in the code were using lp_smb_passwd_file() and chopping off the filename part. This makes more sense to me and I will docuement it in the man pages o Ran through Insure-lite and corrected memory leaks. Need for a public flogging this time Jeremy (-: -- jerry (This used to be commit 4792029a2991bd84251d152a62b1033dec62cee2) --- source3/lib/time.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index c7ccb79bfb..9714d4b9f8 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -304,6 +304,12 @@ void unix_to_nt_time(NTTIME *nt, time_t t) nt->high = 0; return; } + if (t == -1) + { + nt->low = 0xffffffff; + nt->high = 0xffffffff; + return; + } /* this converts GMT to kludge-GMT */ t -= LocTimeDiff(t) - serverzone; -- cgit From 2e783a47076bd0994b6ce86df7ec967bc1c2da63 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sun, 12 Aug 2001 17:30:01 +0000 Subject: this is a big global fix for the ptr = Realloc(ptr, size) bug. many possible mem leaks, and segfaults fixed. someone should port this fix to 2.2 also. (This used to be commit fa8e55b8b465114ce209344965c1ca0333b84db9) --- source3/lib/time.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index 9714d4b9f8..12643b0522 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -121,7 +121,7 @@ Updated by Paul Eggert ********************************************************************/ static int TimeZoneFaster(time_t t) { - static struct dst_table {time_t start,end; int zone;} *dst_table = NULL; + static struct dst_table {time_t start,end; int zone;} *tdt, *dst_table = NULL; static int table_size = 0; int i; int zone = 0; @@ -141,11 +141,14 @@ static int TimeZoneFaster(time_t t) time_t low,high; zone = TimeZone(t); - dst_table = (struct dst_table *)Realloc(dst_table, + tdt = (struct dst_table *)Realloc(dst_table, sizeof(dst_table[0])*(i+1)); - if (!dst_table) { + if (!tdt) { + DEBUG(0,("TimeZoneFaster: out of memory!\n")); + if (dst_table) free (dst_table); table_size = 0; } else { + dst_table = tdt; table_size++; dst_table[i].zone = zone; -- cgit From 82901df5e31b1e83761a90cf717717213fda1197 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Tue, 28 Aug 2001 06:02:18 +0000 Subject: Merge from TNG - function to initialise NTTIME structure. (This used to be commit 14bc8283f26fb80633575e471de4a15a492113c6) --- source3/lib/time.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index 12643b0522..88be3fa334 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -596,3 +596,12 @@ time_t get_create_time(SMB_STRUCT_STAT *st,BOOL fake_dirs) return ret; } +/**************************************************************************** +initialise an NTTIME to -1, which means "unknown" or "don't expire" +****************************************************************************/ + +void init_nt_time(NTTIME *nt) +{ + nt->high = 0x7FFFFFFF; + nt->low = 0xFFFFFFFF; +} -- cgit From 484a7c0341fe033fe26fe1e6b597ed1c456c39d4 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Mon, 17 Sep 2001 02:19:44 +0000 Subject: move to SAFE_FREE() (This used to be commit 60e907b7e8e1c008463a88ed2b076344278986ef) --- source3/lib/time.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index 88be3fa334..f5cd96223c 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -145,7 +145,7 @@ static int TimeZoneFaster(time_t t) sizeof(dst_table[0])*(i+1)); if (!tdt) { DEBUG(0,("TimeZoneFaster: out of memory!\n")); - if (dst_table) free (dst_table); + SAFE_FREE(dst_table); table_size = 0; } else { dst_table = tdt; -- cgit From dc1fc3ee8ec2199bc73bb5d7ec711c6800f61d65 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Tue, 2 Oct 2001 04:29:50 +0000 Subject: Removed 'extern int DEBUGLEVEL' as it is now in the smb.h header. (This used to be commit 2d0922b0eabfdc0aaf1d0797482fef47ed7fde8e) --- source3/lib/time.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index f5cd96223c..59106386d4 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -30,8 +30,6 @@ int serverzone=0; int extra_time_offset = 0; -extern int DEBUGLEVEL; - #ifndef CHAR_BIT #define CHAR_BIT 8 #endif -- cgit From cb4b13a82ba26c70674fe903d89db1d38103dff7 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 2 Oct 2001 06:57:18 +0000 Subject: Fixed the bug with member servers in a Samba PDC hosted domain not allowing other access. Problem was max time was being set to 0xffffffff, instead of 0x7fffffff. Jeremy. (This used to be commit 94403d841710391ec26539e4b4157439d5778ff7) --- source3/lib/time.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index 59106386d4..cf088e8ee4 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -42,7 +42,19 @@ int extra_time_offset = 0; #define TIME_T_MAX (~ (time_t) 0 - TIME_T_MIN) #endif +/******************************************************************* + External access to time_t_min and time_t_max. +********************************************************************/ +time_t get_time_t_min(void) +{ + return TIME_T_MIN; +} + +time_t get_time_t_max(void) +{ + return TIME_T_MAX; +} /******************************************************************* a gettimeofday wrapper @@ -305,6 +317,12 @@ void unix_to_nt_time(NTTIME *nt, time_t t) nt->high = 0; return; } + if (t == TIME_T_MAX) + { + nt->low = 0xffffffff; + nt->high = 0x7fffffff; + return; + } if (t == -1) { nt->low = 0xffffffff; -- cgit From 79b34d1b11e685d068b9c0ac9a0ec06eaa263d82 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Fri, 23 Nov 2001 00:52:29 +0000 Subject: Removed TimeInit() call from every client program (except for one place in smbd/process.c where the timezone is reinitialised. Was replaced with check for a static is_initialised boolean. (This used to be commit 8fc772c9e5770cd3a8857670214dcff033ebae32) --- source3/lib/time.c | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index cf088e8ee4..b302726a95 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -27,7 +27,6 @@ */ -int serverzone=0; int extra_time_offset = 0; #ifndef CHAR_BIT @@ -105,21 +104,36 @@ static int TimeZone(time_t t) } +static BOOL done_serverzone_init; -/******************************************************************* -init the time differences -********************************************************************/ -void TimeInit(void) +/* Return the smb serverzone value */ + +static int get_serverzone(void) { - serverzone = TimeZone(time(NULL)); + static int serverzone; - if ((serverzone % 60) != 0) { - DEBUG(1,("WARNING: Your timezone is not a multiple of 1 minute.\n")); - } + if (!done_serverzone_init) { + serverzone = TimeZone(time(NULL)); + + if ((serverzone % 60) != 0) { + DEBUG(1,("WARNING: Your timezone is not a multiple of 1 minute.\n")); + } - DEBUG(4,("Serverzone is %d\n",serverzone)); + DEBUG(4,("Serverzone is %d\n",serverzone)); + + done_serverzone_init = True; + } + + return serverzone; } +/* Re-read the smb serverzone value */ + +void TimeInit(void) +{ + done_serverzone_init = False; + get_serverzone(); +} /******************************************************************* return the same value as TimeZone, but it should be more efficient. @@ -284,7 +298,7 @@ time_t nt_time_to_unix(NTTIME *nt) ret = (time_t)(d+0.5); /* this takes us from kludge-GMT to real GMT */ - ret -= serverzone; + ret -= get_serverzone(); ret += LocTimeDiff(ret); return(ret); @@ -331,7 +345,7 @@ void unix_to_nt_time(NTTIME *nt, time_t t) } /* this converts GMT to kludge-GMT */ - t -= LocTimeDiff(t) - serverzone; + t -= LocTimeDiff(t) - get_serverzone(); d = (double)(t); d += TIME_FIXUP_CONSTANT; -- cgit From cdf9b42754b7e97faa7fc4eb1ec69e32c0bfd1a0 Mon Sep 17 00:00:00 2001 From: Jean-François Micouleau Date: Mon, 3 Dec 2001 17:14:23 +0000 Subject: added a tdb to store the account policy informations. You can change them with either usermanager->policies->account or from a command prompt on NT/W2K: net accounts /domain we can add a rpc accounts to the net command. As the net_rpc.c is still empty, I did not start. How should I add command to it ? Should I take the rpcclient/cmd_xxx functions and call them from there ? alse changed the SAM_UNK_INFO_3 parser, it's an NTTIME. This one is more for jeremy ;-) J.F. (This used to be commit bc28a8eebd9245ce3004ae4b1a359db51f77bf21) --- source3/lib/time.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index b302726a95..f0f62ca841 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -304,6 +304,50 @@ time_t nt_time_to_unix(NTTIME *nt) return(ret); } +/**************************************************************************** +convert a NTTIME structure to a time_t +It's originally in "100ns units" + +this is an absolute version of the one above. +By absolute I mean, it doesn't adjust from 1/1/1601 to 1/1/1970 +if the NTTIME was 5 seconds, the time_t is 5 seconds. JFM +****************************************************************************/ +time_t nt_time_to_unix_abs(NTTIME *nt) +{ + double d; + time_t ret; + /* The next two lines are a fix needed for the + broken SCO compiler. JRA. */ + time_t l_time_min = TIME_T_MIN; + time_t l_time_max = TIME_T_MAX; + + if (nt->high == 0) + return(0); + + if (nt->high==0x80000000 && nt->low==0) + return -1; + + /* reverse the time */ + /* it's a negative value, turn it to positive */ + nt->high=~nt->high; + nt->low=~nt->low; + + d = ((double)nt->high)*4.0*(double)(1<<30); + d += (nt->low&0xFFF00000); + d *= 1.0e-7; + + if (!(l_time_min <= d && d <= l_time_max)) + return(0); + + ret = (time_t)(d+0.5); + + /* this takes us from kludge-GMT to real GMT */ + ret -= get_serverzone(); + ret += LocTimeDiff(ret); + + return(ret); +} + /**************************************************************************** @@ -355,6 +399,50 @@ void unix_to_nt_time(NTTIME *nt, time_t t) nt->low = (uint32)(d - ((double)nt->high)*4.0*(double)(1<<30)); } +/**************************************************************************** +convert a time_t to a NTTIME structure + +this is an absolute version of the one above. +By absolute I mean, it doesn't adjust from 1/1/1970 to 1/1/1601 +if the nttime_t was 5 seconds, the NTTIME is 5 seconds. JFM +****************************************************************************/ +void unix_to_nt_time_abs(NTTIME *nt, time_t t) +{ + double d; + + if (t==0) { + nt->low = 0; + nt->high = 0; + return; + } + + if (t == TIME_T_MAX) { + nt->low = 0xffffffff; + nt->high = 0x7fffffff; + return; + } + + if (t == -1) { + /* that's what NT uses for infinite */ + nt->low = 0x0; + nt->high = 0x80000000; + return; + } + + /* this converts GMT to kludge-GMT */ + t -= LocTimeDiff(t) - get_serverzone(); + + d = (double)(t); + d *= 1.0e7; + + nt->high = (uint32)(d * (1.0/(4.0*(double)(1<<30)))); + nt->low = (uint32)(d - ((double)nt->high)*4.0*(double)(1<<30)); + + /* convert to a negative value */ + nt->high=~nt->high; + nt->low=~nt->low; +} + /**************************************************************************** take an NTTIME structure, containing high / low time. convert to unix time. -- cgit From b741f6b04c2b0da7963cf0778f20a8ad1e8dbf9e Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 11 Jan 2002 21:52:46 +0000 Subject: Latest attempt at changeid. Jeremy. (This used to be commit 24ee18c77e1b61004d8ed817118a481f3d43e34c) --- source3/lib/time.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index f0f62ca841..975c58c7a5 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -129,10 +129,34 @@ static int get_serverzone(void) /* Re-read the smb serverzone value */ +static struct timeval start_time_hires; + void TimeInit(void) { - done_serverzone_init = False; - get_serverzone(); + done_serverzone_init = False; + get_serverzone(); + /* Save the start time of this process. */ + GetTimeOfDay(&start_time_hires); +} + +/********************************************************************** + Return a timeval struct of the uptime of this process. As TimeInit is + done before a daemon fork then this is the start time from the parent + daemon start. JRA. +***********************************************************************/ + +void get_process_uptime(struct timeval *ret_time) +{ + struct timeval time_now_hires; + + GetTimeOfDay(&time_now_hires); + ret_time->tv_sec = time_now_hires.tv_sec - start_time_hires.tv_sec; + ret_time->tv_usec = time_now_hires.tv_usec - start_time_hires.tv_usec; + if (time_now_hires.tv_usec < start_time_hires.tv_usec) { + ret_time->tv_sec -= 1; + ret_time->tv_usec = 1000000 + (time_now_hires.tv_usec - start_time_hires.tv_usec); + } else + ret_time->tv_usec = time_now_hires.tv_usec - start_time_hires.tv_usec; } /******************************************************************* -- cgit From 1d40138232a22b78f088847d0d72d6ddec17a65e Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 11 Jan 2002 23:33:12 +0000 Subject: Round and round we go.... Jeremy. (This used to be commit 2603ab3c6870f3697751b887e940910713f08985) --- source3/lib/time.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index 975c58c7a5..c39753403d 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -136,7 +136,8 @@ void TimeInit(void) done_serverzone_init = False; get_serverzone(); /* Save the start time of this process. */ - GetTimeOfDay(&start_time_hires); + if (start_time_hires.tv_sec == 0 && start_time_hires.tv_usec == 0) + GetTimeOfDay(&start_time_hires); } /********************************************************************** -- cgit From cd68afe31256ad60748b34f7318a180cfc2127cc Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Wed, 30 Jan 2002 06:08:46 +0000 Subject: Removed version number from file header. Changed "SMB/Netbios" to "SMB/CIFS" in file header. (This used to be commit 6a58c9bd06d0d7502a24bf5ce5a2faf0a146edfa) --- source3/lib/time.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index c39753403d..5fc43612dd 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -1,6 +1,5 @@ /* - Unix SMB/Netbios implementation. - Version 1.9. + Unix SMB/CIFS implementation. time handling functions Copyright (C) Andrew Tridgell 1992-1998 -- cgit From e90b65284812aaa5ff9e9935ce9bbad7791cbbcd Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 15 Jul 2002 10:35:28 +0000 Subject: updated the 3.0 branch from the head branch - ready for alpha18 (This used to be commit 03ac082dcb375b6f3ca3d810a6a6367542bc23ce) --- source3/lib/time.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index 5fc43612dd..9d87414aea 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -44,11 +44,6 @@ int extra_time_offset = 0; External access to time_t_min and time_t_max. ********************************************************************/ -time_t get_time_t_min(void) -{ - return TIME_T_MIN; -} - time_t get_time_t_max(void) { return TIME_T_MAX; @@ -413,7 +408,7 @@ void unix_to_nt_time(NTTIME *nt, time_t t) } /* this converts GMT to kludge-GMT */ - t -= LocTimeDiff(t) - get_serverzone(); + t -= TimeDiff(t) - get_serverzone(); d = (double)(t); d += TIME_FIXUP_CONSTANT; -- cgit From a834a73e341059be154426390304a42e4a011f72 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 25 Sep 2002 15:19:00 +0000 Subject: sync'ing up for 3.0alpha20 release (This used to be commit 65e7b5273bb58802bf0c389b77f7fcae0a1f6139) --- source3/lib/time.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index 9d87414aea..ef12dc15f3 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -40,6 +40,12 @@ int extra_time_offset = 0; #define TIME_T_MAX (~ (time_t) 0 - TIME_T_MIN) #endif +void get_nttime_max(NTTIME *t) +{ + /* FIXME: This is incorrect */ + unix_to_nt_time(t, get_time_t_max()); +} + /******************************************************************* External access to time_t_min and time_t_max. ********************************************************************/ -- cgit From 7d1eb6f7b62300e2f0a84f045f5885118c6ffa1b Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Thu, 26 Sep 2002 18:58:34 +0000 Subject: sync with HEAD (This used to be commit ee9cbf58071adb627a49a94c6340aaba330486b5) --- source3/lib/time.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index ef12dc15f3..5da63910d9 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -1,8 +1,8 @@ /* Unix SMB/CIFS implementation. time handling functions - Copyright (C) Andrew Tridgell 1992-1998 - + Copyright (C) Andrew Tridgell 1992-1998 + Copyright (C) Stefan (metze) Metzmacher 2002 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or @@ -748,3 +748,13 @@ void init_nt_time(NTTIME *nt) nt->high = 0x7FFFFFFF; nt->low = 0xFFFFFFFF; } + +/**************************************************************************** +check if NTTIME is 0 +****************************************************************************/ +BOOL nt_time_is_zero(NTTIME *nt) +{ + if(nt->high==0) + return True; + return False; +} -- cgit From f35d43a7d21385e95eb93247819339d2cb1f7097 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 10 Dec 2002 00:46:52 +0000 Subject: The _abs time functions should not be converting from/to GMT. Patch from "Jordan Russell" Jeremy. (This used to be commit 199c9fcbb9e9a5d4b75ac370d358f54e91808e76) --- source3/lib/time.c | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index 5da63910d9..ea5c6837bf 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -330,13 +330,14 @@ time_t nt_time_to_unix(NTTIME *nt) } /**************************************************************************** -convert a NTTIME structure to a time_t -It's originally in "100ns units" + Convert a NTTIME structure to a time_t. + It's originally in "100ns units". -this is an absolute version of the one above. -By absolute I mean, it doesn't adjust from 1/1/1601 to 1/1/1970 -if the NTTIME was 5 seconds, the time_t is 5 seconds. JFM + This is an absolute version of the one above. + By absolute I mean, it doesn't adjust from 1/1/1601 to 1/1/1970 + if the NTTIME was 5 seconds, the time_t is 5 seconds. JFM ****************************************************************************/ + time_t nt_time_to_unix_abs(NTTIME *nt) { double d; @@ -366,15 +367,9 @@ time_t nt_time_to_unix_abs(NTTIME *nt) ret = (time_t)(d+0.5); - /* this takes us from kludge-GMT to real GMT */ - ret -= get_serverzone(); - ret += LocTimeDiff(ret); - return(ret); } - - /**************************************************************************** interprets an nt time into a unix time_t ****************************************************************************/ @@ -425,12 +420,13 @@ void unix_to_nt_time(NTTIME *nt, time_t t) } /**************************************************************************** -convert a time_t to a NTTIME structure + Convert a time_t to a NTTIME structure -this is an absolute version of the one above. -By absolute I mean, it doesn't adjust from 1/1/1970 to 1/1/1601 -if the nttime_t was 5 seconds, the NTTIME is 5 seconds. JFM + This is an absolute version of the one above. + By absolute I mean, it doesn't adjust from 1/1/1970 to 1/1/1601 + If the nttime_t was 5 seconds, the NTTIME is 5 seconds. JFM ****************************************************************************/ + void unix_to_nt_time_abs(NTTIME *nt, time_t t) { double d; @@ -454,9 +450,6 @@ void unix_to_nt_time_abs(NTTIME *nt, time_t t) return; } - /* this converts GMT to kludge-GMT */ - t -= LocTimeDiff(t) - get_serverzone(); - d = (double)(t); d *= 1.0e7; -- cgit From 266ec4aac04cb8666234f18baa38ff6387f40cb3 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 24 Feb 2003 03:09:08 +0000 Subject: Merge doxygen, signed/unsigned, const and other small fixes from HEAD to 3.0. Andrew Bartlett (This used to be commit 9ef0d40c3f8aef52ab321dc065264c42065bc876) --- source3/lib/time.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index ea5c6837bf..f76a1bdc0d 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -479,7 +479,7 @@ check if it's a null mtime ****************************************************************************/ BOOL null_mtime(time_t mtime) { - if (mtime == 0 || mtime == 0xFFFFFFFF || mtime == (time_t)-1) + if (mtime == 0 || mtime == (time_t)0xFFFFFFFF || mtime == (time_t)-1) return(True); return(False); } -- cgit From 7309f50062a11e38f3e697cd3ced68333d55e63d Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 9 Jun 2003 02:54:07 +0000 Subject: applied patch from bug#140 this fixes a timestamp problem with 64 bit machines (This used to be commit 0ce6eddad8e148bc6d195ddefb773326339d06e6) --- source3/lib/time.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index f76a1bdc0d..5309711a05 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -308,7 +308,8 @@ time_t nt_time_to_unix(NTTIME *nt) time_t l_time_min = TIME_T_MIN; time_t l_time_max = TIME_T_MAX; - if (nt->high == 0) return(0); + if (nt->high == 0 || (nt->high == 0xffffffff && nt->low == 0xffffffff)) + return(0); d = ((double)nt->high)*4.0*(double)(1<<30); d += (nt->low&0xFFF00000); -- cgit From a98fc57af90be19f8449e0d0df4059eeaff4e2c8 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sun, 12 Oct 2003 20:48:56 +0000 Subject: make nt-time <-> unix-time functions nearly reversible (This used to be commit bda64a11f7c11ca303122299c3e41c49e6afd933) --- source3/lib/time.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index 5309711a05..74ca56bdc5 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -318,8 +318,11 @@ time_t nt_time_to_unix(NTTIME *nt) /* now adjust by 369 years to make the secs since 1970 */ d -= TIME_FIXUP_CONSTANT; - if (!(l_time_min <= d && d <= l_time_max)) - return(0); + if (d <= l_time_min) + return (l_time_min); + + if (d >= l_time_max) + return (l_time_max); ret = (time_t)(d+0.5); -- cgit From fc809973b9be1104af806f9c35e66d1be3dfab35 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Tue, 4 Nov 2003 20:09:44 +0000 Subject: Use the actual size of the buffer in strftime instead of a made up value which just happens to be less than sizeof(fstring). Closes #713. (This used to be commit 761e13da4ef8294f0b131ad7f672d023b0d222f6) --- source3/lib/time.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index 74ca56bdc5..635ede9be2 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -694,7 +694,7 @@ char *timestring(BOOL hires) ".%06ld", (long)tp.tv_usec); } else { - strftime(TimeBuf,100,"%Y/%m/%d %H:%M:%S",tm); + strftime(TimeBuf,sizeof(TimeBuf)-1,"%Y/%m/%d %H:%M:%S",tm); } #else if (hires) { -- cgit From e83fc388b3b13c5c4674683e4b399491f666d705 Mon Sep 17 00:00:00 2001 From: Richard Sharpe Date: Wed, 26 Nov 2003 19:15:22 +0000 Subject: Clean up a comment noticed by Jonathan Shao@Panasas.com and remove an obsolete comment by Luke Leighton. (This used to be commit 316f83add76b56fe102f5dc4c9ce3a0413d9a1f4) --- source3/lib/time.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index 635ede9be2..faca2cba87 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -465,10 +465,9 @@ void unix_to_nt_time_abs(NTTIME *nt, time_t t) nt->low=~nt->low; } - /**************************************************************************** -take an NTTIME structure, containing high / low time. convert to unix time. -lkclXXXX this may need 2 SIVALs not a memcpy. we'll see... +take a Unix time and convert to an NTTIME structure and place in buffer +pointed to by p. ****************************************************************************/ void put_long_date(char *p,time_t t) { -- cgit From 2fc57c9a2ce3a266534dd20e6fed4883e052c557 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 8 Jun 2004 16:14:31 +0000 Subject: r1085: Now it's had some proper user testing, merge in the deferred open fix. I'm still doing more testing, but it fixes a behaviour that we've been wrong on ever since the start of Samba. Jeremy. (This used to be commit 894cc6d16296b934c112786eec896846156aee5d) --- source3/lib/time.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index faca2cba87..e63e0b2965 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -754,3 +754,9 @@ BOOL nt_time_is_zero(NTTIME *nt) return True; return False; } + +SMB_BIG_INT usec_time_diff(struct timeval *larget, struct timeval *smallt) +{ + SMB_BIG_INT sec_diff = larget->tv_sec - smallt->tv_sec; + return (sec_diff * 1000000) + (SMB_BIG_INT)(larget->tv_usec - smallt->tv_usec); +} -- cgit From acf9d61421faa6c0055d57fdee7db300dc5431aa Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 7 Dec 2004 18:25:53 +0000 Subject: r4088: Get medieval on our ass about malloc.... :-). Take control of all our allocation functions so we can funnel through some well known functions. Should help greatly with malloc checking. HEAD patch to follow. Jeremy. (This used to be commit 620f2e608f70ba92f032720c031283d295c5c06a) --- source3/lib/time.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index e63e0b2965..e7b537151f 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -190,8 +190,7 @@ static int TimeZoneFaster(time_t t) time_t low,high; zone = TimeZone(t); - tdt = (struct dst_table *)Realloc(dst_table, - sizeof(dst_table[0])*(i+1)); + tdt = SMB_REALLOC_ARRAY(dst_table, struct dst_table, i+1); if (!tdt) { DEBUG(0,("TimeZoneFaster: out of memory!\n")); SAFE_FREE(dst_table); -- cgit From daa2d8bd1f724a0016a4542a2038186e2d6b82bc Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 11 Feb 2005 19:31:48 +0000 Subject: r5342: Reformat some very old code. Jeremy. (This used to be commit 08553faeeb77aef46264f4dfe738bc202e87ea23) --- source3/lib/time.c | 537 ++++++++++++++++++++++++++++------------------------- 1 file changed, 281 insertions(+), 256 deletions(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index e7b537151f..5d7628c9d3 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -56,8 +56,9 @@ time_t get_time_t_max(void) } /******************************************************************* -a gettimeofday wrapper + A gettimeofday wrapper. ********************************************************************/ + void GetTimeOfDay(struct timeval *tval) { #ifdef HAVE_GETTIMEOFDAY_TZ @@ -70,43 +71,45 @@ void GetTimeOfDay(struct timeval *tval) #define TM_YEAR_BASE 1900 /******************************************************************* -yield the difference between *A and *B, in seconds, ignoring leap seconds + Yield the difference between *A and *B, in seconds, ignoring leap seconds. ********************************************************************/ + static int tm_diff(struct tm *a, struct tm *b) { - int ay = a->tm_year + (TM_YEAR_BASE - 1); - int by = b->tm_year + (TM_YEAR_BASE - 1); - int intervening_leap_days = - (ay/4 - by/4) - (ay/100 - by/100) + (ay/400 - by/400); - int years = ay - by; - int days = 365*years + intervening_leap_days + (a->tm_yday - b->tm_yday); - int hours = 24*days + (a->tm_hour - b->tm_hour); - int minutes = 60*hours + (a->tm_min - b->tm_min); - int seconds = 60*minutes + (a->tm_sec - b->tm_sec); + int ay = a->tm_year + (TM_YEAR_BASE - 1); + int by = b->tm_year + (TM_YEAR_BASE - 1); + int intervening_leap_days = (ay/4 - by/4) - (ay/100 - by/100) + (ay/400 - by/400); + int years = ay - by; + int days = 365*years + intervening_leap_days + (a->tm_yday - b->tm_yday); + int hours = 24*days + (a->tm_hour - b->tm_hour); + int minutes = 60*hours + (a->tm_min - b->tm_min); + int seconds = 60*minutes + (a->tm_sec - b->tm_sec); - return seconds; + return seconds; } /******************************************************************* - return the UTC offset in seconds west of UTC, or 0 if it cannot be determined - ******************************************************************/ + Return the UTC offset in seconds west of UTC, or 0 if it cannot be determined. +******************************************************************/ + static int TimeZone(time_t t) { - struct tm *tm = gmtime(&t); - struct tm tm_utc; - if (!tm) - return 0; - tm_utc = *tm; - tm = localtime(&t); - if (!tm) - return 0; - return tm_diff(&tm_utc,tm); - + struct tm *tm = gmtime(&t); + struct tm tm_utc; + if (!tm) + return 0; + tm_utc = *tm; + tm = localtime(&t); + if (!tm) + return 0; + return tm_diff(&tm_utc,tm); } static BOOL done_serverzone_init; -/* Return the smb serverzone value */ +/******************************************************************* + Return the smb serverzone value. +******************************************************************/ static int get_serverzone(void) { @@ -127,7 +130,9 @@ static int get_serverzone(void) return serverzone; } -/* Re-read the smb serverzone value */ +/******************************************************************* + Re-read the smb serverzone value. +******************************************************************/ static struct timeval start_time_hires; @@ -161,175 +166,180 @@ void get_process_uptime(struct timeval *ret_time) } /******************************************************************* -return the same value as TimeZone, but it should be more efficient. + Return the same value as TimeZone, but it should be more efficient. -We keep a table of DST offsets to prevent calling localtime() on each -call of this function. This saves a LOT of time on many unixes. + We keep a table of DST offsets to prevent calling localtime() on each + call of this function. This saves a LOT of time on many unixes. -Updated by Paul Eggert + Updated by Paul Eggert ********************************************************************/ + static int TimeZoneFaster(time_t t) { - static struct dst_table {time_t start,end; int zone;} *tdt, *dst_table = NULL; - static int table_size = 0; - int i; - int zone = 0; + static struct dst_table {time_t start,end; int zone;} *tdt, *dst_table = NULL; + static int table_size = 0; + int i; + int zone = 0; - if (t == 0) t = time(NULL); + if (t == 0) + t = time(NULL); - /* Tunis has a 8 day DST region, we need to be careful ... */ + /* Tunis has a 8 day DST region, we need to be careful ... */ #define MAX_DST_WIDTH (365*24*60*60) #define MAX_DST_SKIP (7*24*60*60) - for (i=0;i= dst_table[i].start && t <= dst_table[i].end) break; - - if (i= dst_table[i].start && t <= dst_table[i].end) + break; + + if (i MAX_DST_SKIP*2) - t = dst_table[i].start - MAX_DST_SKIP; - else - t = low + (dst_table[i].start-low)/2; - if (TimeZone(t) == zone) - dst_table[i].start = t; - else - low = t; - } - - while (high-60*60 > dst_table[i].end) { - if (high - dst_table[i].end > MAX_DST_SKIP*2) - t = dst_table[i].end + MAX_DST_SKIP; - else - t = high - (high-dst_table[i].end)/2; - if (TimeZone(t) == zone) - dst_table[i].end = t; - else - high = t; - } + /* widen the new entry using two bisection searches */ + while (low+60*60 < dst_table[i].start) { + if (dst_table[i].start - low > MAX_DST_SKIP*2) + t = dst_table[i].start - MAX_DST_SKIP; + else + t = low + (dst_table[i].start-low)/2; + if (TimeZone(t) == zone) + dst_table[i].start = t; + else + low = t; + } + + while (high-60*60 > dst_table[i].end) { + if (high - dst_table[i].end > MAX_DST_SKIP*2) + t = dst_table[i].end + MAX_DST_SKIP; + else + t = high - (high-dst_table[i].end)/2; + if (TimeZone(t) == zone) + dst_table[i].end = t; + else + high = t; + } #if 0 DEBUG(1,("Added DST entry from %s ", asctime(localtime(&dst_table[i].start)))); DEBUG(1,("to %s (%d)\n",asctime(localtime(&dst_table[i].end)), dst_table[i].zone)); #endif - } - } - return zone; + } + } + return zone; } /**************************************************************************** - return the UTC offset in seconds west of UTC, adjusted for extra time offset - **************************************************************************/ + Return the UTC offset in seconds west of UTC, adjusted for extra time offset. +**************************************************************************/ + int TimeDiff(time_t t) { - return TimeZoneFaster(t) + 60*extra_time_offset; + return TimeZoneFaster(t) + 60*extra_time_offset; } - /**************************************************************************** - return the UTC offset in seconds west of UTC, adjusted for extra time - offset, for a local time value. If ut = lt + LocTimeDiff(lt), then - lt = ut - TimeDiff(ut), but the converse does not necessarily hold near - daylight savings transitions because some local times are ambiguous. - LocTimeDiff(t) equals TimeDiff(t) except near daylight savings transitions. - +**************************************************************************/ + Return the UTC offset in seconds west of UTC, adjusted for extra time + offset, for a local time value. If ut = lt + LocTimeDiff(lt), then + lt = ut - TimeDiff(ut), but the converse does not necessarily hold near + daylight savings transitions because some local times are ambiguous. + LocTimeDiff(t) equals TimeDiff(t) except near daylight savings transitions. +**************************************************************************/ + static int LocTimeDiff(time_t lte) { - time_t lt = lte - 60*extra_time_offset; - int d = TimeZoneFaster(lt); - time_t t = lt + d; + time_t lt = lte - 60*extra_time_offset; + int d = TimeZoneFaster(lt); + time_t t = lt + d; - /* if overflow occurred, ignore all the adjustments so far */ - if (((lte < lt) ^ (extra_time_offset < 0)) | ((t < lt) ^ (d < 0))) - t = lte; + /* if overflow occurred, ignore all the adjustments so far */ + if (((lte < lt) ^ (extra_time_offset < 0)) | ((t < lt) ^ (d < 0))) + t = lte; - /* now t should be close enough to the true UTC to yield the right answer */ - return TimeDiff(t); + /* now t should be close enough to the true UTC to yield the right answer */ + return TimeDiff(t); } - /**************************************************************************** -try to optimise the localtime call, it can be quite expensive on some machines + Try to optimise the localtime call, it can be quite expensive on some machines. ****************************************************************************/ + struct tm *LocalTime(time_t *t) { - time_t t2 = *t; + time_t t2 = *t; - t2 -= TimeDiff(t2); + t2 -= TimeDiff(t2); - return(gmtime(&t2)); + return(gmtime(&t2)); } #define TIME_FIXUP_CONSTANT (369.0*365.25*24*60*60-(3.0*24*60*60+6.0*60*60)) /**************************************************************************** -interpret an 8 byte "filetime" structure to a time_t -It's originally in "100ns units since jan 1st 1601" + Interpret an 8 byte "filetime" structure to a time_t + It's originally in "100ns units since jan 1st 1601" -It appears to be kludge-GMT (at least for file listings). This means -its the GMT you get by taking a localtime and adding the -serverzone. This is NOT the same as GMT in some cases. This routine -converts this to real GMT. + It appears to be kludge-GMT (at least for file listings). This means + its the GMT you get by taking a localtime and adding the + serverzone. This is NOT the same as GMT in some cases. This routine + converts this to real GMT. ****************************************************************************/ + time_t nt_time_to_unix(NTTIME *nt) { - double d; - time_t ret; - /* The next two lines are a fix needed for the - broken SCO compiler. JRA. */ - time_t l_time_min = TIME_T_MIN; - time_t l_time_max = TIME_T_MAX; + double d; + time_t ret; + /* The next two lines are a fix needed for the + broken SCO compiler. JRA. */ + time_t l_time_min = TIME_T_MIN; + time_t l_time_max = TIME_T_MAX; - if (nt->high == 0 || (nt->high == 0xffffffff && nt->low == 0xffffffff)) - return(0); + if (nt->high == 0 || (nt->high == 0xffffffff && nt->low == 0xffffffff)) + return(0); - d = ((double)nt->high)*4.0*(double)(1<<30); - d += (nt->low&0xFFF00000); - d *= 1.0e-7; + d = ((double)nt->high)*4.0*(double)(1<<30); + d += (nt->low&0xFFF00000); + d *= 1.0e-7; - /* now adjust by 369 years to make the secs since 1970 */ - d -= TIME_FIXUP_CONSTANT; + /* now adjust by 369 years to make the secs since 1970 */ + d -= TIME_FIXUP_CONSTANT; - if (d <= l_time_min) - return (l_time_min); + if (d <= l_time_min) + return (l_time_min); - if (d >= l_time_max) - return (l_time_max); + if (d >= l_time_max) + return (l_time_max); - ret = (time_t)(d+0.5); + ret = (time_t)(d+0.5); - /* this takes us from kludge-GMT to real GMT */ - ret -= get_serverzone(); - ret += LocTimeDiff(ret); + /* this takes us from kludge-GMT to real GMT */ + ret -= get_serverzone(); + ret += LocTimeDiff(ret); - return(ret); + return(ret); } /**************************************************************************** @@ -374,8 +384,9 @@ time_t nt_time_to_unix_abs(NTTIME *nt) } /**************************************************************************** -interprets an nt time into a unix time_t + Interprets an nt time into a unix time_t. ****************************************************************************/ + time_t interpret_long_date(char *p) { NTTIME nt; @@ -385,27 +396,25 @@ time_t interpret_long_date(char *p) } /**************************************************************************** -put a 8 byte filetime from a time_t -This takes real GMT as input and converts to kludge-GMT + Put a 8 byte filetime from a time_t + This takes real GMT as input and converts to kludge-GMT ****************************************************************************/ + void unix_to_nt_time(NTTIME *nt, time_t t) { double d; - if (t==0) - { + if (t==0) { nt->low = 0; nt->high = 0; return; } - if (t == TIME_T_MAX) - { + if (t == TIME_T_MAX) { nt->low = 0xffffffff; nt->high = 0x7fffffff; return; } - if (t == -1) - { + if (t == -1) { nt->low = 0xffffffff; nt->high = 0xffffffff; return; @@ -465,9 +474,10 @@ void unix_to_nt_time_abs(NTTIME *nt, time_t t) } /**************************************************************************** -take a Unix time and convert to an NTTIME structure and place in buffer -pointed to by p. + Take a Unix time and convert to an NTTIME structure and place in buffer + pointed to by p. ****************************************************************************/ + void put_long_date(char *p,time_t t) { NTTIME nt; @@ -477,181 +487,191 @@ void put_long_date(char *p,time_t t) } /**************************************************************************** -check if it's a null mtime + Check if it's a null mtime. ****************************************************************************/ + BOOL null_mtime(time_t mtime) { - if (mtime == 0 || mtime == (time_t)0xFFFFFFFF || mtime == (time_t)-1) - return(True); - return(False); + if (mtime == 0 || mtime == (time_t)0xFFFFFFFF || mtime == (time_t)-1) + return(True); + return(False); } /******************************************************************* - create a 16 bit dos packed date + Create a 16 bit dos packed date. ********************************************************************/ + static uint16 make_dos_date1(struct tm *t) { - uint16 ret=0; - ret = (((unsigned)(t->tm_mon+1)) >> 3) | ((t->tm_year-80) << 1); - ret = ((ret&0xFF)<<8) | (t->tm_mday | (((t->tm_mon+1) & 0x7) << 5)); - return(ret); + uint16 ret=0; + ret = (((unsigned)(t->tm_mon+1)) >> 3) | ((t->tm_year-80) << 1); + ret = ((ret&0xFF)<<8) | (t->tm_mday | (((t->tm_mon+1) & 0x7) << 5)); + return(ret); } /******************************************************************* - create a 16 bit dos packed time + Create a 16 bit dos packed time. ********************************************************************/ + static uint16 make_dos_time1(struct tm *t) { - uint16 ret=0; - ret = ((((unsigned)t->tm_min >> 3)&0x7) | (((unsigned)t->tm_hour) << 3)); - ret = ((ret&0xFF)<<8) | ((t->tm_sec/2) | ((t->tm_min & 0x7) << 5)); - return(ret); + uint16 ret=0; + ret = ((((unsigned)t->tm_min >> 3)&0x7) | (((unsigned)t->tm_hour) << 3)); + ret = ((ret&0xFF)<<8) | ((t->tm_sec/2) | ((t->tm_min & 0x7) << 5)); + return(ret); } /******************************************************************* - create a 32 bit dos packed date/time from some parameters - This takes a GMT time and returns a packed localtime structure + Create a 32 bit dos packed date/time from some parameters. + This takes a GMT time and returns a packed localtime structure. ********************************************************************/ + static uint32 make_dos_date(time_t unixdate) { - struct tm *t; - uint32 ret=0; + struct tm *t; + uint32 ret=0; - t = LocalTime(&unixdate); - if (!t) - return 0xFFFFFFFF; + t = LocalTime(&unixdate); + if (!t) + return 0xFFFFFFFF; - ret = make_dos_date1(t); - ret = ((ret&0xFFFF)<<16) | make_dos_time1(t); + ret = make_dos_date1(t); + ret = ((ret&0xFFFF)<<16) | make_dos_time1(t); - return(ret); + return(ret); } /******************************************************************* -put a dos date into a buffer (time/date format) -This takes GMT time and puts local time in the buffer + Put a dos date into a buffer (time/date format). + This takes GMT time and puts local time in the buffer. ********************************************************************/ + void put_dos_date(char *buf,int offset,time_t unixdate) { - uint32 x = make_dos_date(unixdate); - SIVAL(buf,offset,x); + uint32 x = make_dos_date(unixdate); + SIVAL(buf,offset,x); } /******************************************************************* -put a dos date into a buffer (date/time format) -This takes GMT time and puts local time in the buffer + Put a dos date into a buffer (date/time format). + This takes GMT time and puts local time in the buffer. ********************************************************************/ + void put_dos_date2(char *buf,int offset,time_t unixdate) { - uint32 x = make_dos_date(unixdate); - x = ((x&0xFFFF)<<16) | ((x&0xFFFF0000)>>16); - SIVAL(buf,offset,x); + uint32 x = make_dos_date(unixdate); + x = ((x&0xFFFF)<<16) | ((x&0xFFFF0000)>>16); + SIVAL(buf,offset,x); } /******************************************************************* -put a dos 32 bit "unix like" date into a buffer. This routine takes -GMT and converts it to LOCAL time before putting it (most SMBs assume -localtime for this sort of date) + Put a dos 32 bit "unix like" date into a buffer. This routine takes + GMT and converts it to LOCAL time before putting it (most SMBs assume + localtime for this sort of date) ********************************************************************/ + void put_dos_date3(char *buf,int offset,time_t unixdate) { - if (!null_mtime(unixdate)) - unixdate -= TimeDiff(unixdate); - SIVAL(buf,offset,unixdate); + if (!null_mtime(unixdate)) + unixdate -= TimeDiff(unixdate); + SIVAL(buf,offset,unixdate); } /******************************************************************* - interpret a 32 bit dos packed date/time to some parameters + Interpret a 32 bit dos packed date/time to some parameters. ********************************************************************/ + static void interpret_dos_date(uint32 date,int *year,int *month,int *day,int *hour,int *minute,int *second) { - uint32 p0,p1,p2,p3; + uint32 p0,p1,p2,p3; - p0=date&0xFF; p1=((date&0xFF00)>>8)&0xFF; - p2=((date&0xFF0000)>>16)&0xFF; p3=((date&0xFF000000)>>24)&0xFF; + p0=date&0xFF; p1=((date&0xFF00)>>8)&0xFF; + p2=((date&0xFF0000)>>16)&0xFF; p3=((date&0xFF000000)>>24)&0xFF; - *second = 2*(p0 & 0x1F); - *minute = ((p0>>5)&0xFF) + ((p1&0x7)<<3); - *hour = (p1>>3)&0xFF; - *day = (p2&0x1F); - *month = ((p2>>5)&0xFF) + ((p3&0x1)<<3) - 1; - *year = ((p3>>1)&0xFF) + 80; + *second = 2*(p0 & 0x1F); + *minute = ((p0>>5)&0xFF) + ((p1&0x7)<<3); + *hour = (p1>>3)&0xFF; + *day = (p2&0x1F); + *month = ((p2>>5)&0xFF) + ((p3&0x1)<<3) - 1; + *year = ((p3>>1)&0xFF) + 80; } /******************************************************************* - create a unix date (int GMT) from a dos date (which is actually in - localtime) + Create a unix date (int GMT) from a dos date (which is actually in + localtime). ********************************************************************/ + time_t make_unix_date(void *date_ptr) { - uint32 dos_date=0; - struct tm t; - time_t ret; + uint32 dos_date=0; + struct tm t; + time_t ret; - dos_date = IVAL(date_ptr,0); + dos_date = IVAL(date_ptr,0); - if (dos_date == 0) return(0); + if (dos_date == 0) + return(0); - interpret_dos_date(dos_date,&t.tm_year,&t.tm_mon, - &t.tm_mday,&t.tm_hour,&t.tm_min,&t.tm_sec); - t.tm_isdst = -1; + interpret_dos_date(dos_date,&t.tm_year,&t.tm_mon, + &t.tm_mday,&t.tm_hour,&t.tm_min,&t.tm_sec); + t.tm_isdst = -1; - /* mktime() also does the local to GMT time conversion for us */ - ret = mktime(&t); + /* mktime() also does the local to GMT time conversion for us */ + ret = mktime(&t); - return(ret); + return(ret); } /******************************************************************* -like make_unix_date() but the words are reversed + Like make_unix_date() but the words are reversed. ********************************************************************/ + time_t make_unix_date2(void *date_ptr) { - uint32 x,x2; + uint32 x,x2; - x = IVAL(date_ptr,0); - x2 = ((x&0xFFFF)<<16) | ((x&0xFFFF0000)>>16); - SIVAL(&x,0,x2); + x = IVAL(date_ptr,0); + x2 = ((x&0xFFFF)<<16) | ((x&0xFFFF0000)>>16); + SIVAL(&x,0,x2); - return(make_unix_date((void *)&x)); + return(make_unix_date((void *)&x)); } /******************************************************************* - create a unix GMT date from a dos date in 32 bit "unix like" format - these generally arrive as localtimes, with corresponding DST - ******************************************************************/ + Create a unix GMT date from a dos date in 32 bit "unix like" format + these generally arrive as localtimes, with corresponding DST. +******************************************************************/ + time_t make_unix_date3(void *date_ptr) { - time_t t = (time_t)IVAL(date_ptr,0); - if (!null_mtime(t)) - t += LocTimeDiff(t); - return(t); + time_t t = (time_t)IVAL(date_ptr,0); + if (!null_mtime(t)) + t += LocTimeDiff(t); + return(t); } - /*************************************************************************** -return a HTTP/1.0 time string - ***************************************************************************/ + Return a HTTP/1.0 time string. +***************************************************************************/ + char *http_timestring(time_t t) { - static fstring buf; - struct tm *tm = LocalTime(&t); + static fstring buf; + struct tm *tm = LocalTime(&t); - if (!tm) - slprintf(buf,sizeof(buf)-1,"%ld seconds since the Epoch",(long)t); - else + if (!tm) + slprintf(buf,sizeof(buf)-1,"%ld seconds since the Epoch",(long)t); + else #ifndef HAVE_STRFTIME - fstrcpy(buf, asctime(tm)); - if(buf[strlen(buf)-1] == '\n') - buf[strlen(buf)-1] = 0; + fstrcpy(buf, asctime(tm)); + if(buf[strlen(buf)-1] == '\n') + buf[strlen(buf)-1] = 0; #else /* !HAVE_STRFTIME */ - strftime(buf, sizeof(buf)-1, "%a, %d %b %Y %H:%M:%S %Z", tm); + strftime(buf, sizeof(buf)-1, "%a, %d %b %Y %H:%M:%S %Z", tm); #endif /* !HAVE_STRFTIME */ - return buf; + return buf; } - - /**************************************************************************** Return the date and time as a string ****************************************************************************/ @@ -710,32 +730,32 @@ char *timestring(BOOL hires) } /**************************************************************************** - return the best approximation to a 'create time' under UNIX from a stat - structure. + Return the best approximation to a 'create time' under UNIX from a stat + structure. ****************************************************************************/ time_t get_create_time(SMB_STRUCT_STAT *st,BOOL fake_dirs) { - time_t ret, ret1; + time_t ret, ret1; - if(S_ISDIR(st->st_mode) && fake_dirs) - return (time_t)315493200L; /* 1/1/1980 */ + if(S_ISDIR(st->st_mode) && fake_dirs) + return (time_t)315493200L; /* 1/1/1980 */ - ret = MIN(st->st_ctime, st->st_mtime); - ret1 = MIN(ret, st->st_atime); + ret = MIN(st->st_ctime, st->st_mtime); + ret1 = MIN(ret, st->st_atime); - if(ret1 != (time_t)0) - return ret1; + if(ret1 != (time_t)0) + return ret1; - /* - * One of ctime, mtime or atime was zero (probably atime). - * Just return MIN(ctime, mtime). - */ - return ret; + /* + * One of ctime, mtime or atime was zero (probably atime). + * Just return MIN(ctime, mtime). + */ + return ret; } /**************************************************************************** -initialise an NTTIME to -1, which means "unknown" or "don't expire" + Initialise an NTTIME to -1, which means "unknown" or "don't expire". ****************************************************************************/ void init_nt_time(NTTIME *nt) @@ -745,8 +765,9 @@ void init_nt_time(NTTIME *nt) } /**************************************************************************** -check if NTTIME is 0 + Check if NTTIME is 0. ****************************************************************************/ + BOOL nt_time_is_zero(NTTIME *nt) { if(nt->high==0) @@ -754,6 +775,10 @@ BOOL nt_time_is_zero(NTTIME *nt) return False; } +/**************************************************************************** + Return a timeval difference in usec. +****************************************************************************/ + SMB_BIG_INT usec_time_diff(struct timeval *larget, struct timeval *smallt) { SMB_BIG_INT sec_diff = larget->tv_sec - smallt->tv_sec; -- cgit From 0f87a9ada358020874206cf65db5c62a0a83ddbb Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 11 Feb 2005 20:00:30 +0000 Subject: r5343: Fix for bug#1525. Timestamps interpreted incorrectly on 64-bit time_t values. Jeremy. (This used to be commit 00f8ac509aaf2f40a067f5fe5c7699ae6f26571e) --- source3/lib/time.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index 5d7628c9d3..84004a099b 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -302,6 +302,8 @@ struct tm *LocalTime(time_t *t) Interpret an 8 byte "filetime" structure to a time_t It's originally in "100ns units since jan 1st 1601" + An 8 byte value of 0xffffffffffffffff will be returned as (time_t)0. + It appears to be kludge-GMT (at least for file listings). This means its the GMT you get by taking a localtime and adding the serverzone. This is NOT the same as GMT in some cases. This routine @@ -385,6 +387,8 @@ time_t nt_time_to_unix_abs(NTTIME *nt) /**************************************************************************** Interprets an nt time into a unix time_t. + Differs from nt_time_to_unix in that an 8 byte value of 0xffffffffffffffff + will be returned as (time_t)-1, whereas nt_time_to_unix returns 0 in this case. ****************************************************************************/ time_t interpret_long_date(char *p) @@ -392,6 +396,9 @@ time_t interpret_long_date(char *p) NTTIME nt; nt.low = IVAL(p,0); nt.high = IVAL(p,4); + if (nt.low == 0xFFFFFFFF && nt.high == 0xFFFFFFFF) { + return (time_t)-1; + } return nt_time_to_unix(&nt); } -- cgit From 5d1cb8e79edea9e8581d3c2c9dd297310cd9a98c Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 23 Mar 2005 23:26:33 +0000 Subject: r6014: rather large change set.... pulling back all recent rpc changes from trunk into 3.0. I've tested a compile and so don't think I've missed any files. But if so, just mail me and I'll clean backup in a couple of hours. Changes include \winreg, \eventlog, \svcctl, and general parse_misc.c updates. I am planning on bracketing the event code with an #ifdef ENABLE_EVENTLOG until I finish merging Marcin's changes (very soon). (This used to be commit 4e0ac63c36527cd8c52ef720cae17e84f67e7221) --- source3/lib/time.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index 84004a099b..9f94791b58 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -791,3 +791,25 @@ SMB_BIG_INT usec_time_diff(struct timeval *larget, struct timeval *smallt) SMB_BIG_INT sec_diff = larget->tv_sec - smallt->tv_sec; return (sec_diff * 1000000) + (SMB_BIG_INT)(larget->tv_usec - smallt->tv_usec); } + + +/**************************************************************************** + convert ASN.1 GeneralizedTime string to unix-time + returns 0 on failure; Currently ignores timezone. +****************************************************************************/ +time_t generalized_to_unix_time(const char *str) +{ + struct tm tm; + + ZERO_STRUCT(tm); + + if (sscanf(str, "%4d%2d%2d%2d%2d%2d", + &tm.tm_year, &tm.tm_mon, &tm.tm_mday, + &tm.tm_hour, &tm.tm_min, &tm.tm_sec) != 6) { + return 0; + } + tm.tm_year -= 1900; + tm.tm_mon -= 1; + + return timegm(&tm); +} -- cgit From f24d88cf9da46680d52b42b92bd484e7b09ce99b Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Tue, 31 May 2005 13:46:45 +0000 Subject: r7139: trying to reduce the number of diffs between trunk and 3.0; changing version to 3.0.20pre1 (This used to be commit 9727d05241574042dd3aa8844ae5c701d22e2da1) --- source3/lib/time.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index 9f94791b58..f7b0aefe4f 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -786,7 +786,7 @@ BOOL nt_time_is_zero(NTTIME *nt) Return a timeval difference in usec. ****************************************************************************/ -SMB_BIG_INT usec_time_diff(struct timeval *larget, struct timeval *smallt) +SMB_BIG_INT usec_time_diff(const struct timeval *larget, const struct timeval *smallt) { SMB_BIG_INT sec_diff = larget->tv_sec - smallt->tv_sec; return (sec_diff * 1000000) + (SMB_BIG_INT)(larget->tv_usec - smallt->tv_usec); -- cgit From 311cf22a2e028d560000da0645abd3625d1cbd3d Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Tue, 2 Aug 2005 20:44:30 +0000 Subject: r8946: Some casts to fix warnings when time_t is an unsigned type. Fixes bugzilla #1888 and #1894. (This used to be commit dcc74371388d280d8ee5130a04e1594ae88d19b3) --- source3/lib/time.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index f7b0aefe4f..5e0f5646fc 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -366,7 +366,7 @@ time_t nt_time_to_unix_abs(NTTIME *nt) return(0); if (nt->high==0x80000000 && nt->low==0) - return -1; + return (time_t)-1; /* reverse the time */ /* it's a negative value, turn it to positive */ @@ -421,7 +421,7 @@ void unix_to_nt_time(NTTIME *nt, time_t t) nt->high = 0x7fffffff; return; } - if (t == -1) { + if (t == (time_t)-1) { nt->low = 0xffffffff; nt->high = 0xffffffff; return; @@ -462,7 +462,7 @@ void unix_to_nt_time_abs(NTTIME *nt, time_t t) return; } - if (t == -1) { + if (t == (time_t)-1) { /* that's what NT uses for infinite */ nt->low = 0x0; nt->high = 0x80000000; -- cgit From 54abd2aa66069e6baf7769c496f46d9dba18db39 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 30 Sep 2005 17:13:37 +0000 Subject: r10656: BIG merge from trunk. Features not copied over * \PIPE\unixinfo * winbindd's {group,alias}membership new functions * winbindd's lookupsids() functionality * swat (trunk changes to be reverted as per discussion with Deryck) (This used to be commit 939c3cb5d78e3a2236209b296aa8aba8bdce32d3) --- source3/lib/time.c | 138 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 138 insertions(+) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index 5e0f5646fc..385762e82c 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -782,6 +782,15 @@ BOOL nt_time_is_zero(NTTIME *nt) return False; } +/**************************************************************************** + Check if two NTTIMEs are the same. +****************************************************************************/ + +BOOL nt_time_equals(NTTIME *nt1, NTTIME *nt2) +{ + return (nt1->high == nt2->high && nt1->low == nt2->low); +} + /**************************************************************************** Return a timeval difference in usec. ****************************************************************************/ @@ -792,6 +801,135 @@ SMB_BIG_INT usec_time_diff(const struct timeval *larget, const struct timeval *s return (sec_diff * 1000000) + (SMB_BIG_INT)(larget->tv_usec - smallt->tv_usec); } +/* + return a timeval struct with the given elements +*/ +struct timeval timeval_set(uint32_t secs, uint32_t usecs) +{ + struct timeval tv; + tv.tv_sec = secs; + tv.tv_usec = usecs; + return tv; +} + +/* + return a zero timeval +*/ +struct timeval timeval_zero(void) +{ + return timeval_set(0,0); +} + +/* + return True if a timeval is zero +*/ +BOOL timeval_is_zero(const struct timeval *tv) +{ + return tv->tv_sec == 0 && tv->tv_usec == 0; +} + +/* + return a timeval for the current time +*/ +struct timeval timeval_current(void) +{ + struct timeval tv; + GetTimeOfDay(&tv); + return tv; +} + +/* + return a timeval ofs microseconds after tv +*/ +struct timeval timeval_add(const struct timeval *tv, + uint32_t secs, uint32_t usecs) +{ + struct timeval tv2 = *tv; + tv2.tv_sec += secs; + tv2.tv_usec += usecs; + tv2.tv_sec += tv2.tv_usec / 1000000; + tv2.tv_usec = tv2.tv_usec % 1000000; + return tv2; +} + +/* + return the sum of two timeval structures +*/ +struct timeval timeval_sum(const struct timeval *tv1, + const struct timeval *tv2) +{ + return timeval_add(tv1, tv2->tv_sec, tv2->tv_usec); +} + +/* + return a timeval secs/usecs into the future +*/ +struct timeval timeval_current_ofs(uint32_t secs, uint32_t usecs) +{ + struct timeval tv = timeval_current(); + return timeval_add(&tv, secs, usecs); +} + +/* + compare two timeval structures. + Return -1 if tv1 < tv2 + Return 0 if tv1 == tv2 + Return 1 if tv1 > tv2 +*/ +int timeval_compare(const struct timeval *tv1, const struct timeval *tv2) +{ + if (tv1->tv_sec > tv2->tv_sec) return 1; + if (tv1->tv_sec < tv2->tv_sec) return -1; + if (tv1->tv_usec > tv2->tv_usec) return 1; + if (tv1->tv_usec < tv2->tv_usec) return -1; + return 0; +} + +/* + return the difference between two timevals as a timeval + if tv1 comes after tv2, then return a zero timeval + (this is *tv2 - *tv1) +*/ +struct timeval timeval_until(const struct timeval *tv1, + const struct timeval *tv2) +{ + struct timeval t; + if (timeval_compare(tv1, tv2) >= 0) { + return timeval_zero(); + } + t.tv_sec = tv2->tv_sec - tv1->tv_sec; + if (tv1->tv_usec > tv2->tv_usec) { + t.tv_sec--; + t.tv_usec = 1000000 - (tv1->tv_usec - tv2->tv_usec); + } else { + t.tv_usec = tv2->tv_usec - tv1->tv_usec; + } + return t; +} + +/* + return the lesser of two timevals +*/ +struct timeval timeval_min(const struct timeval *tv1, + const struct timeval *tv2) +{ + if (tv1->tv_sec < tv2->tv_sec) return *tv1; + if (tv1->tv_sec > tv2->tv_sec) return *tv2; + if (tv1->tv_usec < tv2->tv_usec) return *tv1; + return *tv2; +} + +/* + return the greater of two timevals +*/ +struct timeval timeval_max(const struct timeval *tv1, + const struct timeval *tv2) +{ + if (tv1->tv_sec > tv2->tv_sec) return *tv1; + if (tv1->tv_sec < tv2->tv_sec) return *tv2; + if (tv1->tv_usec > tv2->tv_usec) return *tv1; + return *tv2; +} /**************************************************************************** convert ASN.1 GeneralizedTime string to unix-time -- cgit From 6d5757395a0e54245543794d0d6d6d6a32cd857a Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 5 Nov 2005 04:21:55 +0000 Subject: r11511: A classic "friday night check-in" :-). This moves much of the Samba4 timezone handling code back into Samba3. Gets rid of "kludge-gmt" and removes the effectiveness of the parameter "time offset" (I can add this back in very easily if needed) - it's no longer being looked at. I'm hoping this will fix the problems people have been having with DST transitions. I'll start comprehensive testing tomorrow, but for now all modifications are done. Splits time get/set functions into srv_XXX and cli_XXX as they need to look at different timezone offsets. Get rid of much of the "efficiency" cruft that was added to Samba back in the day when the C library timezone handling functions were slow. Jeremy. (This used to be commit 414303bc0272f207046b471a0364fa296b67c1f8) --- source3/lib/time.c | 476 ++++++++++++++++++++++++++--------------------------- 1 file changed, 233 insertions(+), 243 deletions(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index 385762e82c..2bc4d47143 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -25,7 +25,6 @@ in May 1996 */ - int extra_time_offset = 0; #ifndef CHAR_BIT @@ -92,42 +91,42 @@ static int tm_diff(struct tm *a, struct tm *b) Return the UTC offset in seconds west of UTC, or 0 if it cannot be determined. ******************************************************************/ -static int TimeZone(time_t t) +int get_time_zone(time_t t) { struct tm *tm = gmtime(&t); struct tm tm_utc; - if (!tm) + + if (!tm) { return 0; + } tm_utc = *tm; tm = localtime(&t); - if (!tm) + if (!tm) { return 0; + } return tm_diff(&tm_utc,tm); } -static BOOL done_serverzone_init; - /******************************************************************* - Return the smb serverzone value. + Accessor function for the server time zone offset. + set_server_zone_offset() must have been called first. ******************************************************************/ -static int get_serverzone(void) -{ - static int serverzone; - - if (!done_serverzone_init) { - serverzone = TimeZone(time(NULL)); - - if ((serverzone % 60) != 0) { - DEBUG(1,("WARNING: Your timezone is not a multiple of 1 minute.\n")); - } +static int server_zone_offset; - DEBUG(4,("Serverzone is %d\n",serverzone)); +int get_server_zone_offset(void) +{ + return server_zone_offset; +} - done_serverzone_init = True; - } +/******************************************************************* + Initialize the server time zone offset. Called when a client connects. +******************************************************************/ - return serverzone; +int set_server_zone_offset(time_t t) +{ + server_zone_offset = get_time_zone(t); + return server_zone_offset; } /******************************************************************* @@ -138,11 +137,14 @@ static struct timeval start_time_hires; void TimeInit(void) { - done_serverzone_init = False; - get_serverzone(); + set_server_zone_offset(time(NULL)); + + DEBUG(4,("TimeInit: Serverzone is %d\n", server_zone_offset)); + /* Save the start time of this process. */ - if (start_time_hires.tv_sec == 0 && start_time_hires.tv_usec == 0) + if (start_time_hires.tv_sec == 0 && start_time_hires.tv_usec == 0) { GetTimeOfDay(&start_time_hires); + } } /********************************************************************** @@ -161,140 +163,21 @@ void get_process_uptime(struct timeval *ret_time) if (time_now_hires.tv_usec < start_time_hires.tv_usec) { ret_time->tv_sec -= 1; ret_time->tv_usec = 1000000 + (time_now_hires.tv_usec - start_time_hires.tv_usec); - } else - ret_time->tv_usec = time_now_hires.tv_usec - start_time_hires.tv_usec; -} - -/******************************************************************* - Return the same value as TimeZone, but it should be more efficient. - - We keep a table of DST offsets to prevent calling localtime() on each - call of this function. This saves a LOT of time on many unixes. - - Updated by Paul Eggert -********************************************************************/ - -static int TimeZoneFaster(time_t t) -{ - static struct dst_table {time_t start,end; int zone;} *tdt, *dst_table = NULL; - static int table_size = 0; - int i; - int zone = 0; - - if (t == 0) - t = time(NULL); - - /* Tunis has a 8 day DST region, we need to be careful ... */ -#define MAX_DST_WIDTH (365*24*60*60) -#define MAX_DST_SKIP (7*24*60*60) - - for (i=0;i= dst_table[i].start && t <= dst_table[i].end) - break; - - if (i MAX_DST_SKIP*2) - t = dst_table[i].start - MAX_DST_SKIP; - else - t = low + (dst_table[i].start-low)/2; - if (TimeZone(t) == zone) - dst_table[i].start = t; - else - low = t; - } - - while (high-60*60 > dst_table[i].end) { - if (high - dst_table[i].end > MAX_DST_SKIP*2) - t = dst_table[i].end + MAX_DST_SKIP; - else - t = high - (high-dst_table[i].end)/2; - if (TimeZone(t) == zone) - dst_table[i].end = t; - else - high = t; - } -#if 0 - DEBUG(1,("Added DST entry from %s ", - asctime(localtime(&dst_table[i].start)))); - DEBUG(1,("to %s (%d)\n",asctime(localtime(&dst_table[i].end)), - dst_table[i].zone)); -#endif - } + ret_time->tv_usec = time_now_hires.tv_usec - start_time_hires.tv_usec; } - return zone; } +#if 0 /**************************************************************************** Return the UTC offset in seconds west of UTC, adjusted for extra time offset. **************************************************************************/ int TimeDiff(time_t t) { - return TimeZoneFaster(t) + 60*extra_time_offset; -} - -/**************************************************************************** - Return the UTC offset in seconds west of UTC, adjusted for extra time - offset, for a local time value. If ut = lt + LocTimeDiff(lt), then - lt = ut - TimeDiff(ut), but the converse does not necessarily hold near - daylight savings transitions because some local times are ambiguous. - LocTimeDiff(t) equals TimeDiff(t) except near daylight savings transitions. -**************************************************************************/ - -static int LocTimeDiff(time_t lte) -{ - time_t lt = lte - 60*extra_time_offset; - int d = TimeZoneFaster(lt); - time_t t = lt + d; - - /* if overflow occurred, ignore all the adjustments so far */ - if (((lte < lt) ^ (extra_time_offset < 0)) | ((t < lt) ^ (d < 0))) - t = lte; - - /* now t should be close enough to the true UTC to yield the right answer */ - return TimeDiff(t); -} - -/**************************************************************************** - Try to optimise the localtime call, it can be quite expensive on some machines. -****************************************************************************/ - -struct tm *LocalTime(time_t *t) -{ - time_t t2 = *t; - - t2 -= TimeDiff(t2); - - return(gmtime(&t2)); + return get_time_zone(t); } +#endif #define TIME_FIXUP_CONSTANT (369.0*365.25*24*60*60-(3.0*24*60*60+6.0*60*60)) @@ -304,10 +187,7 @@ struct tm *LocalTime(time_t *t) An 8 byte value of 0xffffffffffffffff will be returned as (time_t)0. - It appears to be kludge-GMT (at least for file listings). This means - its the GMT you get by taking a localtime and adding the - serverzone. This is NOT the same as GMT in some cases. This routine - converts this to real GMT. + Returns GMT. ****************************************************************************/ time_t nt_time_to_unix(NTTIME *nt) @@ -319,8 +199,9 @@ time_t nt_time_to_unix(NTTIME *nt) time_t l_time_min = TIME_T_MIN; time_t l_time_max = TIME_T_MAX; - if (nt->high == 0 || (nt->high == 0xffffffff && nt->low == 0xffffffff)) + if (nt->high == 0 || (nt->high == 0xffffffff && nt->low == 0xffffffff)) { return(0); + } d = ((double)nt->high)*4.0*(double)(1<<30); d += (nt->low&0xFFF00000); @@ -329,18 +210,15 @@ time_t nt_time_to_unix(NTTIME *nt) /* now adjust by 369 years to make the secs since 1970 */ d -= TIME_FIXUP_CONSTANT; - if (d <= l_time_min) + if (d <= l_time_min) { return (l_time_min); + } - if (d >= l_time_max) + if (d >= l_time_max) { return (l_time_max); + } ret = (time_t)(d+0.5); - - /* this takes us from kludge-GMT to real GMT */ - ret -= get_serverzone(); - ret += LocTimeDiff(ret); - return(ret); } @@ -362,11 +240,13 @@ time_t nt_time_to_unix_abs(NTTIME *nt) time_t l_time_min = TIME_T_MIN; time_t l_time_max = TIME_T_MAX; - if (nt->high == 0) + if (nt->high == 0) { return(0); + } - if (nt->high==0x80000000 && nt->low==0) + if (nt->high==0x80000000 && nt->low==0) { return (time_t)-1; + } /* reverse the time */ /* it's a negative value, turn it to positive */ @@ -377,8 +257,9 @@ time_t nt_time_to_unix_abs(NTTIME *nt) d += (nt->low&0xFFF00000); d *= 1.0e-7; - if (!(l_time_min <= d && d <= l_time_max)) + if (!(l_time_min <= d && d <= l_time_max)) { return(0); + } ret = (time_t)(d+0.5); @@ -403,8 +284,7 @@ time_t interpret_long_date(char *p) } /**************************************************************************** - Put a 8 byte filetime from a time_t - This takes real GMT as input and converts to kludge-GMT + Put a 8 byte filetime from a time_t. Uses GMT. ****************************************************************************/ void unix_to_nt_time(NTTIME *nt, time_t t) @@ -427,9 +307,6 @@ void unix_to_nt_time(NTTIME *nt, time_t t) return; } - /* this converts GMT to kludge-GMT */ - t -= TimeDiff(t) - get_serverzone(); - d = (double)(t); d += TIME_FIXUP_CONSTANT; d *= 1.0e7; @@ -485,7 +362,7 @@ void unix_to_nt_time_abs(NTTIME *nt, time_t t) pointed to by p. ****************************************************************************/ -void put_long_date(char *p,time_t t) +void put_long_date(char *p, time_t t) { NTTIME nt; unix_to_nt_time(&nt, t); @@ -533,14 +410,20 @@ static uint16 make_dos_time1(struct tm *t) This takes a GMT time and returns a packed localtime structure. ********************************************************************/ -static uint32 make_dos_date(time_t unixdate) +static uint32 make_dos_date(time_t unixdate, int zone_offset) { struct tm *t; uint32 ret=0; - t = LocalTime(&unixdate); - if (!t) + if (unixdate == 0) { + return 0; + } + + unixdate -= zone_offset; + t = gmtime(&unixdate); + if (!t) { return 0xFFFFFFFF; + } ret = make_dos_date1(t); ret = ((ret&0xFFFF)<<16) | make_dos_time1(t); @@ -553,9 +436,9 @@ static uint32 make_dos_date(time_t unixdate) This takes GMT time and puts local time in the buffer. ********************************************************************/ -void put_dos_date(char *buf,int offset,time_t unixdate) +static void put_dos_date(char *buf,int offset,time_t unixdate, int zone_offset) { - uint32 x = make_dos_date(unixdate); + uint32 x = make_dos_date(unixdate, zone_offset); SIVAL(buf,offset,x); } @@ -564,9 +447,9 @@ void put_dos_date(char *buf,int offset,time_t unixdate) This takes GMT time and puts local time in the buffer. ********************************************************************/ -void put_dos_date2(char *buf,int offset,time_t unixdate) +static void put_dos_date2(char *buf,int offset,time_t unixdate, int zone_offset) { - uint32 x = make_dos_date(unixdate); + uint32 x = make_dos_date(unixdate, zone_offset); x = ((x&0xFFFF)<<16) | ((x&0xFFFF0000)>>16); SIVAL(buf,offset,x); } @@ -577,10 +460,11 @@ void put_dos_date2(char *buf,int offset,time_t unixdate) localtime for this sort of date) ********************************************************************/ -void put_dos_date3(char *buf,int offset,time_t unixdate) +static void put_dos_date3(char *buf,int offset,time_t unixdate, int zone_offset) { - if (!null_mtime(unixdate)) - unixdate -= TimeDiff(unixdate); + if (!null_mtime(unixdate)) { + unixdate -= zone_offset; + } SIVAL(buf,offset,unixdate); } @@ -608,7 +492,7 @@ static void interpret_dos_date(uint32 date,int *year,int *month,int *day,int *ho localtime). ********************************************************************/ -time_t make_unix_date(void *date_ptr) +static time_t make_unix_date(void *date_ptr, int zone_offset) { uint32 dos_date=0; struct tm t; @@ -616,15 +500,17 @@ time_t make_unix_date(void *date_ptr) dos_date = IVAL(date_ptr,0); - if (dos_date == 0) - return(0); + if (dos_date == 0) { + return 0; + } interpret_dos_date(dos_date,&t.tm_year,&t.tm_mon, &t.tm_mday,&t.tm_hour,&t.tm_min,&t.tm_sec); t.tm_isdst = -1; - /* mktime() also does the local to GMT time conversion for us */ - ret = mktime(&t); + ret = timegm(&t); + + ret += zone_offset; return(ret); } @@ -633,7 +519,7 @@ time_t make_unix_date(void *date_ptr) Like make_unix_date() but the words are reversed. ********************************************************************/ -time_t make_unix_date2(void *date_ptr) +static time_t make_unix_date2(void *date_ptr, int zone_offset) { uint32 x,x2; @@ -641,7 +527,7 @@ time_t make_unix_date2(void *date_ptr) x2 = ((x&0xFFFF)<<16) | ((x&0xFFFF0000)>>16); SIVAL(&x,0,x2); - return(make_unix_date((void *)&x)); + return(make_unix_date((void *)&x, zone_offset)); } /******************************************************************* @@ -649,14 +535,83 @@ time_t make_unix_date2(void *date_ptr) these generally arrive as localtimes, with corresponding DST. ******************************************************************/ -time_t make_unix_date3(void *date_ptr) +static time_t make_unix_date3(void *date_ptr, int zone_offset) { time_t t = (time_t)IVAL(date_ptr,0); - if (!null_mtime(t)) - t += LocTimeDiff(t); + if (!null_mtime(t)) { + t += zone_offset; + } return(t); } +/*************************************************************************** + Server versions of the above functions. +***************************************************************************/ + +void srv_put_dos_date(char *buf,int offset,time_t unixdate) +{ + put_dos_date(buf, offset, unixdate, server_zone_offset); +} + +void srv_put_dos_date2(char *buf,int offset, time_t unixdate) +{ + put_dos_date2(buf, offset, unixdate, server_zone_offset); +} + +void srv_put_dos_date3(char *buf,int offset,time_t unixdate) +{ + put_dos_date3(buf, offset, unixdate, server_zone_offset); +} + +time_t srv_make_unix_date(void *date_ptr) +{ + return make_unix_date(date_ptr, server_zone_offset); +} + +time_t srv_make_unix_date2(void *date_ptr) +{ + return make_unix_date2(date_ptr, server_zone_offset); +} + +time_t srv_make_unix_date3(void *date_ptr) +{ + return make_unix_date3(date_ptr, server_zone_offset); +} + +/*************************************************************************** + Client versions of the above functions. +***************************************************************************/ + +void cli_put_dos_date(struct cli_state *cli, char *buf, int offset, time_t unixdate) +{ + put_dos_date(buf, offset, unixdate, cli->serverzone); +} + +void cli_put_dos_date2(struct cli_state *cli, char *buf, int offset, time_t unixdate) +{ + put_dos_date2(buf, offset, unixdate, cli->serverzone); +} + +void cli_put_dos_date3(struct cli_state *cli, char *buf, int offset, time_t unixdate) +{ + put_dos_date3(buf, offset, unixdate, cli->serverzone); +} + +time_t cli_make_unix_date(struct cli_state *cli, void *date_ptr) +{ + return make_unix_date(date_ptr, cli->serverzone); +} + +time_t cli_make_unix_date2(struct cli_state *cli, void *date_ptr) +{ + return make_unix_date2(date_ptr, cli->serverzone); +} + +time_t cli_make_unix_date3(struct cli_state *cli, void *date_ptr) +{ + return make_unix_date3(date_ptr, cli->serverzone); +} + /*************************************************************************** Return a HTTP/1.0 time string. ***************************************************************************/ @@ -664,7 +619,7 @@ time_t make_unix_date3(void *date_ptr) char *http_timestring(time_t t) { static fstring buf; - struct tm *tm = LocalTime(&t); + struct tm *tm = localtime(&t); if (!tm) slprintf(buf,sizeof(buf)-1,"%ld seconds since the Epoch",(long)t); @@ -696,7 +651,7 @@ char *timestring(BOOL hires) } else { t = time(NULL); } - tm = LocalTime(&t); + tm = localtime(&t); if (!tm) { if (hires) { slprintf(TimeBuf, @@ -745,14 +700,16 @@ time_t get_create_time(SMB_STRUCT_STAT *st,BOOL fake_dirs) { time_t ret, ret1; - if(S_ISDIR(st->st_mode) && fake_dirs) + if(S_ISDIR(st->st_mode) && fake_dirs) { return (time_t)315493200L; /* 1/1/1980 */ + } ret = MIN(st->st_ctime, st->st_mtime); ret1 = MIN(ret, st->st_atime); - if(ret1 != (time_t)0) + if(ret1 != (time_t)0) { return ret1; + } /* * One of ctime, mtime or atime was zero (probably atime). @@ -777,8 +734,9 @@ void init_nt_time(NTTIME *nt) BOOL nt_time_is_zero(NTTIME *nt) { - if(nt->high==0) + if(nt->high==0) { return True; + } return False; } @@ -801,9 +759,10 @@ SMB_BIG_INT usec_time_diff(const struct timeval *larget, const struct timeval *s return (sec_diff * 1000000) + (SMB_BIG_INT)(larget->tv_usec - smallt->tv_usec); } -/* - return a timeval struct with the given elements -*/ +/**************************************************************************** + Return a timeval struct with the given elements. +****************************************************************************/ + struct timeval timeval_set(uint32_t secs, uint32_t usecs) { struct timeval tv; @@ -812,25 +771,28 @@ struct timeval timeval_set(uint32_t secs, uint32_t usecs) return tv; } -/* - return a zero timeval -*/ +/**************************************************************************** + Return a zero timeval. +****************************************************************************/ + struct timeval timeval_zero(void) { return timeval_set(0,0); } -/* - return True if a timeval is zero -*/ +/**************************************************************************** + Return True if a timeval is zero. +****************************************************************************/ + BOOL timeval_is_zero(const struct timeval *tv) { return tv->tv_sec == 0 && tv->tv_usec == 0; } -/* - return a timeval for the current time -*/ +/**************************************************************************** + Return a timeval for the current time. +****************************************************************************/ + struct timeval timeval_current(void) { struct timeval tv; @@ -838,9 +800,10 @@ struct timeval timeval_current(void) return tv; } -/* - return a timeval ofs microseconds after tv -*/ +/**************************************************************************** + Return a timeval ofs microseconds after tv. +****************************************************************************/ + struct timeval timeval_add(const struct timeval *tv, uint32_t secs, uint32_t usecs) { @@ -852,44 +815,56 @@ struct timeval timeval_add(const struct timeval *tv, return tv2; } -/* - return the sum of two timeval structures -*/ +/**************************************************************************** + Return the sum of two timeval structures. +****************************************************************************/ + struct timeval timeval_sum(const struct timeval *tv1, const struct timeval *tv2) { return timeval_add(tv1, tv2->tv_sec, tv2->tv_usec); } -/* - return a timeval secs/usecs into the future -*/ +/**************************************************************************** + Return a timeval secs/usecs into the future. +****************************************************************************/ + struct timeval timeval_current_ofs(uint32_t secs, uint32_t usecs) { struct timeval tv = timeval_current(); return timeval_add(&tv, secs, usecs); } -/* - compare two timeval structures. - Return -1 if tv1 < tv2 - Return 0 if tv1 == tv2 - Return 1 if tv1 > tv2 -*/ +/**************************************************************************** + Compare two timeval structures. + Return -1 if tv1 < tv2 + Return 0 if tv1 == tv2 + Return 1 if tv1 > tv2 +****************************************************************************/ + int timeval_compare(const struct timeval *tv1, const struct timeval *tv2) { - if (tv1->tv_sec > tv2->tv_sec) return 1; - if (tv1->tv_sec < tv2->tv_sec) return -1; - if (tv1->tv_usec > tv2->tv_usec) return 1; - if (tv1->tv_usec < tv2->tv_usec) return -1; + if (tv1->tv_sec > tv2->tv_sec) { + return 1; + } + if (tv1->tv_sec < tv2->tv_sec) { + return -1; + } + if (tv1->tv_usec > tv2->tv_usec) { + return 1; + } + if (tv1->tv_usec < tv2->tv_usec) { + return -1; + } return 0; } -/* - return the difference between two timevals as a timeval - if tv1 comes after tv2, then return a zero timeval - (this is *tv2 - *tv1) -*/ +/**************************************************************************** + Return the difference between two timevals as a timeval. + If tv1 comes after tv2, then return a zero timeval + (this is *tv2 - *tv1). +****************************************************************************/ + struct timeval timeval_until(const struct timeval *tv1, const struct timeval *tv2) { @@ -907,34 +882,49 @@ struct timeval timeval_until(const struct timeval *tv1, return t; } -/* - return the lesser of two timevals -*/ +/**************************************************************************** + Return the lesser of two timevals. +****************************************************************************/ + struct timeval timeval_min(const struct timeval *tv1, const struct timeval *tv2) { - if (tv1->tv_sec < tv2->tv_sec) return *tv1; - if (tv1->tv_sec > tv2->tv_sec) return *tv2; - if (tv1->tv_usec < tv2->tv_usec) return *tv1; + if (tv1->tv_sec < tv2->tv_sec) { + return *tv1; + } + if (tv1->tv_sec > tv2->tv_sec) { + return *tv2; + } + if (tv1->tv_usec < tv2->tv_usec) { + return *tv1; + } return *tv2; } -/* - return the greater of two timevals -*/ +/**************************************************************************** + Return the greater of two timevals. +****************************************************************************/ + struct timeval timeval_max(const struct timeval *tv1, const struct timeval *tv2) { - if (tv1->tv_sec > tv2->tv_sec) return *tv1; - if (tv1->tv_sec < tv2->tv_sec) return *tv2; - if (tv1->tv_usec > tv2->tv_usec) return *tv1; + if (tv1->tv_sec > tv2->tv_sec) { + return *tv1; + } + if (tv1->tv_sec < tv2->tv_sec) { + return *tv2; + } + if (tv1->tv_usec > tv2->tv_usec) { + return *tv1; + } return *tv2; } /**************************************************************************** - convert ASN.1 GeneralizedTime string to unix-time - returns 0 on failure; Currently ignores timezone. + Convert ASN.1 GeneralizedTime string to unix-time. + Returns 0 on failure; Currently ignores timezone. ****************************************************************************/ + time_t generalized_to_unix_time(const char *str) { struct tm tm; -- cgit From 47873110838038a864c964682b3bd200ce977f88 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sun, 6 Nov 2005 01:55:09 +0000 Subject: r11530: Add the "time offset" parameter back in for people who might use it. Jeremy. (This used to be commit b745114423a482ea8cd1ea4f80ec3fc2a9caa971) --- source3/lib/time.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index 2bc4d47143..989589121b 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -104,7 +104,7 @@ int get_time_zone(time_t t) if (!tm) { return 0; } - return tm_diff(&tm_utc,tm); + return tm_diff(&tm_utc,tm) + 60*extra_time_offset; } /******************************************************************* -- cgit From da979c9e7eb0c03ac718eb2c6c50937e52c39292 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 4 Feb 2006 21:44:57 +0000 Subject: r13350: Implement rpccli_samr_set_domain_info. Weird that it was not around :-) Implement 'net rpc shell account' -- An editor for account policies nt_time_to_unix_abs changed its argument which to me seems wrong, and I could not find a caller that depends on this. So I changed it. Applied some more const in time.c. Volker (This used to be commit fc73690a7000d5a3f0f5ad34461c1f3a87edeac5) --- source3/lib/time.c | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index 989589121b..f87e53fef5 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -231,7 +231,7 @@ time_t nt_time_to_unix(NTTIME *nt) if the NTTIME was 5 seconds, the time_t is 5 seconds. JFM ****************************************************************************/ -time_t nt_time_to_unix_abs(NTTIME *nt) +time_t nt_time_to_unix_abs(const NTTIME *nt) { double d; time_t ret; @@ -239,6 +239,7 @@ time_t nt_time_to_unix_abs(NTTIME *nt) broken SCO compiler. JRA. */ time_t l_time_min = TIME_T_MIN; time_t l_time_max = TIME_T_MAX; + NTTIME neg_nt; if (nt->high == 0) { return(0); @@ -250,11 +251,11 @@ time_t nt_time_to_unix_abs(NTTIME *nt) /* reverse the time */ /* it's a negative value, turn it to positive */ - nt->high=~nt->high; - nt->low=~nt->low; + neg_nt.high=~nt->high; + neg_nt.low=~nt->low; - d = ((double)nt->high)*4.0*(double)(1<<30); - d += (nt->low&0xFFF00000); + d = ((double)neg_nt.high)*4.0*(double)(1<<30); + d += (neg_nt.low&0xFFF00000); d *= 1.0e-7; if (!(l_time_min <= d && d <= l_time_max)) { @@ -728,11 +729,24 @@ void init_nt_time(NTTIME *nt) nt->low = 0xFFFFFFFF; } +BOOL nt_time_is_set(const NTTIME *nt) +{ + if ((nt->high == 0x7FFFFFFF) && (nt->low == 0xFFFFFFFF)) { + return False; + } + + if ((nt->high == 0x80000000) && (nt->low == 0)) { + return False; + } + + return True; +} + /**************************************************************************** Check if NTTIME is 0. ****************************************************************************/ -BOOL nt_time_is_zero(NTTIME *nt) +BOOL nt_time_is_zero(const NTTIME *nt) { if(nt->high==0) { return True; @@ -744,7 +758,7 @@ BOOL nt_time_is_zero(NTTIME *nt) Check if two NTTIMEs are the same. ****************************************************************************/ -BOOL nt_time_equals(NTTIME *nt1, NTTIME *nt2) +BOOL nt_time_equals(const NTTIME *nt1, const NTTIME *nt2) { return (nt1->high == nt2->high && nt1->low == nt2->low); } -- cgit From 687e5be25e6090cf73867c3e08dab6a381c0adbc Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 10 Feb 2006 01:43:33 +0000 Subject: r13423: Write wrapper functions (and configure tests) so we can always assume we can get a struct timespec out of a stat struct. This will allow us to portably move to nsec timestamps on files and directories in the file server code in future. Jeremy. (This used to be commit 07132d8796a08aa71d6719cb07b5b2c999930632) --- source3/lib/time.c | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index f87e53fef5..b6a22a3098 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -955,3 +955,105 @@ time_t generalized_to_unix_time(const char *str) return timegm(&tm); } + +/**************************************************************************** + Return all the possible time fields from a stat struct as a timespec. +****************************************************************************/ + +struct timespec get_atimespec(SMB_STRUCT_STAT *pst) +{ +#if !defined(HAVE_STAT_HIRES_TIMESTAMPS) + struct timespec ret; + + /* Old system - no ns timestamp. */ + ret.tv_sec = pst->st_atime; + ret.tv_nsec = 0; + return ret; +#else +#if defined(HAVE_STAT_ST_ATIM) + return pst->st_atim; +#elif defined(HAVE_STAT_ST_ATIMENSEC) + struct timespec ret; + ret.tv_sec = pst->st_atime; + ret.tv_nsec = pst->st_atimensec; + return ret; +#else +#error CONFIGURE_ERROR_IN_DETECTING_TIMESPEC_IN_STAT +#endif +#endif +} + +struct timespec get_mtimespec(SMB_STRUCT_STAT *pst) +{ +#if !defined(HAVE_STAT_HIRES_TIMESTAMPS) + struct timespec ret; + + /* Old system - no ns timestamp. */ + ret.tv_sec = pst->st_mtime; + ret.tv_nsec = 0; + return ret; +#else +#if defined(HAVE_STAT_ST_MTIM) + return pst->st_mtim; +#elif defined(HAVE_STAT_ST_MTIMENSEC) + struct timespec ret; + ret.tv_sec = pst->st_mtime; + ret.tv_nsec = pst->st_mtimensec; + return ret; +#else +#error CONFIGURE_ERROR_IN_DETECTING_TIMESPEC_IN_STAT +#endif +#endif +} + +struct timespec get_ctimespec(SMB_STRUCT_STAT *pst) +{ +#if !defined(HAVE_STAT_HIRES_TIMESTAMPS) + struct timespec ret; + + /* Old system - no ns timestamp. */ + ret.tv_sec = pst->ctime; + ret.tv_nsec = 0; + return ret; +#else +#if defined(HAVE_STAT_ST_CTIM) + return pst->st_ctim; +#elif defined(HAVE_STAT_ST_CTIMENSEC) + struct timespec ret; + ret.tv_sec = pst->st_ctime; + ret.tv_nsec = pst->st_ctimensec; + return ret; +#else +#error CONFIGURE_ERROR_IN_DETECTING_TIMESPEC_IN_STAT +#endif +#endif +} + +#if 0 +/**************************************************************************** + Return the best approximation to a 'create time' under UNIX from a stat + structure. +****************************************************************************/ + +struct timespec get_create_timespec(SMB_STRUCT_STAT *st,BOOL fake_dirs) +{ + time_t ret, ret1; + + if(S_ISDIR(st->st_mode) && fake_dirs) { + return (time_t)315493200L; /* 1/1/1980 */ + } + + ret = MIN(st->st_ctime, st->st_mtime); + ret1 = MIN(ret, st->st_atime); + + if(ret1 != (time_t)0) { + return ret1; + } + + /* + * One of ctime, mtime or atime was zero (probably atime). + * Just return MIN(ctime, mtime). + */ + return ret; +} +#endif -- cgit From e5ec28ae5566369bcb9d522a2805c5d99eb5d248 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 10 Feb 2006 05:13:37 +0000 Subject: r13427: Fix ctime -> st_ctime. Jeremy. (This used to be commit 95793d7e64d30190ebf917745c719f9c5a1b31e2) --- source3/lib/time.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index b6a22a3098..a13dcf1646 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -1012,7 +1012,7 @@ struct timespec get_ctimespec(SMB_STRUCT_STAT *pst) struct timespec ret; /* Old system - no ns timestamp. */ - ret.tv_sec = pst->ctime; + ret.tv_sec = pst->st_ctime; ret.tv_nsec = 0; return ret; #else -- cgit From ea069fcf0193cb359cec7e69548d08d069d641da Mon Sep 17 00:00:00 2001 From: James Peach Date: Fri, 5 May 2006 06:16:44 +0000 Subject: r15449: Remove unused function get_nttime_max (which claims it is incorrect). (This used to be commit e7ddcd8c33de1d2f053ac4c5fdaef5c31c280318) --- source3/lib/time.c | 6 ------ 1 file changed, 6 deletions(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index a13dcf1646..749af37cae 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -39,12 +39,6 @@ int extra_time_offset = 0; #define TIME_T_MAX (~ (time_t) 0 - TIME_T_MIN) #endif -void get_nttime_max(NTTIME *t) -{ - /* FIXME: This is incorrect */ - unix_to_nt_time(t, get_time_t_max()); -} - /******************************************************************* External access to time_t_min and time_t_max. ********************************************************************/ -- cgit From 92913918852b0efae64672421554783af1ec3240 Mon Sep 17 00:00:00 2001 From: Jim McDonough Date: Mon, 5 Jun 2006 16:59:10 +0000 Subject: r16047: Remove unnecessary line, as this value is set in either branch of the 'if' below. Spotted by Aleksey Fedoseev. (This used to be commit 00eb42791abf3e34dc42a2067f07b8549ea31abb) --- source3/lib/time.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index 749af37cae..f8a1538910 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -153,7 +153,6 @@ void get_process_uptime(struct timeval *ret_time) GetTimeOfDay(&time_now_hires); ret_time->tv_sec = time_now_hires.tv_sec - start_time_hires.tv_sec; - ret_time->tv_usec = time_now_hires.tv_usec - start_time_hires.tv_usec; if (time_now_hires.tv_usec < start_time_hires.tv_usec) { ret_time->tv_sec -= 1; ret_time->tv_usec = 1000000 + (time_now_hires.tv_usec - start_time_hires.tv_usec); -- cgit From a1e0a0e9286fbe90ca04cda9df38e72d8d18b0c1 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 14 Jun 2006 21:36:49 +0000 Subject: r16230: Fix Klocwork #861 and others. localtime and asctime can return NULL. Ensure we check all returns correctly. Jeremy. (This used to be commit 6c61dc8ed6d84f310ef391fb7700e93ef42c4afc) --- source3/lib/time.c | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index f8a1538910..9a539d415e 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -615,16 +615,19 @@ char *http_timestring(time_t t) static fstring buf; struct tm *tm = localtime(&t); - if (!tm) + if (!tm) { slprintf(buf,sizeof(buf)-1,"%ld seconds since the Epoch",(long)t); - else + } else { #ifndef HAVE_STRFTIME - fstrcpy(buf, asctime(tm)); - if(buf[strlen(buf)-1] == '\n') + const char *asct = asctime(tm); + fstrcpy(buf, asct ? asct : "unknown"); + } + if(buf[strlen(buf)-1] == '\n') { buf[strlen(buf)-1] = 0; #else /* !HAVE_STRFTIME */ strftime(buf, sizeof(buf)-1, "%a, %d %b %Y %H:%M:%S %Z", tm); #endif /* !HAVE_STRFTIME */ + } return buf; } @@ -672,13 +675,15 @@ char *timestring(BOOL hires) } #else if (hires) { + const char *asct = asctime(tm); slprintf(TimeBuf, sizeof(TimeBuf)-1, "%s.%06ld", - asctime(tm), + asct ? asct : "unknown", (long)tp.tv_usec); } else { - fstrcpy(TimeBuf, asctime(tm)); + const char *asct = asctime(tm); + fstrcpy(TimeBuf, asct ? asct : "unknown"); } #endif } @@ -1050,3 +1055,24 @@ struct timespec get_create_timespec(SMB_STRUCT_STAT *st,BOOL fake_dirs) return ret; } #endif + +/**************************************************************************** + Utility function that always returns a const string even if localtime + and asctime fail. +****************************************************************************/ + +const char *time_to_asc(const time_t *t) +{ + const char *asct; + struct tm *lt = localtime(t); + + if (!lt) { + return "unknown time"; + } + + asct = asctime(lt); + if (!asct) { + return "unknown time"; + } + return asct; +} -- cgit From fbdcf2663b56007a438ac4f0d8d82436b1bfe688 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 11 Jul 2006 18:01:26 +0000 Subject: r16945: Sync trunk -> 3.0 for 3.0.24 code. Still need to do the upper layer directories but this is what everyone is waiting for.... Jeremy. (This used to be commit 9dafb7f48ca3e7af956b0a7d1720c2546fc4cfb8) --- source3/lib/time.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index 9a539d415e..0bfdfac856 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -635,7 +635,7 @@ char *http_timestring(time_t t) Return the date and time as a string ****************************************************************************/ -char *timestring(BOOL hires) +char *current_timestring(BOOL hires) { static fstring TimeBuf; struct timeval tp; @@ -1056,6 +1056,51 @@ struct timespec get_create_timespec(SMB_STRUCT_STAT *st,BOOL fake_dirs) } #endif + +/** + Return the date and time as a string +**/ +char *timestring(TALLOC_CTX *mem_ctx, time_t t) +{ + char *TimeBuf; + char tempTime[80]; + struct tm *tm; + + tm = localtime(&t); + if (!tm) { + return talloc_asprintf(mem_ctx, + "%ld seconds since the Epoch", + (long)t); + } + +#ifdef HAVE_STRFTIME + /* some versions of gcc complain about using %c. This is a bug + in the gcc warning, not a bug in this code. See a recent + strftime() manual page for details. + */ + strftime(tempTime,sizeof(tempTime)-1,"%c %Z",tm); + TimeBuf = talloc_strdup(mem_ctx, tempTime); +#else + TimeBuf = talloc_strdup(mem_ctx, asctime(tm)); +#endif + + return TimeBuf; +} + + +/** + return a talloced string representing a NTTIME for human consumption +*/ +const char *nt_time_string(TALLOC_CTX *mem_ctx, NTTIME nt) +{ + time_t t; + if (nt.low == 0 && nt.high == 0) { + return "NTTIME(0)"; + } + t = nt_time_to_unix(&nt); + return timestring(mem_ctx, t); +} + /**************************************************************************** Utility function that always returns a const string even if localtime and asctime fail. -- cgit From 89f6af42ba33ce2c43f891d7da229725a66cc4e6 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 24 Aug 2006 01:31:00 +0000 Subject: r17766: Getting ready to properly expose 100ns times on the wire. Move the internals of nt_time functions to use struct timespecs. Jeremy. (This used to be commit 4ece92f7ef070c86ee7c6f523a207cfaccf84478) --- source3/lib/time.c | 97 ++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 68 insertions(+), 29 deletions(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index 0bfdfac856..9c5f412a9d 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -178,22 +178,28 @@ int TimeDiff(time_t t) Interpret an 8 byte "filetime" structure to a time_t It's originally in "100ns units since jan 1st 1601" - An 8 byte value of 0xffffffffffffffff will be returned as (time_t)0. + An 8 byte value of 0xffffffffffffffff will be returned as a timespec of + + tv_sec = 0 + tv_nsec = 0; Returns GMT. ****************************************************************************/ -time_t nt_time_to_unix(NTTIME *nt) +struct timespec nt_time_to_unix_timespec(NTTIME *nt) { double d; - time_t ret; + struct timespec ret; /* The next two lines are a fix needed for the broken SCO compiler. JRA. */ time_t l_time_min = TIME_T_MIN; time_t l_time_max = TIME_T_MAX; - if (nt->high == 0 || (nt->high == 0xffffffff && nt->low == 0xffffffff)) { - return(0); + if ((nt->high == 0 && nt->low == 0 )|| + (nt->high == 0xffffffff && nt->low == 0xffffffff)) { + ret.tv_sec = 0; + ret.tv_nsec = 0; + return ret; } d = ((double)nt->high)*4.0*(double)(1<<30); @@ -204,15 +210,26 @@ time_t nt_time_to_unix(NTTIME *nt) d -= TIME_FIXUP_CONSTANT; if (d <= l_time_min) { - return (l_time_min); + ret.tv_sec = l_time_min; + ret.tv_nsec = 0; + return ret; } if (d >= l_time_max) { - return (l_time_max); + ret.tv_sec = l_time_max; + ret.tv_nsec = 0; + return ret; } - ret = (time_t)(d+0.5); - return(ret); + ret.tv_sec = (time_t)d; + ret.tv_nsec = (long) ((d*1.0e9) - ((double)ret.tv_sec)*1.0e9); + return ret; +} + +time_t nt_time_to_unix(NTTIME *nt) +{ + struct timespec ts = nt_time_to_unix_timespec(nt); + return ts.tv_sec; } /**************************************************************************** @@ -224,10 +241,10 @@ time_t nt_time_to_unix(NTTIME *nt) if the NTTIME was 5 seconds, the time_t is 5 seconds. JFM ****************************************************************************/ -time_t nt_time_to_unix_abs(const NTTIME *nt) +struct timespec nt_time_to_unix_abs(const NTTIME *nt) { double d; - time_t ret; + struct timespec ret; /* The next two lines are a fix needed for the broken SCO compiler. JRA. */ time_t l_time_min = TIME_T_MIN; @@ -235,11 +252,15 @@ time_t nt_time_to_unix_abs(const NTTIME *nt) NTTIME neg_nt; if (nt->high == 0) { - return(0); + ret.tv_sec = 0; + ret.tv_nsec = 0; + return ret; } if (nt->high==0x80000000 && nt->low==0) { - return (time_t)-1; + ret.tv_sec = (time_t)-1; + ret.tv_nsec = 0; + return ret; } /* reverse the time */ @@ -252,63 +273,81 @@ time_t nt_time_to_unix_abs(const NTTIME *nt) d *= 1.0e-7; if (!(l_time_min <= d && d <= l_time_max)) { - return(0); + ret.tv_sec = 0; + ret.tv_nsec = 0; + return ret; } - ret = (time_t)(d+0.5); - - return(ret); + ret.tv_sec = (time_t)d; + ret.tv_nsec = (long) ((d*1.0e9) - ((double)ret.tv_sec)*1.0e9); + return ret; } /**************************************************************************** - Interprets an nt time into a unix time_t. + Interprets an nt time into a unix struct timespec. Differs from nt_time_to_unix in that an 8 byte value of 0xffffffffffffffff will be returned as (time_t)-1, whereas nt_time_to_unix returns 0 in this case. ****************************************************************************/ -time_t interpret_long_date(char *p) +struct timespec interpret_long_date(char *p) { NTTIME nt; nt.low = IVAL(p,0); nt.high = IVAL(p,4); if (nt.low == 0xFFFFFFFF && nt.high == 0xFFFFFFFF) { - return (time_t)-1; + struct timespec ret; + ret.tv_sec = (time_t)-1; + ret.tv_nsec = 0; + return ret; } - return nt_time_to_unix(&nt); + return nt_time_to_unix_timespec(&nt); } /**************************************************************************** - Put a 8 byte filetime from a time_t. Uses GMT. + Put a 8 byte filetime from a struct timespec. Uses GMT. ****************************************************************************/ -void unix_to_nt_time(NTTIME *nt, time_t t) +void unix_timespec_to_nt_time(NTTIME *nt, struct timespec ts) { double d; - if (t==0) { + if (ts.tv_sec ==0 && ts.tv_nsec == 0) { nt->low = 0; nt->high = 0; return; } - if (t == TIME_T_MAX) { + if (ts.tv_sec == TIME_T_MAX) { nt->low = 0xffffffff; nt->high = 0x7fffffff; return; } - if (t == (time_t)-1) { + if (ts.tv_sec == (time_t)-1) { nt->low = 0xffffffff; nt->high = 0xffffffff; return; } - d = (double)(t); + d = (double)(ts.tv_sec); d += TIME_FIXUP_CONSTANT; d *= 1.0e7; + d += ((double)ts.tv_nsec / 100.0); nt->high = (uint32)(d * (1.0/(4.0*(double)(1<<30)))); nt->low = (uint32)(d - ((double)nt->high)*4.0*(double)(1<<30)); } +/**************************************************************************** + Put a 8 byte filetime from a time_t. Uses GMT. +****************************************************************************/ + +void unix_to_nt_time(NTTIME *nt, time_t t) +{ + struct timespec ts; + ts.tv_sec = t; + ts.tv_nsec = 0; + unix_timespec_to_nt_time(nt, ts); +} + /**************************************************************************** Convert a time_t to a NTTIME structure @@ -356,10 +395,10 @@ void unix_to_nt_time_abs(NTTIME *nt, time_t t) pointed to by p. ****************************************************************************/ -void put_long_date(char *p, time_t t) +void put_long_date(char *p, struct timespec ts) { NTTIME nt; - unix_to_nt_time(&nt, t); + unix_timespec_to_nt_time(&nt, ts); SIVAL(p, 0, nt.low); SIVAL(p, 4, nt.high); } -- cgit From a5a69ec15013cade97ef95c4e45a44063667dbe4 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 24 Aug 2006 01:34:33 +0000 Subject: r17767: Argggg. Broke the build. Need to fix callers of put_long_date() and interpret_long_date() first. Reverting... Jeremy. (This used to be commit 5d9c308e7b780c956f9810c9f345d1ef32d0f528) --- source3/lib/time.c | 97 ++++++++++++++++-------------------------------------- 1 file changed, 29 insertions(+), 68 deletions(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index 9c5f412a9d..0bfdfac856 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -178,28 +178,22 @@ int TimeDiff(time_t t) Interpret an 8 byte "filetime" structure to a time_t It's originally in "100ns units since jan 1st 1601" - An 8 byte value of 0xffffffffffffffff will be returned as a timespec of - - tv_sec = 0 - tv_nsec = 0; + An 8 byte value of 0xffffffffffffffff will be returned as (time_t)0. Returns GMT. ****************************************************************************/ -struct timespec nt_time_to_unix_timespec(NTTIME *nt) +time_t nt_time_to_unix(NTTIME *nt) { double d; - struct timespec ret; + time_t ret; /* The next two lines are a fix needed for the broken SCO compiler. JRA. */ time_t l_time_min = TIME_T_MIN; time_t l_time_max = TIME_T_MAX; - if ((nt->high == 0 && nt->low == 0 )|| - (nt->high == 0xffffffff && nt->low == 0xffffffff)) { - ret.tv_sec = 0; - ret.tv_nsec = 0; - return ret; + if (nt->high == 0 || (nt->high == 0xffffffff && nt->low == 0xffffffff)) { + return(0); } d = ((double)nt->high)*4.0*(double)(1<<30); @@ -210,26 +204,15 @@ struct timespec nt_time_to_unix_timespec(NTTIME *nt) d -= TIME_FIXUP_CONSTANT; if (d <= l_time_min) { - ret.tv_sec = l_time_min; - ret.tv_nsec = 0; - return ret; + return (l_time_min); } if (d >= l_time_max) { - ret.tv_sec = l_time_max; - ret.tv_nsec = 0; - return ret; + return (l_time_max); } - ret.tv_sec = (time_t)d; - ret.tv_nsec = (long) ((d*1.0e9) - ((double)ret.tv_sec)*1.0e9); - return ret; -} - -time_t nt_time_to_unix(NTTIME *nt) -{ - struct timespec ts = nt_time_to_unix_timespec(nt); - return ts.tv_sec; + ret = (time_t)(d+0.5); + return(ret); } /**************************************************************************** @@ -241,10 +224,10 @@ time_t nt_time_to_unix(NTTIME *nt) if the NTTIME was 5 seconds, the time_t is 5 seconds. JFM ****************************************************************************/ -struct timespec nt_time_to_unix_abs(const NTTIME *nt) +time_t nt_time_to_unix_abs(const NTTIME *nt) { double d; - struct timespec ret; + time_t ret; /* The next two lines are a fix needed for the broken SCO compiler. JRA. */ time_t l_time_min = TIME_T_MIN; @@ -252,15 +235,11 @@ struct timespec nt_time_to_unix_abs(const NTTIME *nt) NTTIME neg_nt; if (nt->high == 0) { - ret.tv_sec = 0; - ret.tv_nsec = 0; - return ret; + return(0); } if (nt->high==0x80000000 && nt->low==0) { - ret.tv_sec = (time_t)-1; - ret.tv_nsec = 0; - return ret; + return (time_t)-1; } /* reverse the time */ @@ -273,81 +252,63 @@ struct timespec nt_time_to_unix_abs(const NTTIME *nt) d *= 1.0e-7; if (!(l_time_min <= d && d <= l_time_max)) { - ret.tv_sec = 0; - ret.tv_nsec = 0; - return ret; + return(0); } - ret.tv_sec = (time_t)d; - ret.tv_nsec = (long) ((d*1.0e9) - ((double)ret.tv_sec)*1.0e9); - return ret; + ret = (time_t)(d+0.5); + + return(ret); } /**************************************************************************** - Interprets an nt time into a unix struct timespec. + Interprets an nt time into a unix time_t. Differs from nt_time_to_unix in that an 8 byte value of 0xffffffffffffffff will be returned as (time_t)-1, whereas nt_time_to_unix returns 0 in this case. ****************************************************************************/ -struct timespec interpret_long_date(char *p) +time_t interpret_long_date(char *p) { NTTIME nt; nt.low = IVAL(p,0); nt.high = IVAL(p,4); if (nt.low == 0xFFFFFFFF && nt.high == 0xFFFFFFFF) { - struct timespec ret; - ret.tv_sec = (time_t)-1; - ret.tv_nsec = 0; - return ret; + return (time_t)-1; } - return nt_time_to_unix_timespec(&nt); + return nt_time_to_unix(&nt); } /**************************************************************************** - Put a 8 byte filetime from a struct timespec. Uses GMT. + Put a 8 byte filetime from a time_t. Uses GMT. ****************************************************************************/ -void unix_timespec_to_nt_time(NTTIME *nt, struct timespec ts) +void unix_to_nt_time(NTTIME *nt, time_t t) { double d; - if (ts.tv_sec ==0 && ts.tv_nsec == 0) { + if (t==0) { nt->low = 0; nt->high = 0; return; } - if (ts.tv_sec == TIME_T_MAX) { + if (t == TIME_T_MAX) { nt->low = 0xffffffff; nt->high = 0x7fffffff; return; } - if (ts.tv_sec == (time_t)-1) { + if (t == (time_t)-1) { nt->low = 0xffffffff; nt->high = 0xffffffff; return; } - d = (double)(ts.tv_sec); + d = (double)(t); d += TIME_FIXUP_CONSTANT; d *= 1.0e7; - d += ((double)ts.tv_nsec / 100.0); nt->high = (uint32)(d * (1.0/(4.0*(double)(1<<30)))); nt->low = (uint32)(d - ((double)nt->high)*4.0*(double)(1<<30)); } -/**************************************************************************** - Put a 8 byte filetime from a time_t. Uses GMT. -****************************************************************************/ - -void unix_to_nt_time(NTTIME *nt, time_t t) -{ - struct timespec ts; - ts.tv_sec = t; - ts.tv_nsec = 0; - unix_timespec_to_nt_time(nt, ts); -} - /**************************************************************************** Convert a time_t to a NTTIME structure @@ -395,10 +356,10 @@ void unix_to_nt_time_abs(NTTIME *nt, time_t t) pointed to by p. ****************************************************************************/ -void put_long_date(char *p, struct timespec ts) +void put_long_date(char *p, time_t t) { NTTIME nt; - unix_timespec_to_nt_time(&nt, ts); + unix_to_nt_time(&nt, t); SIVAL(p, 0, nt.low); SIVAL(p, 4, nt.high); } -- cgit From a64925ddff467a47f7adfac4b1b977ddc0c7f4ef Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 24 Aug 2006 16:44:00 +0000 Subject: r17800: Start using struct timespec internally for file times on the wire. This allows us to go to nsec resolution for systems that support it. It should also now be easy to add a correct "create time" (birth time) for systems that support it (*BSD). I'll be watching the build farm closely after this one for breakage :-). Jeremy. (This used to be commit 425280a1d23f97ef0b0be77462386d619f47b21d) --- source3/lib/time.c | 173 +++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 147 insertions(+), 26 deletions(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index 0bfdfac856..fa4ef398f2 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -172,28 +172,52 @@ int TimeDiff(time_t t) } #endif +time_t convert_timespec_to_time_t(struct timespec ts) +{ + /* 1 ns == 1,000,000,000 - one thousand millionths of a second. + increment if it's greater than 500 millionth of a second. */ + if (ts.tv_nsec > 500000000) { + return ts.tv_sec + 1; + } + return ts.tv_sec; +} + +struct timespec convert_time_t_to_timespec(time_t t) +{ + struct timespec ts; + ts.tv_sec = t; + ts.tv_nsec = 0; + return ts; +} + #define TIME_FIXUP_CONSTANT (369.0*365.25*24*60*60-(3.0*24*60*60+6.0*60*60)) /**************************************************************************** Interpret an 8 byte "filetime" structure to a time_t It's originally in "100ns units since jan 1st 1601" - An 8 byte value of 0xffffffffffffffff will be returned as (time_t)0. + An 8 byte value of 0xffffffffffffffff will be returned as a timespec of + + tv_sec = 0 + tv_nsec = 0; Returns GMT. ****************************************************************************/ -time_t nt_time_to_unix(NTTIME *nt) +static struct timespec nt_time_to_unix_timespec(NTTIME *nt) { double d; - time_t ret; + struct timespec ret; /* The next two lines are a fix needed for the broken SCO compiler. JRA. */ time_t l_time_min = TIME_T_MIN; time_t l_time_max = TIME_T_MAX; - if (nt->high == 0 || (nt->high == 0xffffffff && nt->low == 0xffffffff)) { - return(0); + if ((nt->high == 0 && nt->low == 0 )|| + (nt->high == 0xffffffff && nt->low == 0xffffffff)) { + ret.tv_sec = 0; + ret.tv_nsec = 0; + return ret; } d = ((double)nt->high)*4.0*(double)(1<<30); @@ -204,15 +228,25 @@ time_t nt_time_to_unix(NTTIME *nt) d -= TIME_FIXUP_CONSTANT; if (d <= l_time_min) { - return (l_time_min); + ret.tv_sec = l_time_min; + ret.tv_nsec = 0; + return ret; } if (d >= l_time_max) { - return (l_time_max); + ret.tv_sec = l_time_max; + ret.tv_nsec = 0; + return ret; } - ret = (time_t)(d+0.5); - return(ret); + ret.tv_sec = (time_t)d; + ret.tv_nsec = (long) ((d - (double)ret.tv_sec)*1.0e9); + return ret; +} + +time_t nt_time_to_unix(NTTIME *nt) +{ + return convert_timespec_to_time_t(nt_time_to_unix_timespec(nt)); } /**************************************************************************** @@ -235,7 +269,7 @@ time_t nt_time_to_unix_abs(const NTTIME *nt) NTTIME neg_nt; if (nt->high == 0) { - return(0); + return (time_t)0; } if (nt->high==0x80000000 && nt->low==0) { @@ -252,63 +286,78 @@ time_t nt_time_to_unix_abs(const NTTIME *nt) d *= 1.0e-7; if (!(l_time_min <= d && d <= l_time_max)) { - return(0); + return (time_t)0; } ret = (time_t)(d+0.5); - - return(ret); + return ret; } /**************************************************************************** - Interprets an nt time into a unix time_t. + Interprets an nt time into a unix struct timespec. Differs from nt_time_to_unix in that an 8 byte value of 0xffffffffffffffff will be returned as (time_t)-1, whereas nt_time_to_unix returns 0 in this case. ****************************************************************************/ -time_t interpret_long_date(char *p) +struct timespec interpret_long_date(char *p) { NTTIME nt; nt.low = IVAL(p,0); nt.high = IVAL(p,4); if (nt.low == 0xFFFFFFFF && nt.high == 0xFFFFFFFF) { - return (time_t)-1; + struct timespec ret; + ret.tv_sec = (time_t)-1; + ret.tv_nsec = 0; + return ret; } - return nt_time_to_unix(&nt); + return nt_time_to_unix_timespec(&nt); } /**************************************************************************** - Put a 8 byte filetime from a time_t. Uses GMT. + Put a 8 byte filetime from a struct timespec. Uses GMT. ****************************************************************************/ -void unix_to_nt_time(NTTIME *nt, time_t t) +void unix_timespec_to_nt_time(NTTIME *nt, struct timespec ts) { double d; - if (t==0) { + if (ts.tv_sec ==0 && ts.tv_nsec == 0) { nt->low = 0; nt->high = 0; return; } - if (t == TIME_T_MAX) { + if (ts.tv_sec == TIME_T_MAX) { nt->low = 0xffffffff; nt->high = 0x7fffffff; return; } - if (t == (time_t)-1) { + if (ts.tv_sec == (time_t)-1) { nt->low = 0xffffffff; nt->high = 0xffffffff; return; } - d = (double)(t); + d = (double)(ts.tv_sec); d += TIME_FIXUP_CONSTANT; d *= 1.0e7; + d += ((double)ts.tv_nsec / 100.0); nt->high = (uint32)(d * (1.0/(4.0*(double)(1<<30)))); nt->low = (uint32)(d - ((double)nt->high)*4.0*(double)(1<<30)); } +/**************************************************************************** + Put a 8 byte filetime from a time_t. Uses GMT. +****************************************************************************/ + +void unix_to_nt_time(NTTIME *nt, time_t t) +{ + struct timespec ts; + ts.tv_sec = t; + ts.tv_nsec = 0; + unix_timespec_to_nt_time(nt, ts); +} + /**************************************************************************** Convert a time_t to a NTTIME structure @@ -356,14 +405,22 @@ void unix_to_nt_time_abs(NTTIME *nt, time_t t) pointed to by p. ****************************************************************************/ -void put_long_date(char *p, time_t t) +void put_long_date_timespec(char *p, struct timespec ts) { NTTIME nt; - unix_to_nt_time(&nt, t); + unix_timespec_to_nt_time(&nt, ts); SIVAL(p, 0, nt.low); SIVAL(p, 4, nt.high); } +void put_long_date(char *p, time_t t) +{ + struct timespec ts; + ts.tv_sec = t; + ts.tv_nsec = 0; + put_long_date_timespec(p, ts); +} + /**************************************************************************** Check if it's a null mtime. ****************************************************************************/ @@ -717,6 +774,14 @@ time_t get_create_time(SMB_STRUCT_STAT *st,BOOL fake_dirs) return ret; } +struct timespec get_create_timespec(SMB_STRUCT_STAT *st,BOOL fake_dirs) +{ + struct timespec ts; + ts.tv_sec = get_create_time(st, fake_dirs); + ts.tv_nsec = 0; + return ts; +} + /**************************************************************************** Initialise an NTTIME to -1, which means "unknown" or "don't expire". ****************************************************************************/ @@ -955,7 +1020,7 @@ time_t generalized_to_unix_time(const char *str) } /**************************************************************************** - Return all the possible time fields from a stat struct as a timespec. + Get/Set all the possible time fields from a stat struct as a timespec. ****************************************************************************/ struct timespec get_atimespec(SMB_STRUCT_STAT *pst) @@ -981,6 +1046,23 @@ struct timespec get_atimespec(SMB_STRUCT_STAT *pst) #endif } +void set_atimespec(SMB_STRUCT_STAT *pst, struct timespec ts) +{ +#if !defined(HAVE_STAT_HIRES_TIMESTAMPS) + /* Old system - no ns timestamp. */ + pst->st_atime = ts.tv_sec; +#else +#if defined(HAVE_STAT_ST_ATIM) + pst->st_atim = ts; +#elif defined(HAVE_STAT_ST_ATIMENSEC) + pst->st_atime = ts.tv_sec; + pst->st_atimensec = ts.tv_nsec +#else +#error CONFIGURE_ERROR_IN_DETECTING_TIMESPEC_IN_STAT +#endif +#endif +} + struct timespec get_mtimespec(SMB_STRUCT_STAT *pst) { #if !defined(HAVE_STAT_HIRES_TIMESTAMPS) @@ -1004,6 +1086,23 @@ struct timespec get_mtimespec(SMB_STRUCT_STAT *pst) #endif } +void set_mtimespec(SMB_STRUCT_STAT *pst, struct timespec ts) +{ +#if !defined(HAVE_STAT_HIRES_TIMESTAMPS) + /* Old system - no ns timestamp. */ + pst->st_mtime = ts.tv_sec; +#else +#if defined(HAVE_STAT_ST_MTIM) + pst->st_mtim = ts; +#elif defined(HAVE_STAT_ST_MTIMENSEC) + pst->st_mtime = ts.tv_sec; + pst->st_mtimensec = ts.tv_nsec +#else +#error CONFIGURE_ERROR_IN_DETECTING_TIMESPEC_IN_STAT +#endif +#endif +} + struct timespec get_ctimespec(SMB_STRUCT_STAT *pst) { #if !defined(HAVE_STAT_HIRES_TIMESTAMPS) @@ -1027,6 +1126,23 @@ struct timespec get_ctimespec(SMB_STRUCT_STAT *pst) #endif } +void set_ctimespec(SMB_STRUCT_STAT *pst, struct timespec ts) +{ +#if !defined(HAVE_STAT_HIRES_TIMESTAMPS) + /* Old system - no ns timestamp. */ + pst->st_ctime = ts.tv_sec; +#else +#if defined(HAVE_STAT_ST_CTIM) + pst->st_atim = ts; +#elif defined(HAVE_STAT_ST_CTIMENSEC) + pst->st_ctime = ts.tv_sec; + pst->st_ctimensec = ts.tv_nsec +#else +#error CONFIGURE_ERROR_IN_DETECTING_TIMESPEC_IN_STAT +#endif +#endif +} + #if 0 /**************************************************************************** Return the best approximation to a 'create time' under UNIX from a stat @@ -1056,6 +1172,11 @@ struct timespec get_create_timespec(SMB_STRUCT_STAT *st,BOOL fake_dirs) } #endif +void dos_filetime_timespec(struct timespec *tsp) +{ + tsp->tv_sec &= ~1; + tsp->tv_nsec = 0; +} /** Return the date and time as a string -- cgit From 01bb24624d82514520cc648d913509f82b93bcea Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 24 Aug 2006 20:51:57 +0000 Subject: r17809: Add in 64-bit integer time calculations (taken from Samba4) for machines that have 64-bit integers. Leave the (double) code for machines that don't. Needs testing.... :-). Jeremy. (This used to be commit 9e65c175b0794bea3082785b5da6f5b281887ce7) --- source3/lib/time.c | 201 ++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 160 insertions(+), 41 deletions(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index fa4ef398f2..d7f796ca16 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -190,7 +190,13 @@ struct timespec convert_time_t_to_timespec(time_t t) return ts; } -#define TIME_FIXUP_CONSTANT (369.0*365.25*24*60*60-(3.0*24*60*60+6.0*60*60)) +#ifdef uint64 + +#if (SIZEOF_LONG == 8) +#define TIME_FIXUP_CONSTANT_INT 11644473600L +#elif (SIZEOF_LONG_LONG == 8) +#define TIME_FIXUP_CONSTANT_INT 11644473600LL +#endif /**************************************************************************** Interpret an 8 byte "filetime" structure to a time_t @@ -204,14 +210,130 @@ struct timespec convert_time_t_to_timespec(time_t t) Returns GMT. ****************************************************************************/ +/* Large integer version. */ +static struct timespec nt_time_to_unix_timespec(NTTIME *nt) +{ + uint64 d; + struct timespec ret; + + if ((nt->high == 0 && nt->low == 0 )|| + (nt->high == 0xffffffff && nt->low == 0xffffffff)) { + ret.tv_sec = 0; + ret.tv_nsec = 0; + return ret; + } + + d = (((uint64)nt->high) << 32 ) + ((uint64)nt->low); + /* d is now in 100ns units, since jan 1st 1601". + Save off the ns fraction. */ + + ret.tv_nsec = (long) ((d % 100) * 100); + + /* Convert to seconds */ + d /= 1000*1000*10; + + /* Now adjust by 369 years to make the secs since 1970 */ + d -= TIME_FIXUP_CONSTANT_INT; + + if (d <= TIME_T_MIN) { + ret.tv_sec = TIME_T_MIN; + ret.tv_nsec = 0; + return ret; + } + + if (d >= TIME_T_MAX) { + ret.tv_sec = TIME_T_MAX; + ret.tv_nsec = 0; + return ret; + } + + ret.tv_sec = (time_t)d; + return ret; +} + +/**************************************************************************** + Convert a NTTIME structure to a time_t. + It's originally in "100ns units". + + This is an absolute version of the one above. + By absolute I mean, it doesn't adjust from 1/1/1601 to 1/1/1970 + if the NTTIME was 5 seconds, the time_t is 5 seconds. JFM +****************************************************************************/ + +time_t nt_time_to_unix_abs(const NTTIME *nt) +{ + uint64 d; + NTTIME neg_nt; + + if (nt->high == 0) { + return (time_t)0; + } + + if (nt->high==0x80000000 && nt->low==0) { + return (time_t)-1; + } + + /* reverse the time */ + /* it's a negative value, turn it to positive */ + neg_nt.high=~nt->high; + neg_nt.low=~nt->low; + + d = (((uint64)neg_nt.high) << 32 ) + ((uint64)neg_nt.low); + + d += 1000*1000*10/2; + d /= 1000*1000*10; + + if (!(TIME_T_MIN <= d && d <= TIME_T_MAX)) { + return (time_t)0; + } + + return (time_t)d; +} + +/**************************************************************************** + Put a 8 byte filetime from a struct timespec. Uses GMT. +****************************************************************************/ + +void unix_timespec_to_nt_time(NTTIME *nt, struct timespec ts) +{ + uint64 d; + + if (ts.tv_sec ==0 && ts.tv_nsec == 0) { + nt->low = 0; + nt->high = 0; + return; + } + if (ts.tv_sec == TIME_T_MAX) { + nt->low = 0xffffffff; + nt->high = 0x7fffffff; + return; + } + if (ts.tv_sec == (time_t)-1) { + nt->low = 0xffffffff; + nt->high = 0xffffffff; + return; + } + + d = ts.tv_sec; + d += TIME_FIXUP_CONSTANT_INT; + d = ts.tv_sec * 1000*1000*10; + /* d is now in 100ns units. */ + d += (ts.tv_nsec / 100); + + nt->high = (uint32)(d / 1000*1000*10); + nt->low = (uint32)(d % 1000*1000*10); +} + +#else + +/* No 64-bit datatype. Use double float. */ +#define TIME_FIXUP_CONSTANT_DOUBLE (369.0*365.25*24*60*60-(3.0*24*60*60+6.0*60*60)) + +/* Floating point double versions. */ static struct timespec nt_time_to_unix_timespec(NTTIME *nt) { double d; struct timespec ret; - /* The next two lines are a fix needed for the - broken SCO compiler. JRA. */ - time_t l_time_min = TIME_T_MIN; - time_t l_time_max = TIME_T_MAX; if ((nt->high == 0 && nt->low == 0 )|| (nt->high == 0xffffffff && nt->low == 0xffffffff)) { @@ -225,16 +347,16 @@ static struct timespec nt_time_to_unix_timespec(NTTIME *nt) d *= 1.0e-7; /* now adjust by 369 years to make the secs since 1970 */ - d -= TIME_FIXUP_CONSTANT; + d -= TIME_FIXUP_CONSTANT_DOUBLE; - if (d <= l_time_min) { - ret.tv_sec = l_time_min; + if (d <= TIME_T_MIN) { + ret.tv_sec = TIME_T_MIN; ret.tv_nsec = 0; return ret; } - if (d >= l_time_max) { - ret.tv_sec = l_time_max; + if (d >= TIME_T_MAX) { + ret.tv_sec = TIME_T_MAX; ret.tv_nsec = 0; return ret; } @@ -244,11 +366,6 @@ static struct timespec nt_time_to_unix_timespec(NTTIME *nt) return ret; } -time_t nt_time_to_unix(NTTIME *nt) -{ - return convert_timespec_to_time_t(nt_time_to_unix_timespec(nt)); -} - /**************************************************************************** Convert a NTTIME structure to a time_t. It's originally in "100ns units". @@ -262,10 +379,6 @@ time_t nt_time_to_unix_abs(const NTTIME *nt) { double d; time_t ret; - /* The next two lines are a fix needed for the - broken SCO compiler. JRA. */ - time_t l_time_min = TIME_T_MIN; - time_t l_time_max = TIME_T_MAX; NTTIME neg_nt; if (nt->high == 0) { @@ -285,7 +398,7 @@ time_t nt_time_to_unix_abs(const NTTIME *nt) d += (neg_nt.low&0xFFF00000); d *= 1.0e-7; - if (!(l_time_min <= d && d <= l_time_max)) { + if (!(TIME_T_MIN <= d && d <= TIME_T_MAX)) { return (time_t)0; } @@ -293,26 +406,6 @@ time_t nt_time_to_unix_abs(const NTTIME *nt) return ret; } -/**************************************************************************** - Interprets an nt time into a unix struct timespec. - Differs from nt_time_to_unix in that an 8 byte value of 0xffffffffffffffff - will be returned as (time_t)-1, whereas nt_time_to_unix returns 0 in this case. -****************************************************************************/ - -struct timespec interpret_long_date(char *p) -{ - NTTIME nt; - nt.low = IVAL(p,0); - nt.high = IVAL(p,4); - if (nt.low == 0xFFFFFFFF && nt.high == 0xFFFFFFFF) { - struct timespec ret; - ret.tv_sec = (time_t)-1; - ret.tv_nsec = 0; - return ret; - } - return nt_time_to_unix_timespec(&nt); -} - /**************************************************************************** Put a 8 byte filetime from a struct timespec. Uses GMT. ****************************************************************************/ @@ -338,13 +431,39 @@ void unix_timespec_to_nt_time(NTTIME *nt, struct timespec ts) } d = (double)(ts.tv_sec); - d += TIME_FIXUP_CONSTANT; + d += TIME_FIXUP_CONSTANT_DOUBLE; d *= 1.0e7; d += ((double)ts.tv_nsec / 100.0); nt->high = (uint32)(d * (1.0/(4.0*(double)(1<<30)))); nt->low = (uint32)(d - ((double)nt->high)*4.0*(double)(1<<30)); } +#endif + +time_t nt_time_to_unix(NTTIME *nt) +{ + return convert_timespec_to_time_t(nt_time_to_unix_timespec(nt)); +} + +/**************************************************************************** + Interprets an nt time into a unix struct timespec. + Differs from nt_time_to_unix in that an 8 byte value of 0xffffffffffffffff + will be returned as (time_t)-1, whereas nt_time_to_unix returns 0 in this case. +****************************************************************************/ + +struct timespec interpret_long_date(char *p) +{ + NTTIME nt; + nt.low = IVAL(p,0); + nt.high = IVAL(p,4); + if (nt.low == 0xFFFFFFFF && nt.high == 0xFFFFFFFF) { + struct timespec ret; + ret.tv_sec = (time_t)-1; + ret.tv_nsec = 0; + return ret; + } + return nt_time_to_unix_timespec(&nt); +} /**************************************************************************** Put a 8 byte filetime from a time_t. Uses GMT. -- cgit From b3773240504f12788908ca4755602d55842dded0 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 24 Aug 2006 21:37:10 +0000 Subject: r17812: Fix bad unsigned comparisons with TIME_T_MIN/TIME_T_MAX. Jeremy. (This used to be commit bd1fbdfb824883060b02be969a10f999d387973f) --- source3/lib/time.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index d7f796ca16..7d8f79b14a 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -235,13 +235,13 @@ static struct timespec nt_time_to_unix_timespec(NTTIME *nt) /* Now adjust by 369 years to make the secs since 1970 */ d -= TIME_FIXUP_CONSTANT_INT; - if (d <= TIME_T_MIN) { + if (((time_t)d) <= TIME_T_MIN) { ret.tv_sec = TIME_T_MIN; ret.tv_nsec = 0; return ret; } - if (d >= TIME_T_MAX) { + if (((time_t)d) >= TIME_T_MAX) { ret.tv_sec = TIME_T_MAX; ret.tv_nsec = 0; return ret; @@ -283,7 +283,7 @@ time_t nt_time_to_unix_abs(const NTTIME *nt) d += 1000*1000*10/2; d /= 1000*1000*10; - if (!(TIME_T_MIN <= d && d <= TIME_T_MAX)) { + if (!(TIME_T_MIN <= ((time_t)d) && ((time_t)d) <= TIME_T_MAX)) { return (time_t)0; } -- cgit From 94af1ad542bca6604e209b277bca40d11959b3ec Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 24 Aug 2006 23:39:37 +0000 Subject: r17818: Fixup uint64 time calc. NT time is a 64 bit number, not high value seconds, low value 100ns units. Jeremy. (This used to be commit ead75870d5d3c690fabd131a9dd8776e854638dc) --- source3/lib/time.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index 7d8f79b14a..b4477d693a 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -316,12 +316,12 @@ void unix_timespec_to_nt_time(NTTIME *nt, struct timespec ts) d = ts.tv_sec; d += TIME_FIXUP_CONSTANT_INT; - d = ts.tv_sec * 1000*1000*10; + d *= 1000*1000*10; /* d is now in 100ns units. */ d += (ts.tv_nsec / 100); - nt->high = (uint32)(d / 1000*1000*10); - nt->low = (uint32)(d % 1000*1000*10); + nt->low = (uint32)(d & 0xFFFFFFFF); + nt->high = (uint32)(d >> 32 ); } #else -- cgit From b9142f20dfb59055e05fa52c5414fb7c1877c556 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 25 Aug 2006 14:25:06 +0000 Subject: r17831: Attempt to fix the build farm: 0x7fffffffffffffff needs special casing too I think. This broke 'make test' because the newly created user was set to be kicked off Mi, 22 Jan 1975 23:55:33 CET (unix time 159663333) with the setuserinfo21 call. I'm not 100% sure that 0x7ff... means max time as I do it here, I vaguely remember it to mean "don't touch". Does anybody know that for sure? Jeremy, please check this. Thanks, Volker (This used to be commit 872d1299ebffb7b7d696013fc676820f1fa1777c) --- source3/lib/time.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index b4477d693a..192a418e7a 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -223,6 +223,12 @@ static struct timespec nt_time_to_unix_timespec(NTTIME *nt) return ret; } + if ((nt->high == 0x7fffffff) && (nt->low == 0xffffffff)) { + ret.tv_sec = TIME_T_MAX; + ret.tv_nsec = 0; + return ret; + } + d = (((uint64)nt->high) << 32 ) + ((uint64)nt->low); /* d is now in 100ns units, since jan 1st 1601". Save off the ns fraction. */ -- cgit From 6365dcef4d753b11a33ae4311a09a4c475f566aa Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 25 Aug 2006 16:25:09 +0000 Subject: r17834: Another bug found by Volker's tests in the build farm ! Correctly map large nt timevals to TIME_T_MAX. Jeremy. (This used to be commit 63b13d28795bbce6d9fe9e0aa4f518ef94c44f18) --- source3/lib/time.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index 192a418e7a..2db10f98d9 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -223,12 +223,6 @@ static struct timespec nt_time_to_unix_timespec(NTTIME *nt) return ret; } - if ((nt->high == 0x7fffffff) && (nt->low == 0xffffffff)) { - ret.tv_sec = TIME_T_MAX; - ret.tv_nsec = 0; - return ret; - } - d = (((uint64)nt->high) << 32 ) + ((uint64)nt->low); /* d is now in 100ns units, since jan 1st 1601". Save off the ns fraction. */ @@ -247,7 +241,7 @@ static struct timespec nt_time_to_unix_timespec(NTTIME *nt) return ret; } - if (((time_t)d) >= TIME_T_MAX) { + if ((d >= (uint64)TIME_T_MAX)) { ret.tv_sec = TIME_T_MAX; ret.tv_nsec = 0; return ret; -- cgit From 5e44fc4cd47108245c567b9e676a5d8c09787d96 Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Sat, 2 Sep 2006 21:47:56 +0000 Subject: r18009: Fixes bug 4026. This completes the work Jeremy began last week, disambiguating the meaning of c_time. (In POSIX terminology, c_time means "status Change time", not "create time".) All uses of c_time, a_time and m_time have now been replaced with change_time, access_time, and write_time, and when creation time is intended, create_time is used. Additionally, the capability of setting and retrieving the create time have been added to the smbc_setxattr() and smbc_getxattr() functions. An example of setting all four times can be seen with the program examples/libsmbclient/testacl with the following command line similar to: testacl -f -S "system.*:CREATE_TIME:1000000000,ACCESS_TIME:1000000060,WRITE_TIME:1000000120,CHANGE_TIME:1000000180" 'smb://server/share/testfile.txt' The -f option turns on the new mode which uses full time names in the attribute specification (e.g. ACCESS_TIME vs A_TIME). (This used to be commit 8e119b64f1d92026dda855d904be09912a40601c) --- source3/lib/time.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index 2db10f98d9..0fb35bd977 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -1252,7 +1252,7 @@ void set_ctimespec(SMB_STRUCT_STAT *pst, struct timespec ts) pst->st_ctime = ts.tv_sec; #else #if defined(HAVE_STAT_ST_CTIM) - pst->st_atim = ts; + pst->st_ctim = ts; #elif defined(HAVE_STAT_ST_CTIMENSEC) pst->st_ctime = ts.tv_sec; pst->st_ctimensec = ts.tv_nsec -- cgit From 995205fc60f87e1a02aa1c6f309db55ae18e908a Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 6 Sep 2006 18:32:20 +0000 Subject: r18188: merge 3.0-libndr branch (This used to be commit 1115745caed3093c25d6be01ffee21819fb0a675) --- source3/lib/time.c | 1972 ++++++++++++++++++++++++++-------------------------- 1 file changed, 981 insertions(+), 991 deletions(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index 0fb35bd977..715c1a1bcc 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -1,8 +1,10 @@ /* Unix SMB/CIFS implementation. time handling functions - Copyright (C) Andrew Tridgell 1992-1998 + + Copyright (C) Andrew Tridgell 1992-2004 Copyright (C) Stefan (metze) Metzmacher 2002 + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or @@ -20,16 +22,11 @@ #include "includes.h" -/* - This stuff was largely rewritten by Paul Eggert - in May 1996 - */ - -int extra_time_offset = 0; +/** + * @file + * @brief time handling functions + */ -#ifndef CHAR_BIT -#define CHAR_BIT 8 -#endif #ifndef TIME_T_MIN #define TIME_T_MIN ((time_t)0 < (time_t) -1 ? (time_t) 0 \ @@ -39,19 +36,17 @@ int extra_time_offset = 0; #define TIME_T_MAX (~ (time_t) 0 - TIME_T_MIN) #endif -/******************************************************************* +/** External access to time_t_min and time_t_max. -********************************************************************/ - +**/ time_t get_time_t_max(void) { return TIME_T_MAX; } -/******************************************************************* - A gettimeofday wrapper. -********************************************************************/ - +/** +a gettimeofday wrapper +**/ void GetTimeOfDay(struct timeval *tval) { #ifdef HAVE_GETTIMEOFDAY_TZ @@ -61,126 +56,7 @@ void GetTimeOfDay(struct timeval *tval) #endif } -#define TM_YEAR_BASE 1900 - -/******************************************************************* - Yield the difference between *A and *B, in seconds, ignoring leap seconds. -********************************************************************/ - -static int tm_diff(struct tm *a, struct tm *b) -{ - int ay = a->tm_year + (TM_YEAR_BASE - 1); - int by = b->tm_year + (TM_YEAR_BASE - 1); - int intervening_leap_days = (ay/4 - by/4) - (ay/100 - by/100) + (ay/400 - by/400); - int years = ay - by; - int days = 365*years + intervening_leap_days + (a->tm_yday - b->tm_yday); - int hours = 24*days + (a->tm_hour - b->tm_hour); - int minutes = 60*hours + (a->tm_min - b->tm_min); - int seconds = 60*minutes + (a->tm_sec - b->tm_sec); - - return seconds; -} - -/******************************************************************* - Return the UTC offset in seconds west of UTC, or 0 if it cannot be determined. -******************************************************************/ - -int get_time_zone(time_t t) -{ - struct tm *tm = gmtime(&t); - struct tm tm_utc; - - if (!tm) { - return 0; - } - tm_utc = *tm; - tm = localtime(&t); - if (!tm) { - return 0; - } - return tm_diff(&tm_utc,tm) + 60*extra_time_offset; -} - -/******************************************************************* - Accessor function for the server time zone offset. - set_server_zone_offset() must have been called first. -******************************************************************/ - -static int server_zone_offset; - -int get_server_zone_offset(void) -{ - return server_zone_offset; -} - -/******************************************************************* - Initialize the server time zone offset. Called when a client connects. -******************************************************************/ - -int set_server_zone_offset(time_t t) -{ - server_zone_offset = get_time_zone(t); - return server_zone_offset; -} - -/******************************************************************* - Re-read the smb serverzone value. -******************************************************************/ - -static struct timeval start_time_hires; - -void TimeInit(void) -{ - set_server_zone_offset(time(NULL)); - - DEBUG(4,("TimeInit: Serverzone is %d\n", server_zone_offset)); - - /* Save the start time of this process. */ - if (start_time_hires.tv_sec == 0 && start_time_hires.tv_usec == 0) { - GetTimeOfDay(&start_time_hires); - } -} - -/********************************************************************** - Return a timeval struct of the uptime of this process. As TimeInit is - done before a daemon fork then this is the start time from the parent - daemon start. JRA. -***********************************************************************/ - -void get_process_uptime(struct timeval *ret_time) -{ - struct timeval time_now_hires; - - GetTimeOfDay(&time_now_hires); - ret_time->tv_sec = time_now_hires.tv_sec - start_time_hires.tv_sec; - if (time_now_hires.tv_usec < start_time_hires.tv_usec) { - ret_time->tv_sec -= 1; - ret_time->tv_usec = 1000000 + (time_now_hires.tv_usec - start_time_hires.tv_usec); - } else { - ret_time->tv_usec = time_now_hires.tv_usec - start_time_hires.tv_usec; - } -} - -#if 0 -/**************************************************************************** - Return the UTC offset in seconds west of UTC, adjusted for extra time offset. -**************************************************************************/ - -int TimeDiff(time_t t) -{ - return get_time_zone(t); -} -#endif - -time_t convert_timespec_to_time_t(struct timespec ts) -{ - /* 1 ns == 1,000,000,000 - one thousand millionths of a second. - increment if it's greater than 500 millionth of a second. */ - if (ts.tv_nsec > 500000000) { - return ts.tv_sec + 1; - } - return ts.tv_sec; -} +#define TIME_FIXUP_CONSTANT 11644473600LL struct timespec convert_time_t_to_timespec(time_t t) { @@ -190,8 +66,6 @@ struct timespec convert_time_t_to_timespec(time_t t) return ts; } -#ifdef uint64 - #if (SIZEOF_LONG == 8) #define TIME_FIXUP_CONSTANT_INT 11644473600L #elif (SIZEOF_LONG_LONG == 8) @@ -210,441 +84,144 @@ struct timespec convert_time_t_to_timespec(time_t t) Returns GMT. ****************************************************************************/ -/* Large integer version. */ -static struct timespec nt_time_to_unix_timespec(NTTIME *nt) +time_t nt_time_to_unix(NTTIME nt) { - uint64 d; - struct timespec ret; - - if ((nt->high == 0 && nt->low == 0 )|| - (nt->high == 0xffffffff && nt->low == 0xffffffff)) { - ret.tv_sec = 0; - ret.tv_nsec = 0; - return ret; - } - - d = (((uint64)nt->high) << 32 ) + ((uint64)nt->low); - /* d is now in 100ns units, since jan 1st 1601". - Save off the ns fraction. */ - - ret.tv_nsec = (long) ((d % 100) * 100); - - /* Convert to seconds */ - d /= 1000*1000*10; - - /* Now adjust by 369 years to make the secs since 1970 */ - d -= TIME_FIXUP_CONSTANT_INT; - - if (((time_t)d) <= TIME_T_MIN) { - ret.tv_sec = TIME_T_MIN; - ret.tv_nsec = 0; - return ret; - } - - if ((d >= (uint64)TIME_T_MAX)) { - ret.tv_sec = TIME_T_MAX; - ret.tv_nsec = 0; - return ret; - } - - ret.tv_sec = (time_t)d; - return ret; + return convert_timespec_to_time_t(nt_time_to_unix_timespec(&nt)); } /**************************************************************************** - Convert a NTTIME structure to a time_t. - It's originally in "100ns units". - - This is an absolute version of the one above. - By absolute I mean, it doesn't adjust from 1/1/1601 to 1/1/1970 - if the NTTIME was 5 seconds, the time_t is 5 seconds. JFM + Put a 8 byte filetime from a time_t. Uses GMT. ****************************************************************************/ -time_t nt_time_to_unix_abs(const NTTIME *nt) +void unix_to_nt_time(NTTIME *nt, time_t t) { - uint64 d; - NTTIME neg_nt; - - if (nt->high == 0) { - return (time_t)0; - } - - if (nt->high==0x80000000 && nt->low==0) { - return (time_t)-1; - } - - /* reverse the time */ - /* it's a negative value, turn it to positive */ - neg_nt.high=~nt->high; - neg_nt.low=~nt->low; - - d = (((uint64)neg_nt.high) << 32 ) + ((uint64)neg_nt.low); + uint64_t t2; - d += 1000*1000*10/2; - d /= 1000*1000*10; + if (t == (time_t)-1) { + *nt = (NTTIME)-1LL; + return; + } + if (t == 0) { + *nt = 0; + return; + } - if (!(TIME_T_MIN <= ((time_t)d) && ((time_t)d) <= TIME_T_MAX)) { - return (time_t)0; - } + t2 = t; + t2 += TIME_FIXUP_CONSTANT; + t2 *= 1000*1000*10; - return (time_t)d; + *nt = t2; } -/**************************************************************************** - Put a 8 byte filetime from a struct timespec. Uses GMT. -****************************************************************************/ -void unix_timespec_to_nt_time(NTTIME *nt, struct timespec ts) +/** +check if it's a null unix time +**/ +BOOL null_time(time_t t) { - uint64 d; - - if (ts.tv_sec ==0 && ts.tv_nsec == 0) { - nt->low = 0; - nt->high = 0; - return; - } - if (ts.tv_sec == TIME_T_MAX) { - nt->low = 0xffffffff; - nt->high = 0x7fffffff; - return; - } - if (ts.tv_sec == (time_t)-1) { - nt->low = 0xffffffff; - nt->high = 0xffffffff; - return; - } + return t == 0 || + t == (time_t)0xFFFFFFFF || + t == (time_t)-1; +} - d = ts.tv_sec; - d += TIME_FIXUP_CONSTANT_INT; - d *= 1000*1000*10; - /* d is now in 100ns units. */ - d += (ts.tv_nsec / 100); - nt->low = (uint32)(d & 0xFFFFFFFF); - nt->high = (uint32)(d >> 32 ); +/** +check if it's a null NTTIME +**/ +BOOL null_nttime(NTTIME t) +{ + return t == 0 || t == (NTTIME)-1; } -#else +/******************************************************************* + create a 16 bit dos packed date +********************************************************************/ +static uint16_t make_dos_date1(struct tm *t) +{ + uint16_t ret=0; + ret = (((unsigned int)(t->tm_mon+1)) >> 3) | ((t->tm_year-80) << 1); + ret = ((ret&0xFF)<<8) | (t->tm_mday | (((t->tm_mon+1) & 0x7) << 5)); + return ret; +} -/* No 64-bit datatype. Use double float. */ -#define TIME_FIXUP_CONSTANT_DOUBLE (369.0*365.25*24*60*60-(3.0*24*60*60+6.0*60*60)) +/******************************************************************* + create a 16 bit dos packed time +********************************************************************/ +static uint16_t make_dos_time1(struct tm *t) +{ + uint16_t ret=0; + ret = ((((unsigned int)t->tm_min >> 3)&0x7) | (((unsigned int)t->tm_hour) << 3)); + ret = ((ret&0xFF)<<8) | ((t->tm_sec/2) | ((t->tm_min & 0x7) << 5)); + return ret; +} -/* Floating point double versions. */ -static struct timespec nt_time_to_unix_timespec(NTTIME *nt) +/******************************************************************* + create a 32 bit dos packed date/time from some parameters + This takes a GMT time and returns a packed localtime structure +********************************************************************/ +static uint32_t make_dos_date(time_t unixdate, int zone_offset) { - double d; - struct timespec ret; + struct tm *t; + uint32_t ret=0; - if ((nt->high == 0 && nt->low == 0 )|| - (nt->high == 0xffffffff && nt->low == 0xffffffff)) { - ret.tv_sec = 0; - ret.tv_nsec = 0; - return ret; + if (unixdate == 0) { + return 0; } - d = ((double)nt->high)*4.0*(double)(1<<30); - d += (nt->low&0xFFF00000); - d *= 1.0e-7; - - /* now adjust by 369 years to make the secs since 1970 */ - d -= TIME_FIXUP_CONSTANT_DOUBLE; + unixdate -= zone_offset; - if (d <= TIME_T_MIN) { - ret.tv_sec = TIME_T_MIN; - ret.tv_nsec = 0; - return ret; + t = gmtime(&unixdate); + if (!t) { + return 0xFFFFFFFF; } - if (d >= TIME_T_MAX) { - ret.tv_sec = TIME_T_MAX; - ret.tv_nsec = 0; - return ret; - } + ret = make_dos_date1(t); + ret = ((ret&0xFFFF)<<16) | make_dos_time1(t); - ret.tv_sec = (time_t)d; - ret.tv_nsec = (long) ((d - (double)ret.tv_sec)*1.0e9); return ret; } -/**************************************************************************** - Convert a NTTIME structure to a time_t. - It's originally in "100ns units". - - This is an absolute version of the one above. - By absolute I mean, it doesn't adjust from 1/1/1601 to 1/1/1970 - if the NTTIME was 5 seconds, the time_t is 5 seconds. JFM -****************************************************************************/ - -time_t nt_time_to_unix_abs(const NTTIME *nt) -{ - double d; - time_t ret; - NTTIME neg_nt; - - if (nt->high == 0) { - return (time_t)0; - } - - if (nt->high==0x80000000 && nt->low==0) { - return (time_t)-1; - } - - /* reverse the time */ - /* it's a negative value, turn it to positive */ - neg_nt.high=~nt->high; - neg_nt.low=~nt->low; - - d = ((double)neg_nt.high)*4.0*(double)(1<<30); - d += (neg_nt.low&0xFFF00000); - d *= 1.0e-7; - - if (!(TIME_T_MIN <= d && d <= TIME_T_MAX)) { - return (time_t)0; - } - - ret = (time_t)(d+0.5); - return ret; -} - -/**************************************************************************** - Put a 8 byte filetime from a struct timespec. Uses GMT. -****************************************************************************/ - -void unix_timespec_to_nt_time(NTTIME *nt, struct timespec ts) -{ - double d; - - if (ts.tv_sec ==0 && ts.tv_nsec == 0) { - nt->low = 0; - nt->high = 0; - return; - } - if (ts.tv_sec == TIME_T_MAX) { - nt->low = 0xffffffff; - nt->high = 0x7fffffff; - return; - } - if (ts.tv_sec == (time_t)-1) { - nt->low = 0xffffffff; - nt->high = 0xffffffff; - return; - } - - d = (double)(ts.tv_sec); - d += TIME_FIXUP_CONSTANT_DOUBLE; - d *= 1.0e7; - d += ((double)ts.tv_nsec / 100.0); - - nt->high = (uint32)(d * (1.0/(4.0*(double)(1<<30)))); - nt->low = (uint32)(d - ((double)nt->high)*4.0*(double)(1<<30)); -} -#endif - -time_t nt_time_to_unix(NTTIME *nt) -{ - return convert_timespec_to_time_t(nt_time_to_unix_timespec(nt)); -} - -/**************************************************************************** - Interprets an nt time into a unix struct timespec. - Differs from nt_time_to_unix in that an 8 byte value of 0xffffffffffffffff - will be returned as (time_t)-1, whereas nt_time_to_unix returns 0 in this case. -****************************************************************************/ - -struct timespec interpret_long_date(char *p) -{ - NTTIME nt; - nt.low = IVAL(p,0); - nt.high = IVAL(p,4); - if (nt.low == 0xFFFFFFFF && nt.high == 0xFFFFFFFF) { - struct timespec ret; - ret.tv_sec = (time_t)-1; - ret.tv_nsec = 0; - return ret; - } - return nt_time_to_unix_timespec(&nt); -} - -/**************************************************************************** - Put a 8 byte filetime from a time_t. Uses GMT. -****************************************************************************/ - -void unix_to_nt_time(NTTIME *nt, time_t t) -{ - struct timespec ts; - ts.tv_sec = t; - ts.tv_nsec = 0; - unix_timespec_to_nt_time(nt, ts); -} - -/**************************************************************************** - Convert a time_t to a NTTIME structure - - This is an absolute version of the one above. - By absolute I mean, it doesn't adjust from 1/1/1970 to 1/1/1601 - If the nttime_t was 5 seconds, the NTTIME is 5 seconds. JFM -****************************************************************************/ - -void unix_to_nt_time_abs(NTTIME *nt, time_t t) -{ - double d; - - if (t==0) { - nt->low = 0; - nt->high = 0; - return; - } - - if (t == TIME_T_MAX) { - nt->low = 0xffffffff; - nt->high = 0x7fffffff; - return; - } - - if (t == (time_t)-1) { - /* that's what NT uses for infinite */ - nt->low = 0x0; - nt->high = 0x80000000; - return; - } - - d = (double)(t); - d *= 1.0e7; - - nt->high = (uint32)(d * (1.0/(4.0*(double)(1<<30)))); - nt->low = (uint32)(d - ((double)nt->high)*4.0*(double)(1<<30)); - - /* convert to a negative value */ - nt->high=~nt->high; - nt->low=~nt->low; -} - -/**************************************************************************** - Take a Unix time and convert to an NTTIME structure and place in buffer - pointed to by p. -****************************************************************************/ - -void put_long_date_timespec(char *p, struct timespec ts) -{ - NTTIME nt; - unix_timespec_to_nt_time(&nt, ts); - SIVAL(p, 0, nt.low); - SIVAL(p, 4, nt.high); -} - -void put_long_date(char *p, time_t t) -{ - struct timespec ts; - ts.tv_sec = t; - ts.tv_nsec = 0; - put_long_date_timespec(p, ts); -} - -/**************************************************************************** - Check if it's a null mtime. -****************************************************************************/ - -BOOL null_mtime(time_t mtime) -{ - if (mtime == 0 || mtime == (time_t)0xFFFFFFFF || mtime == (time_t)-1) - return(True); - return(False); -} - -/******************************************************************* - Create a 16 bit dos packed date. -********************************************************************/ - -static uint16 make_dos_date1(struct tm *t) -{ - uint16 ret=0; - ret = (((unsigned)(t->tm_mon+1)) >> 3) | ((t->tm_year-80) << 1); - ret = ((ret&0xFF)<<8) | (t->tm_mday | (((t->tm_mon+1) & 0x7) << 5)); - return(ret); -} - -/******************************************************************* - Create a 16 bit dos packed time. -********************************************************************/ - -static uint16 make_dos_time1(struct tm *t) -{ - uint16 ret=0; - ret = ((((unsigned)t->tm_min >> 3)&0x7) | (((unsigned)t->tm_hour) << 3)); - ret = ((ret&0xFF)<<8) | ((t->tm_sec/2) | ((t->tm_min & 0x7) << 5)); - return(ret); -} - -/******************************************************************* - Create a 32 bit dos packed date/time from some parameters. - This takes a GMT time and returns a packed localtime structure. -********************************************************************/ - -static uint32 make_dos_date(time_t unixdate, int zone_offset) -{ - struct tm *t; - uint32 ret=0; - - if (unixdate == 0) { - return 0; - } - - unixdate -= zone_offset; - t = gmtime(&unixdate); - if (!t) { - return 0xFFFFFFFF; - } - - ret = make_dos_date1(t); - ret = ((ret&0xFFFF)<<16) | make_dos_time1(t); - - return(ret); -} - -/******************************************************************* - Put a dos date into a buffer (time/date format). - This takes GMT time and puts local time in the buffer. -********************************************************************/ - -static void put_dos_date(char *buf,int offset,time_t unixdate, int zone_offset) +/** +put a dos date into a buffer (time/date format) +This takes GMT time and puts local time in the buffer +**/ +void push_dos_date(uint8_t *buf, int offset, time_t unixdate, int zone_offset) { - uint32 x = make_dos_date(unixdate, zone_offset); + uint32_t x = make_dos_date(unixdate, zone_offset); SIVAL(buf,offset,x); } -/******************************************************************* - Put a dos date into a buffer (date/time format). - This takes GMT time and puts local time in the buffer. -********************************************************************/ - -static void put_dos_date2(char *buf,int offset,time_t unixdate, int zone_offset) +/** +put a dos date into a buffer (date/time format) +This takes GMT time and puts local time in the buffer +**/ +void push_dos_date2(uint8_t *buf,int offset,time_t unixdate, int zone_offset) { - uint32 x = make_dos_date(unixdate, zone_offset); + uint32_t x; + x = make_dos_date(unixdate, zone_offset); x = ((x&0xFFFF)<<16) | ((x&0xFFFF0000)>>16); SIVAL(buf,offset,x); } -/******************************************************************* - Put a dos 32 bit "unix like" date into a buffer. This routine takes - GMT and converts it to LOCAL time before putting it (most SMBs assume - localtime for this sort of date) -********************************************************************/ - -static void put_dos_date3(char *buf,int offset,time_t unixdate, int zone_offset) +/** +put a dos 32 bit "unix like" date into a buffer. This routine takes +GMT and converts it to LOCAL time before putting it (most SMBs assume +localtime for this sort of date) +**/ +void push_dos_date3(uint8_t *buf,int offset,time_t unixdate, int zone_offset) { - if (!null_mtime(unixdate)) { + if (!null_time(unixdate)) { unixdate -= zone_offset; } SIVAL(buf,offset,unixdate); } /******************************************************************* - Interpret a 32 bit dos packed date/time to some parameters. + interpret a 32 bit dos packed date/time to some parameters ********************************************************************/ - -static void interpret_dos_date(uint32 date,int *year,int *month,int *day,int *hour,int *minute,int *second) +static void interpret_dos_date(uint32_t date,int *year,int *month,int *day,int *hour,int *minute,int *second) { - uint32 p0,p1,p2,p3; + uint32_t p0,p1,p2,p3; p0=date&0xFF; p1=((date&0xFF00)>>8)&0xFF; p2=((date&0xFF0000)>>16)&0xFF; p3=((date&0xFF000000)>>24)&0xFF; @@ -657,139 +234,66 @@ static void interpret_dos_date(uint32 date,int *year,int *month,int *day,int *ho *year = ((p3>>1)&0xFF) + 80; } -/******************************************************************* - Create a unix date (int GMT) from a dos date (which is actually in - localtime). -********************************************************************/ - -static time_t make_unix_date(void *date_ptr, int zone_offset) +/** + create a unix date (int GMT) from a dos date (which is actually in + localtime) +**/ +time_t pull_dos_date(const uint8_t *date_ptr, int zone_offset) { - uint32 dos_date=0; + uint32_t dos_date=0; struct tm t; time_t ret; dos_date = IVAL(date_ptr,0); - if (dos_date == 0) { - return 0; - } + if (dos_date == 0) return (time_t)0; interpret_dos_date(dos_date,&t.tm_year,&t.tm_mon, - &t.tm_mday,&t.tm_hour,&t.tm_min,&t.tm_sec); + &t.tm_mday,&t.tm_hour,&t.tm_min,&t.tm_sec); t.tm_isdst = -1; ret = timegm(&t); ret += zone_offset; - return(ret); + return ret; } -/******************************************************************* - Like make_unix_date() but the words are reversed. -********************************************************************/ - -static time_t make_unix_date2(void *date_ptr, int zone_offset) +/** +like make_unix_date() but the words are reversed +**/ +time_t pull_dos_date2(const uint8_t *date_ptr, int zone_offset) { - uint32 x,x2; + uint32_t x,x2; x = IVAL(date_ptr,0); x2 = ((x&0xFFFF)<<16) | ((x&0xFFFF0000)>>16); SIVAL(&x,0,x2); - return(make_unix_date((void *)&x, zone_offset)); + return pull_dos_date((void *)&x, zone_offset); } -/******************************************************************* - Create a unix GMT date from a dos date in 32 bit "unix like" format - these generally arrive as localtimes, with corresponding DST. -******************************************************************/ - -static time_t make_unix_date3(void *date_ptr, int zone_offset) +/** + create a unix GMT date from a dos date in 32 bit "unix like" format + these generally arrive as localtimes, with corresponding DST +**/ +time_t pull_dos_date3(const uint8_t *date_ptr, int zone_offset) { time_t t = (time_t)IVAL(date_ptr,0); - if (!null_mtime(t)) { + if (!null_time(t)) { t += zone_offset; } - return(t); + return t; } /*************************************************************************** - Server versions of the above functions. + Return a HTTP/1.0 time string. ***************************************************************************/ -void srv_put_dos_date(char *buf,int offset,time_t unixdate) -{ - put_dos_date(buf, offset, unixdate, server_zone_offset); -} - -void srv_put_dos_date2(char *buf,int offset, time_t unixdate) +char *http_timestring(time_t t) { - put_dos_date2(buf, offset, unixdate, server_zone_offset); -} - -void srv_put_dos_date3(char *buf,int offset,time_t unixdate) -{ - put_dos_date3(buf, offset, unixdate, server_zone_offset); -} - -time_t srv_make_unix_date(void *date_ptr) -{ - return make_unix_date(date_ptr, server_zone_offset); -} - -time_t srv_make_unix_date2(void *date_ptr) -{ - return make_unix_date2(date_ptr, server_zone_offset); -} - -time_t srv_make_unix_date3(void *date_ptr) -{ - return make_unix_date3(date_ptr, server_zone_offset); -} - -/*************************************************************************** - Client versions of the above functions. -***************************************************************************/ - -void cli_put_dos_date(struct cli_state *cli, char *buf, int offset, time_t unixdate) -{ - put_dos_date(buf, offset, unixdate, cli->serverzone); -} - -void cli_put_dos_date2(struct cli_state *cli, char *buf, int offset, time_t unixdate) -{ - put_dos_date2(buf, offset, unixdate, cli->serverzone); -} - -void cli_put_dos_date3(struct cli_state *cli, char *buf, int offset, time_t unixdate) -{ - put_dos_date3(buf, offset, unixdate, cli->serverzone); -} - -time_t cli_make_unix_date(struct cli_state *cli, void *date_ptr) -{ - return make_unix_date(date_ptr, cli->serverzone); -} - -time_t cli_make_unix_date2(struct cli_state *cli, void *date_ptr) -{ - return make_unix_date2(date_ptr, cli->serverzone); -} - -time_t cli_make_unix_date3(struct cli_state *cli, void *date_ptr) -{ - return make_unix_date3(date_ptr, cli->serverzone); -} - -/*************************************************************************** - Return a HTTP/1.0 time string. -***************************************************************************/ - -char *http_timestring(time_t t) -{ - static fstring buf; - struct tm *tm = localtime(&t); + static fstring buf; + struct tm *tm = localtime(&t); if (!tm) { slprintf(buf,sizeof(buf)-1,"%ld seconds since the Epoch",(long)t); @@ -807,188 +311,91 @@ char *http_timestring(time_t t) return buf; } -/**************************************************************************** - Return the date and time as a string -****************************************************************************/ -char *current_timestring(BOOL hires) +/** + Return the date and time as a string +**/ +char *timestring(TALLOC_CTX *mem_ctx, time_t t) { - static fstring TimeBuf; - struct timeval tp; - time_t t; + char *TimeBuf; + char tempTime[80]; struct tm *tm; - if (hires) { - GetTimeOfDay(&tp); - t = (time_t)tp.tv_sec; - } else { - t = time(NULL); - } tm = localtime(&t); if (!tm) { - if (hires) { - slprintf(TimeBuf, - sizeof(TimeBuf)-1, - "%ld.%06ld seconds since the Epoch", - (long)tp.tv_sec, - (long)tp.tv_usec); - } else { - slprintf(TimeBuf, - sizeof(TimeBuf)-1, - "%ld seconds since the Epoch", - (long)t); - } - } else { -#ifdef HAVE_STRFTIME - if (hires) { - strftime(TimeBuf,sizeof(TimeBuf)-1,"%Y/%m/%d %H:%M:%S",tm); - slprintf(TimeBuf+strlen(TimeBuf), - sizeof(TimeBuf)-1 - strlen(TimeBuf), - ".%06ld", - (long)tp.tv_usec); - } else { - strftime(TimeBuf,sizeof(TimeBuf)-1,"%Y/%m/%d %H:%M:%S",tm); - } -#else - if (hires) { - const char *asct = asctime(tm); - slprintf(TimeBuf, - sizeof(TimeBuf)-1, - "%s.%06ld", - asct ? asct : "unknown", - (long)tp.tv_usec); - } else { - const char *asct = asctime(tm); - fstrcpy(TimeBuf, asct ? asct : "unknown"); - } -#endif - } - return(TimeBuf); -} - -/**************************************************************************** - Return the best approximation to a 'create time' under UNIX from a stat - structure. -****************************************************************************/ - -time_t get_create_time(SMB_STRUCT_STAT *st,BOOL fake_dirs) -{ - time_t ret, ret1; - - if(S_ISDIR(st->st_mode) && fake_dirs) { - return (time_t)315493200L; /* 1/1/1980 */ - } - - ret = MIN(st->st_ctime, st->st_mtime); - ret1 = MIN(ret, st->st_atime); - - if(ret1 != (time_t)0) { - return ret1; + return talloc_asprintf(mem_ctx, + "%ld seconds since the Epoch", + (long)t); } - /* - * One of ctime, mtime or atime was zero (probably atime). - * Just return MIN(ctime, mtime). +#ifdef HAVE_STRFTIME + /* some versions of gcc complain about using %c. This is a bug + in the gcc warning, not a bug in this code. See a recent + strftime() manual page for details. */ - return ret; -} - -struct timespec get_create_timespec(SMB_STRUCT_STAT *st,BOOL fake_dirs) -{ - struct timespec ts; - ts.tv_sec = get_create_time(st, fake_dirs); - ts.tv_nsec = 0; - return ts; -} - -/**************************************************************************** - Initialise an NTTIME to -1, which means "unknown" or "don't expire". -****************************************************************************/ - -void init_nt_time(NTTIME *nt) -{ - nt->high = 0x7FFFFFFF; - nt->low = 0xFFFFFFFF; -} - -BOOL nt_time_is_set(const NTTIME *nt) -{ - if ((nt->high == 0x7FFFFFFF) && (nt->low == 0xFFFFFFFF)) { - return False; - } - - if ((nt->high == 0x80000000) && (nt->low == 0)) { - return False; - } + strftime(tempTime,sizeof(tempTime)-1,"%c %Z",tm); + TimeBuf = talloc_strdup(mem_ctx, tempTime); +#else + TimeBuf = talloc_strdup(mem_ctx, asctime(tm)); +#endif - return True; + return TimeBuf; } -/**************************************************************************** - Check if NTTIME is 0. -****************************************************************************/ - -BOOL nt_time_is_zero(const NTTIME *nt) +/** + return a talloced string representing a NTTIME for human consumption +*/ +const char *nt_time_string(TALLOC_CTX *mem_ctx, NTTIME nt) { - if(nt->high==0) { - return True; + time_t t; + if (nt == 0) { + return "NTTIME(0)"; } - return False; + t = nt_time_to_unix(nt); + return timestring(mem_ctx, t); } -/**************************************************************************** - Check if two NTTIMEs are the same. -****************************************************************************/ -BOOL nt_time_equals(const NTTIME *nt1, const NTTIME *nt2) +/** + parse a nttime as a large integer in a string and return a NTTIME +*/ +NTTIME nttime_from_string(const char *s) { - return (nt1->high == nt2->high && nt1->low == nt2->low); + return strtoull(s, NULL, 0); } -/**************************************************************************** - Return a timeval difference in usec. -****************************************************************************/ - -SMB_BIG_INT usec_time_diff(const struct timeval *larget, const struct timeval *smallt) +/** + return (tv1 - tv2) in microseconds +*/ +int64_t usec_time_diff(struct timeval *tv1, struct timeval *tv2) { - SMB_BIG_INT sec_diff = larget->tv_sec - smallt->tv_sec; - return (sec_diff * 1000000) + (SMB_BIG_INT)(larget->tv_usec - smallt->tv_usec); + int64_t sec_diff = tv1->tv_sec - tv2->tv_sec; + return (sec_diff * 1000000) + (int64_t)(tv1->tv_usec - tv2->tv_usec); } -/**************************************************************************** - Return a timeval struct with the given elements. -****************************************************************************/ -struct timeval timeval_set(uint32_t secs, uint32_t usecs) +/** + return a zero timeval +*/ +struct timeval timeval_zero(void) { struct timeval tv; - tv.tv_sec = secs; - tv.tv_usec = usecs; + tv.tv_sec = 0; + tv.tv_usec = 0; return tv; } -/**************************************************************************** - Return a zero timeval. -****************************************************************************/ - -struct timeval timeval_zero(void) -{ - return timeval_set(0,0); -} - -/**************************************************************************** - Return True if a timeval is zero. -****************************************************************************/ - +/** + return True if a timeval is zero +*/ BOOL timeval_is_zero(const struct timeval *tv) { return tv->tv_sec == 0 && tv->tv_usec == 0; } -/**************************************************************************** - Return a timeval for the current time. -****************************************************************************/ - +/** + return a timeval for the current time +*/ struct timeval timeval_current(void) { struct timeval tv; @@ -996,71 +403,124 @@ struct timeval timeval_current(void) return tv; } -/**************************************************************************** - Return a timeval ofs microseconds after tv. -****************************************************************************/ +/** + return a timeval struct with the given elements +*/ +struct timeval timeval_set(uint32_t secs, uint32_t usecs) +{ + struct timeval tv; + tv.tv_sec = secs; + tv.tv_usec = usecs; + return tv; +} + +/** + return a timeval ofs microseconds after tv +*/ struct timeval timeval_add(const struct timeval *tv, uint32_t secs, uint32_t usecs) { struct timeval tv2 = *tv; + const unsigned int million = 1000000; tv2.tv_sec += secs; tv2.tv_usec += usecs; - tv2.tv_sec += tv2.tv_usec / 1000000; - tv2.tv_usec = tv2.tv_usec % 1000000; + tv2.tv_sec += tv2.tv_usec / million; + tv2.tv_usec = tv2.tv_usec % million; return tv2; } -/**************************************************************************** - Return the sum of two timeval structures. -****************************************************************************/ - +/** + return the sum of two timeval structures +*/ struct timeval timeval_sum(const struct timeval *tv1, const struct timeval *tv2) { return timeval_add(tv1, tv2->tv_sec, tv2->tv_usec); } -/**************************************************************************** - Return a timeval secs/usecs into the future. -****************************************************************************/ - +/** + return a timeval secs/usecs into the future +*/ struct timeval timeval_current_ofs(uint32_t secs, uint32_t usecs) { struct timeval tv = timeval_current(); return timeval_add(&tv, secs, usecs); } -/**************************************************************************** - Compare two timeval structures. - Return -1 if tv1 < tv2 - Return 0 if tv1 == tv2 - Return 1 if tv1 > tv2 -****************************************************************************/ - -int timeval_compare(const struct timeval *tv1, const struct timeval *tv2) +/** + compare two timeval structures. + Return -1 if tv1 < tv2 + Return 0 if tv1 == tv2 + Return 1 if tv1 > tv2 +*/ +int timeval_compare(const struct timeval *tv1, const struct timeval *tv2) { - if (tv1->tv_sec > tv2->tv_sec) { - return 1; - } - if (tv1->tv_sec < tv2->tv_sec) { - return -1; - } - if (tv1->tv_usec > tv2->tv_usec) { - return 1; - } - if (tv1->tv_usec < tv2->tv_usec) { - return -1; - } + if (tv1->tv_sec > tv2->tv_sec) return 1; + if (tv1->tv_sec < tv2->tv_sec) return -1; + if (tv1->tv_usec > tv2->tv_usec) return 1; + if (tv1->tv_usec < tv2->tv_usec) return -1; return 0; } -/**************************************************************************** - Return the difference between two timevals as a timeval. - If tv1 comes after tv2, then return a zero timeval - (this is *tv2 - *tv1). -****************************************************************************/ +/** + return True if a timer is in the past +*/ +BOOL timeval_expired(const struct timeval *tv) +{ + struct timeval tv2 = timeval_current(); + if (tv2.tv_sec > tv->tv_sec) return True; + if (tv2.tv_sec < tv->tv_sec) return False; + return (tv2.tv_usec >= tv->tv_usec); +} + +/** + return the number of seconds elapsed between two times +*/ +double timeval_elapsed2(const struct timeval *tv1, const struct timeval *tv2) +{ + return (tv2->tv_sec - tv1->tv_sec) + + (tv2->tv_usec - tv1->tv_usec)*1.0e-6; +} + +/** + return the number of seconds elapsed since a given time +*/ +double timeval_elapsed(const struct timeval *tv) +{ + struct timeval tv2 = timeval_current(); + return timeval_elapsed2(tv, &tv2); +} + +/** + return the lesser of two timevals +*/ +struct timeval timeval_min(const struct timeval *tv1, + const struct timeval *tv2) +{ + if (tv1->tv_sec < tv2->tv_sec) return *tv1; + if (tv1->tv_sec > tv2->tv_sec) return *tv2; + if (tv1->tv_usec < tv2->tv_usec) return *tv1; + return *tv2; +} +/** + return the greater of two timevals +*/ +struct timeval timeval_max(const struct timeval *tv1, + const struct timeval *tv2) +{ + if (tv1->tv_sec > tv2->tv_sec) return *tv1; + if (tv1->tv_sec < tv2->tv_sec) return *tv2; + if (tv1->tv_usec > tv2->tv_usec) return *tv1; + return *tv2; +} + +/** + return the difference between two timevals as a timeval + if tv1 comes after tv2, then return a zero timeval + (this is *tv2 - *tv1) +*/ struct timeval timeval_until(const struct timeval *tv1, const struct timeval *tv2) { @@ -1078,42 +538,59 @@ struct timeval timeval_until(const struct timeval *tv1, return t; } -/**************************************************************************** - Return the lesser of two timevals. -****************************************************************************/ -struct timeval timeval_min(const struct timeval *tv1, - const struct timeval *tv2) +/** + convert a timeval to a NTTIME +*/ +NTTIME timeval_to_nttime(const struct timeval *tv) { - if (tv1->tv_sec < tv2->tv_sec) { - return *tv1; - } - if (tv1->tv_sec > tv2->tv_sec) { - return *tv2; - } - if (tv1->tv_usec < tv2->tv_usec) { - return *tv1; - } - return *tv2; + return 10*(tv->tv_usec + + ((TIME_FIXUP_CONSTANT + (uint64_t)tv->tv_sec) * 1000000)); +} + +/******************************************************************* +yield the difference between *A and *B, in seconds, ignoring leap seconds +********************************************************************/ +static int tm_diff(struct tm *a, struct tm *b) +{ + int ay = a->tm_year + (1900 - 1); + int by = b->tm_year + (1900 - 1); + int intervening_leap_days = + (ay/4 - by/4) - (ay/100 - by/100) + (ay/400 - by/400); + int years = ay - by; + int days = 365*years + intervening_leap_days + (a->tm_yday - b->tm_yday); + int hours = 24*days + (a->tm_hour - b->tm_hour); + int minutes = 60*hours + (a->tm_min - b->tm_min); + int seconds = 60*minutes + (a->tm_sec - b->tm_sec); + + return seconds; +} + +int extra_time_offset=0; + +/** + return the UTC offset in seconds west of UTC, or 0 if it cannot be determined + */ +int get_time_zone(time_t t) +{ + struct tm *tm = gmtime(&t); + struct tm tm_utc; + if (!tm) + return 0; + tm_utc = *tm; + tm = localtime(&t); + if (!tm) + return 0; + return tm_diff(&tm_utc,tm)+60*extra_time_offset; } /**************************************************************************** - Return the greater of two timevals. + Check if NTTIME is 0. ****************************************************************************/ -struct timeval timeval_max(const struct timeval *tv1, - const struct timeval *tv2) +BOOL nt_time_is_zero(const NTTIME *nt) { - if (tv1->tv_sec > tv2->tv_sec) { - return *tv1; - } - if (tv1->tv_sec < tv2->tv_sec) { - return *tv2; - } - if (tv1->tv_usec > tv2->tv_usec) { - return *tv1; - } - return *tv2; + return (*nt == 0); } /**************************************************************************** @@ -1138,137 +615,172 @@ time_t generalized_to_unix_time(const char *str) return timegm(&tm); } -/**************************************************************************** - Get/Set all the possible time fields from a stat struct as a timespec. -****************************************************************************/ +/******************************************************************* + Accessor function for the server time zone offset. + set_server_zone_offset() must have been called first. +******************************************************************/ -struct timespec get_atimespec(SMB_STRUCT_STAT *pst) -{ -#if !defined(HAVE_STAT_HIRES_TIMESTAMPS) - struct timespec ret; +static int server_zone_offset; - /* Old system - no ns timestamp. */ - ret.tv_sec = pst->st_atime; - ret.tv_nsec = 0; - return ret; -#else -#if defined(HAVE_STAT_ST_ATIM) - return pst->st_atim; -#elif defined(HAVE_STAT_ST_ATIMENSEC) - struct timespec ret; - ret.tv_sec = pst->st_atime; - ret.tv_nsec = pst->st_atimensec; - return ret; -#else -#error CONFIGURE_ERROR_IN_DETECTING_TIMESPEC_IN_STAT -#endif -#endif +int get_server_zone_offset(void) +{ + return server_zone_offset; } -void set_atimespec(SMB_STRUCT_STAT *pst, struct timespec ts) +/******************************************************************* + Initialize the server time zone offset. Called when a client connects. +******************************************************************/ + +int set_server_zone_offset(time_t t) { -#if !defined(HAVE_STAT_HIRES_TIMESTAMPS) - /* Old system - no ns timestamp. */ - pst->st_atime = ts.tv_sec; -#else -#if defined(HAVE_STAT_ST_ATIM) - pst->st_atim = ts; -#elif defined(HAVE_STAT_ST_ATIMENSEC) - pst->st_atime = ts.tv_sec; - pst->st_atimensec = ts.tv_nsec -#else -#error CONFIGURE_ERROR_IN_DETECTING_TIMESPEC_IN_STAT -#endif -#endif + server_zone_offset = get_time_zone(t); + return server_zone_offset; } -struct timespec get_mtimespec(SMB_STRUCT_STAT *pst) +/**************************************************************************** + Return the date and time as a string +****************************************************************************/ + +char *current_timestring(BOOL hires) { -#if !defined(HAVE_STAT_HIRES_TIMESTAMPS) - struct timespec ret; + static fstring TimeBuf; + struct timeval tp; + time_t t; + struct tm *tm; - /* Old system - no ns timestamp. */ - ret.tv_sec = pst->st_mtime; - ret.tv_nsec = 0; - return ret; -#else -#if defined(HAVE_STAT_ST_MTIM) - return pst->st_mtim; -#elif defined(HAVE_STAT_ST_MTIMENSEC) - struct timespec ret; - ret.tv_sec = pst->st_mtime; - ret.tv_nsec = pst->st_mtimensec; - return ret; + if (hires) { + GetTimeOfDay(&tp); + t = (time_t)tp.tv_sec; + } else { + t = time(NULL); + } + tm = localtime(&t); + if (!tm) { + if (hires) { + slprintf(TimeBuf, + sizeof(TimeBuf)-1, + "%ld.%06ld seconds since the Epoch", + (long)tp.tv_sec, + (long)tp.tv_usec); + } else { + slprintf(TimeBuf, + sizeof(TimeBuf)-1, + "%ld seconds since the Epoch", + (long)t); + } + } else { +#ifdef HAVE_STRFTIME + if (hires) { + strftime(TimeBuf,sizeof(TimeBuf)-1,"%Y/%m/%d %H:%M:%S",tm); + slprintf(TimeBuf+strlen(TimeBuf), + sizeof(TimeBuf)-1 - strlen(TimeBuf), + ".%06ld", + (long)tp.tv_usec); + } else { + strftime(TimeBuf,sizeof(TimeBuf)-1,"%Y/%m/%d %H:%M:%S",tm); + } #else -#error CONFIGURE_ERROR_IN_DETECTING_TIMESPEC_IN_STAT -#endif + if (hires) { + const char *asct = asctime(tm); + slprintf(TimeBuf, + sizeof(TimeBuf)-1, + "%s.%06ld", + asct ? asct : "unknown", + (long)tp.tv_usec); + } else { + const char *asct = asctime(tm); + fstrcpy(TimeBuf, asct ? asct : "unknown"); + } #endif + } + return(TimeBuf); } -void set_mtimespec(SMB_STRUCT_STAT *pst, struct timespec ts) + +/******************************************************************* + Put a dos date into a buffer (time/date format). + This takes GMT time and puts local time in the buffer. +********************************************************************/ + +static void put_dos_date(char *buf,int offset,time_t unixdate, int zone_offset) { -#if !defined(HAVE_STAT_HIRES_TIMESTAMPS) - /* Old system - no ns timestamp. */ - pst->st_mtime = ts.tv_sec; -#else -#if defined(HAVE_STAT_ST_MTIM) - pst->st_mtim = ts; -#elif defined(HAVE_STAT_ST_MTIMENSEC) - pst->st_mtime = ts.tv_sec; - pst->st_mtimensec = ts.tv_nsec -#else -#error CONFIGURE_ERROR_IN_DETECTING_TIMESPEC_IN_STAT -#endif -#endif + uint32 x = make_dos_date(unixdate, zone_offset); + SIVAL(buf,offset,x); } -struct timespec get_ctimespec(SMB_STRUCT_STAT *pst) +/******************************************************************* + Put a dos date into a buffer (date/time format). + This takes GMT time and puts local time in the buffer. +********************************************************************/ + +static void put_dos_date2(char *buf,int offset,time_t unixdate, int zone_offset) { -#if !defined(HAVE_STAT_HIRES_TIMESTAMPS) - struct timespec ret; + uint32 x = make_dos_date(unixdate, zone_offset); + x = ((x&0xFFFF)<<16) | ((x&0xFFFF0000)>>16); + SIVAL(buf,offset,x); +} - /* Old system - no ns timestamp. */ - ret.tv_sec = pst->st_ctime; - ret.tv_nsec = 0; - return ret; -#else -#if defined(HAVE_STAT_ST_CTIM) - return pst->st_ctim; -#elif defined(HAVE_STAT_ST_CTIMENSEC) - struct timespec ret; - ret.tv_sec = pst->st_ctime; - ret.tv_nsec = pst->st_ctimensec; - return ret; -#else -#error CONFIGURE_ERROR_IN_DETECTING_TIMESPEC_IN_STAT -#endif -#endif +/******************************************************************* + Put a dos 32 bit "unix like" date into a buffer. This routine takes + GMT and converts it to LOCAL time before putting it (most SMBs assume + localtime for this sort of date) +********************************************************************/ + +static void put_dos_date3(char *buf,int offset,time_t unixdate, int zone_offset) +{ + if (!null_mtime(unixdate)) { + unixdate -= zone_offset; + } + SIVAL(buf,offset,unixdate); } -void set_ctimespec(SMB_STRUCT_STAT *pst, struct timespec ts) + +/*************************************************************************** + Server versions of the above functions. +***************************************************************************/ + +void srv_put_dos_date(char *buf,int offset,time_t unixdate) { -#if !defined(HAVE_STAT_HIRES_TIMESTAMPS) - /* Old system - no ns timestamp. */ - pst->st_ctime = ts.tv_sec; -#else -#if defined(HAVE_STAT_ST_CTIM) - pst->st_ctim = ts; -#elif defined(HAVE_STAT_ST_CTIMENSEC) - pst->st_ctime = ts.tv_sec; - pst->st_ctimensec = ts.tv_nsec -#else -#error CONFIGURE_ERROR_IN_DETECTING_TIMESPEC_IN_STAT -#endif -#endif + put_dos_date(buf, offset, unixdate, server_zone_offset); +} + +void srv_put_dos_date2(char *buf,int offset, time_t unixdate) +{ + put_dos_date2(buf, offset, unixdate, server_zone_offset); +} + +void srv_put_dos_date3(char *buf,int offset,time_t unixdate) +{ + put_dos_date3(buf, offset, unixdate, server_zone_offset); +} + +/**************************************************************************** + Take a Unix time and convert to an NTTIME structure and place in buffer + pointed to by p. +****************************************************************************/ + +void put_long_date_timespec(char *p, struct timespec ts) +{ + NTTIME nt; + unix_timespec_to_nt_time(&nt, ts); + SIVAL(p, 0, nt & 0xFFFFFFFF); + SIVAL(p, 4, nt >> 32); +} + +void put_long_date(char *p, time_t t) +{ + struct timespec ts; + ts.tv_sec = t; + ts.tv_nsec = 0; + put_long_date_timespec(p, ts); } -#if 0 /**************************************************************************** Return the best approximation to a 'create time' under UNIX from a stat structure. ****************************************************************************/ -struct timespec get_create_timespec(SMB_STRUCT_STAT *st,BOOL fake_dirs) +time_t get_create_time(SMB_STRUCT_STAT *st,BOOL fake_dirs) { time_t ret, ret1; @@ -1289,75 +801,553 @@ struct timespec get_create_timespec(SMB_STRUCT_STAT *st,BOOL fake_dirs) */ return ret; } + +struct timespec get_create_timespec(SMB_STRUCT_STAT *st,BOOL fake_dirs) +{ + struct timespec ts; + ts.tv_sec = get_create_time(st, fake_dirs); + ts.tv_nsec = 0; + return ts; +} + +/**************************************************************************** + Get/Set all the possible time fields from a stat struct as a timespec. +****************************************************************************/ + +struct timespec get_atimespec(SMB_STRUCT_STAT *pst) +{ +#if !defined(HAVE_STAT_HIRES_TIMESTAMPS) + struct timespec ret; + + /* Old system - no ns timestamp. */ + ret.tv_sec = pst->st_atime; + ret.tv_nsec = 0; + return ret; +#else +#if defined(HAVE_STAT_ST_ATIM) + return pst->st_atim; +#elif defined(HAVE_STAT_ST_ATIMENSEC) + struct timespec ret; + ret.tv_sec = pst->st_atime; + ret.tv_nsec = pst->st_atimensec; + return ret; +#else +#error CONFIGURE_ERROR_IN_DETECTING_TIMESPEC_IN_STAT #endif +#endif +} -void dos_filetime_timespec(struct timespec *tsp) +void set_atimespec(SMB_STRUCT_STAT *pst, struct timespec ts) { - tsp->tv_sec &= ~1; - tsp->tv_nsec = 0; +#if !defined(HAVE_STAT_HIRES_TIMESTAMPS) + /* Old system - no ns timestamp. */ + pst->st_atime = ts.tv_sec; +#else +#if defined(HAVE_STAT_ST_ATIM) + pst->st_atim = ts; +#elif defined(HAVE_STAT_ST_ATIMENSEC) + pst->st_atime = ts.tv_sec; + pst->st_atimensec = ts.tv_nsec +#else +#error CONFIGURE_ERROR_IN_DETECTING_TIMESPEC_IN_STAT +#endif +#endif } -/** - Return the date and time as a string -**/ -char *timestring(TALLOC_CTX *mem_ctx, time_t t) +struct timespec get_mtimespec(SMB_STRUCT_STAT *pst) { - char *TimeBuf; - char tempTime[80]; - struct tm *tm; +#if !defined(HAVE_STAT_HIRES_TIMESTAMPS) + struct timespec ret; - tm = localtime(&t); - if (!tm) { - return talloc_asprintf(mem_ctx, - "%ld seconds since the Epoch", - (long)t); - } + /* Old system - no ns timestamp. */ + ret.tv_sec = pst->st_mtime; + ret.tv_nsec = 0; + return ret; +#else +#if defined(HAVE_STAT_ST_MTIM) + return pst->st_mtim; +#elif defined(HAVE_STAT_ST_MTIMENSEC) + struct timespec ret; + ret.tv_sec = pst->st_mtime; + ret.tv_nsec = pst->st_mtimensec; + return ret; +#else +#error CONFIGURE_ERROR_IN_DETECTING_TIMESPEC_IN_STAT +#endif +#endif +} -#ifdef HAVE_STRFTIME - /* some versions of gcc complain about using %c. This is a bug - in the gcc warning, not a bug in this code. See a recent - strftime() manual page for details. - */ - strftime(tempTime,sizeof(tempTime)-1,"%c %Z",tm); - TimeBuf = talloc_strdup(mem_ctx, tempTime); +void set_mtimespec(SMB_STRUCT_STAT *pst, struct timespec ts) +{ +#if !defined(HAVE_STAT_HIRES_TIMESTAMPS) + /* Old system - no ns timestamp. */ + pst->st_mtime = ts.tv_sec; #else - TimeBuf = talloc_strdup(mem_ctx, asctime(tm)); +#if defined(HAVE_STAT_ST_MTIM) + pst->st_mtim = ts; +#elif defined(HAVE_STAT_ST_MTIMENSEC) + pst->st_mtime = ts.tv_sec; + pst->st_mtimensec = ts.tv_nsec +#else +#error CONFIGURE_ERROR_IN_DETECTING_TIMESPEC_IN_STAT #endif +#endif +} - return TimeBuf; +struct timespec get_ctimespec(SMB_STRUCT_STAT *pst) +{ +#if !defined(HAVE_STAT_HIRES_TIMESTAMPS) + struct timespec ret; + + /* Old system - no ns timestamp. */ + ret.tv_sec = pst->st_ctime; + ret.tv_nsec = 0; + return ret; +#else +#if defined(HAVE_STAT_ST_CTIM) + return pst->st_ctim; +#elif defined(HAVE_STAT_ST_CTIMENSEC) + struct timespec ret; + ret.tv_sec = pst->st_ctime; + ret.tv_nsec = pst->st_ctimensec; + return ret; +#else +#error CONFIGURE_ERROR_IN_DETECTING_TIMESPEC_IN_STAT +#endif +#endif } +void set_ctimespec(SMB_STRUCT_STAT *pst, struct timespec ts) +{ +#if !defined(HAVE_STAT_HIRES_TIMESTAMPS) + /* Old system - no ns timestamp. */ + pst->st_ctime = ts.tv_sec; +#else +#if defined(HAVE_STAT_ST_CTIM) + pst->st_ctim = ts; +#elif defined(HAVE_STAT_ST_CTIMENSEC) + pst->st_ctime = ts.tv_sec; + pst->st_ctimensec = ts.tv_nsec +#else +#error CONFIGURE_ERROR_IN_DETECTING_TIMESPEC_IN_STAT +#endif +#endif +} -/** - return a talloced string representing a NTTIME for human consumption -*/ -const char *nt_time_string(TALLOC_CTX *mem_ctx, NTTIME nt) +void dos_filetime_timespec(struct timespec *tsp) { - time_t t; - if (nt.low == 0 && nt.high == 0) { - return "NTTIME(0)"; - } - t = nt_time_to_unix(&nt); - return timestring(mem_ctx, t); + tsp->tv_sec &= ~1; + tsp->tv_nsec = 0; } -/**************************************************************************** - Utility function that always returns a const string even if localtime - and asctime fail. -****************************************************************************/ +/******************************************************************* + Create a unix date (int GMT) from a dos date (which is actually in + localtime). +********************************************************************/ -const char *time_to_asc(const time_t *t) +static time_t make_unix_date(void *date_ptr, int zone_offset) { - const char *asct; - struct tm *lt = localtime(t); + uint32 dos_date=0; + struct tm t; + time_t ret; - if (!lt) { - return "unknown time"; - } + dos_date = IVAL(date_ptr,0); - asct = asctime(lt); - if (!asct) { - return "unknown time"; + if (dos_date == 0) { + return 0; } - return asct; -} + + interpret_dos_date(dos_date,&t.tm_year,&t.tm_mon, + &t.tm_mday,&t.tm_hour,&t.tm_min,&t.tm_sec); + t.tm_isdst = -1; + + ret = timegm(&t); + + ret += zone_offset; + + return(ret); +} + +/******************************************************************* + Like make_unix_date() but the words are reversed. +********************************************************************/ + +static time_t make_unix_date2(void *date_ptr, int zone_offset) +{ + uint32 x,x2; + + x = IVAL(date_ptr,0); + x2 = ((x&0xFFFF)<<16) | ((x&0xFFFF0000)>>16); + SIVAL(&x,0,x2); + + return(make_unix_date((void *)&x, zone_offset)); +} + +/******************************************************************* + Create a unix GMT date from a dos date in 32 bit "unix like" format + these generally arrive as localtimes, with corresponding DST. +******************************************************************/ + +static time_t make_unix_date3(void *date_ptr, int zone_offset) +{ + time_t t = (time_t)IVAL(date_ptr,0); + if (!null_mtime(t)) { + t += zone_offset; + } + return(t); +} + +time_t srv_make_unix_date(void *date_ptr) +{ + return make_unix_date(date_ptr, server_zone_offset); +} + +time_t srv_make_unix_date2(void *date_ptr) +{ + return make_unix_date2(date_ptr, server_zone_offset); +} + +time_t srv_make_unix_date3(void *date_ptr) +{ + return make_unix_date3(date_ptr, server_zone_offset); +} + +time_t convert_timespec_to_time_t(struct timespec ts) +{ + /* 1 ns == 1,000,000,000 - one thousand millionths of a second. + increment if it's greater than 500 millionth of a second. */ + if (ts.tv_nsec > 500000000) { + return ts.tv_sec + 1; + } + return ts.tv_sec; +} + +/**************************************************************************** + Interprets an nt time into a unix struct timespec. + Differs from nt_time_to_unix in that an 8 byte value of 0xffffffffffffffff + will be returned as (time_t)-1, whereas nt_time_to_unix returns 0 in this case. +****************************************************************************/ + +struct timespec interpret_long_date(char *p) +{ + NTTIME nt; + nt = IVAL(p,0) + ((uint64_t)IVAL(p,4) << 32); + if (nt == (uint64_t)-1) { + struct timespec ret; + ret.tv_sec = (time_t)-1; + ret.tv_nsec = 0; + return ret; + } + return nt_time_to_unix_timespec(&nt); +} + +/*************************************************************************** + Client versions of the above functions. +***************************************************************************/ + +void cli_put_dos_date(struct cli_state *cli, char *buf, int offset, time_t unixdate) +{ + put_dos_date(buf, offset, unixdate, cli->serverzone); +} + +void cli_put_dos_date2(struct cli_state *cli, char *buf, int offset, time_t unixdate) +{ + put_dos_date2(buf, offset, unixdate, cli->serverzone); +} + +void cli_put_dos_date3(struct cli_state *cli, char *buf, int offset, time_t unixdate) +{ + put_dos_date3(buf, offset, unixdate, cli->serverzone); +} + +time_t cli_make_unix_date(struct cli_state *cli, void *date_ptr) +{ + return make_unix_date(date_ptr, cli->serverzone); +} + +time_t cli_make_unix_date2(struct cli_state *cli, void *date_ptr) +{ + return make_unix_date2(date_ptr, cli->serverzone); +} + +time_t cli_make_unix_date3(struct cli_state *cli, void *date_ptr) +{ + return make_unix_date3(date_ptr, cli->serverzone); +} + +#if (SIZEOF_LONG == 8) +#define TIME_FIXUP_CONSTANT_INT 11644473600L +#elif (SIZEOF_LONG_LONG == 8) +#define TIME_FIXUP_CONSTANT_INT 11644473600LL +#endif + + +/* Large integer version. */ +struct timespec nt_time_to_unix_timespec(NTTIME *nt) +{ + uint64 d; + struct timespec ret; + + if (*nt == 0 || *nt == (uint64)-1) { + ret.tv_sec = 0; + ret.tv_nsec = 0; + return ret; + } + + d = *nt; + /* d is now in 100ns units, since jan 1st 1601". + Save off the ns fraction. */ + + ret.tv_nsec = (long) ((d % 100) * 100); + + /* Convert to seconds */ + d /= 1000*1000*10; + + /* Now adjust by 369 years to make the secs since 1970 */ + d -= TIME_FIXUP_CONSTANT_INT; + + if (((time_t)d) <= TIME_T_MIN) { + ret.tv_sec = TIME_T_MIN; + ret.tv_nsec = 0; + return ret; + } + + if (((time_t)d) >= TIME_T_MAX) { + ret.tv_sec = TIME_T_MAX; + ret.tv_nsec = 0; + return ret; + } + + ret.tv_sec = (time_t)d; + return ret; +} +/**************************************************************************** + Check if two NTTIMEs are the same. +****************************************************************************/ + +BOOL nt_time_equals(const NTTIME *nt1, const NTTIME *nt2) +{ + return (*nt1 == *nt2); +} + +/******************************************************************* + Re-read the smb serverzone value. +******************************************************************/ + +static struct timeval start_time_hires; + +void TimeInit(void) +{ + set_server_zone_offset(time(NULL)); + + DEBUG(4,("TimeInit: Serverzone is %d\n", server_zone_offset)); + + /* Save the start time of this process. */ + if (start_time_hires.tv_sec == 0 && start_time_hires.tv_usec == 0) { + GetTimeOfDay(&start_time_hires); + } +} + +/********************************************************************** + Return a timeval struct of the uptime of this process. As TimeInit is + done before a daemon fork then this is the start time from the parent + daemon start. JRA. +***********************************************************************/ + +void get_process_uptime(struct timeval *ret_time) +{ + struct timeval time_now_hires; + + GetTimeOfDay(&time_now_hires); + ret_time->tv_sec = time_now_hires.tv_sec - start_time_hires.tv_sec; + if (time_now_hires.tv_usec < start_time_hires.tv_usec) { + ret_time->tv_sec -= 1; + ret_time->tv_usec = 1000000 + (time_now_hires.tv_usec - start_time_hires.tv_usec); + } else { + ret_time->tv_usec = time_now_hires.tv_usec - start_time_hires.tv_usec; + } +} + +/**************************************************************************** + Convert a NTTIME structure to a time_t. + It's originally in "100ns units". + + This is an absolute version of the one above. + By absolute I mean, it doesn't adjust from 1/1/1601 to 1/1/1970 + if the NTTIME was 5 seconds, the time_t is 5 seconds. JFM +****************************************************************************/ + +time_t nt_time_to_unix_abs(const NTTIME *nt) +{ + uint64 d; + + if (*nt == 0) { + return (time_t)0; + } + + if (*nt == (uint64)-1) { + return (time_t)-1; + } + + /* reverse the time */ + /* it's a negative value, turn it to positive */ + d=~*nt; + + d += 1000*1000*10/2; + d /= 1000*1000*10; + + if (!(TIME_T_MIN <= ((time_t)d) && ((time_t)d) <= TIME_T_MAX)) { + return (time_t)0; + } + + return (time_t)d; +} + +/**************************************************************************** + Put a 8 byte filetime from a struct timespec. Uses GMT. +****************************************************************************/ + +void unix_timespec_to_nt_time(NTTIME *nt, struct timespec ts) +{ + uint64 d; + + if (ts.tv_sec ==0 && ts.tv_nsec == 0) { + *nt = 0; + return; + } + if (ts.tv_sec == TIME_T_MAX) { + *nt = 0x7fffffffffffffffLL; + return; + } + if (ts.tv_sec == (time_t)-1) { + *nt = (uint64)-1; + return; + } + + d = ts.tv_sec; + d += TIME_FIXUP_CONSTANT_INT; + d *= 1000*1000*10; + /* d is now in 100ns units. */ + d += (ts.tv_nsec / 100); + + *nt = d; +} + +/**************************************************************************** + Convert a time_t to a NTTIME structure + + This is an absolute version of the one above. + By absolute I mean, it doesn't adjust from 1/1/1970 to 1/1/1601 + If the nttime_t was 5 seconds, the NTTIME is 5 seconds. JFM +****************************************************************************/ + +void unix_to_nt_time_abs(NTTIME *nt, time_t t) +{ + double d; + + if (t==0) { + *nt = 0; + return; + } + + if (t == TIME_T_MAX) { + *nt = 0x7fffffffffffffffLL; + return; + } + + if (t == (time_t)-1) { + /* that's what NT uses for infinite */ + *nt = 0x8000000000000000LL; + return; + } + + d = (double)(t); + d *= 1.0e7; + + *nt = d; + + /* convert to a negative value */ + *nt=~*nt; +} + + +/**************************************************************************** + Check if it's a null mtime. +****************************************************************************/ + +BOOL null_mtime(time_t mtime) +{ + if (mtime == 0 || mtime == (time_t)0xFFFFFFFF || mtime == (time_t)-1) + return(True); + return(False); +} + +/**************************************************************************** + Utility function that always returns a const string even if localtime + and asctime fail. +****************************************************************************/ + +const char *time_to_asc(const time_t *t) +{ + const char *asct; + struct tm *lt = localtime(t); + + if (!lt) { + return "unknown time"; + } + + asct = asctime(lt); + if (!asct) { + return "unknown time"; + } + return asct; +} + +const char *display_time(NTTIME nttime) +{ + static fstring string; + + float high; + float low; + int sec; + int days, hours, mins, secs; + + if (nttime==0) + return "Now"; + + if (nttime==0x8000000000000000LL) + return "Never"; + + high = 65536; + high = high/10000; + high = high*65536; + high = high/1000; + high = high * (~(nttime >> 32)); + + low = ~(nttime & 0xFFFFFFFF); + low = low/(1000*1000*10); + + sec=high+low; + + days=sec/(60*60*24); + hours=(sec - (days*60*60*24)) / (60*60); + mins=(sec - (days*60*60*24) - (hours*60*60) ) / 60; + secs=sec - (days*60*60*24) - (hours*60*60) - (mins*60); + + fstr_sprintf(string, "%u days, %u hours, %u minutes, %u seconds", days, hours, mins, secs); + return (string); +} + +BOOL nt_time_is_set(const NTTIME *nt) +{ + if (*nt == 0x7FFFFFFFFFFFFFFFLL) { + return False; + } + + if (*nt == 0x8000000000000000LL) { + return False; + } + + return True; +} + -- cgit From 8bf6d571764f67603bd120dc06e38b53c69cf320 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 17 Sep 2006 20:05:09 +0000 Subject: r18597: A C++ warning (This used to be commit 528082aed8c24b54d5781c6b3a6062b6cded74ef) --- source3/lib/time.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index 715c1a1bcc..9fe69eb45a 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -270,7 +270,7 @@ time_t pull_dos_date2(const uint8_t *date_ptr, int zone_offset) x2 = ((x&0xFFFF)<<16) | ((x&0xFFFF0000)>>16); SIVAL(&x,0,x2); - return pull_dos_date((void *)&x, zone_offset); + return pull_dos_date((const uint8_t *)&x, zone_offset); } /** -- cgit From 5a2585416c10216bd1097e7e369476dce780f776 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 12 Jan 2007 02:12:15 +0000 Subject: r20692: Fix bug found by Guenther - Just try to log on in offline mode without the fix: all accounts are expired, although they are set to never expire in the PAC/info3. NTTIME "Never" needs to get (time_t) -1. We were casting a uint64 to time_t before comparing, and we should have been doing it the other way around. Guenther please check this fixes things. Jeremy. (This used to be commit f4e898b6224fd82d9805da771ef6040065de7b12) --- source3/lib/time.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index 9fe69eb45a..762c775ea2 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -1112,7 +1112,7 @@ struct timespec nt_time_to_unix_timespec(NTTIME *nt) return ret; } - if (((time_t)d) >= TIME_T_MAX) { + if (d >= (uint64)TIME_T_MAX) { ret.tv_sec = TIME_T_MAX; ret.tv_nsec = 0; return ret; -- cgit From ec4384913415a64f9b95fa679692800d2dc6afd4 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 12 Jan 2007 02:48:37 +0000 Subject: r20694: To get this right we need to do signed 64-bit comparisons here, not unsigned as we're eventually casting into what it normall a signed 32 bit value. Guenther please check (but I think I'm right here). Jeremy. (This used to be commit 31f8e0edc0c3e76654728b2c204faa70830e1f1b) --- source3/lib/time.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index 762c775ea2..e211bda3fb 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -1085,16 +1085,16 @@ time_t cli_make_unix_date3(struct cli_state *cli, void *date_ptr) /* Large integer version. */ struct timespec nt_time_to_unix_timespec(NTTIME *nt) { - uint64 d; + int64 d; struct timespec ret; - if (*nt == 0 || *nt == (uint64)-1) { + if (*nt == 0 || *nt == (int64)-1) { ret.tv_sec = 0; ret.tv_nsec = 0; return ret; } - d = *nt; + d = (int64)*nt; /* d is now in 100ns units, since jan 1st 1601". Save off the ns fraction. */ @@ -1106,20 +1106,20 @@ struct timespec nt_time_to_unix_timespec(NTTIME *nt) /* Now adjust by 369 years to make the secs since 1970 */ d -= TIME_FIXUP_CONSTANT_INT; - if (((time_t)d) <= TIME_T_MIN) { + if (d <= (int64)TIME_T_MIN) { ret.tv_sec = TIME_T_MIN; ret.tv_nsec = 0; return ret; } - if (d >= (uint64)TIME_T_MAX) { + if (d >= (int64)TIME_T_MAX) { ret.tv_sec = TIME_T_MAX; ret.tv_nsec = 0; return ret; } ret.tv_sec = (time_t)d; - return ret; + return ret; } /**************************************************************************** Check if two NTTIMEs are the same. @@ -1238,7 +1238,7 @@ void unix_timespec_to_nt_time(NTTIME *nt, struct timespec ts) This is an absolute version of the one above. By absolute I mean, it doesn't adjust from 1/1/1970 to 1/1/1601 - If the nttime_t was 5 seconds, the NTTIME is 5 seconds. JFM + If the time_t was 5 seconds, the NTTIME is 5 seconds. JFM ****************************************************************************/ void unix_to_nt_time_abs(NTTIME *nt, time_t t) -- cgit From b86d6b75c02576eae7c19c9018273a176b1c376a Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 12 Jan 2007 02:58:01 +0000 Subject: r20695: Remove duplication of constants. Jeremy. (This used to be commit 66cca893e1aa035fa0aa05c0d542848f084fac31) --- source3/lib/time.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index e211bda3fb..f45a8d3e84 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -56,8 +56,6 @@ void GetTimeOfDay(struct timeval *tval) #endif } -#define TIME_FIXUP_CONSTANT 11644473600LL - struct timespec convert_time_t_to_timespec(time_t t) { struct timespec ts; @@ -107,7 +105,7 @@ void unix_to_nt_time(NTTIME *nt, time_t t) } t2 = t; - t2 += TIME_FIXUP_CONSTANT; + t2 += TIME_FIXUP_CONSTANT_INT; t2 *= 1000*1000*10; *nt = t2; @@ -545,7 +543,7 @@ struct timeval timeval_until(const struct timeval *tv1, NTTIME timeval_to_nttime(const struct timeval *tv) { return 10*(tv->tv_usec + - ((TIME_FIXUP_CONSTANT + (uint64_t)tv->tv_sec) * 1000000)); + ((TIME_FIXUP_CONSTANT_INT + (uint64_t)tv->tv_sec) * 1000000)); } /******************************************************************* @@ -1075,13 +1073,6 @@ time_t cli_make_unix_date3(struct cli_state *cli, void *date_ptr) return make_unix_date3(date_ptr, cli->serverzone); } -#if (SIZEOF_LONG == 8) -#define TIME_FIXUP_CONSTANT_INT 11644473600L -#elif (SIZEOF_LONG_LONG == 8) -#define TIME_FIXUP_CONSTANT_INT 11644473600LL -#endif - - /* Large integer version. */ struct timespec nt_time_to_unix_timespec(NTTIME *nt) { -- cgit From 5c9344fa4cb0d1796ca7ea819080d344f6238994 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 30 Jan 2007 19:26:01 +0000 Subject: r21060: Start refactoring out the non-return case statements into functions. Jeremy. (This used to be commit 461db3c8ed045cac70eccf3200bf9163dbce5826) --- source3/lib/time.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index f45a8d3e84..403fb0594d 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -943,7 +943,7 @@ void dos_filetime_timespec(struct timespec *tsp) localtime). ********************************************************************/ -static time_t make_unix_date(void *date_ptr, int zone_offset) +static time_t make_unix_date(const void *date_ptr, int zone_offset) { uint32 dos_date=0; struct tm t; @@ -970,7 +970,7 @@ static time_t make_unix_date(void *date_ptr, int zone_offset) Like make_unix_date() but the words are reversed. ********************************************************************/ -static time_t make_unix_date2(void *date_ptr, int zone_offset) +static time_t make_unix_date2(const void *date_ptr, int zone_offset) { uint32 x,x2; @@ -978,7 +978,7 @@ static time_t make_unix_date2(void *date_ptr, int zone_offset) x2 = ((x&0xFFFF)<<16) | ((x&0xFFFF0000)>>16); SIVAL(&x,0,x2); - return(make_unix_date((void *)&x, zone_offset)); + return(make_unix_date((const void *)&x, zone_offset)); } /******************************************************************* @@ -986,7 +986,7 @@ static time_t make_unix_date2(void *date_ptr, int zone_offset) these generally arrive as localtimes, with corresponding DST. ******************************************************************/ -static time_t make_unix_date3(void *date_ptr, int zone_offset) +static time_t make_unix_date3(const void *date_ptr, int zone_offset) { time_t t = (time_t)IVAL(date_ptr,0); if (!null_mtime(t)) { @@ -995,17 +995,17 @@ static time_t make_unix_date3(void *date_ptr, int zone_offset) return(t); } -time_t srv_make_unix_date(void *date_ptr) +time_t srv_make_unix_date(const void *date_ptr) { return make_unix_date(date_ptr, server_zone_offset); } -time_t srv_make_unix_date2(void *date_ptr) +time_t srv_make_unix_date2(const void *date_ptr) { return make_unix_date2(date_ptr, server_zone_offset); } -time_t srv_make_unix_date3(void *date_ptr) +time_t srv_make_unix_date3(const void *date_ptr) { return make_unix_date3(date_ptr, server_zone_offset); } @@ -1026,7 +1026,7 @@ time_t convert_timespec_to_time_t(struct timespec ts) will be returned as (time_t)-1, whereas nt_time_to_unix returns 0 in this case. ****************************************************************************/ -struct timespec interpret_long_date(char *p) +struct timespec interpret_long_date(const char *p) { NTTIME nt; nt = IVAL(p,0) + ((uint64_t)IVAL(p,4) << 32); -- cgit From efd510fa185a75cad9ae2b5352f72f84113b950f Mon Sep 17 00:00:00 2001 From: Jim McDonough Date: Thu, 1 Mar 2007 20:52:14 +0000 Subject: r21637: Get "password never expires" account policy working. 0x8000000000000000LL is "infinity" to NT and should not be converted numerically to time_t. (This used to be commit f3a8048a628753990f9c5401b2bb50c19d4f66e3) --- source3/lib/time.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index 403fb0594d..3abe233c4f 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -36,6 +36,8 @@ #define TIME_T_MAX (~ (time_t) 0 - TIME_T_MIN) #endif +#define NTTIME_INFINITY (NTTIME)0x8000000000000000LL + /** External access to time_t_min and time_t_max. **/ @@ -1180,6 +1182,10 @@ time_t nt_time_to_unix_abs(const NTTIME *nt) return (time_t)-1; } + if (*nt == NTTIME_INFINITY) { + return (time_t)-1; + } + /* reverse the time */ /* it's a negative value, turn it to positive */ d=~*nt; @@ -1248,7 +1254,7 @@ void unix_to_nt_time_abs(NTTIME *nt, time_t t) if (t == (time_t)-1) { /* that's what NT uses for infinite */ - *nt = 0x8000000000000000LL; + *nt = NTTIME_INFINITY; return; } @@ -1306,7 +1312,7 @@ const char *display_time(NTTIME nttime) if (nttime==0) return "Now"; - if (nttime==0x8000000000000000LL) + if (nttime==NTTIME_INFINITY) return "Never"; high = 65536; @@ -1335,7 +1341,7 @@ BOOL nt_time_is_set(const NTTIME *nt) return False; } - if (*nt == 0x8000000000000000LL) { + if (*nt == NTTIME_INFINITY) { return False; } -- cgit From 4952fe368a40b239140b3035db6075427d237bb9 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 5 Mar 2007 23:40:03 +0000 Subject: r21714: Change the VFS interface to use struct timespec for utimes - change the call to ntimes. This preserves nsec timestamps we get from stat (if the system supports it) and only maps back down to usec or sec resolution on time set. Looks bigger than it is as I had to move lots of internal code from using time_t and struct utimebuf to struct timespec. Jeremy. (This used to be commit 8f3d530c5a748ea90f42ed8fbe68ae92178d4875) --- source3/lib/time.c | 144 +++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 113 insertions(+), 31 deletions(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index 3abe233c4f..e98f8232ab 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -4,6 +4,7 @@ Copyright (C) Andrew Tridgell 1992-2004 Copyright (C) Stefan (metze) Metzmacher 2002 + Copyright (C) Jeremy Allison 2007 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -38,17 +39,19 @@ #define NTTIME_INFINITY (NTTIME)0x8000000000000000LL -/** +/*************************************************************************** External access to time_t_min and time_t_max. -**/ +****************************************************************************/ + time_t get_time_t_max(void) { return TIME_T_MAX; } -/** -a gettimeofday wrapper -**/ +/*************************************************************************** + A gettimeofday wrapper. +****************************************************************************/ + void GetTimeOfDay(struct timeval *tval) { #ifdef HAVE_GETTIMEOFDAY_TZ @@ -58,14 +61,6 @@ void GetTimeOfDay(struct timeval *tval) #endif } -struct timespec convert_time_t_to_timespec(time_t t) -{ - struct timespec ts; - ts.tv_sec = t; - ts.tv_nsec = 0; - return ts; -} - #if (SIZEOF_LONG == 8) #define TIME_FIXUP_CONSTANT_INT 11644473600L #elif (SIZEOF_LONG_LONG == 8) @@ -113,10 +108,10 @@ void unix_to_nt_time(NTTIME *nt, time_t t) *nt = t2; } +/**************************************************************************** + Check if it's a null unix time. +****************************************************************************/ -/** -check if it's a null unix time -**/ BOOL null_time(time_t t) { return t == 0 || @@ -124,15 +119,26 @@ BOOL null_time(time_t t) t == (time_t)-1; } +/**************************************************************************** + Check if it's a null NTTIME. +****************************************************************************/ -/** -check if it's a null NTTIME -**/ BOOL null_nttime(NTTIME t) { return t == 0 || t == (NTTIME)-1; } +/**************************************************************************** + Check if it's a null timespec. +****************************************************************************/ + +BOOL null_timespec(struct timespec ts) +{ + return ts.tv_sec == 0 || + ts.tv_sec == (time_t)0xFFFFFFFF || + ts.tv_sec == (time_t)-1; +} + /******************************************************************* create a 16 bit dos packed date ********************************************************************/ @@ -549,8 +555,9 @@ NTTIME timeval_to_nttime(const struct timeval *tv) } /******************************************************************* -yield the difference between *A and *B, in seconds, ignoring leap seconds + Yield the difference between *A and *B, in seconds, ignoring leap seconds. ********************************************************************/ + static int tm_diff(struct tm *a, struct tm *b) { int ay = a->tm_year + (1900 - 1); @@ -568,9 +575,10 @@ static int tm_diff(struct tm *a, struct tm *b) int extra_time_offset=0; -/** - return the UTC offset in seconds west of UTC, or 0 if it cannot be determined - */ +/******************************************************************* + Return the UTC offset in seconds west of UTC, or 0 if it cannot be determined. +********************************************************************/ + int get_time_zone(time_t t) { struct tm *tm = gmtime(&t); @@ -780,7 +788,7 @@ void put_long_date(char *p, time_t t) structure. ****************************************************************************/ -time_t get_create_time(SMB_STRUCT_STAT *st,BOOL fake_dirs) +time_t get_create_time(const SMB_STRUCT_STAT *st,BOOL fake_dirs) { time_t ret, ret1; @@ -802,7 +810,7 @@ time_t get_create_time(SMB_STRUCT_STAT *st,BOOL fake_dirs) return ret; } -struct timespec get_create_timespec(SMB_STRUCT_STAT *st,BOOL fake_dirs) +struct timespec get_create_timespec(const SMB_STRUCT_STAT *st,BOOL fake_dirs) { struct timespec ts; ts.tv_sec = get_create_time(st, fake_dirs); @@ -814,7 +822,7 @@ struct timespec get_create_timespec(SMB_STRUCT_STAT *st,BOOL fake_dirs) Get/Set all the possible time fields from a stat struct as a timespec. ****************************************************************************/ -struct timespec get_atimespec(SMB_STRUCT_STAT *pst) +struct timespec get_atimespec(const SMB_STRUCT_STAT *pst) { #if !defined(HAVE_STAT_HIRES_TIMESTAMPS) struct timespec ret; @@ -854,7 +862,7 @@ void set_atimespec(SMB_STRUCT_STAT *pst, struct timespec ts) #endif } -struct timespec get_mtimespec(SMB_STRUCT_STAT *pst) +struct timespec get_mtimespec(const SMB_STRUCT_STAT *pst) { #if !defined(HAVE_STAT_HIRES_TIMESTAMPS) struct timespec ret; @@ -894,7 +902,7 @@ void set_mtimespec(SMB_STRUCT_STAT *pst, struct timespec ts) #endif } -struct timespec get_ctimespec(SMB_STRUCT_STAT *pst) +struct timespec get_ctimespec(const SMB_STRUCT_STAT *pst) { #if !defined(HAVE_STAT_HIRES_TIMESTAMPS) struct timespec ret; @@ -1022,6 +1030,81 @@ time_t convert_timespec_to_time_t(struct timespec ts) return ts.tv_sec; } +struct timespec convert_time_t_to_timespec(time_t t) +{ + struct timespec ts; + ts.tv_sec = t; + ts.tv_nsec = 0; + return ts; +} + +/**************************************************************************** + Convert a normalized timeval to a timespec. +****************************************************************************/ + +struct timespec convert_timeval_to_timespec(const struct timeval tv) +{ + struct timespec ts; + ts.tv_sec = tv.tv_sec; + ts.tv_nsec = tv.tv_usec * 1000; + return ts; +} + +/**************************************************************************** + Convert a normalized timespec to a timeval. +****************************************************************************/ + +struct timeval convert_timespec_to_timeval(const struct timespec ts) +{ + struct timeval tv; + tv.tv_sec = ts.tv_sec; + tv.tv_usec = ts.tv_nsec / 1000; + return tv; +} + +/**************************************************************************** + Return a timespec for the current time +****************************************************************************/ + +struct timespec timespec_current(void) +{ + struct timeval tv; + struct timespec ts; + GetTimeOfDay(&tv); + ts.tv_sec = tv.tv_sec; + ts.tv_nsec = tv.tv_sec * 1000; + return ts; +} + +/**************************************************************************** + Return the lesser of two timespecs. +****************************************************************************/ + +struct timespec timespec_min(const struct timespec *ts1, + const struct timespec *ts2) +{ + if (ts1->tv_sec < ts2->tv_sec) return *ts1; + if (ts1->tv_sec > ts2->tv_sec) return *ts2; + if (ts1->tv_nsec < ts2->tv_nsec) return *ts1; + return *ts2; +} + +/**************************************************************************** + compare two timespec structures. + Return -1 if ts1 < ts2 + Return 0 if ts1 == ts2 + Return 1 if ts1 > ts2 +****************************************************************************/ + +int timespec_compare(const struct timespec *ts1, const struct timespec *ts2) +{ + if (ts1->tv_sec > ts2->tv_sec) return 1; + if (ts1->tv_sec < ts2->tv_sec) return -1; + if (ts1->tv_nsec > ts2->tv_nsec) return 1; + if (ts1->tv_nsec < ts2->tv_nsec) return -1; + return 0; +} + /**************************************************************************** Interprets an nt time into a unix struct timespec. Differs from nt_time_to_unix in that an 8 byte value of 0xffffffffffffffff @@ -1284,10 +1367,10 @@ BOOL null_mtime(time_t mtime) and asctime fail. ****************************************************************************/ -const char *time_to_asc(const time_t *t) +const char *time_to_asc(const time_t t) { const char *asct; - struct tm *lt = localtime(t); + struct tm *lt = localtime(&t); if (!lt) { return "unknown time"; @@ -1347,4 +1430,3 @@ BOOL nt_time_is_set(const NTTIME *nt) return True; } - -- cgit From c15c0f2a47caa61f0575a63d88d1481d34530643 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 18 May 2007 23:38:56 +0000 Subject: r23005: If we're running on a system where time_t is 8 bytes we have to take care to preserve the "special" values for Windows of 0x80000000 and 0x7FFFFFFF when casting between time_t and uint32. Add conversion functions (and use them). Jeremy. (This used to be commit 4e1a0b2549f7c11326deed2801de19564af0f16a) --- source3/lib/time.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index e98f8232ab..ba158fe1ae 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -554,6 +554,37 @@ NTTIME timeval_to_nttime(const struct timeval *tv) ((TIME_FIXUP_CONSTANT_INT + (uint64_t)tv->tv_sec) * 1000000)); } +/************************************************************** + Handle conversions between time_t and uint32, taking care to + preserve the "special" values. +**************************************************************/ + +uint32 convert_time_t_to_uint32(time_t t) +{ +#if (defined(SIZEOF_TIME_T) && (SIZEOF_TIME_T == 8)) + /* time_t is 64-bit. */ + if (t == 0x8000000000000000LL) { + return 0x80000000; + } else if (t == 0x7FFFFFFFFFFFFFFFLL) { + return 0x7FFFFFFF; + } +#endif + return (uint32)t; +} + +time_t convert_uint32_to_time_t(uint32 u) +{ +#if (defined(SIZEOF_TIME_T) && (SIZEOF_TIME_T == 8)) + /* time_t is 64-bit. */ + if (u == 0x80000000) { + return (time_t)0x8000000000000000LL; + } else if (u == 0x7FFFFFFF) { + return (time_t)0x7FFFFFFFFFFFFFFFLL) { + } +#endif + return (time_t)u; +} + /******************************************************************* Yield the difference between *A and *B, in seconds, ignoring leap seconds. ********************************************************************/ -- cgit From 92dba2329fcdb00a756d670bbb303091426a4147 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 18 May 2007 23:56:34 +0000 Subject: r23006: Arg. Fix stupid typo in 64-bit path. Jeremy. (This used to be commit 80a63123907c3291d8bdc6d364bf7343f4f084a0) --- source3/lib/time.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index ba158fe1ae..ae7f97790d 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -579,7 +579,7 @@ time_t convert_uint32_to_time_t(uint32 u) if (u == 0x80000000) { return (time_t)0x8000000000000000LL; } else if (u == 0x7FFFFFFF) { - return (time_t)0x7FFFFFFFFFFFFFFFLL) { + return (time_t)0x7FFFFFFFFFFFFFFFLL; } #endif return (time_t)u; -- cgit From 0afd56aa837527941560118d8d156032fb8a2e8d Mon Sep 17 00:00:00 2001 From: Jim McDonough Date: Mon, 21 May 2007 16:01:22 +0000 Subject: r23041: Remainder of fix for 4630: fix special case of unix_to_nt_time() for TIME_T_MAX, and also display of it in http_timestring() (This used to be commit 2553b6a56d20ef6273001ae3b090e156e676592c) --- source3/lib/time.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index ae7f97790d..ee44f5eb13 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -95,7 +95,13 @@ void unix_to_nt_time(NTTIME *nt, time_t t) if (t == (time_t)-1) { *nt = (NTTIME)-1LL; return; - } + } + + if (t == TIME_T_MAX) { + *nt = 0x7fffffffffffffffLL; + return; + } + if (t == 0) { *nt = 0; return; @@ -301,7 +307,9 @@ char *http_timestring(time_t t) static fstring buf; struct tm *tm = localtime(&t); - if (!tm) { + if (t == TIME_T_MAX) { + slprintf(buf,sizeof(buf)-1,"never"); + } else if (!tm) { slprintf(buf,sizeof(buf)-1,"%ld seconds since the Epoch",(long)t); } else { #ifndef HAVE_STRFTIME -- cgit From 51ea3a2d00b1f66f4a1b15fccc8de721785d5ebc Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 5 Jun 2007 19:17:05 +0000 Subject: r23357: timespec_current() was returning the wrong ns time (multiplying tv_sec, not tv_usec). Jeremy. (This used to be commit bafd3b93f9ce74d7a8e2d6b36735f0977a22882c) --- source3/lib/time.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index ee44f5eb13..a703066248 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -1111,7 +1111,7 @@ struct timespec timespec_current(void) struct timespec ts; GetTimeOfDay(&tv); ts.tv_sec = tv.tv_sec; - ts.tv_nsec = tv.tv_sec * 1000; + ts.tv_nsec = tv.tv_usec * 1000; return ts; } -- cgit From d824b98f80ba186030cbb70b3a1e5daf80469ecd Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 9 Jul 2007 19:25:36 +0000 Subject: r23779: Change from v2 or later to v3 or later. Jeremy. (This used to be commit 407e6e695b8366369b7c76af1ff76869b45347b3) --- source3/lib/time.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index a703066248..c2aac13a61 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -8,7 +8,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, -- cgit From 5e54558c6dea67b56bbfaba5698f3a434d3dffb6 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 00:52:41 +0000 Subject: r23784: use the GPLv3 boilerplate as recommended by the FSF and the license text (This used to be commit b0132e94fc5fef936aa766fb99a306b3628e9f07) --- source3/lib/time.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index c2aac13a61..9d874c21fa 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -17,8 +17,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ #include "includes.h" -- cgit From ff0947fbed841065fce85c64ff4b2a2e8f24f056 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 4 Sep 2007 10:15:04 +0000 Subject: r24949: Remove some static buffers (This used to be commit df648d47ff3c4e24f439fda839653bda98323100) --- source3/lib/time.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index 9d874c21fa..35d10186be 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -303,13 +303,13 @@ time_t pull_dos_date3(const uint8_t *date_ptr, int zone_offset) char *http_timestring(time_t t) { - static fstring buf; + fstring buf; struct tm *tm = localtime(&t); if (t == TIME_T_MAX) { - slprintf(buf,sizeof(buf)-1,"never"); + fstrcpy(buf, "never"); } else if (!tm) { - slprintf(buf,sizeof(buf)-1,"%ld seconds since the Epoch",(long)t); + fstr_sprintf(buf, "%ld seconds since the Epoch", (long)t); } else { #ifndef HAVE_STRFTIME const char *asct = asctime(tm); @@ -321,7 +321,7 @@ char *http_timestring(time_t t) strftime(buf, sizeof(buf)-1, "%a, %d %b %Y %H:%M:%S %Z", tm); #endif /* !HAVE_STRFTIME */ } - return buf; + return talloc_strdup(talloc_tos(), buf); } @@ -689,7 +689,7 @@ int set_server_zone_offset(time_t t) char *current_timestring(BOOL hires) { - static fstring TimeBuf; + fstring TimeBuf; struct timeval tp; time_t t; struct tm *tm; @@ -739,7 +739,7 @@ char *current_timestring(BOOL hires) } #endif } - return(TimeBuf); + return talloc_strdup(talloc_tos(), TimeBuf); } @@ -1423,8 +1423,6 @@ const char *time_to_asc(const time_t t) const char *display_time(NTTIME nttime) { - static fstring string; - float high; float low; int sec; @@ -1452,8 +1450,8 @@ const char *display_time(NTTIME nttime) mins=(sec - (days*60*60*24) - (hours*60*60) ) / 60; secs=sec - (days*60*60*24) - (hours*60*60) - (mins*60); - fstr_sprintf(string, "%u days, %u hours, %u minutes, %u seconds", days, hours, mins, secs); - return (string); + return talloc_asprintf(talloc_tos(), "%u days, %u hours, %u minutes, " + "%u seconds", days, hours, mins, secs); } BOOL nt_time_is_set(const NTTIME *nt) -- cgit From 30191d1a5704ad2b158386b511558972d539ce47 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 18 Oct 2007 17:40:25 -0700 Subject: RIP BOOL. Convert BOOL -> bool. I found a few interesting bugs in various places whilst doing this (places that assumed BOOL == int). I also need to fix the Samba4 pidl generation (next checkin). Jeremy. (This used to be commit f35a266b3cbb3e5fa6a86be60f34fe340a3ca71f) --- source3/lib/time.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index 35d10186be..e29308fcd0 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -117,7 +117,7 @@ void unix_to_nt_time(NTTIME *nt, time_t t) Check if it's a null unix time. ****************************************************************************/ -BOOL null_time(time_t t) +bool null_time(time_t t) { return t == 0 || t == (time_t)0xFFFFFFFF || @@ -128,7 +128,7 @@ BOOL null_time(time_t t) Check if it's a null NTTIME. ****************************************************************************/ -BOOL null_nttime(NTTIME t) +bool null_nttime(NTTIME t) { return t == 0 || t == (NTTIME)-1; } @@ -137,7 +137,7 @@ BOOL null_nttime(NTTIME t) Check if it's a null timespec. ****************************************************************************/ -BOOL null_timespec(struct timespec ts) +bool null_timespec(struct timespec ts) { return ts.tv_sec == 0 || ts.tv_sec == (time_t)0xFFFFFFFF || @@ -401,7 +401,7 @@ struct timeval timeval_zero(void) /** return True if a timeval is zero */ -BOOL timeval_is_zero(const struct timeval *tv) +bool timeval_is_zero(const struct timeval *tv) { return tv->tv_sec == 0 && tv->tv_usec == 0; } @@ -479,7 +479,7 @@ int timeval_compare(const struct timeval *tv1, const struct timeval *tv2) /** return True if a timer is in the past */ -BOOL timeval_expired(const struct timeval *tv) +bool timeval_expired(const struct timeval *tv) { struct timeval tv2 = timeval_current(); if (tv2.tv_sec > tv->tv_sec) return True; @@ -634,7 +634,7 @@ int get_time_zone(time_t t) Check if NTTIME is 0. ****************************************************************************/ -BOOL nt_time_is_zero(const NTTIME *nt) +bool nt_time_is_zero(const NTTIME *nt) { return (*nt == 0); } @@ -687,7 +687,7 @@ int set_server_zone_offset(time_t t) Return the date and time as a string ****************************************************************************/ -char *current_timestring(BOOL hires) +char *current_timestring(bool hires) { fstring TimeBuf; struct timeval tp; @@ -826,7 +826,7 @@ void put_long_date(char *p, time_t t) structure. ****************************************************************************/ -time_t get_create_time(const SMB_STRUCT_STAT *st,BOOL fake_dirs) +time_t get_create_time(const SMB_STRUCT_STAT *st,bool fake_dirs) { time_t ret, ret1; @@ -848,7 +848,7 @@ time_t get_create_time(const SMB_STRUCT_STAT *st,BOOL fake_dirs) return ret; } -struct timespec get_create_timespec(const SMB_STRUCT_STAT *st,BOOL fake_dirs) +struct timespec get_create_timespec(const SMB_STRUCT_STAT *st,bool fake_dirs) { struct timespec ts; ts.tv_sec = get_create_time(st, fake_dirs); @@ -1239,7 +1239,7 @@ struct timespec nt_time_to_unix_timespec(NTTIME *nt) Check if two NTTIMEs are the same. ****************************************************************************/ -BOOL nt_time_equals(const NTTIME *nt1, const NTTIME *nt2) +bool nt_time_equals(const NTTIME *nt1, const NTTIME *nt2) { return (*nt1 == *nt2); } @@ -1393,7 +1393,7 @@ void unix_to_nt_time_abs(NTTIME *nt, time_t t) Check if it's a null mtime. ****************************************************************************/ -BOOL null_mtime(time_t mtime) +bool null_mtime(time_t mtime) { if (mtime == 0 || mtime == (time_t)0xFFFFFFFF || mtime == (time_t)-1) return(True); @@ -1454,7 +1454,7 @@ const char *display_time(NTTIME nttime) "%u seconds", days, hours, mins, secs); } -BOOL nt_time_is_set(const NTTIME *nt) +bool nt_time_is_set(const NTTIME *nt) { if (*nt == 0x7FFFFFFFFFFFFFFFLL) { return False; -- cgit From d2cf97aeba14a4d336fb57b01f19bd5a08dcb003 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 29 Nov 2007 13:24:54 -0800 Subject: Remove the explicit TALLOC_CTX * from cli_struct. Make us very explicit about how long a talloc ctx should last. Jeremy. (This used to be commit ba9e2be2b5a59684e854609f9d82ea1633448c62) --- source3/lib/time.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index e29308fcd0..5301e3a55a 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -1181,17 +1181,17 @@ void cli_put_dos_date3(struct cli_state *cli, char *buf, int offset, time_t unix put_dos_date3(buf, offset, unixdate, cli->serverzone); } -time_t cli_make_unix_date(struct cli_state *cli, void *date_ptr) +time_t cli_make_unix_date(struct cli_state *cli, const void *date_ptr) { return make_unix_date(date_ptr, cli->serverzone); } -time_t cli_make_unix_date2(struct cli_state *cli, void *date_ptr) +time_t cli_make_unix_date2(struct cli_state *cli, const void *date_ptr) { return make_unix_date2(date_ptr, cli->serverzone); } -time_t cli_make_unix_date3(struct cli_state *cli, void *date_ptr) +time_t cli_make_unix_date3(struct cli_state *cli, const void *date_ptr) { return make_unix_date3(date_ptr, cli->serverzone); } -- cgit From addf598cde41d17ad4cf497a64b9a2b27e4028c5 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Thu, 20 Dec 2007 22:17:16 +0100 Subject: Some C++ warnings (This used to be commit 5ab82d4f574f2a2e2761e9e414c66a70aeffb05d) --- source3/lib/time.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index 5301e3a55a..f98e03197f 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -1382,7 +1382,7 @@ void unix_to_nt_time_abs(NTTIME *nt, time_t t) d = (double)(t); d *= 1.0e7; - *nt = d; + *nt = (NTTIME)d; /* convert to a negative value */ *nt=~*nt; @@ -1443,7 +1443,7 @@ const char *display_time(NTTIME nttime) low = ~(nttime & 0xFFFFFFFF); low = low/(1000*1000*10); - sec=high+low; + sec=(int)(high+low); days=sec/(60*60*24); hours=(sec - (days*60*60*24)) / (60*60); -- cgit From 9644b6cb50ec01c04a0d6ab17a8e39054fd8b0f8 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Fri, 28 Mar 2008 15:49:13 +0100 Subject: Add a talloc context parameter to current_timestring() to fix memleaks. current_timestring used to return a string talloced to talloc_tos(). When called by DEBUG from a TALLOC_FREE, this produced messages "no talloc stackframe around, leaking memory". For example when used from net conf. This also adds a temporary talloc context to alloc_sub_basic(). For this purpose, the exit strategy is slightly altered: a common exit point is used for success and failure. Michael (This used to be commit 16b5800d4e3a8b88bac67b2550d14e0aaaa302a9) --- source3/lib/time.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index f98e03197f..e5fd929d0f 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -687,7 +687,7 @@ int set_server_zone_offset(time_t t) Return the date and time as a string ****************************************************************************/ -char *current_timestring(bool hires) +char *current_timestring(TALLOC_CTX *ctx, bool hires) { fstring TimeBuf; struct timeval tp; @@ -739,7 +739,7 @@ char *current_timestring(bool hires) } #endif } - return talloc_strdup(talloc_tos(), TimeBuf); + return talloc_strdup(ctx, TimeBuf); } -- cgit From c4d6ca41d919cfec11b0f05e8b2f3bffbfadefcc Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 20 Jun 2008 13:23:31 -0700 Subject: Fix bug #5531 - fix conversion of ns units when converting from nttime to timespec. Fix from hkurma@datadomain.com. Jeremy. (This used to be commit 8c87a4319cc83f55fb105cae81a8efbc3fb5b98b) --- source3/lib/time.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index e5fd929d0f..17990b9269 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -1211,8 +1211,12 @@ struct timespec nt_time_to_unix_timespec(NTTIME *nt) d = (int64)*nt; /* d is now in 100ns units, since jan 1st 1601". Save off the ns fraction. */ - - ret.tv_nsec = (long) ((d % 100) * 100); + + /* + * Take the last seven decimal digits and multiply by 100. + * to convert from 100ns units to 1ns units. + */ + ret.tv_nsec = (long) ((d % (1000 * 1000 * 10)) * 100); /* Convert to seconds */ d /= 1000*1000*10; -- cgit From 33000d77e4b904cf9cdfd3e3d83a3c3cc84d7f2b Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 16 Jun 2008 13:36:53 +0200 Subject: time: move uint64s_nt_time_to_unix_abs() to lib/time.c Guenther (This used to be commit 58f54f180f0a942776455ab6e813628422493dac) --- source3/lib/time.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index 17990b9269..9db88b3fc8 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -1325,6 +1325,13 @@ time_t nt_time_to_unix_abs(const NTTIME *nt) return (time_t)d; } +time_t uint64s_nt_time_to_unix_abs(const uint64_t *src) +{ + NTTIME nttime; + nttime = *src; + return nt_time_to_unix_abs(&nttime); +} + /**************************************************************************** Put a 8 byte filetime from a struct timespec. Uses GMT. ****************************************************************************/ -- cgit From 1cae2ac905cc3e4b6e4c92ec4d64c582cfad8fea Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 27 Aug 2008 15:06:14 -0700 Subject: Add st_birthtime and friends for accurate create times on systems that support it (*BSD and MacOSX). Should have done this ages ago, sorry. Jeremy. (This used to be commit 4c3a9558906f213948c3bdc081be73f8fed148cb) --- source3/lib/time.c | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index 9db88b3fc8..3cf0cb4f64 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -826,14 +826,10 @@ void put_long_date(char *p, time_t t) structure. ****************************************************************************/ -time_t get_create_time(const SMB_STRUCT_STAT *st,bool fake_dirs) +static time_t calc_create_time(const SMB_STRUCT_STAT *st) { time_t ret, ret1; - if(S_ISDIR(st->st_mode) && fake_dirs) { - return (time_t)315493200L; /* 1/1/1980 */ - } - ret = MIN(st->st_ctime, st->st_mtime); ret1 = MIN(ret, st->st_atime); @@ -848,12 +844,36 @@ time_t get_create_time(const SMB_STRUCT_STAT *st,bool fake_dirs) return ret; } -struct timespec get_create_timespec(const SMB_STRUCT_STAT *st,bool fake_dirs) +/**************************************************************************** + Return the 'create time' from a stat struct if it exists (birthtime) or else + use the best approximation. +****************************************************************************/ + +struct timespec get_create_timespec(const SMB_STRUCT_STAT *pst,bool fake_dirs) { - struct timespec ts; - ts.tv_sec = get_create_time(st, fake_dirs); - ts.tv_nsec = 0; - return ts; + struct timespec ret; + + if(S_ISDIR(pst->st_mode) && fake_dirs) { + ret.tv_sec = 315493200L; /* 1/1/1980 */ + ret.tv_nsec = 0; + return ret; + } + +#if defined(HAVE_STAT_ST_BIRTHTIMESPEC) + return pst->st_birthtimespec; +#elif defined(HAVE_STAT_ST_BIRTHTIMENSEC) + ret.tv_sec = pst->st_birthtime; + ret.tv_nsec = pst->st_birthtimenspec; + return ret; +#elif defined(HAVE_STAT_ST_BIRTHTIME) + ret.tv_sec = pst->st_birthtime; + ret.tv_nsec = 0; + return ret; +#else + ret.tv_sec = calc_create_time(pst); + ret.tv_nsec = 0; + return ret; +#endif } /**************************************************************************** -- cgit From b12c7dbb53023d1ea9e7df20137c0ad6ba21b9f0 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 29 Aug 2008 09:29:07 -0700 Subject: Deal with systems that don't initialize birthtime correctly. Pointed out by SATOH Fumiyasu . Jeremy. (This used to be commit 4f60348c0a934123a8e15bc741076366f6713390) --- source3/lib/time.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'source3/lib/time.c') diff --git a/source3/lib/time.c b/source3/lib/time.c index 3cf0cb4f64..8cefef6e23 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -860,20 +860,26 @@ struct timespec get_create_timespec(const SMB_STRUCT_STAT *pst,bool fake_dirs) } #if defined(HAVE_STAT_ST_BIRTHTIMESPEC) - return pst->st_birthtimespec; + ret = pst->st_birthtimespec; #elif defined(HAVE_STAT_ST_BIRTHTIMENSEC) ret.tv_sec = pst->st_birthtime; ret.tv_nsec = pst->st_birthtimenspec; - return ret; #elif defined(HAVE_STAT_ST_BIRTHTIME) ret.tv_sec = pst->st_birthtime; ret.tv_nsec = 0; - return ret; #else ret.tv_sec = calc_create_time(pst); ret.tv_nsec = 0; - return ret; #endif + + /* Deal with systems that don't initialize birthtime correctly. + * Pointed out by SATOH Fumiyasu . + */ + if (null_timespec(ret)) { + ret.tv_sec = calc_create_time(pst); + ret.tv_nsec = 0; + } + return ret; } /**************************************************************************** -- cgit