|
Greenbone Security Assistant
8.0.0
|
HTTP handling of GSA. More...
#include "gsad_http_handler.h"#include "gsad_base.h"#include "gsad_credentials.h"#include "gsad_gmp.h"#include "gsad_i18n.h"#include "gsad_settings.h"#include "gsad_user.h"#include "validator.h"#include <assert.h>#include <glib.h>#include <gvm/base/networking.h>#include <gvm/util/xmlutils.h>#include <stdlib.h>#include <string.h>
Go to the source code of this file.
Data Structures | |
| struct | url_map |
| URL regexp to handler function mapping. More... | |
| struct | http_handler |
| struct | method_router |
Macros | |
| #define | G_LOG_DOMAIN "gsad http handler" |
| GLib log domain. More... | |
| #define | TOKEN_REGEXP "^[a-z0-9\\-]+$" |
| #define | SLAVE_ID_REGEXP "^[a-z0-9\\-]+$" |
Typedefs | |
| typedef struct url_map | url_map_t |
| typedef struct method_router | method_router_t |
Functions | |
| http_handler_t * | http_handler_add (http_handler_t *handlers, http_handler_t *next) |
| int | http_handler_start (http_connection_t *connection, const char *method, const char *url, gsad_connection_info_t *con_info, http_handler_t *handler, void *data) |
| int | http_handler_next (http_connection_t *connection, const char *method, const char *url, gsad_connection_info_t *con_info, http_handler_t *handler, void *data) |
| http_handler_t * | http_handler_new_with_data (http_handler_func_t func, http_handler_free_func_t freefunc, void *data) |
| void | http_handler_free_internal (http_handler_t *handler) |
| http_handler_t * | http_handler_new (http_handler_func_t func) |
| void | http_handler_free (http_handler_t *handler) |
| int | handle_get_post (http_connection_t *connection, const char *method, const char *url, gsad_connection_info_t *con_info, http_handler_t *handler, void *data) |
| void | method_router_free (http_handler_t *handler) |
| http_handler_t * | method_router_new () |
| void | method_router_set_get_handler (http_handler_t *router, http_handler_t *handler) |
| void | method_router_set_post_handler (http_handler_t *router, http_handler_t *handler) |
| int | handle_url (http_connection_t *connection, const char *method, const char *url, gsad_connection_info_t *con_info, http_handler_t *current, void *data) |
| url_map_t * | url_map_new (const gchar *regexp, http_handler_t *handler) |
| void | url_handler_free (http_handler_t *handler) |
| http_handler_t * | url_handler_new (const gchar *regexp, http_handler_t *handler) |
| http_handler_t * | url_handler_add_func (http_handler_t *handlers, const gchar *regexp, http_handler_func_t handle) |
| int | handle_validate (http_connection_t *connection, const char *method, const char *url, gsad_connection_info_t *con_info, http_handler_t *handler, void *data) |
| int | handle_not_found (http_connection_t *connection, const char *method, const char *url, gsad_connection_info_t *con_info, http_handler_t *handler, void *data) |
| int | handle_invalid_method (http_connection_t *connection, const char *method, const char *url, gsad_connection_info_t *con_info, http_handler_t *handler, void *data) |
| int | get_user_from_connection (http_connection_t *connection, user_t **user) |
| int | handle_get_user (http_connection_t *connection, const char *method, const char *url, gsad_connection_info_t *con_info, http_handler_t *handler, void *data) |
| int | handle_setup_user (http_connection_t *connection, const char *method, const char *url, gsad_connection_info_t *con_info, http_handler_t *handler, void *data) |
| int | handle_setup_credentials (http_connection_t *connection, const char *method, const char *url, gsad_connection_info_t *con_info, http_handler_t *handler, void *data) |
| int | handle_logout (http_connection_t *connection, const char *method, const char *url, gsad_connection_info_t *con_info, http_handler_t *handler, void *data) |
| int | handle_gmp_get (http_connection_t *connection, const char *method, const char *url, gsad_connection_info_t *con_info, http_handler_t *handler, void *data) |
| int | handle_gmp_post (http_connection_t *connection, const char *method, const char *url, gsad_connection_info_t *con_info, http_handler_t *handler, void *data) |
| int | handle_system_report (http_connection_t *connection, const char *method, const char *url, gsad_connection_info_t *con_info, http_handler_t *handler, void *data) |
| int | handle_index (http_connection_t *connection, const char *method, const char *url, gsad_connection_info_t *con_info, http_handler_t *handler, void *data) |
| int | handle_static_file (http_connection_t *connection, const char *method, const char *url, gsad_connection_info_t *con_info, http_handler_t *handler, void *data) |
| int | handle_static_config (http_connection_t *connection, const char *method, const char *url, gsad_connection_info_t *con_info, http_handler_t *handler, void *data) |
| http_handler_t * | init_http_handlers () |
| void | cleanup_http_handlers () |
| int | handle_request (void *cls, http_connection_t *connection, const char *url, const char *method, const char *version, const char *upload_data, size_t *upload_data_size, void **con_cls) |
| HTTP request handler for GSAD. More... | |
Variables | |
| validator_t | http_validator |
| Validator instance for http params. More... | |
| http_handler_t * | handlers |
| #define G_LOG_DOMAIN "gsad http handler" |
GLib log domain.
Definition at line 46 of file gsad_http_handler.c.
| #define SLAVE_ID_REGEXP "^[a-z0-9\\-]+$" |
Definition at line 54 of file gsad_http_handler.c.
| #define TOKEN_REGEXP "^[a-z0-9\\-]+$" |
Definition at line 53 of file gsad_http_handler.c.
| typedef struct method_router method_router_t |
Definition at line 89 of file gsad_http_handler.c.
Definition at line 73 of file gsad_http_handler.c.
| void cleanup_http_handlers | ( | ) |
Definition at line 804 of file gsad_http_handler.c.
References gvm_validator_free(), handlers, http_handler_free(), and http_validator.

