Files @ b6386c5628ba
Branch filter:

Location: DistRen/src/client/distren.c - annotation

binki
fixed normal's spelling
7f09dcee58f4
7fcbed937039
7f09dcee58f4
aaedffb71a83
aaedffb71a83
aaedffb71a83
7f09dcee58f4
7f09dcee58f4
7f09dcee58f4
aaedffb71a83
aaedffb71a83
7f09dcee58f4
7f09dcee58f4
7f09dcee58f4
aaedffb71a83
7f09dcee58f4
aaedffb71a83
7f09dcee58f4
7f09dcee58f4
2aa1075cee71
2aa1075cee71
2aa1075cee71
2aa1075cee71
2aa1075cee71
2e10900d91d9
2aa1075cee71
2aa1075cee71
2aa1075cee71
ad5012647934
ad5012647934
ad5012647934
d643c8d1d8a8
d643c8d1d8a8
32011f71cbbb
32011f71cbbb
eee9474aa604
eee9474aa604
32011f71cbbb
627c64f1fd14
627c64f1fd14
627c64f1fd14
ad5012647934
ad5012647934
ad5012647934
ad5012647934
ad5012647934
ad5012647934
f17d2abc8601
f17d2abc8601
f17d2abc8601
f17d2abc8601
ad5012647934
ad5012647934
eee9474aa604
ad5012647934
72489034987c
72489034987c
ad5012647934
ad5012647934
ad5012647934
ad5012647934
ad5012647934
ad5012647934
32011f71cbbb
32011f71cbbb
72489034987c
72489034987c
72489034987c
72489034987c
72489034987c
72489034987c
eee9474aa604
32011f71cbbb
72489034987c
72489034987c
72489034987c
72489034987c
72489034987c
72489034987c
72489034987c
72489034987c
72489034987c
b6386c5628ba
72489034987c
72489034987c
72489034987c
72489034987c
72489034987c
32011f71cbbb
72489034987c
72489034987c
72489034987c
72489034987c
72489034987c
72489034987c
72489034987c
72489034987c
72489034987c
72489034987c
72489034987c
72489034987c
72489034987c
72489034987c
72489034987c
72489034987c
72489034987c
72489034987c
49749aac184e
72489034987c
72489034987c
49749aac184e
d643c8d1d8a8
7df3f36d8160
72489034987c
72489034987c
94aafba083ee
94aafba083ee
94aafba083ee
94aafba083ee
94aafba083ee
94aafba083ee
/*
  Copyright 2008 Nathan Phillip Brink, Ethan Zonca, Matt Orlando

  This file is a part of DistRen.

  DistRen is free software: you can redistribute it and/or modify
  it under the terms of the GNU Affero General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  DistRen is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU Affero General Public License for more details.

  You should have received a copy of the GNU Affero General Public License
  along with DistRen.  If not, see <http://www.gnu.org/licenses/>.
*/


/* Ideas for php-side stuff:
 *
 * PHP adds the users... has captcha and email confirmation wth a pseudo-random number that
 * the user must enter on the site. Apache should be running mod_peruser for safety, and I'm
 * thinking zserver2 for web serving for convenience...
 */


#include "options.h"
#include "execio.h"

#include <stdio.h> /* sprintf, printf */
#include <stdlib.h> /* malloc, free */
#include <libxml/tree.h> /* Happy fun XML time */
#include <libxml/xmlwriter.h>
#include <confuse.h>
#include<string.h> // for strcat


int main(int argc, char *argv[])
{
  struct options_common *options;
  
  cfg_t *cfg;
  
  cfg_opt_t cfg_opts[] =
    {
      CFG_STR_LIST("render_types", NULL, 0),
      CFG_STR("username", NULL, 0),
      CFG_STR("name", NULL, 0),
      CFG_STR("email", NULL, 0),
      CFG_END()
    };

  int i;

  i = 1;
  
  if(options_init(argc, argv, &cfg, cfg_opts, "client", &options))
    {
      fprintf(stderr, "error getting configuration\n");
      return 1;
    }


  // Please find a better way of doing this :( you can't strcat multiple strings.. meh
  // use something like sprintf
  //char *username = cfg_getstr(cfg, "username");
  //char *hostname = cfg_getstr(cfg, "hostname");
  //strcat(username, "@");
  //strcat(username, hostname);


  if( i == 1 ){
    // Create new account on the server if no username exists
    // THIS no longer SEGFAULTS!! YAY
    char buf[10];
    struct execio *testrem;
    char *execargv[] =
      {
	"ssh",
	"username", //cfg_getstr(cfg, "username") . "@" . cfg_getstr(cfg, "hostname"),
	"-i guest.rsa", //yeaaaah any better ideas?
	"sh",
	"-c",
	"\"echo hello from ${HOSTNAME}\"", // "\"useradd -M -c" strcat( cfg_getstr(cfg, "name") cfg_getstr(cfg, "email")) "-d /home/distren --gid 537" cfg_getstr(cfg, "username") "\"",
	(char *)NULL
      };

    size_t readlen;
    fprintf(stderr, "execio madness is occuring!");
    fprintf(stderr, "execio_open returns %d\n", execio_open(&testrem, "ssh", execargv));
    buf[9] = '\0';
    while(!execio_read(testrem, buf, 9, &readlen))
      {
	if(readlen > 9)
	  {
	    fprintf(stderr, "execio_read doesn't set readlen correctly or read() is messed up\n");
	    return 1;
	  }
	buf[readlen] = '\0';
	fprintf(stderr, "read \"%s\"\n", buf);
      }
    execio_close(testrem);
  }

  else
    {
      printf("Well now, you must have registered!\n");
      /* put code here to ssh to zserver2 w/ execio as the user from the conf file */
    }


  options_free(options);
  return 0;
};