s4:netlogon RPC - Fix up a comment
[ira/wip.git] / source4 / rpc_server / netlogon / dcerpc_netlogon.c
index 1a45711c574cdeb12c7ccc6c333ad9914c41a901..1cdb172225613d94963e2f6cb05d61b4fe7f0e10 100644 (file)
@@ -129,7 +129,7 @@ static NTSTATUS dcesrv_netr_ServerAuthenticate3(struct dcesrv_call_state *dce_ca
        }
 
        sam_ctx = samdb_connect(mem_ctx, dce_call->event_ctx, dce_call->conn->dce_ctx->lp_ctx, 
-                               system_session(mem_ctx, dce_call->conn->dce_ctx->lp_ctx));
+                               system_session(dce_call->conn->dce_ctx->lp_ctx));
        if (sam_ctx == NULL) {
                return NT_STATUS_INVALID_SYSTEM_SERVICE;
        }
@@ -256,7 +256,7 @@ static NTSTATUS dcesrv_netr_ServerAuthenticate3(struct dcesrv_call_state *dce_ca
        }
 
        nt_status = schannel_store_session_key_ldb(schannel_ldb, mem_ctx, creds);
-       talloc_free(schannel_ldb);
+       talloc_unlink(mem_ctx, schannel_ldb);
 
        return nt_status;
 }
@@ -343,7 +343,7 @@ static NTSTATUS dcesrv_netr_creds_server_step_check(struct dcesrv_call_state *dc
                                                         schannel_in_use,
                                                         received_authenticator,
                                                         return_authenticator, creds_out);
-       talloc_free(ldb);
+       talloc_unlink(mem_ctx, ldb);
        return nt_status;
 }
 
@@ -366,7 +366,7 @@ static NTSTATUS dcesrv_netr_ServerPasswordSet(struct dcesrv_call_state *dce_call
                                                        &creds);
        NT_STATUS_NOT_OK_RETURN(nt_status);
 
-       sam_ctx = samdb_connect(mem_ctx, dce_call->event_ctx, dce_call->conn->dce_ctx->lp_ctx, system_session(mem_ctx, dce_call->conn->dce_ctx->lp_ctx));
+       sam_ctx = samdb_connect(mem_ctx, dce_call->event_ctx, dce_call->conn->dce_ctx->lp_ctx, system_session(dce_call->conn->dce_ctx->lp_ctx));
        if (sam_ctx == NULL) {
                return NT_STATUS_INVALID_SYSTEM_SERVICE;
        }
@@ -404,7 +404,7 @@ static NTSTATUS dcesrv_netr_ServerPasswordSet2(struct dcesrv_call_state *dce_cal
                                                        &creds);
        NT_STATUS_NOT_OK_RETURN(nt_status);
 
-       sam_ctx = samdb_connect(mem_ctx, dce_call->event_ctx, dce_call->conn->dce_ctx->lp_ctx, system_session(mem_ctx, dce_call->conn->dce_ctx->lp_ctx));
+       sam_ctx = samdb_connect(mem_ctx, dce_call->event_ctx, dce_call->conn->dce_ctx->lp_ctx, system_session(dce_call->conn->dce_ctx->lp_ctx));
        if (sam_ctx == NULL) {
                return NT_STATUS_INVALID_SYSTEM_SERVICE;
        }