| int get_user_from_connection | ( | http_connection_t * | connection, |
| user_t ** | user | ||
| ) |
Definition at line 354 of file gsad_http_handler.c.
References get_client_address(), gvm_validate(), http_validator, SID_COOKIE_NAME, USER_BAD_MISSING_COOKIE, USER_BAD_MISSING_TOKEN, user_find(), and USER_IP_ADDRESS_MISSMATCH.
Referenced by handle_get_user(), and handle_setup_user().


| int handle_get_post | ( | http_connection_t * | connection, |
| const char * | method, | ||
| const char * | url, | ||
| gsad_connection_info_t * | con_info, | ||
| http_handler_t * | handler, | ||
| void * | data | ||
| ) |
Definition at line 181 of file gsad_http_handler.c.
References http_handler::data, method_router::get, http_handler_next(), http_handler_start(), and method_router::post.
Referenced by method_router_new().


| int handle_get_user | ( | http_connection_t * | connection, |
| const char * | method, | ||
| const char * | url, | ||
| gsad_connection_info_t * | con_info, | ||
| http_handler_t * | handler, | ||
| void * | data | ||
| ) |
Definition at line 391 of file gsad_http_handler.c.
References get_user_from_connection(), and http_handler_next().
Referenced by init_http_handlers().


| int handle_gmp_get | ( | http_connection_t * | connection, |
| const char * | method, | ||
| const char * | url, | ||
| gsad_connection_info_t * | con_info, | ||
| http_handler_t * | handler, | ||
| void * | data | ||
| ) |
Definition at line 519 of file gsad_http_handler.c.
References credentials_free(), and exec_gmp_get().
Referenced by init_http_handlers().


| int handle_gmp_post | ( | http_connection_t * | connection, |
| const char * | method, | ||
| const char * | url, | ||
| gsad_connection_info_t * | con_info, | ||
| http_handler_t * | handler, | ||
| void * | data | ||
| ) |
Definition at line 534 of file gsad_http_handler.c.
References accept_language_to_env_fmt(), gsad_connection_info::cookie, exec_gmp_post(), get_client_address(), GSAD_CONTENT_TYPE_TEXT_HTML, gvm_validate(), http_validator, gsad_connection_info::language, send_response(), SID_COOKIE_NAME, and UTF8_ERROR_PAGE.
Referenced by init_http_handlers().


| int handle_index | ( | http_connection_t * | connection, |
| const char * | method, | ||
| const char * | url, | ||
| gsad_connection_info_t * | con_info, | ||
| http_handler_t * | handler, | ||
| void * | data | ||
| ) |
Definition at line 653 of file gsad_http_handler.c.
References cmd_response_data_new(), cmd_response_data_set_allow_caching(), file_content_response(), and handler_send_response().
Referenced by init_http_handlers().


