summaryrefslogtreecommitdiffstats
path: root/plugins-root
diff options
context:
space:
mode:
Diffstat (limited to 'plugins-root')
-rw-r--r--plugins-root/check_icmp.c34
1 files changed, 25 insertions, 9 deletions
diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c
index 5bfb5cb5..1390a03e 100644
--- a/plugins-root/check_icmp.c
+++ b/plugins-root/check_icmp.c
@@ -277,15 +277,6 @@ typedef struct {
277 check_icmp_config config; 277 check_icmp_config config;
278} check_icmp_config_wrapper; 278} check_icmp_config_wrapper;
279check_icmp_config_wrapper process_arguments(int argc, char **argv) { 279check_icmp_config_wrapper process_arguments(int argc, char **argv) {
280 /* get calling name the old-fashioned way for portability instead
281 * of relying on the glibc-ism __progname */
282 char *ptr = strrchr(argv[0], '/');
283 if (ptr) {
284 progname = &ptr[1];
285 } else {
286 progname = argv[0];
287 }
288
289 check_icmp_config_wrapper result = { 280 check_icmp_config_wrapper result = {
290 .errorcode = OK, 281 .errorcode = OK,
291 .config = check_icmp_config_init(), 282 .config = check_icmp_config_init(),
@@ -821,6 +812,15 @@ void parse_address(const struct sockaddr_storage *addr, char *dst, socklen_t siz
821} 812}
822 813
823int main(int argc, char **argv) { 814int main(int argc, char **argv) {
815#ifdef __OpenBSD__
816 /* - rpath is required to read --extra-opts (given up later)
817 * - inet is required for sockets
818 * - dns is required for name lookups (given up later)
819 * - id is required for temporary privilege drops in configparsing and for
820 * permanent privilege dropping after opening the socket (given up later) */
821 pledge("stdio rpath inet dns id", NULL);
822#endif // __OpenBSD__
823
824 setlocale(LC_ALL, ""); 824 setlocale(LC_ALL, "");
825 bindtextdomain(PACKAGE, LOCALEDIR); 825 bindtextdomain(PACKAGE, LOCALEDIR);
826 textdomain(PACKAGE); 826 textdomain(PACKAGE);
@@ -828,6 +828,14 @@ int main(int argc, char **argv) {
828 /* POSIXLY_CORRECT might break things, so unset it (the portable way) */ 828 /* POSIXLY_CORRECT might break things, so unset it (the portable way) */
829 environ = NULL; 829 environ = NULL;
830 830
831 /* determine program- and service-name quickly */
832 progname = strrchr(argv[0], '/');
833 if (progname != NULL) {
834 progname++;
835 } else {
836 progname = argv[0];
837 }
838
831 /* Parse extra opts if any */ 839 /* Parse extra opts if any */
832 argv = np_extra_opts(&argc, argv, progname); 840 argv = np_extra_opts(&argc, argv, progname);
833 841
@@ -837,6 +845,10 @@ int main(int argc, char **argv) {
837 crash("failed to parse config"); 845 crash("failed to parse config");
838 } 846 }
839 847
848#ifdef __OpenBSD__
849 pledge("stdio inet dns id", NULL);
850#endif // __OpenBSD__
851
840 const check_icmp_config config = tmp_config.config; 852 const check_icmp_config config = tmp_config.config;
841 853
842 if (config.output_format_is_set) { 854 if (config.output_format_is_set) {
@@ -899,6 +911,10 @@ int main(int argc, char **argv) {
899 return 1; 911 return 1;
900 } 912 }
901 913
914#ifdef __OpenBSD__
915 pledge("stdio inet", NULL);
916#endif // __OpenBSD__
917
902 if (sockset.socket4) { 918 if (sockset.socket4) {
903 int result = setsockopt(sockset.socket4, SOL_IP, IP_TTL, &config.ttl, sizeof(config.ttl)); 919 int result = setsockopt(sockset.socket4, SOL_IP, IP_TTL, &config.ttl, sizeof(config.ttl));
904 if (debug) { 920 if (debug) {