Skip to content

Commit

Permalink
complete encapsulation of curl functions/includes in http.c
Browse files Browse the repository at this point in the history
Signed-off-by: Hans Zandbelt <hans.zandbelt@openidc.com>
  • Loading branch information
zandbelt committed Feb 25, 2024
1 parent a5addb4 commit fc218ce
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 39 deletions.
6 changes: 2 additions & 4 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@

// clang-format on

#include <curl/curl.h>

#define OPENSSL_THREAD_DEFINES
#include <openssl/err.h>
#include <openssl/evp.h>
Expand Down Expand Up @@ -2518,7 +2516,7 @@ static apr_status_t oidc_cleanup_parent(void *data) {
#endif /* (OPENSSL_VERSION_NUMBER < 0x10100000) && defined (OPENSSL_THREADS) && APR_HAS_THREADS */

EVP_cleanup();
curl_global_cleanup();
oidc_http_cleanup();

ap_log_error(APLOG_MARK, APLOG_INFO, 0, (server_rec *)data, "%s - shutdown", NAMEVERSION);

Expand Down Expand Up @@ -2566,7 +2564,7 @@ static int oidc_post_config(apr_pool_t *pool, apr_pool_t *p1, apr_pool_t *p2, se
#endif
);

curl_global_init(CURL_GLOBAL_ALL);
oidc_http_init();

#if ((OPENSSL_VERSION_NUMBER < 0x10100000) && defined(OPENSSL_THREADS) && APR_HAS_THREADS)
ssl_num_locks = CRYPTO_num_locks();
Expand Down
36 changes: 36 additions & 0 deletions src/http.c
Original file line number Diff line number Diff line change
Expand Up @@ -1040,3 +1040,39 @@ void oidc_http_set_chunked_cookie(request_rec *r, const char *cookieName, const
apr_psprintf(r->pool, "%d", chunkCountValue), expires, ext);
oidc_http_set_cookie(r, cookieName, "", expires, ext);
}

char **oidc_http_proxy_auth_options(void) {
static char *options[] = {OIDC_HTTP_PROXY_AUTH_BASIC,
OIDC_HTTP_PROXY_AUTH_DIGEST,
OIDC_HTTP_PROXY_AUTH_NTLM,
OIDC_HTTP_PROXY_AUTH_ANY,
#ifdef CURLAUTH_NEGOTIATE
OIDC_HTTP_PROXY_AUTH_NEGOTIATE,
#endif
NULL};
return options;
}

unsigned long oidc_http_proxy_s2auth(const char *arg) {
if (_oidc_strcmp(arg, OIDC_HTTP_PROXY_AUTH_BASIC) == 0)
return CURLAUTH_BASIC;
if (_oidc_strcmp(arg, OIDC_HTTP_PROXY_AUTH_DIGEST) == 0)
return CURLAUTH_DIGEST;
if (_oidc_strcmp(arg, OIDC_HTTP_PROXY_AUTH_NTLM) == 0)
return CURLAUTH_NTLM;
if (_oidc_strcmp(arg, OIDC_HTTP_PROXY_AUTH_ANY) == 0)
return CURLAUTH_ANY;
#ifdef CURLAUTH_NEGOTIATE
if (_oidc_strcmp(arg, OIDC_HTTP_PROXY_AUTH_NEGOTIATE) == 0)
return CURLAUTH_NEGOTIATE;
#endif
return CURLAUTH_NONE;
}

void oidc_http_init(void) {
curl_global_init(CURL_GLOBAL_ALL);
}

void oidc_http_cleanup(void) {
curl_global_cleanup();
}
12 changes: 12 additions & 0 deletions src/http.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ typedef struct oidc_http_timeout_t {
apr_time_t retry_interval;
} oidc_http_timeout_t;

