X-Git-Url: https://www.tinc-vpn.org/git/browse?p=tinc;a=blobdiff_plain;f=src%2Fconf.c;h=803c96c219d38621e5f449bb89d6e01cde232f91;hp=a61a3591b8ba592c74bc63a22a6d3e92ff99a0b3;hb=23730375f27c32e0fe1a59c7a761dd85296a7a4a;hpb=0d0dfd0852e9b2c9a7660880966a3c84790d5ea2 diff --git a/src/conf.c b/src/conf.c index a61a3591..803c96c2 100644 --- a/src/conf.c +++ b/src/conf.c @@ -429,7 +429,7 @@ bool read_server_config() return x == 0; } -FILE *ask_and_open(const char *filename, const char *what, const char *mode) +FILE *ask_and_open(const char *filename, const char *what) { FILE *r; char *directory; @@ -479,7 +479,7 @@ FILE *ask_and_open(const char *filename, const char *what, const char *mode) /* Open it first to keep the inode busy */ - r = fopen(fn, mode); + r = fopen(fn, "r+") ?: fopen(fn, "w+"); if(!r) { fprintf(stderr, _("Error opening file `%s': %s\n"), @@ -492,3 +492,34 @@ FILE *ask_and_open(const char *filename, const char *what, const char *mode) return r; } + +bool disable_old_keys(FILE *f) { + char buf[100]; + long pos; + bool disabled = false; + + rewind(f); + pos = ftell(f); + + while(fgets(buf, sizeof buf, f)) { + if(!strncmp(buf, "-----BEGIN RSA", 14)) { + buf[11] = 'O'; + buf[12] = 'L'; + buf[13] = 'D'; + fseek(f, pos, SEEK_SET); + fputs(buf, f); + disabled = true; + } + else if(!strncmp(buf, "-----END RSA", 12)) { + buf[ 9] = 'O'; + buf[10] = 'L'; + buf[11] = 'D'; + fseek(f, pos, SEEK_SET); + fputs(buf, f); + disabled = true; + } + pos = ftell(f); + } + + return disabled; +}