Fix the build.
[tprouty/samba.git] / source4 / librpc / rpc / dcerpc_auth.c
index 7db6c1b7cdbedaf18358409b9e60ea9517f74009..14f0f9deb4b2dd22b8ebf75b4b2044da4812810b 100644 (file)
@@ -25,6 +25,8 @@
 #include "libcli/composite/composite.h"
 #include "auth/gensec/gensec.h"
 #include "librpc/rpc/dcerpc.h"
+#include "librpc/rpc/dcerpc_proto.h"
+#include "param/param.h"
 
 /*
   return the rpc syntax and transfer syntax given the pipe uuid and version
@@ -85,7 +87,7 @@ NTSTATUS dcerpc_bind_auth_none_recv(struct composite_context *ctx)
 /*
   Perform sync non-authenticated dcerpc bind
 */
-NTSTATUS dcerpc_bind_auth_none(struct dcerpc_pipe *p,
+_PUBLIC_ NTSTATUS dcerpc_bind_auth_none(struct dcerpc_pipe *p,
                               const struct ndr_interface_table *table)
 {
        struct composite_context *ctx;
@@ -127,6 +129,7 @@ static void bind_auth_next_step(struct composite_context *c)
        c->status = gensec_update(sec->generic_state, state,
                                  sec->auth_info->credentials,
                                  &state->credentials);
+       data_blob_free(&sec->auth_info->credentials);
 
        if (NT_STATUS_EQUAL(c->status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
                more_processing = true;
@@ -135,6 +138,10 @@ static void bind_auth_next_step(struct composite_context *c)
 
        if (!composite_is_ok(c)) return;
 
+       if (state->pipe->conn->flags & DCERPC_HEADER_SIGNING) {
+               gensec_want_feature(sec->generic_state, GENSEC_FEATURE_SIGN_PKT_HEADER);
+       }
+
        if (state->credentials.length == 0) {
                composite_done(c);
                return;
@@ -144,7 +151,9 @@ static void bind_auth_next_step(struct composite_context *c)
 
        if (!more_processing) {
                /* NO reply expected, so just send it */
-               c->status = dcerpc_auth3(state->pipe->conn, state);
+               c->status = dcerpc_auth3(state->pipe, state);
+               data_blob_free(&state->credentials);
+               sec->auth_info->credentials = data_blob(NULL, 0);
                if (!composite_is_ok(c)) return;
 
                composite_done(c);
@@ -156,6 +165,8 @@ static void bind_auth_next_step(struct composite_context *c)
        creq = dcerpc_alter_context_send(state->pipe, state,
                                         &state->pipe->syntax,
                                         &state->pipe->transfer_syntax);
+       data_blob_free(&state->credentials);
+       sec->auth_info->credentials = data_blob(NULL, 0);
        if (composite_nomem(creq, c)) return;
 
        composite_continue(c, creq, bind_auth_recv_alter, c);
@@ -211,6 +222,7 @@ struct composite_context *dcerpc_bind_auth_send(TALLOC_CTX *mem_ctx,
                                                struct dcerpc_pipe *p,
                                                const struct ndr_interface_table *table,
                                                struct cli_credentials *credentials,
+                                               struct gensec_settings *gensec_settings,
                                                uint8_t auth_type, uint8_t auth_level,
                                                const char *service)
 {
@@ -238,7 +250,8 @@ struct composite_context *dcerpc_bind_auth_send(TALLOC_CTX *mem_ctx,
        sec = &p->conn->security_state;
 
        c->status = gensec_client_start(p, &sec->generic_state,
-                                       p->conn->event_ctx);
+                                       p->conn->event_ctx,
+                                       gensec_settings);
        if (!NT_STATUS_IS_OK(c->status)) {
                DEBUG(1, ("Failed to start GENSEC client mode: %s\n",
                          nt_errstr(c->status)));
@@ -248,7 +261,7 @@ struct composite_context *dcerpc_bind_auth_send(TALLOC_CTX *mem_ctx,
 
        c->status = gensec_set_credentials(sec->generic_state, credentials);
        if (!NT_STATUS_IS_OK(c->status)) {
-               DEBUG(1, ("Failed to set GENSEC client credentails: %s\n",
+               DEBUG(1, ("Failed to set GENSEC client credentials: %s\n",
                          nt_errstr(c->status)));
                composite_error(c, c->status);
                return c;
@@ -278,7 +291,7 @@ struct composite_context *dcerpc_bind_auth_send(TALLOC_CTX *mem_ctx,
                                                  auth_type, auth_level);
        if (!NT_STATUS_IS_OK(c->status)) {
                DEBUG(1, ("Failed to start GENSEC client mechanism %s: %s\n",
-                         gensec_get_name_by_authtype(auth_type),
+                         gensec_get_name_by_authtype(sec->generic_state, auth_type),
                          nt_errstr(c->status)));
                composite_error(c, c->status);
                return c;
@@ -326,6 +339,8 @@ struct composite_context *dcerpc_bind_auth_send(TALLOC_CTX *mem_ctx,
        /* The first request always is a dcerpc_bind. The subsequent ones
         * depend on gensec results */
        creq = dcerpc_bind_send(p, state, &syntax, &transfer_syntax);
+       data_blob_free(&state->credentials);
+       sec->auth_info->credentials = data_blob(NULL, 0);
        if (composite_nomem(creq, c)) return c;
 
        composite_continue(c, creq, bind_auth_recv_bindreply, c);
@@ -369,14 +384,15 @@ NTSTATUS dcerpc_bind_auth_recv(struct composite_context *creq)
    @retval NTSTATUS status code
 */
 
-NTSTATUS dcerpc_bind_auth(struct dcerpc_pipe *p,
+_PUBLIC_ NTSTATUS dcerpc_bind_auth(struct dcerpc_pipe *p,
                          const struct ndr_interface_table *table,
                          struct cli_credentials *credentials,
+                         struct gensec_settings *gensec_settings,
                          uint8_t auth_type, uint8_t auth_level,
                          const char *service)
 {
        struct composite_context *creq;
-       creq = dcerpc_bind_auth_send(p, p, table, credentials,
+       creq = dcerpc_bind_auth_send(p, p, table, credentials, gensec_settings,
                                     auth_type, auth_level, service);
        return dcerpc_bind_auth_recv(creq);
 }