[GLUE] Rsync SAMBA_3_2_0 SVN r25598 in order to create the v3-2-test branch.
[samba.git] / source / rpc_server / srv_pipe_hnd.c
index 86a04e7ccbe9602be030f9fb824b52a78c6e3640..91814979c5b6b37bde57005cc50fb8763d034804 100644 (file)
@@ -7,7 +7,7 @@
  *  
  *  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,
@@ -16,8 +16,7 @@
  *  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"
@@ -66,7 +65,7 @@ static ssize_t read_from_internal_pipe(void *np_conn, char *data, size_t n,
                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);
 
 /****************************************************************************
@@ -168,7 +167,7 @@ static BOOL pipe_init_outgoing_data(pipes_struct *p)
  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;
@@ -276,7 +275,7 @@ smb_np_struct *open_rpc_pipe_p(char *pipe_name,
  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;
@@ -330,6 +329,8 @@ static void *make_internal_rpc_pipe_p(char *pipe_name,
                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;
        }
 
@@ -697,7 +698,7 @@ static void process_complete_pdu(pipes_struct *p)
                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;
        }
 
@@ -824,7 +825,7 @@ static void process_complete_pdu(pipes_struct *p)
        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 {
                /*
@@ -937,7 +938,7 @@ ssize_t write_to_pipe(smb_np_struct *p, char *data, size_t n)
        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);
 }
@@ -1034,6 +1035,7 @@ static ssize_t read_from_internal_pipe(void *np_conn, char *data, size_t 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;
        }
 
        /*
@@ -1167,6 +1169,13 @@ BOOL close_rpc_pipe_hnd(smb_np_struct *p)
                 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);
 
@@ -1223,7 +1232,7 @@ static BOOL close_internal_rpc_pipe_hnd(void *np_conn)
        /* Free the handles database. */
        close_policy_by_pipe(p);
 
-       talloc_free(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.ut.groups);
 
@@ -1240,10 +1249,8 @@ static BOOL close_internal_rpc_pipe_hnd(void *np_conn)
  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;
        }