From 04630cb0e9ed00e1d8580ad81b8784c3dbe5fa82 Mon Sep 17 00:00:00 2001 From: Vysheng Date: Thu, 18 Sep 2014 17:57:23 +0400 Subject: [PATCH] Added reset authorization key --- binlog.c | 20 ++++++++++++++++++++ binlog.h | 2 ++ binlog.tl | 2 ++ loop.c | 11 ++++++++++- main.c | 6 +++++- tgl-layout.h | 2 +- 6 files changed, 40 insertions(+), 3 deletions(-) diff --git a/binlog.c b/binlog.c index 4f37f53..bf9faaa 100644 --- a/binlog.c +++ b/binlog.c @@ -1198,6 +1198,20 @@ static int fetch_comb_binlog_msg_update (void *extra) { return 0; } +static int fetch_comb_binlog_reset_authorization (void *extra) { + int i; + for (i = 0; i <= tgl_state.max_dc_num; i++) if (tgl_state.DC_list[i]) { + struct tgl_dc *D = tgl_state.DC_list[i]; + D->flags = 0; + D->state = st_init; + D->auth_key_id = D->temp_auth_key_id = 0; + D->has_auth = 0; + } + tgl_state.seq = 0; + tgl_state.qts = 0; + return 0; +} + #define FETCH_COMBINATOR_FUNCTION(NAME) \ case CODE_ ## NAME:\ ok = fetch_comb_ ## NAME (0); \ @@ -1288,6 +1302,7 @@ static void replay_log_event (void) { FETCH_COMBINATOR_FUNCTION (binlog_delete_msg) FETCH_COMBINATOR_FUNCTION (binlog_msg_seq_update) FETCH_COMBINATOR_FUNCTION (binlog_msg_update) + FETCH_COMBINATOR_FUNCTION (binlog_reset_authorization) default: vlogprintf (E_ERROR, "Unknown op 0x%08x\n", op); assert (0); @@ -2102,6 +2117,11 @@ void bl_do_msg_update (long long id) { add_log_event (packet_buffer, 4 * (packet_ptr - packet_buffer)); } +void bl_do_reset_authorization (void) { + clear_packet (); + out_int (CODE_binlog_reset_authorization); + add_log_event (packet_buffer, 4 * (packet_ptr - packet_buffer)); +} /*void bl_do_add_dc (int id, const char *ip, int l, int port, long long auth_key_id, const char *auth_key) { clear_packet (); out_int (CODE_binlog_add_dc); diff --git a/binlog.h b/binlog.h index f0d10ce..fd38496 100644 --- a/binlog.h +++ b/binlog.h @@ -93,5 +93,7 @@ void bl_do_delete_msg (struct tgl_message *M); void bl_do_msg_seq_update (long long id); void bl_do_msg_update (long long id); +void bl_do_reset_authorization (void); + //void bl_do_add_dc (int id, const char *ip, int l, int port, long long auth_key_id, const char *auth_key); #endif diff --git a/binlog.tl b/binlog.tl index a5d6964..1df1c17 100644 --- a/binlog.tl +++ b/binlog.tl @@ -74,4 +74,6 @@ binlog.deleteMsg id:long = binlog.Update; binlog.msgSeqUpdate id:long = binlog.Update; binlog.msgUpdate id:long = binlog.Update; +binlog.resetAuthorization = binlog.Update; + //binlog.addDc id:int ip:string port:int auth_key_id:long auth_key:64*[int] = binlog.Update; diff --git a/loop.c b/loop.c index 9c0b4c7..4d12a2b 100644 --- a/loop.c +++ b/loop.c @@ -73,6 +73,7 @@ extern int safe_quit; extern int sync_from_start; extern int disable_output; +extern int reset_authorization; void got_it (char *line, int len); void write_state_file (void); @@ -609,7 +610,15 @@ int loop (void) { lua_binlog_end (); #endif update_prompt (); - + + if (reset_authorization) { + tgl_peer_t *P = tgl_peer_get (TGL_MK_USER (tgl_state.our_id)); + if (P && P->user.phone && reset_authorization == 1) { + set_default_username (P->user.phone); + } + bl_do_reset_authorization (); + } + net_loop (0, all_authorized); int i; diff --git a/main.c b/main.c index de35bc0..6e28593 100644 --- a/main.c +++ b/main.c @@ -97,6 +97,7 @@ char *lua_file; int disable_colors; int readline_disabled; int disable_output; +int reset_authorization; void set_default_username (const char *s) { if (default_username) { @@ -519,7 +520,7 @@ int change_user_group () { void args_parse (int argc, char **argv) { int opt = 0; - while ((opt = getopt (argc, argv, "u:hk:vNl:fEwWCRdL:DU:G:" + while ((opt = getopt (argc, argv, "u:hk:vNl:fEwWCRdL:DU:G:q" #ifdef HAVE_LIBCONFIG "c:p:" #else @@ -599,6 +600,9 @@ void args_parse (int argc, char **argv) { case 'D': disable_output ++; break; + case 'q': + reset_authorization ++; + break; case 'h': default: usage (); diff --git a/tgl-layout.h b/tgl-layout.h index b903f72..0f08bc6 100644 --- a/tgl-layout.h +++ b/tgl-layout.h @@ -72,7 +72,7 @@ struct tgl_dc { int flags; enum tgl_dc_state state; char *ip; - char *user; + //char *user; struct tgl_session *sessions[MAX_DC_SESSIONS]; char auth_key[256]; char temp_auth_key[256];