diff options
-rw-r--r-- | configure.ac | 2 | ||||
m--------- | grecs | 0 | ||||
-rw-r--r-- | po/POTFILES.in | 1 | ||||
-rw-r--r-- | src/pies.c | 1 | ||||
-rw-r--r-- | src/piesctl-cl.opt | 2 | ||||
-rw-r--r-- | src/piesctl.c | 63 | ||||
-rw-r--r-- | src/utmp.c | 11 |
7 files changed, 53 insertions, 27 deletions
diff --git a/configure.ac b/configure.ac index d6d4e4f..114fc07 100644 --- a/configure.ac +++ b/configure.ac @@ -72,7 +72,7 @@ AC_CHECK_FUNCS([alarm dup2 gethostbyname memmove memset select setenv socket str gl_INIT # Grecs -GRECS_SETUP([grecs],[tests git2chg getopt json]) +GRECS_SETUP([grecs],[tests git2chg getopt json sockaddr-list]) GRECS_HOST_PROJECT_INCLUDES='-I$(top_srcdir)/gnu -I$(top_builddir)/gnu' # Test for setproctitle diff --git a/grecs b/grecs -Subproject 384b8c088c290f06f70835402f903627c67de6f +Subproject 3df291f812208a8ce07a2878784a0a73e458719 diff --git a/po/POTFILES.in b/po/POTFILES.in index f696480..acc6127 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -20,7 +20,6 @@ lib/addrfmt.c src/depmap.c src/diag.c src/limits.c -src/meta.c src/meta1gram.y src/meta1lex.l src/pies.c @@ -1795,7 +1795,6 @@ void pies_schedule_action (int act) { action = act; - /*FIXME: got_alarm?*/ } RETSIGTYPE diff --git a/src/piesctl-cl.opt b/src/piesctl-cl.opt index b787a5c..41e982b 100644 --- a/src/piesctl-cl.opt +++ b/src/piesctl-cl.opt @@ -61,7 +61,7 @@ END OPTION(url,u,URL, [<connect to this socket>]) BEGIN - if (pies_url_create (&url, optarg)) + if (pies_url_create (&client.url, optarg)) { grecs_error (NULL, 0, _("%s: cannot create URL: %s"), optarg, strerror (errno)); diff --git a/src/piesctl.c b/src/piesctl.c index dba8988..ff205d5 100644 --- a/src/piesctl.c +++ b/src/piesctl.c @@ -38,7 +38,12 @@ #include "fprintftime.h" struct pies_url *default_url; /* Control socket URL */ -struct pies_url *url; +struct grecs_sockaddr *source_addr; +struct client_conn +{ + struct pies_url *url; + struct grecs_sockaddr *source_addr; +} client; char const *instance = "pies"; char *config_file; char default_config_file[] = SYSCONFDIR "/piesctl.conf"; @@ -46,6 +51,8 @@ int preprocess_only; int verbose; int dump; +struct grecs_sockaddr_hints hints = { .flags = GRECS_AH_PASSIVE }; + #define EX_OK 0 #define EX_NOTFOUND 1 @@ -60,7 +67,12 @@ static struct grecs_keyword instance_keywords[] = { N_("url: string"), N_("Socket URL for that instance."), grecs_type_string, GRECS_DFLT, - NULL, 0, conf_callback_url}, + NULL, offsetof(struct client_conn,url), conf_callback_url}, + {"source", + N_("arg"), + N_("Source IP address."), + grecs_type_sockaddr, GRECS_DFLT, + NULL, offsetof(struct client_conn,source_addr) }, { NULL } }; @@ -80,10 +92,10 @@ callback_instance (enum grecs_callback_command cmd, } if (assert_grecs_value_type (&value->locus, value, GRECS_TYPE_STRING)) return 1; - if (!url && strcmp (value->v.string, instance) == 0) - *(struct pies_url ***) cb_data = &url; + if (strcmp (value->v.string, instance) == 0) + *(struct client_conn **) cb_data = &client; else - *(struct pies_url ***) cb_data = NULL; + *(struct client_conn **) cb_data = NULL; break; case grecs_callback_section_end: @@ -101,6 +113,11 @@ struct grecs_keyword piesctl_keywords[] = { N_("Default socket URL."), grecs_type_string, GRECS_DFLT, &default_url, 0, conf_callback_url}, + {"source", + N_("arg"), + N_("Source IP address."), + grecs_type_sockaddr, GRECS_DFLT, + &source_addr }, {"instance", N_("name"), N_("Configure connection to a pies instance"), @@ -120,7 +137,8 @@ parse_config () DEFAULT_INCLUDE_DIR, NULL); grecs_log_to_stderr = 1; grecs_preprocessor = pp_command_line (); - + grecs_sockaddr_hints = &hints; + if (config_file) file_name = config_file; else if (access (default_config_file, F_OK) == 0) @@ -141,12 +159,12 @@ parse_config () exit (EX_CONFIG); if (grecs_tree_process (tree, piesctl_keywords)) exit (EX_CONFIG); - if (!url && verbose) + if (!client.url && verbose) printf (_("%s: URL not found in %s\n"), program_name, file_name); } - if (!url) + if (!client.url) { /* Try local instance configuration */ file_name = mkfilename (SYSCONFDIR, instance, ".conf"); @@ -166,7 +184,7 @@ parse_config () { assert_grecs_value_type (&node->locus, node->v.value, GRECS_TYPE_STRING); - if (pies_url_create (&url, node->v.value->v.string)) + if (pies_url_create (&client.url, node->v.value->v.string)) { grecs_error (&node->locus, 0, _("%s: cannot create URL: %s"), node->v.value->v.string, strerror (errno)); @@ -180,15 +198,15 @@ parse_config () free (file_name); } - if (!url) + if (!client.url) { if (verbose) printf (_("%s: falling back to default URL\n"), program_name); if (default_url) - url = default_url; + client.url = default_url; else { - if (pies_url_create (&url, DEFAULT_PIES_CONTROL_URL)) + if (pies_url_create (&client.url, DEFAULT_PIES_CONTROL_URL)) { grecs_error (NULL, 0, _("%s: cannot create URL: %s"), DEFAULT_PIES_CONTROL_URL, strerror (errno)); @@ -196,9 +214,12 @@ parse_config () } } } + + if (!client.source_addr) + client.source_addr = source_addr; if (verbose) - printf (_("%s: using URL %s\n"), program_name, url->string); + printf (_("%s: using URL %s\n"), program_name, client.url->string); } static void @@ -385,7 +406,7 @@ shttp_io_free (struct shttp_io *io) } static struct shttp_connection * -shttp_connect (struct pies_url *url) +shttp_connect (struct pies_url *url, struct grecs_sockaddr *source_addr) { int fd; union pies_sockaddr_storage addr; @@ -496,7 +517,17 @@ shttp_connect (struct pies_url *url) grecs_error (NULL, 0, _("%s: cannot set close-on-exec: %s"), url->string, strerror (errno)); - // FIXME: Bind to local address + if (source_addr) + { + if (source_addr->sa->sa_family != addr.s.sa_family) + grecs_error (NULL, 0, + _("source and destination address family differ")); + else if (bind (fd, source_addr->sa, source_addr->len) < 0) + { + grecs_error (NULL, errno, _("failed to bind")); + exit (EX_UNAVAILABLE); + } + } if (connect (fd, &addr.s, socklen)) { @@ -1813,7 +1844,7 @@ main (int argc, char **argv) parse_config (); - conn = shttp_connect (url); + conn = shttp_connect (client.url, client.source_addr); if (!conn) return EX_UNAVAILABLE; @@ -105,18 +105,16 @@ fill_utmp (UTMPX *utmp, #endif } - -int wtmpxreboot = 0; - void write_wtmpx (int type, const char *user, const char *id, pid_t pid, const char *line) { UTMPX utmp; + static int wtmpxreboot = 0; + debug (2, (_("cannot open %s for writing"), WTMP_FILE)); if (access (WTMP_FILE, W_OK)) { - logmsg (LOG_NOTICE, _("cannot open %s for writing"), WTMP_FILE); if (type == BOOT_TIME) wtmpxreboot++; return; @@ -131,17 +129,16 @@ write_wtmpx (int type, const char *user, const char *id, pid_t pid, pies_updwtmpx (WTMP_FILE, &utmp); } -int utmpreboot = 0; - void write_utmpx (int type, const char *user, const char *id, pid_t pid, const char *line) { UTMPX utmp; + static int utmpreboot = 0; if (access (UTMP_FILE, W_OK)) { - logmsg (LOG_NOTICE, _("cannot open %s for writing"), UTMP_FILE); + debug (1, (_("cannot open %s for writing"), UTMP_FILE)); if (type == BOOT_TIME) utmpreboot++; return; |