diff -crN ../dnsadmin-0.4-orig/dnsloadzone.c ./dnsloadzone.c
*** ../dnsadmin-0.4-orig/dnsloadzone.c	Wed Aug  1 18:55:26 2001
--- ./dnsloadzone.c	Mon Jan  7 01:28:35 2002
***************
*** 47,52 ****
--- 47,54 ----
  void insert_dns( char type, char *domain_id, char *host, char *val );
  char *make_ip(char *reverse, char *last);
  char *insert_domain( char *domain);
+ char *insert_slave( char *domain, char *masters);
+ char *insert_option( char *bindoption, char *val);
  
  MYSQL mysql_conn;
  MYSQL_RES *res_conn;
***************
*** 57,62 ****
--- 59,65 ----
  char Domain[MAX_BUFF];
  char Reverse[MAX_BUFF];
  char ZoneFile[MAX_BUFF];
+ char MasterServers[MAX_BUFF];
  
  #define MAX_BUFF 200
  char UserName[MAX_BUFF];
***************
*** 85,90 ****
--- 88,95 ----
  {
   FILE *fs;
   char *tmpstr;
+  char opt_tmp[MAX_BUFF+1];
+  char *listen_tmp;
  
      if ( (fs=fopen(ConfFile, "r"))==NULL) {
          printf("could not open named.conf file\n");
***************
*** 95,106 ****
  
          if ( strcmp(tmpstr,"directory") == 0 ) {
              if ( (tmpstr = strtok(NULL,TOKENS)) == NULL ) {
!             printf("error: named.conf has bad directory entry\n");
!             exit(-1);
!                 } 
!         strncpy(ZoneDir, tmpstr, MAX_BUFF);
!     }
! 
          if ( strcmp(tmpstr,"zone") == 0 ) {
              if ( (tmpstr = strtok(NULL,TOKENS)) == NULL ) continue; 
              if (strcmp(tmpstr, ".") == 0 ) continue;
--- 100,205 ----
  
          if ( strcmp(tmpstr,"directory") == 0 ) {
              if ( (tmpstr = strtok(NULL,TOKENS)) == NULL ) {
!             	printf("error: named.conf has bad directory entry\n");
!             	exit(-1);
!             } 
!             strncpy(ZoneDir, tmpstr, MAX_BUFF);
! 	    if ( insert_option( "directory", ZoneDir) == NULL ) {
! 		printf("error inserting option %s (value %s)\n", "directory", ZoneDir);
! 	    } else {
! 		if ( Debug == 1) printf("Inserted directory path %s into db\n",ZoneDir);
! 	    }
! 	}
! 	if ( strcmp(tmpstr,"version") == 0 ) {
! 		strncpy(opt_tmp,tmpstr,MAX_BUFF);
! 		if ( Debug == 1 ) printf("Found option %s\n", opt_tmp);
! 		if ( (tmpstr = strtok(NULL,"\";")) == NULL ) continue;
! 		if ( insert_option( opt_tmp, tmpstr) == NULL ) 
! 			printf("error inserting option %s (value %s)\n", opt_tmp, tmpstr);
! 
! 	}
! 	if ( strcmp(tmpstr,"named-xfer") == 0 ) {
! 		strncpy(opt_tmp,tmpstr,MAX_BUFF);
! 		if ( (tmpstr = strtok(NULL,TOKENS)) == NULL ) continue;
! 		if ( insert_option( opt_tmp, tmpstr) == NULL ) 
! 			printf("error inserting option %s (value %s)\n", opt_tmp, tmpstr);
! 	}
! 	if ( strcmp(tmpstr,"multiple-cnames") == 0 ) {
! 		strncpy(opt_tmp,tmpstr,MAX_BUFF);
! 		if ( (tmpstr = strtok(NULL,TOKENS)) == NULL ) continue;
! 		if ( insert_option( opt_tmp, tmpstr) == NULL ) 
! 			printf("error inserting option %s (value %s)\n", opt_tmp, tmpstr);
! 	}
! 	if ( strcmp(tmpstr,"notify") == 0 ) {
! 		strncpy(opt_tmp,tmpstr,MAX_BUFF);
! 		if ( (tmpstr = strtok(NULL,TOKENS)) == NULL ) continue;
! 		if ( insert_option( opt_tmp, tmpstr) == NULL ) 
! 			printf("error inserting option %s (value %s)\n", opt_tmp, tmpstr);
! 	}
! 	if ( strcmp(tmpstr,"forward") == 0 ) {
! 		strncpy(opt_tmp,tmpstr,MAX_BUFF);
! 		if ( (tmpstr = strtok(NULL,TOKENS)) == NULL ) continue;
! 		if ( insert_option( opt_tmp, tmpstr) == NULL ) 
! 			printf("error inserting option %s (value %s)\n", opt_tmp, tmpstr);
! 	}
! 
! 	/* forwarders, allow-transfer and blackhole all have a
! 	   list of IP's inside curly brackets */
! 	if ( strcmp(tmpstr,"forwarders") == 0 ) {
! 		strncpy(opt_tmp,tmpstr,MAX_BUFF);
! 		if ( (tmpstr = strtok(NULL,"{}")) == NULL ) continue;
! 		if ( insert_option( opt_tmp, tmpstr) == NULL ) 
! 			printf("error inserting option %s (value %s)\n", opt_tmp, tmpstr);
! 	}
! 	if ( strcmp(tmpstr,"allow-transfer") == 0 ) {
! 		strncpy(opt_tmp,tmpstr,MAX_BUFF);
! 		if ( (tmpstr = strtok(NULL,"{}")) == NULL ) continue;
! 		if ( insert_option( opt_tmp, tmpstr) == NULL ) 
! 			printf("error inserting option %s (value %s)\n", opt_tmp, tmpstr);
! 	}
! 	if ( strcmp(tmpstr,"blackhole") == 0 ) {
! 		strncpy(opt_tmp,tmpstr,MAX_BUFF);
! 		if ( (tmpstr = strtok(NULL,"{}")) == NULL ) continue;
! 		if ( insert_option( opt_tmp, tmpstr) == NULL ) 
! 			printf("error inserting option %s (value %s)\n", opt_tmp, tmpstr);
! 	}
! 
! 	/* listen-on has a list of IP's inside curly brackets, as well as an optional port value */
! 
! 	if ( strcmp(tmpstr,"listen-on") == 0 ) {
! 		strncpy(opt_tmp,tmpstr,MAX_BUFF);
! 		listen_tmp=ZoneLine+strlen(ZoneLine)+1;
! 		listen_tmp[strlen(listen_tmp)-1]=0;
! 
! /* Need some sort of checks here */
! 
! 		if ( insert_option( opt_tmp, listen_tmp) == NULL ) 
! 			printf("error inserting option %s (value %s)\n", opt_tmp, listen_tmp);
! 	}
! 	if ( strcmp(tmpstr,"datasize") == 0 ) {
! 		strncpy(opt_tmp,tmpstr,MAX_BUFF);
! 		if ( (tmpstr = strtok(NULL,TOKENS)) == NULL ) continue;
! 		if ( insert_option( opt_tmp, tmpstr) == NULL ) 
! 			printf("error inserting option %s (value %s)\n", opt_tmp, tmpstr);
! 	}
! 	if ( strcmp(tmpstr,"files") == 0 ) {
! 		strncpy(opt_tmp,tmpstr,MAX_BUFF);
! 		if ( (tmpstr = strtok(NULL,TOKENS)) == NULL ) continue;
! 		if ( insert_option( opt_tmp, tmpstr) == NULL ) 
! 			printf("error inserting option %s (value %s)\n", opt_tmp, tmpstr);
! 	}
! 	if ( strcmp(tmpstr,"stacksize") == 0 ) {
! 		strncpy(opt_tmp,tmpstr,MAX_BUFF);
! 		if ( (tmpstr = strtok(NULL,TOKENS)) == NULL ) continue;
! 		if ( insert_option( opt_tmp, tmpstr) == NULL ) 
! 			printf("error inserting option %s (value %s)\n", opt_tmp, tmpstr);
! 	}
! 	if ( strcmp(tmpstr,"cleaning-interval") == 0 ) {
! 		strncpy(opt_tmp,tmpstr,MAX_BUFF);
! 		if ( (tmpstr = strtok(NULL,TOKENS)) == NULL ) continue;
! 		if ( insert_option( opt_tmp, tmpstr) == NULL ) 
! 			printf("error inserting option %s (value %s)\n", opt_tmp, tmpstr);
! 	}
          if ( strcmp(tmpstr,"zone") == 0 ) {
              if ( (tmpstr = strtok(NULL,TOKENS)) == NULL ) continue; 
              if (strcmp(tmpstr, ".") == 0 ) continue;
***************
*** 115,120 ****
--- 214,222 ----
              if ( get_file(fs) == 1 ) {
                  if ( Debug == 1) printf("found file %s\n", ZoneFile);
                  rip_file(ZoneFile,Domain);
+             } else {
+ 		if ( Debug == 1) printf("found slave zone %s using masters %s\n", Domain, MasterServers);
+ 		if ( insert_slave( Domain, MasterServers) == NULL ) printf("found duplicate slave domain %s\n", Domain);
              }
          }
      }
***************
*** 123,140 ****
  int get_file(FILE *fs)
  {
   int found_file = 0;
   char *tmpstr;
  
      while ( fgets(ZoneLine,MAX_BUFF,fs) != NULL ) {
          if ( strncmp(ZoneLine, "};", 2) == 0 ) return(found_file);
  
          if ( (tmpstr = strtok(ZoneLine,TOKENS)) == NULL ) continue; 
          if ( strcmp(tmpstr,"file") == 0 ) {
              if ( (tmpstr = strtok(NULL,TOKENS)) == NULL ) continue; 
!         strncpy(ZoneFile, ZoneDir, MAX_BUFF);
!         strncat(ZoneFile, "/", MAX_BUFF);
              strncat(ZoneFile,tmpstr,MAX_BUFF);
!             found_file = 1;
          }
      }
      return(found_file);
--- 225,253 ----
  int get_file(FILE *fs)
  {
   int found_file = 0;
+  int slave_zone = 0;
   char *tmpstr;
  
      while ( fgets(ZoneLine,MAX_BUFF,fs) != NULL ) {
          if ( strncmp(ZoneLine, "};", 2) == 0 ) return(found_file);
  
          if ( (tmpstr = strtok(ZoneLine,TOKENS)) == NULL ) continue; 
+         if ( strcmp(tmpstr,"type") == 0 ) {
+            if ( (tmpstr = strtok(NULL,TOKENS)) == NULL ) continue;
+            if ( strcmp(tmpstr,"slave") == 0 ) slave_zone = 1;
+         }       
+ 
+        if ( strcmp(tmpstr,"masters") == 0 ) {
+ 	       if ( (tmpstr = strtok(NULL,"{}")) == NULL ) continue;
+ 	       strncpy(MasterServers,tmpstr,MAX_BUFF);
+ 	   }
+ 
          if ( strcmp(tmpstr,"file") == 0 ) {
              if ( (tmpstr = strtok(NULL,TOKENS)) == NULL ) continue; 
!             if ( slave_zone == 0 ) strncpy(ZoneFile, ZoneDir, MAX_BUFF);
!             if ( slave_zone == 0 ) strncat(ZoneFile, "/", MAX_BUFF);
              strncat(ZoneFile,tmpstr,MAX_BUFF);
!             if ( slave_zone == 0 ) found_file = 1;
          }
      }
      return(found_file);
***************
*** 237,242 ****
--- 350,366 ----
          strcpy( FileBuff2, FileBuff);
          if ( (tmpstr1 = strtok(FileBuff,TOKENS)) == NULL ) continue;
  
+         if ( strcmp(tmpstr1,"$TTL") == 0) {
+             if ( (tmpstr2 = strtok(NULL,TOKENS)) == NULL ) {
+                 printf("PARSE ERROR 11 %s\n", FileBuff2);
+                 continue;
+             }			
+             if ( Debug == 1 ) {
+                 printf("T %-20s %-30s\n", domain, tmpstr2 );
+ 	    }
+ 	    insert_dns('T', domain_id, "*",tmpstr2);
+ 	}
+ 
          if ( strcmp(tmpstr1, "NS") == 0 ) {
              if ( (tmpstr2 = strtok(NULL,TOKENS)) == NULL ) {
                  printf("PARSE ERROR 1 %s\n", FileBuff2);
***************
*** 327,333 ****
                      continue;
                      /*printf("found SOA record\n");*/
                  } else if ( strcmp(tmpstr3,"NS") == 0 ) {
!                     printf("found NS record\n");
                  } else if ( strcmp(tmpstr3,"CNAME") == 0 ) {
                      if ((tmpstr4=strtok(NULL,TOKENS))==NULL) {
                          printf("PARSE ERROR 9 %s\n", FileBuff2);
--- 451,462 ----
                      continue;
                      /*printf("found SOA record\n");*/
                  } else if ( strcmp(tmpstr3,"NS") == 0 ) {
! 	                if ( (tmpstr4 = strtok(NULL,TOKENS)) == NULL ) continue;
!         	        if ( Debug == 1 ) {
!                 	    printf("N %-20s %-30s\n",
!                         	domain, fix_hostname(domain,tmpstr4,0) );
!                 	}
! 	                insert_dns('N', domain_id, fix_hostname(domain,tmpstr4,0),"");    
                  } else if ( strcmp(tmpstr3,"CNAME") == 0 ) {
                      if ((tmpstr4=strtok(NULL,TOKENS))==NULL) {
                          printf("PARSE ERROR 9 %s\n", FileBuff2);
***************
*** 466,471 ****
--- 595,632 ----
          }
          res_conn = mysql_store_result(&mysql_conn);
          mysql_free_result(res_conn);
+ 
+         sprintf(SqlBuf, "drop table options");
+         mysql_query(&mysql_conn, SqlBuf);
+         res_conn = mysql_store_result(&mysql_conn);
+         mysql_free_result(res_conn);
+ 
+         sprintf(SqlBuf, "create table options \
+ ( option_id int auto_increment NOT NULL, bindoption varchar(200) not null, \
+ val varchar(200), key (option_id) )");
+ 		if ( mysql_query(&mysql_conn, SqlBuf) ) {
+             printf("dnsloadzone: could not create options table\n");
+             printf("mysql error: %s\n", mysql_error(&mysql_conn));
+             exit(-1);
+         }
+         res_conn = mysql_store_result(&mysql_conn);
+         mysql_free_result(res_conn);
+ 
+         sprintf(SqlBuf, "drop table slaves");
+         mysql_query(&mysql_conn, SqlBuf);
+         res_conn = mysql_store_result(&mysql_conn);
+         mysql_free_result(res_conn);
+ 
+         sprintf(SqlBuf, "create table slaves \
+ ( slave_id int auto_increment NOT NULL, domain varchar(200) NOT NULL, \
+ masters varchar(200), key( slave_id ) )");
+ 		if ( mysql_query(&mysql_conn, SqlBuf) ) {
+             printf("dnsloadzone: could not create slaves table\n");
+             printf("mysql error: %s\n", mysql_error(&mysql_conn));
+             exit(-1);
+         }
+         res_conn = mysql_store_result(&mysql_conn);
+         mysql_free_result(res_conn);
      }
  
  }
***************
*** 575,580 ****
--- 736,843 ----
      }
      mysql_free_result(res_conn);
      return(domain_id);
+ }
+ 
+ char *insert_slave( char *domain, char *masters )
+ {
+  static char slave_id[10];
+  int found;
+ 
+     memset(slave_id,0,10);
+ 
+     sprintf(SqlBuf, "select slave_id from slaves where domain =\"%s\"",
+         domain);
+ 
+     if ( mysql_query(&mysql_conn, SqlBuf)) {
+         printf("error inserting data %s\n", SqlBuf);
+         printf("mysql_error: %s\n", mysql_error(&mysql_conn));
+         return(NULL);
+     }
+     res_conn = mysql_store_result(&mysql_conn);
+     found = 0;
+     if ( mysql_num_rows(res_conn) != 0 ) {
+         found = 1;
+     }
+     mysql_free_result(res_conn);
+     if ( found == 1 ) {
+         return(NULL);
+     }
+ 
+     sprintf(SqlBuf, "insert into slaves ( domain, masters ) \
+ values ( \"%s\",\"%s\" )", domain, masters );
+ 
+     if ( mysql_query(&mysql_conn, SqlBuf)) {
+         printf("error inserting data %s\n", SqlBuf);
+         return(NULL);
+     }
+     res_conn = mysql_store_result(&mysql_conn);
+     mysql_free_result(res_conn);
+ 
+     sprintf(SqlBuf, "select slave_id from slaves where domain=\"%s\"",
+         domain);
+ 
+     if ( mysql_query(&mysql_conn, SqlBuf)) {
+         printf("error inserting data %s\n", SqlBuf);
+         return(NULL);
+     }
+ 
+     res_conn = mysql_store_result(&mysql_conn);
+         while((row_conn = mysql_fetch_row(res_conn))) {
+         strncpy(slave_id, row_conn[0], 10);
+     }
+     mysql_free_result(res_conn);
+     return(slave_id);
+ }
+ 
+ char *insert_option( char *bindoption, char *val )
+ {
+  static char option_id[10];
+  int found;
+ 
+     memset(option_id,0,10);
+ 
+     sprintf(SqlBuf, "select option_id from options where bindoption =\"%s\"",
+         bindoption);
+ 
+     if ( mysql_query(&mysql_conn, SqlBuf)) {
+         printf("error inserting data %s\n", SqlBuf);
+         printf("mysql_error: %s\n", mysql_error(&mysql_conn));
+         return(NULL);
+     }
+     res_conn = mysql_store_result(&mysql_conn);
+     found = 0;
+     if ( mysql_num_rows(res_conn) != 0 ) {
+         found = 1;
+     }
+     mysql_free_result(res_conn);
+     if ( found == 1 ) {
+         return(NULL);
+     }
+ 
+     sprintf(SqlBuf, "insert into options ( bindoption, val ) \
+ values ( \"%s\",\"%s\" )", bindoption, val );
+ 
+     if ( mysql_query(&mysql_conn, SqlBuf)) {
+         printf("error inserting data %s\n", SqlBuf);
+         return(NULL);
+     }
+     res_conn = mysql_store_result(&mysql_conn);
+     mysql_free_result(res_conn);
+ 
+     sprintf(SqlBuf, "select option_id from options where bindoption=\"%s\"",
+         bindoption);
+ 
+     if ( mysql_query(&mysql_conn, SqlBuf)) {
+         printf("error inserting data %s\n", SqlBuf);
+         return(NULL);
+     }
+ 
+     res_conn = mysql_store_result(&mysql_conn);
+         while((row_conn = mysql_fetch_row(res_conn))) {
+         strncpy(option_id, row_conn[0], 10);
+     }
+     mysql_free_result(res_conn);
+     return(option_id);
  }
  
  void usage()
diff -crN ../dnsadmin-0.4-orig/dnszone.c ./dnszone.c
*** ../dnsadmin-0.4-orig/dnszone.c	Mon Jul  9 06:00:54 2001
--- ./dnszone.c	Mon Jan  7 15:33:30 2002
***************
*** 47,52 ****
--- 47,53 ----
  void domain_named_conf(char *domain, char *filename);
  void get_options(int argc,char **argv);
  void usage();
+ void slave_named_conf();
  
  #define MAX_BUFF 200
  char UserName[MAX_BUFF];
***************
*** 77,89 ****
  {
      init_named_conf();
  
      sprintf(SqlBuf, "select domain_id, domain from domains");
      mysql_query(&mysql_conn1, SqlBuf);
      res_conn1 = mysql_use_result(&mysql_conn1);
  
      while((row_conn1=mysql_fetch_row(res_conn1))!=NULL) {
!         
!         printf("%s %s\n", row_conn1[0], row_conn1[1]); 
          get_domain(row_conn1[0], row_conn1[1]);
  
      }
--- 78,96 ----
  {
      init_named_conf();
  
+     /* Add slaves to named.conf first */
+ 
+     slave_named_conf();
+ 
+ 	/* Now add the zones we're authoritative for */
+ 
      sprintf(SqlBuf, "select domain_id, domain from domains");
      mysql_query(&mysql_conn1, SqlBuf);
      res_conn1 = mysql_use_result(&mysql_conn1);
  
      while((row_conn1=mysql_fetch_row(res_conn1))!=NULL) {
! 
!         printf("%s %s\n", row_conn1[0], row_conn1[1]);
          get_domain(row_conn1[0], row_conn1[1]);
  
      }
***************
*** 127,136 ****
      domain_named_conf(domain, file_name);
  
      /* start the zone file */
!     fprintf(fs, "$TTL 1D\n");
  
      /* get the name servers */
!     sprintf(SqlBuf, 
       "select host from records where domain_id =%s and type='N'",
          domain_id);
      mysql_query(&mysql_conn2, SqlBuf);
--- 134,156 ----
      domain_named_conf(domain, file_name);
  
      /* start the zone file */
!     sprintf(SqlBuf,
!      "select val from records where domain_id =%s and type='T'",
!         domain_id);
!     mysql_query(&mysql_conn2, SqlBuf);
!     res_conn2 = mysql_store_result(&mysql_conn2);
! 
!     if ( mysql_num_rows(res_conn2) == 0) {
! 		fprintf(fs, "$TTL 1D\n");
! 	} else {
! 		/* Only use the first entry */
! 		row_conn2 = mysql_fetch_row(res_conn2);
! 		fprintf(fs, "$TTL %s\n",row_conn2[0]);
! 	}
! 	mysql_free_result(res_conn2);
  
      /* get the name servers */
!     sprintf(SqlBuf,
       "select host from records where domain_id =%s and type='N'",
          domain_id);
      mysql_query(&mysql_conn2, SqlBuf);
***************
*** 139,147 ****
      i = 0;
      while((row_conn2=mysql_fetch_row(res_conn2))!=NULL) {
  
!         /* use the first name server in the SOA record */ 
  	if ( i == 0 ) {
!             fprintf(fs, "%s.\tIN\tSOA\t%s\thostmaster.%s. (\n", 
                  domain, fix_hostname(domain,row_conn2[0],1), domain);
              fprintf(fs, "\t\t\t\t%lu\t; serial\n", time(NULL));
              fprintf(fs, "\t\t\t\t1D\t; refresh\n");
--- 159,167 ----
      i = 0;
      while((row_conn2=mysql_fetch_row(res_conn2))!=NULL) {
  
!         /* use the first name server in the SOA record */
  	if ( i == 0 ) {
!             fprintf(fs, "%s.\tIN\tSOA\t%s\thostmaster.%s. (\n",
                  domain, fix_hostname(domain,row_conn2[0],1), domain);
              fprintf(fs, "\t\t\t\t%lu\t; serial\n", time(NULL));
              fprintf(fs, "\t\t\t\t1D\t; refresh\n");
***************
*** 150,169 ****
              fprintf(fs, "\t\t\t\t1D )\t; minimum\n\n");
              ++i;
          }
!         
          fprintf(fs, "\t\tIN\tNS\t%s\n", fix_hostname(domain, row_conn2[0],1));
      }
      mysql_free_result(res_conn2);
  
      /* get the mx records */
!     sprintf(SqlBuf, 
       "select host, val from records where domain_id =%s and type='M'",
          domain_id);
      mysql_query(&mysql_conn2, SqlBuf);
      res_conn2 = mysql_use_result(&mysql_conn2);
      while((row_conn2=mysql_fetch_row(res_conn2))!=NULL) {
!         
!         fprintf(fs, "\t\tIN\tMX %s\t%s\n", 
              row_conn2[1], fix_hostname(domain, row_conn2[0],1));
      }
      mysql_free_result(res_conn2);
--- 170,189 ----
              fprintf(fs, "\t\t\t\t1D )\t; minimum\n\n");
              ++i;
          }
! 
          fprintf(fs, "\t\tIN\tNS\t%s\n", fix_hostname(domain, row_conn2[0],1));
      }
      mysql_free_result(res_conn2);
  
      /* get the mx records */
!     sprintf(SqlBuf,
       "select host, val from records where domain_id =%s and type='M'",
          domain_id);
      mysql_query(&mysql_conn2, SqlBuf);
      res_conn2 = mysql_use_result(&mysql_conn2);
      while((row_conn2=mysql_fetch_row(res_conn2))!=NULL) {
! 
!         fprintf(fs, "\t\tIN\tMX %s\t%s\n",
              row_conn2[1], fix_hostname(domain, row_conn2[0],1));
      }
      mysql_free_result(res_conn2);
***************
*** 171,179 ****
  
  
      /* get the rest of the records */
!     sprintf(SqlBuf, 
       "select host, type, val from records where domain_id =%s and \
! type!='M' and type!='N'",
          domain_id);
      mysql_query(&mysql_conn2, SqlBuf);
      res_conn2 = mysql_use_result(&mysql_conn2);
--- 191,199 ----
  
  
      /* get the rest of the records */
!     sprintf(SqlBuf,
       "select host, type, val from records where domain_id =%s and \
! type!='M' and type!='N' and type!='T'",
          domain_id);
      mysql_query(&mysql_conn2, SqlBuf);
      res_conn2 = mysql_use_result(&mysql_conn2);
***************
*** 186,192 ****
              }
              fprintf(fs, "IN\t");
          }
!         
  
          /* an A record */
          if ( row_conn2[1][0] == 'A' ) {
--- 206,212 ----
              }
              fprintf(fs, "IN\t");
          }
! 
  
          /* an A record */
          if ( row_conn2[1][0] == 'A' ) {
***************
*** 202,209 ****
                  while(*p!='.')++p;
                  ++p;
              }
!                     
!             fprintf(fs, "%s\t\tIN PTR\t%s\n", p, 
                  fix_hostname(domain,row_conn2[0],1));
  
          }
--- 222,229 ----
                  while(*p!='.')++p;
                  ++p;
              }
