diff options
Diffstat (limited to 'fs/cifs/cifssmb.c')
-rw-r--r-- | fs/cifs/cifssmb.c | 1621 |
1 files changed, 867 insertions, 754 deletions
diff --git a/fs/cifs/cifssmb.c b/fs/cifs/cifssmb.c index 57419a176688..8eb102f940d4 100644 --- a/fs/cifs/cifssmb.c +++ b/fs/cifs/cifssmb.c | |||
@@ -48,7 +48,7 @@ static struct { | |||
48 | {LANMAN_PROT, "\2LM1.2X002"}, | 48 | {LANMAN_PROT, "\2LM1.2X002"}, |
49 | {LANMAN2_PROT, "\2LANMAN2.1"}, | 49 | {LANMAN2_PROT, "\2LANMAN2.1"}, |
50 | #endif /* weak password hashing for legacy clients */ | 50 | #endif /* weak password hashing for legacy clients */ |
51 | {CIFS_PROT, "\2NT LM 0.12"}, | 51 | {CIFS_PROT, "\2NT LM 0.12"}, |
52 | {POSIX_PROT, "\2POSIX 2"}, | 52 | {POSIX_PROT, "\2POSIX 2"}, |
53 | {BAD_PROT, "\2"} | 53 | {BAD_PROT, "\2"} |
54 | }; | 54 | }; |
@@ -61,7 +61,7 @@ static struct { | |||
61 | {LANMAN_PROT, "\2LM1.2X002"}, | 61 | {LANMAN_PROT, "\2LM1.2X002"}, |
62 | {LANMAN2_PROT, "\2LANMAN2.1"}, | 62 | {LANMAN2_PROT, "\2LANMAN2.1"}, |
63 | #endif /* weak password hashing for legacy clients */ | 63 | #endif /* weak password hashing for legacy clients */ |
64 | {CIFS_PROT, "\2NT LM 0.12"}, | 64 | {CIFS_PROT, "\2NT LM 0.12"}, |
65 | {BAD_PROT, "\2"} | 65 | {BAD_PROT, "\2"} |
66 | }; | 66 | }; |
67 | #endif | 67 | #endif |
@@ -84,17 +84,17 @@ static struct { | |||
84 | 84 | ||
85 | /* Mark as invalid, all open files on tree connections since they | 85 | /* Mark as invalid, all open files on tree connections since they |
86 | were closed when session to server was lost */ | 86 | were closed when session to server was lost */ |
87 | static void mark_open_files_invalid(struct cifsTconInfo * pTcon) | 87 | static void mark_open_files_invalid(struct cifsTconInfo *pTcon) |
88 | { | 88 | { |
89 | struct cifsFileInfo *open_file = NULL; | 89 | struct cifsFileInfo *open_file = NULL; |
90 | struct list_head * tmp; | 90 | struct list_head *tmp; |
91 | struct list_head * tmp1; | 91 | struct list_head *tmp1; |
92 | 92 | ||
93 | /* list all files open on tree connection and mark them invalid */ | 93 | /* list all files open on tree connection and mark them invalid */ |
94 | write_lock(&GlobalSMBSeslock); | 94 | write_lock(&GlobalSMBSeslock); |
95 | list_for_each_safe(tmp, tmp1, &pTcon->openFileList) { | 95 | list_for_each_safe(tmp, tmp1, &pTcon->openFileList) { |
96 | open_file = list_entry(tmp,struct cifsFileInfo, tlist); | 96 | open_file = list_entry(tmp, struct cifsFileInfo, tlist); |
97 | if(open_file) { | 97 | if (open_file) { |
98 | open_file->invalidHandle = TRUE; | 98 | open_file->invalidHandle = TRUE; |
99 | } | 99 | } |
100 | } | 100 | } |
@@ -113,75 +113,78 @@ small_smb_init(int smb_command, int wct, struct cifsTconInfo *tcon, | |||
113 | /* SMBs NegProt, SessSetup, uLogoff do not have tcon yet so | 113 | /* SMBs NegProt, SessSetup, uLogoff do not have tcon yet so |
114 | check for tcp and smb session status done differently | 114 | check for tcp and smb session status done differently |
115 | for those three - in the calling routine */ | 115 | for those three - in the calling routine */ |
116 | if(tcon) { | 116 | if (tcon) { |
117 | if(tcon->tidStatus == CifsExiting) { | 117 | if (tcon->tidStatus == CifsExiting) { |
118 | /* only tree disconnect, open, and write, | 118 | /* only tree disconnect, open, and write, |
119 | (and ulogoff which does not have tcon) | 119 | (and ulogoff which does not have tcon) |
120 | are allowed as we start force umount */ | 120 | are allowed as we start force umount */ |
121 | if((smb_command != SMB_COM_WRITE_ANDX) && | 121 | if ((smb_command != SMB_COM_WRITE_ANDX) && |
122 | (smb_command != SMB_COM_OPEN_ANDX) && | 122 | (smb_command != SMB_COM_OPEN_ANDX) && |
123 | (smb_command != SMB_COM_TREE_DISCONNECT)) { | 123 | (smb_command != SMB_COM_TREE_DISCONNECT)) { |
124 | cFYI(1,("can not send cmd %d while umounting", | 124 | cFYI(1, ("can not send cmd %d while umounting", |
125 | smb_command)); | 125 | smb_command)); |
126 | return -ENODEV; | 126 | return -ENODEV; |
127 | } | 127 | } |
128 | } | 128 | } |
129 | if((tcon->ses) && (tcon->ses->status != CifsExiting) && | 129 | if ((tcon->ses) && (tcon->ses->status != CifsExiting) && |
130 | (tcon->ses->server)){ | 130 | (tcon->ses->server)) { |
131 | struct nls_table *nls_codepage; | 131 | struct nls_table *nls_codepage; |
132 | /* Give Demultiplex thread up to 10 seconds to | 132 | /* Give Demultiplex thread up to 10 seconds to |
133 | reconnect, should be greater than cifs socket | 133 | reconnect, should be greater than cifs socket |
134 | timeout which is 7 seconds */ | 134 | timeout which is 7 seconds */ |
135 | while(tcon->ses->server->tcpStatus == CifsNeedReconnect) { | 135 | while (tcon->ses->server->tcpStatus == |
136 | CifsNeedReconnect) { | ||
136 | wait_event_interruptible_timeout(tcon->ses->server->response_q, | 137 | wait_event_interruptible_timeout(tcon->ses->server->response_q, |
137 | (tcon->ses->server->tcpStatus == CifsGood), 10 * HZ); | 138 | (tcon->ses->server->tcpStatus == |
138 | if(tcon->ses->server->tcpStatus == CifsNeedReconnect) { | 139 | CifsGood), 10 * HZ); |
140 | if (tcon->ses->server->tcpStatus == | ||
141 | CifsNeedReconnect) { | ||
139 | /* on "soft" mounts we wait once */ | 142 | /* on "soft" mounts we wait once */ |
140 | if((tcon->retry == FALSE) || | 143 | if ((tcon->retry == FALSE) || |
141 | (tcon->ses->status == CifsExiting)) { | 144 | (tcon->ses->status == CifsExiting)) { |
142 | cFYI(1,("gave up waiting on reconnect in smb_init")); | 145 | cFYI(1, ("gave up waiting on " |
146 | "reconnect in smb_init")); | ||
143 | return -EHOSTDOWN; | 147 | return -EHOSTDOWN; |
144 | } /* else "hard" mount - keep retrying | 148 | } /* else "hard" mount - keep retrying |
145 | until process is killed or server | 149 | until process is killed or server |
146 | comes back on-line */ | 150 | comes back on-line */ |
147 | } else /* TCP session is reestablished now */ | 151 | } else /* TCP session is reestablished now */ |
148 | break; | 152 | break; |
149 | |||
150 | } | 153 | } |
151 | 154 | ||
152 | nls_codepage = load_nls_default(); | 155 | nls_codepage = load_nls_default(); |
153 | /* need to prevent multiple threads trying to | 156 | /* need to prevent multiple threads trying to |
154 | simultaneously reconnect the same SMB session */ | 157 | simultaneously reconnect the same SMB session */ |
155 | down(&tcon->ses->sesSem); | 158 | down(&tcon->ses->sesSem); |
156 | if(tcon->ses->status == CifsNeedReconnect) | 159 | if (tcon->ses->status == CifsNeedReconnect) |
157 | rc = cifs_setup_session(0, tcon->ses, | 160 | rc = cifs_setup_session(0, tcon->ses, |
158 | nls_codepage); | 161 | nls_codepage); |
159 | if(!rc && (tcon->tidStatus == CifsNeedReconnect)) { | 162 | if (!rc && (tcon->tidStatus == CifsNeedReconnect)) { |
160 | mark_open_files_invalid(tcon); | 163 | mark_open_files_invalid(tcon); |
161 | rc = CIFSTCon(0, tcon->ses, tcon->treeName, | 164 | rc = CIFSTCon(0, tcon->ses, tcon->treeName, |
162 | tcon, nls_codepage); | 165 | tcon, nls_codepage); |
163 | up(&tcon->ses->sesSem); | 166 | up(&tcon->ses->sesSem); |
164 | /* tell server which Unix caps we support */ | 167 | /* tell server which Unix caps we support */ |
165 | if (tcon->ses->capabilities & CAP_UNIX) | 168 | if (tcon->ses->capabilities & CAP_UNIX) |
166 | reset_cifs_unix_caps(0 /* no xid */, | 169 | reset_cifs_unix_caps(0 /* no xid */, |
167 | tcon, | 170 | tcon, |
168 | NULL /* we do not know sb */, | 171 | NULL /* we do not know sb */, |
169 | NULL /* no vol info */); | 172 | NULL /* no vol info */); |
170 | /* BB FIXME add code to check if wsize needs | 173 | /* BB FIXME add code to check if wsize needs |
171 | update due to negotiated smb buffer size | 174 | update due to negotiated smb buffer size |
172 | shrinking */ | 175 | shrinking */ |
173 | if(rc == 0) | 176 | if (rc == 0) |
174 | atomic_inc(&tconInfoReconnectCount); | 177 | atomic_inc(&tconInfoReconnectCount); |
175 | 178 | ||
176 | cFYI(1, ("reconnect tcon rc = %d", rc)); | 179 | cFYI(1, ("reconnect tcon rc = %d", rc)); |
177 | /* Removed call to reopen open files here - | 180 | /* Removed call to reopen open files here. |
178 | it is safer (and faster) to reopen files | 181 | It is safer (and faster) to reopen files |
179 | one at a time as needed in read and write */ | 182 | one at a time as needed in read and write */ |
180 | 183 | ||
181 | /* Check if handle based operation so we | 184 | /* Check if handle based operation so we |
182 | know whether we can continue or not without | 185 | know whether we can continue or not without |
183 | returning to caller to reset file handle */ | 186 | returning to caller to reset file handle */ |
184 | switch(smb_command) { | 187 | switch (smb_command) { |
185 | case SMB_COM_READ_ANDX: | 188 | case SMB_COM_READ_ANDX: |
186 | case SMB_COM_WRITE_ANDX: | 189 | case SMB_COM_WRITE_ANDX: |
187 | case SMB_COM_CLOSE: | 190 | case SMB_COM_CLOSE: |
@@ -200,7 +203,7 @@ small_smb_init(int smb_command, int wct, struct cifsTconInfo *tcon, | |||
200 | return -EIO; | 203 | return -EIO; |
201 | } | 204 | } |
202 | } | 205 | } |
203 | if(rc) | 206 | if (rc) |
204 | return rc; | 207 | return rc; |
205 | 208 | ||
206 | *request_buf = cifs_small_buf_get(); | 209 | *request_buf = cifs_small_buf_get(); |
@@ -209,23 +212,24 @@ small_smb_init(int smb_command, int wct, struct cifsTconInfo *tcon, | |||
209 | return -ENOMEM; | 212 | return -ENOMEM; |
210 | } | 213 | } |
211 | 214 | ||
212 | header_assemble((struct smb_hdr *) *request_buf, smb_command, tcon,wct); | 215 | header_assemble((struct smb_hdr *) *request_buf, smb_command, |
216 | tcon, wct); | ||
213 | 217 | ||
214 | if(tcon != NULL) | 218 | if (tcon != NULL) |
215 | cifs_stats_inc(&tcon->num_smbs_sent); | 219 | cifs_stats_inc(&tcon->num_smbs_sent); |
216 | 220 | ||
217 | return rc; | 221 | return rc; |
218 | } | 222 | } |
219 | 223 | ||
220 | int | 224 | int |
221 | small_smb_init_no_tc(const int smb_command, const int wct, | 225 | small_smb_init_no_tc(const int smb_command, const int wct, |
222 | struct cifsSesInfo *ses, void **request_buf) | 226 | struct cifsSesInfo *ses, void **request_buf) |
223 | { | 227 | { |
224 | int rc; | 228 | int rc; |
225 | struct smb_hdr * buffer; | 229 | struct smb_hdr *buffer; |
226 | 230 | ||
227 | rc = small_smb_init(smb_command, wct, NULL, request_buf); | 231 | rc = small_smb_init(smb_command, wct, NULL, request_buf); |
228 | if(rc) | 232 | if (rc) |
229 | return rc; | 233 | return rc; |
230 | 234 | ||
231 | buffer = (struct smb_hdr *)*request_buf; | 235 | buffer = (struct smb_hdr *)*request_buf; |
@@ -237,7 +241,7 @@ small_smb_init_no_tc(const int smb_command, const int wct, | |||
237 | 241 | ||
238 | /* uid, tid can stay at zero as set in header assemble */ | 242 | /* uid, tid can stay at zero as set in header assemble */ |
239 | 243 | ||
240 | /* BB add support for turning on the signing when | 244 | /* BB add support for turning on the signing when |
241 | this function is used after 1st of session setup requests */ | 245 | this function is used after 1st of session setup requests */ |
242 | 246 | ||
243 | return rc; | 247 | return rc; |
@@ -254,52 +258,53 @@ smb_init(int smb_command, int wct, struct cifsTconInfo *tcon, | |||
254 | /* SMBs NegProt, SessSetup, uLogoff do not have tcon yet so | 258 | /* SMBs NegProt, SessSetup, uLogoff do not have tcon yet so |
255 | check for tcp and smb session status done differently | 259 | check for tcp and smb session status done differently |
256 | for those three - in the calling routine */ | 260 | for those three - in the calling routine */ |
257 | if(tcon) { | 261 | if (tcon) { |
258 | if(tcon->tidStatus == CifsExiting) { | 262 | if (tcon->tidStatus == CifsExiting) { |
259 | /* only tree disconnect, open, and write, | 263 | /* only tree disconnect, open, and write, |
260 | (and ulogoff which does not have tcon) | 264 | (and ulogoff which does not have tcon) |
261 | are allowed as we start force umount */ | 265 | are allowed as we start force umount */ |
262 | if((smb_command != SMB_COM_WRITE_ANDX) && | 266 | if ((smb_command != SMB_COM_WRITE_ANDX) && |
263 | (smb_command != SMB_COM_OPEN_ANDX) && | 267 | (smb_command != SMB_COM_OPEN_ANDX) && |
264 | (smb_command != SMB_COM_TREE_DISCONNECT)) { | 268 | (smb_command != SMB_COM_TREE_DISCONNECT)) { |
265 | cFYI(1,("can not send cmd %d while umounting", | 269 | cFYI(1, ("can not send cmd %d while umounting", |
266 | smb_command)); | 270 | smb_command)); |
267 | return -ENODEV; | 271 | return -ENODEV; |
268 | } | 272 | } |
269 | } | 273 | } |
270 | 274 | ||
271 | if((tcon->ses) && (tcon->ses->status != CifsExiting) && | 275 | if ((tcon->ses) && (tcon->ses->status != CifsExiting) && |
272 | (tcon->ses->server)){ | 276 | (tcon->ses->server)) { |
273 | struct nls_table *nls_codepage; | 277 | struct nls_table *nls_codepage; |
274 | /* Give Demultiplex thread up to 10 seconds to | 278 | /* Give Demultiplex thread up to 10 seconds to |
275 | reconnect, should be greater than cifs socket | 279 | reconnect, should be greater than cifs socket |
276 | timeout which is 7 seconds */ | 280 | timeout which is 7 seconds */ |
277 | while(tcon->ses->server->tcpStatus == CifsNeedReconnect) { | 281 | while (tcon->ses->server->tcpStatus == |
282 | CifsNeedReconnect) { | ||
278 | wait_event_interruptible_timeout(tcon->ses->server->response_q, | 283 | wait_event_interruptible_timeout(tcon->ses->server->response_q, |
279 | (tcon->ses->server->tcpStatus == CifsGood), 10 * HZ); | 284 | (tcon->ses->server->tcpStatus == |
280 | if(tcon->ses->server->tcpStatus == | 285 | CifsGood), 10 * HZ); |
286 | if (tcon->ses->server->tcpStatus == | ||
281 | CifsNeedReconnect) { | 287 | CifsNeedReconnect) { |
282 | /* on "soft" mounts we wait once */ | 288 | /* on "soft" mounts we wait once */ |
283 | if((tcon->retry == FALSE) || | 289 | if ((tcon->retry == FALSE) || |
284 | (tcon->ses->status == CifsExiting)) { | 290 | (tcon->ses->status == CifsExiting)) { |
285 | cFYI(1,("gave up waiting on reconnect in smb_init")); | 291 | cFYI(1, ("gave up waiting on " |
292 | "reconnect in smb_init")); | ||
286 | return -EHOSTDOWN; | 293 | return -EHOSTDOWN; |
287 | } /* else "hard" mount - keep retrying | 294 | } /* else "hard" mount - keep retrying |
288 | until process is killed or server | 295 | until process is killed or server |
289 | comes on-line */ | 296 | comes on-line */ |
290 | } else /* TCP session is reestablished now */ | 297 | } else /* TCP session is reestablished now */ |
291 | break; | 298 | break; |
292 | |||
293 | } | 299 | } |
294 | |||
295 | nls_codepage = load_nls_default(); | 300 | nls_codepage = load_nls_default(); |
296 | /* need to prevent multiple threads trying to | 301 | /* need to prevent multiple threads trying to |
297 | simultaneously reconnect the same SMB session */ | 302 | simultaneously reconnect the same SMB session */ |
298 | down(&tcon->ses->sesSem); | 303 | down(&tcon->ses->sesSem); |
299 | if(tcon->ses->status == CifsNeedReconnect) | 304 | if (tcon->ses->status == CifsNeedReconnect) |
300 | rc = cifs_setup_session(0, tcon->ses, | 305 | rc = cifs_setup_session(0, tcon->ses, |
301 | nls_codepage); | 306 | nls_codepage); |
302 | if(!rc && (tcon->tidStatus == CifsNeedReconnect)) { | 307 | if (!rc && (tcon->tidStatus == CifsNeedReconnect)) { |
303 | mark_open_files_invalid(tcon); | 308 | mark_open_files_invalid(tcon); |
304 | rc = CIFSTCon(0, tcon->ses, tcon->treeName, | 309 | rc = CIFSTCon(0, tcon->ses, tcon->treeName, |
305 | tcon, nls_codepage); | 310 | tcon, nls_codepage); |
@@ -307,24 +312,24 @@ smb_init(int smb_command, int wct, struct cifsTconInfo *tcon, | |||
307 | /* tell server which Unix caps we support */ | 312 | /* tell server which Unix caps we support */ |
308 | if (tcon->ses->capabilities & CAP_UNIX) | 313 | if (tcon->ses->capabilities & CAP_UNIX) |
309 | reset_cifs_unix_caps(0 /* no xid */, | 314 | reset_cifs_unix_caps(0 /* no xid */, |
310 | tcon, | 315 | tcon, |
311 | NULL /* do not know sb */, | 316 | NULL /* do not know sb */, |
312 | NULL /* no vol info */); | 317 | NULL /* no vol info */); |
313 | /* BB FIXME add code to check if wsize needs | 318 | /* BB FIXME add code to check if wsize needs |
314 | update due to negotiated smb buffer size | 319 | update due to negotiated smb buffer size |
315 | shrinking */ | 320 | shrinking */ |
316 | if(rc == 0) | 321 | if (rc == 0) |
317 | atomic_inc(&tconInfoReconnectCount); | 322 | atomic_inc(&tconInfoReconnectCount); |
318 | 323 | ||
319 | cFYI(1, ("reconnect tcon rc = %d", rc)); | 324 | cFYI(1, ("reconnect tcon rc = %d", rc)); |
320 | /* Removed call to reopen open files here - | 325 | /* Removed call to reopen open files here. |
321 | it is safer (and faster) to reopen files | 326 | It is safer (and faster) to reopen files |
322 | one at a time as needed in read and write */ | 327 | one at a time as needed in read and write */ |
323 | 328 | ||
324 | /* Check if handle based operation so we | 329 | /* Check if handle based operation so we |
325 | know whether we can continue or not without | 330 | know whether we can continue or not without |
326 | returning to caller to reset file handle */ | 331 | returning to caller to reset file handle */ |
327 | switch(smb_command) { | 332 | switch (smb_command) { |
328 | case SMB_COM_READ_ANDX: | 333 | case SMB_COM_READ_ANDX: |
329 | case SMB_COM_WRITE_ANDX: | 334 | case SMB_COM_WRITE_ANDX: |
330 | case SMB_COM_CLOSE: | 335 | case SMB_COM_CLOSE: |
@@ -343,7 +348,7 @@ smb_init(int smb_command, int wct, struct cifsTconInfo *tcon, | |||
343 | return -EIO; | 348 | return -EIO; |
344 | } | 349 | } |
345 | } | 350 | } |
346 | if(rc) | 351 | if (rc) |
347 | return rc; | 352 | return rc; |
348 | 353 | ||
349 | *request_buf = cifs_buf_get(); | 354 | *request_buf = cifs_buf_get(); |
@@ -355,48 +360,48 @@ smb_init(int smb_command, int wct, struct cifsTconInfo *tcon, | |||
355 | /* potential retries of smb operations it turns out we can determine */ | 360 | /* potential retries of smb operations it turns out we can determine */ |
356 | /* from the mid flags when the request buffer can be resent without */ | 361 | /* from the mid flags when the request buffer can be resent without */ |
357 | /* having to use a second distinct buffer for the response */ | 362 | /* having to use a second distinct buffer for the response */ |
358 | if(response_buf) | 363 | if (response_buf) |
359 | *response_buf = *request_buf; | 364 | *response_buf = *request_buf; |
360 | 365 | ||
361 | header_assemble((struct smb_hdr *) *request_buf, smb_command, tcon, | 366 | header_assemble((struct smb_hdr *) *request_buf, smb_command, tcon, |
362 | wct /*wct */ ); | 367 | wct /*wct */ ); |
363 | 368 | ||
364 | if(tcon != NULL) | 369 | if (tcon != NULL) |
365 | cifs_stats_inc(&tcon->num_smbs_sent); | 370 | cifs_stats_inc(&tcon->num_smbs_sent); |
366 | 371 | ||
367 | return rc; | 372 | return rc; |
368 | } | 373 | } |
369 | 374 | ||
370 | static int validate_t2(struct smb_t2_rsp * pSMB) | 375 | static int validate_t2(struct smb_t2_rsp *pSMB) |
371 | { | 376 | { |
372 | int rc = -EINVAL; | 377 | int rc = -EINVAL; |
373 | int total_size; | 378 | int total_size; |
374 | char * pBCC; | 379 | char *pBCC; |
375 | 380 | ||
376 | /* check for plausible wct, bcc and t2 data and parm sizes */ | 381 | /* check for plausible wct, bcc and t2 data and parm sizes */ |
377 | /* check for parm and data offset going beyond end of smb */ | 382 | /* check for parm and data offset going beyond end of smb */ |
378 | if(pSMB->hdr.WordCount >= 10) { | 383 | if (pSMB->hdr.WordCount >= 10) { |
379 | if((le16_to_cpu(pSMB->t2_rsp.ParameterOffset) <= 1024) && | 384 | if ((le16_to_cpu(pSMB->t2_rsp.ParameterOffset) <= 1024) && |
380 | (le16_to_cpu(pSMB->t2_rsp.DataOffset) <= 1024)) { | 385 | (le16_to_cpu(pSMB->t2_rsp.DataOffset) <= 1024)) { |
381 | /* check that bcc is at least as big as parms + data */ | 386 | /* check that bcc is at least as big as parms + data */ |
382 | /* check that bcc is less than negotiated smb buffer */ | 387 | /* check that bcc is less than negotiated smb buffer */ |
383 | total_size = le16_to_cpu(pSMB->t2_rsp.ParameterCount); | 388 | total_size = le16_to_cpu(pSMB->t2_rsp.ParameterCount); |
384 | if(total_size < 512) { | 389 | if (total_size < 512) { |
385 | total_size+=le16_to_cpu(pSMB->t2_rsp.DataCount); | 390 | total_size += |
391 | le16_to_cpu(pSMB->t2_rsp.DataCount); | ||
386 | /* BCC le converted in SendReceive */ | 392 | /* BCC le converted in SendReceive */ |
387 | pBCC = (pSMB->hdr.WordCount * 2) + | 393 | pBCC = (pSMB->hdr.WordCount * 2) + |
388 | sizeof(struct smb_hdr) + | 394 | sizeof(struct smb_hdr) + |
389 | (char *)pSMB; | 395 | (char *)pSMB; |
390 | if((total_size <= (*(u16 *)pBCC)) && | 396 | if ((total_size <= (*(u16 *)pBCC)) && |
391 | (total_size < | 397 | (total_size < |
392 | CIFSMaxBufSize+MAX_CIFS_HDR_SIZE)) { | 398 | CIFSMaxBufSize+MAX_CIFS_HDR_SIZE)) { |
393 | return 0; | 399 | return 0; |
394 | } | 400 | } |
395 | |||
396 | } | 401 | } |
397 | } | 402 | } |
398 | } | 403 | } |
399 | cifs_dump_mem("Invalid transact2 SMB: ",(char *)pSMB, | 404 | cifs_dump_mem("Invalid transact2 SMB: ", (char *)pSMB, |
400 | sizeof(struct smb_t2_rsp) + 16); | 405 | sizeof(struct smb_t2_rsp) + 16); |
401 | return rc; | 406 | return rc; |
402 | } | 407 | } |
@@ -408,12 +413,12 @@ CIFSSMBNegotiate(unsigned int xid, struct cifsSesInfo *ses) | |||
408 | int rc = 0; | 413 | int rc = 0; |
409 | int bytes_returned; | 414 | int bytes_returned; |
410 | int i; | 415 | int i; |
411 | struct TCP_Server_Info * server; | 416 | struct TCP_Server_Info *server; |
412 | u16 count; | 417 | u16 count; |
413 | unsigned int secFlags; | 418 | unsigned int secFlags; |
414 | u16 dialect; | 419 | u16 dialect; |
415 | 420 | ||
416 | if(ses->server) | 421 | if (ses->server) |
417 | server = ses->server; | 422 | server = ses->server; |
418 | else { | 423 | else { |
419 | rc = -EIO; | 424 | rc = -EIO; |
@@ -425,20 +430,20 @@ CIFSSMBNegotiate(unsigned int xid, struct cifsSesInfo *ses) | |||
425 | return rc; | 430 | return rc; |
426 | 431 | ||
427 | /* if any of auth flags (ie not sign or seal) are overriden use them */ | 432 | /* if any of auth flags (ie not sign or seal) are overriden use them */ |
428 | if(ses->overrideSecFlg & (~(CIFSSEC_MUST_SIGN | CIFSSEC_MUST_SEAL))) | 433 | if (ses->overrideSecFlg & (~(CIFSSEC_MUST_SIGN | CIFSSEC_MUST_SEAL))) |
429 | secFlags = ses->overrideSecFlg; | 434 | secFlags = ses->overrideSecFlg; /* BB FIXME fix sign flags? */ |
430 | else /* if override flags set only sign/seal OR them with global auth */ | 435 | else /* if override flags set only sign/seal OR them with global auth */ |
431 | secFlags = extended_security | ses->overrideSecFlg; | 436 | secFlags = extended_security | ses->overrideSecFlg; |
432 | 437 | ||
433 | cFYI(1,("secFlags 0x%x",secFlags)); | 438 | cFYI(1, ("secFlags 0x%x", secFlags)); |
434 | 439 | ||
435 | pSMB->hdr.Mid = GetNextMid(server); | 440 | pSMB->hdr.Mid = GetNextMid(server); |
436 | pSMB->hdr.Flags2 |= (SMBFLG2_UNICODE | SMBFLG2_ERR_STATUS); | 441 | pSMB->hdr.Flags2 |= (SMBFLG2_UNICODE | SMBFLG2_ERR_STATUS); |
437 | if ((secFlags & CIFSSEC_MUST_KRB5) == CIFSSEC_MUST_KRB5) | 442 | if ((secFlags & CIFSSEC_MUST_KRB5) == CIFSSEC_MUST_KRB5) |
438 | pSMB->hdr.Flags2 |= SMBFLG2_EXT_SEC; | 443 | pSMB->hdr.Flags2 |= SMBFLG2_EXT_SEC; |
439 | 444 | ||
440 | count = 0; | 445 | count = 0; |
441 | for(i=0;i<CIFS_NUM_PROT;i++) { | 446 | for (i = 0; i < CIFS_NUM_PROT; i++) { |
442 | strncpy(pSMB->DialectsArray+count, protocols[i].name, 16); | 447 | strncpy(pSMB->DialectsArray+count, protocols[i].name, 16); |
443 | count += strlen(protocols[i].name) + 1; | 448 | count += strlen(protocols[i].name) + 1; |
444 | /* null at end of source and target buffers anyway */ | 449 | /* null at end of source and target buffers anyway */ |
@@ -448,26 +453,26 @@ CIFSSMBNegotiate(unsigned int xid, struct cifsSesInfo *ses) | |||
448 | 453 | ||
449 | rc = SendReceive(xid, ses, (struct smb_hdr *) pSMB, | 454 | rc = SendReceive(xid, ses, (struct smb_hdr *) pSMB, |
450 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); | 455 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
451 | if (rc != 0) | 456 | if (rc != 0) |
452 | goto neg_err_exit; | 457 | goto neg_err_exit; |
453 | 458 | ||
454 | dialect = le16_to_cpu(pSMBr->DialectIndex); | 459 | dialect = le16_to_cpu(pSMBr->DialectIndex); |
455 | cFYI(1,("Dialect: %d", dialect)); | 460 | cFYI(1, ("Dialect: %d", dialect)); |
456 | /* Check wct = 1 error case */ | 461 | /* Check wct = 1 error case */ |
457 | if((pSMBr->hdr.WordCount < 13) || (dialect == BAD_PROT)) { | 462 | if ((pSMBr->hdr.WordCount < 13) || (dialect == BAD_PROT)) { |
458 | /* core returns wct = 1, but we do not ask for core - otherwise | 463 | /* core returns wct = 1, but we do not ask for core - otherwise |
459 | small wct just comes when dialect index is -1 indicating we | 464 | small wct just comes when dialect index is -1 indicating we |
460 | could not negotiate a common dialect */ | 465 | could not negotiate a common dialect */ |
461 | rc = -EOPNOTSUPP; | 466 | rc = -EOPNOTSUPP; |
462 | goto neg_err_exit; | 467 | goto neg_err_exit; |
463 | #ifdef CONFIG_CIFS_WEAK_PW_HASH | 468 | #ifdef CONFIG_CIFS_WEAK_PW_HASH |
464 | } else if((pSMBr->hdr.WordCount == 13) | 469 | } else if ((pSMBr->hdr.WordCount == 13) |
465 | && ((dialect == LANMAN_PROT) | 470 | && ((dialect == LANMAN_PROT) |
466 | || (dialect == LANMAN2_PROT))) { | 471 | || (dialect == LANMAN2_PROT))) { |
467 | __s16 tmp; | 472 | __s16 tmp; |
468 | struct lanman_neg_rsp * rsp = (struct lanman_neg_rsp *)pSMBr; | 473 | struct lanman_neg_rsp *rsp = (struct lanman_neg_rsp *)pSMBr; |
469 | 474 | ||
470 | if((secFlags & CIFSSEC_MAY_LANMAN) || | 475 | if ((secFlags & CIFSSEC_MAY_LANMAN) || |
471 | (secFlags & CIFSSEC_MAY_PLNTXT)) | 476 | (secFlags & CIFSSEC_MAY_PLNTXT)) |
472 | server->secType = LANMAN; | 477 | server->secType = LANMAN; |
473 | else { | 478 | else { |
@@ -475,7 +480,7 @@ CIFSSMBNegotiate(unsigned int xid, struct cifsSesInfo *ses) | |||
475 | " in /proc/fs/cifs/SecurityFlags")); | 480 | " in /proc/fs/cifs/SecurityFlags")); |
476 | rc = -EOPNOTSUPP; | 481 | rc = -EOPNOTSUPP; |
477 | goto neg_err_exit; | 482 | goto neg_err_exit; |
478 | } | 483 | } |
479 | server->secMode = (__u8)le16_to_cpu(rsp->SecurityMode); | 484 | server->secMode = (__u8)le16_to_cpu(rsp->SecurityMode); |
480 | server->maxReq = le16_to_cpu(rsp->MaxMpxCount); | 485 | server->maxReq = le16_to_cpu(rsp->MaxMpxCount); |
481 | server->maxBuf = min((__u32)le16_to_cpu(rsp->MaxBufSize), | 486 | server->maxBuf = min((__u32)le16_to_cpu(rsp->MaxBufSize), |
@@ -483,7 +488,7 @@ CIFSSMBNegotiate(unsigned int xid, struct cifsSesInfo *ses) | |||
483 | GETU32(server->sessid) = le32_to_cpu(rsp->SessionKey); | 488 | GETU32(server->sessid) = le32_to_cpu(rsp->SessionKey); |
484 | /* even though we do not use raw we might as well set this | 489 | /* even though we do not use raw we might as well set this |
485 | accurately, in case we ever find a need for it */ | 490 | accurately, in case we ever find a need for it */ |
486 | if((le16_to_cpu(rsp->RawMode) & RAW_ENABLE) == RAW_ENABLE) { | 491 | if ((le16_to_cpu(rsp->RawMode) & RAW_ENABLE) == RAW_ENABLE) { |
487 | server->maxRw = 0xFF00; | 492 | server->maxRw = 0xFF00; |
488 | server->capabilities = CAP_MPX_MODE | CAP_RAW_MODE; | 493 | server->capabilities = CAP_MPX_MODE | CAP_RAW_MODE; |
489 | } else { | 494 | } else { |
@@ -504,29 +509,29 @@ CIFSSMBNegotiate(unsigned int xid, struct cifsSesInfo *ses) | |||
504 | utc = CURRENT_TIME; | 509 | utc = CURRENT_TIME; |
505 | ts = cnvrtDosUnixTm(le16_to_cpu(rsp->SrvTime.Date), | 510 | ts = cnvrtDosUnixTm(le16_to_cpu(rsp->SrvTime.Date), |
506 | le16_to_cpu(rsp->SrvTime.Time)); | 511 | le16_to_cpu(rsp->SrvTime.Time)); |
507 | cFYI(1,("SrvTime: %d sec since 1970 (utc: %d) diff: %d", | 512 | cFYI(1, ("SrvTime %d sec since 1970 (utc: %d) diff: %d", |
508 | (int)ts.tv_sec, (int)utc.tv_sec, | 513 | (int)ts.tv_sec, (int)utc.tv_sec, |
509 | (int)(utc.tv_sec - ts.tv_sec))); | 514 | (int)(utc.tv_sec - ts.tv_sec))); |
510 | val = (int)(utc.tv_sec - ts.tv_sec); | 515 | val = (int)(utc.tv_sec - ts.tv_sec); |
511 | seconds = val < 0 ? -val : val; | 516 | seconds = val < 0 ? -val : val; |
512 | result = (seconds / MIN_TZ_ADJ) * MIN_TZ_ADJ; | 517 | result = (seconds / MIN_TZ_ADJ) * MIN_TZ_ADJ; |
513 | remain = seconds % MIN_TZ_ADJ; | 518 | remain = seconds % MIN_TZ_ADJ; |
514 | if(remain >= (MIN_TZ_ADJ / 2)) | 519 | if (remain >= (MIN_TZ_ADJ / 2)) |
515 | result += MIN_TZ_ADJ; | 520 | result += MIN_TZ_ADJ; |
516 | if(val < 0) | 521 | if (val < 0) |
517 | result = - result; | 522 | result = - result; |
518 | server->timeAdj = result; | 523 | server->timeAdj = result; |
519 | } else { | 524 | } else { |
520 | server->timeAdj = (int)tmp; | 525 | server->timeAdj = (int)tmp; |
521 | server->timeAdj *= 60; /* also in seconds */ | 526 | server->timeAdj *= 60; /* also in seconds */ |
522 | } | 527 | } |
523 | cFYI(1,("server->timeAdj: %d seconds", server->timeAdj)); | 528 | cFYI(1, ("server->timeAdj: %d seconds", server->timeAdj)); |
524 | 529 | ||
525 | 530 | ||
526 | /* BB get server time for time conversions and add | 531 | /* BB get server time for time conversions and add |
527 | code to use it and timezone since this is not UTC */ | 532 | code to use it and timezone since this is not UTC */ |
528 | 533 | ||
529 | if (rsp->EncryptionKeyLength == | 534 | if (rsp->EncryptionKeyLength == |
530 | cpu_to_le16(CIFS_CRYPTO_KEY_SIZE)) { | 535 | cpu_to_le16(CIFS_CRYPTO_KEY_SIZE)) { |
531 | memcpy(server->cryptKey, rsp->EncryptionKey, | 536 | memcpy(server->cryptKey, rsp->EncryptionKey, |
532 | CIFS_CRYPTO_KEY_SIZE); | 537 | CIFS_CRYPTO_KEY_SIZE); |
@@ -535,39 +540,39 @@ CIFSSMBNegotiate(unsigned int xid, struct cifsSesInfo *ses) | |||
535 | goto neg_err_exit; | 540 | goto neg_err_exit; |
536 | } | 541 | } |
537 | 542 | ||
538 | cFYI(1,("LANMAN negotiated")); | 543 | cFYI(1, ("LANMAN negotiated")); |
539 | /* we will not end up setting signing flags - as no signing | 544 | /* we will not end up setting signing flags - as no signing |
540 | was in LANMAN and server did not return the flags on */ | 545 | was in LANMAN and server did not return the flags on */ |
541 | goto signing_check; | 546 | goto signing_check; |
542 | #else /* weak security disabled */ | 547 | #else /* weak security disabled */ |
543 | } else if(pSMBr->hdr.WordCount == 13) { | 548 | } else if (pSMBr->hdr.WordCount == 13) { |
544 | cERROR(1,("mount failed, cifs module not built " | 549 | cERROR(1, ("mount failed, cifs module not built " |
545 | "with CIFS_WEAK_PW_HASH support")); | 550 | "with CIFS_WEAK_PW_HASH support")); |
546 | rc = -EOPNOTSUPP; | 551 | rc = -EOPNOTSUPP; |
547 | #endif /* WEAK_PW_HASH */ | 552 | #endif /* WEAK_PW_HASH */ |
548 | goto neg_err_exit; | 553 | goto neg_err_exit; |
549 | } else if(pSMBr->hdr.WordCount != 17) { | 554 | } else if (pSMBr->hdr.WordCount != 17) { |
550 | /* unknown wct */ | 555 | /* unknown wct */ |
551 | rc = -EOPNOTSUPP; | 556 | rc = -EOPNOTSUPP; |
552 | goto neg_err_exit; | 557 | goto neg_err_exit; |
553 | } | 558 | } |
554 | /* else wct == 17 NTLM */ | 559 | /* else wct == 17 NTLM */ |
555 | server->secMode = pSMBr->SecurityMode; | 560 | server->secMode = pSMBr->SecurityMode; |
556 | if((server->secMode & SECMODE_USER) == 0) | 561 | if ((server->secMode & SECMODE_USER) == 0) |
557 | cFYI(1,("share mode security")); | 562 | cFYI(1, ("share mode security")); |
558 | 563 | ||
559 | if((server->secMode & SECMODE_PW_ENCRYPT) == 0) | 564 | if ((server->secMode & SECMODE_PW_ENCRYPT) == 0) |
560 | #ifdef CONFIG_CIFS_WEAK_PW_HASH | 565 | #ifdef CONFIG_CIFS_WEAK_PW_HASH |
561 | if ((secFlags & CIFSSEC_MAY_PLNTXT) == 0) | 566 | if ((secFlags & CIFSSEC_MAY_PLNTXT) == 0) |
562 | #endif /* CIFS_WEAK_PW_HASH */ | 567 | #endif /* CIFS_WEAK_PW_HASH */ |
563 | cERROR(1,("Server requests plain text password" | 568 | cERROR(1, ("Server requests plain text password" |
564 | " but client support disabled")); | 569 | " but client support disabled")); |
565 | 570 | ||
566 | if((secFlags & CIFSSEC_MUST_NTLMV2) == CIFSSEC_MUST_NTLMV2) | 571 | if ((secFlags & CIFSSEC_MUST_NTLMV2) == CIFSSEC_MUST_NTLMV2) |
567 | server->secType = NTLMv2; | 572 | server->secType = NTLMv2; |
568 | else if(secFlags & CIFSSEC_MAY_NTLM) | 573 | else if (secFlags & CIFSSEC_MAY_NTLM) |
569 | server->secType = NTLM; | 574 | server->secType = NTLM; |
570 | else if(secFlags & CIFSSEC_MAY_NTLMV2) | 575 | else if (secFlags & CIFSSEC_MAY_NTLMV2) |
571 | server->secType = NTLMv2; | 576 | server->secType = NTLMv2; |
572 | /* else krb5 ... any others ... */ | 577 | /* else krb5 ... any others ... */ |
573 | 578 | ||
@@ -596,7 +601,7 @@ CIFSSMBNegotiate(unsigned int xid, struct cifsSesInfo *ses) | |||
596 | 601 | ||
597 | /* BB might be helpful to save off the domain of server here */ | 602 | /* BB might be helpful to save off the domain of server here */ |
598 | 603 | ||
599 | if ((pSMBr->hdr.Flags2 & SMBFLG2_EXT_SEC) && | 604 | if ((pSMBr->hdr.Flags2 & SMBFLG2_EXT_SEC) && |
600 | (server->capabilities & CAP_EXTENDED_SECURITY)) { | 605 | (server->capabilities & CAP_EXTENDED_SECURITY)) { |
601 | count = pSMBr->ByteCount; | 606 | count = pSMBr->ByteCount; |
602 | if (count < 16) | 607 | if (count < 16) |
@@ -620,7 +625,7 @@ CIFSSMBNegotiate(unsigned int xid, struct cifsSesInfo *ses) | |||
620 | SecurityBlob, | 625 | SecurityBlob, |
621 | count - 16, | 626 | count - 16, |
622 | &server->secType); | 627 | &server->secType); |
623 | if(rc == 1) { | 628 | if (rc == 1) { |
624 | /* BB Need to fill struct for sessetup here */ | 629 | /* BB Need to fill struct for sessetup here */ |
625 | rc = -EOPNOTSUPP; | 630 | rc = -EOPNOTSUPP; |
626 | } else { | 631 | } else { |
@@ -633,26 +638,37 @@ CIFSSMBNegotiate(unsigned int xid, struct cifsSesInfo *ses) | |||
633 | #ifdef CONFIG_CIFS_WEAK_PW_HASH | 638 | #ifdef CONFIG_CIFS_WEAK_PW_HASH |
634 | signing_check: | 639 | signing_check: |
635 | #endif | 640 | #endif |
636 | if(sign_CIFS_PDUs == FALSE) { | 641 | if ((secFlags & CIFSSEC_MAY_SIGN) == 0) { |
637 | if(server->secMode & SECMODE_SIGN_REQUIRED) | 642 | /* MUST_SIGN already includes the MAY_SIGN FLAG |
638 | cERROR(1,("Server requires " | 643 | so if this is zero it means that signing is disabled */ |
639 | "/proc/fs/cifs/PacketSigningEnabled to be on")); | 644 | cFYI(1, ("Signing disabled")); |
640 | server->secMode &= | 645 | if (server->secMode & SECMODE_SIGN_REQUIRED) |
646 | cERROR(1, ("Server requires " | ||
647 | "/proc/fs/cifs/PacketSigningEnabled " | ||
648 | "to be on")); | ||
649 | server->secMode &= | ||
641 | ~(SECMODE_SIGN_ENABLED | SECMODE_SIGN_REQUIRED); | 650 | ~(SECMODE_SIGN_ENABLED | SECMODE_SIGN_REQUIRED); |
642 | } else if(sign_CIFS_PDUs == 1) { | 651 | } else if ((secFlags & CIFSSEC_MUST_SIGN) == CIFSSEC_MUST_SIGN) { |
643 | if((server->secMode & SECMODE_SIGN_REQUIRED) == 0) | 652 | /* signing required */ |
644 | server->secMode &= | 653 | cFYI(1, ("Must sign - secFlags 0x%x", secFlags)); |
645 | ~(SECMODE_SIGN_ENABLED | SECMODE_SIGN_REQUIRED); | 654 | if ((server->secMode & |
646 | } else if(sign_CIFS_PDUs == 2) { | ||
647 | if((server->secMode & | ||
648 | (SECMODE_SIGN_ENABLED | SECMODE_SIGN_REQUIRED)) == 0) { | 655 | (SECMODE_SIGN_ENABLED | SECMODE_SIGN_REQUIRED)) == 0) { |
649 | cERROR(1,("signing required but server lacks support")); | 656 | cERROR(1, |
650 | } | 657 | ("signing required but server lacks support")); |
658 | rc = -EOPNOTSUPP; | ||
659 | } else | ||
660 | server->secMode |= SECMODE_SIGN_REQUIRED; | ||
661 | } else { | ||
662 | /* signing optional ie CIFSSEC_MAY_SIGN */ | ||
663 | if ((server->secMode & SECMODE_SIGN_REQUIRED) == 0) | ||
664 | server->secMode &= | ||
665 | ~(SECMODE_SIGN_ENABLED | SECMODE_SIGN_REQUIRED); | ||
651 | } | 666 | } |
652 | neg_err_exit: | 667 | |
668 | neg_err_exit: | ||
653 | cifs_buf_release(pSMB); | 669 | cifs_buf_release(pSMB); |
654 | 670 | ||
655 | cFYI(1,("negprot rc %d",rc)); | 671 | cFYI(1, ("negprot rc %d", rc)); |
656 | return rc; | 672 | return rc; |
657 | } | 673 | } |
658 | 674 | ||
@@ -669,7 +685,7 @@ CIFSSMBTDis(const int xid, struct cifsTconInfo *tcon) | |||
669 | * If last user of the connection and | 685 | * If last user of the connection and |
670 | * connection alive - disconnect it | 686 | * connection alive - disconnect it |
671 | * If this is the last connection on the server session disconnect it | 687 | * If this is the last connection on the server session disconnect it |
672 | * (and inside session disconnect we should check if tcp socket needs | 688 | * (and inside session disconnect we should check if tcp socket needs |
673 | * to be freed and kernel thread woken up). | 689 | * to be freed and kernel thread woken up). |
674 | */ | 690 | */ |
675 | if (tcon) | 691 | if (tcon) |
@@ -683,18 +699,18 @@ CIFSSMBTDis(const int xid, struct cifsTconInfo *tcon) | |||
683 | return -EBUSY; | 699 | return -EBUSY; |
684 | } | 700 | } |
685 | 701 | ||
686 | /* No need to return error on this operation if tid invalidated and | 702 | /* No need to return error on this operation if tid invalidated and |
687 | closed on server already e.g. due to tcp session crashing */ | 703 | closed on server already e.g. due to tcp session crashing */ |
688 | if(tcon->tidStatus == CifsNeedReconnect) { | 704 | if (tcon->tidStatus == CifsNeedReconnect) { |
689 | up(&tcon->tconSem); | 705 | up(&tcon->tconSem); |
690 | return 0; | 706 | return 0; |
691 | } | 707 | } |
692 | 708 | ||
693 | if((tcon->ses == NULL) || (tcon->ses->server == NULL)) { | 709 | if ((tcon->ses == NULL) || (tcon->ses->server == NULL)) { |
694 | up(&tcon->tconSem); | 710 | up(&tcon->tconSem); |
695 | return -EIO; | 711 | return -EIO; |
696 | } | 712 | } |
697 | rc = small_smb_init(SMB_COM_TREE_DISCONNECT, 0, tcon, | 713 | rc = small_smb_init(SMB_COM_TREE_DISCONNECT, 0, tcon, |
698 | (void **)&smb_buffer); | 714 | (void **)&smb_buffer); |
699 | if (rc) { | 715 | if (rc) { |
700 | up(&tcon->tconSem); | 716 | up(&tcon->tconSem); |
@@ -711,7 +727,7 @@ CIFSSMBTDis(const int xid, struct cifsTconInfo *tcon) | |||
711 | cifs_small_buf_release(smb_buffer); | 727 | cifs_small_buf_release(smb_buffer); |
712 | up(&tcon->tconSem); | 728 | up(&tcon->tconSem); |
713 | 729 | ||
714 | /* No need to return error on this operation if tid invalidated and | 730 | /* No need to return error on this operation if tid invalidated and |
715 | closed on server already e.g. due to tcp session crashing */ | 731 | closed on server already e.g. due to tcp session crashing */ |
716 | if (rc == -EAGAIN) | 732 | if (rc == -EAGAIN) |
717 | rc = 0; | 733 | rc = 0; |
@@ -745,11 +761,11 @@ CIFSSMBLogoff(const int xid, struct cifsSesInfo *ses) | |||
745 | } | 761 | } |
746 | 762 | ||
747 | smb_buffer_response = (struct smb_hdr *)pSMB; /* BB removeme BB */ | 763 | smb_buffer_response = (struct smb_hdr *)pSMB; /* BB removeme BB */ |
748 | 764 | ||
749 | if(ses->server) { | 765 | if (ses->server) { |
750 | pSMB->hdr.Mid = GetNextMid(ses->server); | 766 | pSMB->hdr.Mid = GetNextMid(ses->server); |
751 | 767 | ||
752 | if(ses->server->secMode & | 768 | if (ses->server->secMode & |
753 | (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) | 769 | (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) |
754 | pSMB->hdr.Flags2 |= SMBFLG2_SECURITY_SIGNATURE; | 770 | pSMB->hdr.Flags2 |= SMBFLG2_SECURITY_SIGNATURE; |
755 | } | 771 | } |
@@ -772,7 +788,7 @@ CIFSSMBLogoff(const int xid, struct cifsSesInfo *ses) | |||
772 | cifs_small_buf_release(pSMB); | 788 | cifs_small_buf_release(pSMB); |
773 | 789 | ||
774 | /* if session dead then we do not need to do ulogoff, | 790 | /* if session dead then we do not need to do ulogoff, |
775 | since server closed smb session, no sense reporting | 791 | since server closed smb session, no sense reporting |
776 | error */ | 792 | error */ |
777 | if (rc == -EAGAIN) | 793 | if (rc == -EAGAIN) |
778 | rc = 0; | 794 | rc = 0; |
@@ -780,6 +796,82 @@ CIFSSMBLogoff(const int xid, struct cifsSesInfo *ses) | |||
780 | } | 796 | } |
781 | 797 | ||
782 | int | 798 | int |
799 | CIFSPOSIXDelFile(const int xid, struct cifsTconInfo *tcon, const char *fileName, | ||
800 | __u16 type, const struct nls_table *nls_codepage, int remap) | ||
801 | { | ||
802 | TRANSACTION2_SPI_REQ *pSMB = NULL; | ||
803 | TRANSACTION2_SPI_RSP *pSMBr = NULL; | ||
804 | struct unlink_psx_rq *pRqD; | ||
805 | int name_len; | ||
806 | int rc = 0; | ||
807 | int bytes_returned = 0; | ||
808 | __u16 params, param_offset, offset, byte_count; | ||
809 | |||
810 | cFYI(1, ("In POSIX delete")); | ||
811 | PsxDelete: | ||
812 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, | ||
813 | (void **) &pSMBr); | ||
814 | if (rc) | ||
815 | return rc; | ||
816 | |||
817 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { | ||
818 | name_len = | ||
819 | cifsConvertToUCS((__le16 *) pSMB->FileName, fileName, | ||
820 | PATH_MAX, nls_codepage, remap); | ||
821 | name_len++; /* trailing null */ | ||
822 | name_len *= 2; | ||
823 | } else { /* BB add path length overrun check */ | ||
824 | name_len = strnlen(fileName, PATH_MAX); | ||
825 | name_len++; /* trailing null */ | ||
826 | strncpy(pSMB->FileName, fileName, name_len); | ||
827 | } | ||
828 | |||
829 | params = 6 + name_len; | ||
830 | pSMB->MaxParameterCount = cpu_to_le16(2); | ||
831 | pSMB->MaxDataCount = 0; /* BB double check this with jra */ | ||
832 | pSMB->MaxSetupCount = 0; | ||
833 | pSMB->Reserved = 0; | ||
834 | pSMB->Flags = 0; | ||
835 | pSMB->Timeout = 0; | ||
836 | pSMB->Reserved2 = 0; | ||
837 | param_offset = offsetof(struct smb_com_transaction2_spi_req, | ||
838 | InformationLevel) - 4; | ||
839 | offset = param_offset + params; | ||
840 | |||
841 | /* Setup pointer to Request Data (inode type) */ | ||
842 | pRqD = (struct unlink_psx_rq *)(((char *)&pSMB->hdr.Protocol) + offset); | ||
843 | pRqD->type = cpu_to_le16(type); | ||
844 | pSMB->ParameterOffset = cpu_to_le16(param_offset); | ||
845 | pSMB->DataOffset = cpu_to_le16(offset); | ||
846 | pSMB->SetupCount = 1; | ||
847 | pSMB->Reserved3 = 0; | ||
848 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); | ||
849 | byte_count = 3 /* pad */ + params + sizeof(struct unlink_psx_rq); | ||
850 | |||
851 | pSMB->DataCount = cpu_to_le16(sizeof(struct unlink_psx_rq)); | ||
852 | pSMB->TotalDataCount = cpu_to_le16(sizeof(struct unlink_psx_rq)); | ||
853 | pSMB->ParameterCount = cpu_to_le16(params); | ||
854 | pSMB->TotalParameterCount = pSMB->ParameterCount; | ||
855 | pSMB->InformationLevel = cpu_to_le16(SMB_POSIX_UNLINK); | ||
856 | pSMB->Reserved4 = 0; | ||
857 | pSMB->hdr.smb_buf_length += byte_count; | ||
858 | pSMB->ByteCount = cpu_to_le16(byte_count); | ||
859 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, | ||
860 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); | ||
861 | if (rc) { | ||
862 | cFYI(1, ("Posix delete returned %d", rc)); | ||
863 | } | ||
864 | cifs_buf_release(pSMB); | ||
865 | |||
866 | cifs_stats_inc(&tcon->num_deletes); | ||
867 | |||
868 | if (rc == -EAGAIN) | ||
869 | goto PsxDelete; | ||
870 | |||
871 | return rc; | ||
872 | } | ||
873 | |||
874 | int | ||
783 | CIFSSMBDelFile(const int xid, struct cifsTconInfo *tcon, const char *fileName, | 875 | CIFSSMBDelFile(const int xid, struct cifsTconInfo *tcon, const char *fileName, |
784 | const struct nls_table *nls_codepage, int remap) | 876 | const struct nls_table *nls_codepage, int remap) |
785 | { | 877 | { |
@@ -797,7 +889,7 @@ DelFileRetry: | |||
797 | 889 | ||
798 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { | 890 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
799 | name_len = | 891 | name_len = |
800 | cifsConvertToUCS((__le16 *) pSMB->fileName, fileName, | 892 | cifsConvertToUCS((__le16 *) pSMB->fileName, fileName, |
801 | PATH_MAX, nls_codepage, remap); | 893 | PATH_MAX, nls_codepage, remap); |
802 | name_len++; /* trailing null */ | 894 | name_len++; /* trailing null */ |
803 | name_len *= 2; | 895 | name_len *= 2; |
@@ -816,7 +908,7 @@ DelFileRetry: | |||
816 | cifs_stats_inc(&tcon->num_deletes); | 908 | cifs_stats_inc(&tcon->num_deletes); |
817 | if (rc) { | 909 | if (rc) { |
818 | cFYI(1, ("Error in RMFile = %d", rc)); | 910 | cFYI(1, ("Error in RMFile = %d", rc)); |
819 | } | 911 | } |
820 | 912 | ||
821 | cifs_buf_release(pSMB); | 913 | cifs_buf_release(pSMB); |
822 | if (rc == -EAGAIN) | 914 | if (rc == -EAGAIN) |
@@ -826,7 +918,7 @@ DelFileRetry: | |||
826 | } | 918 | } |
827 | 919 | ||
828 | int | 920 | int |
829 | CIFSSMBRmDir(const int xid, struct cifsTconInfo *tcon, const char *dirName, | 921 | CIFSSMBRmDir(const int xid, struct cifsTconInfo *tcon, const char *dirName, |
830 | const struct nls_table *nls_codepage, int remap) | 922 | const struct nls_table *nls_codepage, int remap) |
831 | { | 923 | { |
832 | DELETE_DIRECTORY_REQ *pSMB = NULL; | 924 | DELETE_DIRECTORY_REQ *pSMB = NULL; |
@@ -887,7 +979,7 @@ MkDirRetry: | |||
887 | return rc; | 979 | return rc; |
888 | 980 | ||
889 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { | 981 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
890 | name_len = cifsConvertToUCS((__le16 *) pSMB->DirName, name, | 982 | name_len = cifsConvertToUCS((__le16 *) pSMB->DirName, name, |
891 | PATH_MAX, nls_codepage, remap); | 983 | PATH_MAX, nls_codepage, remap); |
892 | name_len++; /* trailing null */ | 984 | name_len++; /* trailing null */ |
893 | name_len *= 2; | 985 | name_len *= 2; |
@@ -916,7 +1008,7 @@ MkDirRetry: | |||
916 | int | 1008 | int |
917 | CIFSPOSIXCreate(const int xid, struct cifsTconInfo *tcon, __u32 posix_flags, | 1009 | CIFSPOSIXCreate(const int xid, struct cifsTconInfo *tcon, __u32 posix_flags, |
918 | __u64 mode, __u16 * netfid, FILE_UNIX_BASIC_INFO *pRetData, | 1010 | __u64 mode, __u16 * netfid, FILE_UNIX_BASIC_INFO *pRetData, |
919 | __u32 *pOplock, const char *name, | 1011 | __u32 *pOplock, const char *name, |
920 | const struct nls_table *nls_codepage, int remap) | 1012 | const struct nls_table *nls_codepage, int remap) |
921 | { | 1013 | { |
922 | TRANSACTION2_SPI_REQ *pSMB = NULL; | 1014 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
@@ -924,7 +1016,6 @@ CIFSPOSIXCreate(const int xid, struct cifsTconInfo *tcon, __u32 posix_flags, | |||
924 | int name_len; | 1016 | int name_len; |
925 | int rc = 0; | 1017 | int rc = 0; |
926 | int bytes_returned = 0; | 1018 | int bytes_returned = 0; |
927 | char *data_offset; | ||
928 | __u16 params, param_offset, offset, byte_count, count; | 1019 | __u16 params, param_offset, offset, byte_count, count; |
929 | OPEN_PSX_REQ * pdata; | 1020 | OPEN_PSX_REQ * pdata; |
930 | OPEN_PSX_RSP * psx_rsp; | 1021 | OPEN_PSX_RSP * psx_rsp; |
@@ -958,13 +1049,12 @@ PsxCreat: | |||
958 | pSMB->Timeout = 0; | 1049 | pSMB->Timeout = 0; |
959 | pSMB->Reserved2 = 0; | 1050 | pSMB->Reserved2 = 0; |
960 | param_offset = offsetof(struct smb_com_transaction2_spi_req, | 1051 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
961 | InformationLevel) - 4; | 1052 | InformationLevel) - 4; |
962 | offset = param_offset + params; | 1053 | offset = param_offset + params; |
963 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; | ||
964 | pdata = (OPEN_PSX_REQ *)(((char *)&pSMB->hdr.Protocol) + offset); | 1054 | pdata = (OPEN_PSX_REQ *)(((char *)&pSMB->hdr.Protocol) + offset); |
965 | pdata->Level = SMB_QUERY_FILE_UNIX_BASIC; | 1055 | pdata->Level = SMB_QUERY_FILE_UNIX_BASIC; |
966 | pdata->Permissions = cpu_to_le64(mode); | 1056 | pdata->Permissions = cpu_to_le64(mode); |
967 | pdata->PosixOpenFlags = cpu_to_le32(posix_flags); | 1057 | pdata->PosixOpenFlags = cpu_to_le32(posix_flags); |
968 | pdata->OpenFlags = cpu_to_le32(*pOplock); | 1058 | pdata->OpenFlags = cpu_to_le32(*pOplock); |
969 | pSMB->ParameterOffset = cpu_to_le16(param_offset); | 1059 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
970 | pSMB->DataOffset = cpu_to_le16(offset); | 1060 | pSMB->DataOffset = cpu_to_le16(offset); |
@@ -979,7 +1069,7 @@ PsxCreat: | |||
979 | pSMB->TotalParameterCount = pSMB->ParameterCount; | 1069 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
980 | pSMB->InformationLevel = cpu_to_le16(SMB_POSIX_OPEN); | 1070 | pSMB->InformationLevel = cpu_to_le16(SMB_POSIX_OPEN); |
981 | pSMB->Reserved4 = 0; | 1071 | pSMB->Reserved4 = 0; |
982 | pSMB->hdr.smb_buf_length += byte_count; | 1072 | pSMB->hdr.smb_buf_length += byte_count; |
983 | pSMB->ByteCount = cpu_to_le16(byte_count); | 1073 | pSMB->ByteCount = cpu_to_le16(byte_count); |
984 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, | 1074 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
985 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); | 1075 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
@@ -988,7 +1078,7 @@ PsxCreat: | |||
988 | goto psx_create_err; | 1078 | goto psx_create_err; |
989 | } | 1079 | } |
990 | 1080 | ||
991 | cFYI(1,("copying inode info")); | 1081 | cFYI(1, ("copying inode info")); |
992 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); | 1082 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
993 | 1083 | ||
994 | if (rc || (pSMBr->ByteCount < sizeof(OPEN_PSX_RSP))) { | 1084 | if (rc || (pSMBr->ByteCount < sizeof(OPEN_PSX_RSP))) { |
@@ -997,34 +1087,33 @@ PsxCreat: | |||
997 | } | 1087 | } |
998 | 1088 | ||
999 | /* copy return information to pRetData */ | 1089 | /* copy return information to pRetData */ |
1000 | psx_rsp = (OPEN_PSX_RSP *)((char *) &pSMBr->hdr.Protocol | 1090 | psx_rsp = (OPEN_PSX_RSP *)((char *) &pSMBr->hdr.Protocol |
1001 | + le16_to_cpu(pSMBr->t2.DataOffset)); | 1091 | + le16_to_cpu(pSMBr->t2.DataOffset)); |
1002 | 1092 | ||
1003 | *pOplock = le16_to_cpu(psx_rsp->OplockFlags); | 1093 | *pOplock = le16_to_cpu(psx_rsp->OplockFlags); |
1004 | if(netfid) | 1094 | if (netfid) |
1005 | *netfid = psx_rsp->Fid; /* cifs fid stays in le */ | 1095 | *netfid = psx_rsp->Fid; /* cifs fid stays in le */ |
1006 | /* Let caller know file was created so we can set the mode. */ | 1096 | /* Let caller know file was created so we can set the mode. */ |
1007 | /* Do we care about the CreateAction in any other cases? */ | 1097 | /* Do we care about the CreateAction in any other cases? */ |
1008 | if(cpu_to_le32(FILE_CREATE) == psx_rsp->CreateAction) | 1098 | if (cpu_to_le32(FILE_CREATE) == psx_rsp->CreateAction) |
1009 | *pOplock |= CIFS_CREATE_ACTION; | 1099 | *pOplock |= CIFS_CREATE_ACTION; |
1010 | /* check to make sure response data is there */ | 1100 | /* check to make sure response data is there */ |
1011 | if(psx_rsp->ReturnedLevel != SMB_QUERY_FILE_UNIX_BASIC) { | 1101 | if (psx_rsp->ReturnedLevel != SMB_QUERY_FILE_UNIX_BASIC) { |
1012 | pRetData->Type = -1; /* unknown */ | 1102 | pRetData->Type = -1; /* unknown */ |
1013 | #ifdef CONFIG_CIFS_DEBUG2 | 1103 | #ifdef CONFIG_CIFS_DEBUG2 |
1014 | cFYI(1,("unknown type")); | 1104 | cFYI(1, ("unknown type")); |
1015 | #endif | 1105 | #endif |
1016 | } else { | 1106 | } else { |
1017 | if(pSMBr->ByteCount < sizeof(OPEN_PSX_RSP) | 1107 | if (pSMBr->ByteCount < sizeof(OPEN_PSX_RSP) |
1018 | + sizeof(FILE_UNIX_BASIC_INFO)) { | 1108 | + sizeof(FILE_UNIX_BASIC_INFO)) { |
1019 | cERROR(1,("Open response data too small")); | 1109 | cERROR(1, ("Open response data too small")); |
1020 | pRetData->Type = -1; | 1110 | pRetData->Type = -1; |
1021 | goto psx_create_err; | 1111 | goto psx_create_err; |
1022 | } | 1112 | } |
1023 | memcpy((char *) pRetData, | 1113 | memcpy((char *) pRetData, |
1024 | (char *)psx_rsp + sizeof(OPEN_PSX_RSP), | 1114 | (char *)psx_rsp + sizeof(OPEN_PSX_RSP), |
1025 | sizeof (FILE_UNIX_BASIC_INFO)); | 1115 | sizeof (FILE_UNIX_BASIC_INFO)); |
1026 | } | 1116 | } |
1027 | |||
1028 | 1117 | ||
1029 | psx_create_err: | 1118 | psx_create_err: |
1030 | cifs_buf_release(pSMB); | 1119 | cifs_buf_release(pSMB); |
@@ -1034,7 +1123,7 @@ psx_create_err: | |||
1034 | if (rc == -EAGAIN) | 1123 | if (rc == -EAGAIN) |
1035 | goto PsxCreat; | 1124 | goto PsxCreat; |
1036 | 1125 | ||
1037 | return rc; | 1126 | return rc; |
1038 | } | 1127 | } |
1039 | 1128 | ||
1040 | static __u16 convert_disposition(int disposition) | 1129 | static __u16 convert_disposition(int disposition) |
@@ -1061,7 +1150,7 @@ static __u16 convert_disposition(int disposition) | |||
1061 | ofun = SMBOPEN_OCREATE | SMBOPEN_OTRUNC; | 1150 | ofun = SMBOPEN_OCREATE | SMBOPEN_OTRUNC; |
1062 | break; | 1151 | break; |
1063 | default: | 1152 | default: |
1064 | cFYI(1,("unknown disposition %d",disposition)); | 1153 | cFYI(1, ("unknown disposition %d", disposition)); |
1065 | ofun = SMBOPEN_OAPPEND; /* regular open */ | 1154 | ofun = SMBOPEN_OAPPEND; /* regular open */ |
1066 | } | 1155 | } |
1067 | return ofun; | 1156 | return ofun; |
@@ -1071,7 +1160,7 @@ int | |||
1071 | SMBLegacyOpen(const int xid, struct cifsTconInfo *tcon, | 1160 | SMBLegacyOpen(const int xid, struct cifsTconInfo *tcon, |
1072 | const char *fileName, const int openDisposition, | 1161 | const char *fileName, const int openDisposition, |
1073 | const int access_flags, const int create_options, __u16 * netfid, | 1162 | const int access_flags, const int create_options, __u16 * netfid, |
1074 | int *pOplock, FILE_ALL_INFO * pfile_info, | 1163 | int *pOplock, FILE_ALL_INFO * pfile_info, |
1075 | const struct nls_table *nls_codepage, int remap) | 1164 | const struct nls_table *nls_codepage, int remap) |
1076 | { | 1165 | { |
1077 | int rc = -EACCES; | 1166 | int rc = -EACCES; |
@@ -1113,16 +1202,16 @@ OldOpenRetry: | |||
1113 | 1 = write | 1202 | 1 = write |
1114 | 2 = rw | 1203 | 2 = rw |
1115 | 3 = execute | 1204 | 3 = execute |
1116 | */ | 1205 | */ |
1117 | pSMB->Mode = cpu_to_le16(2); | 1206 | pSMB->Mode = cpu_to_le16(2); |
1118 | pSMB->Mode |= cpu_to_le16(0x40); /* deny none */ | 1207 | pSMB->Mode |= cpu_to_le16(0x40); /* deny none */ |
1119 | /* set file as system file if special file such | 1208 | /* set file as system file if special file such |
1120 | as fifo and server expecting SFU style and | 1209 | as fifo and server expecting SFU style and |
1121 | no Unix extensions */ | 1210 | no Unix extensions */ |
1122 | 1211 | ||
1123 | if(create_options & CREATE_OPTION_SPECIAL) | 1212 | if (create_options & CREATE_OPTION_SPECIAL) |
1124 | pSMB->FileAttributes = cpu_to_le16(ATTR_SYSTEM); | 1213 | pSMB->FileAttributes = cpu_to_le16(ATTR_SYSTEM); |
1125 | else | 1214 | else |
1126 | pSMB->FileAttributes = cpu_to_le16(0/*ATTR_NORMAL*/); /* BB FIXME */ | 1215 | pSMB->FileAttributes = cpu_to_le16(0/*ATTR_NORMAL*/); /* BB FIXME */ |
1127 | 1216 | ||
1128 | /* if ((omode & S_IWUGO) == 0) | 1217 | /* if ((omode & S_IWUGO) == 0) |
@@ -1132,7 +1221,8 @@ OldOpenRetry: | |||
1132 | being created */ | 1221 | being created */ |
1133 | 1222 | ||
1134 | /* BB FIXME BB */ | 1223 | /* BB FIXME BB */ |
1135 | /* pSMB->CreateOptions = cpu_to_le32(create_options & CREATE_OPTIONS_MASK); */ | 1224 | /* pSMB->CreateOptions = cpu_to_le32(create_options & |
1225 | CREATE_OPTIONS_MASK); */ | ||
1136 | /* BB FIXME END BB */ | 1226 | /* BB FIXME END BB */ |
1137 | 1227 | ||
1138 | pSMB->Sattr = cpu_to_le16(ATTR_HIDDEN | ATTR_SYSTEM | ATTR_DIRECTORY); | 1228 | pSMB->Sattr = cpu_to_le16(ATTR_HIDDEN | ATTR_SYSTEM | ATTR_DIRECTORY); |
@@ -1143,7 +1233,7 @@ OldOpenRetry: | |||
1143 | pSMB->ByteCount = cpu_to_le16(count); | 1233 | pSMB->ByteCount = cpu_to_le16(count); |
1144 | /* long_op set to 1 to allow for oplock break timeouts */ | 1234 | /* long_op set to 1 to allow for oplock break timeouts */ |
1145 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, | 1235 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
1146 | (struct smb_hdr *) pSMBr, &bytes_returned, 1); | 1236 | (struct smb_hdr *) pSMBr, &bytes_returned, 1); |
1147 | cifs_stats_inc(&tcon->num_opens); | 1237 | cifs_stats_inc(&tcon->num_opens); |
1148 | if (rc) { | 1238 | if (rc) { |
1149 | cFYI(1, ("Error in Open = %d", rc)); | 1239 | cFYI(1, ("Error in Open = %d", rc)); |
@@ -1156,17 +1246,17 @@ OldOpenRetry: | |||
1156 | /* Let caller know file was created so we can set the mode. */ | 1246 | /* Let caller know file was created so we can set the mode. */ |
1157 | /* Do we care about the CreateAction in any other cases? */ | 1247 | /* Do we care about the CreateAction in any other cases? */ |
1158 | /* BB FIXME BB */ | 1248 | /* BB FIXME BB */ |
1159 | /* if(cpu_to_le32(FILE_CREATE) == pSMBr->CreateAction) | 1249 | /* if (cpu_to_le32(FILE_CREATE) == pSMBr->CreateAction) |
1160 | *pOplock |= CIFS_CREATE_ACTION; */ | 1250 | *pOplock |= CIFS_CREATE_ACTION; */ |
1161 | /* BB FIXME END */ | 1251 | /* BB FIXME END */ |
1162 | 1252 | ||
1163 | if(pfile_info) { | 1253 | if (pfile_info) { |
1164 | pfile_info->CreationTime = 0; /* BB convert CreateTime*/ | 1254 | pfile_info->CreationTime = 0; /* BB convert CreateTime*/ |
1165 | pfile_info->LastAccessTime = 0; /* BB fixme */ | 1255 | pfile_info->LastAccessTime = 0; /* BB fixme */ |
1166 | pfile_info->LastWriteTime = 0; /* BB fixme */ | 1256 | pfile_info->LastWriteTime = 0; /* BB fixme */ |
1167 | pfile_info->ChangeTime = 0; /* BB fixme */ | 1257 | pfile_info->ChangeTime = 0; /* BB fixme */ |
1168 | pfile_info->Attributes = | 1258 | pfile_info->Attributes = |
1169 | cpu_to_le32(le16_to_cpu(pSMBr->FileAttributes)); | 1259 | cpu_to_le32(le16_to_cpu(pSMBr->FileAttributes)); |
1170 | /* the file_info buf is endian converted by caller */ | 1260 | /* the file_info buf is endian converted by caller */ |
1171 | pfile_info->AllocationSize = | 1261 | pfile_info->AllocationSize = |
1172 | cpu_to_le64(le32_to_cpu(pSMBr->EndOfFile)); | 1262 | cpu_to_le64(le32_to_cpu(pSMBr->EndOfFile)); |
@@ -1185,7 +1275,7 @@ int | |||
1185 | CIFSSMBOpen(const int xid, struct cifsTconInfo *tcon, | 1275 | CIFSSMBOpen(const int xid, struct cifsTconInfo *tcon, |
1186 | const char *fileName, const int openDisposition, | 1276 | const char *fileName, const int openDisposition, |
1187 | const int access_flags, const int create_options, __u16 * netfid, | 1277 | const int access_flags, const int create_options, __u16 * netfid, |
1188 | int *pOplock, FILE_ALL_INFO * pfile_info, | 1278 | int *pOplock, FILE_ALL_INFO * pfile_info, |
1189 | const struct nls_table *nls_codepage, int remap) | 1279 | const struct nls_table *nls_codepage, int remap) |
1190 | { | 1280 | { |
1191 | int rc = -EACCES; | 1281 | int rc = -EACCES; |
@@ -1228,7 +1318,7 @@ openRetry: | |||
1228 | /* set file as system file if special file such | 1318 | /* set file as system file if special file such |
1229 | as fifo and server expecting SFU style and | 1319 | as fifo and server expecting SFU style and |
1230 | no Unix extensions */ | 1320 | no Unix extensions */ |
1231 | if(create_options & CREATE_OPTION_SPECIAL) | 1321 | if (create_options & CREATE_OPTION_SPECIAL) |
1232 | pSMB->FileAttributes = cpu_to_le32(ATTR_SYSTEM); | 1322 | pSMB->FileAttributes = cpu_to_le32(ATTR_SYSTEM); |
1233 | else | 1323 | else |
1234 | pSMB->FileAttributes = cpu_to_le32(ATTR_NORMAL); | 1324 | pSMB->FileAttributes = cpu_to_le32(ATTR_NORMAL); |
@@ -1266,10 +1356,10 @@ openRetry: | |||
1266 | *netfid = pSMBr->Fid; /* cifs fid stays in le */ | 1356 | *netfid = pSMBr->Fid; /* cifs fid stays in le */ |
1267 | /* Let caller know file was created so we can set the mode. */ | 1357 | /* Let caller know file was created so we can set the mode. */ |
1268 | /* Do we care about the CreateAction in any other cases? */ | 1358 | /* Do we care about the CreateAction in any other cases? */ |
1269 | if(cpu_to_le32(FILE_CREATE) == pSMBr->CreateAction) | 1359 | if (cpu_to_le32(FILE_CREATE) == pSMBr->CreateAction) |
1270 | *pOplock |= CIFS_CREATE_ACTION; | 1360 | *pOplock |= CIFS_CREATE_ACTION; |
1271 | if(pfile_info) { | 1361 | if (pfile_info) { |
1272 | memcpy((char *)pfile_info,(char *)&pSMBr->CreationTime, | 1362 | memcpy((char *)pfile_info, (char *)&pSMBr->CreationTime, |
1273 | 36 /* CreationTime to Attributes */); | 1363 | 36 /* CreationTime to Attributes */); |
1274 | /* the file_info buf is endian converted by caller */ | 1364 | /* the file_info buf is endian converted by caller */ |
1275 | pfile_info->AllocationSize = pSMBr->AllocationSize; | 1365 | pfile_info->AllocationSize = pSMBr->AllocationSize; |
@@ -1285,10 +1375,9 @@ openRetry: | |||
1285 | } | 1375 | } |
1286 | 1376 | ||
1287 | int | 1377 | int |
1288 | CIFSSMBRead(const int xid, struct cifsTconInfo *tcon, | 1378 | CIFSSMBRead(const int xid, struct cifsTconInfo *tcon, const int netfid, |
1289 | const int netfid, const unsigned int count, | 1379 | const unsigned int count, const __u64 lseek, unsigned int *nbytes, |
1290 | const __u64 lseek, unsigned int *nbytes, char **buf, | 1380 | char **buf, int *pbuf_type) |
1291 | int * pbuf_type) | ||
1292 | { | 1381 | { |
1293 | int rc = -EACCES; | 1382 | int rc = -EACCES; |
1294 | READ_REQ *pSMB = NULL; | 1383 | READ_REQ *pSMB = NULL; |
@@ -1298,8 +1387,8 @@ CIFSSMBRead(const int xid, struct cifsTconInfo *tcon, | |||
1298 | int resp_buf_type = 0; | 1387 | int resp_buf_type = 0; |
1299 | struct kvec iov[1]; | 1388 | struct kvec iov[1]; |
1300 | 1389 | ||
1301 | cFYI(1,("Reading %d bytes on fid %d",count,netfid)); | 1390 | cFYI(1, ("Reading %d bytes on fid %d", count, netfid)); |
1302 | if(tcon->ses->capabilities & CAP_LARGE_FILES) | 1391 | if (tcon->ses->capabilities & CAP_LARGE_FILES) |
1303 | wct = 12; | 1392 | wct = 12; |
1304 | else | 1393 | else |
1305 | wct = 10; /* old style read */ | 1394 | wct = 10; /* old style read */ |
@@ -1316,28 +1405,28 @@ CIFSSMBRead(const int xid, struct cifsTconInfo *tcon, | |||
1316 | pSMB->AndXCommand = 0xFF; /* none */ | 1405 | pSMB->AndXCommand = 0xFF; /* none */ |
1317 | pSMB->Fid = netfid; | 1406 | pSMB->Fid = netfid; |
1318 | pSMB->OffsetLow = cpu_to_le32(lseek & 0xFFFFFFFF); | 1407 | pSMB->OffsetLow = cpu_to_le32(lseek & 0xFFFFFFFF); |
1319 | if(wct == 12) | 1408 | if (wct == 12) |
1320 | pSMB->OffsetHigh = cpu_to_le32(lseek >> 32); | 1409 | pSMB->OffsetHigh = cpu_to_le32(lseek >> 32); |
1321 | else if((lseek >> 32) > 0) /* can not handle this big offset for old */ | 1410 | else if ((lseek >> 32) > 0) /* can not handle this big offset for old */ |
1322 | return -EIO; | 1411 | return -EIO; |
1323 | 1412 | ||
1324 | pSMB->Remaining = 0; | 1413 | pSMB->Remaining = 0; |
1325 | pSMB->MaxCount = cpu_to_le16(count & 0xFFFF); | 1414 | pSMB->MaxCount = cpu_to_le16(count & 0xFFFF); |
1326 | pSMB->MaxCountHigh = cpu_to_le32(count >> 16); | 1415 | pSMB->MaxCountHigh = cpu_to_le32(count >> 16); |
1327 | if(wct == 12) | 1416 | if (wct == 12) |
1328 | pSMB->ByteCount = 0; /* no need to do le conversion since 0 */ | 1417 | pSMB->ByteCount = 0; /* no need to do le conversion since 0 */ |
1329 | else { | 1418 | else { |
1330 | /* old style read */ | 1419 | /* old style read */ |
1331 | struct smb_com_readx_req * pSMBW = | 1420 | struct smb_com_readx_req *pSMBW = |
1332 | (struct smb_com_readx_req *)pSMB; | 1421 | (struct smb_com_readx_req *)pSMB; |
1333 | pSMBW->ByteCount = 0; | 1422 | pSMBW->ByteCount = 0; |
1334 | } | 1423 | } |
1335 | 1424 | ||
1336 | iov[0].iov_base = (char *)pSMB; | 1425 | iov[0].iov_base = (char *)pSMB; |
1337 | iov[0].iov_len = pSMB->hdr.smb_buf_length + 4; | 1426 | iov[0].iov_len = pSMB->hdr.smb_buf_length + 4; |
1338 | rc = SendReceive2(xid, tcon->ses, iov, | 1427 | rc = SendReceive2(xid, tcon->ses, iov, |
1339 | 1 /* num iovecs */, | 1428 | 1 /* num iovecs */, |
1340 | &resp_buf_type, 0); | 1429 | &resp_buf_type, 0); |
1341 | cifs_stats_inc(&tcon->num_reads); | 1430 | cifs_stats_inc(&tcon->num_reads); |
1342 | pSMBr = (READ_RSP *)iov[0].iov_base; | 1431 | pSMBr = (READ_RSP *)iov[0].iov_base; |
1343 | if (rc) { | 1432 | if (rc) { |
@@ -1351,33 +1440,34 @@ CIFSSMBRead(const int xid, struct cifsTconInfo *tcon, | |||
1351 | /*check that DataLength would not go beyond end of SMB */ | 1440 | /*check that DataLength would not go beyond end of SMB */ |
1352 | if ((data_length > CIFSMaxBufSize) | 1441 | if ((data_length > CIFSMaxBufSize) |
1353 | || (data_length > count)) { | 1442 | || (data_length > count)) { |
1354 | cFYI(1,("bad length %d for count %d",data_length,count)); | 1443 | cFYI(1, ("bad length %d for count %d", |
1444 | data_length, count)); | ||
1355 | rc = -EIO; | 1445 | rc = -EIO; |
1356 | *nbytes = 0; | 1446 | *nbytes = 0; |
1357 | } else { | 1447 | } else { |
1358 | pReadData = (char *) (&pSMBr->hdr.Protocol) + | 1448 | pReadData = (char *) (&pSMBr->hdr.Protocol) + |
1359 | le16_to_cpu(pSMBr->DataOffset); | 1449 | le16_to_cpu(pSMBr->DataOffset); |
1360 | /* if(rc = copy_to_user(buf, pReadData, data_length)) { | 1450 | /* if (rc = copy_to_user(buf, pReadData, data_length)) { |
1361 | cERROR(1,("Faulting on read rc = %d",rc)); | 1451 | cERROR(1,("Faulting on read rc = %d",rc)); |
1362 | rc = -EFAULT; | 1452 | rc = -EFAULT; |
1363 | }*/ /* can not use copy_to_user when using page cache*/ | 1453 | }*/ /* can not use copy_to_user when using page cache*/ |
1364 | if(*buf) | 1454 | if (*buf) |
1365 | memcpy(*buf,pReadData,data_length); | 1455 | memcpy(*buf, pReadData, data_length); |
1366 | } | 1456 | } |
1367 | } | 1457 | } |
1368 | 1458 | ||
1369 | /* cifs_small_buf_release(pSMB); */ /* Freed earlier now in SendReceive2 */ | 1459 | /* cifs_small_buf_release(pSMB); */ /* Freed earlier now in SendReceive2 */ |
1370 | if(*buf) { | 1460 | if (*buf) { |
1371 | if(resp_buf_type == CIFS_SMALL_BUFFER) | 1461 | if (resp_buf_type == CIFS_SMALL_BUFFER) |
1372 | cifs_small_buf_release(iov[0].iov_base); | 1462 | cifs_small_buf_release(iov[0].iov_base); |
1373 | else if(resp_buf_type == CIFS_LARGE_BUFFER) | 1463 | else if (resp_buf_type == CIFS_LARGE_BUFFER) |
1374 | cifs_buf_release(iov[0].iov_base); | 1464 | cifs_buf_release(iov[0].iov_base); |
1375 | } else if(resp_buf_type != CIFS_NO_BUFFER) { | 1465 | } else if (resp_buf_type != CIFS_NO_BUFFER) { |
1376 | /* return buffer to caller to free */ | 1466 | /* return buffer to caller to free */ |
1377 | *buf = iov[0].iov_base; | 1467 | *buf = iov[0].iov_base; |
1378 | if(resp_buf_type == CIFS_SMALL_BUFFER) | 1468 | if (resp_buf_type == CIFS_SMALL_BUFFER) |
1379 | *pbuf_type = CIFS_SMALL_BUFFER; | 1469 | *pbuf_type = CIFS_SMALL_BUFFER; |
1380 | else if(resp_buf_type == CIFS_LARGE_BUFFER) | 1470 | else if (resp_buf_type == CIFS_LARGE_BUFFER) |
1381 | *pbuf_type = CIFS_LARGE_BUFFER; | 1471 | *pbuf_type = CIFS_LARGE_BUFFER; |
1382 | } /* else no valid buffer on return - leave as null */ | 1472 | } /* else no valid buffer on return - leave as null */ |
1383 | 1473 | ||
@@ -1391,7 +1481,7 @@ int | |||
1391 | CIFSSMBWrite(const int xid, struct cifsTconInfo *tcon, | 1481 | CIFSSMBWrite(const int xid, struct cifsTconInfo *tcon, |
1392 | const int netfid, const unsigned int count, | 1482 | const int netfid, const unsigned int count, |
1393 | const __u64 offset, unsigned int *nbytes, const char *buf, | 1483 | const __u64 offset, unsigned int *nbytes, const char *buf, |
1394 | const char __user * ubuf, const int long_op) | 1484 | const char __user *ubuf, const int long_op) |
1395 | { | 1485 | { |
1396 | int rc = -EACCES; | 1486 | int rc = -EACCES; |
1397 | WRITE_REQ *pSMB = NULL; | 1487 | WRITE_REQ *pSMB = NULL; |
@@ -1401,10 +1491,10 @@ CIFSSMBWrite(const int xid, struct cifsTconInfo *tcon, | |||
1401 | __u16 byte_count; | 1491 | __u16 byte_count; |
1402 | 1492 | ||
1403 | /* cFYI(1,("write at %lld %d bytes",offset,count));*/ | 1493 | /* cFYI(1,("write at %lld %d bytes",offset,count));*/ |
1404 | if(tcon->ses == NULL) | 1494 | if (tcon->ses == NULL) |
1405 | return -ECONNABORTED; | 1495 | return -ECONNABORTED; |
1406 | 1496 | ||
1407 | if(tcon->ses->capabilities & CAP_LARGE_FILES) | 1497 | if (tcon->ses->capabilities & CAP_LARGE_FILES) |
1408 | wct = 14; | 1498 | wct = 14; |
1409 | else | 1499 | else |
1410 | wct = 12; | 1500 | wct = 12; |
@@ -1420,20 +1510,20 @@ CIFSSMBWrite(const int xid, struct cifsTconInfo *tcon, | |||
1420 | pSMB->AndXCommand = 0xFF; /* none */ | 1510 | pSMB->AndXCommand = 0xFF; /* none */ |
1421 | pSMB->Fid = netfid; | 1511 | pSMB->Fid = netfid; |
1422 | pSMB->OffsetLow = cpu_to_le32(offset & 0xFFFFFFFF); | 1512 | pSMB->OffsetLow = cpu_to_le32(offset & 0xFFFFFFFF); |
1423 | if(wct == 14) | 1513 | if (wct == 14) |
1424 | pSMB->OffsetHigh = cpu_to_le32(offset >> 32); | 1514 | pSMB->OffsetHigh = cpu_to_le32(offset >> 32); |
1425 | else if((offset >> 32) > 0) /* can not handle this big offset for old */ | 1515 | else if ((offset >> 32) > 0) /* can not handle big offset for old srv */ |
1426 | return -EIO; | 1516 | return -EIO; |
1427 | 1517 | ||
1428 | pSMB->Reserved = 0xFFFFFFFF; | 1518 | pSMB->Reserved = 0xFFFFFFFF; |
1429 | pSMB->WriteMode = 0; | 1519 | pSMB->WriteMode = 0; |
1430 | pSMB->Remaining = 0; | 1520 | pSMB->Remaining = 0; |
1431 | 1521 | ||
1432 | /* Can increase buffer size if buffer is big enough in some cases - ie we | 1522 | /* Can increase buffer size if buffer is big enough in some cases ie we |
1433 | can send more if LARGE_WRITE_X capability returned by the server and if | 1523 | can send more if LARGE_WRITE_X capability returned by the server and if |
1434 | our buffer is big enough or if we convert to iovecs on socket writes | 1524 | our buffer is big enough or if we convert to iovecs on socket writes |
1435 | and eliminate the copy to the CIFS buffer */ | 1525 | and eliminate the copy to the CIFS buffer */ |
1436 | if(tcon->ses->capabilities & CAP_LARGE_WRITE_X) { | 1526 | if (tcon->ses->capabilities & CAP_LARGE_WRITE_X) { |
1437 | bytes_sent = min_t(const unsigned int, CIFSMaxBufSize, count); | 1527 | bytes_sent = min_t(const unsigned int, CIFSMaxBufSize, count); |
1438 | } else { | 1528 | } else { |
1439 | bytes_sent = (tcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE) | 1529 | bytes_sent = (tcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE) |
@@ -1443,11 +1533,11 @@ CIFSSMBWrite(const int xid, struct cifsTconInfo *tcon, | |||
1443 | if (bytes_sent > count) | 1533 | if (bytes_sent > count) |
1444 | bytes_sent = count; | 1534 | bytes_sent = count; |
1445 | pSMB->DataOffset = | 1535 | pSMB->DataOffset = |
1446 | cpu_to_le16(offsetof(struct smb_com_write_req,Data) - 4); | 1536 | cpu_to_le16(offsetof(struct smb_com_write_req, Data) - 4); |
1447 | if(buf) | 1537 | if (buf) |
1448 | memcpy(pSMB->Data,buf,bytes_sent); | 1538 | memcpy(pSMB->Data, buf, bytes_sent); |
1449 | else if(ubuf) { | 1539 | else if (ubuf) { |
1450 | if(copy_from_user(pSMB->Data,ubuf,bytes_sent)) { | 1540 | if (copy_from_user(pSMB->Data, ubuf, bytes_sent)) { |
1451 | cifs_buf_release(pSMB); | 1541 | cifs_buf_release(pSMB); |
1452 | return -EFAULT; | 1542 | return -EFAULT; |
1453 | } | 1543 | } |
@@ -1456,7 +1546,7 @@ CIFSSMBWrite(const int xid, struct cifsTconInfo *tcon, | |||
1456 | cifs_buf_release(pSMB); | 1546 | cifs_buf_release(pSMB); |
1457 | return -EINVAL; | 1547 | return -EINVAL; |
1458 | } /* else setting file size with write of zero bytes */ | 1548 | } /* else setting file size with write of zero bytes */ |
1459 | if(wct == 14) | 1549 | if (wct == 14) |
1460 | byte_count = bytes_sent + 1; /* pad */ | 1550 | byte_count = bytes_sent + 1; /* pad */ |
1461 | else /* wct == 12 */ { | 1551 | else /* wct == 12 */ { |
1462 | byte_count = bytes_sent + 5; /* bigger pad, smaller smb hdr */ | 1552 | byte_count = bytes_sent + 5; /* bigger pad, smaller smb hdr */ |
@@ -1465,10 +1555,11 @@ CIFSSMBWrite(const int xid, struct cifsTconInfo *tcon, | |||
1465 | pSMB->DataLengthHigh = cpu_to_le16(bytes_sent >> 16); | 1555 | pSMB->DataLengthHigh = cpu_to_le16(bytes_sent >> 16); |
1466 | pSMB->hdr.smb_buf_length += byte_count; | 1556 | pSMB->hdr.smb_buf_length += byte_count; |
1467 | 1557 | ||
1468 | if(wct == 14) | 1558 | if (wct == 14) |
1469 | pSMB->ByteCount = cpu_to_le16(byte_count); | 1559 | pSMB->ByteCount = cpu_to_le16(byte_count); |
1470 | else { /* old style write has byte count 4 bytes earlier so 4 bytes pad */ | 1560 | else { /* old style write has byte count 4 bytes earlier |
1471 | struct smb_com_writex_req * pSMBW = | 1561 | so 4 bytes pad */ |
1562 | struct smb_com_writex_req *pSMBW = | ||
1472 | (struct smb_com_writex_req *)pSMB; | 1563 | (struct smb_com_writex_req *)pSMB; |
1473 | pSMBW->ByteCount = cpu_to_le16(byte_count); | 1564 | pSMBW->ByteCount = cpu_to_le16(byte_count); |
1474 | } | 1565 | } |
@@ -1487,7 +1578,7 @@ CIFSSMBWrite(const int xid, struct cifsTconInfo *tcon, | |||
1487 | 1578 | ||
1488 | cifs_buf_release(pSMB); | 1579 | cifs_buf_release(pSMB); |
1489 | 1580 | ||
1490 | /* Note: On -EAGAIN error only caller can retry on handle based calls | 1581 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
1491 | since file handle passed in no longer valid */ | 1582 | since file handle passed in no longer valid */ |
1492 | 1583 | ||
1493 | return rc; | 1584 | return rc; |
@@ -1505,9 +1596,9 @@ CIFSSMBWrite2(const int xid, struct cifsTconInfo *tcon, | |||
1505 | int smb_hdr_len; | 1596 | int smb_hdr_len; |
1506 | int resp_buf_type = 0; | 1597 | int resp_buf_type = 0; |
1507 | 1598 | ||
1508 | cFYI(1,("write2 at %lld %d bytes", (long long)offset, count)); | 1599 | cFYI(1, ("write2 at %lld %d bytes", (long long)offset, count)); |
1509 | 1600 | ||
1510 | if(tcon->ses->capabilities & CAP_LARGE_FILES) | 1601 | if (tcon->ses->capabilities & CAP_LARGE_FILES) |
1511 | wct = 14; | 1602 | wct = 14; |
1512 | else | 1603 | else |
1513 | wct = 12; | 1604 | wct = 12; |
@@ -1521,37 +1612,37 @@ CIFSSMBWrite2(const int xid, struct cifsTconInfo *tcon, | |||
1521 | pSMB->AndXCommand = 0xFF; /* none */ | 1612 | pSMB->AndXCommand = 0xFF; /* none */ |
1522 | pSMB->Fid = netfid; | 1613 | pSMB->Fid = netfid; |
1523 | pSMB->OffsetLow = cpu_to_le32(offset & 0xFFFFFFFF); | 1614 | pSMB->OffsetLow = cpu_to_le32(offset & 0xFFFFFFFF); |
1524 | if(wct == 14) | 1615 | if (wct == 14) |
1525 | pSMB->OffsetHigh = cpu_to_le32(offset >> 32); | 1616 | pSMB->OffsetHigh = cpu_to_le32(offset >> 32); |
1526 | else if((offset >> 32) > 0) /* can not handle this big offset for old */ | 1617 | else if ((offset >> 32) > 0) /* can not handle big offset for old srv */ |
1527 | return -EIO; | 1618 | return -EIO; |
1528 | pSMB->Reserved = 0xFFFFFFFF; | 1619 | pSMB->Reserved = 0xFFFFFFFF; |
1529 | pSMB->WriteMode = 0; | 1620 | pSMB->WriteMode = 0; |
1530 | pSMB->Remaining = 0; | 1621 | pSMB->Remaining = 0; |
1531 | 1622 | ||
1532 | pSMB->DataOffset = | 1623 | pSMB->DataOffset = |
1533 | cpu_to_le16(offsetof(struct smb_com_write_req,Data) - 4); | 1624 | cpu_to_le16(offsetof(struct smb_com_write_req, Data) - 4); |
1534 | 1625 | ||
1535 | pSMB->DataLengthLow = cpu_to_le16(count & 0xFFFF); | 1626 | pSMB->DataLengthLow = cpu_to_le16(count & 0xFFFF); |
1536 | pSMB->DataLengthHigh = cpu_to_le16(count >> 16); | 1627 | pSMB->DataLengthHigh = cpu_to_le16(count >> 16); |
1537 | smb_hdr_len = pSMB->hdr.smb_buf_length + 1; /* hdr + 1 byte pad */ | 1628 | smb_hdr_len = pSMB->hdr.smb_buf_length + 1; /* hdr + 1 byte pad */ |
1538 | if(wct == 14) | 1629 | if (wct == 14) |
1539 | pSMB->hdr.smb_buf_length += count+1; | 1630 | pSMB->hdr.smb_buf_length += count+1; |
1540 | else /* wct == 12 */ | 1631 | else /* wct == 12 */ |
1541 | pSMB->hdr.smb_buf_length += count+5; /* smb data starts later */ | 1632 | pSMB->hdr.smb_buf_length += count+5; /* smb data starts later */ |
1542 | if(wct == 14) | 1633 | if (wct == 14) |
1543 | pSMB->ByteCount = cpu_to_le16(count + 1); | 1634 | pSMB->ByteCount = cpu_to_le16(count + 1); |
1544 | else /* wct == 12 */ /* bigger pad, smaller smb hdr, keep offset ok */ { | 1635 | else /* wct == 12 */ /* bigger pad, smaller smb hdr, keep offset ok */ { |
1545 | struct smb_com_writex_req * pSMBW = | 1636 | struct smb_com_writex_req *pSMBW = |
1546 | (struct smb_com_writex_req *)pSMB; | 1637 | (struct smb_com_writex_req *)pSMB; |
1547 | pSMBW->ByteCount = cpu_to_le16(count + 5); | 1638 | pSMBW->ByteCount = cpu_to_le16(count + 5); |
1548 | } | 1639 | } |
1549 | iov[0].iov_base = pSMB; | 1640 | iov[0].iov_base = pSMB; |
1550 | if(wct == 14) | 1641 | if (wct == 14) |
1551 | iov[0].iov_len = smb_hdr_len + 4; | 1642 | iov[0].iov_len = smb_hdr_len + 4; |
1552 | else /* wct == 12 pad bigger by four bytes */ | 1643 | else /* wct == 12 pad bigger by four bytes */ |
1553 | iov[0].iov_len = smb_hdr_len + 8; | 1644 | iov[0].iov_len = smb_hdr_len + 8; |
1554 | 1645 | ||
1555 | 1646 | ||
1556 | rc = SendReceive2(xid, tcon->ses, iov, n_vec + 1, &resp_buf_type, | 1647 | rc = SendReceive2(xid, tcon->ses, iov, n_vec + 1, &resp_buf_type, |
1557 | long_op); | 1648 | long_op); |
@@ -1559,7 +1650,7 @@ CIFSSMBWrite2(const int xid, struct cifsTconInfo *tcon, | |||
1559 | if (rc) { | 1650 | if (rc) { |
1560 | cFYI(1, ("Send error Write2 = %d", rc)); | 1651 | cFYI(1, ("Send error Write2 = %d", rc)); |
1561 | *nbytes = 0; | 1652 | *nbytes = 0; |
1562 | } else if(resp_buf_type == 0) { | 1653 | } else if (resp_buf_type == 0) { |
1563 | /* presumably this can not happen, but best to be safe */ | 1654 | /* presumably this can not happen, but best to be safe */ |
1564 | rc = -EIO; | 1655 | rc = -EIO; |
1565 | *nbytes = 0; | 1656 | *nbytes = 0; |
@@ -1568,15 +1659,15 @@ CIFSSMBWrite2(const int xid, struct cifsTconInfo *tcon, | |||
1568 | *nbytes = le16_to_cpu(pSMBr->CountHigh); | 1659 | *nbytes = le16_to_cpu(pSMBr->CountHigh); |
1569 | *nbytes = (*nbytes) << 16; | 1660 | *nbytes = (*nbytes) << 16; |
1570 | *nbytes += le16_to_cpu(pSMBr->Count); | 1661 | *nbytes += le16_to_cpu(pSMBr->Count); |
1571 | } | 1662 | } |
1572 | 1663 | ||
1573 | /* cifs_small_buf_release(pSMB); */ /* Freed earlier now in SendReceive2 */ | 1664 | /* cifs_small_buf_release(pSMB); */ /* Freed earlier now in SendReceive2 */ |
1574 | if(resp_buf_type == CIFS_SMALL_BUFFER) | 1665 | if (resp_buf_type == CIFS_SMALL_BUFFER) |
1575 | cifs_small_buf_release(iov[0].iov_base); | 1666 | cifs_small_buf_release(iov[0].iov_base); |
1576 | else if(resp_buf_type == CIFS_LARGE_BUFFER) | 1667 | else if (resp_buf_type == CIFS_LARGE_BUFFER) |
1577 | cifs_buf_release(iov[0].iov_base); | 1668 | cifs_buf_release(iov[0].iov_base); |
1578 | 1669 | ||
1579 | /* Note: On -EAGAIN error only caller can retry on handle based calls | 1670 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
1580 | since file handle passed in no longer valid */ | 1671 | since file handle passed in no longer valid */ |
1581 | 1672 | ||
1582 | return rc; | 1673 | return rc; |
@@ -1596,7 +1687,7 @@ CIFSSMBLock(const int xid, struct cifsTconInfo *tcon, | |||
1596 | int timeout = 0; | 1687 | int timeout = 0; |
1597 | __u16 count; | 1688 | __u16 count; |
1598 | 1689 | ||
1599 | cFYI(1, ("In CIFSSMBLock - timeout %d numLock %d",waitFlag,numLock)); | 1690 | cFYI(1, ("In CIFSSMBLock - timeout %d numLock %d", waitFlag, numLock)); |
1600 | rc = small_smb_init(SMB_COM_LOCKING_ANDX, 8, tcon, (void **) &pSMB); | 1691 | rc = small_smb_init(SMB_COM_LOCKING_ANDX, 8, tcon, (void **) &pSMB); |
1601 | 1692 | ||
1602 | if (rc) | 1693 | if (rc) |
@@ -1604,7 +1695,7 @@ CIFSSMBLock(const int xid, struct cifsTconInfo *tcon, | |||
1604 | 1695 | ||
1605 | pSMBr = (LOCK_RSP *)pSMB; /* BB removeme BB */ | 1696 | pSMBr = (LOCK_RSP *)pSMB; /* BB removeme BB */ |
1606 | 1697 | ||
1607 | if(lockType == LOCKING_ANDX_OPLOCK_RELEASE) { | 1698 | if (lockType == LOCKING_ANDX_OPLOCK_RELEASE) { |
1608 | timeout = -1; /* no response expected */ | 1699 | timeout = -1; /* no response expected */ |
1609 | pSMB->Timeout = 0; | 1700 | pSMB->Timeout = 0; |
1610 | } else if (waitFlag == TRUE) { | 1701 | } else if (waitFlag == TRUE) { |
@@ -1620,7 +1711,7 @@ CIFSSMBLock(const int xid, struct cifsTconInfo *tcon, | |||
1620 | pSMB->AndXCommand = 0xFF; /* none */ | 1711 | pSMB->AndXCommand = 0xFF; /* none */ |
1621 | pSMB->Fid = smb_file_id; /* netfid stays le */ | 1712 | pSMB->Fid = smb_file_id; /* netfid stays le */ |
1622 | 1713 | ||
1623 | if((numLock != 0) || (numUnlock != 0)) { | 1714 | if ((numLock != 0) || (numUnlock != 0)) { |
1624 | pSMB->Locks[0].Pid = cpu_to_le16(current->tgid); | 1715 | pSMB->Locks[0].Pid = cpu_to_le16(current->tgid); |
1625 | /* BB where to store pid high? */ | 1716 | /* BB where to store pid high? */ |
1626 | pSMB->Locks[0].LengthLow = cpu_to_le32((u32)len); | 1717 | pSMB->Locks[0].LengthLow = cpu_to_le32((u32)len); |
@@ -1648,7 +1739,7 @@ CIFSSMBLock(const int xid, struct cifsTconInfo *tcon, | |||
1648 | } | 1739 | } |
1649 | cifs_small_buf_release(pSMB); | 1740 | cifs_small_buf_release(pSMB); |
1650 | 1741 | ||
1651 | /* Note: On -EAGAIN error only caller can retry on handle based calls | 1742 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
1652 | since file handle passed in no longer valid */ | 1743 | since file handle passed in no longer valid */ |
1653 | return rc; | 1744 | return rc; |
1654 | } | 1745 | } |
@@ -1656,12 +1747,11 @@ CIFSSMBLock(const int xid, struct cifsTconInfo *tcon, | |||
1656 | int | 1747 | int |
1657 | CIFSSMBPosixLock(const int xid, struct cifsTconInfo *tcon, | 1748 | CIFSSMBPosixLock(const int xid, struct cifsTconInfo *tcon, |
1658 | const __u16 smb_file_id, const int get_flag, const __u64 len, | 1749 | const __u16 smb_file_id, const int get_flag, const __u64 len, |
1659 | struct file_lock *pLockData, const __u16 lock_type, | 1750 | struct file_lock *pLockData, const __u16 lock_type, |
1660 | const int waitFlag) | 1751 | const int waitFlag) |
1661 | { | 1752 | { |
1662 | struct smb_com_transaction2_sfi_req *pSMB = NULL; | 1753 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
1663 | struct smb_com_transaction2_sfi_rsp *pSMBr = NULL; | 1754 | struct smb_com_transaction2_sfi_rsp *pSMBr = NULL; |
1664 | char *data_offset; | ||
1665 | struct cifs_posix_lock *parm_data; | 1755 | struct cifs_posix_lock *parm_data; |
1666 | int rc = 0; | 1756 | int rc = 0; |
1667 | int timeout = 0; | 1757 | int timeout = 0; |
@@ -1670,7 +1760,7 @@ CIFSSMBPosixLock(const int xid, struct cifsTconInfo *tcon, | |||
1670 | 1760 | ||
1671 | cFYI(1, ("Posix Lock")); | 1761 | cFYI(1, ("Posix Lock")); |
1672 | 1762 | ||
1673 | if(pLockData == NULL) | 1763 | if (pLockData == NULL) |
1674 | return EINVAL; | 1764 | return EINVAL; |
1675 | 1765 | ||
1676 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); | 1766 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); |
@@ -1680,7 +1770,7 @@ CIFSSMBPosixLock(const int xid, struct cifsTconInfo *tcon, | |||
1680 | 1770 | ||
1681 | pSMBr = (struct smb_com_transaction2_sfi_rsp *)pSMB; | 1771 | pSMBr = (struct smb_com_transaction2_sfi_rsp *)pSMB; |
1682 | 1772 | ||
1683 | params = 6; | 1773 | params = 6; |
1684 | pSMB->MaxSetupCount = 0; | 1774 | pSMB->MaxSetupCount = 0; |
1685 | pSMB->Reserved = 0; | 1775 | pSMB->Reserved = 0; |
1686 | pSMB->Flags = 0; | 1776 | pSMB->Flags = 0; |
@@ -1688,14 +1778,12 @@ CIFSSMBPosixLock(const int xid, struct cifsTconInfo *tcon, | |||
1688 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; | 1778 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
1689 | offset = param_offset + params; | 1779 | offset = param_offset + params; |
1690 | 1780 | ||
1691 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; | ||
1692 | |||
1693 | count = sizeof(struct cifs_posix_lock); | 1781 | count = sizeof(struct cifs_posix_lock); |
1694 | pSMB->MaxParameterCount = cpu_to_le16(2); | 1782 | pSMB->MaxParameterCount = cpu_to_le16(2); |
1695 | pSMB->MaxDataCount = cpu_to_le16(1000); /* BB find max SMB PDU from sess */ | 1783 | pSMB->MaxDataCount = cpu_to_le16(1000); /* BB find max SMB PDU from sess */ |
1696 | pSMB->SetupCount = 1; | 1784 | pSMB->SetupCount = 1; |
1697 | pSMB->Reserved3 = 0; | 1785 | pSMB->Reserved3 = 0; |
1698 | if(get_flag) | 1786 | if (get_flag) |
1699 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION); | 1787 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION); |
1700 | else | 1788 | else |
1701 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); | 1789 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
@@ -1705,11 +1793,11 @@ CIFSSMBPosixLock(const int xid, struct cifsTconInfo *tcon, | |||
1705 | pSMB->TotalDataCount = pSMB->DataCount; | 1793 | pSMB->TotalDataCount = pSMB->DataCount; |
1706 | pSMB->TotalParameterCount = pSMB->ParameterCount; | 1794 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
1707 | pSMB->ParameterOffset = cpu_to_le16(param_offset); | 1795 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
1708 | parm_data = (struct cifs_posix_lock *) | 1796 | parm_data = (struct cifs_posix_lock *) |
1709 | (((char *) &pSMB->hdr.Protocol) + offset); | 1797 | (((char *) &pSMB->hdr.Protocol) + offset); |
1710 | 1798 | ||
1711 | parm_data->lock_type = cpu_to_le16(lock_type); | 1799 | parm_data->lock_type = cpu_to_le16(lock_type); |
1712 | if(waitFlag) { | 1800 | if (waitFlag) { |
1713 | timeout = 3; /* blocking operation, no timeout */ | 1801 | timeout = 3; /* blocking operation, no timeout */ |
1714 | parm_data->lock_flags = cpu_to_le16(1); | 1802 | parm_data->lock_flags = cpu_to_le16(1); |
1715 | pSMB->Timeout = cpu_to_le32(-1); | 1803 | pSMB->Timeout = cpu_to_le32(-1); |
@@ -1746,22 +1834,22 @@ CIFSSMBPosixLock(const int xid, struct cifsTconInfo *tcon, | |||
1746 | rc = -EIO; /* bad smb */ | 1834 | rc = -EIO; /* bad smb */ |
1747 | goto plk_err_exit; | 1835 | goto plk_err_exit; |
1748 | } | 1836 | } |
1749 | if(pLockData == NULL) { | 1837 | if (pLockData == NULL) { |
1750 | rc = -EINVAL; | 1838 | rc = -EINVAL; |
1751 | goto plk_err_exit; | 1839 | goto plk_err_exit; |
1752 | } | 1840 | } |
1753 | data_offset = le16_to_cpu(pSMBr->t2.DataOffset); | 1841 | data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
1754 | data_count = le16_to_cpu(pSMBr->t2.DataCount); | 1842 | data_count = le16_to_cpu(pSMBr->t2.DataCount); |
1755 | if(data_count < sizeof(struct cifs_posix_lock)) { | 1843 | if (data_count < sizeof(struct cifs_posix_lock)) { |
1756 | rc = -EIO; | 1844 | rc = -EIO; |
1757 | goto plk_err_exit; | 1845 | goto plk_err_exit; |
1758 | } | 1846 | } |
1759 | parm_data = (struct cifs_posix_lock *) | 1847 | parm_data = (struct cifs_posix_lock *) |
1760 | ((char *)&pSMBr->hdr.Protocol + data_offset); | 1848 | ((char *)&pSMBr->hdr.Protocol + data_offset); |
1761 | if(parm_data->lock_type == cpu_to_le16(CIFS_UNLCK)) | 1849 | if (parm_data->lock_type == cpu_to_le16(CIFS_UNLCK)) |
1762 | pLockData->fl_type = F_UNLCK; | 1850 | pLockData->fl_type = F_UNLCK; |
1763 | } | 1851 | } |
1764 | 1852 | ||
1765 | plk_err_exit: | 1853 | plk_err_exit: |
1766 | if (pSMB) | 1854 | if (pSMB) |
1767 | cifs_small_buf_release(pSMB); | 1855 | cifs_small_buf_release(pSMB); |
@@ -1784,7 +1872,7 @@ CIFSSMBClose(const int xid, struct cifsTconInfo *tcon, int smb_file_id) | |||
1784 | 1872 | ||
1785 | /* do not retry on dead session on close */ | 1873 | /* do not retry on dead session on close */ |
1786 | rc = small_smb_init(SMB_COM_CLOSE, 3, tcon, (void **) &pSMB); | 1874 | rc = small_smb_init(SMB_COM_CLOSE, 3, tcon, (void **) &pSMB); |
1787 | if(rc == -EAGAIN) | 1875 | if (rc == -EAGAIN) |
1788 | return 0; | 1876 | return 0; |
1789 | if (rc) | 1877 | if (rc) |
1790 | return rc; | 1878 | return rc; |
@@ -1798,7 +1886,7 @@ CIFSSMBClose(const int xid, struct cifsTconInfo *tcon, int smb_file_id) | |||
1798 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); | 1886 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
1799 | cifs_stats_inc(&tcon->num_closes); | 1887 | cifs_stats_inc(&tcon->num_closes); |
1800 | if (rc) { | 1888 | if (rc) { |
1801 | if(rc!=-EINTR) { | 1889 | if (rc != -EINTR) { |
1802 | /* EINTR is expected when user ctl-c to kill app */ | 1890 | /* EINTR is expected when user ctl-c to kill app */ |
1803 | cERROR(1, ("Send error in Close = %d", rc)); | 1891 | cERROR(1, ("Send error in Close = %d", rc)); |
1804 | } | 1892 | } |
@@ -1807,7 +1895,7 @@ CIFSSMBClose(const int xid, struct cifsTconInfo *tcon, int smb_file_id) | |||
1807 | cifs_small_buf_release(pSMB); | 1895 | cifs_small_buf_release(pSMB); |
1808 | 1896 | ||
1809 | /* Since session is dead, file will be closed on server already */ | 1897 | /* Since session is dead, file will be closed on server already */ |
1810 | if(rc == -EAGAIN) | 1898 | if (rc == -EAGAIN) |
1811 | rc = 0; | 1899 | rc = 0; |
1812 | 1900 | ||
1813 | return rc; | 1901 | return rc; |
@@ -1839,7 +1927,7 @@ renameRetry: | |||
1839 | 1927 | ||
1840 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { | 1928 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
1841 | name_len = | 1929 | name_len = |
1842 | cifsConvertToUCS((__le16 *) pSMB->OldFileName, fromName, | 1930 | cifsConvertToUCS((__le16 *) pSMB->OldFileName, fromName, |
1843 | PATH_MAX, nls_codepage, remap); | 1931 | PATH_MAX, nls_codepage, remap); |
1844 | name_len++; /* trailing null */ | 1932 | name_len++; /* trailing null */ |
1845 | name_len *= 2; | 1933 | name_len *= 2; |
@@ -1851,7 +1939,7 @@ renameRetry: | |||
1851 | toName, PATH_MAX, nls_codepage, remap); | 1939 | toName, PATH_MAX, nls_codepage, remap); |
1852 | name_len2 += 1 /* trailing null */ + 1 /* Signature word */ ; | 1940 | name_len2 += 1 /* trailing null */ + 1 /* Signature word */ ; |
1853 | name_len2 *= 2; /* convert to bytes */ | 1941 | name_len2 *= 2; /* convert to bytes */ |
1854 | } else { /* BB improve the check for buffer overruns BB */ | 1942 | } else { /* BB improve the check for buffer overruns BB */ |
1855 | name_len = strnlen(fromName, PATH_MAX); | 1943 | name_len = strnlen(fromName, PATH_MAX); |
1856 | name_len++; /* trailing null */ | 1944 | name_len++; /* trailing null */ |
1857 | strncpy(pSMB->OldFileName, fromName, name_len); | 1945 | strncpy(pSMB->OldFileName, fromName, name_len); |
@@ -1872,7 +1960,7 @@ renameRetry: | |||
1872 | cifs_stats_inc(&tcon->num_renames); | 1960 | cifs_stats_inc(&tcon->num_renames); |
1873 | if (rc) { | 1961 | if (rc) { |
1874 | cFYI(1, ("Send error in rename = %d", rc)); | 1962 | cFYI(1, ("Send error in rename = %d", rc)); |
1875 | } | 1963 | } |
1876 | 1964 | ||
1877 | cifs_buf_release(pSMB); | 1965 | cifs_buf_release(pSMB); |
1878 | 1966 | ||
@@ -1882,13 +1970,13 @@ renameRetry: | |||
1882 | return rc; | 1970 | return rc; |
1883 | } | 1971 | } |
1884 | 1972 | ||
1885 | int CIFSSMBRenameOpenFile(const int xid,struct cifsTconInfo *pTcon, | 1973 | int CIFSSMBRenameOpenFile(const int xid, struct cifsTconInfo *pTcon, |
1886 | int netfid, char * target_name, | 1974 | int netfid, char *target_name, |
1887 | const struct nls_table * nls_codepage, int remap) | 1975 | const struct nls_table *nls_codepage, int remap) |
1888 | { | 1976 | { |
1889 | struct smb_com_transaction2_sfi_req *pSMB = NULL; | 1977 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
1890 | struct smb_com_transaction2_sfi_rsp *pSMBr = NULL; | 1978 | struct smb_com_transaction2_sfi_rsp *pSMBr = NULL; |
1891 | struct set_file_rename * rename_info; | 1979 | struct set_file_rename *rename_info; |
1892 | char *data_offset; | 1980 | char *data_offset; |
1893 | char dummy_string[30]; | 1981 | char dummy_string[30]; |
1894 | int rc = 0; | 1982 | int rc = 0; |
@@ -1927,13 +2015,14 @@ int CIFSSMBRenameOpenFile(const int xid,struct cifsTconInfo *pTcon, | |||
1927 | rename_info->overwrite = cpu_to_le32(1); | 2015 | rename_info->overwrite = cpu_to_le32(1); |
1928 | rename_info->root_fid = 0; | 2016 | rename_info->root_fid = 0; |
1929 | /* unicode only call */ | 2017 | /* unicode only call */ |
1930 | if(target_name == NULL) { | 2018 | if (target_name == NULL) { |
1931 | sprintf(dummy_string,"cifs%x",pSMB->hdr.Mid); | 2019 | sprintf(dummy_string, "cifs%x", pSMB->hdr.Mid); |
1932 | len_of_str = cifsConvertToUCS((__le16 *)rename_info->target_name, | 2020 | len_of_str = cifsConvertToUCS((__le16 *)rename_info->target_name, |
1933 | dummy_string, 24, nls_codepage, remap); | 2021 | dummy_string, 24, nls_codepage, remap); |
1934 | } else { | 2022 | } else { |
1935 | len_of_str = cifsConvertToUCS((__le16 *)rename_info->target_name, | 2023 | len_of_str = cifsConvertToUCS((__le16 *)rename_info->target_name, |
1936 | target_name, PATH_MAX, nls_codepage, remap); | 2024 | target_name, PATH_MAX, nls_codepage, |
2025 | remap); | ||
1937 | } | 2026 | } |
1938 | rename_info->target_name_len = cpu_to_le32(2 * len_of_str); | 2027 | rename_info->target_name_len = cpu_to_le32(2 * len_of_str); |
1939 | count = 12 /* sizeof(struct set_file_rename) */ + (2 * len_of_str) + 2; | 2028 | count = 12 /* sizeof(struct set_file_rename) */ + (2 * len_of_str) + 2; |
@@ -1947,10 +2036,10 @@ int CIFSSMBRenameOpenFile(const int xid,struct cifsTconInfo *pTcon, | |||
1947 | pSMB->hdr.smb_buf_length += byte_count; | 2036 | pSMB->hdr.smb_buf_length += byte_count; |
1948 | pSMB->ByteCount = cpu_to_le16(byte_count); | 2037 | pSMB->ByteCount = cpu_to_le16(byte_count); |
1949 | rc = SendReceive(xid, pTcon->ses, (struct smb_hdr *) pSMB, | 2038 | rc = SendReceive(xid, pTcon->ses, (struct smb_hdr *) pSMB, |
1950 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); | 2039 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
1951 | cifs_stats_inc(&pTcon->num_t2renames); | 2040 | cifs_stats_inc(&pTcon->num_t2renames); |
1952 | if (rc) { | 2041 | if (rc) { |
1953 | cFYI(1,("Send error in Rename (by file handle) = %d", rc)); | 2042 | cFYI(1, ("Send error in Rename (by file handle) = %d", rc)); |
1954 | } | 2043 | } |
1955 | 2044 | ||
1956 | cifs_buf_release(pSMB); | 2045 | cifs_buf_release(pSMB); |
@@ -1962,9 +2051,9 @@ int CIFSSMBRenameOpenFile(const int xid,struct cifsTconInfo *pTcon, | |||
1962 | } | 2051 | } |
1963 | 2052 | ||
1964 | int | 2053 | int |
1965 | CIFSSMBCopy(const int xid, struct cifsTconInfo *tcon, const char * fromName, | 2054 | CIFSSMBCopy(const int xid, struct cifsTconInfo *tcon, const char *fromName, |
1966 | const __u16 target_tid, const char *toName, const int flags, | 2055 | const __u16 target_tid, const char *toName, const int flags, |
1967 | const struct nls_table *nls_codepage, int remap) | 2056 | const struct nls_table *nls_codepage, int remap) |
1968 | { | 2057 | { |
1969 | int rc = 0; | 2058 | int rc = 0; |
1970 | COPY_REQ *pSMB = NULL; | 2059 | COPY_REQ *pSMB = NULL; |
@@ -1986,7 +2075,7 @@ copyRetry: | |||
1986 | pSMB->Flags = cpu_to_le16(flags & COPY_TREE); | 2075 | pSMB->Flags = cpu_to_le16(flags & COPY_TREE); |
1987 | 2076 | ||
1988 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { | 2077 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
1989 | name_len = cifsConvertToUCS((__le16 *) pSMB->OldFileName, | 2078 | name_len = cifsConvertToUCS((__le16 *) pSMB->OldFileName, |
1990 | fromName, PATH_MAX, nls_codepage, | 2079 | fromName, PATH_MAX, nls_codepage, |
1991 | remap); | 2080 | remap); |
1992 | name_len++; /* trailing null */ | 2081 | name_len++; /* trailing null */ |
@@ -1994,11 +2083,12 @@ copyRetry: | |||
1994 | pSMB->OldFileName[name_len] = 0x04; /* pad */ | 2083 | pSMB->OldFileName[name_len] = 0x04; /* pad */ |
1995 | /* protocol requires ASCII signature byte on Unicode string */ | 2084 | /* protocol requires ASCII signature byte on Unicode string */ |
1996 | pSMB->OldFileName[name_len + 1] = 0x00; | 2085 | pSMB->OldFileName[name_len + 1] = 0x00; |
1997 | name_len2 = cifsConvertToUCS((__le16 *)&pSMB->OldFileName[name_len + 2], | 2086 | name_len2 = |
2087 | cifsConvertToUCS((__le16 *)&pSMB->OldFileName[name_len + 2], | ||
1998 | toName, PATH_MAX, nls_codepage, remap); | 2088 | toName, PATH_MAX, nls_codepage, remap); |
1999 | name_len2 += 1 /* trailing null */ + 1 /* Signature word */ ; | 2089 | name_len2 += 1 /* trailing null */ + 1 /* Signature word */ ; |
2000 | name_len2 *= 2; /* convert to bytes */ | 2090 | name_len2 *= 2; /* convert to bytes */ |
2001 | } else { /* BB improve the check for buffer overruns BB */ | 2091 | } else { /* BB improve the check for buffer overruns BB */ |
2002 | name_len = strnlen(fromName, PATH_MAX); | 2092 | name_len = strnlen(fromName, PATH_MAX); |
2003 | name_len++; /* trailing null */ | 2093 | name_len++; /* trailing null */ |
2004 | strncpy(pSMB->OldFileName, fromName, name_len); | 2094 | strncpy(pSMB->OldFileName, fromName, name_len); |
@@ -2058,7 +2148,7 @@ createSymLinkRetry: | |||
2058 | name_len++; /* trailing null */ | 2148 | name_len++; /* trailing null */ |
2059 | name_len *= 2; | 2149 | name_len *= 2; |
2060 | 2150 | ||
2061 | } else { /* BB improve the check for buffer overruns BB */ | 2151 | } else { /* BB improve the check for buffer overruns BB */ |
2062 | name_len = strnlen(fromName, PATH_MAX); | 2152 | name_len = strnlen(fromName, PATH_MAX); |
2063 | name_len++; /* trailing null */ | 2153 | name_len++; /* trailing null */ |
2064 | strncpy(pSMB->FileName, fromName, name_len); | 2154 | strncpy(pSMB->FileName, fromName, name_len); |
@@ -2070,7 +2160,7 @@ createSymLinkRetry: | |||
2070 | pSMB->Timeout = 0; | 2160 | pSMB->Timeout = 0; |
2071 | pSMB->Reserved2 = 0; | 2161 | pSMB->Reserved2 = 0; |
2072 | param_offset = offsetof(struct smb_com_transaction2_spi_req, | 2162 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
2073 | InformationLevel) - 4; | 2163 | InformationLevel) - 4; |
2074 | offset = param_offset + params; | 2164 | offset = param_offset + params; |
2075 | 2165 | ||
2076 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; | 2166 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
@@ -2081,7 +2171,7 @@ createSymLinkRetry: | |||
2081 | , nls_codepage); | 2171 | , nls_codepage); |
2082 | name_len_target++; /* trailing null */ | 2172 | name_len_target++; /* trailing null */ |
2083 | name_len_target *= 2; | 2173 | name_len_target *= 2; |
2084 | } else { /* BB improve the check for buffer overruns BB */ | 2174 | } else { /* BB improve the check for buffer overruns BB */ |
2085 | name_len_target = strnlen(toName, PATH_MAX); | 2175 | name_len_target = strnlen(toName, PATH_MAX); |
2086 | name_len_target++; /* trailing null */ | 2176 | name_len_target++; /* trailing null */ |
2087 | strncpy(data_offset, toName, name_len_target); | 2177 | strncpy(data_offset, toName, name_len_target); |
@@ -2108,9 +2198,7 @@ createSymLinkRetry: | |||
2108 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); | 2198 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
2109 | cifs_stats_inc(&tcon->num_symlinks); | 2199 | cifs_stats_inc(&tcon->num_symlinks); |
2110 | if (rc) { | 2200 | if (rc) { |
2111 | cFYI(1, | 2201 | cFYI(1, ("Send error in SetPathInfo create symlink = %d", rc)); |
2112 | ("Send error in SetPathInfo (create symlink) = %d", | ||
2113 | rc)); | ||
2114 | } | 2202 | } |
2115 | 2203 | ||
2116 | if (pSMB) | 2204 | if (pSMB) |
@@ -2149,7 +2237,7 @@ createHardLinkRetry: | |||
2149 | name_len++; /* trailing null */ | 2237 | name_len++; /* trailing null */ |
2150 | name_len *= 2; | 2238 | name_len *= 2; |
2151 | 2239 | ||
2152 | } else { /* BB improve the check for buffer overruns BB */ | 2240 | } else { /* BB improve the check for buffer overruns BB */ |
2153 | name_len = strnlen(toName, PATH_MAX); | 2241 | name_len = strnlen(toName, PATH_MAX); |
2154 | name_len++; /* trailing null */ | 2242 | name_len++; /* trailing null */ |
2155 | strncpy(pSMB->FileName, toName, name_len); | 2243 | strncpy(pSMB->FileName, toName, name_len); |
@@ -2161,7 +2249,7 @@ createHardLinkRetry: | |||
2161 | pSMB->Timeout = 0; | 2249 | pSMB->Timeout = 0; |
2162 | pSMB->Reserved2 = 0; | 2250 | pSMB->Reserved2 = 0; |
2163 | param_offset = offsetof(struct smb_com_transaction2_spi_req, | 2251 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
2164 | InformationLevel) - 4; | 2252 | InformationLevel) - 4; |
2165 | offset = param_offset + params; | 2253 | offset = param_offset + params; |
2166 | 2254 | ||
2167 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; | 2255 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
@@ -2171,7 +2259,7 @@ createHardLinkRetry: | |||
2171 | nls_codepage, remap); | 2259 | nls_codepage, remap); |
2172 | name_len_target++; /* trailing null */ | 2260 | name_len_target++; /* trailing null */ |
2173 | name_len_target *= 2; | 2261 | name_len_target *= 2; |
2174 | } else { /* BB improve the check for buffer overruns BB */ | 2262 | } else { /* BB improve the check for buffer overruns BB */ |
2175 | name_len_target = strnlen(fromName, PATH_MAX); | 2263 | name_len_target = strnlen(fromName, PATH_MAX); |
2176 | name_len_target++; /* trailing null */ | 2264 | name_len_target++; /* trailing null */ |
2177 | strncpy(data_offset, fromName, name_len_target); | 2265 | strncpy(data_offset, fromName, name_len_target); |
@@ -2243,13 +2331,13 @@ winCreateHardLinkRetry: | |||
2243 | name_len++; /* trailing null */ | 2331 | name_len++; /* trailing null */ |
2244 | name_len *= 2; | 2332 | name_len *= 2; |
2245 | pSMB->OldFileName[name_len] = 0; /* pad */ | 2333 | pSMB->OldFileName[name_len] = 0; /* pad */ |
2246 | pSMB->OldFileName[name_len + 1] = 0x04; | 2334 | pSMB->OldFileName[name_len + 1] = 0x04; |
2247 | name_len2 = | 2335 | name_len2 = |
2248 | cifsConvertToUCS((__le16 *)&pSMB->OldFileName[name_len + 2], | 2336 | cifsConvertToUCS((__le16 *)&pSMB->OldFileName[name_len + 2], |
2249 | toName, PATH_MAX, nls_codepage, remap); | 2337 | toName, PATH_MAX, nls_codepage, remap); |
2250 | name_len2 += 1 /* trailing null */ + 1 /* Signature word */ ; | 2338 | name_len2 += 1 /* trailing null */ + 1 /* Signature word */ ; |
2251 | name_len2 *= 2; /* convert to bytes */ | 2339 | name_len2 *= 2; /* convert to bytes */ |
2252 | } else { /* BB improve the check for buffer overruns BB */ | 2340 | } else { /* BB improve the check for buffer overruns BB */ |
2253 | name_len = strnlen(fromName, PATH_MAX); | 2341 | name_len = strnlen(fromName, PATH_MAX); |
2254 | name_len++; /* trailing null */ | 2342 | name_len++; /* trailing null */ |
2255 | strncpy(pSMB->OldFileName, fromName, name_len); | 2343 | strncpy(pSMB->OldFileName, fromName, name_len); |
@@ -2302,12 +2390,11 @@ querySymLinkRetry: | |||
2302 | 2390 | ||
2303 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { | 2391 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
2304 | name_len = | 2392 | name_len = |
2305 | cifs_strtoUCS((__le16 *) pSMB->FileName, searchName, PATH_MAX | 2393 | cifs_strtoUCS((__le16 *) pSMB->FileName, searchName, |
2306 | /* find define for this maxpathcomponent */ | 2394 | PATH_MAX, nls_codepage); |
2307 | , nls_codepage); | ||
2308 | name_len++; /* trailing null */ | 2395 | name_len++; /* trailing null */ |
2309 | name_len *= 2; | 2396 | name_len *= 2; |
2310 | } else { /* BB improve the check for buffer overruns BB */ | 2397 | } else { /* BB improve the check for buffer overruns BB */ |
2311 | name_len = strnlen(searchName, PATH_MAX); | 2398 | name_len = strnlen(searchName, PATH_MAX); |
2312 | name_len++; /* trailing null */ | 2399 | name_len++; /* trailing null */ |
2313 | strncpy(pSMB->FileName, searchName, name_len); | 2400 | strncpy(pSMB->FileName, searchName, name_len); |
@@ -2324,7 +2411,7 @@ querySymLinkRetry: | |||
2324 | pSMB->Timeout = 0; | 2411 | pSMB->Timeout = 0; |
2325 | pSMB->Reserved2 = 0; | 2412 | pSMB->Reserved2 = 0; |
2326 | pSMB->ParameterOffset = cpu_to_le16(offsetof( | 2413 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
2327 | struct smb_com_transaction2_qpi_req ,InformationLevel) - 4); | 2414 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
2328 | pSMB->DataCount = 0; | 2415 | pSMB->DataCount = 0; |
2329 | pSMB->DataOffset = 0; | 2416 | pSMB->DataOffset = 0; |
2330 | pSMB->SetupCount = 1; | 2417 | pSMB->SetupCount = 1; |
@@ -2355,16 +2442,16 @@ querySymLinkRetry: | |||
2355 | 2442 | ||
2356 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) { | 2443 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) { |
2357 | name_len = UniStrnlen((wchar_t *) ((char *) | 2444 | name_len = UniStrnlen((wchar_t *) ((char *) |
2358 | &pSMBr->hdr.Protocol +data_offset), | 2445 | &pSMBr->hdr.Protocol + data_offset), |
2359 | min_t(const int, buflen,count) / 2); | 2446 | min_t(const int, buflen, count) / 2); |
2360 | /* BB FIXME investigate remapping reserved chars here */ | 2447 | /* BB FIXME investigate remapping reserved chars here */ |
2361 | cifs_strfromUCS_le(symlinkinfo, | 2448 | cifs_strfromUCS_le(symlinkinfo, |
2362 | (__le16 *) ((char *)&pSMBr->hdr.Protocol + | 2449 | (__le16 *) ((char *)&pSMBr->hdr.Protocol |
2363 | data_offset), | 2450 | + data_offset), |
2364 | name_len, nls_codepage); | 2451 | name_len, nls_codepage); |
2365 | } else { | 2452 | } else { |
2366 | strncpy(symlinkinfo, | 2453 | strncpy(symlinkinfo, |
2367 | (char *) &pSMBr->hdr.Protocol + | 2454 | (char *) &pSMBr->hdr.Protocol + |
2368 | data_offset, | 2455 | data_offset, |
2369 | min_t(const int, buflen, count)); | 2456 | min_t(const int, buflen, count)); |
2370 | } | 2457 | } |
@@ -2385,14 +2472,14 @@ querySymLinkRetry: | |||
2385 | Setup words themselves and ByteCount | 2472 | Setup words themselves and ByteCount |
2386 | MaxSetupCount (size of returned setup area) and | 2473 | MaxSetupCount (size of returned setup area) and |
2387 | MaxParameterCount (returned parms size) must be set by caller */ | 2474 | MaxParameterCount (returned parms size) must be set by caller */ |
2388 | static int | 2475 | static int |
2389 | smb_init_ntransact(const __u16 sub_command, const int setup_count, | 2476 | smb_init_ntransact(const __u16 sub_command, const int setup_count, |
2390 | const int parm_len, struct cifsTconInfo *tcon, | 2477 | const int parm_len, struct cifsTconInfo *tcon, |
2391 | void ** ret_buf) | 2478 | void **ret_buf) |
2392 | { | 2479 | { |
2393 | int rc; | 2480 | int rc; |
2394 | __u32 temp_offset; | 2481 | __u32 temp_offset; |
2395 | struct smb_com_ntransact_req * pSMB; | 2482 | struct smb_com_ntransact_req *pSMB; |
2396 | 2483 | ||
2397 | rc = small_smb_init(SMB_COM_NT_TRANSACT, 19 + setup_count, tcon, | 2484 | rc = small_smb_init(SMB_COM_NT_TRANSACT, 19 + setup_count, tcon, |
2398 | (void **)&pSMB); | 2485 | (void **)&pSMB); |
@@ -2416,47 +2503,47 @@ smb_init_ntransact(const __u16 sub_command, const int setup_count, | |||
2416 | } | 2503 | } |
2417 | 2504 | ||
2418 | static int | 2505 | static int |
2419 | validate_ntransact(char * buf, char ** ppparm, char ** ppdata, | 2506 | validate_ntransact(char *buf, char **ppparm, char **ppdata, |
2420 | int * pdatalen, int * pparmlen) | 2507 | int *pdatalen, int *pparmlen) |
2421 | { | 2508 | { |
2422 | char * end_of_smb; | 2509 | char *end_of_smb; |
2423 | __u32 data_count, data_offset, parm_count, parm_offset; | 2510 | __u32 data_count, data_offset, parm_count, parm_offset; |
2424 | struct smb_com_ntransact_rsp * pSMBr; | 2511 | struct smb_com_ntransact_rsp *pSMBr; |
2425 | 2512 | ||
2426 | if(buf == NULL) | 2513 | if (buf == NULL) |
2427 | return -EINVAL; | 2514 | return -EINVAL; |
2428 | 2515 | ||
2429 | pSMBr = (struct smb_com_ntransact_rsp *)buf; | 2516 | pSMBr = (struct smb_com_ntransact_rsp *)buf; |
2430 | 2517 | ||
2431 | /* ByteCount was converted from little endian in SendReceive */ | 2518 | /* ByteCount was converted from little endian in SendReceive */ |
2432 | end_of_smb = 2 /* sizeof byte count */ + pSMBr->ByteCount + | 2519 | end_of_smb = 2 /* sizeof byte count */ + pSMBr->ByteCount + |
2433 | (char *)&pSMBr->ByteCount; | 2520 | (char *)&pSMBr->ByteCount; |
2434 | 2521 | ||
2435 | |||
2436 | data_offset = le32_to_cpu(pSMBr->DataOffset); | 2522 | data_offset = le32_to_cpu(pSMBr->DataOffset); |
2437 | data_count = le32_to_cpu(pSMBr->DataCount); | 2523 | data_count = le32_to_cpu(pSMBr->DataCount); |
2438 | parm_offset = le32_to_cpu(pSMBr->ParameterOffset); | 2524 | parm_offset = le32_to_cpu(pSMBr->ParameterOffset); |
2439 | parm_count = le32_to_cpu(pSMBr->ParameterCount); | 2525 | parm_count = le32_to_cpu(pSMBr->ParameterCount); |
2440 | 2526 | ||
2441 | *ppparm = (char *)&pSMBr->hdr.Protocol + parm_offset; | 2527 | *ppparm = (char *)&pSMBr->hdr.Protocol + parm_offset; |
2442 | *ppdata = (char *)&pSMBr->hdr.Protocol + data_offset; | 2528 | *ppdata = (char *)&pSMBr->hdr.Protocol + data_offset; |
2443 | 2529 | ||
2444 | /* should we also check that parm and data areas do not overlap? */ | 2530 | /* should we also check that parm and data areas do not overlap? */ |
2445 | if(*ppparm > end_of_smb) { | 2531 | if (*ppparm > end_of_smb) { |
2446 | cFYI(1,("parms start after end of smb")); | 2532 | cFYI(1, ("parms start after end of smb")); |
2447 | return -EINVAL; | 2533 | return -EINVAL; |
2448 | } else if(parm_count + *ppparm > end_of_smb) { | 2534 | } else if (parm_count + *ppparm > end_of_smb) { |
2449 | cFYI(1,("parm end after end of smb")); | 2535 | cFYI(1, ("parm end after end of smb")); |
2450 | return -EINVAL; | 2536 | return -EINVAL; |
2451 | } else if(*ppdata > end_of_smb) { | 2537 | } else if (*ppdata > end_of_smb) { |
2452 | cFYI(1,("data starts after end of smb")); | 2538 | cFYI(1, ("data starts after end of smb")); |
2453 | return -EINVAL; | 2539 | return -EINVAL; |
2454 | } else if(data_count + *ppdata > end_of_smb) { | 2540 | } else if (data_count + *ppdata > end_of_smb) { |
2455 | cFYI(1,("data %p + count %d (%p) ends after end of smb %p start %p", | 2541 | cFYI(1,("data %p + count %d (%p) ends after end of smb %p start %p", |
2456 | *ppdata, data_count, (data_count + *ppdata), end_of_smb, pSMBr)); /* BB FIXME */ | 2542 | *ppdata, data_count, (data_count + *ppdata), |
2543 | end_of_smb, pSMBr)); | ||
2457 | return -EINVAL; | 2544 | return -EINVAL; |
2458 | } else if(parm_count + data_count > pSMBr->ByteCount) { | 2545 | } else if (parm_count + data_count > pSMBr->ByteCount) { |
2459 | cFYI(1,("parm count and data count larger than SMB")); | 2546 | cFYI(1, ("parm count and data count larger than SMB")); |
2460 | return -EINVAL; | 2547 | return -EINVAL; |
2461 | } | 2548 | } |
2462 | return 0; | 2549 | return 0; |
@@ -2465,14 +2552,14 @@ validate_ntransact(char * buf, char ** ppparm, char ** ppdata, | |||
2465 | int | 2552 | int |
2466 | CIFSSMBQueryReparseLinkInfo(const int xid, struct cifsTconInfo *tcon, | 2553 | CIFSSMBQueryReparseLinkInfo(const int xid, struct cifsTconInfo *tcon, |
2467 | const unsigned char *searchName, | 2554 | const unsigned char *searchName, |
2468 | char *symlinkinfo, const int buflen,__u16 fid, | 2555 | char *symlinkinfo, const int buflen, __u16 fid, |
2469 | const struct nls_table *nls_codepage) | 2556 | const struct nls_table *nls_codepage) |
2470 | { | 2557 | { |
2471 | int rc = 0; | 2558 | int rc = 0; |
2472 | int bytes_returned; | 2559 | int bytes_returned; |
2473 | int name_len; | 2560 | int name_len; |
2474 | struct smb_com_transaction_ioctl_req * pSMB; | 2561 | struct smb_com_transaction_ioctl_req *pSMB; |
2475 | struct smb_com_transaction_ioctl_rsp * pSMBr; | 2562 | struct smb_com_transaction_ioctl_rsp *pSMBr; |
2476 | 2563 | ||
2477 | cFYI(1, ("In Windows reparse style QueryLink for path %s", searchName)); | 2564 | cFYI(1, ("In Windows reparse style QueryLink for path %s", searchName)); |
2478 | rc = smb_init(SMB_COM_NT_TRANSACT, 23, tcon, (void **) &pSMB, | 2565 | rc = smb_init(SMB_COM_NT_TRANSACT, 23, tcon, (void **) &pSMB, |
@@ -2511,47 +2598,53 @@ CIFSSMBQueryReparseLinkInfo(const int xid, struct cifsTconInfo *tcon, | |||
2511 | /* BB also check enough total bytes returned */ | 2598 | /* BB also check enough total bytes returned */ |
2512 | rc = -EIO; /* bad smb */ | 2599 | rc = -EIO; /* bad smb */ |
2513 | else { | 2600 | else { |
2514 | if(data_count && (data_count < 2048)) { | 2601 | if (data_count && (data_count < 2048)) { |
2515 | char * end_of_smb = 2 /* sizeof byte count */ + | 2602 | char *end_of_smb = 2 /* sizeof byte count */ + |
2516 | pSMBr->ByteCount + | 2603 | pSMBr->ByteCount + |
2517 | (char *)&pSMBr->ByteCount; | 2604 | (char *)&pSMBr->ByteCount; |
2518 | 2605 | ||
2519 | struct reparse_data * reparse_buf = (struct reparse_data *) | 2606 | struct reparse_data *reparse_buf = |
2520 | ((char *)&pSMBr->hdr.Protocol + data_offset); | 2607 | (struct reparse_data *) |
2521 | if((char*)reparse_buf >= end_of_smb) { | 2608 | ((char *)&pSMBr->hdr.Protocol |
2609 | + data_offset); | ||
2610 | if ((char *)reparse_buf >= end_of_smb) { | ||
2522 | rc = -EIO; | 2611 | rc = -EIO; |
2523 | goto qreparse_out; | 2612 | goto qreparse_out; |
2524 | } | 2613 | } |
2525 | if((reparse_buf->LinkNamesBuf + | 2614 | if ((reparse_buf->LinkNamesBuf + |
2526 | reparse_buf->TargetNameOffset + | 2615 | reparse_buf->TargetNameOffset + |
2527 | reparse_buf->TargetNameLen) > | 2616 | reparse_buf->TargetNameLen) > |
2528 | end_of_smb) { | 2617 | end_of_smb) { |
2529 | cFYI(1,("reparse buf extended beyond SMB")); | 2618 | cFYI(1,("reparse buf goes beyond SMB")); |
2530 | rc = -EIO; | 2619 | rc = -EIO; |
2531 | goto qreparse_out; | 2620 | goto qreparse_out; |
2532 | } | 2621 | } |
2533 | 2622 | ||
2534 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) { | 2623 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) { |
2535 | name_len = UniStrnlen((wchar_t *) | 2624 | name_len = UniStrnlen((wchar_t *) |
2536 | (reparse_buf->LinkNamesBuf + | 2625 | (reparse_buf->LinkNamesBuf + |
2537 | reparse_buf->TargetNameOffset), | 2626 | reparse_buf->TargetNameOffset), |
2538 | min(buflen/2, reparse_buf->TargetNameLen / 2)); | 2627 | min(buflen/2, |
2628 | reparse_buf->TargetNameLen / 2)); | ||
2539 | cifs_strfromUCS_le(symlinkinfo, | 2629 | cifs_strfromUCS_le(symlinkinfo, |
2540 | (__le16 *) (reparse_buf->LinkNamesBuf + | 2630 | (__le16 *) (reparse_buf->LinkNamesBuf + |
2541 | reparse_buf->TargetNameOffset), | 2631 | reparse_buf->TargetNameOffset), |
2542 | name_len, nls_codepage); | 2632 | name_len, nls_codepage); |
2543 | } else { /* ASCII names */ | 2633 | } else { /* ASCII names */ |
2544 | strncpy(symlinkinfo,reparse_buf->LinkNamesBuf + | 2634 | strncpy(symlinkinfo, |
2545 | reparse_buf->TargetNameOffset, | 2635 | reparse_buf->LinkNamesBuf + |
2546 | min_t(const int, buflen, reparse_buf->TargetNameLen)); | 2636 | reparse_buf->TargetNameOffset, |
2637 | min_t(const int, buflen, | ||
2638 | reparse_buf->TargetNameLen)); | ||
2547 | } | 2639 | } |
2548 | } else { | 2640 | } else { |
2549 | rc = -EIO; | 2641 | rc = -EIO; |
2550 | cFYI(1,("Invalid return data count on get reparse info ioctl")); | 2642 | cFYI(1, ("Invalid return data count on " |
2643 | "get reparse info ioctl")); | ||
2551 | } | 2644 | } |
2552 | symlinkinfo[buflen] = 0; /* just in case so the caller | 2645 | symlinkinfo[buflen] = 0; /* just in case so the caller |
2553 | does not go off the end of the buffer */ | 2646 | does not go off the end of the buffer */ |
2554 | cFYI(1,("readlink result - %s",symlinkinfo)); | 2647 | cFYI(1, ("readlink result - %s", symlinkinfo)); |
2555 | } | 2648 | } |
2556 | } | 2649 | } |
2557 | qreparse_out: | 2650 | qreparse_out: |
@@ -2566,7 +2659,8 @@ qreparse_out: | |||
2566 | #ifdef CONFIG_CIFS_POSIX | 2659 | #ifdef CONFIG_CIFS_POSIX |
2567 | 2660 | ||
2568 | /*Convert an Access Control Entry from wire format to local POSIX xattr format*/ | 2661 | /*Convert an Access Control Entry from wire format to local POSIX xattr format*/ |
2569 | static void cifs_convert_ace(posix_acl_xattr_entry * ace, struct cifs_posix_ace * cifs_ace) | 2662 | static void cifs_convert_ace(posix_acl_xattr_entry *ace, |
2663 | struct cifs_posix_ace *cifs_ace) | ||
2570 | { | 2664 | { |
2571 | /* u8 cifs fields do not need le conversion */ | 2665 | /* u8 cifs fields do not need le conversion */ |
2572 | ace->e_perm = cpu_to_le16(cifs_ace->cifs_e_perm); | 2666 | ace->e_perm = cpu_to_le16(cifs_ace->cifs_e_perm); |
@@ -2578,30 +2672,31 @@ static void cifs_convert_ace(posix_acl_xattr_entry * ace, struct cifs_posix_ace | |||
2578 | } | 2672 | } |
2579 | 2673 | ||
2580 | /* Convert ACL from CIFS POSIX wire format to local Linux POSIX ACL xattr */ | 2674 | /* Convert ACL from CIFS POSIX wire format to local Linux POSIX ACL xattr */ |
2581 | static int cifs_copy_posix_acl(char * trgt,char * src, const int buflen, | 2675 | static int cifs_copy_posix_acl(char *trgt, char *src, const int buflen, |
2582 | const int acl_type,const int size_of_data_area) | 2676 | const int acl_type, const int size_of_data_area) |
2583 | { | 2677 | { |
2584 | int size = 0; | 2678 | int size = 0; |
2585 | int i; | 2679 | int i; |
2586 | __u16 count; | 2680 | __u16 count; |
2587 | struct cifs_posix_ace * pACE; | 2681 | struct cifs_posix_ace *pACE; |
2588 | struct cifs_posix_acl * cifs_acl = (struct cifs_posix_acl *)src; | 2682 | struct cifs_posix_acl *cifs_acl = (struct cifs_posix_acl *)src; |
2589 | posix_acl_xattr_header * local_acl = (posix_acl_xattr_header *)trgt; | 2683 | posix_acl_xattr_header *local_acl = (posix_acl_xattr_header *)trgt; |
2590 | 2684 | ||
2591 | if (le16_to_cpu(cifs_acl->version) != CIFS_ACL_VERSION) | 2685 | if (le16_to_cpu(cifs_acl->version) != CIFS_ACL_VERSION) |
2592 | return -EOPNOTSUPP; | 2686 | return -EOPNOTSUPP; |
2593 | 2687 | ||
2594 | if(acl_type & ACL_TYPE_ACCESS) { | 2688 | if (acl_type & ACL_TYPE_ACCESS) { |
2595 | count = le16_to_cpu(cifs_acl->access_entry_count); | 2689 | count = le16_to_cpu(cifs_acl->access_entry_count); |
2596 | pACE = &cifs_acl->ace_array[0]; | 2690 | pACE = &cifs_acl->ace_array[0]; |
2597 | size = sizeof(struct cifs_posix_acl); | 2691 | size = sizeof(struct cifs_posix_acl); |
2598 | size += sizeof(struct cifs_posix_ace) * count; | 2692 | size += sizeof(struct cifs_posix_ace) * count; |
2599 | /* check if we would go beyond end of SMB */ | 2693 | /* check if we would go beyond end of SMB */ |
2600 | if(size_of_data_area < size) { | 2694 | if (size_of_data_area < size) { |
2601 | cFYI(1,("bad CIFS POSIX ACL size %d vs. %d",size_of_data_area,size)); | 2695 | cFYI(1, ("bad CIFS POSIX ACL size %d vs. %d", |
2696 | size_of_data_area, size)); | ||
2602 | return -EINVAL; | 2697 | return -EINVAL; |
2603 | } | 2698 | } |
2604 | } else if(acl_type & ACL_TYPE_DEFAULT) { | 2699 | } else if (acl_type & ACL_TYPE_DEFAULT) { |
2605 | count = le16_to_cpu(cifs_acl->access_entry_count); | 2700 | count = le16_to_cpu(cifs_acl->access_entry_count); |
2606 | size = sizeof(struct cifs_posix_acl); | 2701 | size = sizeof(struct cifs_posix_acl); |
2607 | size += sizeof(struct cifs_posix_ace) * count; | 2702 | size += sizeof(struct cifs_posix_ace) * count; |
@@ -2610,7 +2705,7 @@ static int cifs_copy_posix_acl(char * trgt,char * src, const int buflen, | |||
2610 | count = le16_to_cpu(cifs_acl->default_entry_count); | 2705 | count = le16_to_cpu(cifs_acl->default_entry_count); |
2611 | size += sizeof(struct cifs_posix_ace) * count; | 2706 | size += sizeof(struct cifs_posix_ace) * count; |
2612 | /* check if we would go beyond end of SMB */ | 2707 | /* check if we would go beyond end of SMB */ |
2613 | if(size_of_data_area < size) | 2708 | if (size_of_data_area < size) |
2614 | return -EINVAL; | 2709 | return -EINVAL; |
2615 | } else { | 2710 | } else { |
2616 | /* illegal type */ | 2711 | /* illegal type */ |
@@ -2618,76 +2713,77 @@ static int cifs_copy_posix_acl(char * trgt,char * src, const int buflen, | |||
2618 | } | 2713 | } |
2619 | 2714 | ||
2620 | size = posix_acl_xattr_size(count); | 2715 | size = posix_acl_xattr_size(count); |
2621 | if((buflen == 0) || (local_acl == NULL)) { | 2716 | if ((buflen == 0) || (local_acl == NULL)) { |
2622 | /* used to query ACL EA size */ | 2717 | /* used to query ACL EA size */ |
2623 | } else if(size > buflen) { | 2718 | } else if (size > buflen) { |
2624 | return -ERANGE; | 2719 | return -ERANGE; |
2625 | } else /* buffer big enough */ { | 2720 | } else /* buffer big enough */ { |
2626 | local_acl->a_version = cpu_to_le32(POSIX_ACL_XATTR_VERSION); | 2721 | local_acl->a_version = cpu_to_le32(POSIX_ACL_XATTR_VERSION); |
2627 | for(i = 0;i < count ;i++) { | 2722 | for (i = 0; i < count ; i++) { |
2628 | cifs_convert_ace(&local_acl->a_entries[i],pACE); | 2723 | cifs_convert_ace(&local_acl->a_entries[i], pACE); |
2629 | pACE ++; | 2724 | pACE++; |
2630 | } | 2725 | } |
2631 | } | 2726 | } |
2632 | return size; | 2727 | return size; |
2633 | } | 2728 | } |
2634 | 2729 | ||
2635 | static __u16 convert_ace_to_cifs_ace(struct cifs_posix_ace * cifs_ace, | 2730 | static __u16 convert_ace_to_cifs_ace(struct cifs_posix_ace *cifs_ace, |
2636 | const posix_acl_xattr_entry * local_ace) | 2731 | const posix_acl_xattr_entry *local_ace) |
2637 | { | 2732 | { |
2638 | __u16 rc = 0; /* 0 = ACL converted ok */ | 2733 | __u16 rc = 0; /* 0 = ACL converted ok */ |
2639 | 2734 | ||
2640 | cifs_ace->cifs_e_perm = le16_to_cpu(local_ace->e_perm); | 2735 | cifs_ace->cifs_e_perm = le16_to_cpu(local_ace->e_perm); |
2641 | cifs_ace->cifs_e_tag = le16_to_cpu(local_ace->e_tag); | 2736 | cifs_ace->cifs_e_tag = le16_to_cpu(local_ace->e_tag); |
2642 | /* BB is there a better way to handle the large uid? */ | 2737 | /* BB is there a better way to handle the large uid? */ |
2643 | if(local_ace->e_id == cpu_to_le32(-1)) { | 2738 | if (local_ace->e_id == cpu_to_le32(-1)) { |
2644 | /* Probably no need to le convert -1 on any arch but can not hurt */ | 2739 | /* Probably no need to le convert -1 on any arch but can not hurt */ |
2645 | cifs_ace->cifs_uid = cpu_to_le64(-1); | 2740 | cifs_ace->cifs_uid = cpu_to_le64(-1); |
2646 | } else | 2741 | } else |
2647 | cifs_ace->cifs_uid = cpu_to_le64(le32_to_cpu(local_ace->e_id)); | 2742 | cifs_ace->cifs_uid = cpu_to_le64(le32_to_cpu(local_ace->e_id)); |
2648 | /*cFYI(1,("perm %d tag %d id %d",ace->e_perm,ace->e_tag,ace->e_id));*/ | 2743 | /*cFYI(1,("perm %d tag %d id %d",ace->e_perm,ace->e_tag,ace->e_id));*/ |
2649 | return rc; | 2744 | return rc; |
2650 | } | 2745 | } |
2651 | 2746 | ||
2652 | /* Convert ACL from local Linux POSIX xattr to CIFS POSIX ACL wire format */ | 2747 | /* Convert ACL from local Linux POSIX xattr to CIFS POSIX ACL wire format */ |
2653 | static __u16 ACL_to_cifs_posix(char * parm_data,const char * pACL,const int buflen, | 2748 | static __u16 ACL_to_cifs_posix(char *parm_data, const char *pACL, |
2654 | const int acl_type) | 2749 | const int buflen, const int acl_type) |
2655 | { | 2750 | { |
2656 | __u16 rc = 0; | 2751 | __u16 rc = 0; |
2657 | struct cifs_posix_acl * cifs_acl = (struct cifs_posix_acl *)parm_data; | 2752 | struct cifs_posix_acl *cifs_acl = (struct cifs_posix_acl *)parm_data; |
2658 | posix_acl_xattr_header * local_acl = (posix_acl_xattr_header *)pACL; | 2753 | posix_acl_xattr_header *local_acl = (posix_acl_xattr_header *)pACL; |
2659 | int count; | 2754 | int count; |
2660 | int i; | 2755 | int i; |
2661 | 2756 | ||
2662 | if((buflen == 0) || (pACL == NULL) || (cifs_acl == NULL)) | 2757 | if ((buflen == 0) || (pACL == NULL) || (cifs_acl == NULL)) |
2663 | return 0; | 2758 | return 0; |
2664 | 2759 | ||
2665 | count = posix_acl_xattr_count((size_t)buflen); | 2760 | count = posix_acl_xattr_count((size_t)buflen); |
2666 | cFYI(1,("setting acl with %d entries from buf of length %d and version of %d", | 2761 | cFYI(1, ("setting acl with %d entries from buf of length %d and " |
2762 | "version of %d", | ||
2667 | count, buflen, le32_to_cpu(local_acl->a_version))); | 2763 | count, buflen, le32_to_cpu(local_acl->a_version))); |
2668 | if(le32_to_cpu(local_acl->a_version) != 2) { | 2764 | if (le32_to_cpu(local_acl->a_version) != 2) { |
2669 | cFYI(1,("unknown POSIX ACL version %d", | 2765 | cFYI(1, ("unknown POSIX ACL version %d", |
2670 | le32_to_cpu(local_acl->a_version))); | 2766 | le32_to_cpu(local_acl->a_version))); |
2671 | return 0; | 2767 | return 0; |
2672 | } | 2768 | } |
2673 | cifs_acl->version = cpu_to_le16(1); | 2769 | cifs_acl->version = cpu_to_le16(1); |
2674 | if(acl_type == ACL_TYPE_ACCESS) | 2770 | if (acl_type == ACL_TYPE_ACCESS) |
2675 | cifs_acl->access_entry_count = cpu_to_le16(count); | 2771 | cifs_acl->access_entry_count = cpu_to_le16(count); |
2676 | else if(acl_type == ACL_TYPE_DEFAULT) | 2772 | else if (acl_type == ACL_TYPE_DEFAULT) |
2677 | cifs_acl->default_entry_count = cpu_to_le16(count); | 2773 | cifs_acl->default_entry_count = cpu_to_le16(count); |
2678 | else { | 2774 | else { |
2679 | cFYI(1,("unknown ACL type %d",acl_type)); | 2775 | cFYI(1, ("unknown ACL type %d", acl_type)); |
2680 | return 0; | 2776 | return 0; |
2681 | } | 2777 | } |
2682 | for(i=0;i<count;i++) { | 2778 | for (i = 0; i < count; i++) { |
2683 | rc = convert_ace_to_cifs_ace(&cifs_acl->ace_array[i], | 2779 | rc = convert_ace_to_cifs_ace(&cifs_acl->ace_array[i], |
2684 | &local_acl->a_entries[i]); | 2780 | &local_acl->a_entries[i]); |
2685 | if(rc != 0) { | 2781 | if (rc != 0) { |
2686 | /* ACE not converted */ | 2782 | /* ACE not converted */ |
2687 | break; | 2783 | break; |
2688 | } | 2784 | } |
2689 | } | 2785 | } |
2690 | if(rc == 0) { | 2786 | if (rc == 0) { |
2691 | rc = (__u16)(count * sizeof(struct cifs_posix_ace)); | 2787 | rc = (__u16)(count * sizeof(struct cifs_posix_ace)); |
2692 | rc += sizeof(struct cifs_posix_acl); | 2788 | rc += sizeof(struct cifs_posix_acl); |
2693 | /* BB add check to make sure ACL does not overflow SMB */ | 2789 | /* BB add check to make sure ACL does not overflow SMB */ |
@@ -2697,9 +2793,9 @@ static __u16 ACL_to_cifs_posix(char * parm_data,const char * pACL,const int bufl | |||
2697 | 2793 | ||
2698 | int | 2794 | int |
2699 | CIFSSMBGetPosixACL(const int xid, struct cifsTconInfo *tcon, | 2795 | CIFSSMBGetPosixACL(const int xid, struct cifsTconInfo *tcon, |
2700 | const unsigned char *searchName, | 2796 | const unsigned char *searchName, |
2701 | char *acl_inf, const int buflen, const int acl_type, | 2797 | char *acl_inf, const int buflen, const int acl_type, |
2702 | const struct nls_table *nls_codepage, int remap) | 2798 | const struct nls_table *nls_codepage, int remap) |
2703 | { | 2799 | { |
2704 | /* SMB_QUERY_POSIX_ACL */ | 2800 | /* SMB_QUERY_POSIX_ACL */ |
2705 | TRANSACTION2_QPI_REQ *pSMB = NULL; | 2801 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
@@ -2708,7 +2804,7 @@ CIFSSMBGetPosixACL(const int xid, struct cifsTconInfo *tcon, | |||
2708 | int bytes_returned; | 2804 | int bytes_returned; |
2709 | int name_len; | 2805 | int name_len; |
2710 | __u16 params, byte_count; | 2806 | __u16 params, byte_count; |
2711 | 2807 | ||
2712 | cFYI(1, ("In GetPosixACL (Unix) for path %s", searchName)); | 2808 | cFYI(1, ("In GetPosixACL (Unix) for path %s", searchName)); |
2713 | 2809 | ||
2714 | queryAclRetry: | 2810 | queryAclRetry: |
@@ -2716,16 +2812,16 @@ queryAclRetry: | |||
2716 | (void **) &pSMBr); | 2812 | (void **) &pSMBr); |
2717 | if (rc) | 2813 | if (rc) |
2718 | return rc; | 2814 | return rc; |
2719 | 2815 | ||
2720 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { | 2816 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
2721 | name_len = | 2817 | name_len = |
2722 | cifsConvertToUCS((__le16 *) pSMB->FileName, searchName, | 2818 | cifsConvertToUCS((__le16 *) pSMB->FileName, searchName, |
2723 | PATH_MAX, nls_codepage, remap); | 2819 | PATH_MAX, nls_codepage, remap); |
2724 | name_len++; /* trailing null */ | 2820 | name_len++; /* trailing null */ |
2725 | name_len *= 2; | 2821 | name_len *= 2; |
2726 | pSMB->FileName[name_len] = 0; | 2822 | pSMB->FileName[name_len] = 0; |
2727 | pSMB->FileName[name_len+1] = 0; | 2823 | pSMB->FileName[name_len+1] = 0; |
2728 | } else { /* BB improve the check for buffer overruns BB */ | 2824 | } else { /* BB improve the check for buffer overruns BB */ |
2729 | name_len = strnlen(searchName, PATH_MAX); | 2825 | name_len = strnlen(searchName, PATH_MAX); |
2730 | name_len++; /* trailing null */ | 2826 | name_len++; /* trailing null */ |
2731 | strncpy(pSMB->FileName, searchName, name_len); | 2827 | strncpy(pSMB->FileName, searchName, name_len); |
@@ -2734,7 +2830,7 @@ queryAclRetry: | |||
2734 | params = 2 /* level */ + 4 /* rsrvd */ + name_len /* incl null */ ; | 2830 | params = 2 /* level */ + 4 /* rsrvd */ + name_len /* incl null */ ; |
2735 | pSMB->TotalDataCount = 0; | 2831 | pSMB->TotalDataCount = 0; |
2736 | pSMB->MaxParameterCount = cpu_to_le16(2); | 2832 | pSMB->MaxParameterCount = cpu_to_le16(2); |
2737 | /* BB find exact max data count below from sess structure BB */ | 2833 | /* BB find exact max data count below from sess structure BB */ |
2738 | pSMB->MaxDataCount = cpu_to_le16(4000); | 2834 | pSMB->MaxDataCount = cpu_to_le16(4000); |
2739 | pSMB->MaxSetupCount = 0; | 2835 | pSMB->MaxSetupCount = 0; |
2740 | pSMB->Reserved = 0; | 2836 | pSMB->Reserved = 0; |
@@ -2742,7 +2838,8 @@ queryAclRetry: | |||
2742 | pSMB->Timeout = 0; | 2838 | pSMB->Timeout = 0; |
2743 | pSMB->Reserved2 = 0; | 2839 | pSMB->Reserved2 = 0; |
2744 | pSMB->ParameterOffset = cpu_to_le16( | 2840 | pSMB->ParameterOffset = cpu_to_le16( |
2745 | offsetof(struct smb_com_transaction2_qpi_req ,InformationLevel) - 4); | 2841 | offsetof(struct smb_com_transaction2_qpi_req, |
2842 | InformationLevel) - 4); | ||
2746 | pSMB->DataCount = 0; | 2843 | pSMB->DataCount = 0; |
2747 | pSMB->DataOffset = 0; | 2844 | pSMB->DataOffset = 0; |
2748 | pSMB->SetupCount = 1; | 2845 | pSMB->SetupCount = 1; |
@@ -2763,7 +2860,7 @@ queryAclRetry: | |||
2763 | cFYI(1, ("Send error in Query POSIX ACL = %d", rc)); | 2860 | cFYI(1, ("Send error in Query POSIX ACL = %d", rc)); |
2764 | } else { | 2861 | } else { |
2765 | /* decode response */ | 2862 | /* decode response */ |
2766 | 2863 | ||
2767 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); | 2864 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
2768 | if (rc || (pSMBr->ByteCount < 2)) | 2865 | if (rc || (pSMBr->ByteCount < 2)) |
2769 | /* BB also check enough total bytes returned */ | 2866 | /* BB also check enough total bytes returned */ |
@@ -2773,7 +2870,7 @@ queryAclRetry: | |||
2773 | __u16 count = le16_to_cpu(pSMBr->t2.DataCount); | 2870 | __u16 count = le16_to_cpu(pSMBr->t2.DataCount); |
2774 | rc = cifs_copy_posix_acl(acl_inf, | 2871 | rc = cifs_copy_posix_acl(acl_inf, |
2775 | (char *)&pSMBr->hdr.Protocol+data_offset, | 2872 | (char *)&pSMBr->hdr.Protocol+data_offset, |
2776 | buflen,acl_type,count); | 2873 | buflen, acl_type, count); |
2777 | } | 2874 | } |
2778 | } | 2875 | } |
2779 | cifs_buf_release(pSMB); | 2876 | cifs_buf_release(pSMB); |
@@ -2784,10 +2881,10 @@ queryAclRetry: | |||
2784 | 2881 | ||
2785 | int | 2882 | int |
2786 | CIFSSMBSetPosixACL(const int xid, struct cifsTconInfo *tcon, | 2883 | CIFSSMBSetPosixACL(const int xid, struct cifsTconInfo *tcon, |
2787 | const unsigned char *fileName, | 2884 | const unsigned char *fileName, |
2788 | const char *local_acl, const int buflen, | 2885 | const char *local_acl, const int buflen, |
2789 | const int acl_type, | 2886 | const int acl_type, |
2790 | const struct nls_table *nls_codepage, int remap) | 2887 | const struct nls_table *nls_codepage, int remap) |
2791 | { | 2888 | { |
2792 | struct smb_com_transaction2_spi_req *pSMB = NULL; | 2889 | struct smb_com_transaction2_spi_req *pSMB = NULL; |
2793 | struct smb_com_transaction2_spi_rsp *pSMBr = NULL; | 2890 | struct smb_com_transaction2_spi_rsp *pSMBr = NULL; |
@@ -2800,16 +2897,16 @@ CIFSSMBSetPosixACL(const int xid, struct cifsTconInfo *tcon, | |||
2800 | cFYI(1, ("In SetPosixACL (Unix) for path %s", fileName)); | 2897 | cFYI(1, ("In SetPosixACL (Unix) for path %s", fileName)); |
2801 | setAclRetry: | 2898 | setAclRetry: |
2802 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, | 2899 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
2803 | (void **) &pSMBr); | 2900 | (void **) &pSMBr); |
2804 | if (rc) | 2901 | if (rc) |
2805 | return rc; | 2902 | return rc; |
2806 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { | 2903 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
2807 | name_len = | 2904 | name_len = |
2808 | cifsConvertToUCS((__le16 *) pSMB->FileName, fileName, | 2905 | cifsConvertToUCS((__le16 *) pSMB->FileName, fileName, |
2809 | PATH_MAX, nls_codepage, remap); | 2906 | PATH_MAX, nls_codepage, remap); |
2810 | name_len++; /* trailing null */ | 2907 | name_len++; /* trailing null */ |
2811 | name_len *= 2; | 2908 | name_len *= 2; |
2812 | } else { /* BB improve the check for buffer overruns BB */ | 2909 | } else { /* BB improve the check for buffer overruns BB */ |
2813 | name_len = strnlen(fileName, PATH_MAX); | 2910 | name_len = strnlen(fileName, PATH_MAX); |
2814 | name_len++; /* trailing null */ | 2911 | name_len++; /* trailing null */ |
2815 | strncpy(pSMB->FileName, fileName, name_len); | 2912 | strncpy(pSMB->FileName, fileName, name_len); |
@@ -2823,15 +2920,15 @@ setAclRetry: | |||
2823 | pSMB->Timeout = 0; | 2920 | pSMB->Timeout = 0; |
2824 | pSMB->Reserved2 = 0; | 2921 | pSMB->Reserved2 = 0; |
2825 | param_offset = offsetof(struct smb_com_transaction2_spi_req, | 2922 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
2826 | InformationLevel) - 4; | 2923 | InformationLevel) - 4; |
2827 | offset = param_offset + params; | 2924 | offset = param_offset + params; |
2828 | parm_data = ((char *) &pSMB->hdr.Protocol) + offset; | 2925 | parm_data = ((char *) &pSMB->hdr.Protocol) + offset; |
2829 | pSMB->ParameterOffset = cpu_to_le16(param_offset); | 2926 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
2830 | 2927 | ||
2831 | /* convert to on the wire format for POSIX ACL */ | 2928 | /* convert to on the wire format for POSIX ACL */ |
2832 | data_count = ACL_to_cifs_posix(parm_data,local_acl,buflen,acl_type); | 2929 | data_count = ACL_to_cifs_posix(parm_data, local_acl, buflen, acl_type); |
2833 | 2930 | ||
2834 | if(data_count == 0) { | 2931 | if (data_count == 0) { |
2835 | rc = -EOPNOTSUPP; | 2932 | rc = -EOPNOTSUPP; |
2836 | goto setACLerrorExit; | 2933 | goto setACLerrorExit; |
2837 | } | 2934 | } |
@@ -2849,7 +2946,7 @@ setAclRetry: | |||
2849 | pSMB->hdr.smb_buf_length += byte_count; | 2946 | pSMB->hdr.smb_buf_length += byte_count; |
2850 | pSMB->ByteCount = cpu_to_le16(byte_count); | 2947 | pSMB->ByteCount = cpu_to_le16(byte_count); |
2851 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, | 2948 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
2852 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); | 2949 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
2853 | if (rc) { | 2950 | if (rc) { |
2854 | cFYI(1, ("Set POSIX ACL returned %d", rc)); | 2951 | cFYI(1, ("Set POSIX ACL returned %d", rc)); |
2855 | } | 2952 | } |
@@ -2864,86 +2961,85 @@ setACLerrorExit: | |||
2864 | /* BB fix tabs in this function FIXME BB */ | 2961 | /* BB fix tabs in this function FIXME BB */ |
2865 | int | 2962 | int |
2866 | CIFSGetExtAttr(const int xid, struct cifsTconInfo *tcon, | 2963 | CIFSGetExtAttr(const int xid, struct cifsTconInfo *tcon, |
2867 | const int netfid, __u64 * pExtAttrBits, __u64 *pMask) | 2964 | const int netfid, __u64 * pExtAttrBits, __u64 *pMask) |
2868 | { | 2965 | { |
2869 | int rc = 0; | 2966 | int rc = 0; |
2870 | struct smb_t2_qfi_req *pSMB = NULL; | 2967 | struct smb_t2_qfi_req *pSMB = NULL; |
2871 | struct smb_t2_qfi_rsp *pSMBr = NULL; | 2968 | struct smb_t2_qfi_rsp *pSMBr = NULL; |
2872 | int bytes_returned; | 2969 | int bytes_returned; |
2873 | __u16 params, byte_count; | 2970 | __u16 params, byte_count; |
2874 | 2971 | ||
2875 | cFYI(1,("In GetExtAttr")); | 2972 | cFYI(1, ("In GetExtAttr")); |
2876 | if(tcon == NULL) | 2973 | if (tcon == NULL) |
2877 | return -ENODEV; | 2974 | return -ENODEV; |
2878 | 2975 | ||
2879 | GetExtAttrRetry: | 2976 | GetExtAttrRetry: |
2880 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, | 2977 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
2881 | (void **) &pSMBr); | 2978 | (void **) &pSMBr); |
2882 | if (rc) | 2979 | if (rc) |
2883 | return rc; | 2980 | return rc; |
2884 | 2981 | ||
2885 | params = 2 /* level */ +2 /* fid */; | 2982 | params = 2 /* level */ +2 /* fid */; |
2886 | pSMB->t2.TotalDataCount = 0; | 2983 | pSMB->t2.TotalDataCount = 0; |
2887 | pSMB->t2.MaxParameterCount = cpu_to_le16(4); | 2984 | pSMB->t2.MaxParameterCount = cpu_to_le16(4); |
2888 | /* BB find exact max data count below from sess structure BB */ | 2985 | /* BB find exact max data count below from sess structure BB */ |
2889 | pSMB->t2.MaxDataCount = cpu_to_le16(4000); | 2986 | pSMB->t2.MaxDataCount = cpu_to_le16(4000); |
2890 | pSMB->t2.MaxSetupCount = 0; | 2987 | pSMB->t2.MaxSetupCount = 0; |
2891 | pSMB->t2.Reserved = 0; | 2988 | pSMB->t2.Reserved = 0; |
2892 | pSMB->t2.Flags = 0; | 2989 | pSMB->t2.Flags = 0; |
2893 | pSMB->t2.Timeout = 0; | 2990 | pSMB->t2.Timeout = 0; |
2894 | pSMB->t2.Reserved2 = 0; | 2991 | pSMB->t2.Reserved2 = 0; |
2895 | pSMB->t2.ParameterOffset = cpu_to_le16(offsetof(struct smb_t2_qfi_req, | 2992 | pSMB->t2.ParameterOffset = cpu_to_le16(offsetof(struct smb_t2_qfi_req, |
2896 | Fid) - 4); | 2993 | Fid) - 4); |
2897 | pSMB->t2.DataCount = 0; | 2994 | pSMB->t2.DataCount = 0; |
2898 | pSMB->t2.DataOffset = 0; | 2995 | pSMB->t2.DataOffset = 0; |
2899 | pSMB->t2.SetupCount = 1; | 2996 | pSMB->t2.SetupCount = 1; |
2900 | pSMB->t2.Reserved3 = 0; | 2997 | pSMB->t2.Reserved3 = 0; |
2901 | pSMB->t2.SubCommand = cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION); | 2998 | pSMB->t2.SubCommand = cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION); |
2902 | byte_count = params + 1 /* pad */ ; | 2999 | byte_count = params + 1 /* pad */ ; |
2903 | pSMB->t2.TotalParameterCount = cpu_to_le16(params); | 3000 | pSMB->t2.TotalParameterCount = cpu_to_le16(params); |
2904 | pSMB->t2.ParameterCount = pSMB->t2.TotalParameterCount; | 3001 | pSMB->t2.ParameterCount = pSMB->t2.TotalParameterCount; |
2905 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_ATTR_FLAGS); | 3002 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_ATTR_FLAGS); |
2906 | pSMB->Pad = 0; | 3003 | pSMB->Pad = 0; |
2907 | pSMB->Fid = netfid; | 3004 | pSMB->Fid = netfid; |
2908 | pSMB->hdr.smb_buf_length += byte_count; | 3005 | pSMB->hdr.smb_buf_length += byte_count; |
2909 | pSMB->t2.ByteCount = cpu_to_le16(byte_count); | 3006 | pSMB->t2.ByteCount = cpu_to_le16(byte_count); |
2910 | 3007 | ||
2911 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, | 3008 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
2912 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); | 3009 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
2913 | if (rc) { | 3010 | if (rc) { |
2914 | cFYI(1, ("error %d in GetExtAttr", rc)); | 3011 | cFYI(1, ("error %d in GetExtAttr", rc)); |
2915 | } else { | 3012 | } else { |
2916 | /* decode response */ | 3013 | /* decode response */ |
2917 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); | 3014 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
2918 | if (rc || (pSMBr->ByteCount < 2)) | 3015 | if (rc || (pSMBr->ByteCount < 2)) |
2919 | /* BB also check enough total bytes returned */ | 3016 | /* BB also check enough total bytes returned */ |
2920 | /* If rc should we check for EOPNOSUPP and | 3017 | /* If rc should we check for EOPNOSUPP and |
2921 | disable the srvino flag? or in caller? */ | 3018 | disable the srvino flag? or in caller? */ |
2922 | rc = -EIO; /* bad smb */ | 3019 | rc = -EIO; /* bad smb */ |
2923 | else { | 3020 | else { |
2924 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); | 3021 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
2925 | __u16 count = le16_to_cpu(pSMBr->t2.DataCount); | 3022 | __u16 count = le16_to_cpu(pSMBr->t2.DataCount); |
2926 | struct file_chattr_info * pfinfo; | 3023 | struct file_chattr_info *pfinfo; |
2927 | /* BB Do we need a cast or hash here ? */ | 3024 | /* BB Do we need a cast or hash here ? */ |
2928 | if(count != 16) { | 3025 | if (count != 16) { |
2929 | cFYI(1, ("Illegal size ret in GetExtAttr")); | 3026 | cFYI(1, ("Illegal size ret in GetExtAttr")); |
2930 | rc = -EIO; | 3027 | rc = -EIO; |
2931 | goto GetExtAttrOut; | 3028 | goto GetExtAttrOut; |
2932 | } | 3029 | } |
2933 | pfinfo = (struct file_chattr_info *) | 3030 | pfinfo = (struct file_chattr_info *) |
2934 | (data_offset + (char *) &pSMBr->hdr.Protocol); | 3031 | (data_offset + (char *) &pSMBr->hdr.Protocol); |
2935 | *pExtAttrBits = le64_to_cpu(pfinfo->mode); | 3032 | *pExtAttrBits = le64_to_cpu(pfinfo->mode); |
2936 | *pMask = le64_to_cpu(pfinfo->mask); | 3033 | *pMask = le64_to_cpu(pfinfo->mask); |
2937 | } | 3034 | } |
2938 | } | 3035 | } |
2939 | GetExtAttrOut: | 3036 | GetExtAttrOut: |
2940 | cifs_buf_release(pSMB); | 3037 | cifs_buf_release(pSMB); |
2941 | if (rc == -EAGAIN) | 3038 | if (rc == -EAGAIN) |
2942 | goto GetExtAttrRetry; | 3039 | goto GetExtAttrRetry; |
2943 | return rc; | 3040 | return rc; |
2944 | } | 3041 | } |
2945 | 3042 | ||
2946 | |||
2947 | #endif /* CONFIG_POSIX */ | 3043 | #endif /* CONFIG_POSIX */ |
2948 | 3044 | ||
2949 | 3045 | ||
@@ -2955,7 +3051,7 @@ static const struct cifs_sid sid_user = | |||
2955 | {1, 2 , {0, 0, 0, 0, 0, 5}, {32, 545, 0, 0}}; | 3051 | {1, 2 , {0, 0, 0, 0, 0, 5}, {32, 545, 0, 0}}; |
2956 | 3052 | ||
2957 | /* Convert CIFS ACL to POSIX form */ | 3053 | /* Convert CIFS ACL to POSIX form */ |
2958 | static int parse_sec_desc(struct cifs_sid * psec_desc, int acl_len) | 3054 | static int parse_sec_desc(struct cifs_sid *psec_desc, int acl_len) |
2959 | { | 3055 | { |
2960 | return 0; | 3056 | return 0; |
2961 | } | 3057 | } |
@@ -2963,7 +3059,7 @@ static int parse_sec_desc(struct cifs_sid * psec_desc, int acl_len) | |||
2963 | /* Get Security Descriptor (by handle) from remote server for a file or dir */ | 3059 | /* Get Security Descriptor (by handle) from remote server for a file or dir */ |
2964 | int | 3060 | int |
2965 | CIFSSMBGetCIFSACL(const int xid, struct cifsTconInfo *tcon, __u16 fid, | 3061 | CIFSSMBGetCIFSACL(const int xid, struct cifsTconInfo *tcon, __u16 fid, |
2966 | /* BB fix up return info */ char *acl_inf, const int buflen, | 3062 | /* BB fix up return info */ char *acl_inf, const int buflen, |
2967 | const int acl_type /* ACCESS/DEFAULT not sure implication */) | 3063 | const int acl_type /* ACCESS/DEFAULT not sure implication */) |
2968 | { | 3064 | { |
2969 | int rc = 0; | 3065 | int rc = 0; |
@@ -2973,7 +3069,7 @@ CIFSSMBGetCIFSACL(const int xid, struct cifsTconInfo *tcon, __u16 fid, | |||
2973 | 3069 | ||
2974 | cFYI(1, ("GetCifsACL")); | 3070 | cFYI(1, ("GetCifsACL")); |
2975 | 3071 | ||
2976 | rc = smb_init_ntransact(NT_TRANSACT_QUERY_SECURITY_DESC, 0, | 3072 | rc = smb_init_ntransact(NT_TRANSACT_QUERY_SECURITY_DESC, 0, |
2977 | 8 /* parm len */, tcon, (void **) &pSMB); | 3073 | 8 /* parm len */, tcon, (void **) &pSMB); |
2978 | if (rc) | 3074 | if (rc) |
2979 | return rc; | 3075 | return rc; |
@@ -2994,23 +3090,23 @@ CIFSSMBGetCIFSACL(const int xid, struct cifsTconInfo *tcon, __u16 fid, | |||
2994 | if (rc) { | 3090 | if (rc) { |
2995 | cFYI(1, ("Send error in QuerySecDesc = %d", rc)); | 3091 | cFYI(1, ("Send error in QuerySecDesc = %d", rc)); |
2996 | } else { /* decode response */ | 3092 | } else { /* decode response */ |
2997 | struct cifs_sid * psec_desc; | 3093 | struct cifs_sid *psec_desc; |
2998 | __le32 * parm; | 3094 | __le32 * parm; |
2999 | int parm_len; | 3095 | int parm_len; |
3000 | int data_len; | 3096 | int data_len; |
3001 | int acl_len; | 3097 | int acl_len; |
3002 | struct smb_com_ntransact_rsp * pSMBr; | 3098 | struct smb_com_ntransact_rsp *pSMBr; |
3003 | 3099 | ||
3004 | /* validate_nttransact */ | 3100 | /* validate_nttransact */ |
3005 | rc = validate_ntransact(iov[0].iov_base, (char **)&parm, | 3101 | rc = validate_ntransact(iov[0].iov_base, (char **)&parm, |
3006 | (char **)&psec_desc, | 3102 | (char **)&psec_desc, |
3007 | &parm_len, &data_len); | 3103 | &parm_len, &data_len); |
3008 | 3104 | if (rc) | |
3009 | if(rc) | ||
3010 | goto qsec_out; | 3105 | goto qsec_out; |
3011 | pSMBr = (struct smb_com_ntransact_rsp *)iov[0].iov_base; | 3106 | pSMBr = (struct smb_com_ntransact_rsp *)iov[0].iov_base; |
3012 | 3107 | ||
3013 | cERROR(1,("smb %p parm %p data %p",pSMBr,parm,psec_desc)); /* BB removeme BB */ | 3108 | cERROR(1, ("smb %p parm %p data %p", |
3109 | pSMBr, parm, psec_desc)); /* BB removeme BB */ | ||
3014 | 3110 | ||
3015 | if (le32_to_cpu(pSMBr->ParameterCount) != 4) { | 3111 | if (le32_to_cpu(pSMBr->ParameterCount) != 4) { |
3016 | rc = -EIO; /* bad smb */ | 3112 | rc = -EIO; /* bad smb */ |
@@ -3020,14 +3116,14 @@ CIFSSMBGetCIFSACL(const int xid, struct cifsTconInfo *tcon, __u16 fid, | |||
3020 | /* BB check that data area is minimum length and as big as acl_len */ | 3116 | /* BB check that data area is minimum length and as big as acl_len */ |
3021 | 3117 | ||
3022 | acl_len = le32_to_cpu(*(__le32 *)parm); | 3118 | acl_len = le32_to_cpu(*(__le32 *)parm); |
3023 | /* BB check if(acl_len > bufsize) */ | 3119 | /* BB check if (acl_len > bufsize) */ |
3024 | 3120 | ||
3025 | parse_sec_desc(psec_desc, acl_len); | 3121 | parse_sec_desc(psec_desc, acl_len); |
3026 | } | 3122 | } |
3027 | qsec_out: | 3123 | qsec_out: |
3028 | if(buf_type == CIFS_SMALL_BUFFER) | 3124 | if (buf_type == CIFS_SMALL_BUFFER) |
3029 | cifs_small_buf_release(iov[0].iov_base); | 3125 | cifs_small_buf_release(iov[0].iov_base); |
3030 | else if(buf_type == CIFS_LARGE_BUFFER) | 3126 | else if (buf_type == CIFS_LARGE_BUFFER) |
3031 | cifs_buf_release(iov[0].iov_base); | 3127 | cifs_buf_release(iov[0].iov_base); |
3032 | /* cifs_small_buf_release(pSMB); */ /* Freed earlier now in SendReceive2 */ | 3128 | /* cifs_small_buf_release(pSMB); */ /* Freed earlier now in SendReceive2 */ |
3033 | return rc; | 3129 | return rc; |
@@ -3036,9 +3132,9 @@ qsec_out: | |||
3036 | /* Legacy Query Path Information call for lookup to old servers such | 3132 | /* Legacy Query Path Information call for lookup to old servers such |
3037 | as Win9x/WinME */ | 3133 | as Win9x/WinME */ |
3038 | int SMBQueryInformation(const int xid, struct cifsTconInfo *tcon, | 3134 | int SMBQueryInformation(const int xid, struct cifsTconInfo *tcon, |
3039 | const unsigned char *searchName, | 3135 | const unsigned char *searchName, |
3040 | FILE_ALL_INFO * pFinfo, | 3136 | FILE_ALL_INFO *pFinfo, |
3041 | const struct nls_table *nls_codepage, int remap) | 3137 | const struct nls_table *nls_codepage, int remap) |
3042 | { | 3138 | { |
3043 | QUERY_INFORMATION_REQ * pSMB; | 3139 | QUERY_INFORMATION_REQ * pSMB; |
3044 | QUERY_INFORMATION_RSP * pSMBr; | 3140 | QUERY_INFORMATION_RSP * pSMBr; |
@@ -3046,31 +3142,31 @@ int SMBQueryInformation(const int xid, struct cifsTconInfo *tcon, | |||
3046 | int bytes_returned; | 3142 | int bytes_returned; |
3047 | int name_len; | 3143 | int name_len; |
3048 | 3144 | ||
3049 | cFYI(1, ("In SMBQPath path %s", searchName)); | 3145 | cFYI(1, ("In SMBQPath path %s", searchName)); |
3050 | QInfRetry: | 3146 | QInfRetry: |
3051 | rc = smb_init(SMB_COM_QUERY_INFORMATION, 0, tcon, (void **) &pSMB, | 3147 | rc = smb_init(SMB_COM_QUERY_INFORMATION, 0, tcon, (void **) &pSMB, |
3052 | (void **) &pSMBr); | 3148 | (void **) &pSMBr); |
3053 | if (rc) | 3149 | if (rc) |
3054 | return rc; | 3150 | return rc; |
3055 | 3151 | ||
3056 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { | 3152 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
3057 | name_len = | 3153 | name_len = |
3058 | cifsConvertToUCS((__le16 *) pSMB->FileName, searchName, | 3154 | cifsConvertToUCS((__le16 *) pSMB->FileName, searchName, |
3059 | PATH_MAX, nls_codepage, remap); | 3155 | PATH_MAX, nls_codepage, remap); |
3060 | name_len++; /* trailing null */ | 3156 | name_len++; /* trailing null */ |
3061 | name_len *= 2; | 3157 | name_len *= 2; |
3062 | } else { | 3158 | } else { |
3063 | name_len = strnlen(searchName, PATH_MAX); | 3159 | name_len = strnlen(searchName, PATH_MAX); |
3064 | name_len++; /* trailing null */ | 3160 | name_len++; /* trailing null */ |
3065 | strncpy(pSMB->FileName, searchName, name_len); | 3161 | strncpy(pSMB->FileName, searchName, name_len); |
3066 | } | 3162 | } |
3067 | pSMB->BufferFormat = 0x04; | 3163 | pSMB->BufferFormat = 0x04; |
3068 | name_len++; /* account for buffer type byte */ | 3164 | name_len++; /* account for buffer type byte */ |
3069 | pSMB->hdr.smb_buf_length += (__u16) name_len; | 3165 | pSMB->hdr.smb_buf_length += (__u16) name_len; |
3070 | pSMB->ByteCount = cpu_to_le16(name_len); | 3166 | pSMB->ByteCount = cpu_to_le16(name_len); |
3071 | 3167 | ||
3072 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, | 3168 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
3073 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); | 3169 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
3074 | if (rc) { | 3170 | if (rc) { |
3075 | cFYI(1, ("Send error in QueryInfo = %d", rc)); | 3171 | cFYI(1, ("Send error in QueryInfo = %d", rc)); |
3076 | } else if (pFinfo) { /* decode response */ | 3172 | } else if (pFinfo) { /* decode response */ |
@@ -3127,17 +3223,17 @@ QPathInfoRetry: | |||
3127 | 3223 | ||
3128 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { | 3224 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
3129 | name_len = | 3225 | name_len = |
3130 | cifsConvertToUCS((__le16 *) pSMB->FileName, searchName, | 3226 | cifsConvertToUCS((__le16 *) pSMB->FileName, searchName, |
3131 | PATH_MAX, nls_codepage, remap); | 3227 | PATH_MAX, nls_codepage, remap); |
3132 | name_len++; /* trailing null */ | 3228 | name_len++; /* trailing null */ |
3133 | name_len *= 2; | 3229 | name_len *= 2; |
3134 | } else { /* BB improve the check for buffer overruns BB */ | 3230 | } else { /* BB improve the check for buffer overruns BB */ |
3135 | name_len = strnlen(searchName, PATH_MAX); | 3231 | name_len = strnlen(searchName, PATH_MAX); |
3136 | name_len++; /* trailing null */ | 3232 | name_len++; /* trailing null */ |
3137 | strncpy(pSMB->FileName, searchName, name_len); | 3233 | strncpy(pSMB->FileName, searchName, name_len); |
3138 | } | 3234 | } |
3139 | 3235 | ||
3140 | params = 2 /* level */ + 4 /* reserved */ + name_len /* includes NUL */ ; | 3236 | params = 2 /* level */ + 4 /* reserved */ + name_len /* includes NUL */; |
3141 | pSMB->TotalDataCount = 0; | 3237 | pSMB->TotalDataCount = 0; |
3142 | pSMB->MaxParameterCount = cpu_to_le16(2); | 3238 | pSMB->MaxParameterCount = cpu_to_le16(2); |
3143 | pSMB->MaxDataCount = cpu_to_le16(4000); /* BB find exact max SMB PDU from sess structure BB */ | 3239 | pSMB->MaxDataCount = cpu_to_le16(4000); /* BB find exact max SMB PDU from sess structure BB */ |
@@ -3147,7 +3243,7 @@ QPathInfoRetry: | |||
3147 | pSMB->Timeout = 0; | 3243 | pSMB->Timeout = 0; |
3148 | pSMB->Reserved2 = 0; | 3244 | pSMB->Reserved2 = 0; |
3149 | pSMB->ParameterOffset = cpu_to_le16(offsetof( | 3245 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
3150 | struct smb_com_transaction2_qpi_req ,InformationLevel) - 4); | 3246 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
3151 | pSMB->DataCount = 0; | 3247 | pSMB->DataCount = 0; |
3152 | pSMB->DataOffset = 0; | 3248 | pSMB->DataOffset = 0; |
3153 | pSMB->SetupCount = 1; | 3249 | pSMB->SetupCount = 1; |
@@ -3156,7 +3252,7 @@ QPathInfoRetry: | |||
3156 | byte_count = params + 1 /* pad */ ; | 3252 | byte_count = params + 1 /* pad */ ; |
3157 | pSMB->TotalParameterCount = cpu_to_le16(params); | 3253 | pSMB->TotalParameterCount = cpu_to_le16(params); |
3158 | pSMB->ParameterCount = pSMB->TotalParameterCount; | 3254 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
3159 | if(legacy) | 3255 | if (legacy) |
3160 | pSMB->InformationLevel = cpu_to_le16(SMB_INFO_STANDARD); | 3256 | pSMB->InformationLevel = cpu_to_le16(SMB_INFO_STANDARD); |
3161 | else | 3257 | else |
3162 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_ALL_INFO); | 3258 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_ALL_INFO); |
@@ -3173,16 +3269,18 @@ QPathInfoRetry: | |||
3173 | 3269 | ||
3174 | if (rc) /* BB add auto retry on EOPNOTSUPP? */ | 3270 | if (rc) /* BB add auto retry on EOPNOTSUPP? */ |
3175 | rc = -EIO; | 3271 | rc = -EIO; |
3176 | else if (!legacy && (pSMBr->ByteCount < 40)) | 3272 | else if (!legacy && (pSMBr->ByteCount < 40)) |
3177 | rc = -EIO; /* bad smb */ | 3273 | rc = -EIO; /* bad smb */ |
3178 | else if(legacy && (pSMBr->ByteCount < 24)) | 3274 | else if (legacy && (pSMBr->ByteCount < 24)) |
3179 | rc = -EIO; /* 24 or 26 expected but we do not read last field */ | 3275 | rc = -EIO; /* 24 or 26 expected but we do not read |
3180 | else if (pFindData){ | 3276 | last field */ |
3277 | else if (pFindData) { | ||
3181 | int size; | 3278 | int size; |
3182 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); | 3279 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
3183 | if(legacy) /* we do not read the last field, EAsize, fortunately | 3280 | if (legacy) /* we do not read the last field, EAsize, |
3184 | since it varies by subdialect and on Set vs. Get, is | 3281 | fortunately since it varies by subdialect |
3185 | two bytes or 4 bytes depending but we don't care here */ | 3282 | and on Set vs. Get, is two bytes or 4 |
3283 | bytes depending but we don't care here */ | ||
3186 | size = sizeof(FILE_INFO_STANDARD); | 3284 | size = sizeof(FILE_INFO_STANDARD); |
3187 | else | 3285 | else |
3188 | size = sizeof(FILE_ALL_INFO); | 3286 | size = sizeof(FILE_ALL_INFO); |
@@ -3226,24 +3324,24 @@ UnixQPathInfoRetry: | |||
3226 | PATH_MAX, nls_codepage, remap); | 3324 | PATH_MAX, nls_codepage, remap); |
3227 | name_len++; /* trailing null */ | 3325 | name_len++; /* trailing null */ |
3228 | name_len *= 2; | 3326 | name_len *= 2; |
3229 | } else { /* BB improve the check for buffer overruns BB */ | 3327 | } else { /* BB improve the check for buffer overruns BB */ |
3230 | name_len = strnlen(searchName, PATH_MAX); | 3328 | name_len = strnlen(searchName, PATH_MAX); |
3231 | name_len++; /* trailing null */ | 3329 | name_len++; /* trailing null */ |
3232 | strncpy(pSMB->FileName, searchName, name_len); | 3330 | strncpy(pSMB->FileName, searchName, name_len); |
3233 | } | 3331 | } |
3234 | 3332 | ||
3235 | params = 2 /* level */ + 4 /* reserved */ + name_len /* includes NUL */ ; | 3333 | params = 2 /* level */ + 4 /* reserved */ + name_len /* includes NUL */; |
3236 | pSMB->TotalDataCount = 0; | 3334 | pSMB->TotalDataCount = 0; |
3237 | pSMB->MaxParameterCount = cpu_to_le16(2); | 3335 | pSMB->MaxParameterCount = cpu_to_le16(2); |
3238 | /* BB find exact max SMB PDU from sess structure BB */ | 3336 | /* BB find exact max SMB PDU from sess structure BB */ |
3239 | pSMB->MaxDataCount = cpu_to_le16(4000); | 3337 | pSMB->MaxDataCount = cpu_to_le16(4000); |
3240 | pSMB->MaxSetupCount = 0; | 3338 | pSMB->MaxSetupCount = 0; |
3241 | pSMB->Reserved = 0; | 3339 | pSMB->Reserved = 0; |
3242 | pSMB->Flags = 0; | 3340 | pSMB->Flags = 0; |
3243 | pSMB->Timeout = 0; | 3341 | pSMB->Timeout = 0; |
3244 | pSMB->Reserved2 = 0; | 3342 | pSMB->Reserved2 = 0; |
3245 | pSMB->ParameterOffset = cpu_to_le16(offsetof( | 3343 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
3246 | struct smb_com_transaction2_qpi_req ,InformationLevel) - 4); | 3344 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
3247 | pSMB->DataCount = 0; | 3345 | pSMB->DataCount = 0; |
3248 | pSMB->DataOffset = 0; | 3346 | pSMB->DataOffset = 0; |
3249 | pSMB->SetupCount = 1; | 3347 | pSMB->SetupCount = 1; |
@@ -3303,12 +3401,11 @@ findUniqueRetry: | |||
3303 | 3401 | ||
3304 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { | 3402 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
3305 | name_len = | 3403 | name_len = |
3306 | cifsConvertToUCS((__le16 *) pSMB->FileName, searchName, PATH_MAX | 3404 | cifsConvertToUCS((__le16 *) pSMB->FileName, searchName, |
3307 | /* find define for this maxpathcomponent */ | 3405 | PATH_MAX, nls_codepage); |
3308 | , nls_codepage); | ||
3309 | name_len++; /* trailing null */ | 3406 | name_len++; /* trailing null */ |
3310 | name_len *= 2; | 3407 | name_len *= 2; |
3311 | } else { /* BB improve the check for buffer overruns BB */ | 3408 | } else { /* BB improve the check for buffer overruns BB */ |
3312 | name_len = strnlen(searchName, PATH_MAX); | 3409 | name_len = strnlen(searchName, PATH_MAX); |
3313 | name_len++; /* trailing null */ | 3410 | name_len++; /* trailing null */ |
3314 | strncpy(pSMB->FileName, searchName, name_len); | 3411 | strncpy(pSMB->FileName, searchName, name_len); |
@@ -3324,7 +3421,7 @@ findUniqueRetry: | |||
3324 | pSMB->Timeout = 0; | 3421 | pSMB->Timeout = 0; |
3325 | pSMB->Reserved2 = 0; | 3422 | pSMB->Reserved2 = 0; |
3326 | pSMB->ParameterOffset = cpu_to_le16( | 3423 | pSMB->ParameterOffset = cpu_to_le16( |
3327 | offsetof(struct smb_com_transaction2_ffirst_req,InformationLevel) - 4); | 3424 | offsetof(struct smb_com_transaction2_ffirst_req, InformationLevel)-4); |
3328 | pSMB->DataCount = 0; | 3425 | pSMB->DataCount = 0; |
3329 | pSMB->DataOffset = 0; | 3426 | pSMB->DataOffset = 0; |
3330 | pSMB->SetupCount = 1; /* one byte, no need to le convert */ | 3427 | pSMB->SetupCount = 1; /* one byte, no need to le convert */ |
@@ -3364,10 +3461,10 @@ findUniqueRetry: | |||
3364 | /* xid, tcon, searchName and codepage are input parms, rest are returned */ | 3461 | /* xid, tcon, searchName and codepage are input parms, rest are returned */ |
3365 | int | 3462 | int |
3366 | CIFSFindFirst(const int xid, struct cifsTconInfo *tcon, | 3463 | CIFSFindFirst(const int xid, struct cifsTconInfo *tcon, |
3367 | const char *searchName, | 3464 | const char *searchName, |
3368 | const struct nls_table *nls_codepage, | 3465 | const struct nls_table *nls_codepage, |
3369 | __u16 * pnetfid, | 3466 | __u16 *pnetfid, |
3370 | struct cifs_search_info * psrch_inf, int remap, const char dirsep) | 3467 | struct cifs_search_info *psrch_inf, int remap, const char dirsep) |
3371 | { | 3468 | { |
3372 | /* level 257 SMB_ */ | 3469 | /* level 257 SMB_ */ |
3373 | TRANSACTION2_FFIRST_REQ *pSMB = NULL; | 3470 | TRANSACTION2_FFIRST_REQ *pSMB = NULL; |
@@ -3378,7 +3475,7 @@ CIFSFindFirst(const int xid, struct cifsTconInfo *tcon, | |||
3378 | int name_len; | 3475 | int name_len; |
3379 | __u16 params, byte_count; | 3476 | __u16 params, byte_count; |
3380 | 3477 | ||
3381 | cFYI(1, ("In FindFirst for %s",searchName)); | 3478 | cFYI(1, ("In FindFirst for %s", searchName)); |
3382 | 3479 | ||
3383 | findFirstRetry: | 3480 | findFirstRetry: |
3384 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, | 3481 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
@@ -3388,7 +3485,7 @@ findFirstRetry: | |||
3388 | 3485 | ||
3389 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { | 3486 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
3390 | name_len = | 3487 | name_len = |
3391 | cifsConvertToUCS((__le16 *) pSMB->FileName,searchName, | 3488 | cifsConvertToUCS((__le16 *) pSMB->FileName, searchName, |
3392 | PATH_MAX, nls_codepage, remap); | 3489 | PATH_MAX, nls_codepage, remap); |
3393 | /* We can not add the asterik earlier in case | 3490 | /* We can not add the asterik earlier in case |
3394 | it got remapped to 0xF03A as if it were part of the | 3491 | it got remapped to 0xF03A as if it were part of the |
@@ -3405,7 +3502,7 @@ findFirstRetry: | |||
3405 | } else { /* BB add check for overrun of SMB buf BB */ | 3502 | } else { /* BB add check for overrun of SMB buf BB */ |
3406 | name_len = strnlen(searchName, PATH_MAX); | 3503 | name_len = strnlen(searchName, PATH_MAX); |
3407 | /* BB fix here and in unicode clause above ie | 3504 | /* BB fix here and in unicode clause above ie |
3408 | if(name_len > buffersize-header) | 3505 | if (name_len > buffersize-header) |
3409 | free buffer exit; BB */ | 3506 | free buffer exit; BB */ |
3410 | strncpy(pSMB->FileName, searchName, name_len); | 3507 | strncpy(pSMB->FileName, searchName, name_len); |
3411 | pSMB->FileName[name_len] = dirsep; | 3508 | pSMB->FileName[name_len] = dirsep; |
@@ -3438,8 +3535,8 @@ findFirstRetry: | |||
3438 | pSMB->SearchAttributes = | 3535 | pSMB->SearchAttributes = |
3439 | cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM | | 3536 | cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM | |
3440 | ATTR_DIRECTORY); | 3537 | ATTR_DIRECTORY); |
3441 | pSMB->SearchCount= cpu_to_le16(CIFSMaxBufSize/sizeof(FILE_UNIX_INFO)); | 3538 | pSMB->SearchCount = cpu_to_le16(CIFSMaxBufSize/sizeof(FILE_UNIX_INFO)); |
3442 | pSMB->SearchFlags = cpu_to_le16(CIFS_SEARCH_CLOSE_AT_END | | 3539 | pSMB->SearchFlags = cpu_to_le16(CIFS_SEARCH_CLOSE_AT_END | |
3443 | CIFS_SEARCH_RETURN_RESUME); | 3540 | CIFS_SEARCH_RETURN_RESUME); |
3444 | pSMB->InformationLevel = cpu_to_le16(psrch_inf->info_level); | 3541 | pSMB->InformationLevel = cpu_to_le16(psrch_inf->info_level); |
3445 | 3542 | ||
@@ -3466,7 +3563,7 @@ findFirstRetry: | |||
3466 | } else { /* decode response */ | 3563 | } else { /* decode response */ |
3467 | /* BB remember to free buffer if error BB */ | 3564 | /* BB remember to free buffer if error BB */ |
3468 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); | 3565 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
3469 | if(rc == 0) { | 3566 | if (rc == 0) { |
3470 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) | 3567 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) |
3471 | psrch_inf->unicode = TRUE; | 3568 | psrch_inf->unicode = TRUE; |
3472 | else | 3569 | else |
@@ -3474,18 +3571,19 @@ findFirstRetry: | |||
3474 | 3571 | ||
3475 | psrch_inf->ntwrk_buf_start = (char *)pSMBr; | 3572 | psrch_inf->ntwrk_buf_start = (char *)pSMBr; |
3476 | psrch_inf->smallBuf = 0; | 3573 | psrch_inf->smallBuf = 0; |
3477 | psrch_inf->srch_entries_start = | 3574 | psrch_inf->srch_entries_start = |
3478 | (char *) &pSMBr->hdr.Protocol + | 3575 | (char *) &pSMBr->hdr.Protocol + |
3479 | le16_to_cpu(pSMBr->t2.DataOffset); | 3576 | le16_to_cpu(pSMBr->t2.DataOffset); |
3480 | parms = (T2_FFIRST_RSP_PARMS *)((char *) &pSMBr->hdr.Protocol + | 3577 | parms = (T2_FFIRST_RSP_PARMS *)((char *) &pSMBr->hdr.Protocol + |
3481 | le16_to_cpu(pSMBr->t2.ParameterOffset)); | 3578 | le16_to_cpu(pSMBr->t2.ParameterOffset)); |
3482 | 3579 | ||
3483 | if(parms->EndofSearch) | 3580 | if (parms->EndofSearch) |
3484 | psrch_inf->endOfSearch = TRUE; | 3581 | psrch_inf->endOfSearch = TRUE; |
3485 | else | 3582 | else |
3486 | psrch_inf->endOfSearch = FALSE; | 3583 | psrch_inf->endOfSearch = FALSE; |
3487 | 3584 | ||
3488 | psrch_inf->entries_in_buffer = le16_to_cpu(parms->SearchCount); | 3585 | psrch_inf->entries_in_buffer = |
3586 | le16_to_cpu(parms->SearchCount); | ||
3489 | psrch_inf->index_of_last_entry = 2 /* skip . and .. */ + | 3587 | psrch_inf->index_of_last_entry = 2 /* skip . and .. */ + |
3490 | psrch_inf->entries_in_buffer; | 3588 | psrch_inf->entries_in_buffer; |
3491 | *pnetfid = parms->SearchHandle; | 3589 | *pnetfid = parms->SearchHandle; |
@@ -3498,7 +3596,7 @@ findFirstRetry: | |||
3498 | } | 3596 | } |
3499 | 3597 | ||
3500 | int CIFSFindNext(const int xid, struct cifsTconInfo *tcon, | 3598 | int CIFSFindNext(const int xid, struct cifsTconInfo *tcon, |
3501 | __u16 searchHandle, struct cifs_search_info * psrch_inf) | 3599 | __u16 searchHandle, struct cifs_search_info *psrch_inf) |
3502 | { | 3600 | { |
3503 | TRANSACTION2_FNEXT_REQ *pSMB = NULL; | 3601 | TRANSACTION2_FNEXT_REQ *pSMB = NULL; |
3504 | TRANSACTION2_FNEXT_RSP *pSMBr = NULL; | 3602 | TRANSACTION2_FNEXT_RSP *pSMBr = NULL; |
@@ -3510,7 +3608,7 @@ int CIFSFindNext(const int xid, struct cifsTconInfo *tcon, | |||
3510 | 3608 | ||
3511 | cFYI(1, ("In FindNext")); | 3609 | cFYI(1, ("In FindNext")); |
3512 | 3610 | ||
3513 | if(psrch_inf->endOfSearch == TRUE) | 3611 | if (psrch_inf->endOfSearch == TRUE) |
3514 | return -ENOENT; | 3612 | return -ENOENT; |
3515 | 3613 | ||
3516 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, | 3614 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
@@ -3518,12 +3616,13 @@ int CIFSFindNext(const int xid, struct cifsTconInfo *tcon, | |||
3518 | if (rc) | 3616 | if (rc) |
3519 | return rc; | 3617 | return rc; |
3520 | 3618 | ||
3521 | params = 14; /* includes 2 bytes of null string, converted to LE below */ | 3619 | params = 14; /* includes 2 bytes of null string, converted to LE below*/ |
3522 | byte_count = 0; | 3620 | byte_count = 0; |
3523 | pSMB->TotalDataCount = 0; /* no EAs */ | 3621 | pSMB->TotalDataCount = 0; /* no EAs */ |
3524 | pSMB->MaxParameterCount = cpu_to_le16(8); | 3622 | pSMB->MaxParameterCount = cpu_to_le16(8); |
3525 | pSMB->MaxDataCount = | 3623 | pSMB->MaxDataCount = |
3526 | cpu_to_le16((tcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE) & 0xFFFFFF00); | 3624 | cpu_to_le16((tcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE) & |
3625 | 0xFFFFFF00); | ||
3527 | pSMB->MaxSetupCount = 0; | 3626 | pSMB->MaxSetupCount = 0; |
3528 | pSMB->Reserved = 0; | 3627 | pSMB->Reserved = 0; |
3529 | pSMB->Flags = 0; | 3628 | pSMB->Flags = 0; |
@@ -3539,15 +3638,6 @@ int CIFSFindNext(const int xid, struct cifsTconInfo *tcon, | |||
3539 | pSMB->SearchHandle = searchHandle; /* always kept as le */ | 3638 | pSMB->SearchHandle = searchHandle; /* always kept as le */ |
3540 | pSMB->SearchCount = | 3639 | pSMB->SearchCount = |
3541 | cpu_to_le16(CIFSMaxBufSize / sizeof (FILE_UNIX_INFO)); | 3640 | cpu_to_le16(CIFSMaxBufSize / sizeof (FILE_UNIX_INFO)); |
3542 | /* test for Unix extensions */ | ||
3543 | /* if (tcon->ses->capabilities & CAP_UNIX) { | ||
3544 | pSMB->InformationLevel = cpu_to_le16(SMB_FIND_FILE_UNIX); | ||
3545 | psrch_inf->info_level = SMB_FIND_FILE_UNIX; | ||
3546 | } else { | ||
3547 | pSMB->InformationLevel = | ||
3548 | cpu_to_le16(SMB_FIND_FILE_DIRECTORY_INFO); | ||
3549 | psrch_inf->info_level = SMB_FIND_FILE_DIRECTORY_INFO; | ||
3550 | } */ | ||
3551 | pSMB->InformationLevel = cpu_to_le16(psrch_inf->info_level); | 3641 | pSMB->InformationLevel = cpu_to_le16(psrch_inf->info_level); |
3552 | pSMB->ResumeKey = psrch_inf->resume_key; | 3642 | pSMB->ResumeKey = psrch_inf->resume_key; |
3553 | pSMB->SearchFlags = | 3643 | pSMB->SearchFlags = |
@@ -3555,7 +3645,7 @@ int CIFSFindNext(const int xid, struct cifsTconInfo *tcon, | |||
3555 | 3645 | ||
3556 | name_len = psrch_inf->resume_name_len; | 3646 | name_len = psrch_inf->resume_name_len; |
3557 | params += name_len; | 3647 | params += name_len; |
3558 | if(name_len < PATH_MAX) { | 3648 | if (name_len < PATH_MAX) { |
3559 | memcpy(pSMB->ResumeFileName, psrch_inf->presume_name, name_len); | 3649 | memcpy(pSMB->ResumeFileName, psrch_inf->presume_name, name_len); |
3560 | byte_count += name_len; | 3650 | byte_count += name_len; |
3561 | /* 14 byte parm len above enough for 2 byte null terminator */ | 3651 | /* 14 byte parm len above enough for 2 byte null terminator */ |
@@ -3570,20 +3660,20 @@ int CIFSFindNext(const int xid, struct cifsTconInfo *tcon, | |||
3570 | pSMB->ParameterCount = pSMB->TotalParameterCount; | 3660 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
3571 | pSMB->hdr.smb_buf_length += byte_count; | 3661 | pSMB->hdr.smb_buf_length += byte_count; |
3572 | pSMB->ByteCount = cpu_to_le16(byte_count); | 3662 | pSMB->ByteCount = cpu_to_le16(byte_count); |
3573 | 3663 | ||
3574 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, | 3664 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
3575 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); | 3665 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
3576 | cifs_stats_inc(&tcon->num_fnext); | 3666 | cifs_stats_inc(&tcon->num_fnext); |
3577 | if (rc) { | 3667 | if (rc) { |
3578 | if (rc == -EBADF) { | 3668 | if (rc == -EBADF) { |
3579 | psrch_inf->endOfSearch = TRUE; | 3669 | psrch_inf->endOfSearch = TRUE; |
3580 | rc = 0; /* search probably was closed at end of search above */ | 3670 | rc = 0; /* search probably was closed at end of search*/ |
3581 | } else | 3671 | } else |
3582 | cFYI(1, ("FindNext returned = %d", rc)); | 3672 | cFYI(1, ("FindNext returned = %d", rc)); |
3583 | } else { /* decode response */ | 3673 | } else { /* decode response */ |
3584 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); | 3674 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
3585 | 3675 | ||
3586 | if(rc == 0) { | 3676 | if (rc == 0) { |
3587 | /* BB fixme add lock for file (srch_info) struct here */ | 3677 | /* BB fixme add lock for file (srch_info) struct here */ |
3588 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) | 3678 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) |
3589 | psrch_inf->unicode = TRUE; | 3679 | psrch_inf->unicode = TRUE; |
@@ -3594,7 +3684,7 @@ int CIFSFindNext(const int xid, struct cifsTconInfo *tcon, | |||
3594 | parms = (T2_FNEXT_RSP_PARMS *)response_data; | 3684 | parms = (T2_FNEXT_RSP_PARMS *)response_data; |
3595 | response_data = (char *)&pSMBr->hdr.Protocol + | 3685 | response_data = (char *)&pSMBr->hdr.Protocol + |
3596 | le16_to_cpu(pSMBr->t2.DataOffset); | 3686 | le16_to_cpu(pSMBr->t2.DataOffset); |
3597 | if(psrch_inf->smallBuf) | 3687 | if (psrch_inf->smallBuf) |
3598 | cifs_small_buf_release( | 3688 | cifs_small_buf_release( |
3599 | psrch_inf->ntwrk_buf_start); | 3689 | psrch_inf->ntwrk_buf_start); |
3600 | else | 3690 | else |
@@ -3602,15 +3692,16 @@ int CIFSFindNext(const int xid, struct cifsTconInfo *tcon, | |||
3602 | psrch_inf->srch_entries_start = response_data; | 3692 | psrch_inf->srch_entries_start = response_data; |
3603 | psrch_inf->ntwrk_buf_start = (char *)pSMB; | 3693 | psrch_inf->ntwrk_buf_start = (char *)pSMB; |
3604 | psrch_inf->smallBuf = 0; | 3694 | psrch_inf->smallBuf = 0; |
3605 | if(parms->EndofSearch) | 3695 | if (parms->EndofSearch) |
3606 | psrch_inf->endOfSearch = TRUE; | 3696 | psrch_inf->endOfSearch = TRUE; |
3607 | else | 3697 | else |
3608 | psrch_inf->endOfSearch = FALSE; | 3698 | psrch_inf->endOfSearch = FALSE; |
3609 | 3699 | psrch_inf->entries_in_buffer = | |
3610 | psrch_inf->entries_in_buffer = le16_to_cpu(parms->SearchCount); | 3700 | le16_to_cpu(parms->SearchCount); |
3611 | psrch_inf->index_of_last_entry += | 3701 | psrch_inf->index_of_last_entry += |
3612 | psrch_inf->entries_in_buffer; | 3702 | psrch_inf->entries_in_buffer; |
3613 | /* cFYI(1,("fnxt2 entries in buf %d index_of_last %d",psrch_inf->entries_in_buffer,psrch_inf->index_of_last_entry)); */ | 3703 | /* cFYI(1,("fnxt2 entries in buf %d index_of_last %d", |
3704 | psrch_inf->entries_in_buffer, psrch_inf->index_of_last_entry)); */ | ||
3614 | 3705 | ||
3615 | /* BB fixme add unlock here */ | 3706 | /* BB fixme add unlock here */ |
3616 | } | 3707 | } |
@@ -3625,12 +3716,12 @@ int CIFSFindNext(const int xid, struct cifsTconInfo *tcon, | |||
3625 | FNext2_err_exit: | 3716 | FNext2_err_exit: |
3626 | if (rc != 0) | 3717 | if (rc != 0) |
3627 | cifs_buf_release(pSMB); | 3718 | cifs_buf_release(pSMB); |
3628 | |||
3629 | return rc; | 3719 | return rc; |
3630 | } | 3720 | } |
3631 | 3721 | ||
3632 | int | 3722 | int |
3633 | CIFSFindClose(const int xid, struct cifsTconInfo *tcon, const __u16 searchHandle) | 3723 | CIFSFindClose(const int xid, struct cifsTconInfo *tcon, |
3724 | const __u16 searchHandle) | ||
3634 | { | 3725 | { |
3635 | int rc = 0; | 3726 | int rc = 0; |
3636 | FINDCLOSE_REQ *pSMB = NULL; | 3727 | FINDCLOSE_REQ *pSMB = NULL; |
@@ -3642,7 +3733,7 @@ CIFSFindClose(const int xid, struct cifsTconInfo *tcon, const __u16 searchHandle | |||
3642 | 3733 | ||
3643 | /* no sense returning error if session restarted | 3734 | /* no sense returning error if session restarted |
3644 | as file handle has been closed */ | 3735 | as file handle has been closed */ |
3645 | if(rc == -EAGAIN) | 3736 | if (rc == -EAGAIN) |
3646 | return 0; | 3737 | return 0; |
3647 | if (rc) | 3738 | if (rc) |
3648 | return rc; | 3739 | return rc; |
@@ -3667,9 +3758,9 @@ CIFSFindClose(const int xid, struct cifsTconInfo *tcon, const __u16 searchHandle | |||
3667 | 3758 | ||
3668 | int | 3759 | int |
3669 | CIFSGetSrvInodeNumber(const int xid, struct cifsTconInfo *tcon, | 3760 | CIFSGetSrvInodeNumber(const int xid, struct cifsTconInfo *tcon, |
3670 | const unsigned char *searchName, | 3761 | const unsigned char *searchName, |
3671 | __u64 * inode_number, | 3762 | __u64 * inode_number, |
3672 | const struct nls_table *nls_codepage, int remap) | 3763 | const struct nls_table *nls_codepage, int remap) |
3673 | { | 3764 | { |
3674 | int rc = 0; | 3765 | int rc = 0; |
3675 | TRANSACTION2_QPI_REQ *pSMB = NULL; | 3766 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
@@ -3677,24 +3768,23 @@ CIFSGetSrvInodeNumber(const int xid, struct cifsTconInfo *tcon, | |||
3677 | int name_len, bytes_returned; | 3768 | int name_len, bytes_returned; |
3678 | __u16 params, byte_count; | 3769 | __u16 params, byte_count; |
3679 | 3770 | ||
3680 | cFYI(1,("In GetSrvInodeNum for %s",searchName)); | 3771 | cFYI(1, ("In GetSrvInodeNum for %s", searchName)); |
3681 | if(tcon == NULL) | 3772 | if (tcon == NULL) |
3682 | return -ENODEV; | 3773 | return -ENODEV; |
3683 | 3774 | ||
3684 | GetInodeNumberRetry: | 3775 | GetInodeNumberRetry: |
3685 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, | 3776 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
3686 | (void **) &pSMBr); | 3777 | (void **) &pSMBr); |
3687 | if (rc) | 3778 | if (rc) |
3688 | return rc; | 3779 | return rc; |
3689 | 3780 | ||
3690 | |||
3691 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { | 3781 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
3692 | name_len = | 3782 | name_len = |
3693 | cifsConvertToUCS((__le16 *) pSMB->FileName, searchName, | 3783 | cifsConvertToUCS((__le16 *) pSMB->FileName, searchName, |
3694 | PATH_MAX,nls_codepage, remap); | 3784 | PATH_MAX, nls_codepage, remap); |
3695 | name_len++; /* trailing null */ | 3785 | name_len++; /* trailing null */ |
3696 | name_len *= 2; | 3786 | name_len *= 2; |
3697 | } else { /* BB improve the check for buffer overruns BB */ | 3787 | } else { /* BB improve the check for buffer overruns BB */ |
3698 | name_len = strnlen(searchName, PATH_MAX); | 3788 | name_len = strnlen(searchName, PATH_MAX); |
3699 | name_len++; /* trailing null */ | 3789 | name_len++; /* trailing null */ |
3700 | strncpy(pSMB->FileName, searchName, name_len); | 3790 | strncpy(pSMB->FileName, searchName, name_len); |
@@ -3711,7 +3801,7 @@ GetInodeNumberRetry: | |||
3711 | pSMB->Timeout = 0; | 3801 | pSMB->Timeout = 0; |
3712 | pSMB->Reserved2 = 0; | 3802 | pSMB->Reserved2 = 0; |
3713 | pSMB->ParameterOffset = cpu_to_le16(offsetof( | 3803 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
3714 | struct smb_com_transaction2_qpi_req ,InformationLevel) - 4); | 3804 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
3715 | pSMB->DataCount = 0; | 3805 | pSMB->DataCount = 0; |
3716 | pSMB->DataOffset = 0; | 3806 | pSMB->DataOffset = 0; |
3717 | pSMB->SetupCount = 1; | 3807 | pSMB->SetupCount = 1; |
@@ -3737,12 +3827,12 @@ GetInodeNumberRetry: | |||
3737 | /* If rc should we check for EOPNOSUPP and | 3827 | /* If rc should we check for EOPNOSUPP and |
3738 | disable the srvino flag? or in caller? */ | 3828 | disable the srvino flag? or in caller? */ |
3739 | rc = -EIO; /* bad smb */ | 3829 | rc = -EIO; /* bad smb */ |
3740 | else { | 3830 | else { |
3741 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); | 3831 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
3742 | __u16 count = le16_to_cpu(pSMBr->t2.DataCount); | 3832 | __u16 count = le16_to_cpu(pSMBr->t2.DataCount); |
3743 | struct file_internal_info * pfinfo; | 3833 | struct file_internal_info *pfinfo; |
3744 | /* BB Do we need a cast or hash here ? */ | 3834 | /* BB Do we need a cast or hash here ? */ |
3745 | if(count < 8) { | 3835 | if (count < 8) { |
3746 | cFYI(1, ("Illegal size ret in QryIntrnlInf")); | 3836 | cFYI(1, ("Illegal size ret in QryIntrnlInf")); |
3747 | rc = -EIO; | 3837 | rc = -EIO; |
3748 | goto GetInodeNumOut; | 3838 | goto GetInodeNumOut; |
@@ -3769,12 +3859,12 @@ CIFSGetDFSRefer(const int xid, struct cifsSesInfo *ses, | |||
3769 | /* TRANS2_GET_DFS_REFERRAL */ | 3859 | /* TRANS2_GET_DFS_REFERRAL */ |
3770 | TRANSACTION2_GET_DFS_REFER_REQ *pSMB = NULL; | 3860 | TRANSACTION2_GET_DFS_REFER_REQ *pSMB = NULL; |
3771 | TRANSACTION2_GET_DFS_REFER_RSP *pSMBr = NULL; | 3861 | TRANSACTION2_GET_DFS_REFER_RSP *pSMBr = NULL; |
3772 | struct dfs_referral_level_3 * referrals = NULL; | 3862 | struct dfs_referral_level_3 *referrals = NULL; |
3773 | int rc = 0; | 3863 | int rc = 0; |
3774 | int bytes_returned; | 3864 | int bytes_returned; |
3775 | int name_len; | 3865 | int name_len; |
3776 | unsigned int i; | 3866 | unsigned int i; |
3777 | char * temp; | 3867 | char *temp; |
3778 | __u16 params, byte_count; | 3868 | __u16 params, byte_count; |
3779 | *number_of_UNC_in_array = 0; | 3869 | *number_of_UNC_in_array = 0; |
3780 | *targetUNCs = NULL; | 3870 | *targetUNCs = NULL; |
@@ -3787,8 +3877,8 @@ getDFSRetry: | |||
3787 | (void **) &pSMBr); | 3877 | (void **) &pSMBr); |
3788 | if (rc) | 3878 | if (rc) |
3789 | return rc; | 3879 | return rc; |
3790 | 3880 | ||
3791 | /* server pointer checked in called function, | 3881 | /* server pointer checked in called function, |
3792 | but should never be null here anyway */ | 3882 | but should never be null here anyway */ |
3793 | pSMB->hdr.Mid = GetNextMid(ses->server); | 3883 | pSMB->hdr.Mid = GetNextMid(ses->server); |
3794 | pSMB->hdr.Tid = ses->ipc_tid; | 3884 | pSMB->hdr.Tid = ses->ipc_tid; |
@@ -3807,19 +3897,19 @@ getDFSRetry: | |||
3807 | searchName, PATH_MAX, nls_codepage, remap); | 3897 | searchName, PATH_MAX, nls_codepage, remap); |
3808 | name_len++; /* trailing null */ | 3898 | name_len++; /* trailing null */ |
3809 | name_len *= 2; | 3899 | name_len *= 2; |
3810 | } else { /* BB improve the check for buffer overruns BB */ | 3900 | } else { /* BB improve the check for buffer overruns BB */ |
3811 | name_len = strnlen(searchName, PATH_MAX); | 3901 | name_len = strnlen(searchName, PATH_MAX); |
3812 | name_len++; /* trailing null */ | 3902 | name_len++; /* trailing null */ |
3813 | strncpy(pSMB->RequestFileName, searchName, name_len); | 3903 | strncpy(pSMB->RequestFileName, searchName, name_len); |
3814 | } | 3904 | } |
3815 | 3905 | ||
3816 | if(ses->server) { | 3906 | if (ses->server) { |
3817 | if(ses->server->secMode & | 3907 | if (ses->server->secMode & |
3818 | (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) | 3908 | (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) |
3819 | pSMB->hdr.Flags2 |= SMBFLG2_SECURITY_SIGNATURE; | 3909 | pSMB->hdr.Flags2 |= SMBFLG2_SECURITY_SIGNATURE; |
3820 | } | 3910 | } |
3821 | 3911 | ||
3822 | pSMB->hdr.Uid = ses->Suid; | 3912 | pSMB->hdr.Uid = ses->Suid; |
3823 | 3913 | ||
3824 | params = 2 /* level */ + name_len /*includes null */ ; | 3914 | params = 2 /* level */ + name_len /*includes null */ ; |
3825 | pSMB->TotalDataCount = 0; | 3915 | pSMB->TotalDataCount = 0; |
@@ -3833,7 +3923,7 @@ getDFSRetry: | |||
3833 | pSMB->Timeout = 0; | 3923 | pSMB->Timeout = 0; |
3834 | pSMB->Reserved2 = 0; | 3924 | pSMB->Reserved2 = 0; |
3835 | pSMB->ParameterOffset = cpu_to_le16(offsetof( | 3925 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
3836 | struct smb_com_transaction2_get_dfs_refer_req, MaxReferralLevel) - 4); | 3926 | struct smb_com_transaction2_get_dfs_refer_req, MaxReferralLevel) - 4); |
3837 | pSMB->SetupCount = 1; | 3927 | pSMB->SetupCount = 1; |
3838 | pSMB->Reserved3 = 0; | 3928 | pSMB->Reserved3 = 0; |
3839 | pSMB->SubCommand = cpu_to_le16(TRANS2_GET_DFS_REFERRAL); | 3929 | pSMB->SubCommand = cpu_to_le16(TRANS2_GET_DFS_REFERRAL); |
@@ -3852,74 +3942,87 @@ getDFSRetry: | |||
3852 | /* BB Add logic to parse referrals here */ | 3942 | /* BB Add logic to parse referrals here */ |
3853 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); | 3943 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
3854 | 3944 | ||
3855 | if (rc || (pSMBr->ByteCount < 17)) /* BB also check enough total bytes returned */ | 3945 | /* BB Also check if enough total bytes returned? */ |
3946 | if (rc || (pSMBr->ByteCount < 17)) | ||
3856 | rc = -EIO; /* bad smb */ | 3947 | rc = -EIO; /* bad smb */ |
3857 | else { | 3948 | else { |
3858 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); | 3949 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
3859 | __u16 data_count = le16_to_cpu(pSMBr->t2.DataCount); | 3950 | __u16 data_count = le16_to_cpu(pSMBr->t2.DataCount); |
3860 | 3951 | ||
3861 | cFYI(1, | 3952 | cFYI(1, |
3862 | ("Decoding GetDFSRefer response. BCC: %d Offset %d", | 3953 | ("Decoding GetDFSRefer response BCC: %d Offset %d", |
3863 | pSMBr->ByteCount, data_offset)); | 3954 | pSMBr->ByteCount, data_offset)); |
3864 | referrals = | 3955 | referrals = |
3865 | (struct dfs_referral_level_3 *) | 3956 | (struct dfs_referral_level_3 *) |
3866 | (8 /* sizeof start of data block */ + | 3957 | (8 /* sizeof start of data block */ + |
3867 | data_offset + | 3958 | data_offset + |
3868 | (char *) &pSMBr->hdr.Protocol); | 3959 | (char *) &pSMBr->hdr.Protocol); |
3869 | cFYI(1,("num_referrals: %d dfs flags: 0x%x ... \nfor referral one refer size: 0x%x srv type: 0x%x refer flags: 0x%x ttl: 0x%x", | 3960 | cFYI(1, ("num_referrals: %d dfs flags: 0x%x ... \n" |
3870 | le16_to_cpu(pSMBr->NumberOfReferrals),le16_to_cpu(pSMBr->DFSFlags), le16_to_cpu(referrals->ReferralSize),le16_to_cpu(referrals->ServerType),le16_to_cpu(referrals->ReferralFlags),le16_to_cpu(referrals->TimeToLive))); | 3961 | "for referral one refer size: 0x%x srv " |
3962 | "type: 0x%x refer flags: 0x%x ttl: 0x%x", | ||
3963 | le16_to_cpu(pSMBr->NumberOfReferrals), | ||
3964 | le16_to_cpu(pSMBr->DFSFlags), | ||
3965 | le16_to_cpu(referrals->ReferralSize), | ||
3966 | le16_to_cpu(referrals->ServerType), | ||
3967 | le16_to_cpu(referrals->ReferralFlags), | ||
3968 | le16_to_cpu(referrals->TimeToLive))); | ||
3871 | /* BB This field is actually two bytes in from start of | 3969 | /* BB This field is actually two bytes in from start of |
3872 | data block so we could do safety check that DataBlock | 3970 | data block so we could do safety check that DataBlock |
3873 | begins at address of pSMBr->NumberOfReferrals */ | 3971 | begins at address of pSMBr->NumberOfReferrals */ |
3874 | *number_of_UNC_in_array = le16_to_cpu(pSMBr->NumberOfReferrals); | 3972 | *number_of_UNC_in_array = |
3973 | le16_to_cpu(pSMBr->NumberOfReferrals); | ||
3875 | 3974 | ||
3876 | /* BB Fix below so can return more than one referral */ | 3975 | /* BB Fix below so can return more than one referral */ |
3877 | if(*number_of_UNC_in_array > 1) | 3976 | if (*number_of_UNC_in_array > 1) |
3878 | *number_of_UNC_in_array = 1; | 3977 | *number_of_UNC_in_array = 1; |
3879 | 3978 | ||
3880 | /* get the length of the strings describing refs */ | 3979 | /* get the length of the strings describing refs */ |
3881 | name_len = 0; | 3980 | name_len = 0; |
3882 | for(i=0;i<*number_of_UNC_in_array;i++) { | 3981 | for (i = 0; i < *number_of_UNC_in_array; i++) { |
3883 | /* make sure that DfsPathOffset not past end */ | 3982 | /* make sure that DfsPathOffset not past end */ |
3884 | __u16 offset = le16_to_cpu(referrals->DfsPathOffset); | 3983 | __u16 offset = |
3984 | le16_to_cpu(referrals->DfsPathOffset); | ||
3885 | if (offset > data_count) { | 3985 | if (offset > data_count) { |
3886 | /* if invalid referral, stop here and do | 3986 | /* if invalid referral, stop here and do |
3887 | not try to copy any more */ | 3987 | not try to copy any more */ |
3888 | *number_of_UNC_in_array = i; | 3988 | *number_of_UNC_in_array = i; |
3889 | break; | 3989 | break; |
3890 | } | 3990 | } |
3891 | temp = ((char *)referrals) + offset; | 3991 | temp = ((char *)referrals) + offset; |
3892 | 3992 | ||
3893 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) { | 3993 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) { |
3894 | name_len += UniStrnlen((wchar_t *)temp,data_count); | 3994 | name_len += UniStrnlen((wchar_t *)temp, |
3995 | data_count); | ||
3895 | } else { | 3996 | } else { |
3896 | name_len += strnlen(temp,data_count); | 3997 | name_len += strnlen(temp, data_count); |
3897 | } | 3998 | } |
3898 | referrals++; | 3999 | referrals++; |
3899 | /* BB add check that referral pointer does not fall off end PDU */ | 4000 | /* BB add check that referral pointer does |
3900 | 4001 | not fall off end PDU */ | |
3901 | } | 4002 | } |
3902 | /* BB add check for name_len bigger than bcc */ | 4003 | /* BB add check for name_len bigger than bcc */ |
3903 | *targetUNCs = | 4004 | *targetUNCs = |
3904 | kmalloc(name_len+1+ (*number_of_UNC_in_array),GFP_KERNEL); | 4005 | kmalloc(name_len+1+(*number_of_UNC_in_array), |
3905 | if(*targetUNCs == NULL) { | 4006 | GFP_KERNEL); |
4007 | if (*targetUNCs == NULL) { | ||
3906 | rc = -ENOMEM; | 4008 | rc = -ENOMEM; |
3907 | goto GetDFSRefExit; | 4009 | goto GetDFSRefExit; |
3908 | } | 4010 | } |
3909 | /* copy the ref strings */ | 4011 | /* copy the ref strings */ |
3910 | referrals = | 4012 | referrals = (struct dfs_referral_level_3 *) |
3911 | (struct dfs_referral_level_3 *) | 4013 | (8 /* sizeof data hdr */ + data_offset + |
3912 | (8 /* sizeof data hdr */ + | ||
3913 | data_offset + | ||
3914 | (char *) &pSMBr->hdr.Protocol); | 4014 | (char *) &pSMBr->hdr.Protocol); |
3915 | 4015 | ||
3916 | for(i=0;i<*number_of_UNC_in_array;i++) { | 4016 | for (i = 0; i < *number_of_UNC_in_array; i++) { |
3917 | temp = ((char *)referrals) + le16_to_cpu(referrals->DfsPathOffset); | 4017 | temp = ((char *)referrals) + |
4018 | le16_to_cpu(referrals->DfsPathOffset); | ||
3918 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) { | 4019 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) { |
3919 | cifs_strfromUCS_le(*targetUNCs, | 4020 | cifs_strfromUCS_le(*targetUNCs, |
3920 | (__le16 *) temp, name_len, nls_codepage); | 4021 | (__le16 *) temp, |
4022 | name_len, | ||
4023 | nls_codepage); | ||
3921 | } else { | 4024 | } else { |
3922 | strncpy(*targetUNCs,temp,name_len); | 4025 | strncpy(*targetUNCs, temp, name_len); |
3923 | } | 4026 | } |
3924 | /* BB update target_uncs pointers */ | 4027 | /* BB update target_uncs pointers */ |
3925 | referrals++; | 4028 | referrals++; |
@@ -3996,18 +4099,17 @@ oldQFSInfoRetry: | |||
3996 | rc = -EIO; /* bad smb */ | 4099 | rc = -EIO; /* bad smb */ |
3997 | else { | 4100 | else { |
3998 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); | 4101 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
3999 | cFYI(1,("qfsinf resp BCC: %d Offset %d", | 4102 | cFYI(1, ("qfsinf resp BCC: %d Offset %d", |
4000 | pSMBr->ByteCount, data_offset)); | 4103 | pSMBr->ByteCount, data_offset)); |
4001 | 4104 | ||
4002 | response_data = | 4105 | response_data = (FILE_SYSTEM_ALLOC_INFO *) |
4003 | (FILE_SYSTEM_ALLOC_INFO *) | ||
4004 | (((char *) &pSMBr->hdr.Protocol) + data_offset); | 4106 | (((char *) &pSMBr->hdr.Protocol) + data_offset); |
4005 | FSData->f_bsize = | 4107 | FSData->f_bsize = |
4006 | le16_to_cpu(response_data->BytesPerSector) * | 4108 | le16_to_cpu(response_data->BytesPerSector) * |
4007 | le32_to_cpu(response_data-> | 4109 | le32_to_cpu(response_data-> |
4008 | SectorsPerAllocationUnit); | 4110 | SectorsPerAllocationUnit); |
4009 | FSData->f_blocks = | 4111 | FSData->f_blocks = |
4010 | le32_to_cpu(response_data->TotalAllocationUnits); | 4112 | le32_to_cpu(response_data->TotalAllocationUnits); |
4011 | FSData->f_bfree = FSData->f_bavail = | 4113 | FSData->f_bfree = FSData->f_bavail = |
4012 | le32_to_cpu(response_data->FreeAllocationUnits); | 4114 | le32_to_cpu(response_data->FreeAllocationUnits); |
4013 | cFYI(1, | 4115 | cFYI(1, |
@@ -4056,7 +4158,7 @@ QFSInfoRetry: | |||
4056 | pSMB->TotalParameterCount = cpu_to_le16(params); | 4158 | pSMB->TotalParameterCount = cpu_to_le16(params); |
4057 | pSMB->ParameterCount = pSMB->TotalParameterCount; | 4159 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
4058 | pSMB->ParameterOffset = cpu_to_le16(offsetof( | 4160 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
4059 | struct smb_com_transaction2_qfsi_req, InformationLevel) - 4); | 4161 | struct smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
4060 | pSMB->DataCount = 0; | 4162 | pSMB->DataCount = 0; |
4061 | pSMB->DataOffset = 0; | 4163 | pSMB->DataOffset = 0; |
4062 | pSMB->SetupCount = 1; | 4164 | pSMB->SetupCount = 1; |
@@ -4071,7 +4173,7 @@ QFSInfoRetry: | |||
4071 | if (rc) { | 4173 | if (rc) { |
4072 | cFYI(1, ("Send error in QFSInfo = %d", rc)); | 4174 | cFYI(1, ("Send error in QFSInfo = %d", rc)); |
4073 | } else { /* decode response */ | 4175 | } else { /* decode response */ |
4074 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); | 4176 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
4075 | 4177 | ||
4076 | if (rc || (pSMBr->ByteCount < 24)) | 4178 | if (rc || (pSMBr->ByteCount < 24)) |
4077 | rc = -EIO; /* bad smb */ | 4179 | rc = -EIO; /* bad smb */ |
@@ -4136,7 +4238,7 @@ QFSAttributeRetry: | |||
4136 | pSMB->TotalParameterCount = cpu_to_le16(params); | 4238 | pSMB->TotalParameterCount = cpu_to_le16(params); |
4137 | pSMB->ParameterCount = pSMB->TotalParameterCount; | 4239 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
4138 | pSMB->ParameterOffset = cpu_to_le16(offsetof( | 4240 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
4139 | struct smb_com_transaction2_qfsi_req, InformationLevel) - 4); | 4241 | struct smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
4140 | pSMB->DataCount = 0; | 4242 | pSMB->DataCount = 0; |
4141 | pSMB->DataOffset = 0; | 4243 | pSMB->DataOffset = 0; |
4142 | pSMB->SetupCount = 1; | 4244 | pSMB->SetupCount = 1; |
@@ -4153,7 +4255,8 @@ QFSAttributeRetry: | |||
4153 | } else { /* decode response */ | 4255 | } else { /* decode response */ |
4154 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); | 4256 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
4155 | 4257 | ||
4156 | if (rc || (pSMBr->ByteCount < 13)) { /* BB also check enough bytes returned */ | 4258 | if (rc || (pSMBr->ByteCount < 13)) { |
4259 | /* BB also check if enough bytes returned */ | ||
4157 | rc = -EIO; /* bad smb */ | 4260 | rc = -EIO; /* bad smb */ |
4158 | } else { | 4261 | } else { |
4159 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); | 4262 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
@@ -4204,7 +4307,7 @@ QFSDeviceRetry: | |||
4204 | pSMB->TotalParameterCount = cpu_to_le16(params); | 4307 | pSMB->TotalParameterCount = cpu_to_le16(params); |
4205 | pSMB->ParameterCount = pSMB->TotalParameterCount; | 4308 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
4206 | pSMB->ParameterOffset = cpu_to_le16(offsetof( | 4309 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
4207 | struct smb_com_transaction2_qfsi_req, InformationLevel) - 4); | 4310 | struct smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
4208 | 4311 | ||
4209 | pSMB->DataCount = 0; | 4312 | pSMB->DataCount = 0; |
4210 | pSMB->DataOffset = 0; | 4313 | pSMB->DataOffset = 0; |
@@ -4274,8 +4377,8 @@ QFSUnixRetry: | |||
4274 | byte_count = params + 1 /* pad */ ; | 4377 | byte_count = params + 1 /* pad */ ; |
4275 | pSMB->ParameterCount = cpu_to_le16(params); | 4378 | pSMB->ParameterCount = cpu_to_le16(params); |
4276 | pSMB->TotalParameterCount = pSMB->ParameterCount; | 4379 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
4277 | pSMB->ParameterOffset = cpu_to_le16(offsetof(struct | 4380 | pSMB->ParameterOffset = cpu_to_le16(offsetof(struct |
4278 | smb_com_transaction2_qfsi_req, InformationLevel) - 4); | 4381 | smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
4279 | pSMB->SetupCount = 1; | 4382 | pSMB->SetupCount = 1; |
4280 | pSMB->Reserved3 = 0; | 4383 | pSMB->Reserved3 = 0; |
4281 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); | 4384 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
@@ -4335,7 +4438,8 @@ SETFSUnixRetry: | |||
4335 | pSMB->Flags = 0; | 4438 | pSMB->Flags = 0; |
4336 | pSMB->Timeout = 0; | 4439 | pSMB->Timeout = 0; |
4337 | pSMB->Reserved2 = 0; | 4440 | pSMB->Reserved2 = 0; |
4338 | param_offset = offsetof(struct smb_com_transaction2_setfsi_req, FileNum) - 4; | 4441 | param_offset = offsetof(struct smb_com_transaction2_setfsi_req, FileNum) |
4442 | - 4; | ||
4339 | offset = param_offset + params; | 4443 | offset = param_offset + params; |
4340 | 4444 | ||
4341 | pSMB->MaxParameterCount = cpu_to_le16(4); | 4445 | pSMB->MaxParameterCount = cpu_to_le16(4); |
@@ -4417,8 +4521,8 @@ QFSPosixRetry: | |||
4417 | byte_count = params + 1 /* pad */ ; | 4521 | byte_count = params + 1 /* pad */ ; |
4418 | pSMB->ParameterCount = cpu_to_le16(params); | 4522 | pSMB->ParameterCount = cpu_to_le16(params); |
4419 | pSMB->TotalParameterCount = pSMB->ParameterCount; | 4523 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
4420 | pSMB->ParameterOffset = cpu_to_le16(offsetof(struct | 4524 | pSMB->ParameterOffset = cpu_to_le16(offsetof(struct |
4421 | smb_com_transaction2_qfsi_req, InformationLevel) - 4); | 4525 | smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
4422 | pSMB->SetupCount = 1; | 4526 | pSMB->SetupCount = 1; |
4423 | pSMB->Reserved3 = 0; | 4527 | pSMB->Reserved3 = 0; |
4424 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); | 4528 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
@@ -4447,18 +4551,18 @@ QFSPosixRetry: | |||
4447 | le64_to_cpu(response_data->TotalBlocks); | 4551 | le64_to_cpu(response_data->TotalBlocks); |
4448 | FSData->f_bfree = | 4552 | FSData->f_bfree = |
4449 | le64_to_cpu(response_data->BlocksAvail); | 4553 | le64_to_cpu(response_data->BlocksAvail); |
4450 | if(response_data->UserBlocksAvail == cpu_to_le64(-1)) { | 4554 | if (response_data->UserBlocksAvail == cpu_to_le64(-1)) { |
4451 | FSData->f_bavail = FSData->f_bfree; | 4555 | FSData->f_bavail = FSData->f_bfree; |
4452 | } else { | 4556 | } else { |
4453 | FSData->f_bavail = | 4557 | FSData->f_bavail = |
4454 | le64_to_cpu(response_data->UserBlocksAvail); | 4558 | le64_to_cpu(response_data->UserBlocksAvail); |
4455 | } | 4559 | } |
4456 | if(response_data->TotalFileNodes != cpu_to_le64(-1)) | 4560 | if (response_data->TotalFileNodes != cpu_to_le64(-1)) |
4457 | FSData->f_files = | 4561 | FSData->f_files = |
4458 | le64_to_cpu(response_data->TotalFileNodes); | 4562 | le64_to_cpu(response_data->TotalFileNodes); |
4459 | if(response_data->FreeFileNodes != cpu_to_le64(-1)) | 4563 | if (response_data->FreeFileNodes != cpu_to_le64(-1)) |
4460 | FSData->f_ffree = | 4564 | FSData->f_ffree = |
4461 | le64_to_cpu(response_data->FreeFileNodes); | 4565 | le64_to_cpu(response_data->FreeFileNodes); |
4462 | } | 4566 | } |
4463 | } | 4567 | } |
4464 | cifs_buf_release(pSMB); | 4568 | cifs_buf_release(pSMB); |
@@ -4470,15 +4574,15 @@ QFSPosixRetry: | |||
4470 | } | 4574 | } |
4471 | 4575 | ||
4472 | 4576 | ||
4473 | /* We can not use write of zero bytes trick to | 4577 | /* We can not use write of zero bytes trick to |
4474 | set file size due to need for large file support. Also note that | 4578 | set file size due to need for large file support. Also note that |
4475 | this SetPathInfo is preferred to SetFileInfo based method in next | 4579 | this SetPathInfo is preferred to SetFileInfo based method in next |
4476 | routine which is only needed to work around a sharing violation bug | 4580 | routine which is only needed to work around a sharing violation bug |
4477 | in Samba which this routine can run into */ | 4581 | in Samba which this routine can run into */ |
4478 | 4582 | ||
4479 | int | 4583 | int |
4480 | CIFSSMBSetEOF(const int xid, struct cifsTconInfo *tcon, const char *fileName, | 4584 | CIFSSMBSetEOF(const int xid, struct cifsTconInfo *tcon, const char *fileName, |
4481 | __u64 size, int SetAllocation, | 4585 | __u64 size, int SetAllocation, |
4482 | const struct nls_table *nls_codepage, int remap) | 4586 | const struct nls_table *nls_codepage, int remap) |
4483 | { | 4587 | { |
4484 | struct smb_com_transaction2_spi_req *pSMB = NULL; | 4588 | struct smb_com_transaction2_spi_req *pSMB = NULL; |
@@ -4517,22 +4621,22 @@ SetEOFRetry: | |||
4517 | pSMB->Timeout = 0; | 4621 | pSMB->Timeout = 0; |
4518 | pSMB->Reserved2 = 0; | 4622 | pSMB->Reserved2 = 0; |
4519 | param_offset = offsetof(struct smb_com_transaction2_spi_req, | 4623 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
4520 | InformationLevel) - 4; | 4624 | InformationLevel) - 4; |
4521 | offset = param_offset + params; | 4625 | offset = param_offset + params; |
4522 | if(SetAllocation) { | 4626 | if (SetAllocation) { |
4523 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) | 4627 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
4524 | pSMB->InformationLevel = | 4628 | pSMB->InformationLevel = |
4525 | cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO2); | 4629 | cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO2); |
4526 | else | 4630 | else |
4527 | pSMB->InformationLevel = | 4631 | pSMB->InformationLevel = |
4528 | cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO); | 4632 | cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO); |
4529 | } else /* Set File Size */ { | 4633 | } else /* Set File Size */ { |
4530 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) | 4634 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
4531 | pSMB->InformationLevel = | 4635 | pSMB->InformationLevel = |
4532 | cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO2); | 4636 | cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO2); |
4533 | else | 4637 | else |
4534 | pSMB->InformationLevel = | 4638 | pSMB->InformationLevel = |
4535 | cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO); | 4639 | cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO); |
4536 | } | 4640 | } |
4537 | 4641 | ||
4538 | parm_data = | 4642 | parm_data = |
@@ -4567,8 +4671,8 @@ SetEOFRetry: | |||
4567 | } | 4671 | } |
4568 | 4672 | ||
4569 | int | 4673 | int |
4570 | CIFSSMBSetFileSize(const int xid, struct cifsTconInfo *tcon, __u64 size, | 4674 | CIFSSMBSetFileSize(const int xid, struct cifsTconInfo *tcon, __u64 size, |
4571 | __u16 fid, __u32 pid_of_opener, int SetAllocation) | 4675 | __u16 fid, __u32 pid_of_opener, int SetAllocation) |
4572 | { | 4676 | { |
4573 | struct smb_com_transaction2_sfi_req *pSMB = NULL; | 4677 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
4574 | struct smb_com_transaction2_sfi_rsp *pSMBr = NULL; | 4678 | struct smb_com_transaction2_sfi_rsp *pSMBr = NULL; |
@@ -4589,7 +4693,7 @@ CIFSSMBSetFileSize(const int xid, struct cifsTconInfo *tcon, __u64 size, | |||
4589 | 4693 | ||
4590 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid_of_opener); | 4694 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid_of_opener); |
4591 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid_of_opener >> 16)); | 4695 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid_of_opener >> 16)); |
4592 | 4696 | ||
4593 | params = 6; | 4697 | params = 6; |
4594 | pSMB->MaxSetupCount = 0; | 4698 | pSMB->MaxSetupCount = 0; |
4595 | pSMB->Reserved = 0; | 4699 | pSMB->Reserved = 0; |
@@ -4599,7 +4703,7 @@ CIFSSMBSetFileSize(const int xid, struct cifsTconInfo *tcon, __u64 size, | |||
4599 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; | 4703 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
4600 | offset = param_offset + params; | 4704 | offset = param_offset + params; |
4601 | 4705 | ||
4602 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; | 4706 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
4603 | 4707 | ||
4604 | count = sizeof(struct file_end_of_file_info); | 4708 | count = sizeof(struct file_end_of_file_info); |
4605 | pSMB->MaxParameterCount = cpu_to_le16(2); | 4709 | pSMB->MaxParameterCount = cpu_to_le16(2); |
@@ -4614,25 +4718,25 @@ CIFSSMBSetFileSize(const int xid, struct cifsTconInfo *tcon, __u64 size, | |||
4614 | pSMB->TotalParameterCount = pSMB->ParameterCount; | 4718 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
4615 | pSMB->ParameterOffset = cpu_to_le16(param_offset); | 4719 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
4616 | parm_data = | 4720 | parm_data = |
4617 | (struct file_end_of_file_info *) (((char *) &pSMB->hdr.Protocol) + | 4721 | (struct file_end_of_file_info *) (((char *) &pSMB->hdr.Protocol) |
4618 | offset); | 4722 | + offset); |
4619 | pSMB->DataOffset = cpu_to_le16(offset); | 4723 | pSMB->DataOffset = cpu_to_le16(offset); |
4620 | parm_data->FileSize = cpu_to_le64(size); | 4724 | parm_data->FileSize = cpu_to_le64(size); |
4621 | pSMB->Fid = fid; | 4725 | pSMB->Fid = fid; |
4622 | if(SetAllocation) { | 4726 | if (SetAllocation) { |
4623 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) | 4727 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
4624 | pSMB->InformationLevel = | 4728 | pSMB->InformationLevel = |
4625 | cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO2); | 4729 | cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO2); |
4626 | else | 4730 | else |
4627 | pSMB->InformationLevel = | 4731 | pSMB->InformationLevel = |
4628 | cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO); | 4732 | cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO); |
4629 | } else /* Set File Size */ { | 4733 | } else /* Set File Size */ { |
4630 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) | 4734 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
4631 | pSMB->InformationLevel = | 4735 | pSMB->InformationLevel = |
4632 | cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO2); | 4736 | cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO2); |
4633 | else | 4737 | else |
4634 | pSMB->InformationLevel = | 4738 | pSMB->InformationLevel = |
4635 | cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO); | 4739 | cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO); |
4636 | } | 4740 | } |
4637 | pSMB->Reserved4 = 0; | 4741 | pSMB->Reserved4 = 0; |
4638 | pSMB->hdr.smb_buf_length += byte_count; | 4742 | pSMB->hdr.smb_buf_length += byte_count; |
@@ -4648,21 +4752,21 @@ CIFSSMBSetFileSize(const int xid, struct cifsTconInfo *tcon, __u64 size, | |||
4648 | if (pSMB) | 4752 | if (pSMB) |
4649 | cifs_small_buf_release(pSMB); | 4753 | cifs_small_buf_release(pSMB); |
4650 | 4754 | ||
4651 | /* Note: On -EAGAIN error only caller can retry on handle based calls | 4755 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
4652 | since file handle passed in no longer valid */ | 4756 | since file handle passed in no longer valid */ |
4653 | 4757 | ||
4654 | return rc; | 4758 | return rc; |
4655 | } | 4759 | } |
4656 | 4760 | ||
4657 | /* Some legacy servers such as NT4 require that the file times be set on | 4761 | /* Some legacy servers such as NT4 require that the file times be set on |
4658 | an open handle, rather than by pathname - this is awkward due to | 4762 | an open handle, rather than by pathname - this is awkward due to |
4659 | potential access conflicts on the open, but it is unavoidable for these | 4763 | potential access conflicts on the open, but it is unavoidable for these |
4660 | old servers since the only other choice is to go from 100 nanosecond DCE | 4764 | old servers since the only other choice is to go from 100 nanosecond DCE |
4661 | time and resort to the original setpathinfo level which takes the ancient | 4765 | time and resort to the original setpathinfo level which takes the ancient |
4662 | DOS time format with 2 second granularity */ | 4766 | DOS time format with 2 second granularity */ |
4663 | int | 4767 | int |
4664 | CIFSSMBSetFileTimes(const int xid, struct cifsTconInfo *tcon, const FILE_BASIC_INFO * data, | 4768 | CIFSSMBSetFileTimes(const int xid, struct cifsTconInfo *tcon, |
4665 | __u16 fid) | 4769 | const FILE_BASIC_INFO *data, __u16 fid) |
4666 | { | 4770 | { |
4667 | struct smb_com_transaction2_sfi_req *pSMB = NULL; | 4771 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
4668 | struct smb_com_transaction2_sfi_rsp *pSMBr = NULL; | 4772 | struct smb_com_transaction2_sfi_rsp *pSMBr = NULL; |
@@ -4684,7 +4788,7 @@ CIFSSMBSetFileTimes(const int xid, struct cifsTconInfo *tcon, const FILE_BASIC_I | |||
4684 | use an existing handle (rather than opening one on the fly) */ | 4788 | use an existing handle (rather than opening one on the fly) */ |
4685 | /* pSMB->hdr.Pid = cpu_to_le16((__u16)pid_of_opener); | 4789 | /* pSMB->hdr.Pid = cpu_to_le16((__u16)pid_of_opener); |
4686 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid_of_opener >> 16));*/ | 4790 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid_of_opener >> 16));*/ |
4687 | 4791 | ||
4688 | params = 6; | 4792 | params = 6; |
4689 | pSMB->MaxSetupCount = 0; | 4793 | pSMB->MaxSetupCount = 0; |
4690 | pSMB->Reserved = 0; | 4794 | pSMB->Reserved = 0; |
@@ -4694,7 +4798,7 @@ CIFSSMBSetFileTimes(const int xid, struct cifsTconInfo *tcon, const FILE_BASIC_I | |||
4694 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; | 4798 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
4695 | offset = param_offset + params; | 4799 | offset = param_offset + params; |
4696 | 4800 | ||
4697 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; | 4801 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
4698 | 4802 | ||
4699 | count = sizeof (FILE_BASIC_INFO); | 4803 | count = sizeof (FILE_BASIC_INFO); |
4700 | pSMB->MaxParameterCount = cpu_to_le16(2); | 4804 | pSMB->MaxParameterCount = cpu_to_le16(2); |
@@ -4717,16 +4821,16 @@ CIFSSMBSetFileTimes(const int xid, struct cifsTconInfo *tcon, const FILE_BASIC_I | |||
4717 | pSMB->Reserved4 = 0; | 4821 | pSMB->Reserved4 = 0; |
4718 | pSMB->hdr.smb_buf_length += byte_count; | 4822 | pSMB->hdr.smb_buf_length += byte_count; |
4719 | pSMB->ByteCount = cpu_to_le16(byte_count); | 4823 | pSMB->ByteCount = cpu_to_le16(byte_count); |
4720 | memcpy(data_offset,data,sizeof(FILE_BASIC_INFO)); | 4824 | memcpy(data_offset, data, sizeof(FILE_BASIC_INFO)); |
4721 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, | 4825 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
4722 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); | 4826 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
4723 | if (rc) { | 4827 | if (rc) { |
4724 | cFYI(1,("Send error in Set Time (SetFileInfo) = %d",rc)); | 4828 | cFYI(1, ("Send error in Set Time (SetFileInfo) = %d", rc)); |
4725 | } | 4829 | } |
4726 | 4830 | ||
4727 | cifs_small_buf_release(pSMB); | 4831 | cifs_small_buf_release(pSMB); |
4728 | 4832 | ||
4729 | /* Note: On -EAGAIN error only caller can retry on handle based calls | 4833 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
4730 | since file handle passed in no longer valid */ | 4834 | since file handle passed in no longer valid */ |
4731 | 4835 | ||
4732 | return rc; | 4836 | return rc; |
@@ -4735,7 +4839,7 @@ CIFSSMBSetFileTimes(const int xid, struct cifsTconInfo *tcon, const FILE_BASIC_I | |||
4735 | 4839 | ||
4736 | int | 4840 | int |
4737 | CIFSSMBSetTimes(const int xid, struct cifsTconInfo *tcon, const char *fileName, | 4841 | CIFSSMBSetTimes(const int xid, struct cifsTconInfo *tcon, const char *fileName, |
4738 | const FILE_BASIC_INFO * data, | 4842 | const FILE_BASIC_INFO *data, |
4739 | const struct nls_table *nls_codepage, int remap) | 4843 | const struct nls_table *nls_codepage, int remap) |
4740 | { | 4844 | { |
4741 | TRANSACTION2_SPI_REQ *pSMB = NULL; | 4845 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
@@ -4760,7 +4864,7 @@ SetTimesRetry: | |||
4760 | PATH_MAX, nls_codepage, remap); | 4864 | PATH_MAX, nls_codepage, remap); |
4761 | name_len++; /* trailing null */ | 4865 | name_len++; /* trailing null */ |
4762 | name_len *= 2; | 4866 | name_len *= 2; |
4763 | } else { /* BB improve the check for buffer overruns BB */ | 4867 | } else { /* BB improve the check for buffer overruns BB */ |
4764 | name_len = strnlen(fileName, PATH_MAX); | 4868 | name_len = strnlen(fileName, PATH_MAX); |
4765 | name_len++; /* trailing null */ | 4869 | name_len++; /* trailing null */ |
4766 | strncpy(pSMB->FileName, fileName, name_len); | 4870 | strncpy(pSMB->FileName, fileName, name_len); |
@@ -4776,7 +4880,7 @@ SetTimesRetry: | |||
4776 | pSMB->Timeout = 0; | 4880 | pSMB->Timeout = 0; |
4777 | pSMB->Reserved2 = 0; | 4881 | pSMB->Reserved2 = 0; |
4778 | param_offset = offsetof(struct smb_com_transaction2_spi_req, | 4882 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
4779 | InformationLevel) - 4; | 4883 | InformationLevel) - 4; |
4780 | offset = param_offset + params; | 4884 | offset = param_offset + params; |
4781 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; | 4885 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
4782 | pSMB->ParameterOffset = cpu_to_le16(param_offset); | 4886 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
@@ -4837,11 +4941,11 @@ SetAttrLgcyRetry: | |||
4837 | 4941 | ||
4838 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { | 4942 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
4839 | name_len = | 4943 | name_len = |
4840 | ConvertToUCS((__le16 *) pSMB->fileName, fileName, | 4944 | ConvertToUCS((__le16 *) pSMB->fileName, fileName, |
4841 | PATH_MAX, nls_codepage); | 4945 | PATH_MAX, nls_codepage); |
4842 | name_len++; /* trailing null */ | 4946 | name_len++; /* trailing null */ |
4843 | name_len *= 2; | 4947 | name_len *= 2; |
4844 | } else { /* BB improve the check for buffer overruns BB */ | 4948 | } else { /* BB improve the check for buffer overruns BB */ |
4845 | name_len = strnlen(fileName, PATH_MAX); | 4949 | name_len = strnlen(fileName, PATH_MAX); |
4846 | name_len++; /* trailing null */ | 4950 | name_len++; /* trailing null */ |
4847 | strncpy(pSMB->fileName, fileName, name_len); | 4951 | strncpy(pSMB->fileName, fileName, name_len); |
@@ -4867,8 +4971,8 @@ SetAttrLgcyRetry: | |||
4867 | 4971 | ||
4868 | int | 4972 | int |
4869 | CIFSSMBUnixSetPerms(const int xid, struct cifsTconInfo *tcon, | 4973 | CIFSSMBUnixSetPerms(const int xid, struct cifsTconInfo *tcon, |
4870 | char *fileName, __u64 mode, __u64 uid, __u64 gid, | 4974 | char *fileName, __u64 mode, __u64 uid, __u64 gid, |
4871 | dev_t device, const struct nls_table *nls_codepage, | 4975 | dev_t device, const struct nls_table *nls_codepage, |
4872 | int remap) | 4976 | int remap) |
4873 | { | 4977 | { |
4874 | TRANSACTION2_SPI_REQ *pSMB = NULL; | 4978 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
@@ -4888,7 +4992,7 @@ setPermsRetry: | |||
4888 | 4992 | ||
4889 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { | 4993 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
4890 | name_len = | 4994 | name_len = |
4891 | cifsConvertToUCS((__le16 *) pSMB->FileName, fileName, | 4995 | cifsConvertToUCS((__le16 *) pSMB->FileName, fileName, |
4892 | PATH_MAX, nls_codepage, remap); | 4996 | PATH_MAX, nls_codepage, remap); |
4893 | name_len++; /* trailing null */ | 4997 | name_len++; /* trailing null */ |
4894 | name_len *= 2; | 4998 | name_len *= 2; |
@@ -4908,7 +5012,7 @@ setPermsRetry: | |||
4908 | pSMB->Timeout = 0; | 5012 | pSMB->Timeout = 0; |
4909 | pSMB->Reserved2 = 0; | 5013 | pSMB->Reserved2 = 0; |
4910 | param_offset = offsetof(struct smb_com_transaction2_spi_req, | 5014 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
4911 | InformationLevel) - 4; | 5015 | InformationLevel) - 4; |
4912 | offset = param_offset + params; | 5016 | offset = param_offset + params; |
4913 | data_offset = | 5017 | data_offset = |
4914 | (FILE_UNIX_BASIC_INFO *) ((char *) &pSMB->hdr.Protocol + | 5018 | (FILE_UNIX_BASIC_INFO *) ((char *) &pSMB->hdr.Protocol + |
@@ -4931,7 +5035,7 @@ setPermsRetry: | |||
4931 | older clients, but we should be precise - we use SetFileSize to | 5035 | older clients, but we should be precise - we use SetFileSize to |
4932 | set file size and do not want to truncate file size to zero | 5036 | set file size and do not want to truncate file size to zero |
4933 | accidently as happened on one Samba server beta by putting | 5037 | accidently as happened on one Samba server beta by putting |
4934 | zero instead of -1 here */ | 5038 | zero instead of -1 here */ |
4935 | data_offset->EndOfFile = NO_CHANGE_64; | 5039 | data_offset->EndOfFile = NO_CHANGE_64; |
4936 | data_offset->NumOfBytes = NO_CHANGE_64; | 5040 | data_offset->NumOfBytes = NO_CHANGE_64; |
4937 | data_offset->LastStatusChange = NO_CHANGE_64; | 5041 | data_offset->LastStatusChange = NO_CHANGE_64; |
@@ -4943,20 +5047,20 @@ setPermsRetry: | |||
4943 | data_offset->DevMajor = cpu_to_le64(MAJOR(device)); | 5047 | data_offset->DevMajor = cpu_to_le64(MAJOR(device)); |
4944 | data_offset->DevMinor = cpu_to_le64(MINOR(device)); | 5048 | data_offset->DevMinor = cpu_to_le64(MINOR(device)); |
4945 | data_offset->Permissions = cpu_to_le64(mode); | 5049 | data_offset->Permissions = cpu_to_le64(mode); |
4946 | 5050 | ||
4947 | if(S_ISREG(mode)) | 5051 | if (S_ISREG(mode)) |
4948 | data_offset->Type = cpu_to_le32(UNIX_FILE); | 5052 | data_offset->Type = cpu_to_le32(UNIX_FILE); |
4949 | else if(S_ISDIR(mode)) | 5053 | else if (S_ISDIR(mode)) |
4950 | data_offset->Type = cpu_to_le32(UNIX_DIR); | 5054 | data_offset->Type = cpu_to_le32(UNIX_DIR); |
4951 | else if(S_ISLNK(mode)) | 5055 | else if (S_ISLNK(mode)) |
4952 | data_offset->Type = cpu_to_le32(UNIX_SYMLINK); | 5056 | data_offset->Type = cpu_to_le32(UNIX_SYMLINK); |
4953 | else if(S_ISCHR(mode)) | 5057 | else if (S_ISCHR(mode)) |
4954 | data_offset->Type = cpu_to_le32(UNIX_CHARDEV); | 5058 | data_offset->Type = cpu_to_le32(UNIX_CHARDEV); |
4955 | else if(S_ISBLK(mode)) | 5059 | else if (S_ISBLK(mode)) |
4956 | data_offset->Type = cpu_to_le32(UNIX_BLOCKDEV); | 5060 | data_offset->Type = cpu_to_le32(UNIX_BLOCKDEV); |
4957 | else if(S_ISFIFO(mode)) | 5061 | else if (S_ISFIFO(mode)) |
4958 | data_offset->Type = cpu_to_le32(UNIX_FIFO); | 5062 | data_offset->Type = cpu_to_le32(UNIX_FIFO); |
4959 | else if(S_ISSOCK(mode)) | 5063 | else if (S_ISSOCK(mode)) |
4960 | data_offset->Type = cpu_to_le32(UNIX_SOCKET); | 5064 | data_offset->Type = cpu_to_le32(UNIX_SOCKET); |
4961 | 5065 | ||
4962 | 5066 | ||
@@ -4974,20 +5078,20 @@ setPermsRetry: | |||
4974 | return rc; | 5078 | return rc; |
4975 | } | 5079 | } |
4976 | 5080 | ||
4977 | int CIFSSMBNotify(const int xid, struct cifsTconInfo *tcon, | 5081 | int CIFSSMBNotify(const int xid, struct cifsTconInfo *tcon, |
4978 | const int notify_subdirs, const __u16 netfid, | 5082 | const int notify_subdirs, const __u16 netfid, |
4979 | __u32 filter, struct file * pfile, int multishot, | 5083 | __u32 filter, struct file *pfile, int multishot, |
4980 | const struct nls_table *nls_codepage) | 5084 | const struct nls_table *nls_codepage) |
4981 | { | 5085 | { |
4982 | int rc = 0; | 5086 | int rc = 0; |
4983 | struct smb_com_transaction_change_notify_req * pSMB = NULL; | 5087 | struct smb_com_transaction_change_notify_req *pSMB = NULL; |
4984 | struct smb_com_ntransaction_change_notify_rsp * pSMBr = NULL; | 5088 | struct smb_com_ntransaction_change_notify_rsp *pSMBr = NULL; |
4985 | struct dir_notify_req *dnotify_req; | 5089 | struct dir_notify_req *dnotify_req; |
4986 | int bytes_returned; | 5090 | int bytes_returned; |
4987 | 5091 | ||
4988 | cFYI(1, ("In CIFSSMBNotify for file handle %d",(int)netfid)); | 5092 | cFYI(1, ("In CIFSSMBNotify for file handle %d", (int)netfid)); |
4989 | rc = smb_init(SMB_COM_NT_TRANSACT, 23, tcon, (void **) &pSMB, | 5093 | rc = smb_init(SMB_COM_NT_TRANSACT, 23, tcon, (void **) &pSMB, |
4990 | (void **) &pSMBr); | 5094 | (void **) &pSMBr); |
4991 | if (rc) | 5095 | if (rc) |
4992 | return rc; | 5096 | return rc; |
4993 | 5097 | ||
@@ -5008,7 +5112,7 @@ int CIFSSMBNotify(const int xid, struct cifsTconInfo *tcon, | |||
5008 | pSMB->SetupCount = 4; /* single byte does not need le conversion */ | 5112 | pSMB->SetupCount = 4; /* single byte does not need le conversion */ |
5009 | pSMB->SubCommand = cpu_to_le16(NT_TRANSACT_NOTIFY_CHANGE); | 5113 | pSMB->SubCommand = cpu_to_le16(NT_TRANSACT_NOTIFY_CHANGE); |
5010 | pSMB->ParameterCount = pSMB->TotalParameterCount; | 5114 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
5011 | if(notify_subdirs) | 5115 | if (notify_subdirs) |
5012 | pSMB->WatchTree = 1; /* one byte - no le conversion needed */ | 5116 | pSMB->WatchTree = 1; /* one byte - no le conversion needed */ |
5013 | pSMB->Reserved2 = 0; | 5117 | pSMB->Reserved2 = 0; |
5014 | pSMB->CompletionFilter = cpu_to_le32(filter); | 5118 | pSMB->CompletionFilter = cpu_to_le32(filter); |
@@ -5021,11 +5125,11 @@ int CIFSSMBNotify(const int xid, struct cifsTconInfo *tcon, | |||
5021 | cFYI(1, ("Error in Notify = %d", rc)); | 5125 | cFYI(1, ("Error in Notify = %d", rc)); |
5022 | } else { | 5126 | } else { |
5023 | /* Add file to outstanding requests */ | 5127 | /* Add file to outstanding requests */ |
5024 | /* BB change to kmem cache alloc */ | 5128 | /* BB change to kmem cache alloc */ |
5025 | dnotify_req = kmalloc( | 5129 | dnotify_req = kmalloc( |
5026 | sizeof(struct dir_notify_req), | 5130 | sizeof(struct dir_notify_req), |
5027 | GFP_KERNEL); | 5131 | GFP_KERNEL); |
5028 | if(dnotify_req) { | 5132 | if (dnotify_req) { |
5029 | dnotify_req->Pid = pSMB->hdr.Pid; | 5133 | dnotify_req->Pid = pSMB->hdr.Pid; |
5030 | dnotify_req->PidHigh = pSMB->hdr.PidHigh; | 5134 | dnotify_req->PidHigh = pSMB->hdr.PidHigh; |
5031 | dnotify_req->Mid = pSMB->hdr.Mid; | 5135 | dnotify_req->Mid = pSMB->hdr.Mid; |
@@ -5036,20 +5140,20 @@ int CIFSSMBNotify(const int xid, struct cifsTconInfo *tcon, | |||
5036 | dnotify_req->filter = filter; | 5140 | dnotify_req->filter = filter; |
5037 | dnotify_req->multishot = multishot; | 5141 | dnotify_req->multishot = multishot; |
5038 | spin_lock(&GlobalMid_Lock); | 5142 | spin_lock(&GlobalMid_Lock); |
5039 | list_add_tail(&dnotify_req->lhead, | 5143 | list_add_tail(&dnotify_req->lhead, |
5040 | &GlobalDnotifyReqList); | 5144 | &GlobalDnotifyReqList); |
5041 | spin_unlock(&GlobalMid_Lock); | 5145 | spin_unlock(&GlobalMid_Lock); |
5042 | } else | 5146 | } else |
5043 | rc = -ENOMEM; | 5147 | rc = -ENOMEM; |
5044 | } | 5148 | } |
5045 | cifs_buf_release(pSMB); | 5149 | cifs_buf_release(pSMB); |
5046 | return rc; | 5150 | return rc; |
5047 | } | 5151 | } |
5048 | #ifdef CONFIG_CIFS_XATTR | 5152 | #ifdef CONFIG_CIFS_XATTR |
5049 | ssize_t | 5153 | ssize_t |
5050 | CIFSSMBQAllEAs(const int xid, struct cifsTconInfo *tcon, | 5154 | CIFSSMBQAllEAs(const int xid, struct cifsTconInfo *tcon, |
5051 | const unsigned char *searchName, | 5155 | const unsigned char *searchName, |
5052 | char * EAData, size_t buf_size, | 5156 | char *EAData, size_t buf_size, |
5053 | const struct nls_table *nls_codepage, int remap) | 5157 | const struct nls_table *nls_codepage, int remap) |
5054 | { | 5158 | { |
5055 | /* BB assumes one setup word */ | 5159 | /* BB assumes one setup word */ |
@@ -5058,8 +5162,8 @@ CIFSSMBQAllEAs(const int xid, struct cifsTconInfo *tcon, | |||
5058 | int rc = 0; | 5162 | int rc = 0; |
5059 | int bytes_returned; | 5163 | int bytes_returned; |
5060 | int name_len; | 5164 | int name_len; |
5061 | struct fea * temp_fea; | 5165 | struct fea *temp_fea; |
5062 | char * temp_ptr; | 5166 | char *temp_ptr; |
5063 | __u16 params, byte_count; | 5167 | __u16 params, byte_count; |
5064 | 5168 | ||
5065 | cFYI(1, ("In Query All EAs path %s", searchName)); | 5169 | cFYI(1, ("In Query All EAs path %s", searchName)); |
@@ -5071,7 +5175,7 @@ QAllEAsRetry: | |||
5071 | 5175 | ||
5072 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { | 5176 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
5073 | name_len = | 5177 | name_len = |
5074 | cifsConvertToUCS((__le16 *) pSMB->FileName, searchName, | 5178 | cifsConvertToUCS((__le16 *) pSMB->FileName, searchName, |
5075 | PATH_MAX, nls_codepage, remap); | 5179 | PATH_MAX, nls_codepage, remap); |
5076 | name_len++; /* trailing null */ | 5180 | name_len++; /* trailing null */ |
5077 | name_len *= 2; | 5181 | name_len *= 2; |
@@ -5081,7 +5185,7 @@ QAllEAsRetry: | |||
5081 | strncpy(pSMB->FileName, searchName, name_len); | 5185 | strncpy(pSMB->FileName, searchName, name_len); |
5082 | } | 5186 | } |
5083 | 5187 | ||
5084 | params = 2 /* level */ + 4 /* reserved */ + name_len /* includes NUL */ ; | 5188 | params = 2 /* level */ + 4 /* reserved */ + name_len /* includes NUL */; |
5085 | pSMB->TotalDataCount = 0; | 5189 | pSMB->TotalDataCount = 0; |
5086 | pSMB->MaxParameterCount = cpu_to_le16(2); | 5190 | pSMB->MaxParameterCount = cpu_to_le16(2); |
5087 | pSMB->MaxDataCount = cpu_to_le16(4000); /* BB find exact max SMB PDU from sess structure BB */ | 5191 | pSMB->MaxDataCount = cpu_to_le16(4000); /* BB find exact max SMB PDU from sess structure BB */ |
@@ -5091,7 +5195,7 @@ QAllEAsRetry: | |||
5091 | pSMB->Timeout = 0; | 5195 | pSMB->Timeout = 0; |
5092 | pSMB->Reserved2 = 0; | 5196 | pSMB->Reserved2 = 0; |
5093 | pSMB->ParameterOffset = cpu_to_le16(offsetof( | 5197 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
5094 | struct smb_com_transaction2_qpi_req ,InformationLevel) - 4); | 5198 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
5095 | pSMB->DataCount = 0; | 5199 | pSMB->DataCount = 0; |
5096 | pSMB->DataOffset = 0; | 5200 | pSMB->DataOffset = 0; |
5097 | pSMB->SetupCount = 1; | 5201 | pSMB->SetupCount = 1; |
@@ -5115,7 +5219,7 @@ QAllEAsRetry: | |||
5115 | /* BB also check enough total bytes returned */ | 5219 | /* BB also check enough total bytes returned */ |
5116 | /* BB we need to improve the validity checking | 5220 | /* BB we need to improve the validity checking |
5117 | of these trans2 responses */ | 5221 | of these trans2 responses */ |
5118 | if (rc || (pSMBr->ByteCount < 4)) | 5222 | if (rc || (pSMBr->ByteCount < 4)) |
5119 | rc = -EIO; /* bad smb */ | 5223 | rc = -EIO; /* bad smb */ |
5120 | /* else if (pFindData){ | 5224 | /* else if (pFindData){ |
5121 | memcpy((char *) pFindData, | 5225 | memcpy((char *) pFindData, |
@@ -5128,39 +5232,40 @@ QAllEAsRetry: | |||
5128 | /* check that each element of each entry does not | 5232 | /* check that each element of each entry does not |
5129 | go beyond end of list */ | 5233 | go beyond end of list */ |
5130 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); | 5234 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
5131 | struct fealist * ea_response_data; | 5235 | struct fealist *ea_response_data; |
5132 | rc = 0; | 5236 | rc = 0; |
5133 | /* validate_trans2_offsets() */ | 5237 | /* validate_trans2_offsets() */ |
5134 | /* BB to check if(start of smb + data_offset > &bcc+ bcc)*/ | 5238 | /* BB check if start of smb + data_offset > &bcc+ bcc */ |
5135 | ea_response_data = (struct fealist *) | 5239 | ea_response_data = (struct fealist *) |
5136 | (((char *) &pSMBr->hdr.Protocol) + | 5240 | (((char *) &pSMBr->hdr.Protocol) + |
5137 | data_offset); | 5241 | data_offset); |
5138 | name_len = le32_to_cpu(ea_response_data->list_len); | 5242 | name_len = le32_to_cpu(ea_response_data->list_len); |
5139 | cFYI(1,("ea length %d", name_len)); | 5243 | cFYI(1, ("ea length %d", name_len)); |
5140 | if(name_len <= 8) { | 5244 | if (name_len <= 8) { |
5141 | /* returned EA size zeroed at top of function */ | 5245 | /* returned EA size zeroed at top of function */ |
5142 | cFYI(1,("empty EA list returned from server")); | 5246 | cFYI(1, ("empty EA list returned from server")); |
5143 | } else { | 5247 | } else { |
5144 | /* account for ea list len */ | 5248 | /* account for ea list len */ |
5145 | name_len -= 4; | 5249 | name_len -= 4; |
5146 | temp_fea = ea_response_data->list; | 5250 | temp_fea = ea_response_data->list; |
5147 | temp_ptr = (char *)temp_fea; | 5251 | temp_ptr = (char *)temp_fea; |
5148 | while(name_len > 0) { | 5252 | while (name_len > 0) { |
5149 | __u16 value_len; | 5253 | __u16 value_len; |
5150 | name_len -= 4; | 5254 | name_len -= 4; |
5151 | temp_ptr += 4; | 5255 | temp_ptr += 4; |
5152 | rc += temp_fea->name_len; | 5256 | rc += temp_fea->name_len; |
5153 | /* account for prefix user. and trailing null */ | 5257 | /* account for prefix user. and trailing null */ |
5154 | rc = rc + 5 + 1; | 5258 | rc = rc + 5 + 1; |
5155 | if(rc<(int)buf_size) { | 5259 | if (rc < (int)buf_size) { |
5156 | memcpy(EAData,"user.",5); | 5260 | memcpy(EAData, "user.", 5); |
5157 | EAData+=5; | 5261 | EAData += 5; |
5158 | memcpy(EAData,temp_ptr,temp_fea->name_len); | 5262 | memcpy(EAData, temp_ptr, |
5159 | EAData+=temp_fea->name_len; | 5263 | temp_fea->name_len); |
5264 | EAData += temp_fea->name_len; | ||
5160 | /* null terminate name */ | 5265 | /* null terminate name */ |
5161 | *EAData = 0; | 5266 | *EAData = 0; |
5162 | EAData = EAData + 1; | 5267 | EAData = EAData + 1; |
5163 | } else if(buf_size == 0) { | 5268 | } else if (buf_size == 0) { |
5164 | /* skip copy - calc size only */ | 5269 | /* skip copy - calc size only */ |
5165 | } else { | 5270 | } else { |
5166 | /* stop before overrun buffer */ | 5271 | /* stop before overrun buffer */ |
@@ -5172,11 +5277,15 @@ QAllEAsRetry: | |||
5172 | /* account for trailing null */ | 5277 | /* account for trailing null */ |
5173 | name_len--; | 5278 | name_len--; |
5174 | temp_ptr++; | 5279 | temp_ptr++; |
5175 | value_len = le16_to_cpu(temp_fea->value_len); | 5280 | value_len = |
5281 | le16_to_cpu(temp_fea->value_len); | ||
5176 | name_len -= value_len; | 5282 | name_len -= value_len; |
5177 | temp_ptr += value_len; | 5283 | temp_ptr += value_len; |
5178 | /* BB check that temp_ptr is still within smb BB*/ | 5284 | /* BB check that temp_ptr is still |
5179 | /* no trailing null to account for in value len */ | 5285 | within the SMB BB*/ |
5286 | |||
5287 | /* no trailing null to account for | ||
5288 | in value len */ | ||
5180 | /* go on to next EA */ | 5289 | /* go on to next EA */ |
5181 | temp_fea = (struct fea *)temp_ptr; | 5290 | temp_fea = (struct fea *)temp_ptr; |
5182 | } | 5291 | } |
@@ -5191,9 +5300,9 @@ QAllEAsRetry: | |||
5191 | return (ssize_t)rc; | 5300 | return (ssize_t)rc; |
5192 | } | 5301 | } |
5193 | 5302 | ||
5194 | ssize_t CIFSSMBQueryEA(const int xid,struct cifsTconInfo * tcon, | 5303 | ssize_t CIFSSMBQueryEA(const int xid, struct cifsTconInfo *tcon, |
5195 | const unsigned char * searchName,const unsigned char * ea_name, | 5304 | const unsigned char *searchName, const unsigned char *ea_name, |
5196 | unsigned char * ea_value, size_t buf_size, | 5305 | unsigned char *ea_value, size_t buf_size, |
5197 | const struct nls_table *nls_codepage, int remap) | 5306 | const struct nls_table *nls_codepage, int remap) |
5198 | { | 5307 | { |
5199 | TRANSACTION2_QPI_REQ *pSMB = NULL; | 5308 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
@@ -5201,8 +5310,8 @@ ssize_t CIFSSMBQueryEA(const int xid,struct cifsTconInfo * tcon, | |||
5201 | int rc = 0; | 5310 | int rc = 0; |
5202 | int bytes_returned; | 5311 | int bytes_returned; |
5203 | int name_len; | 5312 | int name_len; |
5204 | struct fea * temp_fea; | 5313 | struct fea *temp_fea; |
5205 | char * temp_ptr; | 5314 | char *temp_ptr; |
5206 | __u16 params, byte_count; | 5315 | __u16 params, byte_count; |
5207 | 5316 | ||
5208 | cFYI(1, ("In Query EA path %s", searchName)); | 5317 | cFYI(1, ("In Query EA path %s", searchName)); |
@@ -5214,7 +5323,7 @@ QEARetry: | |||
5214 | 5323 | ||
5215 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { | 5324 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
5216 | name_len = | 5325 | name_len = |
5217 | cifsConvertToUCS((__le16 *) pSMB->FileName, searchName, | 5326 | cifsConvertToUCS((__le16 *) pSMB->FileName, searchName, |
5218 | PATH_MAX, nls_codepage, remap); | 5327 | PATH_MAX, nls_codepage, remap); |
5219 | name_len++; /* trailing null */ | 5328 | name_len++; /* trailing null */ |
5220 | name_len *= 2; | 5329 | name_len *= 2; |
@@ -5224,7 +5333,7 @@ QEARetry: | |||
5224 | strncpy(pSMB->FileName, searchName, name_len); | 5333 | strncpy(pSMB->FileName, searchName, name_len); |
5225 | } | 5334 | } |
5226 | 5335 | ||
5227 | params = 2 /* level */ + 4 /* reserved */ + name_len /* includes NUL */ ; | 5336 | params = 2 /* level */ + 4 /* reserved */ + name_len /* includes NUL */; |
5228 | pSMB->TotalDataCount = 0; | 5337 | pSMB->TotalDataCount = 0; |
5229 | pSMB->MaxParameterCount = cpu_to_le16(2); | 5338 | pSMB->MaxParameterCount = cpu_to_le16(2); |
5230 | pSMB->MaxDataCount = cpu_to_le16(4000); /* BB find exact max SMB PDU from sess structure BB */ | 5339 | pSMB->MaxDataCount = cpu_to_le16(4000); /* BB find exact max SMB PDU from sess structure BB */ |
@@ -5234,7 +5343,7 @@ QEARetry: | |||
5234 | pSMB->Timeout = 0; | 5343 | pSMB->Timeout = 0; |
5235 | pSMB->Reserved2 = 0; | 5344 | pSMB->Reserved2 = 0; |
5236 | pSMB->ParameterOffset = cpu_to_le16(offsetof( | 5345 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
5237 | struct smb_com_transaction2_qpi_req ,InformationLevel) - 4); | 5346 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
5238 | pSMB->DataCount = 0; | 5347 | pSMB->DataCount = 0; |
5239 | pSMB->DataOffset = 0; | 5348 | pSMB->DataOffset = 0; |
5240 | pSMB->SetupCount = 1; | 5349 | pSMB->SetupCount = 1; |
@@ -5258,7 +5367,7 @@ QEARetry: | |||
5258 | /* BB also check enough total bytes returned */ | 5367 | /* BB also check enough total bytes returned */ |
5259 | /* BB we need to improve the validity checking | 5368 | /* BB we need to improve the validity checking |
5260 | of these trans2 responses */ | 5369 | of these trans2 responses */ |
5261 | if (rc || (pSMBr->ByteCount < 4)) | 5370 | if (rc || (pSMBr->ByteCount < 4)) |
5262 | rc = -EIO; /* bad smb */ | 5371 | rc = -EIO; /* bad smb */ |
5263 | /* else if (pFindData){ | 5372 | /* else if (pFindData){ |
5264 | memcpy((char *) pFindData, | 5373 | memcpy((char *) pFindData, |
@@ -5271,18 +5380,18 @@ QEARetry: | |||
5271 | /* check that each element of each entry does not | 5380 | /* check that each element of each entry does not |
5272 | go beyond end of list */ | 5381 | go beyond end of list */ |
5273 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); | 5382 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
5274 | struct fealist * ea_response_data; | 5383 | struct fealist *ea_response_data; |
5275 | rc = -ENODATA; | 5384 | rc = -ENODATA; |
5276 | /* validate_trans2_offsets() */ | 5385 | /* validate_trans2_offsets() */ |
5277 | /* BB to check if(start of smb + data_offset > &bcc+ bcc)*/ | 5386 | /* BB check if start of smb + data_offset > &bcc+ bcc*/ |
5278 | ea_response_data = (struct fealist *) | 5387 | ea_response_data = (struct fealist *) |
5279 | (((char *) &pSMBr->hdr.Protocol) + | 5388 | (((char *) &pSMBr->hdr.Protocol) + |
5280 | data_offset); | 5389 | data_offset); |
5281 | name_len = le32_to_cpu(ea_response_data->list_len); | 5390 | name_len = le32_to_cpu(ea_response_data->list_len); |
5282 | cFYI(1,("ea length %d", name_len)); | 5391 | cFYI(1, ("ea length %d", name_len)); |
5283 | if(name_len <= 8) { | 5392 | if (name_len <= 8) { |
5284 | /* returned EA size zeroed at top of function */ | 5393 | /* returned EA size zeroed at top of function */ |
5285 | cFYI(1,("empty EA list returned from server")); | 5394 | cFYI(1, ("empty EA list returned from server")); |
5286 | } else { | 5395 | } else { |
5287 | /* account for ea list len */ | 5396 | /* account for ea list len */ |
5288 | name_len -= 4; | 5397 | name_len -= 4; |
@@ -5290,28 +5399,30 @@ QEARetry: | |||
5290 | temp_ptr = (char *)temp_fea; | 5399 | temp_ptr = (char *)temp_fea; |
5291 | /* loop through checking if we have a matching | 5400 | /* loop through checking if we have a matching |
5292 | name and then return the associated value */ | 5401 | name and then return the associated value */ |
5293 | while(name_len > 0) { | 5402 | while (name_len > 0) { |
5294 | __u16 value_len; | 5403 | __u16 value_len; |
5295 | name_len -= 4; | 5404 | name_len -= 4; |
5296 | temp_ptr += 4; | 5405 | temp_ptr += 4; |
5297 | value_len = le16_to_cpu(temp_fea->value_len); | 5406 | value_len = |
5298 | /* BB validate that value_len falls within SMB, | 5407 | le16_to_cpu(temp_fea->value_len); |
5299 | even though maximum for name_len is 255 */ | 5408 | /* BB validate that value_len falls within SMB, |
5300 | if(memcmp(temp_fea->name,ea_name, | 5409 | even though maximum for name_len is 255 */ |
5410 | if (memcmp(temp_fea->name, ea_name, | ||
5301 | temp_fea->name_len) == 0) { | 5411 | temp_fea->name_len) == 0) { |
5302 | /* found a match */ | 5412 | /* found a match */ |
5303 | rc = value_len; | 5413 | rc = value_len; |
5304 | /* account for prefix user. and trailing null */ | 5414 | /* account for prefix user. and trailing null */ |
5305 | if(rc<=(int)buf_size) { | 5415 | if (rc <= (int)buf_size) { |
5306 | memcpy(ea_value, | 5416 | memcpy(ea_value, |
5307 | temp_fea->name+temp_fea->name_len+1, | 5417 | temp_fea->name+temp_fea->name_len+1, |
5308 | rc); | 5418 | rc); |
5309 | /* ea values, unlike ea names, | 5419 | /* ea values, unlike ea |
5310 | are not null terminated */ | 5420 | names, are not null |
5311 | } else if(buf_size == 0) { | 5421 | terminated */ |
5422 | } else if (buf_size == 0) { | ||
5312 | /* skip copy - calc size only */ | 5423 | /* skip copy - calc size only */ |
5313 | } else { | 5424 | } else { |
5314 | /* stop before overrun buffer */ | 5425 | /* stop before overrun buffer */ |
5315 | rc = -ERANGE; | 5426 | rc = -ERANGE; |
5316 | } | 5427 | } |
5317 | break; | 5428 | break; |
@@ -5323,11 +5434,11 @@ QEARetry: | |||
5323 | temp_ptr++; | 5434 | temp_ptr++; |
5324 | name_len -= value_len; | 5435 | name_len -= value_len; |
5325 | temp_ptr += value_len; | 5436 | temp_ptr += value_len; |
5326 | /* no trailing null to account for in value len */ | 5437 | /* No trailing null to account for in |
5327 | /* go on to next EA */ | 5438 | value_len. Go on to next EA */ |
5328 | temp_fea = (struct fea *)temp_ptr; | 5439 | temp_fea = (struct fea *)temp_ptr; |
5329 | } | 5440 | } |
5330 | } | 5441 | } |
5331 | } | 5442 | } |
5332 | } | 5443 | } |
5333 | if (pSMB) | 5444 | if (pSMB) |
@@ -5340,9 +5451,9 @@ QEARetry: | |||
5340 | 5451 | ||
5341 | int | 5452 | int |
5342 | CIFSSMBSetEA(const int xid, struct cifsTconInfo *tcon, const char *fileName, | 5453 | CIFSSMBSetEA(const int xid, struct cifsTconInfo *tcon, const char *fileName, |
5343 | const char * ea_name, const void * ea_value, | 5454 | const char *ea_name, const void *ea_value, |
5344 | const __u16 ea_value_len, const struct nls_table *nls_codepage, | 5455 | const __u16 ea_value_len, const struct nls_table *nls_codepage, |
5345 | int remap) | 5456 | int remap) |
5346 | { | 5457 | { |
5347 | struct smb_com_transaction2_spi_req *pSMB = NULL; | 5458 | struct smb_com_transaction2_spi_req *pSMB = NULL; |
5348 | struct smb_com_transaction2_spi_rsp *pSMBr = NULL; | 5459 | struct smb_com_transaction2_spi_rsp *pSMBr = NULL; |
@@ -5361,11 +5472,11 @@ SetEARetry: | |||
5361 | 5472 | ||
5362 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { | 5473 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
5363 | name_len = | 5474 | name_len = |
5364 | cifsConvertToUCS((__le16 *) pSMB->FileName, fileName, | 5475 | cifsConvertToUCS((__le16 *) pSMB->FileName, fileName, |
5365 | PATH_MAX, nls_codepage, remap); | 5476 | PATH_MAX, nls_codepage, remap); |
5366 | name_len++; /* trailing null */ | 5477 | name_len++; /* trailing null */ |
5367 | name_len *= 2; | 5478 | name_len *= 2; |
5368 | } else { /* BB improve the check for buffer overruns BB */ | 5479 | } else { /* BB improve the check for buffer overruns BB */ |
5369 | name_len = strnlen(fileName, PATH_MAX); | 5480 | name_len = strnlen(fileName, PATH_MAX); |
5370 | name_len++; /* trailing null */ | 5481 | name_len++; /* trailing null */ |
5371 | strncpy(pSMB->FileName, fileName, name_len); | 5482 | strncpy(pSMB->FileName, fileName, name_len); |
@@ -5376,10 +5487,10 @@ SetEARetry: | |||
5376 | /* done calculating parms using name_len of file name, | 5487 | /* done calculating parms using name_len of file name, |
5377 | now use name_len to calculate length of ea name | 5488 | now use name_len to calculate length of ea name |
5378 | we are going to create in the inode xattrs */ | 5489 | we are going to create in the inode xattrs */ |
5379 | if(ea_name == NULL) | 5490 | if (ea_name == NULL) |
5380 | name_len = 0; | 5491 | name_len = 0; |
5381 | else | 5492 | else |
5382 | name_len = strnlen(ea_name,255); | 5493 | name_len = strnlen(ea_name, 255); |
5383 | 5494 | ||
5384 | count = sizeof(*parm_data) + ea_value_len + name_len + 1; | 5495 | count = sizeof(*parm_data) + ea_value_len + name_len + 1; |
5385 | pSMB->MaxParameterCount = cpu_to_le16(2); | 5496 | pSMB->MaxParameterCount = cpu_to_le16(2); |
@@ -5390,7 +5501,7 @@ SetEARetry: | |||
5390 | pSMB->Timeout = 0; | 5501 | pSMB->Timeout = 0; |
5391 | pSMB->Reserved2 = 0; | 5502 | pSMB->Reserved2 = 0; |
5392 | param_offset = offsetof(struct smb_com_transaction2_spi_req, | 5503 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
5393 | InformationLevel) - 4; | 5504 | InformationLevel) - 4; |
5394 | offset = param_offset + params; | 5505 | offset = param_offset + params; |
5395 | pSMB->InformationLevel = | 5506 | pSMB->InformationLevel = |
5396 | cpu_to_le16(SMB_SET_FILE_EA); | 5507 | cpu_to_le16(SMB_SET_FILE_EA); |
@@ -5410,17 +5521,19 @@ SetEARetry: | |||
5410 | /* we checked above that name len is less than 255 */ | 5521 | /* we checked above that name len is less than 255 */ |
5411 | parm_data->list[0].name_len = (__u8)name_len; | 5522 | parm_data->list[0].name_len = (__u8)name_len; |
5412 | /* EA names are always ASCII */ | 5523 | /* EA names are always ASCII */ |
5413 | if(ea_name) | 5524 | if (ea_name) |
5414 | strncpy(parm_data->list[0].name,ea_name,name_len); | 5525 | strncpy(parm_data->list[0].name, ea_name, name_len); |
5415 | parm_data->list[0].name[name_len] = 0; | 5526 | parm_data->list[0].name[name_len] = 0; |
5416 | parm_data->list[0].value_len = cpu_to_le16(ea_value_len); | 5527 | parm_data->list[0].value_len = cpu_to_le16(ea_value_len); |
5417 | /* caller ensures that ea_value_len is less than 64K but | 5528 | /* caller ensures that ea_value_len is less than 64K but |
5418 | we need to ensure that it fits within the smb */ | 5529 | we need to ensure that it fits within the smb */ |
5419 | 5530 | ||
5420 | /*BB add length check that it would fit in negotiated SMB buffer size BB */ | 5531 | /*BB add length check to see if it would fit in |
5421 | /* if(ea_value_len > buffer_size - 512 (enough for header)) */ | 5532 | negotiated SMB buffer size BB */ |
5422 | if(ea_value_len) | 5533 | /* if (ea_value_len > buffer_size - 512 (enough for header)) */ |
5423 | memcpy(parm_data->list[0].name+name_len+1,ea_value,ea_value_len); | 5534 | if (ea_value_len) |
5535 | memcpy(parm_data->list[0].name+name_len+1, | ||
5536 | ea_value, ea_value_len); | ||
5424 | 5537 | ||
5425 | pSMB->TotalDataCount = pSMB->DataCount; | 5538 | pSMB->TotalDataCount = pSMB->DataCount; |
5426 | pSMB->ParameterCount = cpu_to_le16(params); | 5539 | pSMB->ParameterCount = cpu_to_le16(params); |