~ubuntu-branches/ubuntu/raring/ceph/raring

« back to all changes in this revision

Viewing changes to src/rgw/rgw_swift_auth.cc

  • Committer: Package Import Robot
  • Author(s): Laszlo Boszormenyi (GCS)
  • Date: 2012-02-05 10:07:38 UTC
  • mfrom: (1.1.7) (0.1.11 sid)
  • Revision ID: package-import@ubuntu.com-20120205100738-00s0bxx93mamy8tk
Tags: 0.41-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
 
9
9
#define DOUT_SUBSYS rgw
10
10
 
 
11
#define DEFAULT_SWIFT_PREFIX "swift"
 
12
 
11
13
using namespace ceph::crypto;
12
14
 
13
15
static RGW_SWIFT_Auth_Get rgw_swift_auth_get;
63
65
 
64
66
  int len = strlen(token);
65
67
  if (len & 1) {
66
 
    dout(0) << "failed to verify token: invalid token length len=" << len << dendl;
 
68
    dout(0) << "NOTICE: failed to verify token: invalid token length len=" << len << dendl;
67
69
    return -EINVAL;
68
70
  }
69
71
 
86
88
    ::decode(nonce, iter);
87
89
    ::decode(expiration, iter);
88
90
  } catch (buffer::error& err) {
89
 
    dout(0) << "failed to decode token: caught exception" << dendl;
 
91
    dout(0) << "NOTICE: failed to decode token: caught exception" << dendl;
90
92
    return -EINVAL;
91
93
  }
92
94
  if (expiration < ceph_clock_now(g_ceph_context)) {
93
 
    dout(0) << "old timed out token was used now=" << ceph_clock_now(g_ceph_context) << " token.expiration=" << expiration << dendl;
 
95
    dout(0) << "NOTICE: old timed out token was used now=" << ceph_clock_now(g_ceph_context) << " token.expiration=" << expiration << dendl;
94
96
    return -EPERM;
95
97
  }
96
98
 
110
112
    return ret;
111
113
 
112
114
  if (tok.length() != bl.length()) {
113
 
    dout(0) << "tokens length mismatch: bl.length()=" << bl.length() << " tok.length()=" << tok.length() << dendl;
 
115
    dout(0) << "NOTICE: tokens length mismatch: bl.length()=" << bl.length() << " tok.length()=" << tok.length() << dendl;
114
116
    return -EPERM;
115
117
  }
116
118
 
117
119
  if (memcmp(tok.c_str(), bl.c_str(), tok.length()) != 0) {
118
120
    char buf[tok.length() * 2 + 1];
119
121
    buf_to_hex((const unsigned char *)tok.c_str(), tok.length(), buf);
120
 
    dout(0) << "WARNING: tokens mismatch tok=" << buf << dendl;
 
122
    dout(0) << "NOTICE: tokens mismatch tok=" << buf << dendl;
121
123
    return -EPERM;
122
124
  }
123
125
 
128
130
{
129
131
  int ret = -EPERM;
130
132
 
131
 
  dout(20) << "RGW_SWIFT_Auth_Get::execute()" << dendl;
132
 
 
133
133
  const char *key = s->env->get("HTTP_X_AUTH_KEY");
134
134
  const char *user = s->env->get("HTTP_X_AUTH_USER");
135
135
 
136
 
  string user_str = user;
 
136
  string user_str;
137
137
  RGWUserInfo info;
138
138
  bufferlist bl;
139
139
  RGWAccessKey *swift_key;
140
140
  map<string, RGWAccessKey>::iterator siter;
141
141
 
142
 
  if (g_conf->rgw_swift_url.length() == 0 ||
143
 
      g_conf->rgw_swift_url_prefix.length() == 0) {
144
 
    dout(0) << "server is misconfigured, missing rgw_swift_url_prefix or rgw_swift_url" << dendl;
145
 
    ret = -EINVAL;
146
 
    goto done;
147
 
  }
 
142
  string swift_url = g_conf->rgw_swift_url;
 
143
  string swift_prefix = g_conf->rgw_swift_url_prefix;
 
144
 
 
145
  if (swift_prefix.size() == 0) {
 
146
    swift_prefix = DEFAULT_SWIFT_PREFIX;
 
147
  }
 
148
 
 
149
  if (swift_url.size() == 0) {
 
150
    bool add_port = false;
 
151
    const char *server_port = s->env->get("SERVER_PORT_SECURE");
 
152
    const char *protocol;
 
153
    if (server_port) {
 
154
      add_port = (strcmp(server_port, "443") != 0);
 
155
      protocol = "https";
 
156
    } else {
 
157
      server_port = s->env->get("SERVER_PORT");
 
158
      add_port = (strcmp(server_port, "80") != 0);
 
159
      protocol = "http";
 
160
    }
 
161
    const char *host = s->env->get("HTTP_HOST");
 
162
    if (!host) {
 
163
      dout(0) << "NOTICE: server is misconfigured, missing rgw_swift_url_prefix or rgw_swift_url, HTTP_HOST is not set" << dendl;
 
164
      ret = -EINVAL;
 
165
      goto done;
 
166
    }
 
167
    swift_url = protocol;
 
168
    swift_url.append("://");
 
169
    swift_url.append(host);
 
170
    if (add_port) {
 
171
      swift_url.append(":");
 
172
      swift_url.append(server_port);
 
173
    }
 
174
  }
 
175
 
148
176
 
149
177
  if (!key || !user)
150
178
    goto done;
151
179
 
 
180
  user_str = user;
 
181
 
152
182
  if ((ret = rgw_get_user_info_by_swift(user_str, info)) < 0)
153
183
    goto done;
154
184
 
160
190
  swift_key = &siter->second;
161
191
 
162
192
  if (swift_key->key.compare(key) != 0) {
163
 
    dout(0) << "RGW_SWIFT_Auth_Get::execute(): bad swift key" << dendl;
 
193
    dout(0) << "NOTICE: RGW_SWIFT_Auth_Get::execute(): bad swift key" << dendl;
164
194
    ret = -EPERM;
165
195
    goto done;
166
196
  }
167
197
 
168
 
  CGI_PRINTF(s, "X-Storage-Url: %s/%s/v1\n", g_conf->rgw_swift_url.c_str(),
169
 
             g_conf->rgw_swift_url_prefix.c_str());
 
198
  CGI_PRINTF(s, "X-Storage-Url: %s/%s/v1\n", swift_url.c_str(),
 
199
             swift_prefix.c_str());
170
200
 
171
201
  if ((ret = encode_token(swift_key->id, swift_key->key, bl)) < 0)
172
202
    goto done;
175
205
    char buf[bl.length() * 2 + 1];
176
206
    buf_to_hex((const unsigned char *)bl.c_str(), bl.length(), buf);
177
207
 
178
 
    CGI_PRINTF(s, "X-Storage-Token: AUTH_rgwtk%s\n", buf);
 
208
    CGI_PRINTF(s, "X-Auth-Token: AUTH_rgwtk%s\n", buf);
179
209
  }
180
210
 
181
211
  ret = STATUS_NO_CONTENT;
186
216
  end_header(s);
187
217
}
188
218
 
 
219
int RGWHandler_SWIFT_Auth::init(struct req_state *state, FCGX_Request *fcgx)
 
220
{
 
221
  state->dialect = "swift-auth";
 
222
 
 
223
  return RGWHandler::init(state, fcgx);
 
224
}
 
225
 
189
226
int RGWHandler_SWIFT_Auth::authorize()
190
227
{
191
228
  return 0;