@@ -643,7 +643,7 @@ static NTSTATUS dcesrv_netr_LogonSamLogon_base(struct dcesrv_call_state *dce_cal
                sam6 = talloc_zero(mem_ctx, struct netr_SamInfo6);
                NT_STATUS_HAVE_NO_MEMORY(sam6);
                sam6->base = *sam;
-               sam6->forest.string = lp_realm(dce_call->conn->dce_ctx->lp_ctx);
+               sam6->forest.string = lp_dnsdomain(dce_call->conn->dce_ctx->lp_ctx);
                sam6->principle.string = talloc_asprintf(mem_ctx, "%s@%s", 
                                                         sam->account_name.string, sam6->forest.string);
                NT_STATUS_HAVE_NO_MEMORY(sam6->principle.string);
@@ -1096,7 +1096,7 @@ static NTSTATUS fill_one_domain_info(TALLOC_CTX *mem_ctx,
 
        if (is_local) {
                info->domainname.string = lp_sam_name(lp_ctx);
-               info->dns_domainname.string = lp_realm(lp_ctx);
+               info->dns_domainname.string = lp_dnsdomain(lp_ctx);
                info->domain_guid = samdb_result_guid(res, "objectGUID");
                info->domain_sid = samdb_result_dom_sid(mem_ctx, res, "objectSid");
        } else {
@@ -1125,16 +1125,18 @@ static NTSTATUS dcesrv_netr_LogonGetDomainInfo(struct dcesrv_call_state *dce_cal
        struct netlogon_creds_CredentialState *creds;
        const char * const attrs[] = { "objectSid", "objectGUID", "flatName",
                "securityIdentifier", "trustPartner", NULL };
+       const char * const attrs2[] = { "dNSHostName",
+               "msDS-SupportedEncryptionTypes", NULL };
        const char *temp_str;
        const char *old_dns_hostname;
        struct ldb_context *sam_ctx;
-       struct ldb_message **res1, **res2, *new_msg;
+       struct ldb_message **res1, **res2, **res3, *new_msg;
        struct ldb_dn *workstation_dn;
        struct netr_DomainInformation *domain_info;
        struct netr_LsaPolicyInformation *lsa_policy_info;
        struct netr_OsVersionInfoEx *os_version;
        uint32_t default_supported_enc_types = 0xFFFFFFFF;
-       int ret1, ret2, i;
+       int ret1, ret2, ret3, i;
        NTSTATUS status;
 
        status = dcesrv_netr_creds_server_step_check(dce_call,
@@ -1150,7 +1152,7 @@ static NTSTATUS dcesrv_netr_LogonGetDomainInfo(struct dcesrv_call_state *dce_cal
 
        sam_ctx = samdb_connect(mem_ctx, dce_call->event_ctx,
                dce_call->conn->dce_ctx->lp_ctx,
-               system_session(mem_ctx, dce_call->conn->dce_ctx->lp_ctx));
+               system_session(dce_call->conn->dce_ctx->lp_ctx));
        if (sam_ctx == NULL) {
                return NT_STATUS_INVALID_SYSTEM_SERVICE;
        }
@@ -1175,11 +1177,16 @@ static NTSTATUS dcesrv_netr_LogonGetDomainInfo(struct dcesrv_call_state *dce_cal
                        dom_sid_string(mem_ctx, creds->sid));
                NT_STATUS_HAVE_NO_MEMORY(workstation_dn);
 
+               /* Lookup for attributes in workstation object */
+               ret1 = gendb_search_dn(sam_ctx, mem_ctx, workstation_dn,
+                       &res1, attrs2);
+               if (ret1 != 1) {
+                       return NT_STATUS_INTERNAL_DB_CORRUPTION;
+               }
+
                /* Gets the old DNS hostname */
-               old_dns_hostname = samdb_search_string(sam_ctx, mem_ctx,
-                                                       workstation_dn,
-                                                       "dNSHostName",
-                                                       NULL);
+               old_dns_hostname = samdb_result_string(res1[0], "dNSHostName",
+                       NULL);
 
                /* Gets host informations and put them in our directory */
                new_msg = ldb_msg_new(mem_ctx);
@@ -1273,15 +1280,15 @@ static NTSTATUS dcesrv_netr_LogonGetDomainInfo(struct dcesrv_call_state *dce_cal
                   primary domain is also a "trusted" domain, so we need to
                   put the primary domain into the lists of returned trusts as
                   well. */
-               ret1 = gendb_search_dn(sam_ctx, mem_ctx, samdb_base_dn(sam_ctx),
-                       &res1, attrs);
-               if (ret1 != 1) {
+               ret2 = gendb_search_dn(sam_ctx, mem_ctx, samdb_base_dn(sam_ctx),
+                       &res2, attrs);
+               if (ret2 != 1) {
                        return NT_STATUS_INTERNAL_DB_CORRUPTION;
                }
 
-               ret2 = gendb_search(sam_ctx, mem_ctx, NULL, &res2, attrs,
+               ret3 = gendb_search(sam_ctx, mem_ctx, NULL, &res3, attrs,
                        "(objectClass=trustedDomain)");
-               if (ret2 == -1) {
+               if (ret3 == -1) {
                        return NT_STATUS_INTERNAL_DB_CORRUPTION;
                }
 
@@ -1294,35 +1301,34 @@ static NTSTATUS dcesrv_netr_LogonGetDomainInfo(struct dcesrv_call_state *dce_cal
 
                status = fill_one_domain_info(mem_ctx,
                        dce_call->conn->dce_ctx->lp_ctx,
-                       sam_ctx, res1[0], &domain_info->primary_domain,
+                       sam_ctx, res2[0], &domain_info->primary_domain,
                        true, false);
                NT_STATUS_NOT_OK_RETURN(status);
 
-               domain_info->trusted_domain_count = ret2 + 1;
+               domain_info->trusted_domain_count = ret3 + 1;
                domain_info->trusted_domains = talloc_array(mem_ctx,
                        struct netr_OneDomainInfo,
                        domain_info->trusted_domain_count);
                NT_STATUS_HAVE_NO_MEMORY(domain_info->trusted_domains);
 
-               for (i=0;i<ret2;i++) {
+               for (i=0;i<ret3;i++) {
                        status = fill_one_domain_info(mem_ctx,
                                dce_call->conn->dce_ctx->lp_ctx,
-                               sam_ctx, res2[i],
+                               sam_ctx, res3[i],
                                &domain_info->trusted_domains[i],
                                false, true);
                        NT_STATUS_NOT_OK_RETURN(status);
                }
 
                status = fill_one_domain_info(mem_ctx,
-                       dce_call->conn->dce_ctx->lp_ctx, sam_ctx, res1[0],
+                       dce_call->conn->dce_ctx->lp_ctx, sam_ctx, res2[0],
                        &domain_info->trusted_domains[i], true, true);
                NT_STATUS_NOT_OK_RETURN(status);
 
                /* Sets the supported encryption types */
-               domain_info->supported_enc_types = samdb_search_uint(
-                       sam_ctx, mem_ctx,
-                       default_supported_enc_types, workstation_dn,
-                       "msDS-SupportedEncryptionTypes", NULL);
+               domain_info->supported_enc_types = samdb_result_uint(res1[0],
+                       "msDS-SupportedEncryptionTypes",
+                       default_supported_enc_types);
 
                /* Other host domain informations */
 
@@ -1407,10 +1413,11 @@ static WERROR dcesrv_netr_DsRGetDCNameEx2(struct dcesrv_call_state *dce_call, TA
                return WERR_DS_UNAVAILABLE;
        }
 
-       /* Win7-beta will send the domain name in the form the user typed, so we have to cope
-          with both the short and long form here */
-       if (r->in.domain_name != NULL && !lp_is_my_domain_or_realm(dce_call->conn->dce_ctx->lp_ctx, 
-                                                               r->in.domain_name)) {
+       /* Windows 7 sends the domain name in the form the user typed, so we
+        * have to cope  with both the short and long form here */
+       if (r->in.domain_name != NULL &&
+                       !lp_is_my_domain_or_realm(dce_call->conn->dce_ctx->lp_ctx,
+                                                 r->in.domain_name)) {
                return WERR_NO_SUCH_DOMAIN;
        }
 
@@ -1432,15 +1439,15 @@ static WERROR dcesrv_netr_DsRGetDCNameEx2(struct dcesrv_call_state *dce_call, TA
         */
        info->dc_unc                    = talloc_asprintf(mem_ctx, "\\\\%s.%s",
                                                          lp_netbios_name(dce_call->conn->dce_ctx->lp_ctx), 
-                                                         lp_realm(dce_call->conn->dce_ctx->lp_ctx));
+                                                         lp_dnsdomain(dce_call->conn->dce_ctx->lp_ctx));
        W_ERROR_HAVE_NO_MEMORY(info->dc_unc);
        info->dc_address                = talloc_strdup(mem_ctx, "\\\\0.0.0.0");
        W_ERROR_HAVE_NO_MEMORY(info->dc_address);
        info->dc_address_type           = DS_ADDRESS_TYPE_INET;
        info->domain_guid               = samdb_result_guid(res[0], "objectGUID");
-       info->domain_name               = lp_realm(dce_call->conn->dce_ctx->lp_ctx);
-       info->forest_name               = lp_realm(dce_call->conn->dce_ctx->lp_ctx);
-       info->dc_flags                  = DS_DNS_FOREST |
+       info->domain_name               = lp_dnsdomain(dce_call->conn->dce_ctx->lp_ctx);
+       info->forest_name               = lp_dnsdomain(dce_call->conn->dce_ctx->lp_ctx);
+       info->dc_flags                  = DS_DNS_FOREST_ROOT |
                                          DS_DNS_DOMAIN |
                                          DS_DNS_CONTROLLER |
                                          DS_SERVER_WRITABLE |
@@ -1451,8 +1458,9 @@ static WERROR dcesrv_netr_DsRGetDCNameEx2(struct dcesrv_call_state *dce_call, TA
                                          DS_SERVER_LDAP |
                                          DS_SERVER_GC |
                                          DS_SERVER_PDC;
-       info->dc_site_name      = talloc_strdup(mem_ctx, "Default-First-Site-Name");
+       info->dc_site_name      = samdb_server_site_name(sam_ctx, mem_ctx);
        W_ERROR_HAVE_NO_MEMORY(info->dc_site_name);
+       /* FIXME: Hardcoded site name */
        info->client_site_name  = talloc_strdup(mem_ctx, "Default-First-Site-Name");
        W_ERROR_HAVE_NO_MEMORY(info->client_site_name);
 
@@ -1555,6 +1563,7 @@ static WERROR dcesrv_netr_DsRAddressToSitenamesExW(struct dcesrv_call_state *dce
        W_ERROR_HAVE_NO_MEMORY(ctr->subnetname);
 
        for (i=0; i<ctr->count; i++) {
+               /* FIXME: Hardcoded site name */
                ctr->sitename[i].string   = "Default-First-Site-Name";
                ctr->subnetname[i].string = NULL;
        }
@@ -1614,7 +1623,7 @@ static WERROR dcesrv_netr_DsrEnumerateDomainTrusts(struct dcesrv_call_state *dce
        /* TODO: add filtering by trust_flags, and correct trust_type
           and attributes */
        trusts->array[0].netbios_name = lp_sam_name(dce_call->conn->dce_ctx->lp_ctx);
-       trusts->array[0].dns_name     = lp_realm(dce_call->conn->dce_ctx->lp_ctx);
+       trusts->array[0].dns_name     = lp_dnsdomain(dce_call->conn->dce_ctx->lp_ctx);
        trusts->array[0].trust_flags =
                NETR_TRUST_FLAG_TREEROOT | 
                NETR_TRUST_FLAG_IN_FOREST |