| 1 | /* 
 | 
|---|
| 2 |    Unix SMB/CIFS implementation.
 | 
|---|
| 3 |    Main winbindd irpc handlers
 | 
|---|
| 4 | 
 | 
|---|
| 5 |    Copyright (C) Stefan Metzmacher      2006
 | 
|---|
| 6 |    
 | 
|---|
| 7 |    This program is free software; you can redistribute it and/or modify
 | 
|---|
| 8 |    it under the terms of the GNU General Public License as published by
 | 
|---|
| 9 |    the Free Software Foundation; either version 3 of the License, or
 | 
|---|
| 10 |    (at your option) any later version.
 | 
|---|
| 11 |    
 | 
|---|
| 12 |    This program is distributed in the hope that it will be useful,
 | 
|---|
| 13 |    but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
|---|
| 14 |    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
|---|
| 15 |    GNU General Public License for more details.
 | 
|---|
| 16 |    
 | 
|---|
| 17 |    You should have received a copy of the GNU General Public License
 | 
|---|
| 18 |    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | 
|---|
| 19 | */
 | 
|---|
| 20 | 
 | 
|---|
| 21 | #include "includes.h"
 | 
|---|
| 22 | #include "winbind/wb_server.h"
 | 
|---|
| 23 | #include "lib/messaging/irpc.h"
 | 
|---|
| 24 | #include "libcli/composite/composite.h"
 | 
|---|
| 25 | #include "librpc/gen_ndr/ndr_winbind.h"
 | 
|---|
| 26 | #include "smbd/service_task.h"
 | 
|---|
| 27 | 
 | 
|---|
| 28 | struct wb_irpc_SamLogon_state {
 | 
|---|
| 29 |         struct irpc_message *msg;
 | 
|---|
| 30 |         struct winbind_SamLogon *req;
 | 
|---|
| 31 | };
 | 
|---|
| 32 | 
 | 
|---|
| 33 | static void wb_irpc_SamLogon_callback(struct composite_context *ctx);
 | 
|---|
| 34 | 
 | 
|---|
| 35 | static NTSTATUS wb_irpc_SamLogon(struct irpc_message *msg, 
 | 
|---|
| 36 |                                  struct winbind_SamLogon *req)
 | 
|---|
| 37 | {
 | 
|---|
| 38 |         struct wbsrv_service *service = talloc_get_type(msg->private_data,
 | 
|---|
| 39 |                                         struct wbsrv_service);
 | 
|---|
| 40 |         struct wb_irpc_SamLogon_state *s;
 | 
|---|
| 41 |         struct composite_context *ctx;
 | 
|---|
| 42 | 
 | 
|---|
| 43 |         DEBUG(5, ("wb_irpc_SamLogon called\n"));
 | 
|---|
| 44 | 
 | 
|---|
| 45 |         s = talloc(msg, struct wb_irpc_SamLogon_state);
 | 
|---|
| 46 |         NT_STATUS_HAVE_NO_MEMORY(s);
 | 
|---|
| 47 | 
 | 
|---|
| 48 |         s->msg = msg;
 | 
|---|
| 49 |         s->req = req;
 | 
|---|
| 50 | 
 | 
|---|
| 51 |         ctx = wb_sam_logon_send(msg, service, req);
 | 
|---|
| 52 |         NT_STATUS_HAVE_NO_MEMORY(ctx);
 | 
|---|
| 53 | 
 | 
|---|
| 54 |         ctx->async.fn = wb_irpc_SamLogon_callback;
 | 
|---|
| 55 |         ctx->async.private_data = s;
 | 
|---|
| 56 | 
 | 
|---|
| 57 |         msg->defer_reply = true;
 | 
|---|
| 58 |         return NT_STATUS_OK;
 | 
|---|
| 59 | }
 | 
|---|
| 60 | 
 | 
|---|
| 61 | static void wb_irpc_SamLogon_callback(struct composite_context *ctx)
 | 
|---|
| 62 | {
 | 
|---|
| 63 |         struct wb_irpc_SamLogon_state *s = talloc_get_type(ctx->async.private_data,
 | 
|---|
| 64 |                                            struct wb_irpc_SamLogon_state);
 | 
|---|
| 65 |         NTSTATUS status;
 | 
|---|
| 66 | 
 | 
|---|
| 67 |         DEBUG(5, ("wb_irpc_SamLogon_callback called\n"));
 | 
|---|
| 68 | 
 | 
|---|
| 69 |         status = wb_sam_logon_recv(ctx, s, s->req);
 | 
|---|
| 70 | 
 | 
|---|
| 71 |         irpc_send_reply(s->msg, status);
 | 
|---|
| 72 | }
 | 
|---|
| 73 | 
 | 
|---|
| 74 | struct wb_irpc_DsrUpdateReadOnlyServerDnsRecords_state {
 | 
|---|
| 75 |         struct irpc_message *msg;
 | 
|---|
| 76 |         struct winbind_DsrUpdateReadOnlyServerDnsRecords *req;
 | 
|---|
| 77 | };
 | 
