Changeset - 5b8e1f111c7f
[Not reviewed]
default
0 1 0
ethanzonca - 16 years ago 2009-07-30 15:08:21

Conf file replacer (beta)
1 file changed with 32 insertions and 0 deletions:
0 comments (0 inline, 0 general)
src/server/slavefuncs.c
Show inline comments
 
@@ -169,6 +169,38 @@ void conf_replace(char *username){
 
	fsync(); // fsync the file we wrote data to
 
	rename(); // rename the old file to the new file
 
*/
 

	
 
  int maxlinelen = 120;
 
  char *fileOrig = SYSCONFDIR "distrenslave.conf";
 
  char *fileRepl = SYSCONFDIR "distrenslave.conf.edited";
 
  char *text2find = "!username";
 
  char *text2repl = username;
 
  char buffer[maxlinelen+2];
 
  char *buff_ptr, *find_ptr;
 
  FILE *fp1, *fp2;
 
  size_t find_len = strlen(text2find);
 
  fp1 = fopen(fileOrig,"r");
 
  fp2 = fopen(fileRepl,"w");
 
  if (fp1 !=NULL || fp2 !=NULL){
 
    while(fgets(buffer,maxlinelen+2,fp1))
 
      {
 
          buff_ptr = buffer;
 
          while ((find_ptr = strstr(buff_ptr,text2find)))
 
          {
 
          while(buff_ptr < find_ptr)
 
          	fputc((int)*buff_ptr++,fp2);
 
          fputs(text2repl,fp2);
 
          buff_ptr += find_len;
 
          }
 
          fputs(buff_ptr,fp2);
 
      }
 
  }
 
  else{
 
	  fprintf(stderr, "distrenslave.conf doesn't exist!");
 
  }
 
  fclose(fp2);
 
  fclose(fp1);
 
  fprintf(stderr,"conf replacements likely worked")
 
}
 

	
 

	
0 comments (0 inline, 0 general)