! 
!             fprintf(fs, "%s\t\tIN PTR\t%s\n", p,
                  fix_hostname(domain,row_conn2[0],1));
  
          }
***************
*** 224,238 ****
          printf("could not open named.conf file\n");
      }
      fprintf(fs_named_conf, "options {\n");
!         fprintf(fs_named_conf, "directory \"/var/named\";\n");
          fprintf(fs_named_conf, "/*     \n");
!         fprintf(fs_named_conf, 
  "* If there is a firewall between you and nameservers you want\n");
!         fprintf(fs_named_conf, 
  "* to talk to, you might need to uncomment the query-source\n");
!         fprintf(fs_named_conf, 
  "* directive below.  Previous versions of BIND always asked\n");
!         fprintf(fs_named_conf, 
  "* questions using port 53, but BIND 8.1 uses an unprivileged\n");
          fprintf(fs_named_conf, "* port by default.\n");
          fprintf(fs_named_conf, "*/\n");
--- 244,274 ----
          printf("could not open named.conf file\n");
      }
      fprintf(fs_named_conf, "options {\n");
! 
!     sprintf(SqlBuf, "select bindoption, val from options");
!     mysql_query(&mysql_conn1, SqlBuf);
!     res_conn1 = mysql_use_result(&mysql_conn1);
! 
!     while((row_conn1=mysql_fetch_row(res_conn1))!=NULL) {
! 
! 		if ( (strcmp(row_conn1[0],"forwarders") == 0) ||
! 		     (strcmp(row_conn1[0],"allow-transfer") == 0) ||
! 		     (strcmp(row_conn1[0],"blackhole") == 0) ) {
! 				fprintf(fs_named_conf,"\t%s {%s};\n",row_conn1[0],row_conn1[1]);
! 		} else if ( strcmp(row_conn1[0],"listen-on") == 0 ) {
! 				fprintf(fs_named_conf,"\t%s %s\n",row_conn1[0],row_conn1[1]);
! 		} else {
! 				fprintf(fs_named_conf, "\t%s \"%s\";\n",row_conn1[0],row_conn1[1]);
! 		}
! 	}
          fprintf(fs_named_conf, "/*     \n");
