Changeset 251


Ignore:
Timestamp:
05/05/11 21:34:35 (13 years ago)
Author:
tim
Message:

simplified NTTIME storage and conversions

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/regfi.h

    r250 r251  
    191191 */
    192192 /* Minimum time is Jan 1, 1990 00:00:00 */
    193 #define REGFI_MTIME_MIN_HIGH       0x01B41E6D
     193#define REGFI_MTIME_MIN            0x01B41E6D00000000L
    194194
    195195 /* Maximum time is Jan 1, 2290 00:00:00
    196196  * (We hope no one is using Windows by then...)
    197197  */
    198 #define REGFI_MTIME_MAX_HIGH       0x03047543
     198#define REGFI_MTIME_MAX            0x0304754300000000L
    199199
    200200
     
    270270                    : ~ (time_t) 0 << (sizeof (time_t) * CHAR_BIT - 1))
    271271#define TIME_T_MAX (~ (time_t) 0 - TIME_T_MIN)
    272 #define TIME_FIXUP_CONSTANT (369.0*365.25*24*60*60-(3.0*24*60*60+6.0*60*60))
     272#define REGFI_TIME_FIXUP (369.0*365.25*24*60*60-(3.0*24*60*60+6.0*60*60))
    273273
    274274
     
    278278/******************************************************************************/
    279279
    280 typedef struct _regfi_nttime
    281 {
    282   uint32_t low;
    283   uint32_t high;
    284 } REGFI_NTTIME;
    285 
     280typedef uint64_t REGFI_NTTIME;
    286281
    287282typedef struct _regfi_log
     
    17311726/* XXX: move to base API and document */
    17321727_EXPORT()
    1733 void                  regfi_unix2nt_time(REGFI_NTTIME* nt, time_t t);
    1734 _EXPORT()
    1735 double                regfi_nt2unix_time(const REGFI_NTTIME* nt);
     1728REGFI_NTTIME          regfi_unix2nt_time(time_t t);
     1729_EXPORT()
     1730double                regfi_nt2unix_time(REGFI_NTTIME nt);
    17361731
    17371732
  • trunk/lib/regfi.c

    r250 r251  
    27532753  ret_val->sequence1 = IVAL(file_header, 0x4);
    27542754  ret_val->sequence2 = IVAL(file_header, 0x8);
    2755   ret_val->mtime.low = IVAL(file_header, 0xC);
    2756   ret_val->mtime.high = IVAL(file_header, 0x10);
     2755  ret_val->mtime = ((uint64_t)IVAL(file_header, 0x10)) << 32;
     2756  ret_val->mtime |= IVAL(file_header, 0xC);
    27572757  ret_val->major_version = IVAL(file_header, 0x14);
    27582758  ret_val->minor_version = IVAL(file_header, 0x18);
     
    29362936  }
    29372937
    2938   ret_val->mtime.low = IVAL(nk_header, 0x4);
    2939   ret_val->mtime.high = IVAL(nk_header, 0x8);
     2938  ret_val->mtime = ((uint64_t)IVAL(nk_header, 0x8)) << 32;
     2939  ret_val->mtime |= IVAL(nk_header, 0x4);
    29402940  /* If the key is unallocated and the MTIME is earlier than Jan 1, 1990
    29412941   * or later than Jan 1, 2290, we consider this a bad key.  This helps
     
    29432943   */
    29442944  if(unalloc
    2945      && (ret_val->mtime.high < REGFI_MTIME_MIN_HIGH
    2946          || ret_val->mtime.high > REGFI_MTIME_MAX_HIGH))
     2945     && (ret_val->mtime < REGFI_MTIME_MIN
     2946         || ret_val->mtime > REGFI_MTIME_MAX))
    29472947  { goto fail_locked; }
    29482948
     
    37943794
    37953795/****************************************************************************
    3796  Put a 8 byte filetime from a time_t
     3796 Returns an 8 byte filetime from a time_t
    37973797 This takes real GMT as input and converts to kludge-GMT
    37983798****************************************************************************/
    3799 void regfi_unix2nt_time(REGFI_NTTIME *nt, time_t t)
     3799REGFI_NTTIME regfi_unix2nt_time(time_t t)
    38003800{
    38013801  double d;
    3802  
    3803   if (t==0)
    3804   {
    3805     nt->low = 0;
    3806     nt->high = 0;
    3807     return;
    3808   }
     3802
     3803  if (t==0)
     3804    return 0L;
    38093805 
    38103806  if (t == TIME_T_MAX)
    3811   {
    3812     nt->low = 0xffffffff;
    3813     nt->high = 0x7fffffff;
    3814     return;
    3815   }             
     3807    return 0x7fffffffffffffffL;
    38163808 
    38173809  if (t == -1)
    3818   {
    3819     nt->low = 0xffffffff;
    3820     nt->high = 0xffffffff;
    3821     return;
    3822   }             
     3810    return 0xffffffffffffffffL;
    38233811 
    38243812  /* this converts GMT to kludge-GMT */
     
    38293817  /* t -= TimeDiff(t) - get_serverzone(); */
    38303818 
    3831   d = (double)(t);
    3832   d += TIME_FIXUP_CONSTANT;
     3819  d = (double)(t) + REGFI_TIME_FIXUP;
    38333820  d *= 1.0e7;
    3834  
    3835   nt->high = (uint32_t)(d * (1.0/(4.0*(double)(1<<30))));
    3836   nt->low  = (uint32_t)(d - ((double)nt->high)*4.0*(double)(1<<30));
     3821  /*
     3822  nt->high = (uint32_t)(d * (1.0/c));
     3823  nt->low  = (uint32_t)(d - ((double)nt->high) * c);
     3824  */
     3825
     3826  return (REGFI_NTTIME) d;
    38373827}
    38383828
     
    38493839 converts this to real GMT.
    38503840****************************************************************************/
    3851 double regfi_nt2unix_time(const REGFI_NTTIME* nt)
     3841double regfi_nt2unix_time(REGFI_NTTIME nt)
    38523842{
    38533843  double ret_val;
    3854 
    3855   /* The next two lines are a fix needed for the
    3856      broken SCO compiler. JRA. */
    3857   time_t l_time_min = TIME_T_MIN;
    3858   time_t l_time_max = TIME_T_MAX;
    3859  
    3860   if (nt->high == 0 || (nt->high == 0xffffffff && nt->low == 0xffffffff))
    3861     return(0);
    3862  
    3863   ret_val = ((double)nt->high)*4.0*(double)(1<<30);
    3864   ret_val += nt->low;
    3865   ret_val *= 1.0e-7;
     3844 
     3845  if (nt == 0 || nt == 0xffffffffffffffffL)
     3846    return 0;
     3847 
     3848  ret_val = (double)(nt) * 1.0e-7;
    38663849 
    38673850  /* now adjust by 369 years to make the secs since 1970 */
    3868   ret_val -= TIME_FIXUP_CONSTANT;
    3869  
    3870   /* XXX: should these sanity checks be removed? */
    3871   if (ret_val <= l_time_min)
    3872     return (l_time_min);
    3873  
    3874   if (ret_val >= l_time_max)
    3875     return (l_time_max);
     3851  ret_val -= REGFI_TIME_FIXUP;
    38763852 
    38773853  /* this takes us from kludge-GMT to real GMT */
  • trunk/src/common.c

    r232 r251  
    361361
    362362
    363 void formatTime(const REGFI_NTTIME* nttime, char* output)
     363void formatTime(REGFI_NTTIME nttime, char* output)
    364364{
    365365  time_t tmp_time[1];
  • trunk/src/reglookup-recover.c

    r233 r251  
    7373  char* quoted_raw = "";
    7474
    75   formatTime(&nk->mtime, mtime);
     75  formatTime(nk->mtime, mtime);
    7676 
    7777  /* XXX: Add command line option to choose output encoding */
  • trunk/src/reglookup.c

    r249 r251  
    107107  {
    108108    cur_key = regfi_iterator_cur_key(iter);
    109     *tmp_time = regfi_nt2unix_time(&cur_key->mtime);
     109    *tmp_time = regfi_nt2unix_time(cur_key->mtime);
    110110    tmp_time_s = gmtime(tmp_time);
    111111    strftime(mtime, sizeof(mtime), "%Y-%m-%d %H:%M:%S", tmp_time_s);
     
    304304  const REGFI_CLASSNAME* classname;
    305305
    306   formatTime(&key->mtime, mtime);
     306  formatTime(key->mtime, mtime);
    307307
    308308  if(print_security && (sk=regfi_fetch_sk(iter->f, key)))
Note: See TracChangeset for help on using the changeset viewer.