Changeset - 7511a4140204
[Not reviewed]
default
0 1 0
ethanzonca - 16 years ago 2009-07-30 15:37:19

conf_replace works nicely, ssh_keygen is disabled due to odd crashing without segfault.
1 file changed with 15 insertions and 9 deletions:
0 comments (0 inline, 0 general)
src/server/slavefuncs.c
Show inline comments
 
@@ -87,14 +87,14 @@ int register_user(char *username, char *
 
      fprintf(stderr, "read \"%s\"\n", buf);
 
    }
 
  execio_close(testrem);
 

	
 
  /* @TODO: Parse the output buffer or something to check when user creation fails due to duplicate users. This is pretty important. */
 

	
 
  ssh_keygen(); // generates distren_rsa
 
  fprintf(stderr, "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAH");
 
  // ssh_keygen(); // generates distren_rsa
 

	
 
  conf_replace(username); // puts the person's username in the conf
 
  /* @TODO: Scan distrenslave.conf for !username and !key and replace them with "keyname" and the "username" */
 
  return 1;
 
}
 

	
 

	
 
@@ -169,43 +169,49 @@ void conf_replace(char *username){
 
	read(); // Read the created file, scanning for and replacing strings, whie
 
	writ(); // writing out to the newly created file
 
	fsync(); // fsync the file we wrote data to
 
	rename(); // rename the old file to the new file
 
*/
 

	
 
	/* Note: SYSCONFDIR doesn't include a trailing slash */
 
  int maxlinelen = 120;
 
  char *fileOrig = SYSCONFDIR "distrenslave.conf";
 
  char *fileRepl = SYSCONFDIR "distrenslave.conf.edited";
 
  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){
 
  if (fp1 ==NULL){
 
	  fprintf(stderr, "%s doesn't exist\n",fileOrig);
 
  }
 
  else if(fp2 ==NULL){
 
	  fprintf(stderr, "Can't write a file to disk! Check permissions.\n");
 
  }
 
  else{
 
    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);
 
      }
 
    rename(fileRepl, fileOrig);
 
  }
 
  else{
 
	  fprintf(stderr, "distrenslave.conf doesn't exist!");
 
  }
 

	
 
  fclose(fp2);
 
  fclose(fp1);
 
  fprintf(stderr,"conf replacements likely worked");
 
  fprintf(stderr,"Wrote conf file...\n");
 
}
 

	
 

	
 
/* Executors */
 

	
 
/*
0 comments (0 inline, 0 general)