42 #if defined(LDAP_CONFIGURATION) 48 #if defined(HAVE_IFADDRS_H) 53 #if defined(LDAP_CASA_AUTH) 57 #if defined(LDAP_USE_GSSAPI) 58 #include <sasl/sasl.h> 62 static LDAP * ld = NULL;
63 static char *ldap_server = NULL,
64 *ldap_username = NULL,
65 *ldap_password = NULL,
67 *ldap_dhcp_server_cn = NULL,
68 *ldap_debug_file = NULL;
69 static int ldap_port = LDAP_PORT,
70 ldap_method = LDAP_METHOD_DYNAMIC,
73 ldap_enable_retry = -1,
75 #if defined (LDAP_USE_SSL) 76 static int ldap_use_ssl = -1,
77 ldap_tls_reqcert = -1,
78 ldap_tls_crlcheck = -1;
79 static char *ldap_tls_ca_file = NULL,
80 *ldap_tls_ca_dir = NULL,
81 *ldap_tls_cert = NULL,
83 *ldap_tls_ciphers = NULL,
84 *ldap_tls_randfile = NULL;
87 #if defined (LDAP_USE_GSSAPI) 88 static char *ldap_gssapi_keytab = NULL,
89 *ldap_gssapi_principal = NULL;
91 struct ldap_sasl_instance {
99 static struct ldap_sasl_instance *ldap_sasl_inst = NULL;
102 _ldap_sasl_interact(LDAP *ld,
unsigned flags,
void *defaults,
void *sin) ;
105 static struct ldap_config_stack *ldap_stack = NULL;
107 typedef struct ldap_dn_node {
108 struct ldap_dn_node *next;
113 static ldap_dn_node *ldap_service_dn_head = NULL;
114 static ldap_dn_node *ldap_service_dn_tail = NULL;
116 static int ldap_read_function (
struct parse *cfile);
118 static struct parse *
119 x_parser_init(
const char *name)
129 cfile = (
struct parse *) NULL;
130 res =
new_parse (&cfile, -1, inbuf, LDAP_BUFFER_SIZE, name, 0);
131 if (res != ISC_R_SUCCESS)
137 cfile->
bufsiz = LDAP_BUFFER_SIZE;
140 cfile->read_function = ldap_read_function;
145 x_parser_free(
struct parse **cfile)
151 (*cfile)->inbuf = NULL;
152 (*cfile)->bufsiz = 0;
155 return ISC_R_SUCCESS;
159 x_parser_resize(
struct parse *cfile,
size_t len)
165 size = cfile->
bufsiz + (len | (LDAP_BUFFER_SIZE-1)) + 1;
170 #if defined (DEBUG_LDAP) 171 log_info (
"Reallocated %s buffer from %zu to %zu",
186 log_error(
"Unable to reallocated %s buffer from %zu to %zu",
192 x_parser_strcat(
struct parse *cfile,
const char *str)
194 size_t cur = strlen(cfile->
inbuf);
195 size_t len = strlen(str);
198 if (cur + len >= cfile->
bufsiz && !x_parser_resize(cfile, len))
201 cnt = cfile->
bufsiz > cur ? cfile->
bufsiz - cur - 1 : 0;
202 return strncat(cfile->
inbuf, str, cnt);
206 x_parser_reset(
struct parse *cfile)
208 cfile->
inbuf[0] =
'\0';
213 x_parser_length(
struct parse *cfile)
220 x_strxform(
char *dst,
const char *src,
size_t dst_size,
223 if(dst && src && dst_size)
228 for(pos=0; pos < len && pos + 1 < dst_size; pos++)
229 dst[pos] = xform((
int)src[pos]);
238 get_host_entry(
char *fqdnname,
size_t fqdnname_size,
239 char *hostaddr,
size_t hostaddr_size)
241 #if defined(MAXHOSTNAMELEN) 242 char hname[MAXHOSTNAMELEN+1];
248 if (NULL == fqdnname || 1 >= fqdnname_size)
251 memset(hname, 0,
sizeof(hname));
252 if (gethostname(hname,
sizeof(hname)-1))
255 if (NULL == (hp = gethostbyname(hname)))
258 strncpy(fqdnname, hp->h_name, fqdnname_size-1);
259 fqdnname[fqdnname_size-1] =
'\0';
261 if (hostaddr != NULL)
263 if (hp->h_addr != NULL)
265 struct in_addr *aptr = (
struct in_addr *)hp->h_addr;
267 if (hostaddr_size >= INET_ADDRSTRLEN &&
268 inet_ntop(AF_INET, aptr, hostaddr, hostaddr_size) != NULL)
273 char *astr = inet_ntoa(*aptr);
274 size_t alen = strlen(astr);
275 if (astr && alen > 0 && hostaddr_size > alen)
277 strncpy(hostaddr, astr, hostaddr_size-1);
278 hostaddr[hostaddr_size-1] =
'\0';
288 #if defined(HAVE_IFADDRS_H) 290 is_iface_address(
struct ifaddrs *addrs,
struct in_addr *addr)
293 struct sockaddr_in *sa;
296 if(addrs == NULL || addr == NULL)
299 for (ia = addrs; ia != NULL; ia = ia->ifa_next)
302 if (ia->ifa_addr && (ia->ifa_flags & IFF_UP) &&
303 ia->ifa_addr->sa_family == AF_INET)
305 sa = (
struct sockaddr_in *)(ia->ifa_addr);
306 if (addr->s_addr == sa->sin_addr.s_addr)
314 get_host_address(
const char *hostname,
char *hostaddr,
size_t hostaddr_size,
struct ifaddrs *addrs)
316 if (hostname && *hostname && hostaddr && hostaddr_size)
320 #if defined(HAVE_INET_PTON) 321 if (inet_pton(AF_INET, hostname, &addr) == 1)
323 if (inet_aton(hostname, &addr) != 0)
327 if(strlen(hostname) < hostaddr_size)
329 strncpy(hostaddr, hostname, hostaddr_size-1);
330 hostaddr[hostaddr_size-1] =
'\0';
332 if (addrs != NULL && is_iface_address (addrs, &addr) > 0)
341 if ((hp = gethostbyname(hostname)) != NULL && hp->h_addr != NULL)
343 struct in_addr *aptr = (
struct in_addr *)hp->h_addr;
349 for (h=hp->h_addr_list; *h; h++)
351 struct in_addr *haddr = (
struct in_addr *)*h;
352 if (is_iface_address (addrs, haddr) > 0)
360 #if defined(HAVE_INET_NTOP) 361 if (hostaddr_size >= INET_ADDRSTRLEN &&
362 inet_ntop(AF_INET, aptr, hostaddr, hostaddr_size) != NULL)
367 char *astr = inet_ntoa(*aptr);
368 size_t alen = strlen(astr);
369 if (astr && alen > 0 && alen < hostaddr_size)
371 strncpy(hostaddr, astr, hostaddr_size-1);
372 hostaddr[hostaddr_size-1] =
'\0';
384 ldap_parse_class (
struct ldap_config_stack *item,
struct parse *cfile)
386 struct berval **tempbv;
388 if ((tempbv = ldap_get_values_len (ld, item->ldent,
"cn")) == NULL ||
392 ldap_value_free_len (tempbv);
397 x_parser_strcat (cfile,
"class \"");
398 x_parser_strcat (cfile, tempbv[0]->bv_val);
399 x_parser_strcat (cfile,
"\" {\n");
401 item->close_brace = 1;
402 ldap_value_free_len (tempbv);
406 is_hex_string(
const char *str)
418 for (i=0; str[i]; ++i)
426 else if(isxdigit((
unsigned char)str[i]))
435 return i > 0 && !colon;
439 ldap_parse_subclass (
struct ldap_config_stack *item,
struct parse *cfile)
441 struct berval **tempbv, **classdata;
444 if ((tempbv = ldap_get_values_len (ld, item->ldent,
"cn")) == NULL ||
448 ldap_value_free_len (tempbv);
453 if ((classdata = ldap_get_values_len (ld, item->ldent,
454 "dhcpClassData")) == NULL ||
455 classdata[0] == NULL)
457 if (classdata != NULL)
458 ldap_value_free_len (classdata);
459 ldap_value_free_len (tempbv);
464 x_parser_strcat (cfile,
"subclass \"");
465 x_parser_strcat (cfile, classdata[0]->bv_val);
466 if (is_hex_string(tempbv[0]->bv_val))
468 x_parser_strcat (cfile,
"\" ");
469 x_parser_strcat (cfile, tempbv[0]->bv_val);
470 x_parser_strcat (cfile,
" {\n");
475 x_parser_strcat (cfile,
"\" \"");
476 x_parser_strcat (cfile, tmp);
477 x_parser_strcat (cfile,
"\" {\n");
481 item->close_brace = 1;
482 ldap_value_free_len (tempbv);
483 ldap_value_free_len (classdata);
488 ldap_parse_host (
struct ldap_config_stack *item,
struct parse *cfile)
490 struct berval **tempbv, **hwaddr;
492 if ((tempbv = ldap_get_values_len (ld, item->ldent,
"cn")) == NULL ||
496 ldap_value_free_len (tempbv);
501 hwaddr = ldap_get_values_len (ld, item->ldent,
"dhcpHWAddress");
503 x_parser_strcat (cfile,
"host ");
504 x_parser_strcat (cfile, tempbv[0]->bv_val);
505 x_parser_strcat (cfile,
" {\n");
509 if (hwaddr[0] != NULL)
511 x_parser_strcat (cfile,
"hardware ");
512 x_parser_strcat (cfile, hwaddr[0]->bv_val);
513 x_parser_strcat (cfile,
";\n");
515 ldap_value_free_len (hwaddr);
518 item->close_brace = 1;
519 ldap_value_free_len (tempbv);
524 ldap_parse_shared_network (
struct ldap_config_stack *item,
struct parse *cfile)
526 struct berval **tempbv;
528 if ((tempbv = ldap_get_values_len (ld, item->ldent,
"cn")) == NULL ||
532 ldap_value_free_len (tempbv);
537 x_parser_strcat (cfile,
"shared-network \"");
538 x_parser_strcat (cfile, tempbv[0]->bv_val);
539 x_parser_strcat (cfile,
"\" {\n");
541 item->close_brace = 1;
542 ldap_value_free_len (tempbv);
547 parse_netmask (
int netmask,
char *netmaskbuf)
553 for (i=1; i <= netmask; i++)
558 sprintf (netmaskbuf,
"%d.%d.%d.%d", (
int) (nm >> 24) & 0xff,
559 (
int) (nm >> 16) & 0xff,
560 (
int) (nm >> 8) & 0xff,
566 ldap_parse_subnet (
struct ldap_config_stack *item,
struct parse *cfile)
568 struct berval **tempbv, **netmaskstr;
569 char netmaskbuf[
sizeof(
"255.255.255.255")];
572 if ((tempbv = ldap_get_values_len (ld, item->ldent,
"cn")) == NULL ||
576 ldap_value_free_len (tempbv);
581 if ((netmaskstr = ldap_get_values_len (ld, item->ldent,
582 "dhcpNetmask")) == NULL ||
583 netmaskstr[0] == NULL)
585 if (netmaskstr != NULL)
586 ldap_value_free_len (netmaskstr);
587 ldap_value_free_len (tempbv);
592 x_parser_strcat (cfile,
"subnet ");
593 x_parser_strcat (cfile, tempbv[0]->bv_val);
595 x_parser_strcat (cfile,
" netmask ");
596 parse_netmask (strtol (netmaskstr[0]->bv_val, NULL, 10), netmaskbuf);
597 x_parser_strcat (cfile, netmaskbuf);
599 x_parser_strcat (cfile,
" {\n");
601 ldap_value_free_len (tempbv);
602 ldap_value_free_len (netmaskstr);
604 if ((tempbv = ldap_get_values_len (ld, item->ldent,
"dhcpRange")) != NULL)
606 for (i=0; tempbv[i] != NULL; i++)
608 x_parser_strcat (cfile,
"range");
609 x_parser_strcat (cfile,
" ");
610 x_parser_strcat (cfile, tempbv[i]->bv_val);
611 x_parser_strcat (cfile,
";\n");
613 ldap_value_free_len (tempbv);
616 item->close_brace = 1;
620 ldap_parse_subnet6 (
struct ldap_config_stack *item,
struct parse *cfile)
622 struct berval **tempbv;
625 if ((tempbv = ldap_get_values_len (ld, item->ldent,
"cn")) == NULL ||
629 ldap_value_free_len (tempbv);
634 x_parser_strcat (cfile,
"subnet6 ");
635 x_parser_strcat (cfile, tempbv[0]->bv_val);
637 x_parser_strcat (cfile,
" {\n");
639 ldap_value_free_len (tempbv);
641 if ((tempbv = ldap_get_values_len (ld, item->ldent,
"dhcpRange")) != NULL)
643 for (i=0; tempbv[i] != NULL; i++)
645 x_parser_strcat (cfile,
"range6");
646 x_parser_strcat (cfile,
" ");
647 x_parser_strcat (cfile, tempbv[i]->bv_val);
648 x_parser_strcat (cfile,
";\n");
650 ldap_value_free_len (tempbv);
653 if ((tempbv = ldap_get_values_len (ld, item->ldent,
"dhcpPermitList")) != NULL)
655 for (i=0; tempbv[i] != NULL; i++)
657 x_parser_strcat (cfile, tempbv[i]->bv_val);
658 x_parser_strcat (cfile,
";\n");
660 ldap_value_free_len (tempbv);
663 item->close_brace = 1;
667 ldap_parse_pool (
struct ldap_config_stack *item,
struct parse *cfile)
669 struct berval **tempbv;
672 x_parser_strcat (cfile,
"pool {\n");
674 if ((tempbv = ldap_get_values_len (ld, item->ldent,
"dhcpRange")) != NULL)
676 x_parser_strcat (cfile,
"range");
677 for (i=0; tempbv[i] != NULL; i++)
679 x_parser_strcat (cfile,
" ");
680 x_parser_strcat (cfile, tempbv[i]->bv_val);
682 x_parser_strcat (cfile,
";\n");
683 ldap_value_free_len (tempbv);
686 if ((tempbv = ldap_get_values_len (ld, item->ldent,
"dhcpPermitList")) != NULL)
688 for (i=0; tempbv[i] != NULL; i++)
690 x_parser_strcat (cfile, tempbv[i]->bv_val);
691 x_parser_strcat (cfile,
";\n");
693 ldap_value_free_len (tempbv);
696 item->close_brace = 1;
700 ldap_parse_pool6 (
struct ldap_config_stack *item,
struct parse *cfile)
702 struct berval **tempbv;
705 x_parser_strcat (cfile,
"pool {\n");
707 if ((tempbv = ldap_get_values_len (ld, item->ldent,
"dhcpRange")) != NULL)
709 x_parser_strcat (cfile,
"range6");
710 for (i=0; tempbv[i] != NULL; i++)
712 x_parser_strcat (cfile,
" ");
713 x_parser_strcat (cfile, tempbv[i]->bv_val);
715 x_parser_strcat (cfile,
";\n");
716 ldap_value_free_len (tempbv);
719 if ((tempbv = ldap_get_values_len (ld, item->ldent,
"dhcpPermitList")) != NULL)
721 for (i=0; tempbv[i] != NULL; i++)
723 x_parser_strcat(cfile, tempbv[i]->bv_val);
724 x_parser_strcat (cfile,
";\n");
726 ldap_value_free_len (tempbv);
729 item->close_brace = 1;
733 ldap_parse_group (
struct ldap_config_stack *item,
struct parse *cfile)
735 x_parser_strcat (cfile,
"group {\n");
736 item->close_brace = 1;
741 ldap_parse_key (
struct ldap_config_stack *item,
struct parse *cfile)
743 struct berval **tempbv;
745 if ((tempbv = ldap_get_values_len (ld, item->ldent,
"cn")) != NULL)
747 x_parser_strcat (cfile,
"key ");
748 x_parser_strcat (cfile, tempbv[0]->bv_val);
749 x_parser_strcat (cfile,
" {\n");
750 ldap_value_free_len (tempbv);
753 if ((tempbv = ldap_get_values_len (ld, item->ldent,
"dhcpKeyAlgorithm")) != NULL)
755 x_parser_strcat (cfile,
"algorithm ");
756 x_parser_strcat (cfile, tempbv[0]->bv_val);
757 x_parser_strcat (cfile,
";\n");
758 ldap_value_free_len (tempbv);
761 if ((tempbv = ldap_get_values_len (ld, item->ldent,
"dhcpKeySecret")) != NULL)
763 x_parser_strcat (cfile,
"secret ");
764 x_parser_strcat (cfile, tempbv[0]->bv_val);
765 x_parser_strcat (cfile,
";\n");
766 ldap_value_free_len (tempbv);
769 item->close_brace = 1;
774 ldap_parse_zone (
struct ldap_config_stack *item,
struct parse *cfile)
776 char *cnFindStart, *cnFindEnd;
777 struct berval **tempbv;
781 if ((tempbv = ldap_get_values_len (ld, item->ldent,
"cn")) != NULL)
783 x_parser_strcat (cfile,
"zone ");
784 x_parser_strcat (cfile, tempbv[0]->bv_val);
785 x_parser_strcat (cfile,
" {\n");
786 ldap_value_free_len (tempbv);
789 if ((tempbv = ldap_get_values_len (ld, item->ldent,
"dhcpDnsZoneServer")) != NULL)
791 x_parser_strcat (cfile,
"primary ");
792 x_parser_strcat (cfile, tempbv[0]->bv_val);
794 x_parser_strcat (cfile,
";\n");
795 ldap_value_free_len (tempbv);
798 if ((tempbv = ldap_get_values_len (ld, item->ldent,
"dhcpKeyDN")) != NULL)
800 cnFindStart = strchr(tempbv[0]->bv_val,
'=');
801 if (cnFindStart != NULL)
802 cnFindEnd = strchr(++cnFindStart,
',');
806 if (cnFindEnd != NULL && cnFindEnd > cnFindStart)
808 len = cnFindEnd - cnFindStart;
819 strncpy (keyCn, cnFindStart, len);
822 x_parser_strcat (cfile,
"key ");
823 x_parser_strcat (cfile, keyCn);
824 x_parser_strcat (cfile,
";\n");
829 ldap_value_free_len (tempbv);
832 item->close_brace = 1;
835 #if defined(HAVE_IFADDRS_H) 837 ldap_parse_failover (
struct ldap_config_stack *item,
struct parse *cfile)
839 struct berval **tempbv, **peername;
840 struct ifaddrs *addrs = NULL;
841 char srvaddr[2][64] = {
"\0",
"\0"};
842 int primary, split = 0, match;
844 if ((peername = ldap_get_values_len (ld, item->ldent,
"cn")) == NULL ||
847 if (peername != NULL)
848 ldap_value_free_len (peername);
851 log_error(
"Unable to find mandatory failover peering name attribute");
866 if ((tempbv = ldap_get_values_len (ld, item->ldent,
"dhcpFailOverPrimaryServer")) != NULL &&
869 match = get_host_address (tempbv[0]->bv_val, srvaddr[0],
sizeof(srvaddr[0]), addrs);
878 log_info(
"Can't resolve address of the primary failover '%s' server %s",
879 peername[0]->bv_val, tempbv[0]->bv_val);
880 ldap_value_free_len (tempbv);
881 ldap_value_free_len (peername);
888 ldap_value_free_len (tempbv);
890 if ((tempbv = ldap_get_values_len (ld, item->ldent,
"dhcpFailOverSecondaryServer")) != NULL &&
893 match = get_host_address (tempbv[0]->bv_val, srvaddr[1],
sizeof(srvaddr[1]), addrs);
900 log_info(
"Both, primary and secondary failover '%s' server" 901 " attributes match our local address", peername[0]->bv_val);
902 ldap_value_free_len (tempbv);
903 ldap_value_free_len (peername);
915 log_info(
"Can't resolve address of the secondary failover '%s' server %s",
916 peername[0]->bv_val, tempbv[0]->bv_val);
917 ldap_value_free_len (tempbv);
918 ldap_value_free_len (peername);
925 ldap_value_free_len (tempbv);
928 if (primary == -1 || srvaddr[0] ==
'\0' || srvaddr[1] ==
'\0')
930 log_error(
"Could not decide if the server type is primary" 931 " or secondary for failover peering '%s'.", peername[0]->bv_val);
932 ldap_value_free_len (peername);
938 x_parser_strcat (cfile,
"failover peer \"");
939 x_parser_strcat (cfile, peername[0]->bv_val);
940 x_parser_strcat (cfile,
"\" {\n");
943 x_parser_strcat (cfile,
"primary;\n");
945 x_parser_strcat (cfile,
"secondary;\n");
947 x_parser_strcat (cfile,
"address ");
949 x_parser_strcat (cfile, srvaddr[0]);
951 x_parser_strcat (cfile, srvaddr[1]);
952 x_parser_strcat (cfile,
";\n");
954 x_parser_strcat (cfile,
"peer address ");
956 x_parser_strcat (cfile, srvaddr[1]);
958 x_parser_strcat (cfile, srvaddr[0]);
959 x_parser_strcat (cfile,
";\n");
961 if ((tempbv = ldap_get_values_len (ld, item->ldent,
"dhcpFailOverPrimaryPort")) != NULL &&
965 x_parser_strcat (cfile,
"port ");
967 x_parser_strcat (cfile,
"peer port ");
968 x_parser_strcat (cfile, tempbv[0]->bv_val);
969 x_parser_strcat (cfile,
";\n");
972 ldap_value_free_len (tempbv);
974 if ((tempbv = ldap_get_values_len (ld, item->ldent,
"dhcpFailOverSecondaryPort")) != NULL &&
978 x_parser_strcat (cfile,
"peer port ");
980 x_parser_strcat (cfile,
"port ");
981 x_parser_strcat (cfile, tempbv[0]->bv_val);
982 x_parser_strcat (cfile,
";\n");
985 ldap_value_free_len (tempbv);
987 if ((tempbv = ldap_get_values_len (ld, item->ldent,
"dhcpFailOverResponseDelay")) != NULL &&
990 x_parser_strcat (cfile,
"max-response-delay ");
991 x_parser_strcat (cfile, tempbv[0]->bv_val);
992 x_parser_strcat (cfile,
";\n");
995 ldap_value_free_len (tempbv);
997 if ((tempbv = ldap_get_values_len (ld, item->ldent,
"dhcpFailOverUnackedUpdates")) != NULL &&
1000 x_parser_strcat (cfile,
"max-unacked-updates ");
1001 x_parser_strcat (cfile, tempbv[0]->bv_val);
1002 x_parser_strcat (cfile,
";\n");
1005 ldap_value_free_len (tempbv);
1007 if ((tempbv = ldap_get_values_len (ld, item->ldent,
"dhcpFailOverLoadBalanceTime")) != NULL &&
1010 x_parser_strcat (cfile,
"load balance max seconds ");
1011 x_parser_strcat (cfile, tempbv[0]->bv_val);
1012 x_parser_strcat (cfile,
";\n");
1015 ldap_value_free_len (tempbv);
1019 (tempbv = ldap_get_values_len (ld, item->ldent,
"dhcpMaxClientLeadTime")) != NULL &&
1022 x_parser_strcat (cfile,
"mclt ");
1023 x_parser_strcat (cfile, tempbv[0]->bv_val);
1024 x_parser_strcat (cfile,
";\n");
1027 ldap_value_free_len (tempbv);
1031 (tempbv = ldap_get_values_len (ld, item->ldent,
"dhcpFailOverSplit")) != NULL &&
1034 x_parser_strcat (cfile,
"split ");
1035 x_parser_strcat (cfile, tempbv[0]->bv_val);
1036 x_parser_strcat (cfile,
";\n");
1040 ldap_value_free_len (tempbv);
1043 if (primary && !split &&
1044 (tempbv = ldap_get_values_len (ld, item->ldent,
"dhcpFailOverHashBucketAssignment")) != NULL &&
1047 x_parser_strcat (cfile,
"hba ");
1048 x_parser_strcat (cfile, tempbv[0]->bv_val);
1049 x_parser_strcat (cfile,
";\n");
1052 ldap_value_free_len (tempbv);
1054 item->close_brace = 1;
1059 add_to_config_stack (LDAPMessage * res, LDAPMessage * ent)
1061 struct ldap_config_stack *ns;
1066 ns->close_brace = 0;
1068 ns->next = ldap_stack;
1075 struct sigaction old, new;
1087 new.sa_handler = SIG_IGN;
1088 sigemptyset (&
new.sa_mask);
1089 sigaction (SIGPIPE, &
new, &old);
1091 ldap_unbind_ext_s (ld, NULL, NULL);
1094 sigaction (SIGPIPE, &old, &
new);
1099 _do_lookup_dhcp_string_option (
struct option_state *options,
int option_name)
1105 memset (&db, 0,
sizeof (db));
1109 (
struct lease *) NULL,
1113 db.data != NULL && *db.data !=
'\0')
1118 log_fatal (
"no memory for ldap option %d value", option_name);
1120 memcpy (ret, db.data, db.len);
1132 _do_lookup_dhcp_int_option (
struct option_state *options,
int option_name)
1138 memset (&db, 0,
sizeof (db));
1142 (
struct lease *) NULL,
1146 db.data != NULL && *db.data !=
'\0')
1148 ret = strtol ((
const char *) db.data, NULL, 10);
1159 _do_lookup_dhcp_enum_option (
struct option_state *options,
int option_name)
1165 memset (&db, 0,
sizeof (db));
1169 (
struct lease *) NULL,
1173 db.data != NULL && *db.data !=
'\0')
1178 log_fatal (
"invalid option name %d", option_name);
1189 ldap_rebind_cb (LDAP *ld, LDAP_CONST
char *url, ber_tag_t request, ber_int_t msgid,
void *parms)
1192 LDAPURLDesc *ldapurl = NULL;
1194 struct berval creds;
1196 log_info(
"LDAP rebind to '%s'", url);
1197 if ((ret = ldap_url_parse(url, &ldapurl)) != LDAP_SUCCESS)
1199 log_error (
"Error: Can not parse ldap rebind url '%s': %s",
1200 url, ldap_err2string(ret));
1205 #if defined (LDAP_USE_SSL) 1206 if (strcasecmp(ldapurl->lud_scheme,
"ldaps") == 0)
1208 int opt = LDAP_OPT_X_TLS_HARD;
1209 if ((ret = ldap_set_option (ld, LDAP_OPT_X_TLS, &opt)) != LDAP_SUCCESS)
1211 log_error (
"Error: Cannot init LDAPS session to %s:%d: %s",
1212 ldapurl->lud_host, ldapurl->lud_port, ldap_err2string (ret));
1213 ldap_free_urldesc(ldapurl);
1218 log_info (
"LDAPS session successfully enabled to %s", ldap_server);
1222 if (strcasecmp(ldapurl->lud_scheme,
"ldap") == 0 &&
1223 ldap_use_ssl != LDAP_SSL_OFF)
1225 if ((ret = ldap_start_tls_s (ld, NULL, NULL)) != LDAP_SUCCESS)
1227 log_error (
"Error: Cannot start TLS session to %s:%d: %s",
1228 ldapurl->lud_host, ldapurl->lud_port, ldap_err2string (ret));
1229 ldap_free_urldesc(ldapurl);
1234 log_info (
"TLS session successfully started to %s:%d",
1235 ldapurl->lud_host, ldapurl->lud_port);
1240 #if defined(LDAP_USE_GSSAPI) 1241 if (ldap_gssapi_principal != NULL) {
1242 krb5_get_tgt(ldap_gssapi_principal, ldap_gssapi_keytab);
1243 if ((ret = ldap_sasl_interactive_bind_s(ld, NULL, ldap_sasl_inst->sasl_mech,
1244 NULL, NULL, LDAP_SASL_AUTOMATIC,
1245 _ldap_sasl_interact, ldap_sasl_inst)
1248 log_error (
"Error: Cannot SASL bind to ldap server %s:%d: %s",
1249 ldap_server, ldap_port, ldap_err2string (ret));
1251 ldap_get_option( ld, LDAP_OPT_DIAGNOSTIC_MESSAGE, (
void*)&msg);
1252 log_error (
"\tAdditional info: %s", msg);
1257 ldap_free_urldesc(ldapurl);
1262 if (ldap_username != NULL && *ldap_username !=
'\0' && ldap_password != NULL)
1264 who = ldap_username;
1265 creds.bv_val = strdup(ldap_password);
1266 if (creds.bv_val == NULL)
1267 log_fatal (
"Error: Unable to allocate memory to duplicate ldap_password");
1269 creds.bv_len = strlen(ldap_password);
1271 if ((ret = ldap_sasl_bind_s (ld, who, LDAP_SASL_SIMPLE, &creds,
1272 NULL, NULL, NULL)) != LDAP_SUCCESS)
1274 log_error (
"Error: Cannot login into ldap server %s:%d: %s",
1275 ldapurl->lud_host, ldapurl->lud_port, ldap_err2string (ret));
1282 ldap_free_urldesc(ldapurl);
1287 _do_ldap_retry(
int ret,
const char *server,
int port)
1289 static int inform = 1;
1291 if (ldap_enable_retry > 0 && ret == LDAP_SERVER_DOWN && ldap_init_retry > 0)
1293 if (inform || (ldap_init_retry % 10) == 0)
1296 log_info (
"Can't contact LDAP server %s:%d: retrying for %d sec",
1297 server, port, ldap_init_retry);
1300 return ldap_init_retry--;
1305 static struct berval *
1306 _do_ldap_str2esc_filter_bv(
const char *str, ber_len_t len,
struct berval *bv_o)
1310 if (!str || !bv_o || (ber_str2bv(str, len, 0, &bv_i) == NULL) ||
1311 (ldap_bv2escaped_filter_value(&bv_i, bv_o) != 0))
1322 struct berval creds;
1323 #if defined(LDAP_USE_GSSAPI) 1324 char *gssapi_realm = NULL;
1325 char *gssapi_user = NULL;
1326 char *running = NULL;
1327 const char *gssapi_delim =
"@";
1333 if (ldap_server == NULL)
1342 ldap_server = _do_lookup_dhcp_string_option (options, SV_LDAP_SERVER);
1343 ldap_dhcp_server_cn = _do_lookup_dhcp_string_option (options,
1344 SV_LDAP_DHCP_SERVER_CN);
1345 ldap_port = _do_lookup_dhcp_int_option (options, SV_LDAP_PORT);
1346 ldap_base_dn = _do_lookup_dhcp_string_option (options, SV_LDAP_BASE_DN);
1347 ldap_method = _do_lookup_dhcp_enum_option (options, SV_LDAP_METHOD);
1348 ldap_debug_file = _do_lookup_dhcp_string_option (options,
1349 SV_LDAP_DEBUG_FILE);
1350 ldap_referrals = _do_lookup_dhcp_enum_option (options, SV_LDAP_REFERRALS);
1351 ldap_init_retry = _do_lookup_dhcp_int_option (options, SV_LDAP_INIT_RETRY);
1353 #if defined (LDAP_USE_SSL) 1354 ldap_use_ssl = _do_lookup_dhcp_enum_option (options, SV_LDAP_SSL);
1355 if( ldap_use_ssl != LDAP_SSL_OFF)
1357 ldap_tls_reqcert = _do_lookup_dhcp_enum_option (options, SV_LDAP_TLS_REQCERT);
1358 ldap_tls_ca_file = _do_lookup_dhcp_string_option (options, SV_LDAP_TLS_CA_FILE);
1359 ldap_tls_ca_dir = _do_lookup_dhcp_string_option (options, SV_LDAP_TLS_CA_DIR);
1360 ldap_tls_cert = _do_lookup_dhcp_string_option (options, SV_LDAP_TLS_CERT);
1361 ldap_tls_key = _do_lookup_dhcp_string_option (options, SV_LDAP_TLS_KEY);
1362 ldap_tls_crlcheck = _do_lookup_dhcp_enum_option (options, SV_LDAP_TLS_CRLCHECK);
1363 ldap_tls_ciphers = _do_lookup_dhcp_string_option (options, SV_LDAP_TLS_CIPHERS);
1364 ldap_tls_randfile = _do_lookup_dhcp_string_option (options, SV_LDAP_TLS_RANDFILE);
1368 #if defined (LDAP_USE_GSSAPI) 1369 ldap_gssapi_principal = _do_lookup_dhcp_string_option (options,
1370 SV_LDAP_GSSAPI_PRINCIPAL);
1372 if (ldap_gssapi_principal == NULL) {
1373 log_error(
"ldap_gssapi_principal is not set," 1374 "GSSAPI Authentication for LDAP will not be used");
1376 ldap_gssapi_keytab = _do_lookup_dhcp_string_option (options,
1377 SV_LDAP_GSSAPI_KEYTAB);
1378 if (ldap_gssapi_keytab == NULL) {
1379 log_fatal(
"ldap_gssapi_keytab must be specified");
1382 running = strdup(ldap_gssapi_principal);
1383 if (running == NULL)
1384 log_fatal(
"Could not allocate memory to duplicate gssapi principal");
1386 gssapi_user = strtok(running, gssapi_delim);
1387 if (!gssapi_user || strlen(gssapi_user) == 0) {
1388 log_fatal (
"GSSAPI principal must specify user: user@realm");
1391 gssapi_realm = strtok(NULL, gssapi_delim);
1392 if (!gssapi_realm || strlen(gssapi_realm) == 0) {
1393 log_fatal (
"GSSAPI principal must specify realm: user@realm");
1396 ldap_sasl_inst = malloc(
sizeof(
struct ldap_sasl_instance));
1397 if (ldap_sasl_inst == NULL)
1398 log_fatal(
"Could not allocate memory for sasl instance! Can not run!");
1400 ldap_sasl_inst->sasl_mech = ber_strdup(
"GSSAPI");
1401 if (ldap_sasl_inst->sasl_mech == NULL)
1402 log_fatal(
"Could not allocate memory to duplicate gssapi mechanism");
1404 ldap_sasl_inst->sasl_realm = ber_strdup(gssapi_realm);
1405 if (ldap_sasl_inst->sasl_realm == NULL)
1406 log_fatal(
"Could not allocate memory to duplicate gssapi realm");
1408 ldap_sasl_inst->sasl_authz_id = ber_strdup(gssapi_user);
1409 if (ldap_sasl_inst->sasl_authz_id == NULL)
1410 log_fatal(
"Could not allocate memory to duplicate gssapi user");
1412 ldap_sasl_inst->sasl_authc_id = NULL;
1413 ldap_sasl_inst->sasl_password = NULL;
1418 #if defined (LDAP_CASA_AUTH) 1419 if (!load_uname_pwd_from_miCASA(&ldap_username,&ldap_password))
1421 #if defined (DEBUG_LDAP) 1422 log_info (
"Authentication credential taken from file");
1426 ldap_username = _do_lookup_dhcp_string_option (options, SV_LDAP_USERNAME);
1427 ldap_password = _do_lookup_dhcp_string_option (options, SV_LDAP_PASSWORD);
1429 #if defined (LDAP_CASA_AUTH) 1436 if (ldap_server == NULL || ldap_base_dn == NULL)
1438 log_info (
"Not searching LDAP since ldap-server, ldap-port and ldap-base-dn were not specified in the config file");
1439 ldap_method = LDAP_METHOD_STATIC;
1443 if (ldap_debug_file != NULL && ldap_debug_fd == -1)
1445 if ((ldap_debug_fd = open (ldap_debug_file, O_CREAT | O_TRUNC | O_WRONLY | O_CLOEXEC,
1446 S_IRUSR | S_IWUSR)) < 0)
1447 log_error (
"Error opening debug LDAP log file %s: %s", ldap_debug_file,
1451 #if defined (DEBUG_LDAP) 1452 log_info (
"Connecting to LDAP server %s:%d", ldap_server, ldap_port);
1455 #if defined (LDAP_USE_SSL) 1456 if (ldap_use_ssl == -1)
1463 int opt = LDAP_OPT_X_TLS_ALLOW;
1464 if ((ret = ldap_set_option (NULL, LDAP_OPT_X_TLS_REQUIRE_CERT,
1465 &opt)) != LDAP_SUCCESS)
1467 log_error (
"Warning: Cannot set LDAP TLS require cert option to 'allow': %s",
1468 ldap_err2string (ret));
1472 if (ldap_use_ssl != LDAP_SSL_OFF)
1474 if (ldap_tls_reqcert != -1)
1476 if ((ret = ldap_set_option (NULL, LDAP_OPT_X_TLS_REQUIRE_CERT,
1477 &ldap_tls_reqcert)) != LDAP_SUCCESS)
1479 log_error (
"Cannot set LDAP TLS require cert option: %s",
1480 ldap_err2string (ret));
1484 if( ldap_tls_ca_file != NULL)
1486 if ((ret = ldap_set_option (NULL, LDAP_OPT_X_TLS_CACERTFILE,
1487 ldap_tls_ca_file)) != LDAP_SUCCESS)
1489 log_error (
"Cannot set LDAP TLS CA certificate file %s: %s",
1490 ldap_tls_ca_file, ldap_err2string (ret));
1493 if( ldap_tls_ca_dir != NULL)
1495 if ((ret = ldap_set_option (NULL, LDAP_OPT_X_TLS_CACERTDIR,
1496 ldap_tls_ca_dir)) != LDAP_SUCCESS)
1498 log_error (
"Cannot set LDAP TLS CA certificate dir %s: %s",
1499 ldap_tls_ca_dir, ldap_err2string (ret));
1502 if( ldap_tls_cert != NULL)
1504 if ((ret = ldap_set_option (NULL, LDAP_OPT_X_TLS_CERTFILE,
1505 ldap_tls_cert)) != LDAP_SUCCESS)
1507 log_error (
"Cannot set LDAP TLS client certificate file %s: %s",
1508 ldap_tls_cert, ldap_err2string (ret));
1511 if( ldap_tls_key != NULL)
1513 if ((ret = ldap_set_option (NULL, LDAP_OPT_X_TLS_KEYFILE,
1514 ldap_tls_key)) != LDAP_SUCCESS)
1516 log_error (
"Cannot set LDAP TLS certificate key file %s: %s",
1517 ldap_tls_key, ldap_err2string (ret));
1520 if( ldap_tls_crlcheck != -1)
1522 int opt = ldap_tls_crlcheck;
1523 if ((ret = ldap_set_option (NULL, LDAP_OPT_X_TLS_CRLCHECK,
1524 &opt)) != LDAP_SUCCESS)
1526 log_error (
"Cannot set LDAP TLS crl check option: %s",
1527 ldap_err2string (ret));
1530 if( ldap_tls_ciphers != NULL)
1532 if ((ret = ldap_set_option (NULL, LDAP_OPT_X_TLS_CIPHER_SUITE,
1533 ldap_tls_ciphers)) != LDAP_SUCCESS)
1535 log_error (
"Cannot set LDAP TLS cipher suite %s: %s",
1536 ldap_tls_ciphers, ldap_err2string (ret));
1539 if( ldap_tls_randfile != NULL)
1541 if ((ret = ldap_set_option (NULL, LDAP_OPT_X_TLS_RANDOM_FILE,
1542 ldap_tls_randfile)) != LDAP_SUCCESS)
1544 log_error (
"Cannot set LDAP TLS random file %s: %s",
1545 ldap_tls_randfile, ldap_err2string (ret));
1552 uri = malloc(strlen(ldap_server) + 16);
1555 log_error (
"Cannot build ldap init URI %s:%d", ldap_server, ldap_port);
1559 sprintf(uri,
"ldap://%s:%d", ldap_server, ldap_port);
1560 ldap_initialize(&ld, uri);
1564 log_error (
"Cannot init ldap session to %s:%d", ldap_server, ldap_port);
1570 version = LDAP_VERSION3;
1571 if ((ret = ldap_set_option (ld, LDAP_OPT_PROTOCOL_VERSION, &version)) != LDAP_OPT_SUCCESS)
1573 log_error (
"Cannot set LDAP version to %d: %s", version,
1574 ldap_err2string (ret));
1577 if (ldap_referrals != -1)
1579 if ((ret = ldap_set_option (ld, LDAP_OPT_REFERRALS, ldap_referrals ?
1580 LDAP_OPT_ON : LDAP_OPT_OFF)) != LDAP_OPT_SUCCESS)
1582 log_error (
"Cannot %s LDAP referrals option: %s",
1583 (ldap_referrals ?
"enable" :
"disable"),
1584 ldap_err2string (ret));
1588 if ((ret = ldap_set_rebind_proc(ld, ldap_rebind_cb, NULL)) != LDAP_SUCCESS)
1590 log_error (
"Warning: Cannot set ldap rebind procedure: %s",
1591 ldap_err2string (ret));
1594 #if defined (LDAP_USE_SSL) 1595 if (ldap_use_ssl == LDAP_SSL_LDAPS ||
1596 (ldap_use_ssl == LDAP_SSL_ON && ldap_port == LDAPS_PORT))
1598 int opt = LDAP_OPT_X_TLS_HARD;
1599 if ((ret = ldap_set_option (ld, LDAP_OPT_X_TLS, &opt)) != LDAP_SUCCESS)
1601 log_error (
"Error: Cannot init LDAPS session to %s:%d: %s",
1602 ldap_server, ldap_port, ldap_err2string (ret));
1608 log_info (
"LDAPS session successfully enabled to %s:%d",
1609 ldap_server, ldap_port);
1612 else if (ldap_use_ssl != LDAP_SSL_OFF)
1616 ret = ldap_start_tls_s (ld, NULL, NULL);
1618 while(_do_ldap_retry(ret, ldap_server, ldap_port) > 0);
1620 if (ret != LDAP_SUCCESS)
1622 log_error (
"Error: Cannot start TLS session to %s:%d: %s",
1623 ldap_server, ldap_port, ldap_err2string (ret));
1629 log_info (
"TLS session successfully started to %s:%d",
1630 ldap_server, ldap_port);
1635 #if defined(LDAP_USE_GSSAPI) 1636 if (ldap_gssapi_principal != NULL) {
1637 krb5_get_tgt(ldap_gssapi_principal, ldap_gssapi_keytab);
1638 if ((ret = ldap_sasl_interactive_bind_s(ld, NULL, ldap_sasl_inst->sasl_mech,
1639 NULL, NULL, LDAP_SASL_AUTOMATIC,
1640 _ldap_sasl_interact, ldap_sasl_inst)
1643 log_error (
"Error: Cannot SASL bind to ldap server %s:%d: %s",
1644 ldap_server, ldap_port, ldap_err2string (ret));
1646 ldap_get_option( ld, LDAP_OPT_DIAGNOSTIC_MESSAGE, (
void*)&msg);
1647 log_error (
"\tAdditional info: %s", msg);
1655 if (ldap_username != NULL && *ldap_username !=
'\0' && ldap_password != NULL)
1657 creds.bv_val = strdup(ldap_password);
1658 if (creds.bv_val == NULL)
1659 log_fatal (
"Error: Unable to allocate memory to duplicate ldap_password");
1661 creds.bv_len = strlen(ldap_password);
1665 ret = ldap_sasl_bind_s (ld, ldap_username, LDAP_SASL_SIMPLE,
1666 &creds, NULL, NULL, NULL);
1668 while(_do_ldap_retry(ret, ldap_server, ldap_port) > 0);
1671 if (ret != LDAP_SUCCESS)
1673 log_error (
"Error: Cannot login into ldap server %s:%d: %s",
1674 ldap_server, ldap_port, ldap_err2string (ret));
1680 #if defined (DEBUG_LDAP) 1681 log_info (
"Successfully logged into LDAP server %s", ldap_server);
1687 parse_external_dns (LDAPMessage * ent)
1689 char *search[] = {
"dhcpOptionsDN",
"dhcpSharedNetworkDN",
"dhcpSubnetDN",
1690 "dhcpGroupDN",
"dhcpHostDN",
"dhcpClassesDN",
1691 "dhcpPoolDN",
"dhcpZoneDN",
"dhcpFailOverPeerDN", NULL};
1700 LDAPMessage * newres, * newent;
1701 struct berval **tempbv;
1703 #if defined (DEBUG_LDAP) 1706 dn = ldap_get_dn (ld, ent);
1709 log_info (
"Parsing external DNs for '%s'", dn);
1719 for (i=0; search[i] != NULL; i++)
1721 if ((tempbv = ldap_get_values_len (ld, ent, search[i])) == NULL)
1724 for (j=0; tempbv[j] != NULL; j++)
1726 if (*tempbv[j]->bv_val ==
'\0')
1729 if ((ret = ldap_search_ext_s(ld, tempbv[j]->bv_val, LDAP_SCOPE_BASE,
1730 "objectClass=*", NULL, 0, NULL,
1731 NULL, NULL, 0, &newres)) != LDAP_SUCCESS)
1733 ldap_value_free_len (tempbv);
1738 #if defined (DEBUG_LDAP) 1739 log_info (
"Adding contents of subtree '%s' to config stack from '%s' reference", tempbv[j]->bv_val, search[i]);
1741 for (newent = ldap_first_entry (ld, newres);
1743 newent = ldap_next_entry (ld, newent))
1745 #if defined (DEBUG_LDAP) 1746 dn = ldap_get_dn (ld, newent);
1749 log_info (
"Adding LDAP result set starting with '%s' to config stack", dn);
1754 add_to_config_stack (newres, newent);
1759 ldap_value_free_len (tempbv);
1765 free_stack_entry (
struct ldap_config_stack *item)
1767 struct ldap_config_stack *look_ahead_pointer = item;
1768 int may_free_msg = 1;
1770 while (look_ahead_pointer->next != NULL)
1772 look_ahead_pointer = look_ahead_pointer->next;
1773 if (look_ahead_pointer->res == item->res)
1781 ldap_msgfree (item->res);
1788 next_ldap_entry (
struct parse *cfile)
1790 struct ldap_config_stack *temp_stack;
1792 if (ldap_stack != NULL && ldap_stack->close_brace)
1794 x_parser_strcat (cfile,
"}\n");
1795 ldap_stack->close_brace = 0;
1798 while (ldap_stack != NULL &&
1799 (ldap_stack->ldent == NULL || ( ldap_stack->processed &&
1800 (ldap_stack->ldent = ldap_next_entry (ld, ldap_stack->ldent)) == NULL)))
1802 if (ldap_stack->close_brace)
1804 x_parser_strcat (cfile,
"}\n");
1805 ldap_stack->close_brace = 0;
1808 temp_stack = ldap_stack;
1809 ldap_stack = ldap_stack->next;
1810 free_stack_entry (temp_stack);
1813 if (ldap_stack != NULL && ldap_stack->close_brace)
1815 x_parser_strcat (cfile,
"}\n");
1816 ldap_stack->close_brace = 0;
1822 check_statement_end (
const char *statement)
1826 if (statement == NULL || *statement ==
'\0')
1834 ptr = strrchr (statement,
'}');
1838 for (++ptr; isspace ((
int)*ptr); ptr++);
1853 ptr = strrchr (statement,
';');
1857 for (++ptr; isspace ((
int)*ptr); ptr++);
1871 ldap_parse_entry_options (LDAPMessage *ent,
struct parse *cfile,
1874 struct berval **tempbv;
1877 if (ent == NULL || cfile == NULL)
1878 return (ISC_R_FAILURE);
1880 if ((tempbv = ldap_get_values_len (ld, ent,
"dhcpStatements")) != NULL)
1882 for (i=0; tempbv[i] != NULL; i++)
1884 if (lease_limit != NULL &&
1885 strncasecmp (
"lease limit ", tempbv[i]->bv_val, 12) == 0)
1887 *lease_limit = (
int) strtol ((tempbv[i]->bv_val) + 12, NULL, 10);
1891 x_parser_strcat (cfile, tempbv[i]->bv_val);
1893 switch((
int) check_statement_end (tempbv[i]->bv_val))
1897 x_parser_strcat (cfile,
"\n");
1900 x_parser_strcat (cfile,
";\n");
1904 ldap_value_free_len (tempbv);
1907 if ((tempbv = ldap_get_values_len (ld, ent,
"dhcpOption")) != NULL)
1909 for (i=0; tempbv[i] != NULL; i++)
1911 x_parser_strcat (cfile,
"option ");
1912 x_parser_strcat (cfile, tempbv[i]->bv_val);
1913 switch ((
int) check_statement_end (tempbv[i]->bv_val))
1916 x_parser_strcat (cfile,
"\n");
1919 x_parser_strcat (cfile,
";\n");
1923 ldap_value_free_len (tempbv);
1926 return (ISC_R_SUCCESS);
1931 ldap_generate_config_string (
struct parse *cfile)
1933 struct berval **objectClass;
1935 struct ldap_config_stack *entry;
1936 LDAPMessage * ent, * res, *entfirst, *resfirst;
1937 int i, ignore, found;
1938 int ret, parsedn = 1;
1939 size_t len = cfile->
buflen;
1947 if ((objectClass = ldap_get_values_len (ld, entry->ldent,
1948 "objectClass")) == NULL)
1951 entry->processed = 1;
1954 for (i=0; objectClass[i] != NULL; i++)
1956 if (strcasecmp (objectClass[i]->bv_val,
"dhcpSharedNetwork") == 0)
1957 ldap_parse_shared_network (entry, cfile);
1958 else if (strcasecmp (objectClass[i]->bv_val,
"dhcpClass") == 0)
1959 ldap_parse_class (entry, cfile);
1960 else if (strcasecmp (objectClass[i]->bv_val,
"dhcpSubnet") == 0)
1961 ldap_parse_subnet (entry, cfile);
1962 else if (strcasecmp (objectClass[i]->bv_val,
"dhcpSubnet6") == 0)
1963 ldap_parse_subnet6 (entry, cfile);
1964 else if (strcasecmp (objectClass[i]->bv_val,
"dhcpPool") == 0)
1965 ldap_parse_pool (entry, cfile);
1966 else if (strcasecmp (objectClass[i]->bv_val,
"dhcpPool6") == 0)
1967 ldap_parse_pool6 (entry, cfile);
1968 else if (strcasecmp (objectClass[i]->bv_val,
"dhcpGroup") == 0)
1969 ldap_parse_group (entry, cfile);
1970 else if (strcasecmp (objectClass[i]->bv_val,
"dhcpTSigKey") == 0)
1971 ldap_parse_key (entry, cfile);
1972 else if (strcasecmp (objectClass[i]->bv_val,
"dhcpDnsZone") == 0)
1973 ldap_parse_zone (entry, cfile);
1974 #if defined(HAVE_IFADDRS_H) 1975 else if (strcasecmp (objectClass[i]->bv_val,
"dhcpFailOverPeer") == 0)
1976 ldap_parse_failover (entry, cfile);
1978 else if (strcasecmp (objectClass[i]->bv_val,
"dhcpHost") == 0)
1980 if (ldap_method == LDAP_METHOD_STATIC)
1981 ldap_parse_host (entry, cfile);
1988 else if (strcasecmp (objectClass[i]->bv_val,
"dhcpSubClass") == 0)
1990 if (ldap_method == LDAP_METHOD_STATIC)
1991 ldap_parse_subclass (entry, cfile);
2001 if (found && x_parser_length(cfile) <= len)
2008 ldap_value_free_len (objectClass);
2012 next_ldap_entry (cfile);
2016 ldap_parse_entry_options(entry->ldent, cfile, NULL);
2018 dn = ldap_get_dn (ld, entry->ldent);
2024 #if defined(DEBUG_LDAP) 2025 log_info (
"Found LDAP entry '%s'", dn);
2028 if ((ret = ldap_search_ext_s (ld, dn, LDAP_SCOPE_ONELEVEL,
2029 "(!(|(|(objectClass=dhcpTSigKey)(objectClass=dhcpClass)) (objectClass=dhcpFailOverPeer)))",
2030 NULL, 0, NULL, NULL,
2031 NULL, 0, &res)) != LDAP_SUCCESS)
2039 if ((ret = ldap_search_ext_s (ld, dn, LDAP_SCOPE_ONELEVEL,
2040 "(|(|(objectClass=dhcpTSigKey)(objectClass=dhcpClass)) (objectClass=dhcpFailOverPeer))",
2041 NULL, 0, NULL, NULL,
2042 NULL, 0, &resfirst)) != LDAP_SUCCESS)
2053 ent = ldap_first_entry(ld, res);
2054 entfirst = ldap_first_entry(ld, resfirst);
2056 if (ent == NULL && entfirst == NULL)
2058 parse_external_dns (entry->ldent);
2059 next_ldap_entry (cfile);
2064 add_to_config_stack (res, ent);
2065 parse_external_dns (entry->ldent);
2071 if (entfirst != NULL)
2073 add_to_config_stack (resfirst, entfirst);
2075 parse_external_dns (entry->ldent);
2079 ldap_msgfree (resfirst);
2084 ldap_close_debug_fd()
2086 if (ldap_debug_fd != -1)
2088 close (ldap_debug_fd);
2095 ldap_write_debug (
const void *buff,
size_t size)
2097 if (ldap_debug_fd != -1)
2099 if (write (ldap_debug_fd, buff, size) < 0)
2101 log_error (
"Error writing to LDAP debug file %s: %s." 2102 " Disabling log file.", ldap_debug_file,
2104 ldap_close_debug_fd();
2110 ldap_read_function (
struct parse *cfile)
2117 cfile->
inbuf[0] =
'\0';
2123 while (ldap_stack != NULL && x_parser_length(cfile) <= len)
2124 ldap_generate_config_string (cfile);
2126 if (x_parser_length(cfile) <= len && ldap_stack == NULL)
2130 ldap_write_debug (cfile->
inbuf + len, cfile->
buflen - len);
2131 #if defined (DEBUG_LDAP) 2132 log_info (
"Sending config portion '%s'", cfile->
inbuf + len);
2140 ldap_get_host_name (LDAPMessage * ent)
2142 struct berval **name;
2146 if ((name = ldap_get_values_len (ld, ent,
"cn")) == NULL || name[0] == NULL)
2149 ldap_value_free_len (name);
2151 #if defined (DEBUG_LDAP) 2152 ret = ldap_get_dn (ld, ent);
2155 log_info (
"Cannot get cn attribute for LDAP entry %s", ret);
2162 ret =
dmalloc (strlen (name[0]->bv_val) + 1,
MDL);
2163 strcpy (ret, name[0]->bv_val);
2164 ldap_value_free_len (name);
2171 ldap_read_config (
void)
2173 LDAPMessage * ldres, * hostres, * ent, * hostent;
2174 char hfilter[1024], sfilter[1024], fqdn[257];
2176 ldap_dn_node *curr = NULL;
2177 struct parse *cfile;
2178 struct utsname unme;
2182 struct berval **tempbv = NULL;
2183 struct berval bv_o[2];
2185 cfile = x_parser_init(
"LDAP");
2187 return (ISC_R_NOMEMORY);
2189 ldap_enable_retry = 1;
2192 ldap_enable_retry = 0;
2196 x_parser_free(&cfile);
2197 return (ldap_server == NULL ? ISC_R_SUCCESS : ISC_R_FAILURE);
2201 if (ldap_dhcp_server_cn != NULL)
2203 if (_do_ldap_str2esc_filter_bv(ldap_dhcp_server_cn, 0, &bv_o[0]) == NULL)
2205 log_error (
"Cannot escape ldap filter value %s: %m", ldap_dhcp_server_cn);
2206 x_parser_free(&cfile);
2207 return (ISC_R_FAILURE);
2210 snprintf (hfilter,
sizeof (hfilter),
2211 "(&(objectClass=dhcpServer)(cn=%s))", bv_o[0].bv_val);
2213 ber_memfree(bv_o[0].bv_val);
2217 if (_do_ldap_str2esc_filter_bv(unme.nodename, 0, &bv_o[0]) == NULL)
2219 log_error (
"Cannot escape ldap filter value %s: %m", unme.nodename);
2220 x_parser_free(&cfile);
2221 return (ISC_R_FAILURE);
2225 if(0 == get_host_entry(fqdn,
sizeof(fqdn), NULL, 0))
2227 if (_do_ldap_str2esc_filter_bv(fqdn, 0, &bv_o[1]) == NULL)
2229 log_error (
"Cannot escape ldap filter value %s: %m", fqdn);
2230 ber_memfree(bv_o[0].bv_val);
2231 x_parser_free(&cfile);
2232 return (ISC_R_FAILURE);
2238 if ((*fqdn) && (strcmp(unme.nodename, fqdn))) {
2239 snprintf (hfilter,
sizeof (hfilter),
2240 "(&(objectClass=dhcpServer)(|(cn=%s)(cn=%s)))",
2241 bv_o[0].bv_val, bv_o[1].bv_val);
2243 ber_memfree(bv_o[1].bv_val);
2247 snprintf (hfilter,
sizeof (hfilter),
2248 "(&(objectClass=dhcpServer)(cn=%s))",
2252 ber_memfree(bv_o[0].bv_val);
2255 ldap_enable_retry = 1;
2259 ret = ldap_search_ext_s (ld, ldap_base_dn, LDAP_SCOPE_SUBTREE,
2260 hfilter, NULL, 0, NULL, NULL, NULL, 0,
2263 while(_do_ldap_retry(ret, ldap_server, ldap_port) > 0);
2264 ldap_enable_retry = 0;
2266 if(ret != LDAP_SUCCESS)
2268 log_error (
"Cannot find host LDAP entry %s %s",
2269 ((ldap_dhcp_server_cn == NULL)?(unme.nodename):(ldap_dhcp_server_cn)), hfilter);
2271 ldap_msgfree (hostres);
2273 x_parser_free(&cfile);
2274 return (ISC_R_FAILURE);
2277 if ((hostent = ldap_first_entry (ld, hostres)) == NULL)
2279 log_error (
"Error: Cannot find LDAP entry matching %s", hfilter);
2280 ldap_msgfree (hostres);
2282 x_parser_free(&cfile);
2283 return (ISC_R_FAILURE);
2286 hostdn = ldap_get_dn (ld, hostent);
2287 #if defined(DEBUG_LDAP) 2289 log_info (
"Found dhcpServer LDAP entry '%s'", hostdn);
2292 if (hostdn == NULL ||
2293 (tempbv = ldap_get_values_len (ld, hostent,
"dhcpServiceDN")) == NULL ||
2296 log_error (
"Error: No dhcp service is associated with the server %s %s",
2297 (hostdn ?
"dn" :
"name"), (hostdn ? hostdn :
2298 (ldap_dhcp_server_cn ? ldap_dhcp_server_cn : unme.nodename)));
2301 ldap_value_free_len (tempbv);
2304 ldap_memfree (hostdn);
2305 ldap_msgfree (hostres);
2307 x_parser_free(&cfile);
2308 return (ISC_R_FAILURE);
2311 #if defined(DEBUG_LDAP) 2312 log_info (
"LDAP: Parsing dhcpServer options '%s' ...", hostdn);
2315 res = ldap_parse_entry_options(hostent, cfile, NULL);
2316 if (res != ISC_R_SUCCESS)
2318 ldap_value_free_len (tempbv);
2319 ldap_msgfree (hostres);
2320 ldap_memfree (hostdn);
2322 x_parser_free(&cfile);
2326 if (x_parser_length(cfile) > 0)
2328 ldap_write_debug(cfile->inbuf, cfile->buflen);
2331 if (res != ISC_R_SUCCESS)
2333 log_error (
"LDAP: cannot parse dhcpServer entry '%s'", hostdn);
2334 ldap_value_free_len (tempbv);
2335 ldap_msgfree (hostres);
2336 ldap_memfree (hostdn);
2338 x_parser_free(&cfile);
2341 x_parser_reset(cfile);
2343 ldap_msgfree (hostres);
2345 res = ISC_R_SUCCESS;
2346 for (cnt=0; tempbv[cnt] != NULL; cnt++)
2349 if (_do_ldap_str2esc_filter_bv(hostdn, 0, &bv_o[0]) == NULL)
2351 log_error (
"Cannot escape ldap filter value %s: %m", hostdn);
2352 res = ISC_R_FAILURE;
2356 snprintf(sfilter,
sizeof(sfilter),
"(&(objectClass=dhcpService)" 2357 "(|(|(dhcpPrimaryDN=%s)(dhcpSecondaryDN=%s))(dhcpServerDN=%s)))",
2358 bv_o[0].bv_val, bv_o[0].bv_val, bv_o[0].bv_val);
2360 ber_memfree(bv_o[0].bv_val);
2363 if ((ret = ldap_search_ext_s (ld, tempbv[cnt]->bv_val, LDAP_SCOPE_BASE,
2364 sfilter, NULL, 0, NULL, NULL, NULL,
2365 0, &ldres)) != LDAP_SUCCESS)
2367 log_error (
"Error searching for dhcpServiceDN '%s': %s. Please update the LDAP entry '%s'",
2368 tempbv[cnt]->bv_val, ldap_err2string (ret), hostdn);
2370 ldap_msgfree(ldres);
2371 res = ISC_R_FAILURE;
2375 if ((ent = ldap_first_entry (ld, ldres)) == NULL)
2377 log_error (
"Error: Cannot find dhcpService DN '%s' with server reference. Please update the LDAP server entry '%s'",
2378 tempbv[cnt]->bv_val, hostdn);
2380 ldap_msgfree(ldres);
2381 res = ISC_R_FAILURE;
2394 length = strlen (tempbv[cnt]->bv_val);
2396 if (curr->dn == NULL)
2402 strcpy (curr->dn, tempbv[cnt]->bv_val);
2410 if (ldap_service_dn_tail != NULL)
2411 ldap_service_dn_tail->next = curr;
2413 ldap_service_dn_head = curr;
2415 ldap_service_dn_tail = curr;
2418 log_fatal (
"no memory to remember ldap service dn");
2420 #if defined (DEBUG_LDAP) 2421 log_info (
"LDAP: Parsing dhcpService DN '%s' ...", tempbv[cnt]->bv_val);
2423 add_to_config_stack (ldres, ent);
2425 if (res != ISC_R_SUCCESS)
2427 log_error (
"LDAP: cannot parse dhcpService entry '%s'", tempbv[cnt]->bv_val);
2432 x_parser_free(&cfile);
2433 ldap_close_debug_fd();
2435 ldap_memfree (hostdn);
2436 ldap_value_free_len (tempbv);
2438 if (res != ISC_R_SUCCESS)
2440 struct ldap_config_stack *temp_stack;
2442 while ((curr = ldap_service_dn_head) != NULL)
2444 ldap_service_dn_head = curr->next;
2449 ldap_service_dn_tail = NULL;
2451 while ((temp_stack = ldap_stack) != NULL)
2453 ldap_stack = temp_stack->next;
2454 free_stack_entry (temp_stack);
2461 if (ldap_method == LDAP_METHOD_STATIC)
2475 ldap_parse_options (LDAPMessage * ent,
struct group *
group,
2477 struct class **
class)
2479 int declaration, lease_limit;
2481 struct parse *cfile;
2486 cfile = x_parser_init(type ==
HOST_DECL ?
"LDAP-HOST" :
"LDAP-SUBCLASS");
2488 return (lease_limit);
2494 char *hostdn, *basedn, *temp1, *temp2, filter[1024];
2495 LDAPMessage *groupdn, *entry;
2498 hostdn = ldap_get_dn (ld, ent);
2503 temp1 = strchr (hostdn,
'=');
2505 temp1 = strchr (++temp1,
'=');
2507 temp2 = strchr (++temp1,
',');
2515 if (_do_ldap_str2esc_filter_bv(temp1, (temp2 - temp1), &bv_o) == NULL)
2517 log_error (
"Cannot escape ldap filter value %.*s: %m",
2518 (
int)(temp2 - temp1), temp1);
2523 snprintf (filter,
sizeof(filter),
2524 "(&(cn=%s)(objectClass=dhcpGroup))",
2527 ber_memfree(bv_o.bv_val);
2530 basedn = strchr (temp1,
',');
2535 if (basedn != NULL && *basedn !=
'\0' && filter[0] !=
'\0')
2537 ret = ldap_search_ext_s (ld, basedn, LDAP_SCOPE_SUBTREE, filter,
2538 NULL, 0, NULL, NULL, NULL, 0, &groupdn);
2539 if (ret == LDAP_SUCCESS)
2541 if ((entry = ldap_first_entry (ld, groupdn)) != NULL)
2543 res = ldap_parse_entry_options (entry, cfile, &lease_limit);
2544 if (res != ISC_R_SUCCESS)
2547 x_parser_reset(cfile);
2551 ldap_msgfree( groupdn);
2554 ldap_memfree( hostdn);
2558 res = ldap_parse_entry_options (ent, cfile, &lease_limit);
2559 if (res != ISC_R_SUCCESS)
2561 x_parser_free(&cfile);
2562 return (lease_limit);
2565 if (x_parser_length(cfile) == 0)
2567 x_parser_free(&cfile);
2568 return (lease_limit);
2577 declaration =
parse_statement (cfile, group, type, host, declaration);
2580 x_parser_free(&cfile);
2582 return (lease_limit);
2588 find_haddr_in_ldap (
struct host_decl **hp,
int htype,
unsigned hlen,
2589 const unsigned char *haddr,
const char *
file,
int line)
2591 char buf[128], *type_str;
2592 LDAPMessage * res, *ent;
2594 isc_result_t status;
2599 struct berval bv_o[2];
2604 if (ldap_method == LDAP_METHOD_STATIC)
2615 type_str =
"ethernet";
2618 type_str =
"token-ring";
2624 log_info (
"Ignoring unknown type %d", htype);
2632 snprintf(lo_hwaddr,
sizeof(lo_hwaddr),
"%s",
2634 x_strxform(up_hwaddr, lo_hwaddr,
sizeof(up_hwaddr), toupper);
2636 if (_do_ldap_str2esc_filter_bv(lo_hwaddr, 0, &bv_o[0]) == NULL)
2638 log_error (
"Cannot escape ldap filter value %s: %m", lo_hwaddr);
2641 if (_do_ldap_str2esc_filter_bv(up_hwaddr, 0, &bv_o[1]) == NULL)
2643 log_error (
"Cannot escape ldap filter value %s: %m", up_hwaddr);
2644 ber_memfree(bv_o[0].bv_val);
2648 snprintf (buf,
sizeof (buf),
2649 "(&(objectClass=dhcpHost)(|(dhcpHWAddress=%s %s)(dhcpHWAddress=%s %s)))",
2650 type_str, bv_o[0].bv_val, type_str, bv_o[1].bv_val);
2652 ber_memfree(bv_o[0].bv_val);
2653 ber_memfree(bv_o[1].bv_val);
2656 for (curr = ldap_service_dn_head;
2657 curr != NULL && *curr->dn !=
'\0';
2660 #if defined (DEBUG_LDAP) 2661 log_info (
"Searching for %s in LDAP tree %s", buf, curr->dn);
2663 ret = ldap_search_ext_s (ld, curr->dn, LDAP_SCOPE_SUBTREE, buf, NULL, 0,
2664 NULL, NULL, NULL, 0, &res);
2666 if(ret == LDAP_SERVER_DOWN)
2668 log_info (
"LDAP server was down, trying to reconnect...");
2674 log_info (
"LDAP reconnect failed - try again later...");
2678 ret = ldap_search_ext_s (ld, curr->dn, LDAP_SCOPE_SUBTREE, buf, NULL,
2679 0, NULL, NULL, NULL, 0, &res);
2682 if (ret == LDAP_SUCCESS)
2684 ent = ldap_first_entry (ld, res);
2685 #if defined (DEBUG_LDAP) 2687 log_info (
"No host entry for %s in LDAP tree %s",
2691 while (ent != NULL) {
2692 #if defined (DEBUG_LDAP) 2693 char *dn = ldap_get_dn (ld, ent);
2696 log_info (
"Found dhcpHWAddress LDAP entry %s", dn);
2702 status = host_allocate (&host,
MDL);
2703 if (status != ISC_R_SUCCESS)
2705 log_fatal (
"can't allocate host decl struct: %s",
2706 isc_result_totext (status));
2711 host->
name = ldap_get_host_name (ent);
2712 if (host->
name == NULL)
2714 host_dereference (&host,
MDL);
2722 host_dereference (&host,
MDL);
2731 ent = ldap_next_entry (ld, ent);
2738 return (*hp != NULL);
2748 if (ret != LDAP_NO_SUCH_OBJECT && ret != LDAP_SUCCESS)
2750 log_error (
"Cannot search for %s in LDAP tree %s: %s", buf,
2751 curr->dn, ldap_err2string (ret));
2755 #if defined (DEBUG_LDAP) 2758 log_info (
"ldap_search_ext_s returned %s when searching for %s in %s",
2759 ldap_err2string (ret), buf, curr->dn);
2770 find_subclass_in_ldap (
struct class *
class,
struct class **newclass,
2773 LDAPMessage * res, * ent;
2774 int ret, lease_limit;
2775 isc_result_t status;
2778 struct berval bv_class;
2779 struct berval bv_cdata;
2782 if (ldap_method == LDAP_METHOD_STATIC)
2794 if (_do_ldap_str2esc_filter_bv((
const char*)data->
data, data->
len, &bv_cdata) == NULL)
2796 log_error (
"Cannot escape ldap filter value %s: %m", hex_1);
2801 if (_do_ldap_str2esc_filter_bv(
class->
name, strlen (
class->
name), &bv_class) == NULL)
2805 ber_memfree(bv_cdata.bv_val);
2809 snprintf (buf,
sizeof (buf),
2810 "(&(objectClass=dhcpSubClass)(cn=%s)(dhcpClassData=%s))",
2811 (hex_1 == NULL ? bv_cdata.bv_val : hex_1), bv_class.bv_val);
2814 ber_memfree(bv_cdata.bv_val);
2815 ber_memfree(bv_class.bv_val);
2817 #if defined (DEBUG_LDAP) 2818 log_info (
"Searching LDAP for %s", buf);
2822 for (curr = ldap_service_dn_head;
2823 curr != NULL && *curr->dn !=
'\0';
2826 #if defined (DEBUG_LDAP) 2827 log_info (
"Searching for %s in LDAP tree %s", buf, curr->dn);
2829 ret = ldap_search_ext_s (ld, curr->dn, LDAP_SCOPE_SUBTREE, buf, NULL, 0,
2830 NULL, NULL, NULL, 0, &res);
2832 if(ret == LDAP_SERVER_DOWN)
2834 log_info (
"LDAP server was down, trying to reconnect...");
2841 log_info (
"LDAP reconnect failed - try again later...");
2845 ret = ldap_search_ext_s (ld, curr->dn, LDAP_SCOPE_SUBTREE, buf,
2846 NULL, 0, NULL, NULL, NULL, 0, &res);
2849 if (ret == LDAP_SUCCESS)
2851 if( (ent = ldap_first_entry (ld, res)) != NULL)
2854 #if defined (DEBUG_LDAP) 2855 log_info (
"No subclass entry for %s in LDAP tree %s",
2872 if (ret != LDAP_NO_SUCH_OBJECT && ret != LDAP_SUCCESS)
2874 log_error (
"Cannot search for %s in LDAP tree %s: %s", buf,
2875 curr->dn, ldap_err2string (ret));
2879 #if defined (DEBUG_LDAP) 2882 log_info (
"ldap_search_ext_s returned %s when searching for %s in %s",
2883 ldap_err2string (ret), buf, curr->dn);
2891 #if defined (DEBUG_LDAP) 2892 char *dn = ldap_get_dn (ld, ent);
2895 log_info (
"Found subclass LDAP entry %s", dn);
2900 status = class_allocate (newclass,
MDL);
2901 if (status != ISC_R_SUCCESS)
2903 log_error (
"Cannot allocate memory for a new class");
2909 class_reference (&(*newclass)->superclass,
class,
MDL);
2910 lease_limit = ldap_parse_options (ent, (*newclass)->group,
2912 if (lease_limit == 0)
2913 (*newclass)->lease_limit =
class->lease_limit;
2915 class->lease_limit = lease_limit;
2917 if ((*newclass)->lease_limit)
2919 (*newclass)->billed_leases =
2921 if (!(*newclass)->billed_leases)
2924 class_dereference (newclass,
MDL);
2928 memset ((*newclass)->billed_leases, 0,
2929 ((*newclass)->lease_limit * sizeof (
struct lease *)));
2938 if(res) ldap_msgfree (res);
2943 struct option_state *state,
const char *file,
int line)
2945 LDAPMessage * res, * ent;
2948 isc_result_t status;
2950 char buf[1024], buf1[1024];
2953 if (ldap_method == LDAP_METHOD_STATIC)
2961 memset(&client_id, 0,
sizeof(client_id));
2964 snprintf(buf,
sizeof(buf),
2965 "(&(objectClass=dhcpHost)(dhcpClientId=%s))",
2971 for (curr = ldap_service_dn_head;
2972 curr != NULL && *curr->dn !=
'\0';
2976 #if defined (DEBUG_LDAP) 2977 log_info (
"Searching for %s in LDAP tree %s", buf, buf1);
2979 ret = ldap_search_ext_s (ld, buf1, LDAP_SCOPE_SUBTREE, buf, NULL, 0,
2980 NULL, NULL, NULL, 0, &res);
2982 if(ret == LDAP_SERVER_DOWN)
2984 log_info (
"LDAP server was down, trying to reconnect...");
2991 log_info (
"LDAP reconnect failed - try again later...");
2995 ret = ldap_search_ext_s (ld, buf1, LDAP_SCOPE_SUBTREE, buf,
2996 NULL, 0, NULL, NULL, NULL, 0, &res);
2999 if (ret == LDAP_SUCCESS)
3001 if( (ent = ldap_first_entry (ld, res)) != NULL) {
3002 log_info (
"found entry in search %s", buf1);
3006 #if defined (DEBUG_LDAP) 3007 log_info (
"No subclass entry for %s in LDAP tree %s", buf, curr->dn);
3023 if (ret != LDAP_NO_SUCH_OBJECT && ret != LDAP_SUCCESS)
3025 log_error (
"Cannot search for %s in LDAP tree %s: %s", buf,
3026 curr->dn, ldap_err2string (ret));
3032 log_info (
"did not find: %s", buf);
3039 #if defined (DEBUG_LDAP) 3040 log_info (
"ldap_get_dn %s", curr->dn);
3041 char *dn = ldap_get_dn (ld, ent);
3044 log_info (
"Found subclass LDAP entry %s", dn);
3052 status = host_allocate (&host,
MDL);
3053 if (status != ISC_R_SUCCESS)
3055 log_fatal (
"can't allocate host decl struct: %s",
3056 isc_result_totext (status));
3061 host->
name = ldap_get_host_name (ent);
3062 if (host->
name == NULL)
3064 host_dereference (&host,
MDL);
3073 host_dereference (&host,
MDL);
3086 log_info (
"did not find clientid: %s", buf);
3089 if(res) ldap_msgfree (res);
3094 #if defined(LDAP_USE_GSSAPI) 3096 _ldap_sasl_interact(LDAP *ld,
unsigned flags,
void *defaults,
void *sin)
3098 sasl_interact_t *in;
3099 struct ldap_sasl_instance *ldap_inst = defaults;
3100 int ret = LDAP_OTHER;
3103 if (ld == NULL || sin == NULL)
3104 return LDAP_PARAM_ERROR;
3106 log_info(
"doing interactive bind");
3107 for (in = sin; in != NULL && in->id != SASL_CB_LIST_END; in++) {
3110 log_info(
"got request for SASL_CB_USER %s", ldap_inst->sasl_authz_id);
3111 size = strlen(ldap_inst->sasl_authz_id);
3112 in->result = ldap_inst->sasl_authz_id;
3116 case SASL_CB_GETREALM:
3117 log_info(
"got request for SASL_CB_GETREALM %s", ldap_inst->sasl_realm);
3118 size = strlen(ldap_inst->sasl_realm);
3119 in->result = ldap_inst->sasl_realm;
3123 case SASL_CB_AUTHNAME:
3124 log_info(
"got request for SASL_CB_AUTHNAME %s", ldap_inst->sasl_authc_id);
3125 size = strlen(ldap_inst->sasl_authc_id);
3126 in->result = ldap_inst->sasl_authc_id;
3131 log_info(
"got request for SASL_CB_PASS %s", ldap_inst->sasl_password);
3132 size = strlen(ldap_inst->sasl_password);
3133 in->result = ldap_inst->sasl_password;
struct binding_scope * global_scope
struct shared_network * shared_network
isc_result_t end_parse(struct parse **cfile)
void * dmalloc(unsigned, const char *, int)
struct universe server_universe
char * print_hw_addr(int htype, const int hlen, const unsigned char *data) const
#define print_hex_1(len, data, limit)
int group_reference(struct group **ptr, struct group *bp, const char *file, int line)
void data_string_forget(struct data_string *data, const char *file, int line)
struct group * root_group
int log_error(const char *,...) __attribute__((__format__(__printf__
enum dhcp_token peek_token(const char **rval, unsigned *rlen, struct parse *cfile)
struct parse * saved_state
void log_fatal(const char *,...) __attribute__((__format__(__printf__
void execute_statements_in_scope(struct binding_value **result, struct packet *packet, struct lease *lease, struct client_state *client_state, struct option_state *in_options, struct option_state *out_options, struct binding_scope **scope, struct group *group, struct group *limiting_group, struct on_star *on_star)
int option_state_allocate(struct option_state **ptr, const char *file, int line)
int evaluate_option_cache(struct data_string *result, struct packet *packet, struct lease *lease, struct client_state *client_state, struct option_state *in_options, struct option_state *cfg_options, struct binding_scope **scope, struct option_cache *oc, const char *file, int line)
struct interface_info * interface
void dfree(void *, const char *, int)
struct host_decl * n_ipaddr
struct option_cache * lookup_option(struct universe *universe, struct option_state *options, unsigned code)
int int log_info(const char *,...) __attribute__((__format__(__printf__
isc_result_t get_client_id(struct packet *, struct data_string *)
int parse_statement(struct parse *, struct group *, int, struct host_decl *, int)
int option_state_dereference(struct option_state **ptr, const char *file, int line)
char * quotify_string(const char *s, const char *file, int line)
const unsigned char * data
isc_result_t conf_file_subparse(struct parse *, struct group *, int)
void data_string_copy(struct data_string *dest, const struct data_string *src, const char *file, int line)
int clone_group(struct group **gp, struct group *group, const char *file, int line)
isc_result_t new_parse(struct parse **cfile, int file, char *inbuf, unsigned buflen, const char *name, int eolp)