Forbid command line parameters when parsing configuration files

This behaviour was ambiguous at best.
While there, also correct the usage screen, and the corresponding manual
page.
This commit is contained in:
khorben 2020-03-22 07:45:02 +00:00
parent 3f8590da2c
commit 9e6960f916
2 changed files with 15 additions and 16 deletions

View File

@ -1,4 +1,4 @@
.\" $NetBSD: umbctl.8,v 1.2 2018/08/01 17:26:30 wiz Exp $
.\" $NetBSD: umbctl.8,v 1.3 2020/03/22 07:45:02 khorben Exp $
.\"
.\" Copyright (c) 2018 by Pierre Pronchery <khorben@defora.org>
.\" All rights reserved.
@ -26,11 +26,11 @@
.\"
.\" From: pppoectl.8,v 1.30 2016/09/12 05:35:20 sevan Exp $
.\"
.\" $Id: umbctl.8,v 1.2 2018/08/01 17:26:30 wiz Exp $
.\" $Id: umbctl.8,v 1.3 2020/03/22 07:45:02 khorben Exp $
.\"
.\" last edit-date: [Thu Aug 31 10:47:33 2000]
.\"
.Dd July 24, 2018
.Dd March 22, 2020
.Dt UMBCTL 8
.Os
.Sh NAME
@ -40,15 +40,13 @@
.Nm umbctl
.Op Fl v
.Ar ifname
.Op Ar parameter Ns Op \&= Ns Ar value
.Op Ar parameter Op Ar value
.Op Ar ...
.Pp
.Nm umbctl
.Op Fl v
.Op Fl f Ar config-file
.Fl f Ar config-file
.Ar ifname
.Op Ar parameter Ns Op \&= Ns Ar value
.Op Ar ...
.Sh DESCRIPTION
.Nm
supports the following options:

View File

@ -1,4 +1,4 @@
/* $NetBSD: umbctl.c,v 1.2 2018/08/02 03:40:51 roy Exp $ */
/* $NetBSD: umbctl.c,v 1.3 2020/03/22 07:45:02 khorben Exp $ */
/*
* Copyright (c) 2018 Pierre Pronchery <khorben@defora.org>
*
@ -80,8 +80,8 @@ static const struct umb_valdescr _umb_ber[] =
static int _char_to_utf16(const char * in, uint16_t * out, size_t outlen);
static int _error(int ret, char const * format, ...);
static int _umbctl(char const * ifname, int verbose, int argc, char * argv[]);
static int _umbctl_file(char const * ifname, char const * filename, int verbose,
int argc, char * argv[]);
static int _umbctl_file(char const * ifname, char const * filename,
int verbose);
static void _umbctl_info(char const * ifname, struct umb_info * umbi);
static int _umbctl_ioctl(char const * ifname, int fd, unsigned long request,
struct ifreq * ifr);
@ -177,8 +177,7 @@ static int _umbctl(char const * ifname, int verbose, int argc, char * argv[])
/* umbctl_file */
static int _umbctl_file(char const * ifname, char const * filename, int verbose,
int argc, char * argv[])
static int _umbctl_file(char const * ifname, char const * filename, int verbose)
{
int fd;
struct ifreq ifr;
@ -216,7 +215,6 @@ static int _umbctl_file(char const * ifname, char const * filename, int verbose,
strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
ifr.ifr_data = &umbp;
if(_umbctl_ioctl(ifname, fd, SIOCGUMBPARAM, &ifr) != 0
|| _umbctl_set(ifname, &umbp, argc, argv) != 0
|| _umbctl_ioctl(ifname, fd, SIOCSUMBPARAM, &ifr) != 0)
{
close(fd);
@ -427,7 +425,7 @@ static int _umbctl_socket(void)
/* usage */
static int _usage(void)
{
fputs("Usage: umbctl [-v] ifname [parameter[=value]] [...]\n"
fputs("Usage: umbctl [-v] ifname [parameter [value]] [...]\n"
" umbctl -f config-file ifname [...]\n",
stderr);
return 1;
@ -475,8 +473,11 @@ int main(int argc, char * argv[])
if(optind == argc)
return _usage();
if(filename != NULL)
return _umbctl_file(argv[optind], filename, verbose,
argc - optind - 1, &argv[optind + 1]);
{
if(optind + 1 != argc)
return _usage();
return _umbctl_file(argv[optind], filename, verbose);
}
return _umbctl(argv[optind], verbose, argc - optind - 1,
&argv[optind + 1]);
}