]> code.citadel.org Git - citadel.git/blobdiff - webcit/auth.c
* add logging if auth-basic session connecting fails with weird conditions
[citadel.git] / webcit / auth.c
index 2f3d61bd82c30c99d9f49ccb446838bcb0d572be..d61d7c203002e8805e8b9c38864201b358615f98 100644 (file)
@@ -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;
-}
 
 
 /* 
@@ -111,7 +74,7 @@ void display_openid_name_request(const StrBuf *claimed_id, const StrBuf *usernam
 
        if (StrLength(username) > 0) {
                        Buf = NewStrBufPlain(NULL, StrLength(username));
-                       StrEscAppend(Buf, claimed_id, NULL, 0, 0);
+                       StrEscAppend(Buf, username, NULL, 0, 0);
                        svprintf(HKEY("REASON"), WCS_STRING,
                                 _("However, the user name '%s' conflicts with an existing user."), 
                                 ChrPtr(Buf));
@@ -153,7 +116,6 @@ void become_logged_in(const StrBuf *user, const StrBuf *pass, StrBuf *serv_respo
        wcsession *WCC = WC;
        StrBuf *Buf;
        StrBuf *FloorDiv;
-       StrBuf *Language = NULL;
 
        WCC->logged_in = 1;
 
@@ -197,15 +159,6 @@ void become_logged_in(const StrBuf *user, const StrBuf *pass, StrBuf *serv_respo
                        WCC->cs_inet_email  = NewStrBuf();
                StrBufExtract_NextToken(WCC->cs_inet_email, Buf, &pch, '|');
        }
-       if (havebstr("language"))
-               set_preference("language", NewStrBufDup(SBSTR("language")), 1);
-       else {
-               get_preference("language", &Language);
-               if (Language != NULL) {
-                       set_selected_language(ChrPtr(Language));
-                       go_selected_language();         /* set locale */
-               }
-       }
        get_preference("floordiv_expanded", &FloorDiv);
        WCC->floordiv_expanded = FloorDiv;
        FreeStrBuf(&Buf);
@@ -367,8 +320,8 @@ void do_openid_login(void)
                snprintf(buf, sizeof buf,
                        "OIDS %s|%s://%s/finalize_openid_login|%s://%s",
                        bstr("openid_url"),
-                        (is_https ? "https" : "http"), ChrPtr(WCC->Hdr->http_host),
-                        (is_https ? "https" : "http"), ChrPtr(WCC->Hdr->http_host)
+                        (is_https ? "https" : "http"), ChrPtr(WCC->Hdr->HR.http_host),
+                        (is_https ? "https" : "http"), ChrPtr(WCC->Hdr->HR.http_host)
                );
 
                serv_puts(buf);
@@ -553,14 +506,16 @@ void do_welcome(void)
         */
        if (!get_preference("startpage", &Buf)) {
                Buf = NewStrBuf ();
-               StrBufPrintf(Buf, "dotskip&room=_BASEROOM_");
+               StrBufPrintf(Buf, "dotskip?room=_BASEROOM_");
                set_preference("startpage", Buf, 1);
        }
        if (ChrPtr(Buf)[0] == '/') {
                StrBufCutLeft(Buf, 1);
        }
-       if (StrLength(Buf) == 0)
+       if (StrLength(Buf) == 0) {
                StrBufAppendBufPlain(Buf, "dotgoto?room=_BASEROOM_", -1, 0);
+       }
+       lprintf(9, "Redirecting to user's start page: %s\n", ChrPtr(Buf));
        http_redirect(ChrPtr(Buf));
 }
 
