Commits

Aristarkh Zagorodnikov committed abac0c4

Minor authentication cleanup

Comments (0)

Files changed (1)

gridfs/mod_gridfs.cpp

 	return 0;
 }
 
-//Handles "GridFSUsername <username>" command
+//	Handles "GridFSUsername <username>" command
 static const char *gridfs_username_command(cmd_parms *const command, void *const module_config, const char *const argument)
 {
 	gridfs_config *const config = static_cast<gridfs_config *>(module_config);
 	return 0;
 }
 
-//Handles "GridFSPassword <username>" command
+//	Handles "GridFSPassword <password>" command
 static const char *gridfs_password_command(cmd_parms *const command, void *const module_config, const char *const argument)
 {
 	gridfs_config *const config = static_cast<gridfs_config *>(module_config);
 	config->password = password;
 	return 0;
 }
+
 //	Handles "GridFSCacheMaxAge <cache max age>" command
 static const char *gridfs_cache_max_age_command(cmd_parms *const command, void *const module_config, const char *const argument)
 {
 			try
 			{
 				std::auto_ptr<mongo::ScopedDbConnection> connection(mongo::ScopedDbConnection::getScopedDbConnection(*config->connection_string, config->connect_timeout));
-				mongo::DBClientBase &cc = connection->conn();
-				
-				//try to authenticate only if both username and password are set
+				const std::string& database = *config->database;
+
+				mongo::DBClientBase& client = connection->conn();
 				if (config->username != 0 && config->password != 0)
 				{
 					std::string errmsg;
-					bool ok = cc.auth(*config->database, *config->username, *config->password, errmsg);
-					if (!ok) {
+					if (!client.auth(database, *config->username, *config->password, errmsg))
+					{
 						connection->done();
-						ap_log_rerror(APLOG_MARK, APLOG_CRIT, 0, request, ("mod_gridfs: " + errmsg).c_str());
+						ap_log_rerror(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, 0, request, "mod_gridfs: Authentication failed. %s", errmsg.c_str());
 						return HTTP_INTERNAL_SERVER_ERROR;
 					}
 				}
-				const mongo::GridFS gridfs(cc, *config->database);
-				
+
+				const mongo::GridFS gridfs(client, database);
 				mongo::GridFile gridfile = gridfs.findFile(filename, config->slave_ok);
 				if (!gridfile.exists())
 				{