jvdias 207484
--- /dev/null	2005-10-06 11:34:58.093275500 -0400
jvdias 207484
+++ bind-9.3.2b1/bin/sdb_tools/ldap2zone.c	2005-10-06 18:57:32.000000000 -0400
jvdias 207484
@@ -0,0 +1,397 @@
jvdias 207484
+/*
jvdias 207484
+ * Copyright (C) 2004, 2005 Stig Venaas <venaas@uninett.no>
jvdias 207484
+ * $Id: ldap2zone.c,v 0.1 2005/04/23 21:30:12 venaas Exp $
jvdias 207484
+ *
jvdias 207484
+ * Permission to use, copy, modify, and distribute this software for any
jvdias 207484
+ * purpose with or without fee is hereby granted, provided that the above
jvdias 207484
+ * copyright notice and this permission notice appear in all copies.
jvdias 207484
+ */
jvdias 207484
+
jvdias 207484
+#include <sys/types.h>
jvdias 207484
+#include <stdio.h>
jvdias 207484
+
jvdias 207484
+#include <ldap.h>
jvdias 207484
+
jvdias 207484
+struct string {
jvdias 207484
+    void *data;
jvdias 207484
+    size_t len;
jvdias 207484
+};
jvdias 207484
+
jvdias 207484
+struct assstack_entry {
jvdias 207484
+    struct string key;
jvdias 207484
+    struct string val;
jvdias 207484
+    struct assstack_entry *next;
jvdias 207484
+};
jvdias 207484
+
jvdias 207484
+struct assstack_entry *assstack_find(struct assstack_entry *stack, struct string *key) {
jvdias 207484
+    for (; stack; stack = stack->next)
jvdias 207484
+	if (stack->key.len == key->len && !memcmp(stack->key.data, key->data, key->len))
jvdias 207484
+	    return stack;
jvdias 207484
+    return NULL;
jvdias 207484
+}
jvdias 207484
+
jvdias 207484
+void assstack_push(struct assstack_entry **stack, struct assstack_entry *item) {
jvdias 207484
+    item->next = *stack;
jvdias 207484
+    *stack = item;
jvdias 207484
+}
jvdias 207484
+
jvdias 207484
+void assstack_insertbottom(struct assstack_entry **stack, struct assstack_entry *item) {
jvdias 207484
+    struct assstack_entry *p;
jvdias 207484
+    
jvdias 207484
+    item->next = NULL;
jvdias 207484
+    if (!*stack) {
jvdias 207484
+	*stack = item;
jvdias 207484
+	return;
jvdias 207484
+    }
jvdias 207484
+    /* find end, should keep track of end somewhere */
jvdias 207484
+    /* really a queue, not a stack */
jvdias 207484
+    p = *stack;
jvdias 207484
+    while (p->next)
jvdias 207484
+	p = p->next;
jvdias 207484
+    p->next = item;
jvdias 207484
+}
jvdias 207484
+
jvdias 207484
+void printsoa(struct string *soa) {
jvdias 207484
+    char *s;
jvdias 207484
+    int i;
jvdias 207484
+    
jvdias 207484
+    s = (char *)soa->data;
jvdias 207484
+    i = 0;
jvdias 207484
+    while (i < soa->len) {
jvdias 207484
+	putchar(s[i]);
jvdias 207484
+	if (s[i++] == ' ')
jvdias 207484
+	    break;
jvdias 207484
+    }
jvdias 207484
+    while (i < soa->len) {
jvdias 207484
+	putchar(s[i]);
jvdias 207484
+	if (s[i++] == ' ')
jvdias 207484
+	    break;
jvdias 207484
+    } 
jvdias 207484
+    printf("(\n\t\t\t\t");
jvdias 207484
+    while (i < soa->len) {
jvdias 207484
+	putchar(s[i]);
jvdias 207484
+	if (s[i++] == ' ')
jvdias 207484
+	    break;
jvdias 207484
+    }
jvdias 207484
+    printf("; Serialnumber\n\t\t\t\t");
jvdias 207484
+    while (i < soa->len) {
jvdias 207484
+	if (s[i] == ' ')
jvdias 207484
+	    break;
jvdias 207484
+	putchar(s[i++]);
jvdias 207484
+    }
jvdias 207484
+    i++;
jvdias 207484
+    printf("\t; Refresh\n\t\t\t\t");
jvdias 207484
+    while (i < soa->len) {
jvdias 207484
+	if (s[i] == ' ')
jvdias 207484
+	    break;
jvdias 207484
+	putchar(s[i++]);
jvdias 207484
+    }
jvdias 207484
+    i++;
jvdias 207484
+    printf("\t; Retry\n\t\t\t\t");
jvdias 207484
+    while (i < soa->len) {
jvdias 207484
+	if (s[i] == ' ')
jvdias 207484
+	    break;
jvdias 207484
+	putchar(s[i++]);
jvdias 207484
+    }
jvdias 207484
+    i++;
jvdias 207484
+    printf("\t; Expire\n\t\t\t\t");
jvdias 207484
+    while (i < soa->len) {
jvdias 207484
+	putchar(s[i++]);
jvdias 207484
+    }
jvdias 207484
+    printf(" )\t; Minimum TTL\n");
jvdias 207484
+}
jvdias 207484
+
jvdias 207484
+void printrrs(char *defaultttl, struct assstack_entry *item) {
jvdias 207484
+    struct assstack_entry *stack;
jvdias 207484
+    char *s;
jvdias 207484
+    int first;
jvdias 207484
+    int i;
jvdias 207484
+    char *ttl, *type;
jvdias 207484
+    int top;
jvdias 207484
+    
jvdias 207484
+    s = (char *)item->key.data;
jvdias 207484
+
jvdias 207484
+    if (item->key.len == 1 && *s == '@') {
jvdias 207484
+	top = 1;
jvdias 207484
+	printf("@\t");
jvdias 207484
+    } else {
jvdias 207484
+	top = 0;
jvdias 207484
+	for (i = 0; i < item->key.len; i++)
jvdias 207484
+	    putchar(s[i]);
jvdias 207484
+	if (item->key.len < 8)
jvdias 207484
+	    putchar('\t');
jvdias 207484
+	putchar('\t');
jvdias 207484
+    }
jvdias 207484
+    
jvdias 207484
+    first = 1;
jvdias 207484
+    for (stack = (struct assstack_entry *) item->val.data; stack; stack = stack->next) {
jvdias 207484
+	ttl = (char *)stack->key.data;
jvdias 207484
+	s = strchr(ttl, ' ');
jvdias 207484
+	*s++ = '\0';
jvdias 207484
+	type = s;
jvdias 207484
+	
jvdias 207484
+	if (first)
jvdias 207484
+	    first = 0;
jvdias 207484
+        else
jvdias 207484
+	    printf("\t\t");
jvdias 207484
+	    
jvdias 207484
+	if (strcmp(defaultttl, ttl))
jvdias 207484
+	    printf("%s", ttl);
jvdias 207484
+	putchar('\t');
jvdias 207484
+	
jvdias 207484
+	if (top) {
jvdias 207484
+	    top = 0;
jvdias 207484
+	    printf("IN\t%s\t", type);
jvdias 207484
+	    /* Should always be SOA here */
jvdias 207484
+	    if (!strcmp(type, "SOA")) {
jvdias 207484
+		printsoa(&stack->val);
jvdias 207484
+		continue;
jvdias 207484
+	    }
jvdias 207484
+	} else
jvdias 207484
+	    printf("%s\t", type);
jvdias 207484
+
jvdias 207484
+	s = (char *)stack->val.data;
jvdias 207484
+	for (i = 0; i < stack->val.len; i++)
jvdias 207484
+	    putchar(s[i]);
jvdias 207484
+	putchar('\n');
jvdias 207484
+    }
jvdias 207484
+}
jvdias 207484
+
jvdias 207484
+void print_zone(char *defaultttl, struct assstack_entry *stack) {
jvdias 207484
+    printf("$TTL %s\n", defaultttl);
jvdias 207484
+    for (; stack; stack = stack->next)
jvdias 207484
+	printrrs(defaultttl, stack);
jvdias 207484
+};
jvdias 207484
+
jvdias 207484
+void usage(char *name) {
jvdias 207484
+    fprintf(stderr, "Usage:%s zone-name LDAP-URL default-ttl [serial]\n", name);
jvdias 207484
+    exit(1);
jvdias 207484
+};
jvdias 207484
+
jvdias 207484
+void err(char *name, char *msg) {
jvdias 207484
+    fprintf(stderr, "%s: %s\n", name, msg);
jvdias 207484
+    exit(1);
jvdias 207484
+};
jvdias 207484
+
jvdias 207484
+int putrr(struct assstack_entry **stack, struct berval *name, char *type, char *ttl, struct berval *val) {
jvdias 207484
+    struct string key;
jvdias 207484
+    struct assstack_entry *rr, *rrdata;
jvdias 207484
+    
jvdias 207484
+    /* Do nothing if name or value have 0 length */
jvdias 207484
+    if (!name->bv_len || !val->bv_len)
jvdias 207484
+	return 0;
jvdias 207484
+
jvdias 207484
+    /* see if already have an entry for this name */
jvdias 207484
+    key.len = name->bv_len;
jvdias 207484
+    key.data = name->bv_val;
jvdias 207484
+
jvdias 207484
+    rr = assstack_find(*stack, &key);
jvdias 207484
+    if (!rr) {
jvdias 207484
+	/* Not found, create and push new entry */
jvdias 207484
+	rr = (struct assstack_entry *) malloc(sizeof(struct assstack_entry));
jvdias 207484
+	if (!rr)
jvdias 207484
+	    return -1;
jvdias 207484
+	rr->key.len = name->bv_len;
jvdias 207484
+	rr->key.data = (void *) malloc(rr->key.len);
jvdias 207484
+	if (!rr->key.data) {
jvdias 207484
+	    free(rr);
jvdias 207484
+	    return -1;
jvdias 207484
+	}
jvdias 207484
+	memcpy(rr->key.data, name->bv_val, name->bv_len);
jvdias 207484
+	rr->val.len = sizeof(void *);
jvdias 207484
+	rr->val.data = NULL;
jvdias 207484
+	if (name->bv_len == 1 && *(char *)name->bv_val == '@')
jvdias 207484
+	    assstack_push(stack, rr);
jvdias 207484
+	else
jvdias 207484
+	    assstack_insertbottom(stack, rr);
jvdias 207484
+    }
jvdias 207484
+
jvdias 207484
+    rrdata = (struct assstack_entry *) malloc(sizeof(struct assstack_entry));
jvdias 207484
+    if (!rrdata) {
jvdias 207484
+	free(rr->key.data);
jvdias 207484
+	free(rr);
jvdias 207484
+	return -1;
jvdias 207484
+    }
jvdias 207484
+    rrdata->key.len = strlen(type) + strlen(ttl) + 1;
jvdias 207484
+    rrdata->key.data = (void *) malloc(rrdata->key.len);
jvdias 207484
+    if (!rrdata->key.data) {
jvdias 207484
+	free(rrdata);
jvdias 207484
+	free(rr->key.data);
jvdias 207484
+	free(rr);
jvdias 207484
+	return -1;
jvdias 207484
+    }
jvdias 207484
+    sprintf((char *)rrdata->key.data, "%s %s", ttl, type);
jvdias 207484
+	
jvdias 207484
+    rrdata->val.len = val->bv_len;
jvdias 207484
+    rrdata->val.data = (void *) malloc(val->bv_len);
jvdias 207484
+    if (!rrdata->val.data) {
jvdias 207484
+	free(rrdata->key.data);
jvdias 207484
+	free(rrdata);
jvdias 207484
+	free(rr->key.data);
jvdias 207484
+	free(rr);
jvdias 207484
+	return -1;
jvdias 207484
+    }
jvdias 207484
+    memcpy(rrdata->val.data, val->bv_val, val->bv_len);
jvdias 207484
+
jvdias 207484
+    if (!strcmp(type, "SOA"))
jvdias 207484
+	assstack_push((struct assstack_entry **) &(rr->val.data), rrdata);
jvdias 207484
+    else
jvdias 207484
+	assstack_insertbottom((struct assstack_entry **) &(rr->val.data), rrdata);
jvdias 207484
+    return 0;
jvdias 207484
+}
jvdias 207484
+
jvdias 207484
+int main(int argc, char **argv) {
jvdias 207484
+    char *s, *hostporturl, *base = NULL;
jvdias 207484
+    char *ttl, *defaultttl;
jvdias 207484
+    LDAP *ld;
jvdias 207484
+    char *fltr = NULL;
jvdias 207484
+    LDAPMessage *res, *e;
jvdias 207484
+    char *a, **ttlvals, **soavals, *serial;
jvdias 207484
+    struct berval **vals, **names;
jvdias 207484
+    char type[64];
jvdias 207484
+    BerElement *ptr;
jvdias 207484
+    int i, j, rc, msgid;
jvdias 207484
+    struct assstack_entry *zone = NULL;
jvdias 207484
+    
jvdias 207484
+    if (argc < 4 || argc > 5)
jvdias 207484
+        usage(argv[0]);
jvdias 207484
+
jvdias 207484
+    hostporturl = argv[2];
jvdias 207484
+
jvdias 207484
+    if (hostporturl != strstr( hostporturl, "ldap"))
jvdias 207484
+	err(argv[0], "Not an LDAP URL");
jvdias 207484
+
jvdias 207484
+    s = strchr(hostporturl, ':');
jvdias 207484
+
jvdias 207484
+    if (!s || strlen(s) < 3 || s[1] != '/' || s[2] != '/')
jvdias 207484
+	err(argv[0], "Not an LDAP URL");
jvdias 207484
+
jvdias 207484
+    s = strchr(s+3, '/');
jvdias 207484
+    if (s) {
jvdias 207484
+	*s++ = '\0';
jvdias 207484
+	base = s;
jvdias 207484
+	s = strchr(base, '?');
jvdias 207484
+	if (s)
jvdias 207484
+	    err(argv[0], "LDAP URL can only contain host, port and base");
jvdias 207484
+    }
jvdias 207484
+
jvdias 207484
+    defaultttl = argv[3];
jvdias 207484
+    
jvdias 207484
+    rc = ldap_initialize(&ld, hostporturl);
jvdias 207484
+    if (rc != LDAP_SUCCESS)
jvdias 207484
+	err(argv[0], "ldap_initialize() failed");
jvdias 207484
+
jvdias 207484
+    if (argc == 5) {
jvdias 207484
+	/* serial number specified, check if different from one in SOA */
jvdias 207484
+	fltr = (char *)malloc(strlen(argv[1]) + strlen("(&(relativeDomainName=@)(zoneName=))") + 1);
jvdias 207484
+	sprintf(fltr, "(&(relativeDomainName=@)(zoneName=%s))", argv[1]);
jvdias 207484
+	msgid = ldap_search(ld, base, LDAP_SCOPE_SUBTREE, fltr, NULL, 0);
jvdias 207484
+	if (msgid == -1)
jvdias 207484
+	    err(argv[0], "ldap_search() failed");
jvdias 207484
+
jvdias 207484
+	while ((rc = ldap_result(ld, msgid, 0, NULL, &res)) != LDAP_RES_SEARCH_RESULT ) {
jvdias 207484
+	    /* not supporting continuation references at present */
jvdias 207484
+	    if (rc != LDAP_RES_SEARCH_ENTRY)
jvdias 207484
+		err(argv[0], "ldap_result() returned cont.ref? Exiting");
jvdias 207484
+
jvdias 207484
+	    /* only one entry per result message */
jvdias 207484
+	    e = ldap_first_entry(ld, res);
jvdias 207484
+	    if (e == NULL) {
jvdias 207484
+		ldap_msgfree(res);
jvdias 207484
+		err(argv[0], "ldap_first_entry() failed");
jvdias 207484
+	    }
jvdias 207484
+	
jvdias 207484
+	    soavals = ldap_get_values(ld, e, "SOARecord");
jvdias 207484
+	    if (soavals)
jvdias 207484
+		break;
jvdias 207484
+	}
jvdias 207484
+
jvdias 207484
+	ldap_msgfree(res);
jvdias 207484
+	if (!soavals) {
jvdias 207484
+		err(argv[0], "No SOA Record found");
jvdias 207484
+	}
jvdias 207484
+	
jvdias 207484
+	/* We have a SOA, compare serial numbers */
jvdias 207484
+	/* Only checkinf first value, should be only one */
jvdias 207484
+	s = strchr(soavals[0], ' ');
jvdias 207484
+	s++;
jvdias 207484
+	s = strchr(s, ' ');
jvdias 207484
+	s++;
jvdias 207484
+	serial = s;
jvdias 207484
+	s = strchr(s, ' ');
jvdias 207484
+	*s = '\0';
jvdias 207484
+	if (!strcmp(serial, argv[4])) {
jvdias 207484
+	    ldap_value_free(soavals);
jvdias 207484
+	    err(argv[0], "serial numbers match");
jvdias 207484
+	}
jvdias 207484
+	ldap_value_free(soavals);
jvdias 207484
+    }
jvdias 207484
+
jvdias 207484
+    if (!fltr)
jvdias 207484
+	fltr = (char *)malloc(strlen(argv[1]) + strlen("(zoneName=)") + 1);
jvdias 207484
+    if (!fltr)
jvdias 207484
+	err(argv[0], "Malloc failed");
jvdias 207484
+    sprintf(fltr, "(zoneName=%s)", argv[1]);
jvdias 207484
+
jvdias 207484
+    msgid = ldap_search(ld, base, LDAP_SCOPE_SUBTREE, fltr, NULL, 0);
jvdias 207484
+    if (msgid == -1)
jvdias 207484
+	err(argv[0], "ldap_search() failed");
jvdias 207484
+
jvdias 207484
+    while ((rc = ldap_result(ld, msgid, 0, NULL, &res)) != LDAP_RES_SEARCH_RESULT ) {
jvdias 207484
+	/* not supporting continuation references at present */
jvdias 207484
+	if (rc != LDAP_RES_SEARCH_ENTRY)
jvdias 207484
+	    err(argv[0], "ldap_result() returned cont.ref? Exiting");
jvdias 207484
+
jvdias 207484
+	/* only one entry per result message */
jvdias 207484
+	e = ldap_first_entry(ld, res);
jvdias 207484
+	if (e == NULL) {
jvdias 207484
+	    ldap_msgfree(res);
jvdias 207484
+	    err(argv[0], "ldap_first_entry() failed");
jvdias 207484
+	}
jvdias 207484
+	
jvdias 207484
+	names = ldap_get_values_len(ld, e, "relativeDomainName");
jvdias 207484
+	if (!names)
jvdias 207484
+	    continue;
jvdias 207484
+	
jvdias 207484
+	ttlvals = ldap_get_values(ld, e, "dNSTTL");
jvdias 207484
+	ttl = ttlvals ? ttlvals[0] : defaultttl;
jvdias 207484
+
jvdias 207484
+	for (a = ldap_first_attribute(ld, e, &ptr); a != NULL; a = ldap_next_attribute(ld, e, ptr)) {
jvdias 207484
+	    char *s;
jvdias 207484
+
jvdias 207484
+	    for (s = a; *s; s++)
jvdias 207484
+		*s = toupper(*s);
jvdias 207484
+	    s = strstr(a, "RECORD");
jvdias 207484
+	    if ((s == NULL) || (s == a) || (s - a >= (signed int)sizeof(type))) {
jvdias 207484
+		ldap_memfree(a);
jvdias 207484
+		continue;
jvdias 207484
+	    }
jvdias 207484
+			
jvdias 207484
+	    strncpy(type, a, s - a);
jvdias 207484
+	    type[s - a] = '\0';
jvdias 207484
+	    vals = ldap_get_values_len(ld, e, a);
jvdias 207484
+	    if (vals) {
jvdias 207484
+		for (i = 0; vals[i]; i++)
jvdias 207484
+		    for (j = 0; names[j]; j++)
jvdias 207484
+			if (putrr(&zone, names[j], type, ttl, vals[i]))
jvdias 207484
+			    err(argv[0], "malloc failed");
jvdias 207484
+		ldap_value_free_len(vals);
jvdias 207484
+	    }
jvdias 207484
+	    ldap_memfree(a);
jvdias 207484
+	}
jvdias 207484
+
jvdias 207484
+	if (ptr)
jvdias 207484
+	    ber_free(ptr, 0);
jvdias 207484
+	if (ttlvals)
jvdias 207484
+	    ldap_value_free(ttlvals);
jvdias 207484
+	ldap_value_free_len(names);
jvdias 207484
+	/* free this result */
jvdias 207484
+	ldap_msgfree(res);
jvdias 207484
+    }
jvdias 207484
+
jvdias 207484
+    /* free final result */
jvdias 207484
+    ldap_msgfree(res);
jvdias 207484
+
jvdias 207484
+    print_zone(defaultttl, zone);
jvdias 207484
+    return 0;
jvdias 207484
+}
jvdias 207484
--- bind-9.3.2b1/bin/sdb_tools/Makefile.in.fix_sdb_ldap	2005-02-17 01:43:28.000000000 -0500
jvdias 207484
+++ bind-9.3.2b1/bin/sdb_tools/Makefile.in	2005-10-06 18:57:32.000000000 -0400
jvdias 207484
@@ -30,11 +30,11 @@
jvdias 207484
 LIBS =		${LWRESLIBS} ${DNSLIBS} ${BIND9LIBS} \
