Ignore:
Timestamp:
Sep 19, 2013, 6:20:36 PM (12 years ago)
Author:
Herwig Bauernfeind
Message:

Samba Client 2.1: Even more work on timestamps

Location:
branches/client-2.1/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/client-2.1/src/ndpsmb.c

    r812 r813  
    4242void fsphUnixTimeToDosDate( time_t time, FDATE* fdate, FTIME *ftime)
    4343{
    44     struct tm* gmt = localtime( &time);
     44        struct tm* gmt = localtime( &time);
    4545#if 0 // as localtime() already does dst we don't need to add something
    46     if (gmt->tm_isdst>0) {
     46        if (gmt->tm_isdst>0) {
    4747        debug_printf( "daylight saving in effect %d, timezone %d\n",gmt->tm_isdst, timezone);
    4848        time -= 3600;
    4949        gmt = localtime( &time);
    50     }
     50        }
    5151#endif
    52     fdate->day  = gmt->tm_mday;
    53     fdate->month  = gmt->tm_mon+1;
    54     fdate->year = gmt->tm_year + 1900 - 1980;
    55     ftime->twosecs = gmt->tm_sec/2;
    56     ftime->minutes = gmt->tm_min;
    57     ftime->hours = gmt->tm_hour;
     52        fdate->day  = gmt->tm_mday;
     53        fdate->month  = gmt->tm_mon+1;
     54        fdate->year = gmt->tm_year + 1900 - 1980;
     55        ftime->twosecs = gmt->tm_sec/2;
     56        ftime->minutes = gmt->tm_min;
     57        ftime->hours = gmt->tm_hour;
    5858}
    5959
    6060void fsphDosDateToUnixTime( FDATE fdate, FTIME ftime, ULONG* time)
    6161{
    62     struct tm gmtime = { 0 };
    63 
    64     debug_printf( "fsphDosDateToUnixTime time %02d:%02d\n", ftime.hours, ftime.minutes);
    65     gmtime.tm_mday = fdate.day;
    66     gmtime.tm_mon = fdate.month-1;
    67     gmtime.tm_year = fdate.year + 1980 - 1900;
    68     gmtime.tm_sec = ftime.twosecs*2;
    69     gmtime.tm_min = ftime.minutes;
    70     gmtime.tm_hour = ftime.hours;
    71     gmtime.tm_isdst = -1; // force libc to check dst saving
    72 
    73     *time = mktime( &gmtime);
    74     debug_printf( "fsphDosDateToUnixTime time1 %d %s", *time, ctime( (time_t*)time));
     62        struct tm gmtime = { 0 };
     63
     64        debug_printf( "fsphDosDateToUnixTime time %02d:%02d\n", ftime.hours, ftime.minutes);
     65        gmtime.tm_mday = fdate.day;
     66        gmtime.tm_mon = fdate.month-1;
     67        gmtime.tm_year = fdate.year + 1980 - 1900;
     68        gmtime.tm_sec = ftime.twosecs*2;
     69        gmtime.tm_min = ftime.minutes;
     70        gmtime.tm_hour = ftime.hours;
     71        gmtime.tm_isdst = -1; // force libc to check dst saving
     72
     73        *time = mktime( &gmtime);
     74        debug_printf( "fsphDosDateToUnixTime time1 %d %s", *time, ctime( (time_t*)time));
    7575#if 0 // as mktime() already does dst we don't need to add something
    76     struct tm* gmt;
    77     gmt = localtime( (time_t*) time);
    78     if (gmt->tm_isdst>0) {
     76        struct tm* gmt;
     77        gmt = localtime( (time_t*) time);
     78        if (gmt->tm_isdst>0) {
    7979        debug_printf( "fsphDosDateToUnixTime daylight saving in effect %d, timezone %d\n",gmt->tm_isdst, timezone);
    8080        *time += 3600;
    81     }
     81        }
    8282#endif
    83     debug_printf( "fsphDosDateToUnixTime time2 %d %s", *time, ctime( (time_t*)time));
     83        debug_printf( "fsphDosDateToUnixTime time2 %d %s", *time, ctime( (time_t*)time));
    8484}
    8585       
     
    104104        {ND_PROP_STRING, 0, "USER", "guest"},
    105105        {ND_PROP_STRING, 0, "PASSWORD", ""},
    106         {ND_PROP_STRING, 0, "SPASSWORD",  ""},
     106                {ND_PROP_STRING, 0, "SPASSWORD",  ""},
    107107        {ND_PROP_STRING, 0, "MASTER", "WORKGROUP"},
    108108        {ND_PROP_ULONG, 0, "MASTERTYPE", "1"},
    109         {ND_PROP_ULONG, 0, "CTO", "10"},
    110         {ND_PROP_ULONG, 0, "CLD", "32"},
     109                {ND_PROP_ULONG, 0, "CTO", "10"},
     110                {ND_PROP_ULONG, 0, "CLD", "32"},
    111111        {ND_PROP_ULONG, 0, "EASUPPORT", "1"},
    112112        {ND_PROP_STRING, 0, NULL, NULL}
     
    126126/* A mutex to serialize plugin calls because libsmb may not be thread safe. */
    127127static NDMUTEX mutex;
    128        
     128               
    129129static int lockInit (void)
    130130{
    131     return ph->fsphCreateMutex (&mutex);
    132 }
    133        
     131        return ph->fsphCreateMutex (&mutex);
     132}
     133               
    134134static void lockClose (void)
    135135{
    136     ph->fsphCloseMutex (mutex);
    137 }
    138        
     136        ph->fsphCloseMutex (mutex);
     137}
     138               
    139139static int lockRequest (void)
    140140{
    141     return ph->fsphRequestMutex (mutex, SEM_INDEFINITE_WAIT);
     141        return ph->fsphRequestMutex (mutex, SEM_INDEFINITE_WAIT);
    142142}
    143143
    144144static void lockRelease (void)
    145145{
    146     ph->fsphReleaseMutex (mutex);
     146        ph->fsphReleaseMutex (mutex);
    147147}
    148148
    149149#if LIBSMB_THREAD_SAFE==0
    150150
    151 #define ENTER() do {            \
    152     int rcLock = lockRequest(); \
    153     if (rcLock != NO_ERROR)    \
    154         return rcLock;          \
     151#define ENTER() do {                    \
     152        int rcLock = lockRequest(); \
     153        if (rcLock != NO_ERROR) \
     154                return rcLock;            \
    155155} while (0)
    156156
    157157#define LEAVE() do { \
    158     lockRelease();    \
     158        lockRelease();  \
    159159} while (0)
    160160
     
    181181                ifL = 1;
    182182        }
    183         lockInit();
    184         debugInit();
     183                lockInit();
     184                debugInit();
    185185        debuglocal(9,"Working with %s bit fileio NDFS\n", ifL ? "64" : "32");
    186186        return NO_ERROR;
     
    190190int APIENTRY NdpPluginFree (void)
    191191{
    192         debugDelete();
    193         lockClose();
     192                debugDelete();
     193                lockClose();
    194194        return NO_ERROR;
    195195}
     
    218218        stat->attrFile = (finfo->attr & 0x37);
    219219
    220         fsphUnixTimeToDosDate(finfo->mtime, &stat->fdateLastWrite, &stat->ftimeLastWrite);
    221         fsphUnixTimeToDosDate(finfo->ctime, &stat->fdateCreation, &stat->ftimeCreation);
    222         fsphUnixTimeToDosDate(finfo->atime, &stat->fdateLastAccess, &stat->ftimeLastAccess);
     220                fsphUnixTimeToDosDate(finfo->mtime, &stat->fdateLastWrite, &stat->ftimeLastWrite);
     221                fsphUnixTimeToDosDate(finfo->ctime, &stat->fdateCreation, &stat->ftimeCreation);
     222                fsphUnixTimeToDosDate(finfo->atime, &stat->fdateLastAccess, &stat->ftimeLastAccess);
    223223}
    224224
     
    248248        stat.attrFile = (finfo->attr & 0x37);
    249249
    250         fsphUnixTimeToDosDate(finfo->mtime, &stat.fdateLastWrite, &stat.ftimeLastWrite);
    251         fsphUnixTimeToDosDate(finfo->ctime, &stat.fdateCreation, &stat.ftimeCreation);
    252         fsphUnixTimeToDosDate(finfo->atime, &stat.fdateLastAccess, &stat.ftimeLastAccess);
     250                fsphUnixTimeToDosDate(finfo->mtime, &stat.fdateLastWrite, &stat.ftimeLastWrite);
     251                fsphUnixTimeToDosDate(finfo->ctime, &stat.fdateCreation, &stat.ftimeCreation);
     252                fsphUnixTimeToDosDate(finfo->atime, &stat.fdateLastAccess, &stat.ftimeLastAccess);
    253253        debug_printf( "fname %s\n", finfo->fname);
    254254        debug_printf( "mtime %d %s", finfo->mtime, ctime( (time_t*)&finfo->mtime));
     
    261261static unsigned char fromhex (char c)
    262262{
    263     if ('0' <= c && c <= '9')
    264     {
    265         return c - '0';
    266     }
    267    
    268     if ('A' <= c && c <= 'F')
    269     {
    270         return c - 'A' + 0xA;
    271     }
    272    
    273     if ('a' <= c && c <= 'f')
    274     {
    275         return c - 'a' + 0xA;
    276     }
    277    
    278     return 0;
     263        if ('0' <= c && c <= '9')
     264        {
     265                return c - '0';
     266        }
     267       
     268        if ('A' <= c && c <= 'F')
     269        {
     270                return c - 'A' + 0xA;
     271        }
     272       
     273        if ('a' <= c && c <= 'f')
     274        {
     275                return c - 'a' + 0xA;
     276        }
     277       
     278        return 0;
    279279}
    280280
    281281static char tohex (unsigned char b)
    282282{
    283     b &= 0xF;
    284    
    285     if (b <= 9)
    286     {
    287         return b + '0';
    288     }
    289    
    290     return 'A' + (b - 0xA);
     283        b &= 0xF;
     284       
     285        if (b <= 9)
     286        {
     287                return b + '0';
     288        }
     289       
     290        return 'A' + (b - 0xA);
    291291}
    292292
    293293static void decryptPassword (const char *pszCrypt, char *pszPlain)
    294294{
    295     /* A simple "decryption", character from the hex value. */
    296     const char *s = pszCrypt;
    297     char *d = pszPlain;
    298    
    299     while (*s)
    300     {
    301         *d++ = (char)((fromhex (*s++) << 4) + fromhex (*s++));
    302     }
    303    
    304     *d++ = 0;
     295        /* A simple "decryption", character from the hex value. */
     296        const char *s = pszCrypt;
     297        char *d = pszPlain;
     298       
     299        while (*s)
     300        {
     301                *d++ = (char)((fromhex (*s++) << 4) + fromhex (*s++));
     302        }
     303       
     304        *d++ = 0;
    305305}
    306306
    307307static void encryptPassword (const char *pszPlain, char *pszCrypt)
    308308{
    309     /* A simple "encryption" encode each character as hex value. */
    310     const char *s = pszPlain;
    311     char *d = pszCrypt;
    312    
    313     while (*s)
    314     {
    315         *d++ = tohex ((*s) >> 4);
    316         *d++ = tohex (*s);
    317         s++;
    318     }
    319    
    320     *d++ = 0;
     309        /* A simple "encryption" encode each character as hex value. */
     310        const char *s = pszPlain;
     311        char *d = pszCrypt;
     312       
     313        while (*s)
     314        {
     315                *d++ = tohex ((*s) >> 4);
     316                *d++ = tohex (*s);
     317                s++;
     318        }
     319       
     320        *d++ = 0;
    321321}
    322322
     
    338338        pRes->krb5support = 0;
    339339#endif
    340         pRes->pdc = NULL;
     340                pRes->pdc = NULL;
    341341
    342342        t = 0, q = NULL;
     
    380380
    381381        t = 0, q = NULL;
    382         rc = ph->fsphQueryStringProperty (properties, "SPASSWORD", &q, &t);
    383         if (   rc == NO_ERROR
    384             && *q != '\0'
    385             && defaultPassword)
    386         {
    387             char p[1024];
    388             p[0] = 0;
    389        
    390             decryptPassword (q, p);
    391        
    392             if (*p)
    393             {
     382                rc = ph->fsphQueryStringProperty (properties, "SPASSWORD", &q, &t);
     383                if (   rc == NO_ERROR
     384                        && *q != '\0'
     385                        && defaultPassword)
     386                {
     387                        char p[1024];
     388                        p[0] = 0;
     389               
     390                        decryptPassword (q, p);
     391               
     392                        if (*p)
     393                        {
    394394                strncpy(pRes->srv.password, p, sizeof(pRes->srv.password) - 1);
    395        
    396                 /* clear the plain password */
    397                 ph->fsphSetProperty (properties, "PASSWORD", "");
    398             }
    399         }
    400         else
    401         {
    402             char c[1024];
    403             encryptPassword (pRes->srv.password, c);
    404        
    405             ph->fsphSetProperty (properties, "SPASSWORD", c);
    406        
    407             // clear the plain password
    408             ph->fsphSetProperty (properties, "PASSWORD", "");
    409         }
     395               
     396                                /* clear the plain password */
     397                                ph->fsphSetProperty (properties, "PASSWORD", "");
     398                        }
     399                }
     400                else
     401                {
     402                        char c[1024];
     403                        encryptPassword (pRes->srv.password, c);
     404               
     405                        ph->fsphSetProperty (properties, "SPASSWORD", c);
     406               
     407                        // clear the plain password
     408                        ph->fsphSetProperty (properties, "PASSWORD", "");
     409                }
    410410
    411411        t = 0, q = NULL;
     
    473473
    474474        /*
    475         * Create a directory cache with expiration time and cache listings
    476         * the above values come from the gui. default: timeout 10; listings: 32
    477         */
     475                * Create a directory cache with expiration time and cache listings
     476                * the above values come from the gui. default: timeout 10; listings: 32
     477                */
    478478        dircache_create(&pRes->pdc, pRes->cachetimeout, pRes->cachedepth);
    479479
     
    580580                if (newlevel)
    581581                {
    582                         // reconnect to server here, first test new connection
     582                                // reconnect to server here, first test new connection
    583583                        cli_state* tmp_cli = NULL;
    584584                        rc = smbwrp_connect( &tmpRes, &tmp_cli);
     
    615615        rc = smbwrp_connect( pRes, &cli);
    616616/* changed to real error codes SCS
    617     if (rc)
    618         rc = (rc == 7 ? ERROR_BAD_DEV_TYPE : ERROR_ACCESS_DENIED); */
     617        if (rc)
     618                rc = (rc == 7 ? ERROR_BAD_DEV_TYPE : ERROR_ACCESS_DENIED); */
    619619        switch (rc) {
    620620        case 0:
     
    682682                // nd/ndpm do not use main thread
    683683                if (!rc && _gettid()!=1)
    684                     rc = checkMountResource( pRes);
     684                        rc = checkMountResource( pRes);
    685685                if (!rc)
    686686                {
     
    812812        if (rc)
    813813        {
    814             debuglocal(9,"NdpCreateConnection failed rc=%d\n", rc);     
    815             pfsa->cSectorUnit = 1;
    816             pfsa->cUnit = 123456;
    817             pfsa->cUnitAvail = 123456;
    818             pfsa->cbSector = 2048;
    819             rc = (rc == 7 ? ERROR_BAD_DEV_TYPE : ERROR_ACCESS_DENIED);
    820             LEAVE();
    821             return rc;
     814                debuglocal(9,"NdpCreateConnection failed rc=%d\n", rc);
     815                pfsa->cSectorUnit = 1;
     816                pfsa->cUnit = 123456;
     817                pfsa->cUnitAvail = 123456;
     818                pfsa->cbSector = 2048;
     819                rc = (rc == 7 ? ERROR_BAD_DEV_TYPE : ERROR_ACCESS_DENIED);
     820                LEAVE();
     821                return rc;
    822822        }
    823823
     
    923923 * NO_ERROR - path exists and the path information have been successfully retrieved.
    924924 * ERROR_FILE_NOT_FOUND - all but the last component of the path exist and the
    925  *    path without the last component is a directory. dir1_ok\dir2_ok\does_not_exist.
    926  *    the wildcard can not exist, so the plugin returns FILE_NOT_FOUND, if the parent
    927  *    directory exist.
     925 *      path without the last component is a directory. dir1_ok\dir2_ok\does_not_exist.
     926 *      the wildcard can not exist, so the plugin returns FILE_NOT_FOUND, if the parent
     927 *      directory exist.
    928928 * ERROR_PATH_NOT_FOUND - any of not last path components does not exist, or all
    929  *    but the last component exist and is a file: \dir_ok\dir2_ok\file_ok\non_existing.
     929 *      but the last component exist and is a file: \dir_ok\dir2_ok\file_ok\non_existing.
    930930 * ERROR_REM_NOT_LIST - resource is temporarily unavailable for some reasons.
    931931 * Any other error codes means an internal plugin error, not related to the status
     
    997997                                if (rc == ERROR_REM_NOT_LIST)
    998998                                {
    999                                     // free current cli resources
    1000                                     smbwrp_disconnect( pRes, pConn->cli);
    1001                                     // reconnect
    1002                                     rcCon = smbwrp_connect( pRes, &pConn->cli);
    1003                                     if (rcCon != NO_ERROR)
    1004                                     debuglocal(9,"NdpQueryPathInfo smbwrp_connect rc = %d\n", rcCon);
    1005 
    1006                                     // try file list again if reconnecting worked
    1007                                     if (rcCon == NO_ERROR)
    1008                                     rc = smbwrp_getattr( &pRes->srv, pConn->cli, &finfo);
     999                                        // free current cli resources
     1000                                        smbwrp_disconnect( pRes, pConn->cli);
     1001                                        // reconnect
     1002                                        rcCon = smbwrp_connect( pRes, &pConn->cli);
     1003                                        if (rcCon != NO_ERROR)
     1004                                        debuglocal(9,"NdpQueryPathInfo smbwrp_connect rc = %d\n", rcCon);
     1005
     1006                                        // try file list again if reconnecting worked
     1007                                        if (rcCon == NO_ERROR)
     1008                                        rc = smbwrp_getattr( &pRes->srv, pConn->cli, &finfo);
    10091009                                }
    10101010                                debuglocal(9,"NdpQueryPathInfo smbwrp_getattr, rc = %d\n", rc);
     
    10371037                                        *p = 0;
    10381038                                        rc = smbwrp_getattr( &pRes->srv, pConn->cli, &finfo);
    1039                                         debuglocal(9,"NdpQueryPathInfo upper path in <%s>, rc = %d\n",  finfo.fname, rc);
     1039                                                                                debuglocal(9,"NdpQueryPathInfo upper path in <%s>, rc = %d\n",  finfo.fname, rc);
    10401040                                        if (rc == NO_ERROR)
    10411041                                        {       
    1042                                             rc = (finfo.attr & FILE_DIRECTORY) !=0 ?
    1043                                                 ERROR_FILE_NOT_FOUND:
    1044                                                 ERROR_PATH_NOT_FOUND;
     1042                                                rc = (finfo.attr & FILE_DIRECTORY) !=0 ?
     1043                                                                                                ERROR_FILE_NOT_FOUND:
     1044                                                                                                ERROR_PATH_NOT_FOUND;
    10451045                                        }
    1046                                         else if (rc != ERROR_REM_NOT_LIST)
    1047                                         {
    1048                                               rc = ERROR_PATH_NOT_FOUND;
     1046                                                                                else if (rc != ERROR_REM_NOT_LIST)
     1047                                                                                {
     1048                                                                                          rc = ERROR_PATH_NOT_FOUND;
    10491049                                        }
    10501050                                }
     
    11331133                }
    11341134                debuglocal(9,"NdpFindStart: dir [%s], dir_mask [%s], mask [%s], szPath [%s]\n",
    1135                            state.dir, state.dir_mask, state.mask, state.fullpath);
     1135                                                   state.dir, state.dir_mask, state.mask, state.fullpath);
    11361136                rc = smbwrp_filelist( &pRes->srv, pConn->cli, &state);
    11371137                // we need to handle reconnection also here, because NdpQueryPathInfo
     
    11391139                if (rc == ERROR_REM_NOT_LIST)
    11401140                {
    1141                     // free current cli resources
    1142                     smbwrp_disconnect( pRes, pConn->cli);
    1143                     // reconnect
    1144                     smbwrp_connect( pRes, &pConn->cli);
    1145                     // try file list again next loop
    1146                     rc = smbwrp_filelist( &pRes->srv, pConn->cli, &state);
    1147                     debuglocal(9,"NdpFindStart remote connection lost, rc = %d\n", rc);
     1141                        // free current cli resources
     1142                        smbwrp_disconnect( pRes, pConn->cli);
     1143                        // reconnect
     1144                        smbwrp_connect( pRes, &pConn->cli);
     1145                        // try file list again next loop
     1146                        rc = smbwrp_filelist( &pRes->srv, pConn->cli, &state);
     1147                        debuglocal(9,"NdpFindStart remote connection lost, rc = %d\n", rc);
    11481148                }
    11491149
     
    11671167int APIENTRY NdpDiscardResourceData (HRESOURCE resource, NDDATABUF *pdatabuf)
    11681168{
    1169     // The plugin do not have to deallocate anything
    1170     // because resource data did not contain any pointers
    1171     // to plugins data.
    1172     // Data stored by fsphSetResourceData will be
    1173     // deallocated by NetDrive.
     1169        // The plugin do not have to deallocate anything
     1170        // because resource data did not contain any pointers
     1171        // to plugins data.
     1172        // Data stored by fsphSetResourceData will be
     1173        // deallocated by NetDrive.
    11741174
    11751175        debuglocal(9,"NdpDicardresourceData %d\n", 0);
     
    11901190        debug_printf("NdpSetPathInfo in [%p]\n", pConn);
    11911191
    1192         // delete the dir cache
     1192                // delete the dir cache
    11931193        dircache_invalidate(szPathName, pRes->pdc, 1);
    11941194
     
    13061306        debuglocal(9,"NdpEAQuery in [%p] <%s> %08x %d\n", pConn, path, pGEAList, pGEAList ? pGEAList->cbList : 0);
    13071307
    1308         char *pchBuffer = (char *)malloc(cbBuffer);
    1309         if (!pchBuffer)
    1310         {
    1311                 LEAVE();
    1312                 return ERROR_NOT_ENOUGH_MEMORY;
    1313         }
     1308                char *pchBuffer = (char *)malloc(cbBuffer);
     1309                if (!pchBuffer)
     1310                {
     1311                                LEAVE();
     1312                                return ERROR_NOT_ENOUGH_MEMORY;
     1313                }
    13141314
    13151315        do {
     
    13421342                }
    13431343        } while (0);
    1344         free(pchBuffer);
     1344                free(pchBuffer);
    13451345        debuglocal(9,"NdpEAQuery <%s> %d %d %d\n", pfi->pszName, rc, pFEASrc->cbList, pFEAList->cbList);
    13461346        LEAVE();
     
    14231423                return ERROR_EAS_NOT_SUPPORTED;
    14241424        }
    1425        
    1426         debuglocal(9, "remove me NdpEASize before fsphGetFileInfoData\n");
     1425               
     1426                debuglocal(9, "remove me NdpEASize before fsphGetFileInfoData\n");
    14271427        rc = ph->fsphGetFileInfoData(pfi, &fdata, 0);
    14281428        if (rc || !fdata.ulSize || !fdata.pData)
     
    14341434        ENTER();
    14351435
    1436         debuglocal(9, "remove me NdpEASize before finfo =\n");
     1436                debuglocal(9, "remove me NdpEASize before finfo =\n");
    14371437        finfo = (smbwrp_fileinfo *)fdata.pData;
    1438         debuglocal(9, "remove me NdpEASize after finfo=\n");
     1438                debuglocal(9, "remove me NdpEASize after finfo=\n");
    14391439        easize = finfo->easize;
    14401440        finfo->easize = -1;
     
    14501450        debuglocal(9,"NdpEASize in [%p] <%s> \n", pConn, path);
    14511451
    1452         char *pchBuffer = (char *)malloc(cbBuffer);
    1453         if (!pchBuffer)
    1454         {
    1455                 LEAVE();
    1456                 return ERROR_NOT_ENOUGH_MEMORY;
    1457         }
     1452                char *pchBuffer = (char *)malloc(cbBuffer);
     1453                if (!pchBuffer)
     1454                {
     1455                                LEAVE();
     1456                                return ERROR_NOT_ENOUGH_MEMORY;
     1457                }
    14581458
    14591459        do {
     
    14821482                *pulEASize = pfealist->cbList;
    14831483        } while (0);
    1484         free(pchBuffer);
     1484                free(pchBuffer);
    14851485        debuglocal(9,"NdpEASize <%s> %d %d\n", pfi->pszName, *pulEASize, rc);
    14861486        LEAVE();
     
    17921792int APIENTRY NdpIOCTL (int type, HRESOURCE resource, char *path, int function, void *in, ULONG insize, PULONG poutlen)
    17931793{
    1794     if (function == ND_PL_INIT_THREAD)
    1795        {
    1796           smbwrp_initthread();
    1797           debuglocal(9, "NdpIOCTL init thread\n");
    1798           return NO_ERROR;
    1799        }
    1800 
    1801     debuglocal(9,"NdpIOCTL <%s> %d\n", path, function);
    1802 
    1803     if (in && insize > 4096)
    1804     {
     1794        if (function == ND_PL_INIT_THREAD)
     1795           {
     1796                  smbwrp_initthread();
     1797                  debuglocal(9, "NdpIOCTL init thread\n");
     1798                  return NO_ERROR;
     1799           }
     1800
     1801        debuglocal(9,"NdpIOCTL <%s> %d\n", path, function);
     1802
     1803        if (in && insize > 4096)
     1804        {
    18051805        char out[4096];
    18061806        sprintf (out, "SAMBA IOCTL function = %d, parms [%s] insize = %d, *poutlen = %d", function, in, insize, *poutlen);
     
    18081808        strcpy (in, out);
    18091809        return NO_ERROR;
    1810     }
    1811 
    1812     return ERROR_NOT_SUPPORTED;
     1810        }
     1811
     1812        return ERROR_NOT_SUPPORTED;
    18131813}
    18141814
     
    18631863        debuglocal(9,"NdpFileEAQuery in [%p] <%s>/%d pGEAList=%08x\n", pConn, pConn->file.fname, pConn->file.fd, pGEAList);
    18641864
    1865         char *pchBuffer = (char *)malloc(cbBuffer);
    1866         if (!pchBuffer)
    1867                 return ERROR_NOT_ENOUGH_MEMORY;
     1865                char *pchBuffer = (char *)malloc(cbBuffer);
     1866                if (!pchBuffer)
     1867                                return ERROR_NOT_ENOUGH_MEMORY;
    18681868
    18691869        ENTER();
     
    19031903                }
    19041904        } while (0);
    1905         free(pchBuffer);
     1905                free(pchBuffer);
    19061906        debuglocal(9,"NdpFileEAQuery out <%s>/%d pFEASrc->cbList=%d pFEAList->cbList=%d rc=%d\n", pConn->file.fname, pConn->file.fd, pFEASrc->cbList, pFEAList->cbList, rc);
    19071907        LEAVE();
     
    19781978        debuglocal(9,"NdpFileEASize in [%p] <%s>/%d \n", pConn, pConn->file.fname, pConn->file.fd);
    19791979
    1980         char *pchBuffer = (char *)malloc(cbBuffer);
    1981         if (!pchBuffer)
    1982                 return ERROR_NOT_ENOUGH_MEMORY;
     1980                char *pchBuffer = (char *)malloc(cbBuffer);
     1981                if (!pchBuffer)
     1982                                return ERROR_NOT_ENOUGH_MEMORY;
    19831983
    19841984        ENTER();
     
    20142014                *pulEASize = pFEAList->cbList;
    20152015        } while (0);
    2016         free(pchBuffer);
     2016                free(pchBuffer);
    20172017        debuglocal(9,"NdpFileEASize %d %d\n", *pulEASize, rc);
    20182018        LEAVE();
     
    20312031        debug_printf("NdpFileSetInfo in [%p]\n", pConn);
    20322032
    2033         // delete the dir cache
     2033                // delete the dir cache
    20342034        dircache_invalidate(pConn->file.fullname, pRes->pdc, 1);
    20352035
     
    20442044                pConn->file.openattr = attrFile;
    20452045                fsphDosDateToUnixTime(pfi->stat.fdateLastWrite, pfi->stat.ftimeLastWrite, &(pConn->file.mtime));
    2046                 pConn->file.newmtime = 0;
     2046                fsphDosDateToUnixTime(pfi->stat.fdateCreation, pfi->stat.ftimeCreation, &(pConn->file.ctime));
     2047                pConn->file.updatetime = 2;
    20472048                debug_printf("NdpFileSetInfo mtime %d\n", pConn->file.mtime);
    20482049        } while (0);
     
    21812182                while (ulReadCompleted < ulRead)
    21822183                {
    2183                         ULONG ulActual;
     2184                                ULONG ulActual;
    21842185                        ULONG ulToRead = ulRead - ulReadCompleted;
    21852186                        debuglocal(9,"NdpFileRead completed %d, to read %d\n", ulReadCompleted, ulToRead);
     
    22282229        debuglocal(9,"NdpFileWrite in [%p]\n", pConn);
    22292230
    2230         /* delete the dir cache
    2231         this was moved from NdpFileClose() becasue if there are a lot files in the tree all are reread
    2232         the problem when moved to here is, that last accessed time is not refreshed
    2233         if this is needed, a new function needs to be done to update only one file in the cache */
     2231                /* delete the dir cache
     2232                this was moved from NdpFileClose() becasue if there are a lot files in the tree all are reread
     2233                the problem when moved to here is, that last accessed time is not refreshed
     2234                if this is needed, a new function needs to be done to update only one file in the cache */
    22342235        dircache_invalidate(pConn->file.fullname, pRes->pdc, 1);
    22352236
  • branches/client-2.1/src/smbwrp.c

    r807 r813  
    620620                return os2cli_errno(cli);
    621621        }
    622         file->newmtime = 0;
     622        file->updatetime = 0;
    623623        file->offset = 0;
    624624        return 0;
     
    671671        }
    672672
    673         file->newmtime = 1;
     673        file->updatetime = 1;
    674674        file->offset += ret;
    675675        *result = ret;
     
    693693                return os2cli_errno(cli);
    694694        }
    695         if (file->newmtime)
    696         {
    697                 file->newmtime = 0;
     695        if (file->updatetime == 1)
     696        {
    698697                file->mtime = time(NULL);
     698                if (file->updatetime == 2 && !cli_setattrE(cli, file->fd, file->ctime, 0, file->mtime))
     699                {
     700                        file->updatetime = 0;           
     701                        debuglocal(4,"Set attrE on close failed %d\n", os2cli_errno(cli));
     702                }
    699703                debuglocal(4,"cli_close new mtime %lu\n", file->mtime);
    700704        }
     705               
    701706        file->fd = -1;
    702707        file->offset = 0;
  • branches/client-2.1/src/smbwrp.h

    r806 r813  
    9191        int denymode;
    9292        unsigned long mtime;
    93         int newmtime;
     93        unsigned long ctime;
     94        int updatetime;
     95        // 0 = time is not updated upon file close
     96        // 1 = modified time is updated to current time
     97        // 2 = create and modified time are updated according local file
    9498        char fullname[261];
    9599        char fname[261];
Note: See TracChangeset for help on using the changeset viewer.