Report usage() if getopt() returns '?'

Partial fix for bin/21146
This commit is contained in:
dsl 2003-04-14 09:49:15 +00:00
parent 3c88fe4c61
commit 238b338f74
1 changed files with 18 additions and 2 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: user.c,v 1.67 2003/03/14 16:56:39 jrf Exp $ */
/* $NetBSD: user.c,v 1.68 2003/04/14 09:49:15 dsl Exp $ */
/*
* Copyright (c) 1999 Alistair G. Crooks. All rights reserved.
@ -35,7 +35,7 @@
#ifndef lint
__COPYRIGHT("@(#) Copyright (c) 1999 \
The NetBSD Foundation, Inc. All rights reserved.");
__RCSID("$NetBSD: user.c,v 1.67 2003/03/14 16:56:39 jrf Exp $");
__RCSID("$NetBSD: user.c,v 1.68 2003/04/14 09:49:15 dsl Exp $");
#endif
#include <sys/types.h>
@ -1558,6 +1558,8 @@ useradd(int argc, char **argv)
defaultfield = bigD = 0;
while ((c = getopt(argc, argv, "DG:b:c:d:e:f:g:k:mou:s:" ADD_OPT_EXTENSIONS)) != -1) {
switch(c) {
default:
usermgmt_usage("useradd");
case 'D':
bigD = 1;
break;
@ -1689,6 +1691,8 @@ usermod(int argc, char **argv)
have_new_user = 0;
while ((c = getopt(argc, argv, "G:c:d:e:f:g:l:mos:u:" MOD_OPT_EXTENSIONS)) != -1) {
switch(c) {
default:
usermgmt_usage("usermod");
case 'G':
while ((u.u_groupv[u.u_groupc] = strsep(&optarg, ",")) != NULL &&
u.u_groupc < NGROUPS_MAX) {
@ -1799,6 +1803,8 @@ userdel(int argc, char **argv)
defaultfield = bigD = rmhome = 0;
while ((c = getopt(argc, argv, "r" DEL_OPT_EXTENSIONS)) != -1) {
switch(c) {
default:
usermgmt_usage("userdel");
#ifdef EXTENSIONS
case 'D':
bigD = 1;
@ -1879,6 +1885,8 @@ groupadd(int argc, char **argv)
dupgid = 0;
while ((c = getopt(argc, argv, "g:o" GROUP_ADD_OPT_EXTENSIONS)) != -1) {
switch(c) {
default:
usermgmt_usage("groupadd");
case 'g':
if (!is_number(optarg)) {
errx(EXIT_FAILURE, "When using [-g gid], the gid must be numeric");
@ -1931,6 +1939,8 @@ groupdel(int argc, char **argv)
while ((c = getopt(argc, argv, "" GROUP_DEL_OPT_EXTENSIONS)) != -1) {
switch(c) {
default:
usermgmt_usage("groupdel");
#ifdef EXTENSIONS
case 'v':
verbose = 1;
@ -1975,6 +1985,8 @@ groupmod(int argc, char **argv)
newname = NULL;
while ((c = getopt(argc, argv, "g:on:" GROUP_MOD_OPT_EXTENSIONS)) != -1) {
switch(c) {
default:
usermgmt_usage("groupmod");
case 'g':
if (!is_number(optarg)) {
errx(EXIT_FAILURE, "When using [-g gid], the gid must be numeric");
@ -2047,6 +2059,8 @@ userinfo(int argc, char **argv)
exists = 0;
while ((i = getopt(argc, argv, "ev")) != -1) {
switch(i) {
default:
usermgmt_usage("userinfo");
case 'e':
exists = 1;
break;
@ -2107,6 +2121,8 @@ groupinfo(int argc, char **argv)
exists = 0;
while ((i = getopt(argc, argv, "ev")) != -1) {
switch(i) {
default:
usermgmt_usage("groupinfo");
case 'e':
exists = 1;
break;