diff --git a/mfapi/mfconn.c b/mfapi/mfconn.c index 0322604..37270b4 100644 --- a/mfapi/mfconn.c +++ b/mfapi/mfconn.c @@ -94,8 +94,13 @@ const char *mfconn_create_user_signature(mfconn * conn, if (conn == NULL) return NULL; - signature_raw = strdup_printf("%s%s%d%s", - username, password, app_id, app_key); + if (app_key == NULL) { + signature_raw = strdup_printf("%s%s%d", + username, password, app_id); + } else { + signature_raw = strdup_printf("%s%s%d%s", + username, password, app_id, app_key); + } SHA1((const unsigned char *)signature_raw, strlen(signature_raw), signature_enc); diff --git a/mfshell/main.c b/mfshell/main.c index 8c1abbb..1ec113f 100644 --- a/mfshell/main.c +++ b/mfshell/main.c @@ -21,6 +21,7 @@ #include #include #include +#include #include "../utils/strings.h" #include "mfshell.h" @@ -51,8 +52,12 @@ int main(int argc, char *const argv[]) opts.server = strdup("www.mediafire.com"); } - shell = mfshell_create(35860, "2c6dq0gb2sr8rgsue5a347lzpjnaay46yjazjcjg", + shell = mfshell_create(35860, NULL, opts.server); + if (shell == NULL) { + fprintf(stderr, "cannot create shell\n"); + exit(1); + } // if at least username was set, authenticate automatically if (opts.username != NULL) { diff --git a/mfshell/mfshell.c b/mfshell/mfshell.c index b6d4205..a02ddb6 100644 --- a/mfshell/mfshell.c +++ b/mfshell/mfshell.c @@ -56,8 +56,6 @@ mfshell *mfshell_create(int app_id, char *app_key, char *server) if (app_id <= 0) return NULL; - if (app_key == NULL) - return NULL; if (server == NULL) return NULL; @@ -72,7 +70,11 @@ mfshell *mfshell_create(int app_id, char *app_key, char *server) shell = (mfshell *) calloc(1, sizeof(mfshell)); shell->app_id = app_id; - shell->app_key = strdup(app_key); + if (app_key == NULL) { + shell->app_key = NULL; + } else { + shell->app_key = strdup(app_key); + } shell->server = strdup(server); // object to track folder location @@ -89,6 +91,9 @@ int mfshell_exec(mfshell * shell, int argc, char *const argv[]) { mfcmd *curr_cmd; + if (shell == NULL) + return -1; + for (curr_cmd = shell->commands; curr_cmd->name != NULL; curr_cmd++) { if (strcmp(argv[0], curr_cmd->name) == 0) { return curr_cmd->handler(shell, argc, argv); @@ -222,7 +227,8 @@ void mfshell_run(mfshell * shell) void mfshell_destroy(mfshell * shell) { - free(shell->app_key); + if (shell->app_key != NULL) + free(shell->app_key); free(shell->server); free(shell->local_working_dir); folder_free(shell->folder_curr);