Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nfs_open: Support O_NOFOLLOW #192

Merged
merged 1 commit into from
May 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion include/nfsc/libnfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -455,13 +455,14 @@ EXTERN uint16_t nfs_umask(struct nfs_context *nfs, uint16_t mask);
* Async open(<filename>)
*
* mode is a combination of the flags :
* O_RDONLY, O_WRONLY, O_RDWR , O_SYNC, O_APPEND, O_TRUNC
* O_RDONLY, O_WRONLY, O_RDWR , O_SYNC, O_APPEND, O_TRUNC, O_NOFOLLOW
*
* Function returns
* 0 : The operation was initiated. Once the operation finishes, the callback will be invoked.
* <0 : An error occured when trying to set up the operation. The callback will not be invoked.
*
* Supported flags are
* O_NOFOLLOW
* O_APPEND
* O_RDONLY
* O_WRONLY
Expand Down Expand Up @@ -812,6 +813,7 @@ EXTERN int nfs_creat(struct nfs_context *nfs, const char *path, int mode, struct
* Async create()
*
* Same as nfs_creat_async but allows passing flags:
* O_NOFOLLOW
* O_APPEND
* O_SYNC
* O_EXCL
Expand Down
37 changes: 22 additions & 15 deletions lib/libnfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1461,28 +1461,35 @@ static int nfs_lookup_path_async_internal(struct nfs_context *nfs, fattr3 *attr,
path = data->path;
slash = strchr(path, '/');

if (attr && attr->type == NF3LNK && (!data->no_follow || *path != '\0')) {
READLINK3args rl_args;

if (data->link_count++ >= MAX_LINK_COUNT) {
data->cb(-ELOOP, nfs, "Too many levels of symbolic links", data->private_data);
if (attr && attr->type == NF3LNK) {
if (data->continue_int & O_NOFOLLOW) {
data->cb(-ELOOP, nfs, "Symbolic link encountered", data->private_data);
free_nfs_cb_data(data);
return -1;
}
if (!data->no_follow || *path != '\0') {
READLINK3args rl_args;

rl_args.symlink = *fh;
if (data->link_count++ >= MAX_LINK_COUNT) {
data->cb(-ELOOP, nfs, "Too many levels of symbolic links", data->private_data);
free_nfs_cb_data(data);
return -1;
}

if (rpc_nfs3_readlink_async(nfs->rpc, nfs_lookup_path_2_cb, &rl_args, data) != 0) {
rpc_set_error(nfs->rpc, "RPC error: Failed to send READLINK call for %s", data->path);
data->cb(-ENOMEM, nfs, rpc_get_error(nfs->rpc), data->private_data);
free_nfs_cb_data(data);
return -1;
}
rl_args.symlink = *fh;

if (slash != NULL) {
*slash = '/';
if (rpc_nfs3_readlink_async(nfs->rpc, nfs_lookup_path_2_cb, &rl_args, data) != 0) {
rpc_set_error(nfs->rpc, "RPC error: Failed to send READLINK call for %s", data->path);
data->cb(-ENOMEM, nfs, rpc_get_error(nfs->rpc), data->private_data);
free_nfs_cb_data(data);
return -1;
}

if (slash != NULL) {
*slash = '/';
}
return 0;
}
return 0;
}

if (slash != NULL) {
Expand Down