]> code.citadel.org Git - citadel.git/blobdiff - citadel/modules/openid/serv_openid_rp.c
* follo hashiterator api-change
[citadel.git] / citadel / modules / openid / serv_openid_rp.c
index 44f087d8016df1486c8366f0f9799e7045ccd393..c911bda9b626aa005797b9e12b4b0082cac277a0 100644 (file)
@@ -78,6 +78,7 @@ int attach_openid(struct ctdluser *who, char *claimed_id)
        long fetched_usernum;
        char *data;
        int data_len;
+       char buf[2048];
 
        if (!who) return(1);
        if (!claimed_id) return(1);
@@ -111,8 +112,10 @@ int attach_openid(struct ctdluser *who, char *claimed_id)
        cdb_store(CDB_OPENID, claimed_id, strlen(claimed_id), data, data_len);
        free(data);
 
-       CtdlLogPrintf(CTDL_INFO, "%s has been attached to %s (%ld)\n",
-               claimed_id, who->fullname, who->usernum);
+       snprintf(buf, sizeof buf, "User <%s> (#%ld) has claimed the OpenID URL %s\n",
+               who->fullname, who->usernum, claimed_id);
+       aide_message(buf, "OpenID claim");
+       CtdlLogPrintf(CTDL_INFO, "%s", buf);
        return(0);
 }
 
@@ -147,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);
@@ -251,20 +254,12 @@ void populate_vcard_from_sreg(HashList *sreg_keys) {
 
        /* Only save the vCard if there is some useful data in it */
        if (pop > 0) {
-               char temp[PATH_MAX];
-               FILE *fp;
                char *ser;
-       
-               CtdlMakeTempFileName(temp, sizeof temp);
                ser = vcard_serialize(v);
                if (ser) {
-                       fp = fopen(temp, "w");
-                       if (fp) {
-                               fwrite(ser, strlen(ser), 1, fp);
-                               fclose(fp);
-                               CtdlWriteObject(USERCONFIGROOM, "text/x-vcard", temp, &CC->user, 0, 0, 0);
-                               unlink(temp);
-                       }
+                       CtdlWriteObject(USERCONFIGROOM, "text/x-vcard",
+                               ser, strlen(ser)+1, &CC->user, 0, 0, 0
+                       );
                        free(ser);
                }
        }
@@ -809,6 +804,14 @@ void cmd_oidf(char *argbuf) {
                                logged_in_response();
                        }
 
+                       /*
+                        * If this system does not allow self-service new user registration, the
+                        * remaining modes do not apply, so fail here and now.
+                        */
+                       else if (config.c_disable_newu) {
+                               cprintf("fail\n");
+                       }
+
                        /*
                         * New user whose OpenID is verified and Simple Registration Extension is in use?
                         */
@@ -874,14 +877,17 @@ void openid_cleanup_function(void) {
 
 CTDL_MODULE_INIT(openid_rp)
 {
-       if (!threading)
-       {
+       if (!threading) {
                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");
-               CtdlRegisterProtoHook(cmd_oidd, "OIDD", "Detach an OpenID from an account");
-               CtdlRegisterProtoHook(cmd_oidc, "OIDC", "Create a new user after validating an OpenID");
+
+               /* Only enable the OpenID command set when native mode authentication is in use. */
+               if (config.c_auth_mode == AUTHMODE_NATIVE) {
+                       CtdlRegisterProtoHook(cmd_oids, "OIDS", "Setup OpenID authentication");
+                       CtdlRegisterProtoHook(cmd_oidf, "OIDF", "Finalize OpenID authentication");
+                       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");
+               }
                CtdlRegisterSessionHook(openid_cleanup_function, EVT_LOGOUT);
                CtdlRegisterUserHook(openid_purge, EVT_PURGEUSER);
        }