=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/signify/signify.c,v retrieving revision 1.30 retrieving revision 1.31 diff -c -r1.30 -r1.31 *** src/usr.bin/signify/signify.c 2014/01/12 21:18:52 1.30 --- src/usr.bin/signify/signify.c 2014/01/13 01:40:43 1.31 *************** *** 1,4 **** ! /* $OpenBSD: signify.c,v 1.30 2014/01/12 21:18:52 tedu Exp $ */ /* * Copyright (c) 2013 Ted Unangst * --- 1,4 ---- ! /* $OpenBSD: signify.c,v 1.31 2014/01/13 01:40:43 tedu Exp $ */ /* * Copyright (c) 2013 Ted Unangst * *************** *** 68,82 **** extern char *__progname; static void ! usage(void) { fprintf(stderr, "usage:" #ifndef VERIFYONLY ! "\t%1$s -G [-c comment] [-n] -p pubkey -s seckey\n" ! "\t%1$s -I [-o sigfile] [-p pubkey] [-s seckey]\n" ! "\t%1$s -S [-e] [-o sigfile] -s seckey message\n" #endif ! "\t%1$s -V [-e] [-o sigfile] -p pubkey message\n", __progname); exit(1); } --- 68,84 ---- extern char *__progname; static void ! usage(const char *error) { + if (error) + fprintf(stderr, "%s\n", error); fprintf(stderr, "usage:" #ifndef VERIFYONLY ! "\t%1$s -G [-n] [-c comment] -p pubkey -s seckey\n" ! "\t%1$s -I [-p pubkey] [-s seckey] [-x sigfile]\n" ! "\t%1$s -S [-e] [-x sigfile] -s seckey -m message\n" #endif ! "\t%1$s -V [-e] [-x sigfile] -p pubkey -m message\n", __progname); exit(1); } *************** *** 86,94 **** { int fd; ! fd = open(fname, flags, mode); ! if (fd == -1) ! err(1, "open %s", fname); return fd; } --- 88,106 ---- { int fd; ! if (strcmp(fname, "-") == 0) { ! if ((flags & O_WRONLY)) ! fd = dup(STDOUT_FILENO); ! else ! fd = dup(STDIN_FILENO); ! if (fd == -1) ! err(1, "dup failed"); ! } else { ! fd = open(fname, flags, mode); ! if (fd == -1) ! err(1, "can't open %s for %s", fname, ! (flags & O_WRONLY) ? "writing" : "reading"); ! } return fd; } *************** *** 216,223 **** int fd, rv; fd = xopen(filename, O_CREAT|flags|O_NOFOLLOW|O_WRONLY, mode); ! snprintf(header, sizeof(header), "%s%s\n", COMMENTHDR, ! comment); writeall(fd, header, strlen(header), filename); if ((rv = b64_ntop(buf, len, b64, sizeof(b64)-1)) == -1) errx(1, "b64 encode failed"); --- 228,234 ---- int fd, rv; fd = xopen(filename, O_CREAT|flags|O_NOFOLLOW|O_WRONLY, mode); ! snprintf(header, sizeof(header), "%s%s\n", COMMENTHDR, comment); writeall(fd, header, strlen(header), filename); if ((rv = b64_ntop(buf, len, b64, sizeof(b64)-1)) == -1) errx(1, "b64 encode failed"); *************** *** 451,478 **** rounds = 42; ! while ((ch = getopt(argc, argv, "GISVc:eno:p:s:")) != -1) { switch (ch) { #ifndef VERIFYONLY case 'G': if (verb) ! usage(); verb = GENERATE; break; case 'I': if (verb) ! usage(); verb = INSPECT; break; case 'S': if (verb) ! usage(); verb = SIGN; break; #endif case 'V': if (verb) ! usage(); verb = VERIFY; break; case 'c': --- 462,489 ---- rounds = 42; ! while ((ch = getopt(argc, argv, "GISVc:em:n:p:s:x:")) != -1) { switch (ch) { #ifndef VERIFYONLY case 'G': if (verb) ! usage(NULL); verb = GENERATE; break; case 'I': if (verb) ! usage(NULL); verb = INSPECT; break; case 'S': if (verb) ! usage(NULL); verb = SIGN; break; #endif case 'V': if (verb) ! usage(NULL); verb = VERIFY; break; case 'c': *************** *** 481,531 **** case 'e': embedded = 1; break; case 'n': rounds = 0; break; - case 'o': - sigfile = optarg; - break; case 'p': pubkeyfile = optarg; break; case 's': seckeyfile = optarg; break; default: ! usage(); break; } } argc -= optind; argv += optind; ! #ifdef VERIFYONLY ! if (verb != VERIFY) ! #else if (verb == NONE) ! #endif ! usage(); #ifndef VERIFYONLY if (verb == GENERATE) { ! if (!pubkeyfile || !seckeyfile || argc != 0) ! usage(); generate(pubkeyfile, seckeyfile, rounds, comment); } else if (verb == INSPECT) { - if (argc != 0) - usage(); inspect(seckeyfile, pubkeyfile, sigfile); } else #endif { ! if (argc != 1) ! usage(); - msgfile = argv[0]; - if (!sigfile) { if (snprintf(sigfilebuf, sizeof(sigfilebuf), "%s.sig", msgfile) >= sizeof(sigfilebuf)) errx(1, "path too long"); --- 492,542 ---- case 'e': embedded = 1; break; + case 'm': + msgfile = optarg; + break; case 'n': rounds = 0; break; case 'p': pubkeyfile = optarg; break; case 's': seckeyfile = optarg; break; + case 'x': + sigfile = optarg; + break; default: ! usage(NULL); break; } } argc -= optind; argv += optind; ! if (argc != 0) ! usage(NULL); ! if (verb == NONE) ! usage(NULL); #ifndef VERIFYONLY if (verb == GENERATE) { ! if (!pubkeyfile || !seckeyfile) ! usage("need pubkey and seckey"); generate(pubkeyfile, seckeyfile, rounds, comment); } else if (verb == INSPECT) { inspect(seckeyfile, pubkeyfile, sigfile); } else #endif { ! if (!msgfile) ! usage("need message"); if (!sigfile) { + if (strcmp(msgfile, "-") == 0) + errx(1, "must specify sigfile with - message"); if (snprintf(sigfilebuf, sizeof(sigfilebuf), "%s.sig", msgfile) >= sizeof(sigfilebuf)) errx(1, "path too long"); *************** *** 534,546 **** #ifndef VERIFYONLY if (verb == SIGN) { if (!seckeyfile) ! usage(); sign(seckeyfile, msgfile, sigfile, embedded); } else #endif if (verb == VERIFY) { if (!pubkeyfile) ! usage(); verify(pubkeyfile, msgfile, sigfile, embedded); } } --- 545,557 ---- #ifndef VERIFYONLY if (verb == SIGN) { if (!seckeyfile) ! usage("need seckey"); sign(seckeyfile, msgfile, sigfile, embedded); } else #endif if (verb == VERIFY) { if (!pubkeyfile) ! usage("need pubkey"); verify(pubkeyfile, msgfile, sigfile, embedded); } }