|
Greenbone Security Assistant
8.0.0
|
HTTP handling. More...
#include "gsad_http.h"#include "gsad_base.h"#include "gsad_i18n.h"#include "gsad_settings.h"#include "utils.h"#include <assert.h>#include <gvm/base/networking.h>#include <gvm/util/xmlutils.h>#include <locale.h>#include <stdlib.h>#include <string.h>#include <sys/stat.h>#include <sys/types.h>#include <unistd.h>
Go to the source code of this file.
Macros | |
| #define | G_LOG_DOMAIN "gsad http" |
| GLib log domain. More... | |
Functions | |
| content_type_t | guess_content_type (const gchar *path) |
| Guess a content type from a file extension. More... | |
| void | gsad_add_content_type_header (http_response_t *response, content_type_t *ct) |
| Adds content-type header fields to a response. More... | |
| int | send_redirect_to_uri (http_connection_t *connection, const char *uri, const gchar *sid) |
| Sends a HTTP redirection to an uri. More... | |
| int | send_response (http_connection_t *connection, const char *content, int status_code, const gchar *sid, content_type_t content_type, const char *content_disposition, size_t content_length) |
| Sends a HTTP response. More... | |
| int | handler_send_response (http_connection_t *connection, http_response_t *response, cmd_response_data_t *response_data, const gchar *sid) |
| Send response for handle_request. More... | |
| int | handler_create_response (http_connection_t *connection, gchar *data, cmd_response_data_t *response_data, const gchar *sid) |
| Create and send a response. More... | |
| http_response_t * | create_not_found_response (const gchar *url, cmd_response_data_t *response_data) |
| Create a default 404 (not found) http response. More... | |
| int | handler_send_not_found (http_connection_t *connection, const gchar *url) |
| Send a 404 response for a request. More... | |
| int | handler_send_reauthentication (http_connection_t *connection, int http_status_code, authentication_reason_t reason) |
| Allow for reauthentication of a user. More... | |
| int | remove_sid (http_response_t *response) |
| Attach expired SID cookie to response. More... | |
| int | attach_sid (http_response_t *response, const char *sid) |
| Attach SID cookie to a response, resetting "expire" arg. More... | |
| int | attach_remove_sid (http_response_t *response, const gchar *sid) |
| static int | file_reader (void *cls, uint64_t pos, char *buf, int max) |
| Reads from a file. More... | |
| http_response_t * | file_content_response (http_connection_t *connection, const char *url, const char *path, cmd_response_data_t *response_data) |
| Create a response to serve a file from a path. More... | |
| static int | append_param (void *string, enum MHD_ValueKind kind, const char *key, const char *value) |
| Append a request param to a string. More... | |
| gchar * | reconstruct_url (http_connection_t *connection, const char *url) |
| Reconstruct the URL for a connection. More... | |
| void | add_security_headers (http_response_t *response) |
| Add security headers to a MHD response. More... | |
| void | add_guest_chart_content_security_headers (http_response_t *response) |
| Add guest chart content security headers to a MHD response. More... | |
| void | add_cors_headers (http_response_t *response) |
| void | add_forbid_caching_headers (http_response_t *response) |
| Add header to forbid caching to a HTTP response. More... | |
| int | get_client_address (http_connection_t *conn, char *client_address) |
| Get the client's address. More... | |
| int | serve_post (void *coninfo_cls, enum MHD_ValueKind kind, const char *key, const char *filename, const char *content_type, const char *transfer_encoding, const char *data, uint64_t off, size_t size) |
| Serves part of a POST request. More... | |
| char * | gsad_message (credentials_t *credentials, const char *title, const char *function, int line, const char *msg, cmd_response_data_t *response_data) |
| Handles fatal errors. More... | |
HTTP handling.
Definition in file gsad_http.c.
| #define G_LOG_DOMAIN "gsad http" |
GLib log domain.
Definition at line 46 of file gsad_http.c.
| void add_cors_headers | ( | http_response_t * | response | ) |
Definition at line 861 of file gsad_http.c.
References get_http_cors_origin(), and http_cors_origin.
Referenced by handler_send_response(), send_redirect_to_uri(), and send_response().


