/* 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 . */ #include /* sprintf, printf */ #include /* malloc, free */ #include "options.h" #include "execio.h" #include /* Happy fun XML time */ #include #include #include // for strcat int main(int argc, char *argv[]) { // 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 /* 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 */ int x = 1; // hehe for testing // 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", username, //cfg_getstr(cfg, "username") . "@" . cfg_getstr(cfg, "hostname"), "-i guest.rsa", //yeaaaah enay 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); } return 0; } 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 */ return 0; } cfg_free(cfg); };