Changeset - eee9474aa604
[Not reviewed]
default
0 2 1
ethanzonca - 17 years ago 2009-03-16 21:14:19

Cruddy commit, watch out!
3 files changed with 51 insertions and 32 deletions:
0 comments (0 inline, 0 general)
src/client/distren.c
Show inline comments
 
@@ -23,38 +23,63 @@
 
#include "execio.h"
 
#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[])
 
{
 

	
 

	
 
/* Mneh variable goodness */
 
int isusername;
 
char *host = "protofusion.org";
 
char *username = "guest";
 
char *nameemail;
 
/* */
 

	
 

	
 
// parseconf(); /* calls the confuse parser from options.c */
 
// So I couldn't figure out how to get a function to return multiple variables, so
 
//   I tossed the code from options.c right in here to save me the trouble. Fix if you wish, if possible... :D
 

	
 

	
 

	
 

	
 
/* put some code here to parse for a username, set isusername=0 if no username in the xml file or if no xml file exists. if no file, drop a warning */
 
/* Conf File Parser */
 
    cfg_opt_t opts[] =
 
    {
 
        CFG_STR("username", "guest", CFGF_NONE),
 
        CFG_STR("hostname", "protofusion.org", CFGF_NONE),
 
        CFG_STR("name", "Guest", CFGF_NONE),
 
        CFG_STR("email", "guest@protofusion.org", CFGF_NONE),
 
        CFG_END()
 
     };
 
       cfg_t *cfg;
 
       cfg = cfg_init(opts, CFGF_NONE);
 
       if(cfg_parse(cfg, "distren.conf") == CFG_PARSE_ERROR)
 
    	   return 1;
 
  /* End Conf File Parser */
 

	
 

	
 
if(isusername = 0){
 

	
 

	
 
int x = 1; // hehe for testing
 

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

	
 

	
 
if( x == 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",
 
      host,
 
       username, //cfg_getstr(cfg, "username") . "@" . cfg_getstr(cfg, "hostname"),
 
      "-i guest.rsa", //yeaaaah enay better ideas?
 
      "sh",
 
      "-c",
 
      "\"useradd -M -c",
 
      nameemail,
 
      "-d /home/distren --gid 537",
 
      username,
 
      "\"",
 
      "\"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
 
    };
 

	
 
@@ -77,10 +102,13 @@ char buf[10];
 

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

	
 

	
 
cfg_free(cfg);
 
};
 

	
 

	
src/client/distren.conf
Show inline comments
 
new file 100644
 
hostname = "zserver2"
src/common/options.c
Show inline comments
 
@@ -30,13 +30,13 @@ int execlisten()
 
  return 0;
 
}
 

	
 
int genericfunc()
 
int parseconf()
 
{
 

	
 
  /* Conf File Parser */
 
/* Conf File Parser */
 
    cfg_opt_t opts[] =
 
    {
 
        CFG_STR("test", "mneh", CFGF_NONE),
 
        CFG_STR("username", "guest", CFGF_NONE),
 
        CFG_END()
 
     };
 
       cfg_t *cfg;
 
@@ -45,18 +45,8 @@ int genericfunc()
 
           return 1;
 
/* End Conf File Parser */
 

	
 

	
 
// Testing code:
 
  printf("Client Username: %s\n", cfg_getstr(cfg, "username"));
 
  cfg_free(cfg);
 

	
 
       cfg = cfg_init(opts, CFGF_NONE);
 
       if(cfg_parse(cfg, "distrend.conf") == CFG_PARSE_ERROR)
 
           return 1;
 
/* End Conf File Parser */
 

	
 
       printf("Conf File Test: %s\n", cfg_getstr(cfg, "test"));
 

	
 

	
 
  cfg_free(cfg);
 

	
 
  return 0;
 
}
0 comments (0 inline, 0 general)