Let dsgetdcname() return a struct netr_DsRGetDCNameInfo.
[gd/samba/.git] / source / libnet / libnet_join.c
index 2f8d3e3085f3b2c628156287ea0a2de0e0f39ed3..623ca39f715b1a470123176f3047ad1b1f783d66 100644 (file)
 #define LIBNET_UNJOIN_OUT_DUMP_CTX(ctx, r) \
        LIBNET_UNJOIN_DUMP_CTX(ctx, r, NDR_OUT)
 
-static void init_lsa_String(struct lsa_String *name, const char *s)
-{
-       name->string = s;
-}
+#define W_ERROR_NOT_OK_GOTO_DONE(x) do { \
+       if (!W_ERROR_IS_OK(x)) {\
+               goto done;\
+       }\
+} while (0)
 
 /****************************************************************
 ****************************************************************/
@@ -151,9 +152,24 @@ static ADS_STATUS libnet_join_connect_ads(TALLOC_CTX *mem_ctx,
                libnet_join_set_error_string(mem_ctx, r,
                        "failed to connect to AD: %s",
                        ads_errstr(status));
+               return status;
        }
 
-       return status;
+       if (!r->out.netbios_domain_name) {
+               r->out.netbios_domain_name = talloc_strdup(mem_ctx,
+                                                          r->in.ads->server.workgroup);
+               ADS_ERROR_HAVE_NO_MEMORY(r->out.netbios_domain_name);
+       }
+
+       if (!r->out.dns_domain_name) {
+               r->out.dns_domain_name = talloc_strdup(mem_ctx,
+                                                      r->in.ads->config.realm);
+               ADS_ERROR_HAVE_NO_MEMORY(r->out.dns_domain_name);
+       }
+
+       r->out.domain_is_ad = true;
+
+       return ADS_SUCCESS;
 }
 
 /****************************************************************
@@ -295,13 +311,6 @@ static ADS_STATUS libnet_join_set_machine_spn(TALLOC_CTX *mem_ctx,
        const char *spn_array[3] = {NULL, NULL, NULL};
        char *spn = NULL;
 
-       if (!r->in.ads) {
-               status = libnet_join_connect_ads(mem_ctx, r);
-               if (!ADS_ERR_OK(status)) {
-                       return status;
-               }
-       }
-
        status = libnet_join_find_machine_acct(mem_ctx, r);
        if (!ADS_ERR_OK(status)) {
                return status;
@@ -357,13 +366,6 @@ static ADS_STATUS libnet_join_set_machine_upn(TALLOC_CTX *mem_ctx,
                return ADS_SUCCESS;
        }
 
-       if (!r->in.ads) {
-               status = libnet_join_connect_ads(mem_ctx, r);
-               if (!ADS_ERR_OK(status)) {
-                       return status;
-               }
-       }
-
        status = libnet_join_find_machine_acct(mem_ctx, r);
        if (!ADS_ERR_OK(status)) {
                return status;
@@ -407,13 +409,6 @@ static ADS_STATUS libnet_join_set_os_attributes(TALLOC_CTX *mem_ctx,
                return ADS_SUCCESS;
        }
 
-       if (!r->in.ads) {
-               status = libnet_join_connect_ads(mem_ctx, r);
-               if (!ADS_ERR_OK(status)) {
-                       return status;
-               }
-       }
-
        status = libnet_join_find_machine_acct(mem_ctx, r);
        if (!ADS_ERR_OK(status)) {
                return status;
@@ -524,6 +519,13 @@ static ADS_STATUS libnet_join_post_processing_ads(TALLOC_CTX *mem_ctx,
 {
        ADS_STATUS status;
 
+       if (!r->in.ads) {
+               status = libnet_join_connect_ads(mem_ctx, r);
+               if (!ADS_ERR_OK(status)) {
+                       return status;
+               }
+       }
+
        status = libnet_join_set_machine_spn(mem_ctx, r);
        if (!ADS_ERR_OK(status)) {
                libnet_join_set_error_string(mem_ctx, r,
@@ -595,22 +597,18 @@ static NTSTATUS libnet_join_joindomain_rpc(TALLOC_CTX *mem_ctx,
        POLICY_HND sam_pol, domain_pol, user_pol, lsa_pol;
        NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
        char *acct_name;
-       const char *const_acct_name;
        struct lsa_String lsa_acct_name;
        uint32 user_rid;
-       uint32 num_rids, *name_types, *user_rids;
-       uint32 flags = 0x3e8;
        uint32 acb_info = ACB_WSTRUST;
-       uint32 fields_present;
        uchar pwbuf[532];
-       SAM_USERINFO_CTR ctr;
-       SAM_USER_INFO_25 p25;
-       const int infolevel = 25;
        struct MD5Context md5ctx;
        uchar md5buffer[16];
        DATA_BLOB digested_session_key;
        uchar md4_trust_password[16];
        union lsa_PolicyInformation *info = NULL;
+       struct samr_Ids user_rids;
+       struct samr_Ids name_types;
+       union samr_UserInfo user_info;
 
        if (!r->in.machine_password) {
                r->in.machine_password = talloc_strdup(mem_ctx, generate_random_str(DEFAULT_TRUST_ACCOUNT_PASSWORD_LENGTH));
@@ -654,13 +652,16 @@ static NTSTATUS libnet_join_joindomain_rpc(TALLOC_CTX *mem_ctx,
        }
 
        if (!NT_STATUS_IS_OK(status)) {
-               status = rpccli_lsa_query_info_policy(pipe_hnd, mem_ctx, &lsa_pol,
-                                                     5,
-                                                     &r->out.netbios_domain_name,
-                                                     &r->out.domain_sid);
+               status = rpccli_lsa_QueryInfoPolicy(pipe_hnd, mem_ctx,
+                                                   &lsa_pol,
+                                                   LSA_POLICY_INFO_ACCOUNT_DOMAIN,
+                                                   &info);
                if (!NT_STATUS_IS_OK(status)) {
                        goto done;
                }
+
+               r->out.netbios_domain_name = info->account_domain.name.string;
+               r->out.domain_sid = info->account_domain.sid;
        }
 
        rpccli_lsa_Close(pipe_hnd, mem_ctx, &lsa_pol);
@@ -690,7 +691,6 @@ static NTSTATUS libnet_join_joindomain_rpc(TALLOC_CTX *mem_ctx,
 
        acct_name = talloc_asprintf(mem_ctx, "%s$", r->in.machine_name);
        strlower_m(acct_name);
-       const_acct_name = acct_name;
 
        init_lsa_String(&lsa_acct_name, acct_name);
 
@@ -723,20 +723,22 @@ static NTSTATUS libnet_join_joindomain_rpc(TALLOC_CTX *mem_ctx,
                }
        }
 
-       status = rpccli_samr_lookup_names(pipe_hnd, mem_ctx,
-                                         &domain_pol, flags, 1,
-                                         &const_acct_name,
-                                         &num_rids, &user_rids, &name_types);
+       status = rpccli_samr_LookupNames(pipe_hnd, mem_ctx,
+                                        &domain_pol,
+                                        1,
+                                        &lsa_acct_name,
+                                        &user_rids,
+                                        &name_types);
        if (!NT_STATUS_IS_OK(status)) {
                goto done;
        }
 
-       if (name_types[0] != SID_NAME_USER) {
+       if (name_types.ids[0] != SID_NAME_USER) {
                status = NT_STATUS_INVALID_WORKSTATION;
                goto done;
        }
 
-       user_rid = user_rids[0];
+       user_rid = user_rids.ids[0];
 
        status = rpccli_samr_OpenUser(pipe_hnd, mem_ctx,
                                      &domain_pol,
@@ -770,18 +772,18 @@ static NTSTATUS libnet_join_joindomain_rpc(TALLOC_CTX *mem_ctx,
                ;;
        }
 
-       ZERO_STRUCT(ctr);
-       ZERO_STRUCT(p25);
-
-       fields_present = ACCT_NT_PWD_SET | ACCT_LM_PWD_SET | ACCT_FLAGS;
-       init_sam_user_info25P(&p25, fields_present, acb_info, (char *)pwbuf);
+       ZERO_STRUCT(user_info.info25);
 
-       ctr.switch_value = infolevel;
-       ctr.info.id25    = &p25;
+       user_info.info25.info.fields_present = ACCT_NT_PWD_SET |
+                                              ACCT_LM_PWD_SET |
+                                              SAMR_FIELD_ACCT_FLAGS;
+       user_info.info25.info.acct_flags = acb_info;
+       memcpy(&user_info.info25.password.data, pwbuf, sizeof(pwbuf));
 
-       status = rpccli_samr_set_userinfo2(pipe_hnd, mem_ctx, &user_pol,
-                                          infolevel, &cli->user_session_key,
-                                          &ctr);
+       status = rpccli_samr_SetUserInfo(pipe_hnd, mem_ctx,
+                                        &user_pol,
+                                        25,
+                                        &user_info);
        if (!NT_STATUS_IS_OK(status)) {
                goto done;
        }
@@ -801,6 +803,132 @@ static NTSTATUS libnet_join_joindomain_rpc(TALLOC_CTX *mem_ctx,
 /****************************************************************
 ****************************************************************/
 
