svccfg_engine.c revision 3eae19d9cf3390cf5b75e10c9c1945fd36ad856a
/*
* 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"
/*
* svccfg(1) interpreter and command execution engine.
*/
#include <assert.h>
#include <errno.h>
#include <libintl.h>
#include <libtecla.h>
#include <md5.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include "manifest_hash.h"
#include "svccfg.h"
#define MS_PER_US 1000
/*
* Replacement lex(1) character retrieval routines.
*/
int
{
if (E->sc_cmd_file != NULL)
return (getc(E->sc_cmd_file));
if (E->sc_cmd_flags & SC_CMD_EOF)
return (EOF);
if (E->sc_cmd_bufoff < E->sc_cmd_bufsz)
return (*(E->sc_cmd_buf + E->sc_cmd_bufoff++));
if (!(E->sc_cmd_flags & SC_CMD_IACTIVE)) {
E->sc_cmd_flags |= SC_CMD_EOF;
return (EOF);
} else {
#ifdef NATIVE_BUILD
return (EOF);
#else
extern int parens;
if (parens <= 0) {
E->sc_cmd_flags |= SC_CMD_EOF;
return (EOF);
}
for (;;) {
if (E->sc_cmd_buf != NULL)
break;
switch (gl_return_status(E->sc_gl)) {
case GLR_SIGNAL:
gl_abandon_line(E->sc_gl);
continue;
case GLR_EOF:
E->sc_cmd_flags |= SC_CMD_EOF;
return (EOF);
case GLR_ERROR:
/* NOTREACHED */
default:
#ifndef NDEBUG
"returned unexpected value %d.\n", __FILE__,
#endif
abort();
}
}
E->sc_cmd_bufoff = 1;
return (E->sc_cmd_buf[0]);
#endif /* NATIVE_BUILD */
}
}
int
engine_cmd_ungetc(engine_state_t *E, char c)
{
if (E->sc_cmd_file != NULL)
return (ungetc(c, E->sc_cmd_file));
if (E->sc_cmd_buf != NULL)
*(E->sc_cmd_buf + --E->sc_cmd_bufoff) = c;
return (c);
}
/*ARGSUSED*/
void
{
/* our lexer shouldn't need this state */
exit(11);
}
int
engine_exec(char *cmd)
{
est->sc_cmd_bufoff = 0;
(void) yyparse();
return (0);
}
#ifndef NATIVE_BUILD
/* ARGSUSED */
static
{
const char *ext;
return (0);
}
static const char * const whitespace = " \t";
static
{
return (0);
cfc = new_CplFileConf();
return (1);
}
(void) del_CplFileConf(cfc);
return (ret);
}
static struct cmd_info {
const char *name;
} cmds[] = {
{ NULL }
};
int
{
int word_start, err;
const char *bol;
continue;
if (err != 0)
return (err);
}
}
return (0);
}
/*
* Suggest completions. We must first determine if the cursor is in command
* position or in argument position. If the former, complete_command() finds
* matching commands. If the latter, we tail-call the command-specific
* argument-completion routine in the cmds table.
*/
/* ARGSUSED */
static
{
continue;
continue;
break;
word_end));
}
return (0);
}
#endif /* NATIVE_BUILD */
int
{
#ifdef NATIVE_BUILD
uu_die("native build does not support interactive mode.");
#else
char *selfmri;
int r;
extern int parens;
/* The longest string is "[snapname]fmri[:instname]> ". */
assert(r == 0);
for (;;) {
case GLR_SIGNAL:
continue;
case GLR_EOF:
break;
case GLR_ERROR:
/* NOTREACHED */
default:
#ifndef NDEBUG
"returned unexpected value %d.\n", __FILE__,
#endif
abort();
}
break;
}
parens = 0;
est->sc_cmd_bufoff = 0;
(void) yyparse();
}
#endif /* NATIVE_BUILD */
return (0);
}
int
{
int ret;
/* first, copy the stuff set up in engine_init */
/* set up the new guy */
if (dont_exit)
} else {
errno = 0;
if (errno == 0)
else
ret = -1;
goto fail;
}
do {
if (ret != 0) {
ret = -1;
goto fail;
}
ret = -1;
goto fail;
}
}
(void) yyparse();
ret = 0;
fail:
lscf_cleanup(); /* clean up any new repository */
return (ret);
}
/*
* Initialize svccfg state. We recognize four environment variables:
*
* SVCCFG_REPOSITORY Create a private instance of svc.configd(1M) to answer
* requests for the specified repository file.
* SVCCFG_DOOR_PATH Directory for door creation.
*
* SVCCFG_DOOR Rendezvous via an alternative repository door.
*
* SVCCFG_CONFIGD_PATH Resolvable path to alternative svc.configd(1M) binary.
*/
void
{
const char *cp;
"SVCCFG_REPOSITORY specified\n"));
} else {
}
}
}
int
{
bundle_t *b;
char **argv;
if (argc < 1)
return (-2);
opterr = 0;
optind = 0; /* Remember, no argv[0]. */
for (;;) {
if (o == -1)
break;
switch (o) {
case 'n':
flags |= SCI_NOREFRESH;
break;
case 'V':
break;
case '?':
return (-2);
default:
bad_error("getopt", o);
}
}
if (argc != 1) {
return (-2);
}
if (ret != MHASH_NEWFILE)
return (ret);
/* Load */
b = internal_bundle_new();
return (-1);
}
/* Import */
return (-1);
}
if (g_verbose)
if (pname) {
char *errstr;
if (errstr)
else
"mhash_store_entry()\n"));
}
}
/* Verify */
if (verify)
return (0);
}
int
engine_apply(const char *file)
{
int ret;
bundle_t *b;
char *pname;
if (ret != MHASH_NEWFILE)
return (ret);
b = internal_bundle_new();
return (-1);
}
if (lscf_bundle_apply(b) != 0) {
return (-1);
}
if (pname) {
char *errstr;
}
return (0);
}
int
engine_restore(const char *file)
{
bundle_t *b;
b = internal_bundle_new();
return (-1);
}
return (-1);
}
return (0);
}
int
{
/* Display current options. */
if (!g_verbose)
(void) puts("verbose");
return (0);
}
/* Use getopt? */
char *op;
switch (*op) {
case 'v':
g_verbose = 1;
break;
case 'V':
g_verbose = 0;
break;
default:
*op);
}
}
} else {
}
}
return (0);
}
void
{
int i;
if (com == 0) {
"Manifest commands: inventory validate import export "
"archive\n"
"Profile commands: apply extract\n"
"Entity commands: list select unselect add delete\n"
"Snapshot commands: listsnap selectsnap revert\n"
"Property group commands: listpg addpg delpg\n"
"Property commands: listprop setprop delprop editprop\n"
"Property value commands: addpropvalue delpropvalue "
"setenv unsetenv\n"));
return;
}
return;
}
}
}