tttm

git clone https://orangeshoelaces.net/git/tttm.git

6b4d7b682fa823273af9d9cc552c3b59da5725f4

Author: Vasily Kolobkov on 06/02/2016

Committer: Vasily Kolobkov on 06/02/2016

Freeze credential keys

Stats

imap.c |  4 +-
tttm.c | 27 +++-----
2 files changed, 11 insertions(+), 20 deletions(-)

Patch

diff --git a/imap.c b/imap.c
index 8b779db..1929d92 100644
--- a/imap.c
+++ b/imap.c
@@ -129,10 +129,10 @@ imap_discocap(struct imapctx *con)
 }
 
 int
-imap_login(struct imapctx *con, const char *name, const char *pass)
+imap_login(struct imapctx *con, const char *user, const char *pass)
 {
 	return imap_cmd(con, IS_AUTH, "%u LOGIN %LS %LS\r\n", 0, unilat,
-	    -1, con->tag++, name, pass);
+	    -1, con->tag++, user, pass);
 }
 
 int
diff --git a/tttm.c b/tttm.c
index 660f33f..a6a2b7d 100644
--- a/tttm.c
+++ b/tttm.c
@@ -32,33 +32,27 @@ static void	usage(void);
 
 extern char **environ;
 
-static size_t	page;
-static char	stortpl[] = "/tmp/tttm.XXXXXX";
+static size_t	 page;
+static char	 stortpl[] = "/tmp/tttm.XXXXXX";
+static char	*userkey = "IMAP_USER";
+static char	*passkey = "IMAP_PASS";
 
 int
 main(int argc, char **argv)
 {
 	int e, in, out;
 	struct imapctx con;
-	char *namekey, *passkey;
-	char *name, *pass, *sink;
+	char *user, *pass, *sink;
 	int stor;
 	int arg, refetchc, batchsz, mpiped;
 	struct msgd bag[BATCHSZ], *m, *bend;
 	long sv;
 
-	namekey = passkey = 0;
 	in = STDIN_FILENO;
 	out = STDOUT_FILENO;
 
-	while ((arg = getopt(argc, argv, "n:p:u")) != -1) {
+	while ((arg = getopt(argc, argv, "u")) != -1) {
 		switch (arg) {
-		case 'n':
-			namekey = optarg;
-			break;
-		case 'p':
-			passkey = optarg;
-			break;
 		case 'u':
 			in = 6;
 			out = 7;
@@ -89,13 +83,10 @@ main(int argc, char **argv)
 	}
 	if (con.state == IS_AUTH) {
 		goto select;
-	} else if (!(namekey && passkey)) {
-		warnx("authentication credentials are needed");
-		goto logout;
 	}
 
-	if (!(name = getenv(namekey))) {
-		warnx("cannot find name within environment");
+	if (!(user = getenv(userkey))) {
+		warnx("cannot find user name within environment");
 		goto logout;
 	}
 	if (!(pass = getenv(passkey))) {
@@ -103,7 +94,7 @@ main(int argc, char **argv)
 		goto logout;
 	}
 
-	e = imap_login(&con, name, pass);
+	e = imap_login(&con, user, pass);
 	if (e == TE_NO) {
 		warnx("login credentials rejected");
 		goto logout;