]> code.citadel.org Git - citadel.git/blobdiff - citadel/modules/openid/serv_openid_rp.c
* Added a command OIDA to dump all OpenID associations
[citadel.git] / citadel / modules / openid / serv_openid_rp.c
index 2fb909784a37cb1e940594f113aebd0497e7b107..2429a267082651edd8ac3901f18aa4582ef36b78 100644 (file)
@@ -131,7 +131,7 @@ void openid_purge(struct ctdluser *usbuf) {
        char *deleteme = NULL;
        long len;
        void *Value;
-       char *Key;
+       const char *Key;
 
        keys = NewHash(1, NULL);
        if (!keys) return;
@@ -150,7 +150,7 @@ void openid_purge(struct ctdluser *usbuf) {
 
        /* Go through the hash list, deleting keys we stored in it */
 
-       HashPos = GetNewHashPos();
+       HashPos = GetNewHashPos(keys, 0);
        while (GetNextHashPos(keys, HashPos, &len, &Key, &Value)!=0)
        {
                CtdlLogPrintf(CTDL_DEBUG, "Deleting associated OpenID <%s>\n", Value);
@@ -185,6 +185,31 @@ void cmd_oidl(char *argbuf) {
 }
 
 
+/*
+ * List ALL OpenIDs in the database
+ */
+void cmd_oida(char *argbuf) {
+       struct cdbdata *cdboi;
+       long usernum;
+
+       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));
+                       cprintf("%s|%ld\n",
+                               cdboi->ptr + sizeof(long),
+                               usernum
+                       );
+               }
+               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 +299,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,7 +570,12 @@ 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)) {
                curl_easy_setopt(curl, CURLOPT_INTERFACE, config.c_ip_addr);
        }
@@ -755,7 +790,12 @@ 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)) {
                curl_easy_setopt(curl, CURLOPT_INTERFACE, config.c_ip_addr);
        }
@@ -783,9 +823,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");
                        }
                }
 
@@ -802,6 +844,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");
                        }
 
                        /*
@@ -810,6 +853,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");
                        }
 
                        /*
@@ -818,6 +862,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");
                        }
 
                        /*
@@ -834,6 +879,7 @@ void cmd_oidf(char *argbuf) {
                                else {
                                        cprintf("\n");
                                }
+                               CtdlLogPrintf(CTDL_DEBUG, "The desired Simple Registration name is already taken.\n");
                        }
                }
        }
@@ -887,6 +933,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);