Files
@ 5132c78ddaf1
Branch filter:
Location: DistRen/src/client/distren.c - annotation
5132c78ddaf1
4.9 KiB
text/plain
merge
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | 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 3b998819751e 3b998819751e d643c8d1d8a8 d643c8d1d8a8 2b98f7dd04fc eee9474aa604 0a8f68f3d17f 32011f71cbbb 627c64f1fd14 627c64f1fd14 627c64f1fd14 2b98f7dd04fc 2b98f7dd04fc 60d3bb17d7d3 2b98f7dd04fc 2b98f7dd04fc 2b98f7dd04fc 60d3bb17d7d3 60d3bb17d7d3 60d3bb17d7d3 2b98f7dd04fc 2b98f7dd04fc 72489034987c 2b98f7dd04fc 2b98f7dd04fc 2b98f7dd04fc 2b98f7dd04fc 2b98f7dd04fc 2b98f7dd04fc 2b98f7dd04fc 2b98f7dd04fc 2b98f7dd04fc 2b98f7dd04fc 2b98f7dd04fc 2b98f7dd04fc 2b98f7dd04fc 2b98f7dd04fc 2b98f7dd04fc 2b98f7dd04fc 2b98f7dd04fc 2b98f7dd04fc 2b98f7dd04fc 2b98f7dd04fc 2b98f7dd04fc 2b98f7dd04fc 2b98f7dd04fc 2b98f7dd04fc 2b98f7dd04fc 2b98f7dd04fc 2b98f7dd04fc 2b98f7dd04fc 2b98f7dd04fc 2b98f7dd04fc 2b98f7dd04fc 2b98f7dd04fc 2b98f7dd04fc 2b98f7dd04fc 2b98f7dd04fc 2b98f7dd04fc 2b98f7dd04fc 2b98f7dd04fc 2b98f7dd04fc 2b98f7dd04fc 2b98f7dd04fc 2b98f7dd04fc ad5012647934 ad5012647934 32011f71cbbb 2b98f7dd04fc 2b98f7dd04fc 815127c2345a 815127c2345a 815127c2345a 815127c2345a 815127c2345a 60d3bb17d7d3 815127c2345a 815127c2345a 815127c2345a 815127c2345a 815127c2345a 60d3bb17d7d3 815127c2345a 815127c2345a 815127c2345a 815127c2345a 815127c2345a 60d3bb17d7d3 3fcf567f92be 815127c2345a 815127c2345a 815127c2345a 815127c2345a 815127c2345a 3fcf567f92be 815127c2345a 60d3bb17d7d3 60d3bb17d7d3 60d3bb17d7d3 2b98f7dd04fc 32011f71cbbb 72489034987c 72489034987c 72489034987c 72489034987c 72489034987c 72489034987c eee9474aa604 44cdeb8081e1 72489034987c 72489034987c 72489034987c 72489034987c 72489034987c 72489034987c 44cdeb8081e1 72489034987c 72489034987c 72489034987c 72489034987c 72489034987c 32011f71cbbb 72489034987c 72489034987c 72489034987c 72489034987c d13d6894ca72 72489034987c 72489034987c 87eeab8a835d 72489034987c 72489034987c 72489034987c 72489034987c 72489034987c 72489034987c 72489034987c 72489034987c d13d6894ca72 44cdeb8081e1 44cdeb8081e1 44cdeb8081e1 7df3f36d8160 e736dd843da3 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 <distren.h>
#include <stdio.h> /* sprintf, printf */
#include <stdlib.h> /* malloc, free */
#include <unistd.h> /* getopt */
#include <confuse.h>
#include <string.h> // for strcat
int main(int argc, char *argv[])
{
char *input;
char *output;
char *jobid;
char curopt;
distren_t distren;
distren_job_t distren_job;
input = NULL;
output = NULL;
while(-1 != (curopt = getopt(argc, argv, "i:o:h")))
{
if(curopt == ':')
{
fprintf(stderr, "-%c: is missing an argument\n", optopt);
return 1;
}
else if(curopt == '?')
{
fprintf(stderr, "-%c: invalid option specified\n", optopt);
return 1;
}
else if(curopt == 'h')
{
fprintf(stderr, "Usage: %s -i <inputfile> -o <outputfile>\n", argv[0]);
fprintf(stderr, "\t-i\tSpecifies the input file\n\
\t-o\tSpecifies the output file\n\
\t-h\tShows this help message\n");
/*
don't return here because options_init will have an overall
options help page
*/
}
else if(curopt == 'i')
/*
TODO: is strdup good or bad? what about
the idea that all libs should allow plugging different
malloc/free implementations in?
*/
input = strdup(optarg);
else if(curopt == 'o')
output = strdup(optarg);
}
/*
give this error after the general arguments parsing so that
the general help from options_init can have effect
*/
if(!input
|| !output)
{
fprintf(stderr, "Input and output files must be specified\n");
return 1;
}
fprintf(stderr, "reading from %s\nwriting to %s\n", input, output);
if(distren_init_mf(&distren, &malloc, &free))
{
fprintf(stderr, "error initializing distren handle\n");
return 1;
}
if(distren_submit_file(distren, &distren_job, input))
{
fprintf(stderr, "error submitting file\n");
return 1;
}
if(distren_job_getid(distren_job, &jobid))
{
fprintf(stderr, "error retrieving job id\n");
return 1;
}
fprintf(stdout, "jobid: %s\n", jobid);
if(distren_job_retrieve_file(distren_job, output))
{
fprintf(stderr, "error retrieving output file\n");
return 1;
}
/* if these following lines fail, it'll be reported as a core dump ;-) */
distren_job_free(distren_job);
distren_free(distren);
// 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);
// SSH's to client machine with the username speficied.
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);
*/
// Can we prune off some of this code up here^? I'm not exactly sure how execio returns output, but it seems like more could be happening in execio itself, and less happening where it is actually called.
// We need some code to ssh, and if the SSH fails, tell the user to register.
// Killed the user reg code, as the php interface will take care of this. Although it should check for users...
return 0;
};
|