Changeset - f9829af53ca6
[Not reviewed]
default
0 1 0
ethanzonca - 16 years ago 2009-10-10 17:26:01

Cleaned up slavefuncs.c formatting
1 file changed with 82 insertions and 81 deletions:
0 comments (0 inline, 0 general)
src/server/slavefuncs.c
Show inline comments
 
@@ -207,44 +207,44 @@ int curlpost(char *filename, char *url){
 

	
 
/** Generates a SSH key with ssh-keygen */
 
int ssh_keygen(){
 
	/* Checks to see if the keys are already present. */
 
	int status;
 
	struct stat buffer;
 
	status = stat(SYSCONFDIR "/distren.id_rsa", &buffer);
 
	if(status != -1){
 
		fprintf(stderr, "***Please delete etc/distren.id_rsa and etc/distren.id_rsa.pub to register.\n");
 
		return 0;
 
	}
 
  /* Checks to see if the keys are already present. */
 
  int status;
 
  struct stat buffer;
 
  status = stat(SYSCONFDIR "/distren.id_rsa", &buffer);
 
  if(status != -1){
 
    fprintf(stderr, "***Please delete etc/distren.id_rsa and etc/distren.id_rsa.pub to register.\n");
 
    return 0;
 
  }
 

	
 
	/* start execio code */
 
	char *command = "ssh-keygen"; // @TODO: append .exe if win32?
 
	int ret;
 
	char *cmd[] = { command, "-q", "-f", SYSCONFDIR "/distren.id_rsa", "-N", "", (char *)NULL }; // TODO: Give me the correct args!
 
	char buf[10];
 
	struct execio *testrem;
 
	size_t readlen;
 
	ret = execio_open(&testrem, command, cmd); // @TODO: This path will be absolute for testing, should be relative to install on production
 
	buf[9] = '\0';
 
	while(!execio_read(testrem, buf, 9, &readlen))
 
	    {
 
	      if(readlen > 9) {
 
		fprintf(stderr, "Something is terribly wrong!\n");
 
	      }
 
	      buf[readlen] = '\0';
 
	      fprintf(stderr, "read \"%s\"\n", buf);
 
	    }
 
	execio_close(testrem);
 
	/* end execio code */
 
  /* start execio code */
 
  char *command = "ssh-keygen"; // @TODO: append .exe if win32?
 
  int ret;
 
  char *cmd[] = { command, "-q", "-f", SYSCONFDIR "/distren.id_rsa", "-N", "", (char *)NULL }; // TODO: Give me the correct args!
 
  char buf[10];
 
  struct execio *testrem;
 
  size_t readlen;
 
  ret = execio_open(&testrem, command, cmd); // @TODO: This path will be absolute for testing, should be relative to install on production
 
  buf[9] = '\0';
 
  while(!execio_read(testrem, buf, 9, &readlen))
 
    {
 
      if(readlen > 9) {
 
        fprintf(stderr, "Something is terribly wrong!\n");
 
      }
 
      buf[readlen] = '\0';
 
      fprintf(stderr, "read \"%s\"\n", buf);
 
    }
 
  execio_close(testrem);
 
  /* end execio code */
 

	
 
	// Supposedly execio returns 1 if it has bad args.
 
	if(ret == 1){
 
		fprintf(stderr, "Generating your key failed. Ensure that ssh-keygen is present!\n"); // Use different executor that searches the path? there is one...
 
		return 0;
 
	}
 
	else{
 
		fprintf(stderr,"We successfully generated your key! Yay!\n");
 
		return 1;
 
	}
 
  // Supposedly execio returns 1 if it has bad args.
 
  if(ret == 1){
 
    fprintf(stderr, "Generating your key failed. Ensure that ssh-keygen is present!\n"); // Use different executor that searches the path? there is one...
 
    return 0;
 
  }
 
  else{
 
    fprintf(stderr,"We successfully generated your key! Yay!\n");
 
    return 1;
 
  }
 
return 0;
 
}
 

	
 
@@ -253,16 +253,17 @@ int register_user(char *username, char *
 
{
 

	
 
/* Note: this code moved here from after the useradd code, so useradd doesn't happen if there is an existing key, etc */
 

	
 
  /* puts the person's username in the conf */
 
  if(conf_replace(username) == 0){
 
	fprintf(stderr, "Failed!\n");
 
	return 0;
 
	}
 
    fprintf(stderr, "Failed!\n");
 
    return 0;
 
  }
 

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

	
 
  /*
 
@@ -292,12 +293,12 @@ int register_user(char *username, char *
 
      (char *)NULL
 
    };
 
  size_t readlen;
 
 ret = execio_open(&testrem, "ssh", execargv); // TODO: Grab returns from this someday.
 
  ret = execio_open(&testrem, "ssh", execargv); // TODO: Grab returns from this someday.
 
  buf[9] = '\0';
 
  while(!execio_read(testrem, buf, 9, &readlen))
 
    {
 
      if(readlen > 9) {
 
	fprintf(stderr, "!!!! Something is terribly wrong!\n");
 
        fprintf(stderr, "!!!! Something is terribly wrong!\n");
 
      }
 
      buf[readlen] = '\0';
 
      fprintf(stderr, "read \"%s\"\n", buf);
 
@@ -306,12 +307,12 @@ int register_user(char *username, char *
 

	
 
  /* @TODO: Parse the output buffer or something to check when user creation fails due to duplicate users. This is pretty important. */
 
  if(ret == 1){
 
          fprintf(stderr, "Unable to log you in. Ensure that ssh is present on your system.\n"); // Use different executor that searches the path? there is one...
 
          return 0;
 
    fprintf(stderr, "Unable to log you in. Ensure that ssh is present on your system.\n"); // Use different executor that searches the path? there is one...
 
    return 0;
 
  }
 
  else{
 
          fprintf(stderr,"Logged in successfully!\n");
 
          return 1;
 
    fprintf(stderr,"Logged in successfully!\n");
 
    return 1;
 
  }
 

	
 
  return 0; // 0 is fai
 
@@ -348,15 +349,15 @@ int login_user(char *username)
 
  struct stat buffer;
 
  status = stat(SYSCONFDIR "/distren.id_rsa", &buffer);
 
  if(status == -1){
 
	  fprintf(stderr,"Your key has not been found! Re-register or somehow regenerate your key!\nWe need a way to regenerate keys coded in, but we don't have the facilities yet!\n");
 
	  return 0;
 
    fprintf(stderr,"Your key has not been found! Re-register or somehow regenerate your key!\nWe need a way to regenerate keys coded in, but we don't have the facilities yet!\n");
 
    return 0;
 
  }
 
  execio_open(&testrem, "ssh", execargv); // TODO: Grab returns from this someday
 
  buf[9] = '\0'; // null-terminating the array...
 
  while(!execio_read(testrem, buf, 9, &readlen))
 
    {
 
      if(readlen > 9) {
 
	fprintf(stderr, "Something is terribly wrong!\n");
 
        fprintf(stderr, "Something is terribly wrong!\n");
 
      }
 
    buf[readlen] = '\0';
 
    fprintf(stderr, "read \"%s\"\n", buf);
 
@@ -379,25 +380,25 @@ int conf_replace(char *username){
 
  fp1 = fopen(fileOrig,"r");
 
  fp2 = fopen(fileRepl,"w");
 
  if (fp1 ==NULL){
 
	  fprintf(stderr, "%s doesn't exist\n",fileOrig);
 
	  return 0;
 
    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;
 
    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);
 
        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);
 
  }
 
@@ -431,27 +432,27 @@ void exec_blender(struct distrenjob* dis
 
  ret = execio_open(&testrem, command, cmd); // This path will be absolute for testing, @TODO: should be relative to install on production
 
  buf[9] = '\0';
 
  while(!execio_read(testrem, buf, 9, &readlen))
 
  	    {
 
  	      if(readlen > 9) {
 
  		fprintf(stderr, "Something is terribly wrong!\n");
 
  	      }
 
  	      buf[readlen] = '\0';
 
  	      fprintf(stderr, "read \"%s\"\n", buf);
 
    {
 
      if(readlen > 9) {
 
        fprintf(stderr, "Something is terribly wrong!\n");
 
       }
 
       buf[readlen] = '\0';
 
       fprintf(stderr, "read \"%s\"\n", buf);
 

	
 
  	      // @TODO: Better location for this code?
 
  	      tell_the_server(DISTREN_REQUEST_PROGRESS);
 
  	      fprintf(stderr, "Rendering...");
 
  	    }
 
  	execio_close(testrem);
 
       // @TODO: Better location for this code?
 
      tell_the_server(DISTREN_REQUEST_PROGRESS);
 
      fprintf(stderr, "Rendering...");
 
    }
 
  execio_close(testrem);
 
  /* end execio code */
 

	
 
  	if(ret == 1){
 
  		fprintf(stderr,"Error starting Blender. Check your install.\n");
 
  	}
 
  	else{
 
  		fprintf(stderr,"Blender at least started nicely, we don't know if it rendered anything though.\n");
 
  	}
 
  	// Consider placing the following in the exec_blender() function
 
  if(ret == 1){
 
    fprintf(stderr,"Error starting Blender. Check your install.\n");
 
  }
 
  else{
 
    fprintf(stderr,"Blender at least started nicely, we don't know if it rendered anything though.\n");
 
  }
 
  // Consider placing the following in the exec_blender() function
 

	
 
}
 

	
0 comments (0 inline, 0 general)