s3-netlogon: Connecting with the system token should be sufficient.
[metze/samba/wip.git] / source3 / rpc_server / netlogon / srv_netlog_nt.c
index c2dbdc2b2f6d33d011de26d1cb9936d4b704f821..53eff5fcb4ad22e18b20ae1fec80fb300b47281a 100644 (file)
 /* This is the implementation of the netlogon pipe. */
 
 #include "includes.h"
+#include "system/passwd.h" /* uid_wrapper */
+#include "ntdomain.h"
 #include "../libcli/auth/schannel.h"
 #include "../librpc/gen_ndr/srv_netlogon.h"
-#include "../librpc/gen_ndr/srv_samr.h"
-#include "../librpc/gen_ndr/srv_lsa.h"
 #include "../librpc/gen_ndr/ndr_samr_c.h"
 #include "../librpc/gen_ndr/ndr_lsa_c.h"
 #include "rpc_client/cli_lsarpc.h"
-#include "librpc/gen_ndr/messaging.h"
-#include "../lib/crypto/md4.h"
 #include "rpc_client/init_lsa.h"
 #include "rpc_server/rpc_ncacn_np.h"
 #include "../libcli/security/security.h"
@@ -46,6 +44,8 @@
 #include "passdb.h"
 #include "auth.h"
 #include "messages.h"
+#include "../lib/tsocket/tsocket.h"
+#include "lib/param/param.h"
 
 extern userdom_struct current_user_info;
 
@@ -84,16 +84,6 @@ WERROR _netr_LogonControl(struct pipes_struct *p,
        return _netr_LogonControl2Ex(p, &l);
 }
 
-/****************************************************************************
-Send a message to smbd to do a sam synchronisation
-**************************************************************************/
-
-static void send_sync_message(struct messaging_context *msg_ctx)
-{
-        DEBUG(3, ("sending sam synchronisation message\n"));
-        message_send_all(msg_ctx, MSG_SMB_SAM_SYNC, NULL, 0, NULL);
-}
-
 /*************************************************************************
  _netr_LogonControl2
  *************************************************************************/
