s3:mdssvc: fix error handling of mdssvc RPC requests
authorRalph Boehme <slow@samba.org>
Tue, 16 Apr 2019 12:17:11 +0000 (14:17 +0200)
committerJeremy Allison <jra@samba.org>
Thu, 8 Aug 2019 20:24:33 +0000 (20:24 +0000)
It seems for certain error cases macOS just sends an empty response
blob. So if our mdssvc request processing fails, we should just return an empty
response blob, but not fail the mdssvc request at the DCERPC layer.

Example, passing "xxx" as sharename which does not exist at the server:

  $ bin/rpcclient -U slow%pass macmini -c "fetch_attributes xxx /foo/bar 123" -d 10
  ....
  Got pdu len 56, data_len 32
  rpc_api_pipe: got frag len of 56 at offset 0: NT_STATUS_OK
  rpc_api_pipe: host macmini returned 32 bytes.
  mdssvc_cmd: struct mdssvc_cmd
     out: struct mdssvc_cmd
         fragment                 : *
             fragment                 : 0x00000000 (0)
         response_blob            : *
             response_blob: struct mdssvc_blob
                 length                   : 0x00000000 (0)
                 size                     : 0x00010000 (65536)
                 spotlight_blob           : *
                     spotlight_blob: ARRAY(0)
         unkn9                    : *
             unkn9                    : 0x00000000 (0)
  ...

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/rpc_server/mdssvc/mdssvc.c

index 48461eab46fc68dc32bc97e8a8bcd0d2b4cd13c5..5b1f291d054864f7cb3e96c22290bcd1efdecb8b 100644 (file)
@@ -1661,28 +1661,21 @@ bool mds_dispatch(struct mds_ctx *mds_ctx,
                goto cleanup;
        }
 
-       /*
-        * If these functions return an error, they hit something like
-        * a non recoverable talloc error
-        */
        ok = slcmd->function(mds_ctx, query, reply);
-       if (!ok) {
-               DEBUG(1, ("error in Spotlight RPC handler\n"));
-               goto cleanup;
-       }
-
-       DEBUG(5, ("%s", dalloc_dump(reply, 0)));
-
-       len = sl_pack(reply, (char *)response_blob->spotlight_blob,
-                     response_blob->size);
-       if (len == -1) {
-               DEBUG(1, ("error packing Spotlight RPC reply\n"));
-               ok = false;
-               goto cleanup;
+       if (ok) {
+               DBG_DEBUG("%s", dalloc_dump(reply, 0));
+
+               len = sl_pack(reply,
+                             (char *)response_blob->spotlight_blob,
+                             response_blob->size);
+               if (len == -1) {
+                       DBG_ERR("error packing Spotlight RPC reply\n");
+                       ok = false;
+                       goto cleanup;
+               }
+               response_blob->length = len;
        }
 
-       response_blob->length = len;
-
 cleanup:
        talloc_free(query);
        talloc_free(reply);