*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#include "includes.h"
BOOL *is_data_outstanding);
static ssize_t write_to_internal_pipe(void *np_conn, char *data, size_t n);
static BOOL close_internal_rpc_pipe_hnd(void *np_conn);
-static void *make_internal_rpc_pipe_p(char *pipe_name,
+static void *make_internal_rpc_pipe_p(const char *pipe_name,
connection_struct *conn, uint16 vuid);
/****************************************************************************
Find first available pipe slot.
****************************************************************************/
-smb_np_struct *open_rpc_pipe_p(char *pipe_name,
+smb_np_struct *open_rpc_pipe_p(const char *pipe_name,
connection_struct *conn, uint16 vuid)
{
int i;
Make an internal namedpipes structure
****************************************************************************/
-static void *make_internal_rpc_pipe_p(char *pipe_name,
+static void *make_internal_rpc_pipe_p(const char *pipe_name,
connection_struct *conn, uint16 vuid)
{
pipes_struct *p;
DEBUG(0,("open_rpc_pipe_p: malloc fail for in_data struct.\n"));
talloc_destroy(p->mem_ctx);
talloc_destroy(p->pipe_state_mem_ctx);
+ close_policy_by_pipe(p);
+ SAFE_FREE(p);
return NULL;
}
p->conn = conn;
- /* Ensure the connection isn't idled whilst this pipe is open. */
- p->conn->num_files_open++;
-
p->vuid = vuid;
p->endian = RPC_LITTLE_ENDIAN;
ZERO_STRUCT(p->pipe_user);
- p->pipe_user.uid = (uid_t)-1;
- p->pipe_user.gid = (gid_t)-1;
+ p->pipe_user.ut.uid = (uid_t)-1;
+ p->pipe_user.ut.gid = (gid_t)-1;
/* Store the session key and NT_TOKEN */
if (vuser) {
p->session_key = data_blob(vuser->session_key.data, vuser->session_key.length);
- p->pipe_user.nt_user_token = dup_nt_token(vuser->nt_user_token);
+ p->pipe_user.nt_user_token = dup_nt_token(
+ NULL, vuser->nt_user_token);
}
/*
DEBUG(10,("process_complete_pdu: pipe %s in fault state.\n",
p->name ));
set_incoming_fault(p);
- setup_fault_pdu(p, NT_STATUS(0x1c010002));
+ setup_fault_pdu(p, NT_STATUS(DCERPC_FAULT_OP_RNG_ERROR));
return;
}
(unsigned int)p->hdr.pkt_type ));
switch (p->hdr.pkt_type) {
+ case RPC_REQUEST:
+ reply = process_request_pdu(p, &rpc_in);
+ break;
+
+ case RPC_PING: /* CL request - ignore... */
+ DEBUG(0,("process_complete_pdu: Error. Connectionless packet type %u received on pipe %s.\n",
+ (unsigned int)p->hdr.pkt_type, p->name));
+ break;
+
+ case RPC_RESPONSE: /* No responses here. */
+ DEBUG(0,("process_complete_pdu: Error. RPC_RESPONSE received from client on pipe %s.\n",
+ p->name ));
+ break;
+
+ case RPC_FAULT:
+ case RPC_WORKING: /* CL request - reply to a ping when a call in process. */
+ case RPC_NOCALL: /* CL - server reply to a ping call. */
+ case RPC_REJECT:
+ case RPC_ACK:
+ case RPC_CL_CANCEL:
+ case RPC_FACK:
+ case RPC_CANCEL_ACK:
+ DEBUG(0,("process_complete_pdu: Error. Connectionless packet type %u received on pipe %s.\n",
+ (unsigned int)p->hdr.pkt_type, p->name));
+ break;
+
case RPC_BIND:
/*
* We assume that a pipe bind is only in one pdu.
reply = api_pipe_bind_req(p, &rpc_in);
}
break;
+
+ case RPC_BINDACK:
+ case RPC_BINDNACK:
+ DEBUG(0,("process_complete_pdu: Error. RPC_BINDACK/RPC_BINDNACK packet type %u received on pipe %s.\n",
+ (unsigned int)p->hdr.pkt_type, p->name));
+ break;
+
+
case RPC_ALTCONT:
/*
* We assume that a pipe bind is only in one pdu.
reply = api_pipe_alter_context(p, &rpc_in);
}
break;
+
+ case RPC_ALTCONTRESP:
+ DEBUG(0,("process_complete_pdu: Error. RPC_ALTCONTRESP on pipe %s: Should only be server -> client.\n",
+ p->name));
+ break;
+
case RPC_AUTH3:
/*
* The third packet in an NTLMSSP auth exchange.
reply = api_pipe_bind_auth3(p, &rpc_in);
}
break;
- case RPC_REQUEST:
- reply = process_request_pdu(p, &rpc_in);
+
+ case RPC_SHUTDOWN:
+ DEBUG(0,("process_complete_pdu: Error. RPC_SHUTDOWN on pipe %s: Should only be server -> client.\n",
+ p->name));
+ break;
+
+ case RPC_CO_CANCEL:
+ /* For now just free all client data and continue processing. */
+ DEBUG(3,("process_complete_pdu: RPC_ORPHANED. Abandoning rpc call.\n"));
+ /* As we never do asynchronous RPC serving, we can never cancel a
+ call (as far as I know). If we ever did we'd have to send a cancel_ack
+ reply. For now, just free all client data and continue processing. */
+ reply = True;
+ break;
+#if 0
+ /* Enable this if we're doing async rpc. */
+ /* We must check the call-id matches the outstanding callid. */
+ if(pipe_init_outgoing_data(p)) {
+ /* Send a cancel_ack PDU reply. */
+ /* We should probably check the auth-verifier here. */
+ reply = setup_cancel_ack_reply(p, &rpc_in);
+ }
+ break;
+#endif
+
+ case RPC_ORPHANED:
+ /* We should probably check the auth-verifier here.
+ For now just free all client data and continue processing. */
+ DEBUG(3,("process_complete_pdu: RPC_ORPHANED. Abandoning rpc call.\n"));
+ reply = True;
break;
+
default:
DEBUG(0,("process_complete_pdu: Unknown rpc type = %u received.\n", (unsigned int)p->hdr.pkt_type ));
break;
if (!reply) {
DEBUG(3,("process_complete_pdu: DCE/RPC fault sent on pipe %s\n", p->pipe_srv_name));
set_incoming_fault(p);
- setup_fault_pdu(p, NT_STATUS(0x1c010002));
+ setup_fault_pdu(p, NT_STATUS(DCERPC_FAULT_OP_RNG_ERROR));
prs_mem_free(&rpc_in);
} else {
/*
*/
if(p->in_data.pdu_needed_len == 0) {
- return unmarshall_rpc_header(p);
+ ssize_t rret = unmarshall_rpc_header(p);
+ if (rret == -1 || p->in_data.pdu_needed_len > 0) {
+ return rret;
+ }
+ /* If rret == 0 and pdu_needed_len == 0 here we have a PDU that consists
+ of an RPC_HEADER only. This is a RPC_SHUTDOWN, RPC_CO_CANCEL or RPC_ORPHANED
+ pdu type. Deal with this in process_complete_pdu(). */
}
/*
DEBUG(6,(" name: %s open: %s len: %d\n",
p->name, BOOLSTR(p->open), (int)n));
- dump_data(50, data, n);
+ dump_data(50, (uint8 *)data, n);
return p->namedpipe_write(p->np_state, data, n);
}
if(n > RPC_MAX_PDU_FRAG_LEN) {
DEBUG(5,("read_from_pipe: too large read (%u) requested on \
pipe %s. We can only service %d sized reads.\n", (unsigned int)n, p->name, RPC_MAX_PDU_FRAG_LEN ));
+ n = RPC_MAX_PDU_FRAG_LEN;
}
/*
p->name, p->pnum, pipes_open));
DLIST_REMOVE(Pipes, p);
+
+ /* TODO: Remove from pipe open db */
+
+ if ( !delete_pipe_opendb( p ) ) {
+ DEBUG(3,("close_rpc_pipe_hnd: failed to delete %s "
+ "pipe from open db.\n", p->name));
+ }
ZERO_STRUCTP(p);
/* Free the handles database. */
close_policy_by_pipe(p);
- delete_nt_token(&p->pipe_user.nt_user_token);
+ TALLOC_FREE(p->pipe_user.nt_user_token);
data_blob_free(&p->session_key);
- SAFE_FREE(p->pipe_user.groups);
+ SAFE_FREE(p->pipe_user.ut.groups);
DLIST_REMOVE(InternalPipes, p);
- p->conn->num_files_open--;
-
ZERO_STRUCTP(p);
SAFE_FREE(p);
Find an rpc pipe given a pipe handle in a buffer and an offset.
****************************************************************************/
-smb_np_struct *get_rpc_pipe_p(char *buf, int where)
+smb_np_struct *get_rpc_pipe_p(uint16 pnum)
{
- int pnum = SVAL(buf,where);
-
if (chain_p) {
return chain_p;
}