-
Notifications
You must be signed in to change notification settings - Fork 278
/
encfs.cpp
746 lines (617 loc) · 20.9 KB
/
encfs.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
/*****************************************************************************
* Author: Valient Gough <vgough@pobox.com>
*
*****************************************************************************
* Copyright (c) 2003-2007, Valient Gough
*
* This program is free software; you can distribute it and/or modify it under
* the terms of the GNU General Public License (GPL), as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*/
#include "encfs.h"
#include <cerrno>
#include <cstddef>
#include <cstdio>
#include <cstring>
#include <fcntl.h>
#include <inttypes.h>
#include <memory>
#include <stdint.h>
#include <sys/stat.h>
#include <sys/statvfs.h>
#include <sys/time.h>
#include <time.h>
#include <unistd.h>
#include <utime.h>
#ifdef linux
#include <sys/fsuid.h>
#endif
#if defined(HAVE_SYS_XATTR_H)
#include <sys/xattr.h>
#elif defined(HAVE_ATTR_XATTR_H)
#include <attr/xattr.h>
#endif
#include "internal/easylogging++.h"
#include <functional>
#include <string>
#include <vector>
#include "Context.h"
#include "DirNode.h"
#include "Error.h"
#include "FileNode.h"
#include "FileUtils.h"
#include "fuse.h"
#ifndef MIN
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#endif
#define ESUCCESS 0
using namespace std;
using namespace std::placeholders;
namespace encfs {
#define GET_FN(ctx, finfo) ctx->getNode((void *)(uintptr_t)finfo->fh)
static EncFS_Context *context() {
return (EncFS_Context *)fuse_get_context()->private_data;
}
/**
* Helper function - determine if the filesystem is read-only
* Optionally takes a pointer to the EncFS_Context, will get it from FUSE
* if the argument is NULL.
*/
static bool isReadOnly(EncFS_Context *ctx) {
if (ctx == NULL) ctx = (EncFS_Context *)fuse_get_context()->private_data;
return ctx->opts->readOnly;
}
// helper function -- apply a functor to a cipher path, given the plain path
static int withCipherPath(const char *opName, const char *path,
function<int(EncFS_Context *, const string &)> op,
bool passReturnCode = false) {
EncFS_Context *ctx = context();
int res = -EIO;
std::shared_ptr<DirNode> FSRoot = ctx->getRoot(&res);
if (!FSRoot) return res;
try {
string cyName = FSRoot->cipherPath(path);
VLOG(1) << "op: " << opName << " : " << cyName;
res = op(ctx, cyName);
if (res == -1) {
int eno = errno;
VLOG(1) << "op: " << opName << " error: " << strerror(eno);
res = -eno;
} else if (!passReturnCode) {
res = ESUCCESS;
}
} catch (encfs::Error &err) {
RLOG(ERROR) << "withCipherPath: error caught in " << opName << ": "
<< err.what();
}
return res;
}
// helper function -- apply a functor to a node
static int withFileNode(const char *opName, const char *path,
struct fuse_file_info *fi,
function<int(FileNode *)> op) {
EncFS_Context *ctx = context();
int res = -EIO;
std::shared_ptr<DirNode> FSRoot = ctx->getRoot(&res);
if (!FSRoot) return res;
try {
auto do_op = [&FSRoot, opName, &op](FileNode *fnode) {
rAssert(fnode != nullptr);
VLOG(1) << "op: " << opName << " : " << fnode->cipherName();
// check that we're not recursing into the mount point itself
if (FSRoot->touchesMountpoint(fnode->cipherName())) {
VLOG(1) << "op: " << opName << " error: Tried to touch mountpoint: '"
<< fnode->cipherName() << "'";
return -EIO;
}
return op(fnode);
};
if (fi != nullptr && fi->fh != 0)
res = do_op(reinterpret_cast<FileNode *>(fi->fh));
else
res = do_op(FSRoot->lookupNode(path, opName).get());
if (res < 0) {
RLOG(DEBUG) << "op: " << opName << " error: " << strerror(-res);
}
} catch (encfs::Error &err) {
RLOG(ERROR) << "withFileNode: error caught in " << opName << ": "
<< err.what();
}
return res;
}
/*
The log messages below always print encrypted filenames, not
plaintext. This avoids possibly leaking information to log files.
The purpose of this layer of code is to take the FUSE request and dispatch
to the internal interfaces. Any marshaling of arguments and return types
can be done here.
*/
int _do_getattr(FileNode *fnode, struct stat *stbuf) {
int res = fnode->getAttr(stbuf);
if (res == ESUCCESS && S_ISLNK(stbuf->st_mode)) {
EncFS_Context *ctx = context();
std::shared_ptr<DirNode> FSRoot = ctx->getRoot(&res);
if (FSRoot) {
// determine plaintext link size.. Easiest to read and decrypt..
std::vector<char> buf(stbuf->st_size + 1, '\0');
res = ::readlink(fnode->cipherName(), buf.data(), stbuf->st_size);
if (res >= 0) {
// other functions expect c-strings to be null-terminated, which
// readlink doesn't provide
buf[res] = '\0';
stbuf->st_size = FSRoot->plainPath(buf.data()).length();
res = ESUCCESS;
} else {
res = -errno;
}
}
}
return res;
}
int encfs_getattr(const char *path, struct stat *stbuf) {
return withFileNode("getattr", path, NULL, bind(_do_getattr, _1, stbuf));
}
int encfs_fgetattr(const char *path, struct stat *stbuf,
struct fuse_file_info *fi) {
return withFileNode("fgetattr", path, fi, bind(_do_getattr, _1, stbuf));
}
int encfs_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
off_t offset, struct fuse_file_info *finfo) {
EncFS_Context *ctx = context();
int res = ESUCCESS;
std::shared_ptr<DirNode> FSRoot = ctx->getRoot(&res);
if (!FSRoot) return res;
try {
DirTraverse dt = FSRoot->openDir(path);
VLOG(1) << "readdir on " << FSRoot->cipherPath(path);
if (dt.valid()) {
int fileType = 0;
ino_t inode = 0;
std::string name = dt.nextPlaintextName(&fileType, &inode);
while (!name.empty()) {
struct stat st;
st.st_ino = inode;
st.st_mode = fileType << 12;
// TODO: add offset support.
#if defined(fuse_fill_dir_flags)
if (filler(buf, name.c_str(), &st, 0, 0)) break;
#else
if (filler(buf, name.c_str(), &st, 0)) break;
#endif
name = dt.nextPlaintextName(&fileType, &inode);
}
} else {
VLOG(1) << "readdir request invalid, path: '" << path << "'";
}
return res;
} catch (encfs::Error &err) {
RLOG(ERROR) << "Error caught in readdir";
return -EIO;
}
}
int encfs_mknod(const char *path, mode_t mode, dev_t rdev) {
EncFS_Context *ctx = context();
if (isReadOnly(ctx)) return -EROFS;
int res = -EIO;
std::shared_ptr<DirNode> FSRoot = ctx->getRoot(&res);
if (!FSRoot) return res;
try {
std::shared_ptr<FileNode> fnode = FSRoot->lookupNode(path, "mknod");
VLOG(1) << "mknod on " << fnode->cipherName() << ", mode " << mode
<< ", dev " << rdev;
uid_t uid = 0;
gid_t gid = 0;
if (ctx->publicFilesystem) {
fuse_context *context = fuse_get_context();
uid = context->uid;
gid = context->gid;
}
res = fnode->mknod(mode, rdev, uid, gid);
// Is this error due to access problems?
if (ctx->publicFilesystem && -res == EACCES) {
// try again using the parent dir's group
string parent = fnode->plaintextParent();
VLOG(1) << "trying public filesystem workaround for " << parent;
std::shared_ptr<FileNode> dnode =
FSRoot->lookupNode(parent.c_str(), "mknod");
struct stat st;
if (dnode->getAttr(&st) == 0)
res = fnode->mknod(mode, rdev, uid, st.st_gid);
}
} catch (encfs::Error &err) {
RLOG(ERROR) << "error caught in mknod: " << err.what();
}
return res;
}
int encfs_mkdir(const char *path, mode_t mode) {
fuse_context *fctx = fuse_get_context();
EncFS_Context *ctx = context();
if (isReadOnly(ctx)) return -EROFS;
int res = -EIO;
std::shared_ptr<DirNode> FSRoot = ctx->getRoot(&res);
if (!FSRoot) return res;
try {
uid_t uid = 0;
gid_t gid = 0;
if (ctx->publicFilesystem) {
uid = fctx->uid;
gid = fctx->gid;
}
res = FSRoot->mkdir(path, mode, uid, gid);
// Is this error due to access problems?
if (ctx->publicFilesystem && -res == EACCES) {
// try again using the parent dir's group
string parent = parentDirectory(path);
std::shared_ptr<FileNode> dnode =
FSRoot->lookupNode(parent.c_str(), "mkdir");
struct stat st;
if (dnode->getAttr(&st) == 0)
res = FSRoot->mkdir(path, mode, uid, st.st_gid);
}
} catch (encfs::Error &err) {
RLOG(ERROR) << "error caught in mkdir: " << err.what();
}
return res;
}
int encfs_unlink(const char *path) {
EncFS_Context *ctx = context();
if (isReadOnly(ctx)) return -EROFS;
int res = -EIO;
std::shared_ptr<DirNode> FSRoot = ctx->getRoot(&res);
if (!FSRoot) return res;
try {
// let DirNode handle it atomically so that it can handle race
// conditions
res = FSRoot->unlink(path);
} catch (encfs::Error &err) {
RLOG(ERROR) << "error caught in unlink: " << err.what();
}
return res;
}
int _do_rmdir(EncFS_Context *, const string &cipherPath) {
return rmdir(cipherPath.c_str());
}
int encfs_rmdir(const char *path) {
if (isReadOnly(NULL)) return -EROFS;
return withCipherPath("rmdir", path, bind(_do_rmdir, _1, _2));
}
int _do_readlink(EncFS_Context *ctx, const string &cyName, char *buf,
size_t size) {
int res = ESUCCESS;
std::shared_ptr<DirNode> FSRoot = ctx->getRoot(&res);
if (!FSRoot) return res;
res = ::readlink(cyName.c_str(), buf, size - 1);
if (res == -1) return -errno;
buf[res] = '\0'; // ensure null termination
string decodedName;
try {
decodedName = FSRoot->plainPath(buf);
} catch (...) {
VLOG(1) << "caught error decoding path";
}
if (!decodedName.empty()) {
strncpy(buf, decodedName.c_str(), size - 1);
buf[size - 1] = '\0';
return ESUCCESS;
} else {
RLOG(WARNING) << "Error decoding link";
return -1;
}
}
int encfs_readlink(const char *path, char *buf, size_t size) {
return withCipherPath("readlink", path,
bind(_do_readlink, _1, _2, buf, size));
}
/**
* Create a symbolic link pointing to "to" named "from"
*/
int encfs_symlink(const char *to, const char *from) {
EncFS_Context *ctx = context();
if (isReadOnly(ctx)) return -EROFS;
int res = -EIO;
std::shared_ptr<DirNode> FSRoot = ctx->getRoot(&res);
if (!FSRoot) return res;
try {
string fromCName = FSRoot->cipherPath(from);
// allow fully qualified names in symbolic links.
string toCName = FSRoot->relativeCipherPath(to);
VLOG(1) << "symlink " << fromCName << " -> " << toCName;
// use setfsuid / setfsgid so that the new link will be owned by the
// uid/gid provided by the fuse_context.
int olduid = -1;
int oldgid = -1;
if (ctx->publicFilesystem) {
fuse_context *context = fuse_get_context();
olduid = setfsuid(context->uid);
oldgid = setfsgid(context->gid);
}
res = ::symlink(toCName.c_str(), fromCName.c_str());
if (olduid >= 0) setfsuid(olduid);
if (oldgid >= 0) setfsgid(oldgid);
if (res == -1)
res = -errno;
else
res = ESUCCESS;
} catch (encfs::Error &err) {
RLOG(ERROR) << "error caught in symlink: " << err.what();
}
return res;
}
int encfs_link(const char *from, const char *to) {
EncFS_Context *ctx = context();
if (isReadOnly(ctx)) return -EROFS;
int res = -EIO;
std::shared_ptr<DirNode> FSRoot = ctx->getRoot(&res);
if (!FSRoot) return res;
try {
res = FSRoot->link(from, to);
} catch (encfs::Error &err) {
RLOG(ERROR) << "error caught in link: " << err.what();
}
return res;
}
int encfs_rename(const char *from, const char *to) {
EncFS_Context *ctx = context();
if (isReadOnly(ctx)) return -EROFS;
int res = -EIO;
std::shared_ptr<DirNode> FSRoot = ctx->getRoot(&res);
if (!FSRoot) return res;
try {
res = FSRoot->rename(from, to);
} catch (encfs::Error &err) {
RLOG(ERROR) << "error caught in rename: " << err.what();
}
return res;
}
int _do_chmod(EncFS_Context *, const string &cipherPath, mode_t mode) {
return chmod(cipherPath.c_str(), mode);
}
int encfs_chmod(const char *path, mode_t mode) {
if (isReadOnly(NULL)) return -EROFS;
return withCipherPath("chmod", path, bind(_do_chmod, _1, _2, mode));
}
int _do_chown(EncFS_Context *, const string &cyName, uid_t u, gid_t g) {
int res = lchown(cyName.c_str(), u, g);
return (res == -1) ? -errno : ESUCCESS;
}
int encfs_chown(const char *path, uid_t uid, gid_t gid) {
if (isReadOnly(NULL)) return -EROFS;
return withCipherPath("chown", path, bind(_do_chown, _1, _2, uid, gid));
}
int _do_truncate(FileNode *fnode, off_t size) { return fnode->truncate(size); }
int encfs_truncate(const char *path, off_t size) {
if (isReadOnly(NULL)) return -EROFS;
return withFileNode("truncate", path, NULL, bind(_do_truncate, _1, size));
}
int encfs_ftruncate(const char *path, off_t size, struct fuse_file_info *fi) {
if (isReadOnly(NULL)) return -EROFS;
return withFileNode("ftruncate", path, fi, bind(_do_truncate, _1, size));
}
int _do_utime(EncFS_Context *, const string &cyName, struct utimbuf *buf) {
int res = utime(cyName.c_str(), buf);
return (res == -1) ? -errno : ESUCCESS;
}
int encfs_utime(const char *path, struct utimbuf *buf) {
if (isReadOnly(NULL)) return -EROFS;
return withCipherPath("utime", path, bind(_do_utime, _1, _2, buf));
}
int _do_utimens(EncFS_Context *, const string &cyName,
const struct timespec ts[2]) {
#ifdef HAVE_UTIMENSAT
int res = utimensat(AT_FDCWD, cyName.c_str(), ts, AT_SYMLINK_NOFOLLOW);
#else
struct timeval tv[2];
tv[0].tv_sec = ts[0].tv_sec;
tv[0].tv_usec = ts[0].tv_nsec / 1000;
tv[1].tv_sec = ts[1].tv_sec;
tv[1].tv_usec = ts[1].tv_nsec / 1000;
int res = lutimes(cyName.c_str(), tv);
#endif
return (res == -1) ? -errno : ESUCCESS;
}
int encfs_utimens(const char *path, const struct timespec ts[2]) {
if (isReadOnly(NULL)) return -EROFS;
return withCipherPath("utimens", path, bind(_do_utimens, _1, _2, ts));
}
int encfs_open(const char *path, struct fuse_file_info *file) {
EncFS_Context *ctx = context();
if (isReadOnly(ctx) && (file->flags & O_WRONLY || file->flags & O_RDWR))
return -EROFS;
int res = -EIO;
std::shared_ptr<DirNode> FSRoot = ctx->getRoot(&res);
if (!FSRoot) return res;
try {
std::shared_ptr<FileNode> fnode =
FSRoot->openNode(path, "open", file->flags, &res);
if (fnode) {
VLOG(1) << "encfs_open for " << fnode->cipherName() << ", flags "
<< file->flags;
if (res >= 0) {
file->fh =
reinterpret_cast<uintptr_t>(ctx->putNode(path, std::move(fnode)));
res = ESUCCESS;
}
}
} catch (encfs::Error &err) {
RLOG(ERROR) << "error caught in open: " << err.what();
}
return res;
}
int encfs_create(const char *path, mode_t mode, struct fuse_file_info *file) {
int res = encfs_mknod(path, mode, 0);
if (res) {
return res;
}
return encfs_open(path, file);
}
int _do_flush(FileNode *fnode) {
/* Flush can be called multiple times for an open file, so it doesn't
close the file. However it is important to call close() for some
underlying filesystems (like NFS).
*/
int res = fnode->open(O_RDONLY);
if (res >= 0) {
int fh = res;
int nfh = dup(fh);
if (nfh == -1) {
return -errno;
}
res = close(nfh);
if (res == -1) {
return -errno;
}
}
return res;
}
// Called on each close() of a file descriptor
int encfs_flush(const char *path, struct fuse_file_info *fi) {
return withFileNode("flush", path, fi, bind(_do_flush, _1));
}
/*
Note: This is advisory -- it might benefit us to keep file nodes around for a
bit after they are released just in case they are reopened soon. But that
requires a cache layer.
*/
int encfs_release(const char *path, struct fuse_file_info *finfo) {
EncFS_Context *ctx = context();
try {
ctx->eraseNode(path, reinterpret_cast<FileNode *>(finfo->fh));
return ESUCCESS;
} catch (encfs::Error &err) {
RLOG(ERROR) << "error caught in release: " << err.what();
return -EIO;
}
}
int _do_read(FileNode *fnode, unsigned char *ptr, size_t size, off_t off) {
return fnode->read(off, ptr, size);
}
int encfs_read(const char *path, char *buf, size_t size, off_t offset,
struct fuse_file_info *file) {
return withFileNode("read", path, file,
bind(_do_read, _1, (unsigned char *)buf, size, offset));
}
int _do_fsync(FileNode *fnode, int dataSync) {
return fnode->sync(dataSync != 0);
}
int encfs_fsync(const char *path, int dataSync, struct fuse_file_info *file) {
if (isReadOnly(NULL)) return -EROFS;
return withFileNode("fsync", path, file, bind(_do_fsync, _1, dataSync));
}
int _do_write(FileNode *fnode, unsigned char *ptr, size_t size, off_t offset) {
if (fnode->write(offset, ptr, size))
return size;
else
return -EIO;
}
int encfs_write(const char *path, const char *buf, size_t size, off_t offset,
struct fuse_file_info *file) {
if (isReadOnly(NULL)) return -EROFS;
return withFileNode("write", path, file,
bind(_do_write, _1, (unsigned char *)buf, size, offset));
}
// statfs works even if encfs is detached..
int encfs_statfs(const char *path, struct statvfs *st) {
EncFS_Context *ctx = context();
int res = -EIO;
try {
(void)path; // path should always be '/' for now..
rAssert(st != NULL);
string cyName = ctx->rootCipherDir;
VLOG(1) << "doing statfs of " << cyName;
res = statvfs(cyName.c_str(), st);
if (!res) {
// adjust maximum name length..
st->f_namemax = 6 * (st->f_namemax - 2) / 8; // approx..
}
if (res == -1) res = -errno;
} catch (encfs::Error &err) {
RLOG(ERROR) << "error caught in statfs: " << err.what();
}
return res;
}
#ifdef HAVE_XATTR
#ifdef XATTR_ADD_OPT
int _do_setxattr(EncFS_Context *, const string &cyName, const char *name,
const char *value, size_t size, uint32_t pos) {
int options = 0;
return ::setxattr(cyName.c_str(), name, value, size, pos, options);
}
int encfs_setxattr(const char *path, const char *name, const char *value,
size_t size, int flags, uint32_t position) {
if (isReadOnly(NULL)) return -EROFS;
(void)flags;
return withCipherPath("setxattr", path, bind(_do_setxattr, _1, _2, name,
value, size, position));
}
#else
int _do_setxattr(EncFS_Context *, const string &cyName, const char *name,
const char *value, size_t size, int flags) {
return ::setxattr(cyName.c_str(), name, value, size, flags);
}
int encfs_setxattr(const char *path, const char *name, const char *value,
size_t size, int flags) {
if (isReadOnly(NULL)) return -EROFS;
return withCipherPath("setxattr", path,
bind(_do_setxattr, _1, _2, name, value, size, flags));
}
#endif
#ifdef XATTR_ADD_OPT
int _do_getxattr(EncFS_Context *, const string &cyName, const char *name,
void *value, size_t size, uint32_t pos) {
int options = 0;
return ::getxattr(cyName.c_str(), name, value, size, pos, options);
}
int encfs_getxattr(const char *path, const char *name, char *value, size_t size,
uint32_t position) {
return withCipherPath(
"getxattr", path,
bind(_do_getxattr, _1, _2, name, (void *)value, size, position), true);
}
#else
int _do_getxattr(EncFS_Context *, const string &cyName, const char *name,
void *value, size_t size) {
return ::getxattr(cyName.c_str(), name, value, size);
}
int encfs_getxattr(const char *path, const char *name, char *value,
size_t size) {
return withCipherPath("getxattr", path,
bind(_do_getxattr, _1, _2, name, (void *)value, size),
true);
}
#endif
int _do_listxattr(EncFS_Context *, const string &cyName, char *list,
size_t size) {
#ifdef XATTR_ADD_OPT
int options = 0;
int res = ::listxattr(cyName.c_str(), list, size, options);
#else
int res = ::listxattr(cyName.c_str(), list, size);
#endif
return (res == -1) ? -errno : res;
}
int encfs_listxattr(const char *path, char *list, size_t size) {
return withCipherPath("listxattr", path,
bind(_do_listxattr, _1, _2, list, size), true);
}
int _do_removexattr(EncFS_Context *, const string &cyName, const char *name) {
#ifdef XATTR_ADD_OPT
int options = 0;
int res = ::removexattr(cyName.c_str(), name, options);
#else
int res = ::removexattr(cyName.c_str(), name);
#endif
return (res == -1) ? -errno : res;
}
int encfs_removexattr(const char *path, const char *name) {
if (isReadOnly(NULL)) return -EROFS;
return withCipherPath("removexattr", path,
bind(_do_removexattr, _1, _2, name));
}
} // namespace encfs
#endif // HAVE_XATTR