static NTSTATUS pdb_samba_dsdb_add_sam_account(struct pdb_methods *m,
					struct samu *sampass)
{
	int ret;
	NTSTATUS status;
	struct ldb_dn *dn;
	struct pdb_samba_dsdb_state *state = talloc_get_type_abort(
		m->private_data, struct pdb_samba_dsdb_state);
	uint32_t acb_flags = pdb_get_acct_ctrl(sampass);
	const char *username = pdb_get_username(sampass);
	const struct dom_sid *user_sid = pdb_get_user_sid(sampass);
	TALLOC_CTX *tframe = talloc_stackframe();

	acb_flags &= (ACB_NORMAL|ACB_WSTRUST|ACB_SVRTRUST|ACB_DOMTRUST);

	ret = ldb_transaction_start(state->ldb);
	if (ret != LDB_SUCCESS) {
		talloc_free(tframe);
		return NT_STATUS_LOCK_NOT_GRANTED;
	}

	status = dsdb_add_user(state->ldb, talloc_tos(), username,
			       acb_flags, user_sid, NULL, &dn);
	if (!NT_STATUS_IS_OK(status)) {
		ldb_transaction_cancel(state->ldb);
		talloc_free(tframe);
		return status;
	}

	ret = pdb_samba_dsdb_replace_by_sam(state, pdb_element_is_set_or_changed,
					dn, sampass);
	if (ret != LDB_SUCCESS) {
		ldb_transaction_cancel(state->ldb);
		talloc_free(tframe);
		return dsdb_ldb_err_to_ntstatus(ret);
	}

	ret = ldb_transaction_commit(state->ldb);
	if (ret != LDB_SUCCESS) {
		DEBUG(0,("Failed to commit transaction to add and modify account record %s: %s\n",
			 ldb_dn_get_linearized(dn),
			 ldb_errstring(state->ldb)));
		talloc_free(tframe);
		return NT_STATUS_INTERNAL_DB_CORRUPTION;
	}
	talloc_free(tframe);
	return NT_STATUS_OK;
}
static NTSTATUS pdb_samba_dsdb_add_sam_account(struct pdb_methods *m,
					struct samu *sampass)
{
	int ret;
	NTSTATUS status;
	struct ldb_dn *dn;
	struct pdb_samba_dsdb_state *state = talloc_get_type_abort(
		m->private_data, struct pdb_samba_dsdb_state);
	uint32_t acb_flags = pdb_get_acct_ctrl(sampass);
	const char *username = pdb_get_username(sampass);
	const struct dom_sid *user_sid = pdb_get_user_sid(sampass);
	TALLOC_CTX *tframe = talloc_stackframe();

	acb_flags &= (ACB_NORMAL|ACB_WSTRUST|ACB_SVRTRUST|ACB_DOMTRUST);

	ret = ldb_transaction_start(state->ldb);
	if (ret != LDB_SUCCESS) {
		talloc_free(tframe);
		return NT_STATUS_LOCK_NOT_GRANTED;
	}

	status = dsdb_add_user(state->ldb, talloc_tos(), username,
			       acb_flags, user_sid, NULL, &dn);
	if (!NT_STATUS_IS_OK(status)) {
		ldb_transaction_cancel(state->ldb);
		talloc_free(tframe);
		return status;
	}

	ret = pdb_samba_dsdb_replace_by_sam(state, pdb_element_is_set_or_changed,
					dn, sampass);
	if (ret != LDB_SUCCESS) {
		ldb_transaction_cancel(state->ldb);
		talloc_free(tframe);
		return dsdb_ldb_err_to_ntstatus(ret);
	}

	ret = ldb_transaction_commit(state->ldb);
	if (ret != LDB_SUCCESS) {
		DEBUG(0,("Failed to commit transaction to add and modify account record %s: %s\n",
			 ldb_dn_get_linearized(dn),
			 ldb_errstring(state->ldb)));
		talloc_free(tframe);
		return NT_STATUS_INTERNAL_DB_CORRUPTION;
	}
	talloc_free(tframe);
	return NT_STATUS_OK;
}