smb_trans2_find.c revision a1511e6b39158073666f6bd04cec5295813931f6
/*
* 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.
*/
/*
* 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
* SMB_FIND_FILE_ID_FULL_DIRECTORY_INFO 0x105
* SMB_FIND_FILE_ID_BOTH_DIRECTORY_INFO 0x106
*
* 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
*
*
* SMB_FIND_FILE_ID_FULL_DIRECTORY_INFO
*
* This is the same as SMB_FIND_FILE_FULL_DIRECTORY_INFO but with
* FileId inserted after EaSize. FileId is preceded by a 4 byte
* alignment padding.
*
* Response Field Description
* ================================= ==================================
* ...
* ULONG EaSize; Size of file's extended attributes
* UCHAR Reserved[4]
* LARGE_INTEGER FileId Internal file system unique id.
* 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
*
*
* SMB_FIND_FILE_ID_BOTH_DIRECTORY_INFO
*
* This is the same as SMB_FIND_FILE_BOTH_DIRECTORY_INFO but with
* FileId inserted after ShortName. FileId is preceded by a 2 byte
* alignment pad.
*
* Response Field Description
* ================================= ==================================
* ...
* WCHAR ShortName[12]; File's 8.3 conformant name in Unicode
* UCHAR Reserved[2]
* LARGE_INTEGER FileId Internal file system unique id.
* 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/smb_fsops.h>
typedef struct smb_find_args {
smb_fileinfo_t *, smb_find_args_t *);
/*
* Tunable parameter to limit the maximum
* number of entries to be returned.
*/
/*
* 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 count;
char *path;
smb_odir_t *od;
uint32_t odir_flags = 0;
return (SDRC_ERROR);
}
return (SDRC_ERROR);
}
if (smb_is_stream_name(path)) {
return (SDRC_ERROR);
}
}
if (args.fa_maxdata == 0)
return (SDRC_ERROR);
(void) smb_convert_wildcards(path);
if (odid == 0)
return (SDRC_ERROR);
return (SDRC_ERROR);
if (count == -1) {
return (SDRC_ERROR);
}
if (count == 0) {
return (SDRC_ERROR);
}
} /* else leave odir open for trans2_find_next2 */
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
*
*
* The last parameter in the request is a filename, which is a
* null-terminated unicode string.
*
* smb_mbc_decodef(&xa->req_param_mb, "%www lwu", sr,
* &odid, &fa_maxcount, &fa_infolev, &cookie, &fa_fflag, &fname)
*
* The filename parameter is not currently decoded because we
* expect a 2-byte null but Mac OS 10 clients send a 1-byte null,
* which leads to a decode error.
* Thus, we do not support resume by filename. We treat a request
* to resume by filename as SMB_FIND_CONTINUE_FROM_LAST.
*/
{
int count;
smb_odir_t *od;
!= 0) {
return (SDRC_ERROR);
}
/* continuation by filename not supported */
odir_resume.or_idx = 0;
} else {
}
if (args.fa_maxdata == 0)
return (SDRC_ERROR);
return (SDRC_ERROR);
}
if (count == -1) {
return (SDRC_ERROR);
}
} /* else leave odir open for trans2_find_next2 */
return (SDRC_SUCCESS);
}
/*
* smb_trans2_find_entries
*
* Find and encode up to args->fa_maxcount directory entries.
* For compatibilty with Windows, if args->fa_maxcount is zero treat it as 1.
*
* Returns:
* count - count of entries encoded
* *eos = B_TRUE if no more directory entries
* -1 - error
*/
static int
{
int rc;
maxcount = 1;
count = 0;
return (-1);
break;
if (rc == -1)
return (-1);
if (rc == 1)
break;
++count;
}
/* save the last cookie returned to client */
if (count != 0)
/* if eos not already detected, check if more entries */
if (!*eos)
return (count);
}
/*
* 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;
break;
break;
+ 2 + 8;
break;
case SMB_FIND_FILE_NAMES_INFO:
break;
4 + 32 + 4 + 1 + 1 + 24 + 4;
break;
default:
maxdata = 0;
}
return (maxdata);
}
/*
* smb_trans2_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.
*
* We always null terminate the filename. The space for the null
* is included in the maxdata calculation and is therefore included
* in the next_entry_offset. namelen is the unterminated length of
* the filename. For levels except STANDARD and EA_SIZE, if the
* filename is ascii the name length returned to the client should
* include the null terminator. Otherwise the length returned to
* the client should not include the terminator.
*
* Returns: 0 - data successfully encoded
* 1 - client request's maxdata limit reached
* -1 - error
*/
static int
{
char buf83[26];
char *tmpbuf;
if (namelen == -1)
return (-1);
return (1);
/*
* If ascii the filename length returned to the client should
* include the null terminator for levels except STANDARD and
* EASIZE.
*/
namelen += 1;
}
switch (args->fa_infolev) {
case SMB_INFO_STANDARD:
break;
case SMB_INFO_QUERY_EA_SIZE:
/*
* Unicode filename should NOT be aligned. Encode ('u')
* into a temporary buffer, then encode buffer as a
* byte stream ('#c').
* Regardless of whether unicode or ascii, a single
* termination byte is used.
*/
return (-1);
}
0L, /* EA Size */
namelen + 1,
tmpbuf);
break;
break;
0L,
break;
0L,
break;
mb_flags);
return (-1);
}
sr,
0L,
break;
mb_flags);
return (-1);
}
"%llTTTTqqlllb.24c2.qu",
sr,
0L,
break;
case SMB_FIND_FILE_NAMES_INFO:
break;
}
return (0);
}
/*
* Close a search started by a Trans2FindFirst2 request.
*/
{
return (SDRC_SUCCESS);
}
void
{
}
{
smb_odir_t *od;
return (SDRC_ERROR);
return (SDRC_ERROR);
}
if (smbsr_encode_empty_result(sr))
return (SDRC_ERROR);
return (SDRC_SUCCESS);
}