r23792: convert Samba4 to GPLv3
[tprouty/samba.git] / source4 / libnet / libnet_rpc.c
index 3c9b7352ccfc92acdf3a7cac0a5dd9d4a6dfa011..04e91097b546fe9daaa0d517c2836d45ced9177b 100644 (file)
@@ -6,7 +6,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,
@@ -15,8 +15,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"
@@ -57,15 +56,13 @@ static struct composite_context* libnet_RpcConnectSrv_send(struct libnet_context
        struct composite_context *pipe_connect_req;
 
        /* composite context allocation and setup */
-       c = talloc_zero(mem_ctx, struct composite_context);
-       if (c == NULL) return NULL;
+       c = composite_create(ctx, ctx->event_ctx);
+       if (c == NULL) return c;
 
        s = talloc_zero(c, struct rpc_connect_srv_state);
        if (composite_nomem(s, c)) return c;
 
-       c->state = COMPOSITE_STATE_IN_PROGRESS;
        c->private_data = s;
-       c->event_ctx = ctx->event_ctx;
 
        s->ctx = ctx;
        s->r = *r;
@@ -218,15 +215,13 @@ static struct composite_context* libnet_RpcConnectDC_send(struct libnet_context
        struct composite_context *lookup_dc_req;
 
        /* composite context allocation and setup */
-       c = talloc_zero(mem_ctx, struct composite_context);
-       if (c == NULL) return NULL;
+       c = composite_create(ctx, ctx->event_ctx);
+       if (c == NULL) return c;
 
        s = talloc_zero(c, struct rpc_connect_dc_state);
        if (composite_nomem(s, c)) return c;
 
-       c->state = COMPOSITE_STATE_IN_PROGRESS;
        c->private_data = s;
-       c->event_ctx = ctx->event_ctx;
 
        s->ctx = ctx;
        s->r   = *r;
@@ -330,14 +325,14 @@ static void continue_rpc_connect(struct composite_context *ctx)
        s->r.out.dcerpc_pipe = s->r2.out.dcerpc_pipe;
 
        /* prepare a monitor message and post it */
-       msg.type       = net_pipe_connected;
-       msg.data       = NULL;
-       msg.data_size  = 0;
-
        data.host      = s->r.out.dcerpc_pipe->binding->host;
        data.endpoint  = s->r.out.dcerpc_pipe->binding->endpoint;
        data.transport = s->r.out.dcerpc_pipe->binding->transport;
 
+       msg.type       = net_pipe_connected;
+       msg.data       = (void*)&data;
+       msg.data_size  = sizeof(data);
+       
        if (s->monitor_fn) s->monitor_fn(&msg);
 
        composite_done(c);
@@ -412,6 +407,7 @@ static void continue_lsa_query_info(struct rpc_request *req);
 static void continue_lsa_query_info2(struct rpc_request *req);
 static void continue_epm_map_binding(struct composite_context *ctx);
 static void continue_secondary_conn(struct composite_context *ctx);
+static void continue_epm_map_binding_send(struct composite_context *c);
 
 
 /**
@@ -432,15 +428,13 @@ static struct composite_context* libnet_RpcConnectDCInfo_send(struct libnet_cont
        struct rpc_connect_dci_state *s;
 
        /* composite context allocation and setup */
-       c = talloc_zero(mem_ctx, struct composite_context);
-       if (c == NULL) return NULL;
+       c = composite_create(ctx, ctx->event_ctx);
+       if (c == NULL) return c;
 
        s = talloc_zero(c, struct rpc_connect_dci_state);
        if (composite_nomem(s, c)) return c;
 
-       c->state = COMPOSITE_STATE_IN_PROGRESS;
        c->private_data = s;
-       c->event_ctx = ctx->event_ctx;
 
        s->ctx = ctx;
        s->r   = *r;
@@ -521,7 +515,7 @@ static void continue_lsa_policy(struct rpc_request *req)
        struct rpc_connect_dci_state *s;
        struct rpc_request *query_info_req;
 
-       c = talloc_get_type(req->async.private, struct composite_context);
+       c = talloc_get_type(req->async.private_data, struct composite_context);
        s = talloc_get_type(c->private_data, struct rpc_connect_dci_state);
 
        c->status = dcerpc_ndr_request_recv(req);
@@ -530,8 +524,16 @@ static void continue_lsa_policy(struct rpc_request *req)
                return;
        }
 
-       if (!NT_STATUS_IS_OK(s->lsa_query_info2.out.result)) {
-               composite_error(c, s->lsa_query_info2.out.result);
+       if (NT_STATUS_EQUAL(s->lsa_open_policy.out.result, NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED)) {
+               s->r.out.realm = NULL;
+               s->r.out.guid  = NULL;
+               s->r.out.domain_name = NULL;
+               s->r.out.domain_sid  = NULL;
+               /* Skip to the creating the actual connection, no info available on this transport */
+               continue_epm_map_binding_send(c);
+               return;
+       } else if (!NT_STATUS_IS_OK(s->lsa_open_policy.out.result)) {
+               composite_error(c, s->lsa_open_policy.out.result);
                return;
        }
 
@@ -556,7 +558,7 @@ static void continue_lsa_query_info2(struct rpc_request *req)
        struct rpc_connect_dci_state *s;
        struct rpc_request *query_info_req;
 
-       c = talloc_get_type(req->async.private, struct composite_context);
+       c = talloc_get_type(req->async.private_data, struct composite_context);
        s = talloc_get_type(c->private_data, struct rpc_connect_dci_state);
 
        c->status = dcerpc_ndr_request_recv(req);
@@ -610,15 +612,14 @@ static void continue_lsa_query_info2(struct rpc_request *req)
 
 
 /*
-  Step 5 of RpcConnectDCInfo: Get domain name and sid and request endpoint
-  map binding
+  Step 5 of RpcConnectDCInfo: Get domain name and sid
 */
 static void continue_lsa_query_info(struct rpc_request *req)
 {
-       struct composite_context *c, *epm_map_req;
+       struct composite_context *c;
        struct rpc_connect_dci_state *s;
 
-       c = talloc_get_type(req->async.private, struct composite_context);
+       c = talloc_get_type(req->async.private_data, struct composite_context);
        s = talloc_get_type(c->private_data, struct rpc_connect_dci_state);
 
        c->status = dcerpc_ndr_request_recv(req);
@@ -634,6 +635,20 @@ static void continue_lsa_query_info(struct rpc_request *req)
        s->r.out.domain_sid  = s->lsa_query_info.out.info->domain.sid;
        s->r.out.domain_name = s->lsa_query_info.out.info->domain.name.string;
 
+       continue_epm_map_binding_send(c);
+}
+
+/* 
+   Step 5 (continued) of RpcConnectDCInfo: request endpoint
+   map binding.
+
+   We may short-cut to this step if we dont' support LSA OpenPolicy on this transport
+*/
+static void continue_epm_map_binding_send(struct composite_context *c)
+{
+       struct rpc_connect_dci_state *s;
+       struct composite_context *epm_map_req;
+       s = talloc_get_type(c->private_data, struct rpc_connect_dci_state);
 
        /* prepare to get endpoint mapping for the requested interface */
        s->final_binding = talloc(s, struct dcerpc_binding);
@@ -650,7 +665,6 @@ static void continue_lsa_query_info(struct rpc_request *req)
        composite_continue(c, epm_map_req, continue_epm_map_binding, c);
 }
 
-
 /*
   Step 6 of RpcConnectDCInfo: Receive endpoint mapping and create secondary
   rpc connection derived from already used pipe but connected to the requested
@@ -682,7 +696,7 @@ static void continue_epm_map_binding(struct composite_context *ctx)
 
 
 /*
-  Step 7 of RpcConnectDCInfo: Get actual lsa pipe to be returned
+  Step 7 of RpcConnectDCInfo: Get actual pipe to be returned
   and complete this composite call
 */
 static void continue_secondary_conn(struct composite_context *ctx)