Ignore:
Timestamp:
Dec 23, 2010, 2:49:52 PM (15 years ago)
Author:
Silvan Scherrer
Message:

samba client 2.1: packing and more

File:
1 edited

Legend:

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

    r499 r505  
    9292    debug_printf( "fsphDosDateToUnixTime time2 %d %s", *time, ctime( (time_t*)time));
    9393}
    94 
    95 // -------------------------------------------------------------
    9694       
    97 int StrLen(char * s)
    98 {
    99         char * p;
    100         if (!s)
    101         {
    102                 return 0;
    103         }
    104         for (p = s; *p; p++);
    105         return (p - s);
    106 }
    107 
    108 char * StrNCat(char *dst, const char *src, int count)
    109 {
    110         int i;
    111         if (!dst || !src || count <= 0)
    112         {
    113                 return dst;
    114         }
    115         for (i = 0; dst[i]; i++);
    116         for (;i < count && *src; i++, src++)
    117         {
    118                 dst[i] = *src;
    119         }
    120         dst[i] = 0;
    121         return dst;
    122 }
    123 
    124 char * StrNCpy(char *dst, const char *src, int count)
    125 {
    126         if (!dst || !src || count <= 0)
    127         {
    128                 return dst;
    129         }
    130         *dst = 0;
    131         return StrNCat(dst, src, count);
    132 }
    133 
    134 char * StrCpy(char *dst, const char *src)
    135 {
    136         char * p;
    137         if (!dst || !src)
    138         {
    139                 return dst;
    140         }
    141         p = dst;
    142         while (*p++ = *src++);
    143         return dst;
    144 }
    145 
    146 char * StrCat(char *dst, const char *src)
    147 {
    148         int i;
    149         if (!dst || !src)
    150         {
    151                 return dst;
    152         }
    153         for (i = 0; dst[i]; i++);
    154         for (; *src; i++, src++)
    155         {
    156                 dst[i] = *src;
    157         }
    158         dst[i] = 0;
    159         return dst;
    160 }
    161 
    162 void * MemCpy(void * dst, const void * src, int len)
    163 {
    164         int i;
    165         if (!src || !dst || len <= 0)
    166         {
    167                 return dst;
    168         }
    169         for (i = 0; i < len; i++)
    170         {
    171                 ((char *)dst)[i] = ((char *)src)[i];
    172         }
    173         return dst;
    174 }
    175 
    176 void *MemSet(void *dst, char c, int len)
    177 {
    178         int i;
    179         if (!dst || len <= 0)
    180         {
    181                 return dst;
    182         }
    183         for (i = 0; i < len; i++)
    184         {
    185                 ((char *)dst)[i] = c;
    186         }
    187         return dst;
    188 }
    189 
    19095// -------------------------------------------------------------
    19196
     
    269174                name = pConn->pRes->srv.share_name;
    270175        }
    271         StrNCpy(stat->achName, name, CCHMAXPATHCOMP - 1);
     176        strncpy(stat->achName, name, CCHMAXPATHCOMP - 1);
    272177        stat->cbFile = finfo->size;
    273178        stat->cbFileAlloc = stat->cbFile;
    274179        stat->oNextEntryOffset = 0ul;
    275         stat->cchName = StrLen(stat->achName);
     180        stat->cchName = strlen(stat->achName);
    276181        stat->attrFile = (finfo->attr & 0x37);
    277182
     
    313218        debug_printf( "ftimeLastAccess %02d:%02d:%02d\n", stat.ftimeLastWrite.hours, stat.ftimeLastWrite.minutes, stat.ftimeLastWrite.twosecs*2);
    314219
    315         ph->fsphAddFile32L(plist, &stat, name, StrLen(name), finfo, sizeof(*finfo), 0);
     220        ph->fsphAddFile32L(plist, &stat, name, strlen(name), finfo, sizeof(*finfo), 0);
    316221        return 1;
    317222}
     
    402307        if (!rc && t && *q)
    403308        {
    404                 StrNCpy(pRes->srv.workgroup, q, sizeof(pRes->srv.workgroup) - 1);
     309                strncpy(pRes->srv.workgroup, q, sizeof(pRes->srv.workgroup) - 1);
    405310                pRes->rootlevel = 1;
    406311        }
     
    410315        if (!rc && t && *q)
    411316        {
    412                 StrNCpy(pRes->srv.server_name, q, sizeof(pRes->srv.server_name) - 1);
     317                strncpy(pRes->srv.server_name, q, sizeof(pRes->srv.server_name) - 1);
    413318                pRes->rootlevel = 2;
    414319        }
     
    418323        if (!rc && t && *q)
    419324        {
    420                 StrNCpy(pRes->srv.share_name, q, sizeof(pRes->srv.share_name) - 1);
     325                strncpy(pRes->srv.share_name, q, sizeof(pRes->srv.share_name) - 1);
    421326                pRes->rootlevel = 3;
    422327        }
     
    426331        if (!rc && t && *q)
    427332        {
    428                 StrNCpy(pRes->srv.username, q, sizeof(pRes->srv.username) - 1);
     333                strncpy(pRes->srv.username, q, sizeof(pRes->srv.username) - 1);
    429334        }
    430335
     
    433338        if (!rc && t && *q)
    434339        {
    435                 StrNCpy(pRes->srv.password, q, sizeof(pRes->srv.password) - 1);
     340                strncpy(pRes->srv.password, q, sizeof(pRes->srv.password) - 1);
    436341                defaultPassword = 0;
    437342        }
     
    450355            if (*p)
    451356            {
    452                 StrNCpy(pRes->srv.password, p, sizeof(pRes->srv.password) - 1);
     357                strncpy(pRes->srv.password, p, sizeof(pRes->srv.password) - 1);
    453358       
    454359                /* clear the plain password */
     
    471376        if (!rc && t && *q)
    472377        {
    473                 StrNCpy(pRes->srv.master, q, sizeof(pRes->srv.master) - 1);
     378                strncpy(pRes->srv.master, q, sizeof(pRes->srv.master) - 1);
    474379        }
    475380
     
    537442        if (iftestpath(path))
    538443        {
    539                 StrCpy(result, "\\A.+,;=[].B");
     444                strcpy(result, "\\A.+,;=[].B");
    540445                return NO_ERROR;
    541446        }
     
    560465                        if (!p)
    561466                        {
    562                                 p = path + StrLen(path);
    563                         }
    564                         if (StrLen(tmp->workgroup) != p - path
     467                                p = path + strlen(path);
     468                        }
     469                        if (strlen(tmp->workgroup) != p - path
    565470                                || (p == path || ph->fsphStrNICmp(path, tmp->workgroup, p - path)))
    566471                        {
    567                                 StrNCpy(tmp->workgroup, path, p - path);
     472                                strncpy(tmp->workgroup, path, p - path);
    568473                                tmp->workgroup[p - path] = 0;
    569474                                newlevel = 1;
     
    577482                        if (!p)
    578483                        {
    579                                 p = path + StrLen(path);
    580                         }
    581                         if (StrLen(tmp->server_name) != p - path
     484                                p = path + strlen(path);
     485                        }
     486                        if (strlen(tmp->server_name) != p - path
    582487                                || (p == path || ph->fsphStrNICmp(path, tmp->server_name, p - path)))
    583488                        {
    584                                 StrNCpy(tmp->server_name, path, p - path);
     489                                strncpy(tmp->server_name, path, p - path);
    585490                                tmp->server_name[p - path] = 0;
    586491                                newlevel = 1;
     
    594499                        if (!p)
    595500                        {
    596                                 p = path + StrLen(path);
    597                         }
    598                         if (StrLen(tmp->share_name) != (p - path)
     501                                p = path + strlen(path);
     502                        }
     503                        if (strlen(tmp->share_name) != (p - path)
    599504                                || (p == path || ph->fsphStrNICmp(path, tmp->share_name, p - path)))
    600505                        {
    601                                 StrNCpy(tmp->share_name, path, p - path);
     506                                strncpy(tmp->share_name, path, p - path);
    602507                                tmp->share_name[p - path] = 0;
    603508                                newlevel = 1;
     
    623528        }
    624529
    625         StrCpy(result, "\\");
    626         StrNCat(result, path, CCHMAXPATH);
     530        strcpy(result, "\\");
     531        strncat(result, path, CCHMAXPATH);
    627532
    628533        return rc;
     
    698603        else
    699604        {
    700                 MemSet(pRes, 0, sizeof(Resource));
     605                memset(pRes, 0, sizeof(Resource));
    701606                //pRes->objany = objany;
    702607                // parse init string
     
    728633        Resource *pRes = (Resource *)resource;
    729634        dircache_delete(pRes->pdc);
    730         MemSet(&pRes->srv, 0, sizeof(pRes->srv));
     635        memset(&pRes->srv, 0, sizeof(pRes->srv));
    731636        free(pRes);
    732637        debuglocal(9,"NdpFreeResource %d\n", NO_ERROR);
     
    791696                } break;
    792697        }
    793         *poutlen = StrLen(s) + 1;
     698        *poutlen = strlen(s) + 1;
    794699        if (*poutlen > insize)
    795700        {
     
    798703        else
    799704        {
    800                 MemCpy(pdata, s, *poutlen);
     705                memcpy(pdata, s, *poutlen);
    801706        }
    802707
     
    885790                return rc;
    886791        }
    887         MemSet(pConn, 0, sizeof(Connection));
     792        memset(pConn, 0, sizeof(Connection));
    888793        pConn->pRes = pRes;
    889794        pConn->file.fd = -1;
     
    997902                                break;
    998903                        }
    999                         StrNCpy(finfo.fname, path, sizeof(finfo.fname) - 1);
     904                        strncpy(finfo.fname, path, sizeof(finfo.fname) - 1);
    1000905                        debuglocal(9,"NdpQueryPathInfo smbwrp_getattr for <%s>\n", path);
    1001906                        rc = smbwrp_getattr( &pRes->srv, pConn->cli, &finfo);
     
    1072977        debug_printf("NdpFindStart in\n");
    1073978
    1074                 StrNCpy(dir, szPath, sizeof(dir) - 1);
     979                strncpy(dir, szPath, sizeof(dir) - 1);
    1075980                if (pel)
    1076981                {
    1077982                        mask = pel->name;
    1078                         dir[StrLen(szPath) - pel->length] = 0;
    1079                 }
    1080                 action = StrLen(dir) - 1;
     983                        dir[strlen(szPath) - pel->length] = 0;
     984                }
     985                action = strlen(dir) - 1;
    1081986                if (dir[action] == '\\')
    1082987                {
     
    1088993                        return rc;
    1089994                }
    1090                 action = StrLen(path) - 1;
     995                action = strlen(path) - 1;
    1091996                if (path[action] != '\\')
    1092997                {
    1093                         StrNCat(path, "\\", sizeof(path) - 1);
    1094                 }
    1095                 StrCpy(dir, path);
    1096                 StrNCat(path, mask, sizeof(path) - 1);
     998                        strncat(path, "\\", sizeof(path) - 1);
     999                }
     1000                strcpy(dir, path);
     1001                strncat(path, mask, sizeof(path) - 1);
    10971002
    10981003                // this structure will be used by libsmb callbacks, so we store here all we need
     
    11901095                }
    11911096
    1192                 MemSet(&finfo, 0, sizeof(finfo));
    1193 
    1194                 StrNCpy(finfo.fname, path, sizeof(finfo.fname) - 1);
     1097                memset(&finfo, 0, sizeof(finfo));
     1098
     1099                strncpy(finfo.fname, path, sizeof(finfo.fname) - 1);
    11951100                fsphDosDateToUnixTime(pfi->stat.fdateLastWrite, pfi->stat.ftimeLastWrite, &(finfo.mtime));
    11961101                finfo.attr = pfi->stat.attrFile & 0x37;
     
    12431148                                pfeadest->cbValue = pfea->cbValue;
    12441149                                pfeadest->fEA = 0;
    1245                                 StrCpy((char *)(pfeadest + 1), name);
    1246                                 MemCpy((char *)(pfeadest + 1) + pfea->cbName + 1, (char *)(pfea + 1) + pfea->cbName + 1, pfea->cbValue);
     1150                                strcpy((char *)(pfeadest + 1), name);
     1151                                memcpy((char *)(pfeadest + 1) + pfea->cbName + 1, (char *)(pfea + 1) + pfea->cbName + 1, pfea->cbValue);
    12471152                                pfeadest = (FEA *)((char *)pFEAList + ddone);
    12481153                        }
     
    15851490                        break;
    15861491                }
    1587                 l1 = StrLen(szSrc);
    1588                 l2 = StrLen(src);
     1492                l1 = strlen(szSrc);
     1493                l2 = strlen(src);
    15891494                if (l1 > l2)
    15901495                {
     
    16481553                }
    16491554
    1650                 StrNCpy(pConn->file.fullname, szFileName, sizeof(pConn->file.fullname) - 1);
    1651                 StrNCpy(pConn->file.fname, path, sizeof(pConn->file.fname) - 1);
     1555                strncpy(pConn->file.fullname, szFileName, sizeof(pConn->file.fullname) - 1);
     1556                strncpy(pConn->file.fname, path, sizeof(pConn->file.fname) - 1);
    16521557                flags |= O_BINARY;
    16531558                switch (ulOpenMode & 3)
     
    17181623                }
    17191624
    1720                 MemSet(&finfo, 0, sizeof(finfo));
    1721                 StrNCpy(finfo.fname, path, sizeof(finfo.fname) - 1);
     1625                memset(&finfo, 0, sizeof(finfo));
     1626                strncpy(finfo.fname, path, sizeof(finfo.fname) - 1);
    17221627                finfo.attr = usAttr & 0x37;
    17231628                rc = smbwrp_setattr(pConn->cli, &finfo);
     
    17651670                        break;
    17661671                }
    1767                 StrNCpy(finfo.fname, pConn->file.fname, sizeof(finfo.fname) - 1);
     1672                strncpy(finfo.fname, pConn->file.fname, sizeof(finfo.fname) - 1);
    17681673                rc = smbwrp_fgetattr(pConn->cli, &pConn->file, &finfo);
    17691674                if (!rc)
Note: See TracChangeset for help on using the changeset viewer.