ndr_server.c revision 2c1b14e51525da2c09064641416fc4aed457c72f
/*
* 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 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Server side RPC handler.
*/
#include <sys/byteorder.h>
#include <thread.h>
#include <synch.h>
#include <stdlib.h>
#include <strings.h>
#include <string.h>
#include <time.h>
#include <smbsrv/libmlrpc.h>
#include <smbsrv/mlsvc_util.h>
#define SMB_CTXT_BUFSZ 65536
/*
* Fragment size (5680: NT style).
*/
#define MLRPC_FRAG_SZ 5680
static unsigned long mlrpc_frag_size = MLRPC_FRAG_SZ;
/*
* Service context table.
*/
#define CTXT_TABLE_ENTRIES 128
static mutex_t mlrpc_context_lock;
static int ndr_s_transact(struct mlsvc_rpc_context *);
static struct mlsvc_rpc_context *ndr_s_lookup(int);
static void ndr_s_release(struct mlsvc_rpc_context *);
static struct mlsvc_rpc_context *ndr_s_allocate(int);
static void ndr_s_deallocate(struct mlsvc_rpc_context *);
static void ndr_s_rewind(struct mlsvc_rpc_context *);
static void ndr_s_flush(struct mlsvc_rpc_context *);
static int mlrpc_s_process(struct mlrpc_xaction *);
static int mlrpc_s_bind(struct mlrpc_xaction *);
static int mlrpc_s_request(struct mlrpc_xaction *);
static void mlrpc_reply_prepare_hdr(struct mlrpc_xaction *);
static int mlrpc_s_alter_context(struct mlrpc_xaction *);
static void mlrpc_reply_fault(struct mlrpc_xaction *, unsigned long);
static int mlrpc_build_reply(struct mlrpc_xaction *);
/*
* Allocate and associate a service context with a fid.
*/
int
{
struct mlsvc_rpc_context *svc;
(void) mutex_lock(&mlrpc_context_lock);
(void) mutex_unlock(&mlrpc_context_lock);
return (EEXIST);
}
(void) mutex_unlock(&mlrpc_context_lock);
return (ENOMEM);
}
(void) mutex_unlock(&mlrpc_context_lock);
return (EINVAL);
}
(void) mutex_unlock(&mlrpc_context_lock);
return (0);
}
/*
* Release the context associated with a fid when an opipe is closed.
*/
int
ndr_s_close(int fid)
{
struct mlsvc_rpc_context *svc;
(void) mutex_lock(&mlrpc_context_lock);
(void) mutex_unlock(&mlrpc_context_lock);
return (ENOENT);
}
/*
* Release twice: once for the lookup above
* and again to close the fid.
*/
(void) mutex_unlock(&mlrpc_context_lock);
return (0);
}
/*
* Write RPC request data to the input stream. Input data is buffered
* until the response is requested.
*/
int
{
struct mlsvc_rpc_context *svc;
if (len == 0)
return (0);
(void) mutex_lock(&mlrpc_context_lock);
(void) mutex_unlock(&mlrpc_context_lock);
return (ENOENT);
}
(void) mutex_unlock(&mlrpc_context_lock);
}
/*
* Read RPC response data. If the input stream contains an RPC request,
* we need to process the RPC transaction, which will place the RPC
* response in the output (frags) stream. Otherwise, read data from
* the output stream.
*/
int
{
struct mlsvc_rpc_context *svc;
int rc;
if (nbytes == 0) {
*resid = 0;
return (0);
}
(void) mutex_lock(&mlrpc_context_lock);
(void) mutex_unlock(&mlrpc_context_lock);
return (ENOENT);
}
(void) mutex_unlock(&mlrpc_context_lock);
(void) mutex_lock(&mlrpc_context_lock);
(void) mutex_unlock(&mlrpc_context_lock);
return (rc);
}
}
if (*resid == 0) {
/*
* Nothing left, cleanup the output stream.
*/
}
(void) mutex_lock(&mlrpc_context_lock);
(void) mutex_unlock(&mlrpc_context_lock);
return (0);
}
/*
* Process a server-side RPC request.
*/
static int
{
struct mlndr_stream *recv_mlnds;
struct mlndr_stream *send_mlnds;
char *data;
int datalen;
return (ENOMEM);
return (ENOMEM);
}
/*
* Copy the input data and reset the input stream.
*/
(void) mlrpc_s_process(mxa);
return (0);
}
/*
* Must be called with mlrpc_context_lock held.
*/
static struct mlsvc_rpc_context *
ndr_s_lookup(int fid)
{
struct mlsvc_rpc_context *svc;
int i;
for (i = 0; i < CTXT_TABLE_ENTRIES; ++i) {
svc = &context_table[i];
return (NULL);
return (svc);
}
}
return (NULL);
}
/*
* Must be called with mlrpc_context_lock held.
*/
static void
{
}
/*
* Must be called with mlrpc_context_lock held.
*/
static struct mlsvc_rpc_context *
ndr_s_allocate(int fid)
{
int i;
for (i = 0; i < CTXT_TABLE_ENTRIES; ++i) {
svc = &context_table[i];
return (NULL);
return (svc);
}
}
return (NULL);
}
/*
* Must be called with mlrpc_context_lock held.
*/
static void
{
/*
* Ensure that there are no RPC service policy handles
* (associated with this fid) left around.
*/
}
}
/*
* Rewind the input data stream, ready for the next write.
*/
static void
{
}
/*
* Flush the output data stream.
*/
static void
{
}
}
/*
* Check whether or not the specified user has administrator privileges,
* i.e. is a member of Domain Admins or Administrators.
* Returns true if the user is an administrator, otherwise returns false.
*/
{
}
/*
* Check whether or not the specified user has power-user privileges,
* i.e. is a member of Domain Admins, Administrators or Power Users.
* This is typically required for operations such as managing shares.
* Returns true if the user is a power user, otherwise returns false.
*/
{
}
{
return (svc->oc_native_os);
}
/*
* This is the entry point for all server-side RPC processing.
* It is assumed that the PDU has already been received.
*/
static int
{
int rc;
if (!MLRPC_DRC_IS_OK(rc))
return (-1);
(void) mlrpc_reply_prepare_hdr(mxa);
case MLRPC_PTYPE_BIND:
break;
case MLRPC_PTYPE_REQUEST:
break;
break;
default:
break;
}
if (MLRPC_DRC_IS_FAULT(rc))
(void) mlrpc_build_reply(mxa);
return (rc);
}
/*
* Multiple p_cont_elem[]s, multiple transfer_syntaxes[] and multiple
* p_results[] not supported.
*/
static int
{
unsigned p_cont_id;
struct mlrpc_binding *mbind;
char as_buf[64];
char ts_buf[64];
int as_vers;
int ts_vers;
struct mlndr_stream *send_mlnds;
struct mlrpc_service *msvc;
int rc;
/* acquire targets */
/*
* Set up temporary secondary address port.
* We will correct this later (below).
*/
result_list->reserved = 0;
result_list->reserved2 = 0;
/* sanity check */
mlndo_trace("mlrpc_s_bind: warning: multiple p_cont_elem");
}
/*
* Duplicate p_cont_id.
* Send a bind_ack with a better error.
*/
mlndo_trace("mlrpc_s_bind: duplicate binding");
return (MLRPC_DRC_FAULT_BIND_PCONT_BUSY);
}
/*
* No free binding slot
*/
mlndo_trace("mlrpc_s_bind: no resources");
return (MLRPC_DRC_OK);
}
if (!msvc) {
return (MLRPC_DRC_OK);
}
/*
* We can now use the correct secondary address port.
*/
/* mbind->context set by app */
mbind->instance_specific = 0;
/*
* Call the service-specific bind() handler. If
* this fails, we shouild send a specific error
* on the bind ack.
*/
if (MLRPC_DRC_IS_FAULT(rc)) {
mbind->which_side = 0;
mbind->instance_specific = 0;
return (rc);
}
}
return (MLRPC_DRC_BINDING_MADE);
}
/*
* mlrpc_s_alter_context
*
* The alter context request is used to request additional presentation
* a bind request.
*/
static int
{
struct mlrpc_binding *mbind;
struct mlrpc_service *msvc;
unsigned p_cont_id;
int as_vers;
int ts_vers;
result_list->reserved = 0;
result_list->reserved2 = 0;
return (MLRPC_DRC_FAULT_BIND_PCONT_BUSY);
return (MLRPC_DRC_OK);
}
if (msvc == 0) {
return (MLRPC_DRC_OK);
}
/* mbind->context set by app */
mbind->instance_specific = 0;
return (MLRPC_DRC_BINDING_MADE);
}
static int
{
struct mlrpc_binding *mbind;
struct mlrpc_service *msvc;
unsigned p_cont_id;
int rc;
return (MLRPC_DRC_FAULT_REQUEST_PCONT_INVALID);
/*
* Make room for the response hdr.
*/
else
if (MLRPC_DRC_IS_FAULT(rc)) {
mlndo_printf(0, 0, "%s[0x%02x]: 0x%04x",
}
return (rc);
}
/*
* The transaction and the two mlnds streams use the same heap, which
* should already exist at this point. The heap will also be available
* to the stub.
*/
int
{
struct mlrpc_stub_table *ste;
char *param;
int rc;
return (MLRPC_DRC_FAULT_OUT_OF_MEMORY);
}
mlndo_printf(0, 0, "%s[0x%02x]: invalid opnum",
return (MLRPC_DRC_FAULT_REQUEST_OPNUM_INVALID);
}
return (MLRPC_DRC_FAULT_OUT_OF_MEMORY);
if (!MLRPC_DRC_IS_OK(rc))
return (rc);
if (rc == MLRPC_DRC_OK)
return (rc);
}
/*
* We can perform some initial setup of the response header here.
* We also need to cache some of the information from the bind
* negotiation for use during subsequent RPC calls.
*/
static void
{
hdr->rpc_vers_minor = 0;
hdr->frag_length = 0;
hdr->auth_length = 0;
#ifdef _BIG_ENDIAN
#else
#endif
case MLRPC_PTYPE_BIND:
/*
* Save the maximum fragment sizes
* for use with subsequent requests.
*/
break;
case MLRPC_PTYPE_REQUEST:
/* mxa->send_hdr.response_hdr.alloc_hint */
break;
/*
* The max_xmit_frag, max_recv_frag and assoc_group_id are
* ignored by the client but it's useful to fill them in.
*/
break;
default:
}
}
/*
* Signal an RPC fault. The stream is reset and we overwrite whatever
* was in the response header with the fault information.
*/
static void
{
unsigned long fault_status;
hdr->rpc_vers_minor = 0;
hdr->auth_length = 0;
#ifdef _BIG_ENDIAN
#else
#endif
switch (drc & MLRPC_DRC_MASK_SPECIFIER) {
break;
break;
break;
break;
default:
break;
}
}
/*
* Note that the frag_length for bind ack and alter context is
* non-standard.
*/
static int
{
unsigned long pdu_size;
unsigned long frag_size;
unsigned long pdu_data_size;
unsigned long frag_data_size;
/*
* Single fragment response. The PDU size may be zero
* here (i.e. bind or fault response). So don't make
* any assumptions about it until after the header is
* encoded.
*/
case MLRPC_PTYPE_BIND_ACK:
break;
case MLRPC_PTYPE_FAULT:
/* already setup */
break;
case MLRPC_PTYPE_RESPONSE:
break;
break;
default:
break;
}
mlnds->pdu_scan_offset = 0;
(void) mlrpc_encode_pdu_hdr(mxa);
return (0);
}
/*
* Multiple fragment response.
*/
mlnds->pdu_scan_offset = 0;
(void) mlrpc_encode_pdu_hdr(mxa);
/*
* We need to update the 24-byte header in subsequent fragments.
*
* pdu_data_size: total data remaining to be handled
* frag_size: total fragment size including header
* frag_data_size: data in fragment
* (i.e. frag_size - MLRPC_RSP_HDR_SIZE)
*/
while (pdu_data_size) {
if (pdu_data_size <= frag_data_size) {
} else {
}
mlnds->pdu_scan_offset = 0;
(void) mlrpc_encode_pdu_hdr(mxa);
break;
}
return (0);
}
/*
* mlrpc_build_frag
*
* Build an RPC PDU fragment from the specified buffer.
* and report an error.
*/
static void
{
return;
} else {
}
}