Changeset - d131e91f8598
[Not reviewed]
default
0 1 0
ethanzonca - 16 years ago 2009-07-30 15:46:53

Commenting
1 file changed with 10 insertions and 8 deletions:
0 comments (0 inline, 0 general)
src/server/slavefuncs.c
Show inline comments
 
@@ -25,12 +25,13 @@
 

	
 
#include <stdio.h>
 
#include <string.h>
 
#include <unistd.h>
 
#include <stdlib.h> /*< malloc(), free() */
 

	
 
/** Generates a SSH key with ssh-keygen */
 
int ssh_keygen(){
 
	// distren.id_rsa and distren.id_rsa.pub are now generated in SYSCONFDIR (etc)
 
	char *command = "ssh-keygen"; // @TODO: append .exe if win32?
 
	char *path_to_command = "/usr/bin/ssh-keygen";
 
	int ret;
 
	char *cmd[] = { command, "-q", "-f", SYSCONFDIR "/distren.id_rsa", "-N", "", (char *)0 }; // TODO: Give me the correct args!
 
@@ -44,12 +45,13 @@ int ssh_keygen(){
 
		fprintf(stderr,"We successfully generated your key! Yay!");
 
		return 1;
 
	}
 
return 0;
 
}
 

	
 
/** Registers the user on the DistRen server */
 
int register_user(char *username, char *email)
 
{
 
  /*
 
   * Logs into sandboxed user on zserver2 and registers a user. Should eventually generate a key on the server and return it to the user.
 
   * All created user accounts should be sandboxed accordingly, requiring a different skel, and the default shell to be rbash. Also,
 
   * a custom path defined in the .bash_profile of the skel is needed.
 
@@ -68,38 +70,38 @@ int register_user(char *username, char *
 
      "-M",
 
      "-c",
 
      email,
 
      "-d",
 
      "/home/distren",
 
      "--gid",
 
      "541", // Add in shellscript to generate ssh key and set keyname
 
      "541",
 
      username,
 
      (char *)NULL
 
    };
 
  size_t readlen;
 
  fprintf(stderr, "Opening stream:\n", execio_open(&testrem, "ssh", execargv));
 
  buf[9] = '\0'; // null-terminating the array...
 
  while(!execio_read(testrem, buf, 9, &readlen)) // What's with the readlen stuff?
 
  while(!execio_read(testrem, buf, 9, &readlen))
 
    {
 
      if(readlen > 9) {
 
	fprintf(stderr, "!!!! Something is terribly wrong!\n");
 
      }
 
      buf[readlen] = '\0'; // Null-terminating the end of it again based on how large the data is?
 
      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. */
 

	
 
  ssh_keygen(); // generates keys for login, @TODO: pub key must somehow be sent to the server.
 

	
 
  conf_replace(username); // puts the person's username in the conf
 
  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;
 
@@ -142,26 +144,25 @@ int login_user(char *username)
 
  if(fopen(userkey, "r") == NULL){
 
	  fprintf(stderr,"Your key, %s, has not been found! Re-register or somehow regenerate your key! We need a way to regenerate keys coded in, but we don't have the facilities yet!",userkey);
 
	  return 0;
 
  }
 
  fprintf(stderr, "Opening stream:\n", execio_open(&testrem, "ssh", execargv));
 
  buf[9] = '\0'; // null-terminating the array...
 
  while(!execio_read(testrem, buf, 9, &readlen)) // What's with the readlen stuff?
 
  while(!execio_read(testrem, buf, 9, &readlen))
 
    {
 
      if(readlen > 9) {
 
	fprintf(stderr, "!!!! Something is terribly wrong!\n");
 
      }
 
    buf[readlen] = '\0'; // Null-terminating the end of it again based on how large the data is?
 
    buf[readlen] = '\0';
 
    fprintf(stderr, "read \"%s\"\n", buf);
 
    }
 
  execio_close(testrem);
 
  return 1; // 1 can be like... error-free login...
 
}
 

	
 
/* Replaces username and key in the slave's conf file */
 

	
 
/** Replaces username and key in the slave's conf file */
 
void conf_replace(char *username){
 
  /* Note: SYSCONFDIR doesn't include a trailing slash */
 
  int maxlinelen = 120;
 
  char *fileOrig = SYSCONFDIR "/distrenslave.conf";
 
  char *fileRepl = SYSCONFDIR "/distrenslave.conf.edited";
 
  char *text2find = "!username";
 
@@ -203,12 +204,13 @@ void conf_replace(char *username){
 
/* Executors */
 

	
 
/*
 
  It seems that the client will need to know the job number. fixme.
 
*/
 

	
 
/** Executor function for Blender operations */
 
void exec_blender(struct blendjob* blendjob, char *input, char *output, int frame)
 
{
 
  char *frame_str;
 
  asprintf(frame,frame_str); // GNU/*nix compatible only, fix before releasing win32, although dll for windows for asprintf exists!
 
  int ret;
 
  char *cmd[] = { "blender", "-b", "-o", output, input, "-f", frame_str, (char *)0 };
0 comments (0 inline, 0 general)