]> code.citadel.org Git - citadel.git/blobdiff - webcit/auth.c
Added some glue code for attachment of an OpenID to
[citadel.git] / webcit / auth.c
index 5ebe8e48618d7a52fe99d2b20fdca9a812bccc8a..b923dd9dbdbcd77f172b7e91ebcd325e1339fc1e 100644 (file)
@@ -5,22 +5,22 @@
  */
 
 #include "webcit.h"
+#include "webserver.h"
 
 /*
- * user states
- * the plain text states of a user. filled in at \ function TODO initialize_ax_defs()
- * due to NLS
+ * Access level definitions.  This is initialized from a function rather than a
+ * static array so that the strings may be localized.
  */
 char *axdefs[7]; 
 
 void initialize_axdefs(void) {
-       axdefs[0] = _("Deleted");       /*!0: an erased user */
-       axdefs[1] = _("New User");      /*!1: a new user */
-       axdefs[2] = _("Problem User");  /*!2: a trouble maker */
-       axdefs[3] = _("Local User");    /*!3: user with normal privileges */
-       axdefs[4] = _("Network User");  /*!4: a user that may access network resources */
-       axdefs[5] = _("Preferred User");/*!5: a moderator */
-       axdefs[6] = _("Aide");          /*!6: chief */
+       axdefs[0] = _("Deleted");       /* an erased user */
+       axdefs[1] = _("New User");      /* a new user */
+       axdefs[2] = _("Problem User");  /* a trouble maker */
+       axdefs[3] = _("Local User");    /* user with normal privileges */
+       axdefs[4] = _("Network User");  /* a user that may access network resources */
+       axdefs[5] = _("Preferred User");/* a moderator */
+       axdefs[6] = _("Aide");          /* chief */
 }
 
 
@@ -249,6 +249,8 @@ void do_login(void)
        if (WC->logged_in) {
                if (WC->need_regi) {
                        display_reg(1);
+               } else if (WC->need_vali) {
+                       validate();
                } else {
                        do_welcome();
                }
@@ -259,13 +261,14 @@ void do_login(void)
 }
 
 
-
-
 /* 
  * Perform authentication using OpenID
+ * assemble the checkid_setup request and then redirect to the user's identity provider
  */
 void do_openid_login(void)
 {
+       char buf[4096];
+
        if (havebstr("language")) {
                set_selected_language(bstr("language"));
                go_selected_language();
@@ -276,10 +279,78 @@ void do_openid_login(void)
                return;
        }
        if (havebstr("login_action")) {
+               snprintf(buf, sizeof buf,
+                       "OIDS %s|%s://%s/finalize_openid_login|%s://%s",
+                       bstr("openid_url"),
+                       (is_https ? "https" : "http"), WC->http_host,
+                       (is_https ? "https" : "http"), WC->http_host
+               );
+
+               serv_puts(buf);
+               serv_getln(buf, sizeof buf);
+               if (buf[0] == '2') {
+                       lprintf(CTDL_DEBUG, "OpenID server contacted; redirecting to %s\n", &buf[4]);
+                       http_redirect(&buf[4]);
+                       return;
+               }
+               else {
+                       display_openid_login(&buf[4]);
+                       return;
+               }
+       }
+
+       /* If we get to this point then something failed. */
+       display_openid_login(_("Your password was not accepted."));
+}
+
+/* 
+ * Complete the authentication using OpenID
+ * This function handles the positive or negative assertion from the user's Identity Provider
+ */
+void finalize_openid_login(void)
+{
+       char buf[1024];
+       struct wcsession *WCC = WC;
+       int already_logged_in = (WCC->logged_in) ;
 
-               fetch_http(bstr("openid_url"));         // FIXME
+       if (havebstr("openid.mode")) {
+               if (!strcasecmp(bstr("openid.mode"), "id_res")) {
 
+                       // FIXME id accepted but the code isn't finished
+                       serv_puts("OIDF");
+                       serv_getln(buf, sizeof buf);
+
+                       if (buf[0] == '8') {
+                               urlcontent *u;
+                               void *U;
+                               long HKLen;
+                               char *HKey;
+                               HashPos *Cursor;
+                               
+                               Cursor = GetNewHashPos ();
+                               while (GetNextHashPos(WCC->urlstrings, Cursor, &HKLen, &HKey, &U)) {
+                                       u = (urlcontent*) U;
+                                       if (!strncasecmp(u->url_key, "openid.", 7)) {
+                                               serv_printf("%s|%s", &u->url_key[7], u->url_data);
+                                       }
+                               }
+
+                               serv_puts("000");
+
+                               while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
+                                       // FIXME
+                               }
+                       }
+               }
+       }
+
+       /* If we were already logged in, this was an attempt to associate an OpenID account */
+       if (already_logged_in) {
+               display_openids();
+               return;
        }
+
+       /* Otherwise the user is probably attempting to log in using OpenID */
        if (WC->logged_in) {
                if (WC->need_regi) {
                        display_reg(1);
@@ -293,16 +364,10 @@ void do_openid_login(void)
 }
 
 
-
-
-
-
-
-
 /*
- * display the user a welcome screen.
+ * Display a welcome screen to the user.
  *
- * if this is the first time login, and the web based setup is enabled, 
+ * If this is the first time login, and the web based setup is enabled, 
  * lead the user through the setup routines
  */
 void do_welcome(void)