xref: /illumos-gate/usr/src/uts/common/fs/smbsrv/smb2_close.c (revision 48edc7cf07b5dccc3ad84bf2dafe4150bd666d60)
1 /*
2  * This file and its contents are supplied under the terms of the
3  * Common Development and Distribution License ("CDDL"), version 1.0.
4  * You may only use this file in accordance with the terms of version
5  * 1.0 of the CDDL.
6  *
7  * A full copy of the text of the CDDL should have accompanied this
8  * source.  A copy of the CDDL is also available via the Internet at
9  * http://www.illumos.org/license/CDDL.
10  */
11 
12 /*
13  * Copyright 2014 Nexenta Systems, Inc.  All rights reserved.
14  */
15 
16 /*
17  * Dispatch function for SMB2_CLOSE
18  */
19 
20 #include <smbsrv/smb2_kproto.h>
21 
22 smb_sdrc_t
23 smb2_close(smb_request_t *sr)
24 {
25 	smb_attr_t attr;
26 	smb_ofile_t *of;
27 	uint16_t StructSize;
28 	uint16_t Flags;
29 	uint32_t reserved;
30 	smb2fid_t smb2fid;
31 	uint32_t status;
32 	int rc = 0;
33 
34 	/*
35 	 * SMB2 Close request
36 	 */
37 	rc = smb_mbc_decodef(
38 	    &sr->smb_data, "wwlqq",
39 	    &StructSize,		/* w */
40 	    &Flags,			/* w */
41 	    &reserved,			/* l */
42 	    &smb2fid.persistent,	/* q */
43 	    &smb2fid.temporal);		/* q */
44 	if (rc)
45 		return (SDRC_ERROR);
46 	if (StructSize != 24)
47 		return (SDRC_ERROR);
48 
49 	status = smb2sr_lookup_fid(sr, &smb2fid);
50 	if (status) {
51 		smb2sr_put_error(sr, status);
52 		return (SDRC_SUCCESS);
53 	}
54 	of = sr->fid_ofile;
55 
56 	bzero(&attr, sizeof (attr));
57 	if (Flags & SMB2_CLOSE_FLAG_POSTQUERY_ATTRIB) {
58 		attr.sa_mask = SMB_AT_ALL;
59 		status = smb2_ofile_getattr(sr, of, &attr);
60 		if (status) {
61 			/*
62 			 * We could not stat the open file.
63 			 * Let's not fail the close call,
64 			 * but just turn off the flag.
65 			 */
66 			Flags = 0;
67 		}
68 	}
69 
70 	smb_ofile_close(of, 0);
71 
72 	/*
73 	 * SMB2 Close reply
74 	 */
75 	(void) smb_mbc_encodef(
76 	    &sr->reply,
77 	    "wwlTTTTqql",
78 	    60,	/* StructSize */	/* w */
79 	    Flags,			/* w */
80 	    0, /* reserved */		/* l */
81 	    &attr.sa_crtime,		/* T */
82 	    &attr.sa_vattr.va_atime,	/* T */
83 	    &attr.sa_vattr.va_mtime,	/* T */
84 	    &attr.sa_vattr.va_ctime,	/* T */
85 	    attr.sa_allocsz,		/* q */
86 	    attr.sa_vattr.va_size,	/* q */
87 	    attr.sa_dosattr);		/* l */
88 
89 	return (SDRC_SUCCESS);
90 }
91