[pkg-opensc-commit] [libp11] 202/239: examples: auth: allow PIN from command line
Eric Dorland
eric at moszumanska.debian.org
Sat Oct 17 06:21:34 UTC 2015
This is an automated email from the git hooks/post-receive script.
eric pushed a commit to branch master
in repository libp11.
commit 61de9ceeace6732ed5b65f451ad3d4d1e4dce7d1
Author: Nikos Mavrogiannopoulos <nmav at redhat.com>
Date: Thu Jul 2 11:02:42 2015 +0200
examples: auth: allow PIN from command line
---
examples/auth.c | 54 +++++++++++++++++++++++++++++-------------------------
1 file changed, 29 insertions(+), 25 deletions(-)
diff --git a/examples/auth.c b/examples/auth.c
index 98ff161..f433aba 100644
--- a/examples/auth.c
+++ b/examples/auth.c
@@ -36,8 +36,8 @@ int main(int argc, char *argv[])
int rc = 0, fd;
unsigned int nslots, ncerts, siglen;
- if (argc != 2) {
- fprintf(stderr, "usage: auth /usr/lib/opensc-pkcs11.so\n");
+ if (argc < 2) {
+ fprintf(stderr, "usage: auth /usr/lib/opensc-pkcs11.so [PIN]\n");
return 1;
}
@@ -92,29 +92,33 @@ int main(int argc, char *argv[])
goto loggedin;
/* get password */
- struct termios old, new;
-
- /* Turn echoing off and fail if we can't. */
- if (tcgetattr(0, &old) != 0)
- goto failed;
-
- new = old;
- new.c_lflag &= ~ECHO;
- if (tcsetattr(0, TCSAFLUSH, &new) != 0)
- goto failed;
-
- /* Read the password. */
- printf("Password for token %.32s: ", slot->token->label);
- fgets(password, sizeof(password), stdin);
-
- /* Restore terminal. */
- (void)tcsetattr(0, TCSAFLUSH, &old);
-
- /* strip tailing \n from password */
- rc = strlen(password);
- if (rc <= 0)
- goto failed;
- password[rc-1]=0;
+ if (argc > 2) {
+ strcpy(password, argv[2]);
+ } else {
+ struct termios old, new;
+
+ /* Turn echoing off and fail if we can't. */
+ if (tcgetattr(0, &old) != 0)
+ goto failed;
+
+ new = old;
+ new.c_lflag &= ~ECHO;
+ if (tcsetattr(0, TCSAFLUSH, &new) != 0)
+ goto failed;
+
+ /* Read the password. */
+ printf("Password for token %.32s: ", slot->token->label);
+ fgets(password, sizeof(password), stdin);
+
+ /* Restore terminal. */
+ (void)tcsetattr(0, TCSAFLUSH, &old);
+
+ /* strip tailing \n from password */
+ rc = strlen(password);
+ if (rc <= 0)
+ goto failed;
+ password[rc-1]=0;
+ }
/* perform pkcs #11 login */
rc = PKCS11_login(slot, 0, password);
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-opensc/libp11.git
More information about the pkg-opensc-commit
mailing list