]> code.citadel.org Git - citadel.git/blobdiff - webcit/auth.c
* The code that handled session establishment via http-auth was also handling re...
[citadel.git] / webcit / auth.c
index 80064a689dd3beacec1cfee6007b81782248bf6e..8dfce2214e839c7422098e687df52ada03960bcf 100644 (file)
@@ -8,6 +8,7 @@
 #include "webserver.h"
 #include <ctype.h>
 
+extern uint32_t hashlittle( const void *key, size_t length, uint32_t initval);
 
 void display_reg(int during_login);
 
@@ -27,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;
-}
 
 
 /* 
@@ -950,23 +914,60 @@ void _display_reg(void) {display_reg(0);}
 
 void Header_HandleAuth(StrBuf *Line, ParsedHttpHdrs *hdr)
 {
-       const char *Pos = NULL;
-       if (strncasecmp(ChrPtr(Line), "Basic", 5) == 0) {
-               StrBufCutLeft(Line, 6);
-               StrBufDecodeBase64(Line);
-               StrBufExtract_NextToken(hdr->c_username, Line, &Pos, ':');
-               StrBufExtract_NextToken(hdr->c_password, Line, &Pos, ':');
-               hdr->got_auth = AUTH_BASIC;
+       if (hdr->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;
+               }
+               else 
+                       lprintf(1, "Authentication scheme not supported! [%s]\n", ChrPtr(Line));
        }
-       else 
-               lprintf(1, "Authentication scheme not supported! [%s]\n", ChrPtr(Line));
+}
+
+void CheckAuthBasic(ParsedHttpHdrs *hdr)
+{
+/*
+  todo: enable this if we can have other sessions than authenticated ones.
+       if (hdr->DontNeedAuth)
+               return;
+*/
+       StrBufAppendBufPlain(hdr->plainauth, HKEY(":"), 0);
+       StrBufAppendBuf(hdr->plainauth, hdr->user_agent, 0);
+       hdr->SessionKey = hashlittle(SKEY(hdr->plainauth), 89479832);
+       
+}
+
+void GetAuthBasic(ParsedHttpHdrs *hdr)
+{
+       const char *Pos = NULL;
+       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));
+       StrBufExtract_NextToken(hdr->c_username, hdr->plainauth, &Pos, ':');
+       StrBufExtract_NextToken(hdr->c_password, hdr->plainauth, &Pos, ':');
 }
 
 void Header_HandleCookie(StrBuf *Line, ParsedHttpHdrs *hdr)
 {
-       hdr->RawCookie = Line;
+       const char *pch;
+/*
+  todo: enable this if we can have other sessions than authenticated ones.
        if (hdr->DontNeedAuth)
                return;
+*/
+       pch = strstr(ChrPtr(Line), "webcit=");
+       if (pch == NULL) {
+               return;
+       }
+
+       hdr->RawCookie = Line;
+       StrBufCutLeft(hdr->RawCookie, (pch - ChrPtr(hdr->RawCookie)) + 7);
+       StrBufDecodeHex(hdr->RawCookie);
+
        if (hdr->c_username == NULL)
                hdr->c_username = NewStrBufPlain(HKEY(DEFAULT_HTTPAUTH_USER));
        if (hdr->c_password == NULL)
@@ -1020,7 +1021,6 @@ SessionDestroyModule_AUTH
        FreeStrBuf(&sess->wc_fullname);
        FreeStrBuf(&sess->wc_password);
        FreeStrBuf(&sess->wc_roomname);
-       FreeStrBuf(&sess->httpauth_user);
        FreeStrBuf(&sess->httpauth_pass);
        FreeStrBuf(&sess->cs_inet_email);
 }