Blob Blame History Raw
From d0c56c2b21e381ddb49c1906ad00d77684c4bc9b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dan=20Hor=C3=A1k?= <dan@danny.cz>
Date: Tue, 18 May 2010 11:32:22 +0200
Subject: [PATCH 1/3] add -h command line option
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The recent code treats -h as unknown options and throws an error.

Signed-off-by: Dan Horák <dan@danny.cz>
---
 man/man1/pkcsconf.1.in           |    4 +++-
 usr/sbin/pkcsconf/pkcsconf.c     |    8 ++++++--
 usr/sbin/pkcsconf/pkcsconf.msg   |    3 ++-
 usr/sbin/pkcsconf/pkcsconf_msg.h |    1 +
 4 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/man/man1/pkcsconf.1.in b/man/man1/pkcsconf.1.in
index a620882..6f5540a 100644
--- a/man/man1/pkcsconf.1.in
+++ b/man/man1/pkcsconf.1.in
@@ -4,7 +4,7 @@ pkcsconf
 
 .SH SYNOPSIS
 \fBpkcsconf\fP
-[\fB-itsmMIupP\fP]
+[\fB-itsmMIupPh\fP]
 [\fB-c\fP \fIslotnumber\fP \fB-U\fP \fIuserPIN\fP
 \fB-S\fP \fISOPin\fP \fB-n\fP \fInewpin\fP]
 
