]> code.citadel.org Git - citadel.git/blobdiff - citadel/modules/openid/serv_openid_rp.c
Began laying the framework for creating new users with OpenID
[citadel.git] / citadel / modules / openid / serv_openid_rp.c
index 2f8de996827756e6b603882fb76bdee1c30d1ef9..d0515618a8b89b036bc1e8f4040d1c1e3f276eb0 100644 (file)
@@ -56,7 +56,7 @@ struct ctdl_openid {
  * The structure of an openid record *key* is:
  *
  * |--------------claimed_id-------------|
- *     (auctual length of claimed id)
+ *     (actual length of claimed id)
  *
  *
  * The structure of an openid record *value* is:
@@ -67,6 +67,7 @@ struct ctdl_openid {
  */
 
 
+
 /*
  * Attach an OpenID to a Citadel account
  */
@@ -120,18 +121,39 @@ int attach_openid(struct ctdluser *who, char *claimed_id)
  */
 void openid_purge(struct ctdluser *usbuf) {
        struct cdbdata *cdboi;
+       HashList *keys = NULL;
+       HashPos *HashPos;
+       char *deleteme = NULL;
+       long len;
+       void *Value;
+       char *Key;
+
+       keys = NewHash(1, NULL);
+       if (!keys) return;
+
 
        cdb_rewind(CDB_OPENID);
        while (cdboi = cdb_next_item(CDB_OPENID), cdboi != NULL) {
                if (cdboi->len > sizeof(long)) {
                        if (((long)*(cdboi->ptr)) == usbuf->usernum) {
-                               CtdlLogPrintf(CTDL_DEBUG, "FIXME we have to delete an openid\n");
+                               deleteme = strdup(cdboi->ptr + sizeof(long)),
+                               Put(keys, deleteme, strlen(deleteme), deleteme, generic_free_handler);
                        }
                }
                cdb_free(cdboi);
        }
 
-       /* FIXME finish this */
+       /* Go through the hash list, deleting keys we stored in it */
+
+       HashPos = GetNewHashPos();
+       while (GetNextHashPos(keys, HashPos, &len, &Key, &Value)!=0)
+       {
+               CtdlLogPrintf(CTDL_DEBUG, "Deleting associated OpenID <%s>\n", Value);
+               cdb_delete(CDB_OPENID, Value, strlen(Value));
+               /* note: don't free(Value) -- deleting the hash list will handle this for us */
+       }
+       DeleteHashPos(&HashPos);
+       DeleteHash(&keys);
 }
 
 
@@ -218,6 +240,17 @@ int getuserbyopenid(struct ctdluser *usbuf, char *claimed_id)
 
 
 
+int openid_create_user_via_sri(struct ctdluser *usbuf, char *claimed_id, HashList *sri_keys)
+{
+       if (config.c_auth_mode != AUTHMODE_NATIVE) return(1);
+       if (config.c_disable_newu) return(2);
+
+       /* FIXME do something */
+
+       return(99);
+}
+
+
 /**************************************************************************/
 /*                                                                        */
 /* Functions in this section handle OpenID protocol                       */
@@ -469,12 +502,6 @@ void cmd_oids(char *argbuf) {
 
 
 
-/*
- * Callback function to free a pointer (used below in the hash list)
- */
-void free_oid_key(void *ptr) {
-       free(ptr);
-}
 
 
 /*
@@ -485,7 +512,6 @@ void cmd_oidf(char *argbuf) {
        char thiskey[1024];
        char thisdata[1024];
        HashList *keys = NULL;
-       HashPos *HashPos;
        struct ctdl_openid *oiddata = (struct ctdl_openid *) CC->openid_data;
 
        keys = NewHash(1, NULL);
@@ -500,7 +526,7 @@ void cmd_oidf(char *argbuf) {
                extract_token(thiskey, buf, 0, '|', sizeof thiskey);
                extract_token(thisdata, buf, 1, '|', sizeof thisdata);
                CtdlLogPrintf(CTDL_DEBUG, "%s: [%d] %s\n", thiskey, strlen(thisdata), thisdata);
-               Put(keys, thiskey, strlen(thiskey), strdup(thisdata), free_oid_key);
+               Put(keys, thiskey, strlen(thiskey), strdup(thisdata), generic_free_handler);
        }
 
 
@@ -636,8 +662,17 @@ void cmd_oidf(char *argbuf) {
                                cprintf("authenticate\n%s\n%s\n", usbuf.fullname, usbuf.password);
                        }
 
+                       /*
+                        * New user whose OpenID is verified and Simple Registration Extension is in use?
+                        */
+                       else if (openid_create_user_via_sri(&usbuf, oiddata->claimed_id, keys) == 0) {
+                               cprintf("authenticate\n%s\n%s\n", usbuf.fullname, usbuf.password);
+                       }
+
+                       /* FIXME right here we have to handle manual account creation */
+
                        else {
-                               cprintf("fail\n");              // FIXME do the login here!!
+                               cprintf("fail\n");
                        }
                }
        }
@@ -646,17 +681,21 @@ void cmd_oidf(char *argbuf) {
        }
        cprintf("000\n");
 
-       /* Free the hash list */
+       /*
+        * We will eventually do something with the data in the hash list.
+        *
        long len;
        void *Value;
        char *Key;
-
+       HashPos *HashPos;
        HashPos = GetNewHashPos();
        while (GetNextHashPos(keys, HashPos, &len, &Key, &Value)!=0)
        {
-               free(Value);
        }
        DeleteHashPos(&HashPos);
+        */
+
+       DeleteHash(&keys);              /* This will free() all the key data for us */
 }