Ignore:
Timestamp:
Nov 24, 2016, 1:14:11 PM (9 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: update vendor to version 4.4.3

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vendor/current/source3/lib/time.c

    r740 r988  
    1 /* 
     1/*
    22   Unix SMB/CIFS implementation.
    33   time handling functions
    44
    55   Copyright (C) Andrew Tridgell                1992-2004
    6    Copyright (C) Stefan (metze) Metzmacher      2002   
     6   Copyright (C) Stefan (metze) Metzmacher      2002
    77   Copyright (C) Jeremy Allison                 2007
    88
     
    1111   the Free Software Foundation; either version 3 of the License, or
    1212   (at your option) any later version.
    13    
     13
    1414   This program is distributed in the hope that it will be useful,
    1515   but WITHOUT ANY WARRANTY; without even the implied warranty of
    1616   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1717   GNU General Public License for more details.
    18    
     18
    1919   You should have received a copy of the GNU General Public License
    2020   along with this program.  If not, see <http://www.gnu.org/licenses/>.
     
    8888/****************************************************************************
    8989 Convert ASN.1 GeneralizedTime string to unix-time.
    90  Returns 0 on failure; Currently ignores timezone. 
     90 Returns 0 on failure; Currently ignores timezone.
    9191****************************************************************************/
    9292
    9393time_t generalized_to_unix_time(const char *str)
    94 { 
     94{
    9595        struct tm tm;
    9696
    9797        ZERO_STRUCT(tm);
    9898
    99         if (sscanf(str, "%4d%2d%2d%2d%2d%2d", 
    100                    &tm.tm_year, &tm.tm_mon, &tm.tm_mday, 
     99        if (sscanf(str, "%4d%2d%2d%2d%2d%2d",
     100                   &tm.tm_year, &tm.tm_mon, &tm.tm_mday,
    101101                   &tm.tm_hour, &tm.tm_min, &tm.tm_sec) != 6) {
    102102                return 0;
     
    165165
    166166/****************************************************************************
    167  Take a Unix time and convert to an NTTIME structure and place in buffer 
     167 Take a Unix time and convert to an NTTIME structure and place in buffer
    168168 pointed to by p, rounded to the correct resolution.
    169169****************************************************************************/
     
    173173        NTTIME nt;
    174174        round_timespec(res, &ts);
    175         unix_timespec_to_nt_time(&nt, ts);
    176         SIVAL(p, 0, nt & 0xFFFFFFFF);
    177         SIVAL(p, 4, nt >> 32);
     175        nt = unix_timespec_to_nt_time(ts);
     176        SBVAL(p, 0, nt);
    178177}
    179178
     
    199198time_t make_unix_date(const void *date_ptr, int zone_offset)
    200199{
    201         uint32_t dos_date=0;
    202         struct tm t;
    203         time_t ret;
    204 
    205         dos_date = IVAL(date_ptr,0);
    206 
    207         if (dos_date == 0) {
    208                 return 0;
    209         }
    210  
    211         interpret_dos_date(dos_date,&t.tm_year,&t.tm_mon,
    212                         &t.tm_mday,&t.tm_hour,&t.tm_min,&t.tm_sec);
    213         t.tm_isdst = -1;
    214  
    215         ret = timegm(&t);
    216 
    217         ret += zone_offset;
    218 
    219         return(ret);
     200        return pull_dos_date(date_ptr, zone_offset);
    220201}
    221202
     
    226207time_t make_unix_date2(const void *date_ptr, int zone_offset)
    227208{
    228         uint32_t x,x2;
    229 
    230         x = IVAL(date_ptr,0);
    231         x2 = ((x&0xFFFF)<<16) | ((x&0xFFFF0000)>>16);
    232         SIVAL(&x,0,x2);
    233 
    234         return(make_unix_date((const void *)&x, zone_offset));
     209        return pull_dos_date2(date_ptr, zone_offset);
    235210}
    236211
     
    242217time_t make_unix_date3(const void *date_ptr, int zone_offset)
    243218{
    244         time_t t = (time_t)IVAL(date_ptr,0);
    245         if (!null_time(t)) {
    246                 t += zone_offset;
    247         }
    248         return(t);
     219        return pull_dos_date3(date_ptr, zone_offset);
    249220}
    250221
     
    262233{
    263234        return make_unix_date3(date_ptr, server_zone_offset);
    264 }
    265 
    266 /****************************************************************************
    267  Convert a normalized timeval to a timespec.
    268 ****************************************************************************/
    269 
    270 struct timespec convert_timeval_to_timespec(const struct timeval tv)
    271 {
    272         struct timespec ts;
    273         ts.tv_sec = tv.tv_sec;
    274         ts.tv_nsec = tv.tv_usec * 1000;
    275         return ts;
    276 }
    277 
    278 /****************************************************************************
    279  Convert a normalized timespec to a timeval.
    280 ****************************************************************************/
    281 
    282 struct timeval convert_timespec_to_timeval(const struct timespec ts)
    283 {
    284         struct timeval tv;
    285         tv.tv_sec = ts.tv_sec;
    286         tv.tv_usec = ts.tv_nsec / 1000;
    287         return tv;
    288 }
    289 
    290 /****************************************************************************
    291  Return a timespec for the current time
    292 ****************************************************************************/
    293 
    294 struct timespec timespec_current(void)
    295 {
    296         struct timespec ts;
    297         clock_gettime(CLOCK_REALTIME, &ts);
    298         return ts;
    299 }
    300 
    301 /****************************************************************************
    302  Return the lesser of two timespecs.
    303 ****************************************************************************/
    304 
    305 struct timespec timespec_min(const struct timespec *ts1,
    306                            const struct timespec *ts2)
    307 {
    308         if (ts1->tv_sec < ts2->tv_sec) return *ts1;
    309         if (ts1->tv_sec > ts2->tv_sec) return *ts2;
    310         if (ts1->tv_nsec < ts2->tv_nsec) return *ts1;
    311         return *ts2;
    312 }
    313 
    314 /****************************************************************************
    315   compare two timespec structures.
    316   Return -1 if ts1 < ts2
    317   Return 0 if ts1 == ts2
    318   Return 1 if ts1 > ts2
    319 ****************************************************************************/
    320 
    321 int timespec_compare(const struct timespec *ts1, const struct timespec *ts2)
    322 {
    323         if (ts1->tv_sec  > ts2->tv_sec)  return 1;
    324         if (ts1->tv_sec  < ts2->tv_sec)  return -1;
    325         if (ts1->tv_nsec > ts2->tv_nsec) return 1;
    326         if (ts1->tv_nsec < ts2->tv_nsec) return -1;
    327         return 0;
    328 }
    329 
    330 /****************************************************************************
    331  Round up a timespec if nsec > 500000000, round down if lower,
    332  then zero nsec.
    333 ****************************************************************************/
    334 
    335 void round_timespec_to_sec(struct timespec *ts)
    336 {
    337         ts->tv_sec = convert_timespec_to_time_t(*ts);
    338         ts->tv_nsec = 0;
    339 }
    340 
    341 /****************************************************************************
    342  Round a timespec to usec value.
    343 ****************************************************************************/
    344 
    345 void round_timespec_to_usec(struct timespec *ts)
    346 {
    347         struct timeval tv = convert_timespec_to_timeval(*ts);
    348         *ts = convert_timeval_to_timespec(tv);
    349         while (ts->tv_nsec > 1000000000) {
    350                 ts->tv_sec += 1;
    351                 ts->tv_nsec -= 1000000000;
    352         }
    353235}
    354236
     
    362244{
    363245        NTTIME nt;
    364         nt = IVAL(p,0) + ((uint64_t)IVAL(p,4) << 32);
     246        nt = BVAL(p, 0);
    365247        if (nt == (uint64_t)-1) {
    366248                struct timespec ret;
     
    369251                return ret;
    370252        }
    371         return nt_time_to_unix_timespec(&nt);
     253        return nt_time_to_unix_timespec(nt);
    372254}
    373255
     
    470352
    471353/****************************************************************************
    472  Put a 8 byte filetime from a struct timespec. Uses GMT.
    473 ****************************************************************************/
    474 
    475 void unix_timespec_to_nt_time(NTTIME *nt, struct timespec ts)
    476 {
    477         uint64_t d;
    478 
    479         if (ts.tv_sec ==0 && ts.tv_nsec == 0) {
    480                 *nt = 0;
    481                 return;
    482         }
    483         if (ts.tv_sec == TIME_T_MAX) {
    484                 *nt = 0x7fffffffffffffffLL;
    485                 return;
    486         }               
    487         if (ts.tv_sec == (time_t)-1) {
    488                 *nt = (uint64_t)-1;
    489                 return;
    490         }               
    491 
    492         d = ts.tv_sec;
    493         d += TIME_FIXUP_CONSTANT_INT;
    494         d *= 1000*1000*10;
    495         /* d is now in 100ns units. */
    496         d += (ts.tv_nsec / 100);
    497 
    498         *nt = d;
    499 }
    500 
    501 #if 0
    502 void nt_time_to_unix_timespec(struct timespec *ts, NTTIME t)
    503 {
    504         if (ts == NULL) {
    505                 return;
    506         }
    507 
    508         /* t starts in 100 nsec units since 1601-01-01. */
    509 
    510         t *= 100;
    511         /* t is now in nsec units since 1601-01-01. */
    512 
    513         t -= TIME_FIXUP_CONSTANT*1000*1000*100;
    514         /* t is now in nsec units since the UNIX epoch 1970-01-01. */
    515 
    516         ts->tv_sec  = t / 1000000000LL;
    517 
    518         if (TIME_T_MIN > ts->tv_sec || ts->tv_sec > TIME_T_MAX) {
    519                 ts->tv_sec  = 0;
    520                 ts->tv_nsec = 0;
    521                 return;
    522         }
    523 
    524         ts->tv_nsec = t - ts->tv_sec*1000000000LL;
    525 }
    526 #endif
    527 
    528 /****************************************************************************
    529354 Convert a time_t to a NTTIME structure
    530355
     
    547372                return;
    548373        }
    549                
     374
    550375        if (t == (time_t)-1) {
    551376                /* that's what NT uses for infinite */
    552377                *nt = NTTIME_INFINITY;
    553378                return;
    554         }               
     379        }
    555380
    556381        d = (double)(t);
     
    598423                return "Never";
    599424
    600         high = 65536;   
     425        high = 65536;
    601426        high = high/10000;
    602427        high = high*65536;
Note: See TracChangeset for help on using the changeset viewer.