}
+static bool lookup_cluster_resource_type(TALLOC_CTX *mem_ctx,
+ const char *resource_name,
+ uint32_t *type)
+{
+ int ret;
+ char *resource_name_canon;
+
+ ret = find_service(mem_ctx, resource_name, &resource_name_canon);
+ if (ret != 0) {
+ return false;
+ }
+
+ return true;
+}
+
/****************************************************************
_clusapi_OpenResource
****************************************************************/
void _clusapi_OpenResource(struct pipes_struct *p,
struct clusapi_OpenResource *r)
{
- p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
+ bool ok;
+ struct clusapi_handle *h;
+
+ if (p->auth.auth_level < DCERPC_AUTH_LEVEL_PRIVACY) {
+ p->fault_state = DCERPC_FAULT_ACCESS_DENIED;
+ *r->out.Status = WERR_ACCESS_DENIED;
+ return;
+ }
+
+ if (r->in.lpszResourceName == NULL ||
+ r->in.lpszResourceName[0] == '\0') {
+ *r->out.Status = WERR_RESOURCE_NOT_FOUND;
+ *r->out.rpc_status = WERR_OK;
+ return;
+ }
+
+ ok = lookup_cluster_resource_type(talloc_tos(),
+ r->in.lpszResourceName,
+ NULL);
+ if (!ok) {
+ *r->out.Status = WERR_RESOURCE_NOT_FOUND;
+ *r->out.rpc_status = WERR_OK;
+ return;
+ }
+
+ h = talloc_zero(p, struct clusapi_handle);
+ if (h == NULL) {
+ *r->out.Status = WERR_NOT_ENOUGH_MEMORY;
+ *r->out.rpc_status = WERR_OK;
+ return;
+ }
+
+ h->type = CLUSAPI_HANDLE_TYPE_RESOURCE;
+
+ ok = create_policy_hnd(p, r->out.hResource, h);
+ if (!ok) {
+ *r->out.Status = WERR_FOOBAR;
+ *r->out.rpc_status = WERR_FOOBAR;
+ return;
+ }
+
+ *r->out.Status = WERR_OK;
+ *r->out.rpc_status = WERR_OK;
}