From a0159a2dc04389a62d81f39d91f76cfab6b7293c Mon Sep 17 00:00:00 2001 From: Eduardo Chappa Date: Mon, 1 Nov 2021 20:42:12 -0600 Subject: * When Alpine is trying to decide which client-id to choose it used to limit its choices the ps_global->vars[V_XOAUTH2_INFO].current_val.l. Now it will also use ps_global->vars[V_XOAUTH2_INFO].main_user_val.l. In addition some of the code in alpine/xoauth2conf.c was moved to the c-client library. --- imap/src/c-client/mail.h | 3 +++ imap/src/c-client/oauth2_aux.c | 42 ++++++++++++++++++++++++++++++++++++------ 2 files changed, 39 insertions(+), 6 deletions(-) (limited to 'imap') diff --git a/imap/src/c-client/mail.h b/imap/src/c-client/mail.h index 8e848201..94ac64fa 100644 --- a/imap/src/c-client/mail.h +++ b/imap/src/c-client/mail.h @@ -2034,6 +2034,9 @@ char *oauth2_generate_state(void); void oauth2deviceinfo_get_accesscode(void *, void *); XOAUTH2_INFO_S *new_xoauth2_info(void); void free_xoauth2_info(XOAUTH2_INFO_S **); +void free_xoauth2_info_list(XOAUTH2_INFO_S ***); XOAUTH2_INFO_S *copy_xoauth2_info(XOAUTH2_INFO_S *); +int same_xoauth2_info(XOAUTH2_INFO_S, XOAUTH2_INFO_S); char *oauth2_generate_state(void); void renew_accesstoken(MAILSTREAM *); +XOAUTH2_INFO_S **parse_xoauth2_info_list(char **, int *); diff --git a/imap/src/c-client/oauth2_aux.c b/imap/src/c-client/oauth2_aux.c index a0828ba4..363f41d1 100644 --- a/imap/src/c-client/oauth2_aux.c +++ b/imap/src/c-client/oauth2_aux.c @@ -65,7 +65,8 @@ char *xoauth2_server(char *, char *); (Y)[i].name = (Y)[i].value = NULL; \ } -char *xoauth2_server(char *server, char *tenant) +char * +xoauth2_server(char *server, char *tenant) { char *rv = NULL; char *s; @@ -100,7 +101,8 @@ char *xoauth2_server(char *server, char *tenant) return rv; } -JSON_S *oauth2_json_reply(OAUTH2_SERVER_METHOD_S RefreshMethod, OAUTH2_S *oauth2, int *status) +JSON_S * +oauth2_json_reply(OAUTH2_SERVER_METHOD_S RefreshMethod, OAUTH2_S *oauth2, int *status) { JSON_S *json = NULL; HTTP_PARAM_S params[OAUTH2_PARAM_NUMBER]; @@ -312,7 +314,8 @@ mm_login_oauth2_c_client_method (NETMBX *mb, char *user, char *method, } } -void oauth2deviceinfo_get_accesscode(void *inp, void *outp) +void +oauth2deviceinfo_get_accesscode(void *inp, void *outp) { OAUTH2_DEVICEPROC_S *oad = (OAUTH2_DEVICEPROC_S *) inp; OAUTH2_S *oauth2 = oad->xoauth2; @@ -380,14 +383,16 @@ void oauth2deviceinfo_get_accesscode(void *inp, void *outp) *(int *)outp = rv; } -XOAUTH2_INFO_S *new_xoauth2_info(void) +XOAUTH2_INFO_S * +new_xoauth2_info(void) { XOAUTH2_INFO_S *rv = fs_get(sizeof(XOAUTH2_INFO_S)); memset((void *) rv, 0, sizeof(XOAUTH2_INFO_S)); return rv; } -void free_xoauth2_info(XOAUTH2_INFO_S **xp) +void +free_xoauth2_info(XOAUTH2_INFO_S **xp) { if(xp == NULL || *xp == NULL) return; @@ -400,7 +405,8 @@ void free_xoauth2_info(XOAUTH2_INFO_S **xp) fs_give((void **) xp); } -XOAUTH2_INFO_S *copy_xoauth2_info(XOAUTH2_INFO_S *x) +XOAUTH2_INFO_S * +copy_xoauth2_info(XOAUTH2_INFO_S *x) { XOAUTH2_INFO_S *y; @@ -415,6 +421,30 @@ XOAUTH2_INFO_S *copy_xoauth2_info(XOAUTH2_INFO_S *x) return y; } +int +same_xoauth2_info(XOAUTH2_INFO_S x, XOAUTH2_INFO_S y) +{ + int rv = 0; + if(x.name && y.name && !strcmp((char *) x.name, (char *) y.name) + && x.client_id && y.client_id && !strcmp(x.client_id, y.client_id) + && ((!x.client_secret && !y.client_secret) + || (x.client_secret && y.client_secret && !strcmp(x.client_secret, y.client_secret))) + && ((!x.tenant && !y.tenant) || (x.tenant && y.tenant && !strcmp(x.tenant, y.tenant)))) + rv = 1; + return rv; +} + +void +free_xoauth2_info_list(XOAUTH2_INFO_S ***xp) +{ + int i; + + if(xp == NULL || *xp == NULL || **xp) return; + for(i = 0; (*xp)[i] != NULL; i++) free_xoauth2_info(&(*xp)[i]); + fs_give((void **) &xp); +} + + /* This function does not create a refresh token and and * an access token, but uses an already known refresh token * to generate a refresh token on an ALREADY OPEN stream. -- cgit v1.2.3-70-g09d2