|---|
| 78 | 
 | 
|---|
| 79 | static void wb_irpc_DsrUpdateReadOnlyServerDnsRecords_callback(struct composite_context *ctx);
 | 
|---|
| 80 | 
 | 
|---|
| 81 | static NTSTATUS wb_irpc_DsrUpdateReadOnlyServerDnsRecords(struct irpc_message *msg,
 | 
|---|
| 82 |                                  struct winbind_DsrUpdateReadOnlyServerDnsRecords *req)
 | 
|---|
| 83 | {
 | 
|---|
| 84 |         struct wbsrv_service *service = talloc_get_type(msg->private_data,
 | 
|---|
| 85 |                                         struct wbsrv_service);
 | 
|---|
| 86 |         struct wb_irpc_DsrUpdateReadOnlyServerDnsRecords_state *s;
 | 
|---|
| 87 |         struct composite_context *ctx;
 | 
|---|
| 88 | 
 | 
|---|
| 89 |         DEBUG(5, ("wb_irpc_DsrUpdateReadOnlyServerDnsRecords called\n"));
 | 
|---|
| 90 | 
 | 
|---|
| 91 |         s = talloc(msg, struct wb_irpc_DsrUpdateReadOnlyServerDnsRecords_state);
 | 
|---|
| 92 |         NT_STATUS_HAVE_NO_MEMORY(s);
 | 
|---|
| 93 | 
 | 
|---|
| 94 |         s->msg = msg;
 | 
|---|
| 95 |         s->req = req;
 | 
|---|
| 96 | 
 | 
|---|
| 97 |         ctx = wb_update_rodc_dns_send(msg, service, req);
 | 
|---|
| 98 |         NT_STATUS_HAVE_NO_MEMORY(ctx);
 | 
|---|
| 99 | 
 | 
|---|
| 100 |         ctx->async.fn = wb_irpc_DsrUpdateReadOnlyServerDnsRecords_callback;
 | 
|---|
| 101 |         ctx->async.private_data = s;
 | 
|---|
| 102 | 
 | 
|---|
| 103 |         msg->defer_reply = true;
 | 
|---|
| 104 |         return NT_STATUS_OK;
 | 
|---|
| 105 | }
 | 
|---|
| 106 | 
 | 
|---|
| 107 | static void wb_irpc_DsrUpdateReadOnlyServerDnsRecords_callback(struct composite_context *ctx)
 | 
|---|
| 108 | {
 | 
|---|
| 109 |         struct wb_irpc_DsrUpdateReadOnlyServerDnsRecords_state *s = talloc_get_type(ctx->async.private_data,
 | 
|---|
| 110 |                                            struct wb_irpc_DsrUpdateReadOnlyServerDnsRecords_state);
 | 
|---|
| 111 |         NTSTATUS status;
 | 
|---|
| 112 | 
 | 
|---|
| 113 |         DEBUG(5, ("wb_irpc_DsrUpdateReadOnlyServerDnsRecords_callback called\n"));
 | 
|---|
| 114 | 
 | 
|---|
| 115 |         status = wb_update_rodc_dns_recv(ctx, s, s->req);
 | 
|---|
| 116 | 
 | 
|---|
| 117 |         irpc_send_reply(s->msg, status);
 | 
|---|
| 118 | }
 | 
|---|
| 119 | 
 | 
|---|
| 120 | struct wb_irpc_get_idmap_state {
 | 
|---|
| 121 |         struct irpc_message *msg;
 | 
|---|
| 122 |         struct winbind_get_idmap *req;
 | 
|---|
| 123 |         int level;
 | 
|---|
| 124 | };
 | 
|---|
| 125 | 
 | 
|---|
| 126 | static void wb_irpc_get_idmap_callback(struct composite_context *ctx);
 | 
|---|
| 127 | 
 | 
|---|
| 128 | static NTSTATUS wb_irpc_get_idmap(struct irpc_message *msg,
 | 
|---|
| 129 |                                   struct winbind_get_idmap *req)
 | 
