zone2ldap.c revision a6f360bb94748620b319066f96d02d61aa1ae487
/*
* Copyright (C) 2001 Jeff McNeil <jeff@snapcase.g-rock.net>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* Change Log
*
* Tue May 1 19:19:54 EDT 2001 - Jeff McNeil
* Update to objectClass code, and add_to_rr_list function
* (I need to rename that) to support the dNSZone schema,
* ditched dNSDomain2 schema support. Version 0.3-ALPHA
*/
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <getopt.h>
#include <dns/dbiterator.h>
#include <dns/fixedname.h>
#include <dns/rdataset.h>
#include <dns/rdatasetiter.h>
#include <dns/rdatatype.h>
#include <ldap.h>
#define DNS_OBJECT 6
#define DNS_TOP 2
#define VERSION "0.3-ALPHA"
typedef struct LDAP_INFO
{
char *dn;
int attrcnt;
}
/* usage Info */
void usage ();
/* Add to the ldap dit */
/* Init an ldap connection */
void init_ldap_conn ();
/* Ldap error checking */
/* Put a hostname into a char ** array */
/* Find out how many items are in a char ** array */
int get_attr_list_size (char **tmp);
/* Get a DN */
/* Add to RR list */
/* Error checking */
/* Generate LDIF Format files */
unsigned int ttl);
/* head pointer to the list */
char *ldapsystem = "localhost";
static char *objectClasses[] =
unsigned int debug = 0;
#ifdef DEBUG
debug = 1;
#endif
int
{
char *basedn;
char *zonefile;
char fullbasedn[1024];
char *ctmp;
char **dc_list;
extern char *optarg;
int create_base = 0;
int topt;
if ((int) argc < 2)
{
usage ();
exit (-1);
}
{
switch (topt)
{
case 'v':
exit(0);
case 'c':
create_base++;
break;
case 'd':
debug++;
break;
case 'D':
break;
case 'w':
break;
case 'b':
break;
case 'z':
break;
case 'f':
break;
case 'h':
break;
case '?':
default:
usage ();
exit (0);
}
}
{
usage ();
exit (-1);
}
if (debug)
printf ("Initializing ISC Routines, parsing zone file\n");
result =
dns_rdata_init (&rdata);
while (result == ISC_R_SUCCESS)
{
if (result == ISC_R_NOMORE)
break;
//isc_result_check(result, "dns_rdatasetiter_first");
while (result == ISC_R_SUCCESS)
{
while (result == ISC_R_SUCCESS)
{
dns_rdata_reset (&rdata);
}
}
}
/* Initialize the LDAP Connection */
if (debug)
init_ldap_conn ();
if (create_base)
{
if (debug)
{
{
base_attrs[0] = &base;
if (ldapbase)
{
else
}
else
{
else
}
}
}
}
else
{
if (debug)
}
{
if (debug)
}
if (debug)
printf("Operation Complete.\n");
return 0;
}
/* Check the status of an isc_result_t after any isc routines.
* I should probably rename this function, as not to cause any
* confusion with the isc* routines. Will exit on error. */
void
{
if (res != ISC_R_SUCCESS)
{
exit (-1);
}
}
/* Takes DNS information, in bind data structure format, and adds textual
* zone information to the LDAP run queue. */
void
{
unsigned int len;
unsigned char type[20];
unsigned char data[2048];
char **dc_list;
char *dn;
if (debug)
}
/* Locate an item in the Run queue linked list, by DN. Used by functions
* which add items to the run queue.
*/
locate_by_dn (char *dn)
{
{
return tmp;
}
}
/* Take textual zone data, and add to the LDAP Run queue. This works like so:
* If locate_by_dn does not return, alloc a new ldap_info structure, and then
* calloc a LDAPMod array, fill in the default "everyone needs this" information,
* including object classes and dc's. If it locate_by_dn does return, then we'll
* realloc for more LDAPMod structs, and appened the new data. If an LDAPMod exists
* for the parameter we're adding, then we'll realloc the mod_values array, and
* add the new value to the existing LDAPMod. Finnaly, it assures linkage exists
* within the Run queue linked ilst*/
void
{
int i;
int x;
int attrlist;
char ldap_type_buffer[128];
char charttl[64];
{
/* There wasn't one already there, so we need to allocate a new one,
* and stick it on the list */
{
exit (-1);
}
{
exit (-1);
}
for (i = 0; i < flags; i++)
{
{
exit (-1);
}
}
if (flags == DNS_OBJECT)
else
{
return;
}
exit(-1);
exit(-1);
exit(-1);
}
else
{
{
if (!strncmp
{
sizeof (char *) * (attrlist + 1));
{
exit (-1);
}
return;
}
}
{
exit (-1);
}
}
}
/* Size of a mod_values list, plus the terminating NULL field. */
int
get_attr_list_size (char **tmp)
{
int i = 0;
{
i++;
ftmp++;
}
return ++i;
}
/* take a hostname, and split it into a char ** of the dc parts,
* example, we have www.domain.com, this function will return:
* array[0] = com, array[1] = domain, array[2] = www. */
char **
{
char *tmp;
static char *dn_buffer[64];
int i = 0;
char *zname;
char *hnamebuff;
if (flags == DNS_OBJECT)
{
{
*--tmp = '\0';
}
else
hnamebuff = "@";
}
else
{
}
{
*tmp++ = '\0';
}
return dn_buffer;
}
/* build an sdb compatible LDAP DN from a "dc_list" (char **).
* will append dNSTTL information to each RR Record, with the
* exception of "@"/SOA. */
char *
{
int size;
int x;
static char dn[1024];
char tmp[128];
for (x = size - 2; x > 0; x--)
{
else if (x == (size - 2))
else
}
return dn;
}
/* Initialize LDAP Conn */
void
{
int result;
{
exit (-1);
}
}
/* Like isc_result_check, only for LDAP */
void
{
{
exit (-1);
}
}
/* For running the ldap_info run queue. */
void
{
int result;
char dnbuffer[1024];
else
}
/* name says it all */
void
usage ()
{
"zone2ldap -D [BIND DN] -w [BIND PASSWORD] -b [BASE DN] -z [ZONE] -f [ZONE FILE] -h [LDAP HOST]
[-c Create LDAP Base structure][-d Debug Output (lots !)] \n ");}