@@ -40,6 +40,8 @@ the current Security Officer (SO) pin (for use when changing the SO pin;
 .IP "\fB-n\fP \fINEWPIN\fP" 10
 the new pin (for use when changing either the user pin or the SO pin; -u, -p
 and -P options); if not specified, user will be prompted
+.IP "\fB-h\fP" 10
+show usage information
 
 .SH SEE ALSO
 .PD 0
diff --git a/usr/sbin/pkcsconf/pkcsconf.c b/usr/sbin/pkcsconf/pkcsconf.c
index 30a143a..768f1ec 100755
--- a/usr/sbin/pkcsconf/pkcsconf.c
+++ b/usr/sbin/pkcsconf/pkcsconf.c
@@ -375,7 +375,7 @@ main(int argc, char *argv[]){
    catd = catopen(MF_PKCSCONF,0);
 
    /* Parse the command line parameters */
-   while ((c = getopt (argc, argv, "itsmMIc:S:U:upPn:l")) != (-1)){
+   while ((c = getopt (argc, argv, "itsmMIc:S:U:upPn:lh")) != (-1)){
       switch (c){
          case 'c':  /* a specific card (slot) is specified */
             flags |= CFG_SLOT;
@@ -429,6 +429,9 @@ main(int argc, char *argv[]){
          case 'l':  /* display slot description */
             flags |= CFG_LIST_SLOT;
             break;
+         case 'h':  /* display command line options */
+	    usage(argv[0]);
+            break;
          default:   /* if something else was passed in it is an error */
             errflag++;
             break;
@@ -1295,7 +1298,7 @@ usage(char *progname){
 
    /* If we get here the user needs help, so give it to them */
    printf(PKCSINIT_MSG(USAGE,
-           "usage:\t%s [-itsmMIupP] [-c slotnumber -U userPIN -S SOPin -n newpin]\n"),
+           "usage:\t%s [-itsmMIupPh] [-c slotnumber -U userPIN -S SOPin -n newpin]\n"),
            progname);
    printf(PKCSINIT_MSG(USAGE1, "\t-i display PKCS11 info\n"));
    printf(PKCSINIT_MSG(USAGE2, "\t-t display token info\n"));
@@ -1305,6 +1308,7 @@ usage(char *progname){
    printf(PKCSINIT_MSG(USAGE7, "\t-u initialize user PIN\n"));
    printf(PKCSINIT_MSG(USAGE8, "\t-p set the user PIN\n"));
    printf(PKCSINIT_MSG(USAGE9, "\t-P set the SO PIN\n"));
+   printf(PKCSINIT_MSG(USAGE10, "\t-h show this help\n"));
 
    exit(-1);
 }
diff --git a/usr/sbin/pkcsconf/pkcsconf.msg b/usr/sbin/pkcsconf/pkcsconf.msg
index 4b5fdf9..bce440b 100755
--- a/usr/sbin/pkcsconf/pkcsconf.msg
+++ b/usr/sbin/pkcsconf/pkcsconf.msg
@@ -373,7 +373,7 @@ LIBERROR	"Error initializing the PKCS11 library: 0x%X\n"
 SLOTMGRERROR	"Error communicating with slot manager: 0x%X\n"
 INVALIDCARD	"Invalid card: %s\n"
 
-USAGE		"usage:\t%s [-iImMpPstu] [-c slotnumber -U userPIN -S SOPin -n newPIN]\n"
+USAGE		"usage:\t%s [-iImMpPstuh] [-c slotnumber -U userPIN -S SOPin -n newPIN]\n"
 USAGE1		"\t-i display PKCS11 info\n"
 USAGE2		"\t-t display token info\n"
 USAGE3		"\t-s display slot info\n"
@@ -383,3 +383,4 @@ USAGE6		"\t-I initialize token\n"
 USAGE7		"\t-u initialize user PIN\n"
 USAGE8		"\t-p set the user PIN\n"
 USAGE9		"\t-P set the SO PIN\n"
+USAGE10		"\t-h show this help\n"
diff --git a/usr/sbin/pkcsconf/pkcsconf_msg.h b/usr/sbin/pkcsconf/pkcsconf_msg.h
index 1ca9c04..f500dbc 100755
--- a/usr/sbin/pkcsconf/pkcsconf_msg.h
+++ b/usr/sbin/pkcsconf/pkcsconf_msg.h
@@ -378,4 +378,5 @@
 #define USAGE7 68
 #define USAGE8 69
 #define USAGE9 70
+#define USAGE10 71
 #endif 
-- 
1.6.6.1

From 248606bef048d70f8fe366b846c6296ba6d92720 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dan=20Hor=C3=A1k?= <dan@danny.cz>
Date: Tue, 18 May 2010 11:32:23 +0200
Subject: [PATCH 2/3] print usage information when no option is given
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

When no option is given pkcsconf does nothing and quits silently with a zero
return code. It should output the usage information and return non-zero code.

Signed-off-by: Dan Horák <dan@danny.cz>
---
 usr/sbin/pkcsconf/pkcsconf.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/usr/sbin/pkcsconf/pkcsconf.c b/usr/sbin/pkcsconf/pkcsconf.c
index 768f1ec..bb12a90 100755
--- a/usr/sbin/pkcsconf/pkcsconf.c
+++ b/usr/sbin/pkcsconf/pkcsconf.c
@@ -440,6 +440,9 @@ main(int argc, char *argv[]){
    if (errflag != 0)  /* If there was an error print the usage statement */
        usage(argv[0]);
 
+   if (!flags)  /* If there was no options print the usage statement */
+       usage(argv[0]);
+
    /* Eliminate the ability to specify -I -p -u -P without a slot number */
    if ( (flags & (CFG_INITIALIZE | CFG_INIT_USER | CFG_SET_USER | CFG_SET_SO))
             && !(flags & CFG_SLOT)){
-- 
1.6.6.1

From 9afec58b81c13ecec417e976721e2a22e8355978 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dan=20Hor=C3=A1k?= <dan@danny.cz>
Date: Thu, 20 May 2010 14:17:23 +0200
Subject: [PATCH 3/3] don't show the -M option

Recent builds are done with SHM undefined, so displaying the -M option that
depends on SHM, doesn't make sense.
---
 usr/sbin/pkcsconf/pkcsconf.c   |    4 ++--
 usr/sbin/pkcsconf/pkcsconf.msg |    2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/usr/sbin/pkcsconf/pkcsconf.c b/usr/sbin/pkcsconf/pkcsconf.c
index bb12a90..0cf99d2 100755
--- a/usr/sbin/pkcsconf/pkcsconf.c
+++ b/usr/sbin/pkcsconf/pkcsconf.c
@@ -375,7 +375,7 @@ main(int argc, char *argv[]){
    catd = catopen(MF_PKCSCONF,0);
 
    /* Parse the command line parameters */
-   while ((c = getopt (argc, argv, "itsmMIc:S:U:upPn:lh")) != (-1)){
+   while ((c = getopt (argc, argv, "itsmIc:S:U:upPn:lh")) != (-1)){
       switch (c){
          case 'c':  /* a specific card (slot) is specified */
             flags |= CFG_SLOT;
@@ -1301,7 +1301,7 @@ usage(char *progname){
 
    /* If we get here the user needs help, so give it to them */
    printf(PKCSINIT_MSG(USAGE,
-           "usage:\t%s [-itsmMIupPh] [-c slotnumber -U userPIN -S SOPin -n newpin]\n"),
+           "usage:\t%s [-itsmIupPh] [-c slotnumber -U userPIN -S SOPin -n newpin]\n"),
            progname);
    printf(PKCSINIT_MSG(USAGE1, "\t-i display PKCS11 info\n"));
    printf(PKCSINIT_MSG(USAGE2, "\t-t display token info\n"));
diff --git a/usr/sbin/pkcsconf/pkcsconf.msg b/usr/sbin/pkcsconf/pkcsconf.msg
index bce440b..0d3ed34 100755
--- a/usr/sbin/pkcsconf/pkcsconf.msg
+++ b/usr/sbin/pkcsconf/pkcsconf.msg
@@ -373,7 +373,7 @@ LIBERROR	"Error initializing the PKCS11 library: 0x%X\n"
 SLOTMGRERROR	"Error communicating with slot manager: 0x%X\n"
 INVALIDCARD	"Invalid card: %s\n"
 
-USAGE		"usage:\t%s [-iImMpPstuh] [-c slotnumber -U userPIN -S SOPin -n newPIN]\n"
+USAGE		"usage:\t%s [-iImpPstuh] [-c slotnumber -U userPIN -S SOPin -n newPIN]\n"
 USAGE1		"\t-i display PKCS11 info\n"
 USAGE2		"\t-t display token info\n"
 USAGE3		"\t-s display slot info\n"
-- 
1.6.6.1