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