81
93
struct stream_connection *conn;
83
95
/* the kdc_server the connection belongs to */
84
struct kdc_server *kdc;
86
struct packet_context *packet;
88
kdc_process_fn_t process;
96
struct kdc_socket *kdc_socket;
98
struct tstream_context *tstream;
100
struct tevent_queue *send_queue;
92
handle fd send events on a KDC socket
94
static void kdc_send_handler(struct kdc_socket *kdc_socket)
96
while (kdc_socket->send_queue) {
97
struct kdc_reply *rep = kdc_socket->send_queue;
101
status = socket_sendto(kdc_socket->sock, &rep->packet, &sendlen,
103
if (NT_STATUS_EQUAL(status, STATUS_MORE_ENTRIES)) {
106
if (NT_STATUS_EQUAL(status, NT_STATUS_INVALID_BUFFER_SIZE)) {
107
/* Replace with a krb err, response to big */
110
DLIST_REMOVE(kdc_socket->send_queue, rep);
114
if (kdc_socket->send_queue == NULL) {
115
EVENT_FD_NOT_WRITEABLE(kdc_socket->fde);
121
handle fd recv events on a KDC socket
123
static void kdc_recv_handler(struct kdc_socket *kdc_socket)
126
TALLOC_CTX *tmp_ctx = talloc_new(kdc_socket);
128
struct kdc_reply *rep;
131
struct socket_address *src;
132
struct socket_address *my_addr;
135
status = socket_pending(kdc_socket->sock, &dsize);
136
if (!NT_STATUS_IS_OK(status)) {
137
talloc_free(tmp_ctx);
141
blob = data_blob_talloc(tmp_ctx, NULL, dsize);
142
if (blob.data == NULL) {
143
/* hope this is a temporary low memory condition */
144
talloc_free(tmp_ctx);
148
status = socket_recvfrom(kdc_socket->sock, blob.data, blob.length, &nread,
150
if (!NT_STATUS_IS_OK(status)) {
151
talloc_free(tmp_ctx);
156
DEBUG(10,("Received krb5 UDP packet of length %lu from %s:%u\n",
157
(long)blob.length, src->addr, (uint16_t)src->port));
159
my_addr = socket_get_my_addr(kdc_socket->sock, tmp_ctx);
161
talloc_free(tmp_ctx);
167
ret = kdc_socket->process(kdc_socket->kdc,
174
talloc_free(tmp_ctx);
178
/* queue a pending reply */
179
rep = talloc(kdc_socket, struct kdc_reply);
181
talloc_free(tmp_ctx);
184
rep->dest = talloc_steal(rep, src);
186
talloc_steal(rep, reply.data);
188
if (rep->packet.data == NULL) {
190
talloc_free(tmp_ctx);
194
DLIST_ADD_END(kdc_socket->send_queue, rep, struct kdc_reply *);
195
EVENT_FD_WRITEABLE(kdc_socket->fde);
196
talloc_free(tmp_ctx);
200
handle fd events on a KDC socket
202
static void kdc_socket_handler(struct tevent_context *ev, struct tevent_fd *fde,
203
uint16_t flags, void *private_data)
205
struct kdc_socket *kdc_socket = talloc_get_type(private_data, struct kdc_socket);
206
if (flags & EVENT_FD_WRITE) {
207
kdc_send_handler(kdc_socket);
209
if (flags & EVENT_FD_READ) {
210
kdc_recv_handler(kdc_socket);
214
104
static void kdc_tcp_terminate_connection(struct kdc_tcp_connection *kdcconn, const char *reason)
216
106
stream_terminate_connection(kdcconn->conn, reason);
220
receive a full packet on a KDC connection
222
static NTSTATUS kdc_tcp_recv(void *private_data, DATA_BLOB blob)
224
struct kdc_tcp_connection *kdcconn = talloc_get_type(private_data,
225
struct kdc_tcp_connection);
226
NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
227
TALLOC_CTX *tmp_ctx = talloc_new(kdcconn);
229
DATA_BLOB input, reply;
230
struct socket_address *src_addr;
231
struct socket_address *my_addr;
233
talloc_steal(tmp_ctx, blob.data);
235
src_addr = socket_get_peer_addr(kdcconn->conn->socket, tmp_ctx);
237
talloc_free(tmp_ctx);
238
return NT_STATUS_NO_MEMORY;
241
my_addr = socket_get_my_addr(kdcconn->conn->socket, tmp_ctx);
243
talloc_free(tmp_ctx);
244
return NT_STATUS_NO_MEMORY;
248
input = data_blob_const(blob.data + 4, blob.length - 4);
250
ret = kdcconn->process(kdcconn->kdc,
256
0 /* Not datagram */);
258
talloc_free(tmp_ctx);
259
return NT_STATUS_INTERNAL_ERROR;
262
/* and now encode the reply */
263
blob = data_blob_talloc(kdcconn, NULL, reply.length + 4);
265
talloc_free(tmp_ctx);
266
return NT_STATUS_NO_MEMORY;
269
RSIVAL(blob.data, 0, reply.length);
270
memcpy(blob.data + 4, reply.data, reply.length);
272
status = packet_send(kdcconn->packet, blob);
273
if (!NT_STATUS_IS_OK(status)) {
274
talloc_free(tmp_ctx);
278
/* the call isn't needed any more */
279
talloc_free(tmp_ctx);
284
receive some data on a KDC connection
286
static void kdc_tcp_recv_handler(struct stream_connection *conn, uint16_t flags)
109
static void kdc_tcp_recv(struct stream_connection *conn, uint16_t flags)
288
111
struct kdc_tcp_connection *kdcconn = talloc_get_type(conn->private_data,
289
112
struct kdc_tcp_connection);
290
packet_recv(kdcconn->packet);
294
called on a tcp recv error
296
static void kdc_tcp_recv_error(void *private_data, NTSTATUS status)
298
struct kdc_tcp_connection *kdcconn = talloc_get_type(private_data,
299
struct kdc_tcp_connection);
300
kdc_tcp_terminate_connection(kdcconn, nt_errstr(status));
304
called when we can write to a connection
113
/* this should never be triggered! */
114
kdc_tcp_terminate_connection(kdcconn, "kdc_tcp_recv: called");
306
117
static void kdc_tcp_send(struct stream_connection *conn, uint16_t flags)
308
119
struct kdc_tcp_connection *kdcconn = talloc_get_type(conn->private_data,
309
120
struct kdc_tcp_connection);
310
packet_queue_run(kdcconn->packet);
121
/* this should never be triggered! */
122
kdc_tcp_terminate_connection(kdcconn, "kdc_tcp_send: called");
315
127
calling conventions
318
static bool kdc_process(struct kdc_server *kdc,
322
struct socket_address *peer_addr,
323
struct socket_address *my_addr,
130
static enum kdc_process_ret kdc_process(struct kdc_server *kdc,
134
struct tsocket_address *peer_addr,
135
struct tsocket_address *my_addr,
140
struct sockaddr_storage ss;
327
141
krb5_data k5_reply;
328
142
krb5_data_zero(&k5_reply);
330
144
krb5_kdc_update_time(NULL);
332
DEBUG(10,("Received KDC packet of length %lu from %s:%d\n",
333
(long)input->length - 4, peer_addr->addr, peer_addr->port));
335
ret = krb5_kdc_process_krb5_request(kdc->smb_krb5_context->krb5_context,
146
ret = tsocket_address_bsd_sockaddr(peer_addr, (struct sockaddr *) &ss,
147
sizeof(struct sockaddr_storage));
149
return KDC_PROCESS_FAILED;
151
pa = tsocket_address_string(peer_addr, mem_ctx);
153
return KDC_PROCESS_FAILED;
156
DEBUG(10,("Received KDC packet of length %lu from %s\n",
157
(long)input->length - 4, pa));
159
ret = krb5_kdc_process_krb5_request(kdc->smb_krb5_context->krb5_context,
337
161
input->data, input->length,
164
(struct sockaddr *) &ss,
343
167
*reply = data_blob(NULL, 0);
168
return KDC_PROCESS_FAILED;
171
if (ret == HDB_ERR_NOT_FOUND_HERE) {
172
*reply = data_blob(NULL, 0);
173
return KDC_PROCESS_PROXY;
346
176
if (k5_reply.length) {
347
177
*reply = data_blob_talloc(mem_ctx, k5_reply.data, k5_reply.length);
348
178
krb5_data_free(&k5_reply);
350
*reply = data_blob(NULL, 0);
180
*reply = data_blob(NULL, 0);
182
return KDC_PROCESS_OK;
185
static void kdc_tcp_call_proxy_done(struct tevent_req *subreq);
186
static void kdc_tcp_call_writev_done(struct tevent_req *subreq);
188
static void kdc_tcp_call_loop(struct tevent_req *subreq)
190
struct kdc_tcp_connection *kdc_conn = tevent_req_callback_data(subreq,
191
struct kdc_tcp_connection);
192
struct kdc_tcp_call *call;
194
enum kdc_process_ret ret;
196
call = talloc(kdc_conn, struct kdc_tcp_call);
198
kdc_tcp_terminate_connection(kdc_conn, "kdc_tcp_call_loop: "
199
"no memory for kdc_tcp_call");
202
call->kdc_conn = kdc_conn;
204
status = tstream_read_pdu_blob_recv(subreq,
208
if (!NT_STATUS_IS_OK(status)) {
211
reason = talloc_asprintf(call, "kdc_tcp_call_loop: "
212
"tstream_read_pdu_blob_recv() - %s",
215
reason = nt_errstr(status);
218
kdc_tcp_terminate_connection(kdc_conn, reason);
222
DEBUG(10,("Received krb5 TCP packet of length %lu from %s\n",
223
(long) call->in.length,
224
tsocket_address_string(kdc_conn->conn->remote_address, call)));
226
/* skip length header */
228
call->in.length -= 4;
231
ret = kdc_conn->kdc_socket->process(kdc_conn->kdc_socket->kdc,
235
kdc_conn->conn->remote_address,
236
kdc_conn->conn->local_address,
238
if (ret == KDC_PROCESS_FAILED) {
239
kdc_tcp_terminate_connection(kdc_conn,
240
"kdc_tcp_call_loop: process function failed");
244
if (ret == KDC_PROCESS_PROXY) {
247
if (!kdc_conn->kdc_socket->kdc->am_rodc) {
248
kdc_tcp_terminate_connection(kdc_conn,
249
"kdc_tcp_call_loop: proxying requested when not RODC");
252
port = tsocket_address_inet_port(kdc_conn->conn->local_address);
254
subreq = kdc_tcp_proxy_send(call,
255
kdc_conn->conn->event.ctx,
256
kdc_conn->kdc_socket->kdc,
259
if (subreq == NULL) {
260
kdc_tcp_terminate_connection(kdc_conn,
261
"kdc_tcp_call_loop: kdc_tcp_proxy_send failed");
264
tevent_req_set_callback(subreq, kdc_tcp_call_proxy_done, call);
268
/* First add the length of the out buffer */
269
RSIVAL(call->out_hdr, 0, call->out.length);
270
call->out_iov[0].iov_base = (char *) call->out_hdr;
271
call->out_iov[0].iov_len = 4;
273
call->out_iov[1].iov_base = (char *) call->out.data;
274
call->out_iov[1].iov_len = call->out.length;
276
subreq = tstream_writev_queue_send(call,
277
kdc_conn->conn->event.ctx,
279
kdc_conn->send_queue,
281
if (subreq == NULL) {
282
kdc_tcp_terminate_connection(kdc_conn, "kdc_tcp_call_loop: "
283
"no memory for tstream_writev_queue_send");
286
tevent_req_set_callback(subreq, kdc_tcp_call_writev_done, call);
289
* The krb5 tcp pdu's has the length as 4 byte (initial_read_size),
290
* packet_full_request_u32 provides the pdu length then.
292
subreq = tstream_read_pdu_blob_send(kdc_conn,
293
kdc_conn->conn->event.ctx,
295
4, /* initial_read_size */
296
packet_full_request_u32,
298
if (subreq == NULL) {
299
kdc_tcp_terminate_connection(kdc_conn, "kdc_tcp_call_loop: "
300
"no memory for tstream_read_pdu_blob_send");
303
tevent_req_set_callback(subreq, kdc_tcp_call_loop, kdc_conn);
306
static void kdc_tcp_call_proxy_done(struct tevent_req *subreq)
308
struct kdc_tcp_call *call = tevent_req_callback_data(subreq,
309
struct kdc_tcp_call);
310
struct kdc_tcp_connection *kdc_conn = call->kdc_conn;
313
status = kdc_tcp_proxy_recv(subreq, call, &call->out);
315
if (!NT_STATUS_IS_OK(status)) {
316
/* generate an error packet */
317
status = kdc_proxy_unavailable_error(kdc_conn->kdc_socket->kdc,
321
if (!NT_STATUS_IS_OK(status)) {
324
reason = talloc_asprintf(call, "kdc_tcp_call_proxy_done: "
325
"kdc_proxy_unavailable_error - %s",
328
reason = "kdc_tcp_call_proxy_done: kdc_proxy_unavailable_error() failed";
331
kdc_tcp_terminate_connection(call->kdc_conn, reason);
335
/* First add the length of the out buffer */
336
RSIVAL(call->out_hdr, 0, call->out.length);
337
call->out_iov[0].iov_base = (char *) call->out_hdr;
338
call->out_iov[0].iov_len = 4;
340
call->out_iov[1].iov_base = (char *) call->out.data;
341
call->out_iov[1].iov_len = call->out.length;
343
subreq = tstream_writev_queue_send(call,
344
kdc_conn->conn->event.ctx,
346
kdc_conn->send_queue,
348
if (subreq == NULL) {
349
kdc_tcp_terminate_connection(kdc_conn, "kdc_tcp_call_loop: "
350
"no memory for tstream_writev_queue_send");
353
tevent_req_set_callback(subreq, kdc_tcp_call_writev_done, call);
356
* The krb5 tcp pdu's has the length as 4 byte (initial_read_size),
357
* packet_full_request_u32 provides the pdu length then.
359
subreq = tstream_read_pdu_blob_send(kdc_conn,
360
kdc_conn->conn->event.ctx,
362
4, /* initial_read_size */
363
packet_full_request_u32,
365
if (subreq == NULL) {
366
kdc_tcp_terminate_connection(kdc_conn, "kdc_tcp_call_loop: "
367
"no memory for tstream_read_pdu_blob_send");
370
tevent_req_set_callback(subreq, kdc_tcp_call_loop, kdc_conn);
373
static void kdc_tcp_call_writev_done(struct tevent_req *subreq)
375
struct kdc_tcp_call *call = tevent_req_callback_data(subreq,
376
struct kdc_tcp_call);
380
rc = tstream_writev_queue_recv(subreq, &sys_errno);
385
reason = talloc_asprintf(call, "kdc_tcp_call_writev_done: "
386
"tstream_writev_queue_recv() - %d:%s",
387
sys_errno, strerror(sys_errno));
389
reason = "kdc_tcp_call_writev_done: tstream_writev_queue_recv() failed";
392
kdc_tcp_terminate_connection(call->kdc_conn, reason);
396
/* We don't care about errors */
356
402
called when we get a new connection
358
static void kdc_tcp_generic_accept(struct stream_connection *conn, kdc_process_fn_t process_fn)
360
struct kdc_server *kdc = talloc_get_type(conn->private_data, struct kdc_server);
361
struct kdc_tcp_connection *kdcconn;
363
kdcconn = talloc_zero(conn, struct kdc_tcp_connection);
365
stream_terminate_connection(conn, "kdc_tcp_accept: out of memory");
368
kdcconn->conn = conn;
370
kdcconn->process = process_fn;
371
conn->private_data = kdcconn;
373
kdcconn->packet = packet_init(kdcconn);
374
if (kdcconn->packet == NULL) {
375
kdc_tcp_terminate_connection(kdcconn, "kdc_tcp_accept: out of memory");
378
packet_set_private(kdcconn->packet, kdcconn);
379
packet_set_socket(kdcconn->packet, conn->socket);
380
packet_set_callback(kdcconn->packet, kdc_tcp_recv);
381
packet_set_full_request(kdcconn->packet, packet_full_request_u32);
382
packet_set_error_handler(kdcconn->packet, kdc_tcp_recv_error);
383
packet_set_event_context(kdcconn->packet, conn->event.ctx);
384
packet_set_fde(kdcconn->packet, conn->event.fde);
385
packet_set_serialise(kdcconn->packet);
388
404
static void kdc_tcp_accept(struct stream_connection *conn)
390
kdc_tcp_generic_accept(conn, kdc_process);
406
struct kdc_socket *kdc_socket;
407
struct kdc_tcp_connection *kdc_conn;
408
struct tevent_req *subreq;
411
kdc_conn = talloc_zero(conn, struct kdc_tcp_connection);
412
if (kdc_conn == NULL) {
413
stream_terminate_connection(conn,
414
"kdc_tcp_accept: out of memory");
418
kdc_conn->send_queue = tevent_queue_create(conn, "kdc_tcp_accept");
419
if (kdc_conn->send_queue == NULL) {
420
stream_terminate_connection(conn,
421
"kdc_tcp_accept: out of memory");
425
kdc_socket = talloc_get_type(conn->private_data, struct kdc_socket);
427
TALLOC_FREE(conn->event.fde);
429
rc = tstream_bsd_existing_socket(kdc_conn,
430
socket_get_fd(conn->socket),
433
stream_terminate_connection(conn,
434
"kdc_tcp_accept: out of memory");
438
kdc_conn->conn = conn;
439
kdc_conn->kdc_socket = kdc_socket;
440
conn->private_data = kdc_conn;
443
* The krb5 tcp pdu's has the length as 4 byte (initial_read_size),
444
* packet_full_request_u32 provides the pdu length then.
446
subreq = tstream_read_pdu_blob_send(kdc_conn,
447
kdc_conn->conn->event.ctx,
449
4, /* initial_read_size */
450
packet_full_request_u32,
452
if (subreq == NULL) {
453
kdc_tcp_terminate_connection(kdc_conn, "kdc_tcp_accept: "
454
"no memory for tstream_read_pdu_blob_send");
457
tevent_req_set_callback(subreq, kdc_tcp_call_loop, kdc_conn);
393
460
static const struct stream_server_ops kdc_tcp_stream_ops = {
394
461
.name = "kdc_tcp",
395
462
.accept_connection = kdc_tcp_accept,
396
.recv_handler = kdc_tcp_recv_handler,
397
.send_handler = kdc_tcp_send
400
static void kpasswdd_tcp_accept(struct stream_connection *conn)
402
kdc_tcp_generic_accept(conn, kpasswdd_process);
405
static const struct stream_server_ops kpasswdd_tcp_stream_ops = {
406
.name = "kpasswdd_tcp",
407
.accept_connection = kpasswdd_tcp_accept,
408
.recv_handler = kdc_tcp_recv_handler,
409
.send_handler = kdc_tcp_send
463
.recv_handler = kdc_tcp_recv,
464
.send_handler = kdc_tcp_send
467
/* hold information about one kdc/kpasswd udp socket */
468
struct kdc_udp_socket {
469
struct kdc_socket *kdc_socket;
470
struct tdgram_context *dgram;
471
struct tevent_queue *send_queue;
474
struct kdc_udp_call {
475
struct kdc_udp_socket *sock;
476
struct tsocket_address *src;
481
static void kdc_udp_call_proxy_done(struct tevent_req *subreq);
482
static void kdc_udp_call_sendto_done(struct tevent_req *subreq);
484
static void kdc_udp_call_loop(struct tevent_req *subreq)
486
struct kdc_udp_socket *sock = tevent_req_callback_data(subreq,
487
struct kdc_udp_socket);
488
struct kdc_udp_call *call;
492
enum kdc_process_ret ret;
494
call = talloc(sock, struct kdc_udp_call);
501
len = tdgram_recvfrom_recv(subreq, &sys_errno,
502
call, &buf, &call->src);
510
call->in.length = len;
512
DEBUG(10,("Received krb5 UDP packet of length %lu from %s\n",
513
(long)call->in.length,
514
tsocket_address_string(call->src, call)));
517
ret = sock->kdc_socket->process(sock->kdc_socket->kdc,
522
sock->kdc_socket->local_address,
524
if (ret == KDC_PROCESS_FAILED) {
529
if (ret == KDC_PROCESS_PROXY) {
532
if (!sock->kdc_socket->kdc->am_rodc) {
533
DEBUG(0,("kdc_udp_call_loop: proxying requested when not RODC"));
538
port = tsocket_address_inet_port(sock->kdc_socket->local_address);
540
subreq = kdc_udp_proxy_send(call,
541
sock->kdc_socket->kdc->task->event_ctx,
542
sock->kdc_socket->kdc,
545
if (subreq == NULL) {
549
tevent_req_set_callback(subreq, kdc_udp_call_proxy_done, call);
553
subreq = tdgram_sendto_queue_send(call,
554
sock->kdc_socket->kdc->task->event_ctx,
560
if (subreq == NULL) {
564
tevent_req_set_callback(subreq, kdc_udp_call_sendto_done, call);
567
subreq = tdgram_recvfrom_send(sock,
568
sock->kdc_socket->kdc->task->event_ctx,
570
if (subreq == NULL) {
571
task_server_terminate(sock->kdc_socket->kdc->task,
572
"no memory for tdgram_recvfrom_send",
576
tevent_req_set_callback(subreq, kdc_udp_call_loop, sock);
579
static void kdc_udp_call_proxy_done(struct tevent_req *subreq)
581
struct kdc_udp_call *call =
582
tevent_req_callback_data(subreq,
583
struct kdc_udp_call);
586
status = kdc_udp_proxy_recv(subreq, call, &call->out);
588
if (!NT_STATUS_IS_OK(status)) {
589
/* generate an error packet */
590
status = kdc_proxy_unavailable_error(call->sock->kdc_socket->kdc,
594
if (!NT_STATUS_IS_OK(status)) {
599
subreq = tdgram_sendto_queue_send(call,
600
call->sock->kdc_socket->kdc->task->event_ctx,
602
call->sock->send_queue,
606
if (subreq == NULL) {
611
tevent_req_set_callback(subreq, kdc_udp_call_sendto_done, call);
614
static void kdc_udp_call_sendto_done(struct tevent_req *subreq)
616
struct kdc_udp_call *call = tevent_req_callback_data(subreq,
617
struct kdc_udp_call);
621
ret = tdgram_sendto_queue_recv(subreq, &sys_errno);
623
/* We don't care about errors */
413
629
start listening on the given address
415
static NTSTATUS kdc_add_socket(struct kdc_server *kdc, const char *address,
416
uint16_t kdc_port, uint16_t kpasswd_port)
631
static NTSTATUS kdc_add_socket(struct kdc_server *kdc,
632
const struct model_ops *model_ops,
636
kdc_process_fn_t process,
418
const struct model_ops *model_ops;
419
struct kdc_socket *kdc_socket;
420
struct kdc_socket *kpasswd_socket;
421
struct socket_address *kdc_address, *kpasswd_address;
639
struct kdc_socket *kdc_socket;
640
struct kdc_udp_socket *kdc_udp_socket;
641
struct tevent_req *udpsubreq;
424
645
kdc_socket = talloc(kdc, struct kdc_socket);
425
646
NT_STATUS_HAVE_NO_MEMORY(kdc_socket);
427
kpasswd_socket = talloc(kdc, struct kdc_socket);
428
NT_STATUS_HAVE_NO_MEMORY(kpasswd_socket);
430
status = socket_create("ip", SOCKET_TYPE_DGRAM, &kdc_socket->sock, 0);
431
if (!NT_STATUS_IS_OK(status)) {
432
talloc_free(kdc_socket);
436
status = socket_create("ip", SOCKET_TYPE_DGRAM, &kpasswd_socket->sock, 0);
437
if (!NT_STATUS_IS_OK(status)) {
438
talloc_free(kpasswd_socket);
442
648
kdc_socket->kdc = kdc;
443
kdc_socket->send_queue = NULL;
444
kdc_socket->process = kdc_process;
446
talloc_steal(kdc_socket, kdc_socket->sock);
448
kdc_socket->fde = event_add_fd(kdc->task->event_ctx, kdc,
449
socket_get_fd(kdc_socket->sock), EVENT_FD_READ,
450
kdc_socket_handler, kdc_socket);
452
kdc_address = socket_address_from_strings(kdc_socket, kdc_socket->sock->backend_name,
454
NT_STATUS_HAVE_NO_MEMORY(kdc_address);
456
status = socket_listen(kdc_socket->sock, kdc_address, 0, 0);
457
if (!NT_STATUS_IS_OK(status)) {
458
DEBUG(0,("Failed to bind to %s:%d UDP for kdc - %s\n",
459
address, kdc_port, nt_errstr(status)));
460
talloc_free(kdc_socket);
464
kpasswd_socket->kdc = kdc;
465
kpasswd_socket->send_queue = NULL;
466
kpasswd_socket->process = kpasswdd_process;
468
talloc_steal(kpasswd_socket, kpasswd_socket->sock);
470
kpasswd_socket->fde = event_add_fd(kdc->task->event_ctx, kdc,
471
socket_get_fd(kpasswd_socket->sock), EVENT_FD_READ,
472
kdc_socket_handler, kpasswd_socket);
474
kpasswd_address = socket_address_from_strings(kpasswd_socket, kpasswd_socket->sock->backend_name,
475
address, kpasswd_port);
476
NT_STATUS_HAVE_NO_MEMORY(kpasswd_address);
478
status = socket_listen(kpasswd_socket->sock, kpasswd_address, 0, 0);
479
if (!NT_STATUS_IS_OK(status)) {
480
DEBUG(0,("Failed to bind to %s:%d UDP for kpasswd - %s\n",
481
address, kpasswd_port, nt_errstr(status)));
482
talloc_free(kpasswd_socket);
486
/* within the kdc task we want to be a single process, so
487
ask for the single process model ops and pass these to the
488
stream_setup_socket() call. */
489
model_ops = process_model_startup(kdc->task->event_ctx, "single");
491
DEBUG(0,("Can't find 'single' process model_ops\n"));
492
talloc_free(kdc_socket);
493
return NT_STATUS_INTERNAL_ERROR;
496
status = stream_setup_socket(kdc->task->event_ctx,
500
"ip", address, &kdc_port,
501
lp_socket_options(kdc->task->lp_ctx),
503
if (!NT_STATUS_IS_OK(status)) {
504
DEBUG(0,("Failed to bind to %s:%u TCP - %s\n",
505
address, kdc_port, nt_errstr(status)));
506
talloc_free(kdc_socket);
510
status = stream_setup_socket(kdc->task->event_ctx,
513
&kpasswdd_tcp_stream_ops,
514
"ip", address, &kpasswd_port,
515
lp_socket_options(kdc->task->lp_ctx),
517
if (!NT_STATUS_IS_OK(status)) {
518
DEBUG(0,("Failed to bind to %s:%u TCP - %s\n",
519
address, kpasswd_port, nt_errstr(status)));
520
talloc_free(kdc_socket);
649
kdc_socket->process = process;
651
ret = tsocket_address_inet_from_strings(kdc_socket, "ip",
653
&kdc_socket->local_address);
655
status = map_nt_error_from_unix(errno);
660
status = stream_setup_socket(kdc->task,
661
kdc->task->event_ctx,
665
"ip", address, &port,
666
lpcfg_socket_options(kdc->task->lp_ctx),
668
if (!NT_STATUS_IS_OK(status)) {
669
DEBUG(0,("Failed to bind to %s:%u TCP - %s\n",
670
address, port, nt_errstr(status)));
671
talloc_free(kdc_socket);
676
kdc_udp_socket = talloc(kdc_socket, struct kdc_udp_socket);
677
NT_STATUS_HAVE_NO_MEMORY(kdc_udp_socket);
679
kdc_udp_socket->kdc_socket = kdc_socket;
681
ret = tdgram_inet_udp_socket(kdc_socket->local_address,
684
&kdc_udp_socket->dgram);
686
status = map_nt_error_from_unix(errno);
687
DEBUG(0,("Failed to bind to %s:%u UDP - %s\n",
688
address, port, nt_errstr(status)));
692
kdc_udp_socket->send_queue = tevent_queue_create(kdc_udp_socket,
693
"kdc_udp_send_queue");
694
NT_STATUS_HAVE_NO_MEMORY(kdc_udp_socket->send_queue);
696
udpsubreq = tdgram_recvfrom_send(kdc_udp_socket,
697
kdc->task->event_ctx,
698
kdc_udp_socket->dgram);
699
NT_STATUS_HAVE_NO_MEMORY(udpsubreq);
700
tevent_req_set_callback(udpsubreq, kdc_udp_call_loop, kdc_udp_socket);
524
702
return NT_STATUS_OK;