diff -Nur bindmon-0.3.orig/Makefile bindmon-0.3/Makefile --- bindmon-0.3.orig/Makefile Sat Jun 26 01:58:18 1999 +++ bindmon-0.3/Makefile Wed May 9 17:21:13 2001 @@ -15,6 +15,7 @@ install: bindmon install -o root -g root -m 755 bindmon $(BINDIR) + install -o root -g root -m 755 man/bindmon.1 $(MANDIR) bindmon: dummy # bindmon: diff -Nur bindmon-0.3.orig/VERSION bindmon-0.3/VERSION --- bindmon-0.3.orig/VERSION Fri Jun 25 05:50:26 1999 +++ bindmon-0.3/VERSION Thu May 10 09:07:57 2001 @@ -1 +1 @@ -0.3 +0.3.inter diff -Nur bindmon-0.3.orig/man/bindmon.1 bindmon-0.3/man/bindmon.1 --- bindmon-0.3.orig/man/bindmon.1 Thu Jan 1 08:00:00 1970 +++ bindmon-0.3/man/bindmon.1 Wed May 9 17:20:00 2001 @@ -0,0 +1,88 @@ +.\"definition +.de Sp +.if n .sp +.if t .sp 0.4 +.. +.TH BINDMON "1" "May 9, 2001" "Misc. Utilities" +.SH NAME +bindmon \- is a program used to accomplish some degree of fault tolerance in TCP/IP services, by monitoring service health and updating BIND maps whenever a service comes up or down +.SH SYNOPSIS +.B bindmon +[ +.B \-cmd +.I COMMAND +] +[ +.B \-log +.I LOGFILEPATH +] +[ +.B \-pid +.I PIDFILEPATH +] +.B \-files +.I INPUTFILE OUTPUTFILE +[ +.B \-files +.I INPUTFILE OUTPUTFILE +] +[ +.B \-ctimeout +.I NSECONDS +] +.SH DESCRIPTION +.B bindmon +is a program used to accomplish some degree of fault tolerance in TCP/IP services, by monitoring service health and updating BIND maps whenever a service comes up or down +.SH OPTIONS +.IP \-cmd +Option to change the default named refresh command string to \fICOMMAND\fP. +.IP \-log +Option to change the default log file path to \fILOGFILEPATH\fP. +.IP \-pid +Option to change the default PID file path to \fIPIDFILEPATH\fP. +.IP \-ctimeout +Option to change the default timeout to \fINSECONDS\fP nanoseconds. +.IP \-files +One or more of these options can be used to specify template file and output file pairs. +.SH USAGE +Rename your current BIND input files to an input form. For instance, if you currently have a file called db.domain, you might rename it to db.domain.in +.PP +Encapsulate entries for single-service hosts in your BIND input file to show that they depend on some TCP service. For instance, where you now might have: + +\fBgateway.m-tech.ab.ca. 0 IN A 10.0.0.1\fP + + You could write: + +\fB#ifup 10.0.0.1 80 5 1 5\fP +.br + \fBgateway.m-tech.ab.ca. 0 IN A 10.0.0.1\fP +.br +\fB#endif\fP + +.PP +This means that the record should only be included if port 80 on 10.0.0.1 is open (maybe it's a WWW server). The health of the port should be checked every 5 minutes. If a single failure to open has been detected, the record should be removed. If five consecutive attempts have succeeded, then it can be reactivated. + +.SH EXAMPLES +\fBbindmon -log /var/log/bindmon.log -files db.test.domain.in db.test.domain\fP +.IP +This command runs bindmon and lets it check the db.test.domain.in as its input template file and writes the corresponding domain file as db.test.domain. +.B bindmon +will also write the log files to /var/log/bindmon.log +.LP +\fBbindmon -ctimeout 100 -files db.test.domain.in db.test.domain\fP +.IP +This command is similar to the command issue above. However, the default path for the log file is used and the socket connection timeout is set to 100 nanoseconds. +.SH PLATFORMS +This program was written on and for Linux/Intel/ELF/libc6. +It should compile cleanly on any ANSI-C environment, and should +be useful on any Unix or Unix-like system. +.PP +This program is primarily intended to monitor and interact +with the Berkeley Internet Name Daemon (BIND). However, it +might be useful in other situations. +.SH WARRANTIES +The author provides no warranties for this software. +.SH COPYRIGHT +This software is distributed under the terms of the GNU General Public License version 2. +This is free software; see the source for copying conditions. There is NO +warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. diff -Nur bindmon-0.3.orig/src/buf bindmon-0.3/src/buf --- bindmon-0.3.orig/src/buf Fri Jun 25 07:47:30 1999 +++ bindmon-0.3/src/buf Thu Jan 1 08:00:00 1970 @@ -1,3 +0,0 @@ - sprintf(ptr, "%04d%02d%02d-%02d:%02d:%02d ", - tm_ptr->tm_year+1900, tm_ptr->tm_mon+1, tm_ptr->tm_mday, - tm_ptr->tm_hour, tm_ptr->tm_min, tm_ptr->tm_sec); diff -Nur bindmon-0.3.orig/src/err bindmon-0.3/src/err --- bindmon-0.3.orig/src/err Wed Jun 23 12:05:52 1999 +++ bindmon-0.3/src/err Thu Jan 1 08:00:00 1970 @@ -1,25 +0,0 @@ -gcc -Wall -g -c condition.c -glob.h: In function `LogMessage': -In file included from condition.c:1: -glob.h:19: storage class specified for parameter `errfile' -glob.h:22: storage class specified for parameter `refreshCommand' -glob.h:23: storage class specified for parameter `defaultCondition' -glob.h:26: storage class specified for parameter `fileList' -glob.h:27: storage class specified for parameter `logFilePath' -glob.h:29: storage class specified for parameter `nConditions' -glob.h:30: storage class specified for parameter `connectTimeout' -glob.h:31: storage class specified for parameter `csArray' -glob.h:32: storage class specified for parameter `minTime' -condition.c:6: parse error before `{' -glob.h:19: parm types given both in parmlist and separately -condition.c:11: `hostaddr' undeclared (first use this function) -condition.c:11: (Each undeclared identifier is reported only once -condition.c:11: for each function it appears in.) -condition.c:12: `portnum' undeclared (first use this function) -condition.c:13: `testFreqSeconds' undeclared (first use this function) -condition.c:14: `numFailRemove' undeclared (first use this function) -condition.c:15: `numOkInclude' undeclared (first use this function) -condition.c:23: `defaultCondition' undeclared (first use this function) -condition.c:28: `nConditions' undeclared (first use this function) -condition.c:30: warning: `return' with a value, in function returning void -make: *** [condition.o] Error 1 diff -Nur bindmon-0.3.orig/src/failover.h bindmon-0.3/src/failover.h --- bindmon-0.3.orig/src/failover.h Fri Jun 25 05:56:48 1999 +++ bindmon-0.3/src/failover.h Wed May 9 08:48:39 2001 @@ -63,6 +63,7 @@ { CONDITION *conditions; LINE *lines; + LINE *elselines; BLOCK *next; }; @@ -104,7 +105,8 @@ BLOCK *BlockMake( CONDITION *conditions, - LINE *lines + LINE *lines, + int elseflag ); FILEPAIR *FilePairParse(char *input, char *output); @@ -113,7 +115,8 @@ FILEPAIR *FilePairMake( char *inputPath, char *outputPath, - char *refreshCommand + char *refreshCommand, + char *defaultCommand ); /********************************************************************** diff -Nur bindmon-0.3.orig/src/filepair.c bindmon-0.3/src/filepair.c --- bindmon-0.3.orig/src/filepair.c Fri Jun 25 07:50:04 1999 +++ bindmon-0.3/src/filepair.c Wed May 9 12:14:16 2001 @@ -48,12 +48,15 @@ return newline; } -BLOCK *BlockMake( CONDITION *conditions, LINE *lines ) +BLOCK *BlockMake( CONDITION *conditions, LINE *lines, int elseflag ) { BLOCK *b; b = (BLOCK*)MyCalloc(1,sizeof(BLOCK),"a condition/line block"); b->conditions = conditions; - b->lines = lines; + if (elseflag==1) + b->elselines = lines; + else + b->lines = lines; b->next = NULL; return b; } @@ -94,13 +97,14 @@ return c; } -BLOCK *FileParse(char *fname) +BLOCK *FileParse(char *fname, char **zonestring) { - char buf[BUFLEN], *ptr; + char buf[BUFLEN], *ptr, *s, *s2, *temp; FILE *f; BLOCK *b = NULL, **bb = NULL; LINE *l = NULL, **ll = NULL; CONDITION *c = NULL; + int elseflag = 0; bb = &b; ll = &l; @@ -108,7 +112,7 @@ f = fopen(fname,"r"); if( f==NULL ) Error("Cannot read from %s",fname); - + while( fgets(buf,BUFLEN,f)==buf ) { if( FirstChar(buf, &ptr)=='#' ) @@ -117,23 +121,32 @@ { if( l!=NULL ) { - *bb = BlockMake(c,l); + *bb = BlockMake(c,l,0); bb = &((*bb)->next); l = NULL; ll = &l; } c = ConditionParse(ptr+6); + elseflag = 0; + } + else if( strncasecmp(ptr,"#else",5)==0 ) + { + *bb = BlockMake(c,l,0); + l = NULL; + ll = &l; + elseflag = 1; } else if( strncasecmp(ptr,"#endif",6)==0 ) { if( l!=NULL ) { - *bb = BlockMake(c,l); + *bb = BlockMake(c,l,elseflag); bb = &((*bb)->next); l = NULL; ll = &l; c = NULL; } + elseflag = 0; } else /* don't know what this command is.. */ { @@ -143,27 +156,50 @@ } else { + /* grab the ORIGIN tag */ + if ( strncasecmp(buf,"$ORIGIN",7)==0 ) + { + temp = malloc(strlen(buf)+1); + strcpy(temp,buf); + s = strchr(temp,' '); + *s++ = 0; + s2 = strchr(s,'\n'); + *(--s2) = 0; + *zonestring = malloc(strlen(s)+1); + strcpy(*zonestring,s); + free(temp); + } *ll = LineMake(buf); ll = &((*ll)->next); } } - *bb = BlockMake(c,l); + *bb = BlockMake(c,l,0); bb = &((*bb)->next); return b; } -FILEPAIR *FilePairMake( char *inputPath, char *outputPath, char *refreshCommand ) +FILEPAIR *FilePairMake( char *inputPath, char *outputPath, char *refreshCommand,char *defaultCommand ) { FILEPAIR *fp; BLOCK *b; CONDITION *c; + char *zonestring,*temp; + fp = (FILEPAIR*)MyCalloc(1,sizeof(FILEPAIR),"file pair"); fp->inputPath = inputPath; fp->outputPath = outputPath; - fp->refreshCommand = refreshCommand; - fp->contents = FileParse(fp->inputPath); + fp->contents = FileParse(fp->inputPath, &temp); + if (temp!=NULL) { + zonestring = malloc(strlen(temp)+strlen(refreshCommand)); + zonestring = strcat(zonestring,refreshCommand); + zonestring = strcat(zonestring,temp); + free(temp); + fp->refreshCommand = zonestring; /* new refresh command */ + } else { + zonestring = defaultCommand; + } fp->seqNo = 0; for( b=fp->contents; b!=NULL; b=b->next ) @@ -214,8 +250,7 @@ } tnow = time(NULL); t = localtime(&tnow); - fprintf(f,"%04d%02d%02d%02d%02d%02d%04d", - t->tm_year+1900, t->tm_mon+1, t->tm_mday, + fprintf(f,"%02d%02d%02d%02d", t->tm_hour, t->tm_min, t->tm_sec, fp->seqNo); ++fp->seqNo; @@ -250,6 +285,11 @@ if( ConditionChainTrue(f, b->conditions) ) { PrintLines(f,b->lines,fp); + } + else + { + if (b->elselines!=NULL) + PrintLines(f,b->elselines,fp); } if( b->conditions!=NULL ) fprintf(f, "; ---- end of condition\n"); diff -Nur bindmon-0.3.orig/src/filepair.c.diff bindmon-0.3/src/filepair.c.diff --- bindmon-0.3.orig/src/filepair.c.diff Thu Jan 1 08:00:00 1970 +++ bindmon-0.3/src/filepair.c.diff Wed May 9 12:20:19 2001 @@ -0,0 +1,94 @@ +51c51 +< BLOCK *BlockMake( CONDITION *conditions, LINE *lines ) +--- +> BLOCK *BlockMake( CONDITION *conditions, LINE *lines, int elseflag ) +56c56,59 +< b->lines = lines; +--- +> if (elseflag==1) +> b->elselines = lines; +> else +> b->lines = lines; +97c100 +< BLOCK *FileParse(char *fname) +--- +> BLOCK *FileParse(char *fname, char **zonestring) +99c102 +< char buf[BUFLEN], *ptr; +--- +> char buf[BUFLEN], *ptr, *s, *s2, *temp; +103a107 +> int elseflag = 0; +111c115 +< +--- +> +120c124 +< *bb = BlockMake(c,l); +--- +> *bb = BlockMake(c,l,0); +125a130,137 +> elseflag = 0; +> } +> else if( strncasecmp(ptr,"#else",5)==0 ) +> { +> *bb = BlockMake(c,l,0); +> l = NULL; +> ll = &l; +> elseflag = 1; +131c143 +< *bb = BlockMake(c,l); +--- +> *bb = BlockMake(c,l,elseflag); +136a149 +> elseflag = 0; +145a159,171 +> /* grab the ORIGIN tag */ +> if ( strncasecmp(buf,"$ORIGIN",7)==0 ) +> { +> temp = malloc(strlen(buf)+1); +> strcpy(temp,buf); +> s = strchr(temp,' '); +> *s++ = 0; +> s2 = strchr(s,'\n'); +> *(--s2) = 0; +> *zonestring = malloc(strlen(s)+1); +> strcpy(*zonestring,s); +> free(temp); +> } +151c177 +< *bb = BlockMake(c,l); +--- +> *bb = BlockMake(c,l,0); +157c183 +< FILEPAIR *FilePairMake( char *inputPath, char *outputPath, char *refreshCommand ) +--- +> FILEPAIR *FilePairMake( char *inputPath, char *outputPath, char *refreshCommand,char *defaultCommand ) +161a188,189 +> char *zonestring,*temp; +> +165,166c193,202 +< fp->refreshCommand = refreshCommand; +< fp->contents = FileParse(fp->inputPath); +--- +> fp->contents = FileParse(fp->inputPath, &temp); +> if (temp!=NULL) { +> zonestring = malloc(strlen(temp)+strlen(refreshCommand)); +> zonestring = strcat(zonestring,refreshCommand); +> zonestring = strcat(zonestring,temp); +> free(temp); +> fp->refreshCommand = zonestring; /* new refresh command */ +> } else { +> zonestring = defaultCommand; +> } +217,218c253 +< fprintf(f,"%04d%02d%02d%02d%02d%02d%04d", +< t->tm_year+1900, t->tm_mon+1, t->tm_mday, +--- +> fprintf(f,"%02d%02d%02d%02d", +252a288,292 +> } +> else +> { +> if (b->elselines!=NULL) +> PrintLines(f,b->elselines,fp); diff -Nur bindmon-0.3.orig/src/glob.h bindmon-0.3/src/glob.h --- bindmon-0.3.orig/src/glob.h Sat Jun 26 01:38:04 1999 +++ bindmon-0.3/src/glob.h Wed May 9 08:45:03 2001 @@ -19,14 +19,14 @@ VARIABLE(FILE, *errfile, NULL) /* Defaults: */ -VARIABLE(char, *refreshCommand, "kill -1 `ps -ef|grep named|awk '{print $2}'`") +VARIABLE(char, *refreshCommand, "rndc reload ") VARIABLE(int, defaultCondition, 1) +VARIABLE(char, *defaultCommand, "killall -HUP named") /* All input files we monitor: */ VARIABLE(FILEPAIR, *fileList, NULL) VARIABLE(char, *logFilePath, "/var/log/bindmon.log") VARIABLE(char, *pidFilePath, "/etc/bindmon.pid") - VARIABLE(int, nConditions, 0) VARIABLE(int, connectTimeout, CONNECT_TIMEOUT) VARIABLE(CONNECT_STRUCT, *csArray, NULL) diff -Nur bindmon-0.3.orig/src/glob.h.diff bindmon-0.3/src/glob.h.diff --- bindmon-0.3.orig/src/glob.h.diff Thu Jan 1 08:00:00 1970 +++ bindmon-0.3/src/glob.h.diff Wed May 9 12:20:37 2001 @@ -0,0 +1,8 @@ +22c22 +< VARIABLE(char, *refreshCommand, "kill -1 `ps -ef|grep named|awk '{print $2}'`") +--- +> VARIABLE(char, *refreshCommand, "rndc reload ") +23a24 +> VARIABLE(char, *defaultCommand, "killall -HUP named") +29d29 +< diff -Nur bindmon-0.3.orig/src/main.c bindmon-0.3/src/main.c --- bindmon-0.3.orig/src/main.c Sat Jun 26 01:40:18 1999 +++ bindmon-0.3/src/main.c Wed May 9 08:47:41 2001 @@ -77,7 +77,7 @@ char *inpath, *outpath; inpath = argv[++i]; outpath = argv[++i]; - *fplast = FilePairMake(inpath, outpath, refreshCommand); + *fplast = FilePairMake(inpath, outpath, refreshCommand, defaultCommand); fplast = &((*fplast)->next); } else if( strcmp(argv[i],"-h")==0 ) diff -Nur bindmon-0.3.orig/src/server.c bindmon-0.3/src/server.c --- bindmon-0.3.orig/src/server.c Sat Jun 26 01:57:14 1999 +++ bindmon-0.3/src/server.c Tue May 8 09:57:43 2001 @@ -43,6 +43,7 @@ { time_t tnow; tnow = time(NULL); + LogMessage(LOG_WARN,"status change - %s:%d (%s)", c->hostAddr, c->portNum, c->conditionTrue? "UP":"DOWN"); } @@ -120,8 +121,9 @@ fp->outputPath); FilePairPrint(fp); err = system(fp->refreshCommand); + LogMessage(LOG_WARN,"restart - returned %d from '%s'", - err,fp->refreshCommand); + err,fp->refreshCommand); } }