+ ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Checking HTTP auth password for resource %s (matched by pattern %s) from ip %s, against username %s",
+ http->GetPath().c_str(), this_acl->path.c_str(), http->GetIP().c_str(), this_acl->username.c_str());
+
+ if (http->headers->IsSet("Authorization"))
+ {
+ /* Password has been given, validate it */
+ std::string authorization = http->headers->GetHeader("Authorization");
+ irc::spacesepstream sep(authorization);
+ std::string authtype;
+ std::string base64;
+
+ sep.GetToken(authtype);
+ if (authtype == "Basic")
+ {
+ std::string user;
+ std::string pass;
+
+ sep.GetToken(base64);
+ std::string userpass = Base64ToBin(base64);
+ ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "HTTP authorization: %s (%s)", userpass.c_str(), base64.c_str());
+
+ irc::sepstream userpasspair(userpass, ':');
+ if (userpasspair.GetToken(user))
+ {
+ userpasspair.GetToken(pass);
+
+ /* Access granted if username and password are correct */
+ if (user == this_acl->username && pass == this_acl->password)
+ {
+ ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "HTTP authorization: password and username match");
+ return true;
+ }
+ else
+ {
+ /* Invalid password */
+ ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "HTTP authorization: password and username do not match");
+ BlockAccess(http, 401, "WWW-Authenticate", "Basic realm=\"Restricted Object\"");
+ }
+ }
+ else
+ {
+ /* Malformed user:pass pair */
+ ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "HTTP authorization: password and username malformed");
+ BlockAccess(http, 401, "WWW-Authenticate", "Basic realm=\"Restricted Object\"");
+ }
+ }
+ else
+ {
+ /* Unsupported authentication type */
+ ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "HTTP authorization: unsupported auth type: %s", authtype.c_str());
+ BlockAccess(http, 401, "WWW-Authenticate", "Basic realm=\"Restricted Object\"");
+ }
+ }
+ else
+ {
+ /* No password given at all, access denied */
+ ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "HTTP authorization: password and username not sent");
+ BlockAccess(http, 401, "WWW-Authenticate", "Basic realm=\"Restricted Object\"");
+ }
+ return false;