lbalhar / rpms / bind

Forked from rpms/bind 6 years ago
Clone
Adam Tkac 788dabf
/*
Adam Tkac 788dabf
 * Copyright (C) 2004, 2005 Stig Venaas <venaas@uninett.no>
Adam Tkac c768d86
 * $Id: ldap2zone.c,v 1.1 2007/07/24 15:18:00 atkac Exp $
Adam Tkac 788dabf
 *
Adam Tkac 788dabf
 * Permission to use, copy, modify, and distribute this software for any
Adam Tkac 788dabf
 * purpose with or without fee is hereby granted, provided that the above
Adam Tkac 788dabf
 * copyright notice and this permission notice appear in all copies.
Adam Tkac 788dabf
 */
Adam Tkac 788dabf
Adam Tkac c768d86
#define LDAP_DEPRECATED 1
Adam Tkac c768d86
Adam Tkac 788dabf
#include <sys/types.h>
Adam Tkac 788dabf
#include <stdio.h>
Adam Tkac 788dabf
#include <stdlib.h>
Adam Tkac 788dabf
#include <ctype.h>
Adam Tkac 788dabf
Adam Tkac 788dabf
#include <ldap.h>
Adam Tkac 788dabf
Adam Tkac 788dabf
struct string {
Adam Tkac 788dabf
    void *data;
Adam Tkac 788dabf
    size_t len;
Adam Tkac 788dabf
};
Adam Tkac 788dabf
Adam Tkac 788dabf
struct assstack_entry {
Adam Tkac 788dabf
    struct string key;
Adam Tkac 788dabf
    struct string val;
Adam Tkac 788dabf
    struct assstack_entry *next;
Adam Tkac 788dabf
};
Adam Tkac 788dabf
Adam Tkac 788dabf
struct assstack_entry *assstack_find(struct assstack_entry *stack, struct string *key);
Adam Tkac 788dabf
void assstack_push(struct assstack_entry **stack, struct assstack_entry *item);
Adam Tkac 788dabf
void assstack_insertbottom(struct assstack_entry **stack, struct assstack_entry *item);
Adam Tkac 788dabf
void printsoa(struct string *soa);
Adam Tkac 788dabf
void printrrs(char *defaultttl, struct assstack_entry *item);
Adam Tkac 788dabf
void print_zone(char *defaultttl, struct assstack_entry *stack);
Adam Tkac 788dabf
void usage(char *name);
Adam Tkac 788dabf
void err(char *name, const char *msg);
Adam Tkac 788dabf
int putrr(struct assstack_entry **stack, struct berval *name, char *type, char *ttl, struct berval *val);
Adam Tkac 788dabf
Adam Tkac 788dabf
struct assstack_entry *assstack_find(struct assstack_entry *stack, struct string *key) {
Adam Tkac 788dabf
    for (; stack; stack = stack->next)
Adam Tkac 788dabf
	if (stack->key.len == key->len && !memcmp(stack->key.data, key->data, key->len))
Adam Tkac 788dabf
	    return stack;
Adam Tkac 788dabf
    return NULL;
Adam Tkac 788dabf
}
Adam Tkac 788dabf
Adam Tkac 788dabf
void assstack_push(struct assstack_entry **stack, struct assstack_entry *item) {
Adam Tkac 788dabf
    item->next = *stack;
Adam Tkac 788dabf
    *stack = item;
Adam Tkac 788dabf
}
Adam Tkac 788dabf
Adam Tkac 788dabf
void assstack_insertbottom(struct assstack_entry **stack, struct assstack_entry *item) {
Adam Tkac 788dabf
    struct assstack_entry *p;
Adam Tkac 788dabf
    
Adam Tkac 788dabf
    item->next = NULL;
Adam Tkac 788dabf
    if (!*stack) {
Adam Tkac 788dabf
	*stack = item;
Adam Tkac 788dabf
	return;
Adam Tkac 788dabf
    }
Adam Tkac 788dabf
    /* find end, should keep track of end somewhere */
Adam Tkac 788dabf
    /* really a queue, not a stack */
Adam Tkac 788dabf
    p = *stack;
Adam Tkac 788dabf
    while (p->next)
Adam Tkac 788dabf
	p = p->next;
Adam Tkac 788dabf
    p->next = item;
Adam Tkac 788dabf
}
Adam Tkac 788dabf
Adam Tkac 788dabf
void printsoa(struct string *soa) {
Adam Tkac 788dabf
    char *s;
Adam Tkac 788dabf
    size_t i;
Adam Tkac 788dabf
    
Adam Tkac 788dabf
    s = (char *)soa->data;
Adam Tkac 788dabf
    i = 0;
Adam Tkac 788dabf
    while (i < soa->len) {
Adam Tkac 788dabf
	putchar(s[i]);
Adam Tkac 788dabf
	if (s[i++] == ' ')
Adam Tkac 788dabf
	    break;
Adam Tkac 788dabf
    }
Adam Tkac 788dabf
    while (i < soa->len) {
Adam Tkac 788dabf
	putchar(s[i]);
Adam Tkac 788dabf
	if (s[i++] == ' ')
Adam Tkac 788dabf
	    break;
Adam Tkac 788dabf
    } 
Adam Tkac 788dabf
    printf("(\n\t\t\t\t");
Adam Tkac 788dabf
    while (i < soa->len) {
Adam Tkac 788dabf
	putchar(s[i]);
Adam Tkac 788dabf
	if (s[i++] == ' ')
Adam Tkac 788dabf
	    break;
Adam Tkac 788dabf
    }
Adam Tkac 788dabf
    printf("; Serialnumber\n\t\t\t\t");
Adam Tkac 788dabf
    while (i < soa->len) {
Adam Tkac 788dabf
	if (s[i] == ' ')
Adam Tkac 788dabf
	    break;
Adam Tkac 788dabf
	putchar(s[i++]);
Adam Tkac 788dabf
    }
Adam Tkac 788dabf
    i++;
Adam Tkac 788dabf
    printf("\t; Refresh\n\t\t\t\t");
Adam Tkac 788dabf
    while (i < soa->len) {
Adam Tkac 788dabf
	if (s[i] == ' ')
Adam Tkac 788dabf
	    break;
Adam Tkac 788dabf
	putchar(s[i++]);
Adam Tkac 788dabf
    }
Adam Tkac 788dabf
    i++;
Adam Tkac 788dabf
    printf("\t; Retry\n\t\t\t\t");
Adam Tkac 788dabf
    while (i < soa->len) {
Adam Tkac 788dabf
	if (s[i] == ' ')
Adam Tkac 788dabf
	    break;
Adam Tkac 788dabf
	putchar(s[i++]);
Adam Tkac 788dabf
    }
Adam Tkac 788dabf
    i++;
Adam Tkac 788dabf
    printf("\t; Expire\n\t\t\t\t");
Adam Tkac 788dabf
    while (i < soa->len) {
Adam Tkac 788dabf
	putchar(s[i++]);
Adam Tkac 788dabf
    }
Adam Tkac 788dabf
    printf(" )\t; Minimum TTL\n");
Adam Tkac 788dabf
}
Adam Tkac 788dabf
Adam Tkac 788dabf
void printrrs(char *defaultttl, struct assstack_entry *item) {
Adam Tkac 788dabf
    struct assstack_entry *stack;
Adam Tkac 788dabf
    char *s;
Adam Tkac 788dabf
    int first;
Adam Tkac 788dabf
    size_t i;
Adam Tkac 788dabf
    char *ttl, *type;
Adam Tkac 788dabf
    int top;
Adam Tkac 788dabf
    
Adam Tkac 788dabf
    s = (char *)item->key.data;
Adam Tkac 788dabf
Adam Tkac 788dabf
    if (item->key.len == 1 && *s == '@') {
Adam Tkac 788dabf
	top = 1;
Adam Tkac 788dabf
	printf("@\t");
Adam Tkac 788dabf
    } else {
Adam Tkac 788dabf
	top = 0;
Adam Tkac 788dabf
	for (i = 0; i < item->key.len; i++)
Adam Tkac 788dabf
	    putchar(s[i]);
Adam Tkac 788dabf
	if (item->key.len < 8)
Adam Tkac 788dabf
	    putchar('\t');
Adam Tkac 788dabf
	putchar('\t');
Adam Tkac 788dabf
    }
Adam Tkac 788dabf
    
Adam Tkac 788dabf
    first = 1;
Adam Tkac 788dabf
    for (stack = (struct assstack_entry *) item->val.data; stack; stack = stack->next) {
Adam Tkac 788dabf
	ttl = (char *)stack->key.data;
Adam Tkac 788dabf
	s = strchr(ttl, ' ');
Adam Tkac 788dabf
	*s++ = '\0';
Adam Tkac 788dabf
	type = s;
Adam Tkac 788dabf
	
Adam Tkac 788dabf
	if (first)
Adam Tkac 788dabf
	    first = 0;
Adam Tkac 788dabf
        else
Adam Tkac 788dabf
	    printf("\t\t");
Adam Tkac 788dabf
	    
Adam Tkac 788dabf
	if (strcmp(defaultttl, ttl))
Adam Tkac 788dabf
	    printf("%s", ttl);
Adam Tkac 788dabf
	putchar('\t');
Adam Tkac 788dabf
	
Adam Tkac 788dabf
	if (top) {
Adam Tkac 788dabf
	    top = 0;
Adam Tkac 788dabf
	    printf("IN\t%s\t", type);
Adam Tkac 788dabf
	    /* Should always be SOA here */
Adam Tkac 788dabf
	    if (!strcmp(type, "SOA")) {
Adam Tkac 788dabf
		printsoa(&stack->val);
Adam Tkac 788dabf
		continue;
Adam Tkac 788dabf
	    }
Adam Tkac 788dabf
	} else
Adam Tkac 788dabf
	    printf("%s\t", type);
Adam Tkac 788dabf
Adam Tkac 788dabf
	s = (char *)stack->val.data;
Adam Tkac 788dabf
	for (i = 0; i < stack->val.len; i++)
Adam Tkac 788dabf
	    putchar(s[i]);
Adam Tkac 788dabf
	putchar('\n');
Adam Tkac 788dabf
    }
Adam Tkac 788dabf
}
Adam Tkac 788dabf
Adam Tkac 788dabf
void print_zone(char *defaultttl, struct assstack_entry *stack) {
Adam Tkac 788dabf
    printf("$TTL %s\n", defaultttl);
Adam Tkac 788dabf
    for (; stack; stack = stack->next)
Adam Tkac 788dabf
	printrrs(defaultttl, stack);
Adam Tkac 788dabf
};
Adam Tkac 788dabf
Adam Tkac 788dabf
void usage(char *name) {
Adam Tkac 788dabf
    fprintf(stderr, "Usage:%s zone-name LDAP-URL default-ttl [serial]\n", name);
Adam Tkac 788dabf
    exit(1);
Adam Tkac 788dabf
};
Adam Tkac 788dabf
Adam Tkac 788dabf
void err(char *name, const char *msg) {
Adam Tkac 788dabf
    fprintf(stderr, "%s: %s\n", name, msg);
Adam Tkac 788dabf
    exit(1);
Adam Tkac 788dabf
};
Adam Tkac 788dabf
Adam Tkac 788dabf
int putrr(struct assstack_entry **stack, struct berval *name, char *type, char *ttl, struct berval *val) {
Adam Tkac 788dabf
    struct string key;
Adam Tkac 788dabf
    struct assstack_entry *rr, *rrdata;
Adam Tkac 788dabf
    
Adam Tkac 788dabf
    /* Do nothing if name or value have 0 length */
Adam Tkac 788dabf
    if (!name->bv_len || !val->bv_len)
Adam Tkac 788dabf
	return 0;
Adam Tkac 788dabf
Adam Tkac 788dabf
    /* see if already have an entry for this name */
Adam Tkac 788dabf
    key.len = name->bv_len;
Adam Tkac 788dabf
    key.data = name->bv_val;
Adam Tkac 788dabf
Adam Tkac 788dabf
    rr = assstack_find(*stack, &key);
Adam Tkac 788dabf
    if (!rr) {
Adam Tkac 788dabf
	/* Not found, create and push new entry */
Adam Tkac 788dabf
	rr = (struct assstack_entry *) malloc(sizeof(struct assstack_entry));
Adam Tkac 788dabf
	if (!rr)
Adam Tkac 788dabf
	    return -1;
Adam Tkac 788dabf
	rr->key.len = name->bv_len;
Adam Tkac 788dabf
	rr->key.data = (void *) malloc(rr->key.len);
Adam Tkac 788dabf
	if (!rr->key.data) {
Adam Tkac 788dabf
	    free(rr);
Adam Tkac 788dabf
	    return -1;
Adam Tkac 788dabf
	}
Adam Tkac 788dabf
	memcpy(rr->key.data, name->bv_val, name->bv_len);
Adam Tkac 788dabf
	rr->val.len = sizeof(void *);
Adam Tkac 788dabf
	rr->val.data = NULL;
Adam Tkac 788dabf
	if (name->bv_len == 1 && *(char *)name->bv_val == '@')
Adam Tkac 788dabf
	    assstack_push(stack, rr);
Adam Tkac 788dabf
	else
Adam Tkac 788dabf
	    assstack_insertbottom(stack, rr);
Adam Tkac 788dabf
    }
Adam Tkac 788dabf
Adam Tkac 788dabf
    rrdata = (struct assstack_entry *) malloc(sizeof(struct assstack_entry));
Adam Tkac 788dabf
    if (!rrdata) {
Adam Tkac 788dabf
	free(rr->key.data);
Adam Tkac 788dabf
	free(rr);
Adam Tkac 788dabf
	return -1;
Adam Tkac 788dabf
    }
Adam Tkac 788dabf
    rrdata->key.len = strlen(type) + strlen(ttl) + 1;
Adam Tkac 788dabf
    rrdata->key.data = (void *) malloc(rrdata->key.len);
Adam Tkac 788dabf
    if (!rrdata->key.data) {
Adam Tkac 788dabf
	free(rrdata);
Adam Tkac 788dabf
	free(rr->key.data);
Adam Tkac 788dabf
	free(rr);
Adam Tkac 788dabf
	return -1;
Adam Tkac 788dabf
    }
Adam Tkac 788dabf
    sprintf((char *)rrdata->key.data, "%s %s", ttl, type);
Adam Tkac 788dabf
	
Adam Tkac 788dabf
    rrdata->val.len = val->bv_len;
Adam Tkac 788dabf
    rrdata->val.data = (void *) malloc(val->bv_len);
Adam Tkac 788dabf
    if (!rrdata->val.data) {
Adam Tkac 788dabf
	free(rrdata->key.data);
Adam Tkac 788dabf
	free(rrdata);
Adam Tkac 788dabf
	free(rr->key.data);
Adam Tkac 788dabf
	free(rr);
Adam Tkac 788dabf
	return -1;
Adam Tkac 788dabf
    }
Adam Tkac 788dabf
    memcpy(rrdata->val.data, val->bv_val, val->bv_len);
Adam Tkac 788dabf
Adam Tkac 788dabf
    if (!strcmp(type, "SOA"))
Adam Tkac 788dabf
	assstack_push((struct assstack_entry **) &(rr->val.data), rrdata);
Adam Tkac 788dabf
    else
Adam Tkac 788dabf
	assstack_insertbottom((struct assstack_entry **) &(rr->val.data), rrdata);
Adam Tkac 788dabf
    return 0;
Adam Tkac 788dabf
}
Adam Tkac 788dabf
Adam Tkac 788dabf
int main(int argc, char **argv) {
Adam Tkac 788dabf
    char *s, *hostporturl, *base = NULL;
Adam Tkac 788dabf
    char *ttl, *defaultttl;
Adam Tkac 788dabf
    LDAP *ld;
Adam Tkac 788dabf
    char *fltr = NULL;
Adam Tkac 788dabf
    LDAPMessage *res, *e;
Adam Tkac 788dabf
    char *a, **ttlvals, **soavals, *serial;
Adam Tkac 788dabf
    struct berval **vals, **names;
Adam Tkac 788dabf
    char type[64];
Adam Tkac 788dabf
    BerElement *ptr;
Adam Tkac 788dabf
    int i, j, rc, msgid;
Adam Tkac 788dabf
    struct assstack_entry *zone = NULL;
Adam Tkac 788dabf
    
Adam Tkac 788dabf
    if (argc < 4 || argc > 5)
Adam Tkac 788dabf
        usage(argv[0]);
Adam Tkac 788dabf
Adam Tkac 788dabf
    hostporturl = argv[2];
Adam Tkac 788dabf
Adam Tkac 788dabf
    if (hostporturl != strstr( hostporturl, "ldap"))
Adam Tkac 788dabf
	err(argv[0], "Not an LDAP URL");
Adam Tkac 788dabf
Adam Tkac 788dabf
    s = strchr(hostporturl, ':');
Adam Tkac 788dabf
Adam Tkac 788dabf
    if (!s || strlen(s) < 3 || s[1] != '/' || s[2] != '/')
Adam Tkac 788dabf
	err(argv[0], "Not an LDAP URL");
Adam Tkac 788dabf
Adam Tkac 788dabf
    s = strchr(s+3, '/');
Adam Tkac 788dabf
    if (s) {
Adam Tkac 788dabf
	*s++ = '\0';
Adam Tkac 788dabf
	base = s;
Adam Tkac 788dabf
	s = strchr(base, '?');
Adam Tkac 788dabf
	if (s)
Adam Tkac 788dabf
	    err(argv[0], "LDAP URL can only contain host, port and base");
Adam Tkac 788dabf
    }
Adam Tkac 788dabf
Adam Tkac 788dabf
    defaultttl = argv[3];
Adam Tkac 788dabf
    
Adam Tkac 788dabf
    rc = ldap_initialize(&ld, hostporturl);
Adam Tkac 788dabf
    if (rc != LDAP_SUCCESS)
Adam Tkac 788dabf
	err(argv[0], "ldap_initialize() failed");
Adam Tkac 788dabf
Adam Tkac 788dabf
    if (argc == 5) {
Adam Tkac 788dabf
	/* serial number specified, check if different from one in SOA */
Adam Tkac 788dabf
	fltr = (char *)malloc(strlen(argv[1]) + strlen("(&(relativeDomainName=@)(zoneName=))") + 1);
Adam Tkac 788dabf
	sprintf(fltr, "(&(relativeDomainName=@)(zoneName=%s))", argv[1]);
Adam Tkac 788dabf
	msgid = ldap_search(ld, base, LDAP_SCOPE_SUBTREE, fltr, NULL, 0);
Adam Tkac 788dabf
	if (msgid == -1)
Adam Tkac 788dabf
	    err(argv[0], "ldap_search() failed");
Adam Tkac 788dabf
Adam Tkac 788dabf
	while ((rc = ldap_result(ld, msgid, 0, NULL, &res)) != LDAP_RES_SEARCH_RESULT ) {
Adam Tkac 788dabf
	    /* not supporting continuation references at present */
Adam Tkac 788dabf
	    if (rc != LDAP_RES_SEARCH_ENTRY)
Adam Tkac 788dabf
		err(argv[0], "ldap_result() returned cont.ref? Exiting");
Adam Tkac 788dabf
Adam Tkac 788dabf
	    /* only one entry per result message */
Adam Tkac 788dabf
	    e = ldap_first_entry(ld, res);
Adam Tkac 788dabf
	    if (e == NULL) {
Adam Tkac 788dabf
		ldap_msgfree(res);
Adam Tkac 788dabf
		err(argv[0], "ldap_first_entry() failed");
Adam Tkac 788dabf
	    }
Adam Tkac 788dabf
	
Adam Tkac 788dabf
	    soavals = ldap_get_values(ld, e, "SOARecord");
Adam Tkac 788dabf
	    if (soavals)
Adam Tkac 788dabf
		break;
Adam Tkac 788dabf
	}
Adam Tkac 788dabf
Adam Tkac 788dabf
	ldap_msgfree(res);
Adam Tkac 788dabf
	if (!soavals) {
Adam Tkac 788dabf
		err(argv[0], "No SOA Record found");
Adam Tkac 788dabf
	}
Adam Tkac 788dabf
	
Adam Tkac 788dabf
	/* We have a SOA, compare serial numbers */
Adam Tkac 788dabf
	/* Only checkinf first value, should be only one */
Adam Tkac 788dabf
	s = strchr(soavals[0], ' ');
Adam Tkac 788dabf
	s++;
Adam Tkac 788dabf
	s = strchr(s, ' ');
Adam Tkac 788dabf
	s++;
Adam Tkac 788dabf
	serial = s;
Adam Tkac 788dabf
	s = strchr(s, ' ');
Adam Tkac 788dabf
	*s = '\0';
Adam Tkac 788dabf
	if (!strcmp(serial, argv[4])) {
Adam Tkac 788dabf
	    ldap_value_free(soavals);
Adam Tkac 788dabf
	    err(argv[0], "serial numbers match");
Adam Tkac 788dabf
	}
Adam Tkac 788dabf
	ldap_value_free(soavals);
Adam Tkac 788dabf
    }
Adam Tkac 788dabf
Adam Tkac 788dabf
    if (!fltr)
Adam Tkac 788dabf
	fltr = (char *)malloc(strlen(argv[1]) + strlen("(zoneName=)") + 1);
Adam Tkac 788dabf
    if (!fltr)
Adam Tkac 788dabf
	err(argv[0], "Malloc failed");
Adam Tkac 788dabf
    sprintf(fltr, "(zoneName=%s)", argv[1]);
Adam Tkac 788dabf
Adam Tkac 788dabf
    msgid = ldap_search(ld, base, LDAP_SCOPE_SUBTREE, fltr, NULL, 0);
Adam Tkac 788dabf
    if (msgid == -1)
Adam Tkac 788dabf
	err(argv[0], "ldap_search() failed");
Adam Tkac 788dabf
Adam Tkac 788dabf
    while ((rc = ldap_result(ld, msgid, 0, NULL, &res)) != LDAP_RES_SEARCH_RESULT ) {
Adam Tkac 788dabf
	/* not supporting continuation references at present */
Adam Tkac 788dabf
	if (rc != LDAP_RES_SEARCH_ENTRY)
Adam Tkac 788dabf
	    err(argv[0], "ldap_result() returned cont.ref? Exiting");
Adam Tkac 788dabf
Adam Tkac 788dabf
	/* only one entry per result message */
Adam Tkac 788dabf
	e = ldap_first_entry(ld, res);
Adam Tkac 788dabf
	if (e == NULL) {
Adam Tkac 788dabf
	    ldap_msgfree(res);
Adam Tkac 788dabf
	    err(argv[0], "ldap_first_entry() failed");
Adam Tkac 788dabf
	}
Adam Tkac 788dabf
	
Adam Tkac 788dabf
	names = ldap_get_values_len(ld, e, "relativeDomainName");
Adam Tkac 788dabf
	if (!names)
Adam Tkac 788dabf
	    continue;
Adam Tkac 788dabf
	
Adam Tkac 788dabf
	ttlvals = ldap_get_values(ld, e, "dNSTTL");
Adam Tkac 788dabf
	ttl = ttlvals ? ttlvals[0] : defaultttl;
Adam Tkac 788dabf
Adam Tkac 788dabf
	for (a = ldap_first_attribute(ld, e, &ptr); a != NULL; a = ldap_next_attribute(ld, e, ptr)) {
Adam Tkac 788dabf
	    char *s;
Adam Tkac 788dabf
Adam Tkac 788dabf
	    for (s = a; *s; s++)
Adam Tkac 788dabf
		*s = toupper(*s);
Adam Tkac 788dabf
	    s = strstr(a, "RECORD");
Adam Tkac 788dabf
	    if ((s == NULL) || (s == a) || (s - a >= (signed int)sizeof(type))) {
Adam Tkac 788dabf
		ldap_memfree(a);
Adam Tkac 788dabf
		continue;
Adam Tkac 788dabf
	    }
Adam Tkac 788dabf
			
Adam Tkac 788dabf
	    strncpy(type, a, s - a);
Adam Tkac 788dabf
	    type[s - a] = '\0';
Adam Tkac 788dabf
	    vals = ldap_get_values_len(ld, e, a);
Adam Tkac 788dabf
	    if (vals) {
Adam Tkac 788dabf
		for (i = 0; vals[i]; i++)
Adam Tkac 788dabf
		    for (j = 0; names[j]; j++)
Adam Tkac 788dabf
			if (putrr(&zone, names[j], type, ttl, vals[i]))
Adam Tkac 788dabf
			    err(argv[0], "malloc failed");
Adam Tkac 788dabf
		ldap_value_free_len(vals);
Adam Tkac 788dabf
	    }
Adam Tkac 788dabf
	    ldap_memfree(a);
Adam Tkac 788dabf
	}
Adam Tkac 788dabf
Adam Tkac 788dabf
	if (ptr)
Adam Tkac 788dabf
	    ber_free(ptr, 0);
Adam Tkac 788dabf
	if (ttlvals)
Adam Tkac 788dabf
	    ldap_value_free(ttlvals);
Adam Tkac 788dabf
	ldap_value_free_len(names);
Adam Tkac 788dabf
	/* free this result */
Adam Tkac 788dabf
	ldap_msgfree(res);
Adam Tkac 788dabf
    }
Adam Tkac 788dabf
Adam Tkac 788dabf
    /* free final result */
Adam Tkac 788dabf
    ldap_msgfree(res);
Adam Tkac 788dabf
Adam Tkac 788dabf
    print_zone(defaultttl, zone);
Adam Tkac 788dabf
    return 0;
Adam Tkac 788dabf
}