xref: /titanic_51/usr/src/uts/common/fs/smbsrv/smb2_change_notify.c (revision a90cf9f29973990687fa61de9f1f6ea22e924e40)
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 2014 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 static smb_sdrc_t smb2_change_notify_async(smb_request_t *);
34 
35 smb_sdrc_t
36 smb2_change_notify(smb_request_t *sr)
37 {
38 	smb_node_t *node = NULL;
39 	uint16_t StructSize;
40 	uint16_t iFlags;
41 	uint32_t oBufLength;
42 	smb2fid_t smb2fid;
43 	uint32_t CompletionFilter;
44 	uint32_t reserved;
45 	uint32_t status;
46 	int rc = 0;
47 
48 	/*
49 	 * SMB2 Change Notify request
50 	 */
51 	rc = smb_mbc_decodef(
52 	    &sr->smb_data,		"wwlqqll",
53 	    &StructSize,		/* w */
54 	    &iFlags,			/* w */
55 	    &oBufLength,		/* l */
56 	    &smb2fid.persistent,	/* q */
57 	    &smb2fid.temporal,		/* q */
58 	    &CompletionFilter,		/* l */
59 	    &reserved);			/* l */
60 	if (rc || StructSize != 32)
61 		return (SDRC_ERROR);
62 
63 	status = smb2sr_lookup_fid(sr, &smb2fid);
64 	if (status)
65 		goto puterror;
66 
67 	node = sr->fid_ofile->f_node;
68 	if (node == NULL || !smb_node_is_dir(node)) {
69 		status = NT_STATUS_INVALID_PARAMETER;
70 		goto puterror;
71 	}
72 
73 	/*
74 	 * Let Change Notify "go async", because it
75 	 * may block indefinitely.
76 	 */
77 	status = smb2sr_go_async(sr, smb2_change_notify_async);
78 puterror:
79 	ASSERT(status != 0);
80 	smb2sr_put_error(sr, status);
81 	return (SDRC_SUCCESS);
82 }
83 
84 static smb_sdrc_t
85 smb2_change_notify_async(smb_request_t *sr)
86 {
87 	uint16_t StructSize;
88 	uint16_t iFlags;
89 	uint32_t oBufLength;
90 	smb2fid_t smb2fid;
91 	uint32_t CompletionFilter;
92 	uint32_t reserved;
93 	uint32_t status;
94 	uint16_t DataOff;
95 	int rc = 0;
96 
97 	/*
98 	 * SMB2 Change Notify request
99 	 */
100 	rc = smb_mbc_decodef(
101 	    &sr->smb_data,		"wwlqqll",
102 	    &StructSize,		/* w */
103 	    &iFlags,			/* w */
104 	    &oBufLength,		/* l */
105 	    &smb2fid.persistent,	/* q */
106 	    &smb2fid.temporal,		/* q */
107 	    &CompletionFilter,		/* l */
108 	    &reserved);			/* l */
109 	if (rc || StructSize != 32)
110 		return (SDRC_ERROR);
111 
112 	status = smb2sr_lookup_fid(sr, &smb2fid);
113 	if (status != 0) {
114 		smb2sr_put_error(sr, status);
115 		return (SDRC_SUCCESS);
116 	}
117 
118 	CompletionFilter &= FILE_NOTIFY_VALID_MASK;
119 	if (iFlags & SMB2_WATCH_TREE)
120 		CompletionFilter |= NODE_FLAGS_WATCH_TREE;
121 
122 	if (oBufLength > smb2_max_trans)
123 		oBufLength = smb2_max_trans;
124 	sr->raw_data.max_bytes = oBufLength;
125 
126 	status = smb_notify_common(sr, &sr->raw_data, CompletionFilter);
127 	if (status != 0) {
128 		smb2sr_put_error(sr, status);
129 		return (SDRC_SUCCESS);
130 	}
131 
132 	/*
133 	 * SMB2 Change Notify reply
134 	 */
135 	DataOff = SMB2_HDR_SIZE + 8;
136 	oBufLength = MBC_LENGTH(&sr->raw_data);
137 	rc = smb_mbc_encodef(
138 	    &sr->reply, "wwlC",
139 	    9,	/* StructSize */	/* w */
140 	    DataOff,			/* w */
141 	    oBufLength,			/* l */
142 	    &sr->raw_data);		/* C */
143 	if (rc)
144 		return (SDRC_ERROR);
145 
146 	return (SDRC_SUCCESS);
147 }
148