unbound 0.1
unbound-control.c File Reference

The remote control utility contacts the unbound server over ssl and sends the command, receives the answer, and displays the result from the commandline. More...

#include "config.h"
#include "util/log.h"
#include "util/config_file.h"
#include "util/locks.h"
#include "util/net_help.h"
#include "util/shm_side/shm_main.h"
#include "util/timeval_func.h"
#include "daemon/stats.h"
#include "sldns/wire2str.h"
#include "sldns/pkthdr.h"
#include "services/rpz.h"
#include "services/listen_dnsport.h"

Macros

#define UNBOUND_CONTROL_CONNECT_TIMEOUT   5000

Functions

static void usage (void)
 timeout to wait for connection over stream, in msec
static void print_stats_shm (const char *cfgfile, int quiet)
 print statistics from shm memory segment
static void ssl_err (const char *s)
 exit with ssl error
static void ssl_path_err (const char *s, const char *path)
 exit with ssl error related to a file path
static SSL_CTX * setup_ctx (struct config_file *cfg)
 setup SSL context
static void checkconnecterr (int err, const char *svr, struct sockaddr_storage *addr, socklen_t addrlen, int statuscmd, int useport)
 check connect error
static int contact_server (const char *svr, struct config_file *cfg, int statuscmd)
 contact the server with TCP connect
static SSL * setup_ssl (SSL_CTX *ctx, int fd)
 setup SSL on the connection
static int remote_read (SSL *ssl, int fd, char *buf, size_t len)
 read from ssl or fd, fatalexit on error, 0 EOF, 1 success
static void remote_write (SSL *ssl, int fd, const char *buf, size_t len)
 write to ssl or fd, fatalexit on error
static void check_args_for_listcmd (int argc, char *argv[])
 check args, to see if too many args.
static void send_file (SSL *ssl, int fd, FILE *in, char *buf, size_t sz)
 send stdin to server
static void send_eof (SSL *ssl, int fd)
 send end-of-file marker to server
static int go_cmd (SSL *ssl, int fd, int quiet, int argc, char *argv[])
 send command and display result
static int go (const char *cfgfile, char *svr, int quiet, int argc, char *argv[])
 go ahead and read config, contact server and perform command and display
int main (int argc, char *argv[])
 Main routine for unbound-control.

Variables

int optind
 getopt global, in case header files fail to declare it.
char * optarg
 getopt global, in case header files fail to declare it.

Detailed Description

The remote control utility contacts the unbound server over ssl and sends the command, receives the answer, and displays the result from the commandline.

Function Documentation

◆ usage()

void usage ( void )
static

timeout to wait for connection over stream, in msec

Give unbound-control usage, and exit (1).

References ssl_err(), ssl_path_err(), and usage().

◆ print_stats_shm()

void print_stats_shm ( const char * cfgfile,
int quiet )
static

print statistics from shm memory segment

References config_create(), config_delete(), config_read(), fatal_exit(), print_stats_shm(), and config_file::shm_key.

Referenced by main(), and print_stats_shm().

◆ ssl_err()

void ssl_err ( const char * s)
static

exit with ssl error

References ssl_err().

Referenced by remote_read(), remote_write(), setup_ctx(), setup_ssl(), ssl_err(), ssl_path_err(), and usage().

◆ ssl_path_err()

void ssl_path_err ( const char * s,
const char * path )
static

exit with ssl error related to a file path

References ssl_err(), and ssl_path_err().

Referenced by setup_ctx(), ssl_path_err(), and usage().

◆ setup_ctx()

◆ checkconnecterr()

void checkconnecterr ( int err,
const char * svr,
struct sockaddr_storage * addr,
socklen_t addrlen,
int statuscmd,
int useport )
static

check connect error

References checkconnecterr(), log_err(), log_err_addr(), and ub_stats_info::svr.

Referenced by checkconnecterr(), and contact_server().

◆ contact_server()

◆ setup_ssl()

SSL * setup_ssl ( SSL_CTX * ctx,
int fd )
static

setup SSL on the connection

References setup_ssl(), and ssl_err().

Referenced by do_service(), go(), setup_ssl(), and setup_ssl().

◆ remote_read()

int remote_read ( SSL * ssl,
int fd,
char * buf,
size_t len )
static

read from ssl or fd, fatalexit on error, 0 EOF, 1 success

References fatal_exit(), remote_read(), sock_strerror(), and ssl_err().

Referenced by go_cmd(), and remote_read().

◆ remote_write()

void remote_write ( SSL * ssl,
int fd,
const char * buf,
size_t len )
static

write to ssl or fd, fatalexit on error

References fatal_exit(), remote_write(), sock_strerror(), and ssl_err().

Referenced by go_cmd(), remote_write(), send_eof(), and send_file().

◆ check_args_for_listcmd()

void check_args_for_listcmd ( int argc,
char * argv[] )
static

check args, to see if too many args.

Because when a file is sent it would wait for the terminal, and we can check for too many arguments, eg. user put arguments on the commandline.

References check_args_for_listcmd(), and fatal_exit().

Referenced by check_args_for_listcmd(), and main().

◆ send_file()

void send_file ( SSL * ssl,
int fd,
FILE * in,
char * buf,
size_t sz )
static

send stdin to server

References remote_write(), and send_file().

Referenced by go_cmd(), and send_file().

◆ send_eof()

void send_eof ( SSL * ssl,
int fd )
static

send end-of-file marker to server

References remote_write(), and send_eof().

Referenced by go_cmd(), and send_eof().

◆ go_cmd()

int go_cmd ( SSL * ssl,
int fd,
int quiet,
int argc,
char * argv[] )
static

send command and display result

References go_cmd(), remote_read(), remote_write(), send_eof(), and send_file().

Referenced by go(), and go_cmd().

◆ go()

int go ( const char * cfgfile,
char * svr,
int quiet,
int argc,
char * argv[] )
static

go ahead and read config, contact server and perform command and display

References config_create(), config_delete(), config_read(), contact_server(), fatal_exit(), go(), go_cmd(), log_warn(), config_file::remote_control_enable, setup_ctx(), setup_ssl(), and sock_close().

Referenced by go(), and main().

◆ main()

int main ( int argc,
char * argv[] )