#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_protocols.h"
#include "gnunet_constants.h"
#include "gnunet_resolver_service.h"
Go to the source code of this file.
Data Structures | |
struct | LEGACY_SERVICE_Context |
Context for "service_task". More... | |
Macros | |
#define | HANDLE_ERROR |
Functions | |
static int | check_ipv4_listed (const struct GNUNET_STRINGS_IPv4NetworkPolicy *list, const struct in_addr *add) |
Check if the given IP address is in the list of IP addresses. More... | |
static int | check_ipv6_listed (const struct GNUNET_STRINGS_IPv6NetworkPolicy *list, const struct in6_addr *ip) |
Check if the given IP address is in the list of IP addresses. More... | |
static size_t | write_test (void *cls, size_t size, void *buf) |
Send a 'TEST' message back to the client. More... | |
static void | handle_test (void *cls, struct GNUNET_SERVER_Client *client, const struct GNUNET_MessageHeader *message) |
Handler for TEST message. More... | |
static int | check_access (void *cls, const struct GNUNET_CONNECTION_Credentials *uc, const struct sockaddr *addr, socklen_t addrlen) |
Check if access to the service is allowed from the given address. More... | |
static char * | get_pid_file_name (struct LEGACY_SERVICE_Context *sctx) |
Get the name of the file where we will write the PID of the service. More... | |
static int | process_acl4 (struct GNUNET_STRINGS_IPv4NetworkPolicy **ret, struct LEGACY_SERVICE_Context *sctx, const char *option) |
Parse an IPv4 access control list. More... | |
static int | process_acl6 (struct GNUNET_STRINGS_IPv6NetworkPolicy **ret, struct LEGACY_SERVICE_Context *sctx, const char *option) |
Parse an IPv6 access control list. More... | |
static void | add_unixpath (struct sockaddr **saddrs, socklen_t *saddrlens, const char *unixpath, int abstract) |
Add the given UNIX domain path as an address to the list (as the first entry). More... | |
int | LEGACY_SERVICE_get_server_addresses (const char *service_name, const struct GNUNET_CONFIGURATION_Handle *cfg, struct sockaddr ***addrs, socklen_t **addr_lens) |
Get the list of addresses that a server for the given service should bind to. More... | |
static int | setup_service (struct LEGACY_SERVICE_Context *sctx) |
Setup addr, addrlen, idle_timeout based on configuration! More... | |
static char * | get_user_name (struct LEGACY_SERVICE_Context *sctx) |
Get the name of the user that'll be used to provide the service. More... | |
static int | write_pid_file (struct LEGACY_SERVICE_Context *sctx, pid_t pid) |
Write PID file. More... | |
static void | shutdown_task (void *cls) |
Task run during shutdown. More... | |
static void | service_task (void *cls) |
Initial task for the service. More... | |
static int | detach_terminal (struct LEGACY_SERVICE_Context *sctx) |
Detach from terminal. More... | |
static int | set_user_id (struct LEGACY_SERVICE_Context *sctx) |
Set user ID. More... | |
static void | pid_file_delete (struct LEGACY_SERVICE_Context *sctx) |
Delete the PID file that was created by our parent. More... | |
int | LEGACY_SERVICE_run (int argc, char *const *argv, const char *service_name, enum LEGACY_SERVICE_Options options, LEGACY_SERVICE_Main task, void *task_cls) |
Run a standard GNUnet service startup sequence (initialize loggers and configuration, parse options). More... | |
struct LEGACY_SERVICE_Context * | LEGACY_SERVICE_start (const char *service_name, const struct GNUNET_CONFIGURATION_Handle *cfg, enum LEGACY_SERVICE_Options options) |
Run a service startup sequence within an existing initialized system. More... | |
struct GNUNET_SERVER_Handle * | LEGACY_SERVICE_get_server (struct LEGACY_SERVICE_Context *ctx) |
Obtain the server used by a service. More... | |
struct GNUNET_NETWORK_Handle *const * | LEGACY_SERVICE_get_listen_sockets (struct LEGACY_SERVICE_Context *ctx) |
Get the NULL-terminated array of listen sockets for this service. More... | |
void | LEGACY_SERVICE_stop (struct LEGACY_SERVICE_Context *sctx) |
Stop a service that was started with "LEGACY_SERVICE_start". More... | |
Variables | |
static const struct GNUNET_SERVER_MessageHandler | defhandlers [] |
Default handlers for all services. More... | |
#define HANDLE_ERROR |
|
static |
Check if the given IP address is in the list of IP addresses.
list | a list of networks |
add | the IP to check (in network byte order) |
Definition at line 48 of file tcp_service_legacy.c.
References add, GNUNET_NO, GNUNET_YES, and list.
Referenced by check_access().
|
static |
Check if the given IP address is in the list of IP addresses.
list | a list of networks |
ip | the IP to check (in network byte order) |
Definition at line 75 of file tcp_service_legacy.c.
References GNUNET_NO, GNUNET_YES, consensus-simulation::int, list, and zero.
Referenced by check_access().
|
static |
Send a 'TEST' message back to the client.
cls | the 'struct GNUNET_SERVER_Client' to send TEST to |
size | number of bytes available in 'buf' |
buf | where to copy the message |
Definition at line 241 of file tcp_service_legacy.c.
References buf, GNUNET_MESSAGE_TYPE_TEST, GNUNET_OK, GNUNET_SERVER_receive_done(), GNUNET_SYSERR, msg, GNUNET_MessageHeader::size, size, and GNUNET_MessageHeader::type.
|
static |
Handler for TEST message.
cls | closure (refers to service) |
client | identification of the client |
message | the actual message |
Definition at line 267 of file tcp_service_legacy.c.
|
static |
Check if access to the service is allowed from the given address.
cls | closure |
uc | credentials, if available, otherwise NULL |
addr | address |
addrlen | length of address |
Definition at line 309 of file tcp_service_legacy.c.
References _, check_ipv4_listed(), check_ipv6_listed(), GNUNET_a2s(), GNUNET_assert, GNUNET_ERROR_TYPE_WARNING, GNUNET_OK, GNUNET_SYSERR, LOG, ret, LEGACY_SERVICE_Context::service_name, LEGACY_SERVICE_Context::v4_allowed, LEGACY_SERVICE_Context::v4_denied, LEGACY_SERVICE_Context::v6_allowed, and LEGACY_SERVICE_Context::v6_denied.
Referenced by LEGACY_SERVICE_start(), and service_task().
|
static |
Get the name of the file where we will write the PID of the service.
sctx | service context |
Definition at line 368 of file tcp_service_legacy.c.
References LEGACY_SERVICE_Context::cfg, GNUNET_CONFIGURATION_get_value_filename(), GNUNET_OK, and LEGACY_SERVICE_Context::service_name.
Referenced by pid_file_delete(), and write_pid_file().
|
static |
Parse an IPv4 access control list.
ret | location where to write the ACL (set) |
sctx | service context to use to get the configuration |
option | name of the ACL option to parse |
Definition at line 391 of file tcp_service_legacy.c.
References _, LEGACY_SERVICE_Context::cfg, GNUNET_break, GNUNET_CONFIGURATION_get_value_string(), GNUNET_CONFIGURATION_have_value(), GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_OK, GNUNET_STRINGS_parse_ipv4_policy(), GNUNET_SYSERR, LOG, ret, and LEGACY_SERVICE_Context::service_name.
Referenced by setup_service().
|
static |
Parse an IPv6 access control list.
ret | location where to write the ACL (set) |
sctx | service context to use to get the configuration |
option | name of the ACL option to parse |
Definition at line 432 of file tcp_service_legacy.c.
References _, LEGACY_SERVICE_Context::cfg, GNUNET_break, GNUNET_CONFIGURATION_get_value_string(), GNUNET_CONFIGURATION_have_value(), GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_OK, GNUNET_STRINGS_parse_ipv6_policy(), GNUNET_SYSERR, LOG, ret, and LEGACY_SERVICE_Context::service_name.
Referenced by setup_service().
|
static |
Add the given UNIX domain path as an address to the list (as the first entry).
saddrs | array to update |
saddrlens | where to store the address length |
unixpath | path to add |
abstract | GNUNET_YES to add an abstract UNIX domain socket. This parameter is ignore on systems other than LINUX |
Definition at line 474 of file tcp_service_legacy.c.
References GNUNET_assert, GNUNET_new, GNUNET_strlcpy(), and GNUNET_YES.
Referenced by LEGACY_SERVICE_get_server_addresses().
int LEGACY_SERVICE_get_server_addresses | ( | const char * | service_name, |
const struct GNUNET_CONFIGURATION_Handle * | cfg, | ||
struct sockaddr *** | addrs, | ||
socklen_t ** | addr_lens | ||
) |
Get the list of addresses that a server for the given service should bind to.
service_name | name of the service |
cfg | configuration (which specifies the addresses) |
addrs | set (call by reference) to an array of pointers to the addresses the server should bind to and listen on; the array will be NULL-terminated (on success) |
addr_lens | set (call by reference) to an array of the lengths of the respective struct sockaddr struct in the addrs array (on success) |
*addrs
and *addr_lens
will be set to NULL). Definition at line 523 of file tcp_service_legacy.c.
References _, add_unixpath(), cfg, GNUNET_a2s(), GNUNET_assert, GNUNET_break, GNUNET_CONFIGURATION_get_value_filename(), GNUNET_CONFIGURATION_get_value_number(), GNUNET_CONFIGURATION_get_value_string(), GNUNET_CONFIGURATION_get_value_yesno(), GNUNET_CONFIGURATION_have_value(), GNUNET_DISK_directory_create_for_file(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_log_strerror_file, GNUNET_malloc, GNUNET_memcpy, GNUNET_NETWORK_shorten_unixpath(), GNUNET_NETWORK_socket_close(), GNUNET_NETWORK_socket_create(), GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, GNUNET_YES, hostname, LOG, LOG_STRERROR, port, res, ret, and service_name.
Referenced by setup_service().
|
static |
Setup addr, addrlen, idle_timeout based on configuration!
Configuration may specify:
sctx | service context to initialize |
Definition at line 872 of file tcp_service_legacy.c.
References _, LEGACY_SERVICE_Context::addrlens, LEGACY_SERVICE_Context::addrs, LEGACY_SERVICE_Context::cfg, getenv(), GNUNET_break, GNUNET_CONFIGURATION_get_value_time(), GNUNET_CONFIGURATION_get_value_yesno(), GNUNET_CONFIGURATION_have_value(), GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_malloc, GNUNET_NETWORK_socket_box_native(), GNUNET_NETWORK_socket_close(), GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_YES, LEGACY_SERVICE_get_server_addresses(), LOG, LEGACY_SERVICE_Context::lsocks, LEGACY_SERVICE_Context::match_gid, LEGACY_SERVICE_Context::match_uid, process_acl4(), process_acl6(), LEGACY_SERVICE_Context::require_found, LEGACY_SERVICE_Context::service_name, LEGACY_SERVICE_Context::timeout, LEGACY_SERVICE_Context::v4_allowed, LEGACY_SERVICE_Context::v4_denied, LEGACY_SERVICE_Context::v6_allowed, and LEGACY_SERVICE_Context::v6_denied.
Referenced by LEGACY_SERVICE_run(), and LEGACY_SERVICE_start().
|
static |
Get the name of the user that'll be used to provide the service.
sctx | service context |
Definition at line 978 of file tcp_service_legacy.c.
References LEGACY_SERVICE_Context::cfg, GNUNET_CONFIGURATION_get_value_filename(), GNUNET_OK, and LEGACY_SERVICE_Context::service_name.
Referenced by set_user_id(), and write_pid_file().
|
static |
Write PID file.
sctx | service context |
pid | PID to write (should be equal to 'getpid()' |
Definition at line 999 of file tcp_service_legacy.c.
References DIR_SEPARATOR, get_pid_file_name(), get_user_name(), GNUNET_break, GNUNET_DISK_directory_create(), GNUNET_DISK_file_change_owner(), GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_OK, GNUNET_strdup, GNUNET_SYSERR, len, LOG_STRERROR_FILE, and pid.
Referenced by service_task().
|
static |
Task run during shutdown.
Stops the server/service.
cls | the struct LEGACY_SERVICE_Context |
Definition at line 1057 of file tcp_service_legacy.c.
References GNUNET_SERVER_destroy(), GNUNET_SERVER_stop_listening(), LEGACY_SERVICE_OPTION_SOFT_SHUTDOWN, GNUNET_SERVICE_Handle::options, and service.
Referenced by service_task().
|
static |
Initial task for the service.
cls | service context |
Definition at line 1076 of file tcp_service_legacy.c.
References _, LEGACY_SERVICE_Context::addrlens, LEGACY_SERVICE_Context::addrs, GNUNET_SERVER_MessageHandler::callback, GNUNET_SERVER_MessageHandler::callback_cls, LEGACY_SERVICE_Context::cfg, check_access(), defhandlers, GNUNET_a2s(), GNUNET_break, GNUNET_DISK_fix_permissions(), GNUNET_ERROR_TYPE_INFO, GNUNET_malloc, GNUNET_memcpy, GNUNET_RESOLVER_connect(), GNUNET_SCHEDULER_add_shutdown(), GNUNET_SERVER_add_handlers(), GNUNET_SERVER_create(), GNUNET_SERVER_create_with_sockets(), GNUNET_SYSERR, LEGACY_SERVICE_OPTION_MANUAL_SHUTDOWN, LOG, LEGACY_SERVICE_Context::lsocks, LEGACY_SERVICE_Context::match_gid, LEGACY_SERVICE_Context::match_uid, LEGACY_SERVICE_Context::my_handlers, LEGACY_SERVICE_Context::options, LEGACY_SERVICE_Context::ready_confirm_fd, LEGACY_SERVICE_Context::require_found, LEGACY_SERVICE_Context::ret, LEGACY_SERVICE_Context::server, LEGACY_SERVICE_Context::service_name, LEGACY_SERVICE_Context::shutdown_task, shutdown_task(), LEGACY_SERVICE_Context::task, LEGACY_SERVICE_Context::task_cls, LEGACY_SERVICE_Context::timeout, and write_pid_file().
Referenced by LEGACY_SERVICE_run().
|
static |
Detach from terminal.
sctx | service context |
Definition at line 1159 of file tcp_service_legacy.c.
References _, GNUNET_break, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_ERROR_TYPE_WARNING, GNUNET_OK, GNUNET_SYSERR, LOG, LOG_STRERROR, pid, and LEGACY_SERVICE_Context::ready_confirm_fd.
Referenced by LEGACY_SERVICE_run().
|
static |
Set user ID.
sctx | service context |
Definition at line 1239 of file tcp_service_legacy.c.
References _, get_user_name(), GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_OK, GNUNET_SYSERR, and LOG.
Referenced by LEGACY_SERVICE_run().
|
static |
Delete the PID file that was created by our parent.
sctx | service context |
Definition at line 1288 of file tcp_service_legacy.c.
References get_pid_file_name(), GNUNET_ERROR_TYPE_WARNING, GNUNET_free, and LOG_STRERROR_FILE.
Referenced by LEGACY_SERVICE_run().
int LEGACY_SERVICE_run | ( | int | argc, |
char *const * | argv, | ||
const char * | service_name, | ||
enum LEGACY_SERVICE_Options | options, | ||
LEGACY_SERVICE_Main | task, | ||
void * | task_cls | ||
) |
Run a standard GNUnet service startup sequence (initialize loggers and configuration, parse options).
argc | number of command line arguments |
argv | command line arguments |
service_name | our service name |
options | service options |
task | main task of the service |
task_cls | closure for task |
Definition at line 1314 of file tcp_service_legacy.c.
References _, LEGACY_SERVICE_Context::addrlens, LEGACY_SERVICE_Context::addrs, cfg, LEGACY_SERVICE_Context::cfg, config_file, detach_terminal(), DIR_SEPARATOR_STR, GAUGER, getenv(), gettext_noop, GNUNET_asprintf(), GNUNET_break, GNUNET_CONFIGURATION_create(), GNUNET_CONFIGURATION_destroy(), GNUNET_CONFIGURATION_get_value_number(), GNUNET_CONFIGURATION_get_value_string(), GNUNET_CONFIGURATION_have_value(), GNUNET_CONFIGURATION_load(), GNUNET_DISK_file_test(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_free_nz, GNUNET_GETOPT_option_cfgfile(), GNUNET_GETOPT_OPTION_END, GNUNET_GETOPT_option_flag(), GNUNET_GETOPT_option_help(), GNUNET_GETOPT_option_logfile(), GNUNET_GETOPT_option_loglevel(), GNUNET_GETOPT_option_version(), GNUNET_GETOPT_run(), GNUNET_log, GNUNET_log_setup(), GNUNET_NO, GNUNET_OK, GNUNET_OS_project_data_get(), GNUNET_SCHEDULER_run(), GNUNET_strdup, GNUNET_SYSERR, GNUNET_TIME_set_offset(), GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_YES, HANDLE_ERROR, LOG, LOG_STRERROR, LEGACY_SERVICE_Context::my_handlers, options, LEGACY_SERVICE_Context::options, pid_file_delete(), LEGACY_SERVICE_Context::ready_confirm_fd, ret, LEGACY_SERVICE_Context::ret, LEGACY_SERVICE_Context::server, LEGACY_SERVICE_Context::service_name, service_name, service_task(), set_user_id(), setup_service(), LEGACY_SERVICE_Context::task, LEGACY_SERVICE_Context::task_cls, LEGACY_SERVICE_Context::timeout, LEGACY_SERVICE_Context::v4_allowed, LEGACY_SERVICE_Context::v4_denied, LEGACY_SERVICE_Context::v6_allowed, and LEGACY_SERVICE_Context::v6_denied.
struct LEGACY_SERVICE_Context* LEGACY_SERVICE_start | ( | const char * | service_name, |
const struct GNUNET_CONFIGURATION_Handle * | cfg, | ||
enum LEGACY_SERVICE_Options | options | ||
) |
Run a service startup sequence within an existing initialized system.
service_name | our service name |
cfg | configuration to use |
options | service options |
Definition at line 1503 of file tcp_service_legacy.c.
References LEGACY_SERVICE_Context::addrlens, LEGACY_SERVICE_Context::addrs, GNUNET_SERVER_MessageHandler::callback, GNUNET_SERVER_MessageHandler::callback_cls, cfg, LEGACY_SERVICE_Context::cfg, check_access(), defhandlers, GNUNET_DISK_fix_permissions(), GNUNET_malloc, GNUNET_memcpy, GNUNET_new, GNUNET_OK, GNUNET_SERVER_add_handlers(), GNUNET_SERVER_create(), GNUNET_SERVER_create_with_sockets(), GNUNET_TIME_UNIT_FOREVER_REL, LEGACY_SERVICE_stop(), LEGACY_SERVICE_Context::lsocks, LEGACY_SERVICE_Context::match_gid, LEGACY_SERVICE_Context::match_uid, LEGACY_SERVICE_Context::my_handlers, options, LEGACY_SERVICE_Context::options, LEGACY_SERVICE_Context::ready_confirm_fd, LEGACY_SERVICE_Context::require_found, LEGACY_SERVICE_Context::ret, LEGACY_SERVICE_Context::server, LEGACY_SERVICE_Context::service_name, service_name, setup_service(), and LEGACY_SERVICE_Context::timeout.
Referenced by libgnunet_plugin_transport_tcp_init().
struct GNUNET_SERVER_Handle* LEGACY_SERVICE_get_server | ( | struct LEGACY_SERVICE_Context * | ctx | ) |
Obtain the server used by a service.
Note that the server must NOT be destroyed by the caller.
ctx | the service context returned from the start function |
Definition at line 1572 of file tcp_service_legacy.c.
References ctx.
Referenced by libgnunet_plugin_transport_tcp_init().
struct GNUNET_NETWORK_Handle* const* LEGACY_SERVICE_get_listen_sockets | ( | struct LEGACY_SERVICE_Context * | ctx | ) |
Get the NULL-terminated array of listen sockets for this service.
ctx | service context to query |
Definition at line 1586 of file tcp_service_legacy.c.
References ctx.
Referenced by libgnunet_plugin_transport_tcp_init().
void LEGACY_SERVICE_stop | ( | struct LEGACY_SERVICE_Context * | sctx | ) |
Stop a service that was started with "LEGACY_SERVICE_start".
Stops a service that was started with GNUNET_SERVICE_start().
sctx | the service context returned from the start function |
Definition at line 1598 of file tcp_service_legacy.c.
References LEGACY_SERVICE_Context::addrlens, LEGACY_SERVICE_Context::addrs, LEGACY_SERVICE_Context::cfg, GAUGER, GNUNET_CONFIGURATION_get_value_string(), GNUNET_CONFIGURATION_have_value(), GNUNET_free, GNUNET_free_nz, GNUNET_OK, GNUNET_SCHEDULER_cancel(), GNUNET_SERVER_destroy(), GNUNET_YES, LEGACY_SERVICE_Context::my_handlers, LEGACY_SERVICE_Context::server, LEGACY_SERVICE_Context::service_name, LEGACY_SERVICE_Context::shutdown_task, LEGACY_SERVICE_Context::v4_allowed, LEGACY_SERVICE_Context::v4_denied, LEGACY_SERVICE_Context::v6_allowed, and LEGACY_SERVICE_Context::v6_denied.
Referenced by LEGACY_SERVICE_start(), libgnunet_plugin_transport_tcp_done(), and libgnunet_plugin_transport_tcp_init().
|
static |
Default handlers for all services.
Will be copied and the "callback_cls" fields will be replaced with the specific service struct.
Definition at line 267 of file tcp_service_legacy.c.
Referenced by LEGACY_SERVICE_start(), and service_task().