int cifs_acl_to_fattr(struct cifs_sb_info *cifs_sb, struct cifs_fattr *fattr, struct inode *inode, const char *path, const __u16 *pfid) { struct cifs_ntsd *pntsd = NULL; u32 acllen = 0; int rc = 0; cFYI(DBG2, "converting ACL to mode for %s", path); if (pfid) pntsd = get_cifs_acl_by_fid(cifs_sb, *pfid, &acllen); else pntsd = get_cifs_acl(cifs_sb, inode, path, &acllen); if (IS_ERR(pntsd)) { rc = PTR_ERR(pntsd); cERROR(1, "%s: error %d getting sec desc", __func__, rc); } else { rc = parse_sec_desc(cifs_sb, pntsd, acllen, fattr); kfree(pntsd); if (rc) cERROR(1, "parse sec desc failed rc = %d", rc); } return rc; }
/* Translate the CIFS ACL (simlar to NTFS ACL) for a file into mode bits */ void acl_to_uid_mode(struct inode *inode, const char *path, const __u16 *pfid) { struct cifs_ntsd *pntsd = NULL; u32 acllen = 0; int rc = 0; cFYI(DBG2, ("converting ACL to mode for %s", path)); pntsd = get_cifs_acl(&acllen, inode, path, pfid); /* if we can retrieve the ACL, now parse Access Control Entries, ACEs */ if (pntsd) rc = parse_sec_desc(pntsd, acllen, inode); if (rc) cFYI(1, ("parse sec desc failed rc = %d", rc)); kfree(pntsd); return; }
/* Translate the CIFS ACL (simlar to NTFS ACL) for a file into mode bits */ int cifs_acl_to_fattr(struct cifs_sb_info *cifs_sb, struct cifs_fattr *fattr, struct inode *inode, const char *path, const struct cifs_fid *pfid) { struct cifs_ntsd *pntsd = NULL; u32 acllen = 0; int rc = 0; struct tcon_link *tlink = cifs_sb_tlink(cifs_sb); struct cifs_tcon *tcon; cifs_dbg(NOISY, "converting ACL to mode for %s\n", path); if (IS_ERR(tlink)) return PTR_ERR(tlink); tcon = tlink_tcon(tlink); if (pfid && (tcon->ses->server->ops->get_acl_by_fid)) pntsd = tcon->ses->server->ops->get_acl_by_fid(cifs_sb, pfid, &acllen); else if (tcon->ses->server->ops->get_acl) pntsd = tcon->ses->server->ops->get_acl(cifs_sb, inode, path, &acllen); else { cifs_put_tlink(tlink); return -EOPNOTSUPP; } /* if we can retrieve the ACL, now parse Access Control Entries, ACEs */ if (IS_ERR(pntsd)) { rc = PTR_ERR(pntsd); cifs_dbg(VFS, "%s: error %d getting sec desc\n", __func__, rc); } else { rc = parse_sec_desc(cifs_sb, pntsd, acllen, fattr); kfree(pntsd); if (rc) cifs_dbg(VFS, "parse sec desc failed rc = %d\n", rc); } cifs_put_tlink(tlink); return rc; }
/* Translate the CIFS ACL (simlar to NTFS ACL) for a file into mode bits */ void cifs_acl_to_fattr(struct cifs_sb_info *cifs_sb, struct cifs_fattr *fattr, struct inode *inode, const char *path, const __u16 *pfid) { struct cifs_ntsd *pntsd = NULL; u32 acllen = 0; int rc = 0; cFYI(DBG2, "converting ACL to mode for %s", path); if (pfid) pntsd = get_cifs_acl_by_fid(cifs_sb, *pfid, &acllen); else pntsd = get_cifs_acl(cifs_sb, inode, path, &acllen); /* if we can retrieve the ACL, now parse Access Control Entries, ACEs */ if (pntsd) rc = parse_sec_desc(pntsd, acllen, fattr); if (rc) cFYI(1, "parse sec desc failed rc = %d", rc); kfree(pntsd); return; }
int main(const int argc, char *const argv[]) { int c, raw = 0; ssize_t attrlen; size_t bufsize = BUFSIZE; char *filename, *attrval; openlog(prog, 0, LOG_DAEMON); while ((c = getopt_long(argc, argv, "r:v", NULL, NULL)) != -1) { switch (c) { case 'v': printf("Version: %s\n", VERSION); goto out; case 'r': raw = 1; break; default: break; } } if (raw && argc == 3) filename = argv[2]; else if (argc == 2) filename = argv[1]; else { getcifsacl_usage(); return 0; } cifsacl: if (bufsize >= XATTR_SIZE_MAX) { printf("buffer to allocate exceeds max size of %d\n", XATTR_SIZE_MAX); return -1; } attrval = malloc(bufsize * sizeof(char)); if (!attrval) { printf("error allocating memory for attribute value buffer\n"); return -1; } attrlen = getxattr(filename, ATTRNAME, attrval, bufsize); if (attrlen == -1) { if (errno == ERANGE) { free(attrval); bufsize += BUFSIZE; goto cifsacl; } else printf("getxattr error: %d\n", errno); } parse_sec_desc((struct cifs_ntsd *)attrval, attrlen, raw); free(attrval); out: return 0; }