Rework copyright notices

While at it, rename mystrtonum.[ch] to strtonum.[ch].
This commit is contained in:
Lucas 2021-02-11 21:02:02 +00:00
parent 33cc12f030
commit 0b93ea8653
7 changed files with 48 additions and 63 deletions

View File

@ -1,6 +1,6 @@
# otpcli - command-line interface for HOTP and TOTP # 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 # To the extent possible under law, the author(s) have dedicated all
# copyright and related and neighboring rights to this software to the # copyright and related and neighboring rights to this software to the
@ -17,18 +17,16 @@
P = otpcli P = otpcli
V = 0.0 V = 0.0
HDR = err.h mystrtonum.h otp.h HDR = err.h strtonum.h otp.h
OBJ = cli.o err.o mystrtonum.o otp.o OBJ = cli.o ${HDR:.h=.o}
SRC = ${OBJ:.o=.c} SRC = ${OBJ:.o=.c}
DIST_FILES = COPYING Makefile ${HDR} ${SRC}
LIBS = -lcrypto
DIST = COPYING Makefile ${HDR} ${SRC}
all: otpcli all: otpcli
${OBJ}: ${HDR}
otpcli: ${OBJ}
${CC} ${LDFLAGS} -o $@ ${OBJ} -lcrypto
clean: clean:
rm -f otpcli ${OBJ} ${P}-${V}.tgz rm -f otpcli ${OBJ} ${P}-${V}.tgz
@ -36,12 +34,16 @@ test: all run-tests.sh
sh ./run-tests.sh sh ./run-tests.sh
dist: clean 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 install: all
mkdir -p ${PREFIX}/bin mkdir -p ${PREFIX}/bin
cp -f ${BIN} ${PREFIX}/bin cp -f ${BIN} ${PREFIX}/bin
cd ${PREFIX}/bin && chmod 555 ${BIN}
uninstall: uninstall:
cd ${PREFIX}/bin && rm -f ${BIN} cd ${PREFIX}/bin && rm -f ${BIN}
${OBJ}: ${HDR}
otpcli: ${OBJ}
${CC} ${LDFLAGS} -o $@ ${OBJ} ${LIBS}

12
cli.c
View File

@ -1,7 +1,7 @@
/* /*
* otpcli - CLI utility for generating OTPs * 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 * To the extent possible under law, the author(s) have dedicated all
* copyright and related and neighboring rights to this software to the * copyright and related and neighboring rights to this software to the
@ -23,7 +23,7 @@
#include <unistd.h> #include <unistd.h>
#include "err.h" #include "err.h"
#include "mystrtonum.h" #include "strtonum.h"
#include "otp.h" #include "otp.h"
#define LINE_SIZE 16384 #define LINE_SIZE 16384
@ -60,12 +60,12 @@ main(int argc, char *argv[])
while ((ch = getopt(argc, argv, "d:H:h:s:T:")) != -1) { while ((ch = getopt(argc, argv, "d:H:h:s:T:")) != -1) {
switch (ch) { switch (ch) {
case 'd': case 'd':
digits = mystrtonum(optarg, 6, 10, &errstr); digits = strtonum(optarg, 6, 10, &errstr);
if (errstr != NULL) if (errstr != NULL)
errx(1, "digits is %s: %s", errstr, optarg); errx(1, "digits is %s: %s", errstr, optarg);
break; break;
case 'H': case 'H':
counter = mystrtonum(optarg, 0, LLONG_MAX, &errstr); counter = strtonum(optarg, 0, LLONG_MAX, &errstr);
if (errstr != NULL) if (errstr != NULL)
errx(1, "counter is %s: %s", errstr, optarg); errx(1, "counter is %s: %s", errstr, optarg);
do_hotp = 1; do_hotp = 1;
@ -81,12 +81,12 @@ main(int argc, char *argv[])
usage(); usage();
break; break;
case 's': case 's':
step = mystrtonum(optarg, 1, UINT_MAX, &errstr); step = strtonum(optarg, 1, UINT_MAX, &errstr);
if (errstr != NULL) if (errstr != NULL)
errx(1, "step is %s: %s", errstr, optarg); errx(1, "step is %s: %s", errstr, optarg);
break; break;
case 'T': case 'T':
counter = mystrtonum(optarg, 0, LLONG_MAX, &errstr); counter = strtonum(optarg, 0, LLONG_MAX, &errstr);
if (errstr != NULL) if (errstr != NULL)
errx(1, "counter is %s: %s", errstr, optarg); errx(1, "counter is %s: %s", errstr, optarg);
do_totp = 1; do_totp = 1;

37
err.c
View File

@ -1,16 +1,31 @@
/* /* $OpenBSD: verr.c,v 1.11 2016/03/13 18:34:20 guenther Exp $ */
* libutil - C utility functions /*-
* 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 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* copyright and related and neighboring rights to this software to the * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* public domain worldwide. This software is distributed without any * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* warranty. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* You should have received a copy of the CC0 Public Domain Dedication * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* along with this software. If not, see * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* <http://creativecommons.org/publicdomain/zero/1.0/>. * 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 * Inspired by OpenBSD's `err.h' header, found at

15
err.h
View File

@ -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
* <http://creativecommons.org/publicdomain/zero/1.0/>.
*/
void err(int, const char *, ...); void err(int, const char *, ...);
void errx(int, const char *, ...); void errx(int, const char *, ...);
void warn(const char *, ...); void warn(const char *, ...);

View File

@ -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
* <http://creativecommons.org/publicdomain/zero/1.0/>.
*/
long long mystrtonum(const char *, long long, long long, const char **);

View File

@ -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 $ */ /* $OpenBSD: strtonum.c,v 1.8 2015/09/13 08:31:48 guenther Exp $ */
/* /*
@ -28,7 +26,7 @@
#define TOOLARGE 3 #define TOOLARGE 3
long long 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) const char **errstrp)
{ {
long long ll = 0; long long ll = 0;

1
strtonum.h Normal file
View File

@ -0,0 +1 @@
long long mystrtonum(const char *, long long, long long, const char **);