smb_trans2_find.c revision 2c1b14e51525da2c09064641416fc4aed457c72f
/*
* 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 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "@(#)smb_trans2_find.c 1.13 08/08/07 SMI"
/*
* This module provides functions for TRANS2_FIND_FIRST2 and
* TRANS2_FIND_NEXT2 requests. The requests allow the client to search
* for the file(s) which match the file specification. The search is
* started with TRANS2_FIND_FIRST2 and can be continued if necessary with
* TRANS2_FIND_NEXT2. There are numerous levels of information which may be
* obtained for the returned files, the desired level is specified in the
* InformationLevel field of the requests.
*
* InformationLevel Name Value
* ================================= ================
*
* SMB_INFO_STANDARD 1
* SMB_INFO_QUERY_EA_SIZE 2
* SMB_INFO_QUERY_EAS_FROM_LIST 3
* SMB_FIND_FILE_DIRECTORY_INFO 0x101
* SMB_FIND_FILE_FULL_DIRECTORY_INFO 0x102
* SMB_FIND_FILE_NAMES_INFO 0x103
* SMB_FIND_FILE_BOTH_DIRECTORY_INFO 0x104
*
* The following sections detail the data returned for each
* InformationLevel. The requested information is placed in the Data
* portion of the transaction response. Note: a client which does not
* support long names can only request SMB_INFO_STANDARD.
*
* A four-byte resume key precedes each data item (described below) if bit
* 2 in the Flags field is set, i.e. if the request indicates the server
* should return resume keys. Note: it is not always the case. If the
* data item already includes the resume key, the resume key should not be
* added again.
*
* 4.3.4.1 SMB_INFO_STANDARD
*
* Response Field Description
* ================================ ==================================
*
* SMB_DATE CreationDate; Date when file was created
* SMB_TIME CreationTime; Time when file was created
* SMB_DATE LastAccessDate; Date of last file access
* SMB_TIME LastAccessTime; Time of last file access
* SMB_DATE LastWriteDate; Date of last write to the file
* SMB_TIME LastWriteTime; Time of last write to the file
* ULONG DataSize; File Size
* ULONG AllocationSize; Size of filesystem allocation unit
* USHORT Attributes; File Attributes
* UCHAR FileNameLength; Length of filename in bytes
* STRING FileName; Name of found file
*
* 4.3.4.2 SMB_INFO_QUERY_EA_SIZE
*
* Response Field Description
* ================================= ==================================
*
* SMB_DATE CreationDate; Date when file was created
* SMB_TIME CreationTime; Time when file was created
* SMB_DATE LastAccessDate; Date of last file access
* SMB_TIME LastAccessTime; Time of last file access
* SMB_DATE LastWriteDate; Date of last write to the file
* SMB_TIME LastWriteTime; Time of last write to the file
* ULONG DataSize; File Size
* ULONG AllocationSize; Size of filesystem allocation unit
* USHORT Attributes; File Attributes
* ULONG EaSize; Size of file's EA information
* UCHAR FileNameLength; Length of filename in bytes
* STRING FileName; Name of found file
*
* 4.3.4.3 SMB_INFO_QUERY_EAS_FROM_LIST
*
* This request returns the same information as SMB_INFO_QUERY_EA_SIZE, but
* only for files which have an EA list which match the EA information in
* the Data part of the request.
*
* 4.3.4.4 SMB_FIND_FILE_DIRECTORY_INFO
*
* Response Field Description
* ================================= ==================================
*
* ULONG NextEntryOffset; Offset from this structure to
* beginning of next one
* ULONG FileIndex;
* LARGE_INTEGER CreationTime; file creation time
* LARGE_INTEGER LastAccessTime; last access time
* LARGE_INTEGER LastWriteTime; last write time
* LARGE_INTEGER ChangeTime; last attribute change time
* LARGE_INTEGER EndOfFile; file size
* LARGE_INTEGER AllocationSize; size of filesystem allocation information
* ULONG ExtFileAttributes; Extended file attributes
* (see section 3.11)
* ULONG FileNameLength; Length of filename in bytes
* STRING FileName; Name of the file
*
* 4.3.4.5 SMB_FIND_FILE_FULL_DIRECTORY_INFO
*
* Response Field Description
* ================================= ==================================
*
* ULONG NextEntryOffset; Offset from this structure to
* beginning of next one
* ULONG FileIndex;
* LARGE_INTEGER CreationTime; file creation time
* LARGE_INTEGER LastAccessTime; last access time
* LARGE_INTEGER LastWriteTime; last write time
* LARGE_INTEGER ChangeTime; last attribute change time
* LARGE_INTEGER EndOfFile; file size
* LARGE_INTEGER AllocationSize; size of filesystem allocation information
* ULONG ExtFileAttributes; Extended file attributes
* (see section 3.11)
* ULONG FileNameLength; Length of filename in bytes
* ULONG EaSize; Size of file's extended attributes
* STRING FileName; Name of the file
*
* 4.3.4.6 SMB_FIND_FILE_BOTH_DIRECTORY_INFO
*
* Response Field Description
* ================================= ==================================
*
* ULONG NextEntryOffset; Offset from this structure to
* beginning of next one
* ULONG FileIndex;
* LARGE_INTEGER CreationTime; file creation time
* LARGE_INTEGER LastAccessTime; last access time
* LARGE_INTEGER LastWriteTime; last write time
* LARGE_INTEGER ChangeTime; last attribute change time
* LARGE_INTEGER EndOfFile; file size
* LARGE_INTEGER AllocationSize; size of filesystem allocation information
* ULONG ExtFileAttributes; Extended file attributes
* (see section 3.11)
* ULONG FileNameLength; Length of FileName in bytes
* ULONG EaSize; Size of file's extended attributes
* UCHAR ShortNameLength; Length of file's short name in bytes
* UCHAR Reserved
* WCHAR ShortName[12]; File's 8.3 conformant name in Unicode
* STRING FileName; Files full length name
*
* 4.3.4.7 SMB_FIND_FILE_NAMES_INFO
*
* Response Field Description
* ================================= ==================================
*
* ULONG NextEntryOffset; Offset from this structure to
* beginning of next one
* ULONG FileIndex;
* ULONG FileNameLength; Length of FileName in bytes
* STRING FileName; Files full length name
*/
#include <smbsrv/smb_incl.h>
#include <smbsrv/smbtrans.h>
#include <smbsrv/smb_fsops.h>
smb_attr_t *, smb_node_t *, char *, char *);
smb_node_t *, int *, uint32_t *);
/*
* The UNIX characters below are considered illegal in Windows file names.
* The following character conversions are used to support sites in which
* Catia v4 is in use on UNIX and Catia v5 is in use on Windows.
*
* ---------------------------
* Unix-char | Windows-char
* ---------------------------
* " | (0x00a8) Diaeresis
* * | (0x00a4) Currency Sign
* : | (0x00f7) Division Sign
* < | (0x00ab) Left-Pointing Double Angle Quotation Mark
* > | (0x00bb) Right-Pointing Double Angle Quotation Mark
* ? | (0x00bf) Inverted Question mark
* \ | (0x00ff) Latin Small Letter Y with Diaeresis
* | | (0x00a6) Broken Bar
*/
void smb_unregister_catia_callback();
/*
* Tunable parameter to limit the maximum
* number of entries to be returned.
*/
/*
* smb_register_catia_callback
*
* This function will be invoked by the catia module to register its
* function that translates filename in version 4 to a format that is
* compatible to version 5.
*/
void
{
}
/*
* smb_unregister_catia_callback
*
* This function will unregister the catia callback prior to the catia
* module gets unloaded.
*/
void
{
catia_callback = 0;
}
/*
* smb_com_trans2_find_first2
*
* Client Request Value
* ============================ ==================================
*
* UCHAR WordCount 15
* UCHAR TotalDataCount Total size of extended attribute list
* UCHAR SetupCount 1
* UCHAR Setup[0] TRANS2_FIND_FIRST2
*
* Parameter Block Encoding Description
* ============================ ==================================
* USHORT SearchAttributes;
* USHORT SearchCount; Maximum number of entries to return
* USHORT Flags; Additional information:
* Bit 0 - close search after this request
* Bit 1 - close search if end of search
* reached
* Bit 2 - return resume keys for each
* entry found
* Bit 3 - continue search from previous
* ending place
* Bit 4 - find with backup intent
* USHORT InformationLevel; See below
* ULONG SearchStorageType;
* STRING FileName; Pattern for the search
* UCHAR Data[ TotalDataCount ] FEAList if InformationLevel is
* QUERY_EAS_FROM_LIST
*
* Response Parameter Block Description
* ============================ ==================================
*
* USHORT Sid; Search handle
* USHORT SearchCount; Number of entries returned
* USHORT EndOfSearch; Was last entry returned?
* USHORT EaErrorOffset; Offset into EA list if EA error
* USHORT LastNameOffset; Offset into data to file name of last
* entry, if server needs it to resume
* search; else 0
* UCHAR Data[ TotalDataCount ] Level dependent info about the matches
* found in the search
*/
{
int maxdata;
char *path;
char *pattern;
return (SDRC_ERROR);
}
return (SDRC_ERROR);
}
if (maxdata == 0) {
return (SDRC_ERROR);
}
/*
* When maxcount is zero Windows behaves as if it was 1.
*/
if (maxcount == 0)
maxcount = 1;
(void) smb_convert_unicode_wildcards(path);
return (SDRC_ERROR);
/*
* Get a copy of information
*/
cookie = 0;
if (!count)
if (rc) {
return (SDRC_ERROR);
}
/*
* Save the sid here in case the search is closed below,
* which will invalidate sr->smb_sid. We return the
* sid, even though the search has been closed, to be
* compatible with Windows.
*/
if (fflag & SMB_FIND_CLOSE_AFTER_REQUEST ||
} else {
}
return (SDRC_SUCCESS);
}
/*
* smb_com_trans2_find_next2
*
* Client Request Value
* ================================== =================================
*
* WordCount 15
* SetupCount 1
* Setup[0] TRANS2_FIND_NEXT2
*
* Parameter Block Encoding Description
* ================================== =================================
*
* USHORT Sid; Search handle
* USHORT SearchCount; Maximum number of entries to
* return
* USHORT InformationLevel; Levels described in
* TRANS2_FIND_FIRST2 request
* ULONG ResumeKey; Value returned by previous find2
* call
* USHORT Flags; Additional information: bit set-
* 0 - close search after this
* request
* 1 - close search if end of search
* reached
* 2 - return resume keys for each
* entry found
* ending place
* 4 - find with backup intent
* STRING FileName; Resume file name
*
* Sid is the value returned by a previous successful TRANS2_FIND_FIRST2
* call. If Bit3 of Flags is set, then FileName may be the NULL string,
* since the search is continued from the previous TRANS2_FIND request.
* Otherwise, FileName must not be more than 256 characters long.
*
* Response Field Description
* ================================== =================================
*
* USHORT SearchCount; Number of entries returned
* USHORT EndOfSearch; Was last entry returned?
* USHORT EaErrorOffset; Offset into EA list if EA error
* USHORT LastNameOffset; Offset into data to file name of
* last entry, if server needs it to
* resume search; else 0
* UCHAR Data[TotalDataCount] Level dependent info about the
* matches found in the search
*/
{
char *pattern;
/*
* The last parameter in the request is a path, which is a
* null-terminated unicode string.
*
* smb_mbc_decodef(&xa->req_param_mb, "%www lwu", sr,
* &sr->smb_sid, &maxcount, &infolev, &cookie, &fflag, &path)
*
* We don't reference this parameter and it is not currently
* decoded because we a expect 2-byte null but Mac OS 10
* clients send a 1-byte null, which leads to a decode error.
*/
return (SDRC_ERROR);
}
return (SDRC_ERROR);
}
if (maxdata == 0) {
return (SDRC_ERROR);
}
/*
* When maxcount is zero Windows behaves as if it was 1.
*/
if (maxcount == 0)
maxcount = 1;
/*
* Get a copy of information
*/
if (fflag & SMB_FIND_CONTINUE_FROM_LAST) {
}
if (rc) {
return (SDRC_ERROR);
}
if (fflag & SMB_FIND_CLOSE_AFTER_REQUEST ||
else {
}
return (SDRC_SUCCESS);
}
/*
* smb_trans2_find_get_maxdata
*
* Calculate the minimum response space required for the specified
* information level.
*
* A non-zero return value provides the minimum space required.
* A return value of zero indicates an unknown information level.
*/
static int
{
int maxdata;
switch (infolev) {
case SMB_INFO_STANDARD :
if (fflag & SMB_FIND_RETURN_RESUME_KEYS)
break;
case SMB_INFO_QUERY_EA_SIZE:
if (fflag & SMB_FIND_RETURN_RESUME_KEYS)
break;
break;
break;
case SMB_FIND_FILE_NAMES_INFO:
break;
4 + 32 + 4 + 1 + 1 + 24 + 4;
break;
default:
maxdata = 0;
}
return (maxdata);
}
/*
* smb_trans2_find_get_dents
*
* This function will get all the directory entry information and mbc
* encode it in the xa. If there is an error, it will be returned;
* otherwise, 0 is returned.
*
* The more field will be updated. If the value returned is one, it means
* there are more entries; otherwise, the returned value will be zero. The
* cookie will also be updated to indicate the next start point for the
* search. The count value will also be updated to stores the total entries
* encoded.
*/
int maxdata,
int wildcards,
char *pattern,
int *more,
int *count)
{
int dent_buf_size;
int i;
int total;
int maxentries;
int rc;
*count = 0;
if (!wildcards)
else {
if (maxcount > SMB_MAX_DENTS_IOVEC)
if (maxentries > maxcount)
}
/* Each entry will need to be aligned so add _POINTER_ALIGNMENT */
if (rc != 0) {
goto out;
}
*count = 0;
else
rc = 0;
out:
for (i = 0; i < total; i++) {
/*LINTED E_BAD_PTR_CAST_ALIGN*/
}
return (0);
}
/*
* smb_get_dents
*
* This function utilizes "smb_fsop_getdents()" to get dir entries.
* The "smb_gather_dents_info()" is the call back function called
* inside the file system. It is very important that the function
* does not sleep or yield since it is processed inside a file
* system transaction.
*
* The function returns 0 when successful and error code when failed.
* If more is provided, the return value of 1 is returned indicating
* more entries; otherwise, 0 is returned.
*/
int smb_get_dents(
int *more)
{
int rc;
char *namebuf;
if (more)
*more = 0;
if (!wildcards) {
/* Already found entry? */
if (*cookie != 0)
return (0);
shortname[0] = '\0';
name83);
if (rc) {
return (rc);
}
/*
* It is not necessary to set the "force" flag (i.e. to
* take into account mangling for case-insensitive collisions)
*/
if (shortname[0] == '\0')
(void) smb_gather_dents_info((char *)ihdr,
return (0);
}
return (0);
}
return (rc);
}
*more = 1;
return (0);
}
/*
* smb_gather_dents_info
*
* The function will accept information of each directory entry and put
* the needed information in the buffer. It is passed as the call back
* function for smb_fsop_getdents() to gather trans2 find info.
*
* If the buffer space is not enough, -1 will be returned. Regardless
* of valid entry or not, 0 will be returned; however, only valid entry
* will be stored in the buffer.
*/
int /*ARGSUSED*/
char *args,
int namelen,
char *name,
char *shortname,
char *name83)
{
/*LINTED E_BAD_PTR_CAST_ALIGN*/
return (-1);
}
return (0);
}
if (catia_callback) {
}
/*
* Each entry needs to be properly aligned or we may get an alignment
* fault on sparc.
*/
/*LINTED E_BAD_PTR_CAST_ALIGN*/
return (0);
}
/*
* smb_trans2_find_process_ients
*
* This function encodes the directory entry information store in
* the iov structure of the ihdr structure.
*
* The total entries encoded will be returned. If the entries encoded
* is less than the total entries in the iov, the more field will
* be updated to 1. Also, the next cookie wil be updated as well.
*/
int
int maxdata,
int *more,
{
int i, err = 0;
? SMB_MSGBUF_UNICODE : 0;
for (i = 0; i < SMB_MAX_DENTS_IOVEC; i++) {
/*LINTED E_BAD_PTR_CAST_ALIGN*/
break;
/*
* Observed differences between our response and Windows
* response, which hasn't caused a problem yet!
*
* 1. The NextEntryOffset field for the last entry should
* be 0. This code always calculate the record length
* and puts the result in the NextEntryOffset field.
*
* 2. The FileIndex field is always 0. This code puts
* the cookie in the FileIndex field.
*/
if (err)
break;
}
/*
* Not enough space to store all the entries returned,
* which is indicated by setting more.
*/
*more = 1;
/*
* Assume the space will be at least enough for 1 entry.
*/
/*LINTED E_BAD_PTR_CAST_ALIGN*/
}
return (i);
}
/*
* smb_trans2_find_mbc_encode
*
* This function encodes the mbc for one directory entry.
*
* The function returns -1 when the max data requested by client
* is reached. If the entry is valid and successful encoded, 0
* will be returned; otherwise, 1 will be returned.
*/
int /*ARGSUSED*/
int maxdata,
{
int uni_namelen;
int shortlen;
char buf83[26];
u_offset_t datasz = 0;
u_offset_t allocsz = 0;
int rc;
if (uni_namelen == -1)
return (1);
return (-1);
&lnkattr, 0, 0);
/*
* We normally want to resolve the object to which a symlink
* refers so that CIFS clients can access sub-directories and
* find the correct association for files. This causes a
* problem, however, if a symlink in a sub-directory points
* to a parent directory (some UNIX GUI's create a symlink in
* $HOME/.desktop that points to the user's home directory).
* trying to follow this recursive path and there is little
* we can do because the path is constructed on the client.
* skc_dirsymlink_enable allows an end-user to disable
* symlinks to directories. Symlinks to other object types
* should be unaffected.
*/
if (rc == 0) {
if (smb_dirsymlink_enable ||
} else {
}
}
}
if (infolev != SMB_FIND_FILE_NAMES_INFO) {
/* data size */
/* allocation size */
}
switch (infolev) {
case SMB_INFO_STANDARD:
if (fflag & SMB_FIND_RETURN_RESUME_KEYS)
break;
case SMB_INFO_QUERY_EA_SIZE:
if (fflag & SMB_FIND_RETURN_RESUME_KEYS)
0L, /* EA Size */
break;
break;
mb_flags);
return (-1);
}
sr,
0L,
break;
case SMB_FIND_FILE_NAMES_INFO:
break;
}
return (0);
}
/*
* Close a search started by a Trans2FindFirst2 request.
*/
{
int rc;
}
void
{
}
{
return (SDRC_ERROR);
}
if (smbsr_encode_empty_result(sr))
return (SDRC_ERROR);
return (SDRC_SUCCESS);
}