]> arthur.barton.de Git - netatalk.git/commitdiff
Spotlight RPC init is working
authorFrank Lahm <franklahm@googlemail.com>
Thu, 28 Jun 2012 15:18:40 +0000 (17:18 +0200)
committerFrank Lahm <franklahm@googlemail.com>
Wed, 15 Aug 2012 18:14:22 +0000 (20:14 +0200)
etc/afpd/spotlight-packet.bin [new file with mode: 0644]
etc/afpd/spotlight.c
include/atalk/dalloc.h
libatalk/talloc/dalloc.c
libatalk/util/netatalk_conf.c

diff --git a/etc/afpd/spotlight-packet.bin b/etc/afpd/spotlight-packet.bin
new file mode 100644 (file)
index 0000000..7ddff55
Binary files /dev/null and b/etc/afpd/spotlight-packet.bin differ
index be513c6b3810c359d51b77780be5f190563bf6cd..176e6d6b93637e6ce254bcdac7125c23d20a6cba 100644 (file)
@@ -79,19 +79,20 @@ static int sl_pack_loop(DALLOC_CTX *query, char *buf, int offset, char *toc_buf,
 /* Helper functions and stuff */
 static const char *neststrings[] = {
     "",
-    "    ",
-    "        ",
-    "            ",
-    "                ",
-    "                    ",
-    "                        "
+    "\t",
+    "\t\t",
+    "\t\t\t",
+    "\t\t\t\t",
+    "\t\t\t\t\t",
+    "\t\t\t\t\t\t",
 };
 
 static int dd_dump(DALLOC_CTX *dd, int nestinglevel)
 {
     const char *type;
 
-    LOG(log_debug, logtype_sl, "%s1: %s(#%d): {", neststrings[nestinglevel], talloc_get_name(dd), talloc_array_length(dd->dd_talloc_array));
+    LOG(log_debug, logtype_sl, "%s%s(#%d): {",
+        neststrings[nestinglevel], talloc_get_name(dd), talloc_array_length(dd->dd_talloc_array));
 
     for (int n = 0; n < talloc_array_length(dd->dd_talloc_array); n++) {
 
@@ -104,28 +105,28 @@ static int dd_dump(DALLOC_CTX *dd, int nestinglevel)
         } else if (STRCMP(type, ==, "uint64_t")) {
             uint64_t i;
             memcpy(&i, dd->dd_talloc_array[n], sizeof(uint64_t));
-            LOG(log_debug, logtype_sl, "%s%u:\t0x%04x", neststrings[nestinglevel + 1], n + 1, i);
+            LOG(log_debug, logtype_sl, "%suint64_t: 0x%04x", neststrings[nestinglevel + 1], i);
         } else if (STRCMP(type, ==, "int64_t")) {
             int64_t i;
             memcpy(&i, dd->dd_talloc_array[n], sizeof(int64_t));
-            LOG(log_debug, logtype_sl, "%s%d:\t%" PRId64, neststrings[nestinglevel + 1], n + 1, i);
+            LOG(log_debug, logtype_sl, "%sint64_t: %" PRId64, neststrings[nestinglevel + 1], i);
         } else if (STRCMP(type, ==, "uint32_t")) {
             uint32_t i;
             memcpy(&i, dd->dd_talloc_array[n], sizeof(uint32_t));
-            LOG(log_debug, logtype_sl, "%s%d:\t%" PRIu32, neststrings[nestinglevel + 1], n + 1, i);
+            LOG(log_debug, logtype_sl, "%s%s: %" PRIu32, neststrings[nestinglevel + 1], type, i);
         } else if (STRCMP(type, ==, "char *")) {
             char *s;
             memcpy(&s, dd->dd_talloc_array[n], sizeof(char *));
-            LOG(log_debug, logtype_sl, "%s%d:\t%s", neststrings[nestinglevel + 1], n + +1, s);
+            LOG(log_debug, logtype_sl, "%sstring: %s", neststrings[nestinglevel + 1], s);
         } else if (STRCMP(type, ==, "sl_bool_t")) {
             sl_bool_t bl;
             memcpy(&bl, dd->dd_talloc_array[n], sizeof(sl_bool_t));
-            LOG(log_debug, logtype_sl, "%s%d:\t%s", neststrings[nestinglevel + 1], n + +1, bl ? "true" : "false");
+            LOG(log_debug, logtype_sl, "%sbool: %s", neststrings[nestinglevel + 1], bl ? "true" : "false");
         } else if (STRCMP(type, ==, "sl_cnids_t")) {
             sl_cnids_t cnids;
             memcpy(&cnids, dd->dd_talloc_array[n], sizeof(sl_cnids_t));
-            LOG(log_debug, logtype_sl, "%s%d:\tunkn1: %" PRIu16 ", unkn2: %" PRIu32,
-                   neststrings[nestinglevel + 1], n + 1, cnids.ca_unkn1, cnids.ca_context);
+            LOG(log_debug, logtype_sl, "%sCNIDs: unkn1: %" PRIu16 ", unkn2: %" PRIu32,
+                   neststrings[nestinglevel + 1], cnids.ca_unkn1, cnids.ca_context);
             if (cnids.ca_cnids)
                 dd_dump(cnids.ca_cnids, nestinglevel + 1);
         }
@@ -729,6 +730,61 @@ EC_CLEANUP:
     EC_EXIT;
 }
 
+/**************************************************************************************************
+ * Spotlight RPC functions
+ **************************************************************************************************/
+
+static int sl_rpc_fetchPropertiesForContext(AFPObj *obj, const DALLOC_CTX *query, DALLOC_CTX *reply, const struct vol *v)
+{
+    EC_INIT;
+
+    char *s;
+    sl_dict_t *dict;
+    sl_array_t *array;
+    sl_uuid_t uuid;
+
+    if (!v->v_uuid)
+        EC_FAIL_LOG("sl_rpc_fetchPropertiesForContext: missing UUID for volume: %s", v->v_localname);
+
+    dict = talloc_zero(reply, sl_dict_t);
+
+    /* key/val 1 */
+    s = talloc_strdup(dict, "kMDSStoreMetaScopes");
+    dalloc_add(dict, &s, char *);
+
+    array = talloc_zero(dict, sl_array_t);
+    s = talloc_strdup(array, "kMDQueryScopeComputer");
+    dalloc_add(array, &s, char *);
+    dalloc_add(dict, array, sl_array_t);
+
+    /* key/val 2 */
+    s = talloc_strdup(dict, "kMDSStorePathScopes");
+    dalloc_add(dict, &s, char *);
+
+    array = talloc_zero(dict, sl_array_t);
+    s = talloc_strdup(array, v->v_path);
+    dalloc_add(array, &s, char *);
+    dalloc_add(dict, array, sl_array_t);
+
+    /* key/val 3 */
+    s = talloc_strdup(dict, "kMDSStoreUUID");
+    dalloc_add(dict, &s, char *);
+
+    memcpy(uuid.sl_uuid, v->v_uuid, 16);
+    dalloc_add(dict, &uuid, sl_uuid_t);
+
+    /* key/val 4 */
+    s = talloc_strdup(dict, "kMDSStoreHasPersistentUUID");
+    dalloc_add(dict, &s, char *);
+    sl_bool_t b = true;
+    dalloc_add(dict, &b, sl_bool_t);
+
+    dalloc_add(reply, dict, sl_dict_t);
+
+EC_CLEANUP:
+    EC_EXIT;
+}
+
 /**************************************************************************************************
  * AFP functions
  **************************************************************************************************/
@@ -781,8 +837,35 @@ int afp_spotlight_rpc(AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf, size_
     case SPOTLIGHT_CMD_RPC: {
         DALLOC_CTX *query;
         EC_NULL( query = talloc_zero(tmp_ctx, DALLOC_CTX) );
-        (void)dissect_spotlight(query, ibuf + 22);
+        DALLOC_CTX *reply;
+        EC_NULL( reply = talloc_zero(tmp_ctx, DALLOC_CTX) );
+
+        EC_ZERO( dissect_spotlight(query, ibuf + 22) );
         dd_dump(query, 0);
+
+        char **cmd;
+        EC_NULL_LOG( cmd = dalloc_get(query, "DALLOC_CTX", 0, "DALLOC_CTX", 0, "char *", 0) );
+
+
+        if (STRCMP(*cmd, ==, "fetchPropertiesForContext:")) {
+            EC_ZERO_LOG( sl_rpc_fetchPropertiesForContext(obj, query, reply, vol) );
+        } else if (STRCMP(*cmd, ==, "fetchQueryResultsForContext:")) {
+            uint64_t *p;
+            if ((p = dalloc_get(query, "DALLOC_CTX", 0, "DALLOC_CTX", 0, "uint64_t", 1)) != NULL) {
+                LOG(log_info, logtype_sl, "fetchQueryResultsForContext: 0x%" PRIx64, *p);
+            }
+        }
+
+        /* Spotlight RPC status code ? 0 in all traces, we use 0xffffffff for an error, never seen from Apple */
+        if (ret == 0)
+            memset(rbuf, 0, 4);
+        else
+            memset(rbuf, 0xff, 4);
+        *rbuflen += 4;
+
+        int len;
+        EC_NEG1_LOG( len = sl_pack(reply, rbuf + 4) );
+        *rbuflen += len;
         break;
     }
     }
@@ -790,6 +873,7 @@ int afp_spotlight_rpc(AFPObj *obj, char *ibuf, size_t ibuflen, char *rbuf, size_
 EC_CLEANUP:
     talloc_free(tmp_ctx);
     if (ret != AFP_OK) {
+        *rbuflen = 0;
         return AFPERR_MISC;
     }
     EC_EXIT;
@@ -849,6 +933,8 @@ int main(int argc, char **argv)
     dalloc_add(cnids->ca_cnids, &id, uint32_t);
     dalloc_add(dd, cnids, sl_cnids_t);
 
+#endif
+
     /* Now the Spotlight types */
     sl_array_t *sl_arrary = talloc_zero(dd, sl_array_t);
     i = 1234;
@@ -860,8 +946,10 @@ int main(int argc, char **argv)
     dalloc_add(sl_arrary, sl_dict, sl_dict_t);
 
     dalloc_add(dd, sl_arrary, sl_array_t);
-#endif
+    dd_dump(dd, 0);
+
 
+#if 0
     /* now parse a real spotlight packet */
     char ibuf[8192];
     char rbuf[8192];
@@ -871,7 +959,7 @@ int main(int argc, char **argv)
 
     EC_NULL( query = talloc_zero(mem_ctx, DALLOC_CTX) );
 
-    EC_NEG1_LOG( fd = open("test.bin", O_RDONLY) );
+    EC_NEG1_LOG( fd = open("spotlight-packet.bin", O_RDONLY) );
     EC_NEG1_LOG( len = read(fd, ibuf, 8192) );
     close(fd);
     EC_NEG1_LOG( dissect_spotlight(query, ibuf + 24) );
@@ -887,6 +975,7 @@ int main(int argc, char **argv)
     lseek(fd, 24, SEEK_SET);
     write(fd, buf, qlen);
     close(fd);
+#endif
 
 EC_CLEANUP:
     if (mem_ctx) {
index 96d10289a8d8c9ba2f315f4ae5e4e5462877388e..70d8db59478f46f4b478f2887c13bb18f5632fd6 100644 (file)
@@ -26,12 +26,11 @@ typedef struct {
     void **dd_talloc_array;
 } DALLOC_CTX;
 
-#define dalloc_add(dd, obj, type)                                       \
-    dalloc_add_talloc_chunk((dd), talloc((dd), type), (obj), sizeof(type));
-
-#define dd_get_count(dd) talloc_array_length(dd->dd_talloc_array)
+#define dalloc_add(d, obj, type) dalloc_add_talloc_chunk((d), talloc((d), type), (obj), sizeof(type));
 
+/* Use dalloc_add() macro, not this function */
 extern int dalloc_add_talloc_chunk(DALLOC_CTX *dd, void *talloc_chunk, void *obj, size_t size);
 
+extern void *dalloc_get(DALLOC_CTX *d, ...);
 
 #endif  /* DALLOC_H */
index 562755d9e0d3ae9214bda5e2c43db3f600ea0e9e..2390d108ebc9c438d6ece5ecace1aa1b8bc61875 100644 (file)
@@ -31,7 +31,7 @@
 #include <atalk/bstrlib.h>
 #include <atalk/dalloc.h>
 
-/* Use dalloc_add_obj() macro, not this function */
+/* Use dalloc_add() macro, not this function */
 int dalloc_add_talloc_chunk(DALLOC_CTX *dd, void *talloc_chunk, void *obj, size_t size)
 {
     AFP_ASSERT(talloc_chunk);
@@ -42,3 +42,38 @@ int dalloc_add_talloc_chunk(DALLOC_CTX *dd, void *talloc_chunk, void *obj, size_
 
     return 0;
 }
+
+void *dalloc_get(DALLOC_CTX *d, ...)
+{
+    EC_INIT;
+    void *p = NULL;
+    va_list args;
+    const char *type;
+    int elem;
+    const char *elemtype;
+
+    va_start(args, d);
+    type = va_arg(args, const char *);
+
+    if (STRCMP(type, !=, "DALLOC_CTX"))
+        EC_FAIL;
+
+    while (STRCMP(type, ==, "DALLOC_CTX")) {
+        elem = va_arg(args, int);
+        AFP_ASSERT(elem < talloc_array_length(d->dd_talloc_array));
+        d = d->dd_talloc_array[elem];
+        type = va_arg(args, const char *);
+    }
+
+    elem = va_arg(args, int);
+    AFP_ASSERT(elem < talloc_array_length(d->dd_talloc_array));
+
+    p = talloc_check_name(d->dd_talloc_array[elem], type);
+
+    va_end(args);
+
+EC_CLEANUP:
+    if (ret != 0)
+        p = NULL;
+    return p;
+}
index 0c0a9416f0f60bb4c4948ee64f589d9ca5744ffc..a08ddebd44dafacaf84a7d8b87fc735e627392a3 100644 (file)
@@ -893,16 +893,16 @@ static struct vol *creatvol(AFPObj *obj,
     initvol_vfs(volume);
 
     /* get/store uuid from file in afpd master*/
-    if (!(pwd) && (volume->v_flags & AFPVOL_TM)) {
-        char *uuid = get_vol_uuid(obj, volume->v_localname);
-        if (!uuid) {
-            LOG(log_error, logtype_afpd, "Volume '%s': couldn't get UUID",
-                volume->v_localname);
-        } else {
-            volume->v_uuid = uuid;
-            LOG(log_debug, logtype_afpd, "Volume '%s': UUID '%s'",
-                volume->v_localname, volume->v_uuid);
-        }
+    become_root();
+    char *uuid = get_vol_uuid(obj, volume->v_localname);
+    unbecome_root();
+    if (!uuid) {
+        LOG(log_error, logtype_afpd, "Volume '%s': couldn't get UUID",
+            volume->v_localname);
+    } else {
+        volume->v_uuid = uuid;
+        LOG(log_debug, logtype_afpd, "Volume '%s': UUID '%s'",
+            volume->v_localname, volume->v_uuid);
     }
 
     /* no errors shall happen beyond this point because the cleanup would mess the volume chain up */