2
-*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
3
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
6
#include <drizzled/server_includes.h>
7
#include <drizzled/session.h>
8
#include <drizzled/plugin/authentication.h>
9
#include <drizzled/gettext.h>
11
#include <curl/curl.h>
15
static bool sysvar_auth_http_enable= false;
16
static char* sysvar_auth_http_url= NULL;
18
size_t curl_cb_read(void *ptr, size_t size, size_t nmemb, void *stream)
22
return (size * nmemb);
26
class Auth_http : public Authentication
29
virtual bool authenticate(Session *session, const char *password)
32
long http_response_code;
34
if (sysvar_auth_http_enable == false)
37
assert(session->security_ctx.user.c_str());
40
// turn off curl stuff that might mess us up
41
rv= curl_easy_setopt(curl_handle, CURLOPT_NOPROGRESS, 1);
42
rv= curl_easy_setopt(curl_handle, CURLOPT_NOSIGNAL, 1);
43
rv= curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, 0);
45
// do a HEAD instead of a default GET
46
rv= curl_easy_setopt(curl_handle, CURLOPT_NOBODY, 1);
48
// set the read callback. this shouldnt get called, because we are doing a HEAD
49
rv= curl_easy_setopt(curl_handle, CURLOPT_READFUNCTION, curl_cb_read);
51
// set the parameters: url, username, password
52
rv= curl_easy_setopt(curl_handle, CURLOPT_URL, sysvar_auth_http_url);
53
rv= curl_easy_setopt(curl_handle, CURLOPT_USERNAME, session->security_ctx.user.c_str());
54
rv= curl_easy_setopt(curl_handle, CURLOPT_PASSWORD, password);
57
rv= curl_easy_perform(curl_handle);
59
// what did we get? goes into http_response_code
60
rv= curl_easy_getinfo(curl_handle, CURLINFO_RESPONSE_CODE, &http_response_code);
62
// so here is an interesting question.
63
// return true if the response_code is 2XX, or return false if its 4XX
64
// for now, return false for 401, true otherwise
65
// this means that if the url breaks, then anyone can log in
66
// this might be the wrong thing
68
if (http_response_code == 401)
74
static int initialize(void *p)
76
Authentication **auth= static_cast<Authentication **>(p);
80
*auth= new Auth_http();
82
// we are trusting that plugin initializers are called singlethreaded at startup
83
// if something else also calls curl_global_init() in a threadrace while we are here,
84
// we will crash the server.
85
curl_handle= curl_easy_init();
87
rv= curl_easy_setopt(curl_handle, CURLOPT_NOPROGRESS, 1);
88
rv= curl_easy_setopt(curl_handle, CURLOPT_NOSIGNAL, 1);
89
rv= curl_easy_setopt(curl_handle, CURLOPT_NOBODY, 1);
94
static int finalize(void *p)
96
Auth_http *auth= static_cast<Auth_http *>(p);
101
curl_easy_cleanup(curl_handle);
106
static DRIZZLE_SYSVAR_BOOL(
108
sysvar_auth_http_enable,
110
N_("Enable HTTP Auth check"),
111
NULL, /* check func */
112
NULL, /* update func */
113
false /* default */);
116
static DRIZZLE_SYSVAR_STR(
118
sysvar_auth_http_url,
120
N_("URL for HTTP Auth check"),
121
NULL, /* check func */
122
NULL, /* update func*/
123
"http://localhost/" /* default */);
125
static struct st_mysql_sys_var* auth_http_system_variables[]= {
126
DRIZZLE_SYSVAR(enable),
132
drizzle_declare_plugin(auth_http)
138
"PAM based authenication.",
140
initialize, /* Plugin Init */
141
finalize, /* Plugin Deinit */
142
NULL, /* status variables */
143
auth_http_system_variables,
144
NULL /* config options */
146
drizzle_declare_plugin_end;