Added reset authorization key

This commit is contained in:
Vysheng 2014-09-18 17:57:23 +04:00
parent c71741599b
commit 04630cb0e9
6 changed files with 40 additions and 3 deletions

View File

@ -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);

View File

@ -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

View File

@ -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;

11
loop.c
View File

@ -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;

6
main.c
View File

@ -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 ();

View File

@ -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];