Changeset - 6b9ed6648d87
[Not reviewed]
default
0 1 0
ethanzonca - 16 years ago 2009-07-31 19:39:35

Added ssh_keygen return checks
1 file changed with 8 insertions and 1 deletions:
0 comments (0 inline, 0 general)
src/server/slavefuncs.c
Show inline comments
 
@@ -116,25 +116,29 @@ int register_user(char *username, char *
 
      }
 
      buf[readlen] = '\0';
 
      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. */
 

	
 
  // puts the person's username in the conf
 
  if(conf_replace(username) == 0){
 
	  fprintf(stderr, "Failed!\n");
 
  }
 
  ssh_keygen(); // generates keys for login, @TODO: pub key must somehow be sent to the server.
 

	
 
  // generates keys for login, @TODO: pub key must somehow be sent to the server.
 
  if(ssh_keygen() == 0){
 
	  fprintf(stderr, "Failed!\n");
 
  }
 

	
 
  return 1;
 
}
 

	
 
/** Logs the user into the server with a nice ssh session */
 
int login_user(char *username)
 
{
 
  char *userhost;
 
  char *userkey;
 
  char buf[10];
 
  struct execio *testrem;
 
  char *execargv[] =
 
@@ -198,42 +202,45 @@ void conf_replace(char *username){
 
  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){
 
	  fprintf(stderr, "%s doesn't exist\n",fileOrig);
 
	  return 0;
 
  }
 
  else if(fp2 ==NULL){
 
	  fprintf(stderr, "Can't write a file to disk! Check permissions.\n");
 
	  return 0;
 
  }
 
  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);
 
    return 1;
 
  }
 

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

	
 

	
 
/* Executors */
 

	
 
/*
 
  It seems that the client will need to know the job number. fixme.
0 comments (0 inline, 0 general)