[GLUE] Rsync SAMBA_3_2_0 SVN r25598 in order to create the v3-2-test branch.
[samba.git] / source / rpc_server / srv_pipe.c
index 812a720d9059f2408d3af9ca7de6ed4a5966cd73..72ce72fb28d6987d49c100bf15b4d05b6dc4e5c2 100644 (file)
@@ -5,7 +5,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,
@@ -14,8 +14,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/>.
  */
 
 /*  this module apparently provides an implementation of DCE/RPC over a
@@ -680,10 +679,9 @@ static BOOL pipe_ntlmssp_verify_final(pipes_struct *p, DATA_BLOB *p_resp_blob)
 
        p->pipe_user.ut.ngroups = a->server_info->n_groups;
        if (p->pipe_user.ut.ngroups) {
-               if (!(p->pipe_user.ut.groups = memdup(a->server_info->groups,
+               if (!(p->pipe_user.ut.groups = (gid_t *)memdup(a->server_info->groups,
                                                sizeof(gid_t) * p->pipe_user.ut.ngroups))) {
-                       DEBUG(0,("pipe_ntlmssp_verify_final: failed to memdup group list to p->pipe_user.groups\n"));
-                       data_blob_free(&p->session_key);
+                       DEBUG(0,("failed to memdup group list to p->pipe_user.groups\n"));
                        return False;
                }
        }
@@ -691,17 +689,9 @@ static BOOL pipe_ntlmssp_verify_final(pipes_struct *p, DATA_BLOB *p_resp_blob)
        if (a->server_info->ptok) {
                p->pipe_user.nt_user_token =
                        dup_nt_token(NULL, a->server_info->ptok);
-               if (!p->pipe_user.nt_user_token) {
-                       DEBUG(1,("pipe_ntlmssp_verify_final: dup_nt_token failed.\n"));
-                       data_blob_free(&p->session_key);
-                       SAFE_FREE(p->pipe_user.ut.groups);
-                       return False;
-               }
-
        } else {
-               DEBUG(1,("pipe_ntlmssp_verify_final: Error: Authmodule failed to provide nt_user_token\n"));
-               data_blob_free(&p->session_key);
-               SAFE_FREE(p->pipe_user.ut.groups);
+               DEBUG(1,("Error: Authmodule failed to provide nt_user_token\n"));
+               p->pipe_user.nt_user_token = NULL;
                return False;
        }
 
@@ -999,9 +989,9 @@ BOOL check_bind_req(struct pipes_struct *p, RPC_IFACE* abstract,
                DEBUG(10,("checking %s\n", pipe_names[i].client_pipe));
                if ( strequal(pipe_names[i].client_pipe, pname)
                        && (abstract->version == pipe_names[i].abstr_syntax.version) 
-                       && (memcmp(&abstract->uuid, &pipe_names[i].abstr_syntax.uuid, sizeof(struct uuid)) == 0)
+                       && (memcmp(&abstract->uuid, &pipe_names[i].abstr_syntax.uuid, sizeof(struct GUID)) == 0)
                        && (transfer->version == pipe_names[i].trans_syntax.version)
-                       && (memcmp(&transfer->uuid, &pipe_names[i].trans_syntax.uuid, sizeof(struct uuid)) == 0) ) {
+                       && (memcmp(&transfer->uuid, &pipe_names[i].trans_syntax.uuid, sizeof(struct GUID)) == 0) ) {
                        struct api_struct       *fns = NULL;
                        int                     n_fns = 0;
                        PIPE_RPC_FNS            *context_fns;
@@ -1641,11 +1631,18 @@ BOOL api_pipe_bind_req(pipes_struct *p, prs_struct *rpc_in_p)
 
                case RPC_ANONYMOUS_AUTH_TYPE:
                        /* Unauthenticated bind request. */
+                       /* Get the authenticated pipe user from current_user */
+                       if (!copy_current_user(&p->pipe_user, &current_user)) {
+                               DEBUG(10, ("Could not copy current user\n"));
+                               goto err_exit;
+                       }
                        /* We're finished - no more packets. */
                        p->auth.auth_type = PIPE_AUTH_TYPE_NONE;
                        /* We must set the pipe auth_level here also. */
                        p->auth.auth_level = PIPE_AUTH_LEVEL_NONE;
                        p->pipe_bound = True;
