From 14987590b80f32fda86003dde9cdbf6775016399 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Wed, 20 May 2009 17:07:21 +0000 Subject: [PATCH] * The code that handled session establishment via http-auth was also handling re-login via cookie data, since they both set c_username and c_password ... the extra function for cookie login wasn't being called at all so I removed it. * When re-establishing a session, use gotoroom() instead of explicitly doing a GOTO server command. This causes the wc_view and other session data to be loaded properly. --- webcit/auth.c | 37 ------------------------------------- webcit/webcit.c | 37 +++++++++++++++++++++++-------------- webcit/webcit.h | 3 --- 3 files changed, 23 insertions(+), 54 deletions(-) diff --git a/webcit/auth.c b/webcit/auth.c index 61d7ecc00..8dfce2214 100644 --- a/webcit/auth.c +++ b/webcit/auth.c @@ -28,43 +28,6 @@ void initialize_axdefs(void) { axdefs[6] = _("Aide"); /* chief */ } -int ReEstablish_Session(void) -{ - StrBuf *Buf = NewStrBuf(); - wcsession *WCC = WC; - - serv_printf("USER %s", ChrPtr(WCC->Hdr->c_username)); - StrBuf_ServGetln(Buf); - if (GetServerStatus(Buf, NULL) == 3) { - serv_printf("PASS %s", ChrPtr(WCC->Hdr->c_password)); - StrBuf_ServGetln(Buf); - if (GetServerStatus(Buf, NULL) == 2) { - become_logged_in(WCC->Hdr->c_username, - WCC->Hdr->c_password, Buf); - get_preference("default_header_charset", &WCC->DefaultCharset); - } - } - /* - * If we don't have a current room, but a cookie specifying the - * current room is supplied, make an effort to go there. - */ - if ((StrLength(WCC->wc_roomname) == 0) && (StrLength(WCC->Hdr->c_roomname) > 0)) { - serv_printf("GOTO %s", - ChrPtr(WCC->Hdr->c_roomname)); - StrBuf_ServGetln(Buf); - if (GetServerStatus(Buf, NULL) == 2) { - if (WCC->wc_roomname == NULL) { - WCC->wc_roomname = NewStrBufDup(WCC->Hdr->c_roomname); - } - else { - FlushStrBuf(WCC->wc_roomname); - StrBufAppendBuf(WCC->wc_roomname, WCC->Hdr->c_roomname, 0); - } - } - } - FreeStrBuf(&Buf); - return 0; -} /* diff --git a/webcit/webcit.c b/webcit/webcit.c index 4908d44f4..f3f910337 100644 --- a/webcit/webcit.c +++ b/webcit/webcit.c @@ -604,8 +604,8 @@ void session_loop(void) /* - * If we're not logged in, but we have HTTP Authentication data, - * try logging in to Citadel using that. + * If we're not logged in, but we have authentication data (either from + * a cookie or from http-auth), try logging in to Citadel using that. */ if ((!WCC->logged_in) && (StrLength(WCC->Hdr->c_username) > 0) @@ -634,24 +634,33 @@ void session_loop(void) (WCC->Hdr->eReqType != eHEAD); /* - * If we're not logged in, but we have username and password cookies - * supplied by the browser, try using them to log in. + * If a 'gotofirst' parameter has been specified, attempt to goto that room + * prior to doing anything else. */ - if ((!WCC->logged_in) - && (StrLength(WCC->Hdr->c_username)>0) - && (StrLength(WCC->Hdr->c_password)>0)) { - ReEstablish_Session(); + if (havebstr("gotofirst")) { + int ret; + ret = gotoroom(sbstr("gotofirst")); /* do quietly to avoid session output! */ + if ((ret/100) != 2) { + lprintf(1, "GOTOFIRST: Unable to change to [%s]; Reason: %d\n", + bstr("gotofirst"), ret); + } } /* - * If a 'gotofirst' parameter has been specified, attempt to goto that room - * prior to doing anything else. + * If we aren't in any room yet, but we have cookie data telling us where we're + * supposed to be, and 'gotofirst' was not specified, then go there. */ - if (havebstr("gotofirst")) { + else if ( (StrLength(WCC->wc_roomname) == 0) && ( (StrLength(WCC->Hdr->c_roomname) > 0) )) { + lprintf(9, "We are in '%s' but cookie indicates '%s', going there...\n", + ChrPtr(WCC->wc_roomname), + ChrPtr(WCC->Hdr->c_roomname) + ); int ret; - ret = gotoroom(sbstr("gotofirst")); /* do this quietly to avoid session output! */ - if (ret != 0) - lprintf(1, "GOTOFIRST: Unable to change to [%s]; Reason: %d\n", bstr("gotofirst"), ret); + ret = gotoroom(WCC->Hdr->c_roomname); /* do quietly to avoid session output! */ + if ((ret/100) != 2) { + lprintf(1, "COOKIEGOTO: Unable to change to [%s]; Reason: %d\n", + ChrPtr(WCC->Hdr->c_roomname), ret); + } } if (WCC->Hdr->Handler != NULL) { diff --git a/webcit/webcit.h b/webcit/webcit.h index cf085c2be..074b4f8da 100644 --- a/webcit/webcit.h +++ b/webcit/webcit.h @@ -717,9 +717,6 @@ void display_success(char *); void authorization_required(const char *message); void CheckAuthBasic(ParsedHttpHdrs *hdr); void GetAuthBasic(ParsedHttpHdrs *hdr); - -int ReEstablish_Session(void); - void server_to_text(void); void save_edit(char *description, char *enter_cmd, int regoto); void display_edit(char *description, char *check_cmd, -- 2.30.2