X-Git-Url: https://www.tinc-vpn.org/git/browse?p=tinc;a=blobdiff_plain;f=src%2Fconf.c;h=d8a8d83214304e079d78f4324bc6685e153e1186;hp=a61a3591b8ba592c74bc63a22a6d3e92ff99a0b3;hb=73d77dd416b87b7c4e9b6aa450f64846235cd2b4;hpb=0966cca8ab6dcde2747c717f21d73fd332e04242 diff --git a/src/conf.c b/src/conf.c index a61a3591..d8a8d832 100644 --- a/src/conf.c +++ b/src/conf.c @@ -2,7 +2,7 @@ conf.c -- configuration code Copyright (C) 1998 Robert van der Meulen 1998-2005 Ivo Timmermans - 2000-2008 Guus Sliepen + 2000-2009 Guus Sliepen 2000 Cris van Pelt This program is free software; you can redistribute it and/or modify @@ -417,7 +417,7 @@ bool read_server_config() cp(); - asprintf(&fname, "%s/tinc.conf", confbase); + xasprintf(&fname, "%s/tinc.conf", confbase); x = read_config_file(config_tree, fname); if(x == -1) { /* System error: complain */ @@ -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; @@ -469,7 +469,7 @@ FILE *ask_and_open(const char *filename, const char *what, const char *mode) char *p; directory = get_current_dir_name(); - asprintf(&p, "%s/%s", directory, fn); + xasprintf(&p, "%s/%s", directory, fn); free(fn); free(directory); fn = p; @@ -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; +}