xref: /illumos-gate/usr/src/uts/common/fs/smbsrv/smb2_setinfo_quota.c (revision 5a342f146a946ddf6f5f5afd4a5dd5baf11d7dd4)
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  */
26 
27 /*
28  * Dispatch function for SMB2_SET_INFO
29  */
30 
31 #include <smbsrv/smb2_kproto.h>
32 #include <smbsrv/smb_fsops.h>
33 #include <smbsrv/ntifs.h>
34 
35 /*
36  * Similar to smb_nt_transact_set_quota()
37  */
38 uint32_t
39 smb2_setinfo_quota(smb_request_t *sr, smb_setinfo_t *si)
40 {
41 	char		*root_path;
42 	uint32_t	status = NT_STATUS_SUCCESS;
43 	smb_ofile_t	*ofile = sr->fid_ofile;
44 	smb_node_t	*tnode;
45 	smb_quota_set_t request;
46 	uint32_t	reply;
47 	list_t 		*quota_list;
48 
49 	bzero(&request, sizeof (smb_quota_set_t));
50 
51 	if (!smb_tree_has_feature(sr->tid_tree, SMB_TREE_QUOTA))
52 		return (NT_STATUS_NOT_SUPPORTED);
53 
54 	if (!smb_user_is_admin(sr->uid_user))
55 		return (NT_STATUS_ACCESS_DENIED);
56 
57 	if ((ofile->f_node == NULL) ||
58 	    (ofile->f_ftype != SMB_FTYPE_DISK))
59 		return (NT_STATUS_ACCESS_DENIED);
60 
61 	tnode = sr->tid_tree->t_snode;
62 	root_path = kmem_zalloc(MAXPATHLEN, KM_SLEEP);
63 	if (smb_node_getmntpath(tnode, root_path, MAXPATHLEN) != 0) {
64 		smbsr_release_file(sr);
65 		kmem_free(root_path, MAXPATHLEN);
66 		return (NT_STATUS_INVALID_PARAMETER);
67 	}
68 
69 	quota_list = &request.qs_quota_list;
70 	list_create(quota_list, sizeof (smb_quota_t),
71 	    offsetof(smb_quota_t, q_list_node));
72 
73 	status = smb_quota_decode_quotas(&si->si_data, quota_list);
74 	if (status == NT_STATUS_SUCCESS) {
75 		request.qs_root_path = root_path;
76 		if (smb_quota_set(sr->sr_server, &request, &reply) != 0) {
77 			status = NT_STATUS_INTERNAL_ERROR;
78 		} else {
79 			status = reply;
80 			xdr_free(xdr_uint32_t, (char *)&reply);
81 		}
82 	}
83 
84 	kmem_free(root_path, MAXPATHLEN);
85 	smb_quota_free_quotas(&request.qs_quota_list);
86 	smbsr_release_file(sr);
87 
88 	return (status);
89 }
90