r24372: Implement backend for wbinfo -U
authorKai Blin <kai@samba.org>
Mon, 13 Aug 2007 16:07:47 +0000 (16:07 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 20:01:47 +0000 (15:01 -0500)
source/winbind/config.mk
source/winbind/wb_samba3_cmd.c
source/winbind/wb_samba3_protocol.c
source/winbind/wb_uid2sid.c [new file with mode: 0644]

index efbf8b595e68f237e8ffe2663514824c1bdcc465..02d6039681e11d7d29fca123aecb957f3720eaf5 100644 (file)
@@ -18,6 +18,7 @@ OBJ_FILES = \
                wb_name2domain.o \
                wb_sid2uid.o \
                wb_sid2gid.o \
+               wb_uid2sid.o \
                wb_connect_lsa.o \
                wb_connect_sam.o \
                wb_cmd_lookupname.o \
index a964aa94349dec92bc7bd699444bdeca4a8853df..76125c4032ca9066cc47830501d7a080c9a7ffc7 100644 (file)
@@ -826,3 +826,52 @@ static void sid2gid_recv(struct composite_context *ctx)
 
        wbsrv_samba3_async_epilogue(status, s3call);
 }
+
+static void uid2sid_recv(struct composite_context *ctx);
+
+NTSTATUS wbsrv_samba3_uid2sid(struct wbsrv_samba3_call *s3call)
+{
+       struct composite_context *ctx;
+       struct wbsrv_service *service =
+               s3call->wbconn->listen_socket->service;
+
+       DEBUG(5, ("wbsrv_samba3_uid2sid called\n"));
+
+       ctx = wb_uid2sid_send(s3call, service, s3call->request.data.uid);
+       NT_STATUS_HAVE_NO_MEMORY(ctx);
+
+       ctx->async.fn = uid2sid_recv;
+       ctx->async.private_data = s3call;
+       s3call->flags |= WBSRV_CALL_FLAGS_REPLY_ASYNC;
+       return NT_STATUS_OK;
+
+}
+
+static void uid2sid_recv(struct composite_context *ctx)
+{
+       struct wbsrv_samba3_call *s3call =
+               talloc_get_type(ctx->async.private_data,
+                               struct wbsrv_samba3_call);
+       NTSTATUS status;
+       struct dom_sid *sid;
+       char *sid_str;
+
+       DEBUG(5, ("uid2sid_recv called\n"));
+
+       status = wb_uid2sid_recv(ctx, s3call, &sid);
+       if(NT_STATUS_IS_OK(status)) {
+               sid_str = dom_sid_string(s3call, sid);
+
+               /* If the conversion failed, bail out with a failure. */
+               if (sid_str == NULL)
+                       wbsrv_samba3_async_epilogue(NT_STATUS_NO_MEMORY,s3call);
+
+               /* But we assume this worked, so we'll set the string. Work
+                * done. */
+               WBSRV_SAMBA3_SET_STRING(s3call->response.data.sid.sid, sid_str);
+               s3call->response.data.sid.type = SID_NAME_USER;
+       }
+
+       wbsrv_samba3_async_epilogue(status, s3call);
+}
+
index e65add9fd8e61154815819cba988c50957b217e2..c5b3af464b2e61c67d87b18a92b6309118f3f3d8 100644 (file)
@@ -165,6 +165,10 @@ NTSTATUS wbsrv_samba3_handle_call(struct wbsrv_samba3_call *s3call)
        case WINBINDD_DUAL_SID2GID:
                return wbsrv_samba3_sid2gid(s3call);
 
+       case WINBINDD_UID_TO_SID:
+       case WINBINDD_DUAL_UID2SID:
+               return wbsrv_samba3_uid2sid(s3call);
+
                /* Unimplemented commands */
 
        case WINBINDD_PAM_CHAUTHTOK:
@@ -174,7 +178,6 @@ NTSTATUS wbsrv_samba3_handle_call(struct wbsrv_samba3_call *s3call)
        case WINBINDD_LIST_GROUPS:
        case WINBINDD_LOOKUPRIDS:
        case WINBINDD_SIDS_TO_XIDS:
-       case WINBINDD_UID_TO_SID:
        case WINBINDD_GID_TO_SID:
        case WINBINDD_ALLOCATE_UID:
        case WINBINDD_ALLOCATE_GID:
@@ -189,7 +192,6 @@ NTSTATUS wbsrv_samba3_handle_call(struct wbsrv_samba3_call *s3call)
        case WINBINDD_GETGRLST:
        case WINBINDD_INIT_CONNECTION:
        case WINBINDD_DUAL_SIDS2XIDS:
-       case WINBINDD_DUAL_UID2SID:
        case WINBINDD_DUAL_GID2SID:
        case WINBINDD_DUAL_SET_MAPPING:
        case WINBINDD_DUAL_SET_HWM:
diff --git a/source/winbind/wb_uid2sid.c b/source/winbind/wb_uid2sid.c
new file mode 100644 (file)
index 0000000..d7a909f
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+   Unix SMB/CIFS implementation.
+
+   Command backend for wbinfo -U
+
+   Copyright (C) Kai Blin 2007
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "includes.h"
+#include "libcli/composite/composite.h"
+#include "winbind/wb_server.h"
+#include "smbd/service_task.h"
+#include "winbind/wb_helper.h"
+#include "libcli/security/proto.h"
+
+struct uid2sid_state {
+       struct composite_context *ctx;
+       struct wbsrv_service *service;
+       struct dom_sid *sid;
+};
+
+struct composite_context *wb_uid2sid_send(TALLOC_CTX *mem_ctx,
+               struct wbsrv_service *service, uid_t uid)
+{
+       struct composite_context *result;
+       struct uid2sid_state *state;
+
+       DEBUG(5, ("wb_uid2sid_send called\n"));
+
+       result = composite_create(mem_ctx, service->task->event_ctx);
+       if (!result) return NULL;
+
+       state = talloc(mem_ctx, struct uid2sid_state);
+       if (composite_nomem(state, result)) return result;
+
+       state->ctx = result;
+       result->private_data = state;
+       state->service = service;
+
+       /* FIXME: This is a stub so far.
+        * We cheat by just using the uid as RID with the domain SID.*/
+       state->sid = dom_sid_add_rid(result, service->primary_sid, uid);
+       if (composite_nomem(state->sid, state->ctx)) return result;
+
+       composite_done(state->ctx);
+       return result;
+}
+
+NTSTATUS wb_uid2sid_recv(struct composite_context *ctx, TALLOC_CTX *mem_ctx,
+               struct dom_sid **sid)
+{
+       NTSTATUS status = composite_wait(ctx);
+
+       DEBUG(5, ("wb_uid2sid_recv called.\n"));
+
+       if (NT_STATUS_IS_OK(status)) {
+               struct uid2sid_state *state =
+                       talloc_get_type(ctx->private_data,
+                               struct uid2sid_state);
+               *sid = talloc_steal(mem_ctx, state->sid);
+       }
+       talloc_free(ctx);
+       return status;
+}
+