| 335 | } |
| 336 | |
| 337 | bool BZFSHTTPAuth::verifyToken(const HTTPRequest& request, HTTPReply& reply) { |
| 338 | // build up the groups list |
| 339 | std::string token, user; |
| 340 | request.getParam("token", token); |
| 341 | request.getParam("user", user); |
| 342 | |
| 343 | std::vector<std::string> groups; |
| 344 | |
| 345 | std::map<int, std::vector<std::string> >::iterator itr = authLevels.begin(); |
| 346 | |
| 347 | while (itr != authLevels.end()) { |
| 348 | for (size_t i = 0; i < itr->second.size(); i++) { |
| 349 | std::string& perm = itr->second[i]; |
| 350 | |
| 351 | std::vector<std::string> groupsWithPerm; |
| 352 | |
| 353 | if (compare_nocase(perm, "ADMIN") == 0) { |
| 354 | groupsWithPerm = findGroupsWithAdmin(); |
| 355 | } |
| 356 | else { |
| 357 | groupsWithPerm = findGroupsWithPerm(perm); |
| 358 | } |
| 359 | |
| 360 | // only add groups that are not in the list yet |
| 361 | for (size_t g = 0; g < groupsWithPerm.size(); g++) { |
| 362 | if (std::find(groups.begin(), groups.end(), groupsWithPerm[g]) == groups.end()) { |
| 363 | groups.push_back(groupsWithPerm[g]); |
| 364 | } |
| 365 | } |
| 366 | } |
| 367 | itr++; |
| 368 | } |
| 369 | |
| 370 | PendingTokenTask* task = new PendingTokenTask; |
| 371 | |
| 372 | if (!user.size() || !token.size()) { |
| 373 | reply.body += "Invalid response"; |
| 374 | reply.docType = HTTPReply::eText; |
| 375 | return true; |
| 376 | } |
| 377 | task->requestID = request.requestID; |
| 378 | task->URL = "http://my.bzflag.org/db/"; |
| 379 | task->URL += "?action=CHECKTOKENS&checktokens=" + url_encode(user); |
| 380 | if (!ipIsLocal(request.ip)) { |
| 381 | task->URL += "@" + request.ip; |
| 382 | } |
| 383 | task->URL += "%3D" + token; |
| 384 | |
| 385 | task->URL += "&groups="; |
| 386 | for (size_t g = 0; g < groups.size(); g++) { |
| 387 | task->URL += groups[g]; |
| 388 | if (g + 1 < groups.size()) { |
| 389 | task->URL += "%0D%0A"; |
| 390 | } |
| 391 | } |
| 392 | |
| 393 | // give the task to bzfs and let it do it, when it's done it'll be processed |
| 394 | bz_addURLJob(task->URL.c_str(), task); |
nothing calls this directly
no test coverage detected