@@ -195,6 +185,8 @@ WERROR _netr_LogonControl2Ex(struct pipes_struct *p,
        struct netr_NETLOGON_INFO_4 *info4;
        const char *fn;
        uint32_t acct_ctrl;
+       NTSTATUS status;
+       struct netr_DsRGetDCNameInfo *dc_info;
 
        switch (p->opnum) {
        case NDR_NETR_LOGONCONTROL:
@@ -210,7 +202,7 @@ WERROR _netr_LogonControl2Ex(struct pipes_struct *p,
                return WERR_INVALID_PARAM;
        }
 
-       acct_ctrl = p->session_info->info3->base.acct_flags;
+       acct_ctrl = p->session_info->info->acct_flags;
 
        switch (r->in.function_code) {
        case NETLOGON_CONTROL_TC_VERIFY:
@@ -313,12 +305,15 @@ WERROR _netr_LogonControl2Ex(struct pipes_struct *p,
                        break;
                }
 
-               if (!get_dc_name(domain, NULL, dc_name2, &dc_ss)) {
+               status = dsgetdcname(p->mem_ctx, p->msg_ctx, domain, NULL, NULL,
+                                    DS_FORCE_REDISCOVERY | DS_RETURN_FLAT_NAME,
+                                    &dc_info);
+               if (!NT_STATUS_IS_OK(status)) {
                        tc_status = WERR_NO_LOGON_SERVERS;
                        break;
                }
 
-               dc_name = talloc_asprintf(p->mem_ctx, "\\\\%s", dc_name2);
+               dc_name = talloc_asprintf(p->mem_ctx, "\\\\%s", dc_info->dc_unc);
                if (!dc_name) {
                        return WERR_NOMEM;
                }
@@ -348,7 +343,7 @@ WERROR _netr_LogonControl2Ex(struct pipes_struct *p,
 
        switch (r->in.level) {
        case 1:
-               info1 = TALLOC_ZERO_P(p->mem_ctx, struct netr_NETLOGON_INFO_1);
+               info1 = talloc_zero(p->mem_ctx, struct netr_NETLOGON_INFO_1);
                W_ERROR_HAVE_NO_MEMORY(info1);
 
                info1->flags                    = flags;
@@ -357,7 +352,7 @@ WERROR _netr_LogonControl2Ex(struct pipes_struct *p,
                r->out.query->info1 = info1;
                break;
        case 2:
-               info2 = TALLOC_ZERO_P(p->mem_ctx, struct netr_NETLOGON_INFO_2);
+               info2 = talloc_zero(p->mem_ctx, struct netr_NETLOGON_INFO_2);
                W_ERROR_HAVE_NO_MEMORY(info2);
 
                info2->flags                    = flags;
@@ -368,7 +363,7 @@ WERROR _netr_LogonControl2Ex(struct pipes_struct *p,
                r->out.query->info2 = info2;
                break;
        case 3:
-               info3 = TALLOC_ZERO_P(p->mem_ctx, struct netr_NETLOGON_INFO_3);
+               info3 = talloc_zero(p->mem_ctx, struct netr_NETLOGON_INFO_3);
                W_ERROR_HAVE_NO_MEMORY(info3);
 
                info3->flags                    = flags;
@@ -377,7 +372,7 @@ WERROR _netr_LogonControl2Ex(struct pipes_struct *p,
                r->out.query->info3 = info3;
                break;
        case 4:
-               info4 = TALLOC_ZERO_P(p->mem_ctx, struct netr_NETLOGON_INFO_4);
+               info4 = talloc_zero(p->mem_ctx, struct netr_NETLOGON_INFO_4);
                W_ERROR_HAVE_NO_MEMORY(info4);
 
                info4->trusted_dc_name          = dc_name;
@@ -389,10 +384,6 @@ WERROR _netr_LogonControl2Ex(struct pipes_struct *p,
                return WERR_UNKNOWN_LEVEL;
        }
 
-        if (lp_server_role() == ROLE_DOMAIN_BDC) {
-                send_sync_message(p->msg_ctx);
-       }
-
        return WERR_OK;
 }
 
@@ -419,7 +410,7 @@ NTSTATUS _netr_NetrEnumerateTrustedDomains(struct pipes_struct *p,
 
        status = rpcint_binding_handle(p->mem_ctx,
                                       &ndr_table_lsarpc,
-                                      p->client_id,
+                                      p->remote_address,
                                       p->session_info,
                                       p->msg_ctx,
                                       &h);
@@ -515,7 +506,8 @@ static NTSTATUS samr_find_machine_account(TALLOC_CTX *mem_ctx,
 {
        NTSTATUS status;
        NTSTATUS result = NT_STATUS_OK;
-       struct policy_handle connect_handle, domain_handle;
+       struct policy_handle connect_handle;
+       struct policy_handle domain_handle = { 0, };
        struct lsa_String domain_name;
        struct dom_sid2 *domain_sid;
        struct lsa_String names;
@@ -524,7 +516,7 @@ static NTSTATUS samr_find_machine_account(TALLOC_CTX *mem_ctx,
        uint32_t rid;
 
        status = dcerpc_samr_Connect2(b, mem_ctx,
-                                     global_myname(),
+                                     lp_netbios_name(),
                                      SAMR_ACCESS_CONNECT_TO_SERVER |
                                      SAMR_ACCESS_ENUM_DOMAINS |
                                      SAMR_ACCESS_LOOKUP_DOMAIN,
@@ -645,17 +637,19 @@ static NTSTATUS get_md4pw(struct samr_Password *md4pw, const char *mach_acct,
        NTSTATUS result = NT_STATUS_OK;
        TALLOC_CTX *mem_ctx;
        struct dcerpc_binding_handle *h = NULL;
-       static struct client_address client_id;
+       struct tsocket_address *local;
        struct policy_handle user_handle;
        uint32_t user_rid;
        struct dom_sid *domain_sid;
        uint32_t acct_ctrl;
        union samr_UserInfo *info;
-       struct auth_serversupplied_info *session_info;
+       struct auth_session_info *session_info;
+       int rc;
+
 #if 0
 
     /*
-     * Currently this code is redundent as we already have a filter
+     * Currently this code is redundant as we already have a filter
      * by hostname list. What this code really needs to do is to
      * get a hosts allowed/hosts denied list from the SAM database
      * on a per user basis, and make the access decision there.
@@ -684,12 +678,19 @@ static NTSTATUS get_md4pw(struct samr_Password *md4pw, const char *mach_acct,
 
        ZERO_STRUCT(user_handle);
 
-       strlcpy(client_id.addr, "127.0.0.1", sizeof(client_id.addr));
-       client_id.name = "127.0.0.1";
+       rc = tsocket_address_inet_from_strings(mem_ctx,
+                                              "ip",
+                                              "127.0.0.1",
+                                              0,
+                                              &local);
+       if (rc < 0) {
+               status = NT_STATUS_NO_MEMORY;
+               goto out;
+       }
 
        status = rpcint_binding_handle(mem_ctx,
                                       &ndr_table_samr,
-                                      &client_id,
+                                      local,
                                       session_info,
                                       msg_ctx,
                                       &h);
@@ -697,12 +698,10 @@ static NTSTATUS get_md4pw(struct samr_Password *md4pw, const char *mach_acct,
                goto out;
        }
 
-       become_root();
        status = samr_find_machine_account(mem_ctx, h, mach_acct,
                                           SEC_FLAG_MAXIMUM_ALLOWED,
                                           &domain_sid, &user_rid,
                                           &user_handle);
-       unbecome_root();
        if (!NT_STATUS_IS_OK(status)) {
                goto out;
        }
@@ -875,6 +874,7 @@ NTSTATUS _netr_ServerAuthenticate3(struct pipes_struct *p,
         * so use a copy to avoid destroying the client values. */
        uint32_t in_neg_flags = *r->in.negotiate_flags;
        const char *fn;
+       struct loadparm_context *lp_ctx;
        struct dom_sid sid;
        struct samr_Password mach_pwd;
        struct netlogon_creds_CredentialState *creds;
@@ -907,10 +907,27 @@ NTSTATUS _netr_ServerAuthenticate3(struct pipes_struct *p,
                srv_flgs |= NETLOGON_NEG_STRONG_KEYS;
        }
 
+       if (in_neg_flags & NETLOGON_NEG_SUPPORTS_AES) {
+               srv_flgs |= NETLOGON_NEG_SUPPORTS_AES;
+       }
+
        if (lp_server_schannel() != false) {
                srv_flgs |= NETLOGON_NEG_SCHANNEL;
        }
 
+       /*
+        * Support authenticaten of trusted domains.
+        *
+        * These flags are the minimum required set which works with win2k3
+        * and win2k8.
+        */
+       if (pdb_capabilities() & PDB_CAP_TRUSTED_DOMAINS_EX) {
+               srv_flgs |= NETLOGON_NEG_TRANSITIVE_TRUSTS |
+                           NETLOGON_NEG_DNS_DOMAIN_TRUSTS |
+                           NETLOGON_NEG_CROSS_FOREST_TRUSTS |
+                           NETLOGON_NEG_NEUTRALIZE_NT4_EMULATION;
+       }
+
        switch (p->opnum) {
                case NDR_NETR_SERVERAUTHENTICATE:
                        fn = "_netr_ServerAuthenticate";
@@ -970,7 +987,7 @@ NTSTATUS _netr_ServerAuthenticate3(struct pipes_struct *p,
                                           &mach_pwd,
                                           r->in.credentials,
                                           r->out.return_credentials,
-                                          *r->in.negotiate_flags);
+                                          srv_flgs);
        if (!creds) {
                DEBUG(0,("%s: netlogon_creds_server_check failed. Rejecting auth "
                        "request from client %s machine account %s\n",
@@ -986,11 +1003,20 @@ NTSTATUS _netr_ServerAuthenticate3(struct pipes_struct *p,
                goto out;
        }
 
+       lp_ctx = loadparm_init_s3(p->mem_ctx, loadparm_s3_helpers());
+       if (lp_ctx == NULL) {
+               DEBUG(10, ("loadparm_init_s3 failed\n"));
+               status = NT_STATUS_INTERNAL_ERROR;
+               goto out;
+       }
+
        /* Store off the state so we can continue after client disconnect. */
        become_root();
-       status = schannel_save_creds_state(p->mem_ctx, lp_private_dir(), creds);
+       status = schannel_save_creds_state(p->mem_ctx, lp_ctx, creds);
        unbecome_root();
 
+       talloc_unlink(p->mem_ctx, lp_ctx);
+
        if (!NT_STATUS_IS_OK(status)) {
                goto out;
        }
@@ -1071,6 +1097,7 @@ static NTSTATUS netr_creds_server_step_check(struct pipes_struct *p,
 {
        NTSTATUS status;
        bool schannel_global_required = (lp_server_schannel() == true) ? true:false;
+       struct loadparm_context *lp_ctx;
 
        if (schannel_global_required) {
                status = schannel_check_required(&p->auth,
@@ -1081,10 +1108,16 @@ static NTSTATUS netr_creds_server_step_check(struct pipes_struct *p,
                }
        }
 
-       status = schannel_check_creds_state(mem_ctx, lp_private_dir(),
+       lp_ctx = loadparm_init_s3(mem_ctx, loadparm_s3_helpers());
+       if (lp_ctx == NULL) {
+               DEBUG(0, ("loadparm_init_s3 failed\n"));
+               return NT_STATUS_INTERNAL_ERROR;
+       }
+
+       status = schannel_check_creds_state(mem_ctx, lp_ctx,
                                            computer_name, received_authenticator,
                                            return_authenticator, creds_out);
-
+       talloc_unlink(mem_ctx, lp_ctx);
        return status;
 }
 
@@ -1092,7 +1125,7 @@ static NTSTATUS netr_creds_server_step_check(struct pipes_struct *p,
  *************************************************************************/
 
 static NTSTATUS netr_set_machine_account_password(TALLOC_CTX *mem_ctx,
-                                                 struct auth_serversupplied_info *session_info,
+                                                 struct auth_session_info *session_info,
                                                  struct messaging_context *msg_ctx,
                                                  const char *account_name,
                                                  struct samr_Password *nt_hash)
@@ -1100,21 +1133,37 @@ static NTSTATUS netr_set_machine_account_password(TALLOC_CTX *mem_ctx,
        NTSTATUS status;
        NTSTATUS result = NT_STATUS_OK;
        struct dcerpc_binding_handle *h = NULL;
-       static struct client_address client_id;
+       struct tsocket_address *local;
        struct policy_handle user_handle;
        uint32_t acct_ctrl;
        union samr_UserInfo *info;
        struct samr_UserInfo18 info18;
        DATA_BLOB in,out;
+       int rc;
+       DATA_BLOB session_key;
 
        ZERO_STRUCT(user_handle);
 
-       strlcpy(client_id.addr, "127.0.0.1", sizeof(client_id.addr));
-       client_id.name = "127.0.0.1";
+       status = session_extract_session_key(session_info,
+                                            &session_key,
+                                            KEY_USE_16BYTES);
+       if (!NT_STATUS_IS_OK(status)) {
+               goto out;
+       }
+
+       rc = tsocket_address_inet_from_strings(mem_ctx,
+                                              "ip",
+                                              "127.0.0.1",
+                                              0,
+                                              &local);
+       if (rc < 0) {
+               status = NT_STATUS_NO_MEMORY;
+               goto out;
+       }
 
        status = rpcint_binding_handle(mem_ctx,
                                       &ndr_table_samr,
-                                      &client_id,
+                                      local,
                                       session_info,
                                       msg_ctx,
                                       &h);
@@ -1122,6 +1171,7 @@ static NTSTATUS netr_set_machine_account_password(TALLOC_CTX *mem_ctx,
                goto out;
        }
 
+       become_root();
        status = samr_find_machine_account(mem_ctx,
                                           h,
                                           account_name,
@@ -1129,6 +1179,7 @@ static NTSTATUS netr_set_machine_account_password(TALLOC_CTX *mem_ctx,
                                           NULL,
                                           NULL,
                                           &user_handle);
+       unbecome_root();
        if (!NT_STATUS_IS_OK(status)) {
                goto out;
        }
@@ -1165,19 +1216,21 @@ static NTSTATUS netr_set_machine_account_password(TALLOC_CTX *mem_ctx,
 
        in = data_blob_const(nt_hash->hash, 16);
        out = data_blob_talloc_zero(mem_ctx, 16);
-       sess_crypt_blob(&out, &in, &session_info->user_session_key, true);
+       sess_crypt_blob(&out, &in, &session_key, true);
        memcpy(info18.nt_pwd.hash, out.data, out.length);
 
        info18.nt_pwd_active = true;
 
        info->info18 = info18;
 
+       become_root();
        status = dcerpc_samr_SetUserInfo2(h,
                                          mem_ctx,
                                          &user_handle,
                                          UserInternal1Information,
                                          info,
                                          &result);
+       unbecome_root();
        if (!NT_STATUS_IS_OK(status)) {
                goto out;
        }
@@ -1249,7 +1302,7 @@ NTSTATUS _netr_ServerPasswordSet2(struct pipes_struct *p,
                                  struct netr_ServerPasswordSet2 *r)
 {
        NTSTATUS status;
-       struct netlogon_creds_CredentialState *creds;
+       struct netlogon_creds_CredentialState *creds = NULL;
        DATA_BLOB plaintext;
        struct samr_CryptPassword password_buf;
        struct samr_Password nt_hash;
@@ -1263,18 +1316,29 @@ NTSTATUS _netr_ServerPasswordSet2(struct pipes_struct *p,
        unbecome_root();
 
        if (!NT_STATUS_IS_OK(status)) {
+               const char *computer_name = "<unknown>";
+
+               if (creds && creds->computer_name) {
+                       computer_name = creds->computer_name;
+               }
                DEBUG(2,("_netr_ServerPasswordSet2: netlogon_creds_server_step "
                        "failed. Rejecting auth request from client %s machine account %s\n",
-                       r->in.computer_name, creds->computer_name));
+                       r->in.computer_name, computer_name));
                TALLOC_FREE(creds);
                return status;
        }
 
        memcpy(password_buf.data, r->in.new_password->data, 512);
        SIVAL(password_buf.data, 512, r->in.new_password->length);
-       netlogon_creds_arcfour_crypt(creds, password_buf.data, 516);
+
+       if (creds->negotiate_flags & NETLOGON_NEG_SUPPORTS_AES) {
+               netlogon_creds_aes_decrypt(creds, password_buf.data, 516);
+       } else {
+               netlogon_creds_arcfour_crypt(creds, password_buf.data, 516);
+       }
 
        if (!extract_pw_from_buffer(p->mem_ctx, password_buf.data, &plaintext)) {
+               TALLOC_FREE(creds);
                return NT_STATUS_WRONG_PASSWORD;
        }
 
@@ -1285,6 +1349,7 @@ NTSTATUS _netr_ServerPasswordSet2(struct pipes_struct *p,
                                                   p->msg_ctx,
                                                   creds->account_name,
                                                   &nt_hash);
+       TALLOC_FREE(creds);
        return status;
 }
 
@@ -1398,21 +1463,25 @@ static NTSTATUS _netr_LogonSamLogon_base(struct pipes_struct *p,
        struct auth_usersupplied_info *user_info = NULL;
        struct auth_serversupplied_info *server_info = NULL;
        struct auth_context *auth_context = NULL;
-       uint8_t pipe_session_key[16];
-       bool process_creds = true;
        const char *fn;
 
+#ifdef DEBUG_PASSWORD
+       logon = netlogon_creds_shallow_copy_logon(p->mem_ctx,
+                                                 r->in.logon_level,
+                                                 r->in.logon);
+       if (logon == NULL) {
+               logon = r->in.logon;
+       }
+#endif
+
        switch (p->opnum) {
                case NDR_NETR_LOGONSAMLOGON:
-                       process_creds = true;
                        fn = "_netr_LogonSamLogon";
                        break;
                case NDR_NETR_LOGONSAMLOGONWITHFLAGS:
-                       process_creds = true;
                        fn = "_netr_LogonSamLogonWithFlags";
                        break;
                case NDR_NETR_LOGONSAMLOGONEX:
-                       process_creds = false;
                        fn = "_netr_LogonSamLogonEx";
                        break;
                default:
@@ -1423,19 +1492,19 @@ static NTSTATUS _netr_LogonSamLogon_base(struct pipes_struct *p,
 
        switch (r->in.validation_level) {
        case 2:
-               r->out.validation->sam2 = TALLOC_ZERO_P(p->mem_ctx, struct netr_SamInfo2);
+               r->out.validation->sam2 = talloc_zero(p->mem_ctx, struct netr_SamInfo2);
                if (!r->out.validation->sam2) {
                        return NT_STATUS_NO_MEMORY;
                }
                break;
        case 3:
-               r->out.validation->sam3 = TALLOC_ZERO_P(p->mem_ctx, struct netr_SamInfo3);
+               r->out.validation->sam3 = talloc_zero(p->mem_ctx, struct netr_SamInfo3);
                if (!r->out.validation->sam3) {
                        return NT_STATUS_NO_MEMORY;
                }
                break;
        case 6:
-               r->out.validation->sam6 = TALLOC_ZERO_P(p->mem_ctx, struct netr_SamInfo6);
+               r->out.validation->sam6 = talloc_zero(p->mem_ctx, struct netr_SamInfo6);
                if (!r->out.validation->sam6) {
                        return NT_STATUS_NO_MEMORY;
                }
@@ -1485,6 +1554,10 @@ static NTSTATUS _netr_LogonSamLogon_base(struct pipes_struct *p,
 
        status = NT_STATUS_OK;
 
+       netlogon_creds_decrypt_samlogon_logon(creds,
+                                             r->in.logon_level,
+                                             logon);
+
        switch (r->in.logon_level) {
        case NetlogonNetworkInformation:
        case NetlogonNetworkTransitiveInformation:
@@ -1507,6 +1580,7 @@ static NTSTATUS _netr_LogonSamLogon_base(struct pipes_struct *p,
                if (!make_user_info_netlogon_network(&user_info,
                                                     nt_username, nt_domain,
                                                     wksname,
+                                                    p->remote_address,
                                                     logon->network->identity_info.parameter_control,
                                                     logon->network->lm.data,
                                                     logon->network->lm.length,
@@ -1528,22 +1602,39 @@ static NTSTATUS _netr_LogonSamLogon_base(struct pipes_struct *p,
        {
                uint8_t chal[8];
 
+#ifdef DEBUG_PASSWORD
+               if (logon != r->in.logon) {
+                       DEBUG(100,("lm owf password:"));
+                       dump_data(100,
+                                 r->in.logon->password->lmpassword.hash, 16);
+
+                       DEBUG(100,("nt owf password:"));
+                       dump_data(100,
+                                 r->in.logon->password->ntpassword.hash, 16);
+               }
+
+               DEBUG(100,("decrypt of lm owf password:"));
+               dump_data(100, logon->password->lmpassword.hash, 16);
+
+               DEBUG(100,("decrypt of nt owf password:"));
+               dump_data(100, logon->password->ntpassword.hash, 16);
+#endif
                status = make_auth_context_subsystem(talloc_tos(),
                                                     &auth_context);
                if (!NT_STATUS_IS_OK(status)) {
                        return status;
                }
 
-               auth_context->get_ntlm_challenge(auth_context, chal);
+               auth_get_ntlm_challenge(auth_context, chal);
 
                if (!make_user_info_netlogon_interactive(&user_info,
                                                         nt_username, nt_domain,
                                                         nt_workstation,
+                                                        p->remote_address,
                                                         logon->password->identity_info.parameter_control,
                                                         chal,
                                                         logon->password->lmpassword.hash,
-                                                        logon->password->ntpassword.hash,
-                                                        creds->session_key)) {
+                                                        logon->password->ntpassword.hash)) {
                        status = NT_STATUS_NO_MEMORY;
                }
                break;
@@ -1554,7 +1645,7 @@ static NTSTATUS _netr_LogonSamLogon_base(struct pipes_struct *p,
        } /* end switch */
 
        if ( NT_STATUS_IS_OK(status) ) {
-               status = auth_context->check_ntlm_password(auth_context,
+               status = auth_check_ntlm_password(auth_context,
                        user_info, &server_info);
        }
 
@@ -1592,40 +1683,31 @@ static NTSTATUS _netr_LogonSamLogon_base(struct pipes_struct *p,
            the SAM Local Security Authority should record that the user is
            logged in to the domain.  */
 
-       if (process_creds) {
-               /* Get the pipe session key from the creds. */
-               memcpy(pipe_session_key, creds->session_key, 16);
-       } else {
-               struct schannel_state *schannel_auth;
-               /* Get the pipe session key from the schannel. */
-               if ((p->auth.auth_type != DCERPC_AUTH_TYPE_SCHANNEL)
-                   || (p->auth.auth_ctx == NULL)) {
-                       return NT_STATUS_INVALID_HANDLE;
-               }
-
-               schannel_auth = talloc_get_type_abort(p->auth.auth_ctx,
-                                                     struct schannel_state);
-               memcpy(pipe_session_key, schannel_auth->creds->session_key, 16);
-       }
-
        switch (r->in.validation_level) {
        case 2:
-               status = serverinfo_to_SamInfo2(server_info, pipe_session_key, 16,
+               status = serverinfo_to_SamInfo2(server_info,
                                                r->out.validation->sam2);
                break;
        case 3:
-               status = serverinfo_to_SamInfo3(server_info, pipe_session_key, 16,
+               status = serverinfo_to_SamInfo3(server_info,
                                                r->out.validation->sam3);
                break;
        case 6:
-               status = serverinfo_to_SamInfo6(server_info, pipe_session_key, 16,
+               status = serverinfo_to_SamInfo6(server_info,
                                                r->out.validation->sam6);
                break;
        }
 
        TALLOC_FREE(server_info);
 
-       return status;
+       if (!NT_STATUS_IS_OK(status)) {
+               return status;
+       }
+
+       netlogon_creds_encrypt_samlogon_validation(creds,
+                                                  r->in.validation_level,
+                                                  r->out.validation);
+       return NT_STATUS_OK;
 }
 
 /****************************************************************
@@ -1714,6 +1796,7 @@ NTSTATUS _netr_LogonSamLogonEx(struct pipes_struct *p,
 {
        NTSTATUS status;
        struct netlogon_creds_CredentialState *creds = NULL;
+       struct loadparm_context *lp_ctx;
 
        *r->out.authoritative = true;
 
@@ -1729,10 +1812,18 @@ NTSTATUS _netr_LogonSamLogonEx(struct pipes_struct *p,
                return NT_STATUS_INVALID_PARAMETER;
         }
 
+       lp_ctx = loadparm_init_s3(p->mem_ctx, loadparm_s3_helpers());
+       if (lp_ctx == NULL) {
+               DEBUG(0, ("loadparm_init_s3 failed\n"));
+               return NT_STATUS_INTERNAL_ERROR;
+       }
+
        become_root();
-       status = schannel_get_creds_state(p->mem_ctx, lp_private_dir(),
+       status = schannel_get_creds_state(p->mem_ctx, lp_ctx,
                                          r->in.computer_name, &creds);
        unbecome_root();
+       talloc_unlink(p->mem_ctx, lp_ctx);
+
        if (!NT_STATUS_IS_OK(status)) {
                return status;
        }
@@ -1769,7 +1860,7 @@ NTSTATUS _netr_LogonSamLogonEx(struct pipes_struct *p,
 WERROR _netr_LogonUasLogon(struct pipes_struct *p,
                           struct netr_LogonUasLogon *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return WERR_NOT_SUPPORTED;
 }
 
@@ -1779,7 +1870,7 @@ WERROR _netr_LogonUasLogon(struct pipes_struct *p,
 WERROR _netr_LogonUasLogoff(struct pipes_struct *p,
                            struct netr_LogonUasLogoff *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return WERR_NOT_SUPPORTED;
 }
 
@@ -1789,7 +1880,7 @@ WERROR _netr_LogonUasLogoff(struct pipes_struct *p,
 NTSTATUS _netr_DatabaseDeltas(struct pipes_struct *p,
                              struct netr_DatabaseDeltas *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return NT_STATUS_NOT_IMPLEMENTED;
 }
 
@@ -1799,7 +1890,7 @@ NTSTATUS _netr_DatabaseDeltas(struct pipes_struct *p,
 NTSTATUS _netr_DatabaseSync(struct pipes_struct *p,
                            struct netr_DatabaseSync *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return NT_STATUS_NOT_IMPLEMENTED;
 }
 
@@ -1809,7 +1900,7 @@ NTSTATUS _netr_DatabaseSync(struct pipes_struct *p,
 NTSTATUS _netr_AccountDeltas(struct pipes_struct *p,
                             struct netr_AccountDeltas *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return NT_STATUS_NOT_IMPLEMENTED;
 }
 
@@ -1819,7 +1910,7 @@ NTSTATUS _netr_AccountDeltas(struct pipes_struct *p,
 NTSTATUS _netr_AccountSync(struct pipes_struct *p,
                           struct netr_AccountSync *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return NT_STATUS_NOT_IMPLEMENTED;
 }
 
@@ -1960,7 +2051,7 @@ WERROR _netr_GetAnyDCName(struct pipes_struct *p,
 NTSTATUS _netr_DatabaseSync2(struct pipes_struct *p,
                             struct netr_DatabaseSync2 *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return NT_STATUS_NOT_IMPLEMENTED;
 }
 
@@ -1970,7 +2061,7 @@ NTSTATUS _netr_DatabaseSync2(struct pipes_struct *p,
 NTSTATUS _netr_DatabaseRedo(struct pipes_struct *p,
                            struct netr_DatabaseRedo *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return NT_STATUS_NOT_IMPLEMENTED;
 }
 
@@ -1980,7 +2071,7 @@ NTSTATUS _netr_DatabaseRedo(struct pipes_struct *p,
 WERROR _netr_DsRGetDCName(struct pipes_struct *p,
                          struct netr_DsRGetDCName *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return WERR_NOT_SUPPORTED;
 }
 
@@ -1990,7 +2081,27 @@ WERROR _netr_DsRGetDCName(struct pipes_struct *p,
 NTSTATUS _netr_LogonGetCapabilities(struct pipes_struct *p,
                                    struct netr_LogonGetCapabilities *r)
 {
-       return NT_STATUS_NOT_IMPLEMENTED;
+       struct netlogon_creds_CredentialState *creds;
+       NTSTATUS status;
+
+       become_root();
+       status = netr_creds_server_step_check(p, p->mem_ctx,
+                                             r->in.computer_name,
+                                             r->in.credential,
+                                             r->out.return_authenticator,
+                                             &creds);
+       unbecome_root();
+       if (!NT_STATUS_IS_OK(status)) {
+               return status;
+       }
+
+       if (r->in.query_level != 1) {
+               return NT_STATUS_NOT_SUPPORTED;
+       }
+
+       r->out.capabilities->server_capabilities = creds->negotiate_flags;
+
+       return NT_STATUS_OK;
 }
 
 /****************************************************************
@@ -1999,7 +2110,7 @@ NTSTATUS _netr_LogonGetCapabilities(struct pipes_struct *p,
 WERROR _netr_NETRLOGONSETSERVICEBITS(struct pipes_struct *p,
                                     struct netr_NETRLOGONSETSERVICEBITS *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return WERR_NOT_SUPPORTED;
 }
 
@@ -2009,7 +2120,7 @@ WERROR _netr_NETRLOGONSETSERVICEBITS(struct pipes_struct *p,
 WERROR _netr_LogonGetTrustRid(struct pipes_struct *p,
                              struct netr_LogonGetTrustRid *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return WERR_NOT_SUPPORTED;
 }
 
@@ -2019,7 +2130,7 @@ WERROR _netr_LogonGetTrustRid(struct pipes_struct *p,
 WERROR _netr_NETRLOGONCOMPUTESERVERDIGEST(struct pipes_struct *p,
                                          struct netr_NETRLOGONCOMPUTESERVERDIGEST *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return WERR_NOT_SUPPORTED;
 }
 
@@ -2029,7 +2140,7 @@ WERROR _netr_NETRLOGONCOMPUTESERVERDIGEST(struct pipes_struct *p,
 WERROR _netr_NETRLOGONCOMPUTECLIENTDIGEST(struct pipes_struct *p,
                                          struct netr_NETRLOGONCOMPUTECLIENTDIGEST *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return WERR_NOT_SUPPORTED;
 }
 
@@ -2039,7 +2150,7 @@ WERROR _netr_NETRLOGONCOMPUTECLIENTDIGEST(struct pipes_struct *p,
 WERROR _netr_DsRGetDCNameEx(struct pipes_struct *p,
                            struct netr_DsRGetDCNameEx *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return WERR_NOT_SUPPORTED;
 }
 
@@ -2049,7 +2160,7 @@ WERROR _netr_DsRGetDCNameEx(struct pipes_struct *p,
 WERROR _netr_DsRGetSiteName(struct pipes_struct *p,
                            struct netr_DsRGetSiteName *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return WERR_NOT_SUPPORTED;
 }
 
@@ -2059,7 +2170,7 @@ WERROR _netr_DsRGetSiteName(struct pipes_struct *p,
 NTSTATUS _netr_LogonGetDomainInfo(struct pipes_struct *p,
                                  struct netr_LogonGetDomainInfo *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return NT_STATUS_NOT_IMPLEMENTED;
 }
 
@@ -2069,7 +2180,7 @@ NTSTATUS _netr_LogonGetDomainInfo(struct pipes_struct *p,
 WERROR _netr_ServerPasswordGet(struct pipes_struct *p,
                               struct netr_ServerPasswordGet *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return WERR_NOT_SUPPORTED;
 }
 
@@ -2079,7 +2190,7 @@ WERROR _netr_ServerPasswordGet(struct pipes_struct *p,
 WERROR _netr_NETRLOGONSENDTOSAM(struct pipes_struct *p,
                                struct netr_NETRLOGONSENDTOSAM *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return WERR_NOT_SUPPORTED;
 }
 
@@ -2089,7 +2200,7 @@ WERROR _netr_NETRLOGONSENDTOSAM(struct pipes_struct *p,
 WERROR _netr_DsRAddressToSitenamesW(struct pipes_struct *p,
                                    struct netr_DsRAddressToSitenamesW *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return WERR_NOT_SUPPORTED;
 }
 
@@ -2099,7 +2210,7 @@ WERROR _netr_DsRAddressToSitenamesW(struct pipes_struct *p,
 WERROR _netr_DsRGetDCNameEx2(struct pipes_struct *p,
                             struct netr_DsRGetDCNameEx2 *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return WERR_NOT_SUPPORTED;
 }
 
@@ -2109,7 +2220,7 @@ WERROR _netr_DsRGetDCNameEx2(struct pipes_struct *p,
 WERROR _netr_NETRLOGONGETTIMESERVICEPARENTDOMAIN(struct pipes_struct *p,
                                                 struct netr_NETRLOGONGETTIMESERVICEPARENTDOMAIN *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return WERR_NOT_SUPPORTED;
 }
 
@@ -2119,7 +2230,7 @@ WERROR _netr_NETRLOGONGETTIMESERVICEPARENTDOMAIN(struct pipes_struct *p,
 WERROR _netr_NetrEnumerateTrustedDomainsEx(struct pipes_struct *p,
                                           struct netr_NetrEnumerateTrustedDomainsEx *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return WERR_NOT_SUPPORTED;
 }
 
@@ -2129,7 +2240,7 @@ WERROR _netr_NetrEnumerateTrustedDomainsEx(struct pipes_struct *p,
 WERROR _netr_DsRAddressToSitenamesExW(struct pipes_struct *p,
                                      struct netr_DsRAddressToSitenamesExW *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return WERR_NOT_SUPPORTED;
 }
 
@@ -2139,7 +2250,7 @@ WERROR _netr_DsRAddressToSitenamesExW(struct pipes_struct *p,
 WERROR _netr_DsrGetDcSiteCoverageW(struct pipes_struct *p,
                                   struct netr_DsrGetDcSiteCoverageW *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return WERR_NOT_SUPPORTED;
 }
 
@@ -2149,7 +2260,7 @@ WERROR _netr_DsrGetDcSiteCoverageW(struct pipes_struct *p,
 WERROR _netr_DsrEnumerateDomainTrusts(struct pipes_struct *p,
                                      struct netr_DsrEnumerateDomainTrusts *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return WERR_NOT_SUPPORTED;
 }
 
@@ -2159,7 +2270,7 @@ WERROR _netr_DsrEnumerateDomainTrusts(struct pipes_struct *p,
 WERROR _netr_DsrDeregisterDNSHostRecords(struct pipes_struct *p,
                                         struct netr_DsrDeregisterDNSHostRecords *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return WERR_NOT_SUPPORTED;
 }
 
@@ -2169,29 +2280,23 @@ WERROR _netr_DsrDeregisterDNSHostRecords(struct pipes_struct *p,
 NTSTATUS _netr_ServerTrustPasswordsGet(struct pipes_struct *p,
                                       struct netr_ServerTrustPasswordsGet *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return NT_STATUS_NOT_IMPLEMENTED;
 }
 
 /****************************************************************
 ****************************************************************/
 
-WERROR _netr_DsRGetForestTrustInformation(struct pipes_struct *p,
-                                         struct netr_DsRGetForestTrustInformation *r)
-{
-       p->rng_fault_state = true;
-       return WERR_NOT_SUPPORTED;
-}
-
-/****************************************************************
-****************************************************************/
-
 static NTSTATUS fill_forest_trust_array(TALLOC_CTX *mem_ctx,
                                        struct lsa_ForestTrustInformation *info)
 {
        struct lsa_ForestTrustRecord *e;
        struct pdb_domain_info *dom_info;
        struct lsa_ForestTrustDomainInfo *domain_info;
+       char **upn_suffixes = NULL;
+       uint32_t num_suffixes = 0;
+       uint32_t i = 0;
+       NTSTATUS status;
 
        dom_info = pdb_get_domain_info(mem_ctx);
        if (dom_info == NULL) {
@@ -2199,7 +2304,15 @@ static NTSTATUS fill_forest_trust_array(TALLOC_CTX *mem_ctx,
        }
 
        info->count = 2;
-       info->entries = talloc_array(info, struct lsa_ForestTrustRecord *, 2);
+
+       become_root();
+       status = pdb_enum_upn_suffixes(info, &num_suffixes, &upn_suffixes);
+       unbecome_root();
+       if (NT_STATUS_IS_OK(status) && (num_suffixes > 0)) {
+               info->count += num_suffixes;
+       }
+
+       info->entries = talloc_array(info, struct lsa_ForestTrustRecord *, info->count);
        if (info->entries == NULL) {
                return NT_STATUS_NO_MEMORY;
        }
@@ -2217,6 +2330,21 @@ static NTSTATUS fill_forest_trust_array(TALLOC_CTX *mem_ctx,
 
        info->entries[0] = e;
 
+       if (num_suffixes > 0) {
+               for (i = 0; i < num_suffixes ; i++) {
+                       e = talloc(info, struct lsa_ForestTrustRecord);
+                       if (e == NULL) {
+                               return NT_STATUS_NO_MEMORY;
+                       }
+
+                       e->flags = 0;
+                       e->type = LSA_FOREST_TRUST_TOP_LEVEL_NAME;
+                       e->time = 0; /* so far always 0 in traces. */
+                       e->forest_trust_data.top_level_name.string = upn_suffixes[i];
+                       info->entries[1 + i] = e;
+               }
+       }
+
        e = talloc(info, struct lsa_ForestTrustRecord);
        if (e == NULL) {
                return NT_STATUS_NO_MEMORY;
@@ -2235,11 +2363,75 @@ static NTSTATUS fill_forest_trust_array(TALLOC_CTX *mem_ctx,
        domain_info->netbios_domain_name.string = talloc_steal(info,
                                                               dom_info->name);
 
-       info->entries[1] = e;
+       info->entries[info->count - 1] = e;
 
        return NT_STATUS_OK;
 }
 
+/****************************************************************
+****************************************************************/
+
+WERROR _netr_DsRGetForestTrustInformation(struct pipes_struct *p,
+                                         struct netr_DsRGetForestTrustInformation *r)
+{
+       NTSTATUS status;
+       struct lsa_ForestTrustInformation *info, **info_ptr;
+
+       if (!(p->pipe_bound && (p->auth.auth_type != DCERPC_AUTH_TYPE_NONE)
+                      && (p->auth.auth_level != DCERPC_AUTH_LEVEL_NONE))) {
+               p->fault_state = DCERPC_FAULT_ACCESS_DENIED;
+               return WERR_ACCESS_DENIED;
+       }
+
+       if (r->in.flags & (~DS_GFTI_UPDATE_TDO)) {
+               p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
+               return WERR_INVALID_FLAGS;
+       }
+
+       if ((r->in.flags & DS_GFTI_UPDATE_TDO) && (lp_server_role() != ROLE_DOMAIN_PDC)) {
+               p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
+               return WERR_NERR_NOTPRIMARY;
+       }
+
+       if ((r->in.trusted_domain_name == NULL) && (r->in.flags & DS_GFTI_UPDATE_TDO)) {
+               p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
+               return WERR_INVALID_PARAMETER;
+       }
+
+       /* retrieve forest trust information and stop further processing */
+       if (r->in.trusted_domain_name == NULL) {
+               info_ptr = talloc(p->mem_ctx, struct lsa_ForestTrustInformation *);
+               if (info_ptr == NULL) {
+                       p->fault_state = DCERPC_FAULT_CANT_PERFORM;
+                       return WERR_NOMEM;
+               }
+               info = talloc_zero(info_ptr, struct lsa_ForestTrustInformation);
+               if (info == NULL) {
+                       p->fault_state = DCERPC_FAULT_CANT_PERFORM;
+                       return WERR_NOMEM;
+               }
+
+               /* Fill forest trust information and expand UPN suffixes list */
+               status = fill_forest_trust_array(p->mem_ctx, info);
+               if (!NT_STATUS_IS_OK(status)) {
+                       p->fault_state = DCERPC_FAULT_CANT_PERFORM;
+                       return WERR_NOMEM;
+               }
+
+               *info_ptr = info;
+               r->out.forest_trust_info = info_ptr;
+
+               return WERR_OK;
+
+       }
+
+       /* TODO: implement remaining parts of DsrGetForestTrustInformation (opnum 43)
+        *       when trusted_domain_name is not NULL */
+
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
+       return WERR_NOT_SUPPORTED;
+}
+
 /****************************************************************
  _netr_GetForestTrustInformation
 ****************************************************************/
@@ -2250,14 +2442,22 @@ NTSTATUS _netr_GetForestTrustInformation(struct pipes_struct *p,
        NTSTATUS status;
        struct netlogon_creds_CredentialState *creds;
        struct lsa_ForestTrustInformation *info, **info_ptr;
+       struct loadparm_context *lp_ctx;
 
        /* TODO: check server name */
 
-       status = schannel_check_creds_state(p->mem_ctx, lp_private_dir(),
+       lp_ctx = loadparm_init_s3(p->mem_ctx, loadparm_s3_helpers());
+       if (lp_ctx == NULL) {
+               DEBUG(0, ("loadparm_init_s3 failed\n"));
+               return NT_STATUS_INTERNAL_ERROR;
+       }
+
+       status = schannel_check_creds_state(p->mem_ctx, lp_ctx,
                                            r->in.computer_name,
                                            r->in.credential,
                                            r->out.return_authenticator,
                                            &creds);
+       talloc_unlink(p->mem_ctx, lp_ctx);
        if (!NT_STATUS_IS_OK(status)) {
                return status;
        }
@@ -2276,6 +2476,7 @@ NTSTATUS _netr_GetForestTrustInformation(struct pipes_struct *p,
                return NT_STATUS_NO_MEMORY;
        }
 
+       /* Fill forest trust information, do expand UPN suffixes list */
        status = fill_forest_trust_array(p->mem_ctx, info);
        if (!NT_STATUS_IS_OK(status)) {
                return status;
@@ -2292,7 +2493,7 @@ NTSTATUS _netr_GetForestTrustInformation(struct pipes_struct *p,
 
 static NTSTATUS get_password_from_trustAuth(TALLOC_CTX *mem_ctx,
                                            const DATA_BLOB *trustAuth_blob,
-                                           const DATA_BLOB *session_key,
+                                           struct netlogon_creds_CredentialState *creds,
                                            struct samr_Password *current_pw_enc,
                                            struct samr_Password *previous_pw_enc)
 {
@@ -2305,29 +2506,26 @@ static NTSTATUS get_password_from_trustAuth(TALLOC_CTX *mem_ctx,
                return NT_STATUS_UNSUCCESSFUL;
        }
 
-
        if (trustAuth.count != 0 && trustAuth.current.count != 0 &&
            trustAuth.current.array[0].AuthType == TRUST_AUTH_TYPE_CLEAR) {
-               mdfour(previous_pw_enc->hash,
+               mdfour(current_pw_enc->hash,
                       trustAuth.current.array[0].AuthInfo.clear.password,
                       trustAuth.current.array[0].AuthInfo.clear.size);
+               netlogon_creds_des_encrypt(creds, current_pw_enc);
        } else {
                return NT_STATUS_UNSUCCESSFUL;
        }
 
-       arcfour_crypt_blob(current_pw_enc->hash, sizeof(current_pw_enc->hash),
-                          session_key);
 
        if (trustAuth.previous.count != 0 &&
            trustAuth.previous.array[0].AuthType == TRUST_AUTH_TYPE_CLEAR) {
                mdfour(previous_pw_enc->hash,
                       trustAuth.previous.array[0].AuthInfo.clear.password,
                       trustAuth.previous.array[0].AuthInfo.clear.size);
+               netlogon_creds_des_encrypt(creds, previous_pw_enc);
        } else {
-               mdfour(previous_pw_enc->hash, NULL, 0);
+               ZERO_STRUCTP(previous_pw_enc);
        }
-       arcfour_crypt_blob(previous_pw_enc->hash, sizeof(previous_pw_enc->hash),
-                          session_key);
 
        return NT_STATUS_OK;
 }
@@ -2346,18 +2544,22 @@ NTSTATUS _netr_ServerGetTrustInfo(struct pipes_struct *p,
        bool trusted;
        struct netr_TrustInfo *trust_info;
        struct pdb_trusted_domain *td;
-       DATA_BLOB trustAuth_blob;
-       struct samr_Password *new_owf_enc;
-       struct samr_Password *old_owf_enc;
-       DATA_BLOB session_key;
+       struct loadparm_context *lp_ctx;
+
+       lp_ctx = loadparm_init_s3(p->mem_ctx, loadparm_s3_helpers());
+       if (lp_ctx == NULL) {
+               DEBUG(0, ("loadparm_init_s3 failed\n"));
+               return NT_STATUS_INTERNAL_ERROR;
+       }
 
        /* TODO: check server name */
 
-       status = schannel_check_creds_state(p->mem_ctx, lp_private_dir(),
+       status = schannel_check_creds_state(p->mem_ctx, lp_ctx,
                                            r->in.computer_name,
                                            r->in.credential,
                                            r->out.return_authenticator,
                                            &creds);
+       talloc_unlink(p->mem_ctx, lp_ctx);
        if (!NT_STATUS_IS_OK(status)) {
                return status;
        }
@@ -2415,36 +2617,24 @@ NTSTATUS _netr_ServerGetTrustInfo(struct pipes_struct *p,
                        *r->out.trust_info = trust_info;
                }
 
-               new_owf_enc = talloc_zero(p->mem_ctx, struct samr_Password);
-               old_owf_enc = talloc_zero(p->mem_ctx, struct samr_Password);
-               if (new_owf_enc == NULL || old_owf_enc == NULL) {
-                       return NT_STATUS_NO_MEMORY;
-               }
-
-/* TODO: which trustAuth shall we use if we have in/out trust or do they have to
- * be equal ? */
-               if (td->trust_direction & NETR_TRUST_FLAG_INBOUND) {
-                       trustAuth_blob = td->trust_auth_incoming;
-               } else if (td->trust_direction & NETR_TRUST_FLAG_OUTBOUND) {
-                       trustAuth_blob = td->trust_auth_outgoing;
+               if (td->trust_auth_incoming.data == NULL) {
+                       return NT_STATUS_INVALID_PARAMETER;
                }
 
-               session_key.data = creds->session_key;
-               session_key.length = sizeof(creds->session_key);
-               status = get_password_from_trustAuth(p->mem_ctx, &trustAuth_blob,
-                                                    &session_key,
-                                                    new_owf_enc, old_owf_enc);
+               status = get_password_from_trustAuth(p->mem_ctx,
+                                                    &td->trust_auth_incoming,
+                                                    creds,
+                                                    r->out.new_owf_password,
+                                                    r->out.old_owf_password);
 
                if (!NT_STATUS_IS_OK(status)) {
                        return status;
                }
 
-               r->out.new_owf_password = new_owf_enc;
-               r->out.old_owf_password = old_owf_enc;
        } else {
 /* TODO: look for machine password */
-               r->out.new_owf_password = NULL;
-               r->out.old_owf_password = NULL;
+               ZERO_STRUCTP(r->out.new_owf_password);
+               ZERO_STRUCTP(r->out.old_owf_password);
 
                return NT_STATUS_NOT_IMPLEMENTED;
        }
@@ -2458,7 +2648,7 @@ NTSTATUS _netr_ServerGetTrustInfo(struct pipes_struct *p,
 NTSTATUS _netr_Unused47(struct pipes_struct *p,
                        struct netr_Unused47 *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return NT_STATUS_NOT_IMPLEMENTED;
 }
 
@@ -2468,6 +2658,6 @@ NTSTATUS _netr_Unused47(struct pipes_struct *p,
 NTSTATUS _netr_DsrUpdateReadOnlyServerDnsRecords(struct pipes_struct *p,
                                                 struct netr_DsrUpdateReadOnlyServerDnsRecords *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return NT_STATUS_NOT_IMPLEMENTED;
 }