From 5a76125050c2f389cdc1c3017dff5fec4aef7e57 Mon Sep 17 00:00:00 2001
From: Panu Matilainen <pmatilai@redhat.com>
Date: Thu, 8 Jun 2017 16:55:16 +0300
Subject: [PATCH] Bury get_fskpass() inside rpmsign utility

librpm is not in the business of providing terminal utility functions,
file signing might well need to ask for passwords but it doesn't
have to be a non-prefixed function in a shared library. The library
provides means to *pass* the password and its up to calling applications
to ask for it if needed.
---
 lib/rpmsignfiles.c | 35 -----------------------------------
 lib/rpmsignfiles.h |  2 --
 rpmsign.c          | 37 ++++++++++++++++++++++++++++++++++++-
 3 files changed, 36 insertions(+), 38 deletions(-)

diff --git a/lib/rpmsignfiles.c b/lib/rpmsignfiles.c
index 87e4e4265..aacb34647 100644
--- a/lib/rpmsignfiles.c
+++ b/lib/rpmsignfiles.c
@@ -7,8 +7,6 @@
 #include "system.h"
 #include "imaevm.h"
 
-#include <termios.h>
-
 #include <rpm/rpmlog.h>		/* rpmlog */
 #include <rpm/rpmstring.h>	/* rnibble */
 #include <rpm/rpmpgp.h>		/* rpmDigestLength */
@@ -34,39 +32,6 @@ static const char *hash_algo_name[] = {
 
 #define ARRAY_SIZE(a)  (sizeof(a) / sizeof(a[0]))
 
-char *get_fskpass(void)
-{
-    struct termios flags, tmp_flags;
-    char *password, *pwd;
-    int passlen = 64;
-
-    password = malloc(passlen);
-    if (!password) {
-	perror("malloc");
-	return NULL;
-    }
-
-    tcgetattr(fileno(stdin), &flags);
-    tmp_flags = flags;
-    tmp_flags.c_lflag &= ~ECHO;
-    tmp_flags.c_lflag |= ECHONL;
-
-    if (tcsetattr(fileno(stdin), TCSANOW, &tmp_flags) != 0) {
-	perror("tcsetattr");
-	return NULL;
-    }
-
-    printf("PEM password: ");
-    pwd = fgets(password, passlen, stdin);
-    pwd[strlen(pwd) - 1] = '\0';  /* remove newline */
-
-    if (tcsetattr(fileno(stdin), TCSANOW, &flags) != 0) {
-	perror("tcsetattr");
-	return NULL;
-    }
-    return pwd;
-}
-
 static char *signFile(const char *algo, const char *fdigest, int diglen,
 const char *key, char *keypass)
 {
diff --git a/lib/rpmsignfiles.h b/lib/rpmsignfiles.h
index 52e2482a9..70ed69412 100644
--- a/lib/rpmsignfiles.h
+++ b/lib/rpmsignfiles.h
@@ -14,8 +14,6 @@ extern "C" {
  */
 rpmRC rpmSignFiles(Header h, const char *key, char *keypass);
 
-char *get_fskpass(void); /* get file signing key password */
-
 #ifdef _cplusplus
 }
 #endif
diff --git a/rpmsign.c b/rpmsign.c
index 66ab8e5eb..6cd63d872 100644
--- a/rpmsign.c
+++ b/rpmsign.c
@@ -1,12 +1,12 @@
 #include "system.h"
 #include <errno.h>
 #include <sys/wait.h>
+#include <termios.h>
 
 #include <popt.h>
 #include <rpm/rpmcli.h>
 #include <rpm/rpmsign.h>
 #include "cliutils.h"
-#include "lib/rpmsignfiles.h"
 #include "debug.h"
 
 #if !defined(__GLIBC__) && !defined(__APPLE__)
@@ -56,6 +56,41 @@ static struct poptOption optionsTable[] = {
     POPT_TABLEEND
 };
 
+#ifdef WITH_IMAEVM
+static char *get_fskpass(void)
+{
+    struct termios flags, tmp_flags;
+    char *password, *pwd;
+    int passlen = 64;
+
+    password = malloc(passlen);
+    if (!password) {
+	perror("malloc");
+	return NULL;
+    }
+
+    tcgetattr(fileno(stdin), &flags);
+    tmp_flags = flags;
+    tmp_flags.c_lflag &= ~ECHO;
+    tmp_flags.c_lflag |= ECHONL;
+
+    if (tcsetattr(fileno(stdin), TCSANOW, &tmp_flags) != 0) {
+	perror("tcsetattr");
+	return NULL;
+    }
+
+    printf("PEM password: ");
+    pwd = fgets(password, passlen, stdin);
+    pwd[strlen(pwd) - 1] = '\0';  /* remove newline */
+
+    if (tcsetattr(fileno(stdin), TCSANOW, &flags) != 0) {
+	perror("tcsetattr");
+	return NULL;
+    }
+    return pwd;
+}
+#endif
+
 /* TODO: permit overriding macro setup on the command line */
 static int doSign(poptContext optCon, struct rpmSignArgs *sargs)
 {
-- 
2.11.0

