diff --git a/src/server/slavefuncs.c b/src/server/slavefuncs.c --- a/src/server/slavefuncs.c +++ b/src/server/slavefuncs.c @@ -29,18 +29,17 @@ #include #include #include -#include /*< malloc(), free() */ +#include #include #include -/** Converts an integer to a string, thanks to Dom_ (http://www.signalsondisplay.com/) */ +/** Converts an integer to a string, in ANSI C, thanks to Dom_ (http://www.signalsondisplay.com/) */ char *int_to_str(int nbr) { int div; int len; int i; char *res; - res = malloc(4 * sizeof(*res)); // Was xmalloc, hopefully it still works :D i = 0; while (i < 3) @@ -63,11 +62,10 @@ char *int_to_str(int nbr) } return (res); } + /** 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. + /* Checks to see if the keys are already present. */ int status; struct stat buffer; status = stat(SYSCONFDIR "/distren.id_rsa", &buffer); @@ -76,11 +74,10 @@ int ssh_keygen(){ return 0; } -/* start execio code */ + /* 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; @@ -95,7 +92,7 @@ int ssh_keygen(){ fprintf(stderr, "read \"%s\"\n", buf); } execio_close(testrem); -/* end execio code */ + /* end execio code */ // Supposedly execio returns 1 if it has bad args. if(ret == 1){ @@ -112,13 +109,10 @@ return 0; /** Registers the user on the DistRen server */ int register_user(char *username, char *email) { - - // @TODO: Check for problems (e.g. existing rsa key) BEFORE useradding! - + /* @TODO: Check for problems (e.g. existing rsa key) BEFORE useradding! */ /* - * 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. + * a custom path defined in the .bashrc of the skel is needed. */ char buf[10]; struct execio *testrem; @@ -127,7 +121,7 @@ int register_user(char *username, char * "ssh", "distren_setup@protofusion.org", "-i", - SYSCONFDIR "/setup_rsa", // default distributed key, account can only create users. + SYSCONFDIR "/setup_rsa", // @TODO: How will we distribute this key? "-p", "23", "newuser", @@ -143,7 +137,7 @@ int register_user(char *username, char * }; size_t readlen; execio_open(&testrem, "ssh", execargv); // TODO: Grab returns from this someday. - buf[9] = '\0'; // null-terminating the array... + buf[9] = '\0'; while(!execio_read(testrem, buf, 9, &readlen)) { if(readlen > 9) { @@ -168,13 +162,12 @@ int register_user(char *username, char * return 0; } - return 1; + return 1; // 1 is success } -/** Logs the user into the server with a nice ssh session */ +/** Logs the user into the server after ensuring that keys exist */ int login_user(char *username) { - char *userhost; userhost = malloc(strlen(username) + strlen("@protofusion.org") + 1); if(!userhost) @@ -198,9 +191,7 @@ int login_user(char *username) (char *)NULL }; size_t readlen; - fprintf(stderr, "Logging you in to %s\n", userhost); - int status; struct stat buffer; status = stat(SYSCONFDIR "/distren.id_rsa", &buffer); @@ -213,18 +204,17 @@ int login_user(char *username) while(!execio_read(testrem, buf, 9, &readlen)) { if(readlen > 9) { - fprintf(stderr, "!!!! Something is terribly wrong!\n"); + 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... + return 1; // 1 means success } -/** Replaces username and key in the slave's conf file */ +/** Replaces !username with a username in the slave's conf file */ int 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"; @@ -259,11 +249,10 @@ int conf_replace(char *username){ } rename(fileRepl, fileOrig); } - fclose(fp2); fclose(fp1); fprintf(stderr,"Wrote conf file...\n"); -return 1; +return 1; // Success } @@ -276,9 +265,7 @@ return 1; /** Executor function for Blender operations */ void exec_blender(struct blendjob* blendjob, char *input, char *output, int frame) { - - char *frame_str = int_to_str(frame); // 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! - + char *frame_str = int_to_str(frame); // Converts the int frame to a string, so it can be in the cmd array. /* start execio code */ char *command = "blender"; // @TODO: append .exe if win32? int ret;