smbfs_rq.c revision 2
2N/A * Copyright (c) 2000, Boris Popov 2N/A * All rights reserved. 2N/A * Redistribution and use in source and binary forms, with or without 2N/A * modification, are permitted provided that the following conditions 2N/A * 1. Redistributions of source code must retain the above copyright 2N/A * notice, this list of conditions and the following disclaimer. 2N/A * 2. Redistributions in binary form must reproduce the above copyright 2N/A * notice, this list of conditions and the following disclaimer in the 2N/A * documentation and/or other materials provided with the distribution. 2N/A * 3. All advertising materials mentioning features or use of this software 2N/A * must display the following acknowledgement: 2N/A * This product includes software developed by Boris Popov. 2N/A * 4. Neither the name of the author nor the names of any co-contributors 2N/A * may be used to endorse or promote products derived from this software 2N/A * without specific prior written permission. 2N/A * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 2N/A * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2N/A * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2N/A * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 2N/A * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2N/A * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2N/A * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2N/A * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2N/A * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2N/A * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2N/A * Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved. 2N/A * Create and initialize a request structure, for either an 2N/A * "internal" request (one that does not use the driver) or 2N/A * a regular "driver" request, that uses driver ioctls. 2N/A * The two kinds are built a little differently: 2N/A * Driver requests are composed starting with the 2N/A * first word of the "variable word vector" section. 2N/A * The driver prepends the SMB header and word count. 2N/A * The driver also needs an output buffer to receive 2N/A * the response, filled in via copyout in the ioctl. 2N/A * Internal requests are composed entirely in this library. 2N/A * Space for the SMB header is reserved here, and later 2N/A * Setup the request buffer. 2N/A * Do the reply buffer later. 2N/A /* Space for the SMB header (filled in later) */ 2N/A * Copy the ctx flags here, so the caller can 2N/A * update the req flags before the OTW call. 2N/A * Reserve space for the word count, which is filled in later by 2N/A * smbfs_rq_wend(). Also initialize the counter that it uses 2N/A * to figure out what value to fill in. 2N/A * Note that the word count happens to be 8-bits, 2N/A * which can lead to confusion. 2N/A * Fill in the word count, in the space reserved by 2N/A * smbfs_rq_wstart(). 2N/A * Fill in the word count (8-bits). 2N/A * Also store it in the rq, in case 2N/A * we're using the ioctl path. 2N/A * Reserve space for the byte count, which is filled in later by 2N/A * smbfs_rq_bend(). Also initialize the counter that it uses 2N/A * to figure out what value to fill in. 2N/A * Note that the byte count happens to be 16-bits, 2N/A * which can lead to confusion. 2N/A * Fill in the byte count, in the space reserved by 2N/A * smbfs_rq_bstart(). * Fill in the byte count (16-bits). * Also store it in the rq, in case * we're using the ioctl path. * The pointer is char * type due to * typical off-by-one alignment. * Do an over-the-wire call without using the nsmb driver. * This is all "internal" to this library, and used only * for connection setup (negotiate protocol, etc.) * Fill in the NBT and SMB headers * Using mbtmp so we can rewind without * affecting the passed request mbdata. /* Have to save and restore m_len */ * rewind done; fill it in /* pid_hi(2), signature(8), reserved(2) */ /* Restore original m_len */ * Sign the message, if flags2 indicates. * Send it, wait for the reply. * Should have an SMB header, at least. * If the request was signed, validate the * signature on the response. /* pid_hi(2), signature(8), reserved(2) */ * Figure out the status return. * Caller looks at rq_status. * Map old DOS errors (etc.) to NT status codes. * We probably don't need this anymore, since * the oldest server we talk to is NT. But if * later find we do need this, add support here * for the DOS errors we care about.