FreeRDP
Loading...
Searching...
No Matches
client_cliprdr_file.c
1
24#include <freerdp/config.h>
25
26#include <stdlib.h>
27#include <errno.h>
28
29#ifdef WITH_FUSE
30#define FUSE_USE_VERSION 30
31#include <fuse_lowlevel.h>
32#endif
33
34#if defined(WITH_FUSE)
35#include <sys/mount.h>
36#include <sys/stat.h>
37#include <errno.h>
38#include <time.h>
39#endif
40
41#include <winpr/crt.h>
42#include <winpr/string.h>
43#include <winpr/assert.h>
44#include <winpr/image.h>
45#include <winpr/stream.h>
46#include <winpr/clipboard.h>
47#include <winpr/path.h>
48
49#include <freerdp/utils/signal.h>
50#include <freerdp/log.h>
51#include <freerdp/client/cliprdr.h>
52#include <freerdp/channels/channels.h>
53#include <freerdp/channels/cliprdr.h>
54
55#include <freerdp/client/client_cliprdr_file.h>
56
57#define NO_CLIP_DATA_ID (UINT64_C(1) << 32)
58#define WIN32_FILETIME_TO_UNIX_EPOCH INT64_C(11644473600)
59
60#ifdef WITH_DEBUG_CLIPRDR
61#define DEBUG_CLIPRDR(log, ...) WLog_Print(log, WLOG_DEBUG, __VA_ARGS__)
62#else
63#define DEBUG_CLIPRDR(log, ...) \
64 do \
65 { \
66 } while (0)
67#endif
68
69#if defined(WITH_FUSE)
70typedef enum eFuseLowlevelOperationType
71{
72 FUSE_LL_OPERATION_NONE,
73 FUSE_LL_OPERATION_LOOKUP,
74 FUSE_LL_OPERATION_GETATTR,
75 FUSE_LL_OPERATION_READ,
76} FuseLowlevelOperationType;
77
78typedef struct sCliprdrFuseFile CliprdrFuseFile;
79
80struct sCliprdrFuseFile
81{
82 CliprdrFuseFile* parent;
83 wArrayList* children;
84
85 size_t filename_len;
86 const char* filename;
87
88 size_t filename_with_root_len;
89 char* filename_with_root;
90 UINT32 list_idx;
91 fuse_ino_t ino;
92
93 BOOL is_directory;
94 BOOL is_readonly;
95
96 BOOL has_size;
97 UINT64 size;
98
99 BOOL has_last_write_time;
100 INT64 last_write_time_unix;
101
102 BOOL has_clip_data_id;
103 UINT32 clip_data_id;
104};
105
106typedef struct
107{
108 CliprdrFileContext* file_context;
109
110 CliprdrFuseFile* clip_data_dir;
111
112 BOOL has_clip_data_id;
113 UINT32 clip_data_id;
114} CliprdrFuseClipDataEntry;
115
116typedef struct
117{
118 CliprdrFileContext* file_context;
119
120 wArrayList* fuse_files;
121
122 BOOL all_files;
123 BOOL has_clip_data_id;
124 UINT32 clip_data_id;
125} FuseFileClearContext;
126
127typedef struct
128{
129 FuseLowlevelOperationType operation_type;
130 CliprdrFuseFile* fuse_file;
131 fuse_req_t fuse_req;
132 UINT32 stream_id;
133} CliprdrFuseRequest;
134
135typedef struct
136{
137 CliprdrFuseFile* parent;
138 char* parent_path;
139} CliprdrFuseFindParentContext;
140#endif
141
142typedef struct
143{
144 char* name;
145 FILE* fp;
146 INT64 size;
147 CliprdrFileContext* context;
148} CliprdrLocalFile;
149
150typedef struct
151{
152 UINT32 lockId;
153 BOOL locked;
154 size_t count;
155 CliprdrLocalFile* files;
156 CliprdrFileContext* context;
157} CliprdrLocalStream;
158
159struct cliprdr_file_context
160{
161#if defined(WITH_FUSE)
162 /* FUSE related**/
163 HANDLE fuse_start_sync;
164 HANDLE fuse_stop_sync;
165 HANDLE fuse_thread;
166 struct fuse_session* fuse_sess;
167#if FUSE_USE_VERSION < 30
168 struct fuse_chan* ch;
169#endif
170
171 wHashTable* inode_table;
172 wHashTable* clip_data_table;
173 wHashTable* request_table;
174
175 CliprdrFuseClipDataEntry* clip_data_entry_without_id;
176 UINT32 current_clip_data_id;
177
178 fuse_ino_t next_ino;
179 UINT32 next_clip_data_id;
180 UINT32 next_stream_id;
181#endif
182
183 /* File clipping */
184 BOOL file_formats_registered;
185 UINT32 file_capability_flags;
186
187 UINT32 local_lock_id;
188
189 wHashTable* local_streams;
190 wLog* log;
191 void* clipboard;
192 CliprdrClientContext* context;
193 char* path;
194 char* exposed_path;
195 BYTE server_data_hash[WINPR_SHA256_DIGEST_LENGTH];
196 BYTE client_data_hash[WINPR_SHA256_DIGEST_LENGTH];
197};
198
199#if defined(WITH_FUSE)
200static CliprdrFuseFile* get_fuse_file_by_ino(CliprdrFileContext* file_context, fuse_ino_t fuse_ino);
201
202static void fuse_file_free(void* data)
203{
204 CliprdrFuseFile* fuse_file = data;
205
206 if (!fuse_file)
207 return;
208
209 ArrayList_Free(fuse_file->children);
210 free(fuse_file->filename_with_root);
211
212 free(fuse_file);
213}
214
215WINPR_ATTR_FORMAT_ARG(1, 2)
216WINPR_ATTR_MALLOC(fuse_file_free, 1)
217WINPR_ATTR_NODISCARD
218static CliprdrFuseFile* fuse_file_new(WINPR_FORMAT_ARG const char* fmt, ...)
219{
220 CliprdrFuseFile* file = calloc(1, sizeof(CliprdrFuseFile));
221 if (!file)
222 return nullptr;
223
224 file->children = ArrayList_New(FALSE);
225 if (!file->children)
226 goto fail;
227
228 WINPR_ASSERT(fmt);
229
230 {
231 va_list ap = WINPR_C_ARRAY_INIT;
232 va_start(ap, fmt);
233 const int rc =
234 winpr_vasprintf(&file->filename_with_root, &file->filename_with_root_len, fmt, ap);
235 va_end(ap);
236
237 if (rc < 0)
238 goto fail;
239 }
240
241 if (file->filename_with_root && (file->filename_with_root_len > 0))
242 {
243 file->filename_len = 0;
244 file->filename = strrchr(file->filename_with_root, '/') + 1;
245 if (file->filename)
246 file->filename_len = strnlen(file->filename, file->filename_with_root_len);
247 }
248 return file;
249fail:
250 fuse_file_free(file);
251 return nullptr;
252}
253
254static void clip_data_entry_free(void* data)
255{
256 CliprdrFuseClipDataEntry* clip_data_entry = data;
257
258 if (!clip_data_entry)
259 return;
260
261 if (clip_data_entry->has_clip_data_id)
262 {
263 CliprdrFileContext* file_context = clip_data_entry->file_context;
264 CLIPRDR_UNLOCK_CLIPBOARD_DATA unlock_clipboard_data = WINPR_C_ARRAY_INIT;
265
266 WINPR_ASSERT(file_context);
267
268 unlock_clipboard_data.common.msgType = CB_UNLOCK_CLIPDATA;
269 unlock_clipboard_data.clipDataId = clip_data_entry->clip_data_id;
270
271 const UINT rc = file_context->context->ClientUnlockClipboardData(file_context->context,
272 &unlock_clipboard_data);
273 if (rc != CHANNEL_RC_OK)
274 WLog_Print(file_context->log, WLOG_DEBUG,
275 "ClientUnlockClipboardData failed with %" PRIu32, rc);
276
277 clip_data_entry->has_clip_data_id = FALSE;
278
279 WLog_Print(file_context->log, WLOG_DEBUG, "Destroyed ClipDataEntry with id %u",
280 clip_data_entry->clip_data_id);
281 }
282
283 free(clip_data_entry);
284}
285
286static BOOL does_server_support_clipdata_locking(CliprdrFileContext* file_context)
287{
288 WINPR_ASSERT(file_context);
289
290 return (cliprdr_file_context_remote_get_flags(file_context) & CB_CAN_LOCK_CLIPDATA) != 0;
291}
292
293static UINT32 get_next_free_clip_data_id(CliprdrFileContext* file_context)
294{
295 UINT32 clip_data_id = 0;
296
297 WINPR_ASSERT(file_context);
298
299 HashTable_Lock(file_context->inode_table);
300 clip_data_id = file_context->next_clip_data_id;
301 while (clip_data_id == 0 ||
302 HashTable_GetItemValue(file_context->clip_data_table, (void*)(uintptr_t)clip_data_id))
303 ++clip_data_id;
304
305 file_context->next_clip_data_id = clip_data_id + 1;
306 HashTable_Unlock(file_context->inode_table);
307
308 return clip_data_id;
309}
310
311static CliprdrFuseClipDataEntry* clip_data_entry_new(CliprdrFileContext* file_context,
312 BOOL needs_clip_data_id)
313{
314 CliprdrFuseClipDataEntry* clip_data_entry = nullptr;
315 CLIPRDR_LOCK_CLIPBOARD_DATA lock_clipboard_data = WINPR_C_ARRAY_INIT;
316
317 WINPR_ASSERT(file_context);
318
319 clip_data_entry = calloc(1, sizeof(CliprdrFuseClipDataEntry));
320 if (!clip_data_entry)
321 return nullptr;
322
323 clip_data_entry->file_context = file_context;
324 clip_data_entry->clip_data_id = get_next_free_clip_data_id(file_context);
325
326 if (!needs_clip_data_id)
327 return clip_data_entry;
328
329 lock_clipboard_data.common.msgType = CB_LOCK_CLIPDATA;
330 lock_clipboard_data.clipDataId = clip_data_entry->clip_data_id;
331
332 if (file_context->context->ClientLockClipboardData(file_context->context, &lock_clipboard_data))
333 {
334 HashTable_Lock(file_context->inode_table);
335 clip_data_entry_free(clip_data_entry);
336 HashTable_Unlock(file_context->inode_table);
337 return nullptr;
338 }
339 clip_data_entry->has_clip_data_id = TRUE;
340
341 WLog_Print(file_context->log, WLOG_DEBUG, "Created ClipDataEntry with id %u",
342 clip_data_entry->clip_data_id);
343
344 return clip_data_entry;
345}
346
347static BOOL should_remove_fuse_file(CliprdrFuseFile* fuse_file, BOOL all_files,
348 BOOL has_clip_data_id, UINT32 clip_data_id)
349{
350 if (all_files)
351 return TRUE;
352
353 if (fuse_file->ino == FUSE_ROOT_ID)
354 return FALSE;
355 if (!fuse_file->has_clip_data_id && !has_clip_data_id)
356 return TRUE;
357 if (fuse_file->has_clip_data_id && has_clip_data_id &&
358 (fuse_file->clip_data_id == clip_data_id))
359 return TRUE;
360
361 return FALSE;
362}
363
364static BOOL maybe_clear_fuse_request(const void* key, void* value, void* arg)
365{
366 CliprdrFuseRequest* fuse_request = value;
367 FuseFileClearContext* clear_context = arg;
368 CliprdrFileContext* file_context = clear_context->file_context;
369 CliprdrFuseFile* fuse_file = fuse_request->fuse_file;
370
371 WINPR_ASSERT(file_context);
372
373 if (!should_remove_fuse_file(fuse_file, clear_context->all_files,
374 clear_context->has_clip_data_id, clear_context->clip_data_id))
375 return TRUE;
376
377 DEBUG_CLIPRDR(file_context->log, "Clearing FileContentsRequest for file \"%s\"",
378 fuse_file->filename_with_root);
379
380 fuse_reply_err(fuse_request->fuse_req, EIO);
381 HashTable_Remove(file_context->request_table, key);
382
383 return TRUE;
384}
385
386static BOOL maybe_steal_inode(const void* key, void* value, void* arg)
387{
388 CliprdrFuseFile* fuse_file = value;
389 FuseFileClearContext* clear_context = arg;
390 CliprdrFileContext* file_context = clear_context->file_context;
391
392 WINPR_ASSERT(file_context);
393
394 if (should_remove_fuse_file(fuse_file, clear_context->all_files,
395 clear_context->has_clip_data_id, clear_context->clip_data_id))
396 {
397 if (!ArrayList_Append(clear_context->fuse_files, fuse_file))
398 WLog_Print(file_context->log, WLOG_ERROR,
399 "Failed to append FUSE file to list for deletion");
400
401 HashTable_Remove(file_context->inode_table, key);
402 }
403
404 return TRUE;
405}
406
407static BOOL notify_delete_child(void* data, WINPR_ATTR_UNUSED size_t index, va_list ap)
408{
409 CliprdrFuseFile* child = data;
410
411 WINPR_ASSERT(child);
412
413 CliprdrFileContext* file_context = va_arg(ap, CliprdrFileContext*);
414 CliprdrFuseFile* parent = va_arg(ap, CliprdrFuseFile*);
415
416 WINPR_ASSERT(file_context);
417 WINPR_ASSERT(parent);
418
419 WINPR_ASSERT(file_context->fuse_sess);
420 fuse_lowlevel_notify_delete(file_context->fuse_sess, parent->ino, child->ino, child->filename,
421 child->filename_len);
422
423 return TRUE;
424}
425
426static BOOL invalidate_inode(void* data, WINPR_ATTR_UNUSED size_t index, va_list ap)
427{
428 CliprdrFuseFile* fuse_file = data;
429
430 WINPR_ASSERT(fuse_file);
431
432 CliprdrFileContext* file_context = va_arg(ap, CliprdrFileContext*);
433 WINPR_ASSERT(file_context);
434 WINPR_ASSERT(file_context->fuse_sess);
435
436 ArrayList_ForEach(fuse_file->children, notify_delete_child, file_context, fuse_file);
437
438 DEBUG_CLIPRDR(file_context->log, "Invalidating inode %lu for file \"%s\"", fuse_file->ino,
439 fuse_file->filename);
440 fuse_lowlevel_notify_inval_inode(file_context->fuse_sess, fuse_file->ino, 0, 0);
441 WLog_Print(file_context->log, WLOG_DEBUG, "Inode %lu invalidated", fuse_file->ino);
442
443 return TRUE;
444}
445
446static void clear_selection(CliprdrFileContext* file_context, BOOL all_selections,
447 CliprdrFuseClipDataEntry* clip_data_entry)
448{
449 FuseFileClearContext clear_context = WINPR_C_ARRAY_INIT;
450 CliprdrFuseFile* clip_data_dir = nullptr;
451
452 WINPR_ASSERT(file_context);
453
454 clear_context.file_context = file_context;
455 clear_context.fuse_files = ArrayList_New(FALSE);
456 WINPR_ASSERT(clear_context.fuse_files);
457
458 wObject* aobj = ArrayList_Object(clear_context.fuse_files);
459 WINPR_ASSERT(aobj);
460 aobj->fnObjectFree = fuse_file_free;
461
462 if (clip_data_entry)
463 {
464 clip_data_dir = clip_data_entry->clip_data_dir;
465 clip_data_entry->clip_data_dir = nullptr;
466
467 WINPR_ASSERT(clip_data_dir);
468
469 CliprdrFuseFile* root_dir = get_fuse_file_by_ino(file_context, FUSE_ROOT_ID);
470 if (root_dir)
471 ArrayList_Remove(root_dir->children, clip_data_dir);
472
473 clear_context.has_clip_data_id = clip_data_dir->has_clip_data_id;
474 clear_context.clip_data_id = clip_data_dir->clip_data_id;
475 }
476 clear_context.all_files = all_selections;
477
478 if (clip_data_entry && clip_data_entry->has_clip_data_id)
479 WLog_Print(file_context->log, WLOG_DEBUG, "Clearing selection for clipDataId %u",
480 clip_data_entry->clip_data_id);
481 else
482 WLog_Print(file_context->log, WLOG_DEBUG, "Clearing selection%s",
483 all_selections ? "s" : "");
484
485 HashTable_Foreach(file_context->request_table, maybe_clear_fuse_request, &clear_context);
486 HashTable_Foreach(file_context->inode_table, maybe_steal_inode, &clear_context);
487 HashTable_Unlock(file_context->inode_table);
488
489 if (file_context->fuse_sess)
490 {
491 /*
492 * fuse_lowlevel_notify_inval_inode() is a blocking operation. If we receive a
493 * FUSE request (e.g. read()), then FUSE would block in read(), since the
494 * mutex of the inode_table would still be locked, if we wouldn't unlock it
495 * here.
496 * So, to avoid a deadlock here, unlock the mutex and reply all incoming
497 * operations with -ENOENT until the invalidation process is complete.
498 */
499 ArrayList_ForEach(clear_context.fuse_files, invalidate_inode, file_context);
500 CliprdrFuseFile* root_dir = get_fuse_file_by_ino(file_context, FUSE_ROOT_ID);
501 if (clip_data_dir && root_dir)
502 {
503 fuse_lowlevel_notify_delete(file_context->fuse_sess, root_dir->ino, clip_data_dir->ino,
504 clip_data_dir->filename, clip_data_dir->filename_len);
505 }
506 }
507 ArrayList_Free(clear_context.fuse_files);
508
509 HashTable_Lock(file_context->inode_table);
510 if (clip_data_entry && clip_data_entry->has_clip_data_id)
511 WLog_Print(file_context->log, WLOG_DEBUG, "Selection cleared for clipDataId %u",
512 clip_data_entry->clip_data_id);
513 else
514 WLog_Print(file_context->log, WLOG_DEBUG, "Selection%s cleared", all_selections ? "s" : "");
515}
516
517static void clear_entry_selection(CliprdrFuseClipDataEntry* clip_data_entry)
518{
519 WINPR_ASSERT(clip_data_entry);
520
521 if (!clip_data_entry->clip_data_dir)
522 return;
523
524 clear_selection(clip_data_entry->file_context, FALSE, clip_data_entry);
525}
526
527static void clear_no_cdi_entry(CliprdrFileContext* file_context)
528{
529 WINPR_ASSERT(file_context);
530
531 WINPR_ASSERT(file_context->inode_table);
532 HashTable_Lock(file_context->inode_table);
533 if (file_context->clip_data_entry_without_id)
534 {
535 clear_entry_selection(file_context->clip_data_entry_without_id);
536
537 clip_data_entry_free(file_context->clip_data_entry_without_id);
538 file_context->clip_data_entry_without_id = nullptr;
539 }
540 HashTable_Unlock(file_context->inode_table);
541}
542
543static BOOL clear_clip_data_entries(WINPR_ATTR_UNUSED const void* key, void* value,
544 WINPR_ATTR_UNUSED void* arg)
545{
546 clear_entry_selection(value);
547
548 return TRUE;
549}
550
551static void clear_cdi_entries(CliprdrFileContext* file_context)
552{
553 WINPR_ASSERT(file_context);
554
555 HashTable_Lock(file_context->inode_table);
556 HashTable_Foreach(file_context->clip_data_table, clear_clip_data_entries, nullptr);
557
558 HashTable_Clear(file_context->clip_data_table);
559 HashTable_Unlock(file_context->inode_table);
560}
561
562static UINT prepare_clip_data_entry_with_id(CliprdrFileContext* file_context)
563{
564 CliprdrFuseClipDataEntry* clip_data_entry = nullptr;
565
566 WINPR_ASSERT(file_context);
567
568 clip_data_entry = clip_data_entry_new(file_context, TRUE);
569 if (!clip_data_entry)
570 {
571 WLog_Print(file_context->log, WLOG_ERROR, "Failed to create clipDataEntry");
572 return ERROR_INTERNAL_ERROR;
573 }
574
575 HashTable_Lock(file_context->inode_table);
576 if (!HashTable_Insert(file_context->clip_data_table,
577 (void*)(uintptr_t)clip_data_entry->clip_data_id, clip_data_entry))
578 {
579 WLog_Print(file_context->log, WLOG_ERROR, "Failed to insert clipDataEntry");
580 clip_data_entry_free(clip_data_entry);
581 HashTable_Unlock(file_context->inode_table);
582 return ERROR_INTERNAL_ERROR;
583 }
584 HashTable_Unlock(file_context->inode_table);
585
586 // HashTable_Insert owns clip_data_entry
587 // NOLINTNEXTLINE(clang-analyzer-unix.Malloc)
588 file_context->current_clip_data_id = clip_data_entry->clip_data_id;
589
590 return CHANNEL_RC_OK;
591}
592
593static UINT prepare_clip_data_entry_without_id(CliprdrFileContext* file_context)
594{
595 WINPR_ASSERT(file_context);
596 WINPR_ASSERT(!file_context->clip_data_entry_without_id);
597
598 file_context->clip_data_entry_without_id = clip_data_entry_new(file_context, FALSE);
599 if (!file_context->clip_data_entry_without_id)
600 {
601 WLog_Print(file_context->log, WLOG_ERROR, "Failed to create clipDataEntry");
602 return ERROR_INTERNAL_ERROR;
603 }
604
605 return CHANNEL_RC_OK;
606}
607#endif
608
609UINT cliprdr_file_context_notify_new_server_format_list(CliprdrFileContext* file_context)
610{
611 UINT rc = CHANNEL_RC_OK;
612 WINPR_ASSERT(file_context);
613 WINPR_ASSERT(file_context->context);
614
615#if defined(WITH_FUSE)
616 clear_no_cdi_entry(file_context);
617 /* TODO: assign timeouts to old locks instead */
618 clear_cdi_entries(file_context);
619
620 if (does_server_support_clipdata_locking(file_context))
621 rc = prepare_clip_data_entry_with_id(file_context);
622 else
623 rc = prepare_clip_data_entry_without_id(file_context);
624#endif
625 return rc;
626}
627
628UINT cliprdr_file_context_notify_new_client_format_list(CliprdrFileContext* file_context)
629{
630 WINPR_ASSERT(file_context);
631 WINPR_ASSERT(file_context->context);
632
633#if defined(WITH_FUSE)
634 clear_no_cdi_entry(file_context);
635 /* TODO: assign timeouts to old locks instead */
636 clear_cdi_entries(file_context);
637#endif
638
639 return CHANNEL_RC_OK;
640}
641
642static CliprdrLocalStream* cliprdr_local_stream_new(CliprdrFileContext* context, UINT32 streamID,
643 const char* data, size_t size);
644static void cliprdr_file_session_terminate(CliprdrFileContext* file, BOOL stop_thread);
645static BOOL local_stream_discard(const void* key, void* value, void* arg);
646
647WINPR_ATTR_FORMAT_ARG(6, 7)
648static void writelog(wLog* log, DWORD level, const char* fname, const char* fkt, size_t line,
649 WINPR_FORMAT_ARG const char* fmt, ...)
650{
651 if (!WLog_IsLevelActive(log, level))
652 return;
653
654 va_list ap = WINPR_C_ARRAY_INIT;
655 va_start(ap, fmt);
656 WLog_PrintTextMessageVA(log, level, line, fname, fkt, fmt, ap);
657 va_end(ap);
658}
659
660#if defined(WITH_FUSE)
661static CliprdrFuseFile* fuse_file_new_root(CliprdrFileContext* file_context);
662static void cliprdr_file_fuse_lookup(fuse_req_t req, fuse_ino_t parent, const char* name);
663static void cliprdr_file_fuse_getattr(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info* fi);
664static void cliprdr_file_fuse_readdir(fuse_req_t req, fuse_ino_t ino, size_t size, off_t off,
665 struct fuse_file_info* fi);
666static void cliprdr_file_fuse_read(fuse_req_t req, fuse_ino_t ino, size_t size, off_t off,
667 struct fuse_file_info* fi);
668static void cliprdr_file_fuse_open(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info* fi);
669static void cliprdr_file_fuse_opendir(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info* fi);
670
671static const struct fuse_lowlevel_ops cliprdr_file_fuse_oper = {
672 .lookup = cliprdr_file_fuse_lookup,
673 .getattr = cliprdr_file_fuse_getattr,
674 .readdir = cliprdr_file_fuse_readdir,
675 .open = cliprdr_file_fuse_open,
676 .read = cliprdr_file_fuse_read,
677 .opendir = cliprdr_file_fuse_opendir,
678};
679
680CliprdrFuseFile* get_fuse_file_by_ino(CliprdrFileContext* file_context, fuse_ino_t fuse_ino)
681{
682 WINPR_ASSERT(file_context);
683
684 return HashTable_GetItemValue(file_context->inode_table, (void*)(uintptr_t)fuse_ino);
685}
686
687static CliprdrFuseFile*
688get_fuse_file_by_name_from_parent(WINPR_ATTR_UNUSED CliprdrFileContext* file_context,
689 CliprdrFuseFile* parent, const char* name)
690{
691 WINPR_ASSERT(file_context);
692 WINPR_ASSERT(parent);
693
694 for (size_t i = 0; i < ArrayList_Count(parent->children); ++i)
695 {
696 CliprdrFuseFile* child = ArrayList_GetItem(parent->children, i);
697
698 WINPR_ASSERT(child);
699
700 if (strncmp(name, child->filename, child->filename_len + 1) == 0)
701 return child;
702 }
703
704 DEBUG_CLIPRDR(file_context->log, "Requested file \"%s\" in directory \"%s\" does not exist",
705 name, parent->filename);
706
707 return nullptr;
708}
709
710static CliprdrFuseRequest* cliprdr_fuse_request_new(CliprdrFileContext* file_context,
711 CliprdrFuseFile* fuse_file, fuse_req_t fuse_req,
712 FuseLowlevelOperationType operation_type)
713{
714 CliprdrFuseRequest* fuse_request = nullptr;
715 UINT32 stream_id = file_context->next_stream_id;
716
717 WINPR_ASSERT(file_context);
718 WINPR_ASSERT(fuse_file);
719
720 fuse_request = calloc(1, sizeof(CliprdrFuseRequest));
721 if (!fuse_request)
722 {
723 WLog_Print(file_context->log, WLOG_ERROR, "Failed to allocate FUSE request for file \"%s\"",
724 fuse_file->filename_with_root);
725 return nullptr;
726 }
727
728 fuse_request->fuse_file = fuse_file;
729 fuse_request->fuse_req = fuse_req;
730 fuse_request->operation_type = operation_type;
731
732 while (stream_id == 0 ||
733 HashTable_GetItemValue(file_context->request_table, (void*)(uintptr_t)stream_id))
734 ++stream_id;
735 fuse_request->stream_id = stream_id;
736
737 file_context->next_stream_id = stream_id + 1;
738
739 if (!HashTable_Insert(file_context->request_table, (void*)(uintptr_t)fuse_request->stream_id,
740 fuse_request))
741 {
742 WLog_Print(file_context->log, WLOG_ERROR, "Failed to track FUSE request for file \"%s\"",
743 fuse_file->filename_with_root);
744 free(fuse_request);
745 return nullptr;
746 }
747
748 return fuse_request;
749}
750
751static BOOL request_file_size_async(CliprdrFileContext* file_context, CliprdrFuseFile* fuse_file,
752 fuse_req_t fuse_req, FuseLowlevelOperationType operation_type)
753{
754 CliprdrFuseRequest* fuse_request = nullptr;
755 CLIPRDR_FILE_CONTENTS_REQUEST file_contents_request = WINPR_C_ARRAY_INIT;
756
757 WINPR_ASSERT(file_context);
758 WINPR_ASSERT(fuse_file);
759
760 fuse_request = cliprdr_fuse_request_new(file_context, fuse_file, fuse_req, operation_type);
761 if (!fuse_request)
762 return FALSE;
763
764 file_contents_request.common.msgType = CB_FILECONTENTS_REQUEST;
765 file_contents_request.streamId = fuse_request->stream_id;
766 file_contents_request.listIndex = fuse_file->list_idx;
767 file_contents_request.dwFlags = FILECONTENTS_SIZE;
768 file_contents_request.cbRequested = 0x8;
769 file_contents_request.haveClipDataId = fuse_file->has_clip_data_id;
770 file_contents_request.clipDataId = fuse_file->clip_data_id;
771
772 if (file_context->context->ClientFileContentsRequest(file_context->context,
773 &file_contents_request))
774 {
775 WLog_Print(file_context->log, WLOG_ERROR,
776 "Failed to send FileContentsRequest for file \"%s\"",
777 fuse_file->filename_with_root);
778 HashTable_Remove(file_context->request_table, (void*)(uintptr_t)fuse_request->stream_id);
779 return FALSE;
780 }
781 // NOLINTNEXTLINE(clang-analyzer-unix.Malloc)
782 DEBUG_CLIPRDR(file_context->log, "Requested file size for file \"%s\" with stream id %u",
783 fuse_file->filename, fuse_request->stream_id);
784
785 // NOLINTNEXTLINE(clang-analyzer-unix.Malloc)
786 return TRUE;
787}
788
789static void write_file_attributes(CliprdrFuseFile* fuse_file, struct stat* attr)
790{
791 memset(attr, 0, sizeof(struct stat));
792
793 if (!fuse_file)
794 return;
795
796 attr->st_ino = fuse_file->ino;
797 if (fuse_file->is_directory)
798 {
799 attr->st_mode = S_IFDIR | (fuse_file->is_readonly ? 0555 : 0755);
800 attr->st_nlink = 2;
801 }
802 else
803 {
804 attr->st_mode = S_IFREG | (fuse_file->is_readonly ? 0444 : 0644);
805 attr->st_nlink = 1;
806 attr->st_size = WINPR_ASSERTING_INT_CAST(off_t, fuse_file->size);
807 }
808 attr->st_uid = getuid();
809 attr->st_gid = getgid();
810 attr->st_atime = attr->st_mtime = attr->st_ctime =
811 (fuse_file->has_last_write_time ? fuse_file->last_write_time_unix : time(nullptr));
812}
813
814static void cliprdr_file_fuse_lookup(fuse_req_t fuse_req, fuse_ino_t parent_ino, const char* name)
815{
816 CliprdrFileContext* file_context = fuse_req_userdata(fuse_req);
817 CliprdrFuseFile* parent = nullptr;
818 CliprdrFuseFile* fuse_file = nullptr;
819 struct fuse_entry_param entry = WINPR_C_ARRAY_INIT;
820
821 WINPR_ASSERT(file_context);
822
823 HashTable_Lock(file_context->inode_table);
824 if (!(parent = get_fuse_file_by_ino(file_context, parent_ino)) || !parent->is_directory)
825 {
826 HashTable_Unlock(file_context->inode_table);
827 fuse_reply_err(fuse_req, ENOENT);
828 return;
829 }
830 if (!(fuse_file = get_fuse_file_by_name_from_parent(file_context, parent, name)))
831 {
832 HashTable_Unlock(file_context->inode_table);
833 fuse_reply_err(fuse_req, ENOENT);
834 return;
835 }
836
837 DEBUG_CLIPRDR(file_context->log, "lookup() has been called for \"%s\"", name);
838 DEBUG_CLIPRDR(file_context->log, "Parent is \"%s\", child is \"%s\"",
839 parent->filename_with_root, fuse_file->filename_with_root);
840
841 if (!fuse_file->is_directory && !fuse_file->has_size)
842 {
843 BOOL result = 0;
844
845 result =
846 request_file_size_async(file_context, fuse_file, fuse_req, FUSE_LL_OPERATION_LOOKUP);
847 HashTable_Unlock(file_context->inode_table);
848
849 if (!result)
850 fuse_reply_err(fuse_req, EIO);
851
852 return;
853 }
854
855 entry.ino = fuse_file->ino;
856 write_file_attributes(fuse_file, &entry.attr);
857 entry.attr_timeout = 1.0;
858 entry.entry_timeout = 1.0;
859 HashTable_Unlock(file_context->inode_table);
860
861 fuse_reply_entry(fuse_req, &entry);
862}
863
864static void cliprdr_file_fuse_getattr(fuse_req_t fuse_req, fuse_ino_t fuse_ino,
865 WINPR_ATTR_UNUSED struct fuse_file_info* file_info)
866{
867 CliprdrFileContext* file_context = fuse_req_userdata(fuse_req);
868 CliprdrFuseFile* fuse_file = nullptr;
869 struct stat attr = WINPR_C_ARRAY_INIT;
870
871 WINPR_ASSERT(file_context);
872
873 HashTable_Lock(file_context->inode_table);
874 if (!(fuse_file = get_fuse_file_by_ino(file_context, fuse_ino)))
875 {
876 HashTable_Unlock(file_context->inode_table);
877 fuse_reply_err(fuse_req, ENOENT);
878 return;
879 }
880
881 DEBUG_CLIPRDR(file_context->log, "getattr() has been called for file \"%s\"",
882 fuse_file->filename_with_root);
883
884 if (!fuse_file->is_directory && !fuse_file->has_size)
885 {
886 BOOL result = 0;
887
888 result =
889 request_file_size_async(file_context, fuse_file, fuse_req, FUSE_LL_OPERATION_GETATTR);
890 HashTable_Unlock(file_context->inode_table);
891
892 if (!result)
893 fuse_reply_err(fuse_req, EIO);
894
895 return;
896 }
897
898 write_file_attributes(fuse_file, &attr);
899 HashTable_Unlock(file_context->inode_table);
900
901 fuse_reply_attr(fuse_req, &attr, 1.0);
902}
903
904static void cliprdr_file_fuse_open(fuse_req_t fuse_req, fuse_ino_t fuse_ino,
905 struct fuse_file_info* file_info)
906{
907 CliprdrFileContext* file_context = fuse_req_userdata(fuse_req);
908 CliprdrFuseFile* fuse_file = nullptr;
909
910 WINPR_ASSERT(file_context);
911
912 HashTable_Lock(file_context->inode_table);
913 if (!(fuse_file = get_fuse_file_by_ino(file_context, fuse_ino)))
914 {
915 HashTable_Unlock(file_context->inode_table);
916 fuse_reply_err(fuse_req, ENOENT);
917 return;
918 }
919 if (fuse_file->is_directory)
920 {
921 HashTable_Unlock(file_context->inode_table);
922 fuse_reply_err(fuse_req, EISDIR);
923 return;
924 }
925 HashTable_Unlock(file_context->inode_table);
926
927 if ((file_info->flags & O_ACCMODE) != O_RDONLY)
928 {
929 fuse_reply_err(fuse_req, EACCES);
930 return;
931 }
932
933 /* Important for KDE to get file correctly */
934 file_info->direct_io = 1;
935
936 fuse_reply_open(fuse_req, file_info);
937}
938
939static BOOL request_file_range_async(CliprdrFileContext* file_context, CliprdrFuseFile* fuse_file,
940 fuse_req_t fuse_req, off_t offset, size_t requested_size)
941{
942 CLIPRDR_FILE_CONTENTS_REQUEST file_contents_request = WINPR_C_ARRAY_INIT;
943
944 WINPR_ASSERT(file_context);
945 WINPR_ASSERT(fuse_file);
946
947 if (requested_size > UINT32_MAX)
948 return FALSE;
949
950 CliprdrFuseRequest* fuse_request =
951 cliprdr_fuse_request_new(file_context, fuse_file, fuse_req, FUSE_LL_OPERATION_READ);
952 if (!fuse_request)
953 return FALSE;
954
955 file_contents_request.common.msgType = CB_FILECONTENTS_REQUEST;
956 file_contents_request.streamId = fuse_request->stream_id;
957 file_contents_request.listIndex = fuse_file->list_idx;
958 file_contents_request.dwFlags = FILECONTENTS_RANGE;
959 file_contents_request.nPositionLow = (UINT32)(offset & 0xFFFFFFFF);
960 file_contents_request.nPositionHigh = (UINT32)((offset >> 32) & 0xFFFFFFFF);
961 file_contents_request.cbRequested = (UINT32)requested_size;
962 file_contents_request.haveClipDataId = fuse_file->has_clip_data_id;
963 file_contents_request.clipDataId = fuse_file->clip_data_id;
964
965 if (file_context->context->ClientFileContentsRequest(file_context->context,
966 &file_contents_request))
967 {
968 WLog_Print(file_context->log, WLOG_ERROR,
969 "Failed to send FileContentsRequest for file \"%s\"",
970 fuse_file->filename_with_root);
971 HashTable_Remove(file_context->request_table, (void*)(uintptr_t)fuse_request->stream_id);
972 return FALSE;
973 }
974
975 // file_context->request_table owns fuse_request
976 // NOLINTBEGIN(clang-analyzer-unix.Malloc)
977 DEBUG_CLIPRDR(
978 file_context->log,
979 "Requested file range (%zu Bytes at offset %lu) for file \"%s\" with stream id %u",
980 requested_size, offset, fuse_file->filename, fuse_request->stream_id);
981
982 return TRUE;
983 // NOLINTEND(clang-analyzer-unix.Malloc)
984}
985
986static void cliprdr_file_fuse_read(fuse_req_t fuse_req, fuse_ino_t fuse_ino, size_t size,
987 off_t offset, WINPR_ATTR_UNUSED struct fuse_file_info* file_info)
988{
989 CliprdrFileContext* file_context = fuse_req_userdata(fuse_req);
990 CliprdrFuseFile* fuse_file = nullptr;
991 BOOL result = 0;
992
993 WINPR_ASSERT(file_context);
994
995 HashTable_Lock(file_context->inode_table);
996 if (!(fuse_file = get_fuse_file_by_ino(file_context, fuse_ino)))
997 {
998 HashTable_Unlock(file_context->inode_table);
999 fuse_reply_err(fuse_req, ENOENT);
1000 return;
1001 }
1002 if (fuse_file->is_directory)
1003 {
1004 HashTable_Unlock(file_context->inode_table);
1005 fuse_reply_err(fuse_req, EISDIR);
1006 return;
1007 }
1008 if (!fuse_file->has_size || (offset < 0) || ((size_t)offset > fuse_file->size))
1009 {
1010 HashTable_Unlock(file_context->inode_table);
1011 fuse_reply_err(fuse_req, EINVAL);
1012 return;
1013 }
1014
1015 size = MIN(size, 8ULL * 1024ULL * 1024ULL);
1016
1017 result = request_file_range_async(file_context, fuse_file, fuse_req, offset, size);
1018 HashTable_Unlock(file_context->inode_table);
1019
1020 if (!result)
1021 fuse_reply_err(fuse_req, EIO);
1022}
1023
1024static void cliprdr_file_fuse_opendir(fuse_req_t fuse_req, fuse_ino_t fuse_ino,
1025 struct fuse_file_info* file_info)
1026{
1027 CliprdrFileContext* file_context = fuse_req_userdata(fuse_req);
1028 CliprdrFuseFile* fuse_file = nullptr;
1029
1030 WINPR_ASSERT(file_context);
1031
1032 HashTable_Lock(file_context->inode_table);
1033 if (!(fuse_file = get_fuse_file_by_ino(file_context, fuse_ino)))
1034 {
1035 HashTable_Unlock(file_context->inode_table);
1036 fuse_reply_err(fuse_req, ENOENT);
1037 return;
1038 }
1039 if (!fuse_file->is_directory)
1040 {
1041 HashTable_Unlock(file_context->inode_table);
1042 fuse_reply_err(fuse_req, ENOTDIR);
1043 return;
1044 }
1045 HashTable_Unlock(file_context->inode_table);
1046
1047 if ((file_info->flags & O_ACCMODE) != O_RDONLY)
1048 {
1049 fuse_reply_err(fuse_req, EACCES);
1050 return;
1051 }
1052
1053 fuse_reply_open(fuse_req, file_info);
1054}
1055
1056static void cliprdr_file_fuse_readdir(fuse_req_t fuse_req, fuse_ino_t fuse_ino, size_t max_size,
1057 off_t offset,
1058 WINPR_ATTR_UNUSED struct fuse_file_info* file_info)
1059{
1060 CliprdrFileContext* file_context = fuse_req_userdata(fuse_req);
1061 CliprdrFuseFile* fuse_file = nullptr;
1062 CliprdrFuseFile* child = nullptr;
1063 struct stat attr = WINPR_C_ARRAY_INIT;
1064 size_t written_size = 0;
1065 size_t entry_size = 0;
1066 char* filename = nullptr;
1067 char* buf = nullptr;
1068
1069 WINPR_ASSERT(file_context);
1070
1071 HashTable_Lock(file_context->inode_table);
1072 if (!(fuse_file = get_fuse_file_by_ino(file_context, fuse_ino)))
1073 {
1074 HashTable_Unlock(file_context->inode_table);
1075 fuse_reply_err(fuse_req, ENOENT);
1076 return;
1077 }
1078 if (!fuse_file->is_directory)
1079 {
1080 HashTable_Unlock(file_context->inode_table);
1081 fuse_reply_err(fuse_req, ENOTDIR);
1082 return;
1083 }
1084
1085 DEBUG_CLIPRDR(file_context->log, "Reading directory \"%s\" at offset %lu",
1086 fuse_file->filename_with_root, offset);
1087
1088 if ((offset < 0) || ((size_t)offset >= ArrayList_Count(fuse_file->children)))
1089 {
1090 HashTable_Unlock(file_context->inode_table);
1091 fuse_reply_buf(fuse_req, nullptr, 0);
1092 return;
1093 }
1094
1095 buf = calloc(max_size, sizeof(char));
1096 if (!buf)
1097 {
1098 HashTable_Unlock(file_context->inode_table);
1099 fuse_reply_err(fuse_req, ENOMEM);
1100 return;
1101 }
1102 written_size = 0;
1103
1104 for (off_t i = offset; i < 2; ++i)
1105 {
1106 if (i == 0)
1107 {
1108 write_file_attributes(fuse_file, &attr);
1109 filename = ".";
1110 }
1111 else if (i == 1)
1112 {
1113 write_file_attributes(fuse_file->parent, &attr);
1114 attr.st_ino = fuse_file->parent ? attr.st_ino : FUSE_ROOT_ID;
1115 attr.st_mode = fuse_file->parent ? attr.st_mode : 0555;
1116 filename = "..";
1117 }
1118 else
1119 {
1120 WINPR_ASSERT(FALSE);
1121 }
1122
1127 entry_size = fuse_add_direntry(fuse_req, buf + written_size, max_size - written_size,
1128 filename, &attr, i + 1);
1129 if (entry_size > max_size - written_size)
1130 break;
1131
1132 written_size += entry_size;
1133 }
1134
1135 for (size_t j = 0, i = 2; j < ArrayList_Count(fuse_file->children); ++j, ++i)
1136 {
1137 if (i < (size_t)offset)
1138 continue;
1139
1140 child = ArrayList_GetItem(fuse_file->children, j);
1141
1142 write_file_attributes(child, &attr);
1143 entry_size =
1144 fuse_add_direntry(fuse_req, buf + written_size, max_size - written_size,
1145 child->filename, &attr, WINPR_ASSERTING_INT_CAST(off_t, i + 1));
1146 if (entry_size > max_size - written_size)
1147 break;
1148
1149 written_size += entry_size;
1150 }
1151 HashTable_Unlock(file_context->inode_table);
1152
1153 fuse_reply_buf(fuse_req, buf, written_size);
1154 free(buf);
1155}
1156
1157static void fuse_abort(int sig, const char* signame, void* context)
1158{
1159 CliprdrFileContext* file = (CliprdrFileContext*)context;
1160
1161 if (file)
1162 {
1163 WLog_Print(file->log, WLOG_INFO, "signal %s [%d] aborting session", signame, sig);
1164 cliprdr_file_session_terminate(file, FALSE);
1165 }
1166}
1167
1168static DWORD WINAPI cliprdr_file_fuse_thread(LPVOID arg)
1169{
1170 CliprdrFileContext* file = (CliprdrFileContext*)arg;
1171
1172 WINPR_ASSERT(file);
1173
1174 DEBUG_CLIPRDR(file->log, "Starting fuse with mountpoint '%s'", file->path);
1175
1176 struct fuse_args args = FUSE_ARGS_INIT(0, nullptr);
1177 fuse_opt_add_arg(&args, file->path);
1178 file->fuse_sess = fuse_session_new(&args, &cliprdr_file_fuse_oper,
1179 sizeof(cliprdr_file_fuse_oper), (void*)file);
1180 (void)SetEvent(file->fuse_start_sync);
1181
1182 if (file->fuse_sess != nullptr)
1183 {
1184 if (freerdp_add_signal_cleanup_handler(file, fuse_abort))
1185 {
1186 if (0 == fuse_session_mount(file->fuse_sess, file->path))
1187 {
1188 fuse_session_loop(file->fuse_sess);
1189 fuse_session_unmount(file->fuse_sess);
1190 }
1191 freerdp_del_signal_cleanup_handler(file, fuse_abort);
1192 }
1193
1194 WLog_Print(file->log, WLOG_DEBUG, "Waiting for FUSE stop sync");
1195 if (WaitForSingleObject(file->fuse_stop_sync, INFINITE) == WAIT_FAILED)
1196 WLog_Print(file->log, WLOG_ERROR, "Failed to wait for stop sync");
1197 fuse_session_destroy(file->fuse_sess);
1198 }
1199 fuse_opt_free_args(&args);
1200
1201 DEBUG_CLIPRDR(file->log, "Quitting fuse with mountpoint '%s'", file->path);
1202
1203 ExitThread(0);
1204 return 0;
1205}
1206
1207static UINT cliprdr_file_context_server_file_contents_response(
1208 CliprdrClientContext* cliprdr_context,
1209 const CLIPRDR_FILE_CONTENTS_RESPONSE* file_contents_response)
1210{
1211 CliprdrFileContext* file_context = nullptr;
1212 CliprdrFuseRequest* fuse_request = nullptr;
1213 struct fuse_entry_param entry = WINPR_C_ARRAY_INIT;
1214
1215 WINPR_ASSERT(cliprdr_context);
1216 WINPR_ASSERT(file_contents_response);
1217
1218 file_context = cliprdr_context->custom;
1219 WINPR_ASSERT(file_context);
1220
1221 HashTable_Lock(file_context->inode_table);
1222 fuse_request = HashTable_GetItemValue(file_context->request_table,
1223 (void*)(uintptr_t)file_contents_response->streamId);
1224 if (!fuse_request)
1225 {
1226 HashTable_Unlock(file_context->inode_table);
1227 return CHANNEL_RC_OK;
1228 }
1229
1230 if (!(file_contents_response->common.msgFlags & CB_RESPONSE_OK))
1231 {
1232 WLog_Print(file_context->log, WLOG_WARN,
1233 "FileContentsRequests for file \"%s\" was unsuccessful",
1234 fuse_request->fuse_file->filename);
1235
1236 fuse_reply_err(fuse_request->fuse_req, EIO);
1237 HashTable_Remove(file_context->request_table,
1238 (void*)(uintptr_t)file_contents_response->streamId);
1239 HashTable_Unlock(file_context->inode_table);
1240 return CHANNEL_RC_OK;
1241 }
1242
1243 if ((fuse_request->operation_type == FUSE_LL_OPERATION_LOOKUP ||
1244 fuse_request->operation_type == FUSE_LL_OPERATION_GETATTR) &&
1245 file_contents_response->cbRequested != sizeof(UINT64))
1246 {
1247 WLog_Print(file_context->log, WLOG_WARN,
1248 "Received invalid file size for file \"%s\" from the client",
1249 fuse_request->fuse_file->filename);
1250 fuse_reply_err(fuse_request->fuse_req, EIO);
1251 HashTable_Remove(file_context->request_table,
1252 (void*)(uintptr_t)file_contents_response->streamId);
1253 HashTable_Unlock(file_context->inode_table);
1254 return CHANNEL_RC_OK;
1255 }
1256
1257 if (fuse_request->operation_type == FUSE_LL_OPERATION_LOOKUP ||
1258 fuse_request->operation_type == FUSE_LL_OPERATION_GETATTR)
1259 {
1260 DEBUG_CLIPRDR(file_context->log, "Received file size for file \"%s\" with stream id %u",
1261 fuse_request->fuse_file->filename, file_contents_response->streamId);
1262
1263 fuse_request->fuse_file->size = *((const UINT64*)file_contents_response->requestedData);
1264 fuse_request->fuse_file->has_size = TRUE;
1265
1266 entry.ino = fuse_request->fuse_file->ino;
1267 write_file_attributes(fuse_request->fuse_file, &entry.attr);
1268 entry.attr_timeout = 1.0;
1269 entry.entry_timeout = 1.0;
1270 }
1271 else if (fuse_request->operation_type == FUSE_LL_OPERATION_READ)
1272 {
1273 DEBUG_CLIPRDR(file_context->log, "Received file range for file \"%s\" with stream id %u",
1274 fuse_request->fuse_file->filename, file_contents_response->streamId);
1275 }
1276 HashTable_Unlock(file_context->inode_table);
1277
1278 switch (fuse_request->operation_type)
1279 {
1280 case FUSE_LL_OPERATION_NONE:
1281 break;
1282 case FUSE_LL_OPERATION_LOOKUP:
1283 fuse_reply_entry(fuse_request->fuse_req, &entry);
1284 break;
1285 case FUSE_LL_OPERATION_GETATTR:
1286 fuse_reply_attr(fuse_request->fuse_req, &entry.attr, entry.attr_timeout);
1287 break;
1288 case FUSE_LL_OPERATION_READ:
1289 fuse_reply_buf(fuse_request->fuse_req,
1290 (const char*)file_contents_response->requestedData,
1291 file_contents_response->cbRequested);
1292 break;
1293 default:
1294 break;
1295 }
1296
1297 HashTable_Remove(file_context->request_table,
1298 (void*)(uintptr_t)file_contents_response->streamId);
1299
1300 return CHANNEL_RC_OK;
1301}
1302#endif
1303
1304static UINT cliprdr_file_context_send_file_contents_failure(
1305 CliprdrFileContext* file, const CLIPRDR_FILE_CONTENTS_REQUEST* fileContentsRequest)
1306{
1307 CLIPRDR_FILE_CONTENTS_RESPONSE response = WINPR_C_ARRAY_INIT;
1308
1309 WINPR_ASSERT(file);
1310 WINPR_ASSERT(fileContentsRequest);
1311
1312 const UINT64 offset = (((UINT64)fileContentsRequest->nPositionHigh) << 32) |
1313 ((UINT64)fileContentsRequest->nPositionLow);
1314 writelog(file->log, WLOG_WARN, __FILE__, __func__, __LINE__,
1315 "server file contents request [lockID %" PRIu32 ", streamID %" PRIu32
1316 ", index %" PRIu32 "] offset %" PRIu64 ", size %" PRIu32 " failed",
1317 fileContentsRequest->clipDataId, fileContentsRequest->streamId,
1318 fileContentsRequest->listIndex, offset, fileContentsRequest->cbRequested);
1319
1320 response.common.msgFlags = CB_RESPONSE_FAIL;
1321 response.streamId = fileContentsRequest->streamId;
1322
1323 WINPR_ASSERT(file->context);
1324 WINPR_ASSERT(file->context->ClientFileContentsResponse);
1325 return file->context->ClientFileContentsResponse(file->context, &response);
1326}
1327
1328static UINT
1329cliprdr_file_context_send_contents_response(CliprdrFileContext* file,
1330 const CLIPRDR_FILE_CONTENTS_REQUEST* request,
1331 const void* data, size_t size)
1332{
1333 if (size > UINT32_MAX)
1334 return ERROR_INVALID_PARAMETER;
1335
1336 CLIPRDR_FILE_CONTENTS_RESPONSE response = { .streamId = request->streamId,
1337 .requestedData = data,
1338 .cbRequested = (UINT32)size,
1339 .common.msgFlags = CB_RESPONSE_OK };
1340
1341 WINPR_ASSERT(request);
1342 WINPR_ASSERT(file);
1343
1344 WLog_Print(file->log, WLOG_DEBUG, "send contents response streamID=%" PRIu32 ", size=%" PRIu32,
1345 response.streamId, response.cbRequested);
1346 WINPR_ASSERT(file->context);
1347 WINPR_ASSERT(file->context->ClientFileContentsResponse);
1348 return file->context->ClientFileContentsResponse(file->context, &response);
1349}
1350
1351static BOOL dump_streams(const void* key, void* value, WINPR_ATTR_UNUSED void* arg)
1352{
1353 const UINT32* ukey = key;
1354 CliprdrLocalStream* cur = value;
1355
1356 writelog(cur->context->log, WLOG_WARN, __FILE__, __func__, __LINE__,
1357 "[key %" PRIu32 "] lockID %" PRIu32 ", count %" PRIuz ", locked %d", *ukey,
1358 cur->lockId, cur->count, cur->locked);
1359 for (size_t x = 0; x < cur->count; x++)
1360 {
1361 const CliprdrLocalFile* file = &cur->files[x];
1362 writelog(cur->context->log, WLOG_WARN, __FILE__, __func__, __LINE__,
1363 "file [%" PRIuz "] %s: %" PRId64, x, file->name, file->size);
1364 }
1365 return TRUE;
1366}
1367
1368static CliprdrLocalFile* file_info_for_request(CliprdrFileContext* file, UINT32 lockId,
1369 UINT32 listIndex)
1370{
1371 WINPR_ASSERT(file);
1372
1373 CliprdrLocalStream* cur = HashTable_GetItemValue(file->local_streams, &lockId);
1374 if (cur)
1375 {
1376 if (listIndex < cur->count)
1377 {
1378 CliprdrLocalFile* f = &cur->files[listIndex];
1379 return f;
1380 }
1381 else
1382 {
1383 writelog(file->log, WLOG_WARN, __FILE__, __func__, __LINE__,
1384 "invalid entry index for lockID %" PRIu32 ", index %" PRIu32 " [count %" PRIuz
1385 "] [locked %d]",
1386 lockId, listIndex, cur->count, cur->locked);
1387 }
1388 }
1389 else
1390 {
1391 writelog(file->log, WLOG_WARN, __FILE__, __func__, __LINE__,
1392 "missing entry for lockID %" PRIu32 ", index %" PRIu32, lockId, listIndex);
1393 HashTable_Foreach(file->local_streams, dump_streams, file);
1394 }
1395
1396 return nullptr;
1397}
1398
1399static CliprdrLocalFile* file_for_request(CliprdrFileContext* file, UINT32 lockId, UINT32 listIndex)
1400{
1401 CliprdrLocalFile* f = file_info_for_request(file, lockId, listIndex);
1402 if (f)
1403 {
1404 if (!f->fp)
1405 {
1406 const char* name = f->name;
1407 f->fp = winpr_fopen(name, "rb");
1408 }
1409 if (!f->fp)
1410 {
1411 char ebuffer[256] = WINPR_C_ARRAY_INIT;
1412 writelog(file->log, WLOG_WARN, __FILE__, __func__, __LINE__,
1413 "[lockID %" PRIu32 ", index %" PRIu32
1414 "] failed to open file '%s' [size %" PRId64 "] %s [%d]",
1415 lockId, listIndex, f->name, f->size,
1416 winpr_strerror(errno, ebuffer, sizeof(ebuffer)), errno);
1417 return nullptr;
1418 }
1419 }
1420
1421 return f;
1422}
1423
1424static void cliprdr_local_file_try_close(CliprdrLocalFile* file, UINT res, UINT64 offset,
1425 UINT64 size)
1426{
1427 WINPR_ASSERT(file);
1428
1429 if (res != 0)
1430 {
1431 WINPR_ASSERT(file->context);
1432 WLog_Print(file->context->log, WLOG_DEBUG, "closing file %s after error %" PRIu32,
1433 file->name, res);
1434 }
1435 else if (((file->size > 0) && (offset + size >= (UINT64)file->size)))
1436 {
1437 WINPR_ASSERT(file->context);
1438 WLog_Print(file->context->log, WLOG_DEBUG, "closing file %s after read", file->name);
1439 }
1440 else
1441 {
1442 // TODO: we need to keep track of open files to avoid running out of file descriptors
1443 // TODO: for the time being just close again.
1444 }
1445 if (file->fp)
1446 (void)fclose(file->fp);
1447 file->fp = nullptr;
1448}
1449
1450static UINT cliprdr_file_context_server_file_size_request(
1451 CliprdrFileContext* file, const CLIPRDR_FILE_CONTENTS_REQUEST* fileContentsRequest)
1452{
1453 WINPR_ASSERT(fileContentsRequest);
1454
1455 if (fileContentsRequest->cbRequested != sizeof(UINT64))
1456 {
1457 WLog_Print(file->log, WLOG_WARN, "unexpected FILECONTENTS_SIZE request: %" PRIu32 " bytes",
1458 fileContentsRequest->cbRequested);
1459 }
1460
1461 HashTable_Lock(file->local_streams);
1462
1463 UINT res = CHANNEL_RC_OK;
1464 CliprdrLocalFile* rfile =
1465 file_for_request(file, fileContentsRequest->clipDataId, fileContentsRequest->listIndex);
1466 if (!rfile)
1467 res = cliprdr_file_context_send_file_contents_failure(file, fileContentsRequest);
1468 else
1469 {
1470 if (_fseeki64(rfile->fp, 0, SEEK_END) < 0)
1471 res = cliprdr_file_context_send_file_contents_failure(file, fileContentsRequest);
1472 else
1473 {
1474 const INT64 size = _ftelli64(rfile->fp);
1475 rfile->size = size;
1476 cliprdr_local_file_try_close(rfile, res, 0, 0);
1477
1478 res = cliprdr_file_context_send_contents_response(file, fileContentsRequest, &size,
1479 sizeof(size));
1480 }
1481 }
1482
1483 HashTable_Unlock(file->local_streams);
1484 return res;
1485}
1486
1487static UINT cliprdr_file_context_server_file_range_request(
1488 CliprdrFileContext* file, const CLIPRDR_FILE_CONTENTS_REQUEST* fileContentsRequest)
1489{
1490 BYTE* data = nullptr;
1491
1492 WINPR_ASSERT(fileContentsRequest);
1493
1494 HashTable_Lock(file->local_streams);
1495 const UINT64 offset = (((UINT64)fileContentsRequest->nPositionHigh) << 32) |
1496 ((UINT64)fileContentsRequest->nPositionLow);
1497
1498 CliprdrLocalFile* rfile =
1499 file_for_request(file, fileContentsRequest->clipDataId, fileContentsRequest->listIndex);
1500 if (!rfile)
1501 goto fail;
1502
1503 if (_fseeki64(rfile->fp, WINPR_ASSERTING_INT_CAST(int64_t, offset), SEEK_SET) < 0)
1504 goto fail;
1505
1506 data = malloc(fileContentsRequest->cbRequested);
1507 if (!data)
1508 goto fail;
1509
1510 {
1511 const size_t r = fread(data, 1, fileContentsRequest->cbRequested, rfile->fp);
1512 const UINT rc =
1513 cliprdr_file_context_send_contents_response(file, fileContentsRequest, data, r);
1514 free(data);
1515
1516 cliprdr_local_file_try_close(rfile, rc, offset, fileContentsRequest->cbRequested);
1517 HashTable_Unlock(file->local_streams);
1518 return rc;
1519 }
1520fail:
1521 if (rfile)
1522 cliprdr_local_file_try_close(rfile, ERROR_INTERNAL_ERROR, offset,
1523 fileContentsRequest->cbRequested);
1524 free(data);
1525 HashTable_Unlock(file->local_streams);
1526 return cliprdr_file_context_send_file_contents_failure(file, fileContentsRequest);
1527}
1528
1529static void cliprdr_local_stream_free(void* obj);
1530
1531static UINT change_lock(CliprdrFileContext* file, UINT32 lockId, BOOL lock)
1532{
1533 UINT rc = CHANNEL_RC_OK;
1534
1535 WINPR_ASSERT(file);
1536
1537 HashTable_Lock(file->local_streams);
1538
1539 {
1540 CliprdrLocalStream* stream = HashTable_GetItemValue(file->local_streams, &lockId);
1541 if (lock && !stream)
1542 {
1543 stream = cliprdr_local_stream_new(file, lockId, nullptr, 0);
1544 if (!HashTable_Insert(file->local_streams, &lockId, stream))
1545 {
1546 rc = ERROR_INTERNAL_ERROR;
1547 cliprdr_local_stream_free(stream);
1548 stream = nullptr;
1549 }
1550 file->local_lock_id = lockId;
1551 }
1552 if (stream)
1553 {
1554 stream->locked = lock;
1555 stream->lockId = lockId;
1556 }
1557 }
1558
1559 // NOLINTNEXTLINE(clang-analyzer-unix.Malloc): HashTable_Insert ownership stream
1560 if (!lock)
1561 {
1562 if (!HashTable_Foreach(file->local_streams, local_stream_discard, file))
1563 rc = ERROR_INTERNAL_ERROR;
1564 }
1565
1566 HashTable_Unlock(file->local_streams);
1567 return rc;
1568}
1569
1570static UINT cliprdr_file_context_lock(CliprdrClientContext* context,
1571 const CLIPRDR_LOCK_CLIPBOARD_DATA* lockClipboardData)
1572{
1573 WINPR_ASSERT(context);
1574 WINPR_ASSERT(lockClipboardData);
1575 CliprdrFileContext* file = (context->custom);
1576 return change_lock(file, lockClipboardData->clipDataId, TRUE);
1577}
1578
1579static UINT cliprdr_file_context_unlock(CliprdrClientContext* context,
1580 const CLIPRDR_UNLOCK_CLIPBOARD_DATA* unlockClipboardData)
1581{
1582 WINPR_ASSERT(context);
1583 WINPR_ASSERT(unlockClipboardData);
1584 CliprdrFileContext* file = (context->custom);
1585 return change_lock(file, unlockClipboardData->clipDataId, FALSE);
1586}
1587
1588static UINT cliprdr_file_context_server_file_contents_request(
1589 CliprdrClientContext* context, const CLIPRDR_FILE_CONTENTS_REQUEST* fileContentsRequest)
1590{
1591 UINT error = NO_ERROR;
1592
1593 WINPR_ASSERT(context);
1594 WINPR_ASSERT(fileContentsRequest);
1595
1596 CliprdrFileContext* file = (context->custom);
1597 WINPR_ASSERT(file);
1598
1599 /*
1600 * MS-RDPECLIP 2.2.5.3 File Contents Request PDU (CLIPRDR_FILECONTENTS_REQUEST):
1601 * The FILECONTENTS_SIZE and FILECONTENTS_RANGE flags MUST NOT be set at the same time.
1602 */
1603 if ((fileContentsRequest->dwFlags & (FILECONTENTS_SIZE | FILECONTENTS_RANGE)) ==
1604 (FILECONTENTS_SIZE | FILECONTENTS_RANGE))
1605 {
1606 WLog_Print(file->log, WLOG_ERROR, "invalid CLIPRDR_FILECONTENTS_REQUEST.dwFlags");
1607 return cliprdr_file_context_send_file_contents_failure(file, fileContentsRequest);
1608 }
1609
1610 if (fileContentsRequest->dwFlags & FILECONTENTS_SIZE)
1611 error = cliprdr_file_context_server_file_size_request(file, fileContentsRequest);
1612
1613 if (fileContentsRequest->dwFlags & FILECONTENTS_RANGE)
1614 error = cliprdr_file_context_server_file_range_request(file, fileContentsRequest);
1615
1616 if (error)
1617 {
1618 WLog_Print(file->log, WLOG_ERROR, "failed to handle CLIPRDR_FILECONTENTS_REQUEST: 0x%08X",
1619 error);
1620 return cliprdr_file_context_send_file_contents_failure(file, fileContentsRequest);
1621 }
1622
1623 return CHANNEL_RC_OK;
1624}
1625
1626BOOL cliprdr_file_context_init(CliprdrFileContext* file, CliprdrClientContext* cliprdr)
1627{
1628 WINPR_ASSERT(file);
1629 WINPR_ASSERT(cliprdr);
1630
1631 cliprdr->custom = file;
1632 file->context = cliprdr;
1633
1634 cliprdr->ServerLockClipboardData = cliprdr_file_context_lock;
1635 cliprdr->ServerUnlockClipboardData = cliprdr_file_context_unlock;
1636 cliprdr->ServerFileContentsRequest = cliprdr_file_context_server_file_contents_request;
1637#if defined(WITH_FUSE)
1638 cliprdr->ServerFileContentsResponse = cliprdr_file_context_server_file_contents_response;
1639
1640 CliprdrFuseFile* root_dir = fuse_file_new_root(file);
1641 return root_dir != nullptr;
1642#else
1643 return TRUE;
1644#endif
1645}
1646
1647#if defined(WITH_FUSE)
1648static void clear_all_selections(CliprdrFileContext* file_context)
1649{
1650 WINPR_ASSERT(file_context);
1651 WINPR_ASSERT(file_context->inode_table);
1652
1653 HashTable_Lock(file_context->inode_table);
1654 clear_selection(file_context, TRUE, nullptr);
1655
1656 HashTable_Clear(file_context->clip_data_table);
1657 HashTable_Unlock(file_context->inode_table);
1658}
1659#endif
1660
1661BOOL cliprdr_file_context_uninit(CliprdrFileContext* file, CliprdrClientContext* cliprdr)
1662{
1663 WINPR_ASSERT(file);
1664 WINPR_ASSERT(cliprdr);
1665
1666 // Clear all data before the channel is closed
1667 // the cleanup handlers are dependent on a working channel.
1668#if defined(WITH_FUSE)
1669 if (file->inode_table)
1670 {
1671 clear_no_cdi_entry(file);
1672 clear_all_selections(file);
1673 }
1674#endif
1675
1676 HashTable_Clear(file->local_streams);
1677
1678 file->context = nullptr;
1679
1680#if defined(WITH_FUSE)
1681 cliprdr->ServerFileContentsResponse = nullptr;
1682#endif
1683
1684 return TRUE;
1685}
1686
1687static BOOL cliprdr_file_content_changed_and_update(void* ihash, size_t hsize, const void* data,
1688 size_t size)
1689{
1690
1691 BYTE hash[WINPR_SHA256_DIGEST_LENGTH] = WINPR_C_ARRAY_INIT;
1692
1693 if (hsize < sizeof(hash))
1694 return FALSE;
1695
1696 if (!winpr_Digest(WINPR_MD_SHA256, data, size, hash, sizeof(hash)))
1697 return FALSE;
1698
1699 const BOOL changed = memcmp(hash, ihash, sizeof(hash)) != 0;
1700 if (changed)
1701 memcpy(ihash, hash, sizeof(hash));
1702 return changed;
1703}
1704
1705static BOOL cliprdr_file_client_content_changed_and_update(CliprdrFileContext* file,
1706 const void* data, size_t size)
1707{
1708 WINPR_ASSERT(file);
1709 return cliprdr_file_content_changed_and_update(file->client_data_hash,
1710 sizeof(file->client_data_hash), data, size);
1711}
1712
1713#if defined(WITH_FUSE)
1714static fuse_ino_t get_next_free_inode(CliprdrFileContext* file_context)
1715{
1716 fuse_ino_t ino = 0;
1717
1718 WINPR_ASSERT(file_context);
1719
1720 ino = file_context->next_ino;
1721 while (ino == 0 || ino == FUSE_ROOT_ID ||
1722 HashTable_GetItemValue(file_context->inode_table, (void*)(uintptr_t)ino))
1723 ++ino;
1724
1725 file_context->next_ino = ino + 1;
1726
1727 return ino;
1728}
1729
1730static CliprdrFuseFile* clip_data_dir_new(CliprdrFileContext* file_context, BOOL has_clip_data_id,
1731 UINT32 clip_data_id)
1732{
1733 WINPR_ASSERT(file_context);
1734
1735 UINT64 data_id = clip_data_id;
1736 if (!has_clip_data_id)
1737 data_id = NO_CLIP_DATA_ID;
1738
1739 CliprdrFuseFile* clip_data_dir = fuse_file_new("/%" PRIu64, data_id);
1740 if (!clip_data_dir)
1741 return nullptr;
1742
1743 clip_data_dir->ino = get_next_free_inode(file_context);
1744 clip_data_dir->is_directory = TRUE;
1745 clip_data_dir->is_readonly = TRUE;
1746 clip_data_dir->has_clip_data_id = has_clip_data_id;
1747 clip_data_dir->clip_data_id = clip_data_id;
1748
1749 CliprdrFuseFile* root_dir = get_fuse_file_by_ino(file_context, FUSE_ROOT_ID);
1750 if (!root_dir)
1751 {
1752 WLog_Print(file_context->log, WLOG_ERROR, "FUSE root directory missing");
1753 fuse_file_free(clip_data_dir);
1754 return nullptr;
1755 }
1756 if (!ArrayList_Append(root_dir->children, clip_data_dir))
1757 {
1758 WLog_Print(file_context->log, WLOG_ERROR, "Failed to append FUSE file");
1759 fuse_file_free(clip_data_dir);
1760 return nullptr;
1761 }
1762 clip_data_dir->parent = root_dir;
1763
1764 if (!HashTable_Insert(file_context->inode_table, (void*)(uintptr_t)clip_data_dir->ino,
1765 clip_data_dir))
1766 {
1767 WLog_Print(file_context->log, WLOG_ERROR, "Failed to insert inode into inode table");
1768 ArrayList_Remove(root_dir->children, clip_data_dir);
1769 fuse_file_free(clip_data_dir);
1770 return nullptr;
1771 }
1772
1773 return clip_data_dir;
1774}
1775
1776static char* get_parent_path(const char* filepath)
1777{
1778 const char* base = strrchr(filepath, '/');
1779 WINPR_ASSERT(base);
1780
1781 while ((base > filepath) && (*base == '/'))
1782 --base;
1783
1784 WINPR_ASSERT(base >= filepath);
1785 const size_t parent_path_length = 1ULL + (size_t)(base - filepath);
1786 char* parent_path = calloc(parent_path_length + 1, sizeof(char));
1787 if (!parent_path)
1788 return nullptr;
1789
1790 memcpy(parent_path, filepath, parent_path_length);
1791
1792 return parent_path;
1793}
1794
1795static BOOL is_fuse_file_not_parent(WINPR_ATTR_UNUSED const void* key, void* value, void* arg)
1796{
1797 CliprdrFuseFile* fuse_file = value;
1798 CliprdrFuseFindParentContext* find_context = arg;
1799
1800 if (!fuse_file->is_directory)
1801 return TRUE;
1802
1803 if (strncmp(find_context->parent_path, fuse_file->filename_with_root,
1804 fuse_file->filename_with_root_len + 1) == 0)
1805 {
1806 find_context->parent = fuse_file;
1807 return FALSE;
1808 }
1809
1810 return TRUE;
1811}
1812
1813static CliprdrFuseFile* get_parent_directory(CliprdrFileContext* file_context, const char* path)
1814{
1815 CliprdrFuseFindParentContext find_context = WINPR_C_ARRAY_INIT;
1816
1817 WINPR_ASSERT(file_context);
1818 WINPR_ASSERT(path);
1819
1820 find_context.parent_path = get_parent_path(path);
1821 if (!find_context.parent_path)
1822 return nullptr;
1823
1824 WINPR_ASSERT(!find_context.parent);
1825
1826 if (HashTable_Foreach(file_context->inode_table, is_fuse_file_not_parent, &find_context))
1827 {
1828 free(find_context.parent_path);
1829 return nullptr;
1830 }
1831 WINPR_ASSERT(find_context.parent);
1832
1833 free(find_context.parent_path);
1834
1835 return find_context.parent;
1836}
1837
1838// NOLINTBEGIN(clang-analyzer-unix.Malloc) HashTable_Insert owns fuse_file
1839static BOOL selection_handle_file(CliprdrFileContext* file_context,
1840 CliprdrFuseClipDataEntry* clip_data_entry, uint32_t index,
1841 const FILEDESCRIPTORW* file)
1842{
1843
1844 WINPR_ASSERT(file_context);
1845 WINPR_ASSERT(clip_data_entry);
1846 WINPR_ASSERT(file);
1847
1848 CliprdrFuseFile* clip_data_dir = clip_data_entry->clip_data_dir;
1849 WINPR_ASSERT(clip_data_dir);
1850
1851 char filename[ARRAYSIZE(file->cFileName) * 8] = WINPR_C_ARRAY_INIT;
1852 const SSIZE_T filenamelen = ConvertWCharNToUtf8(file->cFileName, ARRAYSIZE(file->cFileName),
1853 filename, ARRAYSIZE(filename) - 1);
1854 if (filenamelen < 0)
1855 {
1856 WLog_Print(file_context->log, WLOG_ERROR, "Failed to convert filename");
1857 return FALSE;
1858 }
1859
1860 for (size_t j = 0; filename[j]; ++j)
1861 {
1862 if (filename[j] == '\\')
1863 filename[j] = '/';
1864 }
1865
1866 BOOL crc = FALSE;
1867 CliprdrFuseFile* fuse_file = fuse_file_new(
1868 "%.*s/%s", WINPR_ASSERTING_INT_CAST(int, clip_data_dir->filename_with_root_len),
1869 clip_data_dir->filename_with_root, filename);
1870 if (!fuse_file)
1871 {
1872 WLog_Print(file_context->log, WLOG_ERROR, "Failed to create FUSE file");
1873 goto end;
1874 }
1875
1876 fuse_file->parent = get_parent_directory(file_context, fuse_file->filename_with_root);
1877 if (!fuse_file->parent)
1878 {
1879 WLog_Print(file_context->log, WLOG_ERROR, "Found no parent for FUSE file");
1880 goto end;
1881 }
1882
1883 if (!ArrayList_Append(fuse_file->parent->children, fuse_file))
1884 {
1885 WLog_Print(file_context->log, WLOG_ERROR, "Failed to append FUSE file");
1886 goto end;
1887 }
1888
1889 fuse_file->list_idx = index;
1890 fuse_file->ino = get_next_free_inode(file_context);
1891 fuse_file->has_clip_data_id = clip_data_entry->has_clip_data_id;
1892 fuse_file->clip_data_id = clip_data_entry->clip_data_id;
1893 if (file->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
1894 fuse_file->is_directory = TRUE;
1895 if (file->dwFileAttributes & FILE_ATTRIBUTE_READONLY)
1896 fuse_file->is_readonly = TRUE;
1897 if (file->dwFlags & FD_FILESIZE)
1898 {
1899 fuse_file->size = ((UINT64)file->nFileSizeHigh << 32) + file->nFileSizeLow;
1900 fuse_file->has_size = TRUE;
1901 }
1902 if (file->dwFlags & FD_WRITESTIME)
1903 {
1904 INT64 filetime = 0;
1905
1906 filetime = file->ftLastWriteTime.dwHighDateTime;
1907 filetime <<= 32;
1908 filetime += file->ftLastWriteTime.dwLowDateTime;
1909
1910 fuse_file->last_write_time_unix =
1911 1LL * filetime / (10LL * 1000LL * 1000LL) - WIN32_FILETIME_TO_UNIX_EPOCH;
1912 fuse_file->has_last_write_time = TRUE;
1913 }
1914
1915 if (!HashTable_Insert(file_context->inode_table, (void*)(uintptr_t)fuse_file->ino, fuse_file))
1916 {
1917 WLog_Print(file_context->log, WLOG_ERROR, "Failed to insert inode into inode table");
1918 goto end;
1919 }
1920
1921 crc = TRUE;
1922
1923end:
1924 if (!crc)
1925 {
1926 fuse_file_free(fuse_file);
1927 clear_entry_selection(clip_data_entry);
1928 return FALSE;
1929 }
1930 return TRUE;
1931}
1932// NOLINTEND(clang-analyzer-unix.Malloc) HashTable_Insert owns fuse_file
1933
1934static BOOL set_selection_for_clip_data_entry(CliprdrFileContext* file_context,
1935 CliprdrFuseClipDataEntry* clip_data_entry,
1936 const FILEDESCRIPTORW* files, UINT32 n_files)
1937{
1938 WINPR_ASSERT(file_context);
1939 WINPR_ASSERT(clip_data_entry);
1940 WINPR_ASSERT(files);
1941
1942 if (clip_data_entry->has_clip_data_id)
1943 WLog_Print(file_context->log, WLOG_DEBUG, "Setting selection for clipDataId %u",
1944 clip_data_entry->clip_data_id);
1945 else
1946 WLog_Print(file_context->log, WLOG_DEBUG, "Setting selection");
1947
1948 for (UINT32 i = 0; i < n_files; ++i)
1949 {
1950 const FILEDESCRIPTORW* file = &files[i];
1951 if (!selection_handle_file(file_context, clip_data_entry, i, file))
1952 return FALSE;
1953 }
1954
1955 if (clip_data_entry->has_clip_data_id)
1956 WLog_Print(file_context->log, WLOG_DEBUG, "Selection set for clipDataId %u",
1957 clip_data_entry->clip_data_id);
1958 else
1959 WLog_Print(file_context->log, WLOG_DEBUG, "Selection set");
1960
1961 return TRUE;
1962}
1963
1964static BOOL update_exposed_path(CliprdrFileContext* file_context, wClipboard* clip,
1965 CliprdrFuseClipDataEntry* clip_data_entry)
1966{
1967 wClipboardDelegate* delegate = nullptr;
1968 CliprdrFuseFile* clip_data_dir = nullptr;
1969
1970 WINPR_ASSERT(file_context);
1971 WINPR_ASSERT(clip);
1972 WINPR_ASSERT(clip_data_entry);
1973
1974 delegate = ClipboardGetDelegate(clip);
1975 WINPR_ASSERT(delegate);
1976
1977 clip_data_dir = clip_data_entry->clip_data_dir;
1978 WINPR_ASSERT(clip_data_dir);
1979
1980 free(file_context->exposed_path);
1981 file_context->exposed_path = GetCombinedPath(file_context->path, clip_data_dir->filename);
1982 if (file_context->exposed_path)
1983 WLog_Print(file_context->log, WLOG_DEBUG, "Updated exposed path to \"%s\"",
1984 file_context->exposed_path);
1985
1986 delegate->basePath = file_context->exposed_path;
1987
1988 return delegate->basePath != nullptr;
1989}
1990#endif
1991
1992BOOL cliprdr_file_context_update_server_data(CliprdrFileContext* file_context, wClipboard* clip,
1993 const void* data, size_t size)
1994{
1995#if defined(WITH_FUSE)
1996 CliprdrFuseClipDataEntry* clip_data_entry = nullptr;
1997 FILEDESCRIPTORW* files = nullptr;
1998 UINT32 n_files = 0;
1999 BOOL rc = FALSE;
2000
2001 WINPR_ASSERT(file_context);
2002 WINPR_ASSERT(clip);
2003 if (size > UINT32_MAX)
2004 return FALSE;
2005
2006 if (cliprdr_parse_file_list(data, (UINT32)size, &files, &n_files))
2007 {
2008 WLog_Print(file_context->log, WLOG_ERROR, "Failed to parse file list");
2009 return FALSE;
2010 }
2011
2012 HashTable_Lock(file_context->inode_table);
2013 HashTable_Lock(file_context->clip_data_table);
2014 if (does_server_support_clipdata_locking(file_context))
2015 clip_data_entry = HashTable_GetItemValue(
2016 file_context->clip_data_table, (void*)(uintptr_t)file_context->current_clip_data_id);
2017 else
2018 clip_data_entry = file_context->clip_data_entry_without_id;
2019
2020 WINPR_ASSERT(clip_data_entry);
2021
2022 clear_entry_selection(clip_data_entry);
2023 WINPR_ASSERT(!clip_data_entry->clip_data_dir);
2024
2025 clip_data_entry->clip_data_dir =
2026 clip_data_dir_new(file_context, does_server_support_clipdata_locking(file_context),
2027 file_context->current_clip_data_id);
2028 if (!clip_data_entry->clip_data_dir)
2029 goto fail;
2030 if (!update_exposed_path(file_context, clip, clip_data_entry))
2031 goto fail;
2032 if (!set_selection_for_clip_data_entry(file_context, clip_data_entry, files, n_files))
2033 goto fail;
2034
2035 rc = TRUE;
2036
2037fail:
2038 HashTable_Unlock(file_context->clip_data_table);
2039 HashTable_Unlock(file_context->inode_table);
2040 free(files);
2041 return rc;
2042#else
2043 return FALSE;
2044#endif
2045}
2046
2047void* cliprdr_file_context_get_context(CliprdrFileContext* file)
2048{
2049 WINPR_ASSERT(file);
2050 return file->clipboard;
2051}
2052
2053void cliprdr_file_session_terminate(CliprdrFileContext* file, BOOL stop_thread)
2054{
2055 if (!file)
2056 return;
2057
2058#if defined(WITH_FUSE)
2059 WINPR_ASSERT(file->fuse_stop_sync);
2060
2061 WLog_Print(file->log, WLOG_DEBUG, "Setting FUSE exit flag");
2062 if (file->fuse_sess)
2063 fuse_session_exit(file->fuse_sess);
2064
2065 if (stop_thread)
2066 {
2067 WLog_Print(file->log, WLOG_DEBUG, "Setting FUSE stop event");
2068 (void)SetEvent(file->fuse_stop_sync);
2069 }
2070#endif
2071 /* not elegant but works for umounting FUSE
2072 fuse_chan must receive an oper buf to unblock fuse_session_receive_buf function.
2073 */
2074#if defined(WITH_FUSE)
2075 WLog_Print(file->log, WLOG_DEBUG, "Forcing FUSE to check exit flag");
2076#endif
2077 (void)winpr_PathFileExists(file->path);
2078}
2079
2080void cliprdr_file_context_free(CliprdrFileContext* file)
2081{
2082 if (!file)
2083 return;
2084
2085#if defined(WITH_FUSE)
2086 if (file->fuse_thread)
2087 {
2088 WINPR_ASSERT(file->fuse_stop_sync);
2089
2090 WLog_Print(file->log, WLOG_DEBUG, "Stopping FUSE thread");
2091 cliprdr_file_session_terminate(file, TRUE);
2092
2093 WLog_Print(file->log, WLOG_DEBUG, "Waiting on FUSE thread");
2094 (void)WaitForSingleObject(file->fuse_thread, INFINITE);
2095 (void)CloseHandle(file->fuse_thread);
2096 }
2097 if (file->fuse_stop_sync)
2098 (void)CloseHandle(file->fuse_stop_sync);
2099 if (file->fuse_start_sync)
2100 (void)CloseHandle(file->fuse_start_sync);
2101
2102 HashTable_Free(file->request_table);
2103 HashTable_Free(file->clip_data_table);
2104 HashTable_Free(file->inode_table);
2105
2106#endif
2107 HashTable_Free(file->local_streams);
2108 winpr_RemoveDirectory(file->path);
2109 free(file->path);
2110 free(file->exposed_path);
2111 free(file);
2112}
2113
2114static BOOL create_base_path(CliprdrFileContext* file)
2115{
2116 WINPR_ASSERT(file);
2117
2118 char base[64] = WINPR_C_ARRAY_INIT;
2119 (void)_snprintf(base, sizeof(base), "com.freerdp.client.cliprdr.%" PRIu32,
2120 GetCurrentProcessId());
2121
2122 file->path = GetKnownSubPath(KNOWN_PATH_TEMP, base);
2123 if (!file->path)
2124 return FALSE;
2125
2126 if (!winpr_PathFileExists(file->path) && !winpr_PathMakePath(file->path, nullptr))
2127 {
2128 WLog_Print(file->log, WLOG_ERROR, "Failed to create directory '%s'", file->path);
2129 return FALSE;
2130 }
2131 return TRUE;
2132}
2133
2134static void cliprdr_local_file_free(CliprdrLocalFile* file)
2135{
2136 const CliprdrLocalFile empty = WINPR_C_ARRAY_INIT;
2137 if (!file)
2138 return;
2139 if (file->fp)
2140 {
2141 WLog_Print(file->context->log, WLOG_DEBUG, "closing file %s, discarding entry", file->name);
2142 (void)fclose(file->fp);
2143 }
2144 free(file->name);
2145 *file = empty;
2146}
2147
2148static BOOL cliprdr_local_file_new(CliprdrFileContext* context, CliprdrLocalFile* f,
2149 const char* path)
2150{
2151 const CliprdrLocalFile empty = WINPR_C_ARRAY_INIT;
2152 WINPR_ASSERT(f);
2153 WINPR_ASSERT(context);
2154 WINPR_ASSERT(path);
2155
2156 *f = empty;
2157 f->context = context;
2158 f->name = winpr_str_url_decode(path, strlen(path));
2159 if (!f->name)
2160 goto fail;
2161
2162 return TRUE;
2163fail:
2164 cliprdr_local_file_free(f);
2165 return FALSE;
2166}
2167
2168static void cliprdr_local_files_free(CliprdrLocalStream* stream)
2169{
2170 WINPR_ASSERT(stream);
2171
2172 for (size_t x = 0; x < stream->count; x++)
2173 cliprdr_local_file_free(&stream->files[x]);
2174 free(stream->files);
2175
2176 stream->files = nullptr;
2177 stream->count = 0;
2178}
2179
2180static void cliprdr_local_stream_free(void* obj)
2181{
2182 CliprdrLocalStream* stream = (CliprdrLocalStream*)obj;
2183 if (stream)
2184 cliprdr_local_files_free(stream);
2185
2186 free(stream);
2187}
2188
2189static BOOL append_entry(CliprdrLocalStream* stream, const char* path)
2190{
2191 CliprdrLocalFile* tmp = realloc(stream->files, sizeof(CliprdrLocalFile) * (stream->count + 1));
2192 if (!tmp)
2193 return FALSE;
2194 stream->files = tmp;
2195 CliprdrLocalFile* f = &stream->files[stream->count++];
2196
2197 return cliprdr_local_file_new(stream->context, f, path);
2198}
2199
2200static BOOL is_directory(const char* path)
2201{
2202 WCHAR* wpath = ConvertUtf8ToWCharAlloc(path, nullptr);
2203 if (!wpath)
2204 return FALSE;
2205
2206 HANDLE hFile = CreateFileW(wpath, 0, FILE_SHARE_DELETE, nullptr, OPEN_EXISTING,
2207 FILE_ATTRIBUTE_NORMAL, nullptr);
2208 free(wpath);
2209
2210 if (hFile == INVALID_HANDLE_VALUE)
2211 return FALSE;
2212
2213 BY_HANDLE_FILE_INFORMATION fileInformation = WINPR_C_ARRAY_INIT;
2214 const BOOL status = GetFileInformationByHandle(hFile, &fileInformation);
2215 (void)CloseHandle(hFile);
2216 if (!status)
2217 return FALSE;
2218
2219 return (fileInformation.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
2220}
2221
2222static BOOL add_directory(CliprdrLocalStream* stream, const char* path)
2223{
2224 char* wildcardpath = GetCombinedPath(path, "*");
2225 if (!wildcardpath)
2226 return FALSE;
2227 WCHAR* wpath = ConvertUtf8ToWCharAlloc(wildcardpath, nullptr);
2228 free(wildcardpath);
2229 if (!wpath)
2230 return FALSE;
2231
2232 WIN32_FIND_DATAW FindFileData = WINPR_C_ARRAY_INIT;
2233 HANDLE hFind = FindFirstFileW(wpath, &FindFileData);
2234 free(wpath);
2235
2236 if (hFind == INVALID_HANDLE_VALUE)
2237 return FALSE;
2238
2239 BOOL rc = FALSE;
2240 char* next = nullptr;
2241
2242 WCHAR dotbuffer[6] = WINPR_C_ARRAY_INIT;
2243 WCHAR dotdotbuffer[6] = WINPR_C_ARRAY_INIT;
2244 const WCHAR* dot = InitializeConstWCharFromUtf8(".", dotbuffer, ARRAYSIZE(dotbuffer));
2245 const WCHAR* dotdot = InitializeConstWCharFromUtf8("..", dotdotbuffer, ARRAYSIZE(dotdotbuffer));
2246 do
2247 {
2248 if (_wcscmp(FindFileData.cFileName, dot) == 0)
2249 continue;
2250 if (_wcscmp(FindFileData.cFileName, dotdot) == 0)
2251 continue;
2252
2253 char cFileName[MAX_PATH] = WINPR_C_ARRAY_INIT;
2254 (void)ConvertWCharNToUtf8(FindFileData.cFileName, ARRAYSIZE(FindFileData.cFileName),
2255 cFileName, ARRAYSIZE(cFileName));
2256
2257 free(next);
2258 next = GetCombinedPath(path, cFileName);
2259 if (!next)
2260 goto fail;
2261
2262 if (!append_entry(stream, next))
2263 goto fail;
2264 if (is_directory(next))
2265 {
2266 if (!add_directory(stream, next))
2267 goto fail;
2268 }
2269 } while (FindNextFileW(hFind, &FindFileData));
2270
2271 rc = TRUE;
2272fail:
2273 free(next);
2274 FindClose(hFind);
2275
2276 return rc;
2277}
2278
2279static BOOL cliprdr_local_stream_update(CliprdrLocalStream* stream, const char* data, size_t size)
2280{
2281 BOOL rc = FALSE;
2282 WINPR_ASSERT(stream);
2283 if (size == 0)
2284 return TRUE;
2285
2286 cliprdr_local_files_free(stream);
2287
2288 stream->files = calloc(size, sizeof(CliprdrLocalFile));
2289 if (!stream->files)
2290 return FALSE;
2291
2292 char* copy = strndup(data, size);
2293 if (!copy)
2294 return FALSE;
2295
2296 char* saveptr = nullptr;
2297 char* ptr = strtok_s(copy, "\r\n", &saveptr);
2298 while (ptr)
2299 {
2300 const char* name = ptr;
2301 if (strncmp("file:///", ptr, 8) == 0)
2302 name = &ptr[7];
2303 else if (strncmp("file:/", ptr, 6) == 0)
2304 name = &ptr[5];
2305
2306 if (!append_entry(stream, name))
2307 goto fail;
2308
2309 if (is_directory(name))
2310 {
2311 const BOOL res = add_directory(stream, name);
2312 if (!res)
2313 goto fail;
2314 }
2315 ptr = strtok_s(nullptr, "\r\n", &saveptr);
2316 }
2317
2318 rc = TRUE;
2319fail:
2320 free(copy);
2321 return rc;
2322}
2323
2324CliprdrLocalStream* cliprdr_local_stream_new(CliprdrFileContext* context, UINT32 streamID,
2325 const char* data, size_t size)
2326{
2327 WINPR_ASSERT(context);
2328 CliprdrLocalStream* stream = calloc(1, sizeof(CliprdrLocalStream));
2329 if (!stream)
2330 return nullptr;
2331
2332 stream->context = context;
2333 if (!cliprdr_local_stream_update(stream, data, size))
2334 goto fail;
2335
2336 stream->lockId = streamID;
2337 return stream;
2338
2339fail:
2340 cliprdr_local_stream_free(stream);
2341 return nullptr;
2342}
2343
2344static UINT32 UINTPointerHash(const void* id)
2345{
2346 WINPR_ASSERT(id);
2347 return *((const UINT32*)id);
2348}
2349
2350static BOOL UINTPointerCompare(const void* pointer1, const void* pointer2)
2351{
2352 if (!pointer1 || !pointer2)
2353 return pointer1 == pointer2;
2354
2355 const UINT32* a = pointer1;
2356 const UINT32* b = pointer2;
2357 return *a == *b;
2358}
2359
2360static void* UINTPointerClone(const void* other)
2361{
2362 const UINT32* src = other;
2363 if (!src)
2364 return nullptr;
2365
2366 UINT32* copy = calloc(1, sizeof(UINT32));
2367 if (!copy)
2368 return nullptr;
2369
2370 *copy = *src;
2371 return copy;
2372}
2373
2374#if defined(WITH_FUSE)
2375CliprdrFuseFile* fuse_file_new_root(CliprdrFileContext* file_context)
2376{
2377 CliprdrFuseFile* root_dir = fuse_file_new("/");
2378 if (!root_dir)
2379 return nullptr;
2380
2381 root_dir->ino = FUSE_ROOT_ID;
2382 root_dir->is_directory = TRUE;
2383 root_dir->is_readonly = TRUE;
2384
2385 if (!HashTable_Insert(file_context->inode_table, (void*)(uintptr_t)root_dir->ino, root_dir))
2386 {
2387 fuse_file_free(root_dir);
2388 return nullptr;
2389 }
2390
2391 return root_dir;
2392}
2393#endif
2394
2395CliprdrFileContext* cliprdr_file_context_new(void* context)
2396{
2397 CliprdrFileContext* file = calloc(1, sizeof(CliprdrFileContext));
2398 if (!file)
2399 return nullptr;
2400
2401 file->log = WLog_Get(CLIENT_TAG("common.cliprdr.file"));
2402 file->clipboard = context;
2403
2404 file->local_streams = HashTable_New(FALSE);
2405 if (!file->local_streams)
2406 goto fail;
2407
2408 if (!HashTable_SetHashFunction(file->local_streams, UINTPointerHash))
2409 goto fail;
2410
2411 {
2412 wObject* hkobj = HashTable_KeyObject(file->local_streams);
2413 WINPR_ASSERT(hkobj);
2414 hkobj->fnObjectEquals = UINTPointerCompare;
2415 hkobj->fnObjectFree = free;
2416 hkobj->fnObjectNew = UINTPointerClone;
2417 }
2418
2419 {
2420 wObject* hobj = HashTable_ValueObject(file->local_streams);
2421 WINPR_ASSERT(hobj);
2422 hobj->fnObjectFree = cliprdr_local_stream_free;
2423 }
2424
2425#if defined(WITH_FUSE)
2426 file->inode_table = HashTable_New(FALSE);
2427 file->clip_data_table = HashTable_New(FALSE);
2428 file->request_table = HashTable_New(FALSE);
2429 if (!file->inode_table || !file->clip_data_table || !file->request_table)
2430 goto fail;
2431
2432 {
2433 wObject* ctobj = HashTable_ValueObject(file->request_table);
2434 WINPR_ASSERT(ctobj);
2435 ctobj->fnObjectFree = free;
2436 }
2437 {
2438 wObject* ctobj = HashTable_ValueObject(file->clip_data_table);
2439 WINPR_ASSERT(ctobj);
2440 ctobj->fnObjectFree = clip_data_entry_free;
2441 }
2442#endif
2443
2444 if (!create_base_path(file))
2445 goto fail;
2446
2447#if defined(WITH_FUSE)
2448 if (!(file->fuse_start_sync = CreateEvent(nullptr, TRUE, FALSE, nullptr)))
2449 goto fail;
2450 if (!(file->fuse_stop_sync = CreateEvent(nullptr, TRUE, FALSE, nullptr)))
2451 goto fail;
2452 if (!(file->fuse_thread = CreateThread(nullptr, 0, cliprdr_file_fuse_thread, file, 0, nullptr)))
2453 goto fail;
2454
2455 if (WaitForSingleObject(file->fuse_start_sync, INFINITE) == WAIT_FAILED)
2456 WLog_Print(file->log, WLOG_ERROR, "Failed to wait for start sync");
2457#endif
2458 return file;
2459
2460fail:
2461 WINPR_PRAGMA_DIAG_PUSH
2462 WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
2463 cliprdr_file_context_free(file);
2464 WINPR_PRAGMA_DIAG_POP
2465 return nullptr;
2466}
2467
2468BOOL local_stream_discard(const void* key, void* value, void* arg)
2469{
2470 CliprdrFileContext* file = arg;
2471 CliprdrLocalStream* stream = value;
2472 WINPR_ASSERT(file);
2473 WINPR_ASSERT(stream);
2474
2475 if (!stream->locked)
2476 HashTable_Remove(file->local_streams, key);
2477 return TRUE;
2478}
2479
2480BOOL cliprdr_file_context_clear(CliprdrFileContext* file)
2481{
2482 WINPR_ASSERT(file);
2483
2484 WLog_Print(file->log, WLOG_DEBUG, "clear file clipboard...");
2485
2486 HashTable_Lock(file->local_streams);
2487 HashTable_Foreach(file->local_streams, local_stream_discard, file);
2488 HashTable_Unlock(file->local_streams);
2489
2490 memset(file->server_data_hash, 0, sizeof(file->server_data_hash));
2491 memset(file->client_data_hash, 0, sizeof(file->client_data_hash));
2492 return TRUE;
2493}
2494
2495BOOL cliprdr_file_context_update_client_data(CliprdrFileContext* file, const char* data,
2496 size_t size)
2497{
2498 BOOL rc = FALSE;
2499
2500 WINPR_ASSERT(file);
2501 if (!cliprdr_file_client_content_changed_and_update(file, data, size))
2502 return TRUE;
2503
2504 if (!cliprdr_file_context_clear(file))
2505 return FALSE;
2506
2507 UINT32 lockId = file->local_lock_id;
2508
2509 HashTable_Lock(file->local_streams);
2510 CliprdrLocalStream* stream = HashTable_GetItemValue(file->local_streams, &lockId);
2511
2512 WLog_Print(file->log, WLOG_DEBUG, "update client file list (stream=%p)...", (void*)stream);
2513 if (stream)
2514 rc = cliprdr_local_stream_update(stream, data, size);
2515 else
2516 {
2517 stream = cliprdr_local_stream_new(file, lockId, data, size);
2518 rc = HashTable_Insert(file->local_streams, &stream->lockId, stream);
2519 if (!rc)
2520 cliprdr_local_stream_free(stream);
2521 }
2522 // HashTable_Insert owns stream
2523 // NOLINTNEXTLINE(clang-analyzer-unix.Malloc)
2524 HashTable_Unlock(file->local_streams);
2525 return rc;
2526}
2527
2528UINT32 cliprdr_file_context_current_flags(CliprdrFileContext* file)
2529{
2530 WINPR_ASSERT(file);
2531
2532 if ((file->file_capability_flags & CB_STREAM_FILECLIP_ENABLED) == 0)
2533 return 0;
2534
2535 if (!file->file_formats_registered)
2536 return 0;
2537
2538 return CB_STREAM_FILECLIP_ENABLED | CB_FILECLIP_NO_FILE_PATHS |
2539 CB_HUGE_FILE_SUPPORT_ENABLED; // | CB_CAN_LOCK_CLIPDATA;
2540}
2541
2542BOOL cliprdr_file_context_set_locally_available(CliprdrFileContext* file, BOOL available)
2543{
2544 WINPR_ASSERT(file);
2545 file->file_formats_registered = available;
2546 return TRUE;
2547}
2548
2549BOOL cliprdr_file_context_remote_set_flags(CliprdrFileContext* file, UINT32 flags)
2550{
2551 WINPR_ASSERT(file);
2552 file->file_capability_flags = flags;
2553 return TRUE;
2554}
2555
2556UINT32 cliprdr_file_context_remote_get_flags(CliprdrFileContext* file)
2557{
2558 WINPR_ASSERT(file);
2559 return file->file_capability_flags;
2560}
2561
2562BOOL cliprdr_file_context_has_local_support(CliprdrFileContext* file)
2563{
2564 WINPR_UNUSED(file);
2565
2566#if defined(WITH_FUSE)
2567 return TRUE;
2568#else
2569 return FALSE;
2570#endif
2571}
This struct contains function pointer to initialize/free objects.
Definition collections.h:52
OBJECT_FREE_FN fnObjectFree
Definition collections.h:58
OBJECT_EQUALS_FN fnObjectEquals
Definition collections.h:59
OBJECT_NEW_FN fnObjectNew
Definition collections.h:53