/* * List ALL OpenIDs in the database */ void cmd_oida(char *argbuf) { struct cdbdata *cdboi; long usernum; struct ctdluser usbuf; if (CtdlGetConfigInt("c_disable_newu")) { cprintf("%d this system does not support openid.\n", ERROR + CMD_NOT_SUPPORTED); return; } 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 (CtdlGetUserByNumber(&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"); }
/* * get the name of the room admin for this room */ void cmd_geta(char *cmdbuf) { struct ctdluser usbuf; if (CtdlAccessCheck(ac_logged_in)) return; if (CtdlGetUserByNumber(&usbuf, CC->room.QRroomaide) == 0) { cprintf("%d %s\n", CIT_OK, usbuf.fullname); } else { cprintf("%d \n", CIT_OK); } }
/* * Purge OpenID assocations for missing users (theoretically this will never delete anything) */ int PurgeStaleOpenIDassociations(void) { struct cdbdata *cdboi; struct ctdluser usbuf; HashList *keys = NULL; HashPos *HashPos; char *deleteme = NULL; long len; void *Value; const char *Key; int num_deleted = 0; long usernum = 0L; keys = NewHash(1, NULL); if (!keys) return(0); cdb_rewind(CDB_OPENID); while (cdboi = cdb_next_item(CDB_OPENID), cdboi != NULL) { if (cdboi->len > sizeof(long)) { memcpy(&usernum, cdboi->ptr, sizeof(long)); if (CtdlGetUserByNumber(&usbuf, usernum) != 0) { deleteme = strdup(cdboi->ptr + sizeof(long)), Put(keys, deleteme, strlen(deleteme), deleteme, NULL); } } cdb_free(cdboi); } /* Go through the hash list, deleting keys we stored in it */ HashPos = GetNewHashPos(keys, 0); while (GetNextHashPos(keys, HashPos, &len, &Key, &Value)!=0) { syslog(LOG_DEBUG, "Deleting associated OpenID <%s>", (char*)Value); cdb_delete(CDB_OPENID, Value, strlen(Value)); /* note: don't free(Value) -- deleting the hash list will handle this for us */ ++num_deleted; } DeleteHashPos(&HashPos); DeleteHash(&keys); return num_deleted; }
/* * If a user account exists which is associated with the Claimed ID, log it in and return zero. * Otherwise it returns nonzero. */ int login_via_openid(StrBuf *claimed_id) { struct cdbdata *cdboi; long usernum = 0; cdboi = cdb_fetch(CDB_OPENID, ChrPtr(claimed_id), StrLength(claimed_id)); if (cdboi == NULL) { return(-1); } memcpy(&usernum, cdboi->ptr, sizeof(long)); cdb_free(cdboi); if (!CtdlGetUserByNumber(&CC->user, usernum)) { /* Now become the user we just created */ safestrncpy(CC->curr_user, CC->user.fullname, sizeof CC->curr_user); do_login(); return(0); } else { memset(&CC->user, 0, sizeof(struct ctdluser)); return(-1); } }