|
Greenbone Security Assistant
8.0.0
|
HTTP handling of GSA. More...
#include "gsad_cmd.h"#include "gsad_content_type.h"#include "gsad_credentials.h"#include "gsad_user.h"#include <glib.h>#include <microhttpd.h>

Go to the source code of this file.
Data Structures | |
| struct | gsad_connection_info |
| Connection information. More... | |
Macros | |
| #define | DATE_2822_LEN 100 |
| At least maximum length of rfc2822 format date. More... | |
| #define | EXPIRES_LENGTH 100 |
| Max length of cookie expires param. More... | |
| #define | UTF8_ERROR_PAGE(location) |
| #define | SID_COOKIE_NAME "GSAD_SID" |
| Name of the cookie used to store the SID. More... | |
| #define | REMOVE_SID "0" |
| #define | NOT_FOUND_TITLE "Invalid request" |
| Title for "Page not found" messages. More... | |
| #define | NOT_FOUND_MESSAGE "The requested page or file does not exist." |
| Main message for "Page not found" messages. More... | |
| #define | ERROR_PAGE "<html><body>HTTP Method not supported</body></html>" |
| Error page HTML. More... | |
| #define | BAD_REQUEST_PAGE "<html><body>Bad request.</body></html>" |
| Bad request error HTML. More... | |
| #define | SERVER_ERROR "<html><body>An internal server error has occurred.</body></html>" |
| Server error HTML. More... | |
| #define | MAX_HOST_LEN 1000 |
| Maximum length of the host portion of the redirect address. More... | |
| #define | LOGIN_URL "/login" |
| #define | LOGOUT_URL "/logout" |
| #define | POST_BUFFER_SIZE 500000 |
| Buffer size for POST processor. More... | |
| #define | MHD_HTTP_NOT_ACCEPTABLE MHD_HTTP_METHOD_NOT_ACCEPTABLE |
| The symbol is deprecated, but older versions (0.9.37 - Debian jessie) don't define it yet. More... | |
| #define | MAX_FILE_NAME_SIZE 128 |
| Maximum length of "file name" for /help/ URLs. More... | |
Typedefs | |
| typedef struct gsad_connection_info | gsad_connection_info_t |
| Connection information. More... | |
| typedef struct MHD_Connection | http_connection_t |
| typedef struct MHD_Response | http_response_t |
| typedef enum authentication_reason | authentication_reason_t |
Enumerations | |
| enum | authentication_reason { LOGIN_FAILED, LOGIN_ERROR, LOGOUT, LOGOUT_ALREADY, GMP_SERVICE_DOWN, SESSION_EXPIRED, BAD_MISSING_COOKIE, BAD_MISSING_TOKEN } |
| Content types. 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 | handler_create_response (http_connection_t *connection, gchar *data, cmd_response_data_t *response_data, const gchar *sid) |
| Create and send a 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_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 | 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 | send_redirect_to_uri (http_connection_t *connection, const char *uri, const gchar *sid) |
| Sends a HTTP redirection to an uri. 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... | |
| 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... | |
| gchar * | reconstruct_url (http_connection_t *connection, const char *url) |
| Reconstruct the URL for a connection. 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... | |
| 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) |
| int | exec_gmp_get (http_connection_t *connection, gsad_connection_info_t *con_info, credentials_t *credentials) |
| int | exec_gmp_post (http_connection_t *connection, gsad_connection_info_t *con_info, const char *client_address) |
| int | params_append_mhd (params_t *params, const char *name, const char *filename, const char *chunk_data, int chunk_size, int chunk_offset) |
| char * | gsad_message (credentials_t *, const char *, const char *, int, const char *, cmd_response_data_t *) |
| Handles fatal errors. More... | |
HTTP handling of GSA.
Definition in file gsad_http.h.
| #define BAD_REQUEST_PAGE "<html><body>Bad request.</body></html>" |
Bad request error HTML.
Definition at line 80 of file gsad_http.h.
| #define DATE_2822_LEN 100 |
At least maximum length of rfc2822 format date.
Definition at line 39 of file gsad_http.h.
| #define ERROR_PAGE "<html><body>HTTP Method not supported</body></html>" |
Error page HTML.
Definition at line 75 of file gsad_http.h.
| #define EXPIRES_LENGTH 100 |
Max length of cookie expires param.
Definition at line 44 of file gsad_http.h.
| #define LOGIN_URL "/login" |
Definition at line 95 of file gsad_http.h.
| #define LOGOUT_URL "/logout" |
Definition at line 96 of file gsad_http.h.
| #define MAX_FILE_NAME_SIZE 128 |
Maximum length of "file name" for /help/ URLs.
Definition at line 114 of file gsad_http.h.
| #define MAX_HOST_LEN 1000 |
Maximum length of the host portion of the redirect address.
Definition at line 93 of file gsad_http.h.
| #define MHD_HTTP_NOT_ACCEPTABLE MHD_HTTP_METHOD_NOT_ACCEPTABLE |
The symbol is deprecated, but older versions (0.9.37 - Debian jessie) don't define it yet.
Definition at line 108 of file gsad_http.h.
| #define NOT_FOUND_MESSAGE "The requested page or file does not exist." |
Main message for "Page not found" messages.
Definition at line 70 of file gsad_http.h.
| #define NOT_FOUND_TITLE "Invalid request" |
Title for "Page not found" messages.
Definition at line 65 of file gsad_http.h.
| #define POST_BUFFER_SIZE 500000 |
Buffer size for POST processor.
Definition at line 101 of file gsad_http.h.
| #define REMOVE_SID "0" |
Definition at line 60 of file gsad_http.h.
| #define SERVER_ERROR "<html><body>An internal server error has occurred.</body></html>" |
Server error HTML.
Definition at line 85 of file gsad_http.h.
| #define SID_COOKIE_NAME "GSAD_SID" |
Name of the cookie used to store the SID.
Definition at line 58 of file gsad_http.h.
| #define UTF8_ERROR_PAGE | ( | location | ) |
Definition at line 49 of file gsad_http.h.
| typedef enum authentication_reason authentication_reason_t |
Definition at line 171 of file gsad_http.h.
| typedef struct gsad_connection_info gsad_connection_info_t |
Connection information.
These objects are used to hold connection information during the multiple calls of the request handler that refer to the same request.
Once a request is finished, the object will be free'd.
| typedef struct MHD_Connection http_connection_t |
Definition at line 135 of file gsad_http.h.
| typedef struct MHD_Response http_response_t |
Definition at line 137 of file gsad_http.h.
Content types.
| Enumerator | |
|---|---|
| LOGIN_FAILED | |
| LOGIN_ERROR | |
| LOGOUT | |
| LOGOUT_ALREADY | |
| GMP_SERVICE_DOWN | |
| SESSION_EXPIRED | |
| BAD_MISSING_COOKIE | |
| BAD_MISSING_TOKEN | |
Definition at line 159 of file gsad_http.h.
| 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().


| 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().


| int exec_gmp_get | ( | http_connection_t * | connection, |
| gsad_connection_info_t * | con_info, | ||
| credentials_t * | credentials | ||
| ) |
| int exec_gmp_post | ( | http_connection_t * | connection, |
| gsad_connection_info_t * | con_info, | ||
| const char * | client_address | ||
| ) |
| 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().


| 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().


| int params_append_mhd | ( | params_t * | params, |
| const char * | name, | ||
| const char * | filename, | ||
| const char * | chunk_data, | ||
| int | chunk_size, | ||
| int | chunk_offset | ||
| ) |
| 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().

