smb_opipe.c revision 8b2cc8ac894f2d58f38cf2fb7c3ac778f4c57c09
3db3f65c6274eb042354801a308c8e9bc4994553amw * CDDL HEADER START
3db3f65c6274eb042354801a308c8e9bc4994553amw * The contents of this file are subject to the terms of the
3db3f65c6274eb042354801a308c8e9bc4994553amw * Common Development and Distribution License (the "License").
3db3f65c6274eb042354801a308c8e9bc4994553amw * You may not use this file except in compliance with the License.
3db3f65c6274eb042354801a308c8e9bc4994553amw * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
3db3f65c6274eb042354801a308c8e9bc4994553amw * See the License for the specific language governing permissions
3db3f65c6274eb042354801a308c8e9bc4994553amw * and limitations under the License.
3db3f65c6274eb042354801a308c8e9bc4994553amw * When distributing Covered Code, include this CDDL HEADER in each
3db3f65c6274eb042354801a308c8e9bc4994553amw * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
3db3f65c6274eb042354801a308c8e9bc4994553amw * If applicable, add the following below this CDDL HEADER, with the
3db3f65c6274eb042354801a308c8e9bc4994553amw * fields enclosed by brackets "[]" replaced with your own identifying
3db3f65c6274eb042354801a308c8e9bc4994553amw * information: Portions Copyright [yyyy] [name of copyright owner]
3db3f65c6274eb042354801a308c8e9bc4994553amw * CDDL HEADER END
8b2cc8ac894f2d58f38cf2fb7c3ac778f4c57c09afshin salek ardakani - Sun Microsystems - Irvine United States * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
3db3f65c6274eb042354801a308c8e9bc4994553amw * Use is subject to license terms.
3db3f65c6274eb042354801a308c8e9bc4994553amw * This module provides the interface to NDR RPC.
3db3f65c6274eb042354801a308c8e9bc4994553amwstatic int smb_opipe_do_open(smb_request_t *, smb_opipe_t *);
3db3f65c6274eb042354801a308c8e9bc4994553amwstatic int smb_opipe_set_hdr(smb_opipe_t *opipe, uint32_t, uint32_t);
3db3f65c6274eb042354801a308c8e9bc4994553amwstatic void smb_user_context_fini(smb_opipe_context_t *);
3db3f65c6274eb042354801a308c8e9bc4994553amw * smb_opipe_open
3db3f65c6274eb042354801a308c8e9bc4994553amw * Open a well-known RPC named pipe. This routine should be called if
3db3f65c6274eb042354801a308c8e9bc4994553amw * a file open is requested on a share of type STYPE_IPC.
3db3f65c6274eb042354801a308c8e9bc4994553amw * If we recognize the pipe, we setup a new ofile.
3db3f65c6274eb042354801a308c8e9bc4994553amw * Returns 0 on success, Otherwise an NT status is returned to indicate
3db3f65c6274eb042354801a308c8e9bc4994553amw * an error.
8b2cc8ac894f2d58f38cf2fb7c3ac778f4c57c09afshin salek ardakani - Sun Microsystems - Irvine United States open_param_t *op = &sr->arg.open;
3db3f65c6274eb042354801a308c8e9bc4994553amw if ((pipe_name = smb_opipe_lookup(op->fqi.path)) == NULL)
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego of = smb_ofile_open(sr->tid_tree, NULL, sr->smb_pid, op,
8b2cc8ac894f2d58f38cf2fb7c3ac778f4c57c09afshin salek ardakani - Sun Microsystems - Irvine United States
8b2cc8ac894f2d58f38cf2fb7c3ac778f4c57c09afshin salek ardakani - Sun Microsystems - Irvine United States if (!smb_tree_is_connected(sr->tid_tree)) {
8b2cc8ac894f2d58f38cf2fb7c3ac778f4c57c09afshin salek ardakani - Sun Microsystems - Irvine United States smb_ofile_close(of, 0);
8b2cc8ac894f2d58f38cf2fb7c3ac778f4c57c09afshin salek ardakani - Sun Microsystems - Irvine United States smb_ofile_release(of);
8b2cc8ac894f2d58f38cf2fb7c3ac778f4c57c09afshin salek ardakani - Sun Microsystems - Irvine United States return (NT_STATUS_OBJECT_NAME_NOT_FOUND);
8b2cc8ac894f2d58f38cf2fb7c3ac778f4c57c09afshin salek ardakani - Sun Microsystems - Irvine United States }
8b2cc8ac894f2d58f38cf2fb7c3ac778f4c57c09afshin salek ardakani - Sun Microsystems - Irvine United States
3db3f65c6274eb042354801a308c8e9bc4994553amw op->action_taken = SMB_OACT_LOCK | SMB_OACT_OPENED; /* 0x8001 */
3db3f65c6274eb042354801a308c8e9bc4994553amw opipe->p_doorbuf = kmem_zalloc(SMB_OPIPE_DOOR_BUFSIZE, KM_SLEEP);
3db3f65c6274eb042354801a308c8e9bc4994553amw * p_data points to the offset within p_doorbuf at which
3db3f65c6274eb042354801a308c8e9bc4994553amw * data will be written or read.
3db3f65c6274eb042354801a308c8e9bc4994553amw opipe->p_data = opipe->p_doorbuf + xdr_sizeof(smb_opipe_hdr_xdr, &hdr);
3db3f65c6274eb042354801a308c8e9bc4994553amw * On error, reset the header to clear the fid,
3db3f65c6274eb042354801a308c8e9bc4994553amw * which avoids confusion when smb_opipe_close() is
3db3f65c6274eb042354801a308c8e9bc4994553amw * called by smb_ofile_close().
3db3f65c6274eb042354801a308c8e9bc4994553amw * smb_opipe_lookup
3db3f65c6274eb042354801a308c8e9bc4994553amw * Lookup a path to see if it's a well-known RPC named pipe that we support.
3db3f65c6274eb042354801a308c8e9bc4994553amw * The full pipe path will be in the form \\PIPE\\SERVICE. The first part
3db3f65c6274eb042354801a308c8e9bc4994553amw * can be assumed, so all we need here are the service names.
3db3f65c6274eb042354801a308c8e9bc4994553amw * Returns a pointer to the pipe name (without any leading \'s) on sucess.
3db3f65c6274eb042354801a308c8e9bc4994553amw * Otherwise returns a null pointer.
3db3f65c6274eb042354801a308c8e9bc4994553amwstatic char *
3db3f65c6274eb042354801a308c8e9bc4994553amw static char *named_pipes[] = {
3db3f65c6274eb042354801a308c8e9bc4994553amw "NETLOGON",
3db3f65c6274eb042354801a308c8e9bc4994553amw "SPOOLSS",
3db3f65c6274eb042354801a308c8e9bc4994553amw "EVENTLOG"
3db3f65c6274eb042354801a308c8e9bc4994553amw const char *name;
3db3f65c6274eb042354801a308c8e9bc4994553amw for (i = 0; i < sizeof (named_pipes) / sizeof (named_pipes[0]); ++i) {
3db3f65c6274eb042354801a308c8e9bc4994553amw return (named_pipes[i]);
3db3f65c6274eb042354801a308c8e9bc4994553amw * Initialize the opipe header and context, and make the door call.
3db3f65c6274eb042354801a308c8e9bc4994553amw if (smb_opipe_set_hdr(opipe, SMB_OPIPE_OPEN, len) == -1)
3db3f65c6274eb042354801a308c8e9bc4994553amw return (-1);
3db3f65c6274eb042354801a308c8e9bc4994553amw return (-1);
3db3f65c6274eb042354801a308c8e9bc4994553amw * smb_opipe_fid
3db3f65c6274eb042354801a308c8e9bc4994553amw * The opipe_fid is an arbitrary id used to associate RPC requests
3db3f65c6274eb042354801a308c8e9bc4994553amw * with a binding handle. A new fid is returned on each call.
3db3f65c6274eb042354801a308c8e9bc4994553amw * 0 or -1 are not assigned: 0 is used to indicate an invalid fid
3db3f65c6274eb042354801a308c8e9bc4994553amw * and SMB sometimes uses -1 to indicate all open fid's.
3db3f65c6274eb042354801a308c8e9bc4994553amw * smb_opipe_close
3db3f65c6274eb042354801a308c8e9bc4994553amw * Called whenever an IPC file/pipe is closed.
3db3f65c6274eb042354801a308c8e9bc4994553amwsmb_opipe_set_hdr(smb_opipe_t *opipe, uint32_t cmd, uint32_t datalen)
3db3f65c6274eb042354801a308c8e9bc4994553amw return (smb_opipe_hdr_encode(&opipe->p_hdr, opipe->p_doorbuf,
3db3f65c6274eb042354801a308c8e9bc4994553amw * smb_opipe_transact
3db3f65c6274eb042354801a308c8e9bc4994553amw * This is the entry point for RPC bind and request transactions.
3db3f65c6274eb042354801a308c8e9bc4994553amw * The fid is an arbitrary id used to associate RPC requests with a
3db3f65c6274eb042354801a308c8e9bc4994553amw * particular binding handle.
3db3f65c6274eb042354801a308c8e9bc4994553amw * If the data to be returned is larger than the client expects, we
3db3f65c6274eb042354801a308c8e9bc4994553amw * return as much as the client can handle and report a buffer overflow
3db3f65c6274eb042354801a308c8e9bc4994553amw * warning, which informs the client that we have more data to return.
3db3f65c6274eb042354801a308c8e9bc4994553amw * The residual data remains in the pipe until the client claims it or
3db3f65c6274eb042354801a308c8e9bc4994553amw * closes the pipe.
3db3f65c6274eb042354801a308c8e9bc4994553amw if (smb_opipe_set_hdr(opipe, SMB_OPIPE_READ, mdrcnt) == -1) {
3db3f65c6274eb042354801a308c8e9bc4994553amw if (rc != 0) {
3db3f65c6274eb042354801a308c8e9bc4994553amw * The pipe contains more data than mdrcnt, warn the
3db3f65c6274eb042354801a308c8e9bc4994553amw * client that there is more data in the pipe.
3db3f65c6274eb042354801a308c8e9bc4994553amw * Typically, the client will call SmbReadX, which
3db3f65c6274eb042354801a308c8e9bc4994553amw * will call smb_opipe_read, to get the data.
3db3f65c6274eb042354801a308c8e9bc4994553amw * smb_opipe_write
3db3f65c6274eb042354801a308c8e9bc4994553amw * Write RPC request data to the pipe. The client should call smb_opipe_read
3db3f65c6274eb042354801a308c8e9bc4994553amw * to complete the exchange and obtain the RPC response.
3db3f65c6274eb042354801a308c8e9bc4994553amw * Returns 0 on success or an errno on failure.
3db3f65c6274eb042354801a308c8e9bc4994553amw rc = smb_opipe_set_hdr(opipe, SMB_OPIPE_WRITE, uio->uio_resid);
3db3f65c6274eb042354801a308c8e9bc4994553amw (void) uiomove((caddr_t)opipe->p_data, buflen, UIO_WRITE, uio);
3db3f65c6274eb042354801a308c8e9bc4994553amw * smb_opipe_read
3db3f65c6274eb042354801a308c8e9bc4994553amw * This interface may be called because smb_opipe_transact could not return
3db3f65c6274eb042354801a308c8e9bc4994553amw * all of the data in the original transaction or to form the second half
3db3f65c6274eb042354801a308c8e9bc4994553amw * of a transaction set up using smb_opipe_write. Either way, we just need
3db3f65c6274eb042354801a308c8e9bc4994553amw * to read data from the pipe and return it.
3db3f65c6274eb042354801a308c8e9bc4994553amw * The response data is encoded into raw_data as required by the smb_read
3db3f65c6274eb042354801a308c8e9bc4994553amw * functions. The uio_resid value indicates the number of bytes read.
3db3f65c6274eb042354801a308c8e9bc4994553amw if (smb_opipe_set_hdr(opipe, SMB_OPIPE_READ, uio->uio_resid) == -1) {
3db3f65c6274eb042354801a308c8e9bc4994553amw * Named pipe I/O is serialized per fid to ensure that each request
3db3f65c6274eb042354801a308c8e9bc4994553amw * has exclusive opipe access for the duration of the request.
3db3f65c6274eb042354801a308c8e9bc4994553amwstatic void
3db3f65c6274eb042354801a308c8e9bc4994553amwstatic void
3db3f65c6274eb042354801a308c8e9bc4994553amw * opipe door client (to user space door server).
3db3f65c6274eb042354801a308c8e9bc4994553amw mutex_init(&smb_opipe_door_mutex, NULL, MUTEX_DEFAULT, NULL);
3db3f65c6274eb042354801a308c8e9bc4994553amw * Open the (user space) door. If the door is already open,
3db3f65c6274eb042354801a308c8e9bc4994553amw * close it first because the door-id has probably changed.
3db3f65c6274eb042354801a308c8e9bc4994553amw * Close the (user space) door.
3db3f65c6274eb042354801a308c8e9bc4994553amw * opipe door call interface.
3db3f65c6274eb042354801a308c8e9bc4994553amw * Door serialization and call reference accounting is handled here.
3db3f65c6274eb042354801a308c8e9bc4994553amw return (-1);
3db3f65c6274eb042354801a308c8e9bc4994553amw * Door upcall wrapper - handles data marshalling.
3db3f65c6274eb042354801a308c8e9bc4994553amw * This function should only be called by smb_opipe_door_call.
3db3f65c6274eb042354801a308c8e9bc4994553amw for (i = 0; i < 3; ++i) {
3db3f65c6274eb042354801a308c8e9bc4994553amw if ((rc = door_ki_upcall_limited(smb_opipe_door_hd, &da,
3db3f65c6274eb042354801a308c8e9bc4994553amw return (-1);
3db3f65c6274eb042354801a308c8e9bc4994553amw return (-1);
3db3f65c6274eb042354801a308c8e9bc4994553amw if (smb_opipe_hdr_decode(&hdr, (uint8_t *)da.rbuf, da.rsize) == -1)
3db3f65c6274eb042354801a308c8e9bc4994553amw return (-1);
3db3f65c6274eb042354801a308c8e9bc4994553amw return (-1);
3db3f65c6274eb042354801a308c8e9bc4994553amw return (0);
3db3f65c6274eb042354801a308c8e9bc4994553amwsmb_user_context_init(smb_user_t *user, smb_opipe_context_t *ctx)
3db3f65c6274eb042354801a308c8e9bc4994553amw ctx->oc_domain = smb_kstrdup(user->u_domain, ctx->oc_domain_len);
3db3f65c6274eb042354801a308c8e9bc4994553amw ctx->oc_account = smb_kstrdup(user->u_name, ctx->oc_account_len);
3db3f65c6274eb042354801a308c8e9bc4994553amw ctx->oc_workstation_len = strlen(session->workstation) + 1;
3db3f65c6274eb042354801a308c8e9bc4994553amwstatic void