Fixed a potential memory leak (not to worry, it's
[citadel.git] / citadel / modules / openid / serv_openid_rp.c
1 /*
2  * $Id$
3  *
4  * This is an implementation of OpenID 1.1 Relying Party support, in stateless mode.
5  *
6  */
7
8 #include "sysdep.h"
9 #include <stdlib.h>
10 #include <unistd.h>
11 #include <stdio.h>
12 #include <fcntl.h>
13 #include <signal.h>
14 #include <pwd.h>
15 #include <errno.h>
16 #include <sys/types.h>
17
18 #if TIME_WITH_SYS_TIME
19 # include <sys/time.h>
20 # include <time.h>
21 #else
22 # if HAVE_SYS_TIME_H
23 #  include <sys/time.h>
24 # else
25 #  include <time.h>
26 # endif
27 #endif
28
29 #include <sys/wait.h>
30 #include <string.h>
31 #include <limits.h>
32 #include <curl/curl.h>
33 #include "ctdl_module.h"
34 #include "config.h"
35 #include "citserver.h"
36 #include "user_ops.h"
37
38 struct ctdl_openid {
39         char claimed_id[1024];
40         char server[1024];
41         int validated;
42 };
43
44
45
46
47
48 /**************************************************************************/
49 /*                                                                        */
50 /* Functions in this section handle Citadel internal OpenID mapping stuff */
51 /*                                                                        */
52 /**************************************************************************/
53
54
55 /*
56  * The structure of an openid record *key* is:
57  *
58  * |--------------claimed_id-------------|
59  *     (auctual length of claimed id)
60  *
61  *
62  * The structure of an openid record *value* is:
63  *
64  * |-----user_number----|------------claimed_id---------------|
65  *    (sizeof long)          (actual length of claimed id)
66  *
67  */
68
69
70 /*
71  * Attach an OpenID to a Citadel account
72  */
73 int attach_openid(struct ctdluser *who, char *claimed_id)
74 {
75         struct cdbdata *cdboi;
76         long fetched_usernum;
77         char *data;
78         int data_len;
79
80         if (!who) return(1);
81         if (!claimed_id) return(1);
82         if (IsEmptyStr(claimed_id)) return(1);
83
84         /* Check to see if this OpenID is already in the database */
85
86         cdboi = cdb_fetch(CDB_OPENID, claimed_id, strlen(claimed_id));
87         if (cdboi != NULL) {
88                 memcpy(&fetched_usernum, cdboi->ptr, sizeof(long));
89                 cdb_free(cdboi);
90
91                 if (fetched_usernum == who->usernum) {
92                         CtdlLogPrintf(CTDL_INFO, "%s already associated; no action is taken\n", claimed_id);
93                         return(0);
94                 }
95                 else {
96                         CtdlLogPrintf(CTDL_INFO, "%s already belongs to another user\n", claimed_id);
97                         return(3);
98                 }
99         }
100
101         /* Not already in the database, so attach it now */
102
103         data_len = sizeof(long) + strlen(claimed_id) + 1;
104         data = malloc(data_len);
105
106         memcpy(data, &who->usernum, sizeof(long));
107         memcpy(&data[sizeof(long)], claimed_id, strlen(claimed_id) + 1);
108
109         cdb_store(CDB_OPENID, claimed_id, strlen(claimed_id), data, data_len);
110         free(data);
111
112         CtdlLogPrintf(CTDL_INFO, "%s has been associated with %s (%ld)\n",
113                 claimed_id, who->fullname, who->usernum);
114         return(0);
115 }
116
117
118 /*
119  * When a user is being deleted, we have to delete any OpenID associations
120  */
121 void openid_purge(struct ctdluser *usbuf) {
122         struct cdbdata *cdboi;
123
124         cdb_rewind(CDB_OPENID);
125         while (cdboi = cdb_next_item(CDB_OPENID), cdboi != NULL) {
126                 if (cdboi->len > sizeof(long)) {
127                         if (((long)*(cdboi->ptr)) == usbuf->usernum) {
128                                 CtdlLogPrintf(CTDL_DEBUG, "FIXME we have to delete an openid\n");
129                         }
130                 }
131                 cdb_free(cdboi);
132         }
133
134         /* FIXME finish this */
135 }
136
137
138
139 /*
140  * List the OpenIDs associated with the currently logged in account
141  */
142 void cmd_oidl(char *argbuf) {
143         struct cdbdata *cdboi;
144
145         if (CtdlAccessCheck(ac_logged_in)) return;
146         cdb_rewind(CDB_OPENID);
147         cprintf("%d Associated OpenIDs:\n", LISTING_FOLLOWS);
148
149         while (cdboi = cdb_next_item(CDB_OPENID), cdboi != NULL) {
150                 if (cdboi->len > sizeof(long)) {
151                         if (((long)*(cdboi->ptr)) == CC->user.usernum) {
152                                 cprintf("%s\n", cdboi->ptr + sizeof(long));
153                         }
154                 }
155                 cdb_free(cdboi);
156         }
157         cprintf("000\n");
158 }
159
160
161
162 /*
163  * Detach an OpenID from the currently logged in account
164  */
165 void cmd_oidd(char *argbuf) {
166         struct cdbdata *cdboi;
167         char id_to_detach[1024];
168         int this_is_mine = 0;
169
170         if (CtdlAccessCheck(ac_logged_in)) return;
171         extract_token(id_to_detach, argbuf, 0, '|', sizeof id_to_detach);
172         if (IsEmptyStr(id_to_detach)) {
173                 cprintf("%d An empty OpenID URL is not allowed.\n", ERROR + ILLEGAL_VALUE);
174         }
175
176         cdb_rewind(CDB_OPENID);
177         while (cdboi = cdb_next_item(CDB_OPENID), cdboi != NULL) {
178                 if (cdboi->len > sizeof(long)) {
179                         if (((long)*(cdboi->ptr)) == CC->user.usernum) {
180                                 this_is_mine = 1;
181                         }
182                 }
183                 cdb_free(cdboi);
184         }
185
186         if (!this_is_mine) {
187                 cprintf("%d That OpenID was not found or not associated with your account.\n",
188                         ERROR + ILLEGAL_VALUE);
189                 return;
190         }
191
192         cdb_delete(CDB_OPENID, id_to_detach, strlen(id_to_detach));
193         cprintf("%d %s detached from your account.\n", CIT_OK, id_to_detach);
194 }
195
196
197
198 /*
199  * getuserbyopenid() works the same way as getuser() and getuserbynumber().
200  * If a user account exists which is associated with the Claimed ID, it fills usbuf and returns zero.
201  * Otherwise it returns nonzero.
202  */
203 int getuserbyopenid(struct ctdluser *usbuf, char *claimed_id)
204 {
205         struct cdbdata *cdboi;
206         long usernum = 0;
207
208         cdboi = cdb_fetch(CDB_OPENID, claimed_id, strlen(claimed_id));
209         if (cdboi == NULL) {
210                 return(-1);
211         }
212
213         memcpy(&usernum, cdboi->ptr, sizeof(long));
214         cdb_free(cdboi);
215
216         return(getuserbynumber(usbuf, usernum));
217 }
218
219
220
221 /**************************************************************************/
222 /*                                                                        */
223 /* Functions in this section handle OpenID protocol                       */
224 /*                                                                        */
225 /**************************************************************************/
226
227
228 /* 
229  * Locate a <link> tag and, given its 'rel=' parameter, return its 'href' parameter
230  */
231 void extract_link(char *target_buf, int target_size, char *rel, char *source_buf)
232 {
233         char *ptr = source_buf;
234
235         if (!target_buf) return;
236         if (!rel) return;
237         if (!source_buf) return;
238
239         target_buf[0] = 0;
240
241         while (ptr = bmstrcasestr(ptr, "<link"), ptr != NULL) {
242
243                 char work_buffer[2048];
244                 char *link_tag_start = NULL;
245                 char *link_tag_end = NULL;
246
247                 char rel_tag[2048];
248                 char href_tag[2048];
249
250                 link_tag_start = ptr;
251                 link_tag_end = strchr(ptr, '>');
252                 rel_tag[0] = 0;
253                 href_tag[0] = 0;
254
255                 if ((link_tag_end) && (link_tag_end > link_tag_start)) {
256                         int len;
257                         len = link_tag_end - link_tag_start;
258                         if (len > sizeof work_buffer) len = sizeof work_buffer;
259                         memcpy(work_buffer, link_tag_start, len);
260                 
261                         char *rel_start = NULL;
262                         char *rel_end = NULL;
263                         rel_start = bmstrcasestr(work_buffer, "rel=");
264                         if (rel_start) {
265                                 rel_start = strchr(rel_start, '\"');
266                                 if (rel_start) {
267                                         ++rel_start;
268                                         rel_end = strchr(rel_start, '\"');
269                                         if ((rel_end) && (rel_end > rel_start)) {
270                                                 safestrncpy(rel_tag, rel_start, rel_end - rel_start + 1);
271                                         }
272                                 }
273                         }
274
275                         char *href_start = NULL;
276                         char *href_end = NULL;
277                         href_start = bmstrcasestr(work_buffer, "href=");
278                         if (href_start) {
279                                 href_start = strchr(href_start, '\"');
280                                 if (href_start) {
281                                         ++href_start;
282                                         href_end = strchr(href_start, '\"');
283                                         if ((href_end) && (href_end > href_start)) {
284                                                 safestrncpy(href_tag, href_start, href_end - href_start + 1);
285                                         }
286                                 }
287                         }
288
289                         if (!strcasecmp(rel, rel_tag)) {
290                                 safestrncpy(target_buf, href_tag, target_size);
291                                 return;
292                         }
293
294                 }
295
296         ++ptr;
297         }
298
299
300 }
301
302
303
304 struct fh_data {
305         char *buf;
306         int total_bytes_received;
307         int maxbytes;
308 };
309
310
311 size_t fh_callback(void *ptr, size_t size, size_t nmemb, void *stream)
312 {
313         struct fh_data *fh = (struct fh_data *) stream;
314         int got_bytes = (size * nmemb);
315
316         if (fh->total_bytes_received + got_bytes > fh->maxbytes) {
317                 got_bytes = fh->maxbytes - fh->total_bytes_received;
318         }
319         if (got_bytes > 0) {
320                 memcpy(&fh->buf[fh->total_bytes_received], ptr, got_bytes);
321                 fh->total_bytes_received += got_bytes;
322         }
323
324         return (size * nmemb);  /* always succeed; libcurl doesn't need to know if we truncated it */
325 }
326
327
328
329 /*
330  * Begin an HTTP fetch (returns number of bytes actually fetched, or -1 for error) using libcurl.
331  *
332  * If 'normalize_len' is nonzero, the caller is specifying the buffer size of 'url', and is
333  * requesting that the effective (normalized) URL be copied back to it.
334  */
335 int fetch_http(char *url, char *target_buf, int maxbytes, int normalize_len)
336 {
337         CURL *curl;
338         CURLcode res;
339         char errmsg[1024] = "";
340         struct fh_data fh = {
341                 target_buf,
342                 0,
343                 maxbytes
344         };
345         char *effective_url = NULL;
346
347         if (!url) return(-1);
348         if (!target_buf) return(-1);
349         memset(target_buf, 0, maxbytes);
350
351         curl = curl_easy_init();
352         if (!curl) {
353                 CtdlLogPrintf(CTDL_ALERT, "Unable to initialize libcurl.\n");
354                 return(-1);
355         }
356
357         curl_easy_setopt(curl, CURLOPT_URL, url);
358         curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
359         curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0);
360         curl_easy_setopt(curl, CURLOPT_WRITEDATA, &fh);
361         curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, fh_callback);
362         curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errmsg);
363         curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
364         curl_easy_setopt(curl, CURLOPT_USERAGENT, CITADEL);
365         if (!IsEmptyStr(config.c_ip_addr)) {
366                 curl_easy_setopt(curl, CURLOPT_INTERFACE, config.c_ip_addr);
367         }
368         res = curl_easy_perform(curl);
369         if (res) {
370                 CtdlLogPrintf(CTDL_DEBUG, "fetch_http() libcurl error %d: %s\n", res, errmsg);
371         }
372         if (normalize_len > 0) {
373                 curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &effective_url);
374                 safestrncpy(url, effective_url, normalize_len);
375         }
376         curl_easy_cleanup(curl);
377         return fh.total_bytes_received;
378 }
379
380
381 /*
382  * Setup an OpenID authentication
383  */
384 void cmd_oids(char *argbuf) {
385         char return_to[1024];
386         char trust_root[1024];
387         int i;
388         char buf[SIZ];
389         struct CitContext *CCC = CC;    /* CachedCitContext - performance boost */
390         struct ctdl_openid *oiddata;
391
392         /* commented out because we may be attempting to attach an OpenID to
393          * an existing account that is logged in
394          *
395         if (CCC->logged_in) {
396                 cprintf("%d Already logged in.\n", ERROR + ALREADY_LOGGED_IN);
397                 return;
398         }
399          */
400
401         if (CCC->openid_data != NULL) {
402                 free(CCC->openid_data);
403         }
404         oiddata = malloc(sizeof(struct ctdl_openid));
405         if (oiddata == NULL) {
406                 cprintf("%d malloc failed\n", ERROR + INTERNAL_ERROR);
407                 return;
408         }
409         memset(oiddata, 0, sizeof(struct ctdl_openid));
410         CCC->openid_data = (void *) oiddata;
411
412         extract_token(oiddata->claimed_id, argbuf, 0, '|', sizeof oiddata->claimed_id);
413         extract_token(return_to, argbuf, 1, '|', sizeof return_to);
414         extract_token(trust_root, argbuf, 2, '|', sizeof trust_root);
415         oiddata->validated = 0;
416
417         i = fetch_http(oiddata->claimed_id, buf, sizeof buf - 1, sizeof oiddata->claimed_id);
418         CtdlLogPrintf(CTDL_DEBUG, "Normalized URL and Claimed ID is: %s\n", oiddata->claimed_id);
419         buf[sizeof buf - 1] = 0;
420         if (i > 0) {
421                 char openid_delegate[1024];
422
423                 extract_link(oiddata->server, sizeof oiddata->server, "openid.server", buf);
424                 extract_link(openid_delegate, sizeof openid_delegate, "openid.delegate", buf);
425
426                 if (IsEmptyStr(oiddata->server)) {
427                         cprintf("%d There is no OpenID identity provider at this URL.\n", ERROR);
428                         return;
429                 }
430
431                 /* Empty delegate is legal; we just use the openid_url instead */
432                 if (IsEmptyStr(openid_delegate)) {
433                         safestrncpy(openid_delegate, oiddata->claimed_id, sizeof openid_delegate);
434                 }
435
436                 /* Assemble a URL to which the user-agent will be redirected. */
437                 char redirect_string[4096];
438                 char escaped_identity[512];
439                 char escaped_return_to[2048];
440                 char escaped_trust_root[1024];
441                 char escaped_sreg_optional[256];
442
443                 urlesc(escaped_identity, sizeof escaped_identity, openid_delegate);
444                 urlesc(escaped_return_to, sizeof escaped_return_to, return_to);
445                 urlesc(escaped_trust_root, sizeof escaped_trust_root, trust_root);
446                 urlesc(escaped_sreg_optional, sizeof escaped_sreg_optional,
447                         "nickname,email,fullname,postcode,country");
448
449                 snprintf(redirect_string, sizeof redirect_string,
450                         "%s"
451                         "?openid.mode=checkid_setup"
452                         "&openid.identity=%s"
453                         "&openid.return_to=%s"
454                         "&openid.trust_root=%s"
455                         "&openid.sreg.optional=%s"
456                         ,
457                         oiddata->server,
458                         escaped_identity,
459                         escaped_return_to,
460                         escaped_trust_root,
461                         escaped_sreg_optional
462                 );
463                 cprintf("%d %s\n", CIT_OK, redirect_string);
464                 return;
465         }
466
467         cprintf("%d Unable to fetch OpenID URL\n", ERROR);
468 }
469
470
471
472 /*
473  * Callback function to free a pointer (used below in the hash list)
474  */
475 void free_oid_key(void *ptr) {
476         free(ptr);
477 }
478
479
480 /*
481  * Finalize an OpenID authentication
482  */
483 void cmd_oidf(char *argbuf) {
484         char buf[2048];
485         char thiskey[1024];
486         char thisdata[1024];
487         HashList *keys = NULL;
488         HashPos *HashPos;
489         struct ctdl_openid *oiddata = (struct ctdl_openid *) CC->openid_data;
490
491         keys = NewHash(1, NULL);
492         if (!keys) {
493                 cprintf("%d NewHash() failed\n", ERROR + INTERNAL_ERROR);
494                 return;
495         }
496         
497         cprintf("%d Transmit OpenID data now\n", START_CHAT_MODE);
498
499         while (client_getln(buf, sizeof buf), strcmp(buf, "000")) {
500                 extract_token(thiskey, buf, 0, '|', sizeof thiskey);
501                 extract_token(thisdata, buf, 1, '|', sizeof thisdata);
502                 CtdlLogPrintf(CTDL_DEBUG, "%s: [%d] %s\n", thiskey, strlen(thisdata), thisdata);
503                 Put(keys, thiskey, strlen(thiskey), strdup(thisdata), free_oid_key);
504         }
505
506
507         /* Now that we have all of the parameters, we have to validate the signature against the server */
508         CtdlLogPrintf(CTDL_DEBUG, "About to validate the signature...\n");
509
510         CURL *curl;
511         CURLcode res;
512         struct curl_httppost *formpost = NULL;
513         struct curl_httppost *lastptr = NULL;
514         char errmsg[1024] = "";
515         char *o_assoc_handle = NULL;
516         char *o_sig = NULL;
517         char *o_signed = NULL;
518         int num_signed_values;
519         int i;
520         char k_keyname[128];
521         char k_o_keyname[128];
522         char *k_value = NULL;
523         char valbuf[1024];
524
525         struct fh_data fh = {
526                 valbuf,
527                 0,
528                 sizeof valbuf
529         };
530
531         curl_formadd(&formpost, &lastptr,
532                 CURLFORM_COPYNAME,      "openid.mode",
533                 CURLFORM_COPYCONTENTS,  "check_authentication",
534                 CURLFORM_END);
535         CtdlLogPrintf(CTDL_DEBUG, "%25s : %s\n", "openid.mode", "check_authentication");
536
537         if (GetHash(keys, "assoc_handle", 12, (void *) &o_assoc_handle)) {
538                 curl_formadd(&formpost, &lastptr,
539                         CURLFORM_COPYNAME,      "openid.assoc_handle",
540                         CURLFORM_COPYCONTENTS,  o_assoc_handle,
541                         CURLFORM_END);
542                 CtdlLogPrintf(CTDL_DEBUG, "%25s : %s\n", "openid.assoc_handle", o_assoc_handle);
543         }
544
545         if (GetHash(keys, "sig", 3, (void *) &o_sig)) {
546                 curl_formadd(&formpost, &lastptr,
547                         CURLFORM_COPYNAME,      "openid.sig",
548                         CURLFORM_COPYCONTENTS,  o_sig,
549                         CURLFORM_END);
550                         CtdlLogPrintf(CTDL_DEBUG, "%25s : %s\n", "openid.sig", o_sig);
551         }
552
553         if (GetHash(keys, "signed", 6, (void *) &o_signed)) {
554                 curl_formadd(&formpost, &lastptr,
555                         CURLFORM_COPYNAME,      "openid.signed",
556                         CURLFORM_COPYCONTENTS,  o_signed,
557                         CURLFORM_END);
558                 CtdlLogPrintf(CTDL_DEBUG, "%25s : %s\n", "openid.signed", o_signed);
559
560                 num_signed_values = num_tokens(o_signed, ',');
561                 for (i=0; i<num_signed_values; ++i) {
562                         extract_token(k_keyname, o_signed, i, ',', sizeof k_keyname);
563                         if (strcasecmp(k_keyname, "mode")) {    // work around phpMyID bug
564                                 if (GetHash(keys, k_keyname, strlen(k_keyname), (void *) &k_value)) {
565                                         snprintf(k_o_keyname, sizeof k_o_keyname, "openid.%s", k_keyname);
566                                         curl_formadd(&formpost, &lastptr,
567                                                 CURLFORM_COPYNAME,      k_o_keyname,
568                                                 CURLFORM_COPYCONTENTS,  k_value,
569                                                 CURLFORM_END);
570                                         CtdlLogPrintf(CTDL_DEBUG, "%25s : %s\n", k_o_keyname, k_value);
571                                 }
572                                 else {
573                                         CtdlLogPrintf(CTDL_INFO, "OpenID: signed field '%s' is missing\n",
574                                                 k_keyname);
575                                 }
576                         }
577                 }
578         }
579
580         curl = curl_easy_init();
581         curl_easy_setopt(curl, CURLOPT_URL, oiddata->server);
582         curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
583         curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0);
584         curl_easy_setopt(curl, CURLOPT_WRITEDATA, &fh);
585         curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, fh_callback);
586         curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
587         curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errmsg);
588         curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
589         curl_easy_setopt(curl, CURLOPT_USERAGENT, CITADEL);
590         if (!IsEmptyStr(config.c_ip_addr)) {
591                 curl_easy_setopt(curl, CURLOPT_INTERFACE, config.c_ip_addr);
592         }
593
594         res = curl_easy_perform(curl);
595         if (res) {
596                 CtdlLogPrintf(CTDL_DEBUG, "cmd_oidf() libcurl error %d: %s\n", res, errmsg);
597         }
598         curl_easy_cleanup(curl);
599         curl_formfree(formpost);
600
601         valbuf[fh.total_bytes_received] = 0;
602
603         if (bmstrcasestr(valbuf, "is_valid:true")) {
604                 oiddata->validated = 1;
605         }
606
607         CtdlLogPrintf(CTDL_DEBUG, "Authentication %s.\n", (oiddata->validated ? "succeeded" : "failed") );
608
609         /* Respond to the client */
610
611         if (oiddata->validated) {
612
613                 /* If we were already logged in, attach the OpenID to the user's account */
614                 if (CC->logged_in) {
615                         if (attach_openid(&CC->user, oiddata->claimed_id) == 0) {
616                                 cprintf("attach\n");
617                         }
618                         else {
619                                 cprintf("fail\n");
620                         }
621                 }
622
623                 /* Otherwise, a user is attempting to log in using the validated OpenID */      
624                 else {
625                         struct ctdluser usbuf;
626
627                         /*
628                          * Existing user who has claimed this OpenID?
629                          *
630                          * Note: if you think that sending the password back over the wire is insecure,
631                          * check your assumptions.  If someone has successfully asserted an OpenID that
632                          * is associated with the account, they already have password equivalency and can
633                          * login, so they could just as easily change the password, etc.
634                          */
635                         if (getuserbyopenid(&usbuf, oiddata->claimed_id) == 0) {
636                                 cprintf("authenticate\n%s\n%s\n", usbuf.fullname, usbuf.password);
637                         }
638
639                         else {
640                                 cprintf("fail\n");              // FIXME do the login here!!
641                         }
642                 }
643         }
644         else {
645                 cprintf("fail\n");
646         }
647         cprintf("000\n");
648
649         /* Free the hash list */
650         long len;
651         void *Value;
652         char *Key;
653
654         HashPos = GetNewHashPos();
655         while (GetNextHashPos(keys, HashPos, &len, &Key, &Value)!=0)
656         {
657                 free(Value);
658         }
659         DeleteHashPos(&HashPos);
660 }
661
662
663 // mode = [6]  id_res
664 // identity = [50]  http://uncensored.citadel.org/~ajc/MyID.config.php
665 // assoc_handle = [26]  6ekac3ju181tgepk7v4h9r7ui7
666 // return_to = [42]  http://jemcaterers.net/finish_openid_login
667 // sreg.nickname = [17]  IGnatius T Foobar
668 // sreg.email = [26]  ajc@uncensored.citadel.org
669 // sreg.fullname = [10]  Art Cancro
670 // sreg.postcode = [5]  10549
671 // sreg.country = [2]  US
672 // signed = [102]  mode,identity,assoc_handle,return_to,sreg.nickname,sreg.email,sreg.fullname,sreg.postcode,sreg.country
673 // sig = [28]  vixxxU4MAqWfxxxxCfrHv3TxxxhEw=
674
675
676
677
678 /**************************************************************************/
679 /*                                                                        */
680 /* Functions in this section handle module initialization and shutdown    */
681 /*                                                                        */
682 /**************************************************************************/
683
684
685 /*
686  * This cleanup function blows away the temporary memory used by this module.
687  */
688 void openid_cleanup_function(void) {
689
690         if (CC->openid_data != NULL) {
691                 free(CC->openid_data);
692         }
693 }
694
695
696 CTDL_MODULE_INIT(openid_rp)
697 {
698         if (!threading)
699         {
700                 curl_global_init(CURL_GLOBAL_ALL);
701                 CtdlRegisterProtoHook(cmd_oids, "OIDS", "Setup OpenID authentication");
702                 CtdlRegisterProtoHook(cmd_oidf, "OIDF", "Finalize OpenID authentication");
703                 CtdlRegisterProtoHook(cmd_oidl, "OIDL", "List OpenIDs associated with an account");
704                 CtdlRegisterProtoHook(cmd_oidd, "OIDD", "Detach an OpenID from an account");
705                 CtdlRegisterSessionHook(openid_cleanup_function, EVT_STOP);
706                 CtdlRegisterUserHook(openid_purge, EVT_PURGEUSER);
707         }
708
709         /* return our Subversion id for the Log */
710         return "$Id$";
711 }
712
713
714 /* FIXME ... we have to add the new openid database to serv_vandelay.c */
715