Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Version-proof auth check PERL-155 (Olly Stephens)

  • Loading branch information...
commit c9939cf0c627184a6011d7d34020cfd5688332a0 1 parent 4c7995e
Kristina kchodorow authored

Showing 1 changed file with 23 additions and 14 deletions. Show diff stats Hide diff stats

  1. +23 14 xs/Connection.xs
37 xs/Connection.xs
@@ -178,26 +178,35 @@ connect (self)
178 178
179 179 if (SvPOK(username) && SvPOK(password)) {
180 180 SV *database, *result, **ok;
181   -
  181 +
182 182 database = perl_mongo_call_reader (self, "db_name");
183 183 result = perl_mongo_call_method(self, "authenticate", 0, 3, database, username, password);
184   - if (!result || SvTYPE(result) != SVt_RV) {
185   - if (result && SvPOK(result)) {
186   - croak("%s", SvPV_nolen(result));
187   - }
188   - else {
189   - sv_dump(result);
190   - croak("something weird happened with authentication");
191   - }
  184 + if (!result) {
  185 + SvREFCNT_dec(database);
  186 + SvREFCNT_dec(username);
  187 + SvREFCNT_dec(password);
  188 + croak("authentication returned no result");
192 189 }
193   -
194   - ok = hv_fetch((HV*)SvRV(result), "ok", strlen("ok"), 0);
195   - if (!ok || 1 != SvIV(*ok)) {
  190 + // we're expecting either a string (failure) or a hash (success hopefully)
  191 + if (SvPOK(result)) {
196 192 SvREFCNT_dec(database);
197 193 SvREFCNT_dec(username);
198 194 SvREFCNT_dec(password);
199   -
200   - croak ("couldn't authenticate with server");
  195 + croak("%s", SvPV_nolen(result));
  196 + } else if (SvROK(result)) {
  197 + ok = hv_fetch((HV*)SvRV(result), "ok", strlen("ok"), 0);
  198 + if (!ok || 1 != SvIV(*ok)) {
  199 + SvREFCNT_dec(database);
  200 + SvREFCNT_dec(username);
  201 + SvREFCNT_dec(password);
  202 + croak ("couldn't authenticate with server");
  203 + }
  204 + } else {
  205 + sv_dump(result);
  206 + SvREFCNT_dec(database);
  207 + SvREFCNT_dec(username);
  208 + SvREFCNT_dec(password);
  209 + croak("something weird happened with authentication");
201 210 }
202 211
203 212 SvREFCNT_dec(database);

0 comments on commit c9939cf

Please sign in to comment.
Something went wrong with that request. Please try again.