Changeset 533 for trunk/client


Ignore:
Timestamp:
Jan 26, 2011, 3:31:18 PM (15 years ago)
Author:
Silvan Scherrer
Message:

Samba Client 2.1: degug changes, attemp to fix the trap

Location:
trunk/client/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/client/src/debug.c

    r508 r533  
    3232
    3333int debuglevel = 9; // we set it to 9, so we get all messages
    34 char logfile[_MAX_PATH +1]  = {0};
    35 char debugfile[_MAX_PATH +1] = {0};
     34char logfile[_MAX_PATH +1];
     35char debugfile[_MAX_PATH +1];
    3636char logfilename[] = "log.ndpsmb";
    37 BOOL do_logging = FALSE;
    38 BOOL firstLogLine = TRUE;
     37BOOL do_logging;
     38BOOL firstLogLine;
     39HMTX logMutex;
     40char nameMutex[] = "\\SEM32\\NDPSMB";
    3941
    4042int debuglvl(int level)
     
    4850}
    4951
     52void debugInit()
     53{
     54        *logfile = '\0';
     55        *debugfile = '\0';
     56        do_logging = FALSE;
     57        firstLogLine = TRUE;
     58        logMutex = NULLHANDLE;
     59        struct stat filestat;
     60        APIRET rc = NO_ERROR;
     61
     62        // create the debugfile name
     63        strncat(debugfile, getenv("ETC"), 2);
     64        strncat(debugfile, "\\", sizeof(debugfile) - strlen(debugfile) -1);
     65        strncat(debugfile, "ndpsmb.dbg", sizeof(debugfile) - strlen(debugfile) -1);
     66
     67        // is the file around? if not we have no debug
     68        if (stat(debugfile, &filestat) !=0)
     69           return;
     70
     71        //create the logfile variable
     72        char *env = getenv("LOGFILES");
     73        if (env != NULL)
     74        {
     75           strncat(logfile, env, sizeof(logfile) -1);
     76           strncat(logfile, "\\", sizeof(logfile) - strlen(logfile) -1);
     77           strncat(logfile, logfilename, sizeof(logfile) - strlen(logfile) -1); 
     78        }
     79        else
     80        {
     81           strncat(logfile, logfilename, sizeof(logfile) -1);
     82        }
     83        // set the samba logging stuff
     84        do_logging = TRUE;
     85
     86        // now we create a sem, so that logging from different threads works
     87        rc = DosCreateMutexSem(nameMutex, &logMutex, 0, FALSE);
     88        if (rc == ERROR_DUPLICATE_NAME)
     89        {
     90        rc = DosOpenMutexSem(nameMutex, &logMutex);
     91        }
     92
     93        return;
     94}
     95
     96void debugDelete()
     97{
     98        DosCloseMutexSem(logMutex);
     99        return;
     100}
     101
    50102void debuglocal(int level, const char * fmt, ...)
    51103{
    52104        FILE *f=NULL;
    53         struct stat filestat;
    54105
    55         // do we have to log at all (not needed atm)
    56 /*      if (!debuglvl(level))
     106        // do we have to log at all
     107        if (!do_logging)
    57108        {
    58109                return;
    59         }*/
     110        }
    60111
    61         // if the file ndpsmb.dbg is around we write a logfile
    62         if (!debugfile[0])
     112        // if the sem is created we request it
     113        if (logMutex)
    63114        {
    64            strncpy(debugfile, getenv("ETC"), 2);
    65            strncat(debugfile, "\\", sizeof(debugfile) - strlen(debugfile) -1);
    66            strncat(debugfile, "ndpsmb.dbg", sizeof(debugfile) - strlen(debugfile) -1);
    67         } /* endif */
    68        
    69         if (stat(debugfile, &filestat) !=0)
    70            return;
    71 
    72         //we create the logfile variable only once
    73         if (!logfile[0])
    74         {
    75                 char *env = getenv("LOGFILES");
    76                 if (env != NULL)
    77                 {
    78                    strncpy(logfile, env, sizeof(logfile) -1);
    79                    strncat(logfile, "\\", sizeof(logfile) - strlen(logfile) -1);
    80                    strncat(logfile, logfilename, sizeof(logfile) - strlen(logfile) -1); 
    81                 }
    82                 else
    83                 {
    84                    strncpy(logfile, logfilename, sizeof(logfile) -1);
    85                 }
    86                 // set the samba logging stuff
    87                 do_logging = TRUE;
    88         } /* endif */
     115           DosRequestMutexSem(logMutex, (ULONG) SEM_INDEFINITE_WAIT);
     116        }
    89117
    90118        do
     
    121149                if (logfile)
    122150                {
    123                         fclose(f);
     151//                      fflush(f);
     152                        fclose(f);
    124153                }
    125154        }
    126155        while (0);
     156
     157        // if the sem is created we release it
     158        if (logMutex)
     159        {
     160           DosReleaseMutexSem(logMutex);
     161        }
     162
     163        return;
    127164}
  • trunk/client/src/ndpsmb.c

    r531 r533  
    150150                ifL = 1;
    151151        }
     152        debugInit();
    152153        debuglocal(9,"Working with %s bit fileio NDFS\n", ifL ? "64" : "32");
    153154        return NO_ERROR;
     
    157158int APIENTRY NdpPluginFree (void)
    158159{
     160        debugDelete();
    159161        return NO_ERROR;
    160162}
     
    982984                                        {       
    983985                                            rc = (finfo.attr & FILE_DIRECTORY) !=0 ?
    984                                                 ERROR_PATH_NOT_FOUND :
    985                                                 ERROR_INVALID_PARAMETER;
     986                                                ERROR_FILE_NOT_FOUND:
     987                                                ERROR_PATH_NOT_FOUND;
    986988                                        }
    987989                                        else if (rc != ERROR_REM_NOT_LIST)
     
    12171219        NDDATABUF fdata = {0};
    12181220        smbwrp_fileinfo *finfo;
    1219         char    pBuffer[64*1024];
     1221        const int cbBuffer = 64*1024;
    12201222
    12211223        if (!pfi || !pfi->pszName || !pFEAList)
     
    12391241        debuglocal(9,"NdpEAQuery in [%p] <%s> %08x %d\n", pConn, path, pGEAList, pGEAList ? pGEAList->cbList : 0);
    12401242
     1243        char *pchBuffer = (char *)malloc(cbBuffer);
     1244        if (!pchBuffer)
     1245                return ERROR_NOT_ENOUGH_MEMORY;
     1246
    12411247        do {
    1242                 rc = smbwrp_listea( pConn->cli, path, pBuffer, sizeof( pBuffer));
    1243                 pFEASrc = (FEALIST*) pBuffer;
     1248                rc = smbwrp_listea( pConn->cli, path, pchBuffer, cbBuffer);
     1249                pFEASrc = (FEALIST*) pchBuffer;
    12441250                if (rc)
    12451251                {
     
    12681274                }
    12691275        } while (0);
     1276        free(pchBuffer);
    12701277        debuglocal(9,"NdpEAQuery <%s> %d %d %d\n", pfi->pszName, rc, pFEASrc->cbList, pFEAList->cbList);
    12711278
     
    13341341        NDDATABUF fdata = {0};
    13351342        smbwrp_fileinfo *finfo;
    1336         char    pBuffer[64*1024];
     1343        const int cbBuffer = 64*1024;
    13371344        int easize;
    13381345
     
    13521359                return ERROR_EAS_NOT_SUPPORTED;
    13531360        }
     1361
    13541362        finfo = (smbwrp_fileinfo *)fdata.pData;
    13551363        easize = finfo->easize;
     
    13651373        debuglocal(9,"NdpEASize in [%p] <%s> \n", pConn, path);
    13661374
     1375        char *pchBuffer = (char *)malloc(cbBuffer);
     1376        if (!pchBuffer)
     1377                return ERROR_NOT_ENOUGH_MEMORY;
     1378
    13671379        do {
    1368                 rc = smbwrp_listea(pConn->cli, path, pBuffer, sizeof( pBuffer));
    1369                 pfealist = (FEALIST*)pBuffer;
     1380                rc = smbwrp_listea(pConn->cli, path, pchBuffer, cbBuffer);
     1381                pfealist = (FEALIST*)pchBuffer;
    13701382                if (rc)
    13711383                {
     
    13901402                *pulEASize = pfealist->cbList;
    13911403        } while (0);
     1404        free(pchBuffer);
    13921405        debuglocal(9,"NdpEASize <%s> %d %d\n", pfi->pszName, *pulEASize, rc);
    13931406
     
    17401753        int rc = 0;
    17411754        unsigned long action;
    1742         char pBuffer[64*1024];
     1755        const int cbBuffer = 64*1024;
    17431756        FEALIST * pFEASrc;
    17441757
     
    17531766
    17541767        debuglocal(9,"NdpFileEAQuery in [%p] <%s>/%d pGEAList=%08x\n", pConn, pConn->file.fname, pConn->file.fd, pGEAList);
     1768
     1769        char *pchBuffer = (char *)malloc(cbBuffer);
     1770        if (!pchBuffer)
     1771                return ERROR_NOT_ENOUGH_MEMORY;
     1772
    17551773        do {
    17561774                if (pConn->file.fd < 0)
     
    17591777                        break;
    17601778                }
    1761                 rc = smbwrp_flistea(pConn->cli, &pConn->file, pBuffer, sizeof( pBuffer));
    1762                 pFEASrc = (FEALIST *) pBuffer;
     1779                rc = smbwrp_flistea(pConn->cli, &pConn->file, pchBuffer, cbBuffer);
     1780                pFEASrc = (FEALIST *)pchBuffer;
    17631781                if (rc)
    17641782                {
     
    17871805                }
    17881806        } while (0);
     1807        free(pchBuffer);
    17891808        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);
    17901809
     
    18461865        char path[CCHMAXPATH+1] = {0};
    18471866        FEALIST * pFEAList;
    1848         char pBuffer[64*1024];
     1867        const int cbBuffer = 64*1024;
    18491868
    18501869        if (!pulEASize)
     
    18581877
    18591878        debuglocal(9,"NdpFileEASize in [%p] <%s>/%d \n", pConn, pConn->file.fname, pConn->file.fd);
     1879
     1880        char *pchBuffer = (char *)malloc(cbBuffer);
     1881        if (!pchBuffer)
     1882                return ERROR_NOT_ENOUGH_MEMORY;
     1883
    18601884        do {
    18611885                if (pConn->file.fd < 0)
     
    18641888                        break;
    18651889                }
    1866                 rc = smbwrp_flistea(pConn->cli, &pConn->file, pBuffer, sizeof(pBuffer));
    1867                 pFEAList = (FEALIST*) pBuffer;
     1890                rc = smbwrp_flistea(pConn->cli, &pConn->file, pchBuffer, cbBuffer);
     1891                pFEAList = (FEALIST*)pchBuffer;
    18681892                if (rc)
    18691893                {
     
    18881912                *pulEASize = pFEAList->cbList;
    18891913        } while (0);
     1914        free(pchBuffer);
    18901915        debuglocal(9,"NdpFileEASize %d %d\n", *pulEASize, rc);
    18911916
  • trunk/client/src/smbwrp.c

    r528 r533  
    11131113        }
    11141114
    1115         ZERO_STRUCTP(finfo);
     1115/*      ZERO_STRUCTP(finfo); */
     1116        finfo->atime = 0;
     1117        finfo->ctime = 0;
     1118        finfo->mtime = 0;
     1119        *finfo->fname = '\0';
    11161120       
    11171121        switch (level) {
     
    11571161                        p += ret;
    11581162                        finfo->easize = -1;
    1159                         strncpy(finfo->fname, fname, sizeof(finfo->fname) -1);
     1163                        strncat(finfo->fname, fname, sizeof(finfo->fname) -1);
    11601164                        return PTR_DIFF(p, base);
    11611165
     
    11851189                        }
    11861190                        p += ret;
    1187                         strncpy(finfo->fname, fname, sizeof(finfo->fname) -1);
     1191                        strncat(finfo->fname, fname, sizeof(finfo->fname) -1);
    11881192                        return PTR_DIFF(p, base) + 1;
    11891193                       
     
    12461250                                return pdata_end - base;
    12471251                        }
    1248                         strncpy(finfo->fname, fname, sizeof(finfo->fname) -1);
     1252                        strncat(finfo->fname, fname, sizeof(finfo->fname) -1);
    12491253
    12501254                        /* To be robust in the face of unicode conversion failures
     
    14691473                                                        &resume_key, &last_name_raw);
    14701474
     1475                        debuglocal(9, "fname %s (remove me 1)\n", finfo.fname);
    14711476                        if (!finfo.fname) {
    14721477                                debuglocal(0,"Error: unable to parse name from info level %d\n",
     
    15371542                        p += _os2_interpret_long_filename(frame, cli, info_level, p, rdata_end,
    15381543                                                     &finfo,NULL,NULL);
     1544                        debuglocal(9, "fname %s (remove me 2)\n", finfo.fname);
    15391545                        if (!finfo.fname) {
    15401546                                debuglocal(0,"list_new: unable to parse name from info level %d\n",
Note: See TracChangeset for help on using the changeset viewer.