xref: /illumos-gate/usr/src/uts/common/fs/smbsrv/smb2_setinfo_quota.c (revision 0250c53ad267726f2438e3c6556199a0bbf588a2)
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_SET_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.21 Server Requests Setting 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_set_quota()
44  */
45 uint32_t
46 smb2_setinfo_quota(smb_request_t *sr, smb_setinfo_t *si)
47 {
48 	char		*root_path;
49 	uint32_t	status = NT_STATUS_SUCCESS;
50 	smb_ofile_t	*ofile = sr->fid_ofile;
51 	smb_node_t	*tnode;
52 	smb_quota_set_t request;
53 	uint32_t	reply;
54 	list_t		*quota_list;
55 
56 	bzero(&request, sizeof (smb_quota_set_t));
57 
58 	if (!smb_tree_has_feature(sr->tid_tree, SMB_TREE_QUOTA))
59 		return (NT_STATUS_INVALID_DEVICE_REQUEST);
60 
61 	if ((ofile->f_node == NULL) ||
62 	    (ofile->f_ftype != SMB_FTYPE_DISK))
63 		return (NT_STATUS_INVALID_DEVICE_REQUEST);
64 
65 	if (!smb_user_is_admin(sr->uid_user))
66 		return (NT_STATUS_ACCESS_DENIED);
67 
68 	tnode = sr->tid_tree->t_snode;
69 	root_path = kmem_zalloc(MAXPATHLEN, KM_SLEEP);
70 	if (smb_node_getmntpath(tnode, root_path, MAXPATHLEN) != 0) {
71 		smbsr_release_file(sr);
72 		kmem_free(root_path, MAXPATHLEN);
73 		return (NT_STATUS_INVALID_PARAMETER);
74 	}
75 
76 	quota_list = &request.qs_quota_list;
77 	list_create(quota_list, sizeof (smb_quota_t),
78 	    offsetof(smb_quota_t, q_list_node));
79 
80 	status = smb_quota_decode_quotas(&si->si_data, quota_list);
81 	if (status == NT_STATUS_SUCCESS) {
82 		request.qs_root_path = root_path;
83 		if (smb_quota_set(sr->sr_server, &request, &reply) != 0) {
84 			status = NT_STATUS_INTERNAL_ERROR;
85 		} else {
86 			status = reply;
87 			xdr_free(xdr_uint32_t, (char *)&reply);
88 		}
89 	}
90 
91 	kmem_free(root_path, MAXPATHLEN);
92 	smb_quota_free_quotas(&request.qs_quota_list);
93 	smbsr_release_file(sr);
94 
95 	return (status);
96 }
97