/*
* 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 2015 Nexenta Systems, Inc. All rights reserved.
*/
/*
* Server side RPC handler.
*/
#include <sys/byteorder.h>
#include <errno.h>
#include <synch.h>
#include <stdlib.h>
#include <strings.h>
#include <string.h>
#include <thread.h>
#include <smbsrv/libmlrpc.h>
#include <smbsrv/ntaccess.h>
static int ndr_svc_process(ndr_xa_t *);
static int ndr_svc_bind(ndr_xa_t *);
static int ndr_svc_request(ndr_xa_t *);
static void ndr_reply_prepare_hdr(ndr_xa_t *);
static int ndr_svc_alter_context(ndr_xa_t *);
static void ndr_reply_fault(ndr_xa_t *, unsigned long);
static int ndr_send_reply(ndr_xa_t *);
/*
* External entry point called by smbd.
*/
void
{
int rc;
return;
do {
} while (rc == 0);
/*
* Ensure that there are no RPC service policy handles
* (associated with this fid) left around.
*/
}
/*
* Process one server-side RPC request.
*/
static int
{
goto out1;
if (rc != 0)
goto out2;
if (rc != 0)
goto out3;
if (rc != 0)
goto out4;
(void) ndr_svc_process(mxa);
(void) ndr_send_reply(mxa);
rc = 0;
out4:
out3:
out2:
out1:
return (rc);
}
/*
* 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 (ctx->ui_native_os);
}
/*
* Receive an entire RPC request (all fragments)
* Returns zero or an NDR fault code.
*/
static int
{
unsigned long saved_size;
int rc;
if (rc != 0)
return (rc);
return (NDR_DRC_FAULT_DECODE_FAILED);
if (rc != 0)
return (rc);
}
nds->pdu_scan_offset = 0;
/*
* It leaves scan_offset after the header.
*/
return (rc);
}
/*
* Read one fragment, leaving the decoded frag header in
* recv_hdr.common_hdr, and the data in the recv_nds.
*
* Returns zero or an NDR fault code.
*
* If a first frag, the header is included in the data
* placed in recv_nds (because it's not fully decoded
* until later - we only decode the common part here).
* Additional frags are placed in the recv_nds without
* the header, so that after the first frag header,
* the remaining data will be contiguous. We do this
* by simply not advancing the offset in recv_nds after
* reading and decoding these additional fragments, so
* the payload of such frags will overwrite what was
* (temporarily) the frag header.
*/
static int
{
unsigned char *data;
unsigned long next_offset;
unsigned long pay_size;
int rc;
/* Make room for the frag header. */
return (NDR_DRC_FAULT_OUT_OF_MEMORY);
/* Read the frag header. */
if (rc != 0)
return (NDR_DRC_FAULT_RPCHDR_RECEIVED_RUNT);
/*
* Decode the frag header, get the length.
* NB: It uses nds->pdu_scan_offset
*/
return (NDR_DRC_FAULT_DECODE_FAILED);
if (nds->pdu_scan_offset == 0) {
/* First frag: header stays in the data. */
} /* else overwrite with the payload */
/* Make room for the payload. */
return (NDR_DRC_FAULT_OUT_OF_MEMORY);
/* Read the payload. */
if (rc != 0)
return (NDR_DRC_FAULT_RPCHDR_RECEIVED_RUNT);
return (NDR_DRC_OK);
}
/*
* 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;
(void) ndr_reply_prepare_hdr(mxa);
case NDR_PTYPE_BIND:
break;
case NDR_PTYPE_REQUEST:
break;
case NDR_PTYPE_ALTER_CONTEXT:
break;
default:
break;
}
if (NDR_DRC_IS_FAULT(rc))
return (rc);
}
/*
* Multiple p_cont_elem[]s, multiple transfer_syntaxes[] and multiple
* p_results[] not supported.
*/
static int
{
unsigned p_cont_id;
int as_vers;
int ts_vers;
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 */
ndo_trace("ndr_svc_bind: warning: multiple p_cont_elem");
}
/*
* Duplicate presentation context id.
*/
ndo_trace("ndr_svc_bind: duplicate binding");
return (NDR_DRC_FAULT_BIND_PCONT_BUSY);
}
/*
* No free binding slot
*/
ndo_trace("ndr_svc_bind: no resources");
return (NDR_DRC_OK);
}
return (NDR_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 (NDR_DRC_IS_FAULT(rc)) {
mbind->which_side = 0;
mbind->instance_specific = 0;
return (rc);
}
}
return (NDR_DRC_BINDING_MADE);
}
/*
* ndr_svc_alter_context
*
* The alter context request is used to request additional presentation
* a bind request.
*/
static int
{
unsigned p_cont_id;
int as_vers;
int ts_vers;
result_list->reserved = 0;
result_list->reserved2 = 0;
return (NDR_DRC_FAULT_BIND_PCONT_BUSY);
return (NDR_DRC_OK);
}
return (NDR_DRC_OK);
}
/* mbind->context set by app */
mbind->instance_specific = 0;
return (NDR_DRC_BINDING_MADE);
}
static int
{
unsigned p_cont_id;
int rc;
return (NDR_DRC_FAULT_REQUEST_PCONT_INVALID);
/*
* Make room for the response hdr.
*/
else
if (NDR_DRC_IS_FAULT(rc)) {
ndo_printf(0, 0, "%s[0x%02x]: 0x%04x",
}
return (rc);
}
/*
* The transaction and the two nds streams use the same heap, which
* should already exist at this point. The heap will also be available
* to the stub.
*/
int
{
char *param;
int rc;
return (NDR_DRC_FAULT_OUT_OF_MEMORY);
}
ndo_printf(0, 0, "%s[0x%02x]: invalid opnum",
return (NDR_DRC_FAULT_REQUEST_OPNUM_INVALID);
}
return (NDR_DRC_FAULT_OUT_OF_MEMORY);
if (!NDR_DRC_IS_OK(rc))
return (rc);
if (rc == NDR_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 NDR_PTYPE_BIND:
/*
* and store in the pipe endpoint. Note "xmit" is
* client-to-server; "recv" is server-to-client.
*/
/*
* We're supposed to assign a unique "assoc group"
* (identifies this connection for the client).
* Using the pipe address is adequate.
*/
break;
case NDR_PTYPE_REQUEST:
/* mxa->send_hdr.response_hdr.alloc_hint */
break;
case NDR_PTYPE_ALTER_CONTEXT:
/*
* 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 & NDR_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 NDR_PTYPE_BIND_ACK:
break;
case NDR_PTYPE_FAULT:
/* already setup */
break;
case NDR_PTYPE_RESPONSE:
break;
break;
default:
break;
}
nds->pdu_scan_offset = 0;
(void) ndr_encode_pdu_hdr(mxa);
return (0);
}
/*
* Multiple fragment response.
*
* We need to update the RPC header for every fragment.
*
* 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 - NDR_RSP_HDR_SIZE)
*/
/*
* Send the first frag.
*/
nds->pdu_scan_offset = 0;
(void) ndr_encode_pdu_hdr(mxa);
/*
* Send "middle" (full-sized) fragments...
*/
while (pdu_data_size > frag_data_size) {
nds->pdu_scan_offset = 0;
(void) ndr_encode_pdu_hdr(mxa);
}
/*
* Last frag (pdu_data_size <= frag_data_size)
*/
nds->pdu_scan_offset = 0;
(void) ndr_encode_pdu_hdr(mxa);
return (0);
}