From e005b5e8fb186efccfdbac57f3ac278f05b131d6 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Wed, 21 May 2008 21:43:26 +0000 Subject: [PATCH] * More work on OpenID 1.1 Relying Party support * Changed the startup order to put the citadel.control lock check happen *before* the databases are opened. Otherwise it can corrupt the databases before the lock check shuts it down. --- citadel/configure.ac | 2 +- citadel/control.c | 1 + citadel/modules/openid/serv_openid_rp.c | 52 +++++++++++++++++++--- citadel/modules/rssclient/serv_rssclient.c | 1 + citadel/server_main.c | 9 ++-- 5 files changed, 54 insertions(+), 11 deletions(-) diff --git a/citadel/configure.ac b/citadel/configure.ac index c36130b04..cd32b4496 100644 --- a/citadel/configure.ac +++ b/citadel/configure.ac @@ -624,7 +624,7 @@ AC_CHECK_HEADER(expat.h, dnl Checks for libcurl. AC_CHECK_HEADER(curl/curl.h, - [AC_CHECK_LIB(curl, curl_easy_init, + [AC_CHECK_LIB(curl, curl_version, [ SERVER_LIBS="-lcurl $SERVER_LIBS" ], diff --git a/citadel/control.c b/citadel/control.c index 671a9cc74..8da8192fa 100644 --- a/citadel/control.c +++ b/citadel/control.c @@ -172,6 +172,7 @@ void get_control(void) rewind(control_fp); fread(&CitControl, sizeof(struct CitControl), 1, control_fp); already_have_control = 1; + chown(file_citadel_control, config.c_ctdluid, (-1)); } /* diff --git a/citadel/modules/openid/serv_openid_rp.c b/citadel/modules/openid/serv_openid_rp.c index 05dbbd682..fc691246f 100644 --- a/citadel/modules/openid/serv_openid_rp.c +++ b/citadel/modules/openid/serv_openid_rp.c @@ -33,6 +33,16 @@ #include "ctdl_module.h" +struct associate_handle { + char claimed_id[256]; + char assoc_type[32]; + time_t expires_in; + char assoc_handle[128]; + char mac_key[128]; +}; + + + /* * Locate a tag and, given its 'rel=' parameter, return its 'href' parameter */ @@ -178,6 +188,36 @@ int fetch_http(char *url, char *target_buf, int maxbytes) } +#define ASSOCIATE_RESPONSE_SIZE 4096 + +/* + * libcurl callback function for prepare_openid_associate_request() + */ +size_t associate_callback(void *ptr, size_t size, size_t nmemb, void *stream) +{ + char *response = (char *) stream; + int got_bytes = (size * nmemb); + int len = strlen(response); + + if ((len + got_bytes + 1) < ASSOCIATE_RESPONSE_SIZE) { + memcpy(&response[len], ptr, got_bytes); + response[len+got_bytes] = 0; + } + + return got_bytes; +} + + +/* + * Process the response from an "associate" request + */ +void process_associate_response(associate_response) +{ + // FIXME finish this +} + + + /* * Establish a shared secret with an OpenID Identity Provider by sending * an "associate" request. @@ -188,6 +228,9 @@ void prepare_openid_associate_request(char *openid_server, char *openid_delegate CURLcode res; struct curl_httppost *formpost=NULL; struct curl_httppost *lastptr=NULL; + char associate_response[ASSOCIATE_RESPONSE_SIZE]; + + memset(associate_response, 0, ASSOCIATE_RESPONSE_SIZE); curl_formadd(&formpost, &lastptr, @@ -208,16 +251,13 @@ void prepare_openid_associate_request(char *openid_server, char *openid_delegate curl_easy_setopt(curl, CURLOPT_URL, openid_server); curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0); curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0); - //curl_easy_setopt(curl, CURLOPT_WRITEDATA, &fh); - //curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, fh_callback); - //curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errmsg); + curl_easy_setopt(curl, CURLOPT_WRITEDATA, associate_response); + curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, associate_callback); curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1); curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost); res = curl_easy_perform(curl); - - // FIXME not finished - + process_associate_response(associate_response); curl_easy_cleanup(curl); } curl_formfree(formpost); diff --git a/citadel/modules/rssclient/serv_rssclient.c b/citadel/modules/rssclient/serv_rssclient.c index f176ae7c5..4db28dbb5 100644 --- a/citadel/modules/rssclient/serv_rssclient.c +++ b/citadel/modules/rssclient/serv_rssclient.c @@ -557,6 +557,7 @@ CTDL_MODULE_INIT(rssclient) { if (threading) { + CtdlLogPrintf(CTDL_INFO, "%s\n", curl_version()); CtdlThreadSchedule ("RSS Client", CTDLTHREAD_BIGSTACK, rssclient_scan, NULL, 0); } /* return our Subversion id for the Log */ diff --git a/citadel/server_main.c b/citadel/server_main.c index 37c77ddcd..be547e12e 100644 --- a/citadel/server_main.c +++ b/citadel/server_main.c @@ -214,6 +214,10 @@ int main(int argc, char **argv) CtdlLogPrintf(CTDL_INFO, "Loading citadel.config\n"); get_config(); config.c_ipgm_secret = rand(); + + CtdlLogPrintf(CTDL_INFO, "Acquiring control record\n"); + get_control(); + put_config(); #ifdef HAVE_RUN_DIR @@ -244,11 +248,8 @@ int main(int argc, char **argv) */ master_startup(); - CtdlLogPrintf(CTDL_INFO, "Acquiring control record\n"); - get_control(); - -/** +/* * Initialise the user 0 to have a name. It would be nice to do it in InitializeMasterCC * since it is contained within the MasterCC but we can't because the DB isn't available * at that time so we do it seperate. -- 2.30.2