diff --git a/main.c b/main.c index 91ddc3b..e75e821 100644 --- a/main.c +++ b/main.c @@ -47,6 +47,7 @@ #include #endif +#include "telegram.h" #include "loop.h" #include "mtproto-client.h" #include "interface.h" @@ -59,7 +60,7 @@ #define PROGNAME "telegram-client" #define VERSION "0.01" -#define CONFIG_DIRECTORY ".telegram" +#define CONFIG_DIRECTORY "." PROG_NAME #define CONFIG_FILE "config" #define AUTH_KEY_FILE "auth" #define STATE_FILE "state" @@ -208,7 +209,6 @@ void running_for_first_time (void) { tasprintf (&config_filename, "%s/%s/%s", get_home_directory (), CONFIG_DIRECTORY, CONFIG_FILE); config_filename = make_full_path (config_filename); - static struct stat config_file_stat; int config_file_fd; char *config_directory = get_config_directory (); //char *downloads_directory = get_downloads_directory (); @@ -220,7 +220,7 @@ void running_for_first_time (void) { tfree_str (config_directory); config_directory = NULL; // see if config file is there - if (stat (config_filename, &config_file_stat) != 0) { + if (access (config_filename, R_OK) != 0) { // config file missing, so touch it config_file_fd = open (config_filename, O_CREAT | O_RDWR, 0600); if (config_file_fd == -1) { diff --git a/mtproto-client.c b/mtproto-client.c index 809e009..19c9a9c 100644 --- a/mtproto-client.c +++ b/mtproto-client.c @@ -45,6 +45,7 @@ #include #include +#include "telegram.h" #include "net.h" #include "include.h" #include "queries.h" @@ -126,7 +127,7 @@ int Response_len; * */ -char *rsa_public_key_name = "tg.pub"; +char *rsa_public_key_name; // = "tg.pub"; RSA *pubKey; long long pk_fingerprint; @@ -144,6 +145,10 @@ static int rsa_load_public_key (const char *public_key_name) { return -1; } + if (verbosity) { + logprintf ( "public key '%s' loaded successfully\n", rsa_public_key_name); + } + return 0; } @@ -1807,12 +1812,16 @@ int auth_is_success (void) { void on_start (void) { prng_seed (0, 0); - if (rsa_load_public_key (rsa_public_key_name) < 0) { - perror ("rsa_load_public_key"); - exit (1); - } - if (verbosity) { - logprintf ( "public key '%s' loaded successfully\n", rsa_public_key_name); + if (rsa_public_key_name) { + if (rsa_load_public_key (rsa_public_key_name) < 0) { + perror ("rsa_load_public_key"); + exit (1); + } + } else { + if (rsa_load_public_key ("tg.pub") < 0 && rsa_load_public_key ("/etc/" PROG_NAME "/server.pub") < 0) { + perror ("rsa_load_public_key"); + exit (1); + } } pk_fingerprint = compute_rsa_key_fingerprint (pubKey); } diff --git a/telegram.h b/telegram.h index 41315ce..d72da12 100644 --- a/telegram.h +++ b/telegram.h @@ -18,3 +18,7 @@ */ #define MAX_DC_NUM 9 #define MAX_PEER_NUM 100000 + +#ifndef PROG_NAME +#define PROG_NAME "telegram" +#endif