!         fprintf(fs_named_conf,
  "* If there is a firewall between you and nameservers you want\n");
!         fprintf(fs_named_conf,
  "* to talk to, you might need to uncomment the query-source\n");
!         fprintf(fs_named_conf,
  "* directive below.  Previous versions of BIND always asked\n");
!         fprintf(fs_named_conf,
  "* questions using port 53, but BIND 8.1 uses an unprivileged\n");
          fprintf(fs_named_conf, "* port by default.\n");
          fprintf(fs_named_conf, "*/\n");
***************
*** 269,275 ****
          mkdir(domain_dir, 0777);
      }
  
!     
      fprintf(fs_named_conf, "zone \"%s\" {\n", domain);
      fprintf(fs_named_conf, "\ttype master;\n");
      fprintf(fs_named_conf, "\tnotify yes;\n");
--- 305,311 ----
          mkdir(domain_dir, 0777);
      }
  
! 
      fprintf(fs_named_conf, "zone \"%s\" {\n", domain);
      fprintf(fs_named_conf, "\ttype master;\n");
      fprintf(fs_named_conf, "\tnotify yes;\n");
***************
*** 277,288 ****
      fprintf(fs_named_conf, "};\n\n");
  }
  
  void usage()
  {
      printf("dnszone: -u mysqluser(default root)\n");
      printf("         -p mysqlpass \n");
      printf("         -h mysqlhost(default localhost)\n");
!     printf("         -d database(default localhost)\n");
      printf("         -v (version) \n");
      printf("         -q (debug info)\n");
  
--- 313,363 ----
      fprintf(fs_named_conf, "};\n\n");
  }
  
