Changeset 126


Ignore:
Timestamp:
Apr 7, 2008, 9:33:39 AM (17 years ago)
Author:
Yuri Dario
Message:

Fixes timezone handling for os2->xp->os2, os2->samba->os2. Partially fixes ticket:56.

Location:
branches/samba-3.0/source/ndpsmb
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/samba-3.0/source/ndpsmb/ndpsmb.c

    r123 r126  
    1212#define NULL ((void *)0)
    1313
     14#ifndef DEBUG_PRINTF
     15#define debug_printf( ...)
     16#endif
     17
    1418void log(const char *fmt, ...)
    1519
     
    3943}
    4044
     45// -------------------------------------------------------------
     46
     47/* time conversion functions: SMB protocol sends timestamps in GMT time,
     48*  os2 api uses localtime,
     49*  emx/klibc uses timezone and daylight saving to convert GMT timestamps,
     50*  so only the timezone must be counted in conversion.
     51*/
     52void fsphUnixTimeToDosDate( time_t time, FDATE* fdate, FTIME *ftime)
     53{
     54    struct tm* gmt = localtime( &time);
     55    if (gmt->tm_isdst>0) {
     56        debug_printf( "daylight saving in effect %d, timezone %d\n",gmt->tm_isdst, timezone);
     57        time -= 3600;
     58        gmt = localtime( &time);
     59    }
     60    fdate->day  = gmt->tm_mday;
     61    fdate->month  = gmt->tm_mon+1;
     62    fdate->year = gmt->tm_year + 1900 - 1980;
     63    ftime->twosecs = gmt->tm_sec/2;
     64    ftime->minutes = gmt->tm_min;
     65    ftime->hours = gmt->tm_hour;
     66}
     67
     68void fsphDosDateToUnixTime( FDATE fdate, FTIME ftime, unsigned long* time)
     69{
     70    struct tm gmtime = { 0 };
     71    struct tm* gmt;
     72
     73    debug_printf( "fsphDosDateToUnixTime time %02d:%02d\n", ftime.hours, ftime.minutes);
     74    gmtime.tm_mday = fdate.day;
     75    gmtime.tm_mon = fdate.month-1;
     76    gmtime.tm_year = fdate.year + 1980 - 1900;
     77    gmtime.tm_sec = ftime.twosecs*2;
     78    gmtime.tm_min = ftime.minutes;
     79    gmtime.tm_hour = ftime.hours;
     80    gmtime.tm_isdst = -1; // force libc to check dst saving
     81
     82    *time = mktime( &gmtime);
     83    debug_printf( "fsphDosDateToUnixTime time1 %d %s", *time, ctime( time));
     84    gmt = localtime( (time_t*) time);
     85    if (gmt->tm_isdst>0) {
     86        debug_printf( "fsphDosDateToUnixTime daylight saving in effect %d, timezone %d\n",gmt->tm_isdst, timezone);
     87        *time += 3600;
     88    }
     89    debug_printf( "fsphDosDateToUnixTime time2 %d %s", *time, ctime( time));
     90}
     91
     92// -------------------------------------------------------------
     93       
    4194int StrLen(char * s)
    4295{
     
    339392        stat->attrFile = (finfo->attr & 0x37);
    340393
    341         ph->fsphUnixTimeToDosDate(finfo->mtime, &stat->fdateLastWrite, &stat->ftimeLastWrite);
    342         ph->fsphUnixTimeToDosDate(finfo->ctime, &stat->fdateCreation, &stat->ftimeCreation);
    343         ph->fsphUnixTimeToDosDate(finfo->atime, &stat->fdateLastAccess, &stat->ftimeLastAccess);
     394        fsphUnixTimeToDosDate(finfo->mtime, &stat->fdateLastWrite, &stat->ftimeLastWrite);
     395        fsphUnixTimeToDosDate(finfo->ctime, &stat->fdateCreation, &stat->ftimeCreation);
     396        fsphUnixTimeToDosDate(finfo->atime, &stat->fdateLastAccess, &stat->ftimeLastAccess);
    344397}
    345398
     
    369422        stat.attrFile = (finfo->attr & 0x37);
    370423
    371         ph->fsphUnixTimeToDosDate(finfo->mtime, &stat.fdateLastWrite, &stat.ftimeLastWrite);
    372         ph->fsphUnixTimeToDosDate(finfo->ctime, &stat.fdateCreation, &stat.ftimeCreation);
    373         ph->fsphUnixTimeToDosDate(finfo->atime, &stat.fdateLastAccess, &stat.ftimeLastAccess);
     424        fsphUnixTimeToDosDate(finfo->mtime, &stat.fdateLastWrite, &stat.ftimeLastWrite);
     425        fsphUnixTimeToDosDate(finfo->ctime, &stat.fdateCreation, &stat.ftimeCreation);
     426        fsphUnixTimeToDosDate(finfo->atime, &stat.fdateLastAccess, &stat.ftimeLastAccess);
     427        debug_printf( "fname %s\n", finfo->fname);
     428        debug_printf( "mtime %d %s", finfo->mtime, ctime( &finfo->mtime));
     429        debug_printf( "ftimeLastAccess %02d:%02d:%02d\n", stat.ftimeLastWrite.hours, stat.ftimeLastWrite.minutes, stat.ftimeLastWrite.twosecs*2);
    374430
    375431        ph->fsphAddFile32L(plist, &stat, name, StrLen(name), finfo, sizeof(*finfo), 0);
     
    11791235        NDPATHELEMENT *pel = ph->fsphNameElem(0);
    11801236
    1181         log("NdpFindStart in\n");
     1237        debug_printf("NdpFindStart in\n");
    11821238        do
    11831239        {
     
    12821338        do
    12831339          {
    1284                 log("NdpQueryInfo in <%s>, retry = %d\n", szPath, retry);
     1340                debug_printf("NdpQueryInfo in <%s>, retry = %d\n", szPath, retry);
    12851341
    12861342                do {
     
    14141470        char path[CCHMAXPATH+1] = {0};
    14151471
    1416         log("NdpSetPathInfo in\n");
     1472        debug_printf("NdpSetPathInfo in\n");
    14171473        do {
    14181474                rc = checkconnection(pConn);
     
    14311487
    14321488                StrNCpy(finfo->fname, path, sizeof(finfo->fname) - 1);
    1433                 ph->fsphDosDateToUnixTime(pfi->stat.fdateLastWrite, pfi->stat.ftimeLastWrite, (unsigned long *)&(finfo->mtime));
     1489                fsphDosDateToUnixTime(pfi->stat.fdateLastWrite, pfi->stat.ftimeLastWrite, &(finfo->mtime));
    14341490                if (ifL)
    14351491                {
     
    21402196        smbwrp_fileinfo * finfo = (smbwrp_fileinfo *)(pConn->mem + sizeof(pConn->file));
    21412197
    2142         log("NdpFileQueryInfo in\n");
     2198        debug_printf("NdpFileQueryInfo in\n");
    21432199        do {
    21442200                if (pConn->file.fd < 0 || !*pConn->file.fname)
     
    23812437        smbwrp_fileinfo * finfo = (smbwrp_fileinfo *)pConn->mem;
    23822438
    2383         log("NdpFileSetInfo in\n");
     2439        debug_printf("NdpFileSetInfo in\n");
    23842440        do {
    23852441                if (pConn->file.fd < 0 || !*pConn->file.fname)
     
    24042460                // deferred setinfo - on closing the file
    24052461                pConn->file.openattr = attrFile;
    2406                 ph->fsphDosDateToUnixTime(pfi->stat.fdateLastWrite, pfi->stat.ftimeLastWrite, (unsigned long *)&(pConn->file.mtime));
     2462                fsphDosDateToUnixTime(pfi->stat.fdateLastWrite, pfi->stat.ftimeLastWrite, &(pConn->file.mtime));
     2463                debug_printf("NdpFileSetInfo mtime %d\n", pConn->file.mtime);
    24072464        } while (0);
    24082465        log("NdpFileSetInfo <%s> %08x %d %d\n", pConn->file.fd < 0 ? "!null!" : pConn->file.fname, attrFile, rc, pConn->rc);
  • branches/samba-3.0/source/ndpsmb/smbwrp.c

    r124 r126  
    22
    33#include "smbwrp.h"
     4
     5#ifndef DEBUG_PRINTF
     6#define debug_printf( ...)
     7#endif
    48
    59static int
     
    273277
    274278        if (c_time) {
    275                 *c_time = convert_timespec_to_time_t(interpret_long_date(rdata+0)) - cli->serverzone;
     279                *c_time = convert_timespec_to_time_t(interpret_long_date(rdata+0));
    276280        }
    277281        if (a_time) {
    278                 *a_time = convert_timespec_to_time_t(interpret_long_date(rdata+8)) - cli->serverzone;
     282                *a_time = convert_timespec_to_time_t(interpret_long_date(rdata+8));
    279283        }
    280284        if (m_time) {
    281                 *m_time = convert_timespec_to_time_t(interpret_long_date(rdata+16)) - cli->serverzone;
     285                *m_time = convert_timespec_to_time_t(interpret_long_date(rdata+16));
    282286        }
    283287        if (w_time) {
    284                 *w_time = convert_timespec_to_time_t(interpret_long_date(rdata+24)) - cli->serverzone;
     288                *w_time = convert_timespec_to_time_t(interpret_long_date(rdata+24));
    285289        }
    286290        if (mode) {
     
    344348
    345349        if (c_time) {
    346                 *c_time = convert_timespec_to_time_t(interpret_long_date(rdata+0)) - cli->serverzone;
     350                *c_time = convert_timespec_to_time_t(interpret_long_date(rdata+0));
    347351        }
    348352        if (a_time) {
    349                 *a_time = convert_timespec_to_time_t(interpret_long_date(rdata+8)) - cli->serverzone;
     353                *a_time = convert_timespec_to_time_t(interpret_long_date(rdata+8));
    350354        }
    351355        if (m_time) {
    352                 *m_time = convert_timespec_to_time_t(interpret_long_date(rdata+16)) - cli->serverzone;
     356                *m_time = convert_timespec_to_time_t(interpret_long_date(rdata+16));
    353357        }
    354358        if (w_time) {
    355                 *w_time = convert_timespec_to_time_t(interpret_long_date(rdata+24)) - cli->serverzone;
     359                *w_time = convert_timespec_to_time_t(interpret_long_date(rdata+24));
    356360        }
    357361        if (mode) {
     
    609613        if (file->openattr || file->mtime)
    610614        {
    611                 debuglocal(4,"Set attr on close %s %08x %d %d\n", file->fname, file->openattr, file->mtime, file->mtime + get_time_zone(file->mtime));
    612                 if (!cli_setatr(cli, file->fname, file->openattr, file->mtime + get_time_zone(file->mtime)))
     615                debuglocal(4,"Set attr on close %s %08x %d %d\n", file->fname, file->openattr, file->mtime, file->mtime);
     616                if (!cli_setatr(cli, file->fname, file->openattr, file->mtime))
    613617                {
    614618                        debuglocal(4,"Set attr on close failed %d\n", os2cli_errno(cli));
     
    819823                return EINVAL;
    820824        }
     825        debug_printf( "smbwrp_getattr\n");
    821826        debuglocal(4,"getattr %d %d <%s>\n", cli->capabilities & CAP_NOPATHINFO2, cli->capabilities & CAP_NT_SMBS, finfo->fname);
    822827        if (!(cli->capabilities & CAP_NOPATHINFO2) &&
     
    868873        }
    869874
    870         if (cli_getatr(cli, finfo->fname, (unsigned short *)&finfo->attr, (size_t *)&finfo->size, (time_t *)&finfo->mtime))
     875        if (cli_getatr(cli, finfo->fname, (unsigned short *)&finfo->attr, &finfo->size, (time_t *)&finfo->mtime))
    871876        {
    872877//debuglocal(2,("gotattr1 %08x <%s>\n", finfo->attr, finfo->fname));
     
    10361041        finfo->ctime = def_finfo.ctime_ts.tv_sec;
    10371042        strncpy(finfo->fname, def_finfo.name, sizeof(finfo->fname) - 1);
    1038 
     1043        debug_printf( "fname %s (serverzone %d, level %d)\n",finfo->fname, cli->serverzone, level);
     1044       
    10391045        switch (level) {
    10401046                case 1: /* OS/2 understands this */
     
    10901096                        /* Offset zero is "create time", not "change time". */
    10911097                        p += 8;
    1092                         finfo->atime = interpret_long_date(p).tv_sec - cli->serverzone;
     1098                        finfo->atime = interpret_long_date(p).tv_sec;
    10931099                        p += 8;
    1094                         finfo->mtime = interpret_long_date(p).tv_sec - cli->serverzone;
     1100                        finfo->mtime = interpret_long_date(p).tv_sec;
    10951101                        p += 8;
    1096                         finfo->ctime = interpret_long_date(p).tv_sec - cli->serverzone;
     1102                        finfo->ctime = interpret_long_date(p).tv_sec;
    10971103                        p += 8;
    10981104                        finfo->size = IVAL2_TO_SMB_BIG_UINT(p,0);
     
    14041410        }
    14051411        debuglocal(1,"Filelist <%s> on master <%s> wgrp <%s> server <%s> share <%s> clidev <%s>\n", state->mask, srv->master, srv->workgroup, srv->server_name, srv->share_name, cli->dev);
     1412        debug_printf( "Filelist <%s> on master <%s> wgrp <%s> server <%s> share <%s> clidev <%s>\n", state->mask, srv->master, srv->workgroup, srv->server_name, srv->share_name, cli->dev);
    14061413        if (*srv->workgroup == 0 && *srv->server_name == 0)
    14071414        {
Note: See TracChangeset for help on using the changeset viewer.