Example #1
0
int php_mongo_io_stream_authenticate(mongo_con_manager *manager, mongo_connection *con, mongo_server_options *options, mongo_server_def *server_def, char **error_message)
{
	/* Use the mcon implementation of MongoDB-CR (default) */
	if (server_def->mechanism == MONGO_AUTH_MECHANISM_MONGODB_CR) {
		return mongo_connection_authenticate(manager, con, options, server_def, error_message);
	}
	/* Use the mcon implementation of MongoDB-X509 */
	if (server_def->mechanism == MONGO_AUTH_MECHANISM_MONGODB_X509) {
		return mongo_connection_authenticate(manager, con, options, server_def, error_message);
	}

#if HAVE_MONGO_SASL
	if (server_def->mechanism == MONGO_AUTH_MECHANISM_GSSAPI) {
		return php_mongo_io_authenticate_gssapi(manager, con, options, server_def, error_message);
	}
	if (server_def->mechanism == MONGO_AUTH_MECHANISM_PLAIN) {
		return php_mongo_io_authenticate_plain(manager, con, options, server_def, error_message);
	}
	*error_message = strdup("Unknown authentication mechanism. Only MongoDB-CR, MONGODB-X509, GSSAPI and PLAIN are supported by this build");
#else
	*error_message = strdup("Unknown authentication mechanism. Only MongoDB-CR and MONGODB-X509 are supported by this build");
#endif

	return 0;
}
Example #2
0
/* Helpers */
static int authenticate_connection(mongo_con_manager *manager, mongo_connection *con, mongo_server_options *options, char *database, char *username, char *password, char **error_message)
{
	char *nonce;
	int   retval = 0;

	nonce = mongo_connection_getnonce(manager, con, options, error_message);
	if (!nonce) {
		return 0;
	}

	retval = mongo_connection_authenticate(manager, con, options, database, username, password, nonce, error_message);
	free(nonce);

	return retval;
}