+ void slave_named_conf()
+ {
+ 
+ static char file_name[156];
+ 
+ sprintf(SqlBuf, "select slave_id, domain, masters from slaves");
+ mysql_query(&mysql_conn1, SqlBuf);
+ res_conn1 = mysql_use_result(&mysql_conn1);
+ 
+     while((row_conn1=mysql_fetch_row(res_conn1))!=NULL) {
+ 
+ 		sprintf(file_name, "%s/named.%s", domain_dir, row_conn1[1]);
+ 
+ 			printf("S%s %s\n", row_conn1[0], row_conn1[1]);
+ 
+ 		++domain_count;
+ 		if ( domain_count == 100 ) {
+ 			domain_count = 0;
+ 			++domain_int_dir1;
+ 			if ( domain_int_dir1 == 50 ) {
+ 				domain_int_dir1 = 0;
+ 				++domain_int_dir2;
+ 			}
+ 			sprintf(domain_dir, "%d", domain_int_dir2);
+ 			mkdir(domain_dir, 0777);
+ 			sprintf(domain_dir, "%d/%d", domain_int_dir2, domain_int_dir1);
+ 			mkdir(domain_dir, 0777);
+ 		}
+ 
+ 
+ 		fprintf(fs_named_conf, "zone \"%s\" {\n", row_conn1[1]);
+ 		fprintf(fs_named_conf, "\ttype slave;\n");
+ 		fprintf(fs_named_conf, "\tfile \"%s\";\n", file_name);
+ 		fprintf(fs_named_conf, "\tmasters {%s};\n", row_conn1[2]);
+ 		fprintf(fs_named_conf, "};\n\n");
+ 
+ 	}
+ }
+ 
  void usage()
  {
      printf("dnszone: -u mysqluser(default root)\n");
      printf("         -p mysqlpass \n");
      printf("         -h mysqlhost(default localhost)\n");
!     printf("         -d database(default dnsadmin)\n");
      printf("         -v (version) \n");
      printf("         -q (debug info)\n");
  
***************
*** 310,316 ****
              case 'u':
                  strncpy( UserName, optarg, MAX_BUFF);
                  break;
!             case 'p': 
                  strncpy( PassWord, optarg, MAX_BUFF);
                  break;
              case 'h':
--- 385,391 ----
              case 'u':
                  strncpy( UserName, optarg, MAX_BUFF);
                  break;
!             case 'p':
                  strncpy( PassWord, optarg, MAX_BUFF);
                  break;
              case 'h':
***************
*** 319,325 ****
              case 'd':
                  strncpy( DataBase, optarg, MAX_BUFF);
                  break;
!             case 'a':
                  Debug = 1;
                  break;
              default:
--- 394,400 ----
              case 'd':
                  strncpy( DataBase, optarg, MAX_BUFF);
                  break;
!             case 'q':
                  Debug = 1;
                  break;
              default:
