Greenbone Security Assistant  9.0.1
gsad_http.h File Reference

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>
Include dependency graph for gsad_http.h:
This graph shows which files directly or indirectly include this file:

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

Detailed Description

HTTP handling of GSA.

Definition in file gsad_http.h.

Macro Definition Documentation

◆ BAD_REQUEST_PAGE

#define BAD_REQUEST_PAGE   "<html><body>Bad request.</body></html>"

Bad request error HTML.

Definition at line 80 of file gsad_http.h.

◆ DATE_2822_LEN

#define DATE_2822_LEN   100

At least maximum length of rfc2822 format date.

Definition at line 39 of file gsad_http.h.

◆ ERROR_PAGE

#define ERROR_PAGE   "<html><body>HTTP Method not supported</body></html>"

Error page HTML.

Definition at line 75 of file gsad_http.h.

◆ EXPIRES_LENGTH

#define EXPIRES_LENGTH   100

Max length of cookie expires param.

Definition at line 44 of file gsad_http.h.

◆ LOGIN_URL

#define LOGIN_URL   "/login"

Definition at line 95 of file gsad_http.h.

◆ LOGOUT_URL

#define LOGOUT_URL   "/logout"

Definition at line 96 of file gsad_http.h.

◆ MAX_FILE_NAME_SIZE

#define MAX_FILE_NAME_SIZE   128

Maximum length of "file name" for /help/ URLs.

Definition at line 114 of file gsad_http.h.

◆ MAX_HOST_LEN

#define MAX_HOST_LEN   1000

Maximum length of the host portion of the redirect address.

Definition at line 93 of file gsad_http.h.

◆ MHD_HTTP_NOT_ACCEPTABLE

#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.

◆ NOT_FOUND_MESSAGE

#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.

◆ NOT_FOUND_TITLE

#define NOT_FOUND_TITLE   "Invalid request"

Title for "Page not found" messages.

Definition at line 65 of file gsad_http.h.

◆ POST_BUFFER_SIZE

#define POST_BUFFER_SIZE   500000

Buffer size for POST processor.

Definition at line 101 of file gsad_http.h.

◆ REMOVE_SID

#define REMOVE_SID   "0"

Definition at line 60 of file gsad_http.h.

◆ SERVER_ERROR

#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.

◆ SID_COOKIE_NAME

#define SID_COOKIE_NAME   "GSAD_SID"

Name of the cookie used to store the SID.

Definition at line 58 of file gsad_http.h.

◆ UTF8_ERROR_PAGE

#define UTF8_ERROR_PAGE (   location)
Value:
"<html>" \
"<head><title>Invalid request</title></head>" \
"<body>The request contained invalid UTF-8 in " location ".</body>" \
"</html>"

Definition at line 49 of file gsad_http.h.

Typedef Documentation

◆ authentication_reason_t

Definition at line 169 of file gsad_http.h.

◆ 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.

◆ http_connection_t

typedef struct MHD_Connection http_connection_t

Definition at line 135 of file gsad_http.h.

◆ http_response_t

typedef struct MHD_Response http_response_t

Definition at line 137 of file gsad_http.h.

Enumeration Type Documentation

◆ authentication_reason

Content types.

Enumerator
LOGIN_FAILED 
LOGIN_ERROR 
LOGOUT 
LOGOUT_ALREADY 
GMP_SERVICE_DOWN 
SESSION_EXPIRED 
BAD_MISSING_COOKIE 
BAD_MISSING_TOKEN 
UNKOWN_ERROR 

Definition at line 156 of file gsad_http.h.

157 {
158  LOGIN_FAILED,
159  LOGIN_ERROR,
160  LOGOUT,
166  UNKOWN_ERROR,
167 };

Function Documentation

◆ add_cors_headers()

void add_cors_headers ( http_response_t *  response)

Definition at line 840 of file gsad_http.c.

841 {
842  const gchar *http_cors_origin = get_http_cors_origin ();
843 
844  if (strcmp (http_cors_origin, ""))
845  {
846  MHD_add_response_header (response, "Access-Control-Allow-Origin",
848  MHD_add_response_header (response, "Access-Control-Allow-Credentials",
849  "true");
850  }
851 }

References get_http_cors_origin(), and http_cors_origin.

Referenced by handler_send_response(), send_redirect_to_uri(), and send_response().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ add_forbid_caching_headers()

void add_forbid_caching_headers ( http_response_t *  response)

Add header to forbid caching to a HTTP response.

Parameters
[in]responseThe HTTP response to add the headers to.
[in]allow_caching1 to allow caching, 0 to forbid.

Definition at line 860 of file gsad_http.c.

861 {
862  MHD_add_response_header (response, MHD_HTTP_HEADER_EXPIRES, "-1");
863  MHD_add_response_header (response, MHD_HTTP_HEADER_CACHE_CONTROL,
864  "no-cache, no-store");
865  MHD_add_response_header (response, MHD_HTTP_HEADER_PRAGMA, "no-cache");
866 }

Referenced by handler_send_response(), send_redirect_to_uri(), and send_response().

Here is the caller graph for this function:

◆ add_guest_chart_content_security_headers()

void add_guest_chart_content_security_headers ( http_response_t *  response)

Add guest chart content security headers to a MHD response.

Definition at line 829 of file gsad_http.c.

830 {
831  if (strcmp (get_http_x_frame_options (), ""))
832  MHD_add_response_header (response, "X-Frame-Options",
834  if (strcmp (get_http_content_security_policy (), ""))
835  MHD_add_response_header (response, "Content-Security-Policy",
837 }

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

Here is the call graph for this function:

◆ add_security_headers()

void add_security_headers ( http_response_t *  response)

Add security headers to a MHD response.

Definition at line 807 of file gsad_http.c.

808 {
810  const gchar *http_content_security_policy =
812  const gchar *http_strict_transport_security =
814 
815  if (strcmp (http_x_frame_options, ""))
816  MHD_add_response_header (response, "X-Frame-Options", http_x_frame_options);
817  if (strcmp (http_content_security_policy, ""))
818  MHD_add_response_header (response, "Content-Security-Policy",
821  MHD_add_response_header (response, "Strict-Transport-Security",
823 }

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ attach_remove_sid()

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.

Parameters
[in]responseHTTP response
[in]sidSession ID
Returns
MHD_YES on success, MHD_NO on failure

Definition at line 615 of file gsad_http.c.

616 {
617  if (sid)
618  {
619  if (str_equal (sid, REMOVE_SID))
620  {
621  if (remove_sid (response) == MHD_NO)
622  {
623  MHD_destroy_response (response);
624  g_warning ("%s: failed to remove SID, dropping request",
625  __FUNCTION__);
626  return MHD_NO;
627  }
628  }
629  else
630  {
631  if (attach_sid (response, sid) == MHD_NO)
632  {
633  MHD_destroy_response (response);
634  g_warning ("%s: failed to attach SID, dropping request",
635  __FUNCTION__);
636  return MHD_NO;
637  }
638  }
639  }
640  return MHD_YES;
641 }

References attach_sid(), REMOVE_SID, remove_sid(), and str_equal().

Referenced by handler_send_response(), send_redirect_to_uri(), and send_response().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ attach_sid()

int attach_sid ( http_response_t *  response,
const char *  sid 
)

Attach SID cookie to a response, resetting "expire" arg.

Parameters
[in]responseResponse.
[in]sidSession ID.
Returns
MHD_NO in case of problems. MHD_YES if all is OK.

Definition at line 537 of file gsad_http.c.

538 {
539  int ret, timeout;
540  gchar *value;
541  gchar *locale;
542  char expires[EXPIRES_LENGTH + 1];
543  struct tm expire_time_broken;
544  time_t now, expire_time;
545  gchar *tz;
546 
547  /* Set up the expires param. */
548 
549  /* Store current TZ, switch to GMT. */
550  tz = getenv ("TZ") ? g_strdup (getenv ("TZ")) : NULL;
551  if (setenv ("TZ", "GMT", 1) == -1)
552  {
553  g_critical ("%s: failed to set TZ\n", __FUNCTION__);
554  g_free (tz);
555  exit (EXIT_FAILURE);
556  }
557  tzset ();
558 
559  locale = g_strdup (setlocale (LC_ALL, NULL));
560  setlocale (LC_ALL, "C");
561 
562  timeout = get_session_timeout () * 60 + 30;
563 
564  now = time (NULL);
565  expire_time = now + timeout;
566  if (localtime_r (&expire_time, &expire_time_broken) == NULL)
567  abort ();
568  ret = strftime (expires, EXPIRES_LENGTH, "%a, %d %b %Y %T GMT",
569  &expire_time_broken);
570  if (ret == 0)
571  abort ();
572 
573  setlocale (LC_ALL, locale);
574  g_free (locale);
575 
576  /* Revert to stored TZ. */
577  if (tz)
578  {
579  if (setenv ("TZ", tz, 1) == -1)
580  {
581  g_warning ("%s: Failed to switch to original TZ", __FUNCTION__);
582  g_free (tz);
583  exit (EXIT_FAILURE);
584  }
585  }
586  else
587  unsetenv ("TZ");
588  g_free (tz);
589 
590  /* Add the cookie.
591  *
592  * Tim Brown's suggested cookie included a domain attribute. How would
593  * we get the domain in here? Maybe a --domain option. */
594 
595  value = g_strdup_printf (
596  SID_COOKIE_NAME "=%s; expires=%s; max-age=%d; path=/; %sHTTPonly", sid,
597  expires, timeout, (is_use_secure_cookie () ? "secure; " : ""));
598  ret = MHD_add_response_header (response, "Set-Cookie", value);
599  g_free (value);
600  return ret;
601 }

References EXPIRES_LENGTH, get_session_timeout(), is_use_secure_cookie(), and SID_COOKIE_NAME.

Referenced by attach_remove_sid().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ exec_gmp_get()

int exec_gmp_get ( http_connection_t *  connection,
gsad_connection_info_t *  con_info,
credentials_t *  credentials 
)

Referenced by handle_gmp_get().

Here is the caller graph for this function:

◆ exec_gmp_post()

int exec_gmp_post ( http_connection_t *  connection,
gsad_connection_info_t *  con_info,
const char *  client_address 
)

Referenced by handle_gmp_post().

Here is the caller graph for this function:

◆ file_content_response()

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.

Parameters
[in]connectionConnection.
[in]urlRequested URL.
[in]pathPath to file.
[out]response_dataReturn response data
Returns
Response to send in combination with the response code. NULL only if file information could not be retrieved.

Definition at line 673 of file gsad_http.c.

675 {
676  char date_2822[DATE_2822_LEN];
677  struct tm *mtime;
678  time_t next_week;
679  http_response_t *response;
680  FILE *file;
681  struct stat buf;
682 
683  cmd_response_data_set_status_code (response_data, MHD_HTTP_OK);
684 
685  if (!g_file_test (path, (G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)))
686  {
687  /* path does not exists or is not a file */
688  /* return index.html to show page not found via js */
689  g_debug ("File %s not found. Return index.html", path);
690 
691  path = "index.html";
692  cmd_response_data_set_status_code (response_data, MHD_HTTP_NOT_FOUND);
693  }
694 
695  file = fopen (path, "r"); /* this file is just read and sent */
696 
697  if (file == NULL)
698  {
699  g_debug ("File %s failed, ", path);
700  return create_not_found_response (response_data);
701  }
702 
703  /* Guess content type. */
705 
706  if (stat (path, &buf))
707  {
708  /* File information could not be retrieved. */
709  g_critical ("%s: file <%s> can not be stat'ed.\n", __FUNCTION__, path);
710  fclose (file);
711  return create_not_found_response (response_data);
712  }
713 
714  /* Make sure the requested path really is a file. */
715  if ((buf.st_mode & S_IFMT) != S_IFREG)
716  {
717  fclose (file);
718  return create_not_found_response (response_data);
719  }
720 
721  response = MHD_create_response_from_callback (
722  buf.st_size, 32 * 1024, (MHD_ContentReaderCallback) &file_reader, file,
723  (MHD_ContentReaderFreeCallback) &fclose);
724 
725  mtime = localtime (&buf.st_mtime);
726  if (mtime
727  && strftime (date_2822, DATE_2822_LEN, "%a, %d %b %Y %H:%M:%S %Z", mtime))
728  {
729  MHD_add_response_header (response, "Last-Modified", date_2822);
730  }
731 
732  next_week = time (NULL) + 7 * 24 * 60 * 60;
733  mtime = localtime (&next_week);
734  if (mtime
735  && strftime (date_2822, DATE_2822_LEN, "%a, %d %b %Y %H:%M:%S %Z", mtime))
736  {
737  MHD_add_response_header (response, "Expires", date_2822);
738  }
739 
740  return response;
741 }

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_client_address()

int get_client_address ( http_connection_t *  conn,
char *  client_address 
)

Get the client's address.

Parameters
[in]connConnection.
[out]client_addressBuffer to store client address. Must have at least INET6_ADDRSTRLEN bytes.
Returns
0 success, 1 invalid UTF-8 in X-Real-IP header

Definition at line 878 of file gsad_http.c.

879 {
880  const char *x_real_ip;
881 
882  /* First try X-Real-IP header (unless told to ignore), then MHD connection. */
883 
884  x_real_ip = MHD_lookup_connection_value (conn, MHD_HEADER_KIND, "X-Real-IP");
885 
886  if (!is_ignore_http_x_real_ip () && x_real_ip
887  && g_utf8_validate (x_real_ip, -1, NULL) == FALSE)
888  return 1;
889  else if (!is_ignore_http_x_real_ip () && x_real_ip != NULL)
890  strncpy (client_address, x_real_ip, INET6_ADDRSTRLEN);
891  else if (is_unix_socket ())
892  strncpy (client_address, "unix_socket", INET6_ADDRSTRLEN);
893  else
894  {
895  const union MHD_ConnectionInfo *info;
896 
897  info = MHD_get_connection_info (conn, MHD_CONNECTION_INFO_CLIENT_ADDRESS);
898  sockaddr_as_str ((struct sockaddr_storage *) info->client_addr,
899  client_address);
900  }
901  return 0;
902 }

References is_ignore_http_x_real_ip(), and is_unix_socket().

Referenced by get_user_from_connection(), handle_gmp_post(), and handle_setup_credentials().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gsad_add_content_type_header()

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.

Parameters
[in,out]responseResponse to add header to.
[in]ctContent Type to set.

Definition at line 89 of file gsad_http.c.

90 {
91  if (!response)
92  return;
93 
94  switch (*ct)
95  {
97  MHD_add_response_header (response, MHD_HTTP_HEADER_CONTENT_TYPE,
98  "application/deb");
99  break;
101  MHD_add_response_header (response, MHD_HTTP_HEADER_CONTENT_TYPE,
102  "application/exe");
103  break;
105  MHD_add_response_header (response, MHD_HTTP_HEADER_CONTENT_TYPE,
106  "application/xhtml+xml");
107  break;
109  MHD_add_response_header (response, MHD_HTTP_HEADER_CONTENT_TYPE,
110  "application/key");
111  break;
113  MHD_add_response_header (response, MHD_HTTP_HEADER_CONTENT_TYPE,
114  "application/nbe");
115  break;
117  MHD_add_response_header (response, MHD_HTTP_HEADER_CONTENT_TYPE,
118  "application/pdf");
119  break;
121  MHD_add_response_header (response, MHD_HTTP_HEADER_CONTENT_TYPE,
122  "application/rpm");
123  break;
125  MHD_add_response_header (response, MHD_HTTP_HEADER_CONTENT_TYPE,
126  "application/xml; charset=utf-8");
127  break;
129  MHD_add_response_header (response, MHD_HTTP_HEADER_CONTENT_TYPE,
130  "image/png");
131  break;
133  MHD_add_response_header (response, MHD_HTTP_HEADER_CONTENT_TYPE,
134  "image/svg+xml");
135  break;
137  MHD_add_response_header (response, MHD_HTTP_HEADER_CONTENT_TYPE,
138  "image/gif");
139  break;
141  MHD_add_response_header (response, MHD_HTTP_HEADER_CONTENT_TYPE,
142  "application/octet-stream");
143  break;
145  MHD_add_response_header (response, MHD_HTTP_HEADER_CONTENT_TYPE,
146  "text/css");
147  break;
149  MHD_add_response_header (response, MHD_HTTP_HEADER_CONTENT_TYPE,
150  "text/html; charset=utf-8");
151  break;
153  MHD_add_response_header (response, MHD_HTTP_HEADER_CONTENT_TYPE,
154  "text/javascript");
155  break;
157  MHD_add_response_header (response, MHD_HTTP_HEADER_CONTENT_TYPE,
158  "text/plain; charset=utf-8");
159  break;
161  MHD_add_response_header (response, MHD_HTTP_HEADER_CONTENT_TYPE,
162  "application/json; charset=utf-8");
163  break;
165  break;
166  default:
167  MHD_add_response_header (response, MHD_HTTP_HEADER_CONTENT_TYPE,
168  "text/plain; charset=utf-8");
169  break;
170  }
171 }

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

Here is the caller graph for this function:

◆ gsad_message()

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.

Todo:
Make it accept formatted strings.
Parameters
[in]credentialsUser authentication information.
[in]titleThe title for the message.
[in]functionThe function in which the error occurred.
[in]lineThe line number at which the error occurred.
[in]msgThe response message.
[out]response_dataExtra data return for the HTTP response.
Returns
An XML document as a newly allocated string.

Definition at line 957 of file gsad_http.c.

960 {
961  gchar *xml, *xmltitle;
962 
963  if (function)
964  {
965  xmltitle = g_strdup_printf ("<title>%s: %s:%i (GSA %s)</title>", title,
966  function, line, GSAD_VERSION);
967  }
968  else
969  {
970  xmltitle =
971  g_strdup_printf ("<title>%s (GSA %s)</title>", title, GSAD_VERSION);
972  }
973 
974  if (credentials)
975  {
976  gchar *pre;
977  time_t now;
978  char ctime_now[200];
980 
981  now = time (NULL);
982  ctime_r_strip_newline (&now, ctime_now);
983 
984  pre = g_markup_printf_escaped (
985  "<envelope>"
986  "<version>%s</version>"
987  "<vendor_version>%s</vendor_version>"
988  "<token>%s</token>"
989  "<time>%s</time>"
990  "<login>%s</login>"
991  "<role>%s</role>"
992  "<i18n>%s</i18n>"
993  "<client_address>%s</client_address>",
994  GSAD_VERSION, vendor_version_get (), user_get_token (user), ctime_now,
997 
998  xml = g_strdup_printf ("%s"
999  "<gsad_response>"
1000  "%s"
1001  "<message>%s</message>"
1002  "</gsad_response>"
1003  "<capabilities>%s</capabilities>"
1004  "</envelope>",
1005  pre, xmltitle, msg ? msg : "",
1007 
1008  g_free (pre);
1009  }
1010  else
1011  {
1012  xml = g_strdup_printf ("<envelope>"
1013  "<version>%s</version>"
1014  "<vendor_version>%s</vendor_version>"
1015  "<gsad_response>"
1016  "%s"
1017  "<message>%s</message>"
1018  "<token></token>"
1019  "</gsad_response>"
1020  "</envelope>",
1021  GSAD_VERSION, vendor_version_get (), xmltitle,
1022  msg ? msg : "");
1023  }
1024 
1025  g_free (xmltitle);
1026 
1028  cmd_response_data_set_content_length (response_data, strlen (xml));
1029 
1030  return xml;
1031 }

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_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_tls_certificate_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(), empty_trashcan_gmp(), export_many(), export_preference_file_gmp(), export_resource(), get_aggregate_gmp(), get_asset(), get_capabilities_gmp(), get_config_family(), get_config_nvt_gmp(), get_entities(), get_entity(), get_feeds_gmp(), get_report(), get_setting_gmp(), get_settings_gmp(), get_system_reports_gmp(), get_user(), 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_tls_certificate_gmp(), save_user_gmp(), sync_feed(), test_alert_gmp(), toggle_tag_gmp(), verify_agent_gmp(), verify_scanner_gmp(), wizard(), and wizard_get().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ guess_content_type()

content_type_t guess_content_type ( const gchar *  path)

Guess a content type from a file extension.

Parameters
[in]pathfilename with extension
Returns
a content_type_t for the file

Definition at line 56 of file gsad_http.c.

57 {
58  /* Guess content type. */
59  if (g_str_has_suffix (path, ".png"))
61  else if (g_str_has_suffix (path, ".svg"))
63  else if (g_str_has_suffix (path, ".html"))
65  else if (g_str_has_suffix (path, ".css"))
67  else if (g_str_has_suffix (path, ".js"))
69  else if (g_str_has_suffix (path, ".gif"))
71  else if (g_str_has_suffix (path, ".json"))
73  else if (g_str_has_suffix (path, ".txt"))
75  else
77 }

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

Here is the caller graph for this function:

◆ handler_create_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

Parameters
[in]connectionConnection handle, e.g. used to send response.
[in]dataData to send in response
[in]response_dataResponse data struct. Response data will be freed.
[in]sidSession ID, or NULL. "0" to remove session.
Returns
MHD_YES on success, else MHD_NO.

Definition at line 368 of file gsad_http.c.

370 {
371  http_response_t *response;
372  gsize len = 0;
373 
374  len = cmd_response_data_get_content_length (response_data);
375  if (len == 0 && data)
376  {
377  len = strlen (data);
378  }
379 
380  response = MHD_create_response_from_buffer (len, data, MHD_RESPMEM_MUST_FREE);
381  return handler_send_response (connection, response, response_data, sid);
382 }

References cmd_response_data_get_content_length(), and handler_send_response().

Referenced by handle_static_config(), handle_system_report(), handler_send_reauthentication(), and login().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ handler_send_reauthentication()

int handler_send_reauthentication ( http_connection_t *  connection,
int  http_status_code,
authentication_reason_t  reason 
)

Allow for reauthentication of a user.

Parameters
[in]connectionConnection handle, e.g. used to send response.
[in]http_status_codeHTTP status code for the response.
[in]reasonReason for re-authentication
Returns
MHD_YES on success. MHD_NO on errors.

Definition at line 435 of file gsad_http.c.

438 {
439  const char *msg;
440 
441  switch (reason)
442  {
443  case LOGIN_FAILED:
444  msg = "Login failed.";
445  break;
446  case LOGIN_ERROR:
447  msg = "Login failed. Error during authentication.";
448  break;
449  case GMP_SERVICE_DOWN:
450  msg = "Login failed. GMP Service is down.";
451  break;
452  case SESSION_EXPIRED:
453  msg = "Session expired. Please login again.";
454  break;
455  case LOGOUT_ALREADY:
456  msg = "Already logged out.";
457  break;
458  case BAD_MISSING_TOKEN:
459  msg = "Token missing or bad. Please login again.";
460  break;
461  case BAD_MISSING_COOKIE:
462  msg = "Cookie missing or bad. Please login again.";
463  break;
464  case LOGOUT:
465  msg = "Successfully logged out.";
466  break;
467  case UNKOWN_ERROR:
468  msg = "Unknown error.";
469  break;
470  default:
471  msg = "";
472  }
473 
474  cmd_response_data_t *response_data = cmd_response_data_new ();
475  cmd_response_data_set_status_code (response_data, http_status_code);
476 
477  gchar *xml = gsad_message (NULL, "Authentication required", __FUNCTION__,
478  __LINE__, msg, response_data);
479 
480  return handler_create_response (connection, xml, response_data, REMOVE_SID);
481 }

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, SESSION_EXPIRED, and UNKOWN_ERROR.

Referenced by handle_setup_user(), handle_system_report(), and login().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ handler_send_response()

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

Parameters
[in]connectionConnection handle, e.g. used to send response.
[in]responseResponse.
[in]response_dataResponse data struct. Response data will be freed.
[in]sidSession ID, or NULL. "0" to remove session.
Returns
MHD_YES on success, else MHD_NO.

Definition at line 295 of file gsad_http.c.

297 {
298  int ret;
299  const gchar *content_disposition;
301  int status_code;
302 
303  if (attach_remove_sid (response, sid) == MHD_NO)
304  {
305  cmd_response_data_free (response_data);
306  MHD_destroy_response (response);
307  return MHD_NO;
308  }
309 
311 
313  {
314  MHD_add_response_header (
315  response, MHD_HTTP_HEADER_CONTENT_TYPE,
317  }
318  else
319  {
321  }
322 
323  content_disposition =
325 
326  if (content_disposition != NULL)
327  {
328  MHD_add_response_header (response, "Content-Disposition",
329  content_disposition);
330  }
331 
332  if (cmd_response_data_is_allow_caching (response_data) == FALSE)
333  add_forbid_caching_headers (response);
334  add_security_headers (response);
335  add_cors_headers (response);
336 
337  status_code = cmd_response_data_get_status_code (response_data);
338 
339  cmd_response_data_free (response_data);
340 
341  ret = MHD_queue_response (connection, status_code, response);
342  if (ret == MHD_NO)
343  {
344  /* Assume this was due to a bad request, to keep the MHD "Internal
345  * application error" out of the log. */
347  NULL, GSAD_CONTENT_TYPE_TEXT_HTML, NULL, 0);
348  MHD_destroy_response (response);
349  return MHD_YES;
350  }
351  MHD_destroy_response (response);
352  return ret;
353 }

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(), and handler_create_response().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ params_append_mhd()

int params_append_mhd ( params_t *  params,
const char *  name,
const char *  filename,
const char *  chunk_data,
int  chunk_size,
int  chunk_offset 
)

Referenced by serve_post().

Here is the caller graph for this function:

◆ reconstruct_url()

gchar* reconstruct_url ( http_connection_t *  connection,
const char *  url 
)

Reconstruct the URL for a connection.

Parameters
[in]connectionConnection.
[in]urlBase part of URL.
Returns
URL.

Definition at line 785 of file gsad_http.c.

786 {
787  GString *full_url;
788 
789  full_url = g_string_new (url);
790  /* To simplify appending the token later, ensure there is at least
791  * one param. */
792  g_string_append (full_url, "?r=1&");
793 
794  MHD_get_connection_values (connection, MHD_GET_ARGUMENT_KIND, append_param,
795  full_url);
796 
797  if (full_url->str[strlen (full_url->str) - 1] == '&')
798  full_url->str[strlen (full_url->str) - 1] = '\0';
799 
800  return g_string_free (full_url, FALSE);
801 }

References append_param().

Referenced by handle_request().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ remove_sid()

int remove_sid ( http_response_t *  response)

Attach expired SID cookie to response.

Parameters
[in]responseResponse.
Returns
MHD_NO in case of problems. MHD_YES if all is OK.

Definition at line 491 of file gsad_http.c.

492 {
493  int ret;
494  gchar *value;
495  gchar *locale;
496  char expires[EXPIRES_LENGTH + 1];
497  struct tm expire_time_broken;
498  time_t expire_time;
499 
500  /* Set up the expires param. */
501  locale = g_strdup (setlocale (LC_ALL, NULL));
502  setlocale (LC_ALL, "C");
503 
504  expire_time = time (NULL);
505  if (localtime_r (&expire_time, &expire_time_broken) == NULL)
506  abort ();
507  ret = strftime (expires, EXPIRES_LENGTH, "%a, %d %b %Y %T GMT",
508  &expire_time_broken);
509  if (ret == 0)
510  abort ();
511 
512  setlocale (LC_ALL, locale);
513  g_free (locale);
514 
515  /* Add the cookie.
516  *
517  * Tim Brown's suggested cookie included a domain attribute. How would
518  * we get the domain in here? Maybe a --domain option. */
519 
520  value =
521  g_strdup_printf (SID_COOKIE_NAME "=0; expires=%s; path=/; %sHTTPonly",
522  expires, (is_use_secure_cookie () ? "secure; " : ""));
523  ret = MHD_add_response_header (response, "Set-Cookie", value);
524  g_free (value);
525  return ret;
526 }

References EXPIRES_LENGTH, is_use_secure_cookie(), and SID_COOKIE_NAME.

Referenced by attach_remove_sid().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ send_redirect_to_uri()

int send_redirect_to_uri ( http_connection_t *  connection,
const char *  uri,
const gchar *  sid 
)

Sends a HTTP redirection to an uri.

Parameters
[in]connectionThe connection handle.
[in]uriThe full URI to redirect to.
[in]sidSession ID to add, or NULL.
Returns
MHD_NO in case of a problem. Else MHD_YES.

Definition at line 183 of file gsad_http.c.

185 {
186  int ret;
187  http_response_t *response;
188  char *body;
189 
190  /* Some libmicrohttp versions get into an endless loop in https mode
191  if an empty body is passed. As a workaround and because it is
192  anyway suggested by the HTTP specs, we provide a short body. We
193  assume that uri does not need to be quoted. */
194  body = g_strdup_printf ("<html><body>Code 303 - Redirecting to"
195  " <a href=\"%s\">%s<a/></body></html>\n",
196  uri, uri);
197  response = MHD_create_response_from_buffer (strlen (body), body,
198  MHD_RESPMEM_MUST_FREE);
199 
200  if (!response)
201  {
202  g_warning ("%s: failed to create response, dropping request",
203  __FUNCTION__);
204  return MHD_NO;
205  }
206  ret = MHD_add_response_header (response, MHD_HTTP_HEADER_LOCATION, uri);
207  if (!ret)
208  {
209  MHD_destroy_response (response);
210  g_warning ("%s: failed to add location header, dropping request",
211  __FUNCTION__);
212  return MHD_NO;
213  }
214 
215  if (attach_remove_sid (response, sid) == MHD_NO)
216  {
217  MHD_destroy_response (response);
218  g_warning ("%s: failed to attach SID, dropping request", __FUNCTION__);
219  return MHD_NO;
220  }
221 
222  add_forbid_caching_headers (response);
223  add_security_headers (response);
224  add_cors_headers (response);
225  ret = MHD_queue_response (connection, MHD_HTTP_SEE_OTHER, response);
226  MHD_destroy_response (response);
227  return ret;
228 }

References add_cors_headers(), add_forbid_caching_headers(), add_security_headers(), and attach_remove_sid().

Here is the call graph for this function:

◆ send_response()

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.

Parameters
[in]connectionThe connection handle.
[in]contentThe content.
[in]status_codeThe HTTP status code.
[in]sidSession ID, or NULL.
[in]content_typeThe content type.
[in]content_dispositionThe content disposition or NULL.
[in]content_lengthContent length, 0 for strlen (content).
Returns
MHD_YES on success, MHD_NO on error.

Definition at line 244 of file gsad_http.c.

247 {
248  http_response_t *response;
249  size_t size;
250  int ret;
251 
252  if (content)
253  size = (content_length ? content_length : strlen (content));
254  else
255  {
256  g_warning ("%s: content is NULL", __FUNCTION__);
257  status_code = MHD_HTTP_INTERNAL_SERVER_ERROR;
258  size = 0;
259  }
260  response = MHD_create_response_from_buffer (
261  size, (void *) (content ? content : ""), MHD_RESPMEM_MUST_COPY);
262 
264 
265  if (content_disposition)
266  MHD_add_response_header (response, "Content-Disposition",
267  content_disposition);
268 
269  if (attach_remove_sid (response, sid) == MHD_NO)
270  {
271  return MHD_NO;
272  }
273 
274  add_forbid_caching_headers (response);
275  add_security_headers (response);
276  add_cors_headers (response);
277  ret = MHD_queue_response (connection, status_code, response);
278  MHD_destroy_response (response);
279  return ret;
280 }

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ serve_post()

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.

Parameters
[in,out]coninfo_clsConnection info (a gsad_connection_info).
[in]kindType of request data (header, cookie, etc.).
[in]keyName of data (name of request variable).
[in]filenameName of uploaded file if any, else NULL.
[in]content_typeMIME type of data if known, else NULL.
[in]transfer_encodingTransfer encoding if known, else NULL.
[in]dataData.
[in]offOffset into entire data.
[in]sizeSize of data, in bytes.
Returns
MHD_YES to continue iterating over post data, MHD_NO to stop.

Definition at line 927 of file gsad_http.c.

931 {
932  gsad_connection_info_t *con_info = (gsad_connection_info_t *) coninfo_cls;
933 
934  if (NULL != key)
935  {
936  params_append_mhd (con_info->params, key, filename, data, size, off);
937  return MHD_YES;
938  }
939  return MHD_NO;
940 }

References gsad_connection_info::params, and params_append_mhd().

Referenced by handle_request().

Here is the call graph for this function:
Here is the caller graph for this function:
gsad_connection_info::params
params_t * params
Request parameters.
Definition: gsad_http.h:128
EXPIRES_LENGTH
#define EXPIRES_LENGTH
Max length of cookie expires param.
Definition: gsad_http.h:44
is_unix_socket
gboolean is_unix_socket()
Definition: gsad_settings.c:276
DATE_2822_LEN
#define DATE_2822_LEN
At least maximum length of rfc2822 format date.
Definition: gsad_http.h:39
GSAD_CONTENT_TYPE_APP_DEB
@ GSAD_CONTENT_TYPE_APP_DEB
Definition: gsad_content_type.h:33
cmd_response_data_get_content_length
gsize cmd_response_data_get_content_length(cmd_response_data_t *data)
Get response content length of cmd_response_data_t struct.
Definition: gsad_cmd.c:200
cmd_response_data
Response information for commands.
Definition: gsad_cmd.c:33
MHD_HTTP_NOT_ACCEPTABLE
#define MHD_HTTP_NOT_ACCEPTABLE
The symbol is deprecated, but older versions (0.9.37 - Debian jessie) don't define it yet.
Definition: gsad_http.h:108
get_http_cors_origin
const gchar * get_http_cors_origin()
Definition: gsad_settings.c:201
user_get_username
const gchar * user_get_username(user_t *user)
Definition: gsad_user.c:154
content_type
content_type
Content types.
Definition: gsad_content_type.h:31
get_session_timeout
int get_session_timeout()
Definition: gsad_settings.c:153
ctime_r_strip_newline
char * ctime_r_strip_newline(time_t *time, char *string)
Return string from ctime_r with newline replaces with terminator.
Definition: gsad_base.c:111
user_get_client_address
const gchar * user_get_client_address(user_t *user)
Definition: gsad_user.c:196
user
User information structure, for sessions.
Definition: gsad_user.c:42
add_security_headers
void add_security_headers(http_response_t *response)
Add security headers to a MHD response.
Definition: gsad_http.c:807
UNKOWN_ERROR
@ UNKOWN_ERROR
Definition: gsad_http.h:166
cmd_response_data_set_content_type
void cmd_response_data_set_content_type(cmd_response_data_t *data, content_type_t content_type)
Set content type of cmd_response_data_t struct.
Definition: gsad_cmd.c:134
cmd_response_data_set_status_code
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160
credentials_get_language
const gchar * credentials_get_language(credentials_t *cred)
Definition: gsad_credentials.c:73
cmd_response_data_get_content_type_string
const gchar * cmd_response_data_get_content_type_string(cmd_response_data_t *data)
Get a content type string if set.
Definition: gsad_cmd.c:255
GSAD_CONTENT_TYPE_IMAGE_SVG
@ GSAD_CONTENT_TYPE_IMAGE_SVG
Definition: gsad_content_type.h:49
remove_sid
int remove_sid(http_response_t *response)
Attach expired SID cookie to response.
Definition: gsad_http.c:491
GSAD_CONTENT_TYPE_STRING
@ GSAD_CONTENT_TYPE_STRING
Special marker for using content type string.
Definition: gsad_content_type.h:42
credentials
Structure of credential related information.
Definition: gsad_credentials.c:34
is_ignore_http_x_real_ip
gboolean is_ignore_http_x_real_ip()
Definition: gsad_settings.c:249
GMP_SERVICE_DOWN
@ GMP_SERVICE_DOWN
Definition: gsad_http.h:162
cmd_response_data_set_content_length
void cmd_response_data_set_content_length(cmd_response_data_t *data, gsize content_length)
Set response content length of cmd_response_data_t struct.
Definition: gsad_cmd.c:186
cmd_response_data_get_content_disposition
const gchar * cmd_response_data_get_content_disposition(cmd_response_data_t *data)
Get content disposition of cmd_response_data_t struct.
Definition: gsad_cmd.c:226
GSAD_CONTENT_TYPE_TEXT_PLAIN
@ GSAD_CONTENT_TYPE_TEXT_PLAIN
Definition: gsad_content_type.h:47
create_not_found_response
http_response_t * create_not_found_response(cmd_response_data_t *response_data)
Create a default 404 (not found) http response.
Definition: gsad_http.c:392
GSAD_CONTENT_TYPE_IMAGE_GIF
@ GSAD_CONTENT_TYPE_IMAGE_GIF
Definition: gsad_content_type.h:50
cmd_response_data_is_allow_caching
gboolean cmd_response_data_is_allow_caching(cmd_response_data_t *data)
Get allow_caching flag of cmd_response_data_t struct.
Definition: gsad_cmd.c:122
GSAD_CONTENT_TYPE_APP_XHTML
@ GSAD_CONTENT_TYPE_APP_XHTML
Definition: gsad_content_type.h:35
gsad_message
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.
Definition: gsad_http.c:957
content_type_t
enum content_type content_type_t
Definition: gsad_content_type.h:54
add_cors_headers
void add_cors_headers(http_response_t *response)
Definition: gsad_http.c:840
http_strict_transport_security
const gchar * http_strict_transport_security
Current value of for HTTP header "Strict-Transport-Security".
Definition: gsad_settings.c:70
GSAD_CONTENT_TYPE_APP_KEY
@ GSAD_CONTENT_TYPE_APP_KEY
Definition: gsad_content_type.h:36
GSAD_CONTENT_TYPE_APP_PDF
@ GSAD_CONTENT_TYPE_APP_PDF
Definition: gsad_content_type.h:38
get_http_x_frame_options
const gchar * get_http_x_frame_options()
Definition: gsad_settings.c:189
get_http_guest_chart_x_frame_options
const gchar * get_http_guest_chart_x_frame_options()
Definition: gsad_settings.c:213
params_append_mhd
int params_append_mhd(params_t *params, const char *name, const char *filename, const char *chunk_data, int chunk_size, int chunk_offset)
add_forbid_caching_headers
void add_forbid_caching_headers(http_response_t *response)
Add header to forbid caching to a HTTP response.
Definition: gsad_http.c:860
GSAD_CONTENT_TYPE_APP_RPM
@ GSAD_CONTENT_TYPE_APP_RPM
Definition: gsad_content_type.h:39
cmd_response_data_new
cmd_response_data_t * cmd_response_data_new()
Allocates memory for a cmd_response_data_t sturct and initializes it.
Definition: gsad_cmd.c:65
GSAD_CONTENT_TYPE_TEXT_JS
@ GSAD_CONTENT_TYPE_TEXT_JS
Definition: gsad_content_type.h:46
GSAD_CONTENT_TYPE_APP_XML
@ GSAD_CONTENT_TYPE_APP_XML
Definition: gsad_content_type.h:40
cmd_response_data_get_content_type
content_type_t cmd_response_data_get_content_type(cmd_response_data_t *data)
Get content type of cmd_response_data_t struct.
Definition: gsad_cmd.c:148
guess_content_type
content_type_t guess_content_type(const gchar *path)
Guess a content type from a file extension.
Definition: gsad_http.c:56
BAD_MISSING_COOKIE
@ BAD_MISSING_COOKIE
Definition: gsad_http.h:164
user_get_capabilities
const gchar * user_get_capabilities(user_t *user)
Definition: gsad_user.c:178
GSAD_CONTENT_TYPE_TEXT_CSS
@ GSAD_CONTENT_TYPE_TEXT_CSS
Definition: gsad_content_type.h:44
GSAD_CONTENT_TYPE_APP_EXE
@ GSAD_CONTENT_TYPE_APP_EXE
Definition: gsad_content_type.h:34
send_response
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.
Definition: gsad_http.c:244
GSAD_CONTENT_TYPE_TEXT_HTML
@ GSAD_CONTENT_TYPE_TEXT_HTML
Definition: gsad_content_type.h:45
str_equal
gboolean str_equal(const gchar *str1, const gchar *str2)
Check if two strings are equal.
Definition: utils.c:35
http_cors_origin
const gchar * http_cors_origin
Current value of for HTTP header "Access-Control-Allow-Origin".
Definition: gsad_settings.c:75
BAD_MISSING_TOKEN
@ BAD_MISSING_TOKEN
Definition: gsad_http.h:165
LOGOUT_ALREADY
@ LOGOUT_ALREADY
Definition: gsad_http.h:161
SESSION_EXPIRED
@ SESSION_EXPIRED
Definition: gsad_http.h:163
GSAD_CONTENT_TYPE_APP_NBE
@ GSAD_CONTENT_TYPE_APP_NBE
Definition: gsad_content_type.h:37
GSAD_CONTENT_TYPE_IMAGE_PNG
@ GSAD_CONTENT_TYPE_IMAGE_PNG
Definition: gsad_content_type.h:43
http_response_t
struct MHD_Response http_response_t
Definition: gsad_http.h:137
SID_COOKIE_NAME
#define SID_COOKIE_NAME
Name of the cookie used to store the SID.
Definition: gsad_http.h:58
http_x_frame_options
const gchar * http_x_frame_options
Current value for HTTP header "X-Frame-Options".
Definition: gsad_settings.c:50
attach_remove_sid
int attach_remove_sid(http_response_t *response, const gchar *sid)
Definition: gsad_http.c:615
attach_sid
int attach_sid(http_response_t *response, const char *sid)
Attach SID cookie to a response, resetting "expire" arg.
Definition: gsad_http.c:537
BAD_REQUEST_PAGE
#define BAD_REQUEST_PAGE
Bad request error HTML.
Definition: gsad_http.h:80
LOGOUT
@ LOGOUT
Definition: gsad_http.h:160
http_content_security_policy
const gchar * http_content_security_policy
Current value for HTTP header "Content-Security-Policy".
Definition: gsad_settings.c:55
get_http_content_security_policy
const gchar * get_http_content_security_policy()
Definition: gsad_settings.c:177
LOGIN_ERROR
@ LOGIN_ERROR
Definition: gsad_http.h:159
REMOVE_SID
#define REMOVE_SID
Definition: gsad_http.h:60
user_get_role
const gchar * user_get_role(user_t *user)
Definition: gsad_user.c:208
credentials_get_user
user_t * credentials_get_user(credentials_t *cred)
Definition: gsad_credentials.c:67
is_use_secure_cookie
gboolean is_use_secure_cookie()
Definition: gsad_settings.c:165
GSAD_CONTENT_TYPE_DONE
@ GSAD_CONTENT_TYPE_DONE
Special marker.
Definition: gsad_content_type.h:41
handler_create_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.
Definition: gsad_http.c:368
gsad_add_content_type_header
void gsad_add_content_type_header(http_response_t *response, content_type_t *ct)
Adds content-type header fields to a response.
Definition: gsad_http.c:89
cmd_response_data_get_status_code
int cmd_response_data_get_status_code(cmd_response_data_t *data)
Get http status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:174
append_param
static int append_param(void *string, enum MHD_ValueKind kind, const char *key, const char *value)
Append a request param to a string.
Definition: gsad_http.c:754
get_http_guest_chart_content_security_policy
const gchar * get_http_guest_chart_content_security_policy()
Definition: gsad_settings.c:225
handler_send_response
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.
Definition: gsad_http.c:295
cmd_response_data_free
void cmd_response_data_free(cmd_response_data_t *data)
Frees the memory of a cmd_response_data_t struct.
Definition: gsad_cmd.c:81
GSAD_CONTENT_TYPE_APP_JSON
@ GSAD_CONTENT_TYPE_APP_JSON
Definition: gsad_content_type.h:51
gsad_connection_info
Connection information.
Definition: gsad_http.h:125
LOGIN_FAILED
@ LOGIN_FAILED
Definition: gsad_http.h:158
get_http_strict_transport_security
const gchar * get_http_strict_transport_security()
Definition: gsad_settings.c:237
GSAD_CONTENT_TYPE_OCTET_STREAM
@ GSAD_CONTENT_TYPE_OCTET_STREAM
Definition: gsad_content_type.h:48
file_reader
static int file_reader(void *cls, uint64_t pos, char *buf, int max)
Reads from a file.
Definition: gsad_http.c:653
vendor_version_get
const gchar * vendor_version_get()
Get the vendor version.
Definition: gsad_settings.c:117
user_get_token
const gchar * user_get_token(user_t *user)
Definition: gsad_user.c:172