~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/auth_http/auth_http.cc

add test for bug600088: multibyte comments not shown correctly in SHOW CREATE TABLE 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2009 Sun Microsystems, Inc.
 
4
 *  Copyright (C) 2009 Sun Microsystems
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#include <config.h>
 
20
#include "config.h"
21
21
 
22
22
#include <curl/curl.h>
23
23
 
24
24
#include <string>
25
25
#include <cassert>
26
 
#include <boost/program_options.hpp>
27
 
#include <drizzled/module/option_map.h>
28
 
#include <drizzled/identifier.h>
29
 
#include <drizzled/plugin/authentication.h>
30
 
#include <drizzled/gettext.h>
31
 
namespace po= boost::program_options;
 
26
 
 
27
#include "drizzled/security_context.h"
 
28
#include "drizzled/plugin/authentication.h"
 
29
#include "drizzled/gettext.h"
 
30
 
32
31
using namespace drizzled;
33
32
using namespace std;
34
33
 
 
34
static bool sysvar_auth_http_enable= false;
 
35
static char* sysvar_auth_http_url= NULL;
 
36
 
35
37
static size_t curl_cb_read(void *ptr, size_t size, size_t nmemb, void *stream)
36
38
{
37
39
  (void) ptr;
44
46
{
45
47
  CURLcode rv;
46
48
  CURL *curl_handle;
47
 
  const std::string auth_url;
48
49
public:
49
 
  Auth_http(std::string name_arg, const std::string &url_arg) :
50
 
    drizzled::plugin::Authentication(name_arg),
51
 
    auth_url(url_arg)
 
50
  Auth_http(std::string name_arg)
 
51
    : drizzled::plugin::Authentication(name_arg)
52
52
  {
53
53
    // we are trusting that plugin initializers are called singlethreaded at startup
54
54
    // if something else also calls curl_global_init() in a threadrace while we are here,
73
73
    curl_global_cleanup();
74
74
  }
75
75
 
76
 
  virtual bool authenticate(const identifier::User &sctx, const string &password)
 
76
  virtual bool authenticate(const SecurityContext &sctx, const string &password)
77
77
  {
78
78
    long http_response_code;
79
79
 
80
 
    assert(sctx.username().c_str());
 
80
    if (sysvar_auth_http_enable == false)
 
81
      return true;
 
82
 
 
83
    assert(sctx.getUser().c_str());
 
84
 
81
85
 
82
86
    // set the parameters: url, username, password
83
 
    rv= curl_easy_setopt(curl_handle, CURLOPT_URL, auth_url.c_str());
 
87
    rv= curl_easy_setopt(curl_handle, CURLOPT_URL, sysvar_auth_http_url);
84
88
#if defined(HAVE_CURLOPT_USERNAME)
85
89
 
86
90
    rv= curl_easy_setopt(curl_handle, CURLOPT_USERNAME,
87
 
                         sctx.username().c_str());
 
91
                         sctx.getUser().c_str());
88
92
    rv= curl_easy_setopt(curl_handle, CURLOPT_PASSWORD, password.c_str());
89
93
 
90
94
#else
91
95
 
92
 
    string userpwd(sctx.username());
 
96
    string userpwd(sctx.getUser());
93
97
    userpwd.append(":");
94
98
    userpwd.append(password);
95
99
    rv= curl_easy_setopt(curl_handle, CURLOPT_USERPWD, userpwd.c_str());
118
122
 
119
123
static int initialize(drizzled::module::Context &context)
120
124
{
121
 
  const module::option_map &vm= context.getOptions();
122
 
 
123
125
  /* 
124
126
   * Per libcurl manual, in multi-threaded applications, curl_global_init() should
125
127
   * be called *before* curl_easy_init()...which is called in Auto_http's 
128
130
  if (curl_global_init(CURL_GLOBAL_NOTHING) != 0)
129
131
    return 1;
130
132
 
131
 
  const string auth_url(vm["url"].as<string>());
132
 
  if (auth_url.size() == 0)
133
 
  {
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"));
138
 
    return 1;
139
 
  }
140
 
 
141
 
  auth= new Auth_http("auth_http", auth_url);
 
133
  auth= new Auth_http("auth_http");
142
134
  context.add(auth);
143
 
  context.registerVariable(new sys_var_const_string_val("url", auth_url));
144
135
 
145
136
  return 0;
146
137
}
147
138
 
148
 
static void init_options(drizzled::module::option_context &context)
149
 
{
150
 
  context("url", po::value<string>()->default_value(""),
151
 
          N_("URL for HTTP Auth check"));
152
 
 
139
static DRIZZLE_SYSVAR_BOOL(
 
140
  enable,
 
141
  sysvar_auth_http_enable,
 
142
  PLUGIN_VAR_NOCMDARG,
 
143
  N_("Enable HTTP Auth check"),
 
144
  NULL, /* check func */
 
145
  NULL, /* update func */
 
146
  false /* default */);
 
147
 
 
148
 
 
149
static DRIZZLE_SYSVAR_STR(
 
150
  url,
 
151
  sysvar_auth_http_url,
 
152
  PLUGIN_VAR_READONLY,
 
153
  N_("URL for HTTP Auth check"),
 
154
  NULL, /* check func */
 
155
  NULL, /* update func*/
 
156
  "http://localhost/" /* default */);
 
157
 
 
158
static drizzle_sys_var* auth_http_system_variables[]= {
 
159
  DRIZZLE_SYSVAR(enable),
 
160
  DRIZZLE_SYSVAR(url),
 
161
  NULL
 
162
};
153
163
 
154
164
 
155
165
DRIZZLE_DECLARE_PLUGIN
156
166
{
157
167
  DRIZZLE_VERSION_ID,
158
 
  "auth-http",
 
168
  "auth_http",
159
169
  "0.1",
160
170
  "Mark Atwood",
161
171
  "HTTP based authenication.",
162
172
  PLUGIN_LICENSE_GPL,
163
173
  initialize, /* Plugin Init */
164
 
  NULL,
165
 
  init_options    /* config options */
 
174
  auth_http_system_variables,
 
175
  NULL    /* config options */
166
176
}
167
177
DRIZZLE_DECLARE_PLUGIN_END;