X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=citadel%2Fmodules%2Fopenid%2Fserv_openid_rp.c;h=2e65c1acc2bdb76136603fe1cfed967e24529c7b;hb=8c47559cb5ae97ec0fa35660ee16fd61a9451c72;hp=d6bdedf07f61c0887e188f9f038cfc37b3fd193b;hpb=310a0b0cbc9e57eb652d0f2c4aef689ffb323219;p=citadel.git diff --git a/citadel/modules/openid/serv_openid_rp.c b/citadel/modules/openid/serv_openid_rp.c index d6bdedf07..2e65c1acc 100644 --- a/citadel/modules/openid/serv_openid_rp.c +++ b/citadel/modules/openid/serv_openid_rp.c @@ -3,6 +3,21 @@ * * This is an implementation of OpenID 1.1 Relying Party support, in stateless mode. * + * Copyright (c) 2007-2009 by the citadel.org team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "sysdep.h" @@ -132,6 +147,7 @@ void openid_purge(struct ctdluser *usbuf) { long len; void *Value; const char *Key; + long usernum = 0L; keys = NewHash(1, NULL); if (!keys) return; @@ -140,7 +156,8 @@ void openid_purge(struct ctdluser *usbuf) { cdb_rewind(CDB_OPENID); while (cdboi = cdb_next_item(CDB_OPENID), cdboi != NULL) { if (cdboi->len > sizeof(long)) { - if (((long)*(cdboi->ptr)) == usbuf->usernum) { + memcpy(&usernum, cdboi->ptr, sizeof(long)); + if (usernum == usbuf->usernum) { deleteme = strdup(cdboi->ptr + sizeof(long)), Put(keys, deleteme, strlen(deleteme), deleteme, generic_free_handler); } @@ -168,6 +185,7 @@ void openid_purge(struct ctdluser *usbuf) { */ void cmd_oidl(char *argbuf) { struct cdbdata *cdboi; + long usernum = 0L; if (CtdlAccessCheck(ac_logged_in)) return; cdb_rewind(CDB_OPENID); @@ -175,7 +193,8 @@ void cmd_oidl(char *argbuf) { while (cdboi = cdb_next_item(CDB_OPENID), cdboi != NULL) { if (cdboi->len > sizeof(long)) { - if (((long)*(cdboi->ptr)) == CC->user.usernum) { + memcpy(&usernum, cdboi->ptr, sizeof(long)); + if (usernum == CC->user.usernum) { cprintf("%s\n", cdboi->ptr + sizeof(long)); } } @@ -185,6 +204,36 @@ void cmd_oidl(char *argbuf) { } +/* + * List ALL OpenIDs in the database + */ +void cmd_oida(char *argbuf) { + struct cdbdata *cdboi; + long usernum; + struct ctdluser usbuf; + + if (CtdlAccessCheck(ac_aide)) return; + cdb_rewind(CDB_OPENID); + cprintf("%d List of all OpenIDs in the database:\n", LISTING_FOLLOWS); + + while (cdboi = cdb_next_item(CDB_OPENID), cdboi != NULL) { + if (cdboi->len > sizeof(long)) { + memcpy(&usernum, cdboi->ptr, sizeof(long)); + if (getuserbynumber(&usbuf, usernum) != 0) { + usbuf.fullname[0] = 0; + } + cprintf("%s|%ld|%s\n", + cdboi->ptr + sizeof(long), + usernum, + usbuf.fullname + ); + } + cdb_free(cdboi); + } + cprintf("000\n"); +} + + /* * Attempt to register (populate the vCard) the currently-logged-in user * using the data from Simple Registration Extension, if present. @@ -274,6 +323,11 @@ void populate_vcard_from_sreg(HashList *sreg_keys) { void cmd_oidc(char *argbuf) { struct ctdl_openid *oiddata = (struct ctdl_openid *) CC->openid_data; + if (!oiddata) { + cprintf("%d You have not verified an OpenID yet.\n", ERROR); + return; + } + if (!oiddata->verified) { cprintf("%d You have not verified an OpenID yet.\n", ERROR); return; @@ -304,6 +358,7 @@ void cmd_oidd(char *argbuf) { struct cdbdata *cdboi; char id_to_detach[1024]; int this_is_mine = 0; + long usernum = 0L; if (CtdlAccessCheck(ac_logged_in)) return; extract_token(id_to_detach, argbuf, 0, '|', sizeof id_to_detach); @@ -314,7 +369,8 @@ void cmd_oidd(char *argbuf) { cdb_rewind(CDB_OPENID); while (cdboi = cdb_next_item(CDB_OPENID), cdboi != NULL) { if (cdboi->len > sizeof(long)) { - if (((long)*(cdboi->ptr)) == CC->user.usernum) { + memcpy(&usernum, cdboi->ptr, sizeof(long)); + if (usernum == CC->user.usernum) { this_is_mine = 1; } } @@ -903,6 +959,7 @@ CTDL_MODULE_INIT(openid_rp) CtdlRegisterProtoHook(cmd_oidl, "OIDL", "List OpenIDs associated with an account"); CtdlRegisterProtoHook(cmd_oidd, "OIDD", "Detach an OpenID from an account"); CtdlRegisterProtoHook(cmd_oidc, "OIDC", "Create new user after validating OpenID"); + CtdlRegisterProtoHook(cmd_oida, "OIDA", "List all OpenIDs in the database"); } CtdlRegisterSessionHook(openid_cleanup_function, EVT_LOGOUT); CtdlRegisterUserHook(openid_purge, EVT_PURGEUSER);