+                       /* The session key was initialized from the SMB
+                        * session in make_internal_rpc_pipe_p */
                        break;
 
                default:
@@ -2236,9 +2233,9 @@ BOOL api_pipe_request(pipes_struct *p)
        pipe_fns = find_pipe_fns_by_context(p->contexts, p->hdr_req.context_id);
        
        if ( pipe_fns ) {
-               set_current_rpc_talloc(p->mem_ctx);
+               TALLOC_CTX *frame = talloc_stackframe();
                ret = api_rpcTNP(p, p->name, pipe_fns->cmds, pipe_fns->n_cmds);
-               set_current_rpc_talloc(NULL);   
+               TALLOC_FREE(frame);
        }
        else {
                DEBUG(0,("api_pipe_request: No rpc function table associated with context [%d] on pipe [%s]\n",
@@ -2305,6 +2302,13 @@ BOOL api_rpcTNP(pipes_struct *p, const char *rpc_name,
                return True;
        }
 
+       if (p->rng_fault_state) {
+               DEBUG(4, ("api_rpcTNP: rng fault return\n"));
+               p->rng_fault_state = False;
+               setup_fault_pdu(p, NT_STATUS(DCERPC_FAULT_OP_RNG_ERROR));
+               return True;
+       }
+
        slprintf(name, sizeof(name)-1, "out_%s", rpc_name);
        offset2 = prs_offset(&p->out_data.rdata);
        prs_set_offset(&p->out_data.rdata, offset1);
@@ -2318,7 +2322,7 @@ BOOL api_rpcTNP(pipes_struct *p, const char *rpc_name,
        if ((DEBUGLEVEL >= 10) && 
            (prs_offset(&p->in_data.data) != prs_data_size(&p->in_data.data))) {
                size_t data_len = prs_data_size(&p->in_data.data) - prs_offset(&p->in_data.data);
-               char *data = SMB_MALLOC(data_len);
+               char *data = (char *)SMB_MALLOC(data_len);
 
                DEBUG(10, ("api_rpcTNP: rpc input buffer underflow (parse error?)\n"));
                if (data) {
@@ -2353,13 +2357,13 @@ void get_pipe_fns( int idx, struct api_struct **fns, int *n_fns )
                        netlog_get_pipe_fns( &cmds, &n_cmds );
                        break;
                case PI_SRVSVC:
-                       srvsvc_get_pipe_fns( &cmds, &n_cmds );
+                       srvsvc2_get_pipe_fns( &cmds, &n_cmds );
                        break;
                case PI_WKSSVC:
                        wkssvc_get_pipe_fns( &cmds, &n_cmds );
                        break;
                case PI_WINREG:
-                       reg_get_pipe_fns( &cmds, &n_cmds );
+                       winreg_get_pipe_fns( &cmds, &n_cmds );
                        break;
                case PI_SPOOLSS:
                        spoolss_get_pipe_fns( &cmds, &n_cmds );
@@ -2368,17 +2372,17 @@ void get_pipe_fns( int idx, struct api_struct **fns, int *n_fns )
                        netdfs_get_pipe_fns( &cmds, &n_cmds );
                        break;
                case PI_SVCCTL:
-                       svcctl_get_pipe_fns( &cmds, &n_cmds );
+                       svcctl2_get_pipe_fns( &cmds, &n_cmds );
                        break;
                case PI_EVENTLOG:
-                       eventlog_get_pipe_fns( &cmds, &n_cmds );
+                       eventlog2_get_pipe_fns( &cmds, &n_cmds );
                        break;
                case PI_NTSVCS:
                        ntsvcs_get_pipe_fns( &cmds, &n_cmds );
                        break;
 #ifdef DEVELOPER
-               case PI_ECHO:
-                       echo_get_pipe_fns( &cmds, &n_cmds );
+               case PI_RPCECHO:
+                       rpcecho_get_pipe_fns( &cmds, &n_cmds );
                        break;
 #endif
                default: