mirror of
https://github.com/bklang/ldap2dns.git
synced 2025-10-28 06:44:14 -04:00
+ Updated INSTALL and FAQ
+ Replaced all remaining deprecated LDAP API calls + Converted to getopt_long and added double-dash options (--help) + Added search timeout and max record count options git-svn-id: https://svn.alkaloid.net/gpl/ldap2dns/trunk@325 06cd67b6-e706-0410-b29e-9de616bca6e9
This commit is contained in:
@@ -6,7 +6,9 @@ Version 0.4.0-pre1 (latest)
|
|||||||
+ Fixed a number of possible segfaults if required cmdline options were missing
|
+ Fixed a number of possible segfaults if required cmdline options were missing
|
||||||
Thanks Steve Ayotte (sayotte.alkaloid.net)
|
Thanks Steve Ayotte (sayotte.alkaloid.net)
|
||||||
+ Added more verbose LDAP error and sanity checking output
|
+ Added more verbose LDAP error and sanity checking output
|
||||||
+ Removed (some) deprecated LDAP API calls
|
+ Replaced all deprecated LDAP API calls
|
||||||
|
+ Converted to getopt_long and added double-dash options (--help)
|
||||||
|
+ Added search timeout and max record count options
|
||||||
|
|
||||||
Version 0.3.7
|
Version 0.3.7
|
||||||
+ Changed default location of ldap.conf to /etc/ldap.conf
|
+ Changed default location of ldap.conf to /etc/ldap.conf
|
||||||
|
|||||||
16
FAQ
16
FAQ
@@ -1,4 +1,15 @@
|
|||||||
1) What happened to the webadmin directory?
|
1) Where can I find a web interface?
|
||||||
|
2005-06-06 bklang
|
||||||
|
|
||||||
|
The official web interface of ldap2dns is "Beatnik." Beatnik is a module for
|
||||||
|
the Horde framework (http://www.horde.org). Beatnik is actively developed and
|
||||||
|
should be ready for release soon. Early adopters are encouraged to checkout
|
||||||
|
the code from SVN trunk. The author uses Beatnik productively today.
|
||||||
|
|
||||||
|
See http://projects.alkaloid.net for more information.
|
||||||
|
|
||||||
|
|
||||||
|
2) What happened to the webadmin directory?
|
||||||
|
|
||||||
2005-12-22 bklang
|
2005-12-22 bklang
|
||||||
** See security note at the end of this section regarding the old webadmin **
|
** See security note at the end of this section regarding the old webadmin **
|
||||||
@@ -25,7 +36,8 @@ responsibility for any problems related to the flawed webadmin code.
|
|||||||
|
|
||||||
Thanks to Erik Cabetas for bringing these issues to my attention.
|
Thanks to Erik Cabetas for bringing these issues to my attention.
|
||||||
|
|
||||||
2) Why have you deprecated all that code?
|
|
||||||
|
3) Why have you deprecated all that code?
|
||||||
|
|
||||||
2005-12-07 bklang
|
2005-12-07 bklang
|
||||||
This is partially answered above, but to fully answer the question it's not
|
This is partially answered above, but to fully answer the question it's not
|
||||||
|
|||||||
6
INSTALL
6
INSTALL
@@ -8,8 +8,8 @@ Type "make" in the current directory. If all goes well follow up with a
|
|||||||
|
|
||||||
To create an RPM, use one of the following commands:
|
To create an RPM, use one of the following commands:
|
||||||
|
|
||||||
sudo make DISTRIBUTION=redhat rpm
|
make DISTRIBUTION=redhat rpm
|
||||||
sudo make DISTRIBUTION=suse rpm
|
make DISTRIBUTION=suse rpm
|
||||||
|
|
||||||
if you are running Red Hat or SuSE respectively.
|
if you are running Red Hat or SuSE respectively.
|
||||||
|
|
||||||
@@ -20,4 +20,4 @@ Please send any problem or success reports to the maintainer.
|
|||||||
--
|
--
|
||||||
Ben Klang <ben@alkaloid.net>
|
Ben Klang <ben@alkaloid.net>
|
||||||
Alkaloid Networks
|
Alkaloid Networks
|
||||||
# $Id$
|
$Id$
|
||||||
|
|||||||
12
Makefile
12
Makefile
@@ -1,9 +1,9 @@
|
|||||||
# $Id$
|
# $Id$
|
||||||
VERSION=0.3.7
|
VERSION=0.4.0
|
||||||
RELEASE=0
|
RELEASE=0
|
||||||
CC=gcc -O2
|
CC=gcc
|
||||||
CCDEBUG=gcc -g -ggdb
|
DEBUG_CFLAGS=-g -ggdb
|
||||||
CFLAGS=$(INC) -DVERSION='"$(VERSION)"'
|
CFLAGS=-O2
|
||||||
LIBS=-lldap -llber
|
LIBS=-lldap -llber
|
||||||
LD=gcc
|
LD=gcc
|
||||||
LDFLAGS=
|
LDFLAGS=
|
||||||
@@ -40,10 +40,10 @@ ldap2dns-dbg: ldap2dns.o-dbg
|
|||||||
$(LD) $(LDFLAGS) $(LIBS) -o $@ $+
|
$(LD) $(LDFLAGS) $(LIBS) -o $@ $+
|
||||||
|
|
||||||
ldap2dns.o: ldap2dns.c
|
ldap2dns.o: ldap2dns.c
|
||||||
$(CC) $(CFLAGS) -c $< -o $@
|
$(CC) $(CFLAGS) -DVERSION='"$(VERSION)"' -c $< -o $@
|
||||||
|
|
||||||
ldap2dns.o-dbg: ldap2dns.c
|
ldap2dns.o-dbg: ldap2dns.c
|
||||||
$(CCDEBUG) $(CFLAGS) -c $< -o $@
|
$(CC) $(DEBUG_CFLAGS) $(CFLAGS) -DVERSION='"$(VERSION)"' -c $< -o $@
|
||||||
|
|
||||||
install: all
|
install: all
|
||||||
mkdir -p $(PREFIXDIR)/bin
|
mkdir -p $(PREFIXDIR)/bin
|
||||||
|
|||||||
94
ldap2dns.c
94
ldap2dns.c
@@ -13,6 +13,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <getopt.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#define UPDATE_INTERVAL 59
|
#define UPDATE_INTERVAL 59
|
||||||
@@ -20,6 +21,8 @@
|
|||||||
#define OUTPUT_DATA 1
|
#define OUTPUT_DATA 1
|
||||||
#define OUTPUT_DB 2
|
#define OUTPUT_DB 2
|
||||||
#define MAXHOSTS 10
|
#define MAXHOSTS 10
|
||||||
|
#define DEF_SEARCHTIMEOUT 40
|
||||||
|
#define DEF_RECLIMIT 5000
|
||||||
|
|
||||||
static char tinydns_textfile[256];
|
static char tinydns_textfile[256];
|
||||||
static char tinydns_texttemp[256];
|
static char tinydns_texttemp[256];
|
||||||
@@ -117,6 +120,8 @@ static struct
|
|||||||
char ldifname[128];
|
char ldifname[128];
|
||||||
char exec_command[128];
|
char exec_command[128];
|
||||||
int use_tls[MAXHOSTS];
|
int use_tls[MAXHOSTS];
|
||||||
|
struct timeval searchtimeout;
|
||||||
|
int reclimit;
|
||||||
} options;
|
} options;
|
||||||
|
|
||||||
|
|
||||||
@@ -153,9 +158,9 @@ static void set_datadir(void)
|
|||||||
static void print_usage(void)
|
static void print_usage(void)
|
||||||
{
|
{
|
||||||
print_version();
|
print_version();
|
||||||
printf("usage: ldap2dns[d] [-o data|db] [-h host] [-p port] \\\n");
|
printf("usage: ldap2dns[d] [-o data|db] [-h host] [-p port] [-H hostURI] \\\n");
|
||||||
printf("\t\t[-H hostURI] [-w password] [-L[filename]] [-u numsecs] \\\n");
|
printf("\t\t[-D binddn] [-w password] [-L[filename]] [-u numsecs] \\\n");
|
||||||
printf("\t\t[-D binddn] [-b searchbase] [-v[v]] [-V]\n");
|
printf("\t\t[-b searchbase] [-v[v]] [-V] [-t timeout] [-M maxrecords]\n");
|
||||||
printf("\n");
|
printf("\n");
|
||||||
printf(" *\tldap2dns formats DNS information from an LDAP server for tinydns or BIND\n");
|
printf(" *\tldap2dns formats DNS information from an LDAP server for tinydns or BIND\n");
|
||||||
printf(" *\tldap2dnsd runs backgrounded refreshing the data on regular intervals\n");
|
printf(" *\tldap2dnsd runs backgrounded refreshing the data on regular intervals\n");
|
||||||
@@ -225,12 +230,16 @@ static int parse_options()
|
|||||||
extern int optind, opterr, optopt;
|
extern int optind, opterr, optopt;
|
||||||
char buf[256], value[128];
|
char buf[256], value[128];
|
||||||
int len;
|
int len;
|
||||||
|
int c;
|
||||||
|
int digit_optind = 0;
|
||||||
FILE* ldap_conf,*fp;
|
FILE* ldap_conf,*fp;
|
||||||
char* ev;
|
char* ev;
|
||||||
|
|
||||||
strcpy(options.searchbase, "");
|
strcpy(options.searchbase, "");
|
||||||
strcpy(options.hostname[0], "localhost");
|
strcpy(options.hostname[0], "localhost");
|
||||||
options.port[0] = LDAP_PORT;
|
options.port[0] = LDAP_PORT;
|
||||||
|
options.searchtimeout.tv_sec = DEF_SEARCHTIMEOUT;
|
||||||
|
options.reclimit = DEF_RECLIMIT;
|
||||||
if (ldap_conf = fopen(LDAP_CONF, "r")) {
|
if (ldap_conf = fopen(LDAP_CONF, "r")) {
|
||||||
while(fgets(buf, 256, ldap_conf)!=0) {
|
while(fgets(buf, 256, ldap_conf)!=0) {
|
||||||
int i;
|
int i;
|
||||||
@@ -290,26 +299,54 @@ static int parse_options()
|
|||||||
options.ldifname[0] = '\0';
|
options.ldifname[0] = '\0';
|
||||||
strcpy(options.password, "");
|
strcpy(options.password, "");
|
||||||
strcpy(options.exec_command, "");
|
strcpy(options.exec_command, "");
|
||||||
while ( (len = getopt(main_argc, main_argv, "b:D:e:h:H:o:p:u:Vv::w:L::"))>0 ) {
|
while (1) {
|
||||||
|
int this_option_optind = optind ? optind : 1;
|
||||||
|
int option_index = 0;
|
||||||
|
static struct option long_options[] = {
|
||||||
|
// name, has_arg, flag, val
|
||||||
|
{"help", 0, 0, '?'},
|
||||||
|
{"binddn", 1, 0, 'D'},
|
||||||
|
{"bindpw", 1, 0, 'w'},
|
||||||
|
{"basedn", 1, 0, 'b'},
|
||||||
|
{"output", 1, 0, 'o'},
|
||||||
|
{"ldif", 1, 0, 'L'},
|
||||||
|
{"host", 1, 0, 'h'},
|
||||||
|
{"port", 1, 0, 'p'},
|
||||||
|
{"uri", 1, 0, 'H'},
|
||||||
|
{"update", 1, 0, 'u'},
|
||||||
|
{"exec", 1, 0, 'e'},
|
||||||
|
{"verbose", 0, 0, 'v'},
|
||||||
|
{"version", 0, 0, 'V'},
|
||||||
|
{"timeout", 1, 0, 't'},
|
||||||
|
{"maxrecords", 1, 0, 'M'},
|
||||||
|
{0, 0, 0, 0}
|
||||||
|
};
|
||||||
|
|
||||||
|
c = getopt_long(main_argc, main_argv, "b:D:e:h:H:o:p:u:m:t:Vv::w:L::", long_options, &option_index);
|
||||||
|
|
||||||
|
if (c == -1)
|
||||||
|
break;
|
||||||
|
|
||||||
if (optarg && strlen(optarg)>127) {
|
if (optarg && strlen(optarg)>127) {
|
||||||
fprintf(stderr, "argument %s too long\n", optarg);
|
fprintf(stderr, "argument %s too long\n", optarg);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
switch (len) {
|
|
||||||
case 'b':
|
switch (c) {
|
||||||
|
case 'b':
|
||||||
strncpy(options.searchbase, optarg, sizeof(options.searchbase));
|
strncpy(options.searchbase, optarg, sizeof(options.searchbase));
|
||||||
options.searchbase[ sizeof(options.searchbase) -1] = '\0';
|
options.searchbase[ sizeof(options.searchbase) -1] = '\0';
|
||||||
break;
|
break;
|
||||||
case 'u':
|
case 'u':
|
||||||
if (sscanf(optarg, "%d", &options.update_iv)!=1)
|
if (sscanf(optarg, "%d", &options.update_iv)!=1)
|
||||||
options.update_iv = UPDATE_INTERVAL;
|
options.update_iv = UPDATE_INTERVAL;
|
||||||
if (options.update_iv<=0) options.update_iv = 1;
|
if (options.update_iv<=0) options.update_iv = 1;
|
||||||
break;
|
break;
|
||||||
case 'D':
|
case 'D':
|
||||||
strncpy(options.binddn, optarg, sizeof(options.binddn));
|
strncpy(options.binddn, optarg, sizeof(options.binddn));
|
||||||
options.binddn[ sizeof(options.binddn) -1 ] = '\0';
|
options.binddn[ sizeof(options.binddn) -1 ] = '\0';
|
||||||
break;
|
break;
|
||||||
case 'h':
|
case 'h':
|
||||||
strncpy(options.hostname[0], optarg, sizeof(options.hostname[0]));
|
strncpy(options.hostname[0], optarg, sizeof(options.hostname[0]));
|
||||||
options.hostname[0][ sizeof(options.hostname[0]) -1 ] = '\0';
|
options.hostname[0][ sizeof(options.hostname[0]) -1 ] = '\0';
|
||||||
options.usedhosts = 1;
|
options.usedhosts = 1;
|
||||||
@@ -319,7 +356,7 @@ static int parse_options()
|
|||||||
options.urildap[0][ sizeof( options.urildap[0] ) -1 ] = '\0';
|
options.urildap[0][ sizeof( options.urildap[0] ) -1 ] = '\0';
|
||||||
options.useduris = 1;
|
options.useduris = 1;
|
||||||
break;
|
break;
|
||||||
case 'L':
|
case 'L':
|
||||||
if (optarg==NULL)
|
if (optarg==NULL)
|
||||||
strcpy(options.ldifname, "-");
|
strcpy(options.ldifname, "-");
|
||||||
else{
|
else{
|
||||||
@@ -327,36 +364,45 @@ static int parse_options()
|
|||||||
options.ldifname[ sizeof( options.ldifname ) -1 ] = '\0';
|
options.ldifname[ sizeof( options.ldifname ) -1 ] = '\0';
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'o':
|
case 'o':
|
||||||
options.output = 0;
|
options.output = 0;
|
||||||
if (strcmp(optarg, "data")==0)
|
if (strcmp(optarg, "data")==0)
|
||||||
options.output = OUTPUT_DATA;
|
options.output = OUTPUT_DATA;
|
||||||
else if (strcmp(optarg, "db")==0)
|
else if (strcmp(optarg, "db")==0)
|
||||||
options.output = OUTPUT_DB;
|
options.output = OUTPUT_DB;
|
||||||
break;
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
if (sscanf(optarg, "%hd", &options.port[0])!=1)
|
if (sscanf(optarg, "%hd", &options.port[0])!=1)
|
||||||
options.port[0] = LDAP_PORT;
|
options.port[0] = LDAP_PORT;
|
||||||
break;
|
break;
|
||||||
case 'v':
|
case 'v':
|
||||||
if (optarg && optarg[0]=='v')
|
if (optarg && optarg[0]=='v')
|
||||||
options.verbose = 3;
|
options.verbose = 3;
|
||||||
else
|
else
|
||||||
options.verbose = 1;
|
options.verbose = 1;
|
||||||
break;
|
break;
|
||||||
case 'V':
|
case 'V':
|
||||||
print_version();
|
print_version();
|
||||||
exit(0);
|
exit(0);
|
||||||
case 'w':
|
case 'w':
|
||||||
strncpy(options.password, optarg, sizeof(options.password));
|
strncpy(options.password, optarg, sizeof(options.password));
|
||||||
options.password[ sizeof( options.password ) -1 ] = '\0';
|
options.password[ sizeof( options.password ) -1 ] = '\0';
|
||||||
memset(optarg, 'x', strlen(options.password));
|
memset(optarg, 'x', strlen(options.password));
|
||||||
break;
|
break;
|
||||||
case 'e':
|
case 'e':
|
||||||
strncpy(options.exec_command, optarg, sizeof(options.exec_command));
|
strncpy(options.exec_command, optarg, sizeof(options.exec_command));
|
||||||
options.exec_command[ sizeof( options.exec_command ) -1 ] = '\0';
|
options.exec_command[ sizeof( options.exec_command ) -1 ] = '\0';
|
||||||
break;
|
break;
|
||||||
default:
|
case 't':
|
||||||
|
if (sscanf(optarg, "%hd", &options.searchtimeout.tv_sec)!=1)
|
||||||
|
options.searchtimeout.tv_sec = DEF_SEARCHTIMEOUT;
|
||||||
|
break;
|
||||||
|
case 'M':
|
||||||
|
if (sscanf(optarg, "%hd", &options.reclimit)!=1)
|
||||||
|
options.reclimit = DEF_RECLIMIT;
|
||||||
|
break;
|
||||||
|
case '?':
|
||||||
|
default:
|
||||||
print_usage();
|
print_usage();
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
@@ -557,7 +603,7 @@ static void read_resourcerecords(char* dn, int znix)
|
|||||||
LDAPMessage* m;
|
LDAPMessage* m;
|
||||||
int ldaperr;
|
int ldaperr;
|
||||||
|
|
||||||
if ( (ldaperr = ldap_search_s(ldap_con, dn, LDAP_SCOPE_SUBTREE, "objectclass=DNSrrset", NULL, 0, &res))!=LDAP_SUCCESS )
|
if ( (ldaperr = ldap_search_ext_s(ldap_con, dn, LDAP_SCOPE_SUBTREE, "objectclass=DNSrrset", NULL, 0, NULL, NULL, &options.searchtimeout, options.reclimit, &res))!=LDAP_SUCCESS )
|
||||||
die_ldap(ldaperr);
|
die_ldap(ldaperr);
|
||||||
for (m = ldap_first_entry(ldap_con, res); m; m = ldap_next_entry(ldap_con, m)) {
|
for (m = ldap_first_entry(ldap_con, res); m; m = ldap_next_entry(ldap_con, m)) {
|
||||||
BerElement* ber = NULL;
|
BerElement* ber = NULL;
|
||||||
@@ -754,7 +800,7 @@ static void calc_checksum(int* num, int* sum)
|
|||||||
char* attr_list[2] = { "DNSserial", NULL };
|
char* attr_list[2] = { "DNSserial", NULL };
|
||||||
|
|
||||||
*num = *sum = 0;
|
*num = *sum = 0;
|
||||||
if ( ldaperr = ldap_search_s(ldap_con, options.searchbase[0] ? options.searchbase : NULL, LDAP_SCOPE_SUBTREE, "objectclass=DNSzone", attr_list, 0, &res)!=LDAP_SUCCESS )
|
if ( ldaperr = ldap_search_ext_s(ldap_con, options.searchbase[0] ? options.searchbase : NULL, LDAP_SCOPE_SUBTREE, "objectclass=DNSzone", attr_list, 0, NULL, NULL, &options.searchtimeout, options.reclimit, &res)!=LDAP_SUCCESS )
|
||||||
die_ldap(ldaperr);
|
die_ldap(ldaperr);
|
||||||
for (m = ldap_first_entry(ldap_con, res); m; m = ldap_next_entry(ldap_con, m)) {
|
for (m = ldap_first_entry(ldap_con, res); m; m = ldap_next_entry(ldap_con, m)) {
|
||||||
BerElement* ber = NULL;
|
BerElement* ber = NULL;
|
||||||
@@ -786,7 +832,7 @@ static void read_dnszones(void)
|
|||||||
fprintf(tinyfile, "# Automatically generated by ldap2dns v%s - DO NOT EDIT!\n", VERSION);
|
fprintf(tinyfile, "# Automatically generated by ldap2dns v%s - DO NOT EDIT!\n", VERSION);
|
||||||
if (namedmaster)
|
if (namedmaster)
|
||||||
fprintf(namedmaster, "# Automatically generated by ldap2dns v%s - DO NOT EDIT!\n", VERSION);
|
fprintf(namedmaster, "# Automatically generated by ldap2dns v%s - DO NOT EDIT!\n", VERSION);
|
||||||
if ( (ldaperr = ldap_search_s(ldap_con, options.searchbase[0] ? options.searchbase : NULL, LDAP_SCOPE_SUBTREE, "objectclass=DNSzone", NULL, 0, &res))!=LDAP_SUCCESS )
|
if ( (ldaperr = ldap_search_ext_s(ldap_con, options.searchbase[0] ? options.searchbase : NULL, LDAP_SCOPE_SUBTREE, "objectclass=DNSzone", NULL, 0, NULL, NULL, &options.searchtimeout, options.reclimit, &res))!=LDAP_SUCCESS )
|
||||||
die_ldap(ldaperr);
|
die_ldap(ldaperr);
|
||||||
for (m = ldap_first_entry(ldap_con, res); m; m = ldap_next_entry(ldap_con, m)) {
|
for (m = ldap_first_entry(ldap_con, res); m; m = ldap_next_entry(ldap_con, m)) {
|
||||||
BerElement* ber = NULL;
|
BerElement* ber = NULL;
|
||||||
@@ -927,13 +973,7 @@ static void read_loccodes(void)
|
|||||||
if (tinyfile)
|
if (tinyfile)
|
||||||
fprintf(tinyfile, "# Location Codes (if any) - generated by ldap2dns v%s - DO NOT EDIT!\n", VERSION);
|
fprintf(tinyfile, "# Location Codes (if any) - generated by ldap2dns v%s - DO NOT EDIT!\n", VERSION);
|
||||||
|
|
||||||
if ( (ldaperr = ldap_search_s(ldap_con, options.searchbase[0] ? options.searchbase : NULL,
|
if ( (ldaperr = ldap_search_ext_s(ldap_con, options.searchbase[0] ? options.searchbase : NULL, LDAP_SCOPE_SUBTREE, "objectclass=DNSloccodes", NULL, 0, NULL, NULL, &options.searchtimeout, options.reclimit, &res))!=LDAP_SUCCESS )
|
||||||
LDAP_SCOPE_SUBTREE,
|
|
||||||
"objectclass=DNSloccodes",
|
|
||||||
NULL,
|
|
||||||
0,
|
|
||||||
&res)
|
|
||||||
)!=LDAP_SUCCESS )
|
|
||||||
die_ldap(ldaperr);
|
die_ldap(ldaperr);
|
||||||
for (m = ldap_first_entry(ldap_con, res); m; m = ldap_next_entry(ldap_con, m)) {
|
for (m = ldap_first_entry(ldap_con, res); m; m = ldap_next_entry(ldap_con, m)) {
|
||||||
BerElement* ber = NULL;
|
BerElement* ber = NULL;
|
||||||
|
|||||||
Reference in New Issue
Block a user