r25398: Parse loadparm context to all lp_*() functions.
[gd/samba-autobuild/.git] / source4 / winbind / wb_samba3_cmd.c
index 29cf3573c19b7906bce22f84fc8fee5a01eceb0d..3ca2b02f4ab7f2bc7adbd22eb702bc7822c9a326 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.
@@ -87,7 +86,7 @@ NTSTATUS wbsrv_samba3_interface_version(struct wbsrv_samba3_call *s3call)
 NTSTATUS wbsrv_samba3_info(struct wbsrv_samba3_call *s3call)
 {
        s3call->response.result                 = WINBINDD_OK;
-       s3call->response.data.info.winbind_separator = *lp_winbind_separator();
+       s3call->response.data.info.winbind_separator = *lp_winbind_separator(global_loadparm);
        WBSRV_SAMBA3_SET_STRING(s3call->response.data.info.samba_version,
                                SAMBA_VERSION_STRING);
        return NT_STATUS_OK;
@@ -97,7 +96,7 @@ NTSTATUS wbsrv_samba3_domain_name(struct wbsrv_samba3_call *s3call)
 {
        s3call->response.result                 = WINBINDD_OK;
        WBSRV_SAMBA3_SET_STRING(s3call->response.data.domain_name,
-                               lp_workgroup());
+                               lp_workgroup(global_loadparm));
        return NT_STATUS_OK;
 }
 
@@ -105,7 +104,7 @@ NTSTATUS wbsrv_samba3_netbios_name(struct wbsrv_samba3_call *s3call)
 {
        s3call->response.result                 = WINBINDD_OK;
        WBSRV_SAMBA3_SET_STRING(s3call->response.data.netbios_name,
-                               lp_netbios_name());
+                               lp_netbios_name(global_loadparm));
        return NT_STATUS_OK;
 }
 
@@ -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));
@@ -642,6 +641,51 @@ static void list_trustdom_recv_doms(struct composite_context *ctx)
        wbsrv_samba3_async_epilogue(status, s3call);
 }
 
+
+/* List users */
+
+static void list_users_recv(struct composite_context *ctx);
+
+NTSTATUS wbsrv_samba3_list_users(struct wbsrv_samba3_call *s3call)
+{
+       struct composite_context *ctx;
+       struct wbsrv_service *service =
+               s3call->wbconn->listen_socket->service;
+
+       DEBUG(5, ("wbsrv_samba3_list_users called\n"));
+
+       ctx = wb_cmd_list_users_send(s3call, service,
+                       s3call->request.domain_name);
+       NT_STATUS_HAVE_NO_MEMORY(ctx);
+
+       ctx->async.fn = list_users_recv;
+       ctx->async.private_data = s3call;
+       s3call->flags |= WBSRV_CALL_FLAGS_REPLY_ASYNC;
+       return NT_STATUS_OK;
+}
+
+static void list_users_recv(struct composite_context *ctx)
+{
+       struct wbsrv_samba3_call *s3call =
+               talloc_get_type(ctx->async.private_data,
+                               struct wbsrv_samba3_call);
+       uint32_t extra_data_len;
+       char *extra_data;
+       NTSTATUS status;
+
+       DEBUG(5, ("list_users_recv called\n"));
+
+       status = wb_cmd_list_users_recv(ctx, s3call, &extra_data_len,
+                       &extra_data);
+
+       if (NT_STATUS_IS_OK(status)) {
+               s3call->response.extra_data.data = extra_data;
+               s3call->response.length += extra_data_len;
+       }
+
+       wbsrv_samba3_async_epilogue(status, s3call);
+}
+
 /* NSS calls */
 
 static void getpwnam_recv(struct composite_context *ctx);
@@ -717,23 +761,101 @@ static void getpwuid_recv(struct composite_context *ctx)
        wbsrv_samba3_async_epilogue(status, s3call);
 }
 
+static void setpwent_recv(struct composite_context *ctx);
+
 NTSTATUS wbsrv_samba3_setpwent(struct wbsrv_samba3_call *s3call)
 {
+       struct composite_context *ctx;
+       struct wbsrv_service *service = s3call->wbconn->listen_socket->service;
+
        DEBUG(5, ("wbsrv_samba3_setpwent called\n"));
-       s3call->response.result = WINBINDD_OK;
+
+       ctx = wb_cmd_setpwent_send(s3call, service);
+       NT_STATUS_HAVE_NO_MEMORY(ctx);
+
+       ctx->async.fn = setpwent_recv;
+       ctx->async.private_data = s3call;
+       s3call->flags |= WBSRV_CALL_FLAGS_REPLY_ASYNC;
        return NT_STATUS_OK;
 }
 
+static void setpwent_recv(struct composite_context *ctx)
+{
+       struct wbsrv_samba3_call *s3call =
+               talloc_get_type(ctx->async.private_data,
+                               struct wbsrv_samba3_call);
+       NTSTATUS status;
+       struct wbsrv_pwent *pwent;
+
+       DEBUG(5, ("setpwent_recv called\n"));
+
+       status = wb_cmd_setpwent_recv(ctx, s3call->wbconn, &pwent);
+       if (NT_STATUS_IS_OK(status)) {
+               s3call->wbconn->protocol_private_data = pwent;
+       }
+
+       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;
 }
@@ -789,7 +911,7 @@ NTSTATUS wbsrv_samba3_sid2uid(struct wbsrv_samba3_call *s3call)
                s3call->wbconn->listen_socket->service;
        struct dom_sid *sid;
 
-       DEBUG(1, ("wbsrv_samba3_sid2uid called\n"));
+       DEBUG(5, ("wbsrv_samba3_sid2uid called\n"));
 
        sid = dom_sid_parse_talloc(s3call, s3call->request.data.sid);
        NT_STATUS_HAVE_NO_MEMORY(sid);