xref: /illumos-gate/usr/src/uts/common/fs/smbsrv/smb2_set_info.c (revision 93bc28dbaee6387120d48b12b3dc1ba5f7418e6e)
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 2017 Nexenta Systems, Inc.  All rights reserved.
14  */
15 
16 /*
17  * Dispatch function for SMB2_SET_INFO
18  */
19 
20 #include <smbsrv/smb2_kproto.h>
21 #include <smbsrv/smb_fsops.h>
22 #include <smbsrv/ntifs.h>
23 
24 smb_sdrc_t
smb2_set_info(smb_request_t * sr)25 smb2_set_info(smb_request_t *sr)
26 {
27 	smb_setinfo_t sinfo;
28 	uint16_t StructSize;
29 	uint16_t iBufOffset;
30 	uint32_t iBufLength;
31 	uint32_t AddlInfo;
32 	smb2fid_t smb2fid;
33 	uint32_t status;
34 	uint8_t InfoType, InfoClass;
35 	int rc = 0;
36 
37 	bzero(&sinfo, sizeof (sinfo));
38 
39 	/*
40 	 * Decode SMB2 Set Info request
41 	 */
42 	rc = smb_mbc_decodef(
43 	    &sr->smb_data, "wbblw..lqq",
44 	    &StructSize,		/* w */
45 	    &InfoType,			/* b */
46 	    &InfoClass,			/* b */
47 	    &iBufLength,		/* l */
48 	    &iBufOffset,		/* w */
49 	    /* reserved			  .. */
50 	    &AddlInfo,			/* l */
51 	    &smb2fid.persistent,	/* q */
52 	    &smb2fid.temporal);		/* q */
53 	if (rc || StructSize != 33)
54 		return (SDRC_ERROR);
55 
56 	/*
57 	 * If there's an input buffer, setup a shadow.
58 	 */
59 	if (iBufLength) {
60 		rc = MBC_SHADOW_CHAIN(&sinfo.si_data, &sr->smb_data,
61 		    sr->smb2_cmd_hdr + iBufOffset, iBufLength);
62 		if (rc) {
63 			return (SDRC_ERROR);
64 		}
65 	}
66 
67 	/* No output data. */
68 	sr->raw_data.max_bytes = 0;
69 
70 	status = smb2sr_lookup_fid(sr, &smb2fid);
71 	DTRACE_SMB2_START(op__SetInfo, smb_request_t *, sr);
72 
73 	if (status)
74 		goto errout;
75 
76 	if (iBufLength > smb2_max_trans) {
77 		status = NT_STATUS_INVALID_PARAMETER;
78 		goto errout;
79 	}
80 
81 	sinfo.si_node = sr->fid_ofile->f_node;
82 	sr->user_cr = sr->fid_ofile->f_cr;
83 
84 	switch (InfoType) {
85 	case SMB2_0_INFO_FILE:
86 		status = smb2_setinfo_file(sr, &sinfo, InfoClass);
87 		break;
88 	case SMB2_0_INFO_FILESYSTEM:
89 		status = smb2_setinfo_fs(sr, &sinfo, InfoClass);
90 		break;
91 	case SMB2_0_INFO_SECURITY:
92 		status = smb2_setinfo_sec(sr, &sinfo, AddlInfo);
93 		break;
94 	case SMB2_0_INFO_QUOTA:
95 		status = smb2_setinfo_quota(sr, &sinfo);
96 		break;
97 	default:
98 		status = NT_STATUS_INVALID_PARAMETER;
99 		break;
100 	}
101 
102 errout:
103 	sr->smb2_status = status;
104 	DTRACE_SMB2_DONE(op__SetInfo, smb_request_t *, sr);
105 
106 	if (status) {
107 		smb2sr_put_error(sr, status);
108 		return (SDRC_SUCCESS);
109 	}
110 
111 	/*
112 	 * SMB2 Query Info reply
113 	 */
114 	(void) smb_mbc_encodef(
115 	    &sr->reply, "w..",
116 	    2);	/* StructSize */	/* w */
117 
118 	return (SDRC_SUCCESS);
119 }
120