2010-10-11 14:59:26 -04:00
|
|
|
/* Copyright (c) 2010
|
|
|
|
|
* The Regents of the University of Michigan
|
|
|
|
|
* All Rights Reserved
|
|
|
|
|
*
|
|
|
|
|
* Permission is granted to use, copy and redistribute this software
|
|
|
|
|
* for noncommercial education and research purposes, so long as no
|
|
|
|
|
* fee is charged, and so long as the name of the University of Michigan
|
|
|
|
|
* is not used in any advertising or publicity pertaining to the use
|
|
|
|
|
* or distribution of this software without specific, written prior
|
|
|
|
|
* authorization. Permission to modify or otherwise create derivative
|
|
|
|
|
* works of this software is not granted.
|
|
|
|
|
*
|
|
|
|
|
* This software is provided as is, without representation or warranty
|
|
|
|
|
* of any kind either express or implied, including without limitation
|
|
|
|
|
* the implied warranties of merchantability, fitness for a particular
|
|
|
|
|
* purpose, or noninfringement. The Regents of the University of
|
|
|
|
|
* Michigan shall not be liable for any damages, including special,
|
|
|
|
|
* indirect, incidental, or consequential damages, with respect to any
|
|
|
|
|
* claim arising out of or in connection with the use of the software,
|
|
|
|
|
* even if it has been or is hereafter advised of the possibility of
|
|
|
|
|
* such damages.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <Windows.h>
|
2010-10-12 10:06:01 -04:00
|
|
|
#include <strsafe.h>
|
2010-10-11 14:59:26 -04:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
|
|
#include "daemon_debug.h"
|
|
|
|
|
#include "nfs41_ops.h"
|
|
|
|
|
#include "upcall.h"
|
|
|
|
|
#include "util.h"
|
|
|
|
|
|
2010-10-27 09:22:20 -04:00
|
|
|
|
2010-10-11 14:59:26 -04:00
|
|
|
/* NFS41_MOUNT */
|
2010-10-27 09:22:20 -04:00
|
|
|
static int parse_mount(unsigned char *buffer, uint32_t length, nfs41_upcall *upcall)
|
2010-10-11 14:59:26 -04:00
|
|
|
{
|
|
|
|
|
int status;
|
|
|
|
|
mount_upcall_args *args = &upcall->args.mount;
|
|
|
|
|
|
2010-10-12 10:04:06 -04:00
|
|
|
status = get_name(&buffer, &length, &args->hostname);
|
2010-10-11 14:59:26 -04:00
|
|
|
if(status) goto out;
|
2010-10-12 10:04:06 -04:00
|
|
|
status = get_name(&buffer, &length, &args->path);
|
2010-10-12 10:03:03 -04:00
|
|
|
if(status) goto out;
|
|
|
|
|
|
|
|
|
|
dprintf(1, "parsing NFS14_MOUNT: srv_name=%s root=%s\n",
|
2010-10-12 10:04:06 -04:00
|
|
|
args->hostname, args->path);
|
2010-10-11 14:59:26 -04:00
|
|
|
out:
|
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-27 09:22:20 -04:00
|
|
|
static int handle_mount(nfs41_upcall *upcall)
|
2010-10-11 14:59:26 -04:00
|
|
|
{
|
|
|
|
|
int status;
|
|
|
|
|
mount_upcall_args *args = &upcall->args.mount;
|
2010-10-12 10:06:01 -04:00
|
|
|
nfs41_abs_path path;
|
2010-10-11 14:59:26 -04:00
|
|
|
multi_addr4 addrs;
|
|
|
|
|
nfs41_root *root;
|
|
|
|
|
nfs41_client *client;
|
|
|
|
|
|
|
|
|
|
// resolve hostname,port
|
2010-10-12 10:06:01 -04:00
|
|
|
status = nfs41_server_resolve(args->hostname, 2049, &addrs);
|
2010-10-11 14:59:26 -04:00
|
|
|
if (status) {
|
|
|
|
|
eprintf("nfs41_server_resolve() failed with %d\n", status);
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
// create root
|
2010-10-26 14:35:30 -04:00
|
|
|
status = nfs41_root_create(args->hostname,
|
|
|
|
|
NFS41_MAX_FILEIO_SIZE + WRITE_OVERHEAD,
|
2010-10-11 14:59:26 -04:00
|
|
|
NFS41_MAX_FILEIO_SIZE + READ_OVERHEAD, &root);
|
|
|
|
|
if (status) {
|
|
|
|
|
eprintf("nfs41_rpc_clnt_create failed %d\n", status);
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
// add a mount
|
|
|
|
|
status = nfs41_root_mount_addrs(root, &addrs, 0, 0, &client);
|
|
|
|
|
if (status) {
|
|
|
|
|
eprintf("nfs41_root_mount() failed with %d\n", status);
|
|
|
|
|
goto out_err;
|
|
|
|
|
}
|
2010-10-12 10:06:01 -04:00
|
|
|
|
|
|
|
|
// make a copy of the path for nfs41_lookup()
|
|
|
|
|
InitializeSRWLock(&path.lock);
|
|
|
|
|
if (FAILED(StringCchCopyA(path.path, NFS41_MAX_PATH_LEN, args->path))) {
|
|
|
|
|
status = ERROR_BUFFER_OVERFLOW;
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
path.len = (unsigned short)strlen(path.path);
|
|
|
|
|
|
2010-10-11 14:59:26 -04:00
|
|
|
// look up the mount path, and fail if it doesn't exist
|
|
|
|
|
status = nfs41_lookup(root, client->session,
|
2010-10-12 10:06:01 -04:00
|
|
|
&path, NULL, NULL, NULL, NULL);
|
2010-10-11 14:59:26 -04:00
|
|
|
if (status) {
|
|
|
|
|
eprintf("nfs41_lookup('%s') failed with %d\n",
|
2010-10-12 10:06:01 -04:00
|
|
|
path.path, status);
|
2010-10-11 14:59:26 -04:00
|
|
|
goto out_err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
args->root = root;
|
|
|
|
|
out:
|
|
|
|
|
return status;
|
|
|
|
|
|
|
|
|
|
out_err:
|
|
|
|
|
nfs41_root_free(root);
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-27 09:22:20 -04:00
|
|
|
static int marshall_mount(unsigned char *buffer, uint32_t *length, nfs41_upcall *upcall)
|
2010-10-11 14:59:26 -04:00
|
|
|
{
|
|
|
|
|
mount_upcall_args *args = &upcall->args.mount;
|
|
|
|
|
dprintf(2, "NFS41_MOUNT: writing pointer to nfs41_root %p\n", args->root);
|
|
|
|
|
return safe_write(&buffer, length, &args->root, sizeof(args->root));
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-27 09:22:20 -04:00
|
|
|
const nfs41_upcall_op nfs41_op_mount = {
|
|
|
|
|
parse_mount,
|
|
|
|
|
handle_mount,
|
|
|
|
|
marshall_mount
|
|
|
|
|
};
|
|
|
|
|
|
2010-10-11 14:59:26 -04:00
|
|
|
|
|
|
|
|
/* NFS41_UNMOUNT */
|
2010-10-27 09:22:20 -04:00
|
|
|
static int parse_unmount(unsigned char *buffer, uint32_t length, nfs41_upcall *upcall)
|
2010-10-11 14:59:26 -04:00
|
|
|
{
|
|
|
|
|
int status;
|
|
|
|
|
unmount_upcall_args *args = &upcall->args.unmount;
|
|
|
|
|
|
|
|
|
|
status = safe_read(&buffer, &length, &args->root, sizeof(nfs41_session *));
|
2010-10-12 10:03:03 -04:00
|
|
|
if (status) goto out;
|
|
|
|
|
|
|
|
|
|
dprintf(1, "parsing NFS41_UNMOUNT: unmount root=%p\n", args->root);
|
|
|
|
|
out:
|
2010-10-11 14:59:26 -04:00
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-27 09:22:20 -04:00
|
|
|
static int handle_unmount(nfs41_upcall *upcall)
|
2010-10-11 14:59:26 -04:00
|
|
|
{
|
|
|
|
|
int status = NO_ERROR;
|
|
|
|
|
unmount_upcall_args *args = &upcall->args.unmount;
|
|
|
|
|
nfs41_root_free(args->root);
|
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-27 09:22:20 -04:00
|
|
|
const nfs41_upcall_op nfs41_op_unmount = {
|
|
|
|
|
parse_unmount,
|
|
|
|
|
handle_unmount
|
|
|
|
|
};
|