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) 2007, 2010, Oracle and/or its affiliates. 24 * Copyright 2016 Nexenta Systems, Inc. All rights reserved. 25 */ 26 27 /* 28 * Dispatch function for SMB2_CHANGE_NOTIFY 29 */ 30 31 #include <smbsrv/smb2_kproto.h> 32 33 /* For the output DataOffset fields in here. */ 34 #define DATA_OFF (SMB2_HDR_SIZE + 8) 35 36 static smb_sdrc_t smb2_change_notify_async(smb_request_t *); 37 38 smb_sdrc_t 39 smb2_change_notify(smb_request_t *sr) 40 { 41 uint16_t StructSize; 42 uint16_t iFlags; 43 uint32_t oBufLength; 44 smb2fid_t smb2fid; 45 uint32_t CompletionFilter; 46 uint32_t reserved; 47 uint32_t status; 48 int rc = 0; 49 50 /* 51 * SMB2 Change Notify request 52 */ 53 rc = smb_mbc_decodef( 54 &sr->smb_data, "wwlqqll", 55 &StructSize, /* w */ 56 &iFlags, /* w */ 57 &oBufLength, /* l */ 58 &smb2fid.persistent, /* q */ 59 &smb2fid.temporal, /* q */ 60 &CompletionFilter, /* l */ 61 &reserved); /* l */ 62 if (rc || StructSize != 32) 63 return (SDRC_ERROR); 64 65 status = smb2sr_lookup_fid(sr, &smb2fid); 66 if (status != 0) 67 goto puterror; 68 69 CompletionFilter &= FILE_NOTIFY_VALID_MASK; 70 if (iFlags & SMB2_WATCH_TREE) 71 CompletionFilter |= FILE_NOTIFY_CHANGE_EV_SUBDIR; 72 73 if (oBufLength > smb2_max_trans) 74 oBufLength = smb2_max_trans; 75 76 /* 77 * Check for events and consume, non-blocking. 78 * Special return STATUS_PENDING means: 79 * No events; caller must call "act2" next. 80 * SMB2 does that in the "async" handler. 81 */ 82 status = smb_notify_act1(sr, oBufLength, CompletionFilter); 83 if (status == NT_STATUS_PENDING) { 84 status = smb2sr_go_async(sr, smb2_change_notify_async); 85 } 86 87 if (NT_SC_SEVERITY(status) == NT_STATUS_SEVERITY_SUCCESS) { 88 sr->smb2_status = status; 89 90 oBufLength = sr->raw_data.chain_offset; 91 (void) smb_mbc_encodef( 92 &sr->reply, "wwlC", 93 9, /* StructSize */ /* w */ 94 DATA_OFF, /* w */ 95 oBufLength, /* l */ 96 &sr->raw_data); /* C */ 97 } else { 98 puterror: 99 smb2sr_put_error(sr, status); 100 } 101 102 return (SDRC_SUCCESS); 103 } 104 105 /* 106 * This is called when the dispatch loop has made it to the end of a 107 * compound request, and we had a notify that will require blocking. 108 */ 109 static smb_sdrc_t 110 smb2_change_notify_async(smb_request_t *sr) 111 { 112 uint32_t status; 113 114 status = smb_notify_act2(sr); 115 if (status == NT_STATUS_PENDING) { 116 /* See next: smb2_change_notify_finish */ 117 return (SDRC_SR_KEPT); 118 } 119 120 /* Note: Never NT_STATUS_NOTIFY_ENUM_DIR here. */ 121 ASSERT(status != NT_STATUS_NOTIFY_ENUM_DIR); 122 123 if (status != 0) 124 smb2sr_put_error(sr, status); 125 126 return (SDRC_SUCCESS); 127 } 128 129 /* 130 * This is called via taskq_dispatch in smb_notify.c 131 * to finish up an NT transact notify change request. 132 * Build an SMB2 Change Notify reply and send it. 133 */ 134 void 135 smb2_change_notify_finish(void *arg) 136 { 137 smb_request_t *sr = arg; 138 uint32_t status; 139 uint32_t oBufLength; 140 141 SMB_REQ_VALID(sr); 142 143 /* 144 * Common part of notify, puts data in sr->raw_data 145 */ 146 status = smb_notify_act3(sr); 147 if (NT_SC_SEVERITY(status) == NT_STATUS_SEVERITY_SUCCESS) { 148 sr->smb2_status = status; 149 150 oBufLength = sr->raw_data.chain_offset; 151 (void) smb_mbc_encodef( 152 &sr->reply, "wwlC", 153 9, /* StructSize */ /* w */ 154 DATA_OFF, /* w */ 155 oBufLength, /* l */ 156 &sr->raw_data); /* C */ 157 } else { 158 smb2sr_put_error(sr, status); 159 } 160 161 smb2sr_finish_async(sr); 162 } 163