#define OIDC_HTTP_PROXY_AUTH_BASIC "basic"
#define OIDC_HTTP_PROXY_AUTH_DIGEST "digest"
#define OIDC_HTTP_PROXY_AUTH_NTLM "ntlm"
#define OIDC_HTTP_PROXY_AUTH_ANY "any"
#define OIDC_HTTP_PROXY_AUTH_NEGOTIATE "negotiate"

typedef struct oidc_http_outgoing_proxy_t {
const char *host_port;
const char *username_password;
Expand Down Expand Up @@ -163,4 +169,10 @@ char *oidc_http_get_chunked_cookie(request_rec *r, const char *cookieName, int c
void oidc_http_set_chunked_cookie(request_rec *r, const char *cookieName, const char *cookieValue, apr_time_t expires,
int chunkSize, const char *ext);

char **oidc_http_proxy_auth_options(void);
unsigned long oidc_http_proxy_s2auth(const char *arg);

void oidc_http_init(void);
void oidc_http_cleanup(void);

#endif /* MOD_AUTH_OPENIDC_HTTP_H_ */
2 changes: 1 addition & 1 deletion src/mod_auth_openidc.c
Original file line number Diff line number Diff line change
Expand Up @@ -4769,7 +4769,7 @@ module AP_MODULE_DECLARE_DATA auth_openidc_module = {
oidc_create_dir_config,
oidc_merge_dir_config,
oidc_create_server_config,
oidc_merge_server_config,
oidc_merge_server_config,
oidc_config_cmds,
oidc_register_hooks
};
Expand Down
36 changes: 2 additions & 34 deletions src/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@
* @Author: Hans Zandbelt - hans.zandbelt@openidc.com
*/

#include <curl/curl.h>

#include "mod_auth_openidc.h"

/*
Expand Down Expand Up @@ -1249,41 +1247,11 @@ const char *oidc_parse_x_forwarded_headers(apr_pool_t *pool, const char *arg, ap
return NULL;
}

#define OIDC_PROXY_AUTH_BASIC "basic"
#define OIDC_PROXY_AUTH_DIGEST "digest"
#define OIDC_PROXY_AUTH_NTLM "ntlm"
#define OIDC_PROXY_AUTH_ANY "any"
#ifdef CURLAUTH_NEGOTIATE
#define OIDC_PROXY_AUTH_NEGOTIATE "negotiate"
#endif

const char *oidc_parse_outgoing_proxy_auth_type(apr_pool_t *pool, const char *arg, unsigned long *auth_type) {
static char *options[] = {OIDC_PROXY_AUTH_BASIC,
OIDC_PROXY_AUTH_DIGEST,
OIDC_PROXY_AUTH_NTLM,
OIDC_PROXY_AUTH_ANY,
#ifdef CURLAUTH_NEGOTIATE
OIDC_PROXY_AUTH_NEGOTIATE,
#endif
NULL};
const char *rv = oidc_valid_string_option(pool, arg, options);
const char *rv = oidc_valid_string_option(pool, arg, oidc_http_proxy_auth_options());
if (rv != NULL)
return rv;

if (_oidc_strcmp(arg, OIDC_PROXY_AUTH_BASIC) == 0) {
*auth_type = CURLAUTH_BASIC;
} else if (_oidc_strcmp(arg, OIDC_PROXY_AUTH_DIGEST) == 0) {
*auth_type = CURLAUTH_DIGEST;
} else if (_oidc_strcmp(arg, OIDC_PROXY_AUTH_NTLM) == 0) {
*auth_type = CURLAUTH_NTLM;
} else if (_oidc_strcmp(arg, OIDC_PROXY_AUTH_ANY) == 0) {
*auth_type = CURLAUTH_ANY;
#ifdef CURLAUTH_NEGOTIATE
} else if (_oidc_strcmp(arg, OIDC_PROXY_AUTH_NEGOTIATE) == 0) {
*auth_type = CURLAUTH_NEGOTIATE;
#endif
}

*auth_type = oidc_http_proxy_s2auth(arg);
return NULL;
}

Expand Down

0 comments on commit fc218ce

Please sign in to comment.