X-Git-Url: https://www.tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Finvitation.c;h=110e3953be34be066c0add8ce0785db69d838f09;hb=2e318f379992a730f592b4c5261d26d8e1a38cfd;hp=6ccfc1f4cf8e7499bbf2e407174074d698c23aa3;hpb=933f7f7526d89a4ad41e2c2936c26cb41997ed78;p=tinc diff --git a/src/invitation.c b/src/invitation.c index 6ccfc1f4..110e3953 100644 --- a/src/invitation.c +++ b/src/invitation.c @@ -142,12 +142,19 @@ char *get_my_hostname() { } } + if(!tty) { + if(!hostname) { + fprintf(stderr, "Could not determine the external address or hostname. Please set Address manually.\n"); + return NULL; + } + goto save; + } + again: - printf("Please enter your host's external address or hostname"); + fprintf(stderr, "Please enter your host's external address or hostname"); if(hostname) - printf(" [%s]", hostname); - printf(": "); - fflush(stdout); + fprintf(stderr, " [%s]", hostname); + fprintf(stderr, ": "); if(!fgets(line, sizeof line, stdin)) { fprintf(stderr, "Error while reading stdin: %s\n", strerror(errno)); @@ -404,8 +411,12 @@ int cmd_invite(int argc, char *argv[]) { char buf[1024]; while(fgets(buf, sizeof buf, tc)) { if((!strncasecmp(buf, "Mode", 4) && strchr(" \t=", buf[4])) - || (!strncasecmp(buf, "Broadcast", 9) && strchr(" \t=", buf[9]))) + || (!strncasecmp(buf, "Broadcast", 9) && strchr(" \t=", buf[9]))) { fputs(buf, f); + // Make sure there is a newline character. + if(!strchr(buf, '\n')) + fputc('\n', f); + } } fclose(tc); } @@ -567,7 +578,7 @@ make_names: if(!access(tinc_conf, F_OK)) { fprintf(stderr, "Configuration file %s already exists!\n", tinc_conf); - if(!tty || confbasegiven) + if(confbasegiven) return false; // Generate a random netname, ask for a better one later. @@ -743,7 +754,7 @@ make_names: check_port(name); ask_netname: - if(ask_netname) { + if(ask_netname && tty) { fprintf(stderr, "Enter a new netname: "); if(!fgets(line, sizeof line, stdin)) { fprintf(stderr, "Error while reading stdin: %s\n", strerror(errno)); @@ -767,6 +778,8 @@ ask_netname: make_names(); } + fprintf(stderr, "Configuration stored in: %s\n", confbase); + return true; } @@ -823,7 +836,7 @@ int cmd_join(int argc, char *argv[]) { } // Make sure confbase exists and is accessible. - if(strcmp(confdir, confbase) && mkdir(confdir, 0755) && errno != EEXIST) { + if(!confbase_given && mkdir(confdir, 0755) && errno != EEXIST) { fprintf(stderr, "Could not create directory %s: %s\n", confdir, strerror(errno)); return 1; } @@ -850,10 +863,8 @@ int cmd_join(int argc, char *argv[]) { if(argc > 1) { invitation = argv[1]; } else { - if(tty) { - printf("Enter invitation URL: "); - fflush(stdout); - } + if(tty) + fprintf(stderr, "Enter invitation URL: "); errno = EPIPE; if(!fgets(line, sizeof line, stdin)) { fprintf(stderr, "Error while reading stdin: %s\n", strerror(errno));