]> code.citadel.org Git - citadel.git/blobdiff - citadel/modules/openid/serv_openid_rp.c
here be more migration
[citadel.git] / citadel / modules / openid / serv_openid_rp.c
index c8824ccf682b313e2f17ca9ace38c04fb892665d..748da3bed81af4be1ee30a0e849bb4275ec343d5 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This is an implementation of OpenID 2.0 relying party support in stateless mode.
  *
- * Copyright (c) 2007-2011 by the citadel.org team
+ * Copyright (c) 2007-2015 by the citadel.org team
  *
  * This program is open source software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -211,7 +211,14 @@ void cmd_oidl(char *argbuf) {
        struct cdbdata *cdboi;
        long usernum = 0L;
 
+       if (CtdlGetConfigInt("c_disable_newu"))
+       {
+               cprintf("%d this system does not support openid.\n",
+                       ERROR + CMD_NOT_SUPPORTED);
+               return;
+       }
        if (CtdlAccessCheck(ac_logged_in)) return;
+
        cdb_rewind(CDB_OPENID);
        cprintf("%d Associated OpenIDs:\n", LISTING_FOLLOWS);
 
@@ -236,6 +243,12 @@ void cmd_oida(char *argbuf) {
        long usernum;
        struct ctdluser usbuf;
 
+       if (CtdlGetConfigInt("c_disable_newu"))
+       {
+               cprintf("%d this system does not support openid.\n",
+                       ERROR + CMD_NOT_SUPPORTED);
+               return;
+       }
        if (CtdlAccessCheck(ac_aide)) return;
        cdb_rewind(CDB_OPENID);
        cprintf("%d List of all OpenIDs in the database:\n", LISTING_FOLLOWS);
@@ -265,6 +278,12 @@ void cmd_oida(char *argbuf) {
 void cmd_oidc(char *argbuf) {
        ctdl_openid *oiddata = (ctdl_openid *) CC->openid_data;
 
+       if (CtdlGetConfigInt("c_disable_newu"))
+       {
+               cprintf("%d this system does not support openid.\n",
+                       ERROR + CMD_NOT_SUPPORTED);
+               return;
+       }
        if ( (!oiddata) || (!oiddata->verified) ) {
                cprintf("%d You have not verified an OpenID yet.\n", ERROR);
                return;
@@ -292,6 +311,12 @@ void cmd_oidd(char *argbuf) {
        int this_is_mine = 0;
        long usernum = 0L;
 
+       if (CtdlGetConfigInt("c_disable_newu"))
+       {
+               cprintf("%d this system does not support openid.\n",
+                       ERROR + CMD_NOT_SUPPORTED);
+               return;
+       }
        if (CtdlAccessCheck(ac_logged_in)) return;
        extract_token(id_to_detach, argbuf, 0, '|', sizeof id_to_detach);
        if (IsEmptyStr(id_to_detach)) {
@@ -333,8 +358,8 @@ int openid_create_user_via_ax(StrBuf *claimed_id, HashList *sreg_keys)
        const char *Key;
        void *Value;
 
-       if (config.c_auth_mode != AUTHMODE_NATIVE) return(1);
-       if (config.c_disable_newu) return(2);
+       if (CtdlGetConfigInt("c_auth_mode") != AUTHMODE_NATIVE) return(1);
+       if (CtdlGetConfigInt("c_disable_newu")) return(2);
        if (CC->logged_in) return(3);
 
        HashPos *HashPos = GetNewHashPos(sreg_keys, 0);
@@ -528,12 +553,12 @@ CURL *ctdl_openid_curl_easy_init(char *errmsg) {
        curl_easy_setopt(curl, CURLOPT_TIMEOUT, 30);            /* die after 30 seconds */
 
        if (
-               (!IsEmptyStr(config.c_ip_addr))
-               && (strcmp(config.c_ip_addr, "*"))
-               && (strcmp(config.c_ip_addr, "::"))
-               && (strcmp(config.c_ip_addr, "0.0.0.0"))
+               (!IsEmptyStr(CtdlGetConfigStr("c_ip_addr")))
+               && (strcmp(CtdlGetConfigStr("c_ip_addr"), "*"))
+               && (strcmp(CtdlGetConfigStr("c_ip_addr"), "::"))
+               && (strcmp(CtdlGetConfigStr("c_ip_addr"), "0.0.0.0"))
        ) {
-               curl_easy_setopt(curl, CURLOPT_INTERFACE, config.c_ip_addr);
+               curl_easy_setopt(curl, CURLOPT_INTERFACE, CtdlGetConfigStr("c_ip_addr"));
        }
 
        return(curl);
@@ -807,6 +832,12 @@ void cmd_oids(char *argbuf) {
        ctdl_openid *oiddata;
        int discovery_succeeded = 0;
 
+       if (CtdlGetConfigInt("c_disable_newu"))
+       {
+               cprintf("%d this system does not support openid.\n",
+                       ERROR + CMD_NOT_SUPPORTED);
+               return;
+       }
        Free_ctdl_openid ((ctdl_openid**)&CCC->openid_data);
 
        CCC->openid_data = oiddata = malloc(sizeof(ctdl_openid));
@@ -932,6 +963,12 @@ void cmd_oidf(char *argbuf) {
        void *Value;
        ctdl_openid *oiddata = (ctdl_openid *) CC->openid_data;
 
+       if (CtdlGetConfigInt("c_disable_newu"))
+       {
+               cprintf("%d this system does not support openid.\n",
+                       ERROR + CMD_NOT_SUPPORTED);
+               return;
+       }
        if (oiddata == NULL) {
                cprintf("%d run OIDS first.\n", ERROR + INTERNAL_ERROR);
                return;
@@ -1071,7 +1108,7 @@ void cmd_oidf(char *argbuf) {
                         * 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) {
+                       else if (CtdlGetConfigInt("c_disable_newu")) {
                                cprintf("fail\n");
                                syslog(LOG_DEBUG, "Creating user failed due to local policy");
                        }
@@ -1129,10 +1166,10 @@ void cmd_oidf(char *argbuf) {
 CTDL_MODULE_INIT(openid_rp)
 {
        if (!threading) {
-               curl_global_init(CURL_GLOBAL_ALL);
+// evcurl call this for us. curl_global_init(CURL_GLOBAL_ALL);
 
                /* Only enable the OpenID command set when native mode authentication is in use. */
-               if (config.c_auth_mode == AUTHMODE_NATIVE) {
+               if (CtdlGetConfigInt("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");
@@ -1140,7 +1177,7 @@ CTDL_MODULE_INIT(openid_rp)
                        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);
+               CtdlRegisterSessionHook(openid_cleanup_function, EVT_LOGOUT, PRIO_LOGOUT + 10);
                CtdlRegisterUserHook(openid_purge, EVT_PURGEUSER);
                openid_level_supported = 1;     /* This module supports OpenID 1.0 only */
        }