/** \details Check if the authenticated user belongs to the Exchange organization \param dce_call pointer to the session context \param emsabp_ctx pointer to the EMSABP context \return true on success, otherwise false */ _PUBLIC_ bool emsabp_verify_user(struct dcesrv_call_state *dce_call, struct emsabp_context *emsabp_ctx) { int ret; TALLOC_CTX *mem_ctx; const char *username = NULL; struct ldb_message *ldb_msg = NULL; username = dcesrv_call_account_name(dce_call); mem_ctx = talloc_named(emsabp_ctx->mem_ctx, 0, __FUNCTION__); ret = emsabp_get_account_info(mem_ctx, emsabp_ctx, username, &ldb_msg); /* cache account_name upon success */ if (MAPI_STATUS_IS_OK(ret)) { emsabp_ctx->account_name = talloc_strdup(emsabp_ctx->mem_ctx, username); } talloc_free(mem_ctx); return MAPI_STATUS_IS_OK(ret); }
/** \details Check if the authenticated user belongs to the Exchange organization and is enabled \param dce_call pointer to the session context \param emsmdbp_ctx pointer to the EMSMDBP context \return true on success, otherwise false */ _PUBLIC_ bool emsmdbp_verify_user(struct dcesrv_call_state *dce_call, struct emsmdbp_context *emsmdbp_ctx) { int ret; const char *username = NULL; int msExchUserAccountControl; struct ldb_result *res = NULL; const char * const recipient_attrs[] = { "msExchUserAccountControl", NULL }; username = dcesrv_call_account_name(dce_call); ret = ldb_search(emsmdbp_ctx->samdb_ctx, emsmdbp_ctx, &res, ldb_get_default_basedn(emsmdbp_ctx->samdb_ctx), LDB_SCOPE_SUBTREE, recipient_attrs, "sAMAccountName=%s", ldb_binary_encode_string(emsmdbp_ctx, username)); /* If the search failed */ if (ret != LDB_SUCCESS || !res->count) { return false; } /* If msExchUserAccountControl attribute is not found */ if (!res->msgs[0]->num_elements) { return false; } /* If the attribute exists check its value */ msExchUserAccountControl = ldb_msg_find_attr_as_int(res->msgs[0], "msExchUserAccountControl", 2); if (msExchUserAccountControl == 2) { return false; } /* Get a copy of the username for later use and setup missing conn_info components */ emsmdbp_ctx->username = talloc_strdup(emsmdbp_ctx, username); openchangedb_get_MailboxReplica(emsmdbp_ctx->oc_ctx, emsmdbp_ctx->username, &emsmdbp_ctx->mstore_ctx->conn_info->repl_id, &emsmdbp_ctx->mstore_ctx->conn_info->replica_guid); return true; }