]> code.citadel.org Git - citadel.git/blobdiff - citadel/modules/openid/serv_openid_rp.c
* Add the account name to oida
[citadel.git] / citadel / modules / openid / serv_openid_rp.c
index 02c0eee40f68eb613a0bf7b8c70cf0929abd7cc5..603efac2a423a3ccdb6085bbc958631c27d7af35 100644 (file)
@@ -185,6 +185,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 +304,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;
@@ -540,6 +575,10 @@ int fetch_http(char *url, char *target_buf, int maxbytes, int normalize_len)
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, fh_callback);
        curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errmsg);
        curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
+#ifdef CURLOPT_HTTP_CONTENT_DECODING
+       curl_easy_setopt(curl, CURLOPT_HTTP_CONTENT_DECODING, 1);
+       curl_easy_setopt(curl, CURLOPT_ENCODING, "");
+#endif
        curl_easy_setopt(curl, CURLOPT_USERAGENT, CITADEL);
        curl_easy_setopt(curl, CURLOPT_TIMEOUT, 180);           /* die after 180 seconds */
        if (!IsEmptyStr(config.c_ip_addr)) {
@@ -756,6 +795,10 @@ void cmd_oidf(char *argbuf) {
        curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
        curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errmsg);
        curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
+#ifdef CURLOPT_HTTP_CONTENT_DECODING
+       curl_easy_setopt(curl, CURLOPT_HTTP_CONTENT_DECODING, 1);
+       curl_easy_setopt(curl, CURLOPT_ENCODING, "");
+#endif
        curl_easy_setopt(curl, CURLOPT_USERAGENT, CITADEL);
        curl_easy_setopt(curl, CURLOPT_TIMEOUT, 180);           /* die after 180 seconds */
        if (!IsEmptyStr(config.c_ip_addr)) {
@@ -785,9 +828,11 @@ void cmd_oidf(char *argbuf) {
                if (CC->logged_in) {
                        if (attach_openid(&CC->user, oiddata->claimed_id) == 0) {
                                cprintf("attach\n");
+                               CtdlLogPrintf(CTDL_DEBUG, "OpenID attach succeeded\n");
                        }
                        else {
                                cprintf("fail\n");
+                               CtdlLogPrintf(CTDL_DEBUG, "OpenID attach failed\n");
                        }
                }
 
@@ -804,6 +849,7 @@ void cmd_oidf(char *argbuf) {
                        if (login_via_openid(oiddata->claimed_id) == 0) {
                                cprintf("authenticate\n%s\n%s\n", CC->user.fullname, CC->user.password);
                                logged_in_response();
+                               CtdlLogPrintf(CTDL_DEBUG, "Logged in using previously claimed OpenID\n");
                        }
 
                        /*
@@ -812,6 +858,7 @@ void cmd_oidf(char *argbuf) {
                         */
                        else if (config.c_disable_newu) {
                                cprintf("fail\n");
+                               CtdlLogPrintf(CTDL_DEBUG, "Creating user failed due to local policy\n");
                        }
 
                        /*
@@ -820,6 +867,7 @@ void cmd_oidf(char *argbuf) {
                        else if (openid_create_user_via_sreg(oiddata->claimed_id, keys) == 0) {
                                cprintf("authenticate\n%s\n%s\n", CC->user.fullname, CC->user.password);
                                logged_in_response();
+                               CtdlLogPrintf(CTDL_DEBUG, "Successfully auto-created new user\n");
                        }
 
                        /*
@@ -836,6 +884,7 @@ void cmd_oidf(char *argbuf) {
                                else {
                                        cprintf("\n");
                                }
+                               CtdlLogPrintf(CTDL_DEBUG, "The desired Simple Registration name is already taken.\n");
                        }
                }
        }
@@ -889,6 +938,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);