conf.c revision 78eb75caca75144af27b7903ffed3fb549faab2f
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (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 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
*/
#include <stdio.h>
#include <libintl.h>
#include <fcntl.h>
#include <ctype.h>
#include <strings.h>
#include <unistd.h>
#include <stdlib.h>
#include "err.h"
#include "lut.h"
#include "fn.h"
#include "opts.h"
#include "conf.h"
/* forward declarations of functions private to this module */
static const char *Confname; /* name of the confile file */
static char *Confbuf; /* copy of the config file (a la mmap()) */
static int Conflen; /* length of mmap'd area */
/*
* our structured representation of the configuration file
* is made up of a list of these
*/
struct confinfo {
int cf_lineno; /* line number in file */
const char *cf_entry; /* name of entry, if line has an entry */
char **cf_args; /* raw rhs of entry */
const char *cf_com; /* any comment text found */
int cf_flags;
};
/* allocate & fill in another entry in our list */
static void
{
if (entry) {
}
else {
Confinfolast = cp;
}
}
static char **Args; /* static buffer for args */
static int ArgsN; /* size of our static buffer */
static int ArgsI; /* index into Cmdargs as we walk table */
#define CONF_ARGS_INC 1024
/* callback for lut_walk to build a cmdargs vector */
static void
{
/* need bigger table */
ArgsN += CONF_ARGS_INC;
}
}
/* isolate and return the next token */
static char *
{
char *eptr;
ptr++;
/* found end quote */
*eptr++ = '\0';
return (ptr);
/* found end of unquoted area */
*eptr++ = '\0';
return (ptr);
}
if (quote)
/*NOTREACHED*/
return (NULL);
else
return (ptr);
}
/*
* conf_open -- open the configuration file, lock it if we have write perms
*/
void
{
int lineno = 0;
char *line;
char *eline;
char *ebuf;
char *comment;
/* special case this so we don't even try locking the file */
return;
return; /* empty file, don't bother parsing it */
"newline, last line ignored.");
lineno++;
/* check for continued lines */
*eline = ' ';
lineno++;
continue;
}
/* check for comments */
*eline = '\0';
continue;
}
/* check for end of line */
if (*eline == '\n')
break;
}
char *entry;
*eline++ = '\0';
/*
* now we have the entry, if any, at "line"
* and the comment, if any, at "comment"
*/
/* entry is first token */
/*
* we somehow opened some future format
* conffile that we likely don't understand.
* if the given version is "1" then go on,
* otherwise someone is mixing versions
* and we can't help them other than to
* print an error and exit.
*/
err(0, "%s version not "
"supported by "
"this version of logadm.",
Confname);
} else if (entry) {
char *ap;
char **args;
int i;
ArgsI = 0;
if (ArgsI == 0) {
/* short entry allowed */
} else {
for (i = 0; i < ArgsI; i++)
}
} else
comment, 0);
}
}
/*
* possible future enhancement: go through and mark any entries:
* logfile -P <date>
* as DELETED if the logfile doesn't exist
*/
}
/*
* conf_close -- close the configuration file
*/
void
{
if (Debug > 1) {
Confname);
}
conf_print(fp);
Conffd = -1;
}
if (Conffd != -1) {
Conffd = -1;
}
if (Conflut) {
}
if (Confentries) {
Confentries = NULL;
}
}
/*
* conf_lookup -- lookup an entry in the config file
*/
char **
conf_lookup(const char *lhs)
{
if (cp) {
} else
return (NULL);
}
/*
* conf_opts -- return the parsed opts for an entry
*/
struct opts *
{
if (cp) {
}
}
/*
* conf_replace -- replace an entry in the config file
*/
void
{
if (Conffd == -1)
return;
if (cp) {
} else
}
/*
* conf_set -- set options for an entry in the config file
*/
void
{
if (Conffd == -1)
return;
if (cp) {
} else {
err(0, "conf_set internal error");
}
}
/*
* conf_entries -- list all the entry names
*/
struct fn_list *
conf_entries(void)
{
return (Confentries);
}
/* print the config file */
static void
{
continue;
char **p;
/* existence of opts overrides args */
opts_printword(*p, stream);
}
}
}
}
}
}
#ifdef TESTMODULE
/*
* test main for conf module, usage: a.out conffile
*/
{
if (argc != 2)
err_done(0);
}
#endif /* TESTMODULE */