| int handle_invalid_method | ( | http_connection_t * | connection, |
| const char * | method, | ||
| const char * | url, | ||
| gsad_connection_info_t * | con_info, | ||
| http_handler_t * | handler, | ||
| void * | data | ||
| ) |
Definition at line 338 of file gsad_http_handler.c.
References ERROR_PAGE, GSAD_CONTENT_TYPE_TEXT_HTML, http_handler_next(), and send_response().
Referenced by init_http_handlers().


| int handle_logout | ( | http_connection_t * | connection, |
| const char * | method, | ||
| const char * | url, | ||
| gsad_connection_info_t * | con_info, | ||
| http_handler_t * | handler, | ||
| void * | data | ||
| ) |
Definition at line 500 of file gsad_http_handler.c.
References GSAD_CONTENT_TYPE_TEXT_HTML, REMOVE_SID, send_response(), user_free(), user_get_username(), and user_logout().
Referenced by init_http_handlers().


| int handle_not_found | ( | http_connection_t * | connection, |
| const char * | method, | ||
| const char * | url, | ||
| gsad_connection_info_t * | con_info, | ||
| http_handler_t * | handler, | ||
| void * | data | ||
| ) |
Definition at line 330 of file gsad_http_handler.c.
References handler_send_not_found().
Referenced by init_http_handlers().


| int handle_request | ( | void * | cls, |
| http_connection_t * | connection, | ||
| const char * | url, | ||
| const char * | method, | ||
| const char * | version, | ||
| const char * | upload_data, | ||
| size_t * | upload_data_size, | ||
| void ** | con_cls | ||
| ) |
HTTP request handler for GSAD.
This routine is an MHD_AccessHandlerCallback, the request handler for microhttpd.
| [in] | cls | A pointer to http_handler_t |
| [in] | connection | Connection handle, e.g. used to send response. |
| [in] | url | The URL requested. |
| [in] | method | "GET" or "POST", others are disregarded. |
| [in] | version | Not used for this callback. |
| [in] | upload_data | Data used for POST requests. |
| [in] | upload_data_size | Size of upload_data. |
| [out] | con_cls | For exchange of connection-related data (here a struct gsad_connection_info). |
Definition at line 832 of file gsad_http_handler.c.
References BAD_REQUEST_PAGE, gsad_connection_info::connectiontype, GSAD_CONTENT_TYPE_TEXT_HTML, handlers, http_handler_start(), MHD_HTTP_NOT_ACCEPTABLE, gsad_connection_info::params, params_mhd_add(), params_mhd_validate(), params_new(), POST_BUFFER_SIZE, gsad_connection_info::postprocessor, reconstruct_url(), send_response(), and serve_post().

| int handle_setup_credentials | ( | http_connection_t * | connection, |
| const char * | method, | ||
| const char * | url, | ||
| gsad_connection_info_t * | con_info, | ||
| http_handler_t * | handler, | ||
| void * | data | ||
| ) |
Definition at line 458 of file gsad_http_handler.c.
References accept_language_to_env_fmt(), credentials_new(), get_client_address(), GSAD_CONTENT_TYPE_TEXT_HTML, http_handler_next(), send_response(), user_free(), user_get_language(), and UTF8_ERROR_PAGE.
Referenced by init_http_handlers().


| int handle_setup_user | ( | http_connection_t * | connection, |
| const char * | method, | ||
| const char * | url, | ||
| gsad_connection_info_t * | con_info, | ||
| http_handler_t * | handler, | ||
| void * | data | ||
| ) |
Definition at line 401 of file gsad_http_handler.c.
References BAD_MISSING_COOKIE, BAD_MISSING_TOKEN, get_user_from_connection(), GMP_SERVICE_DOWN, handler_send_reauthentication(), http_handler_next(), LOGIN_ERROR, LOGIN_FAILED, LOGOUT_ALREADY, LOGOUT_URL, SESSION_EXPIRED, USER_BAD_MISSING_COOKIE, USER_BAD_MISSING_TOKEN, USER_EXPIRED_TOKEN, user_get_username(), USER_GMP_DOWN, USER_GUEST_LOGIN_ERROR, USER_GUEST_LOGIN_FAILED, and USER_IP_ADDRESS_MISSMATCH.
Referenced by init_http_handlers().


