source: branches/client-1.5/src/ndpsmb.c@ 157

Last change on this file since 157 was 157, checked in by Yuri Dario, 17 years ago

Don't forget to initialize pointers, saves from crashes :-)

  • Property svn:eol-style set to native
File size: 50.2 KB
Line 
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
39void 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*/
74void 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
90void 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
116int 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
127char * 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
143char * 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
153char * 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
165char * 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
181void * 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
195void *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 */
212const char *NdpTypes[] =
213{
214 "SMBFS",
215 NULL
216}
217;
218
219/* Properties of supported resource types */
220
221/* Properties of resource */
222static 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 */
241const NDPROPERTYINFO *NdpPropertiesInfo[] =
242{
243 smbProperties
244};
245
246
247static PLUGINHELPERTABLE2L *ph;
248static int ifL;
249
250int 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
272int APIENTRY NdpPluginFree (void)
273{
274 return NO_ERROR;
275}
276
277
278void 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
305int 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
341static 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
361static 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
373static 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
387static 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 */
406int 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
565int 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
583int 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 */
702static int checkMountResource( Resource* pRes)
703{
704 int rc;
705 unsigned long action;
706 cli_state* cli = NULL;
707 smbwrp_file file;
708
709 debug_printf("checkMountResource in tid#%d\n", _gettid());
710 rc = smbwrp_connect( pRes, &cli);
711 if (rc)
712 rc = (rc == 7 ? ERROR_BAD_DEV_TYPE : ERROR_ACCESS_DENIED);
713 smbwrp_disconnect( pRes, cli);
714
715 return rc;
716}
717
718int APIENTRY NdpMountResource (HRESOURCE *presource, int type, NDPROPERTYHANDLE properties)
719{
720 int rc = NO_ERROR;
721 unsigned long objany = OBJ_ANY;
722 Resource *pRes = NULL;
723
724 log("NdpMountResource in\n");
725
726 // init code
727 smbwrp_init();
728
729 /* since samba plugin support only 1 type of resources we do not need */
730 /* to check what the found type really is */
731 pRes = malloc( sizeof(Resource));
732 if (pRes == NULL)
733 {
734 rc = ERROR_NOT_ENOUGH_MEMORY;
735 }
736 else
737 {
738 MemSet(pRes, 0, sizeof(Resource));
739 //pRes->objany = objany;
740 // parse init string
741 rc = initResource (pRes, properties);
742 // try to connect to resource (check type) only if thread!=1, so ndctl startup
743 // is not slowed down by network connections.
744 // ndctl does mounting on main thread (#1)
745 // nd/ndpm do not use main thread
746 if (!rc && _gettid()!=1)
747 rc = checkMountResource( pRes);
748 if (!rc)
749 {
750 // store resource data
751 *presource = (HRESOURCE)pRes;
752 }
753 else
754 {
755 free(pRes);
756 }
757 }
758 log("NdpMountResource rc=%d\n", rc);
759 return rc;
760}
761
762// -------------------------------------------------------------
763
764int APIENTRY NdpFreeResource (HRESOURCE resource)
765{
766 Resource *pRes = (Resource *)resource;
767 MemSet(&pRes->srv, 0, sizeof(pRes->srv));
768 free(pRes);
769 log("NdpFreeResource %d\n", NO_ERROR);
770 return NO_ERROR;
771}
772
773// -------------------------------------------------------------
774
775int APIENTRY NdpRsrcCompare (HRESOURCE resource, HRESOURCE resource2)
776{
777 Resource *pRes = (Resource *)resource;
778 Resource *pRes2 = (Resource *)resource2;
779 int rc = ND_RSRC_DIFFERENT;
780
781 log("NdpRsrcCompare in\n");
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
791 log("NdpRsrcCompare %d\n", rc);
792
793 return rc;
794}
795
796int APIENTRY NdpRsrcUpdate (HRESOURCE resource, HRESOURCE resource2)
797{
798 // do nothing
799 log("NdpRsrcUpdate %d\n", NO_ERROR);
800 return NO_ERROR;
801}
802
803int 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
809 log("NdpRsrcQueryInfo in\n");
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
840 log("NdpRsrcQueryInfo %d\n", rc);
841
842 return rc;
843}
844
845int 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
852int APIENTRY NdpRsrcQueryFSAllocate (HRESOURCE resource, NDFSALLOCATE *pfsa)
853{
854 Resource *pRes = (Resource *)resource;
855 int rc = NO_ERROR, rc1;
856 unsigned long action = 0;
857 smbwrp_file file;
858 cli_state* cli = NULL;
859 FSALLOCATE fsa;
860
861 log("NdpRsrcQueryFSAllocate %08x\n", pfsa);
862
863 if (!pfsa)
864 {
865 return NO_ERROR;
866 }
867
868 debug_printf("checkMountResource in tid#%d\n", _gettid());
869 rc = smbwrp_connect( pRes, &cli);
870 if (rc)
871 {
872 log("NdpCreateConnection failed rc=%d\n", rc);
873 pfsa->cSectorUnit = 1;
874 pfsa->cUnit = 123456;
875 pfsa->cUnitAvail = 123456;
876 pfsa->cbSector = 2048;
877 rc = (rc == 7 ? ERROR_BAD_DEV_TYPE : ERROR_ACCESS_DENIED);
878 return rc;
879 }
880
881 rc = smbwrp_dskattr( cli, &fsa);
882 if (rc)
883 {
884 pfsa->cSectorUnit = 1;
885 pfsa->cUnit = 123456;
886 pfsa->cUnitAvail = 123456;
887 pfsa->cbSector = 2048;
888 //rc = rc ? rc : (resp.rc ? resp.rc : ERROR_INVALID_PARAMETER);
889 }
890 else
891 {
892 pfsa->cSectorUnit = fsa.cSectorUnit;
893 pfsa->cUnit = fsa.cUnit;
894 pfsa->cUnitAvail = fsa.cUnitAvail;
895 pfsa->cbSector = fsa.cbSector;
896 }
897
898 smbwrp_disconnect( pRes, cli);
899
900 log("NdpRsrcQueryFSAllocate %d/%d (cUnit = %d/cUnitAvail = %d/cbSector = %d)\n", rc, rc1, pfsa->cUnit, pfsa->cUnitAvail, pfsa->cbSector);
901 return rc;
902}
903
904// -------------------------------------------------------------
905
906int APIENTRY NdpCreateConnection (HRESOURCE resource, HCONNECTION *pconn)
907{
908 int rc = 0;
909 Resource * pRes = (Resource *)resource;
910 unsigned long action;
911 Connection *pConn = NULL;
912
913 log("NdpCreateConnection in\n");
914
915 pConn = malloc( sizeof(Connection));
916 if (pConn == NULL)
917 {
918 rc = ERROR_NOT_ENOUGH_MEMORY;
919 }
920 if (rc)
921 {
922 log("NdpCreateConnection ERROR_NOT_ENOUGH_MEMORY %d\n", rc);
923 return rc;
924 }
925 MemSet(pConn, 0, sizeof(Connection));
926 pConn->pRes = pRes;
927 pConn->file.fd = -1;
928
929 log("NdpCreateConnection send CONNECT\n");
930 rc = smbwrp_connect( pRes, &pConn->cli);
931 if (rc)
932 {
933 free(pConn);
934 pConn = NULL;
935 rc = (rc == 7 ? ERROR_BAD_DEV_TYPE : ERROR_INVALID_PARAMETER);
936 }
937
938 *pconn = (HCONNECTION)pConn;
939 log("NdpCreateConnection %d\n", rc);
940 return rc;
941}
942
943// -------------------------------------------------------------
944
945int APIENTRY NdpFreeConnection (HCONNECTION conn)
946{
947 Connection *pConn = (Connection *)conn;
948 Resource *pRes = pConn->pRes;
949 int rc;
950
951 log("NdpFreeConnection in\n");
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);
961 log("NdpFreeConnection %d\n", NO_ERROR);
962 return NO_ERROR;
963}
964
965// -------------------------------------------------------------
966
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 */
983int APIENTRY NdpQueryPathInfo (HCONNECTION conn, void *plist, char *szPath)
984{
985 Connection *pConn = (Connection *)conn;
986 Resource *pRes = pConn->pRes;
987 smbwrp_fileinfo finfo;
988 int rc = 0;
989 unsigned long action;
990 char path[CCHMAXPATH+1] = {0};
991 int retry = 0;
992
993 log("NdpQueryPathInfo in <%s>, retry = %d\n", szPath, retry);
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 }
1000
1001
1002 do {
1003
1004 rc = pathparser(pRes, pConn, szPath, path);
1005 log("NdpQueryPathInfo pathparser for <%s> rc=%d\n", path, rc);
1006 switch (rc)
1007 {
1008 case NO_ERROR :
1009 case ERROR_FILE_NOT_FOUND:
1010 case ERROR_PATH_NOT_FOUND:
1011 case ERROR_ACCESS_DENIED:
1012 case ERROR_INVALID_PARAMETER:
1013 {
1014 break;
1015 }
1016 default :
1017 {
1018 rc = ERROR_PATH_NOT_FOUND;
1019 }
1020 }
1021 if (rc)
1022 {
1023 break;
1024 }
1025 StrNCpy(finfo.fname, path, sizeof(finfo.fname) - 1);
1026 log("NdpQueryPathInfo smbwrp_getattr for <%s>\n", path);
1027 rc = smbwrp_getattr( &pRes->srv, pConn->cli, &finfo);
1028 if (rc)
1029 {
1030 // remote server not available for first time?
1031 if (rc == ERROR_REM_NOT_LIST && retry == 0)
1032 {
1033 // free current cli resources
1034 smbwrp_disconnect( pRes, pConn->cli);
1035 // reconnect
1036 smbwrp_connect( pRes, &pConn->cli);
1037 // try file list again
1038 rc = smbwrp_getattr( &pRes->srv, pConn->cli, &finfo);
1039 log("NdpQueryPathInfo remote connection lost, retry rc = %d\n", rc);
1040 }
1041 switch (rc)
1042 {
1043 case NO_ERROR :
1044 case ERROR_FILE_NOT_FOUND:
1045 case ERROR_PATH_NOT_FOUND:
1046 case ERROR_ACCESS_DENIED:
1047 case ERROR_INVALID_PARAMETER:
1048 case ERROR_REM_NOT_LIST:
1049 break;
1050 default :
1051 {
1052 rc = ERROR_PATH_NOT_FOUND;
1053 }
1054 }
1055 }
1056 else
1057 {
1058 finfo.easize = -1;
1059 getfindinfoL(pConn, plist, &finfo, 0, NULL);
1060 }
1061 if (rc == ERROR_FILE_NOT_FOUND)
1062 {
1063 // now try the upper path
1064 char * p = ph->fsphStrChr(finfo.fname, '\\');
1065 if (p && p > finfo.fname)
1066 {
1067 *p = 0;
1068 rc = smbwrp_getattr( &pRes->srv, pConn->cli, &finfo);
1069 if (rc)
1070 {
1071 log("NdpQueryPathInfo upper path in <%s>, retry = %d\n", finfo.fname, retry);
1072 rc = rc ? ERROR_PATH_NOT_FOUND : ERROR_INVALID_PARAMETER;
1073 }
1074 }
1075 }
1076 } while (0);
1077 log("NdpQueryPathInfo <%s> (%s) %d\n", szPath, path, rc);
1078
1079 return rc;
1080}
1081
1082// -------------------------------------------------------------
1083
1084int APIENTRY NdpFindStart (HCONNECTION conn, void *plist, NDFILEINFOL *pfiparent, char *szPath, ULONG ulAttribute)
1085{
1086 Connection *pConn = (Connection *)conn;
1087 Resource *pRes = pConn->pRes;
1088 int rc = NO_ERROR, count = 0;
1089 unsigned long action;
1090 char *mask = "*";
1091 char dir[CCHMAXPATH+1] = {0};
1092 char path[CCHMAXPATH+1] = {0};
1093 smbwrp_fileinfo * data;
1094 NDPATHELEMENT *pel = ph->fsphNameElem(0);
1095 filelist_state state;
1096 char * p;
1097
1098 debug_printf("NdpFindStart in\n");
1099
1100 StrNCpy(dir, szPath, sizeof(dir) - 1);
1101 if (pel)
1102 {
1103 mask = pel->name;
1104 dir[StrLen(szPath) - pel->length] = 0;
1105 }
1106 action = StrLen(dir) - 1;
1107 if (dir[action] == '\\')
1108 {
1109 dir[action] = 0;
1110 }
1111 rc = pathparser(pRes, pConn, dir, path);
1112 if (rc)
1113 {
1114 return rc;
1115 }
1116 action = StrLen(path) - 1;
1117 if (path[action] != '\\')
1118 {
1119 StrNCat(path, "\\", sizeof(path) - 1);
1120 }
1121 StrCpy(dir, path);
1122 StrNCat(path, mask, sizeof(path) - 1);
1123
1124 // this structure will be used by libsmb callbacks, so we store here all we need
1125 // to fill netdrive structures
1126 state.pConn = pConn;
1127 state.plist = plist;
1128 state.ulAttribute = ulAttribute;
1129 strcpy( state.dir, dir);
1130 strcpy( state.dir_mask, mask);
1131 strcpy( state.mask, path);
1132 p = getlastslash(state.mask);
1133 if (p)
1134 {
1135 *(p + 1) = '*';
1136 *(p + 2) = 0;
1137 }
1138 else
1139 {
1140 strcpy(state.mask, "\\*");
1141 }
1142 rc = smbwrp_filelist( &pRes->srv, pConn->cli, &state);
1143 // we need to handle reconnection also here, because NdpQueryPathInfo
1144 // could be called with '*' and exit then immediately (without calling libsmb)
1145 if (rc == ERROR_REM_NOT_LIST)
1146 {
1147 // free current cli resources
1148 smbwrp_disconnect( pRes, pConn->cli);
1149 // reconnect
1150 smbwrp_connect( pRes, &pConn->cli);
1151 // try file list again next loop
1152 rc = smbwrp_filelist( &pRes->srv, pConn->cli, &state);
1153 log("NdpFindStart remote connection lost, retry rc = %d\n", rc);
1154 }
1155
1156 log("NdpFindStart <%s> (%s) cnt %d %d\n", szPath, path, count, rc);
1157
1158 return rc;
1159}
1160
1161int APIENTRY NdpDeletePathInfo (HRESOURCE resource, NDFILEINFOL *pfi)
1162{
1163// log("NdpDeletePathInfo %d\n", 0);
1164 return NO_ERROR;
1165}
1166
1167int APIENTRY NdpRefresh (HCONNECTION conn, char *path, int tree)
1168{
1169 log("NdpRefresh <%s> %d\n", path, 0);
1170 return NO_ERROR;
1171}
1172
1173int APIENTRY NdpDiscardResourceData (HRESOURCE resource, NDDATABUF *pdatabuf)
1174{
1175 // The plugin do not have to deallocate anything
1176 // because resource data did not contain any pointers
1177 // to plugins data.
1178 // Data stored by fsphSetResourceData will be
1179 // deallocated by NetDrive.
1180
1181 log("NdpDicardresourceData %d\n", 0);
1182 return NO_ERROR;
1183}
1184
1185int APIENTRY NdpSetPathInfo (HCONNECTION conn, NDFILEINFOL *pfi, char *szPathName)
1186{
1187 Connection *pConn = (Connection *)conn;
1188 Resource *pRes = pConn->pRes;
1189 int rc = 0;
1190 unsigned long action;
1191 char path[CCHMAXPATH+1] = {0};
1192 smbwrp_fileinfo finfo;
1193
1194 debug_printf("NdpSetPathInfo in FIXME\n");
1195
1196 do {
1197 rc = pathparser(pRes, pConn, szPathName, path);
1198 if (rc)
1199 {
1200 break;
1201 }
1202
1203 MemSet(&finfo, 0, sizeof(finfo));
1204
1205 StrNCpy(finfo.fname, path, sizeof(finfo.fname) - 1);
1206 fsphDosDateToUnixTime(pfi->stat.fdateLastWrite, pfi->stat.ftimeLastWrite, &(finfo.mtime));
1207 finfo.attr = pfi->stat.attrFile & 0x37;
1208 rc = smbwrp_setattr(pConn->cli, &finfo);
1209 } while (0);
1210 log("NdpSetPathInfo <%s> (%s) %d\n", szPathName, path, rc);
1211
1212 return rc;
1213}
1214
1215int buildFEALIST(FEALIST *pFEASrc, GEALIST *pGEAList, FEALIST *pFEAList)
1216{
1217 int rc = 0;
1218 FEA * pfea;
1219 FEA * pfeadest;
1220 unsigned long size, done = sizeof(pFEAList->cbList), dsize, ddone = sizeof(pFEAList->cbList);
1221
1222 size = pFEASrc->cbList;
1223 pfea = pFEASrc->list;
1224 pfeadest = pFEAList->list;
1225 dsize = pFEAList->cbList;
1226//log("buildFEALIST in destsize %d srcsize %d pGEAList=%08x pGEAList->cbList=%d\n", dsize, ddone, size, pGEAList, pGEAList ? pGEAList->cbList : 0);
1227 while (done < size)
1228 {
1229 char * name = (char *)(pfea + 1);
1230 int insert = 1;
1231 if (pGEAList && pGEAList->cbList > sizeof(pGEAList->cbList))
1232 {
1233 GEA * pgea = pGEAList->list;
1234 unsigned long size = pGEAList->cbList - sizeof(pGEAList->cbList), done = 0;
1235 insert = 0;
1236 while (done < size)
1237 {
1238//log("comp <%s> <%s>\n", name, pgea->szName);
1239 if (!ph->fsphStrNCmp(name, pgea->szName, pgea->cbName))
1240 {
1241 insert = 1;
1242 break;
1243 }
1244 done += pgea->cbName + 2;
1245 pgea = (GEA *)((char *)pgea + pgea->cbName + 2);
1246 }
1247 }
1248 if (insert)
1249 {
1250 ddone += sizeof(FEA) + pfea->cbName + 1 + pfea->cbValue;
1251 if (ddone <= dsize)
1252 {
1253 pfeadest->cbName = pfea->cbName;
1254 pfeadest->cbValue = pfea->cbValue;
1255 pfeadest->fEA = 0;
1256 StrCpy((char *)(pfeadest + 1), name);
1257 MemCpy((char *)(pfeadest + 1) + pfea->cbName + 1, (char *)(pfea + 1) + pfea->cbName + 1, pfea->cbValue);
1258 pfeadest = (FEA *)((char *)pFEAList + ddone);
1259 }
1260 }
1261 done += sizeof(FEA) + pfea->cbName + 1 + pfea->cbValue;
1262//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);
1263 pfea = (FEA *)((char *)pFEASrc + done);
1264 }
1265 pFEAList->cbList = ddone;
1266 if (ddone > dsize && dsize > sizeof(pFEAList->cbList))
1267 {
1268 rc = ERROR_BUFFER_OVERFLOW;
1269 }
1270 log("buildFEALIST rc=%d destsize=%d destdone=%d srcsize=%d pGEAList=%08x\n", rc, dsize, ddone, size, pGEAList);
1271 return rc;
1272}
1273
1274int APIENTRY NdpEAQuery (HCONNECTION conn, GEALIST *pGEAList, NDFILEINFOL *pfi, FEALIST *pFEAList)
1275{
1276 Connection *pConn = (Connection *)conn;
1277 Resource *pRes = pConn->pRes;
1278 int rc = 0;
1279 unsigned long action;
1280 char * path = NULL;
1281 FEALIST * pFEASrc;
1282 NDDATABUF fdata = {0};
1283 smbwrp_fileinfo *finfo;
1284 char pBuffer[64*1024];
1285
1286 if (!pfi || !pfi->pszName || !pFEAList)
1287 {
1288 return ERROR_EAS_NOT_SUPPORTED;
1289 }
1290 if (!pRes->easupport)
1291 {
1292 return ERROR_EAS_NOT_SUPPORTED;
1293 }
1294
1295 rc = ph->fsphGetFileInfoData(pfi, &fdata, 0);
1296 if (rc || !fdata.ulSize || !fdata.pData)
1297 {
1298 log("NdpEAQuery: ph->fsphGetFileInfoData = %d/%d %08x\n", rc, fdata.ulSize, fdata.pData);
1299 return ERROR_EAS_NOT_SUPPORTED;
1300 }
1301 finfo = (smbwrp_fileinfo *)fdata.pData;
1302 path = finfo->fname;
1303
1304 log("NdpEAQuery in <%s> %08x %d\n", path, pGEAList, pGEAList ? pGEAList->cbList : 0);
1305
1306 do {
1307 rc = smbwrp_listea( pConn->cli, path, pBuffer, sizeof( pBuffer));
1308 pFEASrc = (FEALIST*) pBuffer;
1309 if (rc)
1310 {
1311 //rc = pConn->rc ? pConn->rc : (resp.rc ? resp.rc : ERROR_INVALID_PARAMETER);
1312 switch (rc)
1313 {
1314 case ERROR_FILE_NOT_FOUND :
1315 case ERROR_PATH_NOT_FOUND :
1316 {
1317 pFEAList->cbList = sizeof(pFEAList->cbList);
1318 rc = NO_ERROR;
1319 } break;
1320 case ERROR_BUFFER_OVERFLOW :
1321 {
1322 pFEAList->cbList = pFEASrc->cbList;
1323 } break;
1324 default :
1325 {
1326 rc = ERROR_EAS_NOT_SUPPORTED;
1327 }
1328 }
1329 }
1330 else
1331 {
1332 rc = buildFEALIST((FEALIST *)pFEASrc, pGEAList, pFEAList);
1333 }
1334 } while (0);
1335 log("NdpEAQuery <%s> %d %d %d\n", pfi->pszName, rc, pFEASrc->cbList, pFEAList->cbList);
1336
1337 return rc;
1338}
1339
1340int APIENTRY NdpEASet (HCONNECTION conn, FEALIST *pFEAList, NDFILEINFOL *pfi)
1341{
1342 Connection *pConn = (Connection *)conn;
1343 Resource *pRes = pConn->pRes;
1344 int rc = 0;
1345 char * path;
1346 unsigned long action;
1347 NDDATABUF fdata = {0};
1348 smbwrp_fileinfo *finfo;
1349
1350 log("NdpEASet in\n");
1351
1352 if (!pfi || !pfi->pszName || !pFEAList || pFEAList->cbList <= sizeof(long))
1353 {
1354 return ERROR_EAS_NOT_SUPPORTED;
1355 }
1356 if (!pRes->easupport)
1357 {
1358 return ERROR_EAS_NOT_SUPPORTED;
1359 }
1360
1361 rc = ph->fsphGetFileInfoData(pfi, &fdata, 0);
1362 if (rc || !fdata.ulSize || !fdata.pData)
1363 {
1364 log("NdpEASet: ph->fsphGetFileInfoData = %d/%d/%08x\n", rc, fdata.ulSize, fdata.pData);
1365 return ERROR_EAS_NOT_SUPPORTED;
1366 }
1367 finfo = (smbwrp_fileinfo *)fdata.pData;
1368 path = finfo->fname;
1369
1370 do {
1371 // got FEA there
1372 FEA * pfea;
1373 unsigned long done = sizeof(long);
1374 pfea = pFEAList->list;
1375 while (done < pFEAList->cbList)
1376 {
1377 rc = smbwrp_setea(pConn->cli, path, (char*)(pfea + 1), pfea->cbValue ? (char *)(pfea + 1) + pfea->cbName + 1: NULL, pfea->cbValue);
1378 if (rc)
1379 {
1380 break;
1381 }
1382 pfea = (FEA *)((char *)(pfea + 1) + pfea->cbName + 1 + pfea->cbValue);
1383 done += sizeof(FEA) + pfea->cbName + 1 + pfea->cbValue;
1384 }
1385 } while (0);
1386 log("NdpEASet %d\n", rc);
1387
1388 return rc;
1389}
1390
1391int APIENTRY NdpEASize (HCONNECTION conn, NDFILEINFOL *pfi, ULONG *pulEASize)
1392{
1393 Connection *pConn = (Connection *)conn;
1394 Resource *pRes = pConn->pRes;
1395 int rc = 0;
1396 unsigned long action;
1397 char * path = NULL;
1398 FEALIST * pfealist;
1399 NDDATABUF fdata = {0};
1400 smbwrp_fileinfo *finfo;
1401 char pBuffer[64*1024];
1402 int easize;
1403
1404 if (!pfi || !pulEASize)
1405 {
1406 return ERROR_EAS_NOT_SUPPORTED;
1407 }
1408 if (!pRes->easupport)
1409 {
1410 return ERROR_EAS_NOT_SUPPORTED;
1411 }
1412
1413 rc = ph->fsphGetFileInfoData(pfi, &fdata, 0);
1414 if (rc || !fdata.ulSize || !fdata.pData)
1415 {
1416 log("NdpEASize: ph->fsphGetFileInfoData = %d/%d/%08x\n", rc, fdata.ulSize, fdata.pData);
1417 return ERROR_EAS_NOT_SUPPORTED;
1418 }
1419 finfo = (smbwrp_fileinfo *)fdata.pData;
1420 easize = finfo->easize;
1421 finfo->easize = -1;
1422 path = finfo->fname;
1423 if (easize >= 0)
1424 {
1425 *pulEASize = easize;
1426 log("NdpEASize <%s> cached %d\n", path, easize);
1427 return NO_ERROR;
1428 }
1429
1430 log("NdpEASize in <%s> \n", path);
1431
1432 do {
1433 rc = smbwrp_listea(pConn->cli, path, pBuffer, sizeof( pBuffer));
1434 pfealist = (FEALIST*)pBuffer;
1435 if (rc)
1436 {
1437 //rc = pConn->rc ? pConn->rc : (resp.rc ? resp.rc : ERROR_INVALID_PARAMETER);
1438 switch (rc)
1439 {
1440 case ERROR_FILE_NOT_FOUND :
1441 case ERROR_PATH_NOT_FOUND :
1442 {
1443 pfealist->cbList = sizeof(pfealist->cbList);
1444 } /* Fall through */
1445 case ERROR_BUFFER_OVERFLOW :
1446 {
1447 rc = NO_ERROR;
1448 } break;
1449 default :
1450 {
1451 rc = ERROR_EAS_NOT_SUPPORTED;
1452 }
1453 }
1454 }
1455 *pulEASize = pfealist->cbList;
1456 } while (0);
1457 log("NdpEASize <%s> %d %d\n", pfi->pszName, *pulEASize, rc);
1458
1459 return rc;
1460}
1461
1462int APIENTRY NdpSetCurrentDir (HCONNECTION conn, NDFILEINFOL *pfi, char *szPath)
1463{
1464 Connection *pConn = (Connection *)conn;
1465 Resource *pRes = pConn->pRes;
1466 int rc = 0;
1467 unsigned long action;
1468 char path[CCHMAXPATH+1] = {0};
1469
1470 log("NdpSetCurrentDir in\n");
1471
1472 do {
1473 rc = pathparser(pRes, pConn, szPath, path);
1474 if (rc)
1475 {
1476 break;
1477 }
1478
1479 rc = smbwrp_chdir(&pRes->srv, pConn->cli, path);
1480 } while (0);
1481 log("NdpSetCurrentDir <%s> (%s) %d\n", szPath, path, rc);
1482
1483 return rc;
1484}
1485
1486int APIENTRY NdpCopy (HCONNECTION conn, NDFILEINFOL *pfiDst, char *szDst, NDFILEINFOL *pfiSrc, char *szSrc, ULONG ulOption)
1487{
1488 log("NdpCopy <%s> -> <%s> %d\n", szSrc, szDst, ERROR_CANNOT_COPY);
1489 return ERROR_CANNOT_COPY;
1490}
1491
1492int APIENTRY NdpCopy2 (HCONNECTION conn, HRESOURCE resDst, NDFILEINFOL *pfiDst, char *szDst, NDFILEINFOL *pfiSrc, char *szSrc, ULONG ulOption)
1493{
1494 log("NdpCopy2 <%s> -> <%s> %d\n", szSrc, szDst, ERROR_CANNOT_COPY);
1495 return ERROR_CANNOT_COPY;
1496}
1497
1498int APIENTRY NdpForceDelete (HCONNECTION conn, NDFILEINFOL *pfi, char *szFile)
1499{
1500 Connection *pConn = (Connection *)conn;
1501 Resource *pRes = pConn->pRes;
1502 int rc = 0;
1503 unsigned long action;
1504 char path[CCHMAXPATH+1] = {0};
1505
1506 log("NdpForceDelete in\n");
1507
1508 do {
1509 rc = pathparser(pRes, pConn, szFile, path);
1510 if (rc)
1511 {
1512 break;
1513 }
1514
1515 rc = smbwrp_unlink(pConn->cli, path);
1516 } while (0);
1517 log("NdpForceDelete <%s> (%s) %d\n", szFile, path, rc);
1518
1519 return rc;
1520}
1521
1522int APIENTRY NdpCreateDir (HCONNECTION conn, NDFILEINFOL *pfiparent, char *szDirName, FEALIST *pFEAList)
1523{
1524 Connection *pConn = (Connection *)conn;
1525 Resource *pRes = pConn->pRes;
1526 int rc = 0;
1527 unsigned long action;
1528 char path[CCHMAXPATH+1] = {0};
1529
1530 log("NdpCreateDir in\n");
1531
1532 do {
1533 rc = pathparser(pRes, pConn, szDirName, path);
1534 if (rc)
1535 {
1536 break;
1537 }
1538
1539 rc = smbwrp_mkdir(pConn->cli, path);
1540 } while (0);
1541 log("NdpCreateDir <%s> (%s) %d\n", szDirName, path, rc);
1542
1543 return rc;
1544}
1545
1546int APIENTRY NdpDeleteDir (HCONNECTION conn, NDFILEINFOL *pfi, char *szDir)
1547{
1548 Connection *pConn = (Connection *)conn;
1549 Resource *pRes = pConn->pRes;
1550 int rc = 0;
1551 unsigned long action;
1552 char path[CCHMAXPATH+1] = {0};
1553
1554 log("NdpDeleteDir in\n");
1555
1556 do {
1557 rc = pathparser(pRes, pConn, szDir, path);
1558 if (rc)
1559 {
1560 break;
1561 }
1562
1563 rc = smbwrp_rmdir(pConn->cli, path);
1564 } while (0);
1565 log("NdpDeleteDir <%s> (%s) %d\n", szDir, path, rc);
1566
1567 return rc;
1568}
1569
1570int APIENTRY NdpMove (HCONNECTION conn, NDFILEINFOL *pfiDst, char *szDst, NDFILEINFOL *pfiSrc, char *szSrc)
1571{
1572 Connection *pConn = (Connection *)conn;
1573 Resource *pRes = pConn->pRes;
1574 int rc = 0;
1575 unsigned long action;
1576 char src[CCHMAXPATH+1] = {0};
1577 int l1, l2;
1578 char * p = szDst;
1579
1580 log("NdpMove in from <%s> to <%s>\n", szSrc, szDst);
1581
1582 do
1583 {
1584 rc = pathparser(pRes, pConn, szSrc, src);
1585 if (rc)
1586 {
1587 break;
1588 }
1589 l1 = StrLen(szSrc);
1590 l2 = StrLen(src);
1591 if (l1 > l2)
1592 {
1593 if (ph->fsphStrNICmp(szSrc, szDst, l1 - l2))
1594 {
1595 // the file moved accross different shares or servers or workgroups
1596 rc = ERROR_WRITE_PROTECT;
1597 break;
1598 }
1599 p = szDst + l1 - l2 + 1;
1600 }
1601 //pConn->mem[CCHMAXPATH + 1] = '\\';
1602 rc = smbwrp_rename(pConn->cli, src, p);
1603 } while (0);
1604 log("NdpMove <%s> -> <%s> (%s) %d\n", szSrc, szDst, src, rc);
1605
1606 return rc;
1607}
1608
1609int APIENTRY NdpMove2 (HCONNECTION conn, HRESOURCE resDst, NDFILEINFOL *pfiDst, char *szDst, NDFILEINFOL *pfiSrc, char *szSrc)
1610{
1611 log("NdpMove2 <%s> -> <%s> %d\n", szSrc, szDst, ERROR_WRITE_PROTECT);
1612 return ERROR_WRITE_PROTECT;
1613}
1614
1615
1616int APIENTRY NdpChangeCase (HCONNECTION conn, char *szDst, NDFILEINFOL *pfiSrc, char *szSrc, char *szNewName, ULONG ulNameLen)
1617{
1618 return NdpMove (conn, pfiSrc, szDst, pfiSrc, szSrc);
1619}
1620
1621int APIENTRY NdpRename (HCONNECTION conn, char *szDst, NDFILEINFOL *pfiSrc, char *szSrc, char *szNewName, ULONG ulNameLen)
1622{
1623 return NdpMove (conn, pfiSrc, szDst, pfiSrc, szSrc);
1624}
1625
1626int smbopen(Connection *pConn, char *szFileName, int flags, ULONG ulOpenMode, ULONG ulAttribute, FEALIST *pFEAList)
1627{
1628 Resource *pRes = pConn->pRes;
1629 unsigned long action;
1630 int rc = 0;
1631 char path[CCHMAXPATH+1] = {0};
1632
1633 log("smbopen in %d\n", pConn->file.fd);
1634
1635 do {
1636 if (pConn->file.fd > 0)
1637 {
1638 rc = ERROR_TOO_MANY_OPEN_FILES;
1639 break;
1640 }
1641
1642 rc = pathparser(pRes, pConn, szFileName, path);
1643 if (rc)
1644 {
1645 break;
1646 }
1647
1648 StrNCpy(pConn->file.fullname, szFileName, sizeof(pConn->file.fullname) - 1);
1649 StrNCpy(pConn->file.fname, path, sizeof(pConn->file.fname) - 1);
1650 flags |= O_BINARY;
1651 switch (ulOpenMode & 3)
1652 {
1653 case OPEN_ACCESS_READONLY : flags |= O_RDONLY; break;
1654 case OPEN_ACCESS_WRITEONLY : flags |= O_WRONLY; break;
1655 case OPEN_ACCESS_READWRITE : flags |= O_RDWR; break;
1656 default : flags |= O_RDWR;
1657 }
1658 pConn->file.openmode = flags;
1659 pConn->file.openattr = ulAttribute & 0x37;
1660 pConn->file.denymode = (ulOpenMode & 0x70) >> 4;
1661 rc = smbwrp_open(pConn->cli, &pConn->file);
1662 } while (0);
1663 log("smbopen <%s> (%s) %08x %08x %08x %d. file = %d\n", szFileName, path, flags, ulOpenMode, ulAttribute, rc, pConn->file.fd);
1664 if (!rc && pFEAList)
1665 {
1666 int rc1 = NdpFileEASet((HCONNECTION)pConn, (NDFILEHANDLE)0, pFEAList);
1667 log("smbopen NdpFileEASet %d. pFEAList->cbList %d\n", rc1, pFEAList->cbList);
1668 }
1669
1670 return rc;
1671}
1672
1673int APIENTRY NdpOpenReplace (HCONNECTION conn, NDFILEINFOL *pfi, NDFILEHANDLE *phandle, char *szFileName, ULONG ulSize, ULONG ulOpenMode, ULONG ulAttribute, FEALIST *pFEAList)
1674{
1675 return smbopen((Connection *)conn, szFileName, O_TRUNC, ulOpenMode, ulAttribute, pFEAList);
1676}
1677
1678int APIENTRY NdpOpenReplaceL(HCONNECTION conn, NDFILEINFO *pfi, NDFILEHANDLE *phandle, char *szFileName, LONGLONG llSize, ULONG ulOpenMode, ULONG ulAttribute, FEALIST *pFEAList)
1679{
1680 return smbopen((Connection *)conn, szFileName, O_TRUNC, ulOpenMode, ulAttribute, pFEAList);
1681}
1682
1683int APIENTRY NdpOpenCreate (HCONNECTION conn, NDFILEINFOL *pfiparent, NDFILEHANDLE *phandle, char *szFileName, ULONG ulSize, ULONG ulOpenMode, ULONG ulAttribute, FEALIST *pFEAList)
1684{
1685// return smbopen((Connection *)conn, szFileName, O_CREAT, ulOpenMode, ulAttribute);
1686 return smbopen((Connection *)conn, szFileName, O_CREAT | O_EXCL, ulOpenMode, ulAttribute, pFEAList);
1687}
1688
1689int APIENTRY NdpOpenCreateL(HCONNECTION conn, NDFILEINFO *pfiparent, NDFILEHANDLE *phandle, char *szFileName, LONGLONG llSize, ULONG ulOpenMode, ULONG ulAttribute, FEALIST *pFEAList)
1690{
1691 return smbopen((Connection *)conn, szFileName, O_CREAT | O_EXCL, ulOpenMode, ulAttribute, pFEAList);
1692}
1693
1694int APIENTRY NdpOpenExisting (HCONNECTION conn, NDFILEINFOL *pfi, NDFILEHANDLE *phandle, char *szFileName, ULONG ulOpenMode, USHORT *pfNeedEA)
1695{
1696 if (pfNeedEA) *pfNeedEA = 0; // wtf is this ?
1697 return smbopen((Connection *)conn, szFileName, 0, ulOpenMode, 0, NULL);
1698}
1699
1700int APIENTRY NdpSetFileAttribute (HCONNECTION conn, NDFILEINFOL *pfi, char *szFileName, USHORT usAttr)
1701{
1702 Connection *pConn = (Connection *)conn;
1703 Resource *pRes = pConn->pRes;
1704 int rc = 0;
1705 unsigned long action;
1706
1707 smbwrp_fileinfo finfo;
1708 char path[CCHMAXPATH+1] = {0};
1709
1710 log("NdpSetFileAttribute in\n");
1711 do {
1712 rc = pathparser(pRes, pConn, szFileName, path);
1713 if (rc)
1714 {
1715 break;
1716 }
1717
1718 MemSet(&finfo, 0, sizeof(finfo));
1719 StrNCpy(finfo.fname, path, sizeof(finfo.fname) - 1);
1720 finfo.attr = usAttr & 0x37;
1721 rc = smbwrp_setattr(pConn->cli, &finfo);
1722 } while (0);
1723 log("NdpSetFileAttribute <%s> (%s) %04x %d\n", szFileName, path, usAttr, rc);
1724
1725 return rc;
1726}
1727
1728int APIENTRY NdpFlush (HRESOURCE resource)
1729{
1730 log("NdpFlush %d\n", ERROR_NOT_SUPPORTED);
1731 return ERROR_NOT_SUPPORTED;
1732}
1733
1734int APIENTRY NdpIOCTL (int type, HRESOURCE resource, char *path, int function, void *in, ULONG insize, PULONG poutlen)
1735{
1736 log("NdpIOCTL <%s> %d\n", path, function);
1737
1738 if (in && insize > 4096)
1739 {
1740 char out[4096];
1741 sprintf (out, "SAMBA IOCTL function = %d, parms [%s] insize = %d, *poutlen = %d", function, in, insize, *poutlen);
1742 *poutlen = strlen(out);
1743 strcpy (in, out);
1744 return NO_ERROR;
1745 }
1746
1747 return ERROR_NOT_SUPPORTED;
1748}
1749
1750int APIENTRY NdpFileQueryInfo (HCONNECTION conn, NDFILEHANDLE handle, void *plist)
1751{
1752 Connection *pConn = (Connection *)conn;
1753 Resource *pRes = pConn->pRes;
1754 int rc = 0;
1755 unsigned long action;
1756 smbwrp_fileinfo finfo;
1757
1758 debug_printf("NdpFileQueryInfo in\n");
1759 do {
1760 if (pConn->file.fd < 0 || !*pConn->file.fname)
1761 {
1762 rc = ERROR_INVALID_HANDLE;
1763 break;
1764 }
1765 StrNCpy(finfo.fname, pConn->file.fname, sizeof(finfo.fname) - 1);
1766 rc = smbwrp_fgetattr(pConn->cli, &pConn->file, &finfo);
1767 if (!rc)
1768 {
1769 finfo.easize = -1;
1770 getfindinfoL(pConn, plist, &finfo, 0, NULL);
1771 }
1772 } while (0);
1773 log("NdpFileQueryInfo <%s> %d\n", pConn->file.fd < 0 ? "!null!" : pConn->file.fname, rc);
1774
1775 return rc;
1776}
1777
1778int APIENTRY NdpFileEAQuery (HCONNECTION conn, NDFILEHANDLE handle, GEALIST *pGEAList, FEALIST *pFEAList)
1779{
1780 Connection *pConn = (Connection *)conn;
1781 Resource *pRes = pConn->pRes;
1782 int rc = 0;
1783 unsigned long action;
1784 char pBuffer[64*1024];
1785 FEALIST * pFEASrc;
1786
1787 if (!pFEAList)
1788 {
1789 return ERROR_EAS_NOT_SUPPORTED;
1790 }
1791 if (!pRes->easupport)
1792 {
1793 return ERROR_EAS_NOT_SUPPORTED;
1794 }
1795
1796 log("NdpFileEAQuery in <%s>/%d pGEAList=%08x\n", pConn->file.fname, pConn->file.fd, pGEAList);
1797 do {
1798 if (pConn->file.fd < 0)
1799 {
1800 rc = ERROR_INVALID_HANDLE;
1801 break;
1802 }
1803 rc = smbwrp_flistea(pConn->cli, &pConn->file, pBuffer, sizeof( pBuffer));
1804 pFEASrc = (FEALIST *) pBuffer;
1805 if (rc)
1806 {
1807 //rc = pConn->rc ? pConn->rc : (resp.rc ? resp.rc : ERROR_INVALID_PARAMETER);
1808 switch (rc)
1809 {
1810 case ERROR_FILE_NOT_FOUND :
1811 case ERROR_PATH_NOT_FOUND :
1812 {
1813 pFEAList->cbList = sizeof(pFEAList->cbList);
1814 rc = NO_ERROR;
1815 } break;
1816 case ERROR_BUFFER_OVERFLOW :
1817 {
1818 pFEAList->cbList = pFEASrc->cbList;
1819 } break;
1820 default :
1821 {
1822 rc = ERROR_EAS_NOT_SUPPORTED;
1823 }
1824 }
1825 }
1826 else
1827 {
1828 rc = buildFEALIST(pFEASrc, pGEAList, pFEAList);
1829 }
1830 } while (0);
1831 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);
1832
1833 return rc;
1834}
1835
1836int APIENTRY NdpFileEASet (HCONNECTION conn, NDFILEHANDLE handle, FEALIST *pFEAList)
1837{
1838 Connection *pConn = (Connection *)conn;
1839 Resource *pRes = pConn->pRes;
1840 int rc = 0;
1841 unsigned long action;
1842
1843 log("NdpFileEASet in\n");
1844
1845 if (!pFEAList || pFEAList->cbList <= sizeof(long))
1846 {
1847 return ERROR_EAS_NOT_SUPPORTED;
1848 }
1849 if (!pRes->easupport)
1850 {
1851 return ERROR_EAS_NOT_SUPPORTED;
1852 }
1853
1854 do {
1855 // got FEA there
1856 FEA * pfea;
1857 unsigned long done = sizeof(long);
1858 if (pConn->file.fd < 0)
1859 {
1860 rc = ERROR_INVALID_HANDLE;
1861 break;
1862 }
1863
1864 pfea = pFEAList->list;
1865 while (done < pFEAList->cbList)
1866 {
1867 rc = smbwrp_fsetea(pConn->cli, &pConn->file, (char *)(pfea + 1), pfea->cbValue ? (char *)(pfea + 1) + pfea->cbName + 1: NULL, pfea->cbValue);
1868 if (rc)
1869 {
1870 break;
1871 }
1872 pfea = (FEA *)((char *)(pfea + 1) + pfea->cbName + 1 + pfea->cbValue);
1873 done += sizeof(FEA) + pfea->cbName + 1 + pfea->cbValue;
1874 }
1875
1876 } while (0);
1877 log("NdpFileEASet %d\n", rc);
1878
1879 return rc;
1880}
1881
1882int APIENTRY NdpFileEASize (HCONNECTION conn, NDFILEHANDLE handle, ULONG *pulEASize)
1883{
1884 Connection *pConn = (Connection *)conn;
1885 Resource *pRes = pConn->pRes;
1886 int rc = 0;
1887 unsigned long action;
1888 char path[CCHMAXPATH+1] = {0};
1889 FEALIST * pFEAList;
1890 char pBuffer[64*1024];
1891
1892 if (!pulEASize)
1893 {
1894 return ERROR_EAS_NOT_SUPPORTED;
1895 }
1896 if (!pRes->easupport)
1897 {
1898 return ERROR_EAS_NOT_SUPPORTED;
1899 }
1900
1901 log("NdpFileEASize in <%s>/%d \n", pConn->file.fname, pConn->file.fd);
1902 do {
1903 if (pConn->file.fd < 0)
1904 {
1905 rc = ERROR_INVALID_HANDLE;
1906 break;
1907 }
1908 rc = smbwrp_flistea(pConn->cli, &pConn->file, pBuffer, sizeof(pBuffer));
1909 pFEAList = (FEALIST*) pBuffer;
1910 if (rc)
1911 {
1912 //rc = pConn->rc ? pConn->rc : (resp.rc ? resp.rc : ERROR_INVALID_PARAMETER);
1913 switch (rc)
1914 {
1915 case ERROR_FILE_NOT_FOUND :
1916 case ERROR_PATH_NOT_FOUND :
1917 {
1918 pFEAList->cbList = sizeof(pFEAList->cbList);
1919 } /* Fall through */
1920 case ERROR_BUFFER_OVERFLOW :
1921 {
1922 rc = NO_ERROR;
1923 } break;
1924 default :
1925 {
1926 rc = ERROR_EAS_NOT_SUPPORTED;
1927 }
1928 }
1929 }
1930 *pulEASize = pFEAList->cbList;
1931 } while (0);
1932 log("NdpFileEASize %d %d\n", *pulEASize, rc);
1933
1934 return rc;
1935}
1936
1937int APIENTRY NdpFileSetInfo (HCONNECTION conn, NDFILEHANDLE handle, NDFILEINFOL *pfi)
1938{
1939 Connection *pConn = (Connection *)conn;
1940 Resource *pRes = pConn->pRes;
1941 int rc = 0;
1942 unsigned long action, attrFile;
1943
1944 debug_printf("NdpFileSetInfo in\n");
1945 do {
1946 if (pConn->file.fd < 0 || !*pConn->file.fname)
1947 {
1948 rc = ERROR_INVALID_HANDLE;
1949 break;
1950 }
1951 attrFile = pfi->stat.attrFile;
1952 // deferred setinfo - on closing the file
1953 pConn->file.openattr = attrFile;
1954 fsphDosDateToUnixTime(pfi->stat.fdateLastWrite, pfi->stat.ftimeLastWrite, &(pConn->file.mtime));
1955 debug_printf("NdpFileSetInfo mtime %d\n", pConn->file.mtime);
1956 } while (0);
1957 log("NdpFileSetInfo <%s> %08x %d\n", pConn->file.fd < 0 ? "!null!" : pConn->file.fname, attrFile, rc);
1958
1959 return NO_ERROR;
1960}
1961
1962int APIENTRY NdpFileSetFilePtrL(HCONNECTION conn, NDFILEHANDLE handle, LONGLONG llOffset, ULONG ulMethod, LONGLONG *pllActual)
1963{
1964 Connection *pConn = (Connection *)conn;
1965 Resource *pRes = pConn->pRes;
1966 int rc = 0;
1967 unsigned long action;
1968
1969 log("NdpFileSetFilePtrl in\n");
1970
1971 do {
1972 if (pConn->file.fd < 0)
1973 {
1974 rc = ERROR_INVALID_HANDLE;
1975 break;
1976 }
1977
1978 rc = smbwrp_lseek(pConn->cli, &pConn->file, ulMethod, llOffset);
1979 if (!rc)
1980 *pllActual = pConn->file.offset;
1981
1982 } while (0);
1983 log("NdpFileSetFilePtrL <%s> %lld %lu %lld %d\n", pConn->file.fd < 0 ? "!null!" : pConn->file.fname, llOffset, ulMethod, *pllActual, rc);
1984
1985 return rc;
1986}
1987
1988int APIENTRY NdpFileSetFilePtr (HCONNECTION conn, NDFILEHANDLE handle, LONG lOffset, ULONG ulMethod, ULONG *pulActual)
1989{
1990 LONGLONG llActual;
1991 int rc = NdpFileSetFilePtrL(conn, handle, lOffset, ulMethod, &llActual);
1992 *pulActual = llActual & 0xFFFFFFFF;
1993 log("NdpFileSetFilePtr %ld %lu %ld %d\n", lOffset, ulMethod, *pulActual, rc);
1994 return rc;
1995}
1996
1997int APIENTRY NdpFileClose (HCONNECTION conn, NDFILEHANDLE handle)
1998{
1999 Connection *pConn = (Connection *)conn;
2000 Resource *pRes = pConn->pRes;
2001 int rc = 0;
2002 unsigned long action;
2003
2004 log("NdpFileClose in %d <%s>\n", pConn->file.fd, pConn->file.fd < 0 ? "!null!" : pConn->file.fname);
2005
2006 do {
2007 if (pConn->file.fd < 0)
2008 {
2009 rc = ERROR_INVALID_HANDLE;
2010 break;
2011 }
2012
2013 rc = smbwrp_close(pConn->cli, &pConn->file);
2014
2015 } while (0);
2016 log("NdpFileClose %d %d\n", pConn->file.fd, rc);
2017
2018 pConn->file.fd = -1;
2019 return rc;
2020}
2021
2022int APIENTRY NdpFileCommit (HCONNECTION conn, NDFILEHANDLE handle)
2023{
2024 log("NdpFileCommit %d\n", NO_ERROR);
2025 return NO_ERROR;
2026}
2027
2028
2029int APIENTRY NdpFileNewSize (HCONNECTION conn, NDFILEHANDLE handle, ULONG ulLen)
2030{
2031 int rc = NdpFileNewSizeL(conn, handle, ulLen);
2032 log("NdpFileNewSize %ld %d\n", ulLen, rc);
2033 return rc;
2034}
2035
2036int APIENTRY NdpFileNewSizeL(HCONNECTION conn, NDFILEHANDLE handle, LONGLONG llLen)
2037{
2038 Connection *pConn = (Connection *)conn;
2039 Resource *pRes = pConn->pRes;
2040 int rc = 0;
2041 unsigned long action;
2042
2043 log("NdpFileNewSizeL in\n");
2044
2045 do {
2046 if (pConn->file.fd < 0)
2047 {
2048 rc = ERROR_INVALID_HANDLE;
2049 break;
2050 }
2051
2052 rc = smbwrp_setfilesize(pConn->cli, &pConn->file, llLen);
2053
2054 } while (0);
2055 log("NdpFileNewSizeL <%s> %lld %d\n", pConn->file.fd < 0 ? "!null!" : pConn->file.fname, llLen, rc);
2056
2057 return rc;
2058}
2059
2060int APIENTRY NdpFileRead (HCONNECTION conn, NDFILEHANDLE handle, void *pBuffer, ULONG ulRead, ULONG *pulActual)
2061{
2062 Connection *pConn = (Connection *)conn;
2063 Resource *pRes = pConn->pRes;
2064 int rc = 0;
2065 unsigned long done = 0;
2066 unsigned long onedone;
2067 unsigned long action;
2068
2069 log("NdpFileRead in\n");
2070
2071 do {
2072 if (pConn->file.fd < 0)
2073 {
2074 rc = ERROR_INVALID_HANDLE;
2075 break;
2076 }
2077 rc = smbwrp_read(pConn->cli, &pConn->file, pBuffer, ulRead, pulActual);
2078 //*pulActual = ulRead;
2079 //DosSleep(0);
2080
2081 } while (0);
2082 log("NdpFileRead <%s> %lu %lu %d\n", pConn->file.fd < 0 ? "!null!" : pConn->file.fname, ulRead, *pulActual, rc);
2083
2084 return rc;
2085}
2086
2087int APIENTRY NdpFileWrite (HCONNECTION conn, NDFILEHANDLE handle, void *pBuffer, ULONG ulWrite, ULONG *pulActual)
2088{
2089 Connection *pConn = (Connection *)conn;
2090 Resource *pRes = pConn->pRes;
2091 int rc = 0;
2092 unsigned long done = 0;
2093 unsigned long onedone;
2094 unsigned long action;
2095
2096 log("NdpFileWrite in\n");
2097
2098 do {
2099 if (pConn->file.fd < 0)
2100 {
2101 rc = ERROR_INVALID_HANDLE;
2102 break;
2103 }
2104 rc = smbwrp_write(pConn->cli, &pConn->file, pBuffer, ulWrite, pulActual);
2105
2106 } while (0);
2107 log("NdpFileWrite <%s> %lu %lu %d\n", pConn->file.fd < 0 ? "!null!" : pConn->file.fname, ulWrite, *pulActual, rc);
2108
2109 return rc;
2110}
2111
Note: See TracBrowser for help on using the repository browser.