1*a90cf9f2SGordon Ross /* 2*a90cf9f2SGordon Ross * This file and its contents are supplied under the terms of the 3*a90cf9f2SGordon Ross * Common Development and Distribution License ("CDDL"), version 1.0. 4*a90cf9f2SGordon Ross * You may only use this file in accordance with the terms of version 5*a90cf9f2SGordon Ross * 1.0 of the CDDL. 6*a90cf9f2SGordon Ross * 7*a90cf9f2SGordon Ross * A full copy of the text of the CDDL should have accompanied this 8*a90cf9f2SGordon Ross * source. A copy of the CDDL is also available via the Internet at 9*a90cf9f2SGordon Ross * http://www.illumos.org/license/CDDL. 10*a90cf9f2SGordon Ross */ 11*a90cf9f2SGordon Ross 12*a90cf9f2SGordon Ross /* 13*a90cf9f2SGordon Ross * Copyright 2013 Nexenta Systems, Inc. All rights reserved. 14*a90cf9f2SGordon Ross */ 15*a90cf9f2SGordon Ross 16*a90cf9f2SGordon Ross /* 17*a90cf9f2SGordon Ross * Helper functions for SMB2 open handles 18*a90cf9f2SGordon Ross */ 19*a90cf9f2SGordon Ross 20*a90cf9f2SGordon Ross #include <smbsrv/smb2_kproto.h> 21*a90cf9f2SGordon Ross 22*a90cf9f2SGordon Ross uint32_t 23*a90cf9f2SGordon Ross smb2_ofile_getattr(smb_request_t *sr, smb_ofile_t *of, smb_attr_t *ap) 24*a90cf9f2SGordon Ross { 25*a90cf9f2SGordon Ross uint_t mask; 26*a90cf9f2SGordon Ross int rc; 27*a90cf9f2SGordon Ross 28*a90cf9f2SGordon Ross mask = ap->sa_mask; 29*a90cf9f2SGordon Ross bzero(ap, sizeof (*ap)); 30*a90cf9f2SGordon Ross ap->sa_mask = mask; 31*a90cf9f2SGordon Ross 32*a90cf9f2SGordon Ross switch (of->f_ftype) { 33*a90cf9f2SGordon Ross case SMB_FTYPE_DISK: 34*a90cf9f2SGordon Ross case SMB_FTYPE_PRINTER: 35*a90cf9f2SGordon Ross rc = smb_node_getattr(sr, of->f_node, of->f_cr, of, ap); 36*a90cf9f2SGordon Ross break; 37*a90cf9f2SGordon Ross case SMB_FTYPE_BYTE_PIPE: 38*a90cf9f2SGordon Ross case SMB_FTYPE_MESG_PIPE: 39*a90cf9f2SGordon Ross rc = smb_opipe_getattr(of, ap); 40*a90cf9f2SGordon Ross break; 41*a90cf9f2SGordon Ross default: 42*a90cf9f2SGordon Ross rc = ENOTTY; 43*a90cf9f2SGordon Ross break; 44*a90cf9f2SGordon Ross } 45*a90cf9f2SGordon Ross if (rc) 46*a90cf9f2SGordon Ross return (smb_errno2status(rc)); 47*a90cf9f2SGordon Ross 48*a90cf9f2SGordon Ross return (0); 49*a90cf9f2SGordon Ross } 50*a90cf9f2SGordon Ross 51*a90cf9f2SGordon Ross /* 52*a90cf9f2SGordon Ross * Get the stuff needed by FileStandardInformation that was 53*a90cf9f2SGordon Ross * not already obtained by smb2_ofile_getattr(). 54*a90cf9f2SGordon Ross * (qi_delete_on_close, qi_isdir) 55*a90cf9f2SGordon Ross */ 56*a90cf9f2SGordon Ross uint32_t 57*a90cf9f2SGordon Ross smb2_ofile_getstd(smb_ofile_t *of, smb_queryinfo_t *qi) 58*a90cf9f2SGordon Ross { 59*a90cf9f2SGordon Ross smb_node_t *node; 60*a90cf9f2SGordon Ross 61*a90cf9f2SGordon Ross switch (of->f_ftype) { 62*a90cf9f2SGordon Ross case SMB_FTYPE_DISK: 63*a90cf9f2SGordon Ross case SMB_FTYPE_PRINTER: 64*a90cf9f2SGordon Ross node = of->f_node; 65*a90cf9f2SGordon Ross qi->qi_delete_on_close = 66*a90cf9f2SGordon Ross (node->flags & NODE_FLAGS_DELETE_ON_CLOSE) != 0; 67*a90cf9f2SGordon Ross qi->qi_isdir = smb_node_is_dir(node); 68*a90cf9f2SGordon Ross break; 69*a90cf9f2SGordon Ross case SMB_FTYPE_BYTE_PIPE: 70*a90cf9f2SGordon Ross case SMB_FTYPE_MESG_PIPE: 71*a90cf9f2SGordon Ross qi->qi_delete_on_close = 1; 72*a90cf9f2SGordon Ross qi->qi_isdir = 0; 73*a90cf9f2SGordon Ross break; 74*a90cf9f2SGordon Ross default: 75*a90cf9f2SGordon Ross return (NT_STATUS_INVALID_DEVICE_REQUEST); 76*a90cf9f2SGordon Ross } 77*a90cf9f2SGordon Ross 78*a90cf9f2SGordon Ross return (0); 79*a90cf9f2SGordon Ross } 80*a90cf9f2SGordon Ross 81*a90cf9f2SGordon Ross /* 82*a90cf9f2SGordon Ross * Get info for FileNameInformation, FileAlternateNameInformation. 83*a90cf9f2SGordon Ross * (qi_name, qi_shortname) 84*a90cf9f2SGordon Ross */ 85*a90cf9f2SGordon Ross uint32_t 86*a90cf9f2SGordon Ross smb2_ofile_getname(smb_ofile_t *of, smb_queryinfo_t *qi) 87*a90cf9f2SGordon Ross { 88*a90cf9f2SGordon Ross int rc; 89*a90cf9f2SGordon Ross 90*a90cf9f2SGordon Ross switch (of->f_ftype) { 91*a90cf9f2SGordon Ross case SMB_FTYPE_DISK: 92*a90cf9f2SGordon Ross case SMB_FTYPE_PRINTER: 93*a90cf9f2SGordon Ross rc = smb_node_getshrpath(of->f_node, of->f_tree, 94*a90cf9f2SGordon Ross qi->qi_name, MAXPATHLEN); 95*a90cf9f2SGordon Ross break; 96*a90cf9f2SGordon Ross case SMB_FTYPE_BYTE_PIPE: 97*a90cf9f2SGordon Ross case SMB_FTYPE_MESG_PIPE: 98*a90cf9f2SGordon Ross rc = smb_opipe_getname(of, qi->qi_name, MAXPATHLEN); 99*a90cf9f2SGordon Ross break; 100*a90cf9f2SGordon Ross default: 101*a90cf9f2SGordon Ross rc = ENOTTY; 102*a90cf9f2SGordon Ross break; 103*a90cf9f2SGordon Ross } 104*a90cf9f2SGordon Ross if (rc) 105*a90cf9f2SGordon Ross return (smb_errno2status(rc)); 106*a90cf9f2SGordon Ross qi->qi_namelen = smb_wcequiv_strlen(qi->qi_name); 107*a90cf9f2SGordon Ross 108*a90cf9f2SGordon Ross return (0); 109*a90cf9f2SGordon Ross 110*a90cf9f2SGordon Ross } 111