smb_vss.c revision 9fb67ea305c66b6a297583b9b0db6796b0dfe497
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2010 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Volume Copy Shadow Services (VSS) provides a way for users to
* restore/recover deleted files/directories.
* For the server to support VSS for Microsoft clients, there is
* two basic functions that need to be implemented.
* The first is to intercept the NT_TRANSACT_IOCTL command with
* the function code of FSCTL_SRV_ENUMERATE_SNAPSHOTS (0x00144064).
* This is to report the count or the count and list of snapshots
* for that share.
* The second function need to trap commands with the
* SMB_FLAGS2_REPARSE_PATH bit set in the smb header. This bit
* means that there is a @GMT token in path that needs to be
* processed. The @GMT token means to process this command, but
* in the snapshot.
*/
#include <smbsrv/smb_kproto.h>
#include <smbsrv/winioctl.h>
#include <smbsrv/smb_door.h>
/* Size of the token on the wire due to encoding */
#define SMB_VSS_COUNT_SIZE 16
static boolean_t smb_vss_is_gmttoken(const char *);
static const char *smb_vss_find_gmttoken(const char *);
static void smb_vss_remove_first_token_from_path(char *);
static uint32_t smb_vss_get_count(char *);
static void smb_vss_map_gmttoken(char *, char *, char *);
static void smb_vss_get_snapshots_free(smb_gmttoken_response_t *);
/*
* This is to respond to the nt_transact_ioctl to either respond with the
* number of snapshots, or to respond with the list. It needs to be sorted
* before the reply. If the the max data bytes to return is
* SMB_VSS_COUNT_SIZE, then all that is requested is the count, otherwise
* return the count and the list of @GMT tokens (one token for each
* snapshot).
*/
{
char *root_path;
return (NT_STATUS_INVALID_PARAMETER);
return (NT_STATUS_INVALID_PARAMETER);
smb_ascii_or_unicode_null_len(sr)), 0) != 0) {
}
} else {
}
return (status);
}
/*
* sr - the request info, used to find root of dataset,
* unicode or ascii, where the share is rooted in the
* dataset
* root_node - root of the share
* cur_node - where in the share for the command
* buf - is the path for the command to be processed
* returned without @GMT if processed
* vss_cur_node - returned value for the snapshot version
* of the cur_node
* vss_root_node - returned value for the snapshot version
* of the root_node
*
* This routine is the processing for handling the
* SMB_FLAGS2_REPARSE_PATH bit being set in the smb header.
*
* By using the cur_node passed in, a new node is found or
* created that is the same place in the directory tree, but
* in the snapshot. We also use root_node to do the same for
* the root.
* One the new smb node is found, the path is modified by
* removing the @GMT token from the path in the buf.
*/
int
{
const char *p;
char *rootpath;
char *snapname;
char *nodepath;
char gmttoken[SMB_VSS_GMT_SIZE];
int err = 0;
return (ESTALE);
return (ENOENT);
if (err != 0)
return (err);
if (err != 0)
goto error;
*snapname = '\0';
if (!*snapname) {
goto error;
}
/* note the value of root_node->vp */
MAXPATHLEN, kcred);
if (err != 0)
goto error;
if (vp) {
/* note the value of cur_node->vp */
MAXPATHLEN, kcred);
if (err != 0) {
goto error;
}
if (*vss_root_node == NULL) {
goto error;
}
if (vp) {
if (*vss_cur_node != NULL) {
} else {
(void) smb_node_release(*vss_root_node);
}
} else {
(void) smb_node_release(*vss_root_node);
}
} else {
}
return (err);
}
static boolean_t
smb_vss_is_gmttoken(const char *s)
{
char *t = "@GMT-NNNN.NN.NN-NN.NN.NN";
const char *str;
char *template;
template = t;
str = s;
while (*template) {
if (*template == 'N') {
if (!smb_isdigit(*str))
return (B_FALSE);
return (B_FALSE);
}
template++;
str++;
}
/* Make sure it is JUST the @GMT token */
return (B_TRUE);
return (B_FALSE);
}
static const char *
smb_vss_find_gmttoken(const char *path)
{
const char *p;
p = path;
while (*p) {
if (smb_vss_is_gmttoken(p))
return (p);
p++;
}
return (NULL);
}
static uint32_t
{
uint32_t i;
char **gmttokens;
if (returned_count > count)
num_gmttokens, data_size) != 0)
return (NT_STATUS_INVALID_PARAMETER);
if (status == NT_STATUS_SUCCESS) {
for (i = 0; i < num_gmttokens; i++) {
*gmttokens) != 0)
gmttokens++;
}
}
return (status);
}
/* This removes the first @GMT from the path */
static void
{
while (*src != '\0') {
if (*src == '/')
src += 1;
continue;
}
src++;
dest++;
}
}
/*
* This returns the number of snapshots for the dataset
* of the path provided.
*/
static uint32_t
smb_vss_get_count(char *resource_path)
{
int rc;
if (rc != 0)
count = 0;
return (count);
}
/*
* This takes a path for the root of the dataset and gets the counts of
* snapshots for that dataset and the list of @GMT tokens (one for each
* snapshot) up to the count provided.
*
* Call smb_vss_get_snapshots_free after to free up the data.
*/
static void
{
}
static void
{
}
/*
* Returns the snapshot name for the @GMT token provided for the dataset
* of the path. If the snapshot cannot be found, a string with a NULL
* is returned.
*/
static void
{
&result, smb_string_xdr);
}