Make sure getpass() is available
authorTobias Brunner <tobias@strongswan.org>
Thu, 29 May 2014 10:25:21 +0000 (12:25 +0200)
committerTobias Brunner <tobias@strongswan.org>
Thu, 29 May 2014 10:28:53 +0000 (12:28 +0200)
It's not on Android for example.

src/charon-cmd/cmd/cmd_creds.c
src/pki/pki.c
src/swanctl/commands/load_creds.c

index 7fee85d..45d008e 100644 (file)
@@ -72,7 +72,7 @@ static shared_key_t* callback_shared(private_cmd_creds_t *this,
                                                                id_match_t *match_me, id_match_t *match_other)
 {
        shared_key_t *shared;
-       char *label, *pwd;
+       char *label, *pwd = NULL;
 
        if (type == this->prompted)
        {
@@ -95,7 +95,9 @@ static shared_key_t* callback_shared(private_cmd_creds_t *this,
                default:
                        return NULL;
        }
+#ifdef HAVE_GETPASS
        pwd = getpass(label);
+#endif
        if (!pwd || strlen(pwd) == 0)
        {
                return NULL;
index ae4ef1c..8d880f0 100644 (file)
@@ -165,7 +165,7 @@ static shared_key_t* cb(void *data, shared_key_type_t type,
                                                identification_t *me, identification_t *other,
                                                id_match_t *match_me, id_match_t *match_other)
 {
-       char buf[64], *label, *secret;
+       char buf[64], *label, *secret = NULL;
 
        switch (type)
        {
@@ -179,7 +179,9 @@ static shared_key_t* cb(void *data, shared_key_type_t type,
                        return NULL;
        }
        snprintf(buf, sizeof(buf), "%s: ", label);
+#ifdef HAVE_GETPASS
        secret = getpass(buf);
+#endif
        if (secret)
        {
                if (match_me)
index 94d31f4..ee792ad 100644 (file)
@@ -144,13 +144,15 @@ CALLBACK(password_cb, shared_key_t*,
        identification_t *me, identification_t *other,
        id_match_t *match_me, id_match_t *match_other)
 {
-       char *pwd;
+       char *pwd = NULL;
 
        if (type != SHARED_PRIVATE_KEY_PASS)
        {
                return NULL;
        }
+#ifdef HAVE_GETPASS
        pwd = getpass(prompt);
+#endif
        if (!pwd || strlen(pwd) == 0)
        {
                return NULL;