Greenbone Security Assistant
|
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 , UNKOWN_ERROR } |
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_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.
#define BAD_REQUEST_PAGE "<html><body>Bad request.</body></html>" |
Bad request error HTML.
#define DATE_2822_LEN 100 |
At least maximum length of rfc2822 format date.
#define ERROR_PAGE "<html><body>HTTP Method not supported</body></html>" |
Error page HTML.
#define EXPIRES_LENGTH 100 |
Max length of cookie expires param.
#define LOGIN_URL "/login" |
#define LOGOUT_URL "/logout" |
#define MAX_FILE_NAME_SIZE 128 |
Maximum length of "file name" for /help/ URLs.
#define MAX_HOST_LEN 1000 |
Maximum length of the host portion of the redirect address.
#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.
#define NOT_FOUND_MESSAGE "The requested page or file does not exist." |
Main message for "Page not found" messages.
#define NOT_FOUND_TITLE "Invalid request" |
Title for "Page not found" messages.
#define POST_BUFFER_SIZE 500000 |
Buffer size for POST processor.
#define REMOVE_SID "0" |
#define SERVER_ERROR "<html><body>An internal server error has occurred.</body></html>" |
Server error HTML.
#define SID_COOKIE_NAME "GSAD_SID" |
Name of the cookie used to store the SID.
#define UTF8_ERROR_PAGE | ( | location | ) |
typedef enum authentication_reason authentication_reason_t |
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 |
typedef struct MHD_Response http_response_t |
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.
[in] | response | The HTTP response to add the headers to. |
[in] | allow_caching | 1 to allow caching, 0 to forbid. |
void add_guest_chart_content_security_headers | ( | http_response_t * | response | ) |
Add guest chart content security headers to a MHD response.
void add_security_headers | ( | http_response_t * | response | ) |
Add security headers to a MHD 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 |
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. |
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 |
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. |
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. |
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. |
content_type_t guess_content_type | ( | const gchar * | path | ) |
Guess a content type from a file extension.
[in] | path | filename with extension |
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. |
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 |
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. |
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. |
int remove_sid | ( | http_response_t * | response | ) |
Attach expired SID cookie to response.
[in] | response | Response. |
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. |
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). |
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. |