| void add_forbid_caching_headers | ( | http_response_t * | response | ) |
Add header to forbid caching to a HTTP response.
| [in] | response | The HTTP response to add the headers to. |
| [in] | allow_caching | 1 to allow caching, 0 to forbid. |
Definition at line 881 of file gsad_http.c.
Referenced by handler_send_response(), send_redirect_to_uri(), and send_response().

| void add_guest_chart_content_security_headers | ( | http_response_t * | response | ) |
Add guest chart content security headers to a MHD response.
Definition at line 850 of file gsad_http.c.
References get_http_content_security_policy(), get_http_guest_chart_content_security_policy(), get_http_guest_chart_x_frame_options(), and get_http_x_frame_options().

| void add_security_headers | ( | http_response_t * | response | ) |
Add security headers to a MHD response.
Definition at line 828 of file gsad_http.c.
References get_http_content_security_policy(), get_http_strict_transport_security(), get_http_x_frame_options(), http_content_security_policy, http_strict_transport_security, and http_x_frame_options.
Referenced by handler_send_response(), send_redirect_to_uri(), and send_response().


|
static |
Append a request param to a string.
| [in] | string | String. |
| [in] | kind | Kind of request data. |
| [in] | key | Key. |
| [in] | value | Value. |
Definition at line 775 of file gsad_http.c.
Referenced by reconstruct_url().

| int attach_remove_sid | ( | http_response_t * | response, |
| const gchar * | sid | ||
| ) |
Attach or remove session id
If sid is "0" the session id will be removed. Otherwise if the sid is not NULL the sid will be attached to the response.
| [in] | response | HTTP response |
| [in] | sid | Session ID |
Definition at line 636 of file gsad_http.c.
References attach_sid(), REMOVE_SID, remove_sid(), and str_equal().
Referenced by handler_send_response(), send_redirect_to_uri(), and send_response().


| int attach_sid | ( | http_response_t * | response, |
| const char * | sid | ||
| ) |
Attach SID cookie to a response, resetting "expire" arg.
| [in] | response | Response. |
| [in] | sid | Session ID. |
Definition at line 558 of file gsad_http.c.
References EXPIRES_LENGTH, get_session_timeout(), is_use_secure_cookie(), and SID_COOKIE_NAME.
Referenced by attach_remove_sid().


| http_response_t* create_not_found_response | ( | const gchar * | url, |
| cmd_response_data_t * | response_data | ||
| ) |
Create a default 404 (not found) http response.
| [in] | url | Requested (not found) url |
| [out] | response_data | Response data to return |
Definition at line 393 of file gsad_http.c.
References cmd_response_data_get_content_length(), cmd_response_data_set_content_length(), cmd_response_data_set_content_type(), cmd_response_data_set_status_code(), and GSAD_CONTENT_TYPE_TEXT_HTML.
Referenced by file_content_response(), and handler_send_not_found().


| http_response_t* file_content_response | ( | http_connection_t * | connection, |
| const char * | url, | ||
| const char * | path, | ||
| cmd_response_data_t * | response_data | ||
| ) |
Create a response to serve a file from a path.
| [in] | connection | Connection. |
| [in] | url | Requested URL. |
| [in] | path | Path to file. |
| [out] | response_data | Return response data |
Definition at line 694 of file gsad_http.c.
References cmd_response_data_set_content_type(), cmd_response_data_set_status_code(), create_not_found_response(), DATE_2822_LEN, file_reader(), and guess_content_type().
Referenced by handle_index(), handle_static_config(), and handle_static_file().


|
static |
Reads from a file.
| [in] | cls | File. |
| [in] | pos | Position in file to start reading. |
| [out] | buf | Buffer to read into. |
| [in] | max | Maximum number of bytes to read. |
Definition at line 674 of file gsad_http.c.
Referenced by file_content_response().

| int get_client_address | ( | http_connection_t * | conn, |
| char * | client_address | ||
| ) |
Get the client's address.
| [in] | conn | Connection. |
| [out] | client_address | Buffer to store client address. Must have at least INET6_ADDRSTRLEN bytes. |
Definition at line 899 of file gsad_http.c.
References is_ignore_http_x_real_ip(), and is_unix_socket().
Referenced by get_user_from_connection(), handle_gmp_post(), and handle_setup_credentials().