@@ -786,14 +741,19 @@ void validate(void)
 void display_reg(int during_login)
 {
        StrBuf *Buf;
-       message_summary *VCMsg;
-       wc_mime_attachment *VCAtt;
+       message_summary *VCMsg = NULL;
+       wc_mime_attachment *VCAtt = NULL;
        long vcard_msgnum;
 
        Buf = NewStrBuf();
        if (goto_config_room(Buf) != 0) {
-               if (during_login) do_welcome();
-               else display_main_menu();
+               lprintf(9, "display_reg() exiting because goto_config_room() failed\n");
+               if (during_login) {
+                       do_welcome();
+               }
+               else {
+                       display_main_menu();
+               }
                FreeStrBuf(&Buf);
                return;
        }
@@ -801,8 +761,13 @@ void display_reg(int during_login)
        FreeStrBuf(&Buf);
        vcard_msgnum = locate_user_vcard_in_this_room(&VCMsg, &VCAtt);
        if (vcard_msgnum < 0L) {
-               if (during_login) do_welcome();
-               else display_main_menu();
+               lprintf(9, "display_reg() exiting because locate_user_vcard_in_this_room() failed\n");
+               if (during_login) {
+                       do_welcome();
+               }
+               else {
+                       display_main_menu();
+               }
                return;
        }
 
@@ -810,9 +775,14 @@ void display_reg(int during_login)
                do_edit_vcard(vcard_msgnum, "1", VCMsg, VCAtt, "do_welcome", USERCONFIGROOM);
        }
        else {
-               do_edit_vcard(vcard_msgnum, "1", VCMsg, VCAtt, "display_main_menu", USERCONFIGROOM);
+               StrBuf *ReturnTo;
+               ReturnTo = NewStrBufPlain(HKEY("display_main_menu?gotofirst="));
+               StrBufAppendBuf(ReturnTo, WC->wc_roomname, 0);
+               do_edit_vcard(vcard_msgnum, "1", VCMsg, VCAtt, ChrPtr(ReturnTo), USERCONFIGROOM);
+               FreeStrBuf(&ReturnTo);
        }
 
+       /* FIXME - don't we have to free VCMsg and VCAtt ?? */
 }
 
 
@@ -927,37 +897,50 @@ void changepw(void)
 
 int ConditionalAide(StrBuf *Target, WCTemplputParams *TP)
 {
-       return (WC->is_aide == 0);
+       wcsession *WCC = WC;
+       return (WCC != NULL)? (WC->is_aide == 0) : 0;
 }
 
 int ConditionalRoomAide(StrBuf *Target, WCTemplputParams *TP)
 {
-       return (WC->is_room_aide == 0);
+       wcsession *WCC = WC;
+       return (WCC != NULL)? (WCC->is_room_aide == 0) : 0;
 }
 
