diff --git a/Makefile b/Makefile index 86cc255..06a6eb3 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ # otpcli - command-line interface for HOTP and TOTP # -# Written in 2020 by Lucas +# Written in 2020-2021 by Lucas # # To the extent possible under law, the author(s) have dedicated all # copyright and related and neighboring rights to this software to the @@ -17,18 +17,16 @@ P = otpcli V = 0.0 -HDR = err.h mystrtonum.h otp.h -OBJ = cli.o err.o mystrtonum.o otp.o -SRC = ${OBJ:.o=.c} -DIST_FILES = COPYING Makefile ${HDR} ${SRC} +HDR = err.h strtonum.h otp.h +OBJ = cli.o ${HDR:.h=.o} +SRC = ${OBJ:.o=.c} + +LIBS = -lcrypto + +DIST = COPYING Makefile ${HDR} ${SRC} all: otpcli -${OBJ}: ${HDR} - -otpcli: ${OBJ} - ${CC} ${LDFLAGS} -o $@ ${OBJ} -lcrypto - clean: rm -f otpcli ${OBJ} ${P}-${V}.tgz @@ -36,12 +34,16 @@ test: all run-tests.sh sh ./run-tests.sh dist: clean - pax -w -s '#^#${P}-${V}/#' ${DIST_FILES} | gzip >${P}-${V}.tgz + pax -w -s ',^,$P-$V/,' ${DIST} | gzip >$P-$V.tgz install: all mkdir -p ${PREFIX}/bin cp -f ${BIN} ${PREFIX}/bin - cd ${PREFIX}/bin && chmod 555 ${BIN} uninstall: cd ${PREFIX}/bin && rm -f ${BIN} + +${OBJ}: ${HDR} + +otpcli: ${OBJ} + ${CC} ${LDFLAGS} -o $@ ${OBJ} ${LIBS} diff --git a/cli.c b/cli.c index 3be0610..4139bc3 100644 --- a/cli.c +++ b/cli.c @@ -1,7 +1,7 @@ /* * otpcli - CLI utility for generating OTPs * - * Written in 2020 by Lucas + * Written in 2020-2021 by Lucas * * To the extent possible under law, the author(s) have dedicated all * copyright and related and neighboring rights to this software to the @@ -23,7 +23,7 @@ #include #include "err.h" -#include "mystrtonum.h" +#include "strtonum.h" #include "otp.h" #define LINE_SIZE 16384 @@ -60,12 +60,12 @@ main(int argc, char *argv[]) while ((ch = getopt(argc, argv, "d:H:h:s:T:")) != -1) { switch (ch) { case 'd': - digits = mystrtonum(optarg, 6, 10, &errstr); + digits = strtonum(optarg, 6, 10, &errstr); if (errstr != NULL) errx(1, "digits is %s: %s", errstr, optarg); break; case 'H': - counter = mystrtonum(optarg, 0, LLONG_MAX, &errstr); + counter = strtonum(optarg, 0, LLONG_MAX, &errstr); if (errstr != NULL) errx(1, "counter is %s: %s", errstr, optarg); do_hotp = 1; @@ -81,12 +81,12 @@ main(int argc, char *argv[]) usage(); break; case 's': - step = mystrtonum(optarg, 1, UINT_MAX, &errstr); + step = strtonum(optarg, 1, UINT_MAX, &errstr); if (errstr != NULL) errx(1, "step is %s: %s", errstr, optarg); break; case 'T': - counter = mystrtonum(optarg, 0, LLONG_MAX, &errstr); + counter = strtonum(optarg, 0, LLONG_MAX, &errstr); if (errstr != NULL) errx(1, "counter is %s: %s", errstr, optarg); do_totp = 1; diff --git a/err.c b/err.c index 172be6a..a3187e8 100644 --- a/err.c +++ b/err.c @@ -1,16 +1,31 @@ -/* - * libutil - C utility functions +/* $OpenBSD: verr.c,v 1.11 2016/03/13 18:34:20 guenther Exp $ */ +/*- + * Copyright (c) 1993 + * The Regents of the University of California. All rights reserved. * - * Written in 2020 by Lucas + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. * - * To the extent possible under law, the author(s) have dedicated all - * copyright and related and neighboring rights to this software to the - * public domain worldwide. This software is distributed without any - * warranty. - * - * You should have received a copy of the CC0 Public Domain Dedication - * along with this software. If not, see - * . + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. */ /* * Inspired by OpenBSD's `err.h' header, found at diff --git a/err.h b/err.h index 15b3675..3b8431a 100644 --- a/err.h +++ b/err.h @@ -1,18 +1,3 @@ -/* - * libutil - C utility functions - * - * Written in 2020 by Lucas - * - * To the extent possible under law, the author(s) have dedicated all - * copyright and related and neighboring rights to this software to the - * public domain worldwide. This software is distributed without any - * warranty. - * - * You should have received a copy of the CC0 Public Domain Dedication - * along with this software. If not, see - * . - */ - void err(int, const char *, ...); void errx(int, const char *, ...); void warn(const char *, ...); diff --git a/mystrtonum.h b/mystrtonum.h deleted file mode 100644 index 742100e..0000000 --- a/mystrtonum.h +++ /dev/null @@ -1,16 +0,0 @@ -/* - * libutil - C utility functions - * - * Written in 2020 by Lucas - * - * To the extent possible under law, the author(s) have dedicated all - * copyright and related and neighboring rights to this software to the - * public domain worldwide. This software is distributed without any - * warranty. - * - * You should have received a copy of the CC0 Public Domain Dedication - * along with this software. If not, see - * . - */ - -long long mystrtonum(const char *, long long, long long, const char **); diff --git a/mystrtonum.c b/strtonum.c similarity index 93% rename from mystrtonum.c rename to strtonum.c index 3ad8e34..fdfc72a 100644 --- a/mystrtonum.c +++ b/strtonum.c @@ -1,5 +1,3 @@ -/* This is OpenBSD's strtonum(3), renamed to mystrtonum */ - /* $OpenBSD: strtonum.c,v 1.8 2015/09/13 08:31:48 guenther Exp $ */ /* @@ -28,7 +26,7 @@ #define TOOLARGE 3 long long -mystrtonum(const char *numstr, long long minval, long long maxval, +strtonum(const char *numstr, long long minval, long long maxval, const char **errstrp) { long long ll = 0; diff --git a/strtonum.h b/strtonum.h new file mode 100644 index 0000000..22c195d --- /dev/null +++ b/strtonum.h @@ -0,0 +1 @@ +long long mystrtonum(const char *, long long, long long, const char **);