15331Samw /* 25331Samw * CDDL HEADER START 35331Samw * 45331Samw * The contents of this file are subject to the terms of the 55331Samw * Common Development and Distribution License (the "License"). 65331Samw * You may not use this file except in compliance with the License. 75331Samw * 85331Samw * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 95331Samw * or http://www.opensolaris.org/os/licensing. 105331Samw * See the License for the specific language governing permissions 115331Samw * and limitations under the License. 125331Samw * 135331Samw * When distributing Covered Code, include this CDDL HEADER in each 145331Samw * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 155331Samw * If applicable, add the following below this CDDL HEADER, with the 165331Samw * fields enclosed by brackets "[]" replaced with your own identifying 175331Samw * information: Portions Copyright [yyyy] [name of copyright owner] 185331Samw * 195331Samw * CDDL HEADER END 205331Samw */ 215331Samw /* 228670SJose.Borrego@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 235331Samw * Use is subject to license terms. 245331Samw */ 255331Samw 265331Samw 275331Samw /* 288670SJose.Borrego@Sun.COM * smb_com_search 298670SJose.Borrego@Sun.COM * smb_com_find, smb_com_find_close 308670SJose.Borrego@Sun.COM * smb_find_unique 315331Samw * 328670SJose.Borrego@Sun.COM * These commands are used for directory searching. They share the same 338670SJose.Borrego@Sun.COM * message formats, defined below: 345331Samw * 358670SJose.Borrego@Sun.COM * Client Request Description 368670SJose.Borrego@Sun.COM * ---------------------------------- --------------------------------- 375331Samw * 388670SJose.Borrego@Sun.COM * UCHAR WordCount; Count of parameter words = 2 398670SJose.Borrego@Sun.COM * USHORT MaxCount; Number of dir. entries to return 408670SJose.Borrego@Sun.COM * USHORT SearchAttributes; 418670SJose.Borrego@Sun.COM * USHORT ByteCount; Count of data bytes; min = 5 428670SJose.Borrego@Sun.COM * UCHAR BufferFormat1; 0x04 -- ASCII 438670SJose.Borrego@Sun.COM * UCHAR FileName[]; File name, may be null 448670SJose.Borrego@Sun.COM * UCHAR BufferFormat2; 0x05 -- Variable block 458670SJose.Borrego@Sun.COM * USHORT ResumeKeyLength; Length of resume key, may be 0 468670SJose.Borrego@Sun.COM * UCHAR ResumeKey[]; Resume key 475331Samw * 488670SJose.Borrego@Sun.COM * FileName specifies the file to be sought. SearchAttributes indicates 498670SJose.Borrego@Sun.COM * the attributes that the file must have. If SearchAttributes is 508670SJose.Borrego@Sun.COM * zero then only normal files are returned. If the system file, hidden or 518670SJose.Borrego@Sun.COM * directory attributes are specified then the search is inclusive - both the 528670SJose.Borrego@Sun.COM * specified type(s) of files and normal files are returned. If the volume 538670SJose.Borrego@Sun.COM * label attribute is specified then the search is exclusive, and only the 548670SJose.Borrego@Sun.COM * volume label entry is returned. 558670SJose.Borrego@Sun.COM * 568670SJose.Borrego@Sun.COM * MaxCount specifies the number of directory entries to be returned. 578670SJose.Borrego@Sun.COM * 588670SJose.Borrego@Sun.COM * Server Response Description 598670SJose.Borrego@Sun.COM * ---------------------------------- --------------------------------- 605331Samw * 618670SJose.Borrego@Sun.COM * UCHAR WordCount; Count of parameter words = 1 628670SJose.Borrego@Sun.COM * USHORT Count; Number of entries returned 638670SJose.Borrego@Sun.COM * USHORT ByteCount; Count of data bytes; min = 3 648670SJose.Borrego@Sun.COM * UCHAR BufferFormat; 0x05 -- Variable block 658670SJose.Borrego@Sun.COM * USHORT DataLength; Length of data 668670SJose.Borrego@Sun.COM * UCHAR DirectoryInformationData[]; Data 675331Samw * 688670SJose.Borrego@Sun.COM * The response will contain one or more directory entries as determined by 698670SJose.Borrego@Sun.COM * the Count field. No more than MaxCount entries will be returned. Only 708670SJose.Borrego@Sun.COM * entries that match the sought FileName and SearchAttributes combination 718670SJose.Borrego@Sun.COM * will be returned. 728670SJose.Borrego@Sun.COM * 738670SJose.Borrego@Sun.COM * ResumeKey must be null (length = 0) on the initial search request. 748670SJose.Borrego@Sun.COM * Subsequent search requests intended to continue a search must contain 758670SJose.Borrego@Sun.COM * the ResumeKey field extracted from the last directory entry of the 768670SJose.Borrego@Sun.COM * previous response. ResumeKey is self-contained, for calls containing 778670SJose.Borrego@Sun.COM * a non-zero ResumeKey neither the SearchAttributes or FileName fields 788670SJose.Borrego@Sun.COM * will be valid in the request. ResumeKey has the following format: 798670SJose.Borrego@Sun.COM * 808670SJose.Borrego@Sun.COM * Resume Key Field Description 818670SJose.Borrego@Sun.COM * ---------------------------------- --------------------------------- 825331Samw * 838670SJose.Borrego@Sun.COM * UCHAR Reserved; bit 7 - consumer use 848670SJose.Borrego@Sun.COM * bits 5,6 - system use (must preserve) 858670SJose.Borrego@Sun.COM * bits 0-4 - server use (must preserve) 868670SJose.Borrego@Sun.COM * UCHAR FileName[11]; Name of the returned file 878670SJose.Borrego@Sun.COM * UCHAR ReservedForServer[5]; Client must not modify 888670SJose.Borrego@Sun.COM * byte 0 - uniquely identifies find 898670SJose.Borrego@Sun.COM * through find_close 908670SJose.Borrego@Sun.COM * bytes 1-4 - available for server use 918670SJose.Borrego@Sun.COM * (must be non-zero) 928670SJose.Borrego@Sun.COM * UCHAR ReservedForConsumer[4]; Server must not modify 938670SJose.Borrego@Sun.COM * 948670SJose.Borrego@Sun.COM * FileName is 8.3 format, with the three character extension left 958670SJose.Borrego@Sun.COM * justified into FileName[9-11]. 965331Samw * 978670SJose.Borrego@Sun.COM * There may be multiple matching entries in response to a single request 988670SJose.Borrego@Sun.COM * as wildcards are supported in the last component of FileName of the 998670SJose.Borrego@Sun.COM * initial request. 1008670SJose.Borrego@Sun.COM * 1018670SJose.Borrego@Sun.COM * Returned directory entries in the DirectoryInformationData field of the 1028670SJose.Borrego@Sun.COM * response each have the following format: 1038670SJose.Borrego@Sun.COM * 1048670SJose.Borrego@Sun.COM * Directory Information Field Description 1058670SJose.Borrego@Sun.COM * ---------------------------------- --------------------------------- 1065331Samw * 1078670SJose.Borrego@Sun.COM * SMB_RESUME_KEY ResumeKey; Described above 1088670SJose.Borrego@Sun.COM * UCHAR FileAttributes; Attributes of the found file 1098670SJose.Borrego@Sun.COM * SMB_TIME LastWriteTime; Time file was last written 1108670SJose.Borrego@Sun.COM * SMB_DATE LastWriteDate; Date file was last written 1118670SJose.Borrego@Sun.COM * ULONG FileSize; Size of the file 1128670SJose.Borrego@Sun.COM * UCHAR FileName[13]; ASCII, space-filled null terminated 1138670SJose.Borrego@Sun.COM * 1148670SJose.Borrego@Sun.COM * FileName must conform to 8.3 rules, and is padded after the extension 1158670SJose.Borrego@Sun.COM * with 0x20 characters if necessary. 1165331Samw * 1178670SJose.Borrego@Sun.COM * As can be seen from the above structure, these commands cannot return 1188670SJose.Borrego@Sun.COM * long filenames, and cannot return UNICODE filenames. 1198670SJose.Borrego@Sun.COM * 1208670SJose.Borrego@Sun.COM * Files which have a size greater than 2^32 bytes should have the least 1218670SJose.Borrego@Sun.COM * significant 32 bits of their size returned in FileSize. 1225331Samw * 1238670SJose.Borrego@Sun.COM * smb_com_search 1248670SJose.Borrego@Sun.COM * -------------- 1258670SJose.Borrego@Sun.COM * 1268670SJose.Borrego@Sun.COM * If the client is prior to the LANMAN1.0 dialect, the returned FileName 1278670SJose.Borrego@Sun.COM * should be uppercased. 1288670SJose.Borrego@Sun.COM * If the client has negotiated a dialect prior to the LANMAN1.0 dialect, 1298670SJose.Borrego@Sun.COM * or if bit0 of the Flags2 SMB header field of the request is clear, 1308670SJose.Borrego@Sun.COM * the returned FileName should be uppercased. 1315331Samw * 1328670SJose.Borrego@Sun.COM * SMB_COM_SEARCH terminates when either the requested maximum number of 1338670SJose.Borrego@Sun.COM * entries that match the named file are found, or the end of directory is 1348670SJose.Borrego@Sun.COM * reached without the maximum number of matches being found. A response 1358670SJose.Borrego@Sun.COM * containing no entries indicates that no matching entries were found 1368670SJose.Borrego@Sun.COM * between the starting point of the search and the end of directory. 1378670SJose.Borrego@Sun.COM * 1388670SJose.Borrego@Sun.COM * 1398670SJose.Borrego@Sun.COM * The find, find_close and find_unique protocols may be used in place of 1408670SJose.Borrego@Sun.COM * the core "search" protocol when LANMAN 1.0 dialect has been negotiated. 1415331Samw * 1428670SJose.Borrego@Sun.COM * smb_com_find 1438670SJose.Borrego@Sun.COM * ------------ 1448670SJose.Borrego@Sun.COM * 1458670SJose.Borrego@Sun.COM * The find protocol is used to match the find OS/2 system call. 1468670SJose.Borrego@Sun.COM * 1478670SJose.Borrego@Sun.COM * The format of the find protocol is the same as the core "search" protocol. 1488670SJose.Borrego@Sun.COM * The difference is that the directory is logically Opened with a find protocol 1498670SJose.Borrego@Sun.COM * and logically closed with the find close protocol. 1508670SJose.Borrego@Sun.COM * As is true of a failing open, if a find request (find "first" request where 1515331Samw * resume_key is null) fails (no entries are found), no find close protocol is 1525331Samw * expected. 1535331Samw * 1548670SJose.Borrego@Sun.COM * If no global characters are present, a "find unique" protocol should be used 1555331Samw * (only one entry is expected and find close need not be sent). 1565331Samw * 1578670SJose.Borrego@Sun.COM * A find request will terminate when either the requested maximum number of 1588670SJose.Borrego@Sun.COM * entries that match the named file are found, or the end of directory is 1598670SJose.Borrego@Sun.COM * reached without the maximum number of matches being found. A response 1608670SJose.Borrego@Sun.COM * containing no entries indicates that no matching entries were found between 1618670SJose.Borrego@Sun.COM * the starting point of the search and the end of directory. 1625331Samw * 1638670SJose.Borrego@Sun.COM * If a find requests more data than can be placed in a message of the 1645331Samw * max-xmit-size for the TID specified, the server will return only the number 1655331Samw * of entries which will fit. 1665331Samw * 1678670SJose.Borrego@Sun.COM * 1688670SJose.Borrego@Sun.COM * smb_com_find_close 1698670SJose.Borrego@Sun.COM * ------------------ 1708670SJose.Borrego@Sun.COM * 1718670SJose.Borrego@Sun.COM * The find close protocol is used to match the find close OS/2 system call. 1728670SJose.Borrego@Sun.COM * 1738670SJose.Borrego@Sun.COM * Whereas the first find protocol logically opens the directory, subsequent 1748670SJose.Borrego@Sun.COM * find protocols presenting a resume_key further "read" the directory, the 1758670SJose.Borrego@Sun.COM * find close protocol "closes" the directory allowing the server to free any 1768670SJose.Borrego@Sun.COM * resources held in support of the directory search. 1775331Samw * 1788670SJose.Borrego@Sun.COM * In our implementation this translates to closing the odir. 1798670SJose.Borrego@Sun.COM * 1808670SJose.Borrego@Sun.COM * 1818670SJose.Borrego@Sun.COM * smb_com_find_unique 1828670SJose.Borrego@Sun.COM * ------------------- 1835331Samw * 1848670SJose.Borrego@Sun.COM * The format of the find unique protocol is the same as the core "search" 1858670SJose.Borrego@Sun.COM * protocol. The difference is that the directory is logically opened, any 1868670SJose.Borrego@Sun.COM * matching entries returned, and then the directory is logically closed. 1878670SJose.Borrego@Sun.COM * 1888670SJose.Borrego@Sun.COM * The resume search key key will be returned as in the find protocol and 1898670SJose.Borrego@Sun.COM * search protocol however it may NOT be returned to continue the search. 1908670SJose.Borrego@Sun.COM * Only one buffer of entries is expected and find close need not be sent. 1915331Samw * 1928670SJose.Borrego@Sun.COM * If a find unique requests more data than can be placed in a message of the 1938670SJose.Borrego@Sun.COM * max-xmit-size for the TID specified, the server will abort the virtual 1948670SJose.Borrego@Sun.COM * circuit to the consumer. 1955331Samw */ 1968670SJose.Borrego@Sun.COM 1978670SJose.Borrego@Sun.COM #include <smbsrv/smb_incl.h> 1988670SJose.Borrego@Sun.COM 1998670SJose.Borrego@Sun.COM /* *** smb_com_search *** */ 2008670SJose.Borrego@Sun.COM 2018670SJose.Borrego@Sun.COM smb_sdrc_t 2028670SJose.Borrego@Sun.COM smb_pre_search(smb_request_t *sr) 2038670SJose.Borrego@Sun.COM { 2048670SJose.Borrego@Sun.COM DTRACE_SMB_1(op__Search__start, smb_request_t *, sr); 2058670SJose.Borrego@Sun.COM return (SDRC_SUCCESS); 2068670SJose.Borrego@Sun.COM } 2078670SJose.Borrego@Sun.COM 2088670SJose.Borrego@Sun.COM void 2098670SJose.Borrego@Sun.COM smb_post_search(smb_request_t *sr) 2108670SJose.Borrego@Sun.COM { 2118670SJose.Borrego@Sun.COM DTRACE_SMB_1(op__Search__done, smb_request_t *, sr); 2128670SJose.Borrego@Sun.COM } 2138670SJose.Borrego@Sun.COM 2148670SJose.Borrego@Sun.COM smb_sdrc_t 2158670SJose.Borrego@Sun.COM smb_com_search(smb_request_t *sr) 2168670SJose.Borrego@Sun.COM { 2178670SJose.Borrego@Sun.COM int rc; 2188670SJose.Borrego@Sun.COM uint16_t count, maxcount, index; 2198670SJose.Borrego@Sun.COM uint16_t sattr, odid; 2208670SJose.Borrego@Sun.COM uint16_t key_len; 2218670SJose.Borrego@Sun.COM uint32_t client_key; 2228670SJose.Borrego@Sun.COM char name[SMB_SHORTNAMELEN]; 2238670SJose.Borrego@Sun.COM char *path; 2248670SJose.Borrego@Sun.COM unsigned char resume_char; 2258670SJose.Borrego@Sun.COM unsigned char type; 2268670SJose.Borrego@Sun.COM boolean_t find_first, to_upper; 2278670SJose.Borrego@Sun.COM smb_tree_t *tree; 2288670SJose.Borrego@Sun.COM smb_odir_t *od; 2298670SJose.Borrego@Sun.COM smb_fileinfo_t fileinfo; 2308670SJose.Borrego@Sun.COM smb_odir_resume_t odir_resume; 2318670SJose.Borrego@Sun.COM boolean_t eos; 2328670SJose.Borrego@Sun.COM 2338670SJose.Borrego@Sun.COM to_upper = B_FALSE; 2348670SJose.Borrego@Sun.COM if ((sr->session->dialect <= LANMAN1_0) || 2358670SJose.Borrego@Sun.COM ((sr->smb_flg2 & SMB_FLAGS2_KNOWS_LONG_NAMES) == 0)) { 2368670SJose.Borrego@Sun.COM to_upper = B_TRUE; 2378670SJose.Borrego@Sun.COM } 2388670SJose.Borrego@Sun.COM 2398670SJose.Borrego@Sun.COM /* We only handle 8.3 name here */ 2408670SJose.Borrego@Sun.COM sr->smb_flg2 &= ~SMB_FLAGS2_KNOWS_LONG_NAMES; 2418670SJose.Borrego@Sun.COM sr->smb_flg &= ~SMB_FLAGS_CASE_INSENSITIVE; 2428670SJose.Borrego@Sun.COM 2438670SJose.Borrego@Sun.COM if (smbsr_decode_vwv(sr, "ww", &maxcount, &sattr) != 0) 2448670SJose.Borrego@Sun.COM return (SDRC_ERROR); 2458670SJose.Borrego@Sun.COM 2468670SJose.Borrego@Sun.COM rc = smbsr_decode_data(sr, "%Abw", sr, &path, &type, &key_len); 2478670SJose.Borrego@Sun.COM if ((rc != 0) || (type != 0x05)) 2488670SJose.Borrego@Sun.COM return (SDRC_ERROR); 2498670SJose.Borrego@Sun.COM 2508670SJose.Borrego@Sun.COM tree = sr->tid_tree; 2518670SJose.Borrego@Sun.COM 2528670SJose.Borrego@Sun.COM /* Volume information only */ 2538670SJose.Borrego@Sun.COM if ((sattr == FILE_ATTRIBUTE_VOLUME) && (key_len != 21)) { 2548670SJose.Borrego@Sun.COM (void) memset(name, ' ', sizeof (name)); 2558670SJose.Borrego@Sun.COM (void) strncpy(name, tree->t_volume, sizeof (name)); 2568670SJose.Borrego@Sun.COM 2578670SJose.Borrego@Sun.COM if (key_len >= 21) { 2588670SJose.Borrego@Sun.COM (void) smb_mbc_decodef(&sr->smb_data, "17.l", 2598670SJose.Borrego@Sun.COM &client_key); 2608670SJose.Borrego@Sun.COM } else { 2618670SJose.Borrego@Sun.COM client_key = 0; 2628670SJose.Borrego@Sun.COM } 2638670SJose.Borrego@Sun.COM 2648670SJose.Borrego@Sun.COM (void) smb_mbc_encodef(&sr->reply, "bwwbwb11c5.lb8.13c", 2658670SJose.Borrego@Sun.COM 1, 0, VAR_BCC, 5, 0, 0, path+1, 2668670SJose.Borrego@Sun.COM client_key, sattr, name); 2678670SJose.Borrego@Sun.COM 2688670SJose.Borrego@Sun.COM rc = (sr->reply.chain_offset - sr->cur_reply_offset) - 8; 2698670SJose.Borrego@Sun.COM (void) smb_mbc_poke(&sr->reply, sr->cur_reply_offset, "bwwbw", 2708670SJose.Borrego@Sun.COM 1, 1, rc+3, 5, rc); 2718670SJose.Borrego@Sun.COM 2728670SJose.Borrego@Sun.COM return (SDRC_SUCCESS); 2738670SJose.Borrego@Sun.COM } 2748670SJose.Borrego@Sun.COM 2758670SJose.Borrego@Sun.COM if ((key_len != 0) && (key_len != 21)) 2768670SJose.Borrego@Sun.COM return (SDRC_ERROR); 2778670SJose.Borrego@Sun.COM 2788670SJose.Borrego@Sun.COM find_first = (key_len == 0); 2798670SJose.Borrego@Sun.COM resume_char = 0; 2808670SJose.Borrego@Sun.COM client_key = 0; 2818670SJose.Borrego@Sun.COM 2828670SJose.Borrego@Sun.COM if (find_first) { 2838670SJose.Borrego@Sun.COM /* NT interprets NULL filename as "\" */ 2848670SJose.Borrego@Sun.COM if (strlen(path) == 0) 2858670SJose.Borrego@Sun.COM path = "\\"; 2868670SJose.Borrego@Sun.COM 2879343SAfshin.Ardakani@Sun.COM odid = smb_odir_open(sr, path, sattr, 0); 2888670SJose.Borrego@Sun.COM if (odid == 0) { 2898670SJose.Borrego@Sun.COM if (sr->smb_error.status == NT_STATUS_ACCESS_DENIED) 2908670SJose.Borrego@Sun.COM smbsr_warn(sr, NT_STATUS_NO_MORE_FILES, 2918670SJose.Borrego@Sun.COM ERRDOS, ERROR_NO_MORE_FILES); 2928670SJose.Borrego@Sun.COM return (SDRC_ERROR); 2938670SJose.Borrego@Sun.COM } 2948670SJose.Borrego@Sun.COM } else { 2958670SJose.Borrego@Sun.COM if (smb_mbc_decodef(&sr->smb_data, "b12.wwl", 2968670SJose.Borrego@Sun.COM &resume_char, &index, &odid, &client_key) != 0) { 2978670SJose.Borrego@Sun.COM return (SDRC_ERROR); 2988670SJose.Borrego@Sun.COM } 2998670SJose.Borrego@Sun.COM } 3008670SJose.Borrego@Sun.COM 3018670SJose.Borrego@Sun.COM od = smb_tree_lookup_odir(sr->tid_tree, odid); 3028670SJose.Borrego@Sun.COM if (od == NULL) { 3038670SJose.Borrego@Sun.COM smbsr_error(sr, NT_STATUS_INVALID_HANDLE, 3048670SJose.Borrego@Sun.COM ERRDOS, ERROR_INVALID_HANDLE); 3058670SJose.Borrego@Sun.COM return (SDRC_ERROR); 3068670SJose.Borrego@Sun.COM } 3078670SJose.Borrego@Sun.COM 3088670SJose.Borrego@Sun.COM if (!find_first) { 3098670SJose.Borrego@Sun.COM odir_resume.or_type = SMB_ODIR_RESUME_IDX; 3108670SJose.Borrego@Sun.COM odir_resume.or_idx = index; 3118670SJose.Borrego@Sun.COM smb_odir_resume_at(od, &odir_resume); 3128670SJose.Borrego@Sun.COM } 3138670SJose.Borrego@Sun.COM 3148670SJose.Borrego@Sun.COM (void) smb_mbc_encodef(&sr->reply, "bwwbw", 1, 0, VAR_BCC, 5, 0); 3158670SJose.Borrego@Sun.COM 3168670SJose.Borrego@Sun.COM rc = 0; 3178670SJose.Borrego@Sun.COM index = 0; 3188670SJose.Borrego@Sun.COM count = 0; 3198670SJose.Borrego@Sun.COM if (maxcount > SMB_MAX_SEARCH) 3208670SJose.Borrego@Sun.COM maxcount = SMB_MAX_SEARCH; 3218670SJose.Borrego@Sun.COM 3228670SJose.Borrego@Sun.COM while (count < maxcount) { 3238670SJose.Borrego@Sun.COM rc = smb_odir_read_fileinfo(sr, od, &fileinfo, &eos); 3248670SJose.Borrego@Sun.COM if ((rc != 0 || (eos == B_TRUE))) 3258670SJose.Borrego@Sun.COM break; 3268670SJose.Borrego@Sun.COM 3278845Samw@Sun.COM (void) memset(name, ' ', sizeof (name)); 3288845Samw@Sun.COM if (*fileinfo.fi_shortname == '\0') { 3298845Samw@Sun.COM (void) strlcpy(name, fileinfo.fi_name, 3308845Samw@Sun.COM SMB_SHORTNAMELEN - 1); 3318670SJose.Borrego@Sun.COM if (to_upper) 3328845Samw@Sun.COM (void) utf8_strupr(name); 3338845Samw@Sun.COM } else { 3348845Samw@Sun.COM (void) strlcpy(name, fileinfo.fi_shortname, 3358845Samw@Sun.COM SMB_SHORTNAMELEN - 1); 3368670SJose.Borrego@Sun.COM } 3378670SJose.Borrego@Sun.COM 3388670SJose.Borrego@Sun.COM (void) smb_mbc_encodef(&sr->reply, "b8c3c.wwlbYl13c", 3398670SJose.Borrego@Sun.COM resume_char, 3408670SJose.Borrego@Sun.COM fileinfo.fi_name83, fileinfo.fi_name83+9, 3418670SJose.Borrego@Sun.COM index, odid, client_key, 3428670SJose.Borrego@Sun.COM fileinfo.fi_dosattr & 0xff, 3438670SJose.Borrego@Sun.COM smb_gmt2local(sr, fileinfo.fi_mtime.tv_sec), 3448670SJose.Borrego@Sun.COM (int32_t)fileinfo.fi_size, 3458845Samw@Sun.COM name); 3468670SJose.Borrego@Sun.COM 3478670SJose.Borrego@Sun.COM smb_odir_save_cookie(od, index, fileinfo.fi_cookie); 3488670SJose.Borrego@Sun.COM 3498670SJose.Borrego@Sun.COM count++; 3508670SJose.Borrego@Sun.COM index++; 3518670SJose.Borrego@Sun.COM } 3528670SJose.Borrego@Sun.COM 3538670SJose.Borrego@Sun.COM if (rc != 0) { 3548670SJose.Borrego@Sun.COM smb_odir_close(od); 355*9635SJoyce.McIntosh@Sun.COM smb_odir_release(od); 3568670SJose.Borrego@Sun.COM return (SDRC_ERROR); 3578670SJose.Borrego@Sun.COM } 3588670SJose.Borrego@Sun.COM 3598670SJose.Borrego@Sun.COM if (count == 0 && find_first) { 3608670SJose.Borrego@Sun.COM smb_odir_close(od); 361*9635SJoyce.McIntosh@Sun.COM smb_odir_release(od); 3628670SJose.Borrego@Sun.COM smbsr_warn(sr, NT_STATUS_NO_MORE_FILES, 3638670SJose.Borrego@Sun.COM ERRDOS, ERROR_NO_MORE_FILES); 3648670SJose.Borrego@Sun.COM return (SDRC_ERROR); 3658670SJose.Borrego@Sun.COM } 3668670SJose.Borrego@Sun.COM 3678670SJose.Borrego@Sun.COM rc = (sr->reply.chain_offset - sr->cur_reply_offset) - 8; 3688670SJose.Borrego@Sun.COM if (smb_mbc_poke(&sr->reply, sr->cur_reply_offset, "bwwbw", 3698670SJose.Borrego@Sun.COM 1, count, rc+3, 5, rc) < 0) { 3708670SJose.Borrego@Sun.COM smb_odir_close(od); 371*9635SJoyce.McIntosh@Sun.COM smb_odir_release(od); 3728670SJose.Borrego@Sun.COM return (SDRC_ERROR); 3738670SJose.Borrego@Sun.COM } 3748670SJose.Borrego@Sun.COM 375*9635SJoyce.McIntosh@Sun.COM smb_odir_release(od); 3768670SJose.Borrego@Sun.COM return (SDRC_SUCCESS); 3778670SJose.Borrego@Sun.COM } 3788670SJose.Borrego@Sun.COM 3798670SJose.Borrego@Sun.COM 3808670SJose.Borrego@Sun.COM /* *** smb_com_find *** */ 3818670SJose.Borrego@Sun.COM 3826030Sjb150015 smb_sdrc_t 3836139Sjb150015 smb_pre_find(smb_request_t *sr) 3846139Sjb150015 { 3856139Sjb150015 DTRACE_SMB_1(op__Find__start, smb_request_t *, sr); 3866139Sjb150015 return (SDRC_SUCCESS); 3876139Sjb150015 } 3886139Sjb150015 3896139Sjb150015 void 3906139Sjb150015 smb_post_find(smb_request_t *sr) 3916139Sjb150015 { 3926139Sjb150015 DTRACE_SMB_1(op__Find__done, smb_request_t *, sr); 3936139Sjb150015 } 3946139Sjb150015 3956139Sjb150015 smb_sdrc_t 3966139Sjb150015 smb_com_find(smb_request_t *sr) 3975331Samw { 3985331Samw int rc; 3998670SJose.Borrego@Sun.COM uint16_t count, maxcount, index; 4008670SJose.Borrego@Sun.COM uint16_t sattr, odid; 4018670SJose.Borrego@Sun.COM uint16_t key_len; 4028670SJose.Borrego@Sun.COM uint32_t client_key; 4038845Samw@Sun.COM char name[SMB_SHORTNAMELEN]; 4048670SJose.Borrego@Sun.COM smb_odir_t *od; 4058670SJose.Borrego@Sun.COM smb_fileinfo_t fileinfo; 4068670SJose.Borrego@Sun.COM boolean_t eos; 4078670SJose.Borrego@Sun.COM 4085331Samw char *path; 4097348SJose.Borrego@Sun.COM unsigned char resume_char; 4105331Samw unsigned char type; 4117348SJose.Borrego@Sun.COM boolean_t find_first = B_TRUE; 4128670SJose.Borrego@Sun.COM smb_odir_resume_t odir_resume; 4135331Samw 4146030Sjb150015 if (smbsr_decode_vwv(sr, "ww", &maxcount, &sattr) != 0) 4156139Sjb150015 return (SDRC_ERROR); 4165331Samw 4176030Sjb150015 rc = smbsr_decode_data(sr, "%Abw", sr, &path, &type, &key_len); 4186030Sjb150015 if ((rc != 0) || (type != 0x05)) 4196139Sjb150015 return (SDRC_ERROR); 4205331Samw 4218670SJose.Borrego@Sun.COM if ((key_len != 0) && (key_len != 21)) 4228670SJose.Borrego@Sun.COM return (SDRC_ERROR); 4238670SJose.Borrego@Sun.COM 4248670SJose.Borrego@Sun.COM find_first = (key_len == 0); 4258670SJose.Borrego@Sun.COM resume_char = 0; 4268670SJose.Borrego@Sun.COM client_key = 0; 4278670SJose.Borrego@Sun.COM 4288670SJose.Borrego@Sun.COM if (find_first) { 4299343SAfshin.Ardakani@Sun.COM odid = smb_odir_open(sr, path, sattr, 0); 4308670SJose.Borrego@Sun.COM if (odid == 0) 4316139Sjb150015 return (SDRC_ERROR); 4328670SJose.Borrego@Sun.COM } else { 4337348SJose.Borrego@Sun.COM if (smb_mbc_decodef(&sr->smb_data, "b12.wwl", 4348670SJose.Borrego@Sun.COM &resume_char, &index, &odid, &client_key) != 0) { 4356139Sjb150015 return (SDRC_ERROR); 4365331Samw } 4378670SJose.Borrego@Sun.COM } 4385331Samw 4398670SJose.Borrego@Sun.COM od = smb_tree_lookup_odir(sr->tid_tree, odid); 4408670SJose.Borrego@Sun.COM if (od == NULL) { 4418670SJose.Borrego@Sun.COM smbsr_error(sr, NT_STATUS_INVALID_HANDLE, 4428670SJose.Borrego@Sun.COM ERRDOS, ERROR_INVALID_HANDLE); 4438670SJose.Borrego@Sun.COM return (SDRC_ERROR); 4448670SJose.Borrego@Sun.COM } 4455331Samw 4468670SJose.Borrego@Sun.COM if (!find_first) { 4478670SJose.Borrego@Sun.COM odir_resume.or_type = SMB_ODIR_RESUME_IDX; 4488670SJose.Borrego@Sun.COM odir_resume.or_idx = index; 4498670SJose.Borrego@Sun.COM smb_odir_resume_at(od, &odir_resume); 4505331Samw } 4515331Samw 4527052Samw (void) smb_mbc_encodef(&sr->reply, "bwwbw", 1, 0, VAR_BCC, 5, 0); 4535331Samw 4548670SJose.Borrego@Sun.COM rc = 0; 4557348SJose.Borrego@Sun.COM index = 0; 4565331Samw count = 0; 4577348SJose.Borrego@Sun.COM if (maxcount > SMB_MAX_SEARCH) 4587348SJose.Borrego@Sun.COM maxcount = SMB_MAX_SEARCH; 4597348SJose.Borrego@Sun.COM 4605331Samw while (count < maxcount) { 4618670SJose.Borrego@Sun.COM rc = smb_odir_read_fileinfo(sr, od, &fileinfo, &eos); 4628670SJose.Borrego@Sun.COM if ((rc != 0 || (eos == B_TRUE))) 4635331Samw break; 4645331Samw 4658845Samw@Sun.COM (void) memset(name, ' ', sizeof (name)); 4668845Samw@Sun.COM if (*fileinfo.fi_shortname == '\0') { 4678845Samw@Sun.COM (void) strlcpy(name, fileinfo.fi_name, 4688845Samw@Sun.COM SMB_SHORTNAMELEN - 1); 4698845Samw@Sun.COM } else { 4708845Samw@Sun.COM (void) strlcpy(name, fileinfo.fi_shortname, 4718845Samw@Sun.COM SMB_SHORTNAMELEN - 1); 4728670SJose.Borrego@Sun.COM } 4738670SJose.Borrego@Sun.COM 4747348SJose.Borrego@Sun.COM (void) smb_mbc_encodef(&sr->reply, "b8c3c.wwlbYl13c", 4757348SJose.Borrego@Sun.COM resume_char, 4768670SJose.Borrego@Sun.COM fileinfo.fi_name83, fileinfo.fi_name83+9, 4778670SJose.Borrego@Sun.COM index, odid, client_key, 4788670SJose.Borrego@Sun.COM fileinfo.fi_dosattr & 0xff, 4798670SJose.Borrego@Sun.COM smb_gmt2local(sr, fileinfo.fi_mtime.tv_sec), 4808670SJose.Borrego@Sun.COM (int32_t)fileinfo.fi_size, 4818845Samw@Sun.COM name); 4827348SJose.Borrego@Sun.COM 4838670SJose.Borrego@Sun.COM smb_odir_save_cookie(od, index, fileinfo.fi_cookie); 4848670SJose.Borrego@Sun.COM 4855331Samw count++; 4867348SJose.Borrego@Sun.COM index++; 4875331Samw } 4885331Samw 4898670SJose.Borrego@Sun.COM if (rc != 0) { 4908670SJose.Borrego@Sun.COM smb_odir_close(od); 491*9635SJoyce.McIntosh@Sun.COM smb_odir_release(od); 4926139Sjb150015 return (SDRC_ERROR); 4935331Samw } 4945331Samw 4957348SJose.Borrego@Sun.COM if (count == 0 && find_first) { 4968670SJose.Borrego@Sun.COM smb_odir_close(od); 497*9635SJoyce.McIntosh@Sun.COM smb_odir_release(od); 4987348SJose.Borrego@Sun.COM smbsr_warn(sr, NT_STATUS_NO_MORE_FILES, 4997348SJose.Borrego@Sun.COM ERRDOS, ERROR_NO_MORE_FILES); 5006139Sjb150015 return (SDRC_ERROR); 5015331Samw } 5025331Samw 5035331Samw rc = (MBC_LENGTH(&sr->reply) - sr->cur_reply_offset) - 8; 5047052Samw if (smb_mbc_poke(&sr->reply, sr->cur_reply_offset, "bwwbw", 5056030Sjb150015 1, count, rc+3, 5, rc) < 0) { 5068670SJose.Borrego@Sun.COM smb_odir_close(od); 507*9635SJoyce.McIntosh@Sun.COM smb_odir_release(od); 5086139Sjb150015 return (SDRC_ERROR); 5095331Samw } 5105331Samw 511*9635SJoyce.McIntosh@Sun.COM smb_odir_release(od); 5126139Sjb150015 return (SDRC_SUCCESS); 5135331Samw } 5145331Samw 5158670SJose.Borrego@Sun.COM 5168670SJose.Borrego@Sun.COM /* *** smb_com_find_close *** */ 5178670SJose.Borrego@Sun.COM 5186030Sjb150015 smb_sdrc_t 5196139Sjb150015 smb_pre_find_close(smb_request_t *sr) 5206139Sjb150015 { 5216139Sjb150015 DTRACE_SMB_1(op__FindClose__start, smb_request_t *, sr); 5226139Sjb150015 return (SDRC_SUCCESS); 5236139Sjb150015 } 5246139Sjb150015 5256139Sjb150015 void 5266139Sjb150015 smb_post_find_close(smb_request_t *sr) 5276139Sjb150015 { 5286139Sjb150015 DTRACE_SMB_1(op__FindClose__done, smb_request_t *, sr); 5296139Sjb150015 } 5306139Sjb150015 5316139Sjb150015 smb_sdrc_t 5326139Sjb150015 smb_com_find_close(smb_request_t *sr) 5335331Samw { 5348670SJose.Borrego@Sun.COM int rc; 5358670SJose.Borrego@Sun.COM uint16_t maxcount, index; 5368670SJose.Borrego@Sun.COM uint16_t sattr, odid; 5378670SJose.Borrego@Sun.COM uint16_t key_len; 5388670SJose.Borrego@Sun.COM uint32_t client_key; 5398670SJose.Borrego@Sun.COM char *path; 5408670SJose.Borrego@Sun.COM unsigned char resume_char; 5418670SJose.Borrego@Sun.COM unsigned char type; 5428670SJose.Borrego@Sun.COM smb_odir_t *od; 5435331Samw 5446030Sjb150015 if (smbsr_decode_vwv(sr, "ww", &maxcount, &sattr) != 0) 5456139Sjb150015 return (SDRC_ERROR); 5465331Samw 5475331Samw rc = smbsr_decode_data(sr, "%Abw", sr, &path, &type, &key_len); 5486030Sjb150015 if ((rc != 0) || (type != 0x05)) 5496139Sjb150015 return (SDRC_ERROR); 5505331Samw 5518670SJose.Borrego@Sun.COM if (key_len == 0) { 5528670SJose.Borrego@Sun.COM smbsr_error(sr, NT_STATUS_INVALID_HANDLE, 5538670SJose.Borrego@Sun.COM ERRDOS, ERROR_INVALID_HANDLE); 5548670SJose.Borrego@Sun.COM return (SDRC_ERROR); 5558670SJose.Borrego@Sun.COM } else if (key_len != 21) { 5568670SJose.Borrego@Sun.COM return (SDRC_ERROR); 5578670SJose.Borrego@Sun.COM } 5588670SJose.Borrego@Sun.COM 5598670SJose.Borrego@Sun.COM odid = 0; 5608670SJose.Borrego@Sun.COM if (smb_mbc_decodef(&sr->smb_data, "b12.wwl", 5618670SJose.Borrego@Sun.COM &resume_char, &index, &odid, &client_key) != 0) { 5628670SJose.Borrego@Sun.COM return (SDRC_ERROR); 5638670SJose.Borrego@Sun.COM } 5648670SJose.Borrego@Sun.COM 5658670SJose.Borrego@Sun.COM od = smb_tree_lookup_odir(sr->tid_tree, odid); 5668670SJose.Borrego@Sun.COM if (od == NULL) { 5678670SJose.Borrego@Sun.COM smbsr_error(sr, NT_STATUS_INVALID_HANDLE, 5688670SJose.Borrego@Sun.COM ERRDOS, ERROR_INVALID_HANDLE); 5696139Sjb150015 return (SDRC_ERROR); 5705331Samw } 5715331Samw 572*9635SJoyce.McIntosh@Sun.COM smb_odir_close(od); 5738670SJose.Borrego@Sun.COM smb_odir_release(od); 5748670SJose.Borrego@Sun.COM 5758670SJose.Borrego@Sun.COM if (smbsr_encode_result(sr, 1, 3, "bwwbw", 1, 0, 3, 5, 0)) 5768670SJose.Borrego@Sun.COM return (SDRC_ERROR); 5778670SJose.Borrego@Sun.COM 5788670SJose.Borrego@Sun.COM return (SDRC_SUCCESS); 5798670SJose.Borrego@Sun.COM } 5808670SJose.Borrego@Sun.COM 5818670SJose.Borrego@Sun.COM 5828670SJose.Borrego@Sun.COM /* *** smb_com_find_unique *** */ 5838670SJose.Borrego@Sun.COM 5848670SJose.Borrego@Sun.COM smb_sdrc_t 5858670SJose.Borrego@Sun.COM smb_pre_find_unique(smb_request_t *sr) 5868670SJose.Borrego@Sun.COM { 5878670SJose.Borrego@Sun.COM DTRACE_SMB_1(op__FindUnique__start, smb_request_t *, sr); 5888670SJose.Borrego@Sun.COM return (SDRC_SUCCESS); 5898670SJose.Borrego@Sun.COM } 5908670SJose.Borrego@Sun.COM 5918670SJose.Borrego@Sun.COM void 5928670SJose.Borrego@Sun.COM smb_post_find_unique(smb_request_t *sr) 5938670SJose.Borrego@Sun.COM { 5948670SJose.Borrego@Sun.COM DTRACE_SMB_1(op__FindUnique__done, smb_request_t *, sr); 5958670SJose.Borrego@Sun.COM } 5968670SJose.Borrego@Sun.COM 5978670SJose.Borrego@Sun.COM smb_sdrc_t 5988670SJose.Borrego@Sun.COM smb_com_find_unique(struct smb_request *sr) 5998670SJose.Borrego@Sun.COM { 6008670SJose.Borrego@Sun.COM int rc; 6018670SJose.Borrego@Sun.COM uint16_t count, maxcount, index; 6028670SJose.Borrego@Sun.COM uint16_t sattr, odid; 6038670SJose.Borrego@Sun.COM char *path; 6048670SJose.Borrego@Sun.COM unsigned char resume_char = '\0'; 6058670SJose.Borrego@Sun.COM uint32_t client_key = 0; 6068845Samw@Sun.COM char name[SMB_SHORTNAMELEN]; 6078670SJose.Borrego@Sun.COM smb_odir_t *od; 6088670SJose.Borrego@Sun.COM smb_fileinfo_t fileinfo; 6098670SJose.Borrego@Sun.COM boolean_t eos; 6108934SJose.Borrego@Sun.COM smb_vdb_t *vdb; 6118670SJose.Borrego@Sun.COM 6128670SJose.Borrego@Sun.COM if (smbsr_decode_vwv(sr, "ww", &maxcount, &sattr) != 0) 6138670SJose.Borrego@Sun.COM return (SDRC_ERROR); 6148670SJose.Borrego@Sun.COM 6158934SJose.Borrego@Sun.COM vdb = kmem_alloc(sizeof (smb_vdb_t), KM_SLEEP); 6168670SJose.Borrego@Sun.COM if ((smbsr_decode_data(sr, "%AV", sr, &path, vdb) != 0) || 6178934SJose.Borrego@Sun.COM (vdb->vdb_len != 0)) { 6188934SJose.Borrego@Sun.COM kmem_free(vdb, sizeof (smb_vdb_t)); 6198670SJose.Borrego@Sun.COM return (SDRC_ERROR); 6208670SJose.Borrego@Sun.COM } 6218934SJose.Borrego@Sun.COM kmem_free(vdb, sizeof (smb_vdb_t)); 6228670SJose.Borrego@Sun.COM 6238670SJose.Borrego@Sun.COM (void) smb_mbc_encodef(&sr->reply, "bwwbw", 1, 0, VAR_BCC, 5, 0); 6248670SJose.Borrego@Sun.COM 6259343SAfshin.Ardakani@Sun.COM odid = smb_odir_open(sr, path, sattr, 0); 6268670SJose.Borrego@Sun.COM if (odid == 0) 6278670SJose.Borrego@Sun.COM return (SDRC_ERROR); 6288670SJose.Borrego@Sun.COM od = smb_tree_lookup_odir(sr->tid_tree, odid); 6298670SJose.Borrego@Sun.COM if (od == NULL) 6308670SJose.Borrego@Sun.COM return (SDRC_ERROR); 6318670SJose.Borrego@Sun.COM 6328670SJose.Borrego@Sun.COM rc = 0; 6338670SJose.Borrego@Sun.COM count = 0; 6348670SJose.Borrego@Sun.COM index = 0; 6358670SJose.Borrego@Sun.COM if (maxcount > SMB_MAX_SEARCH) 6368670SJose.Borrego@Sun.COM maxcount = SMB_MAX_SEARCH; 6378670SJose.Borrego@Sun.COM 6388670SJose.Borrego@Sun.COM while (count < maxcount) { 6398670SJose.Borrego@Sun.COM rc = smb_odir_read_fileinfo(sr, od, &fileinfo, &eos); 6408670SJose.Borrego@Sun.COM if ((rc != 0 || (eos == B_TRUE))) 6418670SJose.Borrego@Sun.COM break; 6428670SJose.Borrego@Sun.COM 6438845Samw@Sun.COM (void) memset(name, ' ', sizeof (name)); 6448845Samw@Sun.COM if (*fileinfo.fi_shortname == '\0') { 6458845Samw@Sun.COM (void) strlcpy(name, fileinfo.fi_name, 6468845Samw@Sun.COM SMB_SHORTNAMELEN - 1); 6478845Samw@Sun.COM } else { 6488845Samw@Sun.COM (void) strlcpy(name, fileinfo.fi_shortname, 6498845Samw@Sun.COM SMB_SHORTNAMELEN - 1); 6505331Samw } 6515331Samw 6528670SJose.Borrego@Sun.COM (void) smb_mbc_encodef(&sr->reply, "b8c3c.wwlbYl13c", 6538670SJose.Borrego@Sun.COM resume_char, 6548670SJose.Borrego@Sun.COM fileinfo.fi_name83, fileinfo.fi_name83+9, 6558670SJose.Borrego@Sun.COM index, odid, client_key, 6568670SJose.Borrego@Sun.COM fileinfo.fi_dosattr & 0xff, 6578670SJose.Borrego@Sun.COM smb_gmt2local(sr, fileinfo.fi_mtime.tv_sec), 6588670SJose.Borrego@Sun.COM (int32_t)fileinfo.fi_size, 6598845Samw@Sun.COM name); 6608670SJose.Borrego@Sun.COM 6618670SJose.Borrego@Sun.COM count++; 6628670SJose.Borrego@Sun.COM index++; 6638670SJose.Borrego@Sun.COM } 6648670SJose.Borrego@Sun.COM 665*9635SJoyce.McIntosh@Sun.COM smb_odir_close(od); 6668670SJose.Borrego@Sun.COM smb_odir_release(od); 6678670SJose.Borrego@Sun.COM 6688670SJose.Borrego@Sun.COM if (rc != 0) 6698670SJose.Borrego@Sun.COM return (SDRC_ERROR); 6708670SJose.Borrego@Sun.COM 6718670SJose.Borrego@Sun.COM if (count == 0) { 6728670SJose.Borrego@Sun.COM smbsr_warn(sr, NT_STATUS_NO_MORE_FILES, 6738670SJose.Borrego@Sun.COM ERRDOS, ERROR_NO_MORE_FILES); 6746139Sjb150015 return (SDRC_ERROR); 6755331Samw } 6765331Samw 6778670SJose.Borrego@Sun.COM rc = (MBC_LENGTH(&sr->reply) - sr->cur_reply_offset) - 8; 6788670SJose.Borrego@Sun.COM if (smb_mbc_poke(&sr->reply, sr->cur_reply_offset, 6798670SJose.Borrego@Sun.COM "bwwbw", 1, count, rc+3, 5, rc) < 0) { 6806139Sjb150015 return (SDRC_ERROR); 6818670SJose.Borrego@Sun.COM } 6828670SJose.Borrego@Sun.COM 6836139Sjb150015 return (SDRC_SUCCESS); 6845331Samw } 685