r25175: Change to talloc_asprintf_append_buffer().
[jelmer/samba4-debian.git] / source / winbind / wb_samba3_cmd.c
index 55a763f91ebaba7d1d9cffea7f7d34fa33fbd0ba..56a168ebb0ed65386a4a7bedca61ace7c2bca8ed 100644 (file)
@@ -21,8 +21,6 @@
 */
 
 #include "includes.h"
-#include "nsswitch/winbind_nss_config.h"
-#include "nsswitch/winbindd_nss.h"
 #include "winbind/wb_server.h"
 #include "winbind/wb_async_helpers.h"
 #include "winbind/wb_helper.h"
@@ -31,6 +29,7 @@
 #include "librpc/gen_ndr/netlogon.h"
 #include "libcli/security/security.h"
 #include "auth/pam_errors.h"
+#include "param/param.h"
 
 /* 
    Send off the reply to an async Samba3 query, handling filling in the PAM, NTSTATUS and string errors.
@@ -253,7 +252,7 @@ static void userdomgroups_recv_groups(struct composite_context *ctx)
        }
 
        for (i=0; i<num_sids; i++) {
-               sids_string = talloc_asprintf_append(
+               sids_string = talloc_asprintf_append_buffer(
                        sids_string, "%s\n", dom_sid_string(s3call, sids[i]));
        }
 
@@ -320,7 +319,7 @@ static void usersids_recv_sids(struct composite_context *ctx)
        }
 
        for (i=0; i<num_sids; i++) {
-               sids_string = talloc_asprintf_append(
+               sids_string = talloc_asprintf_append_buffer(
                        sids_string, "%s\n", dom_sid_string(s3call, sids[i]));
                if (sids_string == NULL) {
                        status = NT_STATUS_NO_MEMORY;
@@ -621,7 +620,7 @@ static void list_trustdom_recv_doms(struct composite_context *ctx)
        }
 
        for (i=0; i<num_domains; i++) {
-               result = talloc_asprintf_append(
+               result = talloc_asprintf_append_buffer(
                        result, "%s\\%s\\%s",
                        domains[i]->name, domains[i]->name,
                        dom_sid_string(s3call, domains[i]->sid));
@@ -798,16 +797,65 @@ static void setpwent_recv(struct composite_context *ctx)
        wbsrv_samba3_async_epilogue(status, s3call);
 }
 
+static void getpwent_recv(struct composite_context *ctx);
+
 NTSTATUS wbsrv_samba3_getpwent(struct wbsrv_samba3_call *s3call)
 {
+       struct composite_context *ctx;
+       struct wbsrv_service *service = s3call->wbconn->listen_socket->service;
+       struct wbsrv_pwent *pwent;
+
        DEBUG(5, ("wbsrv_samba3_getpwent called\n"));
-       s3call->response.result = WINBINDD_ERROR;
+
+       NT_STATUS_HAVE_NO_MEMORY(s3call->wbconn->protocol_private_data);
+
+       pwent = talloc_get_type(s3call->wbconn->protocol_private_data,
+                       struct wbsrv_pwent);
+       NT_STATUS_HAVE_NO_MEMORY(pwent);
+
+       ctx = wb_cmd_getpwent_send(s3call, service, pwent,
+                       s3call->request.data.num_entries);
+       NT_STATUS_HAVE_NO_MEMORY(ctx);
+
+       ctx->async.fn = getpwent_recv;
+       ctx->async.private_data = s3call;
+       s3call->flags |= WBSRV_CALL_FLAGS_REPLY_ASYNC;
        return NT_STATUS_OK;
 }
 
+static void getpwent_recv(struct composite_context *ctx)
+{
+       struct wbsrv_samba3_call *s3call =
+               talloc_get_type(ctx->async.private_data,
+                               struct wbsrv_samba3_call);
+       NTSTATUS status;
+       struct winbindd_pw *pw;
+       uint32_t num_users;
+
+       DEBUG(5, ("getpwent_recv called\n"));
+
+       status = wb_cmd_getpwent_recv(ctx, s3call, &pw, &num_users);
+       if (NT_STATUS_IS_OK(status)) {
+               uint32_t extra_len = sizeof(struct winbindd_pw) * num_users;
+
+               s3call->response.data.num_entries = num_users;
+               s3call->response.extra_data.data = pw;
+               s3call->response.length += extra_len;
+       }
+
+       wbsrv_samba3_async_epilogue(status, s3call);
+}
+
 NTSTATUS wbsrv_samba3_endpwent(struct wbsrv_samba3_call *s3call)
 {
+       struct wbsrv_pwent *pwent =
+               talloc_get_type(s3call->wbconn->protocol_private_data,
+                               struct wbsrv_pwent);
        DEBUG(5, ("wbsrv_samba3_endpwent called\n"));
+
+       talloc_free(pwent);
+
+       s3call->wbconn->protocol_private_data = NULL;
        s3call->response.result = WINBINDD_OK;
        return NT_STATUS_OK;
 }