smb_nt_transact_quota.c revision 9fb67ea305c66b6a297583b9b0db6796b0dfe497
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe/*
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * CDDL HEADER START
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * The contents of this file are subject to the terms of the
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Common Development and Distribution License (the "License").
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * You may not use this file except in compliance with the License.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * or http://www.opensolaris.org/os/licensing.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * See the License for the specific language governing permissions
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * and limitations under the License.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * When distributing Covered Code, include this CDDL HEADER in each
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * If applicable, add the following below this CDDL HEADER, with the
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * fields enclosed by brackets "[]" replaced with your own identifying
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * information: Portions Copyright [yyyy] [name of copyright owner]
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * CDDL HEADER END
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe/*
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Use is subject to license terms.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe#include <smbsrv/smb_kproto.h>
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe#include <smbsrv/smb_fsops.h>
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe#include <smbsrv/smb_share.h>
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe#include <smbsrv/string.h>
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe#include <smbsrv/lmerr.h>
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe#include <sys/fs/zfs.h>
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe#include <smbsrv/smb_xdr.h>
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe#include <smbsrv/smb_door.h>
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe#include <smbsrv/smb_idmap.h>
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe/*
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * A user/group quota entry passed over the wire consists of:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * - next offset (uint32_t)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * - length of SID (uint32_t)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * - last modified time (uint64_t)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * - quota used (uint64_t)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * - quota limit (uint64_t)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * - quota threahold (uint64_t)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * - variable length sid - max = 32 bytes
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * SMB_QUOTA_SIZE_NO_SID is the size of the above, excluding the sid.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe#define SMB_QUOTA_SIZE_NO_SID \
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe ((2 * sizeof (uint32_t)) + (4 * sizeof (uint64_t)))
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe#define SMB_QUOTA_EST_SIZE (SMB_QUOTA_SIZE_NO_SID + SMB_EST_SID_SIZE)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe#define SMB_QUOTA_MAX_SIZE (SMB_QUOTA_SIZE_NO_SID + SMB_MAX_SID_SIZE)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowestatic int smb_quota_query(smb_quota_query_t *, smb_quota_response_t *);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowestatic int smb_quota_set(smb_quota_set_t *, uint32_t *);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowestatic uint32_t smb_quota_init_sids(smb_xa_t *, smb_quota_query_t *,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe smb_ofile_t *);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowestatic uint32_t smb_quota_decode_sids(smb_xa_t *, list_t *);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowestatic void smb_quota_free_sids(smb_quota_query_t *);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowestatic void smb_quota_max_quota(smb_xa_t *, smb_quota_query_t *);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowestatic uint32_t smb_quota_decode_quotas(smb_xa_t *, list_t *);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowestatic uint32_t smb_quota_encode_quotas(smb_xa_t *, smb_quota_query_t *,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe smb_quota_response_t *, smb_ofile_t *);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowestatic void smb_quota_free_quotas(list_t *);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe/*
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * smb_nt_transact_query_quota
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * This method allows the client to retrieve quota information from
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * the server. The result of the call is returned to the client in the
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Data part of the transaction response.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * On entry, the 'TotalParameterCount' field must be equal to 16, and the
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * client parameter block must be encoded with the following parameters:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Request Description
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * ========================== ==================================
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * WORD fid SMB file identifier of the target directory
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * BYTE ReturnSingleEntry A boolean indicating whether to return
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * a single entry (TRUE) or multiple entries (FALSE).
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * BYTE RestartScan A boolean indicating whether to continue from
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * the previous request (FALSE) or restart a new
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * sequence (TRUE).
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * DWORD SidListLength The length, in bytes, of the SidList in the
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * data block or 0 if there is no SidList.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * DWORD StartSidLength If SidListLength is 0 (i.e. there is no SidList
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * in the data block), then this is either:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * 1) the (non-zero) length in bytes of the
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * StartSid in the parameter buffer, or
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * 2) if 0, there is no StartSid in the
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * parameter buffer, in which case, all SIDs
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * are to be enumerated as if they were
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * passed in the SidList.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Otherwise, StartSidLength is ignored.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * DWORD StartSidOffset The offset, in bytes, to the StartSid in the
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * parameter block (if one exists).
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * One of SidListLength and StartSidLength must be 0.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * An SMB_COM_NT_TRANSACTION response is sent in reply when the request
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * is successful. The 'TotalParameterCount' is set to 4, and the parameter
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * block in the server response contains a 32-bit unsigned integer
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * indicating the length, in bytes, of the returned quota information.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * The 'TotalDataCount' is set to indicate the length of the data buffer,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * and the data buffer contains the following quota information:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Data Block Encoding Description
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * ================================== =================================
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * ULONG NextEntryOffset; Offset to start of next entry from
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * start of this entry, or 0 for the
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * final entry
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * ULONG SidLength; Length (bytes) of SID
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * SMB_TIME ChangeTime; Time that the quota was last changed
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * LARGE_INTEGER QuotaUsed; Amount of quota (bytes) used by user
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * LARGE_INTEGER QuotaThreshold; Quota warning limit (bytes) for user
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * LARGE_INTEGER QuotaLimit; The quota limit (bytes) for this user
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * USHORT Sid; Search handle
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowesmb_sdrc_t
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowesmb_nt_transact_query_quota(smb_request_t *sr, smb_xa_t *xa)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe{
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe uint8_t single, restart;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe uint32_t sidlistlen, startsidlen, startsidoff;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe smb_node_t *tnode;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe smb_ofile_t *ofile;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe smb_quota_query_t request;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe smb_quota_response_t reply;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe uint32_t status = NT_STATUS_SUCCESS;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe bzero(&request, sizeof (smb_quota_query_t));
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe bzero(&reply, sizeof (smb_quota_response_t));
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (!smb_tree_has_feature(sr->tid_tree, SMB_TREE_QUOTA)) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe smbsr_error(sr, NT_STATUS_NOT_SUPPORTED, 0, 0);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe return (SDRC_ERROR);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (xa->smb_tpscnt != 16) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe smbsr_error(sr, NT_STATUS_INVALID_PARAMETER, 0, 0);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe return (SDRC_ERROR);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (smb_mbc_decodef(&xa->req_param_mb, "%wbblll", sr, &sr->smb_fid,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe &single, &restart, &sidlistlen, &startsidlen, &startsidoff)) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe smbsr_error(sr, NT_STATUS_INVALID_PARAMETER, 0, 0);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe return (SDRC_ERROR);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if ((sidlistlen != 0) && (startsidlen != 0)) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe smbsr_error(sr, NT_STATUS_INVALID_PARAMETER, 0, 0);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe return (SDRC_ERROR);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe smbsr_lookup_file(sr);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe ofile = sr->fid_ofile;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (ofile == NULL) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe smbsr_error(sr, NT_STATUS_INVALID_HANDLE, ERRDOS, ERRbadfid);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe return (SDRC_ERROR);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if ((ofile->f_node == NULL) || (ofile->f_ftype != SMB_FTYPE_DISK)) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe smbsr_error(sr, NT_STATUS_ACCESS_DENIED, ERRDOS,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe ERROR_ACCESS_DENIED);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe smbsr_release_file(sr);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe return (SDRC_ERROR);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe tnode = sr->tid_tree->t_snode;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe request.qq_root_path = kmem_zalloc(MAXPATHLEN, KM_SLEEP);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (smb_node_getmntpath(tnode, request.qq_root_path, MAXPATHLEN) != 0) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe smbsr_error(sr, NT_STATUS_INVALID_PARAMETER, ERRDOS,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe ERROR_INVALID_PARAMETER);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe smbsr_release_file(sr);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe kmem_free(request.qq_root_path, MAXPATHLEN);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe return (SDRC_ERROR);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (sidlistlen != 0)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe request.qq_query_op = SMB_QUOTA_QUERY_SIDLIST;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe else if (startsidlen != 0)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe request.qq_query_op = SMB_QUOTA_QUERY_STARTSID;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe else
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe request.qq_query_op = SMB_QUOTA_QUERY_ALL;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe request.qq_single = single;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe request.qq_restart = restart;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe smb_quota_max_quota(xa, &request);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe status = smb_quota_init_sids(xa, &request, ofile);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (status == NT_STATUS_SUCCESS) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (smb_quota_query(&request, &reply) != 0) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe status = NT_STATUS_INTERNAL_ERROR;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe } else {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe status = reply.qr_status;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (status == NT_STATUS_SUCCESS) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe status = smb_quota_encode_quotas(xa,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe &request, &reply, ofile);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe xdr_free(smb_quota_response_xdr, (char *)&reply);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe kmem_free(request.qq_root_path, MAXPATHLEN);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe smb_quota_free_sids(&request);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (status != NT_STATUS_SUCCESS) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (status == NT_STATUS_NO_MORE_DATA) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe smb_ofile_set_quota_resume(ofile, NULL);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe smbsr_warn(sr, status, 0, 0);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe status = NT_STATUS_SUCCESS;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe } else {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe smbsr_error(sr, status, 0, 0);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (void) smb_mbc_encodef(&xa->rep_param_mb, "l", 0);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe smbsr_release_file(sr);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe return ((status == NT_STATUS_SUCCESS) ? SDRC_SUCCESS : SDRC_ERROR);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe}
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe/*
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * smb_nt_transact_set_quota
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * This method allows the client to set quota information on the server.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * The result status of the call is returned to the client in the
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * 'status' field of the SMB response header.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * On entry, the 'TotalParameterCount' field must be equal to 2, and the
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * client parameter block must be encoded with the following parameters:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Data Block Encoding Description
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * ================================== =================================
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * ULONG NextEntryOffset; Offset to start of next entry from
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * start of this entry, or 0 for the
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * final entry
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * ULONG SidLength; Length (bytes) of SID
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * SMB_TIME ChangeTime; Time that the quota was last changed
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * LARGE_INTEGER QuotaUsed; Amount of quota (bytes) used by user
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * LARGE_INTEGER QuotaThreshold; Quota warning limit (bytes) for user
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * LARGE_INTEGER QuotaLimit; The quota limit (bytes) for this user
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * VARIABLE Sid; Security identifier of the user
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * An SMB_COM_NT_TRANSACTION response is sent in reply when the request
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * is successful. The 'TotalParameterCount' and the 'TotalDataCount' are set
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * to 0, and the parameter block 'Status' field in the server SMB response
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * header contains a 32-bit unsigned integer indicating the result status
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * (NT_STATUS_SUCCESS if successful).
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Only users with Admin privileges (i.e. of the BUILTIN/Administrators
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * group) will be allowed to set quotas.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowesmb_sdrc_t
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowesmb_nt_transact_set_quota(smb_request_t *sr, smb_xa_t *xa)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe{
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe char *root_path;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe uint32_t status = NT_STATUS_SUCCESS;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe smb_node_t *tnode;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe smb_ofile_t *ofile;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe smb_quota_set_t request;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe uint32_t reply;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe list_t *quota_list;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe bzero(&request, sizeof (smb_quota_set_t));
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (!smb_tree_has_feature(sr->tid_tree, SMB_TREE_QUOTA)) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe smbsr_error(sr, NT_STATUS_NOT_SUPPORTED, 0, 0);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe return (SDRC_ERROR);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (!smb_user_is_admin(sr->uid_user)) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe smbsr_error(sr, NT_STATUS_ACCESS_DENIED, ERRSRV, ERRaccess);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe return (-1);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (xa->smb_tpscnt != 2) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe smbsr_error(sr, NT_STATUS_INVALID_PARAMETER, 0, 0);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe return (SDRC_ERROR);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (smb_mbc_decodef(&xa->req_param_mb, "%w", sr,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe &sr->smb_fid)) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe smbsr_error(sr, NT_STATUS_INVALID_PARAMETER, 0, 0);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe return (SDRC_ERROR);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe smbsr_lookup_file(sr);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe ofile = sr->fid_ofile;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (ofile == NULL) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe smbsr_error(sr, NT_STATUS_INVALID_HANDLE, ERRDOS, ERRbadfid);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe return (SDRC_ERROR);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if ((ofile->f_node == NULL) || (ofile->f_ftype != SMB_FTYPE_DISK)) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe smbsr_error(sr, NT_STATUS_ACCESS_DENIED, ERRDOS,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe ERROR_ACCESS_DENIED);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe smbsr_release_file(sr);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe return (SDRC_ERROR);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe tnode = sr->tid_tree->t_snode;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe root_path = kmem_zalloc(MAXPATHLEN, KM_SLEEP);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (smb_node_getmntpath(tnode, root_path, MAXPATHLEN) != 0) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe smbsr_error(sr, NT_STATUS_INVALID_PARAMETER, ERRDOS,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe ERROR_INVALID_PARAMETER);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe smbsr_release_file(sr);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe kmem_free(root_path, MAXPATHLEN);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe return (SDRC_ERROR);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe quota_list = &request.qs_quota_list;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe list_create(quota_list, sizeof (smb_quota_t),
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe offsetof(smb_quota_t, q_list_node));
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe status = smb_quota_decode_quotas(xa, quota_list);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (status == NT_STATUS_SUCCESS) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe request.qs_root_path = root_path;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (smb_quota_set(&request, &reply) != 0) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe status = NT_STATUS_INTERNAL_ERROR;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe } else {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe status = reply;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe xdr_free(xdr_uint32_t, (char *)&reply);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe kmem_free(root_path, MAXPATHLEN);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe smb_quota_free_quotas(&request.qs_quota_list);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe smbsr_release_file(sr);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (status != NT_STATUS_SUCCESS) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe smbsr_error(sr, status, 0, 0);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (void) smb_mbc_encodef(&xa->rep_param_mb, "l", 0);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe return (SDRC_ERROR);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe return (SDRC_SUCCESS);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe}
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe/*
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * smb_quota_init_sids
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * If the query is of type SMB_QUOTA_QUERY_SIDLIST or
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * SMB_QUOTA_QUERY_STARTSID decode the list of sids from
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * the client request into request->qq_sid_list.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Otherwise (type SMB_QUOTA_QUERY_ALL) find the resume sid
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * and insert it into request->qq_sid_list, or reset the
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * resume sid to NULL if request->qq_restart.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Returns: NT_STATUS codes
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowestatic uint32_t
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowesmb_quota_init_sids(smb_xa_t *xa, smb_quota_query_t *request,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe smb_ofile_t *ofile)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe{
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe smb_quota_sid_t *sid;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe list_t *sid_list;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe uint32_t status = NT_STATUS_SUCCESS;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe sid_list = &request->qq_sid_list;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe list_create(sid_list, sizeof (smb_quota_sid_t),
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe offsetof(smb_quota_sid_t, qs_list_node));
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe switch (request->qq_query_op) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe case SMB_QUOTA_QUERY_SIDLIST:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe case SMB_QUOTA_QUERY_STARTSID:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe status = smb_quota_decode_sids(xa, sid_list);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe break;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe case SMB_QUOTA_QUERY_ALL:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (request->qq_restart)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe smb_ofile_set_quota_resume(ofile, NULL);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe else {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe sid = kmem_zalloc(sizeof (smb_quota_sid_t), KM_SLEEP);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe list_insert_tail(sid_list, sid);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe smb_ofile_get_quota_resume(ofile, sid->qs_sidstr,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe SMB_SID_STRSZ);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (*sid->qs_sidstr == '\0')
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe status = NT_STATUS_INVALID_PARAMETER;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe break;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe default:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe status = NT_STATUS_INVALID_PARAMETER;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe break;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe return (status);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe}
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe/*
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * smb_quota_free_sids
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowestatic void
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowesmb_quota_free_sids(smb_quota_query_t *request)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe{
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe list_t *sid_list;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe smb_quota_sid_t *sid;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe sid_list = &request->qq_sid_list;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe while ((sid = list_head(sid_list)) != NULL) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe list_remove(sid_list, sid);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe kmem_free(sid, sizeof (smb_quota_sid_t));
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe list_destroy(sid_list);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe}
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe/*
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * smb_quota_decode_sids
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Decode the SIDs from the data block and stores them in string form in list.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Eaxh sid entry comprises:
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * next_offset (4 bytes) - offset of next entry
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * sid length (4 bytes)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * sid (variable length = sidlen)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * The last entry will have a next_offset value of 0.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Returns NT_STATUS codes.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowestatic uint32_t
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowesmb_quota_decode_sids(smb_xa_t *xa, list_t *list)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe{
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe uint32_t offset, mb_offset, sid_offset, bytes_left;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe uint32_t next_offset, sidlen;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe smb_sid_t *sid;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe smb_quota_sid_t *qsid;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe uint32_t status = NT_STATUS_SUCCESS;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe struct mbuf_chain sidbuf;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe offset = 0;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe do {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe mb_offset = offset + xa->req_data_mb.chain_offset;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe bytes_left = xa->req_data_mb.max_bytes - mb_offset;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (void) MBC_SHADOW_CHAIN(&sidbuf, &xa->req_data_mb,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe mb_offset, bytes_left);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (smb_mbc_decodef(&sidbuf, "ll", &next_offset, &sidlen)) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe status = NT_STATUS_INVALID_PARAMETER;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe break;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe sid_offset = offset + (2 * sizeof (uint32_t));
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe sid = smb_decode_sid(xa, sid_offset);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (sid == NULL) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe status = NT_STATUS_INVALID_PARAMETER;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe break;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe qsid = kmem_zalloc(sizeof (smb_quota_sid_t), KM_SLEEP);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe smb_sid_tostr(sid, qsid->qs_sidstr);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe smb_sid_free(sid);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe sid = NULL;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe list_insert_tail(list, qsid);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe offset += next_offset;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe } while ((next_offset != 0) && (bytes_left > 0));
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe return (status);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe}
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe/*
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * smb_quota_max_quota
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * If the query is if type SMB_QUOTA_QUERY_SIDLIST a quota entry
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * is returned for each sid in the sidlist. request->qr_max_quota
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * is set to 0 and is unused.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Otherwise (for SMB_QUOTA_QUERY_STARTSID and SMB_QUOTA_QUERY_ALL)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * max_quota is the maximum number of quota entries requested from
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * the file system (via door call smb_quota_query()).
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * If single is set max_quota is set to 1. If single is not set
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * max quota is calculated as the number of quotas of size
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * SMB_QUOTA_EST_SIZE that would fit in the response buffer.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowestatic void
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowesmb_quota_max_quota(smb_xa_t *xa, smb_quota_query_t *request)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe{
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (request->qq_query_op == SMB_QUOTA_QUERY_SIDLIST)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe request->qq_max_quota = 0;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe else if (request->qq_single)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe request->qq_max_quota = 1;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe else
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe request->qq_max_quota = (xa->smb_mdrcnt / SMB_QUOTA_EST_SIZE);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe}
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe/*
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * smb_quota_decode_quotas
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Decode the quota entries into a list_t of smb_quota_t.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * SMB_QUOTA_SIZE_NO_SID is the size of a quota entry,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * excluding the sid.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * The last entry will have a next_offset value of 0.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Returns NT_STATUS codes.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowestatic uint32_t
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowesmb_quota_decode_quotas(smb_xa_t *xa, list_t *list)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe{
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe uint32_t offset, mb_offset, sid_offset, bytes_left;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe uint32_t next_offset, sidlen;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe uint64_t mtime;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe smb_sid_t *sid;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe smb_quota_t *quota;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe uint32_t status = NT_STATUS_SUCCESS;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe struct mbuf_chain quotabuf;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe offset = 0;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe do {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe mb_offset = offset + xa->req_data_mb.chain_offset;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe bytes_left = xa->req_data_mb.max_bytes - mb_offset;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (void) MBC_SHADOW_CHAIN(&quotabuf, &xa->req_data_mb,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe mb_offset, bytes_left);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe quota = kmem_zalloc(sizeof (smb_quota_t), KM_SLEEP);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (smb_mbc_decodef(&quotabuf, "llqqqq",
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe &next_offset, &sidlen, &mtime,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe &quota->q_used, &quota->q_thresh, &quota->q_limit)) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe kmem_free(quota, sizeof (smb_quota_t));
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe status = NT_STATUS_INVALID_PARAMETER;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe break;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe sid_offset = offset + SMB_QUOTA_SIZE_NO_SID;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe sid = smb_decode_sid(xa, sid_offset);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (sid == NULL) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe kmem_free(quota, sizeof (smb_quota_t));
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe status = NT_STATUS_INVALID_PARAMETER;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe break;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe bzero(quota->q_sidstr, SMB_SID_STRSZ);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe smb_sid_tostr(sid, quota->q_sidstr);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe smb_sid_free(sid);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe sid = NULL;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe list_insert_tail(list, quota);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe offset += next_offset;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe } while ((next_offset != 0) && (bytes_left > 0));
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe return (status);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe}
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe/*
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * smb_quota_free_quotas
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowestatic void
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowesmb_quota_free_quotas(list_t *list)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe{
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe smb_quota_t *quota;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe while ((quota = list_head(list)) != NULL) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe list_remove(list, quota);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe kmem_free(quota, sizeof (smb_quota_t));
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe list_destroy(list);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe}
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe/*
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * smb_quota_encode_quotas
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Encode the quota entries from a list_t of smb_quota_t.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * SMB_QUOTA_SIZE_NO_SID is the size of a quota entry,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * excluding the sid.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * The last entry will have a next_offset value of 0.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Sets the last encoded SID as the resume sid.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowestatic uint32_t
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowesmb_quota_encode_quotas(smb_xa_t *xa, smb_quota_query_t *request,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe smb_quota_response_t *reply, smb_ofile_t *ofile)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe{
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe uint32_t next_offset, sid_offset, total_bytes;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe uint64_t mtime = 0;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe uint32_t sidlen, pad;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe smb_sid_t *sid;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe char *sidstr = NULL, *resume = NULL;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe smb_quota_t *quota, *next_quota;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe list_t *list = &reply->qr_quota_list;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe int rc;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe uint32_t status = NT_STATUS_SUCCESS;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe total_bytes = 0;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe quota = list_head(list);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe while (quota) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe next_quota = list_next(list, quota);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe sidstr = quota->q_sidstr;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if ((sid = smb_sid_fromstr(sidstr)) == NULL) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe quota = next_quota;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe continue;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe sidlen = smb_sid_len(sid);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe sid_offset = SMB_QUOTA_SIZE_NO_SID;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe next_offset = sid_offset + sidlen;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe pad = smb_pad_align(next_offset, 8);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe next_offset += pad;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (!MBC_ROOM_FOR(&xa->rep_data_mb, next_offset)) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe smb_sid_free(sid);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe break;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (!MBC_ROOM_FOR(&xa->rep_data_mb,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe next_offset + SMB_QUOTA_MAX_SIZE)) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe next_quota = NULL;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe rc = smb_mbc_encodef(&xa->rep_data_mb, "llqqqq",
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe next_quota ? next_offset : 0, sidlen, mtime,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe quota->q_used, quota->q_thresh, quota->q_limit);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (rc == 0) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe smb_encode_sid(xa, sid);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe rc = smb_mbc_encodef(&xa->rep_data_mb, "#.", pad);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe smb_sid_free(sid);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (rc != 0) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe status = NT_STATUS_INTERNAL_ERROR;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe break;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe resume = sidstr;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe total_bytes += next_offset;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe quota = next_quota;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe rc = smb_mbc_encodef(&xa->rep_param_mb, "l", total_bytes);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if ((status == NT_STATUS_SUCCESS) &&
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe ((request->qq_query_op == SMB_QUOTA_QUERY_STARTSID) ||
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (request->qq_query_op == SMB_QUOTA_QUERY_ALL))) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe smb_ofile_set_quota_resume(ofile, resume);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe return (status);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe}
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe/*
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * smb_quota_query_user_quota
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Get user quota information for a single user (uid)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * for the current file system.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Find the user's sid, insert it in the sidlist of a
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * smb_quota_query_t request and invoke the door call
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * smb_quota_query() to obtain the quota information.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Returns: NT_STATUS codes.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Loweuint32_t
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowesmb_quota_query_user_quota(smb_request_t *sr, uid_t uid, smb_quota_t *quota)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe{
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe smb_sid_t *sid;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe smb_quota_sid_t qsid;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe smb_quota_query_t request;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe smb_quota_response_t reply;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe list_t *sid_list;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe smb_quota_t *q;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe smb_node_t *tnode;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe uint32_t status = NT_STATUS_SUCCESS;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (smb_idmap_getsid(uid, SMB_IDMAP_USER, &sid) != IDMAP_SUCCESS)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe return (NT_STATUS_INTERNAL_ERROR);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe smb_sid_tostr(sid, qsid.qs_sidstr);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe smb_sid_free(sid);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe bzero(&request, sizeof (smb_quota_query_t));
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe bzero(&reply, sizeof (smb_quota_response_t));
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe tnode = sr->tid_tree->t_snode;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe request.qq_root_path = kmem_zalloc(MAXPATHLEN, KM_SLEEP);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (smb_node_getmntpath(tnode, request.qq_root_path, MAXPATHLEN) != 0) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe kmem_free(request.qq_root_path, MAXPATHLEN);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe return (NT_STATUS_INTERNAL_ERROR);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe sid_list = &request.qq_sid_list;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe list_create(sid_list, sizeof (smb_quota_sid_t),
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe offsetof(smb_quota_sid_t, qs_list_node));
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe list_insert_tail(sid_list, &qsid);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe request.qq_query_op = SMB_QUOTA_QUERY_SIDLIST;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe request.qq_single = B_TRUE;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (smb_quota_query(&request, &reply) != 0) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe status = NT_STATUS_INTERNAL_ERROR;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe } else {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if (reply.qr_status != NT_STATUS_SUCCESS) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe status = reply.qr_status;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe } else {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe q = list_head(&reply.qr_quota_list);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe if ((q == NULL) ||
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe (strcmp(qsid.qs_sidstr, q->q_sidstr) != 0)) {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe /* should never happen */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe status = NT_STATUS_INTERNAL_ERROR;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe } else {
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe bcopy(q, quota, sizeof (smb_quota_t));
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe xdr_free(smb_quota_response_xdr, (char *)&reply);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe }
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe kmem_free(request.qq_root_path, MAXPATHLEN);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe list_remove(sid_list, &qsid);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe list_destroy(sid_list);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe return (status);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe}
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe/*
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * smb_quota_query
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Door call to query quotas for the provided filesystem path.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Returns: -1 - door call (or encode/decode) failure.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * 0 - success. Status set in reply.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowestatic int
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowesmb_quota_query(smb_quota_query_t *request, smb_quota_response_t *reply)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe{
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe int rc;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe rc = smb_kdoor_upcall(SMB_DR_QUOTA_QUERY,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe request, smb_quota_query_xdr, reply, smb_quota_response_xdr);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe return (rc);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe}
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe/*
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * smb_quota_set
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe *
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Door call to set quotas for the provided filesystem path.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * Returns: -1 - door call (or encode/decode) failure.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe * 0 - success. Status set in reply.
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe */
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowestatic int
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowesmb_quota_set(smb_quota_set_t *request, uint32_t *reply)
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe{
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe int rc;
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe rc = smb_kdoor_upcall(SMB_DR_QUOTA_SET,
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe request, smb_quota_set_xdr, reply, xdr_uint32_t);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe return (rc);
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe}
10d63b7db37a83b39c7f511cf9426c9d03ea0760Richard Lowe