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 2014 Nexenta Systems, Inc. All rights reserved. 14*a90cf9f2SGordon Ross */ 15*a90cf9f2SGordon Ross 16*a90cf9f2SGordon Ross /* 17*a90cf9f2SGordon Ross * Dispatch function for SMB2_CLOSE 18*a90cf9f2SGordon Ross */ 19*a90cf9f2SGordon Ross 20*a90cf9f2SGordon Ross #include <smbsrv/smb2_kproto.h> 21*a90cf9f2SGordon Ross 22*a90cf9f2SGordon Ross smb_sdrc_t 23*a90cf9f2SGordon Ross smb2_close(smb_request_t *sr) 24*a90cf9f2SGordon Ross { 25*a90cf9f2SGordon Ross smb_attr_t attr; 26*a90cf9f2SGordon Ross smb_ofile_t *of; 27*a90cf9f2SGordon Ross uint16_t StructSize; 28*a90cf9f2SGordon Ross uint16_t Flags; 29*a90cf9f2SGordon Ross uint32_t reserved; 30*a90cf9f2SGordon Ross smb2fid_t smb2fid; 31*a90cf9f2SGordon Ross uint32_t status; 32*a90cf9f2SGordon Ross int rc = 0; 33*a90cf9f2SGordon Ross 34*a90cf9f2SGordon Ross /* 35*a90cf9f2SGordon Ross * SMB2 Close request 36*a90cf9f2SGordon Ross */ 37*a90cf9f2SGordon Ross rc = smb_mbc_decodef( 38*a90cf9f2SGordon Ross &sr->smb_data, "wwlqq", 39*a90cf9f2SGordon Ross &StructSize, /* w */ 40*a90cf9f2SGordon Ross &Flags, /* w */ 41*a90cf9f2SGordon Ross &reserved, /* l */ 42*a90cf9f2SGordon Ross &smb2fid.persistent, /* q */ 43*a90cf9f2SGordon Ross &smb2fid.temporal); /* q */ 44*a90cf9f2SGordon Ross if (rc) 45*a90cf9f2SGordon Ross return (SDRC_ERROR); 46*a90cf9f2SGordon Ross if (StructSize != 24) 47*a90cf9f2SGordon Ross return (SDRC_ERROR); 48*a90cf9f2SGordon Ross 49*a90cf9f2SGordon Ross status = smb2sr_lookup_fid(sr, &smb2fid); 50*a90cf9f2SGordon Ross if (status) { 51*a90cf9f2SGordon Ross smb2sr_put_error(sr, status); 52*a90cf9f2SGordon Ross return (SDRC_SUCCESS); 53*a90cf9f2SGordon Ross } 54*a90cf9f2SGordon Ross of = sr->fid_ofile; 55*a90cf9f2SGordon Ross 56*a90cf9f2SGordon Ross bzero(&attr, sizeof (attr)); 57*a90cf9f2SGordon Ross if (Flags & SMB2_CLOSE_FLAG_POSTQUERY_ATTRIB) { 58*a90cf9f2SGordon Ross attr.sa_mask = SMB_AT_ALL; 59*a90cf9f2SGordon Ross status = smb2_ofile_getattr(sr, of, &attr); 60*a90cf9f2SGordon Ross if (status) { 61*a90cf9f2SGordon Ross /* 62*a90cf9f2SGordon Ross * We could not stat the open file. 63*a90cf9f2SGordon Ross * Let's not fail the close call, 64*a90cf9f2SGordon Ross * but just turn off the flag. 65*a90cf9f2SGordon Ross */ 66*a90cf9f2SGordon Ross Flags = 0; 67*a90cf9f2SGordon Ross } 68*a90cf9f2SGordon Ross } 69*a90cf9f2SGordon Ross 70*a90cf9f2SGordon Ross smb_ofile_close(of, 0); 71*a90cf9f2SGordon Ross 72*a90cf9f2SGordon Ross /* 73*a90cf9f2SGordon Ross * SMB2 Close reply 74*a90cf9f2SGordon Ross */ 75*a90cf9f2SGordon Ross (void) smb_mbc_encodef( 76*a90cf9f2SGordon Ross &sr->reply, 77*a90cf9f2SGordon Ross "wwlTTTTqql", 78*a90cf9f2SGordon Ross 60, /* StructSize */ /* w */ 79*a90cf9f2SGordon Ross Flags, /* w */ 80*a90cf9f2SGordon Ross 0, /* reserved */ /* l */ 81*a90cf9f2SGordon Ross &attr.sa_crtime, /* T */ 82*a90cf9f2SGordon Ross &attr.sa_vattr.va_atime, /* T */ 83*a90cf9f2SGordon Ross &attr.sa_vattr.va_mtime, /* T */ 84*a90cf9f2SGordon Ross &attr.sa_vattr.va_ctime, /* T */ 85*a90cf9f2SGordon Ross attr.sa_allocsz, /* q */ 86*a90cf9f2SGordon Ross attr.sa_vattr.va_size, /* q */ 87*a90cf9f2SGordon Ross attr.sa_dosattr); /* l */ 88*a90cf9f2SGordon Ross 89*a90cf9f2SGordon Ross return (SDRC_SUCCESS); 90*a90cf9f2SGordon Ross } 91