diary

Text-based journaling program
git clone https://git.in0rdr.ch/diary.git
Log | Files | Refs | README | LICENSE

commit ff75ef69c18fc9211e2211f744744a381ede4ab7
parent cfb52f7e69a15d7e8f424fa987b42493c87e658b
Author: Andreas Gruhler <agruhl@gmx.ch>
Date:   Mon, 31 May 2021 22:10:27 +0200

chmod tokenfile and prevent crash

Don't crash when there already exists a tokenfile with bad syntax or
expired/bad refresh token.

Diffstat:
Mcaldav.c | 12++++++++++++
1 file changed, 12 insertions(+), 0 deletions(-)

diff --git a/caldav.c b/caldav.c @@ -84,6 +84,10 @@ char* read_tokenfile() { char* tokenfile_path = expand_path(CONFIG.google_tokenfile); token_file = fopen(tokenfile_path, "r"); + + chmod(tokenfile_path, S_IRUSR|S_IWUSR); + perror("chmod"); + if (token_file == NULL) { perror("Failed to open tokenfile"); return NULL; @@ -523,6 +527,14 @@ void caldav_sync(struct tm* date, WINDOW* header, WINDOW* cal, int pad_pos) { user_principal = caldav_req(date, GOOGLE_CALDAV_URI, "PROPFIND", principal_postfields, 0); } + if (user_principal == NULL) { + // todo: automatically remove tokenfile and retry until success? + fprintf(stderr, "Unable to fetch principal, invalid refresh token, please delete '%s' and retry.\n", CONFIG.google_tokenfile); + access_token = NULL; + refresh_token = NULL; + return; + } + user_principal = parse_caldav_current_user_principal(user_principal); fprintf(stderr, "\nUser Principal: %s\n", user_principal);