s3-clusapi: implement _clusapi_OpenResource().
authorGünther Deschner <gd@samba.org>
Wed, 1 Jul 2015 11:06:12 +0000 (13:06 +0200)
committerGünther Deschner <gd@samba.org>
Sun, 3 Feb 2019 09:26:12 +0000 (10:26 +0100)
Guenther

Signed-off-by: Günther Deschner <gd@samba.org>
source3/rpc_server/clusapi/srv_clusapi_nt.c

index fba8668ddf44c1dcff046d3818905e4cf4cb6f05..9dbd2565828623db49bd843c0c0848ece613f9fb 100644 (file)
@@ -174,6 +174,21 @@ WERROR _clusapi_CreateEnum(struct pipes_struct *p,
 }
 
 
+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
 ****************************************************************/
@@ -181,7 +196,49 @@ WERROR _clusapi_CreateEnum(struct pipes_struct *p,
 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;
 }