| void gsad_add_content_type_header | ( | http_response_t * | response, |
| content_type_t * | ct | ||
| ) |
Adds content-type header fields to a response.
This function should be called only once per response and is the only function where values of enum content_types are translated into strings.
| [in,out] | response | Response to add header to. |
| [in] | ct | Content Type to set. |
Definition at line 89 of file gsad_http.c.
References GSAD_CONTENT_TYPE_APP_DEB, GSAD_CONTENT_TYPE_APP_EXE, GSAD_CONTENT_TYPE_APP_JSON, GSAD_CONTENT_TYPE_APP_KEY, GSAD_CONTENT_TYPE_APP_NBE, GSAD_CONTENT_TYPE_APP_PDF, GSAD_CONTENT_TYPE_APP_RPM, GSAD_CONTENT_TYPE_APP_XHTML, GSAD_CONTENT_TYPE_APP_XML, GSAD_CONTENT_TYPE_DONE, GSAD_CONTENT_TYPE_IMAGE_GIF, GSAD_CONTENT_TYPE_IMAGE_PNG, GSAD_CONTENT_TYPE_IMAGE_SVG, GSAD_CONTENT_TYPE_OCTET_STREAM, GSAD_CONTENT_TYPE_TEXT_CSS, GSAD_CONTENT_TYPE_TEXT_HTML, GSAD_CONTENT_TYPE_TEXT_JS, and GSAD_CONTENT_TYPE_TEXT_PLAIN.
Referenced by handler_send_response(), and send_response().

| char* gsad_message | ( | credentials_t * | credentials, |
| const char * | title, | ||
| const char * | function, | ||
| int | line, | ||
| const char * | msg, | ||
| cmd_response_data_t * | response_data | ||
| ) |
Handles fatal errors.
| [in] | credentials | User authentication information. |
| [in] | title | The title for the message. |
| [in] | function | The function in which the error occurred. |
| [in] | line | The line number at which the error occurred. |
| [in] | msg | The response message. |
| [out] | response_data | Extra data return for the HTTP response. |
Definition at line 978 of file gsad_http.c.
References cmd_response_data_set_content_length(), cmd_response_data_set_content_type(), credentials_get_language(), credentials_get_user(), ctime_r_strip_newline(), GSAD_CONTENT_TYPE_APP_XML, user_get_capabilities(), user_get_client_address(), user_get_role(), user_get_token(), user_get_username(), and vendor_version_get().
Referenced by auth_settings_gmp(), bulk_delete_gmp(), check_modify_config(), clone_gmp(), create_agent_gmp(), create_alert_gmp(), create_asset_gmp(), create_config_gmp(), create_container_task_gmp(), create_credential_gmp(), create_filter_gmp(), create_group_gmp(), create_host_gmp(), create_note_gmp(), create_override_gmp(), create_permission_gmp(), create_permissions_gmp(), create_port_list_gmp(), create_port_range_gmp(), create_report_gmp(), create_role_gmp(), create_scanner_gmp(), create_schedule_gmp(), create_tag_gmp(), create_target_gmp(), create_task_gmp(), create_ticket_gmp(), create_user_gmp(), delete_asset_gmp(), delete_resource(), download_agent_gmp(), download_ca_pub(), download_credential_gmp(), download_key_pub(), download_ssl_cert(), edit_alert(), edit_resource(), edit_role(), empty_trashcan_gmp(), export_many(), export_preference_file_gmp(), export_resource(), get_aggregate_gmp(), get_alert(), get_alerts(), get_asset(), get_assets(), get_config(), get_config_family(), get_config_nvt(), get_feeds_gmp(), get_info(), get_many(), get_one(), get_report(), get_setting_gmp(), get_settings_gmp(), get_system_reports_gmp(), get_user(), get_users(), handle_system_report(), handler_send_reauthentication(), import_config_gmp(), import_port_list_gmp(), import_report_format_gmp(), move_task_gmp(), new_alert(), report_alert_gmp(), resource_action(), restore_gmp(), run_wizard_gmp(), save_agent_gmp(), save_alert_gmp(), save_asset_gmp(), save_auth_gmp(), save_config_family_gmp(), save_config_gmp(), save_config_nvt_gmp(), save_container_task_gmp(), save_credential_gmp(), save_filter_gmp(), save_group_gmp(), save_my_settings_gmp(), save_note_gmp(), save_osp_prefs(), save_override_gmp(), save_permission_gmp(), save_port_list_gmp(), save_report_format_gmp(), save_role_gmp(), save_scanner_gmp(), save_schedule_gmp(), save_setting_gmp(), save_tag_gmp(), save_target_gmp(), save_task_gmp(), save_ticket_gmp(), save_user_gmp(), simple_gmpf(), sync_config_gmp(), sync_feed(), test_alert_gmp(), toggle_tag_gmp(), verify_agent_gmp(), verify_report_format_gmp(), verify_scanner_gmp(), wizard(), and wizard_get().

