static NTSTATUS startup_kpasswd_server(TALLOC_CTX *mem_ctx,
				       struct kdc_server *kdc,
				       struct loadparm_context *lp_ctx,
				       struct interface *ifaces)
{
	int num_interfaces;
	int i;
	TALLOC_CTX *tmp_ctx;
	NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
	uint16_t kpasswd_port;
	bool done_wildcard = false;
	bool ok;

	kpasswd_port = lpcfg_kpasswd_port(lp_ctx);
	if (kpasswd_port == 0) {
		return NT_STATUS_OK;
	}

	tmp_ctx = talloc_named_const(mem_ctx, 0, "kpasswd");
	if (tmp_ctx == NULL) {
		return NT_STATUS_NO_MEMORY;
	}

	num_interfaces = iface_list_count(ifaces);

	ok = lpcfg_bind_interfaces_only(lp_ctx);
	if (!ok) {
		int num_binds = 0;
		char **wcard;

		wcard = iface_list_wildcard(tmp_ctx);
		if (wcard == NULL) {
			status = NT_STATUS_NO_MEMORY;
			goto out;
		}

		for (i = 0; wcard[i] != NULL; i++) {
			status = kdc_add_socket(kdc,
						kdc->task->model_ops,
						"kpasswd",
						wcard[i],
						kpasswd_port,
						kpasswd_process,
						false);
			if (NT_STATUS_IS_OK(status)) {
				num_binds++;
			}
		}
		talloc_free(wcard);

		if (num_binds == 0) {
			status = NT_STATUS_INVALID_PARAMETER_MIX;
			goto out;
		}

		done_wildcard = true;
	}

	for (i = 0; i < num_interfaces; i++) {
		const char *address = talloc_strdup(tmp_ctx, iface_list_n_ip(ifaces, i));

		status = kdc_add_socket(kdc,
					kdc->task->model_ops,
					"kpasswd",
					address,
					kpasswd_port,
					kpasswd_process,
					done_wildcard);
		if (NT_STATUS_IS_OK(status)) {
			goto out;
		}
	}

out:
	talloc_free(tmp_ctx);
	return status;
}
static NTSTATUS startup_kpasswd_server(TALLOC_CTX *mem_ctx,
				       struct kdc_server *kdc,
				       struct loadparm_context *lp_ctx,
				       struct interface *ifaces)
{
	int num_interfaces;
	int i;
	TALLOC_CTX *tmp_ctx;
	NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
	uint16_t kpasswd_port;
	bool done_wildcard = false;
	bool ok;

	kpasswd_port = lpcfg_kpasswd_port(lp_ctx);
	if (kpasswd_port == 0) {
		return NT_STATUS_OK;
	}

	tmp_ctx = talloc_named_const(mem_ctx, 0, "kpasswd");
	if (tmp_ctx == NULL) {
		return NT_STATUS_NO_MEMORY;
	}

	num_interfaces = iface_list_count(ifaces);

	ok = lpcfg_bind_interfaces_only(lp_ctx);
	if (!ok) {
		int num_binds = 0;
		char **wcard;

		wcard = iface_list_wildcard(tmp_ctx);
		if (wcard == NULL) {
			status = NT_STATUS_NO_MEMORY;
			goto out;
		}

		for (i = 0; wcard[i] != NULL; i++) {
			status = kdc_add_socket(kdc,
						kdc->task->model_ops,
						"kpasswd",
						wcard[i],
						kpasswd_port,
						kpasswd_process,
						false);
			if (NT_STATUS_IS_OK(status)) {
				num_binds++;
			}
		}
		talloc_free(wcard);

		if (num_binds == 0) {
			status = NT_STATUS_INVALID_PARAMETER_MIX;
			goto out;
		}

		done_wildcard = true;
	}

	for (i = 0; i < num_interfaces; i++) {
		const char *address = talloc_strdup(tmp_ctx, iface_list_n_ip(ifaces, i));

		status = kdc_add_socket(kdc,
					kdc->task->model_ops,
					"kpasswd",
					address,
					kpasswd_port,
					kpasswd_process,
					done_wildcard);
		if (NT_STATUS_IS_OK(status)) {
			goto out;
		}
	}

out:
	talloc_free(tmp_ctx);
	return status;
}