vscanadm.c revision 911106dfb16696472af8c1b7b4c554a829354fa8
/*
* 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 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdio.h>
#include <strings.h>
#include <limits.h>
#include <stdlib.h>
#include <stdarg.h>
#include <errno.h>
#include <ctype.h>
#include <unistd.h>
#include <fcntl.h>
#include <libintl.h>
#include <libvscan.h>
/* Property Names */
#define VS_ADM_MAXSIZE "max-size"
#define VS_ADM_MAXSIZE_ACTION "max-size-action"
#define VS_ADM_TYPES "types"
/* Scan Engine Property Names */
#define VS_ADM_SE_ENABLE "enable"
#define VS_ADM_SE_HOST "host"
#define VS_ADM_SE_PORT "port"
#define VS_ADM_SE_MAXCONN "max-connection"
/* Property Values */
#define VS_ADM_ON "on"
#define VS_ADM_OFF "off"
#define VS_ADM_ALLOW "allow"
#define VS_ADM_DENY "deny"
/*
* Print buffer length: used for sizing buffers that are filled with
* user-readable strings for property values. Define a number that
* accounts for some pre-value information, and won't (likely)
* wrap an 80-column display
*/
#define VS_ADM_PRINT_BUF_LEN 4096
/* Program exit codes */
#define VS_ADM_EXIT_SUCCESS 0
#define VS_ADM_EXIT_ERROR 1
#define VS_ADM_EXIT_USAGE 2
/*
* vscanadm property definition. Maps the property ids to a
* property name, and includes functions to convert to and from
* input strings and native data.
*/
typedef struct vs_adm_property {
const char *vap_name;
int (*vap_parse)(const char *, void *);
int (*vap_unparse)(const void *, char *, size_t);
#define VS_ADM_HELP_GET ("[-p property]...\n" \
"\tdisplay vscan properties")
#define VS_ADM_HELP_SET ("-p property=value [-p property=value]...\n" \
"\tset values of vscan properties")
#define VS_ADM_HELP_GET_ENG ("[-p property] [engine_id]\n" \
"\tdisplay values of scan engine properties")
#define VS_ADM_HELP_ADD_ENG ("[-p property=value]... engine_id\n" \
"\tadd scan engine")
#define VS_ADM_HELP_SET_ENG ("-p property=value [-p property=value]" \
"... engine_id\n\tset values of scan engine properties")
#define VS_ADM_HELP_REM_ENG ("engine_id\n" \
"\tremove scan engine")
#define VS_ADM_HELP_SHOW ("\n\tdisplay the values of all vscan " \
"service and scan engine properties")
#define VS_ADM_HELP_STATS ("[-z]\n\tdisplay vscan service statistics")
#define VS_ADM_HELP_IMPORT ("-p property filename\n" \
"\timport property from file")
#define VS_ADM_HELP_EXPORT ("-p property filename\n" \
"\texport property to file")
#define VS_ADM_HELP_VALIDATE ("-p property filename\n" \
"\tvalidate property in file")
/*
* vscanadm command structure. Encapsulates the vscanadm
* subcommand name, pointer to the subcommand implementation
*/
typedef struct vs_adm_cmd {
int (*vac_func)(int, char *[]);
const char *vac_name;
char *vac_helpid;
}
/* Subcommand implementation functions */
static int vs_adm_set(int, char **);
static int vs_adm_get(int, char **);
static int vs_adm_set_engine(int, char **);
static int vs_adm_get_engine(int, char **);
static int vs_adm_rem_engine(int, char **);
static int vs_adm_show(int, char **);
static int vs_adm_stats(int, char **);
static int vs_adm_import(int, char **);
static int vs_adm_export(int, char **);
static int vs_adm_validate(int, char **);
/*
* Parse routines to transform libvscan API data into user-readable strings
*/
static int vs_adm_parse_maxsize(const char *, void *);
static int vs_adm_parse_maxsize_action(const char *, void *);
static int vs_adm_parse_types(const char *, void *);
static int vs_adm_parse_enable(const char *, void *);
static int vs_adm_parse_host(const char *, void *);
static int vs_adm_parse_port(const char *, void *);
static int vs_adm_parse_maxconn(const char *, void *);
/*
* Unparse routines to transform strings from the user input into
* API native data.
*
* While some value validation is performed in the course of unparsing
* string data, complete value validation is left to libvscan.
* Values that are in unacceptable form, out of range, or otherwise
* violate rules for a given property will be rejected
*/
static int vs_adm_unparse_maxsize(const void *, char *, size_t);
static int vs_adm_unparse_maxsize_action(const void *, char *, size_t);
static int vs_adm_unparse_types(const void *, char *, size_t);
static int vs_adm_unparse_enable(const void *, char *, size_t);
static int vs_adm_unparse_host(const void *, char *, size_t);
static int vs_adm_unparse_port(const void *, char *, size_t);
static int vs_adm_unparse_maxconn(const void *, char *, size_t);
/*
* The properties table includes a vscanadm property entry, specifying
* the property nane, property id, parse amd inparse methods,
* for each vscanadm property.
*/
static const vs_adm_property_t vs_adm_props_all[] = {
};
/*
* The subcommand table. Used to find the subcommand specified
* by the user and dispatch the processing for the subcommand.
* Also used to display usage information for each subcommand.
*/
static const vs_adm_cmd_t vs_adm_cmds[] =
{
};
static const char *vs_adm_cmd;
static const char *vs_adm_subcmd;
static int vs_adm_usage(FILE *);
static void vs_adm_output_getcmd(uint64_t, const void *);
static void vs_adm_output_stats(vs_stats_t *);
static const vs_adm_property_t *vs_adm_prop_by_name(const char *);
static int vs_adm_parse(const vs_adm_property_t *, const char *, void *);
static void vs_adm_unparse(const vs_adm_property_t *, const void *,
char *, size_t);
static int vs_adm_file_read(char *, char *, int);
static int vs_adm_file_write(char *, char *);
/*
* main
*/
int
{
const vs_adm_cmd_t *cp;
const char *p;
int i, err;
/* executable and subcommand names */
vs_adm_cmd = argv[0];
else
vs_adm_cmd = p + 1;
/* require at least command and sub-command */
if (argc < 2)
return (vs_adm_usage(stdout));
/* Check for the "-?" help switch */
for (i = 1; i < argc; i++) {
return (vs_adm_usage(stdout));
}
/* Locate the specified subcommand */
break;
}
gettext("invalid subcommand"),
return (vs_adm_usage(stderr));
}
/* invoke sub-command handler */
}
/*
* vs_adm_usage
*/
static int
{
const vs_adm_cmd_t *cp;
}
return (VS_ADM_EXIT_USAGE);
}
/*
* vs_adm_get
*
* Gets and displays general vscan service configuration properties.
*/
static int
{
int i, rc;
const vs_adm_property_t *vap;
if (argc <= 2) {
} else {
for (i = 2; i < argc; i++) {
/* the "-p" specifier is optional */
if (++i >= argc)
return (VS_ADM_EXIT_USAGE);
}
return (VS_ADM_EXIT_ERROR);
}
}
}
if (rc != VS_ERR_NONE) {
return (VS_ADM_EXIT_ERROR);
}
return (VS_ADM_EXIT_SUCCESS);
}
/*
* vs_adm_set
*
* Sets values for general vscan service configuration properties
*
* Calls a common function used by the set, add, and remove
* subcommands to modify general property values.
*/
static int
{
int rc;
if (argc < 3)
return (VS_ADM_EXIT_USAGE);
if (rc != VS_ADM_EXIT_SUCCESS)
return (rc);
if (rc != VS_ERR_NONE) {
return (VS_ADM_EXIT_ERROR);
}
return (VS_ADM_EXIT_SUCCESS);
}
/*
* vs_adm_get_engine
*
* Gets and displays scan engine configuration properties for
* one or more scan engines.
*/
static int
{
int i, rc;
const vs_adm_property_t *vap;
for (i = 2; i < argc; i++) {
/* if not preceded by -p, must be engine id and must be last */
if (i != (argc - 1))
return (VS_ADM_EXIT_USAGE);
gettext("invalid scan engine"));
return (VS_ADM_EXIT_ERROR);
}
} else {
/* property should follow the -p */
if (++i >= argc)
return (VS_ADM_EXIT_USAGE);
return (VS_ADM_EXIT_ERROR);
}
}
}
/* get properties for specified engine */
if (engid) {
if (rc != VS_ERR_NONE) {
return (VS_ADM_EXIT_ERROR);
}
return (VS_ADM_EXIT_SUCCESS);
}
/* get properties for all engines */
return (VS_ADM_EXIT_ERROR);
}
for (i = 0; i < VS_SE_MAX; i++) {
break;
}
if (i == 0) {
gettext("no scan engines configured"));
}
return (VS_ADM_EXIT_SUCCESS);
}
/*
* vs_adm_set_engine
*
* Sets one or more scan engine configuration properties for a
* single scan engine.
*/
static int
{
const vs_adm_property_t *vap;
char *val;
int i, rc;
char *engid;
return (VS_ADM_EXIT_USAGE);
/* Get the engine id */
return (VS_ADM_EXIT_USAGE);
}
gettext("invalid scan engine"));
return (VS_ADM_EXIT_ERROR);
}
/* The "-p" is optional */
if (++i >= argc)
return (VS_ADM_EXIT_USAGE);
}
return (VS_ADM_EXIT_USAGE);
*val = 0;
val++;
/* Find the SE property pointer from the SE property name */
return (VS_ADM_EXIT_ERROR);
}
return (VS_ADM_EXIT_ERROR);
}
}
if (add)
else
if (rc != VS_ERR_NONE) {
return (VS_ADM_EXIT_ERROR);
}
return (VS_ADM_EXIT_SUCCESS);
}
/*
* vs_adm_rem_engine
*/
/* ARGSUSED */
static int
{
int rc;
char *engid;
if (argc != 3)
return (VS_ADM_EXIT_USAGE);
gettext("invalid scan engine"));
return (VS_ADM_EXIT_ERROR);
}
return (rc);
}
return (VS_ADM_EXIT_SUCCESS);
}
/*
* vs_adm_import
*/
static int
{
int rc;
char *filename;
return (rc);
if (rc != VS_ADM_EXIT_SUCCESS)
return (rc);
if (rc != VS_ERR_NONE) {
return (VS_ADM_EXIT_ERROR);
}
return (VS_ADM_EXIT_SUCCESS);
}
/*
* vs_adm_validate
*/
static int
{
int rc;
char *filename;
return (rc);
if (rc != VS_ADM_EXIT_SUCCESS)
return (rc);
return (VS_ADM_EXIT_ERROR);
}
return (VS_ADM_EXIT_SUCCESS);
}
/*
* vs_adm_export
*/
static int
{
int rc;
char *filename;
return (rc);
return (VS_ADM_EXIT_ERROR);
}
if (rc != VS_ADM_EXIT_SUCCESS)
return (rc);
return (VS_ADM_EXIT_SUCCESS);
}
/*
* vs_adm_file_usage
*
* import, export and validate - VS_PROPID_TYPES only
*/
static int
{
const vs_adm_property_t *vap;
char *prop;
if (argc < 4)
return (VS_ADM_EXIT_USAGE);
/* -p optional */
if (argc != 5)
return (VS_ADM_EXIT_USAGE);
} else if (argc != 4)
return (VS_ADM_EXIT_USAGE);
/* only VS_PROPID_TYPES supported */
return (VS_ADM_EXIT_USAGE);
}
return (VS_ADM_EXIT_SUCCESS);
}
/*
* vs_adm_file_read
*/
static int
{
return (VS_ADM_EXIT_ERROR);
}
gettext("invalid property value"));
return (VS_ADM_EXIT_ERROR);
}
/* remove newline */
return (VS_ADM_EXIT_SUCCESS);
}
/*
* vs_adm_file_write
*/
static int
{
int bytes;
return (VS_ADM_EXIT_ERROR);
}
return (VS_ADM_EXIT_ERROR);
}
return (VS_ADM_EXIT_SUCCESS);
}
/*
* vs_adm_show
*
* Gets and displays all general properties and all scan engine
* properties.
*/
/* ARGSUSED */
static int
{
if (argc > 2)
return (VS_ADM_EXIT_USAGE);
return (VS_ADM_EXIT_SUCCESS);
}
/*
* vs_adm_stats
*
* Gets and displays vscan service statistics.
*/
/* ARGSUSED */
static int
{
int rc;
/* get statistics */
if (argc == 2) {
return (VS_ADM_EXIT_SUCCESS);
} else {
return (VS_ADM_EXIT_ERROR);
}
}
/* reset statistics */
return (VS_ADM_EXIT_SUCCESS);
} else {
return (VS_ADM_EXIT_ERROR);
}
}
/* usage error */
return (vs_adm_usage(stdout));
}
/*
* vs_adm_output_stats
*/
static void
{
int i;
char *engid;
return;
if (stats->vss_cleaned > 0)
for (i = 0; i < VS_SE_MAX; i++) {
if (*engid == 0)
break;
}
}
/*
* vs_adm_props_from_input
*/
static int
{
const vs_adm_property_t *vap;
char *val;
int i;
for (i = 2; i < argc; i++) {
/* The "-p" is optional */
if (++i >= argc)
return (VS_ADM_EXIT_USAGE);
}
return (VS_ADM_EXIT_USAGE);
/* Find the vscanadm property pointer from the property name */
*val = '\0';
val++;
return (VS_ADM_EXIT_ERROR);
}
/* Add in the property id and parse the property value */
return (VS_ADM_EXIT_ERROR);
}
}
return (VS_ADM_EXIT_SUCCESS);
}
/*
* vs_adm_output_getcmd
*
* Prints the results of a get command; both the get for general
* configuration properties as well as the get for an engine
* properties.
*
*/
static void
{
char value[VS_ADM_PRINT_BUF_LEN];
const vs_adm_property_t *vap;
if (VS_PROPID_IS_SE(propids))
/*
* Unparse values from the property structure into readable strings
* and print them.
*/
continue;
continue;
*value = '\0';
if (label)
}
}
/*
* vs_adm_prop_by_name
*
* Finds and returns a pointer to a vscan property structure from the
* property table by property name.
*/
static const vs_adm_property_t *
vs_adm_prop_by_name(const char *propname)
{
const vs_adm_property_t *p;
return (p);
}
return (NULL);
}
/*
* vs_adm_prop_by_id
*
* Finds and returns a pointer to a vscan property structure from the
* property table by property name.
*/
static const vs_adm_property_t *
{
const vs_adm_property_t *p;
for (p = vs_adm_props_all; p->vap_id != 0; p++) {
return (p);
}
return (NULL);
}
/*
* vs_adm_parse
*
* Entry point for parsing the user input strings into a data structure
* used for setting values. Dispatches the actual parsing to the parse
* routine for the specified vscanadm property.
*
* This function is used to dispatch parsing for values supplied by the
* user for all subcommands; both the general configuration as well as
* scan engine configuration. The structure pointer is therefore typed
* as a void pointer, and cast appropriately in the parse routine for
* the vscanadm property.
*/
static int
void *vp)
{
}
/*
* vs_adm_parse_maxsize
*
* Parses a user-supplied string into a maxsize (decimal) value for
* the general vscan configuration properties.
*/
static int
{
char *end;
errno = 0;
if (errno != 0)
return (-1);
return (0);
}
/*
* vs_adm_parse_maxsize_action
*
* Parses a user-supplied string into a maxsize action value for the
* general vscan configuration properties.
*
* Returns: 0 success
* -1 failure
*/
static int
{
return (0);
}
return (0);
}
return (-1);
}
/*
* vs_adm_parse_types
*
* Returns: 0 success
* -1 on failure.
*/
static int
{
return (-1);
return (-1);
return (0);
}
/*
* vs_adm_parse_enable
*
* Parses a user-supplied string into an enable value for the
* properties of a scan engine.
*
* Returns: 0 success
* -1 on failure.
*/
static int
{
return (0);
}
return (0);
}
return (-1);
}
/*
* vs_adm_parse_host
*
* Parses a user-supplied string into an ip address value for the
* properties of a scan engine.
*/
static int
{
return (-1);
return (-1);
return (0);
}
/*
* vs_adm_parse_port
*
* Parses a user-supplied string into a port value for the properties of
* a scan engine. The port is an unsigned short int, but the conversion
* must be done on a word-sized int. Casting the converted int into the
* port member of the property structure can result in a valid but
* unintended value, so the range is checked first for validity.
*
* Returns: 0 success
* -1 on failure.
*/
static int
{
unsigned long port;
char *end;
end = 0;
return (-1);
return (0);
}
/*
* vs_adm_parse_maxconn
*
* Parses a user-supplied string into a max connections (decimal) value
* for the properties of a scan engine.
*
* Returns: 0 success
* -1 on failure.
*/
static int
{
char *end;
return (-1);
return (0);
}
/*
* vs_adm_unparse
*
* Entry point for unparsing native data into a readable string
* used for display to the user. Dispatches the actual unparsing to
* the unparse routine for the specified vscanadm property.
*
* This function is used to dispatch unparsing for all subcommands.
* The structure pointer is therefore typed as a void pointer, and
* cast appropriately in the unparse routine for the vscanadm property.
*/
static void
{
}
/*
* vs_adm_unparse_maxsize
*
* Unparses a max fsize value in native data form into a
* user-readable string.
*/
/* ARGSUSED */
static int
{
return (0);
}
/*
* vs_adm_unparse_maxsize_action
*
* Unparses a max fsize action value in native data form into a
* user-readable string.
*/
/* ARGSUSED */
static int
{
return (0);
}
/*
* vs_adm_unparse_types
*
* Returns: 0 success
* -1 on failure.
*/
static int
{
return (0);
}
/*
* vs_adm_unparse_enable
*
* Unparses the enable value for a scan engine in native data
* form into a user-readable string.
*/
/* ARGSUSED */
static int
{
return (0);
}
/*
* vs_adm_unparse_host
*
* Unparses an ip address for a scan engine in native data
* form into a user-readable string.
*
* Returns: 0 success
* -1 on failure.
*/
/* ARGSUSED */
static int
{
return (0);
}
/*
* vs_adm_unparse_port
*
* Unparses a port value for a scan engine in native data
* form into a user-readable string.
*/
/* ARGSUSED */
static int
{
return (0);
}
/*
* vs_adm_unparse_maxconn
*
* Unparses a max connecctions for a scan engine in native data
* form into a user-readable string.
*
*/
/* ARGSUSED */
static int
{
return (0);
}