-int ConditionalIsLoggedIn(StrBuf *Target, WCTemplputParams *TP) {
-  return (WC->logged_in == 0);
+
+int ConditionalIsLoggedIn(StrBuf *Target, WCTemplputParams *TP) 
+{
+       wcsession *WCC = WC;
+       return (WCC != NULL)? (WCC->logged_in == 0) : 0;
 }
+
+
 int ConditionalRoomAcessDelete(StrBuf *Target, WCTemplputParams *TP)
 {
        wcsession *WCC = WC;
-       return ( (WCC->is_room_aide) || (WCC->is_mailbox) || (WCC->room_flags2 & QR2_COLLABDEL) );
+       return (WCC != NULL)? ( (WCC->is_room_aide) || (WCC->is_mailbox) || (WCC->room_flags2 & QR2_COLLABDEL) ) : 0;
 }
 
 
+void _display_openid_login(void) {
+       display_openid_login(NULL);
+}
+
+
+void _display_reg(void) {
+       display_reg(0);
+}
 
-void _display_openid_login(void) {display_openid_login(NULL);}
-void _display_reg(void) {display_reg(0);}
 
 void Header_HandleAuth(StrBuf *Line, ParsedHttpHdrs *hdr)
 {
-       if (hdr->got_auth == NO_AUTH) /* don't override cookie auth... */
+       if (hdr->HR.got_auth == NO_AUTH) /* don't override cookie auth... */
        {
                if (strncasecmp(ChrPtr(Line), "Basic", 5) == 0) {
                        StrBufCutLeft(Line, 6);
                        StrBufDecodeBase64(Line);
-                       hdr->plainauth = Line;
-                       hdr->got_auth = AUTH_BASIC;
+                       hdr->HR.plainauth = Line;
+                       hdr->HR.got_auth = AUTH_BASIC;
                }
                else 
                        lprintf(1, "Authentication scheme not supported! [%s]\n", ChrPtr(Line));
@@ -971,10 +954,13 @@ void CheckAuthBasic(ParsedHttpHdrs *hdr)
        if (hdr->DontNeedAuth)
                return;
 */
-       StrBufAppendBufPlain(hdr->plainauth, HKEY(":"), 0);
-       StrBufAppendBuf(hdr->plainauth, hdr->user_agent, 0);
-       hdr->SessionKey = hashlittle(SKEY(hdr->plainauth), 89479832);
-       
+       StrBufAppendBufPlain(hdr->HR.plainauth, HKEY(":"), 0);
+       StrBufAppendBuf(hdr->HR.plainauth, hdr->HR.user_agent, 0);
+       hdr->HR.SessionKey = hashlittle(SKEY(hdr->HR.plainauth), 89479832);
+/*
+       lprintf(1, "CheckAuthBasic: calculated sessionkey %ld\n", 
+               hdr->HR.SessionKey);
+*/
 }
 
 void GetAuthBasic(ParsedHttpHdrs *hdr)
@@ -984,8 +970,8 @@ void GetAuthBasic(ParsedHttpHdrs *hdr)
                hdr->c_username = NewStrBufPlain(HKEY(DEFAULT_HTTPAUTH_USER));
        if (hdr->c_password == NULL)
                hdr->c_password = NewStrBufPlain(HKEY(DEFAULT_HTTPAUTH_PASS));
-       StrBufExtract_NextToken(hdr->c_username, hdr->plainauth, &Pos, ':');
-       StrBufExtract_NextToken(hdr->c_password, hdr->plainauth, &Pos, ':');
+       StrBufExtract_NextToken(hdr->c_username, hdr->HR.plainauth, &Pos, ':');
+       StrBufExtract_NextToken(hdr->c_password, hdr->HR.plainauth, &Pos, ':');
 }
 
 void Header_HandleCookie(StrBuf *Line, ParsedHttpHdrs *hdr)
@@ -996,29 +982,52 @@ void Header_HandleCookie(StrBuf *Line, ParsedHttpHdrs *hdr)
        if (hdr->DontNeedAuth)
                return;
 */
-       hdr->RawCookie = Line;
-
-       pch = strstr(ChrPtr(hdr->RawCookie), "webcit=");
-       
-       if (pch != NULL)
-               StrBufCutLeft(hdr->RawCookie, (pch - ChrPtr(hdr->RawCookie)) + 7);
+       pch = strstr(ChrPtr(Line), "webcit=");
+       if (pch == NULL) {
+               return;
+       }
 
-       StrBufDecodeHex(hdr->RawCookie);
+       hdr->HR.RawCookie = Line;
+       StrBufCutLeft(hdr->HR.RawCookie, (pch - ChrPtr(hdr->HR.RawCookie)) + 7);
+       StrBufDecodeHex(hdr->HR.RawCookie);
 
-       if (hdr->c_username == NULL)
-               hdr->c_username = NewStrBufPlain(HKEY(DEFAULT_HTTPAUTH_USER));
-       if (hdr->c_password == NULL)
-               hdr->c_password = NewStrBufPlain(HKEY(DEFAULT_HTTPAUTH_PASS));
-       if (hdr->c_roomname == NULL)
-               hdr->c_roomname = NewStrBuf();
-       cookie_to_stuff(Line, &hdr->desired_session,
+       cookie_to_stuff(Line, &hdr->HR.desired_session,
                        hdr->c_username,
                        hdr->c_password,
-                       hdr->c_roomname);
-       hdr->got_auth = AUTH_COOKIE;
+                       hdr->c_roomname,
+                       hdr->c_language
+       );
+       hdr->HR.got_auth = AUTH_COOKIE;
 }
 
+void 
+HttpNewModule_AUTH
+(ParsedHttpHdrs *httpreq)
+{
+       httpreq->c_username = NewStrBufPlain(HKEY(DEFAULT_HTTPAUTH_USER));
+       httpreq->c_password = NewStrBufPlain(HKEY(DEFAULT_HTTPAUTH_PASS));
+       httpreq->c_roomname = NewStrBuf();
+       httpreq->c_language = NewStrBuf();
+}
+void 
+HttpDetachModule_AUTH
+(ParsedHttpHdrs *httpreq)
+{
+       FLUSHStrBuf(httpreq->c_username);
+       FLUSHStrBuf(httpreq->c_password);
+       FLUSHStrBuf(httpreq->c_roomname);
+       FLUSHStrBuf(httpreq->c_language);
+}
 
+void 
+HttpDestroyModule_AUTH
+(ParsedHttpHdrs *httpreq)
+{
+       FreeStrBuf(&httpreq->c_username);
+       FreeStrBuf(&httpreq->c_password);
+       FreeStrBuf(&httpreq->c_roomname);
+       FreeStrBuf(&httpreq->c_language);
+}
 
 void 
 InitModule_AUTH