s4-winbindd: implement WINBINDD_SIDS_TO_XIDS
authorAndrew Tridgell <tridge@samba.org>
Tue, 26 Jul 2011 00:52:59 +0000 (10:52 +1000)
committerAndrew Bartlett <abartlet@samba.org>
Thu, 8 Sep 2011 13:09:54 +0000 (15:09 +0200)
this fixes wbinfo --sids-to-unix-ids

Pair-Programmed-With: Andrew Bartlett <abartlet@samba.org>

source4/winbind/wb_samba3_cmd.c
source4/winbind/wb_samba3_protocol.c

index 7ceee4193e838c14105817e51607302a0b8ce2d3..679a2a2335cda9af09b27a640d1cd2861275418f 100644 (file)
@@ -1517,3 +1517,97 @@ static void gid2sid_recv(struct composite_context *ctx)
        wbsrv_samba3_async_epilogue(status, s3call);
 }
 
+static void sids2xids_recv(struct composite_context *ctx)
+{
+       struct wbsrv_samba3_call *s3call =
+               talloc_get_type(ctx->async.private_data,
+                               struct wbsrv_samba3_call);
+       NTSTATUS status;
+       struct id_map *ids;
+       unsigned i, count;
+       struct winbindd_response *resp = s3call->response;
+
+       DEBUG(5, ("sids2xids_recv called\n"));
+
+       status = wb_sids2xids_recv(ctx, &ids, &count);
+       if (!NT_STATUS_IS_OK(status)) {
+               goto done;
+       }
+
+       /* fill in extra_data with the list of IDs. Each is prefixed
+        * by 'U' or 'G' for user and group, and followed by a
+        * newline */
+       resp->extra_data.data = talloc_strdup(resp, "");
+       if (resp->extra_data.data == NULL) {
+               status = NT_STATUS_NO_MEMORY;
+               goto done;
+       }
+
+       for (i=0; i<count; i++) {
+               char type_char = '*';
+               if (ids[i].status != ID_MAPPED) {
+                       resp->extra_data.data = talloc_asprintf_append_buffer(resp->extra_data.data, "\n");
+                       if (resp->extra_data.data == NULL) {
+                               status = NT_STATUS_NO_MEMORY;
+                               goto done;
+                       }
+                       continue;
+               }
+               switch (ids[i].xid.type) {
+               case ID_TYPE_UID:
+                       type_char = 'U';
+                       break;
+               case ID_TYPE_GID:
+                       type_char = 'G';
+                       break;
+               case ID_TYPE_BOTH:
+                       type_char = 'B';
+                       break;
+               case ID_TYPE_NOT_SPECIFIED:
+                       type_char = 'N';
+                       break;
+               }
+               resp->extra_data.data = talloc_asprintf_append_buffer(resp->extra_data.data, "%c%u\n",
+                                                                     type_char, (unsigned)ids[i].xid.id);
+               if (resp->extra_data.data == NULL) {
+                       status = NT_STATUS_NO_MEMORY;
+                       goto done;
+               }
+       }
+       resp->length += strlen(resp->extra_data.data) + 1;
+
+done:
+       wbsrv_samba3_async_epilogue(status, s3call);
+}
+
+
+NTSTATUS wbsrv_samba3_sids2xids(struct wbsrv_samba3_call *s3call)
+{
+       struct composite_context *ctx;
+       struct wbsrv_service *service =
+               s3call->wbconn->listen_socket->service;
+       struct id_map *ids = NULL;
+       unsigned count = 0;
+       char *saveptr = NULL;
+       char *sidstr;
+
+       DEBUG(5, ("wbsrv_samba3_sids2xids called\n"));
+
+       for (sidstr = strtok_r(s3call->request->extra_data.data, "\n", &saveptr);
+            sidstr;
+            sidstr = strtok_r(NULL, "\n", &saveptr)) {
+               count += 1;
+               ids = talloc_realloc(s3call, ids, struct id_map, count);
+               NT_STATUS_HAVE_NO_MEMORY(ids);
+               ids[count-1].sid = dom_sid_parse_talloc(ids, sidstr);
+               NT_STATUS_HAVE_NO_MEMORY(ids->sid);
+       }
+
+       ctx = wb_sids2xids_send(s3call, service, count, ids);
+       NT_STATUS_HAVE_NO_MEMORY(ctx);
+
+       ctx->async.fn = sids2xids_recv;
+       ctx->async.private_data = s3call;
+       s3call->flags |= WBSRV_CALL_FLAGS_REPLY_ASYNC;
+       return NT_STATUS_OK;
+}
index 6c89f340631cbe8427f7a4368a5742acf03b8fa1..2846e9ce90d8542f3c641bdaf69285b520f8a187 100644 (file)
@@ -214,13 +214,15 @@ NTSTATUS wbsrv_samba3_handle_call(struct wbsrv_samba3_call *s3call)
        case WINBINDD_PAM_LOGOFF:
                return wbsrv_samba3_pam_logoff(s3call);
 
+       case WINBINDD_SIDS_TO_XIDS:
+               return wbsrv_samba3_sids2xids(s3call);
+
        /* Unimplemented commands */
        case WINBINDD_GETPWSID:
        case WINBINDD_PAM_CHAUTHTOK:
        case WINBINDD_PAM_CHNG_PSWD_AUTH_CRAP:
        case WINBINDD_LOOKUPRIDS:
        case WINBINDD_LOOKUPSIDS:
-       case WINBINDD_SIDS_TO_XIDS:
        case WINBINDD_ALLOCATE_UID:
        case WINBINDD_ALLOCATE_GID:
        case WINBINDD_SHOW_SEQUENCE: