Changeset - 2cc251e83bbb
[Not reviewed]
default
0 1 0
ethanzonca - 16 years ago 2009-09-03 22:20:20

Minor edits, added execio return checking to the login function
1 file changed with 20 insertions and 6 deletions:
0 comments (0 inline, 0 general)
src/server/slavefuncs.c
Show inline comments
 
@@ -60,12 +60,17 @@ xmlNodePtr xml_quickxpath(xmlXPathContex
 
  xmlXPathFreeObject(xmlxpathobjptr);
 

	
 
  return toreturn;
 
}
 

	
 

	
 
/** Stub for deleting job data from the disk. @TODO: unstubify me! */
 
int delete_jobdata(int jobnum){
 
  return 0;
 
}
 

	
 
/** Stub stub stubbiness ugh @TODO: Kill me. */
 
void tell_the_server(char *stuff){
 
}
 

	
 
/** Function referenced by curlget() to write data to disk. */
 
size_t curl_writetodisk(void *ptr, size_t size, size_t nmemb, FILE *stream)
 
@@ -91,13 +96,13 @@ int curlget(char *url, char *out){
 
  }
 
  return res; // 0 means OK, nonzero means AAAH badness
 
}
 

	
 
/** Posts a file to a url with cUrl */
 
int curlpost(char *filename, char *url){
 
  char *targetname = "uploadedfile"; // Name of the target in the php file
 
  char *targetname = "uploadedfile"; // Name of the target in the php file on the server (Don't change me unless you have different PHP code)
 
  CURL *curl;
 
  CURLcode res;
 
  struct curl_httppost *formpost=NULL;
 
  struct curl_httppost *lastptr=NULL;
 
  struct curl_slist *headerlist=NULL;
 
  static const char buf[] = "Expect:";
 
@@ -113,13 +118,13 @@ int curlpost(char *filename, char *url){
 
  /* filename field... */
 
  curl_formadd(&formpost,
 
               &lastptr,
 
               CURLFORM_COPYNAME, "filename",
 
               CURLFORM_COPYCONTENTS, filename,
 
               CURLFORM_END);
 
  /* submit field, not usually needed, just in case */
 
  /* submit field, not usually needed, just in case... */
 
  curl_formadd(&formpost,
 
               &lastptr,
 
               CURLFORM_COPYNAME, "submit",
 
               CURLFORM_COPYCONTENTS, "send",
 
               CURLFORM_END);
 

	
 
@@ -154,14 +159,14 @@ int ssh_keygen(){
 
	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); // This path will be absolute for testing, should be relative to install on production
 
	buf[9] = '\0'; // null-terminating the array...
 
	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';
 
@@ -200,12 +205,13 @@ int register_user(char *username, char *
 
  }
 

	
 
  /*
 
   * 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",
 
@@ -222,27 +228,35 @@ int register_user(char *username, char *
 
      "--gid",
 
      "541",
 
      username,
 
      (char *)NULL
 
    };
 
  size_t readlen;
 
  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");
 
      }
 
      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 1; // 1 is success
 
  return 0; // 0 is fai
 
}
 

	
 
/** Logs the user into the server after ensuring that keys exist */
 
int login_user(char *username)
 
{
 
  char *userhost;
0 comments (0 inline, 0 general)