smb_opipe.c revision 8b2cc8ac894f2d58f38cf2fb7c3ac778f4c57c09
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* This module provides the interface to NDR RPC.
*/
#include <sys/door_data.h>
#include <smbsrv/smb_incl.h>
#define SMB_OPIPE_ISOPEN(OPIPE) \
static char *smb_opipe_lookup(const char *path);
static uint32_t smb_opipe_fid(void);
static void smb_opipe_enter(smb_opipe_t *);
static void smb_opipe_exit(smb_opipe_t *);
static int smb_opipe_door_id = -1;
static uint64_t smb_opipe_door_ncall = 0;
static kmutex_t smb_opipe_door_mutex;
static kcondvar_t smb_opipe_door_cv;
static int smb_opipe_door_call(smb_opipe_t *);
static int smb_opipe_door_upcall(smb_opipe_t *);
static void smb_user_context_fini(smb_opipe_context_t *);
/*
* smb_opipe_open
*
* Open a well-known RPC named pipe. This routine should be called if
* a file open is requested on a share of type STYPE_IPC.
* If we recognize the pipe, we setup a new ofile.
*
* Returns 0 on success, Otherwise an NT status is returned to indicate
* an error.
*/
int
{
char *pipe_name;
return (NT_STATUS_OBJECT_NAME_NOT_FOUND);
op->create_options = 0;
smb_ofile_close(of, 0);
return (NT_STATUS_OBJECT_NAME_NOT_FOUND);
}
| SMB_PIPE_UNLIMITED_INSTANCES; /* 0x05ff */
/*
* p_data points to the offset within p_doorbuf at which
* data will be written or read.
*/
/*
* On error, reset the header to clear the fid,
* which avoids confusion when smb_opipe_close() is
* called by smb_ofile_close().
*/
smb_ofile_close(of, 0);
return (NT_STATUS_NO_MEMORY);
}
return (NT_STATUS_SUCCESS);
}
/*
* smb_opipe_lookup
*
* Lookup a path to see if it's a well-known RPC named pipe that we support.
* The full pipe path will be in the form \\PIPE\\SERVICE. The first part
* can be assumed, so all we need here are the service names.
*
* Returns a pointer to the pipe name (without any leading \'s) on sucess.
* Otherwise returns a null pointer.
*/
static char *
smb_opipe_lookup(const char *path)
{
static char *named_pipes[] = {
"LSARPC",
"NETLOGON",
"SAMR",
"SPOOLSS",
"SRVSVC",
"SVCCTL",
"WINREG",
"WKSSVC",
"EVENTLOG"
};
const char *name;
int i;
return (NULL);
path += 4;
}
for (i = 0; i < sizeof (named_pipes) / sizeof (named_pipes[0]); ++i) {
return (named_pipes[i]);
}
return (NULL);
}
/*
* Initialize the opipe header and context, and make the door call.
*/
static int
{
return (-1);
return (-1);
return (smb_opipe_door_call(opipe));
}
/*
* smb_opipe_fid
*
* The opipe_fid is an arbitrary id used to associate RPC requests
* with a binding handle. A new fid is returned on each call.
* 0 or -1 are not assigned: 0 is used to indicate an invalid fid
* and SMB sometimes uses -1 to indicate all open fid's.
*/
static uint32_t
smb_opipe_fid(void)
{
static kmutex_t smb_opipe_fid_mutex;
if (opipe_fid == 0)
do {
++opipe_fid;
return (opipe_fid);
}
/*
* smb_opipe_close
*
*/
void
{
if (SMB_OPIPE_ISOPEN(opipe)) {
(void) smb_opipe_door_call(opipe);
}
}
static int
{
}
/*
* smb_opipe_transact
*
* This is the entry point for RPC bind and request transactions.
* The fid is an arbitrary id used to associate RPC requests with a
* particular binding handle.
*
* If the data to be returned is larger than the client expects, we
* return as much as the client can handle and report a buffer overflow
* warning, which informs the client that we have more data to return.
* The residual data remains in the pipe until the client claims it or
* closes the pipe.
*/
{
int mdrcnt;
int nbytes;
int rc;
else
return (SDRC_ERROR);
}
return (SDRC_ERROR);
}
if (rc != 0) {
return (SDRC_ERROR);
}
if (nbytes) {
}
/*
* The pipe contains more data than mdrcnt, warn the
* client that there is more data in the pipe.
* Typically, the client will call SmbReadX, which
* will call smb_opipe_read, to get the data.
*/
}
return (SDRC_SUCCESS);
}
/*
* smb_opipe_write
*
* Write RPC request data to the pipe. The client should call smb_opipe_read
* to complete the exchange and obtain the RPC response.
*
* Returns 0 on success or an errno on failure.
*/
int
{
int rc;
if (!SMB_OPIPE_ISOPEN(opipe)) {
return (EBADF);
}
return (ENOMEM);
}
}
/*
* smb_opipe_read
*
* This interface may be called because smb_opipe_transact could not return
* all of the data in the original transaction or to form the second half
* of a transaction set up using smb_opipe_write. Either way, we just need
* to read data from the pipe and return it.
*
* The response data is encoded into raw_data as required by the smb_read
* functions. The uio_resid value indicates the number of bytes read.
*/
int
{
int rc;
if (!SMB_OPIPE_ISOPEN(opipe)) {
return (EBADF);
}
return (ENOMEM);
}
return (EIO);
}
if (nbytes) {
}
return (rc);
}
/*
* Named pipe I/O is serialized per fid to ensure that each request
* has exclusive opipe access for the duration of the request.
*/
static void
{
}
static void
{
}
/*
* opipe door client (to user space door server).
*/
void
smb_opipe_door_init(void)
{
}
void
smb_opipe_door_fini(void)
{
}
/*
* Open the (user space) door. If the door is already open,
* close it first because the door-id has probably changed.
*/
int
{
smb_opipe_door_ncall = 0;
if (smb_opipe_door_hd == NULL) {
}
}
/*
* Close the (user space) door.
*/
void
smb_opipe_door_close(void)
{
if (smb_opipe_door_hd != NULL) {
while (smb_opipe_door_ncall > 0)
}
}
/*
* opipe door call interface.
* Door serialization and call reference accounting is handled here.
*/
static int
{
int rc;
if (smb_opipe_door_hd == NULL) {
if (smb_opipe_door_open(smb_opipe_door_id) != 0)
return (-1);
}
return (rc);
}
/*
* Door upcall wrapper - handles data marshalling.
* This function should only be called by smb_opipe_door_call.
*/
static int
{
int i;
int rc;
for (i = 0; i < 3; ++i) {
break;
return (-1);
}
if (rc != 0)
return (-1);
return (-1);
return (-1);
}
return (0);
}
void
{
}
static void
{
if (ctx) {
if (ctx->oc_account)
if (ctx->oc_workstation)
}
}
void
{
int i;
if (userlist) {
}
}