Files
@ 3d6275c1cbe8
Branch filter:
Location: DistRen/src/server/slavefuncs.c - annotation
3d6275c1cbe8
8.3 KiB
text/plain
Patching things up...
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 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 | 1f744ce71f83 1f744ce71f83 1f744ce71f83 1f744ce71f83 1f744ce71f83 1f744ce71f83 1f744ce71f83 1f744ce71f83 1f744ce71f83 1f744ce71f83 1f744ce71f83 1f744ce71f83 1f744ce71f83 1f744ce71f83 1f744ce71f83 1f744ce71f83 1f744ce71f83 1f744ce71f83 1f744ce71f83 7407ad359daa 7407ad359daa e1fa88daaa57 7407ad359daa d851e72d74a8 4798596e5c1c d851e72d74a8 32109b7e973a b4fe3a4fca78 8feb0005e773 d851e72d74a8 38944c233d6a 38944c233d6a 32109b7e973a d131e91f8598 8feb0005e773 b8c48b48a032 38944c233d6a 38944c233d6a 38944c233d6a 38944c233d6a 38944c233d6a 38944c233d6a 38944c233d6a 38944c233d6a 38944c233d6a eeea6dcb5927 eeea6dcb5927 eeea6dcb5927 eeea6dcb5927 eeea6dcb5927 eeea6dcb5927 eeea6dcb5927 eeea6dcb5927 3d6275c1cbe8 eeea6dcb5927 eeea6dcb5927 eeea6dcb5927 eeea6dcb5927 eeea6dcb5927 eeea6dcb5927 eeea6dcb5927 eeea6dcb5927 eeea6dcb5927 eeea6dcb5927 eeea6dcb5927 eeea6dcb5927 eeea6dcb5927 eeea6dcb5927 8feb0005e773 8feb0005e773 8feb0005e773 8feb0005e773 8feb0005e773 8feb0005e773 8feb0005e773 8feb0005e773 28e718d82e23 28e718d82e23 d131e91f8598 5b11cfeabe1c a46f1313e103 7407ad359daa 7407ad359daa 7407ad359daa 7407ad359daa a46f1313e103 1f744ce71f83 1f744ce71f83 1f744ce71f83 1f744ce71f83 a46f1313e103 a46f1313e103 a46f1313e103 f0035ee94e64 a46f1313e103 a46f1313e103 fa2868e02737 a46f1313e103 a46f1313e103 a46f1313e103 a46f1313e103 a46f1313e103 a46f1313e103 d131e91f8598 a46f1313e103 a46f1313e103 a46f1313e103 1f744ce71f83 1f744ce71f83 1f744ce71f83 d131e91f8598 1f744ce71f83 1f744ce71f83 1f744ce71f83 1f744ce71f83 d131e91f8598 a46f1313e103 1f744ce71f83 1f744ce71f83 4e24c5b3210e f6d15092135b 4e24c5b3210e 959990cde96a 959990cde96a 81246e11146e 7511a4140204 5b11cfeabe1c 1f744ce71f83 1f744ce71f83 d131e91f8598 d851e72d74a8 d851e72d74a8 d851e72d74a8 d851e72d74a8 d851e72d74a8 d851e72d74a8 d851e72d74a8 d851e72d74a8 d851e72d74a8 2c7d4da48d01 d851e72d74a8 d851e72d74a8 d851e72d74a8 d851e72d74a8 d851e72d74a8 d851e72d74a8 d851e72d74a8 2c7d4da48d01 d851e72d74a8 d851e72d74a8 d851e72d74a8 d851e72d74a8 d851e72d74a8 d851e72d74a8 d851e72d74a8 d851e72d74a8 2c7d4da48d01 d851e72d74a8 4e24c5b3210e d851e72d74a8 d851e72d74a8 d851e72d74a8 d851e72d74a8 d851e72d74a8 d851e72d74a8 d851e72d74a8 2c7d4da48d01 d851e72d74a8 4e24c5b3210e 2c7d4da48d01 2c7d4da48d01 d851e72d74a8 4e24c5b3210e 4e24c5b3210e 5b11cfeabe1c 4e24c5b3210e 1f744ce71f83 1f744ce71f83 d131e91f8598 1f744ce71f83 1f744ce71f83 1f744ce71f83 1f744ce71f83 d131e91f8598 1f744ce71f83 1f744ce71f83 1f744ce71f83 5b11cfeabe1c 1f744ce71f83 1f744ce71f83 d131e91f8598 bbaf7619b582 263aef22faac 5b8e1f111c7f 7511a4140204 7511a4140204 5b8e1f111c7f 5b8e1f111c7f 5b8e1f111c7f 5b8e1f111c7f 5b8e1f111c7f 5b8e1f111c7f 5b8e1f111c7f 5b8e1f111c7f 7511a4140204 7511a4140204 7511a4140204 7511a4140204 7511a4140204 7511a4140204 7511a4140204 5b8e1f111c7f 5b8e1f111c7f 5b8e1f111c7f 5b8e1f111c7f 5b8e1f111c7f 5b8e1f111c7f 5b8e1f111c7f 5b8e1f111c7f 5b8e1f111c7f 5b8e1f111c7f 5b8e1f111c7f 5b8e1f111c7f 7511a4140204 5b8e1f111c7f 7511a4140204 5b8e1f111c7f 5b8e1f111c7f 7511a4140204 9b1f363559ec 0deae41fe011 1f744ce71f83 83b5a81f8c76 1f744ce71f83 1f744ce71f83 0deae41fe011 1f744ce71f83 b4fe3a4fca78 d131e91f8598 1f744ce71f83 1f744ce71f83 1f744ce71f83 00132229c637 00132229c637 f85c9eea7e63 00132229c637 00132229c637 3d6275c1cbe8 00132229c637 3d6275c1cbe8 00132229c637 00132229c637 00132229c637 00132229c637 3d6275c1cbe8 00132229c637 00132229c637 00132229c637 00132229c637 00132229c637 00132229c637 00132229c637 00132229c637 00132229c637 00132229c637 00132229c637 3d6275c1cbe8 3d6275c1cbe8 3d6275c1cbe8 3d6275c1cbe8 3d6275c1cbe8 3d6275c1cbe8 1f744ce71f83 | /*
Copyright 2009 Nathan Phillip Brink, Ethan Zonca, Matthew 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/>.
*/
/*
* Registration on server. Needs attention. Prevent account spamming.
* distrenslave -c username email@example.com
*/
#include "blendjob.h"
#include "execio.h"
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h> /*< malloc(), free() */
#include <sys/stat.h>
#include <fcntl.h>
/** Generates a SSH key with ssh-keygen */
int ssh_keygen(){
// distren.id_rsa and distren.id_rsa.pub are now generated in SYSCONFDIR (etc)
// Checks to see if the keys are already present.
int status;
struct stat buffer;
status = stat(SYSCONFDIR "/distren.id_rsa", &buffer);
if(status == -1){
fprintf(stderr, "Please delete etc/distren.id_rsa and etc/distren.id_rsa.pub to register.");
}
/* start execio code */
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...
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);
/* end execio code */
// Supposedly execio returns 1 if it has bad args.
if(ret == 1){
fprintf(stderr, "Generating your key failed. Ensure that ssh-keygen is present!\n"); // Use different executor that searches the path? there is one...
return 0;
}
else{
fprintf(stderr,"We successfully generated your key! Yay!");
return 1;
}
return 0;
}
/** Registers the user on the DistRen server */
int register_user(char *username, char *email)
{
/*
* Logs into sandboxed user on zserver2 and registers a user. Should eventually generate a key on the server and return it to the user.
* 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 .bash_profile of the skel is needed.
*/
char buf[10];
struct execio *testrem;
char *execargv[] =
{
"ssh",
"distren_setup@protofusion.org",
"-i",
SYSCONFDIR "/setup_rsa", // default distributed key, account can only create users.
"-p",
"23",
"newuser",
"-M",
"-c",
email,
"-d",
"/home/distren",
"--gid",
"541",
username,
(char *)NULL
};
size_t readlen;
fprintf(stderr, "Opening stream:\n", execio_open(&testrem, "ssh", execargv));
buf[9] = '\0'; // null-terminating the array...
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. */
conf_replace(username); // puts the person's username in the conf
ssh_keygen(); // generates keys for login, @TODO: pub key must somehow be sent to the server.
return 1;
}
/** Logs the user into the server with a nice ssh session */
int login_user(char *username)
{
char *userhost;
char *userkey;
char buf[10];
struct execio *testrem;
char *execargv[] =
{
"ssh",
"-i",
(char *)NULL, // Key created from registeruser()
"-p",
"23",
(char *)NULL,// username and hostname
"echo",
"hello", // This should eventually open a non-terminating connection to the server for communication,
(char *)NULL
};
size_t readlen;
/*< @TODO remove being tied to protofusion.org for no reason */
userhost = malloc(strlen(username) + strlen("@protofusion.org") + 1);
if(!userhost)
return 43;
strcpy(userhost, username);
strcat(userhost, "@protofusion.org"); // Throws @protofusion.org after the username
userkey = malloc(strlen(username) + strlen(".rsa") + 1);
if(!userkey)
{
free(userhost);
return 44;
}
strcpy(userkey, username);
strcat(userkey,".rsa");
fprintf(stderr, "Logging you in to %s using key %s\n", userhost, userkey);
if(fopen(userkey, "r") == NULL){
fprintf(stderr,"Your key, %s, has not been found! Re-register or somehow regenerate your key! We need a way to regenerate keys coded in, but we don't have the facilities yet!",userkey);
return 0;
}
fprintf(stderr, "Opening stream:\n", execio_open(&testrem, "ssh", execargv));
buf[9] = '\0'; // null-terminating the array...
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);
return 1; // 1 can be like... error-free login...
}
/** Replaces username and key in the slave's conf file */
void conf_replace(char *username){
/* Note: SYSCONFDIR doesn't include a trailing slash */
int maxlinelen = 120;
char *fileOrig = SYSCONFDIR "/distrenslave.conf";
char *fileRepl = SYSCONFDIR "/distrenslave.conf.edited";
char *text2find = "!username";
char *text2repl = username;
char buffer[maxlinelen+2];
char *buff_ptr, *find_ptr;
FILE *fp1, *fp2;
size_t find_len = strlen(text2find);
fp1 = fopen(fileOrig,"r");
fp2 = fopen(fileRepl,"w");
if (fp1 ==NULL){
fprintf(stderr, "%s doesn't exist\n",fileOrig);
}
else if(fp2 ==NULL){
fprintf(stderr, "Can't write a file to disk! Check permissions.\n");
}
else{
while(fgets(buffer,maxlinelen+2,fp1))
{
buff_ptr = buffer;
while ((find_ptr = strstr(buff_ptr,text2find)))
{
while(buff_ptr < find_ptr)
fputc((int)*buff_ptr++,fp2);
fputs(text2repl,fp2);
buff_ptr += find_len;
}
fputs(buff_ptr,fp2);
}
rename(fileRepl, fileOrig);
}
fclose(fp2);
fclose(fp1);
fprintf(stderr,"Wrote conf file...\n");
}
/* Executors */
/*
It seems that the client will need to know the job number. fixme.
*/
/** Executor function for Blender operations */
void exec_blender(struct blendjob* blendjob, char *input, char *output, int frame)
{
char *frame_str;
asprintf(frame,frame_str); // Converts the int frame to a string, so it can be in the cmd array. GNU/*nix compatible only, fix before releasing win32, although dll for windows for asprintf exists!
ret = execv("/usr/bin/blender", cmd); // This path will be absolute for testing, should be relative to install on production
/* start execio code */
char *command = "blender"; // @TODO: append .exe if win32?
int ret;
char *cmd[] = { command, "-b", "-o", output, input, "-f", frame_str, (char *)NULL };
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...
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);
/* end execio code */
if(ret == 1){
fprintf(stderr,"Error starting Blender. Check your install.");
}
else{
fprintf(stderr,"Blender at least started nicely, who knows if it rendered anything though.");
}
}
|