- if (user)
- {
- std::string* tried_user = saved_user.get(user);
- std::string* tried_pass = saved_pass.get(user);
- if (res->error.Id() == SQL_NO_ERROR)
- {
- if (res->Rows())
- {
- /* We got a row in the result, this means there was a record for the oper..
- * now we just need to check if their host matches, and if it does then
- * oper them up.
- *
- * We now (previous versions of the module didn't) support multiple SQL
- * rows per-oper in the same way the config file does, all rows will be tried
- * until one is found which matches. This is useful to define several different
- * hosts for a single oper.
- *
- * The for() loop works as SQLresult::GetRowMap() returns an empty map when there
- * are no more rows to return.
- */
-
- for (SQLfieldMap& row = res->GetRowMap(); row.size(); row = res->GetRowMap())
- {
- if (OperUser(user, row["hostname"].d, row["type"].d))
- {
- /* If/when one of the rows matches, stop checking and return */
- saved_user.unset(user);
- saved_pass.unset(user);
- }
- if (tried_user && tried_pass)
- {
- LoginFail(user, *tried_user, *tried_pass);
- saved_user.unset(user);
- saved_pass.unset(user);
- }
- }
- }
- else
- {
- /* No rows in result, this means there was no oper line for the user,
- * we should have already checked the o:lines so now we need an
- * "insufficient awesomeness" (invalid credentials) error
- */
- if (tried_user && tried_pass)
- {
- LoginFail(user, *tried_user, *tried_pass);
- saved_user.unset(user);
- saved_pass.unset(user);
- }
- }
- }
- else
- {
- /* This one shouldn't happen, the query failed for some reason.
- * We have to fail the /oper request and give them the same error
- * as above.
- */
- if (tried_user && tried_pass)
- {
- LoginFail(user, *tried_user, *tried_pass);
- saved_user.unset(user);
- saved_pass.unset(user);
- }
-
- }
- }
- }
- }
-
- void LoginFail(User* user, const std::string &username, const std::string &pass)
- {