Began writing some code to associate OpenIDs with Citadel accounts
authorArt Cancro <ajc@citadel.org>
Thu, 29 May 2008 20:16:11 +0000 (20:16 +0000)
committerArt Cancro <ajc@citadel.org>
Thu, 29 May 2008 20:16:11 +0000 (20:16 +0000)
citadel/database_cleanup.sh.in
citadel/modules/openid/serv_openid_rp.c
citadel/server.h
webcit/openid.c

index 0d3aeb93dee169eb2ba3222b640ec84c6b982810..f7deb835ed4fb4c5054005fd637d37715471768e 100755 (executable)
@@ -99,7 +99,7 @@ case "$yesno" in
                exit
 esac
 
-for x in 00 01 02 03 04 05 06 07 08 09 0a 0b
+for x in 00 01 02 03 04 05 06 07 08 09 0a 0b 0c
 do
        filename=cdb.$x
        echo Dumping $filename
@@ -110,7 +110,7 @@ done
 echo Removing old databases
 rm -f ./data/*
 
-for x in 00 01 02 03 04 05 06 07 08 09 0a 0b
+for x in 00 01 02 03 04 05 06 07 08 09 0a 0b 0c
 do
        filename=cdb.$x
        echo Loading $filename
index c6765517f20d7db1b450d53a84b5affd4c03a42e..d1418a246037562c85b68e1456681c634b8962c7 100644 (file)
@@ -32,6 +32,7 @@
 #include <curl/curl.h>
 #include "ctdl_module.h"
 #include "config.h"
+#include "citserver.h"
 
 struct ctdl_openid {
        char claimed_id[1024];
@@ -51,21 +52,38 @@ struct ctdl_openid {
 
 
 /*
- * Attach or detach an OpenID to a Citadel account
+ * Attach an OpenID to a Citadel account
  */
-
-enum {
-       moa_detach,
-       moa_attach
-};
-
-int modify_openid_associations(struct ctdluser *who, char *claimed_id, int operation)
+int attach_openid(struct ctdluser *who, char *claimed_id)
 {
+       struct cdbdata *cdboi;
+
        if (!who) return(1);
        if (!claimed_id) return(1);
        if (IsEmptyStr(claimed_id)) return(1);
 
-       return(2);              // error because we are not done yet FIXME
+       /* Check to see if this OpenID is already in the database */
+
+       cdboi = cdb_fetch(CDB_OPENID, claimed_id, strlen(claimed_id));
+       if (cdboi != NULL) {
+               if ( (long)*cdboi->ptr == who->usernum ) {
+                       cdb_free(cdboi);
+                       CtdlLogPrintf(CTDL_INFO, "%s already associated; no action is taken\n", claimed_id);
+                       return(0);
+               }
+               else {
+                       cdb_free(cdboi);
+                       CtdlLogPrintf(CTDL_INFO, "%s already belongs to another user\n", claimed_id);
+                       return(3);
+               }
+       }
+
+       /* Not already in the database, so attach it now */
+
+       cdb_store(CDB_OPENID, claimed_id, strlen(claimed_id), &who->usernum, sizeof(long));
+       CtdlLogPrintf(CTDL_INFO, "%s has been associated with %s (%ld)\n",
+               claimed_id, who->fullname, who->usernum);
+       return(0);
 }
 
 
@@ -78,6 +96,21 @@ void openid_purge(struct ctdluser *usbuf) {
 
 
 
+/*
+ * List the OpenIDs associated with the currently logged in account
+ */
+void cmd_oidl(char *argbuf) {
+       struct cdbdata *cdboi;
+
+       if (CtdlAccessCheck(ac_logged_in)) return;
+       cdb_rewind(CDB_OPENID);
+       cprintf("%d Associated OpenIDs:\n", LISTING_FOLLOWS);
+
+       while (cdboi = cdb_next_item(CDB_OPENID), cdboi != NULL) {
+               cprintf("FIXME %ld\n", (long)*cdboi->ptr );
+       }
+       cprintf("000\n");
+}
 
 
 
@@ -476,7 +509,7 @@ void cmd_oidf(char *argbuf) {
 
                /* If we were already logged in, attach the OpenID to the user's account */
                if (CC->logged_in) {
-                       if (modify_openid_associations(&CC->user, oiddata->claimed_id, moa_attach) == 0) {
+                       if (attach_openid(&CC->user, oiddata->claimed_id) == 0) {
                                cprintf("attach\n");
                        }
                        else {
@@ -549,6 +582,7 @@ CTDL_MODULE_INIT(openid_rp)
                curl_global_init(CURL_GLOBAL_ALL);
                CtdlRegisterProtoHook(cmd_oids, "OIDS", "Setup OpenID authentication");
                CtdlRegisterProtoHook(cmd_oidf, "OIDF", "Finalize OpenID authentication");
+               CtdlRegisterProtoHook(cmd_oidl, "OIDL", "List OpenIDs associated with an account");
                CtdlRegisterSessionHook(openid_cleanup_function, EVT_STOP);
                CtdlRegisterUserHook(openid_purge, EVT_PURGEUSER);
        }
@@ -556,3 +590,6 @@ CTDL_MODULE_INIT(openid_rp)
        /* return our Subversion id for the Log */
        return "$Id$";
 }
+
+
+/* FIXME ... we have to add the new openid database to serv_vandelay.c */
index 1c2af0e4f52d8910658c5e863247279643f56fd4..1d4457dac82ab04e4c51a8a7044d6e598fe1deb3 100644 (file)
@@ -292,6 +292,7 @@ enum {
        CDB_FULLTEXT,           /* full text search index        */
        CDB_EUIDINDEX,          /* locate msgs by EUID           */
        CDB_USERSBYNUMBER,      /* index of users by number      */
+       CDB_OPENID,             /* associates OpenIDs with users */
        MAXCDB                  /* total number of CDB's defined */
 };
 
index b94f0fbc3f548f3bc579307e0fb65633443ca691..21ffa595a6d9a860a7f48d09de265239a4f80f1e 100644 (file)
@@ -10,6 +10,8 @@
  */
 void display_openids(void)
 {
+       char buf[1024];
+
        output_headers(1, 1, 1, 0, 0, 0);
 
        wprintf("<div class=\"fix_scrollbar_bug\">");
@@ -17,7 +19,12 @@ void display_openids(void)
        svput("BOXTITLE", WCS_STRING, _("Manage Account/OpenID Associations"));
        do_template("beginbox");
 
-       wprintf("FIXME -- we have to list the existing ones here");
+       serv_puts("OIDL");
+       serv_getln(buf, sizeof buf);
+       if (buf[0] == '1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
+               escputs(buf);
+               wprintf("<br />\n");
+       }
 
        wprintf("<hr>\n");