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 1 insertions and 0 deletions:
0 comments (0 inline, 0 general)
src/server/slavefuncs.c
Show inline comments
 
@@ -208,96 +208,97 @@ 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;
 
	}
 

	
 
	/* 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;
 
	}
 
return 0;
 
}
 

	
 
/** Registers the user on the DistRen server */
 
int register_user(char *username, char *email)
 
{
 

	
 
/* 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;
 
	}
 

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

	
 
  /*
 
   * 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 .bashrc of the skel is needed.
 
   */
 
  int ret;
 
  char buf[10];
 
  struct execio *testrem;
 
  char *execargv[] =
 
    {
 
      "ssh",
 
      "distren_setup@protofusion.org",
 
      "-i",
 
      SYSCONFDIR "/setup_rsa", // @TODO: How will we distribute this key?
 
      "-p",
 
      "23",
 
      "newuser",
 
      "-M",
 
      "-c",
 
      email,
 
      "-d",
 
      "/home/distren",
 
      "--gid",
 
      "541",
 
      username,
 
      (char *)NULL
 
    };
 
  size_t readlen;
 
 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");
 
      }
 
      buf[readlen] = '\0';
 
      fprintf(stderr, "read \"%s\"\n", buf);
0 comments (0 inline, 0 general)