From: Art Cancro Date: Thu, 29 May 2008 20:16:11 +0000 (+0000) Subject: Began writing some code to associate OpenIDs with Citadel accounts X-Git-Tag: v7.86~2192 X-Git-Url: https://code.citadel.org/?a=commitdiff_plain;h=54b083bf78b5f0febc0777409953006ff6c864da;hp=cdda425c8f976595723ede8c5b461c090822214b;p=citadel.git Began writing some code to associate OpenIDs with Citadel accounts --- diff --git a/citadel/database_cleanup.sh.in b/citadel/database_cleanup.sh.in index 0d3aeb93d..f7deb835e 100755 --- a/citadel/database_cleanup.sh.in +++ b/citadel/database_cleanup.sh.in @@ -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 diff --git a/citadel/modules/openid/serv_openid_rp.c b/citadel/modules/openid/serv_openid_rp.c index c6765517f..d1418a246 100644 --- a/citadel/modules/openid/serv_openid_rp.c +++ b/citadel/modules/openid/serv_openid_rp.c @@ -32,6 +32,7 @@ #include #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 */ diff --git a/citadel/server.h b/citadel/server.h index 1c2af0e4f..1d4457dac 100644 --- a/citadel/server.h +++ b/citadel/server.h @@ -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 */ }; diff --git a/webcit/openid.c b/webcit/openid.c index b94f0fbc3..21ffa595a 100644 --- a/webcit/openid.c +++ b/webcit/openid.c @@ -10,6 +10,8 @@ */ void display_openids(void) { + char buf[1024]; + output_headers(1, 1, 1, 0, 0, 0); wprintf("
"); @@ -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("
\n"); + } wprintf("
\n");