summaryrefslogtreecommitdiff
path: root/src/authorization
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2021-08-16 11:36:14 +0200
committerChristian Grothoff <christian@grothoff.org>2021-08-16 11:36:14 +0200
commitb2d9f5936b7e867180199771c9e47c6d95ec8b8a (patch)
treecfda3db1cf0a6921f88d20925ed74f2cd427fcd6 /src/authorization
parent7bed96f8e479af98db1a8a0c71b7c2ff2dc2b564 (diff)
downloadanastasis-b2d9f5936b7e867180199771c9e47c6d95ec8b8a.tar.gz
anastasis-b2d9f5936b7e867180199771c9e47c6d95ec8b8a.tar.bz2
anastasis-b2d9f5936b7e867180199771c9e47c6d95ec8b8a.zip
-pass db handle to auth plugins
Diffstat (limited to 'src/authorization')
-rw-r--r--src/authorization/anastasis_authorization_plugin.c12
-rw-r--r--src/authorization/anastasis_authorization_plugin_email.c9
-rw-r--r--src/authorization/anastasis_authorization_plugin_file.c6
-rw-r--r--src/authorization/anastasis_authorization_plugin_iban.c37
-rw-r--r--src/authorization/anastasis_authorization_plugin_post.c10
-rw-r--r--src/authorization/anastasis_authorization_plugin_sms.c9
6 files changed, 54 insertions, 29 deletions
diff --git a/src/authorization/anastasis_authorization_plugin.c b/src/authorization/anastasis_authorization_plugin.c
index da28f40..6683ff3 100644
--- a/src/authorization/anastasis_authorization_plugin.c
+++ b/src/authorization/anastasis_authorization_plugin.c
@@ -20,7 +20,7 @@
* @author Dominik Meister
*/
#include "platform.h"
-#include "anastasis_authorization_plugin.h"
+#include "anastasis_authorization_lib.h"
#include <ltdl.h>
@@ -66,12 +66,18 @@ struct AuthPlugin
*/
char *lib_name;
+ /**
+ * Authorization context passed to the plugin.
+ */
+ struct ANASTASIS_AuthorizationContext ac;
+
};
struct ANASTASIS_AuthorizationPlugin *
ANASTASIS_authorization_plugin_load (
const char *method,
+ struct ANASTASIS_DatabasePlugin *db,
const struct GNUNET_CONFIGURATION_Handle *AH_cfg)
{
struct ANASTASIS_AuthorizationPlugin *authorization;
@@ -90,6 +96,8 @@ ANASTASIS_authorization_plugin_load (
&currency))
return NULL;
ap = GNUNET_new (struct AuthPlugin);
+ ap->ac.db = db;
+ ap->ac.cfg = AH_cfg;
GNUNET_asprintf (&sec_name,
"authorization-%s",
method);
@@ -127,7 +135,7 @@ ANASTASIS_authorization_plugin_load (
"libanastasis_plugin_authorization_%s",
method);
authorization = GNUNET_PLUGIN_load (lib_name,
- (void *) AH_cfg);
+ &ap->ac);
if (NULL == authorization)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
diff --git a/src/authorization/anastasis_authorization_plugin_email.c b/src/authorization/anastasis_authorization_plugin_email.c
index c68e542..22a7824 100644
--- a/src/authorization/anastasis_authorization_plugin_email.c
+++ b/src/authorization/anastasis_authorization_plugin_email.c
@@ -48,6 +48,11 @@ struct Email_Context
*/
json_t *messages;
+ /**
+ * Context we operate in.
+ */
+ const struct ANASTASIS_AuthorizationContext *ac;
+
};
@@ -522,11 +527,13 @@ email_cleanup (struct ANASTASIS_AUTHORIZATION_State *as)
void *
libanastasis_plugin_authorization_email_init (void *cls)
{
+ const struct ANASTASIS_AuthorizationContext *ac = cls;
struct ANASTASIS_AuthorizationPlugin *plugin;
- struct GNUNET_CONFIGURATION_Handle *cfg = cls;
+ const struct GNUNET_CONFIGURATION_Handle *cfg = ac->cfg;
struct Email_Context *ctx;
ctx = GNUNET_new (struct Email_Context);
+ ctx->ac = ac;
{
char *fn;
json_error_t err;
diff --git a/src/authorization/anastasis_authorization_plugin_file.c b/src/authorization/anastasis_authorization_plugin_file.c
index e8e53a0..38939a0 100644
--- a/src/authorization/anastasis_authorization_plugin_file.c
+++ b/src/authorization/anastasis_authorization_plugin_file.c
@@ -58,7 +58,7 @@ struct ANASTASIS_AUTHORIZATION_State
*
* To be possibly used before issuing a 402 payment required to the client.
*
- * @param cls closure
+ * @param cls closure with a `const struct ANASTASIS_AuthorizationContext *`
* @param connection HTTP client request (for queuing response)
* @param truth_mime mime type of @e data
* @param data input to validate (i.e. is it a valid phone number, etc.)
@@ -77,6 +77,7 @@ file_validate (void *cls,
char *filename;
bool flag;
+ (void) cls;
if (NULL == data)
return GNUNET_NO;
filename = GNUNET_STRINGS_data_to_string_alloc (data,
@@ -122,6 +123,7 @@ file_start (void *cls,
const void *data,
size_t data_length)
{
+ const struct ANASTASIS_AuthorizationContext *ac = cls;
struct ANASTASIS_AUTHORIZATION_State *as;
as = GNUNET_new (struct ANASTASIS_AUTHORIZATION_State);
@@ -271,9 +273,11 @@ file_cleanup (struct ANASTASIS_AUTHORIZATION_State *as)
void *
libanastasis_plugin_authorization_file_init (void *cls)
{
+ const struct ANASTASIS_AuthorizationContext *ac = cls;
struct ANASTASIS_AuthorizationPlugin *plugin;
plugin = GNUNET_new (struct ANASTASIS_AuthorizationPlugin);
+ plugin->cls = (void *) ac;
plugin->code_validity_period = GNUNET_TIME_UNIT_MINUTES;
plugin->code_rotation_period = GNUNET_TIME_UNIT_MINUTES;
plugin->code_retransmission_frequency = GNUNET_TIME_UNIT_MINUTES;
diff --git a/src/authorization/anastasis_authorization_plugin_iban.c b/src/authorization/anastasis_authorization_plugin_iban.c
index d1a71f9..548b5c0 100644
--- a/src/authorization/anastasis_authorization_plugin_iban.c
+++ b/src/authorization/anastasis_authorization_plugin_iban.c
@@ -57,9 +57,9 @@ struct IBAN_Context
char *business_name;
/**
- * Database handle.
+ * Handle to interact with a authorization backend.
*/
- struct ANASTASIS_DatabasePlugin *db;
+ const struct ANASTASIS_AuthorizationContext *ac;
/**
* Amount we expect to be transferred.
@@ -407,14 +407,14 @@ iban_process (struct ANASTASIS_AUTHORIZATION_State *as,
GNUNET_CRYPTO_hash (as->iban_number,
strlen (as->iban_number),
&espec.debit_iban_hash);
- as->eh = ctx->db->event_listen (ctx->db->cls,
- &espec.header,
- &bank_event_cb,
- as);
+ as->eh = ctx->ac->db->event_listen (ctx->ac->db->cls,
+ &espec.header,
+ &bank_event_cb,
+ as);
}
- qs = ctx->db->test_challenge_code_satisfied (ctx->db->cls,
- &as->truth_uuid,
- as->code);
+ qs = ctx->ac->db->test_challenge_code_satisfied (ctx->ac->db->cls,
+ &as->truth_uuid,
+ as->code);
switch (qs)
{
case GNUNET_DB_STATUS_HARD_ERROR:
@@ -458,7 +458,7 @@ iban_cleanup (struct ANASTASIS_AUTHORIZATION_State *as)
if (NULL != as->eh)
{
- ctx->db->event_listen_cancel (as->eh);
+ ctx->ac->db->event_listen_cancel (as->eh);
as->eh = NULL;
}
GNUNET_free (as->iban_number);
@@ -469,14 +469,15 @@ iban_cleanup (struct ANASTASIS_AUTHORIZATION_State *as)
/**
* Initialize email based authorization plugin
*
- * @param cls a configuration instance
+ * @param cls a `struct ANASTASIS_AuthorizationContext`
* @return NULL on error, otherwise a `struct ANASTASIS_AuthorizationPlugin`
*/
void *
libanastasis_plugin_authorization_iban_init (void *cls)
{
+ struct ANASTASIS_AuthorizationContext *ac = cls;
struct ANASTASIS_AuthorizationPlugin *plugin;
- struct GNUNET_CONFIGURATION_Handle *cfg = cls;
+ const struct GNUNET_CONFIGURATION_Handle *cfg = ac->cfg;
struct IBAN_Context *ctx;
ctx = GNUNET_new (struct IBAN_Context);
@@ -531,21 +532,12 @@ libanastasis_plugin_authorization_iban_init (void *cls)
}
GNUNET_free (fn);
}
- ctx->db = ANASTASIS_DB_plugin_load (cfg);
- if (NULL == ctx->db)
- {
- json_decref (ctx->messages);
- GNUNET_free (ctx->business_iban);
- GNUNET_free (ctx->business_name);
- GNUNET_free (ctx);
- return NULL;
- }
+ ctx->ac = ac;
if (GNUNET_OK !=
TALER_BANK_auth_parse_cfg (cfg,
"authorization-iban",
&ctx->auth))
{
- ANASTASIS_DB_plugin_unload (ctx->db);
json_decref (ctx->messages);
GNUNET_free (ctx->business_iban);
GNUNET_free (ctx->business_name);
@@ -579,7 +571,6 @@ libanastasis_plugin_authorization_iban_done (void *cls)
struct ANASTASIS_AuthorizationPlugin *plugin = cls;
struct IBAN_Context *ctx = plugin->cls;
- ANASTASIS_DB_plugin_unload (ctx->db);
TALER_BANK_auth_free (&ctx->auth);
json_decref (ctx->messages);
GNUNET_free (ctx->business_iban);
diff --git a/src/authorization/anastasis_authorization_plugin_post.c b/src/authorization/anastasis_authorization_plugin_post.c
index bca4451..dddd273 100644
--- a/src/authorization/anastasis_authorization_plugin_post.c
+++ b/src/authorization/anastasis_authorization_plugin_post.c
@@ -42,6 +42,12 @@ struct PostContext
* Messages of the plugin, read from a resource file.
*/
json_t *messages;
+
+ /**
+ * Argument passed to the "init" function of each
+ * plugin.
+ */
+ const struct ANASTASIS_AuthorizationContext *ac;
};
@@ -576,11 +582,13 @@ post_cleanup (struct ANASTASIS_AUTHORIZATION_State *as)
void *
libanastasis_plugin_authorization_post_init (void *cls)
{
+ const struct ANASTASIS_AuthorizationContext *ac = cls;
struct ANASTASIS_AuthorizationPlugin *plugin;
- struct GNUNET_CONFIGURATION_Handle *cfg = cls;
+ const struct GNUNET_CONFIGURATION_Handle *cfg = ac->cfg;
struct PostContext *ctx;
ctx = GNUNET_new (struct PostContext);
+ ctx->ac = ac;
{
char *fn;
json_error_t err;
diff --git a/src/authorization/anastasis_authorization_plugin_sms.c b/src/authorization/anastasis_authorization_plugin_sms.c
index 05d7148..b780c68 100644
--- a/src/authorization/anastasis_authorization_plugin_sms.c
+++ b/src/authorization/anastasis_authorization_plugin_sms.c
@@ -47,6 +47,11 @@ struct SMS_Context
* Messages of the plugin, read from a resource file.
*/
json_t *messages;
+
+ /**
+ * Context we operate in.
+ */
+ const struct ANASTASIS_AuthorizationContext *ac;
};
@@ -513,11 +518,13 @@ sms_cleanup (struct ANASTASIS_AUTHORIZATION_State *as)
void *
libanastasis_plugin_authorization_sms_init (void *cls)
{
+ const struct ANASTASIS_AuthorizationContext *ac = cls;
struct ANASTASIS_AuthorizationPlugin *plugin;
- struct GNUNET_CONFIGURATION_Handle *cfg = cls;
+ const struct GNUNET_CONFIGURATION_Handle *cfg = ac->cfg;
struct SMS_Context *ctx;
ctx = GNUNET_new (struct SMS_Context);
+ ctx->ac = ac;
{
char *fn;
json_error_t err;