wb-ndr: change winbindd_sid2uid_async() to use WINBIND_GET_IDMAP
authorStefan Metzmacher <metze@sernet.de>
Tue, 11 Dec 2007 10:25:19 +0000 (11:25 +0100)
committerStefan Metzmacher <metze@sernet.de>
Fri, 2 May 2008 14:12:35 +0000 (16:12 +0200)
metze

source/winbindd/winbindd_idmap.c

index 505cba93ce68ca1fa108d0af217bf3dbde237d91..ef97e39b8de2baaf548701edb6100e6765bdf5b6 100644 (file)
@@ -340,37 +340,71 @@ enum winbindd_result winbindd_dual_set_hwm(struct winbindd_domain *domain,
 }
 
 static void winbindd_sid2uid_recv(TALLOC_CTX *mem_ctx, bool success,
-                              struct winbindd_response *response,
-                              void *c, void *private_data)
+                                   struct winbindd_ndr_call *c,
+                                   void *_r,
+                                   void *_cont,
+                                   void *private_data)
 {
-       void (*cont)(void *priv, bool succ, uid_t uid) =
-               (void (*)(void *, bool, uid_t))c;
+       void (*cont)(void *priv, bool succ, uid_t) =
+               (void (*)(void *, bool, uid_t))_cont;
+       struct winbind_get_idmap *r =
+               talloc_get_type_abort(_r, struct winbind_get_idmap);
+       uid_t uid;
 
        if (!success) {
-               DEBUG(5, ("Could not trigger sid2uid\n"));
-               cont(private_data, False, 0);
+               DEBUG(5, ("Could not get_idmap(sid2uid)\n"));
+               TALLOC_FREE(r);
+               cont(private_data, false, (uid_t)-1);
                return;
        }
 
-       if (response->result != WINBINDD_OK) {
-               DEBUG(5, ("sid2uid returned an error\n"));
-               cont(private_data, False, 0);
+       if (r->out.result != WINBIND_STATUS_OK) {
+               DEBUG(5, ("get_idmap(sid2uid) returned an error:0x%08X\n",
+                       r->out.result));
+               TALLOC_FREE(r);
+               cont(private_data, false, (uid_t)-1);
                return;
        }
 
-       cont(private_data, True, response->data.uid);
+       if (r->out.rep->uid > UINT32_MAX) {
+               DEBUG(1, ("get_idmap(sid2uid) returned a 64bit uid %llu\n",
+                       (unsigned long long)r->out.rep->uid));
+               TALLOC_FREE(r);
+               cont(private_data, false, (uid_t)-1);
+               return;
+       }
+
+       uid = r->out.rep->uid;
+       TALLOC_FREE(r);
+       cont(private_data, true, uid);
 }
 
 void winbindd_sid2uid_async(TALLOC_CTX *mem_ctx, const DOM_SID *sid,
                         void (*cont)(void *private_data, bool success, uid_t uid),
                         void *private_data)
 {
-       struct winbindd_request request;
-       ZERO_STRUCT(request);
-       request.cmd = WINBINDD_DUAL_SID2UID;
-       sid_to_fstring(request.data.dual_sid2id.sid, sid);
-       do_async(mem_ctx, idmap_child(), &request, winbindd_sid2uid_recv,
-                (void *)cont, private_data);
+       struct winbind_get_idmap *r = NULL;
+
+       DEBUG(7,("winbindd_sid2uid_async: Resolving %s to a uid\n",
+               sid_string_tos(sid)));
+
+       r = TALLOC_P(mem_ctx, struct winbind_get_idmap);
+       if (!r) goto nomem;
+       r->in.level = TALLOC_P(r, enum winbind_get_idmap_level);
+       if (!r->in.level) goto nomem;
+
+       *r->in.level    = WINBIND_IDMAP_LEVEL_SID_TO_UID;
+       r->in.req.sid   = discard_const(sid);
+
+       do_async_ndr(mem_ctx, idmap_child(),
+                    NDR_WINBIND_GET_IDMAP, r,
+                    winbindd_sid2uid_recv, r,
+                    (void *)cont, private_data);
+       return;
+nomem:
+       TALLOC_FREE(r);
+       cont(private_data, false, (uid_t)-1);
+       return;
 }
 
 enum winbindd_result winbindd_dual_sid2uid(struct winbindd_domain *domain,