+ return x;
+}
+
+bool read_connection_config(connection_t *c) {
+ char *fname;
+ bool x;
+
+ read_config_options(c->config_tree, c->name);
+
+ xasprintf(&fname, "%s/hosts/%s", confbase, c->name);
+ x = read_config_file(c->config_tree, fname);
+ free(fname);
+
+ return x;
+}
+
+bool append_config_file(const char *name, const char *key, const char *value) {
+ char *fname;
+ xasprintf(&fname, "%s/hosts/%s", confbase, name);
+
+ FILE *fp = fopen(fname, "a");
+
+ if(!fp) {
+ logger(LOG_ERR, "Cannot open config file %s: %s", fname, strerror(errno));
+ } else {
+ fprintf(fp, "\n# The following line was automatically added by tinc\n%s = %s\n", key, value);
+ fclose(fp);
+ }
+
+ free(fname);
+
+ return fp;
+}
+
+bool disable_old_keys(FILE *f) {
+ char buf[100];
+ long pos;
+ bool disabled = false;
+
+ rewind(f);
+ pos = ftell(f);
+
+ if(pos < 0)
+ return false;
+
+ while(fgets(buf, sizeof buf, f)) {
+ if(!strncmp(buf, "-----BEGIN RSA", 14)) {
+ buf[11] = 'O';
+ buf[12] = 'L';
+ buf[13] = 'D';
+ if(fseek(f, pos, SEEK_SET))
+ break;
+ if(fputs(buf, f) <= 0)
+ break;
+ disabled = true;
+ }
+ else if(!strncmp(buf, "-----END RSA", 12)) {
+ buf[ 9] = 'O';
+ buf[10] = 'L';
+ buf[11] = 'D';
+ if(fseek(f, pos, SEEK_SET))
+ break;
+ if(fputs(buf, f) <= 0)
+ break;
+ disabled = true;
+ }
+ pos = ftell(f);
+ if(pos < 0)
+ break;
+ }
+
+ return disabled;