X-Git-Url: https://tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Fconf.c;h=d5bc9165804209608d30ced5bf589128e3b946ce;hb=79e46d08a46f2fef2ee4e8eac7ba487007160564;hp=42866b83cb21ddb1b17550ce55dee6193e984a86;hpb=103543aa2c15d9f1e2aa313a2e593a7524cce484;p=tinc diff --git a/src/conf.c b/src/conf.c index 42866b83..d5bc9165 100644 --- a/src/conf.c +++ b/src/conf.c @@ -224,7 +224,7 @@ static char *readline(FILE * fp, char *buf, size_t buflen) { newline = strchr(p, '\n'); if(!newline) - return NULL; + return buf; *newline = '\0'; /* kill newline */ if(newline > p && newline[-1] == '\r') /* and carriage return if necessary */ @@ -238,7 +238,6 @@ static char *readline(FILE * fp, char *buf, size_t buflen) { starting at *base. */ int read_config_file(splay_tree_t *config_tree, const char *fname) { - int err = -2; /* Parse error */ FILE *fp; char buffer[MAX_STRING_SIZE]; char *line; @@ -333,66 +332,6 @@ bool read_server_config() { return x; } -FILE *ask_and_open(const char *filename, const char *what) { - FILE *r; - char *directory; - char line[PATH_MAX]; - const char *fn; - - /* Check stdin and stdout */ - if(!isatty(0) || !isatty(1)) { - /* Argh, they are running us from a script or something. Write - the files to the current directory and let them burn in hell - for ever. */ - fn = filename; - } else { - /* Ask for a file and/or directory name. */ - fprintf(stdout, "Please enter a file to save %s to [%s]: ", - what, filename); - fflush(stdout); - - fn = readline(stdin, line, sizeof line); - - if(!fn) { - fprintf(stderr, "Error while reading stdin: %s\n", - strerror(errno)); - return NULL; - } - - if(!strlen(fn)) - /* User just pressed enter. */ - fn = filename; - } - -#ifdef HAVE_MINGW - if(fn[0] != '\\' && fn[0] != '/' && !strchr(fn, ':')) { -#else - if(fn[0] != '/') { -#endif - /* The directory is a relative path or a filename. */ - char *p; - - directory = get_current_dir_name(); - xasprintf(&p, "%s/%s", directory, fn); - free(directory); - fn = p; - } - - umask(0077); /* Disallow everything for group and other */ - - /* Open it first to keep the inode busy */ - - r = fopen(fn, "r+") ?: fopen(fn, "w+"); - - if(!r) { - fprintf(stderr, "Error opening file `%s': %s\n", - fn, strerror(errno)); - return NULL; - } - - return r; -} - bool disable_old_keys(FILE *f) { char buf[100]; long pos;