dminfo.c revision 45916cd2fec6e79bca5dee0421bd39e3c2910d1e
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
#include <unistd.h>
#include <malloc.h>
#include <memory.h>
#include <fcntl.h>
#define DMPFILE "/etc/security/device_maps"
#define RETRY_SLEEP 6
#define RETRY_COUNT 10
#define EINVOKE 2
#define EFAIL 1
#if !defined(TEXT_DOMAIN)
#define TEXT_DOMAIN "SUNW_BSM_DMINFO"
#endif
char *getdmapfield();
char *getdmapdfield();
static void printdmapent();
static void dmapi_err();
static char *prog_name;
/*
* printdmapent(dmapp) prints a devmap_t structure pointed to by dmapp.
*/
static void
{
(void) printf("\n");
}
/*
* dmapi_err(exit_code,err_msg) prints message pointed to by err_msg to
* stderr. Then prints usage message to stderr. Then exits program with
* exit_code.
*
*/
static void
{
}
"Usage: %s [-v] [-a] [-f filename] %s\n",
"[-d device ...]");
" %s [-v] [-a] [-f filename] %s\n",
"[-n name ...]");
" %s [-v] [-a] [-f filename] %s\n",
"[-t type ...]");
" %s [-v] [-a] [-f filename] %s\n",
"[-u Entry]");
}
}
int
{
char *mptr;
char *tptr;
char *nptr;
int name = 0;
int device = 0;
int file = 0;
int verbose = 0;
int cntr = 0;
int any = 0;
int update = 0;
int tp = 0;
int des;
int status;
/* Internationalization */
(void) textdomain(TEXT_DOMAIN);
/*
* point prog_name to invocation name
*/
else
argc--;
argv++;
/*
* parse arguments
*/
switch (argv[0][1]) {
case 'a':
any++;
break;
case 'd':
gettext("option conflict"));
}
device++;
break;
case 'f':
argc--;
argv++;
if (argc <= 0)
gettext("missing file name"));
file++;
break;
case 'n':
gettext("option conflict"));
}
name++;
break;
case 't':
gettext("option conflict"));
}
tp++;
break;
case 'u':
gettext("option conflict"));
}
update++;
break;
case 'v':
verbose++;
break;
default:
gettext("bad option"));
break;
}
argc--;
argv++;
}
/*
* -d(device) -n(name) and -u(update) switches require at least one
* argument.
*/
if (file)
if (argc < 1) {
gettext("insufficient args for this option"));
}
}
if (update) {
/*
* -u(update) switch requires only one argument
*/
if (argc != 1) {
gettext("too many args for this option"));
}
/*
* read entry argument from stdin into a devmap_t known as dmap
*/
gettext("Bad dmap_devname in entry argument"));
}
NULL) {
gettext("Bad dmap_devtype in entry Argument"));
}
NULL) {
gettext("Bad dmap_devlist in entry argument"));
}
/*
* Find out how long device list is and create a buffer to
* hold it. Then copy it there. This is done since we do not
* want to corrupt the existing string.
*/
if (verbose) {
"dmapinfo: Cannot calloc memory\n"));
}
exit(1);
}
/*
* open the device maps file for read/ write. We are not
* sure we want to write to it yet but we may and this is a
* easy way to get the file descriptor. We want the file
* descriptor so we can lock the file.
*/
if (verbose) {
gettext("dmapinfo: Cannot open %s\n"),
filename);
}
exit(1);
}
cntr = 0;
#ifdef CMW
(cntr++ < RETRY_COUNT)) {
(void) sleep(RETRY_SLEEP);
}
#else
(cntr++ < RETRY_COUNT)) {
(void) sleep(RETRY_SLEEP);
}
#endif
if (status == -1) {
if (verbose) {
}
exit(1);
}
/*
* Now that we have the device_maps file then lets check
* for previous entrys with the same name. If it already
* exists then we will exit with status of 1.
*/
if (verbose) {
gettext("dmapinfo: Checking %s for name (%s).\n"),
}
if (verbose) {
gettext("dmapinfo: Device name (%s) found in %s.\n"),
}
exit(1);
}
if (verbose) {
gettext("dmapinfo: Device name (%s) not found in %s.\n"),
}
/*
* We now Know name does not exist and now we need to check
* to see if any of the devices in the device list are in the
* device maps file. If the already exist then we will exit
* with a status of 1.
*/
while (nptr) {
if (verbose) {
gettext("dmapinfo: "
"Check %s for device (%s).\n"),
}
if (verbose) {
gettext("dmapinfo: "
"Device (%s) found in %s.\n"),
}
exit(1);
}
if (verbose) {
gettext("dmapinfo: "
"Device (%s) not found in %s.\n"),
}
}
/*
* Good the entry is uniq. So lets find out how long it is
* and add it to the end of device maps file in a pretty
* way.
*/
if (verbose) {
filename);
printdmapent(&dmap);
}
cntr += 15;
exit(1);
}
#ifdef CMW
exit(1);
}
#else
exit(1);
}
#endif
exit(1);
}
exit(1);
}
if (verbose) {
filename);
}
exit(0);
}
/*
* Look for devices in device_maps file. If verbose switch is set
* then print entry(s) found. If "any" switch is set then, if any
* device is found will result in a exit status of 0. If "any" switch
* is not set then, if any device is not will result in a exit status
* of 1.
*/
if (device) {
setdmapent();
while (argc >= 1) {
if (verbose) {
}
cntr++;
} else if (any == 0) {
enddmapent();
exit(1);
}
argc--;
argv++;
}
enddmapent();
if (cntr != 0)
exit(0);
exit(1);
}
/*
* Look for names in device_maps file. If verbose switch is set
* then print entry(s) found. If "any" switch is set then, if any
* name is found will result in a exit status of 0. If "any" switch
* is not set then, if any name is not will result in a exit status
* of 1.
*/
if (name) {
setdmapent();
while (argc >= 1) {
if (verbose) {
}
cntr++;
} else if (any == 0)
exit(1);
argc--;
argv++;
}
enddmapent();
if (cntr != 0)
exit(0);
exit(1);
}
/*
* Read all entrys from device maps file. If verbose flag is set
* then all the device maps files are printed. This is useful for
* piping to grep. Also this option used without the verbose option
* is useful to check for device maps file and for at least one
* entry. If the device maps file is found and there is one entry
* the return status is 0.
*/
if (tp) {
cntr = 0;
setdmapent();
while (argc >= 1) {
cntr++;
if (verbose) {
}
}
enddmapent();
exit(1);
}
argc--;
argv++;
}
enddmapent();
if (cntr == 0)
exit(1);
exit(0);
}
/*
* Read all entrys from device maps file. If verbose flag is set
* then all the device maps files are printed. This is useful for
* piping to grep. Also this option used without the verbose option
* is useful to check for device maps file and for atleast one
* entry. If the device maps file is found and there is one entry
* the return status is 0.
*/
cntr = 0;
setdmapent();
while ((dmapp = getdmapent()) != 0) {
cntr++;
if (verbose) {
}
}
enddmapent();
if (cntr == 0)
exit(1);
return (0);
}