22 #include <curl/curl.h>
26 #include <boost/program_options.hpp>
28 #include <drizzled/identifier.h>
29 #include <drizzled/plugin/authentication.h>
30 #include <drizzled/gettext.h>
31 namespace po= boost::program_options;
32 using namespace drizzled;
35 static size_t curl_cb_read(
void *ptr,
size_t size,
size_t nmemb,
void *stream)
39 return (size * nmemb);
47 const std::string auth_url;
49 Auth_http(std::string name_arg,
const std::string &url_arg) :
56 curl_handle= curl_easy_init();
59 rv= curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, 0);
60 rv= curl_easy_setopt(curl_handle, CURLOPT_NOPROGRESS, 1);
61 rv= curl_easy_setopt(curl_handle, CURLOPT_NOSIGNAL, 1);
64 rv= curl_easy_setopt(curl_handle, CURLOPT_NOBODY, 1);
67 rv= curl_easy_setopt(curl_handle, CURLOPT_READFUNCTION, curl_cb_read);
72 curl_easy_cleanup(curl_handle);
73 curl_global_cleanup();
76 virtual bool authenticate(
const identifier::User &sctx,
const string &password)
78 long http_response_code;
80 assert(sctx.username().c_str());
83 rv= curl_easy_setopt(curl_handle, CURLOPT_URL, auth_url.c_str());
84 #if defined(HAVE_CURLOPT_USERNAME)
86 rv= curl_easy_setopt(curl_handle, CURLOPT_USERNAME,
87 sctx.username().c_str());
88 rv= curl_easy_setopt(curl_handle, CURLOPT_PASSWORD, password.c_str());
92 string userpwd(sctx.username());
94 userpwd.append(password);
95 rv= curl_easy_setopt(curl_handle, CURLOPT_USERPWD, userpwd.c_str());
100 rv= curl_easy_perform(curl_handle);
103 rv= curl_easy_getinfo(curl_handle, CURLINFO_RESPONSE_CODE, &http_response_code);
111 if (http_response_code == 401)
128 if (curl_global_init(CURL_GLOBAL_NOTHING) != 0)
131 const string auth_url(vm[
"url"].as<string>());
132 if (auth_url.size() == 0)
134 errmsg_printf(error::ERROR,
135 _(
"auth_http plugin loaded but required option url not "
136 "specified. Against which URL are you intending on "
137 "authenticating?\n"));
141 auth=
new Auth_http(
"auth_http", auth_url);
150 context(
"url", po::value<string>()->default_value(
""),
151 N_(
"URL for HTTP Auth check"));
155 DRIZZLE_DECLARE_PLUGIN
161 N_(
"Authenication against a web server using HTTP"),
167 DRIZZLE_DECLARE_PLUGIN_END;