source: trunk/client/src/ndpsmb.c@ 505

Last change on this file since 505 was 505, checked in by Silvan Scherrer, 15 years ago

samba client 2.1: packing and more

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