jvdias 207484
 		${ISCCFGLIBS} ${ISCCCLIBS} ${ISCLIBS} ${DBDRIVER_LIBS} @LIBS@
jvdias 207484
 
jvdias 207484
-TARGETS =	zone2ldap@EXEEXT@ zonetodb@EXEEXT@
jvdias 207484
+TARGETS =	zone2ldap@EXEEXT@ ldap2zone@EXEEXT@ zonetodb@EXEEXT@
jvdias 207484
 
jvdias 207484
-OBJS	=	zone2ldap.o zonetodb.o
jvdias 207484
+OBJS	=	zone2ldap.o ldap2zone.o zonetodb.o
jvdias 207484
 
jvdias 207484
-SRCS    =       zone2ldap.c zonetodb.c
jvdias 207484
+SRCS    =       zone2ldap.c ldap2zone.c zonetodb.c
jvdias 207484
 
jvdias 207484
 MANPAGES =      zone2ldap.1
jvdias 207484
 
jvdias 207484
@@ -54,6 +54,9 @@
jvdias 207484
 zonetodb:	zonetodb.o  ${DEPLIBS}
jvdias 207484
 	${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ zonetodb.o -lpq ${LIBS}
jvdias 207484
 
jvdias 207484
+ldap2zone:	ldap2zone.o ${DEPLIBS}
jvdias 207484
+	${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ ldap2zone.o -lldap -llber ${LIBS}
jvdias 207484
+
jvdias 207484
 clean distclean manclean maintainer-clean::
jvdias 207484
 	rm -f ${TARGETS} ${OBJS}
jvdias 207484
 
jvdias 207484
@@ -63,5 +66,6 @@
jvdias 207484
 
jvdias 207484
 install:: ${TARGETS} installdirs
jvdias 207484
 	${LIBTOOL_MODE_INSTALL} ${INSTALL_PROGRAM} zone2ldap ${DESTDIR}${sbindir}
jvdias 207484
+	${LIBTOOL_MODE_INSTALL} ${INSTALL_PROGRAM} ldap2zone ${DESTDIR}${sbindir}
jvdias 207484
 	${LIBTOOL_MODE_INSTALL} ${INSTALL_PROGRAM} zonetodb  ${DESTDIR}${sbindir}
jvdias 207484
 	${INSTALL_DATA} ${srcdir}/zone2ldap.1 ${DESTDIR}${mandir}/man1/zone2ldap.1
jvdias 207484
--- bind-9.3.2b1/bin/sdb_tools/zone2ldap.c.fix_sdb_ldap	2005-10-06 18:57:32.000000000 -0400
jvdias 207484
+++ bind-9.3.2b1/bin/sdb_tools/zone2ldap.c	2005-10-06 18:57:32.000000000 -0400
jvdias 207484
@@ -24,6 +24,7 @@
jvdias 207484
 #include <isc/hash.h>
jvdias 207484
 #include <isc/mem.h>
jvdias 207484
 #include <isc/print.h>
jvdias 207484
+#include <isc/hash.h>
jvdias 207484
 #include <isc/result.h>
jvdias 207484
 
jvdias 207484
 #include <dns/db.h>
jvdias 207484
@@ -61,6 +62,9 @@
jvdias 207484
 /* usage Info */
jvdias 207484
 void usage (void);
jvdias 207484
 
jvdias 207484
+/* Check for existence of (and possibly add) containing dNSZone objects */
jvdias 207484
+int lookup_dns_zones( ldap_info *ldinfo);
jvdias 207484
+
jvdias 207484
 /* Add to the ldap dit */
jvdias 207484
 void add_ldap_values (ldap_info * ldinfo);
jvdias 207484
 
jvdias 207484
@@ -77,7 +81,7 @@
jvdias 207484
 int get_attr_list_size (char **tmp);
jvdias 207484
 
jvdias 207484
 /* Get a DN */
jvdias 207484
-char *build_dn_from_dc_list (char **dc_list, unsigned int ttl, int flag);
jvdias 207484
+char *build_dn_from_dc_list (char **dc_list, unsigned int ttl, int flag, char *zone);
jvdias 207484
 
jvdias 207484
 /* Add to RR list */
jvdias 207484
 void add_to_rr_list (char *dn, char *name, char *type, char *data,
jvdias 207484
@@ -99,11 +103,27 @@
jvdias 207484
 init_ldap_conn ();
jvdias 207484
 void usage();
jvdias 207484
 
jvdias 207484
-char *argzone, *ldapbase, *binddn, *bindpw = NULL;
jvdias 207484
-const char *ldapsystem = "localhost";
jvdias 207484
-static const char *objectClasses[] =
jvdias 207484
-  { "top", "dNSZone", NULL };
jvdias 207484
-static const char *topObjectClasses[] = { "top", NULL };
jvdias 207484
+static char *argzone, *ldapbase, *binddn, *bindpw = NULL;
jvdias 207484
+
jvdias 207484
+/* these are needed to placate gcc4's const-ness const-ernations : */
jvdias 207484
+static char localhost[] = "localhost";
jvdias 207484
+static char *ldapsystem=&(localhost[0]);
jvdias 207484
+/* dnszone schema class names: */
jvdias 207484
+static char topClass    [] ="top";
jvdias 207484
+static char dNSZoneClass[] ="dNSZone";
jvdias 207484
+static char objectClass [] ="objectClass";
jvdias 207484
+static char dcObjectClass[]="dcObject";
jvdias 207484
+/* dnszone schema attribute names: */
jvdias 207484
+static char relativeDomainName[]="relativeDomainName";
jvdias 207484
+static char dNSTTL            []="dNSTTL";
jvdias 207484
+static char zoneName          []="zoneName";
jvdias 207484
+static char dc                []="dc";
jvdias 207484
+static char sameZone          []="@";
jvdias 207484
+/* LDAPMod mod_values: */
jvdias 207484
+static char *objectClasses    []= { &(topClass[0]), &(dNSZoneClass[0]), NULL };
jvdias 207484
+static char *topObjectClasses []= { &(topClass[0]), &(dcObjectClass[0]), &(dNSZoneClass[0]), NULL };
jvdias 207484
+static char *dn_buffer      [64]={NULL};
jvdias 207484
+
jvdias 207484
 LDAP *conn;
jvdias 207484
 unsigned int debug = 0;
jvdias 207484
 
jvdias 207484
@@ -119,12 +139,12 @@
jvdias 207484
   isc_result_t result;
jvdias 207484
   char *basedn;
jvdias 207484
   ldap_info *tmp;
jvdias 207484
-  LDAPMod *base_attrs[2];
jvdias 207484
-  LDAPMod base;
jvdias 207484
+  LDAPMod *base_attrs[5];
jvdias 207484
+  LDAPMod base, dcBase, znBase, rdnBase;
jvdias 207484
   isc_buffer_t buff;
jvdias 207484
   char *zonefile=0L;
jvdias 207484
   char fullbasedn[1024];
jvdias 207484
-  char *ctmp;
jvdias 207484
+  char *ctmp, *zn, *dcp[2], *znp[2], *rdn[2];
jvdias 207484
   dns_fixedname_t fixedzone, fixedname;
jvdias 207484
   dns_rdataset_t rdataset;
jvdias 207484
   char **dc_list;
jvdias 207484
@@ -137,7 +157,7 @@
jvdias 207484
   extern char *optarg;
jvdias 207484
   extern int optind, opterr, optopt;
jvdias 207484
   int create_base = 0;
jvdias 207484
-  int topt;
jvdias 207484
+  int topt, dcn, zdn, znlen;
jvdias 207484
 
jvdias 207484
   if ((int) argc < 2)
jvdias 207484
     {
jvdias 207484
@@ -145,7 +165,7 @@
jvdias 207484
       exit (-1);
jvdias 207484
     }
jvdias 207484
 
jvdias 207484
-  while ((topt = getopt ((int) argc, argv, "D:w:b:z:f:h:?dcv")) != -1)
jvdias 207484
+  while ((topt = getopt ((int) argc, argv, "D:Ww:b:z:f:h:?dcv")) != -1)
jvdias 207484
     {
jvdias 207484
       switch (topt)
jvdias 207484
 	{
jvdias 207484
@@ -164,8 +184,11 @@
jvdias 207484
 	case 'w':
jvdias 207484
 	  bindpw = strdup (optarg);
jvdias 207484
 	  break;
jvdias 207484
+	case 'W':
jvdias 207484
+	  bindpw = getpass("Enter LDAP Password: ");
jvdias 207484
+	  break;
jvdias 207484
 	case 'b':
jvdias 207484
-	  ldapbase = strdup (optarg);
jvdias 207484
+          ldapbase = strdup (optarg);
jvdias 207484
 	  break;
jvdias 207484
 	case 'z':
jvdias 207484
 	  argzone = strdup (optarg);
jvdias 207484
@@ -277,27 +300,62 @@
jvdias 207484
     {
jvdias 207484
       if (debug)
jvdias 207484
 	printf ("Creating base zone DN %s\n", argzone);
jvdias 207484
-
jvdias 207484
+      
jvdias 207484
       dc_list = hostname_to_dn_list (argzone, argzone, DNS_TOP);
jvdias 207484
-      basedn = build_dn_from_dc_list (dc_list, 0, NO_SPEC);
jvdias 207484
 
jvdias 207484
-      for (ctmp = &basedn[strlen (basedn)]; ctmp >= &basedn[0]; ctmp--)
jvdias 207484
+      basedn = build_dn_from_dc_list (dc_list, 0, NO_SPEC, argzone);
jvdias 207484
+      if (debug)
jvdias 207484
+	printf ("base DN %s\n", basedn);
jvdias 207484
+
jvdias 207484
+      for (ctmp = &basedn[strlen (basedn)], dcn=0; ctmp >= &basedn[0]; ctmp--)
jvdias 207484
 	{
jvdias 207484
-	  if ((*ctmp == ',') || (ctmp == &basedn[0]))
jvdias 207484
+	    if ((*ctmp == ',') || (ctmp == &basedn[0]))
jvdias 207484
 	    {
jvdias 207484
+
jvdias 207484
 	      base.mod_op = LDAP_MOD_ADD;
jvdias 207484
-	      base.mod_type = (char*)"objectClass";
jvdias 207484
-	      base.mod_values = (char**)topObjectClasses;
jvdias 207484
+	      base.mod_type = objectClass;
jvdias 207484
+	      base.mod_values = topObjectClasses;
jvdias 207484
 	      base_attrs[0] = (void*)&bas;;
jvdias 207484
-	      base_attrs[1] = NULL;
jvdias 207484
-
jvdias 207484
+	     
jvdias 207484
+	      dcBase.mod_op = LDAP_MOD_ADD;
jvdias 207484
+	      dcBase.mod_type = dc;
jvdias 207484
+	      dcp[0]=dc_list[dcn];
jvdias 207484
+	      dcp[1]=0L;
jvdias 207484
+	      dcBase.mod_values=dcp;
jvdias 207484
+	      base_attrs[1] = (void*)&dcBase;
jvdias 207484
+
jvdias 207484
+	      znBase.mod_op = LDAP_MOD_ADD;
jvdias 207484
+	      znBase.mod_type = zoneName;	      
jvdias 207484
+	      for( zdn = dcn, znlen = 0; zdn >= 0; zdn-- )
jvdias 207484
+		  znlen += strlen(dc_list[zdn])+1;
jvdias 207484
+	      znp[0] = (char*)malloc(znlen+1);
jvdias 207484
+	      znp[1] = 0L;
jvdias 207484
+	      for( zdn = dcn, zn=znp[0]; zdn >= 0; zdn-- )		  
jvdias 207484
+		  zn+=sprintf(zn,"%s%s",dc_list[zdn], 
jvdias 207484
+			      ((zdn > 0) && (*(dc_list[zdn-1])!='.')) ? "." : ""
jvdias 207484
+		             );
jvdias 207484
+
jvdias 207484
+	      znBase.mod_values = znp;
jvdias 207484
+	      base_attrs[2] = (void*)&znBase;
jvdias 207484
+
jvdias 207484
+	      rdnBase.mod_op = LDAP_MOD_ADD;
jvdias 207484
+	      rdnBase.mod_type = relativeDomainName;
jvdias 207484
+	      rdn[0] = strdup(sameZone);
jvdias 207484
+	      rdn[1] = 0L;
jvdias 207484
+	      rdnBase.mod_values = rdn;
jvdias 207484
+	      base_attrs[3] = (void*)&rdnBase;
jvdias 207484
+	      
jvdias 207484
+	      dcn++;
jvdias 207484
+
jvdias 207484
+	      base.mod_values = topObjectClasses;
jvdias 207484
+	      base_attrs[4] = NULL;	      
jvdias 207484
+	      
jvdias 207484
 	      if (ldapbase)
jvdias 207484
 		{
jvdias 207484
 		  if (ctmp != &basedn[0])
jvdias 207484
 		    sprintf (fullbasedn, "%s,%s", ctmp + 1, ldapbase);
jvdias 207484
 		  else
jvdias 207484
-		    sprintf (fullbasedn, "%s,%s", ctmp, ldapbase);
jvdias 207484
-
jvdias 207484
+		    sprintf (fullbasedn, "%s,%s", ctmp, ldapbase);		  
jvdias 207484
 		}
jvdias 207484
 	      else
jvdias 207484
 		{
jvdias 207484
@@ -306,8 +364,13 @@
jvdias 207484
 		  else
jvdias 207484
 		    sprintf (fullbasedn, "%s", ctmp);
jvdias 207484
 		}
jvdias 207484
+
jvdias 207484
+	      if( debug )
jvdias 207484
+		  printf("Full base dn: %s\n", fullbasedn);
jvdias 207484
+
jvdias 207484
 	      result = ldap_add_s (conn, fullbasedn, base_attrs);
jvdias 207484
 	      ldap_result_check ("intial ldap_add_s", fullbasedn, result);
jvdias 207484
+
jvdias 207484
 	    }
jvdias 207484
 
jvdias 207484
 	}
jvdias 207484
@@ -383,14 +446,14 @@
jvdias 207484
   isc_result_check (result, "dns_rdata_totext");
jvdias 207484
   data[isc_buffer_usedlength (&buff)] = 0;
jvdias 207484
 
jvdias 207484
-  dc_list = hostname_to_dn_list (name, argzone, DNS_OBJECT);
jvdias 207484
+  dc_list = hostname_to_dn_list ((char*)name, argzone, DNS_OBJECT);
jvdias 207484
   len = (get_attr_list_size (dc_list) - 2);
jvdias 207484
-  dn = build_dn_from_dc_list (dc_list, ttl, WI_SPEC);
jvdias 207484
+  dn = build_dn_from_dc_list (dc_list, ttl, WI_SPEC, argzone);
jvdias 207484
 
jvdias 207484
   if (debug)
jvdias 207484
     printf ("Adding %s (%s %s) to run queue list.\n", dn, type, data);
jvdias 207484
 
jvdias 207484
-  add_to_rr_list (dn, dc_list[len], type, data, ttl, DNS_OBJECT);
jvdias 207484
+  add_to_rr_list (dn, dc_list[len], (char*)type, (char*)data, ttl, DNS_OBJECT);
jvdias 207484
 }
jvdias 207484
 
jvdias 207484
 
jvdias 207484
@@ -430,7 +493,8 @@
jvdias 207484
   int attrlist;
jvdias 207484
   char ldap_type_buffer[128];
jvdias 207484
   char charttl[64];
jvdias 207484
-
jvdias 207484
+  char *zn;
jvdias 207484
+  int znlen;
jvdias 207484
 
jvdias 207484
   if ((tmp = locate_by_dn (dn)) == NULL)
jvdias 207484
     {
jvdias 207484
@@ -465,13 +529,13 @@
jvdias 207484
 	    }
jvdias 207484
 	}
jvdias 207484
       tmp->attrs[0]->mod_op = LDAP_MOD_ADD;
jvdias 207484
-      tmp->attrs[0]->mod_type = (char*)"objectClass";
jvdias 207484
+      tmp->attrs[0]->mod_type = objectClass;
jvdias 207484
 
jvdias 207484
       if (flags == DNS_OBJECT)
jvdias 207484
-	tmp->attrs[0]->mod_values = (char**)objectClasses;
jvdias 207484
+	tmp->attrs[0]->mod_values = objectClasses;
jvdias 207484
       else
jvdias 207484
 	{
jvdias 207484
-	  tmp->attrs[0]->mod_values = (char**)topObjectClasses;
jvdias 207484
+	  tmp->attrs[0]->mod_values =topObjectClasses;
jvdias 207484
 	  tmp->attrs[1] = NULL;
jvdias 207484
 	  tmp->attrcnt = 2;
jvdias 207484
 	  tmp->next = ldap_info_base;
jvdias 207484
@@ -480,7 +544,7 @@
jvdias 207484
 	}
jvdias 207484
 
jvdias 207484
       tmp->attrs[1]->mod_op = LDAP_MOD_ADD;
jvdias 207484
-      tmp->attrs[1]->mod_type = (char*)"relativeDomainName";
jvdias 207484
+      tmp->attrs[1]->mod_type = relativeDomainName;
jvdias 207484
       tmp->attrs[1]->mod_values = (char **) calloc (sizeof (char *), 2);
jvdias 207484
 
jvdias 207484
       if (tmp->attrs[1]->mod_values == (char **)NULL)
jvdias 207484
@@ -502,7 +566,7 @@
jvdias 207484
       tmp->attrs[2]->mod_values[1] = NULL;
jvdias 207484
 
jvdias 207484
       tmp->attrs[3]->mod_op = LDAP_MOD_ADD;
jvdias 207484
-      tmp->attrs[3]->mod_type = (char*)"dNSTTL";
jvdias 207484
+      tmp->attrs[3]->mod_type = dNSTTL;
jvdias 207484
       tmp->attrs[3]->mod_values = (char **) calloc (sizeof (char *), 2);
jvdias 207484
 
jvdias 207484
       if (tmp->attrs[3]->mod_values == (char **)NULL)
jvdias 207484
@@ -512,10 +576,21 @@
jvdias 207484
       tmp->attrs[3]->mod_values[0] = strdup (charttl);
jvdias 207484
       tmp->attrs[3]->mod_values[1] = NULL;
jvdias 207484
 
jvdias 207484
+      znlen=strlen(gbl_zone);      
jvdias 207484
+      if ( *(gbl_zone + (znlen-1)) == '.' )
jvdias 207484
+      { /* ldapdb MUST search by relative zone name */
jvdias 207484
+	  zn = (char*)malloc(znlen);
jvdias 207484
+	  strncpy(zn,gbl_zone,znlen-1);
jvdias 207484
+	  *(zn + (znlen-1))='\0';	  
jvdias 207484
+      }else
jvdias 207484
+      {
jvdias 207484
+	  zn = gbl_zone;
jvdias 207484
+      }
jvdias 207484
+
jvdias 207484
       tmp->attrs[4]->mod_op = LDAP_MOD_ADD;
jvdias 207484
-      tmp->attrs[4]->mod_type = (char*)"zoneName";
jvdias 207484
+      tmp->attrs[4]->mod_type = zoneName;
jvdias 207484
       tmp->attrs[4]->mod_values = (char **)calloc(sizeof(char *), 2);
jvdias 207484
-      tmp->attrs[4]->mod_values[0] = gbl_zone;
jvdias 207484
+      tmp->attrs[4]->mod_values[0] = zn;
jvdias 207484
       tmp->attrs[4]->mod_values[1] = NULL;
jvdias 207484
 
jvdias 207484
       tmp->attrs[5] = NULL;
jvdias 207484
@@ -526,7 +601,7 @@
jvdias 207484
   else
jvdias 207484
     {
jvdias 207484
 
jvdias 207484
-      for (i = 0; tmp->attrs[i] != NULL; i++)
jvdias 207484
+	for (i = 0; tmp->attrs[i] != NULL; i++)
jvdias 207484
 	{
jvdias 207484
 	  sprintf (ldap_type_buffer, "%sRecord", type);
jvdias 207484
 	  if (!strncmp
jvdias 207484
@@ -595,69 +670,105 @@
jvdias 207484
 hostname_to_dn_list (char *hostname, char *zone, unsigned int flags)
jvdias 207484
 {
jvdias 207484
   char *tmp;
jvdias 207484
-  static char *dn_buffer[64];
jvdias 207484
   int i = 0;
jvdias 207484
-  char *zname;
jvdias 207484
-  char *hnamebuff;
jvdias 207484
-
jvdias 207484
-  zname = strdup (hostname);
jvdias 207484
-
jvdias 207484
-  if (flags == DNS_OBJECT)
jvdias 207484
-    {
jvdias 207484
+  char *hname=0L, *last=0L;
jvdias 207484
+  int hlen=strlen(hostname), zlen=(strlen(zone));
jvdias 207484
 
jvdias 207484
-      if (strlen (zname) != strlen (zone))
jvdias 207484
-	{
jvdias 207484
-	  tmp = &zname[strlen (zname) - strlen (zone)];
jvdias 207484
-	  *--tmp = '\0';
jvdias 207484
-	  hnamebuff = strdup (zname);
jvdias 207484
-	  zname = ++tmp;
jvdias 207484
-	}
jvdias 207484
-      else
jvdias 207484
-	hnamebuff = (char*)"@";
jvdias 207484
-    }
jvdias 207484
-  else
jvdias 207484
-    {
jvdias 207484
-      zname = zone;
jvdias 207484
-      hnamebuff = NULL;
jvdias 207484
-    }
jvdias 207484
-
jvdias 207484
-  for (tmp = strrchr (zname, '.'); tmp != (char *) 0;
jvdias 207484
-       tmp = strrchr (zname, '.'))
jvdias 207484
-    {
jvdias 207484
-      *tmp++ = '\0';
jvdias 207484
-      dn_buffer[i++] = tmp;
jvdias 207484
-    }
jvdias 207484
-  dn_buffer[i++] = zname;
jvdias 207484
-  dn_buffer[i++] = hnamebuff;
jvdias 207484
+/*  printf("hostname: %s zone: %s\n",hostname, zone); */
jvdias 207484
+  hname=0L;
jvdias 207484
+  if(flags == DNS_OBJECT)
jvdias 207484
+  {
jvdias 207484
+      if( (zone[ zlen - 1 ] == '.') && (hostname[hlen - 1] != '.') )
jvdias 207484
+      {
jvdias 207484
+	  hname=(char*)malloc(hlen + 1);
jvdias 207484
+	  hlen += 1;
jvdias 207484
+	  sprintf(hname, "%s.", hostname);
jvdias 207484
+	  hostname = hname;
jvdias 207484
+      }
jvdias 207484
+      if(strcmp(hostname, zone) == 0)
jvdias 207484
+      {
jvdias 207484
+	  if( hname == 0 )
jvdias 207484
+	      hname=strdup(hostname);
jvdias 207484
+  	  last = strdup(sameZone);
jvdias 207484
+      }else
jvdias 207484
+      {	   
jvdias 207484
+	  if(  (hlen < zlen) 
jvdias 207484
+	     ||( strcmp( hostname + (hlen - zlen), zone ) != 0)
jvdias 207484
+	    )
jvdias 207484
+	  {
jvdias 207484
+	      if( hname != 0 )
jvdias 207484
+		  free(hname);
jvdias 207484
+	      hname=(char*)malloc( hlen + zlen + 1);
jvdias 207484
+	      if( *zone == '.' )
jvdias 207484
+		  sprintf(hname, "%s%s", hostname, zone);
jvdias 207484
+	      else
jvdias 207484
+		  sprintf(hname,"%s",zone);
jvdias 207484
+	  }else
jvdias 207484
+	  {
jvdias 207484
+	      if( hname == 0 )
jvdias 207484
+		  hname = strdup(hostname);
jvdias 207484
+	  }
jvdias 207484
+	  last = hname;
jvdias 207484
+      }
jvdias 207484
+  }else
jvdias 207484
+  { /* flags == DNS_TOP */
jvdias 207484
+      hname = strdup(zone);
jvdias 207484
+      last = hname;
jvdias 207484
+  }
jvdias 207484
+
jvdias 207484
+  for (tmp = strrchr (hname, '.'); tmp != (char *) 0;
jvdias 207484
+       tmp = strrchr (hname, '.'))
jvdias 207484
+  {
jvdias 207484
+      if( *( tmp + 1 ) != '\0' )
jvdias 207484
+      {
jvdias 207484
+	  *tmp = '\0';
jvdias 207484
+	  dn_buffer[i++] = ++tmp;
jvdias 207484
+      }else
jvdias 207484
+      { /* trailing '.' ! */
jvdias 207484
+	  dn_buffer[i++] = strdup(".");
jvdias 207484
+	  *tmp = '\0';
jvdias 207484
+	  if( tmp == hname )
jvdias 207484
+	      break;
jvdias 207484
+      }	  
jvdias 207484
+  }
jvdias 207484
+  if( ( last != hname ) && (tmp != hname) )
jvdias 207484
+      dn_buffer[i++] = hname;
jvdias 207484
+  dn_buffer[i++] = last;
jvdias 207484
   dn_buffer[i] = NULL;
jvdias 207484
-
jvdias 207484
   return dn_buffer;
jvdias 207484
 }
jvdias 207484
 
jvdias 207484
-
jvdias 207484
 /* build an sdb compatible LDAP DN from a "dc_list" (char **).
jvdias 207484
  * will append dNSTTL information to each RR Record, with the 
jvdias 207484
  * exception of "@"/SOA. */
jvdias 207484
 
jvdias 207484
 char *
jvdias 207484
-build_dn_from_dc_list (char **dc_list, unsigned int ttl, int flag)
jvdias 207484
+build_dn_from_dc_list (char **dc_list, unsigned int ttl, int flag, char *zone)
jvdias 207484
 {
jvdias 207484
   int size;
jvdias 207484
-  int x;
jvdias 207484
+  int x, znlen;
jvdias 207484
   static char dn[1024];
jvdias 207484
   char tmp[128];
jvdias 207484
+  char zn[DNS_NAME_MAXTEXT+1];
jvdias 207484
 
jvdias 207484
   bzero (tmp, sizeof (tmp));
jvdias 207484
   bzero (dn, sizeof (dn));
jvdias 207484
   size = get_attr_list_size (dc_list);
jvdias 207484
+  znlen = strlen(zone);
jvdias 207484
+  if ( *(zone + (znlen-1)) == '.' )
jvdias 207484
+  { /* ldapdb MUST search by relative zone name */
jvdias 207484
+      memcpy(&(zn[0]),zone,znlen-1);
jvdias 207484
+      *(zn + (znlen-1))='\0';
jvdias 207484
+      zone = zn;
jvdias 207484
+  }
jvdias 207484
   for (x = size - 2; x > 0; x--)
jvdias 207484
     {
jvdias 207484
     if (flag == WI_SPEC)
jvdias 207484
     {
jvdias 207484
       if (x == (size - 2) && (strncmp (dc_list[x], "@", 1) == 0) && (ttl))
jvdias 207484
-	sprintf (tmp, "relativeDomainName=%s + dNSTTL=%d,", dc_list[x], ttl);
jvdias 207484
+	sprintf (tmp, "zoneName=%s + relativeDomainName=%s,", zone, dc_list[x]);
jvdias 207484
       else if (x == (size - 2))
jvdias 207484
-	      sprintf(tmp, "relativeDomainName=%s,",dc_list[x]);
jvdias 207484
+	      sprintf(tmp, "zoneName=%s + relativeDomainName=%s,", zone, dc_list[x]);
jvdias 207484
       else
jvdias 207484
 	      sprintf(tmp,"dc=%s,", dc_list[x]);
jvdias 207484
     }
jvdias 207484
@@ -683,6 +794,7 @@
jvdias 207484
 init_ldap_conn ()
jvdias 207484
 {
jvdias 207484
   int result;
jvdias 207484
+  char ldb_tag[]="LDAP Bind";
jvdias 207484
   conn = ldap_open (ldapsystem, LDAP_PORT);
jvdias 207484
   if (conn == NULL)
jvdias 207484
     {
jvdias 207484
@@ -692,7 +804,7 @@
jvdias 207484
     }
jvdias 207484
 
jvdias 207484
   result = ldap_simple_bind_s (conn, binddn, bindpw);
jvdias 207484
-  ldap_result_check ("ldap_simple_bind_s", (char*)"LDAP Bind", result);
jvdias 207484
+  ldap_result_check ("ldap_simple_bind_s", ldb_tag , result);
jvdias 207484
 }
jvdias 207484
 
jvdias 207484
 /* Like isc_result_check, only for LDAP */
jvdias 207484
@@ -709,8 +821,6 @@
jvdias 207484
     }
jvdias 207484
 }
jvdias 207484
 
jvdias 207484
-
jvdias 207484
-
jvdias 207484
 /* For running the ldap_info run queue. */
jvdias 207484
 void
jvdias 207484
 add_ldap_values (ldap_info * ldinfo)
jvdias 207484
@@ -718,14 +828,14 @@
jvdias 207484
   int result;
jvdias 207484
   char dnbuffer[1024];
jvdias 207484
 
jvdias 207484
-
jvdias 207484
   if (ldapbase != NULL)
jvdias 207484
     sprintf (dnbuffer, "%s,%s", ldinfo->dn, ldapbase);
jvdias 207484
   else
jvdias 207484
     sprintf (dnbuffer, "%s", ldinfo->dn);
jvdias 207484
 
jvdias 207484
   result = ldap_add_s (conn, dnbuffer, ldinfo->attrs);
jvdias 207484
-  ldap_result_check ("ldap_add_s", dnbuffer, result);
jvdias 207484
+    ldap_result_check ("ldap_add_s", dnbuffer, result);
jvdias 207484
+
jvdias 207484
 }
jvdias 207484
 
jvdias 207484
 
jvdias 207484
@@ -736,7 +846,7 @@
jvdias 207484
 usage ()
jvdias 207484
 {
jvdias 207484
   fprintf (stderr,
jvdias 207484
-	   "zone2ldap -D [BIND DN] -w [BIND PASSWORD] -b [BASE DN] -z [ZONE] -f [ZONE FILE] -h [LDAP HOST]\n"
jvdias 207484
+	   "zone2ldap -D [BIND DN] [-w BIND PASSWORD | -W:prompt] -b [BASE DN] -z [ZONE] -f [ZONE FILE] -h [LDAP HOST]\n"
jvdias 207484
 	   "\t[-c Create LDAP Base structure][-d Debug Output (lots !)]\n "
jvdias 207484
           );
jvdias 207484
 }