From 8f1e08973d04300bd326dcfdd568a3cb6a7a9631 Mon Sep 17 00:00:00 2001 From: cathugger Date: Thu, 12 Jul 2018 12:35:39 +0000 Subject: [PATCH] prevent termination during key write --- base64.h | 2 +- yaml.c | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/base64.h b/base64.h index 570de19..2a387df 100644 --- a/base64.h +++ b/base64.h @@ -4,7 +4,7 @@ char *base64_to(char *dst,const u8 *src,size_t slen); #define BASE64_TO_LEN(l) (((l + 3 - 1) / 3) * 4) // converts src string from base64 size_t base64_from(u8 *dst,const char *src,size_t slen); -// calculates length needed to store data converted from base +// calculates length needed to store data converted from base64 #define BASE64_FROM_LEN(l) ((l) / 4 * 3) // validates base32 string and optionally stores length of valid data // returns 1 if whole string is good, 0 if string contains invalid data diff --git a/yaml.c b/yaml.c index dc85173..b4564c4 100644 --- a/yaml.c +++ b/yaml.c @@ -1,3 +1,6 @@ +#ifdef __linux__ +#define _POSIX_C_SOURCE 200112L +#endif #include #include @@ -7,6 +10,10 @@ #include #include +#ifndef _WIN32 +#include +#endif + #include "types.h" #include "yaml.h" #include "ioutil.h" @@ -229,6 +236,13 @@ int yamlin_parseandcreate(FILE *fin,char *sname,const char *hostname) break; } if (hashost && haspub && hassec) { +#ifndef _WIN32 + sigset_t nset,oset; + sigemptyset(&nset); + sigaddset(&nset,SIGINT); + sigaddset(&nset,SIGTERM); + sigprocmask(SIG_BLOCK,&nset,&oset); +#endif if (createdir(sname,1) != 0) { fprintf(stderr,"ERROR: could not create directory for key output\n"); return 1; @@ -251,6 +265,9 @@ int yamlin_parseandcreate(FILE *fin,char *sname,const char *hostname) fwrite(&sname[printstartpos],printlen,1,fout); fflush(fout); } +#ifndef _WIN32 + sigprocmask(SIG_SETMASK,&oset,0); +#endif if (hostname) return 0; // finished skipthis = 1;