| int handle_static_config | ( | http_connection_t * | connection, |
| const char * | method, | ||
| const char * | url, | ||
| gsad_connection_info_t * | con_info, | ||
| http_handler_t * | handler, | ||
| void * | data | ||
| ) |
Definition at line 706 of file gsad_http_handler.c.
References cmd_response_data_new(), cmd_response_data_set_allow_caching(), cmd_response_data_set_status_code(), file_content_response(), handler_create_response(), and handler_send_response().
Referenced by init_http_handlers().


| int handle_static_file | ( | http_connection_t * | connection, |
| const char * | method, | ||
| const char * | url, | ||
| gsad_connection_info_t * | con_info, | ||
| http_handler_t * | handler, | ||
| void * | data | ||
| ) |
Definition at line 669 of file gsad_http_handler.c.
References cmd_response_data_new(), cmd_response_data_set_allow_caching(), file_content_response(), and handler_send_response().
Referenced by init_http_handlers().


| int handle_system_report | ( | http_connection_t * | connection, |
| const char * | method, | ||
| const char * | url, | ||
| gsad_connection_info_t * | con_info, | ||
| http_handler_t * | handler, | ||
| void * | data | ||
| ) |
Definition at line 578 of file gsad_http_handler.c.
References cmd_response_data_free(), cmd_response_data_new(), credentials_free(), get_system_report_gmp(), GMP_SERVICE_DOWN, gsad_message(), gvm_validate(), handler_create_response(), handler_send_reauthentication(), http_validator, manager_connect(), params_mhd_add(), params_mhd_validate(), params_new(), and params_t.
Referenced by init_http_handlers().


| int handle_url | ( | http_connection_t * | connection, |
| const char * | method, | ||
| const char * | url, | ||
| gsad_connection_info_t * | con_info, | ||
| http_handler_t * | current, | ||
| void * | data | ||
| ) |
Definition at line 240 of file gsad_http_handler.c.
References http_handler::data, url_map::gregexp, url_map::handler, http_handler_next(), and http_handler_start().
Referenced by url_handler_new().


| int handle_validate | ( | http_connection_t * | connection, |
| const char * | method, | ||
| const char * | url, | ||
| gsad_connection_info_t * | con_info, | ||
| http_handler_t * | handler, | ||
| void * | data | ||
| ) |
Definition at line 298 of file gsad_http_handler.c.
References BAD_REQUEST_PAGE, GSAD_CONTENT_TYPE_TEXT_HTML, handler_send_not_found(), http_handler_next(), MHD_HTTP_NOT_ACCEPTABLE, send_response(), and UTF8_ERROR_PAGE.
Referenced by init_http_handlers().


| http_handler_t* http_handler_add | ( | http_handler_t * | handlers, |
| http_handler_t * | next | ||
| ) |
Definition at line 94 of file gsad_http_handler.c.
References handlers, and http_handler::next.
Referenced by init_http_handlers(), and url_handler_add_func().

| void http_handler_free | ( | http_handler_t * | handler | ) |
Definition at line 166 of file gsad_http_handler.c.
References http_handler::free, http_handler_free(), and http_handler::next.
Referenced by cleanup_http_handlers(), http_handler_free(), method_router_free(), and url_handler_free().


| void http_handler_free_internal | ( | http_handler_t * | handler | ) |
Definition at line 154 of file gsad_http_handler.c.
Referenced by http_handler_new(), method_router_free(), and url_handler_free().

| http_handler_t* http_handler_new | ( | http_handler_func_t | func | ) |
Definition at line 160 of file gsad_http_handler.c.
References http_handler_free_internal(), and http_handler_new_with_data().
Referenced by init_http_handlers(), and url_handler_add_func().


| http_handler_t* http_handler_new_with_data | ( | http_handler_func_t | func, |
| http_handler_free_func_t | freefunc, | ||
| void * | data | ||
| ) |
Definition at line 142 of file gsad_http_handler.c.
References http_handler::data, http_handler::free, http_handler::handle, and http_handler::next.
Referenced by http_handler_new(), method_router_new(), and url_handler_new().

