[151] | 1 | /*
|
---|
| 2 | Netdrive Samba client plugin
|
---|
| 3 | plugin API
|
---|
| 4 | Copyright (C) netlabs.org 2003-2008
|
---|
| 5 |
|
---|
| 6 | This program is free software; you can redistribute it and/or modify
|
---|
| 7 | it under the terms of the GNU General Public License as published by
|
---|
| 8 | the Free Software Foundation; either version 2 of the License, or
|
---|
| 9 | (at your option) any later version.
|
---|
| 10 |
|
---|
| 11 | This program is distributed in the hope that it will be useful,
|
---|
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 14 | GNU General Public License for more details.
|
---|
| 15 |
|
---|
| 16 | You should have received a copy of the GNU General Public License
|
---|
| 17 | along with this program; if not, write to the Free Software
|
---|
| 18 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
| 19 | */
|
---|
| 20 |
|
---|
[48] | 21 | #include <stdio.h>
|
---|
| 22 | #include <stdlib.h>
|
---|
| 23 | #include <stdarg.h>
|
---|
[183] | 24 | #include <string.h>
|
---|
[48] | 25 | #include <time.h>
|
---|
[5] | 26 |
|
---|
[145] | 27 | #define NDPL_LARGEFILES
|
---|
| 28 | #define INCL_LONGLONG
|
---|
| 29 | #include <ndextpl2.h>
|
---|
[147] | 30 | #include "smbwrp.h"
|
---|
| 31 | #include "util.h"
|
---|
[48] | 32 |
|
---|
[189] | 33 | #if 0
|
---|
| 34 |
|
---|
[126] | 35 | #ifndef DEBUG_PRINTF
|
---|
| 36 | #define debug_printf( ...)
|
---|
| 37 | #endif
|
---|
| 38 |
|
---|
[145] | 39 | #define log debug_printf
|
---|
[189] | 40 | #endif
|
---|
[145] | 41 |
|
---|
[189] | 42 | #define debug_printf(...) debuglocal(9, __VA_ARGS__)
|
---|
[5] | 43 |
|
---|
[126] | 44 | // -------------------------------------------------------------
|
---|
| 45 |
|
---|
| 46 | /* time conversion functions: SMB protocol sends timestamps in GMT time,
|
---|
| 47 | * os2 api uses localtime,
|
---|
| 48 | * emx/klibc uses timezone and daylight saving to convert GMT timestamps,
|
---|
| 49 | * so only the timezone must be counted in conversion.
|
---|
| 50 | */
|
---|
| 51 | void fsphUnixTimeToDosDate( time_t time, FDATE* fdate, FTIME *ftime)
|
---|
| 52 | {
|
---|
| 53 | struct tm* gmt = localtime( &time);
|
---|
[493] | 54 | #if 0 // as localtime() already does dst we don't need to add something
|
---|
[126] | 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 | }
|
---|
[493] | 60 | #endif
|
---|
[126] | 61 | fdate->day = gmt->tm_mday;
|
---|
| 62 | fdate->month = gmt->tm_mon+1;
|
---|
| 63 | fdate->year = gmt->tm_year + 1900 - 1980;
|
---|
| 64 | ftime->twosecs = gmt->tm_sec/2;
|
---|
| 65 | ftime->minutes = gmt->tm_min;
|
---|
| 66 | ftime->hours = gmt->tm_hour;
|
---|
[493] | 67 | debug_printf("fsphUnixDateToDosDate\n");
|
---|
[126] | 68 | }
|
---|
| 69 |
|
---|
[183] | 70 | void fsphDosDateToUnixTime( FDATE fdate, FTIME ftime, ULONG* time)
|
---|
[126] | 71 | {
|
---|
| 72 | struct tm gmtime = { 0 };
|
---|
| 73 |
|
---|
| 74 | debug_printf( "fsphDosDateToUnixTime time %02d:%02d\n", ftime.hours, ftime.minutes);
|
---|
| 75 | gmtime.tm_mday = fdate.day;
|
---|
| 76 | gmtime.tm_mon = fdate.month-1;
|
---|
| 77 | gmtime.tm_year = fdate.year + 1980 - 1900;
|
---|
| 78 | gmtime.tm_sec = ftime.twosecs*2;
|
---|
| 79 | gmtime.tm_min = ftime.minutes;
|
---|
| 80 | gmtime.tm_hour = ftime.hours;
|
---|
| 81 | gmtime.tm_isdst = -1; // force libc to check dst saving
|
---|
| 82 |
|
---|
| 83 | *time = mktime( &gmtime);
|
---|
[183] | 84 | debug_printf( "fsphDosDateToUnixTime time1 %d %s", *time, ctime( (time_t*)time));
|
---|
[493] | 85 | #if 0 // as mktime() already does dst we don't need to add something
|
---|
| 86 | struct tm* gmt;
|
---|
[126] | 87 | gmt = localtime( (time_t*) time);
|
---|
| 88 | if (gmt->tm_isdst>0) {
|
---|
| 89 | debug_printf( "fsphDosDateToUnixTime daylight saving in effect %d, timezone %d\n",gmt->tm_isdst, timezone);
|
---|
| 90 | *time += 3600;
|
---|
| 91 | }
|
---|
[493] | 92 | #endif
|
---|
[183] | 93 | debug_printf( "fsphDosDateToUnixTime time2 %d %s", *time, ctime( (time_t*)time));
|
---|
[126] | 94 | }
|
---|
| 95 |
|
---|
| 96 | // -------------------------------------------------------------
|
---|
| 97 |
|
---|
[5] | 98 | int StrLen(char * s)
|
---|
| 99 | {
|
---|
| 100 | char * p;
|
---|
| 101 | if (!s)
|
---|
| 102 | {
|
---|
| 103 | return 0;
|
---|
| 104 | }
|
---|
| 105 | for (p = s; *p; p++);
|
---|
| 106 | return (p - s);
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 | char * StrNCat(char *dst, const char *src, int count)
|
---|
| 110 | {
|
---|
| 111 | int i;
|
---|
| 112 | if (!dst || !src || count <= 0)
|
---|
| 113 | {
|
---|
| 114 | return dst;
|
---|
| 115 | }
|
---|
| 116 | for (i = 0; dst[i]; i++);
|
---|
| 117 | for (;i < count && *src; i++, src++)
|
---|
| 118 | {
|
---|
| 119 | dst[i] = *src;
|
---|
| 120 | }
|
---|
| 121 | dst[i] = 0;
|
---|
| 122 | return dst;
|
---|
| 123 | }
|
---|
| 124 |
|
---|
| 125 | char * StrNCpy(char *dst, const char *src, int count)
|
---|
| 126 | {
|
---|
| 127 | if (!dst || !src || count <= 0)
|
---|
| 128 | {
|
---|
| 129 | return dst;
|
---|
| 130 | }
|
---|
| 131 | *dst = 0;
|
---|
| 132 | return StrNCat(dst, src, count);
|
---|
| 133 | }
|
---|
| 134 |
|
---|
| 135 | char * StrCpy(char *dst, const char *src)
|
---|
| 136 | {
|
---|
| 137 | char * p;
|
---|
| 138 | if (!dst || !src)
|
---|
| 139 | {
|
---|
| 140 | return dst;
|
---|
| 141 | }
|
---|
| 142 | p = dst;
|
---|
| 143 | while (*p++ = *src++);
|
---|
| 144 | return dst;
|
---|
| 145 | }
|
---|
| 146 |
|
---|
| 147 | char * StrCat(char *dst, const char *src)
|
---|
| 148 | {
|
---|
| 149 | int i;
|
---|
| 150 | if (!dst || !src)
|
---|
| 151 | {
|
---|
| 152 | return dst;
|
---|
| 153 | }
|
---|
| 154 | for (i = 0; dst[i]; i++);
|
---|
| 155 | for (; *src; i++, src++)
|
---|
| 156 | {
|
---|
| 157 | dst[i] = *src;
|
---|
| 158 | }
|
---|
| 159 | dst[i] = 0;
|
---|
| 160 | return dst;
|
---|
| 161 | }
|
---|
| 162 |
|
---|
| 163 | void * MemCpy(void * dst, const void * src, int len)
|
---|
| 164 | {
|
---|
| 165 | int i;
|
---|
| 166 | if (!src || !dst || len <= 0)
|
---|
| 167 | {
|
---|
| 168 | return dst;
|
---|
| 169 | }
|
---|
| 170 | for (i = 0; i < len; i++)
|
---|
| 171 | {
|
---|
| 172 | ((char *)dst)[i] = ((char *)src)[i];
|
---|
| 173 | }
|
---|
| 174 | return dst;
|
---|
| 175 | }
|
---|
| 176 |
|
---|
| 177 | void *MemSet(void *dst, char c, int len)
|
---|
| 178 | {
|
---|
| 179 | int i;
|
---|
| 180 | if (!dst || len <= 0)
|
---|
| 181 | {
|
---|
| 182 | return dst;
|
---|
| 183 | }
|
---|
| 184 | for (i = 0; i < len; i++)
|
---|
| 185 | {
|
---|
| 186 | ((char *)dst)[i] = c;
|
---|
| 187 | }
|
---|
| 188 | return dst;
|
---|
| 189 | }
|
---|
| 190 |
|
---|
[131] | 191 | // -------------------------------------------------------------
|
---|
| 192 |
|
---|
[5] | 193 | /* uppercased type of resource */
|
---|
| 194 | const char *NdpTypes[] =
|
---|
| 195 | {
|
---|
| 196 | "SMBFS",
|
---|
| 197 | NULL
|
---|
| 198 | }
|
---|
| 199 | ;
|
---|
| 200 |
|
---|
| 201 | /* Properties of supported resource types */
|
---|
| 202 |
|
---|
| 203 | /* Properties of resource */
|
---|
| 204 | static const NDPROPERTYINFO smbProperties[] =
|
---|
| 205 | {
|
---|
| 206 | {ND_PROP_STRING, 0, "WORKGROUP", ""},
|
---|
| 207 | {ND_PROP_STRING, 0, "SERVER", ""},
|
---|
| 208 | {ND_PROP_STRING, 0, "SHARE", ""},
|
---|
| 209 | {ND_PROP_STRING, 0, "USER", "guest"},
|
---|
| 210 | {ND_PROP_STRING, 0, "PASSWORD", ""},
|
---|
[116] | 211 | {ND_PROP_STRING, 0, "SPASSWORD", ""},
|
---|
[5] | 212 | {ND_PROP_STRING, 0, "MASTER", "WORKGROUP"},
|
---|
[518] | 213 | {ND_PROP_ULONG, 0, "MASTERTYPE", "1"},
|
---|
| 214 | {ND_PROP_ULONG, 0, "CTO", "10"},
|
---|
| 215 | {ND_PROP_ULONG, 0, "CLD", "32"},
|
---|
[520] | 216 | {ND_PROP_ULONG, 0, "EASUPPORT", "1"},
|
---|
[5] | 217 | {ND_PROP_STRING, 0, NULL, NULL}
|
---|
| 218 | };
|
---|
| 219 |
|
---|
| 220 |
|
---|
| 221 | /* Exported array of properties */
|
---|
| 222 | const NDPROPERTYINFO *NdpPropertiesInfo[] =
|
---|
| 223 | {
|
---|
| 224 | smbProperties
|
---|
| 225 | };
|
---|
| 226 |
|
---|
| 227 |
|
---|
[497] | 228 | PLUGINHELPERTABLE2L *ph;
|
---|
[5] | 229 | static int ifL;
|
---|
| 230 |
|
---|
| 231 | int APIENTRY NdpPluginLoad (PLUGINHELPERTABLE2L *pPHT)
|
---|
| 232 | {
|
---|
| 233 | int rc;
|
---|
| 234 | HPIPE pipe;
|
---|
| 235 | unsigned long action;
|
---|
| 236 | ph = pPHT;
|
---|
| 237 | ifL = 0;
|
---|
| 238 | /*
|
---|
| 239 | if (ph->cb < sizeof (PLUGINHELPERTABLE2))
|
---|
| 240 | {
|
---|
| 241 | return ERROR_INVALID_FUNCTION;
|
---|
| 242 | }
|
---|
| 243 | */
|
---|
| 244 | if (ph->cb >= sizeof (PLUGINHELPERTABLE2L))
|
---|
| 245 | {
|
---|
| 246 | ifL = 1;
|
---|
| 247 | }
|
---|
[189] | 248 | debuglocal(9,"Working with %s bit fileio NDFS\n", ifL ? "64" : "32");
|
---|
[5] | 249 | return NO_ERROR;
|
---|
| 250 | }
|
---|
| 251 |
|
---|
| 252 |
|
---|
| 253 | int APIENTRY NdpPluginFree (void)
|
---|
| 254 | {
|
---|
| 255 | return NO_ERROR;
|
---|
| 256 | }
|
---|
| 257 |
|
---|
| 258 |
|
---|
| 259 | void getfindinfo(Connection * pConn, FILEFINDBUF3 * stat, smbwrp_fileinfo * finfo)
|
---|
| 260 | {
|
---|
| 261 | char * name = ph->fsphStrRChr(finfo->fname, '\\');
|
---|
| 262 | if (name)
|
---|
| 263 | {
|
---|
| 264 | name++;
|
---|
| 265 | }
|
---|
| 266 | else
|
---|
| 267 | {
|
---|
| 268 | name = finfo->fname;
|
---|
| 269 | }
|
---|
| 270 | if (!*name)
|
---|
| 271 | {
|
---|
[145] | 272 | name = pConn->pRes->srv.share_name;
|
---|
[5] | 273 | }
|
---|
| 274 | StrNCpy(stat->achName, name, CCHMAXPATHCOMP - 1);
|
---|
| 275 | stat->cbFile = finfo->size;
|
---|
| 276 | stat->cbFileAlloc = stat->cbFile;
|
---|
| 277 | stat->oNextEntryOffset = 0ul;
|
---|
| 278 | stat->cchName = StrLen(stat->achName);
|
---|
| 279 | stat->attrFile = (finfo->attr & 0x37);
|
---|
| 280 |
|
---|
[126] | 281 | fsphUnixTimeToDosDate(finfo->mtime, &stat->fdateLastWrite, &stat->ftimeLastWrite);
|
---|
| 282 | fsphUnixTimeToDosDate(finfo->ctime, &stat->fdateCreation, &stat->ftimeCreation);
|
---|
| 283 | fsphUnixTimeToDosDate(finfo->atime, &stat->fdateLastAccess, &stat->ftimeLastAccess);
|
---|
[5] | 284 | }
|
---|
| 285 |
|
---|
| 286 | int getfindinfoL(Connection * pConn, void * plist, smbwrp_fileinfo * finfo, ULONG ulAttribute, char * mask)
|
---|
| 287 | {
|
---|
| 288 | FILESTATUS3L stat = {0};
|
---|
| 289 | char * name = ph->fsphStrRChr(finfo->fname, '\\');
|
---|
| 290 | if (name)
|
---|
| 291 | {
|
---|
| 292 | name++;
|
---|
| 293 | }
|
---|
| 294 | else
|
---|
| 295 | {
|
---|
| 296 | name = finfo->fname;
|
---|
| 297 | }
|
---|
| 298 | if (!*name)
|
---|
| 299 | {
|
---|
[145] | 300 | name = pConn->pRes->srv.share_name;
|
---|
[5] | 301 | }
|
---|
| 302 | if (mask && (!ph->fsphAttrMatch(ulAttribute, finfo->attr & 0x37) || !ph->fsphWildMatch(mask, name, ND_IGNORE_CASE)))
|
---|
| 303 | {
|
---|
| 304 | return 0;
|
---|
| 305 | }
|
---|
| 306 |
|
---|
| 307 | stat.cbFile = finfo->size;
|
---|
| 308 | stat.cbFileAlloc = stat.cbFile;
|
---|
| 309 | stat.attrFile = (finfo->attr & 0x37);
|
---|
| 310 |
|
---|
[126] | 311 | fsphUnixTimeToDosDate(finfo->mtime, &stat.fdateLastWrite, &stat.ftimeLastWrite);
|
---|
| 312 | fsphUnixTimeToDosDate(finfo->ctime, &stat.fdateCreation, &stat.ftimeCreation);
|
---|
| 313 | fsphUnixTimeToDosDate(finfo->atime, &stat.fdateLastAccess, &stat.ftimeLastAccess);
|
---|
| 314 | debug_printf( "fname %s\n", finfo->fname);
|
---|
[183] | 315 | debug_printf( "mtime %d %s", finfo->mtime, ctime( (time_t*)&finfo->mtime));
|
---|
[126] | 316 | debug_printf( "ftimeLastAccess %02d:%02d:%02d\n", stat.ftimeLastWrite.hours, stat.ftimeLastWrite.minutes, stat.ftimeLastWrite.twosecs*2);
|
---|
[5] | 317 |
|
---|
| 318 | ph->fsphAddFile32L(plist, &stat, name, StrLen(name), finfo, sizeof(*finfo), 0);
|
---|
| 319 | return 1;
|
---|
| 320 | }
|
---|
| 321 |
|
---|
[116] | 322 | static unsigned char fromhex (char c)
|
---|
| 323 | {
|
---|
| 324 | if ('0' <= c && c <= '9')
|
---|
| 325 | {
|
---|
| 326 | return c - '0';
|
---|
| 327 | }
|
---|
| 328 |
|
---|
| 329 | if ('A' <= c && c <= 'F')
|
---|
| 330 | {
|
---|
[122] | 331 | return c - 'A' + 0xA;
|
---|
[116] | 332 | }
|
---|
| 333 |
|
---|
| 334 | if ('a' <= c && c <= 'f')
|
---|
| 335 | {
|
---|
[122] | 336 | return c - 'a' + 0xA;
|
---|
[116] | 337 | }
|
---|
| 338 |
|
---|
| 339 | return 0;
|
---|
| 340 | }
|
---|
[5] | 341 |
|
---|
[116] | 342 | static char tohex (unsigned char b)
|
---|
| 343 | {
|
---|
| 344 | b &= 0xF;
|
---|
| 345 |
|
---|
| 346 | if (b <= 9)
|
---|
| 347 | {
|
---|
| 348 | return b + '0';
|
---|
| 349 | }
|
---|
| 350 |
|
---|
| 351 | return 'A' + (b - 0xA);
|
---|
| 352 | }
|
---|
| 353 |
|
---|
| 354 | static void decryptPassword (const char *pszCrypt, char *pszPlain)
|
---|
| 355 | {
|
---|
| 356 | /* A simple "decryption", character from the hex value. */
|
---|
| 357 | const char *s = pszCrypt;
|
---|
| 358 | char *d = pszPlain;
|
---|
| 359 |
|
---|
| 360 | while (*s)
|
---|
| 361 | {
|
---|
| 362 | *d++ = (char)((fromhex (*s++) << 4) + fromhex (*s++));
|
---|
| 363 | }
|
---|
| 364 |
|
---|
| 365 | *d++ = 0;
|
---|
| 366 | }
|
---|
| 367 |
|
---|
| 368 | static void encryptPassword (const char *pszPlain, char *pszCrypt)
|
---|
| 369 | {
|
---|
| 370 | /* A simple "encryption" encode each character as hex value. */
|
---|
| 371 | const char *s = pszPlain;
|
---|
| 372 | char *d = pszCrypt;
|
---|
| 373 |
|
---|
| 374 | while (*s)
|
---|
| 375 | {
|
---|
| 376 | *d++ = tohex ((*s) >> 4);
|
---|
| 377 | *d++ = tohex (*s);
|
---|
| 378 | s++;
|
---|
| 379 | }
|
---|
| 380 |
|
---|
| 381 | *d++ = 0;
|
---|
| 382 | }
|
---|
| 383 |
|
---|
[5] | 384 | /* accept parameters in form
|
---|
| 385 | * [filename][;name=filename]
|
---|
| 386 | */
|
---|
[145] | 387 | int initResource (Resource *pRes, NDPROPERTYHANDLE properties)
|
---|
[5] | 388 | {
|
---|
| 389 | int rc = NO_ERROR;
|
---|
| 390 | unsigned long t;
|
---|
[183] | 391 | const CHAR * q = NULL;
|
---|
[116] | 392 | int defaultPassword = 1;
|
---|
[5] | 393 |
|
---|
| 394 | pRes->rootlevel = 0;
|
---|
| 395 | pRes->easupport = 1;
|
---|
[145] | 396 | #ifdef HAVE_KRB5_H
|
---|
| 397 | pRes->krb5support = 1;
|
---|
| 398 | #else
|
---|
| 399 | pRes->krb5support = 0;
|
---|
| 400 | #endif
|
---|
[497] | 401 | pRes->pdc = NULL;
|
---|
[5] | 402 |
|
---|
| 403 | t = 0, q = NULL;
|
---|
[145] | 404 | rc = ph->fsphQueryStringProperty (properties, "WORKGROUP", &q, &t);
|
---|
[5] | 405 | if (!rc && t && *q)
|
---|
| 406 | {
|
---|
| 407 | StrNCpy(pRes->srv.workgroup, q, sizeof(pRes->srv.workgroup) - 1);
|
---|
| 408 | pRes->rootlevel = 1;
|
---|
| 409 | }
|
---|
| 410 |
|
---|
| 411 | t = 0, q = NULL;
|
---|
[145] | 412 | rc = ph->fsphQueryStringProperty (properties, "SERVER", &q, &t);
|
---|
[5] | 413 | if (!rc && t && *q)
|
---|
| 414 | {
|
---|
| 415 | StrNCpy(pRes->srv.server_name, q, sizeof(pRes->srv.server_name) - 1);
|
---|
| 416 | pRes->rootlevel = 2;
|
---|
| 417 | }
|
---|
| 418 |
|
---|
| 419 | t = 0, q = NULL;
|
---|
[145] | 420 | rc = ph->fsphQueryStringProperty (properties, "SHARE", &q, &t);
|
---|
[5] | 421 | if (!rc && t && *q)
|
---|
| 422 | {
|
---|
| 423 | StrNCpy(pRes->srv.share_name, q, sizeof(pRes->srv.share_name) - 1);
|
---|
| 424 | pRes->rootlevel = 3;
|
---|
| 425 | }
|
---|
| 426 |
|
---|
| 427 | t = 0, q = NULL;
|
---|
[145] | 428 | rc = ph->fsphQueryStringProperty (properties, "USER", &q, &t);
|
---|
[5] | 429 | if (!rc && t && *q)
|
---|
| 430 | {
|
---|
| 431 | StrNCpy(pRes->srv.username, q, sizeof(pRes->srv.username) - 1);
|
---|
| 432 | }
|
---|
| 433 |
|
---|
| 434 | t = 0, q = NULL;
|
---|
[145] | 435 | rc = ph->fsphQueryStringProperty (properties, "PASSWORD", &q, &t);
|
---|
[5] | 436 | if (!rc && t && *q)
|
---|
| 437 | {
|
---|
| 438 | StrNCpy(pRes->srv.password, q, sizeof(pRes->srv.password) - 1);
|
---|
[116] | 439 | defaultPassword = 0;
|
---|
[5] | 440 | }
|
---|
| 441 |
|
---|
| 442 | t = 0, q = NULL;
|
---|
[145] | 443 | rc = ph->fsphQueryStringProperty (properties, "SPASSWORD", &q, &t);
|
---|
[116] | 444 | if ( rc == NO_ERROR
|
---|
| 445 | && *q != '\0'
|
---|
| 446 | && defaultPassword)
|
---|
| 447 | {
|
---|
| 448 | char p[1024];
|
---|
| 449 | p[0] = 0;
|
---|
| 450 |
|
---|
| 451 | decryptPassword (q, p);
|
---|
| 452 |
|
---|
| 453 | if (*p)
|
---|
| 454 | {
|
---|
| 455 | StrNCpy(pRes->srv.password, p, sizeof(pRes->srv.password) - 1);
|
---|
| 456 |
|
---|
| 457 | /* clear the plain password */
|
---|
[145] | 458 | ph->fsphSetProperty (properties, "PASSWORD", "");
|
---|
[116] | 459 | }
|
---|
| 460 | }
|
---|
| 461 | else
|
---|
| 462 | {
|
---|
| 463 | char c[1024];
|
---|
| 464 | encryptPassword (pRes->srv.password, c);
|
---|
| 465 |
|
---|
[145] | 466 | ph->fsphSetProperty (properties, "SPASSWORD", c);
|
---|
[116] | 467 |
|
---|
| 468 | // clear the plain password
|
---|
[145] | 469 | ph->fsphSetProperty (properties, "PASSWORD", "");
|
---|
[116] | 470 | }
|
---|
| 471 |
|
---|
| 472 | t = 0, q = NULL;
|
---|
[145] | 473 | rc = ph->fsphQueryStringProperty (properties, "MASTER", &q, &t);
|
---|
[5] | 474 | if (!rc && t && *q)
|
---|
| 475 | {
|
---|
| 476 | StrNCpy(pRes->srv.master, q, sizeof(pRes->srv.master) - 1);
|
---|
| 477 | }
|
---|
| 478 |
|
---|
| 479 | t = 0, q = NULL;
|
---|
| 480 |
|
---|
| 481 | t = 0;
|
---|
[145] | 482 | rc = ph->fsphQueryUlongProperty (properties, "MASTERTYPE", &t);
|
---|
[5] | 483 | if (!rc)
|
---|
| 484 | {
|
---|
| 485 | if (t > 1)
|
---|
| 486 | {
|
---|
| 487 | rc = ERROR_INVALID_PARAMETER;
|
---|
| 488 | }
|
---|
| 489 | else
|
---|
| 490 | {
|
---|
| 491 | pRes->srv.ifmastergroup = t;
|
---|
| 492 | }
|
---|
| 493 | }
|
---|
| 494 |
|
---|
| 495 | t = 0;
|
---|
[145] | 496 | rc = ph->fsphQueryUlongProperty (properties, "EASUPPORT", &t);
|
---|
[5] | 497 | if (!rc)
|
---|
| 498 | {
|
---|
| 499 | if (t > 1)
|
---|
| 500 | {
|
---|
| 501 | rc = ERROR_INVALID_PARAMETER;
|
---|
| 502 | }
|
---|
| 503 | else
|
---|
| 504 | {
|
---|
| 505 | pRes->easupport = t;
|
---|
| 506 | }
|
---|
| 507 | }
|
---|
| 508 |
|
---|
[518] | 509 | t = 0;
|
---|
| 510 | rc = ph->fsphQueryUlongProperty (properties, "CTO", &t);
|
---|
| 511 | if (!rc)
|
---|
| 512 | {
|
---|
| 513 | if (t > 600)
|
---|
| 514 | {
|
---|
| 515 | rc = ERROR_INVALID_PARAMETER;
|
---|
| 516 | }
|
---|
| 517 | else
|
---|
| 518 | {
|
---|
| 519 | pRes->cachetimeout = t;
|
---|
| 520 | }
|
---|
| 521 | }
|
---|
[497] | 522 |
|
---|
[518] | 523 | t = 0;
|
---|
| 524 | rc = ph->fsphQueryUlongProperty (properties, "CLD", &t);
|
---|
| 525 | if (!rc)
|
---|
| 526 | {
|
---|
| 527 | if (t > 96)
|
---|
| 528 | {
|
---|
| 529 | rc = ERROR_INVALID_PARAMETER;
|
---|
| 530 | }
|
---|
| 531 | else
|
---|
| 532 | {
|
---|
| 533 | pRes->cachedepth = t;
|
---|
| 534 | }
|
---|
| 535 | }
|
---|
| 536 |
|
---|
| 537 | /*
|
---|
| 538 | * Create a directory cache with expiration time and cache listings
|
---|
| 539 | * the above values come from the gui. default: timeout 10; listings: 32
|
---|
| 540 | */
|
---|
| 541 | dircache_create(&pRes->pdc, pRes->cachetimeout, pRes->cachedepth);
|
---|
| 542 |
|
---|
[5] | 543 | return rc;
|
---|
| 544 | }
|
---|
| 545 |
|
---|
| 546 | int iftestpath(char * path)
|
---|
| 547 | {
|
---|
| 548 | char * p = path;
|
---|
| 549 | if (!path)
|
---|
| 550 | {
|
---|
| 551 | return 0;
|
---|
| 552 | }
|
---|
| 553 | while ((p = ph->fsphStrChr(p, 'A')) != NULL)
|
---|
| 554 | {
|
---|
| 555 | if (ph->fsphStrNCmp(p, "A.+,;=[].B", 10) == 0)
|
---|
| 556 | {
|
---|
| 557 | return 1;
|
---|
| 558 | }
|
---|
| 559 | p++;
|
---|
| 560 | }
|
---|
| 561 | return 0;
|
---|
| 562 | }
|
---|
| 563 |
|
---|
| 564 | int pathparser(Resource *pRes, Connection * pConn, char * path, char * result)
|
---|
| 565 | {
|
---|
| 566 | int rootlevel;
|
---|
| 567 | int rc = NO_ERROR;
|
---|
| 568 | if (!pRes || !path || !result)
|
---|
| 569 | {
|
---|
| 570 | return ERROR_INVALID_PARAMETER;
|
---|
| 571 | }
|
---|
| 572 | // handle special case when someone wants to test support of LFN or smth similar
|
---|
| 573 | if (iftestpath(path))
|
---|
| 574 | {
|
---|
| 575 | StrCpy(result, "\\A.+,;=[].B");
|
---|
| 576 | return NO_ERROR;
|
---|
| 577 | }
|
---|
[145] | 578 |
|
---|
[5] | 579 | rootlevel = pRes->rootlevel;
|
---|
| 580 | if (*path == '\\') path++;
|
---|
[180] | 581 |
|
---|
[5] | 582 | if (rootlevel < 3)
|
---|
| 583 | {
|
---|
| 584 | char * p;
|
---|
[180] | 585 | // flag: 1 parameters changed, reconnection required, 0 do nothing
|
---|
[5] | 586 | int newlevel = 0;
|
---|
[180] | 587 | // use a temporary resource to test disconnection/reconnection
|
---|
| 588 | Resource tmpRes;
|
---|
| 589 | // copy exising data
|
---|
| 590 | memcpy( &tmpRes, pRes, sizeof( tmpRes));
|
---|
| 591 | // pointer to new connection fields
|
---|
| 592 | smbwrp_server * tmp = &tmpRes.srv;
|
---|
[5] | 593 | if (rootlevel == 0)
|
---|
| 594 | {
|
---|
| 595 | p = ph->fsphStrChr(path, '\\');
|
---|
| 596 | if (!p)
|
---|
| 597 | {
|
---|
| 598 | p = path + StrLen(path);
|
---|
| 599 | }
|
---|
| 600 | if (StrLen(tmp->workgroup) != p - path
|
---|
| 601 | || (p == path || ph->fsphStrNICmp(path, tmp->workgroup, p - path)))
|
---|
| 602 | {
|
---|
| 603 | StrNCpy(tmp->workgroup, path, p - path);
|
---|
| 604 | tmp->workgroup[p - path] = 0;
|
---|
| 605 | newlevel = 1;
|
---|
| 606 | }
|
---|
| 607 | path = *p == '\\' ? p + 1 : p;
|
---|
| 608 | rootlevel = 1;
|
---|
| 609 | }
|
---|
| 610 | if (rootlevel == 1) // root path starts from server name
|
---|
| 611 | {
|
---|
| 612 | p = ph->fsphStrChr(path, '\\');
|
---|
| 613 | if (!p)
|
---|
| 614 | {
|
---|
| 615 | p = path + StrLen(path);
|
---|
| 616 | }
|
---|
| 617 | if (StrLen(tmp->server_name) != p - path
|
---|
| 618 | || (p == path || ph->fsphStrNICmp(path, tmp->server_name, p - path)))
|
---|
| 619 | {
|
---|
| 620 | StrNCpy(tmp->server_name, path, p - path);
|
---|
| 621 | tmp->server_name[p - path] = 0;
|
---|
| 622 | newlevel = 1;
|
---|
| 623 | }
|
---|
| 624 | path = *p == '\\' ? p + 1 : p;
|
---|
| 625 | rootlevel = 2;
|
---|
| 626 | }
|
---|
| 627 | if (rootlevel == 2) // root path starts from share name
|
---|
| 628 | {
|
---|
| 629 | p = ph->fsphStrChr(path, '\\');
|
---|
| 630 | if (!p)
|
---|
| 631 | {
|
---|
| 632 | p = path + StrLen(path);
|
---|
| 633 | }
|
---|
| 634 | if (StrLen(tmp->share_name) != (p - path)
|
---|
| 635 | || (p == path || ph->fsphStrNICmp(path, tmp->share_name, p - path)))
|
---|
| 636 | {
|
---|
| 637 | StrNCpy(tmp->share_name, path, p - path);
|
---|
| 638 | tmp->share_name[p - path] = 0;
|
---|
| 639 | newlevel = 1;
|
---|
| 640 | }
|
---|
| 641 | path = *p == '\\' ? p + 1 : p;
|
---|
| 642 | }
|
---|
| 643 | if (newlevel)
|
---|
| 644 | {
|
---|
[180] | 645 | // reconnect to server here, first test new connection
|
---|
| 646 | cli_state* tmp_cli = NULL;
|
---|
| 647 | rc = smbwrp_connect( &tmpRes, &tmp_cli);
|
---|
| 648 | if (!rc)
|
---|
[5] | 649 | {
|
---|
[180] | 650 | // new connection is ok, disconnect old one
|
---|
| 651 | cli_state* cli = pConn->cli;
|
---|
| 652 | smbwrp_disconnect( pRes, cli);
|
---|
| 653 | // save tmp data structure
|
---|
| 654 | memcpy( pRes, &tmpRes, sizeof( tmpRes));
|
---|
| 655 | // save new connection handle
|
---|
| 656 | pConn->cli = tmp_cli;
|
---|
[5] | 657 | }
|
---|
| 658 | }
|
---|
| 659 | }
|
---|
[180] | 660 |
|
---|
[5] | 661 | StrCpy(result, "\\");
|
---|
| 662 | StrNCat(result, path, CCHMAXPATH);
|
---|
[145] | 663 |
|
---|
[5] | 664 | return rc;
|
---|
| 665 | }
|
---|
| 666 |
|
---|
| 667 |
|
---|
[131] | 668 | // -------------------------------------------------------------
|
---|
[5] | 669 |
|
---|
[131] | 670 | /* check if the requested resource is available */
|
---|
| 671 | static int checkMountResource( Resource* pRes)
|
---|
| 672 | {
|
---|
| 673 | int rc;
|
---|
| 674 | unsigned long action;
|
---|
[157] | 675 | cli_state* cli = NULL;
|
---|
[145] | 676 | smbwrp_file file;
|
---|
[131] | 677 |
|
---|
| 678 | debug_printf("checkMountResource in tid#%d\n", _gettid());
|
---|
[145] | 679 | rc = smbwrp_connect( pRes, &cli);
|
---|
[179] | 680 | /* changed to real error codes SCS
|
---|
| 681 | if (rc)
|
---|
| 682 | rc = (rc == 7 ? ERROR_BAD_DEV_TYPE : ERROR_ACCESS_DENIED); */
|
---|
| 683 | switch (rc) {
|
---|
| 684 | case 0:
|
---|
| 685 | rc = NO_ERROR;
|
---|
| 686 | break;
|
---|
| 687 | case 1:
|
---|
| 688 | case 10:
|
---|
| 689 | case 11:
|
---|
| 690 | rc = ERROR_BAD_NET_NAME;
|
---|
| 691 | break;
|
---|
| 692 | case 2:
|
---|
| 693 | rc = ERROR_INIT_ROUTINE_FAILED;
|
---|
| 694 | break;
|
---|
| 695 | case 3:
|
---|
| 696 | rc = ERROR_BAD_NET_RESP;
|
---|
| 697 | break;
|
---|
| 698 | case 4:
|
---|
| 699 | rc = ERROR_NETWORK_BUSY;
|
---|
| 700 | break;
|
---|
| 701 | case 6:
|
---|
| 702 | rc = ERROR_NETWORK_ACCESS_DENIED;
|
---|
| 703 | break;
|
---|
| 704 | case 7:
|
---|
| 705 | rc = ERROR_BAD_NETPATH;
|
---|
| 706 | break;
|
---|
| 707 | default:
|
---|
| 708 | rc = ERROR_UNEXP_NET_ERR;
|
---|
| 709 | break;
|
---|
| 710 | } /* endswitch */
|
---|
| 711 |
|
---|
[145] | 712 | smbwrp_disconnect( pRes, cli);
|
---|
[131] | 713 |
|
---|
| 714 | return rc;
|
---|
| 715 | }
|
---|
| 716 |
|
---|
[5] | 717 | int APIENTRY NdpMountResource (HRESOURCE *presource, int type, NDPROPERTYHANDLE properties)
|
---|
| 718 | {
|
---|
| 719 | int rc = NO_ERROR;
|
---|
| 720 | unsigned long objany = OBJ_ANY;
|
---|
| 721 | Resource *pRes = NULL;
|
---|
[131] | 722 |
|
---|
[189] | 723 | debuglocal(9,"NdpMountResource in\n");
|
---|
[131] | 724 |
|
---|
[145] | 725 | // init code
|
---|
[179] | 726 | smbwrp_init();
|
---|
[145] | 727 |
|
---|
[131] | 728 | /* since samba plugin support only 1 type of resources we do not need */
|
---|
[5] | 729 | /* to check what the found type really is */
|
---|
[145] | 730 | pRes = malloc( sizeof(Resource));
|
---|
| 731 | if (pRes == NULL)
|
---|
[5] | 732 | {
|
---|
| 733 | rc = ERROR_NOT_ENOUGH_MEMORY;
|
---|
[145] | 734 | }
|
---|
| 735 | else
|
---|
[5] | 736 | {
|
---|
| 737 | MemSet(pRes, 0, sizeof(Resource));
|
---|
[145] | 738 | //pRes->objany = objany;
|
---|
[131] | 739 | // parse init string
|
---|
[145] | 740 | rc = initResource (pRes, properties);
|
---|
[131] | 741 | // try to connect to resource (check type) only if thread!=1, so ndctl startup
|
---|
| 742 | // is not slowed down by network connections.
|
---|
| 743 | // ndctl does mounting on main thread (#1)
|
---|
| 744 | // nd/ndpm do not use main thread
|
---|
| 745 | if (!rc && _gettid()!=1)
|
---|
| 746 | rc = checkMountResource( pRes);
|
---|
| 747 | if (!rc)
|
---|
[5] | 748 | {
|
---|
[131] | 749 | // store resource data
|
---|
[5] | 750 | *presource = (HRESOURCE)pRes;
|
---|
| 751 | }
|
---|
| 752 | else
|
---|
| 753 | {
|
---|
[145] | 754 | free(pRes);
|
---|
[5] | 755 | }
|
---|
| 756 | }
|
---|
[189] | 757 | debuglocal(9,"NdpMountResource rc=%d\n", rc);
|
---|
[5] | 758 | return rc;
|
---|
| 759 | }
|
---|
| 760 |
|
---|
[131] | 761 | // -------------------------------------------------------------
|
---|
| 762 |
|
---|
[145] | 763 | int APIENTRY NdpFreeResource (HRESOURCE resource)
|
---|
[5] | 764 | {
|
---|
[145] | 765 | Resource *pRes = (Resource *)resource;
|
---|
[497] | 766 | dircache_delete(pRes->pdc);
|
---|
[145] | 767 | MemSet(&pRes->srv, 0, sizeof(pRes->srv));
|
---|
| 768 | free(pRes);
|
---|
[189] | 769 | debuglocal(9,"NdpFreeResource %d\n", NO_ERROR);
|
---|
[145] | 770 | return NO_ERROR;
|
---|
[5] | 771 | }
|
---|
| 772 |
|
---|
[131] | 773 | // -------------------------------------------------------------
|
---|
[5] | 774 |
|
---|
| 775 | int APIENTRY NdpRsrcCompare (HRESOURCE resource, HRESOURCE resource2)
|
---|
| 776 | {
|
---|
| 777 | Resource *pRes = (Resource *)resource;
|
---|
| 778 | Resource *pRes2 = (Resource *)resource2;
|
---|
| 779 | int rc = ND_RSRC_DIFFERENT;
|
---|
| 780 |
|
---|
[189] | 781 | debuglocal(9,"NdpRsrcCompare in\n");
|
---|
[5] | 782 | if (ph->fsphStrICmp(pRes->srv.server_name, pRes2->srv.server_name) == 0
|
---|
| 783 | && ph->fsphStrICmp(pRes->srv.share_name, pRes2->srv.share_name) == 0
|
---|
| 784 | && ph->fsphStrICmp(pRes->srv.username, pRes2->srv.username) == 0
|
---|
| 785 | && ph->fsphStrICmp(pRes->srv.workgroup, pRes2->srv.workgroup) == 0)
|
---|
| 786 | {
|
---|
| 787 | // resources are equal
|
---|
| 788 | rc = ND_RSRC_EQUAL;
|
---|
| 789 | }
|
---|
| 790 |
|
---|
[189] | 791 | debuglocal(9,"NdpRsrcCompare %d\n", rc);
|
---|
[5] | 792 |
|
---|
| 793 | return rc;
|
---|
| 794 | }
|
---|
| 795 |
|
---|
| 796 | int APIENTRY NdpRsrcUpdate (HRESOURCE resource, HRESOURCE resource2)
|
---|
| 797 | {
|
---|
| 798 | // do nothing
|
---|
[189] | 799 | debuglocal(9,"NdpRsrcUpdate %d\n", NO_ERROR);
|
---|
[5] | 800 | return NO_ERROR;
|
---|
| 801 | }
|
---|
| 802 |
|
---|
| 803 | int APIENTRY NdpRsrcQueryInfo (HRESOURCE resource, ULONG *pulFlags, void *pdata, ULONG insize, ULONG *poutlen)
|
---|
| 804 | {
|
---|
| 805 | Resource *pRes = (Resource *)resource;
|
---|
| 806 | int rc = NO_ERROR;
|
---|
| 807 | char s[4096];
|
---|
| 808 |
|
---|
[189] | 809 | debuglocal(9,"NdpRsrcQueryInfo in\n");
|
---|
[5] | 810 |
|
---|
| 811 | switch (pRes->rootlevel)
|
---|
| 812 | {
|
---|
| 813 | case 0:
|
---|
| 814 | {
|
---|
| 815 | ph->fsph_snprintf(s, sizeof(s) - 1, "SMBFS%s \\\\@%s", ifL ? "64" : "32", pRes->srv.username);
|
---|
| 816 | } break;
|
---|
| 817 | case 1:
|
---|
| 818 | {
|
---|
| 819 | ph->fsph_snprintf(s, sizeof(s) - 1, "SMBFS%s %s: \\\\@%s", ifL ? "64" : "32", pRes->srv.workgroup, pRes->srv.username);
|
---|
| 820 | } break;
|
---|
| 821 | case 2:
|
---|
| 822 | {
|
---|
| 823 | ph->fsph_snprintf(s, sizeof(s) - 1, "SMBFS%s \\\\%s%s%s@%s", ifL ? "64" : "32", *pRes->srv.workgroup ? pRes->srv.workgroup : "", *pRes->srv.workgroup ? ":" : "", pRes->srv.server_name, pRes->srv.username);
|
---|
| 824 | } break;
|
---|
| 825 | default:
|
---|
| 826 | {
|
---|
| 827 | ph->fsph_snprintf(s, sizeof(s) - 1, "SMBFS%s \\\\%s%s%s\\%s@%s", ifL ? "64" : "32", *pRes->srv.workgroup ? pRes->srv.workgroup : "", *pRes->srv.workgroup ? ":" : "", pRes->srv.server_name, pRes->srv.share_name, pRes->srv.username);
|
---|
| 828 | } break;
|
---|
| 829 | }
|
---|
| 830 | *poutlen = StrLen(s) + 1;
|
---|
| 831 | if (*poutlen > insize)
|
---|
| 832 | {
|
---|
| 833 | rc = ERROR_BUFFER_OVERFLOW;
|
---|
| 834 | }
|
---|
| 835 | else
|
---|
| 836 | {
|
---|
| 837 | MemCpy(pdata, s, *poutlen);
|
---|
| 838 | }
|
---|
| 839 |
|
---|
[189] | 840 | debuglocal(9,"NdpRsrcQueryInfo %d\n", rc);
|
---|
[5] | 841 |
|
---|
| 842 | return rc;
|
---|
| 843 | }
|
---|
| 844 |
|
---|
| 845 | int APIENTRY NdpRsrcQueryFSAttach (HRESOURCE resource, void *pdata, ULONG insize, ULONG *poutlen)
|
---|
| 846 | {
|
---|
| 847 | ULONG ulDummy = 0;
|
---|
| 848 | /* just return the resource info string */
|
---|
| 849 | return NdpRsrcQueryInfo (resource, &ulDummy, pdata, insize, poutlen);
|
---|
| 850 | }
|
---|
| 851 |
|
---|
| 852 | int APIENTRY NdpRsrcQueryFSAllocate (HRESOURCE resource, NDFSALLOCATE *pfsa)
|
---|
| 853 | {
|
---|
[145] | 854 | Resource *pRes = (Resource *)resource;
|
---|
[5] | 855 | int rc = NO_ERROR, rc1;
|
---|
| 856 | unsigned long action = 0;
|
---|
[145] | 857 | smbwrp_file file;
|
---|
[157] | 858 | cli_state* cli = NULL;
|
---|
[145] | 859 | FSALLOCATE fsa;
|
---|
[5] | 860 |
|
---|
[189] | 861 | debuglocal(9,"NdpRsrcQueryFSAllocate %08x\n", pfsa);
|
---|
[5] | 862 |
|
---|
| 863 | if (!pfsa)
|
---|
| 864 | {
|
---|
| 865 | return NO_ERROR;
|
---|
| 866 | }
|
---|
| 867 |
|
---|
[145] | 868 | debug_printf("checkMountResource in tid#%d\n", _gettid());
|
---|
| 869 | rc = smbwrp_connect( pRes, &cli);
|
---|
[5] | 870 | if (rc)
|
---|
| 871 | {
|
---|
[189] | 872 | debuglocal(9,"NdpCreateConnection failed rc=%d\n", rc);
|
---|
[145] | 873 | pfsa->cSectorUnit = 1;
|
---|
| 874 | pfsa->cUnit = 123456;
|
---|
| 875 | pfsa->cUnitAvail = 123456;
|
---|
| 876 | pfsa->cbSector = 2048;
|
---|
[150] | 877 | rc = (rc == 7 ? ERROR_BAD_DEV_TYPE : ERROR_ACCESS_DENIED);
|
---|
[145] | 878 | return rc;
|
---|
[5] | 879 | }
|
---|
| 880 |
|
---|
[145] | 881 | rc = smbwrp_dskattr( cli, &fsa);
|
---|
| 882 | if (rc)
|
---|
[5] | 883 | {
|
---|
| 884 | pfsa->cSectorUnit = 1;
|
---|
| 885 | pfsa->cUnit = 123456;
|
---|
| 886 | pfsa->cUnitAvail = 123456;
|
---|
| 887 | pfsa->cbSector = 2048;
|
---|
[145] | 888 | //rc = rc ? rc : (resp.rc ? resp.rc : ERROR_INVALID_PARAMETER);
|
---|
[5] | 889 | }
|
---|
| 890 | else
|
---|
| 891 | {
|
---|
[145] | 892 | pfsa->cSectorUnit = fsa.cSectorUnit;
|
---|
| 893 | pfsa->cUnit = fsa.cUnit;
|
---|
| 894 | pfsa->cUnitAvail = fsa.cUnitAvail;
|
---|
| 895 | pfsa->cbSector = fsa.cbSector;
|
---|
[5] | 896 | }
|
---|
| 897 |
|
---|
[145] | 898 | smbwrp_disconnect( pRes, cli);
|
---|
[5] | 899 |
|
---|
[189] | 900 | debuglocal(9,"NdpRsrcQueryFSAllocate %d/%d (cUnit = %d/cUnitAvail = %d/cbSector = %d)\n", rc, rc1, pfsa->cUnit, pfsa->cUnitAvail, pfsa->cbSector);
|
---|
[5] | 901 | return rc;
|
---|
| 902 | }
|
---|
| 903 |
|
---|
[145] | 904 | // -------------------------------------------------------------
|
---|
| 905 |
|
---|
| 906 | int APIENTRY NdpCreateConnection (HRESOURCE resource, HCONNECTION *pconn)
|
---|
[5] | 907 | {
|
---|
[145] | 908 | int rc = 0;
|
---|
| 909 | Resource * pRes = (Resource *)resource;
|
---|
[5] | 910 | unsigned long action;
|
---|
[145] | 911 | Connection *pConn = NULL;
|
---|
[5] | 912 |
|
---|
[189] | 913 | debuglocal(9,"NdpCreateConnection in\n");
|
---|
[145] | 914 |
|
---|
| 915 | pConn = malloc( sizeof(Connection));
|
---|
| 916 | if (pConn == NULL)
|
---|
[5] | 917 | {
|
---|
[145] | 918 | rc = ERROR_NOT_ENOUGH_MEMORY;
|
---|
| 919 | }
|
---|
| 920 | if (rc)
|
---|
| 921 | {
|
---|
[189] | 922 | debuglocal(9,"NdpCreateConnection ERROR_NOT_ENOUGH_MEMORY %d\n", rc);
|
---|
[145] | 923 | return rc;
|
---|
| 924 | }
|
---|
| 925 | MemSet(pConn, 0, sizeof(Connection));
|
---|
| 926 | pConn->pRes = pRes;
|
---|
| 927 | pConn->file.fd = -1;
|
---|
[5] | 928 |
|
---|
[189] | 929 | debuglocal(9,"NdpCreateConnection send CONNECT\n");
|
---|
[145] | 930 | rc = smbwrp_connect( pRes, &pConn->cli);
|
---|
| 931 | if (rc)
|
---|
| 932 | {
|
---|
| 933 | free(pConn);
|
---|
| 934 | pConn = NULL;
|
---|
[150] | 935 | rc = (rc == 7 ? ERROR_BAD_DEV_TYPE : ERROR_INVALID_PARAMETER);
|
---|
[145] | 936 | }
|
---|
[5] | 937 |
|
---|
[145] | 938 | *pconn = (HCONNECTION)pConn;
|
---|
[507] | 939 | debuglocal(9,"NdpCreateConnection [%p] %d\n", pConn, rc);
|
---|
[145] | 940 | return rc;
|
---|
| 941 | }
|
---|
[5] | 942 |
|
---|
[145] | 943 | // -------------------------------------------------------------
|
---|
[5] | 944 |
|
---|
[145] | 945 | int APIENTRY NdpFreeConnection (HCONNECTION conn)
|
---|
| 946 | {
|
---|
| 947 | Connection *pConn = (Connection *)conn;
|
---|
| 948 | Resource *pRes = pConn->pRes;
|
---|
| 949 | int rc;
|
---|
| 950 |
|
---|
[507] | 951 | debuglocal(9,"NdpFreeConnection in [%p]\n", pConn);
|
---|
[145] | 952 | if (pConn->file.fd >= 0)
|
---|
| 953 | {
|
---|
| 954 | rc = smbwrp_close( pConn->cli, &pConn->file);
|
---|
| 955 | pConn->file.fd = -1;
|
---|
| 956 | }
|
---|
| 957 |
|
---|
| 958 | smbwrp_disconnect( pRes, pConn->cli);
|
---|
| 959 |
|
---|
| 960 | free(pConn);
|
---|
[189] | 961 | debuglocal(9,"NdpFreeConnection %d\n", NO_ERROR);
|
---|
[145] | 962 | return NO_ERROR;
|
---|
[5] | 963 | }
|
---|
| 964 |
|
---|
[145] | 965 | // -------------------------------------------------------------
|
---|
| 966 |
|
---|
[150] | 967 | /*
|
---|
| 968 | * NdpQueryPathInfo is the most important function :) netdrive always calls
|
---|
| 969 | * the function before every operation to find out the path status: does it exist, is it a file, does a
|
---|
| 970 | * parent directory exist, etc.
|
---|
| 971 | * Plugin must return one of the following error codes:
|
---|
| 972 | * NO_ERROR - path exists and the path information have been successfully retrieved.
|
---|
| 973 | * ERROR_FILE_NOT_FOUND - all but the last component of the path exist and the
|
---|
| 974 | * path without the last component is a directory. dir1_ok\dir2_ok\does_not_exist.
|
---|
| 975 | * the wildcard can not exist, so the plugin returns FILE_NOT_FOUND, if the parent
|
---|
| 976 | * directory exist.
|
---|
| 977 | * ERROR_PATH_NOT_FOUND - any of not last path components does not exist, or all
|
---|
| 978 | * but the last component exist and is a file: \dir_ok\dir2_ok\file_ok\non_existing.
|
---|
| 979 | * ERROR_REM_NOT_LIST - resource is temporarily unavailable for some reasons.
|
---|
| 980 | * Any other error codes means an internal plugin error, not related to the status
|
---|
| 981 | * of the path queried.
|
---|
| 982 | */
|
---|
[5] | 983 | int APIENTRY NdpQueryPathInfo (HCONNECTION conn, void *plist, char *szPath)
|
---|
| 984 | {
|
---|
| 985 | Connection *pConn = (Connection *)conn;
|
---|
| 986 | Resource *pRes = pConn->pRes;
|
---|
[145] | 987 | smbwrp_fileinfo finfo;
|
---|
[5] | 988 | int rc = 0;
|
---|
| 989 | unsigned long action;
|
---|
| 990 | char path[CCHMAXPATH+1] = {0};
|
---|
[121] | 991 | int retry = 0;
|
---|
[5] | 992 |
|
---|
[507] | 993 | debuglocal(9,"NdpQueryPathInfo in [%p] <%s>, retry = %d\n", pConn, szPath, retry);
|
---|
[150] | 994 |
|
---|
| 995 | // is wildcard is specified, we suppose parent dir exist, so exit immediately
|
---|
| 996 | if (ph->fsphStrChr(szPath, '*') || ph->fsphStrChr(szPath, '?'))
|
---|
| 997 | {
|
---|
| 998 | return ERROR_FILE_NOT_FOUND;
|
---|
| 999 | }
|
---|
[5] | 1000 |
|
---|
[150] | 1001 |
|
---|
[121] | 1002 | do {
|
---|
[497] | 1003 | /* First check if there is information in the directory cache. */
|
---|
| 1004 | unsigned long ulAge = 0;
|
---|
| 1005 | if (dircache_find_path(pRes->pdc, szPath, &finfo, &ulAge))
|
---|
| 1006 | {
|
---|
| 1007 | if (ulAge <= 15) /* @todo configurable. */
|
---|
| 1008 | {
|
---|
| 1009 | rc = NO_ERROR;
|
---|
| 1010 | finfo.easize = -1;
|
---|
| 1011 | getfindinfoL(pConn, plist, &finfo, 0, NULL);
|
---|
| 1012 | break;
|
---|
| 1013 | }
|
---|
| 1014 | }
|
---|
[5] | 1015 |
|
---|
[121] | 1016 | rc = pathparser(pRes, pConn, szPath, path);
|
---|
[189] | 1017 | debuglocal(9,"NdpQueryPathInfo pathparser for <%s> rc=%d\n", path, rc);
|
---|
[121] | 1018 | switch (rc)
|
---|
[5] | 1019 | {
|
---|
| 1020 | case NO_ERROR :
|
---|
| 1021 | case ERROR_FILE_NOT_FOUND:
|
---|
| 1022 | case ERROR_PATH_NOT_FOUND:
|
---|
| 1023 | case ERROR_ACCESS_DENIED:
|
---|
| 1024 | case ERROR_INVALID_PARAMETER:
|
---|
[121] | 1025 | {
|
---|
[5] | 1026 | break;
|
---|
[121] | 1027 | }
|
---|
[5] | 1028 | default :
|
---|
[121] | 1029 | {
|
---|
| 1030 | rc = ERROR_PATH_NOT_FOUND;
|
---|
[5] | 1031 | }
|
---|
| 1032 | }
|
---|
[121] | 1033 | if (rc)
|
---|
[5] | 1034 | {
|
---|
[121] | 1035 | break;
|
---|
[5] | 1036 | }
|
---|
[145] | 1037 | StrNCpy(finfo.fname, path, sizeof(finfo.fname) - 1);
|
---|
[189] | 1038 | debuglocal(9,"NdpQueryPathInfo smbwrp_getattr for <%s>\n", path);
|
---|
[145] | 1039 | rc = smbwrp_getattr( &pRes->srv, pConn->cli, &finfo);
|
---|
| 1040 | if (rc)
|
---|
[121] | 1041 | {
|
---|
[150] | 1042 | // remote server not available for first time?
|
---|
| 1043 | if (rc == ERROR_REM_NOT_LIST && retry == 0)
|
---|
| 1044 | {
|
---|
| 1045 | // free current cli resources
|
---|
| 1046 | smbwrp_disconnect( pRes, pConn->cli);
|
---|
| 1047 | // reconnect
|
---|
| 1048 | smbwrp_connect( pRes, &pConn->cli);
|
---|
| 1049 | // try file list again
|
---|
| 1050 | rc = smbwrp_getattr( &pRes->srv, pConn->cli, &finfo);
|
---|
[189] | 1051 | debuglocal(9,"NdpQueryPathInfo remote connection lost, retry rc = %d\n", rc);
|
---|
[150] | 1052 | }
|
---|
[145] | 1053 | switch (rc)
|
---|
[121] | 1054 | {
|
---|
| 1055 | case NO_ERROR :
|
---|
| 1056 | case ERROR_FILE_NOT_FOUND:
|
---|
| 1057 | case ERROR_PATH_NOT_FOUND:
|
---|
| 1058 | case ERROR_ACCESS_DENIED:
|
---|
| 1059 | case ERROR_INVALID_PARAMETER:
|
---|
[150] | 1060 | case ERROR_REM_NOT_LIST:
|
---|
[121] | 1061 | break;
|
---|
| 1062 | default :
|
---|
| 1063 | {
|
---|
[145] | 1064 | rc = ERROR_PATH_NOT_FOUND;
|
---|
[121] | 1065 | }
|
---|
| 1066 | }
|
---|
| 1067 | }
|
---|
[527] | 1068 |
|
---|
| 1069 | if (rc == NO_ERROR)
|
---|
| 1070 | {
|
---|
[145] | 1071 | finfo.easize = -1;
|
---|
| 1072 | getfindinfoL(pConn, plist, &finfo, 0, NULL);
|
---|
[5] | 1073 | }
|
---|
[527] | 1074 | else if (rc == ERROR_FILE_NOT_FOUND)
|
---|
[5] | 1075 | {
|
---|
[121] | 1076 | // now try the upper path
|
---|
[527] | 1077 | char * p = ph->fsphStrRChr(finfo.fname, '\\');
|
---|
[145] | 1078 | if (p && p > finfo.fname)
|
---|
[121] | 1079 | {
|
---|
| 1080 | *p = 0;
|
---|
[145] | 1081 | rc = smbwrp_getattr( &pRes->srv, pConn->cli, &finfo);
|
---|
[527] | 1082 | debuglocal(9,"NdpQueryPathInfo upper path in <%s>, rc = %d\n", finfo.fname, rc);
|
---|
| 1083 | if (rc == NO_ERROR)
|
---|
[121] | 1084 | {
|
---|
[527] | 1085 | rc = (finfo.attr & FILE_DIRECTORY) !=0 ?
|
---|
[532] | 1086 | ERROR_FILE_NOT_FOUND:
|
---|
| 1087 | ERROR_PATH_NOT_FOUND;
|
---|
[121] | 1088 | }
|
---|
[527] | 1089 | else if (rc != ERROR_REM_NOT_LIST)
|
---|
| 1090 | {
|
---|
| 1091 | rc = ERROR_PATH_NOT_FOUND;
|
---|
| 1092 | }
|
---|
[5] | 1093 | }
|
---|
| 1094 | }
|
---|
[121] | 1095 | } while (0);
|
---|
[189] | 1096 | debuglocal(9,"NdpQueryPathInfo <%s> (%s) %d\n", szPath, path, rc);
|
---|
[145] | 1097 |
|
---|
[5] | 1098 | return rc;
|
---|
| 1099 | }
|
---|
| 1100 |
|
---|
[145] | 1101 | // -------------------------------------------------------------
|
---|
| 1102 |
|
---|
| 1103 | int APIENTRY NdpFindStart (HCONNECTION conn, void *plist, NDFILEINFOL *pfiparent, char *szPath, ULONG ulAttribute)
|
---|
| 1104 | {
|
---|
| 1105 | Connection *pConn = (Connection *)conn;
|
---|
| 1106 | Resource *pRes = pConn->pRes;
|
---|
| 1107 | int rc = NO_ERROR, count = 0;
|
---|
| 1108 | unsigned long action;
|
---|
| 1109 | char *mask = "*";
|
---|
| 1110 | char dir[CCHMAXPATH+1] = {0};
|
---|
| 1111 | char path[CCHMAXPATH+1] = {0};
|
---|
| 1112 | smbwrp_fileinfo * data;
|
---|
| 1113 | NDPATHELEMENT *pel = ph->fsphNameElem(0);
|
---|
| 1114 | filelist_state state;
|
---|
| 1115 | char * p;
|
---|
| 1116 |
|
---|
[507] | 1117 | debug_printf("NdpFindStart in [%p]\n", pConn);
|
---|
[145] | 1118 |
|
---|
| 1119 | StrNCpy(dir, szPath, sizeof(dir) - 1);
|
---|
| 1120 | if (pel)
|
---|
| 1121 | {
|
---|
| 1122 | mask = pel->name;
|
---|
| 1123 | dir[StrLen(szPath) - pel->length] = 0;
|
---|
| 1124 | }
|
---|
| 1125 | action = StrLen(dir) - 1;
|
---|
| 1126 | if (dir[action] == '\\')
|
---|
| 1127 | {
|
---|
| 1128 | dir[action] = 0;
|
---|
| 1129 | }
|
---|
| 1130 | rc = pathparser(pRes, pConn, dir, path);
|
---|
| 1131 | if (rc)
|
---|
| 1132 | {
|
---|
| 1133 | return rc;
|
---|
| 1134 | }
|
---|
| 1135 | action = StrLen(path) - 1;
|
---|
| 1136 | if (path[action] != '\\')
|
---|
| 1137 | {
|
---|
| 1138 | StrNCat(path, "\\", sizeof(path) - 1);
|
---|
| 1139 | }
|
---|
| 1140 | StrCpy(dir, path);
|
---|
| 1141 | StrNCat(path, mask, sizeof(path) - 1);
|
---|
| 1142 |
|
---|
| 1143 | // this structure will be used by libsmb callbacks, so we store here all we need
|
---|
| 1144 | // to fill netdrive structures
|
---|
| 1145 | state.pConn = pConn;
|
---|
| 1146 | state.plist = plist;
|
---|
| 1147 | state.ulAttribute = ulAttribute;
|
---|
| 1148 | strcpy( state.dir, dir);
|
---|
| 1149 | strcpy( state.dir_mask, mask);
|
---|
| 1150 | strcpy( state.mask, path);
|
---|
[497] | 1151 | state.fullpath = szPath;
|
---|
| 1152 | /* This plugin always reads a complete directory listing and filters results
|
---|
| 1153 | * using actual mask (state.dir_mask) in getfindinfoL.
|
---|
| 1154 | * May be this was a workaround for some server bug.
|
---|
| 1155 | * If this will be changed, then directory listing cache must be changed too,
|
---|
| 1156 | * and must remember the mask, which was used to obtain a listing.
|
---|
| 1157 | * Now the directory cache saves complete directory listings and then uses them to find
|
---|
| 1158 | * information about single files.
|
---|
| 1159 | * However, with a directory cache, it is probably faster to get a full listing and
|
---|
| 1160 | * then use it to obtain info about separate files than to perform a network
|
---|
| 1161 | * list query operation using actual wild cards for each file. Some application,
|
---|
| 1162 | * for example OpenOffice, do this.
|
---|
| 1163 | */
|
---|
[145] | 1164 | p = getlastslash(state.mask);
|
---|
| 1165 | if (p)
|
---|
| 1166 | {
|
---|
| 1167 | *(p + 1) = '*';
|
---|
| 1168 | *(p + 2) = 0;
|
---|
| 1169 | }
|
---|
| 1170 | else
|
---|
| 1171 | {
|
---|
| 1172 | strcpy(state.mask, "\\*");
|
---|
| 1173 | }
|
---|
[497] | 1174 | debuglocal(9,"NdpFindStart: dir [%s], dir_mask [%s], mask [%s], szPath [%s]\n",
|
---|
| 1175 | state.dir, state.dir_mask, state.mask, state.fullpath);
|
---|
[145] | 1176 | rc = smbwrp_filelist( &pRes->srv, pConn->cli, &state);
|
---|
[150] | 1177 | // we need to handle reconnection also here, because NdpQueryPathInfo
|
---|
| 1178 | // could be called with '*' and exit then immediately (without calling libsmb)
|
---|
| 1179 | if (rc == ERROR_REM_NOT_LIST)
|
---|
| 1180 | {
|
---|
| 1181 | // free current cli resources
|
---|
| 1182 | smbwrp_disconnect( pRes, pConn->cli);
|
---|
| 1183 | // reconnect
|
---|
| 1184 | smbwrp_connect( pRes, &pConn->cli);
|
---|
| 1185 | // try file list again next loop
|
---|
| 1186 | rc = smbwrp_filelist( &pRes->srv, pConn->cli, &state);
|
---|
[189] | 1187 | debuglocal(9,"NdpFindStart remote connection lost, retry rc = %d\n", rc);
|
---|
[150] | 1188 | }
|
---|
[145] | 1189 |
|
---|
[189] | 1190 | debuglocal(9,"NdpFindStart <%s> (%s) cnt %d %d\n", szPath, path, count, rc);
|
---|
[145] | 1191 |
|
---|
| 1192 | return rc;
|
---|
| 1193 | }
|
---|
| 1194 |
|
---|
[5] | 1195 | int APIENTRY NdpDeletePathInfo (HRESOURCE resource, NDFILEINFOL *pfi)
|
---|
| 1196 | {
|
---|
[189] | 1197 | // debuglocal(9,"NdpDeletePathInfo %d\n", 0);
|
---|
[5] | 1198 | return NO_ERROR;
|
---|
| 1199 | }
|
---|
| 1200 |
|
---|
| 1201 | int APIENTRY NdpRefresh (HCONNECTION conn, char *path, int tree)
|
---|
| 1202 | {
|
---|
[189] | 1203 | debuglocal(9,"NdpRefresh <%s> %d\n", path, 0);
|
---|
[5] | 1204 | return NO_ERROR;
|
---|
| 1205 | }
|
---|
| 1206 |
|
---|
| 1207 | int APIENTRY NdpDiscardResourceData (HRESOURCE resource, NDDATABUF *pdatabuf)
|
---|
| 1208 | {
|
---|
| 1209 | // The plugin do not have to deallocate anything
|
---|
| 1210 | // because resource data did not contain any pointers
|
---|
| 1211 | // to plugins data.
|
---|
| 1212 | // Data stored by fsphSetResourceData will be
|
---|
| 1213 | // deallocated by NetDrive.
|
---|
| 1214 |
|
---|
[189] | 1215 | debuglocal(9,"NdpDicardresourceData %d\n", 0);
|
---|
[5] | 1216 | return NO_ERROR;
|
---|
| 1217 | }
|
---|
| 1218 |
|
---|
| 1219 | int APIENTRY NdpSetPathInfo (HCONNECTION conn, NDFILEINFOL *pfi, char *szPathName)
|
---|
| 1220 | {
|
---|
| 1221 | Connection *pConn = (Connection *)conn;
|
---|
| 1222 | Resource *pRes = pConn->pRes;
|
---|
| 1223 | int rc = 0;
|
---|
| 1224 | unsigned long action;
|
---|
| 1225 | char path[CCHMAXPATH+1] = {0};
|
---|
[145] | 1226 | smbwrp_fileinfo finfo;
|
---|
[5] | 1227 |
|
---|
[510] | 1228 | debug_printf("NdpSetPathInfo in [%p]\n", pConn);
|
---|
[145] | 1229 |
|
---|
[510] | 1230 | // delete the dir cache
|
---|
| 1231 | dircache_invalidate(szPathName, pRes->pdc, 1);
|
---|
| 1232 |
|
---|
[5] | 1233 | do {
|
---|
| 1234 | rc = pathparser(pRes, pConn, szPathName, path);
|
---|
| 1235 | if (rc)
|
---|
| 1236 | {
|
---|
| 1237 | break;
|
---|
| 1238 | }
|
---|
| 1239 |
|
---|
[145] | 1240 | MemSet(&finfo, 0, sizeof(finfo));
|
---|
[5] | 1241 |
|
---|
[145] | 1242 | StrNCpy(finfo.fname, path, sizeof(finfo.fname) - 1);
|
---|
| 1243 | fsphDosDateToUnixTime(pfi->stat.fdateLastWrite, pfi->stat.ftimeLastWrite, &(finfo.mtime));
|
---|
| 1244 | finfo.attr = pfi->stat.attrFile & 0x37;
|
---|
| 1245 | rc = smbwrp_setattr(pConn->cli, &finfo);
|
---|
[5] | 1246 | } while (0);
|
---|
[189] | 1247 | debuglocal(9,"NdpSetPathInfo <%s> (%s) %d\n", szPathName, path, rc);
|
---|
[145] | 1248 |
|
---|
[5] | 1249 | return rc;
|
---|
| 1250 | }
|
---|
| 1251 |
|
---|
| 1252 | int buildFEALIST(FEALIST *pFEASrc, GEALIST *pGEAList, FEALIST *pFEAList)
|
---|
| 1253 | {
|
---|
| 1254 | int rc = 0;
|
---|
| 1255 | FEA * pfea;
|
---|
| 1256 | FEA * pfeadest;
|
---|
| 1257 | unsigned long size, done = sizeof(pFEAList->cbList), dsize, ddone = sizeof(pFEAList->cbList);
|
---|
| 1258 |
|
---|
| 1259 | size = pFEASrc->cbList;
|
---|
| 1260 | pfea = pFEASrc->list;
|
---|
| 1261 | pfeadest = pFEAList->list;
|
---|
| 1262 | dsize = pFEAList->cbList;
|
---|
[189] | 1263 | //debuglocal(9,"buildFEALIST in destsize %d srcsize %d pGEAList=%08x pGEAList->cbList=%d\n", dsize, ddone, size, pGEAList, pGEAList ? pGEAList->cbList : 0);
|
---|
[5] | 1264 | while (done < size)
|
---|
| 1265 | {
|
---|
| 1266 | char * name = (char *)(pfea + 1);
|
---|
| 1267 | int insert = 1;
|
---|
| 1268 | if (pGEAList && pGEAList->cbList > sizeof(pGEAList->cbList))
|
---|
| 1269 | {
|
---|
| 1270 | GEA * pgea = pGEAList->list;
|
---|
| 1271 | unsigned long size = pGEAList->cbList - sizeof(pGEAList->cbList), done = 0;
|
---|
| 1272 | insert = 0;
|
---|
| 1273 | while (done < size)
|
---|
| 1274 | {
|
---|
[189] | 1275 | //debuglocal(9,"comp <%s> <%s>\n", name, pgea->szName);
|
---|
[5] | 1276 | if (!ph->fsphStrNCmp(name, pgea->szName, pgea->cbName))
|
---|
| 1277 | {
|
---|
| 1278 | insert = 1;
|
---|
| 1279 | break;
|
---|
| 1280 | }
|
---|
| 1281 | done += pgea->cbName + 2;
|
---|
| 1282 | pgea = (GEA *)((char *)pgea + pgea->cbName + 2);
|
---|
| 1283 | }
|
---|
| 1284 | }
|
---|
| 1285 | if (insert)
|
---|
| 1286 | {
|
---|
| 1287 | ddone += sizeof(FEA) + pfea->cbName + 1 + pfea->cbValue;
|
---|
| 1288 | if (ddone <= dsize)
|
---|
| 1289 | {
|
---|
| 1290 | pfeadest->cbName = pfea->cbName;
|
---|
| 1291 | pfeadest->cbValue = pfea->cbValue;
|
---|
| 1292 | pfeadest->fEA = 0;
|
---|
| 1293 | StrCpy((char *)(pfeadest + 1), name);
|
---|
| 1294 | MemCpy((char *)(pfeadest + 1) + pfea->cbName + 1, (char *)(pfea + 1) + pfea->cbName + 1, pfea->cbValue);
|
---|
| 1295 | pfeadest = (FEA *)((char *)pFEAList + ddone);
|
---|
| 1296 | }
|
---|
| 1297 | }
|
---|
| 1298 | done += sizeof(FEA) + pfea->cbName + 1 + pfea->cbValue;
|
---|
[189] | 1299 | //debuglocal(9,"buuildfea <%s> insert=%d pfea->cbName=%d pfea->cbValue=%d srcdone=%d destdone=%d pfeadest=%08x pfea=%08x\n", name, insert, pfea->cbName, pfea->cbValue, done, ddone, pfeadest, pfea);
|
---|
[5] | 1300 | pfea = (FEA *)((char *)pFEASrc + done);
|
---|
| 1301 | }
|
---|
| 1302 | pFEAList->cbList = ddone;
|
---|
| 1303 | if (ddone > dsize && dsize > sizeof(pFEAList->cbList))
|
---|
| 1304 | {
|
---|
| 1305 | rc = ERROR_BUFFER_OVERFLOW;
|
---|
| 1306 | }
|
---|
[189] | 1307 | debuglocal(9,"buildFEALIST rc=%d destsize=%d destdone=%d srcsize=%d pGEAList=%08x\n", rc, dsize, ddone, size, pGEAList);
|
---|
[5] | 1308 | return rc;
|
---|
| 1309 | }
|
---|
| 1310 |
|
---|
| 1311 | int APIENTRY NdpEAQuery (HCONNECTION conn, GEALIST *pGEAList, NDFILEINFOL *pfi, FEALIST *pFEAList)
|
---|
| 1312 | {
|
---|
| 1313 | Connection *pConn = (Connection *)conn;
|
---|
| 1314 | Resource *pRes = pConn->pRes;
|
---|
| 1315 | int rc = 0;
|
---|
| 1316 | unsigned long action;
|
---|
| 1317 | char * path = NULL;
|
---|
| 1318 | FEALIST * pFEASrc;
|
---|
| 1319 | NDDATABUF fdata = {0};
|
---|
[7] | 1320 | smbwrp_fileinfo *finfo;
|
---|
[145] | 1321 | char pBuffer[64*1024];
|
---|
[5] | 1322 |
|
---|
| 1323 | if (!pfi || !pfi->pszName || !pFEAList)
|
---|
| 1324 | {
|
---|
| 1325 | return ERROR_EAS_NOT_SUPPORTED;
|
---|
| 1326 | }
|
---|
| 1327 | if (!pRes->easupport)
|
---|
| 1328 | {
|
---|
| 1329 | return ERROR_EAS_NOT_SUPPORTED;
|
---|
| 1330 | }
|
---|
| 1331 |
|
---|
| 1332 | rc = ph->fsphGetFileInfoData(pfi, &fdata, 0);
|
---|
| 1333 | if (rc || !fdata.ulSize || !fdata.pData)
|
---|
| 1334 | {
|
---|
[189] | 1335 | debuglocal(9,"NdpEAQuery: ph->fsphGetFileInfoData = %d/%d %08x\n", rc, fdata.ulSize, fdata.pData);
|
---|
[5] | 1336 | return ERROR_EAS_NOT_SUPPORTED;
|
---|
| 1337 | }
|
---|
[7] | 1338 | finfo = (smbwrp_fileinfo *)fdata.pData;
|
---|
| 1339 | path = finfo->fname;
|
---|
[5] | 1340 |
|
---|
[507] | 1341 | debuglocal(9,"NdpEAQuery in [%p] <%s> %08x %d\n", pConn, path, pGEAList, pGEAList ? pGEAList->cbList : 0);
|
---|
[145] | 1342 |
|
---|
[5] | 1343 | do {
|
---|
[145] | 1344 | rc = smbwrp_listea( pConn->cli, path, pBuffer, sizeof( pBuffer));
|
---|
| 1345 | pFEASrc = (FEALIST*) pBuffer;
|
---|
[5] | 1346 | if (rc)
|
---|
| 1347 | {
|
---|
[145] | 1348 | //rc = pConn->rc ? pConn->rc : (resp.rc ? resp.rc : ERROR_INVALID_PARAMETER);
|
---|
[5] | 1349 | switch (rc)
|
---|
| 1350 | {
|
---|
| 1351 | case ERROR_FILE_NOT_FOUND :
|
---|
| 1352 | case ERROR_PATH_NOT_FOUND :
|
---|
| 1353 | {
|
---|
| 1354 | pFEAList->cbList = sizeof(pFEAList->cbList);
|
---|
| 1355 | rc = NO_ERROR;
|
---|
| 1356 | } break;
|
---|
| 1357 | case ERROR_BUFFER_OVERFLOW :
|
---|
| 1358 | {
|
---|
| 1359 | pFEAList->cbList = pFEASrc->cbList;
|
---|
| 1360 | } break;
|
---|
| 1361 | default :
|
---|
| 1362 | {
|
---|
| 1363 | rc = ERROR_EAS_NOT_SUPPORTED;
|
---|
| 1364 | }
|
---|
| 1365 | }
|
---|
| 1366 | }
|
---|
| 1367 | else
|
---|
| 1368 | {
|
---|
[145] | 1369 | rc = buildFEALIST((FEALIST *)pFEASrc, pGEAList, pFEAList);
|
---|
[5] | 1370 | }
|
---|
| 1371 | } while (0);
|
---|
[189] | 1372 | debuglocal(9,"NdpEAQuery <%s> %d %d %d\n", pfi->pszName, rc, pFEASrc->cbList, pFEAList->cbList);
|
---|
[145] | 1373 |
|
---|
[5] | 1374 | return rc;
|
---|
| 1375 | }
|
---|
| 1376 |
|
---|
| 1377 | int APIENTRY NdpEASet (HCONNECTION conn, FEALIST *pFEAList, NDFILEINFOL *pfi)
|
---|
| 1378 | {
|
---|
| 1379 | Connection *pConn = (Connection *)conn;
|
---|
| 1380 | Resource *pRes = pConn->pRes;
|
---|
| 1381 | int rc = 0;
|
---|
| 1382 | char * path;
|
---|
| 1383 | unsigned long action;
|
---|
| 1384 | NDDATABUF fdata = {0};
|
---|
[7] | 1385 | smbwrp_fileinfo *finfo;
|
---|
[5] | 1386 |
|
---|
[507] | 1387 | debuglocal(9,"NdpEASet in [%p]\n", pConn);
|
---|
[5] | 1388 |
|
---|
| 1389 | if (!pfi || !pfi->pszName || !pFEAList || pFEAList->cbList <= sizeof(long))
|
---|
| 1390 | {
|
---|
| 1391 | return ERROR_EAS_NOT_SUPPORTED;
|
---|
| 1392 | }
|
---|
| 1393 | if (!pRes->easupport)
|
---|
| 1394 | {
|
---|
| 1395 | return ERROR_EAS_NOT_SUPPORTED;
|
---|
| 1396 | }
|
---|
| 1397 |
|
---|
| 1398 | rc = ph->fsphGetFileInfoData(pfi, &fdata, 0);
|
---|
| 1399 | if (rc || !fdata.ulSize || !fdata.pData)
|
---|
| 1400 | {
|
---|
[189] | 1401 | debuglocal(9,"NdpEASet: ph->fsphGetFileInfoData = %d/%d/%08x\n", rc, fdata.ulSize, fdata.pData);
|
---|
[5] | 1402 | return ERROR_EAS_NOT_SUPPORTED;
|
---|
| 1403 | }
|
---|
[7] | 1404 | finfo = (smbwrp_fileinfo *)fdata.pData;
|
---|
| 1405 | path = finfo->fname;
|
---|
[5] | 1406 |
|
---|
| 1407 | do {
|
---|
[145] | 1408 | // got FEA there
|
---|
| 1409 | FEA * pfea;
|
---|
| 1410 | unsigned long done = sizeof(long);
|
---|
| 1411 | pfea = pFEAList->list;
|
---|
| 1412 | while (done < pFEAList->cbList)
|
---|
[5] | 1413 | {
|
---|
[145] | 1414 | rc = smbwrp_setea(pConn->cli, path, (char*)(pfea + 1), pfea->cbValue ? (char *)(pfea + 1) + pfea->cbName + 1: NULL, pfea->cbValue);
|
---|
| 1415 | if (rc)
|
---|
| 1416 | {
|
---|
| 1417 | break;
|
---|
| 1418 | }
|
---|
| 1419 | pfea = (FEA *)((char *)(pfea + 1) + pfea->cbName + 1 + pfea->cbValue);
|
---|
| 1420 | done += sizeof(FEA) + pfea->cbName + 1 + pfea->cbValue;
|
---|
[5] | 1421 | }
|
---|
| 1422 | } while (0);
|
---|
[189] | 1423 | debuglocal(9,"NdpEASet %d\n", rc);
|
---|
[145] | 1424 |
|
---|
[5] | 1425 | return rc;
|
---|
| 1426 | }
|
---|
| 1427 |
|
---|
| 1428 | int APIENTRY NdpEASize (HCONNECTION conn, NDFILEINFOL *pfi, ULONG *pulEASize)
|
---|
| 1429 | {
|
---|
| 1430 | Connection *pConn = (Connection *)conn;
|
---|
| 1431 | Resource *pRes = pConn->pRes;
|
---|
| 1432 | int rc = 0;
|
---|
| 1433 | unsigned long action;
|
---|
| 1434 | char * path = NULL;
|
---|
| 1435 | FEALIST * pfealist;
|
---|
| 1436 | NDDATABUF fdata = {0};
|
---|
[7] | 1437 | smbwrp_fileinfo *finfo;
|
---|
[145] | 1438 | char pBuffer[64*1024];
|
---|
[5] | 1439 | int easize;
|
---|
| 1440 |
|
---|
| 1441 | if (!pfi || !pulEASize)
|
---|
| 1442 | {
|
---|
| 1443 | return ERROR_EAS_NOT_SUPPORTED;
|
---|
| 1444 | }
|
---|
| 1445 | if (!pRes->easupport)
|
---|
| 1446 | {
|
---|
| 1447 | return ERROR_EAS_NOT_SUPPORTED;
|
---|
| 1448 | }
|
---|
| 1449 |
|
---|
| 1450 | rc = ph->fsphGetFileInfoData(pfi, &fdata, 0);
|
---|
| 1451 | if (rc || !fdata.ulSize || !fdata.pData)
|
---|
| 1452 | {
|
---|
[189] | 1453 | debuglocal(9,"NdpEASize: ph->fsphGetFileInfoData = %d/%d/%08x\n", rc, fdata.ulSize, fdata.pData);
|
---|
[5] | 1454 | return ERROR_EAS_NOT_SUPPORTED;
|
---|
| 1455 | }
|
---|
[7] | 1456 | finfo = (smbwrp_fileinfo *)fdata.pData;
|
---|
| 1457 | easize = finfo->easize;
|
---|
| 1458 | finfo->easize = -1;
|
---|
| 1459 | path = finfo->fname;
|
---|
[5] | 1460 | if (easize >= 0)
|
---|
| 1461 | {
|
---|
| 1462 | *pulEASize = easize;
|
---|
[189] | 1463 | debuglocal(9,"NdpEASize <%s> cached %d\n", path, easize);
|
---|
[5] | 1464 | return NO_ERROR;
|
---|
| 1465 | }
|
---|
| 1466 |
|
---|
[507] | 1467 | debuglocal(9,"NdpEASize in [%p] <%s>\n", pConn, path);
|
---|
[145] | 1468 |
|
---|
[5] | 1469 | do {
|
---|
[145] | 1470 | rc = smbwrp_listea(pConn->cli, path, pBuffer, sizeof( pBuffer));
|
---|
| 1471 | pfealist = (FEALIST*)pBuffer;
|
---|
[5] | 1472 | if (rc)
|
---|
| 1473 | {
|
---|
[145] | 1474 | //rc = pConn->rc ? pConn->rc : (resp.rc ? resp.rc : ERROR_INVALID_PARAMETER);
|
---|
[5] | 1475 | switch (rc)
|
---|
| 1476 | {
|
---|
| 1477 | case ERROR_FILE_NOT_FOUND :
|
---|
| 1478 | case ERROR_PATH_NOT_FOUND :
|
---|
| 1479 | {
|
---|
| 1480 | pfealist->cbList = sizeof(pfealist->cbList);
|
---|
| 1481 | } /* Fall through */
|
---|
| 1482 | case ERROR_BUFFER_OVERFLOW :
|
---|
| 1483 | {
|
---|
| 1484 | rc = NO_ERROR;
|
---|
| 1485 | } break;
|
---|
| 1486 | default :
|
---|
| 1487 | {
|
---|
| 1488 | rc = ERROR_EAS_NOT_SUPPORTED;
|
---|
| 1489 | }
|
---|
| 1490 | }
|
---|
| 1491 | }
|
---|
| 1492 | *pulEASize = pfealist->cbList;
|
---|
| 1493 | } while (0);
|
---|
[189] | 1494 | debuglocal(9,"NdpEASize <%s> %d %d\n", pfi->pszName, *pulEASize, rc);
|
---|
[145] | 1495 |
|
---|
[5] | 1496 | return rc;
|
---|
| 1497 | }
|
---|
| 1498 |
|
---|
| 1499 | int APIENTRY NdpSetCurrentDir (HCONNECTION conn, NDFILEINFOL *pfi, char *szPath)
|
---|
| 1500 | {
|
---|
| 1501 | Connection *pConn = (Connection *)conn;
|
---|
| 1502 | Resource *pRes = pConn->pRes;
|
---|
| 1503 | int rc = 0;
|
---|
| 1504 | unsigned long action;
|
---|
| 1505 | char path[CCHMAXPATH+1] = {0};
|
---|
| 1506 |
|
---|
[507] | 1507 | debuglocal(9,"NdpSetCurrentDir in [%p]\n", pConn);
|
---|
[145] | 1508 |
|
---|
[5] | 1509 | do {
|
---|
| 1510 | rc = pathparser(pRes, pConn, szPath, path);
|
---|
| 1511 | if (rc)
|
---|
| 1512 | {
|
---|
| 1513 | break;
|
---|
| 1514 | }
|
---|
| 1515 |
|
---|
[145] | 1516 | rc = smbwrp_chdir(&pRes->srv, pConn->cli, path);
|
---|
[5] | 1517 | } while (0);
|
---|
[189] | 1518 | debuglocal(9,"NdpSetCurrentDir <%s> (%s) %d\n", szPath, path, rc);
|
---|
[145] | 1519 |
|
---|
[5] | 1520 | return rc;
|
---|
| 1521 | }
|
---|
| 1522 |
|
---|
| 1523 | int APIENTRY NdpCopy (HCONNECTION conn, NDFILEINFOL *pfiDst, char *szDst, NDFILEINFOL *pfiSrc, char *szSrc, ULONG ulOption)
|
---|
| 1524 | {
|
---|
[189] | 1525 | debuglocal(9,"NdpCopy <%s> -> <%s> %d\n", szSrc, szDst, ERROR_CANNOT_COPY);
|
---|
[5] | 1526 | return ERROR_CANNOT_COPY;
|
---|
| 1527 | }
|
---|
| 1528 |
|
---|
| 1529 | int APIENTRY NdpCopy2 (HCONNECTION conn, HRESOURCE resDst, NDFILEINFOL *pfiDst, char *szDst, NDFILEINFOL *pfiSrc, char *szSrc, ULONG ulOption)
|
---|
| 1530 | {
|
---|
[189] | 1531 | debuglocal(9,"NdpCopy2 <%s> -> <%s> %d\n", szSrc, szDst, ERROR_CANNOT_COPY);
|
---|
[5] | 1532 | return ERROR_CANNOT_COPY;
|
---|
| 1533 | }
|
---|
| 1534 |
|
---|
| 1535 | int APIENTRY NdpForceDelete (HCONNECTION conn, NDFILEINFOL *pfi, char *szFile)
|
---|
| 1536 | {
|
---|
| 1537 | Connection *pConn = (Connection *)conn;
|
---|
| 1538 | Resource *pRes = pConn->pRes;
|
---|
| 1539 | int rc = 0;
|
---|
| 1540 | unsigned long action;
|
---|
| 1541 | char path[CCHMAXPATH+1] = {0};
|
---|
| 1542 |
|
---|
[507] | 1543 | debuglocal(9,"NdpForceDelete in [%p]\n", pConn);
|
---|
[145] | 1544 |
|
---|
[497] | 1545 | dircache_invalidate(szFile, pRes->pdc, 1);
|
---|
| 1546 |
|
---|
[5] | 1547 | do {
|
---|
| 1548 | rc = pathparser(pRes, pConn, szFile, path);
|
---|
| 1549 | if (rc)
|
---|
| 1550 | {
|
---|
| 1551 | break;
|
---|
| 1552 | }
|
---|
| 1553 |
|
---|
[145] | 1554 | rc = smbwrp_unlink(pConn->cli, path);
|
---|
[5] | 1555 | } while (0);
|
---|
[189] | 1556 | debuglocal(9,"NdpForceDelete <%s> (%s) %d\n", szFile, path, rc);
|
---|
[145] | 1557 |
|
---|
[5] | 1558 | return rc;
|
---|
| 1559 | }
|
---|
| 1560 |
|
---|
| 1561 | int APIENTRY NdpCreateDir (HCONNECTION conn, NDFILEINFOL *pfiparent, char *szDirName, FEALIST *pFEAList)
|
---|
| 1562 | {
|
---|
| 1563 | Connection *pConn = (Connection *)conn;
|
---|
| 1564 | Resource *pRes = pConn->pRes;
|
---|
| 1565 | int rc = 0;
|
---|
| 1566 | unsigned long action;
|
---|
| 1567 | char path[CCHMAXPATH+1] = {0};
|
---|
| 1568 |
|
---|
[507] | 1569 | debuglocal(9,"NdpCreateDir in [%p]\n", pConn);
|
---|
[145] | 1570 |
|
---|
[497] | 1571 | dircache_invalidate(szDirName, pRes->pdc, 1);
|
---|
| 1572 |
|
---|
[5] | 1573 | do {
|
---|
| 1574 | rc = pathparser(pRes, pConn, szDirName, path);
|
---|
| 1575 | if (rc)
|
---|
| 1576 | {
|
---|
| 1577 | break;
|
---|
| 1578 | }
|
---|
| 1579 |
|
---|
[145] | 1580 | rc = smbwrp_mkdir(pConn->cli, path);
|
---|
[5] | 1581 | } while (0);
|
---|
[189] | 1582 | debuglocal(9,"NdpCreateDir <%s> (%s) %d\n", szDirName, path, rc);
|
---|
[145] | 1583 |
|
---|
[5] | 1584 | return rc;
|
---|
| 1585 | }
|
---|
| 1586 |
|
---|
| 1587 | int APIENTRY NdpDeleteDir (HCONNECTION conn, NDFILEINFOL *pfi, char *szDir)
|
---|
| 1588 | {
|
---|
| 1589 | Connection *pConn = (Connection *)conn;
|
---|
| 1590 | Resource *pRes = pConn->pRes;
|
---|
| 1591 | int rc = 0;
|
---|
| 1592 | unsigned long action;
|
---|
| 1593 | char path[CCHMAXPATH+1] = {0};
|
---|
| 1594 |
|
---|
[507] | 1595 | debuglocal(9,"NdpDeleteDir in [%p]\n", pConn);
|
---|
[145] | 1596 |
|
---|
[497] | 1597 | dircache_invalidate(szDir, pRes->pdc, 1);
|
---|
| 1598 |
|
---|
[5] | 1599 | do {
|
---|
| 1600 | rc = pathparser(pRes, pConn, szDir, path);
|
---|
| 1601 | if (rc)
|
---|
| 1602 | {
|
---|
| 1603 | break;
|
---|
| 1604 | }
|
---|
| 1605 |
|
---|
[145] | 1606 | rc = smbwrp_rmdir(pConn->cli, path);
|
---|
[5] | 1607 | } while (0);
|
---|
[189] | 1608 | debuglocal(9,"NdpDeleteDir <%s> (%s) %d\n", szDir, path, rc);
|
---|
[145] | 1609 |
|
---|
[5] | 1610 | return rc;
|
---|
| 1611 | }
|
---|
| 1612 |
|
---|
| 1613 | int APIENTRY NdpMove (HCONNECTION conn, NDFILEINFOL *pfiDst, char *szDst, NDFILEINFOL *pfiSrc, char *szSrc)
|
---|
| 1614 | {
|
---|
| 1615 | Connection *pConn = (Connection *)conn;
|
---|
| 1616 | Resource *pRes = pConn->pRes;
|
---|
| 1617 | int rc = 0;
|
---|
| 1618 | unsigned long action;
|
---|
| 1619 | char src[CCHMAXPATH+1] = {0};
|
---|
| 1620 | int l1, l2;
|
---|
| 1621 | char * p = szDst;
|
---|
| 1622 |
|
---|
[507] | 1623 | debuglocal(9,"NdpMove in [%p] from <%s> to <%s>\n", pConn, szSrc, szDst);
|
---|
[145] | 1624 |
|
---|
[497] | 1625 | dircache_invalidate(szSrc, pRes->pdc, 1);
|
---|
| 1626 | dircache_invalidate(szDst, pRes->pdc, 1);
|
---|
| 1627 |
|
---|
[5] | 1628 | do
|
---|
| 1629 | {
|
---|
| 1630 | rc = pathparser(pRes, pConn, szSrc, src);
|
---|
| 1631 | if (rc)
|
---|
| 1632 | {
|
---|
| 1633 | break;
|
---|
| 1634 | }
|
---|
| 1635 | l1 = StrLen(szSrc);
|
---|
| 1636 | l2 = StrLen(src);
|
---|
| 1637 | if (l1 > l2)
|
---|
| 1638 | {
|
---|
| 1639 | if (ph->fsphStrNICmp(szSrc, szDst, l1 - l2))
|
---|
| 1640 | {
|
---|
| 1641 | // the file moved accross different shares or servers or workgroups
|
---|
| 1642 | rc = ERROR_WRITE_PROTECT;
|
---|
| 1643 | break;
|
---|
| 1644 | }
|
---|
| 1645 | p = szDst + l1 - l2 + 1;
|
---|
| 1646 | }
|
---|
[145] | 1647 | //pConn->mem[CCHMAXPATH + 1] = '\\';
|
---|
| 1648 | rc = smbwrp_rename(pConn->cli, src, p);
|
---|
[5] | 1649 | } while (0);
|
---|
[189] | 1650 | debuglocal(9,"NdpMove <%s> -> <%s> (%s) %d\n", szSrc, szDst, src, rc);
|
---|
[5] | 1651 |
|
---|
| 1652 | return rc;
|
---|
| 1653 | }
|
---|
| 1654 |
|
---|
| 1655 | int APIENTRY NdpMove2 (HCONNECTION conn, HRESOURCE resDst, NDFILEINFOL *pfiDst, char *szDst, NDFILEINFOL *pfiSrc, char *szSrc)
|
---|
| 1656 | {
|
---|
[189] | 1657 | debuglocal(9,"NdpMove2 <%s> -> <%s> %d\n", szSrc, szDst, ERROR_WRITE_PROTECT);
|
---|
[5] | 1658 | return ERROR_WRITE_PROTECT;
|
---|
| 1659 | }
|
---|
| 1660 |
|
---|
| 1661 |
|
---|
| 1662 | int APIENTRY NdpChangeCase (HCONNECTION conn, char *szDst, NDFILEINFOL *pfiSrc, char *szSrc, char *szNewName, ULONG ulNameLen)
|
---|
| 1663 | {
|
---|
| 1664 | return NdpMove (conn, pfiSrc, szDst, pfiSrc, szSrc);
|
---|
| 1665 | }
|
---|
| 1666 |
|
---|
| 1667 | int APIENTRY NdpRename (HCONNECTION conn, char *szDst, NDFILEINFOL *pfiSrc, char *szSrc, char *szNewName, ULONG ulNameLen)
|
---|
| 1668 | {
|
---|
| 1669 | return NdpMove (conn, pfiSrc, szDst, pfiSrc, szSrc);
|
---|
| 1670 | }
|
---|
| 1671 |
|
---|
| 1672 | int smbopen(Connection *pConn, char *szFileName, int flags, ULONG ulOpenMode, ULONG ulAttribute, FEALIST *pFEAList)
|
---|
| 1673 | {
|
---|
| 1674 | Resource *pRes = pConn->pRes;
|
---|
| 1675 | unsigned long action;
|
---|
| 1676 | int rc = 0;
|
---|
| 1677 | char path[CCHMAXPATH+1] = {0};
|
---|
| 1678 |
|
---|
[507] | 1679 | debuglocal(9,"smbopen in [%p] %d\n", pConn, pConn->file.fd);
|
---|
[145] | 1680 |
|
---|
[497] | 1681 | if (flags & O_CREAT)
|
---|
| 1682 | {
|
---|
| 1683 | dircache_invalidate(szFileName, pRes->pdc, 1);
|
---|
| 1684 | }
|
---|
[5] | 1685 | do {
|
---|
| 1686 | if (pConn->file.fd > 0)
|
---|
| 1687 | {
|
---|
| 1688 | rc = ERROR_TOO_MANY_OPEN_FILES;
|
---|
| 1689 | break;
|
---|
| 1690 | }
|
---|
| 1691 |
|
---|
| 1692 | rc = pathparser(pRes, pConn, szFileName, path);
|
---|
| 1693 | if (rc)
|
---|
| 1694 | {
|
---|
| 1695 | break;
|
---|
| 1696 | }
|
---|
| 1697 |
|
---|
| 1698 | StrNCpy(pConn->file.fullname, szFileName, sizeof(pConn->file.fullname) - 1);
|
---|
| 1699 | StrNCpy(pConn->file.fname, path, sizeof(pConn->file.fname) - 1);
|
---|
| 1700 | flags |= O_BINARY;
|
---|
| 1701 | switch (ulOpenMode & 3)
|
---|
| 1702 | {
|
---|
| 1703 | case OPEN_ACCESS_READONLY : flags |= O_RDONLY; break;
|
---|
| 1704 | case OPEN_ACCESS_WRITEONLY : flags |= O_WRONLY; break;
|
---|
| 1705 | case OPEN_ACCESS_READWRITE : flags |= O_RDWR; break;
|
---|
| 1706 | default : flags |= O_RDWR;
|
---|
| 1707 | }
|
---|
| 1708 | pConn->file.openmode = flags;
|
---|
| 1709 | pConn->file.openattr = ulAttribute & 0x37;
|
---|
| 1710 | pConn->file.denymode = (ulOpenMode & 0x70) >> 4;
|
---|
[145] | 1711 | rc = smbwrp_open(pConn->cli, &pConn->file);
|
---|
[5] | 1712 | } while (0);
|
---|
[189] | 1713 | debuglocal(9,"smbopen <%s> (%s) %08x %08x %08x %d. file = %d\n", szFileName, path, flags, ulOpenMode, ulAttribute, rc, pConn->file.fd);
|
---|
[5] | 1714 | if (!rc && pFEAList)
|
---|
| 1715 | {
|
---|
| 1716 | int rc1 = NdpFileEASet((HCONNECTION)pConn, (NDFILEHANDLE)0, pFEAList);
|
---|
[189] | 1717 | debuglocal(9,"smbopen NdpFileEASet %d. pFEAList->cbList %d\n", rc1, pFEAList->cbList);
|
---|
[5] | 1718 | }
|
---|
| 1719 |
|
---|
| 1720 | return rc;
|
---|
| 1721 | }
|
---|
| 1722 |
|
---|
| 1723 | int APIENTRY NdpOpenReplace (HCONNECTION conn, NDFILEINFOL *pfi, NDFILEHANDLE *phandle, char *szFileName, ULONG ulSize, ULONG ulOpenMode, ULONG ulAttribute, FEALIST *pFEAList)
|
---|
| 1724 | {
|
---|
| 1725 | return smbopen((Connection *)conn, szFileName, O_TRUNC, ulOpenMode, ulAttribute, pFEAList);
|
---|
| 1726 | }
|
---|
| 1727 |
|
---|
| 1728 | int APIENTRY NdpOpenReplaceL(HCONNECTION conn, NDFILEINFO *pfi, NDFILEHANDLE *phandle, char *szFileName, LONGLONG llSize, ULONG ulOpenMode, ULONG ulAttribute, FEALIST *pFEAList)
|
---|
| 1729 | {
|
---|
| 1730 | return smbopen((Connection *)conn, szFileName, O_TRUNC, ulOpenMode, ulAttribute, pFEAList);
|
---|
| 1731 | }
|
---|
| 1732 |
|
---|
| 1733 | int APIENTRY NdpOpenCreate (HCONNECTION conn, NDFILEINFOL *pfiparent, NDFILEHANDLE *phandle, char *szFileName, ULONG ulSize, ULONG ulOpenMode, ULONG ulAttribute, FEALIST *pFEAList)
|
---|
| 1734 | {
|
---|
| 1735 | // return smbopen((Connection *)conn, szFileName, O_CREAT, ulOpenMode, ulAttribute);
|
---|
| 1736 | return smbopen((Connection *)conn, szFileName, O_CREAT | O_EXCL, ulOpenMode, ulAttribute, pFEAList);
|
---|
| 1737 | }
|
---|
| 1738 |
|
---|
| 1739 | int APIENTRY NdpOpenCreateL(HCONNECTION conn, NDFILEINFO *pfiparent, NDFILEHANDLE *phandle, char *szFileName, LONGLONG llSize, ULONG ulOpenMode, ULONG ulAttribute, FEALIST *pFEAList)
|
---|
| 1740 | {
|
---|
| 1741 | return smbopen((Connection *)conn, szFileName, O_CREAT | O_EXCL, ulOpenMode, ulAttribute, pFEAList);
|
---|
| 1742 | }
|
---|
| 1743 |
|
---|
| 1744 | int APIENTRY NdpOpenExisting (HCONNECTION conn, NDFILEINFOL *pfi, NDFILEHANDLE *phandle, char *szFileName, ULONG ulOpenMode, USHORT *pfNeedEA)
|
---|
| 1745 | {
|
---|
| 1746 | if (pfNeedEA) *pfNeedEA = 0; // wtf is this ?
|
---|
| 1747 | return smbopen((Connection *)conn, szFileName, 0, ulOpenMode, 0, NULL);
|
---|
| 1748 | }
|
---|
| 1749 |
|
---|
| 1750 | int APIENTRY NdpSetFileAttribute (HCONNECTION conn, NDFILEINFOL *pfi, char *szFileName, USHORT usAttr)
|
---|
| 1751 | {
|
---|
| 1752 | Connection *pConn = (Connection *)conn;
|
---|
| 1753 | Resource *pRes = pConn->pRes;
|
---|
| 1754 | int rc = 0;
|
---|
| 1755 | unsigned long action;
|
---|
[145] | 1756 |
|
---|
| 1757 | smbwrp_fileinfo finfo;
|
---|
[5] | 1758 | char path[CCHMAXPATH+1] = {0};
|
---|
| 1759 |
|
---|
[507] | 1760 | debuglocal(9,"NdpSetFileAttribute in [%p]\n", pConn);
|
---|
[5] | 1761 | do {
|
---|
| 1762 | rc = pathparser(pRes, pConn, szFileName, path);
|
---|
| 1763 | if (rc)
|
---|
| 1764 | {
|
---|
| 1765 | break;
|
---|
| 1766 | }
|
---|
| 1767 |
|
---|
[145] | 1768 | MemSet(&finfo, 0, sizeof(finfo));
|
---|
| 1769 | StrNCpy(finfo.fname, path, sizeof(finfo.fname) - 1);
|
---|
| 1770 | finfo.attr = usAttr & 0x37;
|
---|
| 1771 | rc = smbwrp_setattr(pConn->cli, &finfo);
|
---|
| 1772 | } while (0);
|
---|
[189] | 1773 | debuglocal(9,"NdpSetFileAttribute <%s> (%s) %04x %d\n", szFileName, path, usAttr, rc);
|
---|
[5] | 1774 |
|
---|
| 1775 | return rc;
|
---|
| 1776 | }
|
---|
| 1777 |
|
---|
| 1778 | int APIENTRY NdpFlush (HRESOURCE resource)
|
---|
| 1779 | {
|
---|
[189] | 1780 | debuglocal(9,"NdpFlush %d\n", ERROR_NOT_SUPPORTED);
|
---|
[5] | 1781 | return ERROR_NOT_SUPPORTED;
|
---|
| 1782 | }
|
---|
| 1783 |
|
---|
[520] | 1784 | // Called when a new thread will call the plugin. Allows to do per thread init, like disable signals.
|
---|
| 1785 | #define ND_PL_INIT_THREAD 0xFFFF0000
|
---|
| 1786 |
|
---|
[5] | 1787 | int APIENTRY NdpIOCTL (int type, HRESOURCE resource, char *path, int function, void *in, ULONG insize, PULONG poutlen)
|
---|
| 1788 | {
|
---|
[520] | 1789 | if (function == ND_PL_INIT_THREAD)
|
---|
| 1790 | {
|
---|
| 1791 | smbwrp_initthread();
|
---|
| 1792 | debuglocal(9, "NdpIOCTL init thread\n");
|
---|
| 1793 | return NO_ERROR;
|
---|
| 1794 | }
|
---|
| 1795 |
|
---|
[189] | 1796 | debuglocal(9,"NdpIOCTL <%s> %d\n", path, function);
|
---|
[111] | 1797 |
|
---|
| 1798 | if (in && insize > 4096)
|
---|
| 1799 | {
|
---|
[127] | 1800 | char out[4096];
|
---|
| 1801 | sprintf (out, "SAMBA IOCTL function = %d, parms [%s] insize = %d, *poutlen = %d", function, in, insize, *poutlen);
|
---|
| 1802 | *poutlen = strlen(out);
|
---|
| 1803 | strcpy (in, out);
|
---|
| 1804 | return NO_ERROR;
|
---|
[111] | 1805 | }
|
---|
| 1806 |
|
---|
| 1807 | return ERROR_NOT_SUPPORTED;
|
---|
[5] | 1808 | }
|
---|
| 1809 |
|
---|
| 1810 | int APIENTRY NdpFileQueryInfo (HCONNECTION conn, NDFILEHANDLE handle, void *plist)
|
---|
| 1811 | {
|
---|
| 1812 | Connection *pConn = (Connection *)conn;
|
---|
| 1813 | Resource *pRes = pConn->pRes;
|
---|
| 1814 | int rc = 0;
|
---|
| 1815 | unsigned long action;
|
---|
[145] | 1816 | smbwrp_fileinfo finfo;
|
---|
[5] | 1817 |
|
---|
[507] | 1818 | debug_printf("NdpFileQueryInfo in [%p]\n", pConn);
|
---|
[5] | 1819 | do {
|
---|
| 1820 | if (pConn->file.fd < 0 || !*pConn->file.fname)
|
---|
| 1821 | {
|
---|
| 1822 | rc = ERROR_INVALID_HANDLE;
|
---|
| 1823 | break;
|
---|
| 1824 | }
|
---|
[145] | 1825 | StrNCpy(finfo.fname, pConn->file.fname, sizeof(finfo.fname) - 1);
|
---|
| 1826 | rc = smbwrp_fgetattr(pConn->cli, &pConn->file, &finfo);
|
---|
| 1827 | if (!rc)
|
---|
[5] | 1828 | {
|
---|
[145] | 1829 | finfo.easize = -1;
|
---|
| 1830 | getfindinfoL(pConn, plist, &finfo, 0, NULL);
|
---|
[5] | 1831 | }
|
---|
| 1832 | } while (0);
|
---|
[189] | 1833 | debuglocal(9,"NdpFileQueryInfo <%s> %d\n", pConn->file.fd < 0 ? "!null!" : pConn->file.fname, rc);
|
---|
[5] | 1834 |
|
---|
| 1835 | return rc;
|
---|
| 1836 | }
|
---|
| 1837 |
|
---|
| 1838 | int APIENTRY NdpFileEAQuery (HCONNECTION conn, NDFILEHANDLE handle, GEALIST *pGEAList, FEALIST *pFEAList)
|
---|
| 1839 | {
|
---|
| 1840 | Connection *pConn = (Connection *)conn;
|
---|
| 1841 | Resource *pRes = pConn->pRes;
|
---|
| 1842 | int rc = 0;
|
---|
| 1843 | unsigned long action;
|
---|
[145] | 1844 | char pBuffer[64*1024];
|
---|
[5] | 1845 | FEALIST * pFEASrc;
|
---|
| 1846 |
|
---|
| 1847 | if (!pFEAList)
|
---|
| 1848 | {
|
---|
| 1849 | return ERROR_EAS_NOT_SUPPORTED;
|
---|
| 1850 | }
|
---|
| 1851 | if (!pRes->easupport)
|
---|
| 1852 | {
|
---|
| 1853 | return ERROR_EAS_NOT_SUPPORTED;
|
---|
| 1854 | }
|
---|
| 1855 |
|
---|
[507] | 1856 | debuglocal(9,"NdpFileEAQuery in [%p] <%s>/%d pGEAList=%08x\n", pConn, pConn->file.fname, pConn->file.fd, pGEAList);
|
---|
[5] | 1857 | do {
|
---|
| 1858 | if (pConn->file.fd < 0)
|
---|
| 1859 | {
|
---|
| 1860 | rc = ERROR_INVALID_HANDLE;
|
---|
| 1861 | break;
|
---|
| 1862 | }
|
---|
[145] | 1863 | rc = smbwrp_flistea(pConn->cli, &pConn->file, pBuffer, sizeof( pBuffer));
|
---|
| 1864 | pFEASrc = (FEALIST *) pBuffer;
|
---|
| 1865 | if (rc)
|
---|
[5] | 1866 | {
|
---|
[145] | 1867 | //rc = pConn->rc ? pConn->rc : (resp.rc ? resp.rc : ERROR_INVALID_PARAMETER);
|
---|
[5] | 1868 | switch (rc)
|
---|
| 1869 | {
|
---|
| 1870 | case ERROR_FILE_NOT_FOUND :
|
---|
| 1871 | case ERROR_PATH_NOT_FOUND :
|
---|
| 1872 | {
|
---|
| 1873 | pFEAList->cbList = sizeof(pFEAList->cbList);
|
---|
| 1874 | rc = NO_ERROR;
|
---|
| 1875 | } break;
|
---|
| 1876 | case ERROR_BUFFER_OVERFLOW :
|
---|
| 1877 | {
|
---|
| 1878 | pFEAList->cbList = pFEASrc->cbList;
|
---|
| 1879 | } break;
|
---|
| 1880 | default :
|
---|
| 1881 | {
|
---|
| 1882 | rc = ERROR_EAS_NOT_SUPPORTED;
|
---|
| 1883 | }
|
---|
| 1884 | }
|
---|
| 1885 | }
|
---|
| 1886 | else
|
---|
| 1887 | {
|
---|
| 1888 | rc = buildFEALIST(pFEASrc, pGEAList, pFEAList);
|
---|
| 1889 | }
|
---|
| 1890 | } while (0);
|
---|
[189] | 1891 | 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);
|
---|
[145] | 1892 |
|
---|
[5] | 1893 | return rc;
|
---|
| 1894 | }
|
---|
| 1895 |
|
---|
| 1896 | int APIENTRY NdpFileEASet (HCONNECTION conn, NDFILEHANDLE handle, FEALIST *pFEAList)
|
---|
| 1897 | {
|
---|
| 1898 | Connection *pConn = (Connection *)conn;
|
---|
| 1899 | Resource *pRes = pConn->pRes;
|
---|
| 1900 | int rc = 0;
|
---|
| 1901 | unsigned long action;
|
---|
| 1902 |
|
---|
[507] | 1903 | debuglocal(9,"NdpFileEASet in [%p]\n", pConn);
|
---|
[5] | 1904 |
|
---|
| 1905 | if (!pFEAList || pFEAList->cbList <= sizeof(long))
|
---|
| 1906 | {
|
---|
| 1907 | return ERROR_EAS_NOT_SUPPORTED;
|
---|
| 1908 | }
|
---|
| 1909 | if (!pRes->easupport)
|
---|
| 1910 | {
|
---|
| 1911 | return ERROR_EAS_NOT_SUPPORTED;
|
---|
| 1912 | }
|
---|
| 1913 |
|
---|
| 1914 | do {
|
---|
[145] | 1915 | // got FEA there
|
---|
| 1916 | FEA * pfea;
|
---|
| 1917 | unsigned long done = sizeof(long);
|
---|
[5] | 1918 | if (pConn->file.fd < 0)
|
---|
| 1919 | {
|
---|
| 1920 | rc = ERROR_INVALID_HANDLE;
|
---|
| 1921 | break;
|
---|
| 1922 | }
|
---|
[145] | 1923 |
|
---|
| 1924 | pfea = pFEAList->list;
|
---|
| 1925 | while (done < pFEAList->cbList)
|
---|
[5] | 1926 | {
|
---|
[145] | 1927 | rc = smbwrp_fsetea(pConn->cli, &pConn->file, (char *)(pfea + 1), pfea->cbValue ? (char *)(pfea + 1) + pfea->cbName + 1: NULL, pfea->cbValue);
|
---|
| 1928 | if (rc)
|
---|
| 1929 | {
|
---|
| 1930 | break;
|
---|
| 1931 | }
|
---|
| 1932 | pfea = (FEA *)((char *)(pfea + 1) + pfea->cbName + 1 + pfea->cbValue);
|
---|
| 1933 | done += sizeof(FEA) + pfea->cbName + 1 + pfea->cbValue;
|
---|
[5] | 1934 | }
|
---|
| 1935 |
|
---|
| 1936 | } while (0);
|
---|
[189] | 1937 | debuglocal(9,"NdpFileEASet %d\n", rc);
|
---|
[145] | 1938 |
|
---|
[5] | 1939 | return rc;
|
---|
| 1940 | }
|
---|
| 1941 |
|
---|
| 1942 | int APIENTRY NdpFileEASize (HCONNECTION conn, NDFILEHANDLE handle, ULONG *pulEASize)
|
---|
| 1943 | {
|
---|
| 1944 | Connection *pConn = (Connection *)conn;
|
---|
| 1945 | Resource *pRes = pConn->pRes;
|
---|
| 1946 | int rc = 0;
|
---|
| 1947 | unsigned long action;
|
---|
| 1948 | char path[CCHMAXPATH+1] = {0};
|
---|
[145] | 1949 | FEALIST * pFEAList;
|
---|
| 1950 | char pBuffer[64*1024];
|
---|
[5] | 1951 |
|
---|
| 1952 | if (!pulEASize)
|
---|
| 1953 | {
|
---|
| 1954 | return ERROR_EAS_NOT_SUPPORTED;
|
---|
| 1955 | }
|
---|
| 1956 | if (!pRes->easupport)
|
---|
| 1957 | {
|
---|
| 1958 | return ERROR_EAS_NOT_SUPPORTED;
|
---|
| 1959 | }
|
---|
| 1960 |
|
---|
[507] | 1961 | debuglocal(9,"NdpFileEASize in [%p] <%s>/%d \n", pConn, pConn->file.fname, pConn->file.fd);
|
---|
[5] | 1962 | do {
|
---|
| 1963 | if (pConn->file.fd < 0)
|
---|
| 1964 | {
|
---|
| 1965 | rc = ERROR_INVALID_HANDLE;
|
---|
| 1966 | break;
|
---|
| 1967 | }
|
---|
[145] | 1968 | rc = smbwrp_flistea(pConn->cli, &pConn->file, pBuffer, sizeof(pBuffer));
|
---|
| 1969 | pFEAList = (FEALIST*) pBuffer;
|
---|
| 1970 | if (rc)
|
---|
[5] | 1971 | {
|
---|
[145] | 1972 | //rc = pConn->rc ? pConn->rc : (resp.rc ? resp.rc : ERROR_INVALID_PARAMETER);
|
---|
[5] | 1973 | switch (rc)
|
---|
| 1974 | {
|
---|
| 1975 | case ERROR_FILE_NOT_FOUND :
|
---|
| 1976 | case ERROR_PATH_NOT_FOUND :
|
---|
| 1977 | {
|
---|
[145] | 1978 | pFEAList->cbList = sizeof(pFEAList->cbList);
|
---|
[5] | 1979 | } /* Fall through */
|
---|
| 1980 | case ERROR_BUFFER_OVERFLOW :
|
---|
| 1981 | {
|
---|
| 1982 | rc = NO_ERROR;
|
---|
| 1983 | } break;
|
---|
| 1984 | default :
|
---|
| 1985 | {
|
---|
| 1986 | rc = ERROR_EAS_NOT_SUPPORTED;
|
---|
| 1987 | }
|
---|
| 1988 | }
|
---|
| 1989 | }
|
---|
[145] | 1990 | *pulEASize = pFEAList->cbList;
|
---|
[5] | 1991 | } while (0);
|
---|
[189] | 1992 | debuglocal(9,"NdpFileEASize %d %d\n", *pulEASize, rc);
|
---|
[145] | 1993 |
|
---|
[5] | 1994 | return rc;
|
---|
| 1995 | }
|
---|
| 1996 |
|
---|
| 1997 | int APIENTRY NdpFileSetInfo (HCONNECTION conn, NDFILEHANDLE handle, NDFILEINFOL *pfi)
|
---|
| 1998 | {
|
---|
| 1999 | Connection *pConn = (Connection *)conn;
|
---|
| 2000 | Resource *pRes = pConn->pRes;
|
---|
| 2001 | int rc = 0;
|
---|
| 2002 | unsigned long action, attrFile;
|
---|
| 2003 |
|
---|
[507] | 2004 | debug_printf("NdpFileSetInfo in [%p]\n", pConn);
|
---|
[520] | 2005 |
|
---|
| 2006 | // delete the dir cache
|
---|
| 2007 | dircache_invalidate(pConn->file.fullname, pRes->pdc, 1);
|
---|
| 2008 |
|
---|
[5] | 2009 | do {
|
---|
| 2010 | if (pConn->file.fd < 0 || !*pConn->file.fname)
|
---|
| 2011 | {
|
---|
| 2012 | rc = ERROR_INVALID_HANDLE;
|
---|
| 2013 | break;
|
---|
| 2014 | }
|
---|
[145] | 2015 | attrFile = pfi->stat.attrFile;
|
---|
[5] | 2016 | // deferred setinfo - on closing the file
|
---|
| 2017 | pConn->file.openattr = attrFile;
|
---|
[126] | 2018 | fsphDosDateToUnixTime(pfi->stat.fdateLastWrite, pfi->stat.ftimeLastWrite, &(pConn->file.mtime));
|
---|
| 2019 | debug_printf("NdpFileSetInfo mtime %d\n", pConn->file.mtime);
|
---|
[5] | 2020 | } while (0);
|
---|
[189] | 2021 | debuglocal(9,"NdpFileSetInfo <%s> %08x %d\n", pConn->file.fd < 0 ? "!null!" : pConn->file.fname, attrFile, rc);
|
---|
[145] | 2022 |
|
---|
[5] | 2023 | return NO_ERROR;
|
---|
| 2024 | }
|
---|
| 2025 |
|
---|
| 2026 | int APIENTRY NdpFileSetFilePtrL(HCONNECTION conn, NDFILEHANDLE handle, LONGLONG llOffset, ULONG ulMethod, LONGLONG *pllActual)
|
---|
| 2027 | {
|
---|
| 2028 | Connection *pConn = (Connection *)conn;
|
---|
| 2029 | Resource *pRes = pConn->pRes;
|
---|
| 2030 | int rc = 0;
|
---|
| 2031 | unsigned long action;
|
---|
| 2032 |
|
---|
[510] | 2033 | debuglocal(9,"NdpFileSetFilePtrL in [%p]\n", pConn);
|
---|
[145] | 2034 |
|
---|
[5] | 2035 | do {
|
---|
| 2036 | if (pConn->file.fd < 0)
|
---|
| 2037 | {
|
---|
| 2038 | rc = ERROR_INVALID_HANDLE;
|
---|
| 2039 | break;
|
---|
| 2040 | }
|
---|
| 2041 |
|
---|
[145] | 2042 | rc = smbwrp_lseek(pConn->cli, &pConn->file, ulMethod, llOffset);
|
---|
| 2043 | if (!rc)
|
---|
[5] | 2044 | *pllActual = pConn->file.offset;
|
---|
[145] | 2045 |
|
---|
[5] | 2046 | } while (0);
|
---|
[189] | 2047 | debuglocal(9,"NdpFileSetFilePtrL <%s> %lld %lu %lld %d\n", pConn->file.fd < 0 ? "!null!" : pConn->file.fname, llOffset, ulMethod, *pllActual, rc);
|
---|
[5] | 2048 |
|
---|
| 2049 | return rc;
|
---|
| 2050 | }
|
---|
| 2051 |
|
---|
| 2052 | int APIENTRY NdpFileSetFilePtr (HCONNECTION conn, NDFILEHANDLE handle, LONG lOffset, ULONG ulMethod, ULONG *pulActual)
|
---|
| 2053 | {
|
---|
| 2054 | LONGLONG llActual;
|
---|
| 2055 | int rc = NdpFileSetFilePtrL(conn, handle, lOffset, ulMethod, &llActual);
|
---|
| 2056 | *pulActual = llActual & 0xFFFFFFFF;
|
---|
[189] | 2057 | debuglocal(9,"NdpFileSetFilePtr %ld %lu %ld %d\n", lOffset, ulMethod, *pulActual, rc);
|
---|
[5] | 2058 | return rc;
|
---|
| 2059 | }
|
---|
| 2060 |
|
---|
| 2061 | int APIENTRY NdpFileClose (HCONNECTION conn, NDFILEHANDLE handle)
|
---|
| 2062 | {
|
---|
| 2063 | Connection *pConn = (Connection *)conn;
|
---|
| 2064 | Resource *pRes = pConn->pRes;
|
---|
| 2065 | int rc = 0;
|
---|
| 2066 | unsigned long action;
|
---|
| 2067 |
|
---|
[507] | 2068 | debuglocal(9,"NdpFileClose in [%p] %d <%s>\n", pConn, pConn->file.fd, pConn->file.fd < 0 ? "!null!" : pConn->file.fname);
|
---|
[5] | 2069 |
|
---|
| 2070 | do {
|
---|
| 2071 | if (pConn->file.fd < 0)
|
---|
| 2072 | {
|
---|
| 2073 | rc = ERROR_INVALID_HANDLE;
|
---|
| 2074 | break;
|
---|
| 2075 | }
|
---|
| 2076 |
|
---|
[145] | 2077 | rc = smbwrp_close(pConn->cli, &pConn->file);
|
---|
| 2078 |
|
---|
[5] | 2079 | } while (0);
|
---|
[189] | 2080 | debuglocal(9,"NdpFileClose %d %d\n", pConn->file.fd, rc);
|
---|
[145] | 2081 |
|
---|
[5] | 2082 | pConn->file.fd = -1;
|
---|
| 2083 | return rc;
|
---|
| 2084 | }
|
---|
| 2085 |
|
---|
| 2086 | int APIENTRY NdpFileCommit (HCONNECTION conn, NDFILEHANDLE handle)
|
---|
| 2087 | {
|
---|
[189] | 2088 | debuglocal(9,"NdpFileCommit %d\n", NO_ERROR);
|
---|
[5] | 2089 | return NO_ERROR;
|
---|
| 2090 | }
|
---|
| 2091 |
|
---|
| 2092 |
|
---|
| 2093 | int APIENTRY NdpFileNewSize (HCONNECTION conn, NDFILEHANDLE handle, ULONG ulLen)
|
---|
| 2094 | {
|
---|
| 2095 | int rc = NdpFileNewSizeL(conn, handle, ulLen);
|
---|
[189] | 2096 | debuglocal(9,"NdpFileNewSize %ld %d\n", ulLen, rc);
|
---|
[5] | 2097 | return rc;
|
---|
| 2098 | }
|
---|
| 2099 |
|
---|
| 2100 | int APIENTRY NdpFileNewSizeL(HCONNECTION conn, NDFILEHANDLE handle, LONGLONG llLen)
|
---|
| 2101 | {
|
---|
| 2102 | Connection *pConn = (Connection *)conn;
|
---|
| 2103 | Resource *pRes = pConn->pRes;
|
---|
| 2104 | int rc = 0;
|
---|
| 2105 | unsigned long action;
|
---|
| 2106 |
|
---|
[507] | 2107 | debuglocal(9,"NdpFileNewSizeL in [%p]\n", pConn);
|
---|
[145] | 2108 |
|
---|
[5] | 2109 | do {
|
---|
| 2110 | if (pConn->file.fd < 0)
|
---|
| 2111 | {
|
---|
| 2112 | rc = ERROR_INVALID_HANDLE;
|
---|
| 2113 | break;
|
---|
| 2114 | }
|
---|
| 2115 |
|
---|
[145] | 2116 | rc = smbwrp_setfilesize(pConn->cli, &pConn->file, llLen);
|
---|
[5] | 2117 |
|
---|
[145] | 2118 | } while (0);
|
---|
[189] | 2119 | debuglocal(9,"NdpFileNewSizeL <%s> %lld %d\n", pConn->file.fd < 0 ? "!null!" : pConn->file.fname, llLen, rc);
|
---|
[5] | 2120 |
|
---|
| 2121 | return rc;
|
---|
| 2122 | }
|
---|
| 2123 |
|
---|
[507] | 2124 | #define NDPSMB_READ_MAX_SIZE (65536 - 4096)
|
---|
| 2125 |
|
---|
[5] | 2126 | int APIENTRY NdpFileRead (HCONNECTION conn, NDFILEHANDLE handle, void *pBuffer, ULONG ulRead, ULONG *pulActual)
|
---|
| 2127 | {
|
---|
| 2128 | Connection *pConn = (Connection *)conn;
|
---|
| 2129 | Resource *pRes = pConn->pRes;
|
---|
| 2130 | int rc = 0;
|
---|
| 2131 | unsigned long done = 0;
|
---|
| 2132 | unsigned long onedone;
|
---|
| 2133 | unsigned long action;
|
---|
[507] | 2134 | ULONG ulReadCompleted = 0;
|
---|
[5] | 2135 |
|
---|
[507] | 2136 | debuglocal(9,"NdpFileRead in [%p]\n", pConn);
|
---|
[5] | 2137 |
|
---|
| 2138 | do {
|
---|
| 2139 | if (pConn->file.fd < 0)
|
---|
| 2140 | {
|
---|
| 2141 | rc = ERROR_INVALID_HANDLE;
|
---|
| 2142 | break;
|
---|
| 2143 | }
|
---|
[507] | 2144 |
|
---|
| 2145 | while (ulReadCompleted < ulRead)
|
---|
| 2146 | {
|
---|
| 2147 | ULONG ulActual;
|
---|
| 2148 | ULONG ulToRead = ulRead - ulReadCompleted;
|
---|
| 2149 | debuglocal(9,"NdpFileRead completed %d, to read %d\n", ulReadCompleted, ulToRead);
|
---|
| 2150 | if (ulToRead > NDPSMB_READ_MAX_SIZE)
|
---|
| 2151 | {
|
---|
| 2152 | ulToRead = NDPSMB_READ_MAX_SIZE;
|
---|
| 2153 | }
|
---|
| 2154 | rc = smbwrp_read(pConn->cli, &pConn->file, (char *)pBuffer + ulReadCompleted, ulToRead, &ulActual);
|
---|
| 2155 | if (ulActual == 0 || rc != NO_ERROR)
|
---|
| 2156 | {
|
---|
| 2157 | break;
|
---|
| 2158 | }
|
---|
| 2159 | ulReadCompleted += ulActual;
|
---|
| 2160 | }
|
---|
| 2161 |
|
---|
[145] | 2162 | //*pulActual = ulRead;
|
---|
| 2163 | //DosSleep(0);
|
---|
[5] | 2164 |
|
---|
| 2165 | } while (0);
|
---|
[507] | 2166 |
|
---|
| 2167 | if (ulReadCompleted > 0)
|
---|
| 2168 | {
|
---|
| 2169 | rc = NO_ERROR; /* Still were able to read some data. */
|
---|
| 2170 | }
|
---|
| 2171 |
|
---|
| 2172 | if (rc == NO_ERROR)
|
---|
| 2173 | {
|
---|
| 2174 | *pulActual = ulReadCompleted;
|
---|
| 2175 | }
|
---|
| 2176 |
|
---|
[189] | 2177 | debuglocal(9,"NdpFileRead <%s> %lu %lu %d\n", pConn->file.fd < 0 ? "!null!" : pConn->file.fname, ulRead, *pulActual, rc);
|
---|
[5] | 2178 |
|
---|
| 2179 | return rc;
|
---|
| 2180 | }
|
---|
| 2181 |
|
---|
| 2182 | int APIENTRY NdpFileWrite (HCONNECTION conn, NDFILEHANDLE handle, void *pBuffer, ULONG ulWrite, ULONG *pulActual)
|
---|
| 2183 | {
|
---|
| 2184 | Connection *pConn = (Connection *)conn;
|
---|
| 2185 | Resource *pRes = pConn->pRes;
|
---|
| 2186 | int rc = 0;
|
---|
| 2187 | unsigned long done = 0;
|
---|
| 2188 | unsigned long onedone;
|
---|
| 2189 | unsigned long action;
|
---|
| 2190 |
|
---|
[507] | 2191 | debuglocal(9,"NdpFileWrite in [%p]\n", pConn);
|
---|
[145] | 2192 |
|
---|
[513] | 2193 | /* delete the dir cache
|
---|
| 2194 | this was moved from NdpFileClose() becasue if there are a lot files in the tree all are reread
|
---|
| 2195 | the problem when moved to here is, that last accessed time is not refreshed
|
---|
| 2196 | if this is needed, a new function needs to be done to update only one file in the cache */
|
---|
| 2197 | dircache_invalidate(pConn->file.fullname, pRes->pdc, 1);
|
---|
| 2198 |
|
---|
[5] | 2199 | do {
|
---|
| 2200 | if (pConn->file.fd < 0)
|
---|
| 2201 | {
|
---|
| 2202 | rc = ERROR_INVALID_HANDLE;
|
---|
| 2203 | break;
|
---|
| 2204 | }
|
---|
[145] | 2205 | rc = smbwrp_write(pConn->cli, &pConn->file, pBuffer, ulWrite, pulActual);
|
---|
[5] | 2206 |
|
---|
| 2207 | } while (0);
|
---|
[189] | 2208 | debuglocal(9,"NdpFileWrite <%s> %lu %lu %d\n", pConn->file.fd < 0 ? "!null!" : pConn->file.fname, ulWrite, *pulActual, rc);
|
---|
[5] | 2209 |
|
---|
| 2210 | return rc;
|
---|
| 2211 | }
|
---|
[145] | 2212 |
|
---|