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 * General Structures Layout 285331Samw * ------------------------- 295331Samw * 305331Samw * This is a simplified diagram showing the relationship between most of the 315331Samw * main structures. 325331Samw * 335331Samw * +-------------------+ 345331Samw * | SMB_INFO | 355331Samw * +-------------------+ 365331Samw * | 375331Samw * | 385331Samw * v 395331Samw * +-------------------+ +-------------------+ +-------------------+ 405331Samw * | SESSION |<----->| SESSION |......| SESSION | 415331Samw * +-------------------+ +-------------------+ +-------------------+ 425331Samw * | 435331Samw * | 445331Samw * v 455331Samw * +-------------------+ +-------------------+ +-------------------+ 465331Samw * | USER |<----->| USER |......| USER | 475331Samw * +-------------------+ +-------------------+ +-------------------+ 485331Samw * | 495331Samw * | 505331Samw * v 515331Samw * +-------------------+ +-------------------+ +-------------------+ 525331Samw * | TREE |<----->| TREE |......| TREE | 535331Samw * +-------------------+ +-------------------+ +-------------------+ 545331Samw * | | 555331Samw * | | 565331Samw * | v 575331Samw * | +-------+ +-------+ +-------+ 585331Samw * | | OFILE |<----->| OFILE |......| OFILE | 595331Samw * | +-------+ +-------+ +-------+ 605331Samw * | 615331Samw * | 625331Samw * v 635331Samw * +-------+ +------+ +------+ 645331Samw * | ODIR |<----->| ODIR |......| ODIR | 655331Samw * +-------+ +------+ +------+ 665331Samw * 675331Samw * 685331Samw * Odir State Machine 695331Samw * ------------------ 705331Samw * 718670SJose.Borrego@Sun.COM * +-------------------------+ 728670SJose.Borrego@Sun.COM * | SMB_ODIR_STATE_OPEN |<----------- open / creation 735331Samw * +-------------------------+ 749635SJoyce.McIntosh@Sun.COM * | ^ 759635SJoyce.McIntosh@Sun.COM * | (first) | (last) 769635SJoyce.McIntosh@Sun.COM * | lookup | release 779635SJoyce.McIntosh@Sun.COM * v | 788670SJose.Borrego@Sun.COM * +-------------------------+ 799635SJoyce.McIntosh@Sun.COM * | SMB_ODIR_STATE_IN_USE |---- 809635SJoyce.McIntosh@Sun.COM * +-------------------------+ | lookup / release / read 819635SJoyce.McIntosh@Sun.COM * | ^------- 829635SJoyce.McIntosh@Sun.COM * | close 839635SJoyce.McIntosh@Sun.COM * | 849635SJoyce.McIntosh@Sun.COM * v 858670SJose.Borrego@Sun.COM * +-------------------------+ 869635SJoyce.McIntosh@Sun.COM * | SMB_ODIR_STATE_CLOSING |---- 879635SJoyce.McIntosh@Sun.COM * +-------------------------+ | close / release / read 889635SJoyce.McIntosh@Sun.COM * | ^------- 899635SJoyce.McIntosh@Sun.COM * | (last) release 909635SJoyce.McIntosh@Sun.COM * | 919635SJoyce.McIntosh@Sun.COM * v 925331Samw * +-------------------------+ 938670SJose.Borrego@Sun.COM * | SMB_ODIR_STATE_CLOSED |----------> deletion 945331Samw * +-------------------------+ 955331Samw * 968670SJose.Borrego@Sun.COM * 975331Samw * SMB_ODIR_STATE_OPEN 989635SJoyce.McIntosh@Sun.COM * - the odir exists in the list of odirs of its tree 999635SJoyce.McIntosh@Sun.COM * - lookup is valid in this state. It will place a hold on the odir 1009635SJoyce.McIntosh@Sun.COM * by incrementing the reference count and the odir will transition 1019635SJoyce.McIntosh@Sun.COM * to SMB_ODIR_STATE_IN_USE 1029635SJoyce.McIntosh@Sun.COM * - read/close/release not valid in this state 1039635SJoyce.McIntosh@Sun.COM * 1049635SJoyce.McIntosh@Sun.COM * SMB_ODIR_STATE_IN_USE 1058670SJose.Borrego@Sun.COM * - the odir exists in the list of odirs of its tree. 1069635SJoyce.McIntosh@Sun.COM * - lookup is valid in this state. It will place a hold on the odir 1079635SJoyce.McIntosh@Sun.COM * by incrementing the reference count. 1089635SJoyce.McIntosh@Sun.COM * - if the last hold is released the odir will transition 1099635SJoyce.McIntosh@Sun.COM * back to SMB_ODIR_STATE_OPEN 1108670SJose.Borrego@Sun.COM * - if a close is received the odir will transition to 1118670SJose.Borrego@Sun.COM * SMB_ODIR_STATE_CLOSING. 1125331Samw * 1135331Samw * SMB_ODIR_STATE_CLOSING 1148670SJose.Borrego@Sun.COM * - the odir exists in the list of odirs of its tree. 1159635SJoyce.McIntosh@Sun.COM * - lookup will fail in this state. 1169635SJoyce.McIntosh@Sun.COM * - when the last hold is released the odir will transition 1179635SJoyce.McIntosh@Sun.COM * to SMB_ODIR_STATE_CLOSED. 1185331Samw * 1195331Samw * SMB_ODIR_STATE_CLOSED 1208670SJose.Borrego@Sun.COM * - the odir exists in the list of odirs of its tree. 1218670SJose.Borrego@Sun.COM * - there are no users of the odir (refcnt == 0) 1228670SJose.Borrego@Sun.COM * - the odir is being removed from the tree's list and deleted. 1239635SJoyce.McIntosh@Sun.COM * - lookup will fail in this state. 1249635SJoyce.McIntosh@Sun.COM * - read/close/release not valid in this state 1255331Samw * 1265331Samw * Comments 1275331Samw * -------- 1285331Samw * The state machine of the odir structures is controlled by 3 elements: 1295331Samw * - The list of odirs of the tree it belongs to. 1305331Samw * - The mutex embedded in the structure itself. 1315331Samw * - The reference count. 1325331Samw * 1335331Samw * There's a mutex embedded in the odir structure used to protect its fields 1345331Samw * and there's a lock embedded in the list of odirs of a tree. To 1355331Samw * increment or to decrement the reference count the mutex must be entered. 1365331Samw * To insert the odir into the list of odirs of the tree and to remove 1375331Samw * the odir from it, the lock must be entered in RW_WRITER mode. 1385331Samw * 1398670SJose.Borrego@Sun.COM * In order to avoid deadlocks, when both (mutex and lock of the odir 1408670SJose.Borrego@Sun.COM * list) have to be entered, the lock must be entered first. 1418670SJose.Borrego@Sun.COM * 1428670SJose.Borrego@Sun.COM * 1438670SJose.Borrego@Sun.COM * Odir Interface 1448670SJose.Borrego@Sun.COM * --------------- 1458670SJose.Borrego@Sun.COM * odid = smb_odir_open(pathname) 1468670SJose.Borrego@Sun.COM * Create an odir representing the directory specified in pathname and 1478670SJose.Borrego@Sun.COM * add it into the tree's list of odirs. 1488670SJose.Borrego@Sun.COM * Return an identifier (odid) uniquely identifying the created odir. 1495331Samw * 1508670SJose.Borrego@Sun.COM * smb_odir_openat(smb_node_t *unode) 1518670SJose.Borrego@Sun.COM * Create an odir representing the extended attribute directory 1528670SJose.Borrego@Sun.COM * associated with the file (or directory) represented by unode 1538670SJose.Borrego@Sun.COM * and add it into the tree's list of odirs. 1548670SJose.Borrego@Sun.COM * Return an identifier (odid) uniquely identifying the created odir. 1558670SJose.Borrego@Sun.COM * 1568670SJose.Borrego@Sun.COM * smb_odir_t *odir = smb_tree_lookup_odir(odid) 1578670SJose.Borrego@Sun.COM * Find the odir corresponding to the specified odid in the tree's 1589635SJoyce.McIntosh@Sun.COM * list of odirs. Place a hold on the odir. 1598670SJose.Borrego@Sun.COM * 1608670SJose.Borrego@Sun.COM * smb_odir_read(..., smb_odirent_t *odirent) 1618670SJose.Borrego@Sun.COM * Find the next directory entry in the odir and return it in odirent. 1625331Samw * 1638670SJose.Borrego@Sun.COM * smb_odir_read_fileinfo(..., smb_fileinfo_t *) 1648670SJose.Borrego@Sun.COM * Find the next directory entry in the odir. Return the details of 1658670SJose.Borrego@Sun.COM * the directory entry in smb_fileinfo_t. (See odir internals below) 1668670SJose.Borrego@Sun.COM * 16710001SJoyce.McIntosh@Sun.COM * smb_odir_read_streaminfo(..., smb_streaminfo_t *) 1688670SJose.Borrego@Sun.COM * Find the next named stream entry in the odir. Return the details of 1698670SJose.Borrego@Sun.COM * the named stream in smb_streaminfo_t. 1708670SJose.Borrego@Sun.COM * 1719635SJoyce.McIntosh@Sun.COM * smb_odir_close(smb_odir_t *odir) 1729635SJoyce.McIntosh@Sun.COM * Close the odir. 1739635SJoyce.McIntosh@Sun.COM * The caller of close must have a hold on the odir being closed. 1749635SJoyce.McIntosh@Sun.COM * The hold should be released after closing. 1759635SJoyce.McIntosh@Sun.COM * 1768670SJose.Borrego@Sun.COM * smb_odir_release(smb_odir_t *odir) 1778670SJose.Borrego@Sun.COM * Release the hold on the odir, obtained by lookup. 1788670SJose.Borrego@Sun.COM * 1798670SJose.Borrego@Sun.COM * 1808670SJose.Borrego@Sun.COM * Odir Internals 1818670SJose.Borrego@Sun.COM * -------------- 1828670SJose.Borrego@Sun.COM * The odir object represent an open directory search. Each read operation 1838670SJose.Borrego@Sun.COM * provides the caller with a structure containing information pertaining 1848670SJose.Borrego@Sun.COM * to the next directory entry that matches the search criteria, namely 1858670SJose.Borrego@Sun.COM * the filename or match pattern and, in the case of smb_odir_read_fileinfo(), 1868670SJose.Borrego@Sun.COM * the search attributes. 1878670SJose.Borrego@Sun.COM * 1888670SJose.Borrego@Sun.COM * The odir maintains a buffer (d_buf) of directory entries read from 1898670SJose.Borrego@Sun.COM * the filesystem via a vop_readdir. The buffer is populated when a read 1908670SJose.Borrego@Sun.COM * request (smb_odir_next_odirent) finds that the buffer is empty or that 1918670SJose.Borrego@Sun.COM * the end of the buffer has been reached, and also when a new client request 1928670SJose.Borrego@Sun.COM * (find next) begins. 1935331Samw * 1948670SJose.Borrego@Sun.COM * The data in d_buf (that which is returned from the file system) can 1958670SJose.Borrego@Sun.COM * be in one of two formats. If the file system supports extended directory 1968670SJose.Borrego@Sun.COM * entries we request that the data be returned as edirent_t structures. If 1978670SJose.Borrego@Sun.COM * it does not the data will be returned as dirent64_t structures. For 1988670SJose.Borrego@Sun.COM * convenience, when the next directory entry is read from d_buf by 1998670SJose.Borrego@Sun.COM * smb_odir_next_odirent it is translated into an smb_odirent_t. 2008670SJose.Borrego@Sun.COM * 2018670SJose.Borrego@Sun.COM * smb_odir_read_fileinfo 2028670SJose.Borrego@Sun.COM * The processing required to obtain the information to populate the caller's 2038670SJose.Borrego@Sun.COM * smb_fileinfo_t differs depending upon whether the directory search is for a 2048670SJose.Borrego@Sun.COM * single specified filename or for multiple files matching a search pattern. 2058670SJose.Borrego@Sun.COM * Thus smb_odir_read_fileinfo uses two static functions: 2068670SJose.Borrego@Sun.COM * smb_odir_single_fileinfo - obtains the smb_fileinfo_t info for the single 2078670SJose.Borrego@Sun.COM * filename as specified in smb_odir_open request. 2088670SJose.Borrego@Sun.COM * smb_odir_wildcard_fileinfo - obtains the smb_fileinfo_t info for the filename 2098670SJose.Borrego@Sun.COM * returned from the smb_odir_next_odirent. This is called in a loop until 2108670SJose.Borrego@Sun.COM * an entry matching the search criteria is found or no more entries exist. 2118670SJose.Borrego@Sun.COM * 2128670SJose.Borrego@Sun.COM * If a directory entry is a VLNK, the name returned in the smb_fileinfo_t 2138670SJose.Borrego@Sun.COM * is the name of the directory entry but the attributes are the attribites 2148670SJose.Borrego@Sun.COM * of the file that is the target of the link. If the link target cannot 2158670SJose.Borrego@Sun.COM * be found the attributes returned are the attributes of the link itself. 2165331Samw * 21710001SJoyce.McIntosh@Sun.COM * smb_odir_read_streaminfo 2188670SJose.Borrego@Sun.COM * In order for an odir to provide information about stream files it 2198670SJose.Borrego@Sun.COM * must be opened with smb_odir_openat(). smb_odir_read_streaminfo() can 2208670SJose.Borrego@Sun.COM * then be used to obtain the name and size of named stream files. 2215331Samw * 2228670SJose.Borrego@Sun.COM * Resuming a Search 2238670SJose.Borrego@Sun.COM * ----------------- 2248670SJose.Borrego@Sun.COM * A directory search often consists of multiple client requests: an initial 2258670SJose.Borrego@Sun.COM * find_first request followed by zero or more find_next requests and a 2268670SJose.Borrego@Sun.COM * find_close request. 2278670SJose.Borrego@Sun.COM * The find_first request will open and lookup the odir, read its desired 2288670SJose.Borrego@Sun.COM * number of entries from the odir, then release the odir and return. 2298670SJose.Borrego@Sun.COM * A find_next request will lookup the odir and read its desired number of 2308670SJose.Borrego@Sun.COM * entries from the odir, then release the odir and return. 2318670SJose.Borrego@Sun.COM * At the end of the search the find_close request will close the odir. 2328670SJose.Borrego@Sun.COM * 2338670SJose.Borrego@Sun.COM * In order to be able to resume a directory search (find_next) the odir 2348670SJose.Borrego@Sun.COM * provides the capability for the caller to save one or more resume points 2358670SJose.Borrego@Sun.COM * (cookies) at the end of a request, and to specify which resume point 2368670SJose.Borrego@Sun.COM * (cookie) to restart from at the beginning of the next search. 2378670SJose.Borrego@Sun.COM * smb_odir_save_cookie(..., cookie) 2388670SJose.Borrego@Sun.COM * smb_odir_resume_at(smb_odir_resume_t *resume) 2398670SJose.Borrego@Sun.COM * A search can be resumed at a specified resume point (cookie), the resume 2408670SJose.Borrego@Sun.COM * point (cookie) stored at a specified index in the d_cookies array, or 2418670SJose.Borrego@Sun.COM * a specified filename. The latter (specified filename) is not yet supported. 2428670SJose.Borrego@Sun.COM * 2438670SJose.Borrego@Sun.COM * See smb_search, smb_find, smb_find_unique, and smb_trans2_find for details 2445331Samw */ 2458670SJose.Borrego@Sun.COM 2465331Samw #include <smbsrv/smb_kproto.h> 2475331Samw #include <smbsrv/smb_fsops.h> 24810504SKeyur.Desai@Sun.COM #include <smbsrv/smb_share.h> 2498670SJose.Borrego@Sun.COM #include <sys/extdirent.h> 2505331Samw 2518670SJose.Borrego@Sun.COM /* static functions */ 2528670SJose.Borrego@Sun.COM static smb_odir_t *smb_odir_create(smb_request_t *, smb_node_t *, 2539343SAfshin.Ardakani@Sun.COM char *, uint16_t, cred_t *); 2548670SJose.Borrego@Sun.COM static void smb_odir_delete(smb_odir_t *); 2558670SJose.Borrego@Sun.COM static int smb_odir_single_fileinfo(smb_request_t *, smb_odir_t *, 2568670SJose.Borrego@Sun.COM smb_fileinfo_t *); 2578670SJose.Borrego@Sun.COM static int smb_odir_wildcard_fileinfo(smb_request_t *, smb_odir_t *, 2588670SJose.Borrego@Sun.COM smb_odirent_t *, smb_fileinfo_t *); 2598670SJose.Borrego@Sun.COM static int smb_odir_next_odirent(smb_odir_t *, smb_odirent_t *); 26010001SJoyce.McIntosh@Sun.COM static boolean_t smb_odir_lookup_link(smb_request_t *, smb_odir_t *, 26110001SJoyce.McIntosh@Sun.COM char *, smb_node_t **); 2625331Samw 2635331Samw 2645331Samw /* 2655331Samw * smb_odir_open 2668670SJose.Borrego@Sun.COM * 2678670SJose.Borrego@Sun.COM * Create an odir representing the directory specified in pathname. 2688670SJose.Borrego@Sun.COM * 2698670SJose.Borrego@Sun.COM * Returns: 2708670SJose.Borrego@Sun.COM * odid - Unique identifier of newly created odir. 2718670SJose.Borrego@Sun.COM * 0 - error, error details set in sr. 2725331Samw */ 2738670SJose.Borrego@Sun.COM uint16_t 2749343SAfshin.Ardakani@Sun.COM smb_odir_open(smb_request_t *sr, char *path, uint16_t sattr, uint32_t flags) 2755331Samw { 2768670SJose.Borrego@Sun.COM int rc; 2778670SJose.Borrego@Sun.COM smb_tree_t *tree; 2788670SJose.Borrego@Sun.COM smb_node_t *dnode; 2798670SJose.Borrego@Sun.COM char pattern[MAXNAMELEN]; 2808670SJose.Borrego@Sun.COM smb_odir_t *od; 2819343SAfshin.Ardakani@Sun.COM cred_t *cr; 2825331Samw 2838670SJose.Borrego@Sun.COM ASSERT(sr); 2848670SJose.Borrego@Sun.COM ASSERT(sr->sr_magic == SMB_REQ_MAGIC); 2858670SJose.Borrego@Sun.COM ASSERT(sr->tid_tree); 2868670SJose.Borrego@Sun.COM ASSERT(sr->tid_tree->t_magic == SMB_TREE_MAGIC); 2875331Samw 2888670SJose.Borrego@Sun.COM tree = sr->tid_tree; 2898670SJose.Borrego@Sun.COM 290*11337SWilliam.Krier@Sun.COM smb_convert_wildcards(path); 291*11337SWilliam.Krier@Sun.COM 2928670SJose.Borrego@Sun.COM rc = smb_pathname_reduce(sr, sr->user_cr, path, 2938670SJose.Borrego@Sun.COM tree->t_snode, tree->t_snode, &dnode, pattern); 2948670SJose.Borrego@Sun.COM if (rc != 0) { 2958670SJose.Borrego@Sun.COM smbsr_errno(sr, rc); 2968670SJose.Borrego@Sun.COM return (0); 2975331Samw } 2985331Samw 2998670SJose.Borrego@Sun.COM if (dnode->vp->v_type != VDIR) { 3008670SJose.Borrego@Sun.COM smbsr_error(sr, NT_STATUS_OBJECT_PATH_NOT_FOUND, 3018670SJose.Borrego@Sun.COM ERRDOS, ERROR_PATH_NOT_FOUND); 3028670SJose.Borrego@Sun.COM smb_node_release(dnode); 3038670SJose.Borrego@Sun.COM return (0); 3045331Samw } 3055331Samw 3068670SJose.Borrego@Sun.COM if (smb_fsop_access(sr, sr->user_cr, dnode, FILE_LIST_DIRECTORY) != 0) { 3078670SJose.Borrego@Sun.COM smbsr_error(sr, NT_STATUS_ACCESS_DENIED, 3088670SJose.Borrego@Sun.COM ERRDOS, ERROR_ACCESS_DENIED); 3098670SJose.Borrego@Sun.COM smb_node_release(dnode); 3108670SJose.Borrego@Sun.COM return (0); 3118670SJose.Borrego@Sun.COM } 3125331Samw 3139343SAfshin.Ardakani@Sun.COM if (flags & SMB_ODIR_OPENF_BACKUP_INTENT) 3149343SAfshin.Ardakani@Sun.COM cr = smb_user_getprivcred(tree->t_user); 3159343SAfshin.Ardakani@Sun.COM else 3169343SAfshin.Ardakani@Sun.COM cr = tree->t_user->u_cred; 3179343SAfshin.Ardakani@Sun.COM 3189343SAfshin.Ardakani@Sun.COM od = smb_odir_create(sr, dnode, pattern, sattr, cr); 3198670SJose.Borrego@Sun.COM smb_node_release(dnode); 3208670SJose.Borrego@Sun.COM return (od ? od->d_odid : 0); 3215331Samw } 3225331Samw 3235331Samw /* 3248670SJose.Borrego@Sun.COM * smb_odir_openat 3258670SJose.Borrego@Sun.COM * 3268670SJose.Borrego@Sun.COM * Create an odir representing the extended attribute directory 3278670SJose.Borrego@Sun.COM * associated with the file (or directory) represented by unode. 3288670SJose.Borrego@Sun.COM * 3298670SJose.Borrego@Sun.COM * Returns: 3308670SJose.Borrego@Sun.COM * odid - Unique identifier of newly created odir. 3318670SJose.Borrego@Sun.COM * 0 - error, error details set in sr. 3328670SJose.Borrego@Sun.COM */ 3338670SJose.Borrego@Sun.COM uint16_t 3348670SJose.Borrego@Sun.COM smb_odir_openat(smb_request_t *sr, smb_node_t *unode) 3358670SJose.Borrego@Sun.COM { 3368670SJose.Borrego@Sun.COM int rc; 3378670SJose.Borrego@Sun.COM vnode_t *xattr_dvp; 3388670SJose.Borrego@Sun.COM smb_odir_t *od; 3398670SJose.Borrego@Sun.COM cred_t *cr; 3408670SJose.Borrego@Sun.COM char pattern[SMB_STREAM_PREFIX_LEN + 2]; 3418670SJose.Borrego@Sun.COM 3428670SJose.Borrego@Sun.COM smb_node_t *xattr_dnode; 3438670SJose.Borrego@Sun.COM 3448670SJose.Borrego@Sun.COM ASSERT(sr); 3458670SJose.Borrego@Sun.COM ASSERT(sr->sr_magic == SMB_REQ_MAGIC); 3468670SJose.Borrego@Sun.COM ASSERT(unode); 3478670SJose.Borrego@Sun.COM ASSERT(unode->n_magic == SMB_NODE_MAGIC); 3488670SJose.Borrego@Sun.COM 3498845Samw@Sun.COM if (SMB_TREE_CONTAINS_NODE(sr, unode) == 0 || 3508845Samw@Sun.COM SMB_TREE_HAS_ACCESS(sr, ACE_LIST_DIRECTORY) == 0) { 3518670SJose.Borrego@Sun.COM smbsr_error(sr, NT_STATUS_ACCESS_DENIED, 3528670SJose.Borrego@Sun.COM ERRDOS, ERROR_ACCESS_DENIED); 3538670SJose.Borrego@Sun.COM return (0); 3548670SJose.Borrego@Sun.COM } 3559343SAfshin.Ardakani@Sun.COM cr = kcred; 3568670SJose.Borrego@Sun.COM 3578670SJose.Borrego@Sun.COM /* find the xattrdir vnode */ 3588670SJose.Borrego@Sun.COM rc = smb_vop_lookup_xattrdir(unode->vp, &xattr_dvp, LOOKUP_XATTR, cr); 3598670SJose.Borrego@Sun.COM if (rc != 0) { 3608670SJose.Borrego@Sun.COM smbsr_errno(sr, rc); 3618670SJose.Borrego@Sun.COM return (0); 3628670SJose.Borrego@Sun.COM } 3638670SJose.Borrego@Sun.COM 3648670SJose.Borrego@Sun.COM /* lookup the xattrdir's smb_node */ 3658670SJose.Borrego@Sun.COM xattr_dnode = smb_node_lookup(sr, NULL, cr, xattr_dvp, XATTR_DIR, 36610001SJoyce.McIntosh@Sun.COM unode, NULL); 3678670SJose.Borrego@Sun.COM VN_RELE(xattr_dvp); 3688670SJose.Borrego@Sun.COM if (xattr_dnode == NULL) { 3698670SJose.Borrego@Sun.COM smbsr_error(sr, NT_STATUS_NO_MEMORY, 3708670SJose.Borrego@Sun.COM ERRDOS, ERROR_NOT_ENOUGH_MEMORY); 3718670SJose.Borrego@Sun.COM return (0); 3728670SJose.Borrego@Sun.COM } 3738670SJose.Borrego@Sun.COM 3748670SJose.Borrego@Sun.COM (void) snprintf(pattern, sizeof (pattern), "%s*", SMB_STREAM_PREFIX); 3759343SAfshin.Ardakani@Sun.COM od = smb_odir_create(sr, xattr_dnode, pattern, SMB_SEARCH_ATTRIBUTES, 3769343SAfshin.Ardakani@Sun.COM cr); 3778670SJose.Borrego@Sun.COM smb_node_release(xattr_dnode); 3788670SJose.Borrego@Sun.COM if (od == NULL) 3798670SJose.Borrego@Sun.COM return (0); 3808670SJose.Borrego@Sun.COM 3819231SAfshin.Ardakani@Sun.COM od->d_flags |= SMB_ODIR_FLAG_XATTR; 3828670SJose.Borrego@Sun.COM return (od->d_odid); 3838670SJose.Borrego@Sun.COM } 3848670SJose.Borrego@Sun.COM 3858670SJose.Borrego@Sun.COM /* 3868670SJose.Borrego@Sun.COM * smb_odir_hold 3879635SJoyce.McIntosh@Sun.COM * 3889635SJoyce.McIntosh@Sun.COM * A hold will only be granted if the odir is open or in_use. 3898670SJose.Borrego@Sun.COM */ 3908670SJose.Borrego@Sun.COM boolean_t 3918670SJose.Borrego@Sun.COM smb_odir_hold(smb_odir_t *od) 3928670SJose.Borrego@Sun.COM { 3938670SJose.Borrego@Sun.COM ASSERT(od); 3948670SJose.Borrego@Sun.COM ASSERT(od->d_magic == SMB_ODIR_MAGIC); 3958670SJose.Borrego@Sun.COM 3968670SJose.Borrego@Sun.COM mutex_enter(&od->d_mutex); 3979635SJoyce.McIntosh@Sun.COM 3989635SJoyce.McIntosh@Sun.COM switch (od->d_state) { 3999635SJoyce.McIntosh@Sun.COM case SMB_ODIR_STATE_OPEN: 4009635SJoyce.McIntosh@Sun.COM od->d_refcnt++; 4019635SJoyce.McIntosh@Sun.COM od->d_state = SMB_ODIR_STATE_IN_USE; 4029635SJoyce.McIntosh@Sun.COM break; 4039635SJoyce.McIntosh@Sun.COM case SMB_ODIR_STATE_IN_USE: 4049635SJoyce.McIntosh@Sun.COM od->d_refcnt++; 4059635SJoyce.McIntosh@Sun.COM break; 4069635SJoyce.McIntosh@Sun.COM case SMB_ODIR_STATE_CLOSING: 4079635SJoyce.McIntosh@Sun.COM case SMB_ODIR_STATE_CLOSED: 4089635SJoyce.McIntosh@Sun.COM default: 4098670SJose.Borrego@Sun.COM mutex_exit(&od->d_mutex); 4108670SJose.Borrego@Sun.COM return (B_FALSE); 4118670SJose.Borrego@Sun.COM } 4128670SJose.Borrego@Sun.COM 4138670SJose.Borrego@Sun.COM mutex_exit(&od->d_mutex); 4148670SJose.Borrego@Sun.COM return (B_TRUE); 4158670SJose.Borrego@Sun.COM } 4168670SJose.Borrego@Sun.COM 4178670SJose.Borrego@Sun.COM /* 4188670SJose.Borrego@Sun.COM * smb_odir_release 4198670SJose.Borrego@Sun.COM * 4208670SJose.Borrego@Sun.COM * If the odir is in SMB_ODIR_STATE_CLOSING and this release 4218670SJose.Borrego@Sun.COM * results in a refcnt of 0, the odir may be removed from 4228670SJose.Borrego@Sun.COM * the tree's list of odirs and deleted. The odir's state is 4238670SJose.Borrego@Sun.COM * set to SMB_ODIR_STATE_CLOSED prior to exiting the mutex and 4249635SJoyce.McIntosh@Sun.COM * deleting the odir. 4255331Samw */ 4265331Samw void 4278670SJose.Borrego@Sun.COM smb_odir_release(smb_odir_t *od) 4285331Samw { 4295331Samw ASSERT(od); 4305331Samw ASSERT(od->d_magic == SMB_ODIR_MAGIC); 4315331Samw 4325331Samw mutex_enter(&od->d_mutex); 4339635SJoyce.McIntosh@Sun.COM ASSERT(od->d_refcnt > 0); 4348670SJose.Borrego@Sun.COM 4355331Samw switch (od->d_state) { 4365331Samw case SMB_ODIR_STATE_OPEN: 4379635SJoyce.McIntosh@Sun.COM break; 4389635SJoyce.McIntosh@Sun.COM case SMB_ODIR_STATE_IN_USE: 4398670SJose.Borrego@Sun.COM od->d_refcnt--; 4409635SJoyce.McIntosh@Sun.COM if (od->d_refcnt == 0) 4419635SJoyce.McIntosh@Sun.COM od->d_state = SMB_ODIR_STATE_OPEN; 4425331Samw break; 4435331Samw case SMB_ODIR_STATE_CLOSING: 4448670SJose.Borrego@Sun.COM od->d_refcnt--; 4458670SJose.Borrego@Sun.COM if (od->d_refcnt == 0) { 4468670SJose.Borrego@Sun.COM od->d_state = SMB_ODIR_STATE_CLOSED; 4478670SJose.Borrego@Sun.COM mutex_exit(&od->d_mutex); 4488670SJose.Borrego@Sun.COM smb_odir_delete(od); 4498670SJose.Borrego@Sun.COM return; 4508670SJose.Borrego@Sun.COM } 4518670SJose.Borrego@Sun.COM break; 4525331Samw case SMB_ODIR_STATE_CLOSED: 4535331Samw default: 4545331Samw break; 4555331Samw } 4565331Samw 4575331Samw mutex_exit(&od->d_mutex); 4585331Samw } 4595331Samw 4605331Samw /* 4618670SJose.Borrego@Sun.COM * smb_odir_close 4625331Samw */ 4638670SJose.Borrego@Sun.COM void 4648670SJose.Borrego@Sun.COM smb_odir_close(smb_odir_t *od) 4655331Samw { 4668670SJose.Borrego@Sun.COM ASSERT(od); 4679635SJoyce.McIntosh@Sun.COM ASSERT(od->d_magic == SMB_ODIR_MAGIC); 4685331Samw 4698670SJose.Borrego@Sun.COM mutex_enter(&od->d_mutex); 4709635SJoyce.McIntosh@Sun.COM ASSERT(od->d_refcnt > 0); 4719635SJoyce.McIntosh@Sun.COM switch (od->d_state) { 4729635SJoyce.McIntosh@Sun.COM case SMB_ODIR_STATE_OPEN: 4739635SJoyce.McIntosh@Sun.COM break; 4749635SJoyce.McIntosh@Sun.COM case SMB_ODIR_STATE_IN_USE: 4759635SJoyce.McIntosh@Sun.COM od->d_state = SMB_ODIR_STATE_CLOSING; 4769635SJoyce.McIntosh@Sun.COM break; 4779635SJoyce.McIntosh@Sun.COM case SMB_ODIR_STATE_CLOSING: 4789635SJoyce.McIntosh@Sun.COM case SMB_ODIR_STATE_CLOSED: 4799635SJoyce.McIntosh@Sun.COM default: 4809635SJoyce.McIntosh@Sun.COM break; 4818670SJose.Borrego@Sun.COM } 4828670SJose.Borrego@Sun.COM mutex_exit(&od->d_mutex); 4838670SJose.Borrego@Sun.COM } 4845331Samw 4858670SJose.Borrego@Sun.COM /* 4868670SJose.Borrego@Sun.COM * smb_odir_read 4878670SJose.Borrego@Sun.COM * 4888670SJose.Borrego@Sun.COM * Find the next directory entry matching the search pattern. 4898670SJose.Borrego@Sun.COM * No search attribute matching is performed. 4908670SJose.Borrego@Sun.COM * 4918670SJose.Borrego@Sun.COM * Returns: 4928670SJose.Borrego@Sun.COM * 0 - success. 4938670SJose.Borrego@Sun.COM * - If a matching entry was found eof will be B_FALSE and 4948670SJose.Borrego@Sun.COM * odirent will be populated. 4958670SJose.Borrego@Sun.COM * - If there are no matching entries eof will be B_TRUE. 4968670SJose.Borrego@Sun.COM * -1 - error, error details set in sr. 4978670SJose.Borrego@Sun.COM */ 4988670SJose.Borrego@Sun.COM int 4998670SJose.Borrego@Sun.COM smb_odir_read(smb_request_t *sr, smb_odir_t *od, 5008670SJose.Borrego@Sun.COM smb_odirent_t *odirent, boolean_t *eof) 5018670SJose.Borrego@Sun.COM { 5029231SAfshin.Ardakani@Sun.COM int rc; 5039231SAfshin.Ardakani@Sun.COM boolean_t ignore_case; 5048670SJose.Borrego@Sun.COM 5058670SJose.Borrego@Sun.COM ASSERT(sr); 5068670SJose.Borrego@Sun.COM ASSERT(sr->sr_magic == SMB_REQ_MAGIC); 5078670SJose.Borrego@Sun.COM ASSERT(od); 5088670SJose.Borrego@Sun.COM ASSERT(od->d_magic == SMB_ODIR_MAGIC); 5098670SJose.Borrego@Sun.COM ASSERT(odirent); 5108670SJose.Borrego@Sun.COM 5118670SJose.Borrego@Sun.COM mutex_enter(&od->d_mutex); 5129635SJoyce.McIntosh@Sun.COM ASSERT(od->d_refcnt > 0); 5138670SJose.Borrego@Sun.COM 5149635SJoyce.McIntosh@Sun.COM switch (od->d_state) { 5159635SJoyce.McIntosh@Sun.COM case SMB_ODIR_STATE_IN_USE: 5169635SJoyce.McIntosh@Sun.COM case SMB_ODIR_STATE_CLOSING: 5179635SJoyce.McIntosh@Sun.COM break; 5189635SJoyce.McIntosh@Sun.COM case SMB_ODIR_STATE_OPEN: 5199635SJoyce.McIntosh@Sun.COM case SMB_ODIR_STATE_CLOSED: 5209635SJoyce.McIntosh@Sun.COM default: 5218670SJose.Borrego@Sun.COM mutex_exit(&od->d_mutex); 5228670SJose.Borrego@Sun.COM return (-1); 5238670SJose.Borrego@Sun.COM } 5248670SJose.Borrego@Sun.COM 5259231SAfshin.Ardakani@Sun.COM ignore_case = (od->d_flags & SMB_ODIR_FLAG_IGNORE_CASE); 5269231SAfshin.Ardakani@Sun.COM 5278670SJose.Borrego@Sun.COM for (;;) { 5288670SJose.Borrego@Sun.COM if ((rc = smb_odir_next_odirent(od, odirent)) != 0) 5295331Samw break; 5308670SJose.Borrego@Sun.COM if (smb_match_name(odirent->od_ino, odirent->od_name, 5319231SAfshin.Ardakani@Sun.COM od->d_pattern, ignore_case)) 5328670SJose.Borrego@Sun.COM break; 5335331Samw } 5348670SJose.Borrego@Sun.COM 5358670SJose.Borrego@Sun.COM mutex_exit(&od->d_mutex); 5368670SJose.Borrego@Sun.COM 5378670SJose.Borrego@Sun.COM switch (rc) { 5388670SJose.Borrego@Sun.COM case 0: 5398670SJose.Borrego@Sun.COM *eof = B_FALSE; 5408670SJose.Borrego@Sun.COM return (0); 5418670SJose.Borrego@Sun.COM case ENOENT: 5428670SJose.Borrego@Sun.COM *eof = B_TRUE; 5438670SJose.Borrego@Sun.COM return (0); 5448670SJose.Borrego@Sun.COM default: 5458670SJose.Borrego@Sun.COM smbsr_errno(sr, rc); 5468670SJose.Borrego@Sun.COM return (-1); 5478670SJose.Borrego@Sun.COM } 5485331Samw } 5495331Samw 5508670SJose.Borrego@Sun.COM /* 5518670SJose.Borrego@Sun.COM * smb_odir_read_fileinfo 5528670SJose.Borrego@Sun.COM * 5538670SJose.Borrego@Sun.COM * Find the next directory entry matching the search pattern 5548670SJose.Borrego@Sun.COM * and attributes: od->d_pattern and od->d_sattr. 5558670SJose.Borrego@Sun.COM * 5568670SJose.Borrego@Sun.COM * If the search pattern specifies a single filename call 5578670SJose.Borrego@Sun.COM * smb_odir_single_fileinfo to get the file attributes and 5588670SJose.Borrego@Sun.COM * populate the caller's smb_fileinfo_t. 5598670SJose.Borrego@Sun.COM * 5608670SJose.Borrego@Sun.COM * If the search pattern contains wildcards call smb_odir_next_odirent 5618670SJose.Borrego@Sun.COM * to get the next directory entry then. Repeat until a matching 5628670SJose.Borrego@Sun.COM * filename is found. Call smb_odir_wildcard_fileinfo to get the 5638670SJose.Borrego@Sun.COM * file attributes and populate the caller's smb_fileinfo_t. 5648670SJose.Borrego@Sun.COM * This is repeated until a file matching the search criteria is found. 5658670SJose.Borrego@Sun.COM * 5668670SJose.Borrego@Sun.COM * Returns: 5678670SJose.Borrego@Sun.COM * 0 - success. 5688670SJose.Borrego@Sun.COM * - If a matching entry was found eof will be B_FALSE and 5698670SJose.Borrego@Sun.COM * fileinfo will be populated. 5708670SJose.Borrego@Sun.COM * - If there are no matching entries eof will be B_TRUE. 5718670SJose.Borrego@Sun.COM * -1 - error, error details set in sr. 5728670SJose.Borrego@Sun.COM */ 5738670SJose.Borrego@Sun.COM int 5748670SJose.Borrego@Sun.COM smb_odir_read_fileinfo(smb_request_t *sr, smb_odir_t *od, 5758670SJose.Borrego@Sun.COM smb_fileinfo_t *fileinfo, boolean_t *eof) 5768670SJose.Borrego@Sun.COM { 57710966SJordan.Brown@Sun.COM int rc, errnum; 5788670SJose.Borrego@Sun.COM smb_odirent_t *odirent; 5799231SAfshin.Ardakani@Sun.COM boolean_t ignore_case; 5808670SJose.Borrego@Sun.COM 5818670SJose.Borrego@Sun.COM ASSERT(sr); 5828670SJose.Borrego@Sun.COM ASSERT(sr->sr_magic == SMB_REQ_MAGIC); 5838670SJose.Borrego@Sun.COM ASSERT(od); 5848670SJose.Borrego@Sun.COM ASSERT(od->d_magic == SMB_ODIR_MAGIC); 5858670SJose.Borrego@Sun.COM ASSERT(fileinfo); 5868670SJose.Borrego@Sun.COM 5878670SJose.Borrego@Sun.COM mutex_enter(&od->d_mutex); 5889635SJoyce.McIntosh@Sun.COM ASSERT(od->d_refcnt > 0); 5898670SJose.Borrego@Sun.COM 5909635SJoyce.McIntosh@Sun.COM switch (od->d_state) { 5919635SJoyce.McIntosh@Sun.COM case SMB_ODIR_STATE_IN_USE: 5929635SJoyce.McIntosh@Sun.COM case SMB_ODIR_STATE_CLOSING: 5939635SJoyce.McIntosh@Sun.COM break; 5949635SJoyce.McIntosh@Sun.COM case SMB_ODIR_STATE_OPEN: 5959635SJoyce.McIntosh@Sun.COM case SMB_ODIR_STATE_CLOSED: 5969635SJoyce.McIntosh@Sun.COM default: 5978670SJose.Borrego@Sun.COM mutex_exit(&od->d_mutex); 5988670SJose.Borrego@Sun.COM return (-1); 5998670SJose.Borrego@Sun.COM } 6008670SJose.Borrego@Sun.COM 6019231SAfshin.Ardakani@Sun.COM ignore_case = (od->d_flags & SMB_ODIR_FLAG_IGNORE_CASE); 6029231SAfshin.Ardakani@Sun.COM 6039231SAfshin.Ardakani@Sun.COM if (!(od->d_flags & SMB_ODIR_FLAG_WILDCARDS)) { 6048670SJose.Borrego@Sun.COM if (od->d_eof) 6058670SJose.Borrego@Sun.COM rc = ENOENT; 6068670SJose.Borrego@Sun.COM else 6078670SJose.Borrego@Sun.COM rc = smb_odir_single_fileinfo(sr, od, fileinfo); 6088670SJose.Borrego@Sun.COM od->d_eof = B_TRUE; 6098670SJose.Borrego@Sun.COM } else { 6108670SJose.Borrego@Sun.COM odirent = kmem_alloc(sizeof (smb_odirent_t), KM_SLEEP); 6118670SJose.Borrego@Sun.COM for (;;) { 6128670SJose.Borrego@Sun.COM bzero(fileinfo, sizeof (smb_fileinfo_t)); 6138670SJose.Borrego@Sun.COM if ((rc = smb_odir_next_odirent(od, odirent)) != 0) 6148670SJose.Borrego@Sun.COM break; 6158670SJose.Borrego@Sun.COM 61610966SJordan.Brown@Sun.COM /* skip non utf8 filename */ 61710966SJordan.Brown@Sun.COM if (u8_validate(odirent->od_name, 61810966SJordan.Brown@Sun.COM strlen(odirent->od_name), NULL, 61910966SJordan.Brown@Sun.COM U8_VALIDATE_ENTIRE, &errnum) < 0) 62010966SJordan.Brown@Sun.COM continue; 62110966SJordan.Brown@Sun.COM 6228670SJose.Borrego@Sun.COM if (!smb_match_name(odirent->od_ino, odirent->od_name, 6239231SAfshin.Ardakani@Sun.COM od->d_pattern, ignore_case)) 6248670SJose.Borrego@Sun.COM continue; 6258670SJose.Borrego@Sun.COM 6268670SJose.Borrego@Sun.COM rc = smb_odir_wildcard_fileinfo(sr, od, odirent, 6278670SJose.Borrego@Sun.COM fileinfo); 6288670SJose.Borrego@Sun.COM if (rc == 0) 6298670SJose.Borrego@Sun.COM break; 6308670SJose.Borrego@Sun.COM } 6318670SJose.Borrego@Sun.COM kmem_free(odirent, sizeof (smb_odirent_t)); 6328670SJose.Borrego@Sun.COM } 6338670SJose.Borrego@Sun.COM mutex_exit(&od->d_mutex); 6348670SJose.Borrego@Sun.COM 6358670SJose.Borrego@Sun.COM switch (rc) { 6368670SJose.Borrego@Sun.COM case 0: 6378670SJose.Borrego@Sun.COM *eof = B_FALSE; 6388670SJose.Borrego@Sun.COM return (0); 6398670SJose.Borrego@Sun.COM case ENOENT: 6408670SJose.Borrego@Sun.COM *eof = B_TRUE; 6418670SJose.Borrego@Sun.COM return (0); 6428670SJose.Borrego@Sun.COM default: 6438670SJose.Borrego@Sun.COM smbsr_errno(sr, rc); 6448670SJose.Borrego@Sun.COM return (-1); 6458670SJose.Borrego@Sun.COM } 6468670SJose.Borrego@Sun.COM } 6478670SJose.Borrego@Sun.COM 6485331Samw 6495331Samw /* 6508670SJose.Borrego@Sun.COM * smb_odir_read_streaminfo 6518670SJose.Borrego@Sun.COM * 6528670SJose.Borrego@Sun.COM * Find the next directory entry whose name begins with SMB_STREAM_PREFIX, 6538670SJose.Borrego@Sun.COM * and thus represents an NTFS named stream. 6548670SJose.Borrego@Sun.COM * No search attribute matching is performed. 6559231SAfshin.Ardakani@Sun.COM * No case conflict name mangling is required for NTFS named stream names. 6565331Samw * 6578670SJose.Borrego@Sun.COM * Returns: 6588670SJose.Borrego@Sun.COM * 0 - success. 6598670SJose.Borrego@Sun.COM * - If a matching entry was found eof will be B_FALSE and 6608670SJose.Borrego@Sun.COM * sinfo will be populated. 6618670SJose.Borrego@Sun.COM * - If there are no matching entries eof will be B_TRUE. 6628670SJose.Borrego@Sun.COM * -1 - error, error details set in sr. 6635331Samw */ 6648670SJose.Borrego@Sun.COM int 6658670SJose.Borrego@Sun.COM smb_odir_read_streaminfo(smb_request_t *sr, smb_odir_t *od, 6668670SJose.Borrego@Sun.COM smb_streaminfo_t *sinfo, boolean_t *eof) 6675331Samw { 6688670SJose.Borrego@Sun.COM int rc; 6698670SJose.Borrego@Sun.COM smb_odirent_t *odirent; 67010504SKeyur.Desai@Sun.COM smb_node_t *fnode; 6718670SJose.Borrego@Sun.COM smb_attr_t attr; 6725331Samw 6738670SJose.Borrego@Sun.COM ASSERT(sr); 6748670SJose.Borrego@Sun.COM ASSERT(sr->sr_magic == SMB_REQ_MAGIC); 6755331Samw ASSERT(od); 6765331Samw ASSERT(od->d_magic == SMB_ODIR_MAGIC); 6778670SJose.Borrego@Sun.COM ASSERT(sinfo); 6788670SJose.Borrego@Sun.COM 6798670SJose.Borrego@Sun.COM mutex_enter(&od->d_mutex); 6809635SJoyce.McIntosh@Sun.COM ASSERT(od->d_refcnt > 0); 6818670SJose.Borrego@Sun.COM 6829635SJoyce.McIntosh@Sun.COM switch (od->d_state) { 6839635SJoyce.McIntosh@Sun.COM case SMB_ODIR_STATE_IN_USE: 6849635SJoyce.McIntosh@Sun.COM case SMB_ODIR_STATE_CLOSING: 6859635SJoyce.McIntosh@Sun.COM break; 6869635SJoyce.McIntosh@Sun.COM case SMB_ODIR_STATE_OPEN: 6879635SJoyce.McIntosh@Sun.COM case SMB_ODIR_STATE_CLOSED: 6889635SJoyce.McIntosh@Sun.COM default: 6898670SJose.Borrego@Sun.COM mutex_exit(&od->d_mutex); 6908670SJose.Borrego@Sun.COM return (-1); 6918670SJose.Borrego@Sun.COM } 6928670SJose.Borrego@Sun.COM 6938670SJose.Borrego@Sun.COM /* Check that odir represents an xattr directory */ 6949231SAfshin.Ardakani@Sun.COM if (!(od->d_flags & SMB_ODIR_FLAG_XATTR)) { 6958670SJose.Borrego@Sun.COM *eof = B_TRUE; 6968670SJose.Borrego@Sun.COM mutex_exit(&od->d_mutex); 6978670SJose.Borrego@Sun.COM return (0); 6988670SJose.Borrego@Sun.COM } 6998670SJose.Borrego@Sun.COM 7008670SJose.Borrego@Sun.COM odirent = kmem_alloc(sizeof (smb_odirent_t), KM_SLEEP); 7018670SJose.Borrego@Sun.COM 7028670SJose.Borrego@Sun.COM for (;;) { 7038670SJose.Borrego@Sun.COM bzero(sinfo, sizeof (smb_streaminfo_t)); 7048670SJose.Borrego@Sun.COM if ((rc = smb_odir_next_odirent(od, odirent)) != 0) 7058670SJose.Borrego@Sun.COM break; 7068670SJose.Borrego@Sun.COM 7078670SJose.Borrego@Sun.COM if (strncmp(odirent->od_name, SMB_STREAM_PREFIX, 7088670SJose.Borrego@Sun.COM SMB_STREAM_PREFIX_LEN)) { 7098670SJose.Borrego@Sun.COM continue; 7108670SJose.Borrego@Sun.COM } 7118670SJose.Borrego@Sun.COM 71210504SKeyur.Desai@Sun.COM rc = smb_fsop_lookup(sr, od->d_cred, 0, od->d_tree->t_snode, 71310504SKeyur.Desai@Sun.COM od->d_dnode, odirent->od_name, &fnode); 7148670SJose.Borrego@Sun.COM if (rc == 0) { 71510504SKeyur.Desai@Sun.COM rc = smb_node_getattr(sr, fnode, &attr); 71610504SKeyur.Desai@Sun.COM smb_node_release(fnode); 7178670SJose.Borrego@Sun.COM } 7188670SJose.Borrego@Sun.COM 7198670SJose.Borrego@Sun.COM if (rc == 0) { 7208670SJose.Borrego@Sun.COM (void) strlcpy(sinfo->si_name, 7218670SJose.Borrego@Sun.COM odirent->od_name + SMB_STREAM_PREFIX_LEN, 7228670SJose.Borrego@Sun.COM sizeof (sinfo->si_name)); 7238670SJose.Borrego@Sun.COM sinfo->si_size = attr.sa_vattr.va_size; 72410504SKeyur.Desai@Sun.COM sinfo->si_alloc_size = attr.sa_allocsz; 7258670SJose.Borrego@Sun.COM break; 7268670SJose.Borrego@Sun.COM } 7278670SJose.Borrego@Sun.COM } 7288670SJose.Borrego@Sun.COM mutex_exit(&od->d_mutex); 7298670SJose.Borrego@Sun.COM 7308670SJose.Borrego@Sun.COM kmem_free(odirent, sizeof (smb_odirent_t)); 7318670SJose.Borrego@Sun.COM 7328670SJose.Borrego@Sun.COM switch (rc) { 7338670SJose.Borrego@Sun.COM case 0: 7348670SJose.Borrego@Sun.COM *eof = B_FALSE; 7358670SJose.Borrego@Sun.COM return (0); 7368670SJose.Borrego@Sun.COM case ENOENT: 7378670SJose.Borrego@Sun.COM *eof = B_TRUE; 7388670SJose.Borrego@Sun.COM return (0); 7398670SJose.Borrego@Sun.COM default: 7408670SJose.Borrego@Sun.COM smbsr_errno(sr, rc); 7418670SJose.Borrego@Sun.COM return (-1); 7428670SJose.Borrego@Sun.COM } 7438670SJose.Borrego@Sun.COM } 7448670SJose.Borrego@Sun.COM 7458670SJose.Borrego@Sun.COM /* 7468670SJose.Borrego@Sun.COM * smb_odir_save_cookie 7478670SJose.Borrego@Sun.COM * 7488670SJose.Borrego@Sun.COM * Callers can save up to SMB_MAX_SEARCH cookies in the odir 7498670SJose.Borrego@Sun.COM * to be used as resume points for a 'find next' request. 7508670SJose.Borrego@Sun.COM */ 7518670SJose.Borrego@Sun.COM void 7528670SJose.Borrego@Sun.COM smb_odir_save_cookie(smb_odir_t *od, int idx, uint32_t cookie) 7538670SJose.Borrego@Sun.COM { 7548670SJose.Borrego@Sun.COM ASSERT(od); 7558670SJose.Borrego@Sun.COM ASSERT(od->d_magic == SMB_ODIR_MAGIC); 7568670SJose.Borrego@Sun.COM ASSERT(idx >= 0 && idx < SMB_MAX_SEARCH); 7575331Samw 7585331Samw mutex_enter(&od->d_mutex); 7598670SJose.Borrego@Sun.COM od->d_cookies[idx] = cookie; 7608670SJose.Borrego@Sun.COM mutex_exit(&od->d_mutex); 7618670SJose.Borrego@Sun.COM } 7628670SJose.Borrego@Sun.COM 7638670SJose.Borrego@Sun.COM /* 7648670SJose.Borrego@Sun.COM * smb_odir_resume_at 7658670SJose.Borrego@Sun.COM * 7669343SAfshin.Ardakani@Sun.COM * If SMB_ODIR_FLAG_WILDCARDS is not set the search is for a single 7679343SAfshin.Ardakani@Sun.COM * file and should not be resumed. 7689343SAfshin.Ardakani@Sun.COM * 7699343SAfshin.Ardakani@Sun.COM * Wildcard searching can be resumed from: 7708670SJose.Borrego@Sun.COM * - the cookie saved at a specified index (SMBsearch, SMBfind). 7718670SJose.Borrego@Sun.COM * - a specified cookie (SMB_trans2_find) 7728670SJose.Borrego@Sun.COM * - a specified filename (SMB_trans2_find) - NOT SUPPORTED. 7738670SJose.Borrego@Sun.COM * Defaults to continuing from where the last search ended. 7748670SJose.Borrego@Sun.COM * 7758670SJose.Borrego@Sun.COM * Continuation from where the last search ended (SMB_trans2_find) 7768670SJose.Borrego@Sun.COM * is implemented by saving the last cookie at a specific index (0) 7778670SJose.Borrego@Sun.COM * smb_odir_resume_at indicates a new request, so reset od->d_bufptr 7788670SJose.Borrego@Sun.COM * and d_eof to force a vop_readdir. 7798670SJose.Borrego@Sun.COM */ 7808670SJose.Borrego@Sun.COM void 7818670SJose.Borrego@Sun.COM smb_odir_resume_at(smb_odir_t *od, smb_odir_resume_t *resume) 7828670SJose.Borrego@Sun.COM { 7838670SJose.Borrego@Sun.COM ASSERT(od); 7848670SJose.Borrego@Sun.COM ASSERT(od->d_magic == SMB_ODIR_MAGIC); 7858670SJose.Borrego@Sun.COM ASSERT(resume); 7868670SJose.Borrego@Sun.COM 7878670SJose.Borrego@Sun.COM mutex_enter(&od->d_mutex); 7888670SJose.Borrego@Sun.COM 7899343SAfshin.Ardakani@Sun.COM if ((od->d_flags & SMB_ODIR_FLAG_WILDCARDS) == 0) { 7909343SAfshin.Ardakani@Sun.COM od->d_eof = B_TRUE; 7919343SAfshin.Ardakani@Sun.COM mutex_exit(&od->d_mutex); 7929343SAfshin.Ardakani@Sun.COM return; 7939343SAfshin.Ardakani@Sun.COM } 7949343SAfshin.Ardakani@Sun.COM 7958670SJose.Borrego@Sun.COM switch (resume->or_type) { 7968670SJose.Borrego@Sun.COM case SMB_ODIR_RESUME_IDX: 7978670SJose.Borrego@Sun.COM ASSERT(resume->or_idx >= 0); 7988670SJose.Borrego@Sun.COM ASSERT(resume->or_idx < SMB_MAX_SEARCH); 7998670SJose.Borrego@Sun.COM 8008670SJose.Borrego@Sun.COM if ((resume->or_idx < 0) || 8018670SJose.Borrego@Sun.COM (resume->or_idx >= SMB_MAX_SEARCH)) { 8028670SJose.Borrego@Sun.COM resume->or_idx = 0; 8038670SJose.Borrego@Sun.COM } 8048670SJose.Borrego@Sun.COM od->d_offset = od->d_cookies[resume->or_idx]; 8058670SJose.Borrego@Sun.COM break; 8068670SJose.Borrego@Sun.COM case SMB_ODIR_RESUME_COOKIE: 8078670SJose.Borrego@Sun.COM od->d_offset = resume->or_cookie; 8088670SJose.Borrego@Sun.COM break; 8098670SJose.Borrego@Sun.COM case SMB_ODIR_RESUME_FNAME: 8108670SJose.Borrego@Sun.COM default: 8118670SJose.Borrego@Sun.COM od->d_offset = od->d_cookies[0]; 8128670SJose.Borrego@Sun.COM break; 8135331Samw } 8148670SJose.Borrego@Sun.COM 8158670SJose.Borrego@Sun.COM /* Force a vop_readdir to refresh d_buf */ 8168670SJose.Borrego@Sun.COM od->d_bufptr = NULL; 8178670SJose.Borrego@Sun.COM od->d_eof = B_FALSE; 8188670SJose.Borrego@Sun.COM 8198670SJose.Borrego@Sun.COM mutex_exit(&od->d_mutex); 8208670SJose.Borrego@Sun.COM } 8218670SJose.Borrego@Sun.COM 8228670SJose.Borrego@Sun.COM 8238670SJose.Borrego@Sun.COM /* *** static functions *** */ 8248670SJose.Borrego@Sun.COM 8258670SJose.Borrego@Sun.COM /* 8268670SJose.Borrego@Sun.COM * smb_odir_create 8278670SJose.Borrego@Sun.COM * Allocate and populate an odir obect and add it to the tree's list. 8288670SJose.Borrego@Sun.COM */ 8298670SJose.Borrego@Sun.COM static smb_odir_t * 8308670SJose.Borrego@Sun.COM smb_odir_create(smb_request_t *sr, smb_node_t *dnode, 8319343SAfshin.Ardakani@Sun.COM char *pattern, uint16_t sattr, cred_t *cr) 8328670SJose.Borrego@Sun.COM { 8338670SJose.Borrego@Sun.COM smb_odir_t *od; 8348670SJose.Borrego@Sun.COM smb_tree_t *tree; 8358670SJose.Borrego@Sun.COM uint16_t odid; 8368670SJose.Borrego@Sun.COM 8378670SJose.Borrego@Sun.COM ASSERT(sr); 8388670SJose.Borrego@Sun.COM ASSERT(sr->sr_magic == SMB_REQ_MAGIC); 8398670SJose.Borrego@Sun.COM ASSERT(sr->tid_tree); 8408670SJose.Borrego@Sun.COM ASSERT(sr->tid_tree->t_magic == SMB_TREE_MAGIC); 8418670SJose.Borrego@Sun.COM ASSERT(dnode); 8428670SJose.Borrego@Sun.COM ASSERT(dnode->n_magic == SMB_NODE_MAGIC); 8438670SJose.Borrego@Sun.COM 8448670SJose.Borrego@Sun.COM tree = sr->tid_tree; 8458670SJose.Borrego@Sun.COM 8468670SJose.Borrego@Sun.COM if (smb_idpool_alloc(&tree->t_odid_pool, &odid)) { 8478670SJose.Borrego@Sun.COM smbsr_error(sr, NT_STATUS_TOO_MANY_OPENED_FILES, 8488670SJose.Borrego@Sun.COM ERRDOS, ERROR_TOO_MANY_OPEN_FILES); 8498670SJose.Borrego@Sun.COM return (NULL); 8508670SJose.Borrego@Sun.COM } 8518670SJose.Borrego@Sun.COM 8528670SJose.Borrego@Sun.COM od = kmem_cache_alloc(tree->t_server->si_cache_odir, KM_SLEEP); 8538670SJose.Borrego@Sun.COM bzero(od, sizeof (smb_odir_t)); 8548670SJose.Borrego@Sun.COM 8558670SJose.Borrego@Sun.COM mutex_init(&od->d_mutex, NULL, MUTEX_DEFAULT, NULL); 8569635SJoyce.McIntosh@Sun.COM od->d_refcnt = 0; 8578670SJose.Borrego@Sun.COM od->d_state = SMB_ODIR_STATE_OPEN; 8588670SJose.Borrego@Sun.COM od->d_magic = SMB_ODIR_MAGIC; 8598670SJose.Borrego@Sun.COM od->d_opened_by_pid = sr->smb_pid; 8608670SJose.Borrego@Sun.COM od->d_session = tree->t_session; 8619343SAfshin.Ardakani@Sun.COM od->d_cred = cr; 8628670SJose.Borrego@Sun.COM od->d_tree = tree; 8638670SJose.Borrego@Sun.COM od->d_dnode = dnode; 8648670SJose.Borrego@Sun.COM smb_node_ref(dnode); 8658670SJose.Borrego@Sun.COM od->d_odid = odid; 8668670SJose.Borrego@Sun.COM od->d_sattr = sattr; 8678670SJose.Borrego@Sun.COM (void) strlcpy(od->d_pattern, pattern, sizeof (od->d_pattern)); 8689231SAfshin.Ardakani@Sun.COM od->d_flags = 0; 869*11337SWilliam.Krier@Sun.COM if (smb_contains_wildcards(od->d_pattern)) 8709231SAfshin.Ardakani@Sun.COM od->d_flags |= SMB_ODIR_FLAG_WILDCARDS; 8719231SAfshin.Ardakani@Sun.COM if (vfs_has_feature(dnode->vp->v_vfsp, VFSFT_DIRENTFLAGS)) 8729231SAfshin.Ardakani@Sun.COM od->d_flags |= SMB_ODIR_FLAG_EDIRENT; 8739231SAfshin.Ardakani@Sun.COM if (smb_tree_has_feature(tree, SMB_TREE_CASEINSENSITIVE)) 8749231SAfshin.Ardakani@Sun.COM od->d_flags |= SMB_ODIR_FLAG_IGNORE_CASE; 8759231SAfshin.Ardakani@Sun.COM if (SMB_TREE_SUPPORTS_CATIA(sr)) 8769231SAfshin.Ardakani@Sun.COM od->d_flags |= SMB_ODIR_FLAG_CATIA; 87710504SKeyur.Desai@Sun.COM if (SMB_TREE_SUPPORTS_ABE(sr)) 87810504SKeyur.Desai@Sun.COM od->d_flags |= SMB_ODIR_FLAG_ABE; 8798670SJose.Borrego@Sun.COM od->d_eof = B_FALSE; 8808670SJose.Borrego@Sun.COM 8818670SJose.Borrego@Sun.COM smb_llist_enter(&tree->t_odir_list, RW_WRITER); 8828670SJose.Borrego@Sun.COM smb_llist_insert_tail(&tree->t_odir_list, od); 8838670SJose.Borrego@Sun.COM smb_llist_exit(&tree->t_odir_list); 8848670SJose.Borrego@Sun.COM 8858670SJose.Borrego@Sun.COM atomic_inc_32(&tree->t_session->s_dir_cnt); 8868670SJose.Borrego@Sun.COM return (od); 8875331Samw } 8885331Samw 8895331Samw /* 8905331Samw * smb_odir_delete 8918670SJose.Borrego@Sun.COM * 8928670SJose.Borrego@Sun.COM * Removal of the odir from the tree's list of odirs must be 8938670SJose.Borrego@Sun.COM * done before any resources associated with the odir are 8948670SJose.Borrego@Sun.COM * released. 8955331Samw */ 8965331Samw static void 8978670SJose.Borrego@Sun.COM smb_odir_delete(smb_odir_t *od) 8985331Samw { 8995331Samw ASSERT(od); 9005331Samw ASSERT(od->d_magic == SMB_ODIR_MAGIC); 9015331Samw ASSERT(od->d_state == SMB_ODIR_STATE_CLOSED); 9025331Samw 9035331Samw smb_llist_enter(&od->d_tree->t_odir_list, RW_WRITER); 9045331Samw smb_llist_remove(&od->d_tree->t_odir_list, od); 9055331Samw smb_llist_exit(&od->d_tree->t_odir_list); 9068670SJose.Borrego@Sun.COM 9076139Sjb150015 od->d_magic = 0; 9085331Samw atomic_dec_32(&od->d_tree->t_session->s_dir_cnt); 9098670SJose.Borrego@Sun.COM smb_node_release(od->d_dnode); 9108670SJose.Borrego@Sun.COM smb_idpool_free(&od->d_tree->t_odid_pool, od->d_odid); 9115331Samw mutex_destroy(&od->d_mutex); 9126139Sjb150015 kmem_cache_free(od->d_tree->t_server->si_cache_odir, od); 9135331Samw } 9148670SJose.Borrego@Sun.COM 9158670SJose.Borrego@Sun.COM /* 9168670SJose.Borrego@Sun.COM * smb_odir_next_odirent 9178670SJose.Borrego@Sun.COM * 9188670SJose.Borrego@Sun.COM * Find the next directory entry in d_buf. If d_bufptr is NULL (buffer 9198670SJose.Borrego@Sun.COM * is empty or we've reached the end of it), read the next set of 9208670SJose.Borrego@Sun.COM * entries from the file system (vop_readdir). 9218670SJose.Borrego@Sun.COM * 9228670SJose.Borrego@Sun.COM * File systems which support VFSFT_EDIRENT_FLAGS will return the 9238670SJose.Borrego@Sun.COM * directory entries as a buffer of edirent_t structure. Others will 9248670SJose.Borrego@Sun.COM * return a buffer of dirent64_t structures. For simplicity translate 9258670SJose.Borrego@Sun.COM * the data into an smb_odirent_t structure. 9268670SJose.Borrego@Sun.COM * The ed_name/d_name in d_buf is NULL terminated by the file system. 9278670SJose.Borrego@Sun.COM * 9288670SJose.Borrego@Sun.COM * Some file systems can have directories larger than SMB_MAXDIRSIZE. 9299231SAfshin.Ardakani@Sun.COM * If the odirent offset >= SMB_MAXDIRSIZE return ENOENT and set d_eof 9309231SAfshin.Ardakani@Sun.COM * to true to stop subsequent calls to smb_vop_readdir. 9318670SJose.Borrego@Sun.COM * 9328670SJose.Borrego@Sun.COM * Returns: 9338670SJose.Borrego@Sun.COM * 0 - success. odirent is populated with the next directory entry 9348670SJose.Borrego@Sun.COM * ENOENT - no more directory entries 9358670SJose.Borrego@Sun.COM * errno - error 9368670SJose.Borrego@Sun.COM */ 9378670SJose.Borrego@Sun.COM static int 9388670SJose.Borrego@Sun.COM smb_odir_next_odirent(smb_odir_t *od, smb_odirent_t *odirent) 9398670SJose.Borrego@Sun.COM { 9408670SJose.Borrego@Sun.COM int rc; 9418670SJose.Borrego@Sun.COM int reclen; 9428670SJose.Borrego@Sun.COM int eof; 9438670SJose.Borrego@Sun.COM dirent64_t *dp; 9448670SJose.Borrego@Sun.COM edirent_t *edp; 9459231SAfshin.Ardakani@Sun.COM char *np; 94610504SKeyur.Desai@Sun.COM uint32_t abe_flag = 0; 9478670SJose.Borrego@Sun.COM 9488670SJose.Borrego@Sun.COM ASSERT(MUTEX_HELD(&od->d_mutex)); 9498670SJose.Borrego@Sun.COM 9509437SJoyce.McIntosh@Sun.COM bzero(odirent, sizeof (smb_odirent_t)); 9519437SJoyce.McIntosh@Sun.COM 9528670SJose.Borrego@Sun.COM if (od->d_bufptr != NULL) { 9539231SAfshin.Ardakani@Sun.COM if (od->d_flags & SMB_ODIR_FLAG_EDIRENT) 9549231SAfshin.Ardakani@Sun.COM reclen = od->d_edp->ed_reclen; 9559231SAfshin.Ardakani@Sun.COM else 9569231SAfshin.Ardakani@Sun.COM reclen = od->d_dp->d_reclen; 9578670SJose.Borrego@Sun.COM 9588670SJose.Borrego@Sun.COM if (reclen == 0) { 9598670SJose.Borrego@Sun.COM od->d_bufptr = NULL; 9608670SJose.Borrego@Sun.COM } else { 9618670SJose.Borrego@Sun.COM od->d_bufptr += reclen; 9628670SJose.Borrego@Sun.COM if (od->d_bufptr >= od->d_buf + od->d_bufsize) 9638670SJose.Borrego@Sun.COM od->d_bufptr = NULL; 9648670SJose.Borrego@Sun.COM } 9658670SJose.Borrego@Sun.COM } 9668670SJose.Borrego@Sun.COM 9678670SJose.Borrego@Sun.COM if (od->d_bufptr == NULL) { 9688670SJose.Borrego@Sun.COM if (od->d_eof) 9698670SJose.Borrego@Sun.COM return (ENOENT); 9708670SJose.Borrego@Sun.COM 9718670SJose.Borrego@Sun.COM od->d_bufsize = sizeof (od->d_buf); 9728670SJose.Borrego@Sun.COM 97310504SKeyur.Desai@Sun.COM if (od->d_flags & SMB_ODIR_FLAG_ABE) 97410504SKeyur.Desai@Sun.COM abe_flag = SMB_ABE; 97510504SKeyur.Desai@Sun.COM 9768670SJose.Borrego@Sun.COM rc = smb_vop_readdir(od->d_dnode->vp, od->d_offset, 97710504SKeyur.Desai@Sun.COM od->d_buf, &od->d_bufsize, &eof, abe_flag, od->d_cred); 9788670SJose.Borrego@Sun.COM 9798670SJose.Borrego@Sun.COM if ((rc == 0) && (od->d_bufsize == 0)) 9808670SJose.Borrego@Sun.COM rc = ENOENT; 9818670SJose.Borrego@Sun.COM 9828670SJose.Borrego@Sun.COM if (rc != 0) { 9838670SJose.Borrego@Sun.COM od->d_bufptr = NULL; 9848670SJose.Borrego@Sun.COM od->d_bufsize = 0; 9858670SJose.Borrego@Sun.COM return (rc); 9868670SJose.Borrego@Sun.COM } 9878670SJose.Borrego@Sun.COM 9888670SJose.Borrego@Sun.COM od->d_eof = (eof != 0); 9898670SJose.Borrego@Sun.COM od->d_bufptr = od->d_buf; 9908670SJose.Borrego@Sun.COM } 9918670SJose.Borrego@Sun.COM 9929231SAfshin.Ardakani@Sun.COM if (od->d_flags & SMB_ODIR_FLAG_EDIRENT) 9939231SAfshin.Ardakani@Sun.COM od->d_offset = od->d_edp->ed_off; 9949231SAfshin.Ardakani@Sun.COM else 9959231SAfshin.Ardakani@Sun.COM od->d_offset = od->d_dp->d_off; 9969231SAfshin.Ardakani@Sun.COM 9978670SJose.Borrego@Sun.COM if (od->d_offset >= SMB_MAXDIRSIZE) { 9988670SJose.Borrego@Sun.COM od->d_bufptr = NULL; 9998670SJose.Borrego@Sun.COM od->d_bufsize = 0; 10009231SAfshin.Ardakani@Sun.COM od->d_eof = B_TRUE; 10018670SJose.Borrego@Sun.COM return (ENOENT); 10028670SJose.Borrego@Sun.COM } 10038670SJose.Borrego@Sun.COM 10049231SAfshin.Ardakani@Sun.COM if (od->d_flags & SMB_ODIR_FLAG_EDIRENT) { 10058670SJose.Borrego@Sun.COM edp = od->d_edp; 10068670SJose.Borrego@Sun.COM odirent->od_ino = edp->ed_ino; 10078670SJose.Borrego@Sun.COM odirent->od_eflags = edp->ed_eflags; 10089231SAfshin.Ardakani@Sun.COM np = edp->ed_name; 10098670SJose.Borrego@Sun.COM } else { 10108670SJose.Borrego@Sun.COM dp = od->d_dp; 10118670SJose.Borrego@Sun.COM odirent->od_ino = dp->d_ino; 10128670SJose.Borrego@Sun.COM odirent->od_eflags = 0; 10139231SAfshin.Ardakani@Sun.COM np = dp->d_name; 10149231SAfshin.Ardakani@Sun.COM } 10159231SAfshin.Ardakani@Sun.COM 10169231SAfshin.Ardakani@Sun.COM if ((od->d_flags & SMB_ODIR_FLAG_CATIA) && 10179231SAfshin.Ardakani@Sun.COM ((od->d_flags & SMB_ODIR_FLAG_XATTR) == 0)) { 10189231SAfshin.Ardakani@Sun.COM smb_vop_catia_v4tov5(np, odirent->od_name, 10199231SAfshin.Ardakani@Sun.COM sizeof (odirent->od_name)); 10209231SAfshin.Ardakani@Sun.COM } else { 10219231SAfshin.Ardakani@Sun.COM (void) strlcpy(odirent->od_name, np, 10228670SJose.Borrego@Sun.COM sizeof (odirent->od_name)); 10238670SJose.Borrego@Sun.COM } 10248670SJose.Borrego@Sun.COM 10258670SJose.Borrego@Sun.COM return (0); 10268670SJose.Borrego@Sun.COM } 10278670SJose.Borrego@Sun.COM 10288670SJose.Borrego@Sun.COM /* 10298670SJose.Borrego@Sun.COM * smb_odir_single_fileinfo 10308670SJose.Borrego@Sun.COM * 10318670SJose.Borrego@Sun.COM * Lookup the file identified by od->d_pattern. 10328670SJose.Borrego@Sun.COM * 10338670SJose.Borrego@Sun.COM * If the looked up file is a link, we attempt to lookup the link target 10348670SJose.Borrego@Sun.COM * to use its attributes in place of those of the files's. 10358670SJose.Borrego@Sun.COM * If we fail to lookup the target of the link we use the original 10368670SJose.Borrego@Sun.COM * file's attributes. 10378670SJose.Borrego@Sun.COM * Check if the attributes match the search attributes. 10388670SJose.Borrego@Sun.COM * 10398670SJose.Borrego@Sun.COM * Returns: 0 - success 10408670SJose.Borrego@Sun.COM * ENOENT - no match 10418670SJose.Borrego@Sun.COM * errno - error 10428670SJose.Borrego@Sun.COM */ 10438670SJose.Borrego@Sun.COM static int 10448670SJose.Borrego@Sun.COM smb_odir_single_fileinfo(smb_request_t *sr, smb_odir_t *od, 10458670SJose.Borrego@Sun.COM smb_fileinfo_t *fileinfo) 10468670SJose.Borrego@Sun.COM { 10478670SJose.Borrego@Sun.COM int rc; 10488670SJose.Borrego@Sun.COM smb_node_t *fnode, *tgt_node; 104910001SJoyce.McIntosh@Sun.COM smb_attr_t attr; 10508670SJose.Borrego@Sun.COM ino64_t ino; 10518670SJose.Borrego@Sun.COM char *name; 10529231SAfshin.Ardakani@Sun.COM boolean_t case_conflict = B_FALSE; 10539231SAfshin.Ardakani@Sun.COM int lookup_flags, flags = 0; 10549231SAfshin.Ardakani@Sun.COM vnode_t *vp; 10558670SJose.Borrego@Sun.COM 10568670SJose.Borrego@Sun.COM ASSERT(sr); 10578670SJose.Borrego@Sun.COM ASSERT(sr->sr_magic == SMB_REQ_MAGIC); 10588670SJose.Borrego@Sun.COM ASSERT(od); 10598670SJose.Borrego@Sun.COM ASSERT(od->d_magic == SMB_ODIR_MAGIC); 10608670SJose.Borrego@Sun.COM 10618670SJose.Borrego@Sun.COM ASSERT(MUTEX_HELD(&od->d_mutex)); 10628670SJose.Borrego@Sun.COM bzero(fileinfo, sizeof (smb_fileinfo_t)); 10638670SJose.Borrego@Sun.COM 10649343SAfshin.Ardakani@Sun.COM rc = smb_fsop_lookup(sr, od->d_cred, 0, od->d_tree->t_snode, 106510001SJoyce.McIntosh@Sun.COM od->d_dnode, od->d_pattern, &fnode); 10668670SJose.Borrego@Sun.COM if (rc != 0) 10678670SJose.Borrego@Sun.COM return (rc); 10688670SJose.Borrego@Sun.COM 10699231SAfshin.Ardakani@Sun.COM /* 10709231SAfshin.Ardakani@Sun.COM * If case sensitive, do a case insensitive smb_vop_lookup to 10719231SAfshin.Ardakani@Sun.COM * check for case conflict 10729231SAfshin.Ardakani@Sun.COM */ 10739231SAfshin.Ardakani@Sun.COM if (od->d_flags & SMB_ODIR_FLAG_IGNORE_CASE) { 10749231SAfshin.Ardakani@Sun.COM lookup_flags = SMB_IGNORE_CASE; 10759231SAfshin.Ardakani@Sun.COM if (od->d_flags & SMB_ODIR_FLAG_CATIA) 10769231SAfshin.Ardakani@Sun.COM lookup_flags |= SMB_CATIA; 10778670SJose.Borrego@Sun.COM 10789231SAfshin.Ardakani@Sun.COM rc = smb_vop_lookup(od->d_dnode->vp, fnode->od_name, &vp, 10799231SAfshin.Ardakani@Sun.COM NULL, lookup_flags, &flags, od->d_tree->t_snode->vp, 10809343SAfshin.Ardakani@Sun.COM od->d_cred); 10819231SAfshin.Ardakani@Sun.COM if (rc != 0) 10829231SAfshin.Ardakani@Sun.COM return (rc); 10839231SAfshin.Ardakani@Sun.COM VN_RELE(vp); 10849231SAfshin.Ardakani@Sun.COM 10859231SAfshin.Ardakani@Sun.COM if (flags & ED_CASE_CONFLICT) 10869231SAfshin.Ardakani@Sun.COM case_conflict = B_TRUE; 10879231SAfshin.Ardakani@Sun.COM } 10889231SAfshin.Ardakani@Sun.COM 108910001SJoyce.McIntosh@Sun.COM if ((rc = smb_node_getattr(sr, fnode, &attr)) != 0) { 109010001SJoyce.McIntosh@Sun.COM smb_node_release(fnode); 109110001SJoyce.McIntosh@Sun.COM return (rc); 109210001SJoyce.McIntosh@Sun.COM } 109310001SJoyce.McIntosh@Sun.COM 10949231SAfshin.Ardakani@Sun.COM ino = attr.sa_vattr.va_nodeid; 10959231SAfshin.Ardakani@Sun.COM (void) smb_mangle_name(ino, fnode->od_name, 10969231SAfshin.Ardakani@Sun.COM fileinfo->fi_shortname, fileinfo->fi_name83, case_conflict); 10979231SAfshin.Ardakani@Sun.COM name = (case_conflict) ? fileinfo->fi_shortname : fnode->od_name; 10988670SJose.Borrego@Sun.COM (void) strlcpy(fileinfo->fi_name, name, sizeof (fileinfo->fi_name)); 10998670SJose.Borrego@Sun.COM 11008670SJose.Borrego@Sun.COM /* follow link to get target node & attr */ 11018670SJose.Borrego@Sun.COM if ((fnode->vp->v_type == VLNK) && 110210001SJoyce.McIntosh@Sun.COM (smb_odir_lookup_link(sr, od, fnode->od_name, &tgt_node))) { 11038670SJose.Borrego@Sun.COM smb_node_release(fnode); 11048670SJose.Borrego@Sun.COM fnode = tgt_node; 110510001SJoyce.McIntosh@Sun.COM if ((rc = smb_node_getattr(sr, fnode, &attr)) != 0) { 110610001SJoyce.McIntosh@Sun.COM smb_node_release(fnode); 110710001SJoyce.McIntosh@Sun.COM return (rc); 110810001SJoyce.McIntosh@Sun.COM } 11098670SJose.Borrego@Sun.COM } 11108670SJose.Borrego@Sun.COM 11118670SJose.Borrego@Sun.COM /* check search attributes */ 111210001SJoyce.McIntosh@Sun.COM if (!smb_sattr_check(attr.sa_dosattr, od->d_sattr)) { 11138670SJose.Borrego@Sun.COM smb_node_release(fnode); 11148670SJose.Borrego@Sun.COM return (ENOENT); 11158670SJose.Borrego@Sun.COM } 11168670SJose.Borrego@Sun.COM 111710001SJoyce.McIntosh@Sun.COM fileinfo->fi_dosattr = attr.sa_dosattr; 111810001SJoyce.McIntosh@Sun.COM fileinfo->fi_nodeid = attr.sa_vattr.va_nodeid; 111910001SJoyce.McIntosh@Sun.COM fileinfo->fi_size = attr.sa_vattr.va_size; 112010504SKeyur.Desai@Sun.COM fileinfo->fi_alloc_size = attr.sa_allocsz; 112110001SJoyce.McIntosh@Sun.COM fileinfo->fi_atime = attr.sa_vattr.va_atime; 112210001SJoyce.McIntosh@Sun.COM fileinfo->fi_mtime = attr.sa_vattr.va_mtime; 112310001SJoyce.McIntosh@Sun.COM fileinfo->fi_ctime = attr.sa_vattr.va_ctime; 112410001SJoyce.McIntosh@Sun.COM if (attr.sa_crtime.tv_sec) 112510001SJoyce.McIntosh@Sun.COM fileinfo->fi_crtime = attr.sa_crtime; 11268670SJose.Borrego@Sun.COM else 112710001SJoyce.McIntosh@Sun.COM fileinfo->fi_crtime = attr.sa_vattr.va_mtime; 11288670SJose.Borrego@Sun.COM 11298670SJose.Borrego@Sun.COM smb_node_release(fnode); 11308670SJose.Borrego@Sun.COM return (0); 11318670SJose.Borrego@Sun.COM } 11328670SJose.Borrego@Sun.COM 11338670SJose.Borrego@Sun.COM /* 11348670SJose.Borrego@Sun.COM * smb_odir_wildcard_fileinfo 11358670SJose.Borrego@Sun.COM * 11368670SJose.Borrego@Sun.COM * odirent contains a directory entry, obtained from a vop_readdir. 11378670SJose.Borrego@Sun.COM * If a case conflict is identified the filename is mangled and the 11388670SJose.Borrego@Sun.COM * shortname is used as 'name', in place of odirent->od_name. This 11398670SJose.Borrego@Sun.COM * name will be used in the smb_fsop_lookup because smb_fsop_lookup 11408670SJose.Borrego@Sun.COM * performs a case insensitive lookup if the tree is case insesitive, 11418670SJose.Borrego@Sun.COM * so the mangled name is required in the case conflict scenario to 11428670SJose.Borrego@Sun.COM * ensure the correct match. 11438670SJose.Borrego@Sun.COM * 11448670SJose.Borrego@Sun.COM * If the looked up file is a link, we attempt to lookup the link target 11458670SJose.Borrego@Sun.COM * to use its attributes in place of those of the files's. 11468670SJose.Borrego@Sun.COM * If we fail to lookup the target of the link we use the original 11478670SJose.Borrego@Sun.COM * file's attributes. 11488670SJose.Borrego@Sun.COM * Check if the attributes match the search attributes. 11498670SJose.Borrego@Sun.COM * 11508670SJose.Borrego@Sun.COM * Although some file systems can have directories larger than 11518670SJose.Borrego@Sun.COM * SMB_MAXDIRSIZE smb_odir_next_odirent ensures that no offset larger 11528670SJose.Borrego@Sun.COM * than SMB_MAXDIRSIZE is returned. It is therefore safe to use the 11538670SJose.Borrego@Sun.COM * offset as the cookie (uint32_t). 11548670SJose.Borrego@Sun.COM * 11558670SJose.Borrego@Sun.COM * Returns: 0 - success 11568670SJose.Borrego@Sun.COM * ENOENT - no match, proceed to next entry 11578670SJose.Borrego@Sun.COM * errno - error 11588670SJose.Borrego@Sun.COM */ 11598670SJose.Borrego@Sun.COM static int 11608670SJose.Borrego@Sun.COM smb_odir_wildcard_fileinfo(smb_request_t *sr, smb_odir_t *od, 11618670SJose.Borrego@Sun.COM smb_odirent_t *odirent, smb_fileinfo_t *fileinfo) 11628670SJose.Borrego@Sun.COM { 11638670SJose.Borrego@Sun.COM int rc; 11648670SJose.Borrego@Sun.COM smb_node_t *fnode, *tgt_node; 116510001SJoyce.McIntosh@Sun.COM smb_attr_t attr; 11668670SJose.Borrego@Sun.COM char *name; 11678670SJose.Borrego@Sun.COM boolean_t case_conflict; 11688670SJose.Borrego@Sun.COM 11698670SJose.Borrego@Sun.COM ASSERT(sr); 11708670SJose.Borrego@Sun.COM ASSERT(sr->sr_magic == SMB_REQ_MAGIC); 11718670SJose.Borrego@Sun.COM ASSERT(od); 11728670SJose.Borrego@Sun.COM ASSERT(od->d_magic == SMB_ODIR_MAGIC); 11738670SJose.Borrego@Sun.COM 11748670SJose.Borrego@Sun.COM ASSERT(MUTEX_HELD(&od->d_mutex)); 11758670SJose.Borrego@Sun.COM bzero(fileinfo, sizeof (smb_fileinfo_t)); 11768670SJose.Borrego@Sun.COM 11779231SAfshin.Ardakani@Sun.COM case_conflict = ((od->d_flags & SMB_ODIR_FLAG_IGNORE_CASE) && 11788670SJose.Borrego@Sun.COM (odirent->od_eflags & ED_CASE_CONFLICT)); 11798670SJose.Borrego@Sun.COM (void) smb_mangle_name(odirent->od_ino, odirent->od_name, 11808670SJose.Borrego@Sun.COM fileinfo->fi_shortname, fileinfo->fi_name83, case_conflict); 11818670SJose.Borrego@Sun.COM name = (case_conflict) ? fileinfo->fi_shortname : odirent->od_name; 11828670SJose.Borrego@Sun.COM (void) strlcpy(fileinfo->fi_name, name, sizeof (fileinfo->fi_name)); 11838670SJose.Borrego@Sun.COM 11849343SAfshin.Ardakani@Sun.COM rc = smb_fsop_lookup(sr, od->d_cred, 0, od->d_tree->t_snode, 118510001SJoyce.McIntosh@Sun.COM od->d_dnode, name, &fnode); 11868670SJose.Borrego@Sun.COM if (rc != 0) 11878670SJose.Borrego@Sun.COM return (rc); 11888670SJose.Borrego@Sun.COM 11898670SJose.Borrego@Sun.COM /* follow link to get target node & attr */ 11908670SJose.Borrego@Sun.COM if ((fnode->vp->v_type == VLNK) && 119110001SJoyce.McIntosh@Sun.COM (smb_odir_lookup_link(sr, od, name, &tgt_node))) { 11928670SJose.Borrego@Sun.COM smb_node_release(fnode); 11938670SJose.Borrego@Sun.COM fnode = tgt_node; 119410001SJoyce.McIntosh@Sun.COM } 119510001SJoyce.McIntosh@Sun.COM 119610001SJoyce.McIntosh@Sun.COM if ((rc = smb_node_getattr(sr, fnode, &attr)) != 0) { 119710001SJoyce.McIntosh@Sun.COM smb_node_release(fnode); 119810001SJoyce.McIntosh@Sun.COM return (rc); 11998670SJose.Borrego@Sun.COM } 12008670SJose.Borrego@Sun.COM 12018670SJose.Borrego@Sun.COM /* check search attributes */ 120210001SJoyce.McIntosh@Sun.COM if (!smb_sattr_check(attr.sa_dosattr, od->d_sattr)) { 12038670SJose.Borrego@Sun.COM smb_node_release(fnode); 12048670SJose.Borrego@Sun.COM return (ENOENT); 12058670SJose.Borrego@Sun.COM } 12068670SJose.Borrego@Sun.COM 12078670SJose.Borrego@Sun.COM fileinfo->fi_cookie = (uint32_t)od->d_offset; 120810001SJoyce.McIntosh@Sun.COM fileinfo->fi_dosattr = attr.sa_dosattr; 120910001SJoyce.McIntosh@Sun.COM fileinfo->fi_nodeid = attr.sa_vattr.va_nodeid; 121010001SJoyce.McIntosh@Sun.COM fileinfo->fi_size = attr.sa_vattr.va_size; 121110504SKeyur.Desai@Sun.COM fileinfo->fi_alloc_size = attr.sa_allocsz; 121210001SJoyce.McIntosh@Sun.COM fileinfo->fi_atime = attr.sa_vattr.va_atime; 121310001SJoyce.McIntosh@Sun.COM fileinfo->fi_mtime = attr.sa_vattr.va_mtime; 121410001SJoyce.McIntosh@Sun.COM fileinfo->fi_ctime = attr.sa_vattr.va_ctime; 121510001SJoyce.McIntosh@Sun.COM if (attr.sa_crtime.tv_sec) 121610001SJoyce.McIntosh@Sun.COM fileinfo->fi_crtime = attr.sa_crtime; 12178670SJose.Borrego@Sun.COM else 121810001SJoyce.McIntosh@Sun.COM fileinfo->fi_crtime = attr.sa_vattr.va_mtime; 12198670SJose.Borrego@Sun.COM 12208670SJose.Borrego@Sun.COM smb_node_release(fnode); 12218670SJose.Borrego@Sun.COM return (0); 12228670SJose.Borrego@Sun.COM } 12238670SJose.Borrego@Sun.COM 12248670SJose.Borrego@Sun.COM /* 12258670SJose.Borrego@Sun.COM * smb_odir_lookup_link 12268670SJose.Borrego@Sun.COM * 12278670SJose.Borrego@Sun.COM * If the file is a symlink we lookup the object to which the 12288670SJose.Borrego@Sun.COM * symlink refers so that we can return its attributes. 12298670SJose.Borrego@Sun.COM * This can cause a problem if a symlink in a sub-directory 12308670SJose.Borrego@Sun.COM * points to a parent directory (some UNIX GUI's create a symlink 12318670SJose.Borrego@Sun.COM * in $HOME/.desktop that points to the user's home directory). 12328670SJose.Borrego@Sun.COM * Some Windows applications (e.g. virus scanning) loop/hang 12338670SJose.Borrego@Sun.COM * trying to follow this recursive path and there is little 12348670SJose.Borrego@Sun.COM * we can do because the path is constructed on the client. 12358670SJose.Borrego@Sun.COM * smb_dirsymlink_enable allows an end-user to disable 12368670SJose.Borrego@Sun.COM * symlinks to directories. Symlinks to other object types 12378670SJose.Borrego@Sun.COM * should be unaffected. 12388670SJose.Borrego@Sun.COM * 12398670SJose.Borrego@Sun.COM * Returns: B_TRUE - followed link. tgt_node and tgt_attr set 12408670SJose.Borrego@Sun.COM * B_FALSE - link not followed 12418670SJose.Borrego@Sun.COM */ 12428670SJose.Borrego@Sun.COM static boolean_t 12438670SJose.Borrego@Sun.COM smb_odir_lookup_link(smb_request_t *sr, smb_odir_t *od, 124410001SJoyce.McIntosh@Sun.COM char *fname, smb_node_t **tgt_node) 12458670SJose.Borrego@Sun.COM { 12468670SJose.Borrego@Sun.COM int rc; 12478670SJose.Borrego@Sun.COM 12489343SAfshin.Ardakani@Sun.COM rc = smb_fsop_lookup(sr, od->d_cred, SMB_FOLLOW_LINKS, 124910001SJoyce.McIntosh@Sun.COM od->d_tree->t_snode, od->d_dnode, fname, tgt_node); 12508670SJose.Borrego@Sun.COM if (rc != 0) { 12518670SJose.Borrego@Sun.COM *tgt_node = NULL; 12528670SJose.Borrego@Sun.COM return (B_FALSE); 12538670SJose.Borrego@Sun.COM } 12548670SJose.Borrego@Sun.COM 125510001SJoyce.McIntosh@Sun.COM if (smb_node_is_dir(*tgt_node) && (!smb_dirsymlink_enable)) { 12568670SJose.Borrego@Sun.COM smb_node_release(*tgt_node); 12578670SJose.Borrego@Sun.COM *tgt_node = NULL; 12588670SJose.Borrego@Sun.COM return (B_FALSE); 12598670SJose.Borrego@Sun.COM } 12608670SJose.Borrego@Sun.COM 12618670SJose.Borrego@Sun.COM return (B_TRUE); 12628670SJose.Borrego@Sun.COM } 1263