Changeset - f621356ea2ca
[Not reviewed]
default
0 3 0
ethanzonca@localhost.localdomain - 16 years ago 2009-11-22 23:13:23
ethanzonca@localhost.localdomain
Removed ssh/registration code
3 files changed with 13 insertions and 211 deletions:
0 comments (0 inline, 0 general)
src/server/distrend.c
Show inline comments
 
@@ -1066,7 +1066,7 @@ int main(int argc, char *argv[])
 

	
 
  /* Argument-parser */
 
  int counter;
 
  int test; // Have some fun if-ness that does fun stuff when this is 1
 
  int test; // Interactive test mode if 1
 

	
 

	
 
  struct distrenjob head;
src/server/slave.c
Show inline comments
 
@@ -19,8 +19,8 @@
 
*/
 

	
 
#include "protocol.h"
 
#include "options.h" /* Confuse, etc. */
 
#include "slavefuncs.h" /* Slave functions */
 
#include "options.h"
 
#include "slavefuncs.h"
 
#include "asprintf.h"
 
#include "remoteio.h"
 

	
 
@@ -35,49 +35,15 @@ int main(int argc, char *argv[])
 

	
 
  int counter;
 

	
 
  /* Parses arguments, skips if there are no args */
 
  /* Parse arguments */
 
  for(counter = 0; counter < argc; counter ++)
 
    if(strcmp(argv[counter], "-h") == 0)
 
      {
 
	fprintf(stderr, "Usage: distrenslave [option] <username> <emailaddr>\nStarts a distren slave\n\t-h\tshow this help\n\t-c\tregisters a user with [username] and [emailaddr] \n");
 
	fprintf(stderr, "Usage: distrenslave [option] \nStarts a distren slave\n\t-h\tshow this help\n"); /* <username> <emailaddr> \t-c\tregisters a user with [username] and [emailaddr] \n */
 
	return 2;
 
      }
 

	
 
  if(argc > 1 && (strcmp("-c", argv[1]) == 0))
 
    {
 
      char *username;
 
      char *email;
 

	
 
      if(argc != 4)
 
	{
 
	  fprintf(stderr, "I need more arguments!\n%d is not enough!\n Invoke 'distrenslave -c <username> <emailaddr> to register. \n Already registered? Edit your distrenslave.conf file!\n'", argc - 1);
 
	  return 234;
 
	}
 

	
 
      username = argv[2];
 
      email = argv[3];
 

	
 
      if(!strchr(email, '@'))
 
	{
 
	  fprintf(stderr, "I want to see an '@' in your email address!\n\"%s\" may be good enough for you, but I need more!\n", email);
 
	  return 235;
 
	}
 
      if( register_user(username, email) == 1)
 
	{
 
	  // register_user generates a key, too */
 
	  curlpost(SYSCONFDIR "/distren.id_rsa", "http://protofusion.org/distren/keys");
 
	  fprintf(stderr, "Registration successful. You may now invoke distrenslave with no arguments.\n");
 
	  return 0;
 
	}
 
      else
 
	{
 
	  fprintf(stderr, "Please try again! :D\n");
 
	  return 0;
 
	}
 
    }
 
  /* End arg parser */
 

	
 
  /* Option getter: Creates vars to grab stuff from conf, uses the options include to grab this data */
 
  /* Get conf data */
 
  char *username;
 
  char *datadir;
 
  cfg_t * my_cfg;
 
@@ -87,27 +53,23 @@ int main(int argc, char *argv[])
 
    CFG_END()
 
  };
 
  struct options_common *commonopts;
 

	
 
  username = NULL;
 
  options_init(argc, argv, &my_cfg, myopts, "slave", &commonopts);
 
  /* End option getter */
 

	
 

	
 
  /* Should _not_ be run every day-ish if the slave is constantly running. */
 
  /* software_updatecheck(datadir); */
 

	
 
  /* Notifies the user if there is no username in the conf file */
 
  /* Notifies the user if there no username in .conf */
 
  if(username == NULL || strcmp(username, "!username") == 0 )
 
    fprintf(stderr, "\nYou didn't register!\nPlease register or edit your config. (see -h)\nIf this error persists, check distrenslave.conf to ensure all items are filled.\n");
 
    fprintf(stderr, "\nYou didn't register!\nPlease register on the DistRen website.\nIf this error persists, check distrenslave.conf to ensure all items are filled.\n");
 
  else 
 
    if( username != NULL || strcmp(username, "!username") != 0 )
 
      {
 
	// Logs ya in:
 
	// Log in the user
 
	if(login_user(username) == 1){
 
	  fprintf(stderr, "You should now be logged into distren.\n");
 
	}
 
	else
 
	  {
 
	    fprintf(stderr, "Login failed. I have no clue why. Sorry.\n");
 
	    fprintf(stderr, "Login failed.\n");
 
	    return 0;
 
	  }
 
      }
src/server/slavefuncs.c
Show inline comments
 
@@ -17,11 +17,6 @@
 
  along with DistRen.  If not, see <http://www.gnu.org/licenses/>.
 
*/
 

	
 
 /*
 
  * Registration on server. Needs attention. Prevent account spamming.
 
  * distrenslave -c username email@example.com
 
 */
 

	
 
#include "protocol.h"
 
#include "asprintf.h"
 
#include "slavefuncs.h"
 
@@ -164,167 +159,12 @@ int curlpost(char *filename, char *url){
 
  return 0;
 
}
 

	
 
/** 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 */
 
  fprintf(stderr,"Preparing to download setup key...\n");
 
  curlget("http://protofusion.org/distren/keys/setup_rsa", SYSCONFDIR "/setup_rsa"); // Grabs key to use for setup login
 

	
 
  /* 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",
 
      "-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);
 
    }
 
  execio_close(testrem);
 

	
 
  /* @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;
 
  }
 
  else{
 
    fprintf(stderr,"Logged in successfully!\n");
 
    return 1;
 
  }
 

	
 
  return 0; // 0 is fai
 
}
 

	
 
/** Logs the user into the server after ensuring that keys exist */
 
int login_user(char *username)
 
{
 
  char *userhost;
 
  userhost = malloc(strlen(username) + strlen("@protofusion.org") + 1);
 
  if(!userhost)
 
    return 43;
 
  strcpy(userhost, username);
 
  strcat(userhost, "@protofusion.org"); // Throws @protofusion.org after the username
 

	
 
  char buf[10];
 
  struct execio *testrem;
 
  char *execargv[] =
 
    {
 
      "ssh",
 
      userhost,// username and hostname
 
      "-i",
 
      SYSCONFDIR "/distren.id_rsa",
 
      "-p",
 
      "23",
 
      "echo",
 
      "hello", // This should eventually open a non-terminating connection to the server for communication,
 

	
 
      (char *)NULL
 
    };
 
  size_t readlen;
 
  fprintf(stderr, "Logging you in to %s\n", userhost);
 
  int status;
 
  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;
 
  }
 
  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");
 
      }
 
    buf[readlen] = '\0';
 
    fprintf(stderr, "read \"%s\"\n", buf);
 
    }
 
  execio_close(testrem);
 
  return 1; // 1 means success
 
  // @TODO: Put some telnet-style auth code here
 
  return 1; // success
 
}
 

	
 
/** Replaces !username with a username in the slave's conf file */
0 comments (0 inline, 0 general)