From: Ross Lagerwall Date: Sun, 14 Sep 2014 14:38:57 +0000 (+0100) Subject: libnfs: Give correct access() results for directories X-Git-Tag: upstream/1.9.6^2~2^2~1 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=c50173cf0d1fbaafcbf444d0b980de72b83373c9;p=deb_libnfs.git libnfs: Give correct access() results for directories Map ACCESS3_{MODIFY,EXTEND,DELETE} to W_OK and ACCESS3_{LOOKUP,EXECUTE} to X_OK so that nfs_access() gives sensible results for directories. Signed-off-by: Ross Lagerwall --- diff --git a/lib/libnfs.c b/lib/libnfs.c index c213cad..566583c 100644 --- a/lib/libnfs.c +++ b/lib/libnfs.c @@ -4314,7 +4314,7 @@ static void nfs_access_cb(struct rpc_context *rpc, int status, void *command_dat ACCESS3res *res; struct nfs_cb_data *data = private_data; struct nfs_context *nfs = data->nfs; - unsigned int nfsmode = 0; + unsigned int mode = 0; assert(rpc->magic == RPC_CONTEXT_MAGIC); @@ -4337,24 +4337,24 @@ static void nfs_access_cb(struct rpc_context *rpc, int status, void *command_dat return; } - if (data->continue_int & R_OK) { - nfsmode |= ACCESS3_READ; + if ((data->continue_int & R_OK) && (res->ACCESS3res_u.resok.access & ACCESS3_READ)) { + mode |= R_OK; } - if (data->continue_int & W_OK) { - nfsmode |= ACCESS3_MODIFY; + if ((data->continue_int & W_OK) && (res->ACCESS3res_u.resok.access & (ACCESS3_MODIFY | ACCESS3_EXTEND | ACCESS3_DELETE))) { + mode |= W_OK; } - if (data->continue_int & X_OK) { - nfsmode |= ACCESS3_EXECUTE; + if ((data->continue_int & X_OK) && (res->ACCESS3res_u.resok.access & (ACCESS3_LOOKUP | ACCESS3_EXECUTE))) { + mode |= X_OK; } - if (res->ACCESS3res_u.resok.access != nfsmode) { + if (data->continue_int != mode) { rpc_set_error(nfs->rpc, "NFS: ACCESS denied. Required access %c%c%c. Allowed access %c%c%c", - nfsmode&ACCESS3_READ?'r':'-', - nfsmode&ACCESS3_MODIFY?'w':'-', - nfsmode&ACCESS3_EXECUTE?'x':'-', - res->ACCESS3res_u.resok.access&ACCESS3_READ?'r':'-', - res->ACCESS3res_u.resok.access&ACCESS3_MODIFY?'w':'-', - res->ACCESS3res_u.resok.access&ACCESS3_EXECUTE?'x':'-'); + data->continue_int&R_OK?'r':'-', + data->continue_int&W_OK?'w':'-', + data->continue_int&X_OK?'x':'-', + mode&R_OK?'r':'-', + mode&W_OK?'w':'-', + mode&X_OK?'x':'-'); data->cb(-EACCES, nfs, rpc_get_error(nfs->rpc), data->private_data); free_nfs_cb_data(data); return; @@ -4373,10 +4373,10 @@ static int nfs_access_continue_internal(struct nfs_context *nfs, fattr3 *attr _U nfsmode |= ACCESS3_READ; } if (data->continue_int & W_OK) { - nfsmode |= ACCESS3_MODIFY; + nfsmode |= ACCESS3_MODIFY | ACCESS3_EXTEND | ACCESS3_DELETE; } if (data->continue_int & X_OK) { - nfsmode |= ACCESS3_EXECUTE; + nfsmode |= ACCESS3_LOOKUP | ACCESS3_EXECUTE; } memset(&args, 0, sizeof(ACCESS3args)); @@ -4394,7 +4394,7 @@ static int nfs_access_continue_internal(struct nfs_context *nfs, fattr3 *attr _U int nfs_access_async(struct nfs_context *nfs, const char *path, int mode, nfs_cb cb, void *private_data) { - if (nfs_lookuppath_async(nfs, path, 0, cb, private_data, nfs_access_continue_internal, NULL, NULL, mode) != 0) { + if (nfs_lookuppath_async(nfs, path, 0, cb, private_data, nfs_access_continue_internal, NULL, NULL, mode & (R_OK | W_OK | X_OK)) != 0) { rpc_set_error(nfs->rpc, "Out of memory: failed to start parsing the path components"); return -1; }