s3:rpc_server: Remove unused arcfour.h from netlogon
[samba.git] / source3 / rpc_server / netlogon / srv_netlog_nt.c
index f600f7403eba1aefa0a80800b5bacc99863c5f25..a846a728f246ef3f513c1cedffd90cf6ef5f270f 100644 (file)
 #include "../librpc/gen_ndr/ndr_lsa_c.h"
 #include "rpc_client/cli_lsarpc.h"
 #include "rpc_client/init_lsa.h"
+#include "rpc_client/init_samr.h"
 #include "rpc_server/rpc_ncacn_np.h"
 #include "../libcli/security/security.h"
 #include "../libcli/security/dom_sid.h"
 #include "librpc/gen_ndr/ndr_drsblobs.h"
-#include "lib/crypto/arcfour.h"
 #include "lib/crypto/md4.h"
 #include "nsswitch/libwbclient/wbclient.h"
 #include "../libcli/registry/util_reg.h"
@@ -46,6 +46,7 @@
 #include "messages.h"
 #include "../lib/tsocket/tsocket.h"
 #include "lib/param/param.h"
+#include "libsmb/dsgetdcname.h"
 
 extern userdom_struct current_user_info;
 
@@ -72,7 +73,20 @@ WERROR _netr_LogonControl(struct pipes_struct *p,
        case 2:
                return WERR_NOT_SUPPORTED;
        default:
-               return WERR_UNKNOWN_LEVEL;
+               return WERR_INVALID_LEVEL;
+       }
+
+       switch (r->in.function_code) {
+       case NETLOGON_CONTROL_QUERY:
+       case NETLOGON_CONTROL_REPLICATE:
+       case NETLOGON_CONTROL_SYNCHRONIZE:
+       case NETLOGON_CONTROL_PDC_REPLICATE:
+       case NETLOGON_CONTROL_BREAKPOINT:
+       case NETLOGON_CONTROL_BACKUP_CHANGE_LOG:
+       case NETLOGON_CONTROL_TRUNCATE_LOG:
+               break;
+       default:
+               return WERR_NOT_SUPPORTED;
        }
 
        l.in.logon_server       = r->in.logon_server;
