bootconf.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* 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 2003 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Functions for accessing the wanboot.conf(4) file.
*/
#include <stdio.h>
#include <string.h>
#include <parseURL.h>
#include <netboot_paths.h>
#include <wanboot_conf.h>
/*
* Parser helper macros:
*/
#define skip_whitespace(p) while (is_whitespace(*(p))) ++p
/*
* Table of valid wanboot.conf(4) names:
*/
static const char *bootconf_names[] = {
};
/*
* Check whether 'name' is valid within wanboot.conf(4).
*/
static boolean_t
valid_name(const char *name)
{
int i;
for (i = 0; bootconf_names[i] != NULL; ++i) {
return (B_TRUE);
}
}
return (B_FALSE);
}
/*
* parse_bootconf() parses a wanboot.conf(4) file and, if there are no
* errors, creates an nvpair list of the name-value pairs defined therein.
*
* Lines must be blank or of the form:
* [name=value] [# comment]
*
* Returns:
* B_TRUE - success
* B_FALSE - error (return code in handle->bc_error_code, line number
* on which the error occurred in handle->bc_error_pos)
*/
static boolean_t
{
char line[BC_MAX_LINE_LENGTH];
goto cleanup;
}
goto cleanup;
}
int i;
char *p = line;
char quote;
++(handle->bc_error_pos);
/*
* Strip off the '\n' at the end of the line.
*/
goto cleanup;
goto cleanup;
}
/*
* Skip leading whitespace.
*/
skip_whitespace(p);
/*
* Blank line/comment-only line?
*/
if (*p == '\0' || *p == '#') {
continue;
}
/*
* Get start and end pointers to the 'name'.
*/
ks = p;
while (!is_whitespace(*p) && *p != '=') {
++p;
}
ke = p;
/*
* Must be of the form "name=value"; skip leading and
* trailing whitespace.
*/
skip_whitespace(p);
if (*p == '=') {
++p; /* skip '=' */
skip_whitespace(p);
} else {
goto cleanup;
}
/*
* The 'value' may be quoted.
*/
if (*p == '"' || *p == '\'') {
quote = *p;
++p; /* skip '"' */
} else {
quote = '\0';
}
/*
* Get start and end pointers to the 'value' string.
* Note that 'value' may be the empty string.
*/
vs = p;
while (*p != '\0' && *p != quote) {
/*
* White space that is not part of a quoted
* value signals end of value.
*/
break;
}
++p;
}
}
ve = p;
/*
* If 'value' string was quoted, ensure that there is a
* balancing close-quote and skip it.
*/
if (quote != '\0') {
if (*p == quote) {
++p;
} else {
goto cleanup;
}
}
/*
* Verify line is well-formed; the rest of the line should
* be blank or comment.
*/
skip_whitespace(p);
if (*p != '\0' && *p != '#') {
goto cleanup;
}
/*
* Nul-terminate both the 'name' and the 'value' string.
*/
*ke = '\0';
*ve = '\0';
/*
* Check that this is a valid parameter name.
*/
if (!valid_name(ks)) {
goto cleanup;
}
/*
* Add the name-value pair to the nvpair list.
*/
goto cleanup;
}
}
/*
* Verify that we didn't exit the parsing loop because of an
* input error.
*/
goto cleanup;
}
/*
* Close the file if open and free the nvlist if an error occurred.
*/
}
}
return (B_FALSE);
}
/*
* All is well.
*/
return (B_TRUE);
}
/*
* valid_encryption() validitate the encryption type value
*
* Returns:
* B_TRUE - success
* B_FALSE - error (return code in handle->bc_error_code)
*/
static boolean_t
{
char *strval;
/*
* Until proven otherwise, encryption is not enabled.
*/
*is_encrypted = B_FALSE;
/*
* If encryption_type was specified then it must be either
* "3des", "aes" or "".
*/
return (B_FALSE);
}
*is_encrypted = B_TRUE;
}
}
return (B_TRUE);
}
/*
* valid_signature() validates the signature type value
*
* Returns:
* B_TRUE - success
* B_FALSE - error (return code in handle->bc_error_code)
*/
static boolean_t
{
char *strval;
/*
* Until proven otherwise, signing is not enabled.
*/
/*
* If signature_type was specified then it must be either
* "sha1" or "".
*/
return (B_FALSE);
}
}
}
return (B_TRUE);
}
/*
* valid_client_authentication() validates the client authentication value
*
* Returns:
* B_TRUE - success
* B_FALSE - error (return code in handle->bc_error_code)
*/
static boolean_t
{
char *strval;
/*
* Until proven otherwise, authentication is not enabled.
*/
/*
* If client_authentication was specified then it must be either
* "yes" or "no".
*/
return (B_FALSE);
}
}
return (B_TRUE);
}
/*
* valid_server_authentication() validates the server authentication value
*
* Returns:
* B_TRUE - success
* B_FALSE - error (return code in handle->bc_error_code)
*/
static boolean_t
{
char *strval;
/*
* Until proven otherwise, authentication is not enabled.
*/
/*
* If server_authentication was specified then it must be either
* "yes" or"no".
*/
return (B_FALSE);
}
}
return (B_TRUE);
}
/*
* valid_root_server() validates the root server and root file values
*
* Returns:
* B_TRUE - success
* B_FALSE - error (return code in handle->bc_error_code)
*/
static boolean_t
{
char *strval;
/*
* Until proven otherwise, assume not https.
*/
/*
* Check whether a root_server URL was specified, and if so whether
* it is a secure URL (of the form https://...).
*/
return (B_FALSE);
}
/*
* Ensure that a root_file was also specified.
*/
return (B_FALSE);
}
} else {
return (B_FALSE);
}
return (B_TRUE);
}
/*
* valid_boot_logger() validates the boot_logger value
*
* Returns:
* B_TRUE - success
* B_FALSE - error (return code in handle->bc_error_code)
*/
static boolean_t
{
char *strval;
/*
* Until proven otherwise, assume not https.
*/
/*
* If boot_logger was specified, make sure that it is a valid URL.
*/
return (B_FALSE);
}
}
return (B_TRUE);
}
/*
* validate_bootconf() checks the consistency of the nvpair list representation
* of a wanboot.conf(4) file as returned by the parse_bootconf() function.
*
* Returns:
* B_TRUE - success
* B_FALSE - error (return code in handle->bc_error_code)
*/
static boolean_t
{
/*
* Check to make sure option values are valid.
*/
return (B_FALSE);
/*
* Now do consistency checking between bootconf settings.
*/
if (is_encrypted && !is_signed) {
return (B_FALSE);
}
if (client_is_authenticated) {
if (!(is_encrypted && is_signed)) {
return (B_FALSE);
}
if (!server_is_authenticated) {
return (B_FALSE);
}
}
if (server_is_authenticated) {
if (!is_signed) {
return (B_FALSE);
}
if (!rootserver_is_https) {
return (B_FALSE);
}
} else if (rootserver_is_https) {
return (B_FALSE);
} else if (bootlogger_is_https) {
return (B_FALSE);
}
return (B_TRUE);
}
/*
* bootconf_end() cleans up once we're done accessing the nvpair list
* representation of wanboot.conf(4).
*/
void
{
}
}
/*
* bootconf_init() must be called to initialize 'handle' before bootconf_get()
* can be used to access values from the wanboot.conf(4) file.
*/
int
{
/*
* Initalise the handle's fields to sensible values.
*/
handle->bc_error_pos = 0;
/*
* Provide a default path for the bootconf file if none was given.
*/
}
/*
* Check that we can successfully parse and validate the file.
*/
return (BC_SUCCESS);
}
/*
*/
return (BC_FAILURE);
}
/*
* bootconf_get() returns the value of a parameter in the wanboot.conf(4) file.
*
* Returns:
* != NULL - the given value
* == NULL - value not found or is empty
*/
char *
{
char *strval;
/*
* Look up the name in bc_nvl and return its value if found.
*/
}
return (NULL);
}