+NTSTATUS libnet_join_ok(const char *netbios_domain_name,
+                       const char *machine_name,
+                       const char *dc_name)
+{
+       uint32_t neg_flags = NETLOGON_NEG_AUTH2_FLAGS |
+                            NETLOGON_NEG_SCHANNEL;
+       /* FIXME: NETLOGON_NEG_SELECT_AUTH2_FLAGS */
+       struct cli_state *cli = NULL;
+       struct rpc_pipe_client *pipe_hnd = NULL;
+       struct rpc_pipe_client *netlogon_pipe = NULL;
+       NTSTATUS status;
+       char *machine_password = NULL;
+       char *machine_account = NULL;
+
+       if (!dc_name) {
+               return NT_STATUS_INVALID_PARAMETER;
+       }
+
+       if (!secrets_init()) {
+               return NT_STATUS_CANT_ACCESS_DOMAIN_INFO;
+       }
+
+       machine_password = secrets_fetch_machine_password(netbios_domain_name,
+                                                         NULL, NULL);
+       if (!machine_password) {
+               return NT_STATUS_NO_TRUST_LSA_SECRET;
+       }
+
+       asprintf(&machine_account, "%s$", machine_name);
+       if (!machine_account) {
+               SAFE_FREE(machine_password);
+               return NT_STATUS_NO_MEMORY;
+       }
+
+       status = cli_full_connection(&cli, NULL,
+                                    dc_name,
+                                    NULL, 0,
+                                    "IPC$", "IPC",
+                                    machine_account,
+                                    NULL,
+                                    machine_password,
+                                    0,
+                                    Undefined, NULL);
+       free(machine_account);
+       free(machine_password);
+
+       if (!NT_STATUS_IS_OK(status)) {
+               status = cli_full_connection(&cli, NULL,
+                                            dc_name,
+                                            NULL, 0,
+                                            "IPC$", "IPC",
+                                            "",
+                                            NULL,
+                                            "",
+                                            0,
+                                            Undefined, NULL);
+       }
+
+       if (!NT_STATUS_IS_OK(status)) {
+               return status;
+       }
+
+       netlogon_pipe = get_schannel_session_key(cli,
+                                                netbios_domain_name,
+                                                &neg_flags, &status);
+       if (!netlogon_pipe) {
+               if (NT_STATUS_EQUAL(status, NT_STATUS_INVALID_NETWORK_RESPONSE)) {
+                       cli_shutdown(cli);
+                       return NT_STATUS_OK;
+               }
+
+               DEBUG(0,("libnet_join_ok: failed to get schannel session "
+                       "key from server %s for domain %s. Error was %s\n",
+               cli->desthost, netbios_domain_name, nt_errstr(status)));
+               cli_shutdown(cli);
+               return status;
+       }
+
+       if (!lp_client_schannel()) {
+               cli_shutdown(cli);
+               return NT_STATUS_OK;
+       }
+
+       pipe_hnd = cli_rpc_pipe_open_schannel_with_key(cli, PI_NETLOGON,
+                                                      PIPE_AUTH_LEVEL_PRIVACY,
+                                                      netbios_domain_name,
+                                                      netlogon_pipe->dc,
+                                                      &status);
+
+       cli_shutdown(cli);
+
+       if (!pipe_hnd) {
+               DEBUG(0,("libnet_join_ok: failed to open schannel session "
+                       "on netlogon pipe to server %s for domain %s. "
+                       "Error was %s\n",
+                       cli->desthost, netbios_domain_name, nt_errstr(status)));
+               return status;
+       }
+
+       return NT_STATUS_OK;
+}
+
+/****************************************************************
+****************************************************************/
+
+static WERROR libnet_join_post_verify(TALLOC_CTX *mem_ctx,
+                                     struct libnet_JoinCtx *r)
+{
+       NTSTATUS status;
+
+       status = libnet_join_ok(r->out.netbios_domain_name,
+                               r->in.machine_name,
+                               r->in.dc_name);
+       if (!NT_STATUS_IS_OK(status)) {
+               libnet_join_set_error_string(mem_ctx, r,
+                       "failed to verify domain membership after joining: %s",
+                       get_friendly_nt_error_msg(status));
+               return WERR_SETUP_NOT_JOINED;
+       }
+
+       return WERR_OK;
+}
+
+/****************************************************************
+****************************************************************/
+
 static bool libnet_join_unjoindomain_remove_secrets(TALLOC_CTX *mem_ctx,
                                                    struct libnet_UnjoinCtx *r)
 {
@@ -826,12 +954,11 @@ static NTSTATUS libnet_join_unjoindomain_rpc(TALLOC_CTX *mem_ctx,
        POLICY_HND sam_pol, domain_pol, user_pol;
        NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
        char *acct_name;
-       uint32 flags = 0x3e8;
-       const char *const_acct_name;
        uint32 user_rid;
-       uint32 num_rids, *name_types, *user_rids;
-       SAM_USERINFO_CTR ctr, *qctr = NULL;
-       SAM_USER_INFO_16 p16;
+       struct lsa_String lsa_acct_name;
+       struct samr_Ids user_rids;
+       struct samr_Ids name_types;
+       union samr_UserInfo *info = NULL;
 
        status = cli_full_connection(&cli, NULL,
                                     r->in.dc_name,
@@ -870,22 +997,26 @@ static NTSTATUS libnet_join_unjoindomain_rpc(TALLOC_CTX *mem_ctx,
 
        acct_name = talloc_asprintf(mem_ctx, "%s$", r->in.machine_name);
        strlower_m(acct_name);
-       const_acct_name = acct_name;
 
-       status = rpccli_samr_lookup_names(pipe_hnd, mem_ctx,
-                                         &domain_pol, flags, 1,
-                                         &const_acct_name,
-                                         &num_rids, &user_rids, &name_types);
+       init_lsa_String(&lsa_acct_name, acct_name);
+
+       status = rpccli_samr_LookupNames(pipe_hnd, mem_ctx,
+                                        &domain_pol,
+                                        1,
+                                        &lsa_acct_name,
+                                        &user_rids,
+                                        &name_types);
+
        if (!NT_STATUS_IS_OK(status)) {
                goto done;
        }
 
-       if (name_types[0] != SID_NAME_USER) {
+       if (name_types.ids[0] != SID_NAME_USER) {
                status = NT_STATUS_INVALID_WORKSTATION;
                goto done;
        }
 
-       user_rid = user_rids[0];
+       user_rid = user_rids.ids[0];
 
        status = rpccli_samr_OpenUser(pipe_hnd, mem_ctx,
                                      &domain_pol,
@@ -896,21 +1027,21 @@ static NTSTATUS libnet_join_unjoindomain_rpc(TALLOC_CTX *mem_ctx,
                goto done;
        }
 
-       status = rpccli_samr_query_userinfo(pipe_hnd, mem_ctx,
-                                           &user_pol, 16, &qctr);
+       status = rpccli_samr_QueryUserInfo(pipe_hnd, mem_ctx,
+                                          &user_pol,
+                                          16,
+                                          &info);
        if (!NT_STATUS_IS_OK(status)) {
                rpccli_samr_Close(pipe_hnd, mem_ctx, &user_pol);
                goto done;
        }
 
-       ZERO_STRUCT(ctr);
-       ctr.switch_value = 16;
-       ctr.info.id16 = &p16;
-
-       p16.acb_info = qctr->info.id16->acb_info | ACB_DISABLED;
+       info->info16.acct_flags |= ACB_DISABLED;
 
-       status = rpccli_samr_set_userinfo2(pipe_hnd, mem_ctx, &user_pol, 16,
-                                          &cli->user_session_key, &ctr);
+       status = rpccli_samr_SetUserInfo(pipe_hnd, mem_ctx,
+                                        &user_pol,
+                                        16,
+                                        info);
 
        rpccli_samr_Close(pipe_hnd, mem_ctx, &user_pol);
 
@@ -944,9 +1075,7 @@ static WERROR do_join_modify_vals_config(struct libnet_JoinCtx *r)
        if (!(r->in.join_flags & WKSSVC_JOIN_FLAGS_JOIN_TYPE)) {
 
                werr = libnet_conf_set_global_parameter(ctx, "security", "user");
-               if (!W_ERROR_IS_OK(werr)) {
-                       goto done;
-               }
+               W_ERROR_NOT_OK_GOTO_DONE(werr);
 
                werr = libnet_conf_set_global_parameter(ctx, "workgroup",
                                                        r->in.domain_name);
@@ -954,27 +1083,22 @@ static WERROR do_join_modify_vals_config(struct libnet_JoinCtx *r)
        }
 
        werr = libnet_conf_set_global_parameter(ctx, "security", "domain");
-       if (!W_ERROR_IS_OK(werr)) {
-               goto done;
-       }
+       W_ERROR_NOT_OK_GOTO_DONE(werr);
 
        werr = libnet_conf_set_global_parameter(ctx, "workgroup",
                                                r->out.netbios_domain_name);
-       if (!W_ERROR_IS_OK(werr)) {
-               goto done;
-       }
+       W_ERROR_NOT_OK_GOTO_DONE(werr);
 
        if (r->out.domain_is_ad) {
                werr = libnet_conf_set_global_parameter(ctx, "security", "ads");
-               if (!W_ERROR_IS_OK(werr)) {
-                       goto done;
-               }
+               W_ERROR_NOT_OK_GOTO_DONE(werr);
 
                werr = libnet_conf_set_global_parameter(ctx, "realm",
                                                        r->out.dns_domain_name);
+               W_ERROR_NOT_OK_GOTO_DONE(werr);
        }
 
-done:
+ done:
        libnet_conf_close(ctx);
        return werr;
 }
@@ -995,14 +1119,11 @@ static WERROR do_unjoin_modify_vals_config(struct libnet_UnjoinCtx *r)
        if (r->in.unjoin_flags & WKSSVC_JOIN_FLAGS_JOIN_TYPE) {
 
                werr = libnet_conf_set_global_parameter(ctx, "security", "user");
-               if (!W_ERROR_IS_OK(werr)) {
-                       goto done;
-               }
+               W_ERROR_NOT_OK_GOTO_DONE(werr);
+               libnet_conf_delete_global_parameter(ctx, "realm");
        }
 
-       libnet_conf_delete_global_parameter(ctx, "realm");
-
-done:
+ done:
        libnet_conf_close(ctx);
        return werr;
 }
@@ -1036,7 +1157,7 @@ static WERROR do_JoinConfig(struct libnet_JoinCtx *r)
 /****************************************************************
 ****************************************************************/
 
-static WERROR do_UnjoinConfig(struct libnet_UnjoinCtx *r)
+static WERROR libnet_unjoin_config(struct libnet_UnjoinCtx *r)
 {
        WERROR werr;
 
@@ -1065,8 +1186,9 @@ static WERROR do_UnjoinConfig(struct libnet_UnjoinCtx *r)
 static WERROR libnet_join_pre_processing(TALLOC_CTX *mem_ctx,
                                         struct libnet_JoinCtx *r)
 {
-
        if (!r->in.domain_name) {
+               libnet_join_set_error_string(mem_ctx, r,
+                       "No domain name defined");
                return WERR_INVALID_PARAM;
        }
 
@@ -1193,7 +1315,7 @@ static WERROR libnet_DomainJoin(TALLOC_CTX *mem_ctx,
 #endif /* WITH_ADS */
 
        if (!r->in.dc_name) {
-               struct DS_DOMAIN_CONTROLLER_INFO *info;
+               struct netr_DsRGetDCNameInfo *info;
                status = dsgetdcname(mem_ctx,
                                     r->in.domain_name,
                                     NULL,
@@ -1211,7 +1333,7 @@ static WERROR libnet_DomainJoin(TALLOC_CTX *mem_ctx,
                }
 
                r->in.dc_name = talloc_strdup(mem_ctx,
-                                             info->domain_controller_name);
+                                             info->dc_unc);
                W_ERROR_HAVE_NO_MEMORY(r->in.dc_name);
        }
 
@@ -1285,6 +1407,11 @@ WERROR libnet_Join(TALLOC_CTX *mem_ctx,
                if (!W_ERROR_IS_OK(werr)) {
                        goto done;
                }
+
+               werr = libnet_join_post_verify(mem_ctx, r);
+               if (!W_ERROR_IS_OK(werr)) {
+                       goto done;
+               }
        }
 
        werr = libnet_join_post_processing(mem_ctx, r);
@@ -1320,7 +1447,7 @@ static WERROR libnet_DomainUnjoin(TALLOC_CTX *mem_ctx,
        }
 
        if (!r->in.dc_name) {
-               struct DS_DOMAIN_CONTROLLER_INFO *info;
+               struct netr_DsRGetDCNameInfo *info;
                status = dsgetdcname(mem_ctx,
                                     r->in.domain_name,
                                     NULL,
@@ -1338,7 +1465,7 @@ static WERROR libnet_DomainUnjoin(TALLOC_CTX *mem_ctx,
                }
 
                r->in.dc_name = talloc_strdup(mem_ctx,
-                                             info->domain_controller_name);
+                                             info->dc_unc);
                W_ERROR_HAVE_NO_MEMORY(r->in.dc_name);
        }
 
@@ -1353,6 +1480,8 @@ static WERROR libnet_DomainUnjoin(TALLOC_CTX *mem_ctx,
                return ntstatus_to_werror(status);
        }
 
+       r->out.disabled_machine_account = true;
+
 #ifdef WITH_ADS
        if (r->in.unjoin_flags & WKSSVC_JOIN_FLAGS_ACCOUNT_DELETE) {
                ADS_STATUS ads_status;
@@ -1362,6 +1491,12 @@ static WERROR libnet_DomainUnjoin(TALLOC_CTX *mem_ctx,
                        libnet_unjoin_set_error_string(mem_ctx, r,
                                "failed to remove machine account from AD: %s",
                                ads_errstr(ads_status));
+               } else {
+                       r->out.deleted_machine_account = true;
+                       /* dirty hack */
+                       r->out.dns_domain_name = talloc_strdup(mem_ctx,
+                                                              r->in.ads->server.realm);
+                       W_ERROR_HAVE_NO_MEMORY(r->out.dns_domain_name);
                }
        }
 #endif /* WITH_ADS */
@@ -1377,6 +1512,12 @@ static WERROR libnet_DomainUnjoin(TALLOC_CTX *mem_ctx,
 static WERROR libnet_unjoin_pre_processing(TALLOC_CTX *mem_ctx,
                                           struct libnet_UnjoinCtx *r)
 {
+       if (!r->in.domain_name) {
+               libnet_unjoin_set_error_string(mem_ctx, r,
+                       "No domain name defined");
+               return WERR_INVALID_PARAM;
+       }
+
        if (r->in.modify_config && !lp_config_backend_is_registry()) {
                return WERR_NOT_SUPPORTED;
        }
@@ -1390,6 +1531,17 @@ static WERROR libnet_unjoin_pre_processing(TALLOC_CTX *mem_ctx,
        return WERR_OK;
 }
 
+/****************************************************************
+****************************************************************/
+
+static WERROR libnet_unjoin_post_processing(TALLOC_CTX *mem_ctx,
+                                           struct libnet_UnjoinCtx *r)
+{
+       saf_delete(r->out.netbios_domain_name);
+       saf_delete(r->out.dns_domain_name);
+
+       return libnet_unjoin_config(r);
+}
 
 /****************************************************************
 ****************************************************************/
@@ -1411,11 +1563,12 @@ WERROR libnet_Unjoin(TALLOC_CTX *mem_ctx,
        if (r->in.unjoin_flags & WKSSVC_JOIN_FLAGS_JOIN_TYPE) {
                werr = libnet_DomainUnjoin(mem_ctx, r);
                if (!W_ERROR_IS_OK(werr)) {
+                       libnet_unjoin_config(r);
                        goto done;
                }
        }
 
-       werr = do_UnjoinConfig(r);
+       werr = libnet_unjoin_post_processing(mem_ctx, r);
        if (!W_ERROR_IS_OK(werr)) {
                goto done;
        }