10 #include <sys/types.h>
19 #define ERROR(err, fmt, ...) \
21 do_log(__FILE__, __LINE__, __FUNCTION__, (fmt), __VA_ARGS__); \
25 #define LOG(fmt, ...) \
27 do_log(__FILE__, __LINE__, __FUNCTION__, (fmt), __VA_ARGS__); \
36 static void do_log(const char *file, int line, const char *func, const char *fmt, ...)
43 len = vasprintf(&message, fmt, args);
49 printf("%s:%d(%s): %s\n", file, line, func, message);
53 static void print_acl(gpfs_acl_t *acl)
55 bool have_v4_flags = acl->acl_level == GPFS_ACL_LEVEL_V4FLAGS ? true : false;
56 int aces_offset = have_v4_flags ? sizeof(unsigned int) : 0;
57 int v4_flags = have_v4_flags ? acl->v4Level1.acl_flags : 0;
58 gpfs_ace_v4_t *ace = NULL;
61 printf("ACL: acl_level [%d] acl_version [%d] acl_type [%d] flags [%08x]\n",
62 acl->acl_level, acl->acl_version, acl->acl_type, v4_flags);
67 ace = acl->v4Level1.ace_v4;
70 for (i = 0; i < acl->acl_nace; i++, ace++) {
71 printf("%d: aceType [%d] aceFlags [%08x] aceIFlags [%08x] aceMask [%08x] aceWho [%u]\n",
72 i, ace->aceType, ace->aceFlags, ace->aceIFlags, ace->aceMask, ace->aceWho);
76 static void set_dacl_prot_fn(const char *path, gpfs_acl_t *acl, bool set)
80 if (acl->acl_level != GPFS_ACL_LEVEL_V4FLAGS) {
81 ERROR(ERR_CALL, "acl_level != GPFS_ACL_LEVEL_V4FLAGS [%d]\n", acl->acl_level);
85 acl->v4Level1.acl_flags |= ACL4_FLAG_DACL_PROTECTED;
87 acl->v4Level1.acl_flags &= ~ACL4_FLAG_DACL_PROTECTED;
90 result = gpfs_putacl(path, GPFS_PUTACL_STRUCT, acl);
92 ERROR(ERR_SYSCALL, "gpfs_getacl: %s\n", strerror(errno));
96 static void show_usage(const char *path)
98 printf("usage: %s [-dD4] PATH\n\n"
99 " -p set ACL4_FLAG_DACL_PROTECTED\n"
100 " -P remove ACL4_FLAG_DACL_PROTECTED\n"
101 " -4 don't request GPFS_ACL_LEVEL_V4FLAGS\n",
106 int main(int argc, char **argv)
108 const char *path = NULL;
109 gpfs_acl_t *acl = NULL;
112 bool set_dacl_prot = false;
113 bool remove_dacl_prot = false;
114 bool set_level_v4flags = true;
116 while ((opt = getopt(argc, argv, "pP4")) != -1) {
119 set_dacl_prot = true;
122 remove_dacl_prot = true;
125 set_level_v4flags = false;
132 if ((optind + 1) != argc) {
141 acl->acl_level = set_level_v4flags ? GPFS_ACL_LEVEL_V4FLAGS : GPFS_ACL_LEVEL_BASE;
142 acl->acl_version = 0;
145 result = gpfs_getacl(path, GPFS_GETACL_STRUCT, acl);
147 ERROR(ERR_SYSCALL, "gpfs_getacl: %s\n", strerror(errno));
150 if (acl->acl_type != GPFS_ACL_TYPE_NFS4) {
151 ERROR(ERR_CALL, "expected GPFS_ACL_TYPE_NFS4 got [%d]\n",
158 printf("Setting ACL4_FLAG_DACL_PROTECTED\n");
159 set_dacl_prot_fn(path, acl, true);
162 if (remove_dacl_prot) {
163 printf("Removing ACL4_FLAG_DACL_PROTECTED\n");
164 set_dacl_prot_fn(path, acl, false);