|---|
| 130 | {
 | 
|---|
| 131 |         struct wbsrv_service *service = talloc_get_type(msg->private_data,
 | 
|---|
| 132 |                                         struct wbsrv_service);
 | 
|---|
| 133 |         struct wb_irpc_get_idmap_state *s;
 | 
|---|
| 134 |         struct composite_context *ctx = NULL;
 | 
|---|
| 135 | 
 | 
|---|
| 136 |         DEBUG(5, ("wb_irpc_get_idmap called\n"));
 | 
|---|
| 137 | 
 | 
|---|
| 138 |         s = talloc(msg, struct wb_irpc_get_idmap_state);
 | 
|---|
| 139 |         NT_STATUS_HAVE_NO_MEMORY(s);
 | 
|---|
| 140 | 
 | 
|---|
| 141 |         s->msg = msg;
 | 
|---|
| 142 |         s->req = req;
 | 
|---|
| 143 |         s->level = req->in.level;
 | 
|---|
| 144 | 
 | 
|---|
| 145 |         switch(s->level) {
 | 
|---|
| 146 |                 case WINBIND_IDMAP_LEVEL_SIDS_TO_XIDS:
 | 
|---|
| 147 |                         ctx = wb_sids2xids_send(msg, service, req->in.count,
 | 
|---|
| 148 |                                                 req->in.ids);
 | 
|---|
| 149 |                         break;
 | 
|---|
| 150 |                 case WINBIND_IDMAP_LEVEL_XIDS_TO_SIDS:
 | 
|---|
| 151 |                         ctx = wb_xids2sids_send(msg, service, req->in.count,
 | 
|---|
| 152 |                                                 req->in.ids);
 | 
|---|
| 153 |                         break;
 | 
|---|
| 154 |         }
 | 
|---|
| 155 |         NT_STATUS_HAVE_NO_MEMORY(ctx);
 | 
|---|
| 156 | 
 | 
|---|
| 157 |         composite_continue(ctx, ctx, wb_irpc_get_idmap_callback, s);
 | 
|---|
| 158 |         msg->defer_reply = true;
 | 
|---|
| 159 | 
 | 
|---|
| 160 |         return NT_STATUS_OK;
 | 
|---|
| 161 | }
 | 
|---|
| 162 | 
 | 
|---|
| 163 | static void wb_irpc_get_idmap_callback(struct composite_context *ctx)
 | 
|---|
| 164 | {
 | 
|---|
| 165 |         struct wb_irpc_get_idmap_state *s;
 | 
|---|
| 166 |         NTSTATUS status;
 | 
|---|
| 167 | 
 | 
|---|
| 168 |         DEBUG(5, ("wb_irpc_get_idmap_callback called\n"));
 | 
|---|
| 169 | 
 | 
|---|
| 170 |         s = talloc_get_type(ctx->async.private_data,
 | 
|---|
| 171 |                             struct wb_irpc_get_idmap_state);
 | 
|---|
| 172 | 
 | 
|---|
| 173 |         switch(s->level) {
 | 
|---|
| 174 |                 case WINBIND_IDMAP_LEVEL_SIDS_TO_XIDS:
 | 
|---|
| 175 |                         status = wb_sids2xids_recv(ctx, &s->req->out.ids);
 | 
|---|
| 176 |                         break;
 | 
|---|
| 177 |                 case WINBIND_IDMAP_LEVEL_XIDS_TO_SIDS:
 | 
|---|
| 178 |                         status = wb_xids2sids_recv(ctx, &s->req->out.ids);
 | 
|---|
| 179 |                         break;
 | 
|---|
| 180 |                 default:
 | 
|---|
| 181 |                         status = NT_STATUS_INTERNAL_ERROR;
 | 
|---|
| 182 |                         break;
 | 
|---|
| 183 |         }
 | 
|---|
| 184 | 
 | 
|---|
| 185 |         irpc_send_reply(s->msg, status);
 | 
|---|
| 186 | }
 | 
|---|
| 187 | 
 | 
|---|
| 188 | NTSTATUS wbsrv_init_irpc(struct wbsrv_service *service)
 | 
|---|
| 189 | {
 | 
|---|
| 190 |         NTSTATUS status;
 | 
|---|
| 191 | 
 | 
|---|
| 192 |         irpc_add_name(service->task->msg_ctx, "winbind_server");
 | 
|---|
| 193 | 
 | 
|---|
| 194 |         status = IRPC_REGISTER(service->task->msg_ctx, winbind, WINBIND_SAMLOGON,
 | 
|---|
| 195 |                                wb_irpc_SamLogon, service);
 | 
|---|
| 196 |         NT_STATUS_NOT_OK_RETURN(status);
 | 
|---|
| 197 | 
 | 
|---|
| 198 |         status = IRPC_REGISTER(service->task->msg_ctx, winbind, WINBIND_DSRUPDATEREADONLYSERVERDNSRECORDS,
 | 
|---|
| 199 |                                wb_irpc_DsrUpdateReadOnlyServerDnsRecords, service);
 | 
|---|
| 200 |         NT_STATUS_NOT_OK_RETURN(status);
 | 
|---|
| 201 | 
 | 
|---|
| 202 |         status = IRPC_REGISTER(service->task->msg_ctx, winbind, WINBIND_GET_IDMAP,
 | 
|---|
| 203 |                                wb_irpc_get_idmap, service);
 | 
|---|
| 204 |         NT_STATUS_NOT_OK_RETURN(status);
 | 
|---|
| 205 | 
 | 
|---|
| 206 |         return NT_STATUS_OK;
 | 
|---|
| 207 | }
 | 
|---|