Commit 04630cb0 authored by Vysheng's avatar Vysheng

Added reset authorization key

parent c7174159
...@@ -1198,6 +1198,20 @@ static int fetch_comb_binlog_msg_update (void *extra) { ...@@ -1198,6 +1198,20 @@ static int fetch_comb_binlog_msg_update (void *extra) {
return 0; 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) \ #define FETCH_COMBINATOR_FUNCTION(NAME) \
case CODE_ ## NAME:\ case CODE_ ## NAME:\
ok = fetch_comb_ ## NAME (0); \ ok = fetch_comb_ ## NAME (0); \
...@@ -1288,6 +1302,7 @@ static void replay_log_event (void) { ...@@ -1288,6 +1302,7 @@ static void replay_log_event (void) {
FETCH_COMBINATOR_FUNCTION (binlog_delete_msg) FETCH_COMBINATOR_FUNCTION (binlog_delete_msg)
FETCH_COMBINATOR_FUNCTION (binlog_msg_seq_update) FETCH_COMBINATOR_FUNCTION (binlog_msg_seq_update)
FETCH_COMBINATOR_FUNCTION (binlog_msg_update) FETCH_COMBINATOR_FUNCTION (binlog_msg_update)
FETCH_COMBINATOR_FUNCTION (binlog_reset_authorization)
default: default:
vlogprintf (E_ERROR, "Unknown op 0x%08x\n", op); vlogprintf (E_ERROR, "Unknown op 0x%08x\n", op);
assert (0); assert (0);
...@@ -2102,6 +2117,11 @@ void bl_do_msg_update (long long id) { ...@@ -2102,6 +2117,11 @@ void bl_do_msg_update (long long id) {
add_log_event (packet_buffer, 4 * (packet_ptr - packet_buffer)); 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) { /*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 (); clear_packet ();
out_int (CODE_binlog_add_dc); out_int (CODE_binlog_add_dc);
......
...@@ -93,5 +93,7 @@ void bl_do_delete_msg (struct tgl_message *M); ...@@ -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_seq_update (long long id);
void bl_do_msg_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); //void bl_do_add_dc (int id, const char *ip, int l, int port, long long auth_key_id, const char *auth_key);
#endif #endif
...@@ -74,4 +74,6 @@ binlog.deleteMsg id:long = binlog.Update; ...@@ -74,4 +74,6 @@ binlog.deleteMsg id:long = binlog.Update;
binlog.msgSeqUpdate id:long = binlog.Update; binlog.msgSeqUpdate id:long = binlog.Update;
binlog.msgUpdate 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; //binlog.addDc id:int ip:string port:int auth_key_id:long auth_key:64*[int] = binlog.Update;
...@@ -73,6 +73,7 @@ extern int safe_quit; ...@@ -73,6 +73,7 @@ extern int safe_quit;
extern int sync_from_start; extern int sync_from_start;
extern int disable_output; extern int disable_output;
extern int reset_authorization;
void got_it (char *line, int len); void got_it (char *line, int len);
void write_state_file (void); void write_state_file (void);
...@@ -609,7 +610,15 @@ int loop (void) { ...@@ -609,7 +610,15 @@ int loop (void) {
lua_binlog_end (); lua_binlog_end ();
#endif #endif
update_prompt (); 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); net_loop (0, all_authorized);
int i; int i;
......
...@@ -97,6 +97,7 @@ char *lua_file; ...@@ -97,6 +97,7 @@ char *lua_file;
int disable_colors; int disable_colors;
int readline_disabled; int readline_disabled;
int disable_output; int disable_output;
int reset_authorization;
void set_default_username (const char *s) { void set_default_username (const char *s) {
if (default_username) { if (default_username) {
...@@ -519,7 +520,7 @@ int change_user_group () { ...@@ -519,7 +520,7 @@ int change_user_group () {
void args_parse (int argc, char **argv) { void args_parse (int argc, char **argv) {
int opt = 0; 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 #ifdef HAVE_LIBCONFIG
"c:p:" "c:p:"
#else #else
...@@ -599,6 +600,9 @@ void args_parse (int argc, char **argv) { ...@@ -599,6 +600,9 @@ void args_parse (int argc, char **argv) {
case 'D': case 'D':
disable_output ++; disable_output ++;
break; break;
case 'q':
reset_authorization ++;
break;
case 'h': case 'h':
default: default:
usage (); usage ();
......
...@@ -72,7 +72,7 @@ struct tgl_dc { ...@@ -72,7 +72,7 @@ struct tgl_dc {
int flags; int flags;
enum tgl_dc_state state; enum tgl_dc_state state;
char *ip; char *ip;
char *user; //char *user;
struct tgl_session *sessions[MAX_DC_SESSIONS]; struct tgl_session *sessions[MAX_DC_SESSIONS];
char auth_key[256]; char auth_key[256];
char temp_auth_key[256]; char temp_auth_key[256];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment