ratox

FIFO based tox client
Log | Files | Refs | README | LICENSE

commit 2373946754a95b676e5b899c15ce70d33cfdbfb4
parent c0c6381928c84d5cd3331f9b0fe1beb3908326c8
Author: FRIGN <dev@frign.de>
Date:   Mon Dec  8 20:50:40 +0100

Add ability to specify save file as command line argument

Also, get closer to the STS (Single Tox Standard) by calling the
the save file "save file" and not "data file".
Additionally, augment the manual section about encrypting and
decrypting the save file.

Diffstat:
config.def.h | 4++--
ratox.1 | 21+++++++++++++++------
ratox.c | 43++++++++++++++++++++++++-------------------
3 files changed, 41 insertions(+), 27 deletions(-)
diff --git a/config.def.h b/config.def.h @@ -1,12 +1,12 @@ /* See LICENSE file for copyright and license details. */ -#define DATAFILE ".ratox.tox" /* connection delay in seconds */ #define CONNECTDELAY 4 /* ringing delay in seconds */ #define RINGINGDELAY 16 #define MAXCALLS 8 -static int encryptdatafile = 0; +static char *savefile = ".ratox.tox"; +static int encryptsavefile = 0; static char proxyaddr[] = "localhost"; static uint16_t proxyport = 8080; diff --git a/ratox.1 b/ratox.1 @@ -1,4 +1,4 @@ -.Dd December 5, 2014 +.Dd December 8, 2014 .Dt RATOX 1 .Os .Sh NAME @@ -9,6 +9,7 @@ .Op Fl 4 | Fl 6 .Op Fl E | Fl e .Op Fl tp +.Op Ar savefile .Sh DESCRIPTION .Nm is a client implementation of the rather popular tox protocol. @@ -22,14 +23,16 @@ Switch to IPv4-only mode. This is the default. .It Fl 6 Switch to IPv6-only mode. .It Fl E -Enable data file encryption. +Enable save file encryption. .It Fl e -Disable data file encryption. +Disable save file encryption. .It Fl t Enable TCP mode. By default, tox operates with UDP and is recommended, as TCP mode implies certain security considerations. .It Fl p Enable TCP SOCKS5 proxy as specified in \fIconfig.h\fR when the package was built. By default when this option is enabled, ratox will use a proxy on \fB127.0.0.1:8080\fR. +.It Ar savefile +Specify the path of the save file to load a profile from or create a new one at. .El .Sh CONFIGURATION .Nm @@ -37,10 +40,16 @@ is configured by modifying \fIconfig.h\fR and recompiling the code. Apart from the command line options there are a few more options that can be tweaked at compile time. .Pp -Encrypting the save file can be done by setting \fBencryptdatafile\fR to \fB1\fR. -You can do this even if your current save file is not encrypted. The next time +You can encrypt/decrypt your save file by setting \fBencryptsavefile\fR to \fB1\fR | \fB0\fR or +specifying +.Fl E +| +.Fl e +respectively. In the former case it will prompt you for a new passphrase, in the latter it will ask you to enter your current passphrase and will then write the save file unencrypted. +.Pp +Trying to load or decrypt an encrypted save file, .Nm -starts it will ask you to supply an encryption passphrase. +will ask you to supply a passphrase. .Sh FILESYSTEM STRUCTURE .Ss Global slots Each of the following global slots contain an \fBin\fR, \fBout\fR and diff --git a/ratox.c b/ratox.c @@ -1004,9 +1004,9 @@ dataload(void) int fd; uint8_t *data, *passphrase2 = NULL; - fd = open(DATAFILE, O_RDONLY); + fd = open(savefile, O_RDONLY); if (fd < 0) { - if (encryptdatafile) { + if (encryptsavefile) { reprompt1: while (readpass("Data : New passphrase > ", &passphrase, &pplen) < 0); while (readpass("Data : Re-enter passphrase > ", &passphrase2, &pp2len) < 0); @@ -1024,7 +1024,7 @@ reprompt1: lseek(fd, 0, SEEK_SET); if (sz == 0) { - weprintf("Data : %s > Empty\n", DATAFILE); + weprintf("Data : %s > Empty\n", savefile); return; } @@ -1033,18 +1033,18 @@ reprompt1: eprintf("malloc:"); if (read(fd, data, sz) != sz) - eprintf("read %s:", DATAFILE); + eprintf("read %s:", savefile); if (tox_is_save_encrypted(data)) { - if (!encryptdatafile) - logmsg("Data : %s > Encrypted, but saving unencrypted\n", DATAFILE); + if (!encryptsavefile) + logmsg("Data : %s > Encrypted, but saving unencrypted\n", savefile); while (readpass("Data : Passphrase > ", &passphrase, &pplen) < 0 || tox_encrypted_load(tox, data, sz, passphrase, pplen) < 0); } else { if (tox_load(tox, data, sz) < 0) - eprintf("Data : %s > Failed to load\n", DATAFILE); - if (encryptdatafile) { - logmsg("Data : %s > Not encrypted, but saving encrypted\n", DATAFILE); + eprintf("Data : %s > Failed to load\n", savefile); + if (encryptsavefile) { + logmsg("Data : %s > Not encrypted, but saving encrypted\n", savefile); reprompt2: while (readpass("Data : New passphrase > ", &passphrase, &pplen) < 0); while (readpass("Data : Re-enter passphrase > ", &passphrase2, &pp2len) < 0); @@ -1068,21 +1068,21 @@ datasave(void) int fd; uint8_t *data; - fd = open(DATAFILE, O_WRONLY | O_TRUNC | O_CREAT , 0666); + fd = open(savefile, O_WRONLY | O_TRUNC | O_CREAT , 0666); if (fd < 0) - eprintf("open %s:", DATAFILE); + eprintf("open %s:", savefile); - sz = encryptdatafile ? tox_encrypted_size(tox) : tox_size(tox); + sz = encryptsavefile ? tox_encrypted_size(tox) : tox_size(tox); data = malloc(sz); if (!data) eprintf("malloc:"); - if (encryptdatafile) + if (encryptsavefile) tox_encrypted_save(tox, data, passphrase, pplen); else tox_save(tox, data); if (write(fd, data, sz) != sz) - eprintf("write %s:", DATAFILE); + eprintf("write %s:", savefile); fsync(fd); free(data); @@ -1943,11 +1943,11 @@ shutdown(void) static void usage(void) { - eprintf("usage: %s [-4|-6] [-E|-e] [-tp]\n" + eprintf("usage: %s [-4|-6] [-E|-e] [-tp] [savefile]\n" " -4\tIPv4 only\n" " -6\tIPv6 only\n" - " -E\tEnable data file encryption\n" - " -e\tDisable data file encryption\n" + " -E\tEnable save file encryption\n" + " -e\tDisable save file encryption\n" " -t\tEnable TCP mode (UDP by default)\n" " -p\tEnable TCP socks5 proxy\n", argv0); } @@ -1962,10 +1962,10 @@ main(int argc, char *argv[]) ipv6 = 1; break; case 'E': - encryptdatafile = 1; + encryptsavefile = 1; break; case 'e': - encryptdatafile = 0; + encryptsavefile = 0; break; case 't': tcpflag = 1; @@ -1977,6 +1977,11 @@ main(int argc, char *argv[]) usage(); } ARGEND; + if (argc > 1) + usage(); + if (argc == 1) + savefile = *argv; + setbuf(stdout, NULL); signal(SIGHUP, initshutdown);