hastd.c (233679) | hastd.c (246922) |
---|---|
1/*- 2 * Copyright (c) 2009-2010 The FreeBSD Foundation 3 * Copyright (c) 2010-2011 Pawel Jakub Dawidek <pawel@dawidek.net> 4 * All rights reserved. 5 * 6 * This software was developed by Pawel Jakub Dawidek under sponsorship from 7 * the FreeBSD Foundation. 8 * --- 15 unchanged lines hidden (view full) --- 24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * SUCH DAMAGE. 29 */ 30 31#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2009-2010 The FreeBSD Foundation 3 * Copyright (c) 2010-2011 Pawel Jakub Dawidek <pawel@dawidek.net> 4 * All rights reserved. 5 * 6 * This software was developed by Pawel Jakub Dawidek under sponsorship from 7 * the FreeBSD Foundation. 8 * --- 15 unchanged lines hidden (view full) --- 24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * SUCH DAMAGE. 29 */ 30 31#include <sys/cdefs.h> |
32__FBSDID("$FreeBSD: head/sbin/hastd/hastd.c 233679 2012-03-29 20:11:16Z trociny $"); | 32__FBSDID("$FreeBSD: head/sbin/hastd/hastd.c 246922 2013-02-17 21:12:34Z pjd $"); |
33 34#include <sys/param.h> 35#include <sys/linker.h> 36#include <sys/module.h> 37#include <sys/stat.h> 38#include <sys/wait.h> 39 40#include <err.h> --- 22 unchanged lines hidden (view full) --- 63/* Path to configuration file. */ 64const char *cfgpath = HAST_CONFIG; 65/* Hastd configuration. */ 66static struct hastd_config *cfg; 67/* Was SIGINT or SIGTERM signal received? */ 68bool sigexit_received = false; 69/* Path to pidfile. */ 70static const char *pidfile; | 33 34#include <sys/param.h> 35#include <sys/linker.h> 36#include <sys/module.h> 37#include <sys/stat.h> 38#include <sys/wait.h> 39 40#include <err.h> --- 22 unchanged lines hidden (view full) --- 63/* Path to configuration file. */ 64const char *cfgpath = HAST_CONFIG; 65/* Hastd configuration. */ 66static struct hastd_config *cfg; 67/* Was SIGINT or SIGTERM signal received? */ 68bool sigexit_received = false; 69/* Path to pidfile. */ 70static const char *pidfile; |
71/* PID file handle. */ | 71/* Pidfile handle. */ |
72struct pidfh *pfh; 73/* Do we run in foreground? */ 74static bool foreground; 75 76/* How often check for hooks running for too long. */ 77#define REPORT_INTERVAL 5 78 79static void --- 663 unchanged lines hidden (view full) --- 743listen_accept(struct hastd_listen *lst) 744{ 745 struct hast_resource *res; 746 struct proto_conn *conn; 747 struct nv *nvin, *nvout, *nverr; 748 const char *resname; 749 const unsigned char *token; 750 char laddr[256], raddr[256]; | 72struct pidfh *pfh; 73/* Do we run in foreground? */ 74static bool foreground; 75 76/* How often check for hooks running for too long. */ 77#define REPORT_INTERVAL 5 78 79static void --- 663 unchanged lines hidden (view full) --- 743listen_accept(struct hastd_listen *lst) 744{ 745 struct hast_resource *res; 746 struct proto_conn *conn; 747 struct nv *nvin, *nvout, *nverr; 748 const char *resname; 749 const unsigned char *token; 750 char laddr[256], raddr[256]; |
751 uint8_t version; |
|
751 size_t size; 752 pid_t pid; 753 int status; 754 755 proto_local_address(lst->hl_conn, laddr, sizeof(laddr)); 756 pjdlog_debug(1, "Accepting connection to %s.", laddr); 757 758 if (proto_accept(lst->hl_conn, &conn) == -1) { --- 33 unchanged lines hidden (view full) --- 792 793 resname = nv_get_string(nvin, "resource"); 794 if (resname == NULL) { 795 pjdlog_error("No 'resource' field in the header received from %s.", 796 raddr); 797 goto close; 798 } 799 pjdlog_debug(2, "%s: resource=%s", raddr, resname); | 752 size_t size; 753 pid_t pid; 754 int status; 755 756 proto_local_address(lst->hl_conn, laddr, sizeof(laddr)); 757 pjdlog_debug(1, "Accepting connection to %s.", laddr); 758 759 if (proto_accept(lst->hl_conn, &conn) == -1) { --- 33 unchanged lines hidden (view full) --- 793 794 resname = nv_get_string(nvin, "resource"); 795 if (resname == NULL) { 796 pjdlog_error("No 'resource' field in the header received from %s.", 797 raddr); 798 goto close; 799 } 800 pjdlog_debug(2, "%s: resource=%s", raddr, resname); |
801 version = nv_get_uint8(nvin, "version"); 802 pjdlog_debug(2, "%s: version=%hhu", raddr, version); 803 if (version == 0) { 804 /* 805 * If no version is sent, it means this is protocol version 1. 806 */ 807 version = 1; 808 } 809 if (version > HAST_PROTO_VERSION) { 810 pjdlog_info("Remote protocol version %hhu is not supported, falling back to version %hhu.", 811 version, (unsigned char)HAST_PROTO_VERSION); 812 version = HAST_PROTO_VERSION; 813 } 814 pjdlog_debug(1, "Negotiated protocol version %hhu.", version); |
|
800 token = nv_get_uint8_array(nvin, &size, "token"); 801 /* 802 * NULL token means that this is first connection. 803 */ 804 if (token != NULL && size != sizeof(res->hr_token)) { 805 pjdlog_error("Received token of invalid size from %s (expected %zu, got %zu).", 806 raddr, sizeof(res->hr_token), size); 807 goto close; --- 97 unchanged lines hidden (view full) --- 905 } 906 } 907 908 /* 909 * Checks and cleanups are done. 910 */ 911 912 if (token == NULL) { | 815 token = nv_get_uint8_array(nvin, &size, "token"); 816 /* 817 * NULL token means that this is first connection. 818 */ 819 if (token != NULL && size != sizeof(res->hr_token)) { 820 pjdlog_error("Received token of invalid size from %s (expected %zu, got %zu).", 821 raddr, sizeof(res->hr_token), size); 822 goto close; --- 97 unchanged lines hidden (view full) --- 920 } 921 } 922 923 /* 924 * Checks and cleanups are done. 925 */ 926 927 if (token == NULL) { |
928 res->hr_version = version; |
|
913 arc4random_buf(res->hr_token, sizeof(res->hr_token)); 914 nvout = nv_alloc(); | 929 arc4random_buf(res->hr_token, sizeof(res->hr_token)); 930 nvout = nv_alloc(); |
931 nv_add_uint8(nvout, version, "version"); |
|
915 nv_add_uint8_array(nvout, res->hr_token, 916 sizeof(res->hr_token), "token"); 917 if (nv_error(nvout) != 0) { 918 pjdlog_common(LOG_ERR, 0, nv_error(nvout), 919 "Unable to prepare return header for %s", raddr); 920 nv_add_stringf(nverr, "errmsg", 921 "Remote node was unable to prepare return header: %s.", 922 strerror(nv_error(nvout))); 923 goto fail; 924 } | 932 nv_add_uint8_array(nvout, res->hr_token, 933 sizeof(res->hr_token), "token"); 934 if (nv_error(nvout) != 0) { 935 pjdlog_common(LOG_ERR, 0, nv_error(nvout), 936 "Unable to prepare return header for %s", raddr); 937 nv_add_stringf(nverr, "errmsg", 938 "Remote node was unable to prepare return header: %s.", 939 strerror(nv_error(nvout))); 940 goto fail; 941 } |
925 if (hast_proto_send(NULL, conn, nvout, NULL, 0) == -1) { | 942 if (hast_proto_send(res, conn, nvout, NULL, 0) == -1) { |
926 int error = errno; 927 928 pjdlog_errno(LOG_ERR, "Unable to send response to %s", 929 raddr); 930 nv_add_stringf(nverr, "errmsg", 931 "Remote node was unable to send response: %s.", 932 strerror(error)); 933 goto fail; --- 387 unchanged lines hidden --- | 943 int error = errno; 944 945 pjdlog_errno(LOG_ERR, "Unable to send response to %s", 946 raddr); 947 nv_add_stringf(nverr, "errmsg", 948 "Remote node was unable to send response: %s.", 949 strerror(error)); 950 goto fail; --- 387 unchanged lines hidden --- |