@@ -184,7 +198,6 @@ WERROR _netr_LogonControl2Ex(struct pipes_struct *p,
        struct netr_NETLOGON_INFO_3 *info3;
        struct netr_NETLOGON_INFO_4 *info4;
        const char *fn;
-       uint32_t acct_ctrl;
        NTSTATUS status;
        struct netr_DsRGetDCNameInfo *dc_info;
 
@@ -199,30 +212,44 @@ WERROR _netr_LogonControl2Ex(struct pipes_struct *p,
                fn = "_netr_LogonControl2Ex";
                break;
        default:
-               return WERR_INVALID_PARAM;
+               return WERR_INVALID_PARAMETER;
        }
 
-       acct_ctrl = p->session_info->info->acct_flags;
+       switch (r->in.level) {
+       case 1:
+       case 2:
+       case 3:
+       case 4:
+               break;
+       default:
+               return WERR_INVALID_LEVEL;
+       }
 
        switch (r->in.function_code) {
-       case NETLOGON_CONTROL_TC_VERIFY:
-       case NETLOGON_CONTROL_CHANGE_PASSWORD:
-       case NETLOGON_CONTROL_REDISCOVER:
+       case NETLOGON_CONTROL_QUERY:
+               break;
+       default:
                if ((geteuid() != sec_initial_uid()) &&
                    !nt_token_check_domain_rid(p->session_info->security_token, DOMAIN_RID_ADMINS) &&
-                   !nt_token_check_sid(&global_sid_Builtin_Administrators, p->session_info->security_token) &&
-                   !(acct_ctrl & (ACB_WSTRUST | ACB_SVRTRUST))) {
+                   !nt_token_check_sid(&global_sid_Builtin_Administrators, p->session_info->security_token))
+               {
                        return WERR_ACCESS_DENIED;
                }
                break;
-       default:
-               break;
        }
 
        tc_status = WERR_NO_SUCH_DOMAIN;
 
        switch (r->in.function_code) {
        case NETLOGON_CONTROL_QUERY:
+               switch (r->in.level) {
+               case 1:
+               case 3:
+                       break;
+               default:
+                       return WERR_INVALID_PARAMETER;
+               }
+
                tc_status = WERR_OK;
                break;
        case NETLOGON_CONTROL_REPLICATE:
@@ -230,26 +257,12 @@ WERROR _netr_LogonControl2Ex(struct pipes_struct *p,
        case NETLOGON_CONTROL_PDC_REPLICATE:
        case NETLOGON_CONTROL_BACKUP_CHANGE_LOG:
        case NETLOGON_CONTROL_BREAKPOINT:
-               if (acct_ctrl & ACB_NORMAL) {
-                       return WERR_NOT_SUPPORTED;
-               } else if (acct_ctrl & (ACB_WSTRUST | ACB_SVRTRUST)) {
-                       return WERR_ACCESS_DENIED;
-               } else {
-                       return WERR_ACCESS_DENIED;
-               }
        case NETLOGON_CONTROL_TRUNCATE_LOG:
-               if (acct_ctrl & ACB_NORMAL) {
-                       break;
-               } else if (acct_ctrl & (ACB_WSTRUST | ACB_SVRTRUST)) {
-                       return WERR_ACCESS_DENIED;
-               } else {
-                       return WERR_ACCESS_DENIED;
-               }
-
        case NETLOGON_CONTROL_TRANSPORT_NOTIFY:
        case NETLOGON_CONTROL_FORCE_DNS_REG:
        case NETLOGON_CONTROL_QUERY_DNS_REG:
                return WERR_NOT_SUPPORTED;
+
        case NETLOGON_CONTROL_FIND_USER:
                if (!r->in.data || !r->in.data->user) {
                        return WERR_NOT_SUPPORTED;
@@ -287,7 +300,7 @@ WERROR _netr_LogonControl2Ex(struct pipes_struct *p,
 
                dc_name = talloc_asprintf(p->mem_ctx, "\\\\%s", dc_name2);
                if (!dc_name) {
-                       return WERR_NOMEM;
+                       return WERR_NOT_ENOUGH_MEMORY;
                }
 
                tc_status = WERR_OK;
@@ -315,7 +328,7 @@ WERROR _netr_LogonControl2Ex(struct pipes_struct *p,
 
                dc_name = talloc_asprintf(p->mem_ctx, "\\\\%s", dc_info->dc_unc);
                if (!dc_name) {
-                       return WERR_NOMEM;
+                       return WERR_NOT_ENOUGH_MEMORY;
                }
 
                tc_status = WERR_OK;
@@ -336,7 +349,7 @@ WERROR _netr_LogonControl2Ex(struct pipes_struct *p,
                /* no idea what this should be */
                DEBUG(0,("%s: unimplemented function level [%d]\n",
                        fn, r->in.function_code));
-               return WERR_UNKNOWN_LEVEL;
+               return WERR_NOT_SUPPORTED;
        }
 
        /* prepare the response */
@@ -381,7 +394,7 @@ WERROR _netr_LogonControl2Ex(struct pipes_struct *p,
                r->out.query->info4 = info4;
                break;
        default:
-               return WERR_UNKNOWN_LEVEL;
+               return WERR_INVALID_LEVEL;
        }
 
        return WERR_OK;
@@ -397,7 +410,7 @@ NTSTATUS _netr_NetrEnumerateTrustedDomains(struct pipes_struct *p,
        NTSTATUS status;
        NTSTATUS result = NT_STATUS_OK;
        DATA_BLOB blob;
-       int num_domains = 0;
+       size_t num_domains = 0;
        const char **trusted_domains = NULL;
        struct lsa_DomainList domain_list;
        struct dcerpc_binding_handle *h = NULL;
@@ -411,6 +424,7 @@ NTSTATUS _netr_NetrEnumerateTrustedDomains(struct pipes_struct *p,
        status = rpcint_binding_handle(p->mem_ctx,
                                       &ndr_table_lsarpc,
                                       p->remote_address,
+                                      p->local_address,
                                       p->session_info,
                                       p->msg_ctx,
                                       &h);
@@ -691,6 +705,7 @@ static NTSTATUS get_md4pw(struct samr_Password *md4pw, const char *mach_acct,
        status = rpcint_binding_handle(mem_ctx,
                                       &ndr_table_samr,
                                       local,
+                                      NULL,
                                       session_info,
                                       msg_ctx,
                                       &h);
@@ -1100,6 +1115,10 @@ static NTSTATUS netr_creds_server_step_check(struct pipes_struct *p,
        bool schannel_global_required = (lp_server_schannel() == true) ? true:false;
        struct loadparm_context *lp_ctx;
 
+       if (creds_out != NULL) {
+               *creds_out = NULL;
+       }
+
        if (schannel_global_required) {
                status = schannel_check_required(&p->auth,
                                                 computer_name,
@@ -1122,14 +1141,27 @@ static NTSTATUS netr_creds_server_step_check(struct pipes_struct *p,
        return status;
 }
 
+
 /*************************************************************************
  *************************************************************************/
 
+struct _samr_Credentials_t {
+       enum {
+               CRED_TYPE_NT_HASH,
+               CRED_TYPE_PLAIN_TEXT,
+       } cred_type;
+       union {
+               struct samr_Password *nt_hash;
+               const char *password;
+       } creds;
+};
+
+
 static NTSTATUS netr_set_machine_account_password(TALLOC_CTX *mem_ctx,
                                                  struct auth_session_info *session_info,
                                                  struct messaging_context *msg_ctx,
                                                  const char *account_name,
-                                                 struct samr_Password *nt_hash)
+                                                 struct _samr_Credentials_t *cr)
 {
        NTSTATUS status;
        NTSTATUS result = NT_STATUS_OK;
@@ -1139,9 +1171,11 @@ static NTSTATUS netr_set_machine_account_password(TALLOC_CTX *mem_ctx,
        uint32_t acct_ctrl;
        union samr_UserInfo *info;
        struct samr_UserInfo18 info18;
+       struct samr_UserInfo26 info26;
        DATA_BLOB in,out;
        int rc;
        DATA_BLOB session_key;
+       enum samr_UserInfoLevel infolevel;
 
        ZERO_STRUCT(user_handle);
 
@@ -1165,6 +1199,7 @@ static NTSTATUS netr_set_machine_account_password(TALLOC_CTX *mem_ctx,
        status = rpcint_binding_handle(mem_ctx,
                                       &ndr_table_samr,
                                       local,
+                                      NULL,
                                       session_info,
                                       msg_ctx,
                                       &h);
@@ -1213,22 +1248,44 @@ static NTSTATUS netr_set_machine_account_password(TALLOC_CTX *mem_ctx,
                goto out;
        }
 
-       ZERO_STRUCT(info18);
+       switch(cr->cred_type) {
+               case CRED_TYPE_NT_HASH:
+                       ZERO_STRUCT(info18);
 
-       in = data_blob_const(nt_hash->hash, 16);
-       out = data_blob_talloc_zero(mem_ctx, 16);
-       sess_crypt_blob(&out, &in, &session_key, true);
-       memcpy(info18.nt_pwd.hash, out.data, out.length);
+                       infolevel = UserInternal1Information;
 
-       info18.nt_pwd_active = true;
+                       in = data_blob_const(cr->creds.nt_hash, 16);
+                       out = data_blob_talloc_zero(mem_ctx, 16);
+                       sess_crypt_blob(&out, &in, &session_key, true);
+                       memcpy(info18.nt_pwd.hash, out.data, out.length);
 
-       info->info18 = info18;
+                       info18.nt_pwd_active = true;
+
+                       info->info18 = info18;
+               break;
+               case CRED_TYPE_PLAIN_TEXT:
+                       ZERO_STRUCT(info26);
+
+                       infolevel = UserInternal5InformationNew;
+
+                       init_samr_CryptPasswordEx(cr->creds.password,
+                                                 &session_key,
+                                                 &info26.password);
+
+                       info26.password_expired = PASS_DONT_CHANGE_AT_NEXT_LOGON;
+                       info->info26 = info26;
+               break;
+               default:
+                       status = NT_STATUS_INTERNAL_ERROR;
+                       goto out;
+               break;
+       }
 
        become_root();
        status = dcerpc_samr_SetUserInfo2(h,
                                          mem_ctx,
                                          &user_handle,
-                                         UserInternal1Information,
+                                         infolevel,
                                          info,
                                          &result);
        unbecome_root();
@@ -1257,7 +1314,8 @@ NTSTATUS _netr_ServerPasswordSet(struct pipes_struct *p,
 {
        NTSTATUS status = NT_STATUS_OK;
        int i;
-       struct netlogon_creds_CredentialState *creds;
+       struct netlogon_creds_CredentialState *creds = NULL;
+       struct _samr_Credentials_t cr = { CRED_TYPE_NT_HASH, {0}};
 
        DEBUG(5,("_netr_ServerPasswordSet: %d\n", __LINE__));
 
@@ -1270,9 +1328,14 @@ NTSTATUS _netr_ServerPasswordSet(struct pipes_struct *p,
        unbecome_root();
 
        if (!NT_STATUS_IS_OK(status)) {
+               const char *computer_name = "<unknown>";
+
+               if (creds != NULL && creds->computer_name != NULL) {
+                       computer_name = creds->computer_name;
+               }
                DEBUG(2,("_netr_ServerPasswordSet: 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;
        }
@@ -1287,11 +1350,12 @@ NTSTATUS _netr_ServerPasswordSet(struct pipes_struct *p,
                DEBUG(100,("%02X ", r->in.new_password->hash[i]));
        DEBUG(100,("\n"));
 
+       cr.creds.nt_hash = r->in.new_password;
        status = netr_set_machine_account_password(p->mem_ctx,
                                                   p->session_info,
                                                   p->msg_ctx,
                                                   creds->account_name,
-                                                  r->in.new_password);
+                                                  &cr);
        return status;
 }
 
@@ -1306,7 +1370,7 @@ NTSTATUS _netr_ServerPasswordSet2(struct pipes_struct *p,
        struct netlogon_creds_CredentialState *creds = NULL;
        DATA_BLOB plaintext;
        struct samr_CryptPassword password_buf;
-       struct samr_Password nt_hash;
+       struct _samr_Credentials_t cr = { CRED_TYPE_PLAIN_TEXT, {0}};
 
        become_root();
        status = netr_creds_server_step_check(p, p->mem_ctx,
@@ -1329,6 +1393,10 @@ NTSTATUS _netr_ServerPasswordSet2(struct pipes_struct *p,
                return status;
        }
 
+       DEBUG(3,("_netr_ServerPasswordSet2: Server Password Seti2 by remote "
+                "machine:[%s] on account [%s]\n",
+                r->in.computer_name, creds->computer_name));
+
        memcpy(password_buf.data, r->in.new_password->data, 512);
        SIVAL(password_buf.data, 512, r->in.new_password->length);
 
@@ -1338,18 +1406,23 @@ NTSTATUS _netr_ServerPasswordSet2(struct pipes_struct *p,
                netlogon_creds_arcfour_crypt(creds, password_buf.data, 516);
        }
 
-       if (!extract_pw_from_buffer(p->mem_ctx, password_buf.data, &plaintext)) {
+       if (!decode_pw_buffer(p->mem_ctx,
+                             password_buf.data,
+                             (char**) &plaintext.data,
+                             &plaintext.length,
+                             CH_UTF16)) {
+               DEBUG(2,("_netr_ServerPasswordSet2: unable to extract password "
+                        "from a buffer. Rejecting auth request as a wrong password\n"));
                TALLOC_FREE(creds);
                return NT_STATUS_WRONG_PASSWORD;
        }
 
-       mdfour(nt_hash.hash, plaintext.data, plaintext.length);
-
+       cr.creds.password = (const char*) plaintext.data;
        status = netr_set_machine_account_password(p->mem_ctx,
                                                   p->session_info,
                                                   p->msg_ctx,
                                                   creds->account_name,
-                                                  &nt_hash);
+                                                  &cr);
        TALLOC_FREE(creds);
        return status;
 }
@@ -1489,7 +1562,7 @@ static NTSTATUS _netr_LogonSamLogon_base(struct pipes_struct *p,
                        return NT_STATUS_INTERNAL_ERROR;
        }
 
-       *r->out.authoritative = true; /* authoritative response */
+       *r->out.authoritative = 1; /* authoritative response */
 
        switch (r->in.validation_level) {
        case 2:
@@ -1559,16 +1632,23 @@ static NTSTATUS _netr_LogonSamLogon_base(struct pipes_struct *p,
                                              r->in.logon_level,
                                              logon);
 
+       status = make_auth3_context_for_netlogon(talloc_tos(), &auth_context);
+       if (!NT_STATUS_IS_OK(status)) {
+               return status;
+       }
+
        switch (r->in.logon_level) {
        case NetlogonNetworkInformation:
        case NetlogonNetworkTransitiveInformation:
        {
                const char *wksname = nt_workstation;
+               const char *workgroup = lp_workgroup();
+               bool ok;
 
-               status = make_auth_context_fixed(talloc_tos(), &auth_context,
-                                                logon->network->challenge);
-               if (!NT_STATUS_IS_OK(status)) {
-                       return status;
+               ok = auth3_context_set_challenge(
+                       auth_context, logon->network->challenge, "fixed");
+               if (!ok) {
+                       return NT_STATUS_NO_MEMORY;
                }
 
                /* For a network logon, the workstation name comes in with two
@@ -1578,10 +1658,12 @@ static NTSTATUS _netr_LogonSamLogon_base(struct pipes_struct *p,
                if (*wksname == '\\') wksname++;
 
                /* Standard challenge/response authentication */
-               if (!make_user_info_netlogon_network(&user_info,
+               if (!make_user_info_netlogon_network(talloc_tos(),
+                                                    &user_info,
                                                     nt_username, nt_domain,
                                                     wksname,
                                                     p->remote_address,
+                                                    p->local_address,
                                                     logon->network->identity_info.parameter_control,
                                                     logon->network->lm.data,
                                                     logon->network->lm.length,
@@ -1589,6 +1671,14 @@ static NTSTATUS _netr_LogonSamLogon_base(struct pipes_struct *p,
                                                     logon->network->nt.length)) {
                        status = NT_STATUS_NO_MEMORY;
                }
+
+               if (NT_STATUS_IS_OK(status)) {
+                       status = NTLMv2_RESPONSE_verify_netlogon_creds(
+                                               user_info->client.account_name,
+                                               user_info->client.domain_name,
+                                               user_info->password.response.nt,
+                                               creds, workgroup);
+               }
                break;
        }
        case NetlogonInteractiveInformation:
@@ -1620,18 +1710,15 @@ static NTSTATUS _netr_LogonSamLogon_base(struct pipes_struct *p,
                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_get_ntlm_challenge(auth_context, chal);
 
-               if (!make_user_info_netlogon_interactive(&user_info,
+               if (!make_user_info_netlogon_interactive(talloc_tos(),
+                                                        &user_info,
                                                         nt_username, nt_domain,
                                                         nt_workstation,
                                                         p->remote_address,
+                                                        p->local_address,
                                                         logon->password->identity_info.parameter_control,
                                                         chal,
                                                         logon->password->lmpassword.hash,
@@ -1649,11 +1736,12 @@ static NTSTATUS _netr_LogonSamLogon_base(struct pipes_struct *p,
                status = auth_check_ntlm_password(p->mem_ctx,
                                                  auth_context,
                                                  user_info,
-                                                 &server_info);
+                                                 &server_info,
+                                                 r->out.authoritative);
        }
 
        TALLOC_FREE(auth_context);
-       free_user_info(&user_info);
+       TALLOC_FREE(user_info);
 
        DEBUG(5,("%s: check_password returned status %s\n",
                  fn, nt_errstr(status)));
@@ -1661,15 +1749,6 @@ static NTSTATUS _netr_LogonSamLogon_base(struct pipes_struct *p,
        /* Check account and password */
 
        if (!NT_STATUS_IS_OK(status)) {
-               /* If we don't know what this domain is, we need to
-                  indicate that we are not authoritative.  This
-                  allows the client to decide if it needs to try
-                  a local user.  Fix by jpjanosi@us.ibm.com, #2976 */
-                if ( NT_STATUS_EQUAL(status, NT_STATUS_NO_SUCH_USER)
-                    && !strequal(nt_domain, get_global_sam_name())
-                    && !is_trusted_domain(nt_domain) )
-                       *r->out.authoritative = false; /* We are not authoritative */
-
                TALLOC_FREE(server_info);
                return status;
        }
@@ -1696,6 +1775,14 @@ static NTSTATUS _netr_LogonSamLogon_base(struct pipes_struct *p,
                                                r->out.validation->sam3);
                break;
        case 6:
+               /* Only allow this if the pipe is protected. */
+               if (p->auth.auth_level < DCERPC_AUTH_LEVEL_PRIVACY) {
+                       DEBUG(0,("netr_Validation6: client %s not using privacy for netlogon\n",
+                               get_remote_machine_name()));
+                       status = NT_STATUS_INVALID_PARAMETER;
+                       break;
+               }
+
                status = serverinfo_to_SamInfo6(server_info,
                                                r->out.validation->sam6);
                break;
@@ -1948,7 +2035,7 @@ static bool wb_getdcname(TALLOC_CTX *mem_ctx,
        *dcname = talloc_strdup(mem_ctx, dc_info->dc_name);
        wbcFreeMemory(dc_info);
        if (!*dcname) {
-               *werr = WERR_NOMEM;
+               *werr = WERR_NOT_ENOUGH_MEMORY;
                return false;
        }
 
@@ -1997,7 +2084,7 @@ WERROR _netr_GetDcName(struct pipes_struct *p,
        *r->out.dcname = talloc_strdup(p->mem_ctx, info->dc_unc);
        talloc_free(info);
        if (!*r->out.dcname) {
-               return WERR_NOMEM;
+               return WERR_NOT_ENOUGH_MEMORY;
        }
 
        return WERR_OK;
@@ -2042,7 +2129,7 @@ WERROR _netr_GetAnyDCName(struct pipes_struct *p,
        *r->out.dcname = talloc_strdup(p->mem_ctx, info->dc_unc);
        talloc_free(info);
        if (!*r->out.dcname) {
-               return WERR_NOMEM;
+               return WERR_NOT_ENOUGH_MEMORY;
        }
 
        return WERR_OK;
@@ -2180,21 +2267,21 @@ NTSTATUS _netr_LogonGetDomainInfo(struct pipes_struct *p,
 /****************************************************************
 ****************************************************************/
 
-WERROR _netr_ServerPasswordGet(struct pipes_struct *p,
-                              struct netr_ServerPasswordGet *r)
+NTSTATUS _netr_ServerPasswordGet(struct pipes_struct *p,
+                                struct netr_ServerPasswordGet *r)
 {
        p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
-       return WERR_NOT_SUPPORTED;
+       return NT_STATUS_NOT_SUPPORTED;
 }
 
 /****************************************************************
 ****************************************************************/
 
-WERROR _netr_NETRLOGONSENDTOSAM(struct pipes_struct *p,
-                               struct netr_NETRLOGONSENDTOSAM *r)
+NTSTATUS _netr_NetrLogonSendToSam(struct pipes_struct *p,
+                               struct netr_NetrLogonSendToSam *r)
 {
        p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
-       return WERR_NOT_SUPPORTED;
+       return NT_STATUS_NOT_IMPLEMENTED;
 }
 
 /****************************************************************
@@ -2406,19 +2493,19 @@ WERROR _netr_DsRGetForestTrustInformation(struct pipes_struct *p,
                info_ptr = talloc(p->mem_ctx, struct lsa_ForestTrustInformation *);
                if (info_ptr == NULL) {
                        p->fault_state = DCERPC_FAULT_CANT_PERFORM;
-                       return WERR_NOMEM;
+                       return WERR_NOT_ENOUGH_MEMORY;
                }
                info = talloc_zero(info_ptr, struct lsa_ForestTrustInformation);
                if (info == NULL) {
                        p->fault_state = DCERPC_FAULT_CANT_PERFORM;
-                       return WERR_NOMEM;
+                       return WERR_NOT_ENOUGH_MEMORY;
                }
 
                /* 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;
+                       return WERR_NOT_ENOUGH_MEMORY;
                }
 
                *info_ptr = info;
@@ -2445,22 +2532,16 @@ 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 */
 
-       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);
+       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;
        }
@@ -2547,22 +2628,16 @@ NTSTATUS _netr_ServerGetTrustInfo(struct pipes_struct *p,
        bool trusted;
        struct netr_TrustInfo *trust_info;
        struct pdb_trusted_domain *td;
-       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_ctx,
-                                           r->in.computer_name,
-                                           r->in.credential,
-                                           r->out.return_authenticator,
-                                           &creds);
-       talloc_unlink(p->mem_ctx, lp_ctx);
+       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;
        }