smb_directory.c revision 037cac007b685e7ea79f6ef7e8e62bfd342a4d56
/*
* 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 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <smbsrv/ntstatus.h>
#include <smbsrv/smb_incl.h>
#include <smbsrv/smb_fsops.h>
typedef struct smb_dirpath {
char *sp_path; /* Original path */
char *sp_curp; /* Current pointer into the original path */
static int smb_dirpath_next(smb_dirpath_t *);
static boolean_t smb_dirpath_isvalid(const char *);
/*
* The create directory message is sent to create a new directory. The
* appropriate Tid and additional pathname are passed. The directory must
* not exist for it to be created.
*
* Client Request Description
* ================================== =================================
* UCHAR WordCount; Count of parameter words = 0
* USHORT ByteCount; Count of data bytes; min = 2
* UCHAR BufferFormat; 0x04
* STRING DirectoryName[]; Directory name
*
* Servers require clients to have at least create permission for the
* subtree containing the directory in order to create a new directory.
* The creator's access rights to the new directory are be determined by
* local policy on the server.
*
* Server Response Description
* ================================== =================================
* UCHAR WordCount; Count of parameter words = 0
* USHORT ByteCount; Count of data bytes = 0
*/
{
int rc;
}
void
{
}
/*
* smb_com_create_directory
*
* It is possible to get a full pathname here and the client expects any
* or all of the components to be created if they don't already exist.
*/
{
int rc = 0;
return (SDRC_ERROR);
}
return (SDRC_ERROR);
}
if (status != 0) {
return (SDRC_ERROR);
}
/*
* Try each component of the path. EEXIST on path
* components is okay except on the last one.
*/
while (smb_dirpath_next(spp)) {
switch (rc) {
case 0:
break;
case EEXIST:
return (SDRC_ERROR);
}
break;
case ENOENT:
return (SDRC_ERROR);
case ENOTDIR:
return (SDRC_ERROR);
default:
return (SDRC_ERROR);
}
}
if (rc != 0) {
return (SDRC_ERROR);
}
}
/*
* smb_validate_dirname
*
* Very basic directory name validation: checks for colons in a path.
* Need to skip the drive prefix since it contains a colon.
*
* Returns NT_STATUS_SUCCESS if the name is valid,
* otherwise NT_STATUS_NOT_A_DIRECTORY.
*/
smb_validate_dirname(char *path)
{
char *name;
return (NT_STATUS_NOT_A_DIRECTORY);
}
return (NT_STATUS_SUCCESS);
}
/*
* smb_common_create_directory
*
* Currently called from:
* smb_com_create_directory
* smb_com_trans2_create_directory
*
* Returns errno values.
*/
int
{
int rc;
if (rc)
return (rc);
/*
* Because of FQM_PATH_MUST_NOT_EXIST and the successful return
* value, only fqi.fq_dnode has a valid parameter (fqi.fq_fnode
* is NULL).
*/
if (rc != NT_STATUS_SUCCESS)
return (EACCES);
/*
* Explicitly set sa_dosattr, otherwise the file system may
* automatically apply FILE_ATTRIBUTE_ARCHIVE which, for
* compatibility with windows servers, should not be set.
*/
return (rc);
}
if (rc != 0) {
return (rc);
}
return (0);
}
static smb_dirpath_t *
{
int pathLen;
char *xpath;
/* Malloc from the request storage area. This is freed automatically */
/* so we don't need to worry about freeing it later */
return (spp);
}
/*
* Perhaps somewhat dangerous since everything happens as a side effect. The
* returns 1 if there is a valid component updated to the fqi, 0 otherwise.
*/
static int
{
char *xp;
int xlen;
if (spp == 0)
return (0);
/* Move the index to the "next" "\" and copy the path to the fqi */
/* path for the next component. */
/* First look for the next component */
/* Now get to the end of the component */
}
/* If we made no progress, we are done */
return (0);
/*
* Now copy the original path up to but not including our current
* pointer
*/
/*LINTED E_PTRDIFF_OVERFLOW*/
/* Now NULL terminate it */
return (1);
}
/*
* The delete directory message is sent to delete an empty directory. The
* appropriate Tid and additional pathname are passed. The directory must
* be empty for it to be deleted.
*
* NT supports a hidden permission known as File Delete Child (FDC). If
* the user has FullControl access to a directory, the user is permitted
* to delete any object in the directory regardless of the permissions
* on the object.
*
* Client Request Description
* ================================== =================================
* UCHAR WordCount; Count of parameter words = 0
* USHORT ByteCount; Count of data bytes; min = 2
* UCHAR BufferFormat; 0x04
* STRING DirectoryName[]; Directory name
*
* The directory to be deleted cannot be the root of the share specified
* by Tid.
*
* Server Response Description
* ================================== =================================
* UCHAR WordCount; Count of parameter words = 0
* USHORT ByteCount; Count of data bytes = 0
*/
{
int rc;
}
void
{
}
{
int rc;
return (SDRC_ERROR);
}
if (rc) {
else
return (SDRC_ERROR);
}
return (SDRC_ERROR);
}
if ((rc != NT_STATUS_SUCCESS) ||
return (SDRC_ERROR);
}
if (SMB_TREE_SUPPORTS_CATIA(sr))
if (rc != 0) {
else
return (SDRC_ERROR);
}
}
/*
* This SMB is used to verify that a path exists and is a directory. No
* error is returned if the given path exists and the client has read
* access to it. Client machines which maintain a concept of a "working
* directory" will find this useful to verify the validity of a "change
* working directory" command. Note that the servers do NOT have a concept
* of working directory for a particular client. The client must always
* supply full pathnames relative to the Tid in the SMB header.
*
* Client Request Description
* ================================== =================================
*
* UCHAR WordCount; Count of parameter words = 0
* USHORT ByteCount; Count of data bytes; min = 2
* UCHAR BufferFormat; 0x04
* STRING DirectoryPath[]; Directory path
*
* Server Response Description
* ================================== =================================
*
* UCHAR WordCount; Count of parameter words = 0
* USHORT ByteCount; Count of data bytes = 0
*
* DOS clients, in particular, depend on ERRbadpath if the directory is
* not found.
*/
{
int rc;
}
void
{
}
{
int rc;
return (SDRC_ERROR);
}
}
return (SDRC_ERROR);
}
if (rc) {
else
return (SDRC_ERROR);
}
return (SDRC_ERROR);
}
if (rc != 0) {
return (SDRC_ERROR);
}
}
static boolean_t
smb_dirpath_isvalid(const char *path)
{
struct {
char *name;
int len;
{ ".\0", 2 },
{ ".\\\0", 3 },
{ "..\0", 3 },
{ "..\\", 3 }
};
char *cp;
char *p;
int i;
if (*path == '\0')
return (B_TRUE);
p += strspn(p, "\\");
return (B_FALSE);
}
}
return (B_TRUE);
}