| content_type_t guess_content_type | ( | const gchar * | path | ) |
Guess a content type from a file extension.
| [in] | path | filename with extension |
Definition at line 56 of file gsad_http.c.
References GSAD_CONTENT_TYPE_APP_JSON, GSAD_CONTENT_TYPE_IMAGE_GIF, GSAD_CONTENT_TYPE_IMAGE_PNG, GSAD_CONTENT_TYPE_IMAGE_SVG, GSAD_CONTENT_TYPE_OCTET_STREAM, GSAD_CONTENT_TYPE_TEXT_CSS, GSAD_CONTENT_TYPE_TEXT_HTML, GSAD_CONTENT_TYPE_TEXT_JS, and GSAD_CONTENT_TYPE_TEXT_PLAIN.
Referenced by file_content_response().

| int handler_create_response | ( | http_connection_t * | connection, |
| gchar * | data, | ||
| cmd_response_data_t * | response_data, | ||
| const gchar * | sid | ||
| ) |
Create and send a response.
The passed response data will be freed and can't be used afterwards
| [in] | connection | Connection handle, e.g. used to send response. |
| [in] | data | Data to send in response |
| [in] | response_data | Response data struct. Response data will be freed. |
| [in] | sid | Session ID, or NULL. "0" to remove session. |
Definition at line 368 of file gsad_http.c.
References cmd_response_data_get_content_length(), and handler_send_response().
Referenced by handle_static_config(), handle_system_report(), handler_send_reauthentication(), and login().


| int handler_send_not_found | ( | http_connection_t * | connection, |
| const gchar * | url | ||
| ) |
Send a 404 response for a request.
| [in] | connection | Connection handle, e.g. used to send response. |
| [in] | url | Requested url. |
Definition at line 438 of file gsad_http.c.
References cmd_response_data_new(), create_not_found_response(), and handler_send_response().
Referenced by handle_not_found(), and handle_validate().


| int handler_send_reauthentication | ( | http_connection_t * | connection, |
| int | http_status_code, | ||
| authentication_reason_t | reason | ||
| ) |
Allow for reauthentication of a user.
| [in] | connection | Connection handle, e.g. used to send response. |
| [in] | http_status_code | HTTP status code for the response. |
| [in] | reason | Reason for re-authentication |
Definition at line 459 of file gsad_http.c.
References BAD_MISSING_COOKIE, BAD_MISSING_TOKEN, cmd_response_data_new(), cmd_response_data_set_status_code(), GMP_SERVICE_DOWN, gsad_message(), handler_create_response(), LOGIN_ERROR, LOGIN_FAILED, LOGOUT, LOGOUT_ALREADY, REMOVE_SID, and SESSION_EXPIRED.
Referenced by handle_setup_user(), handle_system_report(), and login().


