Changeset - df9be21fe006
[Not reviewed]
default
0 1 0
ethanzonca@localhost.localdomain - 16 years ago 2009-07-01 13:27:34
ethanzonca@localhost.localdomain
Please read some of these notes. The whole ssh thing will get interesting.
1 file changed with 72 insertions and 24 deletions:
0 comments (0 inline, 0 general)
src/server/distrend.c
Show inline comments
 
@@ -64,33 +64,84 @@ struct {
 
int main(int argc, char *argv[])
 
{
 

	
 
/* !!!!!!! Important notes !!!!!!!!!!!!
 

	
 
So, we need a common key. Maybe. Or we need to generate a key in registeruser() and get it to the client somehow.
 
If we use a common key, then we'll need different passphrases for each user, which would be kinda crazy. How can
 
we get a key generated on the server, and transferred to the client's distrend?
 

	
 
*/
 

	
 

	
 
// We need the conf parser code from options.c here!!!
 
char *username = "unregistered"; // get this from conf
 

	
 

	
 

	
 
// Checks if the conf is left at the default username
 
int registered;
 
if(username == "unregistered") {
 
  fprintf(stderr,"\nYou have not set your username in distrend.conf!\nIf you need to register a username, run distrend -c username email@example.com\n\n");
 
  registered = 0;
 
}
 
else{
 
  fprintf(stderr,"Logging into the DistRen server...\n");
 
}
 

	
 

	
 

	
 

	
 
// Registered checker, needs input from conf file to see if the default username exists
 
char *username = "unregistered"; // get this from conf
 
int registered;
 
if(username == "unregistered") {
 
  fprintf(stderr,"You have not set your username in distrend.conf!\nIf you need to register a username, run distrend --createuser=username"); // This is what it should maybe be like lol...
 
  registered = 0;
 
// Registration on server. Needs attention. (e.g., people could make tons of accounts with the key we give them...
 
// Set up distrend -c username email@example.com
 
// We must prevent multi-user-creation abuse, too.
 
void registeruser(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. They also
 
  // need a custom path, which can be defined in the .bash_profile of the skel. All activity of server-side configuration should be documented
 
  // to ease the creation of new distren servers, or it should be automated and made much more all-inclusive, not requiring much config.
 
  char buf[10];
 
  struct execio *testrem;
 
  char *execargv[] =
 
    {
 
  "ssh",
 
  "distren_setup@protofusion.org",
 
  "-i",
 
  "setup.rsa", // We gotta figure out how we're going to do the whole keys thing... maybe grab this key via http? But have a secret password compiled in distren to prevent fraud?
 
  "-p",
 
  "23",
 
  "sudo /usr/sbin/useradd",
 
  "-M",
 
  "-c",
 
  email,
 
  "-d",
 
  "/home/distren",
 
  "--gid",
 
  "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?
 
    {
 
      if(readlen > 9) {
 
	fprintf(stderr, "!!!! Something is terribly wrong!\n");
 
      }
 
      if(buf == 0) {
 
	fprintf(stderr, "**** Operation successful, or so we hope. We got no output. Just kidding. You will never see this. Something else should catch this though! And registration should really have some sort of password.");
 
      }
 
    buf[readlen] = '\0'; // Null-terminating the end of it again based on how large the data is?
 
    fprintf(stderr, "read \"%s\"\n", buf);
 
    }
 
  execio_close(testrem);
 
}
 

	
 

	
 

	
 

	
 

	
 
// Registration on server. Needs attention. (e.g., people could make tons of accounts with the key we give them...
 
// This should really not be an interactive process... after contemplation, a user should run distrend --createuser=username which does this, or something. But we must prevent multi-user-creation abuse, too.
 
if(registered==0) {
 
char newusername[100];
 

	
 
  fprintf(stderr, "**** Please enter your desired username: ");
 
  fgets(newusername,100,stdin);
 
  fprintf(stderr, "\n**** Checking availibility of username: %s\n",newusername);
 
  // Mostly kinda copied from old code, but I understand it a tad better now :)
 
void loginuser(char *username, int secret){
 
  // Logs into sandboxed user on zserver2 and registers a user
 
  char buf[10];
 
  struct execio *testrem;
 
@@ -99,18 +150,18 @@ char newusername[100];
 
  "ssh",
 
  "distren_setup@protofusion.org",
 
  "-i",
 
  "setup.rsa",
 
  "setup.rsa", // We gotta figure out how we're going to do the whole keys thing... maybe grab this key via http? But have a secret password compiled in distren to prevent fraud?
 
  "-p",
 
  "23",
 
  "sudo /usr/sbin/useradd",
 
  "-M",
 
  "-c",
 
  "email",
 
  email,
 
  "-d",
 
  "/home/distren",
 
  "--gid",
 
  "541",
 
  newusername,
 
  username,
 
  (char *)NULL
 
  };
 
  size_t readlen;
 
@@ -119,19 +170,15 @@ char newusername[100];
 
  while(!execio_read(testrem, buf, 9, &readlen)) // What's with the readlen stuff?
 
    {
 
      if(readlen > 9) {
 
	fprintf(stderr, "**** Something is terribly wrong!\n");
 
	fprintf(stderr, "!!!! Something is terribly wrong!\n");
 
      }
 
      if(buf == 0) {
 
	fprintf(stderr, "**** Operation successful, or so we hope. We got no output.");
 
	fprintf(stderr, "**** Operation successful, or so we hope. We got no output. Just kidding. You will never see this. Something else should catch this though!");
 
      }
 
    buf[readlen] = '\0'; // Null-terminating the end of it again based on how large the data is?
 
    fprintf(stderr, "read \"%s\"\n", buf);
 
    }
 
  execio_close(testrem);
 
  
 
 }
 
else{
 
  // Login with credentials
 
}
 

	
 

	
 
@@ -141,6 +188,7 @@ else{
 

	
 

	
 

	
 

	
 
/*
 
 frame[frame] Assignments:
 
  "0" - cancelled
0 comments (0 inline, 0 general)