int main(int argc, char *argv[]) { int ret = -1; int flags = O_RDWR | O_SYNC; glfs_t *fs = NULL; glfs_fd_t *fd = NULL; char *volname = NULL; char *logfile = NULL; const char *filename = "file_tmp"; struct glfs_object *object = NULL; acl_t acl = NULL; struct stat sb; if (argc != 3) { fprintf(stderr, "Invalid argument\n"); return 1; } volname = argv[1]; logfile = argv[2]; fs = glfs_new(volname); if (!fs) VALIDATE_AND_GOTO_LABEL_ON_ERROR("glfs_new", ret, out); ret = glfs_set_volfile_server(fs, "tcp", "localhost", 24007); VALIDATE_AND_GOTO_LABEL_ON_ERROR("glfs_set_volfile_server", ret, out); ret = glfs_set_logging(fs, logfile, 7); VALIDATE_AND_GOTO_LABEL_ON_ERROR("glfs_set_logging", ret, out); ret = glfs_init(fs); VALIDATE_AND_GOTO_LABEL_ON_ERROR("glfs_init", ret, out); fd = glfs_creat(fs, filename, flags, 0044); if (fd == NULL) { ret = -1; VALIDATE_AND_GOTO_LABEL_ON_ERROR("glfs_creat", ret, out); } glfs_close(fd); object = glfs_h_lookupat(fs, NULL, filename, NULL, 0); if (object == NULL) { ret = -1; VALIDATE_AND_GOTO_LABEL_ON_ERROR("glfs_h_lookupat", ret, out); } ret = glfs_chown(fs, filename, 99, 99); VALIDATE_AND_GOTO_LABEL_ON_ERROR("glfs_chown", ret, out); ret = glfs_setfsuid(99); VALIDATE_AND_GOTO_LABEL_ON_ERROR("glfs_setfsuid", ret, out); ret = glfs_setfsgid(99); VALIDATE_AND_GOTO_LABEL_ON_ERROR("glfs_setfsgid", ret, out); acl = glfs_h_acl_get(fs, object, ACL_TYPE_ACCESS); if (acl == NULL) { ret = -1; VALIDATE_AND_GOTO_LABEL_ON_ERROR("glfs_h_acl_get", ret, out); } ret = glfs_h_acl_set(fs, object, ACL_TYPE_ACCESS, acl); VALIDATE_AND_GOTO_LABEL_ON_ERROR("glfs_h_acl_get", ret, out); out: glfs_setfsuid(0); glfs_setfsgid(0); if (object) glfs_h_close(object); if (fs) glfs_fini(fs); return ret; }
/* * Read the ACL in GlusterFS format and convert it into fsal ACL before * storing it in fsalattr */ fsal_status_t glusterfs_get_acl(struct glusterfs_export *glfs_export, struct glfs_object *glhandle, glusterfs_fsal_xstat_t *buffxstat, struct attrlist *fsalattr) { fsal_status_t status = { ERR_FSAL_NO_ERROR, 0 }; fsal_acl_data_t acldata; fsal_acl_status_t aclstatus; fsal_ace_t *pace = NULL; int e_count = 0, i_count = 0, new_count = 0, new_i_count = 0; if (fsalattr->acl != NULL) { /* We should never be passed attributes that have an * ACL attached, but just in case some future code * path changes that assumption, let's release the * old ACL properly. */ int acl_status; acl_status = nfs4_acl_release_entry(fsalattr->acl); if (acl_status != NFS_V4_ACL_SUCCESS) LogCrit(COMPONENT_FSAL, "Failed to release old acl, status=%d", acl_status); fsalattr->acl = NULL; } if (NFSv4_ACL_SUPPORT) { buffxstat->e_acl = glfs_h_acl_get(glfs_export->gl_fs->fs, glhandle, ACL_TYPE_ACCESS); if (!buffxstat->e_acl) { status = gluster2fsal_error(errno); return status; } e_count = ace_count(buffxstat->e_acl); if (buffxstat->is_dir) { buffxstat->i_acl = glfs_h_acl_get(glfs_export->gl_fs->fs, glhandle, ACL_TYPE_DEFAULT); i_count = ace_count(buffxstat->i_acl); } /* Allocating memory for both ALLOW and DENY entries */ acldata.naces = 2 * (e_count + i_count); LogDebug(COMPONENT_FSAL, "No of aces present in fsal_acl_t = %d" , acldata.naces); if (!acldata.naces) return status; FSAL_SET_MASK(buffxstat->attr_valid, XATTR_ACL); acldata.aces = (fsal_ace_t *) nfs4_ace_alloc(acldata.naces); pace = acldata.aces; new_count = posix_acl_2_fsal_acl(buffxstat->e_acl, buffxstat->is_dir, false, &pace); if (new_count < 0) return fsalstat(ERR_FSAL_NO_ACE, -1); if (i_count > 0) { new_i_count = posix_acl_2_fsal_acl(buffxstat->i_acl, true, true, &pace); if (new_i_count > 0) new_count += new_i_count; else LogDebug(COMPONENT_FSAL, "Inherit acl is not set for this directory"); } /* Reallocating acldata into the required size */ acldata.aces = (fsal_ace_t *) gsh_realloc(acldata.aces, new_count*sizeof(fsal_ace_t)); acldata.naces = new_count; fsalattr->acl = nfs4_acl_new_entry(&acldata, &aclstatus); LogDebug(COMPONENT_FSAL, "fsal acl = %p, fsal_acl_status = %u", fsalattr->acl, aclstatus); if (fsalattr->acl == NULL) { LogCrit(COMPONENT_FSAL, "failed to create a new acl entry"); return fsalstat(ERR_FSAL_NOMEM, -1); } fsalattr->valid_mask |= ATTR_ACL; } else { /* We were asked for ACL but do not support. */ status = fsalstat(ERR_FSAL_NOTSUPP, 0); } return status; }