diff options
| author | paulson <none@none> | 2006-01-15 08:23:20 -0800 |
|---|---|---|
| committer | paulson <none@none> | 2006-01-15 08:23:20 -0800 |
| commit | 40e2b7c9adf98f629a8a3463b605d4322963ef30 (patch) | |
| tree | dd907c7fcb923e9abeb7832fcabc8b9539449b50 /usr/src/cmd/allocate | |
| parent | 5b024a5b76c96ebbaf36ba7803ba4dbe959f7219 (diff) | |
| download | illumos-joyent-40e2b7c9adf98f629a8a3463b605d4322963ef30.tar.gz | |
6244980 deallocate(1) has a program usage error
6245008 list_devices(1) and allocate(1) don't give any errors when more than one device entry is specified
6250898 allocate -s is not always silent and 'list_devices -s' error is confusing
6251504 'allocate -F sr0 -g rmt', 'allocate -g sr -F -U', 'allocate -g sr -F' all succeed with no errors
6253496 list_devices allows multiple l,n,u options, does not return an error, and performs only one option
6260923 deallocate has problems following the man page usage [or the man page usage is incorrect]
6308874 'list_devices -U <user-ID>' doesn't work as it treats the user-ID as a username
Diffstat (limited to 'usr/src/cmd/allocate')
| -rw-r--r-- | usr/src/cmd/allocate/allocate.c | 200 | ||||
| -rw-r--r-- | usr/src/cmd/allocate/allocate.h | 9 | ||||
| -rw-r--r-- | usr/src/cmd/allocate/allocate3.c | 10 |
3 files changed, 145 insertions, 74 deletions
diff --git a/usr/src/cmd/allocate/allocate.c b/usr/src/cmd/allocate/allocate.c index f02985c7a4..a2c1c967f9 100644 --- a/usr/src/cmd/allocate/allocate.c +++ b/usr/src/cmd/allocate/allocate.c @@ -20,7 +20,7 @@ * CDDL HEADER END */ /* - * Copyright 1992-2002 Sun Microsystems, Inc. All rights reserved. + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -48,13 +48,15 @@ extern int audit_allocate_record(int); static void usage(int func) { - char *use[5]; + char *use[7]; use[0] = gettext("allocate [-s] [-U uname] [-F] device"); use[1] = gettext("allocate [-s] [-U uname] -g dev_type"); use[2] = gettext("deallocate [-s] [-F] device"); - use[3] = gettext("deallocate [-s] [-I]"); - use[4] = gettext("list_devices [-s] [-U uname] {-l|-n|-u} [device]"); + use[3] = gettext("deallocate [-s] -I"); + use[4] = gettext("list_devices [-s] [-U uid] -l [device]"); + use[5] = gettext("list_devices [-s] [-U uid] -n [device]"); + use[6] = gettext("list_devices [-s] [-U uid] -u [device]"); switch (func) { case 0: @@ -64,12 +66,14 @@ usage(int func) (void) fprintf(stderr, "%s\n%s\n", use[2], use[3]); break; case 2: - (void) fprintf(stderr, "%s\n", use[4]); + (void) fprintf(stderr, "%s\n%s\n%s\n", use[4], use[5], + use[6]); break; default: (void) fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n", use[0], use[1], use[2], use[3], use[4]); } + exit(1); } static void @@ -190,7 +194,7 @@ int main(int argc, char *argv[], char *envp[]) { char *name, *env; - int func = -1, optflg = 0, errflg = 0, error = 0, c; + int func = -1, optflg = 0, error = 0, c; uid_t uid = getuid(); char *uname = NULL, *device = NULL; struct passwd *pw_ent; @@ -238,88 +242,152 @@ main(int argc, char *argv[], char *envp[]) func = 2; else { usage(ALL); - exit(1); } audit_allocate_argv(func, argc, argv); - while ((c = getopt(argc, argv, "slnugIU:F")) != -1) - switch (c) { - case 's': - optflg |= SILENT; - break; - case 'U': - optflg |= USERID; - uname = optarg; - break; - case 'g': - optflg |= TYPE; - break; - case 'l': - optflg |= LIST; - break; - case 'n': - optflg |= FREE; - break; - case 'u': - optflg |= CURRENT; - break; - case 'F': - optflg |= FORCE; - break; - case 'I': - optflg |= FORCE_ALL; - break; - case '?': - errflg++; - break; - default : - (void) fprintf(stderr, gettext("Bad option '%c'\n"), c); + if (func == 0) { /* allocate */ + while ((c = getopt(argc, argv, "sU:Fg")) != -1) { + switch (c) { + case 's': + optflg |= SILENT; + break; + case 'U': + optflg |= USERNAME; + uname = optarg; + break; + case 'g': + optflg |= TYPE; + break; + case 'F': + optflg |= FORCE; + break; + case '?': + default : + usage(func); + } } - if (optind < argc) { - device = argv[optind]; + if ((optflg & TYPE) && (optflg & FORCE)) + usage(func); + + /* + * allocate(1) must be supplied with one device argument + */ + if ((argc - optind) != 1) { + usage(func); + } else { + device = argv[optind]; + } } - if (device == NULL && !(optflg & (LIST | FREE | CURRENT | FORCE_ALL))) - errflg++; + else if (func == 1) { /* deallocate */ + while ((c = getopt(argc, argv, "sFI")) != -1) { + switch (c) { + case 's': + optflg |= SILENT; + break; + case 'F': + optflg |= FORCE; + break; + case 'I': + optflg |= FORCE_ALL; + break; + case '?': + default : + usage(func); + } + } + + if ((optflg & FORCE) && (optflg & FORCE_ALL)) + usage(func); - if (errflg) { - usage(func); - exit(2); + /* + * deallocate(1) must be supplied with one device + * argument unless the '-I' argument is supplied + */ + if (!(optflg & FORCE_ALL)) { + if ((argc - optind) != 1) { + usage(func); + } else { + device = argv[optind]; + } + } else { + if ((argc - optind) >= 1) { + usage(func); + } + } } - if (optflg & USERID) { + else if (func == 2) { /* list_devices */ + while ((c = getopt(argc, argv, "sU:lnu")) != -1) { + switch (c) { + case 's': + optflg |= SILENT; + break; + case 'U': + optflg |= USERID; + uid = atoi(optarg); + break; + case 'l': + optflg |= LIST; + break; + case 'n': + optflg |= FREE; + break; + case 'u': + optflg |= CURRENT; + break; + case '?': + default : + usage(func); + } + } + + if (((optflg & LIST) && (optflg & FREE)) || + ((optflg & LIST) && (optflg & CURRENT)) || + ((optflg & FREE) && (optflg & CURRENT)) || + (!(optflg & (LIST | FREE | CURRENT)))) + usage(func); + + /* + * list_devices(1) takes an optional device argument + */ + if ((argc - optind) == 1) { + device = argv[optind]; + } else { + if ((argc - optind) > 1) { + usage(func); + } + } + } + + if (optflg & USERNAME) { if ((pw_ent = getpwnam(uname)) == NULL) { (void) fprintf(stderr, gettext( "Invalid user name -- %s -- \n"), uname); - exit(4); + exit(1); } uid = pw_ent->pw_uid; } - if (func == 0) { - if (optflg & ~ALLOC_OPTS) { - usage(func); - exit(3); - } else { - error = allocate(optflg, uid, device); + if (optflg & USERID) { + if ((pw_ent = getpwuid(uid)) == NULL) { + (void) fprintf(stderr, gettext( + "Invalid user ID -- %d -- \n"), uid); + exit(1); } + uid = pw_ent->pw_uid; + } + + if (func == 0) { + error = allocate(optflg, uid, device); } else if (func == 1) { - if (optflg & ~DEALLOC_OPTS) { - usage(func); - exit(3); - } else { - error = deallocate(optflg, uid, device); - } + error = deallocate(optflg, uid, device); } else if (func == 2) { - if (optflg & ~LIST_OPTS) { - usage(func); - exit(3); - } else { - error = list_devices(optflg, uid, device); - } + error = list_devices(optflg, uid, device); } + (void) audit_allocate_record(error); if (error) { diff --git a/usr/src/cmd/allocate/allocate.h b/usr/src/cmd/allocate/allocate.h index 5bb4771919..29f222a29d 100644 --- a/usr/src/cmd/allocate/allocate.h +++ b/usr/src/cmd/allocate/allocate.h @@ -20,7 +20,7 @@ * CDDL HEADER END */ /* - * Copyright 1992-2002 Sun Microsystems, Inc. All rights reserved. + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -35,17 +35,14 @@ extern "C" { /* Option Flags */ #define SILENT 0001 /* -s */ -#define USERID 0002 /* -U */ +#define USERID 0002 /* -U <uid> for list_devices(1) */ #define LIST 0004 /* -l */ #define FREE 0010 /* -n */ #define CURRENT 0020 /* -u */ #define FORCE 0040 /* -F */ #define FORCE_ALL 0100 /* -I */ #define TYPE 0200 /* -g */ - -#define ALLOC_OPTS (SILENT | USERID | FORCE | TYPE) -#define DEALLOC_OPTS (SILENT | FORCE | FORCE_ALL) -#define LIST_OPTS (SILENT | USERID | LIST | FREE | CURRENT) +#define USERNAME 0400 /* -U <username> for allocate(1) */ /* Misc. */ diff --git a/usr/src/cmd/allocate/allocate3.c b/usr/src/cmd/allocate/allocate3.c index 0a5e0d0d9d..1e24722cbb 100644 --- a/usr/src/cmd/allocate/allocate3.c +++ b/usr/src/cmd/allocate/allocate3.c @@ -20,7 +20,7 @@ * CDDL HEADER END */ /* - * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -588,6 +588,7 @@ allocate_dev(int optflg, uid_t uid, devalloc_t *dev_ent) char *list; int error = 0; int bytes_formated; + int deallocate_optflg = 0; bytes_formated = snprintf(file_name, MAXPATHLEN, "%s/%s", DAC_DIR, dev_ent->da_devname); @@ -608,7 +609,12 @@ allocate_dev(int optflg, uid_t uid, devalloc_t *dev_ent) if (DEV_ALLOCATED(stat_buf)) { if (optflg & FORCE) { - if (deallocate_dev(FORCE, dev_ent, uid)) { + if (optflg & SILENT) + deallocate_optflg = FORCE|SILENT; + else + deallocate_optflg = FORCE; + + if (deallocate_dev(deallocate_optflg, dev_ent, uid)) { dprintf("Couldn't force deallocate device %s\n", dev_ent->da_devname); return (CNTFRC); |