| int handler_send_response | ( | http_connection_t * | connection, |
| http_response_t * | response, | ||
| cmd_response_data_t * | response_data, | ||
| const gchar * | sid | ||
| ) |
Send response for handle_request.
The passed response data will be freed and can't be used afterwards
| [in] | connection | Connection handle, e.g. used to send response. |
| [in] | response | Response. |
| [in] | response_data | Response data struct. Response data will be freed. |
| [in] | sid | Session ID, or NULL. "0" to remove session. |
Definition at line 295 of file gsad_http.c.
References add_cors_headers(), add_forbid_caching_headers(), add_security_headers(), attach_remove_sid(), BAD_REQUEST_PAGE, cmd_response_data_free(), cmd_response_data_get_content_disposition(), cmd_response_data_get_content_type(), cmd_response_data_get_content_type_string(), cmd_response_data_get_status_code(), cmd_response_data_is_allow_caching(), gsad_add_content_type_header(), GSAD_CONTENT_TYPE_STRING, GSAD_CONTENT_TYPE_TEXT_HTML, MHD_HTTP_NOT_ACCEPTABLE, and send_response().
Referenced by handle_index(), handle_static_config(), handle_static_file(), handler_create_response(), and handler_send_not_found().


| gchar* reconstruct_url | ( | http_connection_t * | connection, |
| const char * | url | ||
| ) |
Reconstruct the URL for a connection.
| [in] | connection | Connection. |
| [in] | url | Base part of URL. |
Definition at line 806 of file gsad_http.c.
References append_param().
Referenced by handle_request().


| int remove_sid | ( | http_response_t * | response | ) |
Attach expired SID cookie to response.
| [in] | response | Response. |
Definition at line 512 of file gsad_http.c.
References EXPIRES_LENGTH, is_use_secure_cookie(), and SID_COOKIE_NAME.
Referenced by attach_remove_sid().


| int send_redirect_to_uri | ( | http_connection_t * | connection, |
| const char * | uri, | ||
| const gchar * | sid | ||
| ) |
Sends a HTTP redirection to an uri.
| [in] | connection | The connection handle. |
| [in] | uri | The full URI to redirect to. |
| [in] | sid | Session ID to add, or NULL. |
Definition at line 183 of file gsad_http.c.
References add_cors_headers(), add_forbid_caching_headers(), add_security_headers(), and attach_remove_sid().

| int send_response | ( | http_connection_t * | connection, |
| const char * | content, | ||
| int | status_code, | ||
| const gchar * | sid, | ||
| content_type_t | content_type, | ||
| const char * | content_disposition, | ||
| size_t | content_length | ||
| ) |
Sends a HTTP response.
| [in] | connection | The connection handle. |
| [in] | content | The content. |
| [in] | status_code | The HTTP status code. |
| [in] | sid | Session ID, or NULL. |
| [in] | content_type | The content type. |
| [in] | content_disposition | The content disposition or NULL. |
| [in] | content_length | Content length, 0 for strlen (content). |
Definition at line 244 of file gsad_http.c.
References add_cors_headers(), add_forbid_caching_headers(), add_security_headers(), attach_remove_sid(), and gsad_add_content_type_header().
Referenced by handle_gmp_post(), handle_invalid_method(), handle_logout(), handle_request(), handle_setup_credentials(), handle_validate(), and handler_send_response().


| int serve_post | ( | void * | coninfo_cls, |
| enum MHD_ValueKind | kind, | ||
| const char * | key, | ||
| const char * | filename, | ||
| const char * | content_type, | ||
| const char * | transfer_encoding, | ||
| const char * | data, | ||
| uint64_t | off, | ||
| size_t | size | ||
| ) |
Serves part of a POST request.
Implements an MHD_PostDataIterator.
Called one or more times to collect the multiple parts (key/value pairs) of a POST request. Fills the params of a gsad_connection_info.
After serve_post, the connection info is free'd.
| [in,out] | coninfo_cls | Connection info (a gsad_connection_info). |
| [in] | kind | Type of request data (header, cookie, etc.). |
| [in] | key | Name of data (name of request variable). |
| [in] | filename | Name of uploaded file if any, else NULL. |
| [in] | content_type | MIME type of data if known, else NULL. |
| [in] | transfer_encoding | Transfer encoding if known, else NULL. |
| [in] | data | Data. |
| [in] | off | Offset into entire data. |
| [in] | size | Size of data, in bytes. |
Definition at line 948 of file gsad_http.c.
References gsad_connection_info::params, and params_append_mhd().
Referenced by handle_request().