| int http_handler_next | ( | http_connection_t * | connection, |
| const char * | method, | ||
| const char * | url, | ||
| gsad_connection_info_t * | con_info, | ||
| http_handler_t * | handler, | ||
| void * | data | ||
| ) |
Definition at line 126 of file gsad_http_handler.c.
References http_handler::handle, and http_handler::next.
Referenced by handle_get_post(), handle_get_user(), handle_invalid_method(), handle_setup_credentials(), handle_setup_user(), handle_url(), and handle_validate().

| int http_handler_start | ( | http_connection_t * | connection, |
| const char * | method, | ||
| const char * | url, | ||
| gsad_connection_info_t * | con_info, | ||
| http_handler_t * | handler, | ||
| void * | data | ||
| ) |
Definition at line 114 of file gsad_http_handler.c.
References http_handler::handle.
Referenced by handle_get_post(), handle_request(), and handle_url().

| http_handler_t* init_http_handlers | ( | ) |
Definition at line 743 of file gsad_http_handler.c.
References gvm_validator_add(), gvm_validator_new(), handle_get_user(), handle_gmp_get(), handle_gmp_post(), handle_index(), handle_invalid_method(), handle_logout(), handle_not_found(), handle_setup_credentials(), handle_setup_user(), handle_static_config(), handle_static_file(), handle_system_report(), handle_validate(), handlers, http_handler_add(), http_handler_new(), http_validator, method_router_new(), method_router_set_get_handler(), method_router_set_post_handler(), SLAVE_ID_REGEXP, TOKEN_REGEXP, url_handler_add_func(), and url_handler_new().

| void method_router_free | ( | http_handler_t * | handler | ) |
Definition at line 203 of file gsad_http_handler.c.
References http_handler::data, method_router::get, http_handler_free(), http_handler_free_internal(), and method_router::post.
Referenced by method_router_new().


| http_handler_t* method_router_new | ( | ) |
Definition at line 216 of file gsad_http_handler.c.
References method_router::get, handle_get_post(), http_handler_new_with_data(), method_router_free(), and method_router::post.
Referenced by init_http_handlers().


| void method_router_set_get_handler | ( | http_handler_t * | router, |
| http_handler_t * | handler | ||
| ) |
Definition at line 226 of file gsad_http_handler.c.
References http_handler::data, and method_router::get.
Referenced by init_http_handlers().

| void method_router_set_post_handler | ( | http_handler_t * | router, |
| http_handler_t * | handler | ||
| ) |
Definition at line 233 of file gsad_http_handler.c.
References http_handler::data, and method_router::post.
Referenced by init_http_handlers().

| http_handler_t* url_handler_add_func | ( | http_handler_t * | handlers, |
| const gchar * | regexp, | ||
| http_handler_func_t | handle | ||
| ) |
Definition at line 289 of file gsad_http_handler.c.
References handlers, http_handler_add(), http_handler_new(), and url_handler_new().
Referenced by init_http_handlers().


| void url_handler_free | ( | http_handler_t * | handler | ) |
Definition at line 270 of file gsad_http_handler.c.
References http_handler::data, url_map::gregexp, url_map::handler, http_handler_free(), and http_handler_free_internal().
Referenced by url_handler_new().


| http_handler_t* url_handler_new | ( | const gchar * | regexp, |
| http_handler_t * | handler | ||
| ) |
Definition at line 282 of file gsad_http_handler.c.
References handle_url(), http_handler_new_with_data(), url_handler_free(), and url_map_new().
Referenced by init_http_handlers(), and url_handler_add_func().


| url_map_t* url_map_new | ( | const gchar * | regexp, |
| http_handler_t * | handler | ||
| ) |
Definition at line 261 of file gsad_http_handler.c.
References url_map::gregexp, and url_map::handler.
Referenced by url_handler_new().

| http_handler_t* handlers |
Definition at line 91 of file gsad_http_handler.c.
Referenced by cleanup_http_handlers(), handle_request(), http_handler_add(), init_http_handlers(), and url_handler_add_func().
| validator_t http_validator |
Validator instance for http params.
Definition at line 59 of file gsad_http_handler.c.
Referenced by cleanup_http_handlers(), get_user_from_connection(), handle_gmp_post(), handle_system_report(), and init_http_handlers().