xref: /illumos-gate/usr/src/uts/common/fs/smbsrv/smb2_qinfo_quota.c (revision 1a2d662a91cee3bf82f41cd47c7ae6f3825d9db2)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
24  * Copyright 2013 Nexenta Systems, Inc.  All rights reserved.
25  * Copyright 2022 RackTop Systems, Inc.
26  */
27 
28 /*
29  * Dispatch function for SMB2_QUERY_INFO
30  */
31 
32 #include <smbsrv/smb2_kproto.h>
33 #include <smbsrv/smb_fsops.h>
34 #include <smbsrv/ntifs.h>
35 
36 /*
37  * MS-FSA 2.1.5.20 Server Requests Querying Quota Information
38  *
39  * Support for this operation is optional. If the object store does not
40  * implement this functionality, the operation MUST be failed with
41  * STATUS_INVALID_DEVICE_REQUEST
42  *
43  * Similar to smb_nt_transact_query_quota()
44  */
45 uint32_t
46 smb2_qinfo_quota(smb_request_t *sr, smb_queryinfo_t *qi)
47 {
48 	_NOTE(ARGUNUSED(qi))
49 	uint8_t		single, restart;
50 	uint32_t	sidlistlen, startsidlen, startsidoff;
51 	smb_node_t	*tnode;
52 	smb_ofile_t	*ofile = sr->fid_ofile;
53 	smb_quota_query_t request;
54 	smb_quota_response_t reply;
55 	uint32_t status = NT_STATUS_SUCCESS;
56 	int rc;
57 
58 	bzero(&request, sizeof (smb_quota_query_t));
59 	bzero(&reply, sizeof (smb_quota_response_t));
60 
61 	if (!smb_tree_has_feature(sr->tid_tree, SMB_TREE_QUOTA))
62 		return (NT_STATUS_INVALID_DEVICE_REQUEST);
63 
64 	if ((ofile->f_node == NULL) ||
65 	    (ofile->f_ftype != SMB_FTYPE_DISK))
66 		return (NT_STATUS_INVALID_DEVICE_REQUEST);
67 
68 	rc = smb_mbc_decodef(
69 	    &sr->smb_data, "bb..lll",
70 	    &single,		/* b */
71 	    &restart,		/* b */
72 	    /* reserved		  .. */
73 	    &sidlistlen,	/* l */
74 	    &startsidlen,	/* l */
75 	    &startsidoff);	/* l */
76 	if (rc)
77 		return (NT_STATUS_INVALID_PARAMETER);
78 
79 	if ((sidlistlen != 0) && (startsidlen != 0))
80 		return (NT_STATUS_INVALID_PARAMETER);
81 
82 
83 	tnode = sr->tid_tree->t_snode;
84 	request.qq_root_path = kmem_zalloc(MAXPATHLEN, KM_SLEEP);
85 	if (smb_node_getmntpath(tnode, request.qq_root_path, MAXPATHLEN) != 0) {
86 		kmem_free(request.qq_root_path, MAXPATHLEN);
87 		return (NT_STATUS_INVALID_PARAMETER);
88 	}
89 
90 	if (sidlistlen != 0)
91 		request.qq_query_op = SMB_QUOTA_QUERY_SIDLIST;
92 	else if (startsidlen != 0)
93 		request.qq_query_op = SMB_QUOTA_QUERY_STARTSID;
94 	else
95 		request.qq_query_op = SMB_QUOTA_QUERY_ALL;
96 
97 	request.qq_single = single;
98 	request.qq_restart = restart;
99 	smb_quota_max_quota(&sr->raw_data, &request);
100 
101 	status = smb_quota_init_sids(&sr->smb_data, &request, ofile);
102 
103 	if (status == NT_STATUS_SUCCESS) {
104 		if (smb_quota_query(sr->sr_server, &request, &reply) != 0) {
105 			status = NT_STATUS_INTERNAL_ERROR;
106 		} else {
107 			status = reply.qr_status;
108 			if (status == NT_STATUS_SUCCESS) {
109 				status = smb_quota_encode_quotas(
110 				    &sr->raw_data,
111 				    &request, &reply, ofile);
112 			}
113 			xdr_free(smb_quota_response_xdr, (char *)&reply);
114 		}
115 	}
116 
117 	kmem_free(request.qq_root_path, MAXPATHLEN);
118 	smb_quota_free_sids(&request);
119 
120 	if (status != NT_STATUS_SUCCESS) {
121 		if (status == NT_STATUS_NO_MORE_ENTRIES) {
122 			smb_ofile_set_quota_resume(ofile, NULL);
123 			smbsr_warn(sr, status, 0, 0);
124 			status = NT_STATUS_SUCCESS;
125 		} else {
126 			smbsr_error(sr, status, 0, 0);
127 		}
128 	}
129 
130 	return (status);
131 }
132