Debian Codegraph @

xlators/system/posix-acl/src/posix-acl.c

raw symbols SCIP
1 /*
2 Copyright (c) 2011-2012 Red Hat, Inc. <http://www.redhat.com>
3 This file is part of GlusterFS.
4
5 This file is licensed to you under your choice of the GNU Lesser
6 General Public License, version 3 or any later version (LGPLv3 or
7 later), or the GNU General Public License, version 2 (GPLv2), in all
8 cases as published by the Free Software Foundation.
9 */
10
11 #include <glusterfs/defaults.h>
12
13 #include "posix-acl.h"
14 #include "posix-acl-xattr.h"
15 #include "posix-acl-mem-types.h"
16 #include "posix-acl-messages.h"
17
18 #define UINT64(ptr) ((uint64_t)((long)(ptr)))
19 #define PTR(num) ((void *)((long)(num)))
20
21 int32_t
22 mem_acct_init(xlator_t *this)
23 {
24 int ret = -1;
25
26 if (!this)
27 return ret;
28
29 ret = xlator_mem_acct_init(this, gf_posix_acl_mt_end);
30
31 if (ret != 0) {
32 gf_log(this->name, GF_LOG_ERROR,
33 "Memory accounting init"
34 "failed");
35 return ret;
36 }
37
38 return ret;
39 }
40
41 static uid_t
42 r00t(void)
43 {
44 struct posix_acl_conf *conf = NULL;
45
46 conf = THIS->private;
47
48 return conf->super_uid;
49 }
50
51 static int
52 allowed_xattr(const char *key)
53 {
54 if (!key)
55 return 0;
56
57 if (strcmp(POSIX_ACL_ACCESS_XATTR, key) == 0)
58 return 1;
59 if (strcmp(POSIX_ACL_DEFAULT_XATTR, key) == 0)
60 return 1;
61 if (strcmp(GF_POSIX_ACL_ACCESS, key) == 0)
62 return 1;
63 if (strcmp(GF_POSIX_ACL_DEFAULT, key) == 0)
64 return 1;
65 return 0;
66 }
67
68 int
69 frame_is_user(call_frame_t *frame, uid_t uid)
70 {
71 return (frame->root->uid == uid);
72 }
73
74 int
75 frame_is_super_user(call_frame_t *frame)
76 {
77 int ret;
78
79 ret = frame_is_user(frame, r00t());
80 if (!ret)
81 ret = frame_is_user(frame, 0);
82
83 return ret;
84 }
85
86 int
87 frame_in_group(call_frame_t *frame, gid_t gid)
88 {
89 int i = 0;
90
91 if (frame->root->gid == gid)
92 return 1;
93
94 for (i = 0; i < frame->root->ngrps; i++)
95 if (frame->root->groups[i] == gid)
96 return 1;
97 return 0;
98 }
99
100 mode_t
101 posix_acl_access_set_mode(struct posix_acl *acl, struct posix_acl_ctx *ctx)
102 {
103 struct posix_ace *ace = NULL;
104 struct posix_ace *group_ce = NULL;
105 struct posix_ace *mask_ce = NULL;
106 int count = 0;
107 int i = 0;
108 mode_t mode = 0;
109 int mask = 0;
110
111 count = acl->count;
112
113 ace = acl->entries;
114 for (i = 0; i < count; i++) {
115 switch (ace->tag) {
116 case POSIX_ACL_USER_OBJ:
117 mask |= S_IRWXU;
118 mode |= (ace->perm << 6);
119 break;
120 case POSIX_ACL_GROUP_OBJ:
121 group_ce = ace;
122 break;
123 case POSIX_ACL_MASK:
124 mask_ce = ace;
125 break;
126 case POSIX_ACL_OTHER:
127 mask |= S_IRWXO;
128 mode |= (ace->perm);
129 break;
130 }
131 ace++;
132 }
133
134 if (mask_ce) {
135 mask |= S_IRWXG;
136 mode |= (mask_ce->perm << 3);
137 } else {
138 if (!group_ce)
139 goto out;
140 mask |= S_IRWXG;
141 mode |= (group_ce->perm << 3);
142 }
143
144 out:
145 ctx->perm = (ctx->perm & ~mask) | mode;
146
147 return mode;
148 }
149
150 static int
151 sticky_permits(call_frame_t *frame, inode_t *parent, inode_t *inode)
152 {
153 struct posix_acl_ctx *par = NULL;
154 struct posix_acl_ctx *ctx = NULL;
155
156 if ((0 > frame->root->pid) || frame_is_super_user(frame))
157 return 1;
158
159 par = posix_acl_ctx_get(parent, frame->this);
160 if (par == NULL)
161 return 0;
162
163 ctx = posix_acl_ctx_get(inode, frame->this);
164 if (ctx == NULL)
165 return 0;
166
167 if (!(par->perm & S_ISVTX))
168 return 1;
169
170 if (frame_is_user(frame, par->uid))
171 return 1;
172
173 if (frame_is_user(frame, ctx->uid))
174 return 1;
175
176 return 0;
177 }
178
179 static gf_boolean_t
180 _does_acl_exist(struct posix_acl *acl)
181 {
182 if (acl && (acl->count > POSIX_ACL_MINIMAL_ACE_COUNT))
183 return _gf_true;
184 return _gf_false;
185 }
186
187 static void
188 posix_acl_get_acl_string(call_frame_t *frame, struct posix_acl *acl,
189 char **acl_str)
190 {
191 int i = 0;
192 size_t size_acl = 0;
193 size_t offset = 0;
194 struct posix_ace *ace = NULL;
195 char tmp_str[1024] = {0};
196 #define NON_GRP_FMT "(tag:%" PRIu16 ",perm:%" PRIu16 ",id:%" PRIu32 ")"
197 #define GRP_FMT "(tag:%" PRIu16 ",perm:%" PRIu16 ",id:%" PRIu32 ",in-groups:%d)"
198
199 if (!_does_acl_exist(acl))
200 goto out;
201
202 ace = acl->entries;
203 for (i = 0; i < acl->count; i++) {
204 if (ace->tag != POSIX_ACL_GROUP) {
205 size_acl += snprintf(tmp_str, sizeof tmp_str, NON_GRP_FMT, ace->tag,
206 ace->perm, ace->id);
207 } else {
208 size_acl += snprintf(tmp_str, sizeof tmp_str, GRP_FMT, ace->tag,
209 ace->perm, ace->id,
210 frame_in_group(frame, ace->id));
211 }
212
213 ace++;
214 }
215
216 *acl_str = GF_CALLOC(1, size_acl + 1, gf_posix_acl_mt_char);
217 if (!*acl_str)
218 goto out;
219
220 ace = acl->entries;
221 for (i = 0; i < acl->count; i++) {
222 if (ace->tag != POSIX_ACL_GROUP) {
223 offset += snprintf(*acl_str + offset, size_acl - offset,
224 NON_GRP_FMT, ace->tag, ace->perm, ace->id);
225 } else {
226 offset += snprintf(*acl_str + offset, size_acl - offset, GRP_FMT,
227 ace->tag, ace->perm, ace->id,
228 frame_in_group(frame, ace->id));
229 }
230
231 ace++;
232 }
233 out:
234 return;
235 }
236
237 static void
238 posix_acl_log_permit_denied(call_frame_t *frame, inode_t *inode, int want,
239 struct posix_acl_ctx *ctx, struct posix_acl *acl)
240 {
241 char *acl_str = NULL;
242 client_t *client = NULL;
243
244 if (!frame || !inode || !ctx || !frame->root)
245 goto out;
246
247 client = frame->root->client;
248 posix_acl_get_acl_string(frame, acl, &acl_str);
249
250 gf_msg(frame->this->name, GF_LOG_INFO, EACCES, POSIX_ACL_MSG_EACCES,
251 "client: %s, gfid: %s, req(uid:%d,gid:%d,perm:%d,"
252 "ngrps:%" PRIu16
253 "), ctx(uid:%d,gid:%d,in-groups:%d,perm:%d%d%d,"
254 "updated-fop:%s, acl:%s)",
255 client ? client->client_uid : "-", uuid_utoa(inode->gfid),
256 frame->root->uid, frame->root->gid, want, frame->root->ngrps,
257 ctx->uid, ctx->gid, frame_in_group(frame, ctx->gid),
258 (ctx->perm & S_IRWXU) >> 6, (ctx->perm & S_IRWXG) >> 3,
259 ctx->perm & S_IRWXO, gf_fop_string(ctx->fop),
260 acl_str ? acl_str : "-");
261 out:
262 GF_FREE(acl_str);
263 return;
264 }
265
266 static int
267 acl_permits(call_frame_t *frame, inode_t *inode, int want)
268 {
269 int verdict = 0;
270 struct posix_acl *acl = NULL;
271 struct posix_ace *ace = NULL;
272 struct posix_acl_ctx *ctx = NULL;
273 struct posix_acl_conf *conf = NULL;
274 int i = 0;
275 int perm = 0;
276 int found = 0;
277 int acl_present = 0;
278
279 conf = frame->this->private;
280
281 if ((0 > frame->root->pid) || frame_is_super_user(frame))
282 goto green;
283
284 ctx = posix_acl_ctx_get(inode, frame->this);
285 if (!ctx)
286 goto red;
287
288 posix_acl_get(inode, frame->this, &acl, NULL);
289 if (!acl) {
290 acl = posix_acl_ref(frame->this, conf->minimal_acl);
291 }
292
293 ace = acl->entries;
294
295 if (_does_acl_exist(acl))
296 acl_present = 1;
297
298 for (i = 0; i < acl->count; i++) {
299 switch (ace->tag) {
300 case POSIX_ACL_USER_OBJ:
301 perm = ((ctx->perm & S_IRWXU) >> 6);
302 if (frame_is_user(frame, ctx->uid))
303 goto perm_check;
304 break;
305 case POSIX_ACL_USER:
306 perm = ace->perm;
307 if (frame_is_user(frame, ace->id))
308 goto mask_check;
309 break;
310 case POSIX_ACL_GROUP_OBJ:
311 if (acl_present)
312 perm = ace->perm;
313 else
314 perm = ((ctx->perm & S_IRWXG) >> 3);
315 if (frame_in_group(frame, ctx->gid)) {
316 found = 1;
317 if ((perm & want) == want)
318 goto mask_check;
319 }
320 break;
321 case POSIX_ACL_GROUP:
322 perm = ace->perm;
323 if (frame_in_group(frame, ace->id)) {
324 found = 1;
325 if ((perm & want) == want)
326 goto mask_check;
327 }
328 break;
329 case POSIX_ACL_MASK:
330 break;
331 case POSIX_ACL_OTHER:
332 perm = (ctx->perm & S_IRWXO);
333 if (!found)
334 goto perm_check;
335 /* fall through */
336 default:
337 goto red;
338 }
339
340 ace++;
341 }
342
343 mask_check:
344 ace = acl->entries;
345
346 for (i = 0; i < acl->count; i++, ace++) {
347 if (ace->tag != POSIX_ACL_MASK)
348 continue;
349 if ((ace->perm & perm & want) == want) {
350 goto green;
351 }
352 goto red;
353 }
354
355 perm_check:
356 if ((perm & want) == want) {
357 goto green;
358 } else {
359 goto red;
360 }
361
362 green:
363 verdict = 1;
364 goto out;
365 red:
366 verdict = 0;
367 posix_acl_log_permit_denied(frame, inode, want, ctx, acl);
368 out:
369 if (acl)
370 posix_acl_unref(frame->this, acl);
371
372 return verdict;
373 }
374
375 struct posix_acl_ctx *
376 __posix_acl_ctx_get(inode_t *inode, xlator_t *this, gf_boolean_t create)
377 {
378 struct posix_acl_ctx *ctx = NULL;
379 uint64_t int_ctx = 0;
380 int ret = 0;
381
382 ret = __inode_ctx_get(inode, this, &int_ctx);
383 if ((ret == 0) && (int_ctx))
384 return PTR(int_ctx);
385
386 if (create == _gf_false)
387 return NULL;
388
389 ctx = GF_CALLOC(1, sizeof(*ctx), gf_posix_acl_mt_ctx_t);
390 if (!ctx)
391 return NULL;
392
393 ret = __inode_ctx_put(inode, this, UINT64(ctx));
394 if (ret) {
395 GF_FREE(ctx);
396 ctx = NULL;
397 }
398
399 return ctx;
400 }
401
402 struct posix_acl_ctx *
403 posix_acl_ctx_new(inode_t *inode, xlator_t *this)
404 {
405 struct posix_acl_ctx *ctx = NULL;
406
407 if (inode == NULL) {
408 gf_log_callingfn(this->name, GF_LOG_WARNING, "inode is NULL");
409 return NULL;
410 }
411
412 LOCK(&inode->lock);
413 {
414 ctx = __posix_acl_ctx_get(inode, this, _gf_true);
415 }
416 UNLOCK(&inode->lock);
417
418 if (ctx == NULL)
419 gf_log_callingfn(this->name, GF_LOG_ERROR,
420 "creating inode ctx"
421 "failed for %s",
422 uuid_utoa(inode->gfid));
423 return ctx;
424 }
425
426 struct posix_acl_ctx *
427 posix_acl_ctx_get(inode_t *inode, xlator_t *this)
428 {
429 struct posix_acl_ctx *ctx = NULL;
430
431 if (inode == NULL) {
432 gf_log_callingfn(this->name, GF_LOG_WARNING, "inode is NULL");
433 return NULL;
434 }
435
436 LOCK(&inode->lock);
437 {
438 ctx = __posix_acl_ctx_get(inode, this, _gf_false);
439 }
440 UNLOCK(&inode->lock);
441
442 if (ctx == NULL)
443 gf_log_callingfn(this->name, GF_LOG_ERROR,
444 "inode ctx is NULL "
445 "for %s",
446 uuid_utoa(inode->gfid));
447 return ctx;
448 }
449
450 int
451 __posix_acl_set_specific(inode_t *inode, xlator_t *this, gf_boolean_t is_access,
452 struct posix_acl *acl)
453 {
454 int ret = 0;
455 struct posix_acl_ctx *ctx = NULL;
456
457 ctx = posix_acl_ctx_get(inode, this);
458 if (!ctx) {
459 ret = -1;
460 goto out;
461 }
462
463 if (is_access)
464 ctx->acl_access = acl;
465 else
466 ctx->acl_default = acl;
467 out:
468 return ret;
469 }
470
471 int
472 __posix_acl_set(inode_t *inode, xlator_t *this, struct posix_acl *acl_access,
473 struct posix_acl *acl_default)
474 {
475 int ret = 0;
476 struct posix_acl_ctx *ctx = NULL;
477
478 ctx = posix_acl_ctx_get(inode, this);
479 if (!ctx)
480 goto out;
481
482 ctx->acl_access = acl_access;
483 ctx->acl_default = acl_default;
484
485 out:
486 return ret;
487 }
488
489 int
490 __posix_acl_get(inode_t *inode, xlator_t *this, struct posix_acl **acl_access_p,
491 struct posix_acl **acl_default_p)
492 {
493 int ret = 0;
494 struct posix_acl_ctx *ctx = NULL;
495
496 ctx = posix_acl_ctx_get(inode, this);
497 if (!ctx)
498 goto out;
499
500 if (acl_access_p)
501 *acl_access_p = ctx->acl_access;
502 if (acl_default_p)
503 *acl_default_p = ctx->acl_default;
504
505 out:
506 return ret;
507 }
508
509 struct posix_acl *
510 posix_acl_new(xlator_t *this, int entrycnt)
511 {
512 struct posix_acl *acl = NULL;
513 struct posix_ace *ace = NULL;
514
515 acl = GF_CALLOC(1, sizeof(*acl) + (entrycnt * sizeof(*ace)),
516 gf_posix_acl_mt_posix_ace_t);
517 if (!acl)
518 return NULL;
519
520 acl->count = entrycnt;
521
522 posix_acl_ref(this, acl);
523
524 return acl;
525 }
526
527 void
528 posix_acl_destroy(xlator_t *this, struct posix_acl *acl)
529 {
530 GF_FREE(acl);
531
532 return;
533 }
534
535 struct posix_acl *
536 posix_acl_ref(xlator_t *this, struct posix_acl *acl)
537 {
538 struct posix_acl_conf *conf = NULL;
539
540 conf = this->private;
541
542 LOCK(&conf->acl_lock);
543 {
544 acl->refcnt++;
545 }
546 UNLOCK(&conf->acl_lock);
547
548 return acl;
549 }
550
551 struct posix_acl *
552 posix_acl_dup(xlator_t *this, struct posix_acl *acl)
553 {
554 struct posix_acl *dup = NULL;
555
556 dup = posix_acl_new(this, acl->count);
557 if (!dup)
558 return NULL;
559
560 memcpy(dup->entries, acl->entries, sizeof(struct posix_ace) * acl->count);
561
562 return dup;
563 }
564
565 void
566 posix_acl_unref(xlator_t *this, struct posix_acl *acl)
567 {
568 struct posix_acl_conf *conf = NULL;
569 int refcnt = 0;
570
571 conf = this->private;
572 if (!conf)
573 goto out;
574
575 LOCK(&conf->acl_lock);
576 {
577 refcnt = --acl->refcnt;
578 }
579 UNLOCK(&conf->acl_lock);
580 out:
581 if (!refcnt)
582 posix_acl_destroy(this, acl);
583 }
584
585 int
586 posix_acl_set_specific(inode_t *inode, xlator_t *this, struct posix_acl *acl,
587 gf_boolean_t is_access)
588 {
589 int ret = 0;
590 int oldret = 0;
591 struct posix_acl *old_acl = NULL;
592 struct posix_acl_conf *conf = NULL;
593
594 conf = this->private;
595
596 LOCK(&conf->acl_lock);
597 {
598 if (is_access)
599 oldret = __posix_acl_get(inode, this, &old_acl, NULL);
600 else
601 oldret = __posix_acl_get(inode, this, NULL, &old_acl);
602 if (acl)
603 acl->refcnt++;
604 ret = __posix_acl_set_specific(inode, this, is_access, acl);
605 }
606 UNLOCK(&conf->acl_lock);
607
608 if (!oldret && old_acl) {
609 posix_acl_unref(this, old_acl);
610 }
611
612 return ret;
613 }
614
615 int
616 posix_acl_set(inode_t *inode, xlator_t *this, struct posix_acl *acl_access,
617 struct posix_acl *acl_default)
618 {
619 int ret = 0;
620 int oldret = 0;
621 struct posix_acl *old_access = NULL;
622 struct posix_acl *old_default = NULL;
623 struct posix_acl_conf *conf = NULL;
624
625 conf = this->private;
626
627 LOCK(&conf->acl_lock);
628 {
629 oldret = __posix_acl_get(inode, this, &old_access, &old_default);
630 if (acl_access)
631 acl_access->refcnt++;
632 if (acl_default)
633 acl_default->refcnt++;
634
635 ret = __posix_acl_set(inode, this, acl_access, acl_default);
636 }
637 UNLOCK(&conf->acl_lock);
638
639 if (oldret == 0) {
640 if (old_access)
641 posix_acl_unref(this, old_access);
642 if (old_default)
643 posix_acl_unref(this, old_default);
644 }
645
646 return ret;
647 }
648
649 int
650 posix_acl_get(inode_t *inode, xlator_t *this, struct posix_acl **acl_access_p,
651 struct posix_acl **acl_default_p)
652 {
653 struct posix_acl_conf *conf = NULL;
654 struct posix_acl *acl_access = NULL;
655 struct posix_acl *acl_default = NULL;
656 int ret = 0;
657
658 conf = this->private;
659
660 LOCK(&conf->acl_lock);
661 {
662 ret = __posix_acl_get(inode, this, &acl_access, &acl_default);
663
664 if (ret != 0)
665 goto unlock;
666
667 if (acl_access && acl_access_p)
668 acl_access->refcnt++;
669 if (acl_default && acl_default_p)
670 acl_default->refcnt++;
671 }
672 unlock:
673 UNLOCK(&conf->acl_lock);
674
675 if (acl_access_p)
676 *acl_access_p = acl_access;
677 if (acl_default_p)
678 *acl_default_p = acl_default;
679
680 return ret;
681 }
682
683 mode_t
684 posix_acl_inherit_mode(struct posix_acl *acl, mode_t modein)
685 {
686 struct posix_ace *ace = NULL;
687 int count = 0;
688 int i = 0;
689 mode_t newmode = 0;
690 mode_t mode = 0;
691 struct posix_ace *mask_ce = NULL;
692 struct posix_ace *group_ce = NULL;
693
694 newmode = mode = modein;
695
696 count = acl->count;
697
698 ace = acl->entries;
699 for (i = 0; i < count; i++) {
700 switch (ace->tag) {
701 case POSIX_ACL_USER_OBJ:
702 ace->perm &= (mode >> 6) | ~S_IRWXO;
703 mode &= (ace->perm << 6) | ~S_IRWXU;
704 break;
705 case POSIX_ACL_GROUP_OBJ:
706 group_ce = ace;
707 break;
708 case POSIX_ACL_MASK:
709 mask_ce = ace;
710 break;
711 case POSIX_ACL_OTHER:
712 ace->perm &= (mode) | ~S_IRWXO;
713 mode &= (ace->perm) | ~S_IRWXO;
714 break;
715 }
716 ace++;
717 }
718
719 if (mask_ce) {
720 mask_ce->perm &= (mode >> 3) | ~S_IRWXO;
721 mode &= (mask_ce->perm << 3) | ~S_IRWXG;
722 } else if (group_ce) {
723 group_ce->perm &= (mode >> 3) | ~S_IRWXO;
724 mode &= (group_ce->perm << 3) | ~S_IRWXG;
725 }
726
727 newmode = ((modein & (S_IFMT | S_ISUID | S_ISGID | S_ISVTX)) |
728 (mode & (S_IRWXU | S_IRWXG | S_IRWXO)));
729
730 return newmode;
731 }
732
733 mode_t
734 posix_acl_inherit(xlator_t *this, loc_t *loc, dict_t *params, mode_t mode,
735 int32_t umask, int is_dir)
736 {
737 int ret = 0;
738 struct posix_acl *par_default = NULL;
739 struct posix_acl *acl_default = NULL;
740 struct posix_acl *acl_access = NULL;
741 struct posix_acl_ctx *ctx = NULL;
742 char *xattr_default = NULL;
743 char *xattr_access = NULL;
744 int size_default = 0;
745 int size_access = 0;
746 mode_t retmode = 0;
747 int16_t tmp_mode = 0;
748 mode_t client_umask = 0;
749
750 retmode = mode;
751 client_umask = umask;
752 ret = dict_get_int16(params, "umask", &tmp_mode);
753 if (ret == 0) {
754 client_umask = (mode_t)tmp_mode;
755 dict_del(params, "umask");
756 ret = dict_get_int16(params, "mode", &tmp_mode);
757 if (ret == 0) {
758 retmode = (mode_t)tmp_mode;
759 dict_del(params, "mode");
760 } else {
761 gf_log(this->name, GF_LOG_ERROR,
762 "client sent umask, but not the original mode");
763 }
764 }
765
766 ret = posix_acl_get(loc->parent, this, NULL, &par_default);
767
768 if (!par_default)
769 goto out;
770
771 ctx = posix_acl_ctx_new(loc->inode, this);
772
773 acl_access = posix_acl_dup(this, par_default);
774 if (!acl_access)
775 goto out;
776
777 client_umask = 0; // No umask if we inherit an ACL
778 retmode = posix_acl_inherit_mode(acl_access, retmode);
779 ctx->perm = retmode;
780
781 size_access = posix_acl_to_xattr(this, acl_access, NULL, 0);
782 xattr_access = GF_CALLOC(1, size_access, gf_posix_acl_mt_char);
783 if (!xattr_access) {
784 gf_log(this->name, GF_LOG_ERROR, "out of memory");
785 ret = -1;
786 goto out;
787 }
788 posix_acl_to_xattr(this, acl_access, xattr_access, size_access);
789
790 ret = dict_set_bin(params, POSIX_ACL_ACCESS_XATTR, xattr_access,
791 size_access);
792 if (ret) {
793 gf_log(this->name, GF_LOG_ERROR, "out of memory");
794 GF_FREE(xattr_access);
795 ret = -1;
796 goto out;
797 }
798
799 if (!is_dir)
800 goto set;
801
802 acl_default = posix_acl_ref(this, par_default);
803
804 size_default = posix_acl_to_xattr(this, acl_default, NULL, 0);
805 xattr_default = GF_CALLOC(1, size_default, gf_posix_acl_mt_char);
806 if (!xattr_default) {
807 gf_log(this->name, GF_LOG_ERROR, "out of memory");
808 ret = -1;
809 goto out;
810 }
811 posix_acl_to_xattr(this, acl_default, xattr_default, size_default);
812
813 ret = dict_set_bin(params, POSIX_ACL_DEFAULT_XATTR, xattr_default,
814 size_default);
815 if (ret) {
816 gf_log(this->name, GF_LOG_ERROR, "out of memory");
817 GF_FREE(xattr_default);
818 ret = -1;
819 goto out;
820 }
821
822 set:
823 ret = posix_acl_set(loc->inode, this, acl_access, acl_default);
824 if (ret != 0)
825 goto out;
826
827 out:
828 retmode &= ~client_umask;
829
830 if (par_default)
831 posix_acl_unref(this, par_default);
832 if (acl_access)
833 posix_acl_unref(this, acl_access);
834 if (acl_default)
835 posix_acl_unref(this, acl_default);
836
837 return retmode;
838 }
839
840 mode_t
841 posix_acl_inherit_dir(xlator_t *this, loc_t *loc, dict_t *params, mode_t mode,
842 int32_t umask)
843 {
844 mode_t retmode = 0;
845
846 retmode = posix_acl_inherit(this, loc, params, mode, umask, 1);
847
848 return retmode;
849 }
850
851 mode_t
852 posix_acl_inherit_file(xlator_t *this, loc_t *loc, dict_t *params, mode_t mode,
853 int32_t umask)
854 {
855 mode_t retmode = 0;
856
857 retmode = posix_acl_inherit(this, loc, params, mode, umask, 0);
858
859 return retmode;
860 }
861
862 int
863 posix_acl_ctx_update(inode_t *inode, xlator_t *this, struct iatt *buf,
864 glusterfs_fop_t fop)
865 {
866 struct posix_acl_ctx *ctx = NULL;
867 struct posix_acl *acl = NULL;
868 struct posix_ace *ace = NULL;
869 struct posix_ace *mask_ce = NULL;
870 struct posix_ace *group_ce = NULL;
871 int ret = 0;
872 int i = 0;
873
874 if (!buf || !buf->ia_ctime) {
875 /* No need to update ctx if buf is empty */
876 gf_log_callingfn(this->name, GF_LOG_DEBUG, "iatt struct is empty (%d)",
877 fop);
878 goto out;
879 }
880
881 LOCK(&inode->lock);
882 {
883 ctx = __posix_acl_ctx_get(inode, this, _gf_true);
884 if (!ctx) {
885 ret = -1;
886 goto unlock;
887 }
888
889 ctx->uid = buf->ia_uid;
890 ctx->gid = buf->ia_gid;
891 ctx->perm = st_mode_from_ia(buf->ia_prot, buf->ia_type);
892 ctx->fop = fop;
893
894 acl = ctx->acl_access;
895 if (!_does_acl_exist(acl))
896 goto unlock;
897
898 /* This is an extended ACL (not minimal acl). In case we
899 are only refreshing from iatt and not ACL xattrs (for
900 e.g. from postattributes of setattr() call, we need to
901 update the corresponding ACEs as well.
902 */
903 ace = acl->entries;
904 for (i = 0; i < acl->count; i++) {
905 switch (ace->tag) {
906 case POSIX_ACL_USER_OBJ:
907 ace->perm = (ctx->perm & S_IRWXU) >> 6;
908 break;
909 case POSIX_ACL_USER:
910 case POSIX_ACL_GROUP:
911 break;
912 case POSIX_ACL_GROUP_OBJ:
913 group_ce = ace;
914 break;
915 case POSIX_ACL_MASK:
916 mask_ce = ace;
917 break;
918 case POSIX_ACL_OTHER:
919 ace->perm = (ctx->perm & S_IRWXO);
920 break;
921 }
922 ace++;
923 }
924
925 if (mask_ce)
926 mask_ce->perm = (ctx->perm & S_IRWXG) >> 3;
927 else if (group_ce)
928 group_ce->perm = (ctx->perm & S_IRWXG) >> 3;
929 else
930 ret = -1;
931 }
932 unlock:
933 UNLOCK(&inode->lock);
934 out:
935 return ret;
936 }
937
938 int
939 posix_acl_lookup_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
940 int op_ret, int op_errno, inode_t *inode, struct iatt *buf,
941 dict_t *xattr, struct iatt *postparent)
942 {
943 struct posix_acl *acl_access = NULL;
944 struct posix_acl *acl_default = NULL;
945 struct posix_acl *old_access = NULL;
946 struct posix_acl *old_default = NULL;
947 struct posix_acl_ctx *ctx = NULL;
948 data_t *data = NULL;
949 int ret = 0;
950 dict_t *my_xattr = NULL;
951
952 if (op_ret != 0)
953 goto unwind;
954
955 ctx = posix_acl_ctx_new(inode, this);
956 if (!ctx) {
957 op_ret = -1;
958 op_errno = ENOMEM;
959 goto unwind;
960 }
961
962 ret = posix_acl_get(inode, this, &old_access, &old_default);
963
964 if (xattr == NULL)
965 goto acl_set;
966
967 data = dict_get(xattr, POSIX_ACL_ACCESS_XATTR);
968 if (!data)
969 goto acl_default;
970
971 if (old_access &&
972 posix_acl_matches_xattr(this, old_access, data->data, data->len)) {
973 acl_access = posix_acl_ref(this, old_access);
974 } else {
975 acl_access = posix_acl_from_xattr(this, data->data, data->len);
976 }
977
978 acl_default:
979 data = dict_get(xattr, POSIX_ACL_DEFAULT_XATTR);
980 if (!data)
981 goto acl_set;
982
983 if (old_default &&
984 posix_acl_matches_xattr(this, old_default, data->data, data->len)) {
985 acl_default = posix_acl_ref(this, old_default);
986 } else {
987 acl_default = posix_acl_from_xattr(this, data->data, data->len);
988 }
989
990 acl_set:
991 posix_acl_ctx_update(inode, this, buf, GF_FOP_LOOKUP);
992
993 ret = posix_acl_set(inode, this, acl_access, acl_default);
994 if (ret)
995 gf_log(this->name, GF_LOG_WARNING, "failed to set ACL in context");
996 unwind:
997 my_xattr = frame->local;
998 frame->local = NULL;
999 STACK_UNWIND_STRICT(lookup, frame, op_ret, op_errno, inode, buf, xattr,
1000 postparent);
1001
1002 if (acl_access)
1003 posix_acl_unref(this, acl_access);
1004 if (acl_default)
1005 posix_acl_unref(this, acl_default);
1006 if (old_access)
1007 posix_acl_unref(this, old_access);
1008 if (old_default)
1009 posix_acl_unref(this, old_default);
1010 if (my_xattr)
1011 dict_unref(my_xattr);
1012
1013 return 0;
1014 }
1015
1016 int
1017 posix_acl_lookup(call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xattr)
1018 {
1019 int ret = 0;
1020 dict_t *my_xattr = NULL;
1021
1022 if (!loc->parent)
1023 /* lookup of / is always permitted */
1024 goto green;
1025
1026 if (acl_permits(frame, loc->parent, POSIX_ACL_EXECUTE))
1027 goto green;
1028 else
1029 goto red;
1030
1031 green:
1032 if (xattr) {
1033 my_xattr = dict_ref(xattr);
1034 } else {
1035 my_xattr = dict_new();
1036 }
1037
1038 ret = dict_set_int8(my_xattr, POSIX_ACL_ACCESS_XATTR, 0);
1039 if (ret)
1040 gf_log(this->name, GF_LOG_WARNING, "failed to set key %s",
1041 POSIX_ACL_ACCESS_XATTR);
1042
1043 ret = dict_set_int8(my_xattr, POSIX_ACL_DEFAULT_XATTR, 0);
1044 if (ret)
1045 gf_log(this->name, GF_LOG_WARNING, "failed to set key %s",
1046 POSIX_ACL_DEFAULT_XATTR);
1047
1048 frame->local = my_xattr;
1049 STACK_WIND(frame, posix_acl_lookup_cbk, FIRST_CHILD(this),
1050 FIRST_CHILD(this)->fops->lookup, loc, my_xattr);
1051 return 0;
1052 red:
1053 STACK_UNWIND_STRICT(lookup, frame, -1, EACCES, NULL, NULL, NULL, NULL);
1054
1055 return 0;
1056 }
1057
1058 int
1059 posix_acl_access(call_frame_t *frame, xlator_t *this, loc_t *loc, int mask,
1060 dict_t *xdata)
1061 {
1062 int op_ret = 0;
1063 int op_errno = 0;
1064 int perm = 0;
1065 int mode = 0;
1066 int is_fuse_call = 0;
1067
1068 is_fuse_call = __is_fuse_call(frame);
1069
1070 if (mask & R_OK)
1071 perm |= POSIX_ACL_READ;
1072 if (mask & W_OK)
1073 perm |= POSIX_ACL_WRITE;
1074 if (mask & X_OK)
1075 perm |= POSIX_ACL_EXECUTE;
1076 if (!mask) {
1077 goto unwind;
1078 }
1079 if (!perm) {
1080 op_ret = -1;
1081 op_errno = EINVAL;
1082 goto unwind;
1083 }
1084
1085 if (is_fuse_call) {
1086 mode = acl_permits(frame, loc->inode, perm);
1087 if (mode) {
1088 op_ret = 0;
1089 op_errno = 0;
1090 } else {
1091 op_ret = -1;
1092 op_errno = EACCES;
1093 }
1094 } else {
1095 if (perm & POSIX_ACL_READ) {
1096 if (acl_permits(frame, loc->inode, POSIX_ACL_READ))
1097 mode |= POSIX_ACL_READ;
1098 }
1099
1100 if (perm & POSIX_ACL_WRITE) {
1101 if (acl_permits(frame, loc->inode, POSIX_ACL_WRITE))
1102 mode |= POSIX_ACL_WRITE;
1103 }
1104
1105 if (perm & POSIX_ACL_EXECUTE) {
1106 if (acl_permits(frame, loc->inode, POSIX_ACL_EXECUTE))
1107 mode |= POSIX_ACL_EXECUTE;
1108 }
1109 }
1110
1111 unwind:
1112 if (is_fuse_call)
1113 STACK_UNWIND_STRICT(access, frame, op_ret, op_errno, NULL);
1114 else
1115 STACK_UNWIND_STRICT(access, frame, 0, mode, NULL);
1116 return 0;
1117 }
1118
1119 int
1120 posix_acl_truncate(call_frame_t *frame, xlator_t *this, loc_t *loc, off_t off,
1121 dict_t *xdata)
1122 {
1123 struct posix_acl_ctx *ctx = NULL;
1124
1125 if (acl_permits(frame, loc->inode, POSIX_ACL_WRITE))
1126 goto green;
1127 /* NFS does a truncate through SETATTR, the owner does not need write
1128 * permissions for this. Group permissions and root are checked above.
1129 */
1130 else if (frame->root->pid == NFS_PID) {
1131 ctx = posix_acl_ctx_get(loc->inode, frame->this);
1132
1133 if (ctx && frame_is_user(frame, ctx->uid))
1134 goto green;
1135 }
1136
1137 /* fail by default */
1138 STACK_UNWIND_STRICT(truncate, frame, -1, EACCES, NULL, NULL, NULL);
1139 return 0;
1140
1141 green:
1142 STACK_WIND(frame, default_truncate_cbk, FIRST_CHILD(this),
1143 FIRST_CHILD(this)->fops->truncate, loc, off, xdata);
1144 return 0;
1145 }
1146
1147 int
1148 posix_acl_open(call_frame_t *frame, xlator_t *this, loc_t *loc, int flags,
1149 fd_t *fd, dict_t *xdata)
1150 {
1151 int perm = 0;
1152
1153 switch (flags & O_ACCMODE) {
1154 case O_RDONLY:
1155 perm = POSIX_ACL_READ;
1156
1157 /* If O_FMODE_EXEC is present, its good enough
1158 to have '--x' perm, and its not covered in
1159 O_ACCMODE bits */
1160 if (flags & O_FMODE_EXEC)
1161 perm = POSIX_ACL_EXECUTE;
1162
1163 break;
1164 case O_WRONLY:
1165 perm = POSIX_ACL_WRITE;
1166 break;
1167 case O_RDWR:
1168 perm = POSIX_ACL_READ | POSIX_ACL_WRITE;
1169 break;
1170 }
1171
1172 if (flags & (O_TRUNC | O_APPEND))
1173 perm |= POSIX_ACL_WRITE;
1174
1175 if (acl_permits(frame, loc->inode, perm))
1176 goto green;
1177 else
1178 goto red;
1179 green:
1180 STACK_WIND(frame, default_open_cbk, FIRST_CHILD(this),
1181 FIRST_CHILD(this)->fops->open, loc, flags, fd, xdata);
1182 return 0;
1183 red:
1184 STACK_UNWIND_STRICT(open, frame, -1, EACCES, NULL, NULL);
1185 return 0;
1186 }
1187
1188 int
1189 posix_acl_readv(call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size,
1190 off_t offset, uint32_t flags, dict_t *xdata)
1191 {
1192 if (__is_fuse_call(frame))
1193 goto green;
1194
1195 if (acl_permits(frame, fd->inode, POSIX_ACL_READ))
1196 goto green;
1197 else
1198 goto red;
1199
1200 green:
1201 STACK_WIND(frame, default_readv_cbk, FIRST_CHILD(this),
1202 FIRST_CHILD(this)->fops->readv, fd, size, offset, flags, xdata);
1203 return 0;
1204 red:
1205 STACK_UNWIND_STRICT(readv, frame, -1, EACCES, NULL, 0, NULL, NULL, NULL);
1206 return 0;
1207 }
1208
1209 int
1210 posix_acl_writev(call_frame_t *frame, xlator_t *this, fd_t *fd,
1211 struct iovec *vector, int count, off_t offset, uint32_t flags,
1212 struct iobref *iobref, dict_t *xdata)
1213 {
1214 if (__is_fuse_call(frame))
1215 goto green;
1216
1217 if (acl_permits(frame, fd->inode, POSIX_ACL_WRITE))
1218 goto green;
1219 else
1220 goto red;
1221
1222 green:
1223 STACK_WIND(frame, default_writev_cbk, FIRST_CHILD(this),
1224 FIRST_CHILD(this)->fops->writev, fd, vector, count, offset,
1225 flags, iobref, xdata);
1226 return 0;
1227 red:
1228 STACK_UNWIND_STRICT(writev, frame, -1, EACCES, NULL, NULL, NULL);
1229 return 0;
1230 }
1231
1232 int
1233 posix_acl_ftruncate(call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset,
1234 dict_t *xdata)
1235 {
1236 if (__is_fuse_call(frame))
1237 goto green;
1238
1239 if (acl_permits(frame, fd->inode, POSIX_ACL_WRITE))
1240 goto green;
1241 else
1242 goto red;
1243
1244 green:
1245 STACK_WIND(frame, default_ftruncate_cbk, FIRST_CHILD(this),
1246 FIRST_CHILD(this)->fops->ftruncate, fd, offset, xdata);
1247 return 0;
1248 red:
1249 STACK_UNWIND_STRICT(ftruncate, frame, -1, EACCES, NULL, NULL, NULL);
1250 return 0;
1251 }
1252
1253 int
1254 posix_acl_opendir(call_frame_t *frame, xlator_t *this, loc_t *loc, fd_t *fd,
1255 dict_t *xdata)
1256 {
1257 if (acl_permits(frame, loc->inode, POSIX_ACL_READ))
1258 goto green;
1259 else
1260 goto red;
1261 green:
1262 STACK_WIND(frame, default_opendir_cbk, FIRST_CHILD(this),
1263 FIRST_CHILD(this)->fops->opendir, loc, fd, xdata);
1264 return 0;
1265 red:
1266 STACK_UNWIND_STRICT(opendir, frame, -1, EACCES, NULL, NULL);
1267 return 0;
1268 }
1269
1270 int
1271 posix_acl_mkdir_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
1272 int op_ret, int op_errno, inode_t *inode, struct iatt *buf,
1273 struct iatt *preparent, struct iatt *postparent,
1274 dict_t *xdata)
1275 {
1276 if (op_ret != 0)
1277 goto unwind;
1278
1279 posix_acl_ctx_update(inode, this, buf, GF_FOP_MKDIR);
1280
1281 unwind:
1282 STACK_UNWIND_STRICT(mkdir, frame, op_ret, op_errno, inode, buf, preparent,
1283 postparent, xdata);
1284 return 0;
1285 }
1286
1287 int
1288 posix_acl_mkdir(call_frame_t *frame, xlator_t *this, loc_t *loc, mode_t mode,
1289 mode_t umask, dict_t *xdata)
1290 {
1291 mode_t newmode = 0;
1292
1293 newmode = mode;
1294 if (acl_permits(frame, loc->parent, POSIX_ACL_WRITE | POSIX_ACL_EXECUTE))
1295 goto green;
1296 else
1297 goto red;
1298 green:
1299 newmode = posix_acl_inherit_dir(this, loc, xdata, mode, umask);
1300
1301 STACK_WIND(frame, posix_acl_mkdir_cbk, FIRST_CHILD(this),
1302 FIRST_CHILD(this)->fops->mkdir, loc, newmode, umask, xdata);
1303 return 0;
1304 red:
1305 STACK_UNWIND_STRICT(mkdir, frame, -1, EACCES, NULL, NULL, NULL, NULL, NULL);
1306 return 0;
1307 }
1308
1309 int
1310 posix_acl_mknod_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
1311 int op_ret, int op_errno, inode_t *inode, struct iatt *buf,
1312 struct iatt *preparent, struct iatt *postparent,
1313 dict_t *xdata)
1314 {
1315 if (op_ret != 0)
1316 goto unwind;
1317
1318 posix_acl_ctx_update(inode, this, buf, GF_FOP_MKNOD);
1319
1320 unwind:
1321 STACK_UNWIND_STRICT(mknod, frame, op_ret, op_errno, inode, buf, preparent,
1322 postparent, xdata);
1323 return 0;
1324 }
1325
1326 int
1327 posix_acl_mknod(call_frame_t *frame, xlator_t *this, loc_t *loc, mode_t mode,
1328 dev_t rdev, mode_t umask, dict_t *xdata)
1329 {
1330 mode_t newmode = 0;
1331
1332 newmode = mode;
1333 if (acl_permits(frame, loc->parent, POSIX_ACL_WRITE | POSIX_ACL_EXECUTE))
1334 goto green;
1335 else
1336 goto red;
1337 green:
1338 newmode = posix_acl_inherit_file(this, loc, xdata, mode, umask);
1339
1340 STACK_WIND(frame, posix_acl_mknod_cbk, FIRST_CHILD(this),
1341 FIRST_CHILD(this)->fops->mknod, loc, newmode, rdev, umask,
1342 xdata);
1343 return 0;
1344 red:
1345 STACK_UNWIND_STRICT(mknod, frame, -1, EACCES, NULL, NULL, NULL, NULL, NULL);
1346 return 0;
1347 }
1348
1349 int
1350 posix_acl_create_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
1351 int op_ret, int op_errno, fd_t *fd, inode_t *inode,
1352 struct iatt *buf, struct iatt *preparent,
1353 struct iatt *postparent, dict_t *xdata)
1354 {
1355 if (op_ret != 0)
1356 goto unwind;
1357
1358 posix_acl_ctx_update(inode, this, buf, GF_FOP_CREATE);
1359
1360 unwind:
1361 STACK_UNWIND_STRICT(create, frame, op_ret, op_errno, fd, inode, buf,
1362 preparent, postparent, xdata);
1363 return 0;
1364 }
1365
1366 int
1367 posix_acl_create(call_frame_t *frame, xlator_t *this, loc_t *loc, int flags,
1368 mode_t mode, mode_t umask, fd_t *fd, dict_t *xdata)
1369 {
1370 mode_t newmode = 0;
1371
1372 newmode = mode;
1373 if (acl_permits(frame, loc->parent, POSIX_ACL_WRITE | POSIX_ACL_EXECUTE))
1374 goto green;
1375 else
1376 goto red;
1377 green:
1378 newmode = posix_acl_inherit_file(this, loc, xdata, mode, umask);
1379
1380 STACK_WIND(frame, posix_acl_create_cbk, FIRST_CHILD(this),
1381 FIRST_CHILD(this)->fops->create, loc, flags, newmode, umask, fd,
1382 xdata);
1383 return 0;
1384 red:
1385 STACK_UNWIND_STRICT(create, frame, -1, EACCES, NULL, NULL, NULL, NULL, NULL,
1386 NULL);
1387 return 0;
1388 }
1389
1390 int
1391 posix_acl_symlink_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
1392 int op_ret, int op_errno, inode_t *inode,
1393 struct iatt *buf, struct iatt *preparent,
1394 struct iatt *postparent, dict_t *xdata)
1395 {
1396 if (op_ret != 0)
1397 goto unwind;
1398
1399 posix_acl_ctx_update(inode, this, buf, GF_FOP_SYMLINK);
1400
1401 unwind:
1402 STACK_UNWIND_STRICT(symlink, frame, op_ret, op_errno, inode, buf, preparent,
1403 postparent, xdata);
1404 return 0;
1405 }
1406
1407 int
1408 posix_acl_symlink(call_frame_t *frame, xlator_t *this, const char *linkname,
1409 loc_t *loc, mode_t umask, dict_t *xdata)
1410 {
1411 if (acl_permits(frame, loc->parent, POSIX_ACL_WRITE | POSIX_ACL_EXECUTE))
1412 goto green;
1413 else
1414 goto red;
1415 green:
1416 STACK_WIND(frame, posix_acl_symlink_cbk, FIRST_CHILD(this),
1417 FIRST_CHILD(this)->fops->symlink, linkname, loc, umask, xdata);
1418 return 0;
1419 red:
1420 STACK_UNWIND_STRICT(symlink, frame, -1, EACCES, NULL, NULL, NULL, NULL,
1421 NULL);
1422 return 0;
1423 }
1424
1425 int
1426 posix_acl_unlink(call_frame_t *frame, xlator_t *this, loc_t *loc, int xflag,
1427 dict_t *xdata)
1428 {
1429 if (!sticky_permits(frame, loc->parent, loc->inode))
1430 goto red;
1431
1432 if (acl_permits(frame, loc->parent, POSIX_ACL_WRITE | POSIX_ACL_EXECUTE))
1433 goto green;
1434 else
1435 goto red;
1436 green:
1437 STACK_WIND(frame, default_unlink_cbk, FIRST_CHILD(this),
1438 FIRST_CHILD(this)->fops->unlink, loc, xflag, xdata);
1439 return 0;
1440 red:
1441 STACK_UNWIND_STRICT(unlink, frame, -1, EACCES, NULL, NULL, NULL);
1442 return 0;
1443 }
1444
1445 int
1446 posix_acl_rmdir(call_frame_t *frame, xlator_t *this, loc_t *loc, int flags,
1447 dict_t *xdata)
1448 {
1449 if (!sticky_permits(frame, loc->parent, loc->inode))
1450 goto red;
1451
1452 if (acl_permits(frame, loc->parent, POSIX_ACL_WRITE | POSIX_ACL_EXECUTE))
1453 goto green;
1454 else
1455 goto red;
1456 green:
1457 STACK_WIND(frame, default_rmdir_cbk, FIRST_CHILD(this),
1458 FIRST_CHILD(this)->fops->rmdir, loc, flags, xdata);
1459 return 0;
1460 red:
1461 STACK_UNWIND_STRICT(rmdir, frame, -1, EACCES, NULL, NULL, NULL);
1462 return 0;
1463 }
1464
1465 int
1466 posix_acl_rename(call_frame_t *frame, xlator_t *this, loc_t *old, loc_t *new,
1467 dict_t *xdata)
1468 {
1469 if (!acl_permits(frame, old->parent, POSIX_ACL_WRITE))
1470 goto red;
1471
1472 if (!acl_permits(frame, new->parent, POSIX_ACL_WRITE))
1473 goto red;
1474
1475 if (!sticky_permits(frame, old->parent, old->inode))
1476 goto red;
1477
1478 if (new->inode) {
1479 if (!sticky_permits(frame, new->parent, new->inode))
1480 goto red;
1481 }
1482
1483 STACK_WIND(frame, default_rename_cbk, FIRST_CHILD(this),
1484 FIRST_CHILD(this)->fops->rename, old, new, xdata);
1485 return 0;
1486 red:
1487 STACK_UNWIND_STRICT(rename, frame, -1, EACCES, NULL, NULL, NULL, NULL, NULL,
1488 NULL);
1489 return 0;
1490 }
1491
1492 int
1493 posix_acl_link(call_frame_t *frame, xlator_t *this, loc_t *old, loc_t *new,
1494 dict_t *xdata)
1495 {
1496 struct posix_acl_ctx *ctx = NULL;
1497 int op_errno = 0;
1498
1499 ctx = posix_acl_ctx_get(old->inode, this);
1500 if (!ctx) {
1501 op_errno = EIO;
1502 goto red;
1503 }
1504
1505 if (!acl_permits(frame, new->parent, POSIX_ACL_WRITE)) {
1506 op_errno = EACCES;
1507 goto red;
1508 }
1509
1510 if (!sticky_permits(frame, new->parent, new->inode)) {
1511 op_errno = EACCES;
1512 goto red;
1513 }
1514
1515 STACK_WIND(frame, default_link_cbk, FIRST_CHILD(this),
1516 FIRST_CHILD(this)->fops->link, old, new, xdata);
1517 return 0;
1518 red:
1519 STACK_UNWIND_STRICT(link, frame, -1, op_errno, NULL, NULL, NULL, NULL,
1520 NULL);
1521
1522 return 0;
1523 }
1524
1525 int
1526 posix_acl_readdir(call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size,
1527 off_t offset, dict_t *xdata)
1528 {
1529 if (acl_permits(frame, fd->inode, POSIX_ACL_READ))
1530 goto green;
1531 else
1532 goto red;
1533 green:
1534 STACK_WIND(frame, default_readdir_cbk, FIRST_CHILD(this),
1535 FIRST_CHILD(this)->fops->readdir, fd, size, offset, xdata);
1536 return 0;
1537 red:
1538 STACK_UNWIND_STRICT(readdir, frame, -1, EACCES, NULL, NULL);
1539
1540 return 0;
1541 }
1542
1543 int
1544 posix_acl_readdirp_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
1545 int op_ret, int op_errno, gf_dirent_t *entries,
1546 dict_t *xdata)
1547 {
1548 gf_dirent_t *entry = NULL;
1549 struct posix_acl *acl_access = NULL;
1550 struct posix_acl *acl_default = NULL;
1551 struct posix_acl_ctx *ctx = NULL;
1552 data_t *data = NULL;
1553 int ret = 0;
1554
1555 if (op_ret <= 0)
1556 goto unwind;
1557
1558 list_for_each_entry(entry, &entries->list, list)
1559 {
1560 /* Update the inode ctx */
1561 if (!entry->dict || !entry->inode)
1562 continue;
1563
1564 ctx = posix_acl_ctx_new(entry->inode, this);
1565 if (!ctx) {
1566 op_ret = -1;
1567 op_errno = ENOMEM;
1568 goto unwind;
1569 }
1570
1571 ret = posix_acl_get(entry->inode, this, &acl_access, &acl_default);
1572
1573 data = dict_get(entry->dict, POSIX_ACL_ACCESS_XATTR);
1574 if (!data)
1575 goto acl_default;
1576
1577 if (acl_access &&
1578 posix_acl_matches_xattr(this, acl_access, data->data, data->len))
1579 goto acl_default;
1580
1581 if (acl_access)
1582 posix_acl_unref(this, acl_access);
1583
1584 acl_access = posix_acl_from_xattr(this, data->data, data->len);
1585
1586 acl_default:
1587 data = dict_get(entry->dict, POSIX_ACL_DEFAULT_XATTR);
1588 if (!data)
1589 goto acl_set;
1590
1591 if (acl_default &&
1592 posix_acl_matches_xattr(this, acl_default, data->data, data->len))
1593 goto acl_set;
1594
1595 if (acl_default)
1596 posix_acl_unref(this, acl_default);
1597
1598 acl_default = posix_acl_from_xattr(this, data->data, data->len);
1599
1600 acl_set:
1601 posix_acl_ctx_update(entry->inode, this, &entry->d_stat,
1602 GF_FOP_READDIRP);
1603
1604 ret = posix_acl_set(entry->inode, this, acl_access, acl_default);
1605 if (ret)
1606 gf_log(this->name, GF_LOG_WARNING, "failed to set ACL in context");
1607
1608 if (acl_access)
1609 posix_acl_unref(this, acl_access);
1610 if (acl_default)
1611 posix_acl_unref(this, acl_default);
1612 }
1613
1614 unwind:
1615 STACK_UNWIND_STRICT(readdirp, frame, op_ret, op_errno, entries, xdata);
1616 return 0;
1617 }
1618
1619 int
1620 posix_acl_readdirp(call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size,
1621 off_t offset, dict_t *dict)
1622 {
1623 int ret = 0;
1624 dict_t *alloc_dict = NULL;
1625
1626 if (acl_permits(frame, fd->inode, POSIX_ACL_READ))
1627 goto green;
1628 else
1629 goto red;
1630 green:
1631 if (!dict)
1632 dict = alloc_dict = dict_new();
1633
1634 if (dict) {
1635 ret = dict_set_int8(dict, POSIX_ACL_ACCESS_XATTR, 0);
1636 if (ret)
1637 gf_log(this->name, GF_LOG_WARNING, "failed to set key %s",
1638 POSIX_ACL_ACCESS_XATTR);
1639
1640 ret = dict_set_int8(dict, POSIX_ACL_DEFAULT_XATTR, 0);
1641 if (ret)
1642 gf_log(this->name, GF_LOG_WARNING, "failed to set key %s",
1643 POSIX_ACL_DEFAULT_XATTR);
1644 }
1645
1646 STACK_WIND(frame, posix_acl_readdirp_cbk, FIRST_CHILD(this),
1647 FIRST_CHILD(this)->fops->readdirp, fd, size, offset, dict);
1648
1649 if (alloc_dict)
1650 dict_unref(alloc_dict);
1651 return 0;
1652 red:
1653 STACK_UNWIND_STRICT(readdirp, frame, -1, EACCES, NULL, NULL);
1654
1655 return 0;
1656 }
1657
1658 int
1659 setattr_scrutiny(call_frame_t *frame, inode_t *inode, struct iatt *buf,
1660 int valid)
1661 {
1662 struct posix_acl_ctx *ctx = NULL;
1663
1664 if (frame_is_super_user(frame))
1665 return 0;
1666
1667 ctx = posix_acl_ctx_get(inode, frame->this);
1668 if (!ctx)
1669 return EIO;
1670
1671 if (valid & GF_SET_ATTR_MODE) {
1672 /*
1673 The effective UID of the calling process must match the owner of
1674 the file, or the process must be privileged
1675 */
1676 if (!frame_is_user(frame, ctx->uid))
1677 return EPERM;
1678 /*
1679 If the calling process is not privileged (Linux: does not have
1680 the CAP_FSETID capability), and the group of the file does not
1681 match the effective group ID of the process or one of its
1682 supplementary group IDs, the S_ISGID bit will be turned off, but
1683 this will not cause an error to be returned.
1684
1685 */
1686 if (!frame_in_group(frame, ctx->gid))
1687 buf->ia_prot.sgid = 0;
1688 }
1689
1690 if (valid & (GF_SET_ATTR_ATIME | GF_SET_ATTR_MTIME)) {
1691 /*
1692 Changing timestamps is permitted when: either the process has
1693 appropri? ate privileges, or the effective user ID equals the
1694 user ID of the file, or times is NULL and the process has write
1695 permission for the file.
1696 */
1697 if (!frame_is_user(frame, ctx->uid) &&
1698 !acl_permits(frame, inode, POSIX_ACL_WRITE))
1699 return EACCES;
1700 }
1701
1702 if (valid & GF_SET_ATTR_UID) {
1703 if ((!frame_is_super_user(frame)) && (buf->ia_uid != ctx->uid))
1704 return EPERM;
1705 }
1706
1707 if (valid & GF_SET_ATTR_GID) {
1708 if (!frame_is_user(frame, ctx->uid))
1709 return EPERM;
1710 if (!frame_in_group(frame, buf->ia_gid))
1711 return EPERM;
1712 }
1713
1714 return 0;
1715 }
1716
1717 int
1718 posix_acl_setattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
1719 int op_ret, int op_errno, struct iatt *prebuf,
1720 struct iatt *postbuf, dict_t *xdata)
1721 {
1722 inode_t *inode = NULL;
1723
1724 inode = frame->local;
1725 frame->local = NULL;
1726
1727 if (op_ret != 0)
1728 goto unwind;
1729
1730 posix_acl_ctx_update(inode, this, postbuf, GF_FOP_SETATTR);
1731
1732 unwind:
1733 STACK_UNWIND_STRICT(setattr, frame, op_ret, op_errno, prebuf, postbuf,
1734 xdata);
1735 return 0;
1736 }
1737
1738 int
1739 posix_acl_setattr(call_frame_t *frame, xlator_t *this, loc_t *loc,
1740 struct iatt *buf, int valid, dict_t *xdata)
1741 {
1742 int op_errno = 0;
1743
1744 op_errno = setattr_scrutiny(frame, loc->inode, buf, valid);
1745
1746 if (op_errno)
1747 goto red;
1748
1749 frame->local = loc->inode;
1750
1751 STACK_WIND(frame, posix_acl_setattr_cbk, FIRST_CHILD(this),
1752 FIRST_CHILD(this)->fops->setattr, loc, buf, valid, xdata);
1753 return 0;
1754 red:
1755 STACK_UNWIND_STRICT(setattr, frame, -1, op_errno, NULL, NULL, NULL);
1756
1757 return 0;
1758 }
1759
1760 int
1761 posix_acl_fsetattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
1762 int op_ret, int op_errno, struct iatt *prebuf,
1763 struct iatt *postbuf, dict_t *xdata)
1764 {
1765 inode_t *inode = NULL;
1766
1767 inode = frame->local;
1768 frame->local = NULL;
1769
1770 if (op_ret != 0)
1771 goto unwind;
1772
1773 posix_acl_ctx_update(inode, this, postbuf, GF_FOP_FSETATTR);
1774
1775 unwind:
1776 STACK_UNWIND_STRICT(fsetattr, frame, op_ret, op_errno, prebuf, postbuf,
1777 xdata);
1778 return 0;
1779 }
1780
1781 int
1782 posix_acl_fsetattr(call_frame_t *frame, xlator_t *this, fd_t *fd,
1783 struct iatt *buf, int valid, dict_t *xdata)
1784 {
1785 int op_errno = 0;
1786
1787 op_errno = setattr_scrutiny(frame, fd->inode, buf, valid);
1788
1789 if (op_errno)
1790 goto red;
1791
1792 frame->local = fd->inode;
1793
1794 STACK_WIND(frame, posix_acl_fsetattr_cbk, FIRST_CHILD(this),
1795 FIRST_CHILD(this)->fops->fsetattr, fd, buf, valid, xdata);
1796 return 0;
1797 red:
1798 STACK_UNWIND_STRICT(fsetattr, frame, -1, EACCES, NULL, NULL, NULL);
1799
1800 return 0;
1801 }
1802
1803 int
1804 setxattr_scrutiny(call_frame_t *frame, inode_t *inode, dict_t *xattr)
1805 {
1806 struct posix_acl_ctx *ctx = NULL;
1807 int found = 0;
1808
1809 if (frame_is_super_user(frame))
1810 return 0;
1811
1812 ctx = posix_acl_ctx_get(inode, frame->this);
1813 if (!ctx)
1814 return EIO;
1815
1816 if (dict_get(xattr, POSIX_ACL_ACCESS_XATTR) ||
1817 dict_get(xattr, POSIX_ACL_DEFAULT_XATTR) ||
1818 dict_get(xattr, GF_POSIX_ACL_ACCESS) ||
1819 dict_get(xattr, GF_POSIX_ACL_DEFAULT)) {
1820 found = 1;
1821 if (!frame_is_user(frame, ctx->uid))
1822 return EPERM;
1823 }
1824
1825 if (!found && !acl_permits(frame, inode, POSIX_ACL_WRITE))
1826 return EACCES;
1827
1828 return 0;
1829 }
1830
1831 struct posix_acl *
1832 posix_acl_xattr_update(xlator_t *this, inode_t *inode, dict_t *xattr,
1833 char *name, struct posix_acl *old)
1834 {
1835 struct posix_acl *acl = NULL;
1836 data_t *data = NULL;
1837
1838 data = dict_get(xattr, name);
1839 if (data) {
1840 acl = posix_acl_from_xattr(this, data->data, data->len);
1841 }
1842
1843 if (!acl && old)
1844 acl = posix_acl_ref(this, old);
1845
1846 return acl;
1847 }
1848
1849 int
1850 posix_acl_setxattr_update(xlator_t *this, inode_t *inode, dict_t *xattr)
1851 {
1852 struct posix_acl *acl_access = NULL;
1853 struct posix_acl *acl_default = NULL;
1854 struct posix_acl *old_access = NULL;
1855 struct posix_acl *old_default = NULL;
1856 struct posix_acl_ctx *ctx = NULL;
1857 int ret = 0;
1858
1859 ctx = posix_acl_ctx_get(inode, this);
1860 if (!ctx)
1861 return -1;
1862
1863 ret = posix_acl_get(inode, this, &old_access, &old_default);
1864
1865 acl_access = posix_acl_xattr_update(this, inode, xattr,
1866 POSIX_ACL_ACCESS_XATTR, old_access);
1867
1868 acl_default = posix_acl_xattr_update(this, inode, xattr,
1869 POSIX_ACL_DEFAULT_XATTR, old_default);
1870
1871 ret = posix_acl_set(inode, this, acl_access, acl_default);
1872
1873 if (acl_access && acl_access != old_access) {
1874 posix_acl_access_set_mode(acl_access, ctx);
1875 }
1876
1877 if (acl_access)
1878 posix_acl_unref(this, acl_access);
1879 if (acl_default)
1880 posix_acl_unref(this, acl_default);
1881 if (old_access)
1882 posix_acl_unref(this, old_access);
1883 if (old_default)
1884 posix_acl_unref(this, old_default);
1885
1886 return ret;
1887 }
1888
1889 /* *
1890 * Posix acl can be set using other xattr such as GF_POSIX_ACL_ACCESS/
1891 * GF_POSIX_ACL_DEFAULT which requires to update the context of
1892 * access-control translator
1893 */
1894 int
1895 handling_other_acl_related_xattr(xlator_t *this, inode_t *inode, dict_t *xattr)
1896 {
1897 struct posix_acl *acl = NULL;
1898 struct posix_acl_ctx *ctx = NULL;
1899 data_t *data = NULL;
1900 int ret = 0;
1901
1902 if (!this || !xattr || !inode)
1903 goto out;
1904
1905 data = dict_get(xattr, POSIX_ACL_ACCESS_XATTR);
1906 if (data) {
1907 acl = posix_acl_from_xattr(this, data->data, data->len);
1908 if (!acl) {
1909 ret = -1;
1910 goto out;
1911 }
1912
1913 ret = posix_acl_set_specific(inode, this, acl, _gf_true);
1914 if (ret)
1915 goto out;
1916
1917 ctx = posix_acl_ctx_get(inode, this);
1918 if (!ctx) {
1919 ret = -1;
1920 goto out;
1921 }
1922
1923 posix_acl_access_set_mode(acl, ctx);
1924 posix_acl_unref(this, acl);
1925 acl = NULL;
1926 }
1927
1928 data = dict_get(xattr, POSIX_ACL_DEFAULT_XATTR);
1929 if (data) {
1930 acl = posix_acl_from_xattr(this, data->data, data->len);
1931 if (!acl) {
1932 ret = -1;
1933 goto out;
1934 }
1935
1936 ret = posix_acl_set_specific(inode, this, acl, _gf_false);
1937 }
1938
1939 out:
1940 if (acl)
1941 posix_acl_unref(this, acl);
1942
1943 return ret;
1944 }
1945 int
1946 posix_acl_setxattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
1947 int op_ret, int op_errno, dict_t *xdata)
1948 {
1949 /*
1950 * Update the context of posix_acl_translator, if any of
1951 * POSIX_ACL_*_XATTR set in the call back
1952 */
1953 handling_other_acl_related_xattr(this, (inode_t *)cookie, xdata);
1954
1955 STACK_UNWIND_STRICT(setxattr, frame, op_ret, op_errno, xdata);
1956
1957 return 0;
1958 }
1959
1960 int
1961 posix_acl_setxattr(call_frame_t *frame, xlator_t *this, loc_t *loc,
1962 dict_t *xattr, int flags, dict_t *xdata)
1963 {
1964 int op_errno = 0;
1965
1966 op_errno = setxattr_scrutiny(frame, loc->inode, xattr);
1967
1968 if (op_errno != 0)
1969 goto red;
1970
1971 if (dict_get(xattr, POSIX_ACL_ACCESS_XATTR) ||
1972 dict_get(xattr, POSIX_ACL_DEFAULT_XATTR))
1973 posix_acl_setxattr_update(this, loc->inode, xattr);
1974
1975 /*
1976 * inode is required in call back function to update the context
1977 * this translator
1978 */
1979 STACK_WIND_COOKIE(frame, posix_acl_setxattr_cbk, loc->inode,
1980 FIRST_CHILD(this), FIRST_CHILD(this)->fops->setxattr, loc,
1981 xattr, flags, xdata);
1982 return 0;
1983 red:
1984 STACK_UNWIND_STRICT(setxattr, frame, -1, op_errno, NULL);
1985
1986 return 0;
1987 }
1988
1989 int
1990 posix_acl_fsetxattr(call_frame_t *frame, xlator_t *this, fd_t *fd,
1991 dict_t *xattr, int flags, dict_t *xdata)
1992 {
1993 int op_errno = 0;
1994
1995 op_errno = setxattr_scrutiny(frame, fd->inode, xattr);
1996
1997 if (op_errno != 0)
1998 goto red;
1999
2000 if (dict_get(xattr, POSIX_ACL_ACCESS_XATTR) ||
2001 dict_get(xattr, POSIX_ACL_DEFAULT_XATTR))
2002 posix_acl_setxattr_update(this, fd->inode, xattr);
2003
2004 STACK_WIND(frame, default_fsetxattr_cbk, FIRST_CHILD(this),
2005 FIRST_CHILD(this)->fops->fsetxattr, fd, xattr, flags, xdata);
2006 return 0;
2007 red:
2008 STACK_UNWIND_STRICT(fsetxattr, frame, -1, op_errno, NULL);
2009
2010 return 0;
2011 }
2012
2013 int
2014 posix_acl_getxattr(call_frame_t *frame, xlator_t *this, loc_t *loc,
2015 const char *name, dict_t *xdata)
2016 {
2017 if (allowed_xattr(name))
2018 goto green;
2019
2020 if (acl_permits(frame, loc->inode, POSIX_ACL_READ))
2021 goto green;
2022 else
2023 goto red;
2024
2025 green:
2026 STACK_WIND(frame, default_getxattr_cbk, FIRST_CHILD(this),
2027 FIRST_CHILD(this)->fops->getxattr, loc, name, xdata);
2028 return 0;
2029
2030 red:
2031 STACK_UNWIND_STRICT(getxattr, frame, -1, EACCES, NULL, NULL);
2032
2033 return 0;
2034 }
2035
2036 int
2037 posix_acl_fgetxattr(call_frame_t *frame, xlator_t *this, fd_t *fd,
2038 const char *name, dict_t *xdata)
2039 {
2040 if (allowed_xattr(name))
2041 goto green;
2042
2043 if (acl_permits(frame, fd->inode, POSIX_ACL_READ))
2044 goto green;
2045 else
2046 goto red;
2047 green:
2048 STACK_WIND(frame, default_fgetxattr_cbk, FIRST_CHILD(this),
2049 FIRST_CHILD(this)->fops->fgetxattr, fd, name, xdata);
2050 return 0;
2051 red:
2052 STACK_UNWIND_STRICT(fgetxattr, frame, -1, EACCES, NULL, NULL);
2053
2054 return 0;
2055 }
2056
2057 int
2058 posix_acl_removexattr(call_frame_t *frame, xlator_t *this, loc_t *loc,
2059 const char *name, dict_t *xdata)
2060 {
2061 struct posix_acl_ctx *ctx = NULL;
2062 int op_errno = EACCES;
2063
2064 if (frame_is_super_user(frame))
2065 goto green;
2066
2067 ctx = posix_acl_ctx_get(loc->inode, this);
2068 if (!ctx) {
2069 op_errno = EIO;
2070 goto red;
2071 }
2072
2073 if (allowed_xattr(name)) {
2074 if (!frame_is_user(frame, ctx->uid)) {
2075 op_errno = EPERM;
2076 goto red;
2077 }
2078 }
2079
2080 if (acl_permits(frame, loc->inode, POSIX_ACL_WRITE))
2081 goto green;
2082 else
2083 goto red;
2084 green:
2085 STACK_WIND(frame, default_removexattr_cbk, FIRST_CHILD(this),
2086 FIRST_CHILD(this)->fops->removexattr, loc, name, xdata);
2087 return 0;
2088 red:
2089 STACK_UNWIND_STRICT(removexattr, frame, -1, op_errno, NULL);
2090
2091 return 0;
2092 }
2093
2094 int
2095 posix_acl_forget(xlator_t *this, inode_t *inode)
2096 {
2097 struct posix_acl_ctx *ctx = NULL;
2098
2099 ctx = posix_acl_ctx_get(inode, this);
2100 if (!ctx)
2101 goto out;
2102
2103 if (ctx->acl_access)
2104 posix_acl_unref(this, ctx->acl_access);
2105
2106 if (ctx->acl_default)
2107 posix_acl_unref(this, ctx->acl_default);
2108
2109 GF_FREE(ctx);
2110 out:
2111 return 0;
2112 }
2113
2114 int
2115 reconfigure(xlator_t *this, dict_t *options)
2116 {
2117 struct posix_acl_conf *conf = NULL;
2118
2119 conf = this->private;
2120
2121 GF_OPTION_RECONF("super-uid", conf->super_uid, options, uint32, err);
2122
2123 return 0;
2124 err:
2125 return -1;
2126 }
2127
2128 int
2129 init(xlator_t *this)
2130 {
2131 struct posix_acl_conf *conf = NULL;
2132 struct posix_acl *minacl = NULL;
2133 struct posix_ace *minace = NULL;
2134
2135 conf = GF_CALLOC(1, sizeof(*conf), gf_posix_acl_mt_conf_t);
2136 if (!conf) {
2137 gf_log(this->name, GF_LOG_ERROR, "out of memory");
2138 return -1;
2139 }
2140
2141 LOCK_INIT(&conf->acl_lock);
2142
2143 this->private = conf;
2144
2145 minacl = posix_acl_new(this, 3);
2146 if (!minacl)
2147 return -1;
2148
2149 minace = minacl->entries;
2150 minace[0].tag = POSIX_ACL_USER_OBJ;
2151 minace[1].tag = POSIX_ACL_GROUP_OBJ;
2152 minace[2].tag = POSIX_ACL_OTHER;
2153
2154 conf->minimal_acl = minacl;
2155
2156 GF_OPTION_INIT("super-uid", conf->super_uid, uint32, err);
2157
2158 return 0;
2159 err:
2160 return -1;
2161 }
2162
2163 void
2164 fini(xlator_t *this)
2165 {
2166 struct posix_acl_conf *conf = NULL;
2167 struct posix_acl *minacl = NULL;
2168
2169 conf = this->private;
2170 if (!conf)
2171 return;
2172 this->private = NULL;
2173
2174 minacl = conf->minimal_acl;
2175
2176 LOCK(&conf->acl_lock);
2177 {
2178 conf->minimal_acl = NULL;
2179 }
2180 UNLOCK(&conf->acl_lock);
2181
2182 LOCK_DESTROY(&conf->acl_lock);
2183
2184 GF_FREE(minacl);
2185
2186 GF_FREE(conf);
2187
2188 return;
2189 }
2190
2191 struct xlator_fops fops = {
2192 .lookup = posix_acl_lookup,
2193 .open = posix_acl_open,
2194 #if FD_MODE_CHECK_IS_IMPLEMENTED
2195 .readv = posix_acl_readv,
2196 .writev = posix_acl_writev,
2197 .ftruncate = posix_acl_ftruncate,
2198 .fsetattr = posix_acl_fsetattr,
2199 .fsetxattr = posix_acl_fsetxattr,
2200 .fgetxattr = posix_acl_fgetxattr,
2201 #endif
2202 .access = posix_acl_access,
2203 .truncate = posix_acl_truncate,
2204 .mkdir = posix_acl_mkdir,
2205 .mknod = posix_acl_mknod,
2206 .create = posix_acl_create,
2207 .symlink = posix_acl_symlink,
2208 .unlink = posix_acl_unlink,
2209 .rmdir = posix_acl_rmdir,
2210 .rename = posix_acl_rename,
2211 .link = posix_acl_link,
2212 .opendir = posix_acl_opendir,
2213 .readdir = posix_acl_readdir,
2214 .readdirp = posix_acl_readdirp,
2215 .setattr = posix_acl_setattr,
2216 .setxattr = posix_acl_setxattr,
2217 .getxattr = posix_acl_getxattr,
2218 .removexattr = posix_acl_removexattr,
2219 };
2220
2221 struct xlator_cbks cbks = {.forget = posix_acl_forget};
2222
2223 struct volume_options options[] = {
2224 {
2225 .key = {"super-uid"},
2226 .type = GF_OPTION_TYPE_INT,
2227 .default_value = "0",
2228 .description = "UID to be treated as super user's id instead of 0",
2229 },
2230 {.key = {NULL}},
2231 };
2232
2233 xlator_api_t xlator_api = {
2234 .init = init,
2235 .fini = fini,
2236 .reconfigure = reconfigure,
2237 .mem_acct_init = mem_acct_init,
2238 .op_version = {1}, /* Present from the initial version */
2239 .fops = &fops,
2240 .cbks = &cbks,
2241 .options = options,
2242 .identifier = "access-control",
2243 .category = GF_MAINTAINED,
2244 };