Fixed null-pointer dereference in smp plugin.
[strongswan.git] / src / libcharon / plugins / smp / smp.c
1 /*
2 * Copyright (C) 2007 Martin Willi
3 * Hochschule fuer Technik Rapperswil
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 #include <stdlib.h>
17
18 #include "smp.h"
19
20 #include <sys/types.h>
21 #include <sys/stat.h>
22 #include <sys/socket.h>
23 #include <sys/un.h>
24 #include <unistd.h>
25 #include <errno.h>
26 #include <signal.h>
27 #include <libxml/xmlreader.h>
28 #include <libxml/xmlwriter.h>
29
30 #include <library.h>
31 #include <daemon.h>
32 #include <threading/thread.h>
33 #include <processing/jobs/callback_job.h>
34
35
36 typedef struct private_smp_t private_smp_t;
37
38 /**
39 * Private data of an smp_t object.
40 */
41 struct private_smp_t {
42
43 /**
44 * Public part of smp_t object.
45 */
46 smp_t public;
47
48 /**
49 * XML unix socket fd
50 */
51 int socket;
52
53 /**
54 * job accepting stroke messages
55 */
56 callback_job_t *job;
57 };
58
59 ENUM(ike_sa_state_lower_names, IKE_CREATED, IKE_DELETING,
60 "created",
61 "connecting",
62 "established",
63 "rekeying",
64 "deleting",
65 );
66
67 /**
68 * write a bool into element
69 */
70 static void write_bool(xmlTextWriterPtr writer, char *element, bool val)
71 {
72 xmlTextWriterWriteElement(writer, element, val ? "true" : "false");
73 }
74
75 /**
76 * write a identification_t into element
77 */
78 static void write_id(xmlTextWriterPtr writer, char *element, identification_t *id)
79 {
80 xmlTextWriterStartElement(writer, element);
81 switch (id->get_type(id))
82 {
83 {
84 char *type = "";
85 while (TRUE)
86 {
87 case ID_ANY:
88 type = "any";
89 break;
90 case ID_IPV4_ADDR:
91 type = "ipv4";
92 break;
93 case ID_IPV6_ADDR:
94 type = "ipv6";
95 break;
96 case ID_FQDN:
97 type = "fqdn";
98 break;
99 case ID_RFC822_ADDR:
100 type = "email";
101 break;
102 case ID_DER_ASN1_DN:
103 type = "asn1dn";
104 break;
105 case ID_DER_ASN1_GN:
106 type = "asn1gn";
107 break;
108 }
109 xmlTextWriterWriteAttribute(writer, "type", type);
110 xmlTextWriterWriteFormatString(writer, "%Y", id);
111 break;
112 }
113 default:
114 /* TODO: base64 keyid */
115 xmlTextWriterWriteAttribute(writer, "type", "keyid");
116 break;
117 }
118 xmlTextWriterEndElement(writer);
119 }
120
121 /**
122 * write a host_t address into an element
123 */
124 static void write_address(xmlTextWriterPtr writer, char *element, host_t *host)
125 {
126 xmlTextWriterStartElement(writer, element);
127 xmlTextWriterWriteAttribute(writer, "type",
128 host->get_family(host) == AF_INET ? "ipv4" : "ipv6");
129 if (host->is_anyaddr(host))
130 { /* do not use %any for XML */
131 xmlTextWriterWriteFormatString(writer, "%s",
132 host->get_family(host) == AF_INET ? "0.0.0.0" : "::");
133 }
134 else
135 {
136 xmlTextWriterWriteFormatString(writer, "%H", host);
137 }
138 xmlTextWriterEndElement(writer);
139 }
140
141 /**
142 * write networks element
143 */
144 static void write_networks(xmlTextWriterPtr writer, char *element,
145 linked_list_t *list)
146 {
147 enumerator_t *enumerator;
148 traffic_selector_t *ts;
149
150 xmlTextWriterStartElement(writer, element);
151 enumerator = list->create_enumerator(list);
152 while (enumerator->enumerate(enumerator, (void**)&ts))
153 {
154 xmlTextWriterStartElement(writer, "network");
155 xmlTextWriterWriteAttribute(writer, "type",
156 ts->get_type(ts) == TS_IPV4_ADDR_RANGE ? "ipv4" : "ipv6");
157 xmlTextWriterWriteFormatString(writer, "%R", ts);
158 xmlTextWriterEndElement(writer);
159 }
160 enumerator->destroy(enumerator);
161 xmlTextWriterEndElement(writer);
162 }
163
164 /**
165 * write a childEnd
166 */
167 static void write_childend(xmlTextWriterPtr writer, child_sa_t *child, bool local)
168 {
169 linked_list_t *list;
170
171 xmlTextWriterWriteFormatElement(writer, "spi", "%lx",
172 htonl(child->get_spi(child, local)));
173 list = child->get_traffic_selectors(child, local);
174 write_networks(writer, "networks", list);
175 }
176
177 /**
178 * write a child_sa_t
179 */
180 static void write_child(xmlTextWriterPtr writer, child_sa_t *child)
181 {
182 child_cfg_t *config;
183
184 config = child->get_config(child);
185
186 xmlTextWriterStartElement(writer, "childsa");
187 xmlTextWriterWriteFormatElement(writer, "reqid", "%d",
188 child->get_reqid(child));
189 xmlTextWriterWriteFormatElement(writer, "childconfig", "%s",
190 config->get_name(config));
191 xmlTextWriterStartElement(writer, "local");
192 write_childend(writer, child, TRUE);
193 xmlTextWriterEndElement(writer);
194 xmlTextWriterStartElement(writer, "remote");
195 write_childend(writer, child, FALSE);
196 xmlTextWriterEndElement(writer);
197 xmlTextWriterEndElement(writer);
198 }
199
200 /**
201 * process a ikesalist query request message
202 */
203 static void request_query_ikesa(xmlTextReaderPtr reader, xmlTextWriterPtr writer)
204 {
205 enumerator_t *enumerator;
206 ike_sa_t *ike_sa;
207
208 /* <ikesalist> */
209 xmlTextWriterStartElement(writer, "ikesalist");
210
211 enumerator = charon->controller->create_ike_sa_enumerator(
212 charon->controller, TRUE);
213 while (enumerator->enumerate(enumerator, &ike_sa))
214 {
215 ike_sa_id_t *id;
216 host_t *local, *remote;
217 enumerator_t *children;
218 child_sa_t *child_sa;
219
220 id = ike_sa->get_id(ike_sa);
221
222 xmlTextWriterStartElement(writer, "ikesa");
223 xmlTextWriterWriteFormatElement(writer, "id", "%d",
224 ike_sa->get_unique_id(ike_sa));
225 xmlTextWriterWriteFormatElement(writer, "status", "%N",
226 ike_sa_state_lower_names, ike_sa->get_state(ike_sa));
227 xmlTextWriterWriteElement(writer, "role",
228 id->is_initiator(id) ? "initiator" : "responder");
229 xmlTextWriterWriteElement(writer, "peerconfig", ike_sa->get_name(ike_sa));
230
231 /* <local> */
232 local = ike_sa->get_my_host(ike_sa);
233 xmlTextWriterStartElement(writer, "local");
234 xmlTextWriterWriteFormatElement(writer, "spi", "%.16llx",
235 id->is_initiator(id) ? id->get_initiator_spi(id)
236 : id->get_responder_spi(id));
237 write_id(writer, "identification", ike_sa->get_my_id(ike_sa));
238 write_address(writer, "address", local);
239 xmlTextWriterWriteFormatElement(writer, "port", "%d",
240 local->get_port(local));
241 if (ike_sa->supports_extension(ike_sa, EXT_NATT))
242 {
243 write_bool(writer, "nat", ike_sa->has_condition(ike_sa, COND_NAT_HERE));
244 }
245 xmlTextWriterEndElement(writer);
246 /* </local> */
247
248 /* <remote> */
249 remote = ike_sa->get_other_host(ike_sa);
250 xmlTextWriterStartElement(writer, "remote");
251 xmlTextWriterWriteFormatElement(writer, "spi", "%.16llx",
252 id->is_initiator(id) ? id->get_responder_spi(id)
253 : id->get_initiator_spi(id));
254 write_id(writer, "identification", ike_sa->get_other_id(ike_sa));
255 write_address(writer, "address", remote);
256 xmlTextWriterWriteFormatElement(writer, "port", "%d",
257 remote->get_port(remote));
258 if (ike_sa->supports_extension(ike_sa, EXT_NATT))
259 {
260 write_bool(writer, "nat", ike_sa->has_condition(ike_sa, COND_NAT_THERE));
261 }
262 xmlTextWriterEndElement(writer);
263 /* </remote> */
264
265 /* <childsalist> */
266 xmlTextWriterStartElement(writer, "childsalist");
267 children = ike_sa->create_child_sa_enumerator(ike_sa);
268 while (children->enumerate(children, (void**)&child_sa))
269 {
270 write_child(writer, child_sa);
271 }
272 children->destroy(children);
273 /* </childsalist> */
274 xmlTextWriterEndElement(writer);
275
276 /* </ikesa> */
277 xmlTextWriterEndElement(writer);
278 }
279 enumerator->destroy(enumerator);
280
281 /* </ikesalist> */
282 xmlTextWriterEndElement(writer);
283 }
284
285 /**
286 * process a configlist query request message
287 */
288 static void request_query_config(xmlTextReaderPtr reader, xmlTextWriterPtr writer)
289 {
290 enumerator_t *enumerator;
291 peer_cfg_t *peer_cfg;
292
293 /* <configlist> */
294 xmlTextWriterStartElement(writer, "configlist");
295
296 enumerator = charon->backends->create_peer_cfg_enumerator(charon->backends,
297 NULL, NULL, NULL, NULL);
298 while (enumerator->enumerate(enumerator, &peer_cfg))
299 {
300 enumerator_t *children;
301 child_cfg_t *child_cfg;
302 ike_cfg_t *ike_cfg;
303 linked_list_t *list;
304
305 if (peer_cfg->get_ike_version(peer_cfg) != 2)
306 { /* only IKEv2 connections yet */
307 continue;
308 }
309
310 /* <peerconfig> */
311 xmlTextWriterStartElement(writer, "peerconfig");
312 xmlTextWriterWriteElement(writer, "name", peer_cfg->get_name(peer_cfg));
313
314 /* TODO: write auth_cfgs */
315
316 /* <ikeconfig> */
317 ike_cfg = peer_cfg->get_ike_cfg(peer_cfg);
318 xmlTextWriterStartElement(writer, "ikeconfig");
319 xmlTextWriterWriteElement(writer, "local", ike_cfg->get_my_addr(ike_cfg));
320 xmlTextWriterWriteElement(writer, "remote", ike_cfg->get_other_addr(ike_cfg));
321 xmlTextWriterEndElement(writer);
322 /* </ikeconfig> */
323
324 /* <childconfiglist> */
325 xmlTextWriterStartElement(writer, "childconfiglist");
326 children = peer_cfg->create_child_cfg_enumerator(peer_cfg);
327 while (children->enumerate(children, &child_cfg))
328 {
329 /* <childconfig> */
330 xmlTextWriterStartElement(writer, "childconfig");
331 xmlTextWriterWriteElement(writer, "name",
332 child_cfg->get_name(child_cfg));
333 list = child_cfg->get_traffic_selectors(child_cfg, TRUE, NULL, NULL);
334 write_networks(writer, "local", list);
335 list->destroy_offset(list, offsetof(traffic_selector_t, destroy));
336 list = child_cfg->get_traffic_selectors(child_cfg, FALSE, NULL, NULL);
337 write_networks(writer, "remote", list);
338 list->destroy_offset(list, offsetof(traffic_selector_t, destroy));
339 xmlTextWriterEndElement(writer);
340 /* </childconfig> */
341 }
342 children->destroy(children);
343 /* </childconfiglist> */
344 xmlTextWriterEndElement(writer);
345 /* </peerconfig> */
346 xmlTextWriterEndElement(writer);
347 }
348 enumerator->destroy(enumerator);
349 /* </configlist> */
350 xmlTextWriterEndElement(writer);
351 }
352
353 /**
354 * callback which logs to a XML writer
355 */
356 static bool xml_callback(xmlTextWriterPtr writer, debug_t group, level_t level,
357 ike_sa_t* ike_sa, char* format, va_list args)
358 {
359 if (level <= 1)
360 {
361 /* <item> */
362 xmlTextWriterStartElement(writer, "item");
363 xmlTextWriterWriteFormatAttribute(writer, "level", "%d", level);
364 xmlTextWriterWriteFormatAttribute(writer, "source", "%N", debug_names, group);
365 xmlTextWriterWriteFormatAttribute(writer, "thread", "%u", thread_current_id());
366 xmlTextWriterWriteVFormatString(writer, format, args);
367 xmlTextWriterEndElement(writer);
368 /* </item> */
369 }
370 return TRUE;
371 }
372
373 /**
374 * process a *terminate control request message
375 */
376 static void request_control_terminate(xmlTextReaderPtr reader,
377 xmlTextWriterPtr writer, bool ike)
378 {
379 if (xmlTextReaderRead(reader) &&
380 xmlTextReaderNodeType(reader) == XML_READER_TYPE_TEXT)
381 {
382 const char *str;
383 u_int32_t id;
384 status_t status;
385
386 str = xmlTextReaderConstValue(reader);
387 if (str == NULL)
388 {
389 DBG1(DBG_CFG, "error parsing XML id string");
390 return;
391 }
392 id = atoi(str);
393 if (!id)
394 {
395 enumerator_t *enumerator;
396 ike_sa_t *ike_sa;
397
398 enumerator = charon->controller->create_ike_sa_enumerator(
399 charon->controller, TRUE);
400 while (enumerator->enumerate(enumerator, &ike_sa))
401 {
402 if (streq(str, ike_sa->get_name(ike_sa)))
403 {
404 ike = TRUE;
405 id = ike_sa->get_unique_id(ike_sa);
406 break;
407 }
408 }
409 enumerator->destroy(enumerator);
410 }
411 if (!id)
412 {
413 DBG1(DBG_CFG, "error parsing XML id string");
414 return;
415 }
416
417 DBG1(DBG_CFG, "terminating %s_SA %d", ike ? "IKE" : "CHILD", id);
418
419 /* <log> */
420 xmlTextWriterStartElement(writer, "log");
421 if (ike)
422 {
423 status = charon->controller->terminate_ike(
424 charon->controller, id,
425 (controller_cb_t)xml_callback, writer, 0);
426 }
427 else
428 {
429 status = charon->controller->terminate_child(
430 charon->controller, id,
431 (controller_cb_t)xml_callback, writer, 0);
432 }
433 /* </log> */
434 xmlTextWriterEndElement(writer);
435 xmlTextWriterWriteFormatElement(writer, "status", "%d", status);
436 }
437 }
438
439 /**
440 * process a *initiate control request message
441 */
442 static void request_control_initiate(xmlTextReaderPtr reader,
443 xmlTextWriterPtr writer, bool ike)
444 {
445 if (xmlTextReaderRead(reader) &&
446 xmlTextReaderNodeType(reader) == XML_READER_TYPE_TEXT)
447 {
448 const char *str;
449 status_t status = FAILED;
450 peer_cfg_t *peer;
451 child_cfg_t *child = NULL;
452 enumerator_t *enumerator;
453
454 str = xmlTextReaderConstValue(reader);
455 if (str == NULL)
456 {
457 DBG1(DBG_CFG, "error parsing XML config name string");
458 return;
459 }
460 DBG1(DBG_CFG, "initiating %s_SA %s", ike ? "IKE" : "CHILD", str);
461
462 /* <log> */
463 xmlTextWriterStartElement(writer, "log");
464 peer = charon->backends->get_peer_cfg_by_name(charon->backends,
465 (char*)str);
466 if (peer)
467 {
468 enumerator = peer->create_child_cfg_enumerator(peer);
469 if (ike)
470 {
471 if (enumerator->enumerate(enumerator, &child))
472 {
473 child->get_ref(child);
474 }
475 else
476 {
477 child = NULL;
478 }
479 }
480 else
481 {
482 while (enumerator->enumerate(enumerator, &child))
483 {
484 if (streq(child->get_name(child), str))
485 {
486 child->get_ref(child);
487 break;
488 }
489 child = NULL;
490 }
491 }
492 enumerator->destroy(enumerator);
493 if (child)
494 {
495 status = charon->controller->initiate(charon->controller,
496 peer, child, (controller_cb_t)xml_callback,
497 writer, 0);
498 }
499 else
500 {
501 peer->destroy(peer);
502 }
503 }
504 /* </log> */
505 xmlTextWriterEndElement(writer);
506 xmlTextWriterWriteFormatElement(writer, "status", "%d", status);
507 }
508 }
509
510 /**
511 * process a query request
512 */
513 static void request_query(xmlTextReaderPtr reader, xmlTextWriterPtr writer)
514 {
515 /* <query> */
516 xmlTextWriterStartElement(writer, "query");
517 while (xmlTextReaderRead(reader))
518 {
519 if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_ELEMENT)
520 {
521 if (streq(xmlTextReaderConstName(reader), "ikesalist"))
522 {
523 request_query_ikesa(reader, writer);
524 break;
525 }
526 if (streq(xmlTextReaderConstName(reader), "configlist"))
527 {
528 request_query_config(reader, writer);
529 break;
530 }
531 }
532 }
533 /* </query> */
534 xmlTextWriterEndElement(writer);
535 }
536
537 /**
538 * process a control request
539 */
540 static void request_control(xmlTextReaderPtr reader, xmlTextWriterPtr writer)
541 {
542 /* <control> */
543 xmlTextWriterStartElement(writer, "control");
544 while (xmlTextReaderRead(reader))
545 {
546 if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_ELEMENT)
547 {
548 if (streq(xmlTextReaderConstName(reader), "ikesaterminate"))
549 {
550 request_control_terminate(reader, writer, TRUE);
551 break;
552 }
553 if (streq(xmlTextReaderConstName(reader), "childsaterminate"))
554 {
555 request_control_terminate(reader, writer, FALSE);
556 break;
557 }
558 if (streq(xmlTextReaderConstName(reader), "ikesainitiate"))
559 {
560 request_control_initiate(reader, writer, TRUE);
561 break;
562 }
563 if (streq(xmlTextReaderConstName(reader), "childsainitiate"))
564 {
565 request_control_initiate(reader, writer, FALSE);
566 break;
567 }
568 }
569 }
570 /* </control> */
571 xmlTextWriterEndElement(writer);
572 }
573
574 /**
575 * process a request message
576 */
577 static void request(xmlTextReaderPtr reader, char *id, int fd)
578 {
579 xmlTextWriterPtr writer;
580
581 writer = xmlNewTextWriter(xmlOutputBufferCreateFd(fd, NULL));
582 if (writer == NULL)
583 {
584 DBG1(DBG_CFG, "opening SMP XML writer failed");
585 return;
586 }
587
588 xmlTextWriterStartDocument(writer, NULL, NULL, NULL);
589 /* <message xmlns="http://www.strongswan.org/smp/1.0"
590 id="id" type="response"> */
591 xmlTextWriterStartElement(writer, "message");
592 xmlTextWriterWriteAttribute(writer, "xmlns",
593 "http://www.strongswan.org/smp/1.0");
594 xmlTextWriterWriteAttribute(writer, "id", id);
595 xmlTextWriterWriteAttribute(writer, "type", "response");
596
597 while (xmlTextReaderRead(reader))
598 {
599 if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_ELEMENT)
600 {
601 if (streq(xmlTextReaderConstName(reader), "query"))
602 {
603 request_query(reader, writer);
604 break;
605 }
606 if (streq(xmlTextReaderConstName(reader), "control"))
607 {
608 request_control(reader, writer);
609 break;
610 }
611 }
612 }
613 /* </message> and close document */
614 xmlTextWriterEndDocument(writer);
615 xmlFreeTextWriter(writer);
616 }
617
618 /**
619 * cleanup helper function for open file descriptors
620 */
621 static void closefdp(int *fd)
622 {
623 close(*fd);
624 }
625
626 /**
627 * read from a opened connection and process it
628 */
629 static job_requeue_t process(int *fdp)
630 {
631 int fd = *fdp;
632 bool oldstate;
633 char buffer[4096];
634 ssize_t len;
635 xmlTextReaderPtr reader;
636 char *id = NULL, *type = NULL;
637
638 thread_cleanup_push((thread_cleanup_t)closefdp, (void*)&fd);
639 oldstate = thread_cancelability(TRUE);
640 len = read(fd, buffer, sizeof(buffer));
641 thread_cancelability(oldstate);
642 thread_cleanup_pop(FALSE);
643 if (len <= 0)
644 {
645 close(fd);
646 DBG2(DBG_CFG, "SMP XML connection closed");
647 return JOB_REQUEUE_NONE;
648 }
649 DBG3(DBG_CFG, "got XML request: %b", buffer, (u_int)len);
650
651 reader = xmlReaderForMemory(buffer, len, NULL, NULL, 0);
652 if (reader == NULL)
653 {
654 DBG1(DBG_CFG, "opening SMP XML reader failed");
655 return JOB_REQUEUE_FAIR;;
656 }
657
658 /* read message type and id */
659 while (xmlTextReaderRead(reader))
660 {
661 if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_ELEMENT &&
662 streq(xmlTextReaderConstName(reader), "message"))
663 {
664 id = xmlTextReaderGetAttribute(reader, "id");
665 type = xmlTextReaderGetAttribute(reader, "type");
666 break;
667 }
668 }
669
670 /* process message */
671 if (id && type)
672 {
673 if (streq(type, "request"))
674 {
675 request(reader, id, fd);
676 }
677 else
678 {
679 /* response(reader, id) */
680 }
681 }
682 xmlFreeTextReader(reader);
683 return JOB_REQUEUE_FAIR;;
684 }
685
686 /**
687 * accept from XML socket and create jobs to process connections
688 */
689 static job_requeue_t dispatch(private_smp_t *this)
690 {
691 struct sockaddr_un strokeaddr;
692 int fd, *fdp, strokeaddrlen = sizeof(strokeaddr);
693 callback_job_t *job;
694 bool oldstate;
695
696 /* wait for connections, but allow thread to terminate */
697 oldstate = thread_cancelability(TRUE);
698 fd = accept(this->socket, (struct sockaddr *)&strokeaddr, &strokeaddrlen);
699 thread_cancelability(oldstate);
700
701 if (fd < 0)
702 {
703 DBG1(DBG_CFG, "accepting SMP XML socket failed: %s", strerror(errno));
704 sleep(1);
705 return JOB_REQUEUE_FAIR;;
706 }
707
708 fdp = malloc_thing(int);
709 *fdp = fd;
710 job = callback_job_create((callback_job_cb_t)process, fdp, free, this->job);
711 lib->processor->queue_job(lib->processor, (job_t*)job);
712
713 return JOB_REQUEUE_DIRECT;
714 }
715
716 METHOD(plugin_t, get_name, char*,
717 private_smp_t *this)
718 {
719 return "smp";
720 }
721
722 METHOD(plugin_t, destroy, void,
723 private_smp_t *this)
724 {
725 this->job->cancel(this->job);
726 close(this->socket);
727 free(this);
728 }
729
730 /*
731 * Described in header file
732 */
733 plugin_t *smp_plugin_create()
734 {
735 struct sockaddr_un unix_addr = { AF_UNIX, IPSEC_PIDDIR "/charon.xml"};
736 private_smp_t *this;
737 mode_t old;
738
739 INIT(this,
740 .public = {
741 .plugin = {
742 .get_name = _get_name,
743 .reload = (void*)return_false,
744 .destroy = _destroy,
745 },
746 },
747 );
748
749 /* set up unix socket */
750 this->socket = socket(AF_UNIX, SOCK_STREAM, 0);
751 if (this->socket == -1)
752 {
753 DBG1(DBG_CFG, "could not create XML socket");
754 free(this);
755 return NULL;
756 }
757
758 unlink(unix_addr.sun_path);
759 old = umask(~(S_IRWXU | S_IRWXG));
760 if (bind(this->socket, (struct sockaddr *)&unix_addr, sizeof(unix_addr)) < 0)
761 {
762 DBG1(DBG_CFG, "could not bind XML socket: %s", strerror(errno));
763 close(this->socket);
764 free(this);
765 return NULL;
766 }
767 umask(old);
768 if (chown(unix_addr.sun_path, charon->uid, charon->gid) != 0)
769 {
770 DBG1(DBG_CFG, "changing XML socket permissions failed: %s", strerror(errno));
771 }
772
773 if (listen(this->socket, 5) < 0)
774 {
775 DBG1(DBG_CFG, "could not listen on XML socket: %s", strerror(errno));
776 close(this->socket);
777 free(this);
778 return NULL;
779 }
780
781 this->job = callback_job_create_with_prio((callback_job_cb_t)dispatch,
782 this, NULL, NULL, JOB_PRIO_CRITICAL);
783 lib->processor->queue_job(lib->processor, (job_t*)this->job);
784
785 return &this->public.plugin;
786 }
787