static void import_auth_file (struct tgl_state* TLS) { int auth_file_fd = open (AUTH_FILE_PATH, O_CREAT | O_RDWR, 0600); if (auth_file_fd < 0) { empty_auth_file (TLS); return; } assert (auth_file_fd >= 0); unsigned x; unsigned m; if (read (auth_file_fd, &m, 4) < 4 || (m != DC_SERIALIZED_MAGIC)) { close (auth_file_fd); empty_auth_file (TLS); return; } assert (read (auth_file_fd, &x, 4) == 4); assert (x > 0); int dc_working_num; assert (read (auth_file_fd, &dc_working_num, 4) == 4); int i; for (i = 0; i <= (int)x; i++) { int y; assert (read (auth_file_fd, &y, 4) == 4); if (y) { read_dc (TLS, auth_file_fd, i, m); } } bl_do_set_working_dc (TLS, dc_working_num); int our_id; int l = read (auth_file_fd, &our_id, 4); if (l < 4) { assert (!l); } if (our_id) { bl_do_set_our_id (TLS, our_id); } close (auth_file_fd); }
void read_auth_file(struct tgl_state *TLS) { CMStringA name(FORMAT, "%sauth", TLS->base_path); int auth_file_fd = open(name, O_CREAT | O_RDWR | O_BINARY, 0600); if (auth_file_fd < 0) { empty_auth_file(TLS); return; } assert(auth_file_fd >= 0); unsigned x; unsigned m; if (read(auth_file_fd, &m, 4) < 4 || (m != DC_SERIALIZED_MAGIC)) { close(auth_file_fd); empty_auth_file(TLS); return; } assert(read(auth_file_fd, &x, 4) == 4); assert(x > 0); int dc_working_num; assert(read(auth_file_fd, &dc_working_num, 4) == 4); int i; for (i = 0; i <= (int)x; i++) { int y; assert(read(auth_file_fd, &y, 4) == 4); if (y) { read_dc(TLS, auth_file_fd, i, m); } } bl_do_set_working_dc(TLS, dc_working_num); int our_id; int l = read(auth_file_fd, &our_id, 4); if (l < 4) { assert(!l); } if (our_id) { bl_do_set_our_id(TLS, our_id); } close(auth_file_fd); TLS->callback.logprintf("read auth file: dcs=%d dc_working_num=%d our_id=%d", x, dc_working_num, our_id); }
void read_auth_file (void) { if (binlog_enabled) { return; } int auth_file_fd = open (get_auth_key_filename (), O_CREAT | O_RDWR, 0600); if (auth_file_fd < 0) { empty_auth_file (); } assert (auth_file_fd >= 0); unsigned x; unsigned m; if (read (auth_file_fd, &m, 4) < 4 || (m != DC_SERIALIZED_MAGIC && m != DC_SERIALIZED_MAGIC_V2)) { close (auth_file_fd); empty_auth_file (); return; } assert (read (auth_file_fd, &x, 4) == 4); assert (x <= MAX_DC_ID); assert (read (auth_file_fd, &dc_working_num, 4) == 4); assert (read (auth_file_fd, &auth_state, 4) == 4); if (m == DC_SERIALIZED_MAGIC) { auth_state = 700; } int i; for (i = 0; i <= (int)x; i++) { int y; assert (read (auth_file_fd, &y, 4) == 4); if (y) { read_dc (auth_file_fd, i, m); } } int l = read (auth_file_fd, &our_id, 4); if (l < 4) { assert (!l); } close (auth_file_fd); DC_working = DC_list[dc_working_num]; if (m == DC_SERIALIZED_MAGIC) { DC_working->has_auth = 1; } }
void read_auth_file (void) { if (binlog_enabled) { return; } int auth_file_fd = open (get_auth_key_filename (), O_CREAT | O_RDWR, 0600); if (auth_file_fd < 0) { empty_auth_file (); return; } assert (auth_file_fd >= 0); unsigned x; unsigned m; if (read (auth_file_fd, &m, 4) < 4 || (m != DC_SERIALIZED_MAGIC)) { close (auth_file_fd); empty_auth_file (); return; } assert (read (auth_file_fd, &x, 4) == 4); assert (x > 0); int dc_working_num; assert (read (auth_file_fd, &dc_working_num, 4) == 4); int i; for (i = 0; i <= (int)x; i++) { int y; assert (read (auth_file_fd, &y, 4) == 4); if (y) { read_dc (auth_file_fd, i, m); } } bl_do_set_working_dc (TLS, dc_working_num); int our_id; int l = read (auth_file_fd, &our_id, 4); if (l < 4) { assert (!l); } if (our_id) { bl_do_set_our_id (TLS, TGL_MK_USER (our_id)); } close (auth_file_fd); }
void CTelegramProto::ReadAuth() { DBVARIANT dbv = { 0 }; if (db_get(0, m_szModuleName, "TGL_AUTH", &dbv)) { bl_do_dc_option(TLS, 1, "", 0, TG_SERVER_1, strlen(TG_SERVER_1), 443); bl_do_dc_option(TLS, 2, "", 0, TG_SERVER_2, strlen(TG_SERVER_2), 443); bl_do_dc_option(TLS, 3, "", 0, TG_SERVER_3, strlen(TG_SERVER_3), 443); bl_do_dc_option(TLS, 4, "", 0, TG_SERVER_4, strlen(TG_SERVER_4), 443); bl_do_dc_option(TLS, 5, "", 0, TG_SERVER_5, strlen(TG_SERVER_5), 443); bl_do_set_working_dc(TLS, TG_SERVER_DEFAULT); return; } int *piBlob = (int*)dbv.pbVal; size_t x = (size_t)*piBlob++; int dc_working_num = *piBlob++; for (size_t i = 0; i < x; i++) { int y = *piBlob++; if (y) { read_dc(TLS, piBlob, i); } } bl_do_set_working_dc(TLS, dc_working_num); int our_id = *piBlob++; if (our_id) { bl_do_set_our_id(TLS, TGL_MK_USER(our_id).id); } db_free(&dbv); }