source: trunk/lib/smb_deps.c @ 160

Last change on this file since 160 was 157, checked in by tim, 15 years ago

reorganized data parsing in regfi

simplified some length validation

added big data support to reglookup-recover

fixed reglookup-recover's handling of data values in the offset

  • Property svn:keywords set to Id
File size: 3.6 KB
RevLine 
[30]1/*
2 * This file contains miscellaneous pieces of code which regfio.c
3 * depends upon, from the Samba Subversion tree.  See:
4 *   http://websvn.samba.org/cgi-bin/viewcvs.cgi/trunk/source/
5 *
[132]6 * Copyright (C) 2005-2006,2009 Timothy D. Morgan
[30]7 * Copyright (C) 1992-2005 Samba development team
8 *               (see individual files under Subversion for details.)
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
[111]12 * the Free Software Foundation; version 3 of the License.
[30]13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 *
23 * $Id: smb_deps.c 157 2009-11-23 00:47:22Z tim $
24 */
25
[147]26#include "smb_deps.h"
[30]27
28
29/* From lib/time.c */
30
31/****************************************************************************
32 Put a 8 byte filetime from a time_t
33 This takes real GMT as input and converts to kludge-GMT
34****************************************************************************/
35void unix_to_nt_time(NTTIME *nt, time_t t)
36{
[59]37  double d;
38 
39  if (t==0) 
40  {
41    nt->low = 0;
42    nt->high = 0;
43    return;
44  }
45 
46  if (t == TIME_T_MAX) 
47  {
48    nt->low = 0xffffffff;
49    nt->high = 0x7fffffff;
50    return;
51  }             
52 
53  if (t == -1) 
54  {
55    nt->low = 0xffffffff;
56    nt->high = 0xffffffff;
57    return;
58  }             
59 
60  /* this converts GMT to kludge-GMT */
61  /* XXX: This was removed due to difficult dependency requirements. 
62   *      So far, times appear to be correct without this adjustment, but
63   *      that may be proven wrong with adequate testing.
64   */
65  /* t -= TimeDiff(t) - get_serverzone(); */
66 
67  d = (double)(t);
68  d += TIME_FIXUP_CONSTANT;
69  d *= 1.0e7;
70 
71  nt->high = (uint32)(d * (1.0/(4.0*(double)(1<<30))));
72  nt->low  = (uint32)(d - ((double)nt->high)*4.0*(double)(1<<30));
[30]73}
74
[42]75
76/****************************************************************************
77 Interpret an 8 byte "filetime" structure to a time_t
78 It's originally in "100ns units since jan 1st 1601"
79
80 An 8 byte value of 0xffffffffffffffff will be returned as (time_t)0.
81
82 It appears to be kludge-GMT (at least for file listings). This means
83 its the GMT you get by taking a localtime and adding the
84 serverzone. This is NOT the same as GMT in some cases. This routine
85 converts this to real GMT.
86****************************************************************************/
[84]87time_t nt_time_to_unix(const NTTIME* nt)
[42]88{
[59]89  double d;
90  time_t ret;
91  /* The next two lines are a fix needed for the
92     broken SCO compiler. JRA. */
93  time_t l_time_min = TIME_T_MIN;
94  time_t l_time_max = TIME_T_MAX;
95 
96  if (nt->high == 0 || (nt->high == 0xffffffff && nt->low == 0xffffffff))
97    return(0);
98 
99  d = ((double)nt->high)*4.0*(double)(1<<30);
100  d += (nt->low&0xFFF00000);
101  d *= 1.0e-7;
102 
103  /* now adjust by 369 years to make the secs since 1970 */
104  d -= TIME_FIXUP_CONSTANT;
105 
106  if (d <= l_time_min)
107    return (l_time_min);
108 
109  if (d >= l_time_max)
110    return (l_time_max);
111 
112  ret = (time_t)(d+0.5);
113 
114  /* this takes us from kludge-GMT to real GMT */
115  /* XXX: This was removed due to difficult dependency requirements. 
116   *      So far, times appear to be correct without this adjustment, but
117   *      that may be proven wrong with adequate testing.
118   */
119  /*
120    ret -= get_serverzone();
121    ret += LocTimeDiff(ret);
122  */
[42]123
[59]124  return(ret);
[42]125}
126
[30]127/* End of stuff from lib/time.c */
Note: See TracBrowser for help on using the repository browser.