s3-rpc_server rename NTLMSSP functions to auth_generic..()
[mat/samba.git] / source3 / rpc_server / dcesrv_ntlmssp.c
index 693627749c3ef39aa549e0670e280ae270849015..1a637a07d1d81e67aa1c76f6a1e07d22ed525ef5 100644 (file)
@@ -2,6 +2,7 @@
  *  NTLMSSP Acceptor
  *  DCERPC Server functions
  *  Copyright (C) Simo Sorce 2010.
+ *  Copyright (C) Andrew Bartlett 2011.
  *
  *  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
 
 #include "includes.h"
 #include "rpc_server/dcesrv_ntlmssp.h"
-#include "../libcli/auth/ntlmssp.h"
 #include "ntlmssp_wrap.h"
 #include "auth.h"
+#include "auth/gensec/gensec.h"
 
-NTSTATUS ntlmssp_server_auth_start(TALLOC_CTX *mem_ctx,
+NTSTATUS auth_generic_server_start(TALLOC_CTX *mem_ctx,
+                                  const char *oid,
                                   bool do_sign,
                                   bool do_seal,
                                   bool is_dcerpc,
                                   DATA_BLOB *token_in,
                                   DATA_BLOB *token_out,
                                   const struct tsocket_address *remote_address,
-                                  struct auth_ntlmssp_state **ctx)
+                                  struct gensec_security **ctx)
 {
-       struct auth_ntlmssp_state *a = NULL;
+       struct auth_generic_state *a = NULL;
        NTSTATUS status;
 
-       status = auth_ntlmssp_start(remote_address, &a);
+       status = auth_generic_prepare(remote_address, &a);
        if (!NT_STATUS_IS_OK(status)) {
-               DEBUG(0, (__location__ ": auth_ntlmssp_start failed: %s\n",
+               DEBUG(0, (__location__ ": auth_generic_prepare failed: %s\n",
                          nt_errstr(status)));
                return status;
        }
 
-       /* Clear flags, then set them according to requested flags */
-       auth_ntlmssp_and_flags(a, ~(NTLMSSP_NEGOTIATE_SIGN |
-                                       NTLMSSP_NEGOTIATE_SEAL));
-
        if (do_sign) {
-               auth_ntlmssp_or_flags(a, NTLMSSP_NEGOTIATE_SIGN);
+               gensec_want_feature(a->gensec_security, GENSEC_FEATURE_SIGN);
        }
        if (do_seal) {
-               /* Always implies both sign and seal for ntlmssp */
-               auth_ntlmssp_or_flags(a, NTLMSSP_NEGOTIATE_SIGN |
-                                        NTLMSSP_NEGOTIATE_SEAL);
+               gensec_want_feature(a->gensec_security, GENSEC_FEATURE_SIGN);
+               gensec_want_feature(a->gensec_security, GENSEC_FEATURE_SEAL);
+       }
+
+       if (is_dcerpc) {
+               gensec_want_feature(a->gensec_security, GENSEC_FEATURE_DCE_STYLE);
        }
 
-       status = auth_ntlmssp_update(a, *token_in, token_out);
+       status = auth_generic_start(a, oid);
+       if (!NT_STATUS_IS_OK(status)) {
+               DEBUG(0, (__location__ ": auth_generic_start failed: %s\n",
+                         nt_errstr(status)));
+               return status;
+       }
+
+       status = gensec_update(a->gensec_security, mem_ctx, NULL, *token_in, token_out);
        if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
                DEBUG(0, (__location__ ": auth_ntlmssp_update failed: %s\n",
                          nt_errstr(status)));
                goto done;
        }
 
-       /* Make sure data is bound to the memctx, to be freed the caller */
-       talloc_steal(mem_ctx, token_out->data);
        /* steal ntlmssp context too */
-       *ctx = talloc_move(mem_ctx, &a);
+       *ctx = talloc_move(mem_ctx, &a->gensec_security);
 
        status = NT_STATUS_OK;
 
 done:
-       if (!NT_STATUS_IS_OK(status)) {
-               TALLOC_FREE(a);
-       }
+       TALLOC_FREE(a);
 
        return status;
 }
 
-NTSTATUS ntlmssp_server_step(struct auth_ntlmssp_state *ctx,
+NTSTATUS auth_generic_server_step(struct gensec_security *gensec_security,
                             TALLOC_CTX *mem_ctx,
                             DATA_BLOB *token_in,
                             DATA_BLOB *token_out)
@@ -87,25 +91,22 @@ NTSTATUS ntlmssp_server_step(struct auth_ntlmssp_state *ctx,
 
        /* this has to be done as root in order to verify the password */
        become_root();
-       status = auth_ntlmssp_update(ctx, *token_in, token_out);
+       status = gensec_update(gensec_security, mem_ctx, NULL, *token_in, token_out);
        unbecome_root();
 
-       /* put the output token data on the given mem_ctx */
-       talloc_steal(mem_ctx, token_out->data);
-
        return status;
 }
 
-NTSTATUS ntlmssp_server_check_flags(struct auth_ntlmssp_state *ctx,
+NTSTATUS auth_generic_server_check_flags(struct gensec_security *gensec_security,
                                    bool do_sign, bool do_seal)
 {
-       if (do_sign && !auth_ntlmssp_negotiated_sign(ctx)) {
+       if (do_sign && !gensec_have_feature(gensec_security, GENSEC_FEATURE_SIGN)) {
                DEBUG(1, (__location__ "Integrity was requested but client "
                          "failed to negotiate signing.\n"));
                return NT_STATUS_ACCESS_DENIED;
        }
 
-       if (do_seal && !auth_ntlmssp_negotiated_seal(ctx)) {
+       if (do_seal && !gensec_have_feature(gensec_security, GENSEC_FEATURE_SEAL)) {
                DEBUG(1, (__location__ "Privacy was requested but client "
                          "failed to negotiate sealing.\n"));
                return NT_STATUS_ACCESS_DENIED;
@@ -114,23 +115,22 @@ NTSTATUS ntlmssp_server_check_flags(struct auth_ntlmssp_state *ctx,
        return NT_STATUS_OK;
 }
 
-NTSTATUS ntlmssp_server_get_user_info(struct auth_ntlmssp_state *ctx,
+NTSTATUS auth_generic_server_get_user_info(struct gensec_security *gensec_security,
                                      TALLOC_CTX *mem_ctx,
                                      struct auth_session_info **session_info)
 {
        NTSTATUS status;
 
-       status = auth_ntlmssp_steal_session_info(mem_ctx, ctx, session_info);
+       status = gensec_session_info(gensec_security, mem_ctx, session_info);
        if (!NT_STATUS_IS_OK(status)) {
                DEBUG(1, (__location__ ": Failed to get authenticated user "
                          "info: %s\n", nt_errstr(status)));
                return status;
        }
 
-       DEBUG(5, (__location__ "OK: user: %s domain: %s workstation: %s\n",
-                 auth_ntlmssp_get_username(ctx),
-                 auth_ntlmssp_get_domain(ctx),
-                 auth_ntlmssp_get_client(ctx)));
+       DEBUG(5, (__location__ "OK: user: %s domain: %s\n",
+                 (*session_info)->info->account_name,
+                 (*session_info)->info->domain_name));
 
        return NT_STATUS_OK;
 }