1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate *
4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate * with the License.
8*7c478bd9Sstevel@tonic-gate *
9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate *
14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate *
20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate */
26*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
27*7c478bd9Sstevel@tonic-gate
28*7c478bd9Sstevel@tonic-gate #include <libintl.h>
29*7c478bd9Sstevel@tonic-gate #include <stdio.h>
30*7c478bd9Sstevel@tonic-gate #include "wanboot_conf.h"
31*7c478bd9Sstevel@tonic-gate
32*7c478bd9Sstevel@tonic-gate /*
33*7c478bd9Sstevel@tonic-gate * This function maps an error code (one of those defined in wanboot_conf.h)
34*7c478bd9Sstevel@tonic-gate * into an error message.
35*7c478bd9Sstevel@tonic-gate *
36*7c478bd9Sstevel@tonic-gate * Returns: the error message string.
37*7c478bd9Sstevel@tonic-gate */
38*7c478bd9Sstevel@tonic-gate char *
bootconf_errmsg(bc_handle_t * handle)39*7c478bd9Sstevel@tonic-gate bootconf_errmsg(bc_handle_t *handle)
40*7c478bd9Sstevel@tonic-gate {
41*7c478bd9Sstevel@tonic-gate static char errmsg[256];
42*7c478bd9Sstevel@tonic-gate char *errstr;
43*7c478bd9Sstevel@tonic-gate int chars;
44*7c478bd9Sstevel@tonic-gate
45*7c478bd9Sstevel@tonic-gate errstr = gettext("bootconf_errmsg: internal error");
46*7c478bd9Sstevel@tonic-gate
47*7c478bd9Sstevel@tonic-gate switch (handle->bc_error_code) {
48*7c478bd9Sstevel@tonic-gate case BC_E_NOERROR:
49*7c478bd9Sstevel@tonic-gate errstr = gettext("No error");
50*7c478bd9Sstevel@tonic-gate break;
51*7c478bd9Sstevel@tonic-gate case BC_E_ACCESS:
52*7c478bd9Sstevel@tonic-gate errstr = gettext("Can't open configuration file");
53*7c478bd9Sstevel@tonic-gate break;
54*7c478bd9Sstevel@tonic-gate case BC_E_NVLIST:
55*7c478bd9Sstevel@tonic-gate errstr = gettext("Error creating/adding to nvlist");
56*7c478bd9Sstevel@tonic-gate break;
57*7c478bd9Sstevel@tonic-gate case BC_E_IOERR:
58*7c478bd9Sstevel@tonic-gate errstr = gettext("Error reading/closing configuration file");
59*7c478bd9Sstevel@tonic-gate break;
60*7c478bd9Sstevel@tonic-gate case BC_E_TOO_LONG:
61*7c478bd9Sstevel@tonic-gate if ((chars = snprintf(errmsg, sizeof (errmsg),
62*7c478bd9Sstevel@tonic-gate gettext("Line %d of configuration file is too long"),
63*7c478bd9Sstevel@tonic-gate handle->bc_error_pos)) > 0 && chars < sizeof (errmsg)) {
64*7c478bd9Sstevel@tonic-gate errstr = errmsg;
65*7c478bd9Sstevel@tonic-gate }
66*7c478bd9Sstevel@tonic-gate break;
67*7c478bd9Sstevel@tonic-gate case BC_E_SYNTAX:
68*7c478bd9Sstevel@tonic-gate if ((chars = snprintf(errmsg, sizeof (errmsg),
69*7c478bd9Sstevel@tonic-gate gettext("Syntax error on line %d of configuration file"),
70*7c478bd9Sstevel@tonic-gate handle->bc_error_pos)) > 0 && chars < sizeof (errmsg)) {
71*7c478bd9Sstevel@tonic-gate errstr = errmsg;
72*7c478bd9Sstevel@tonic-gate }
73*7c478bd9Sstevel@tonic-gate break;
74*7c478bd9Sstevel@tonic-gate case BC_E_UNKNOWN_NAME:
75*7c478bd9Sstevel@tonic-gate if ((chars = snprintf(errmsg, sizeof (errmsg),
76*7c478bd9Sstevel@tonic-gate gettext("Unknown name on line %d of configuration file"),
77*7c478bd9Sstevel@tonic-gate handle->bc_error_pos)) > 0 && chars < sizeof (errmsg)) {
78*7c478bd9Sstevel@tonic-gate errstr = errmsg;
79*7c478bd9Sstevel@tonic-gate }
80*7c478bd9Sstevel@tonic-gate break;
81*7c478bd9Sstevel@tonic-gate case BC_E_ENCRYPTION_ILLEGAL:
82*7c478bd9Sstevel@tonic-gate errstr = gettext("Illegal encryption_type");
83*7c478bd9Sstevel@tonic-gate break;
84*7c478bd9Sstevel@tonic-gate case BC_E_SIGNATURE_ILLEGAL:
85*7c478bd9Sstevel@tonic-gate errstr = gettext("Illegal signature_type");
86*7c478bd9Sstevel@tonic-gate break;
87*7c478bd9Sstevel@tonic-gate case BC_E_CLIENT_AUTH_ILLEGAL:
88*7c478bd9Sstevel@tonic-gate errstr = gettext("Illegal client_authentication");
89*7c478bd9Sstevel@tonic-gate break;
90*7c478bd9Sstevel@tonic-gate case BC_E_SERVER_AUTH_ILLEGAL:
91*7c478bd9Sstevel@tonic-gate errstr = gettext("Illegal server_authentication");
92*7c478bd9Sstevel@tonic-gate break;
93*7c478bd9Sstevel@tonic-gate case BC_E_ROOT_SERVER_BAD:
94*7c478bd9Sstevel@tonic-gate errstr = gettext("The root_server URL is malformed");
95*7c478bd9Sstevel@tonic-gate break;
96*7c478bd9Sstevel@tonic-gate case BC_E_ROOT_SERVER_ABSENT:
97*7c478bd9Sstevel@tonic-gate errstr = gettext("A root_server must be provided");
98*7c478bd9Sstevel@tonic-gate break;
99*7c478bd9Sstevel@tonic-gate case BC_E_ROOT_FILE_ABSENT:
100*7c478bd9Sstevel@tonic-gate errstr = gettext("The root_server URL is malformed");
101*7c478bd9Sstevel@tonic-gate break;
102*7c478bd9Sstevel@tonic-gate case BC_E_BOOT_LOGGER_BAD:
103*7c478bd9Sstevel@tonic-gate errstr = gettext("The boot_logger URL is malformed");
104*7c478bd9Sstevel@tonic-gate break;
105*7c478bd9Sstevel@tonic-gate case BC_E_ENCRYPTED_NOT_SIGNED:
106*7c478bd9Sstevel@tonic-gate errstr = gettext("When encryption_type is specified "
107*7c478bd9Sstevel@tonic-gate "signature_type must also be specified");
108*7c478bd9Sstevel@tonic-gate break;
109*7c478bd9Sstevel@tonic-gate case BC_E_CLIENT_AUTH_NOT_ENCRYPTED:
110*7c478bd9Sstevel@tonic-gate errstr = gettext("When client_authentication is \"yes\" "
111*7c478bd9Sstevel@tonic-gate "encryption_type must also be specified");
112*7c478bd9Sstevel@tonic-gate break;
113*7c478bd9Sstevel@tonic-gate case BC_E_CLIENT_AUTH_NOT_SERVER:
114*7c478bd9Sstevel@tonic-gate errstr = gettext("When client_authentication is \"yes\" "
115*7c478bd9Sstevel@tonic-gate "server_authentication must also be \"yes\"");
116*7c478bd9Sstevel@tonic-gate break;
117*7c478bd9Sstevel@tonic-gate case BC_E_SERVER_AUTH_NOT_SIGNED:
118*7c478bd9Sstevel@tonic-gate errstr = gettext("When server_authentication is \"yes\" "
119*7c478bd9Sstevel@tonic-gate "signature_type must also be specified");
120*7c478bd9Sstevel@tonic-gate break;
121*7c478bd9Sstevel@tonic-gate case BC_E_SERVER_AUTH_NOT_HTTPS:
122*7c478bd9Sstevel@tonic-gate errstr = gettext("When server_authentication is \"yes\" "
123*7c478bd9Sstevel@tonic-gate "root_server must specify a secure URL");
124*7c478bd9Sstevel@tonic-gate break;
125*7c478bd9Sstevel@tonic-gate case BC_E_SERVER_AUTH_NOT_HTTP:
126*7c478bd9Sstevel@tonic-gate errstr = gettext("When server_authentication is \"no\" "
127*7c478bd9Sstevel@tonic-gate "root_server must not specify a secure URL");
128*7c478bd9Sstevel@tonic-gate break;
129*7c478bd9Sstevel@tonic-gate case BC_E_BOOTLOGGER_AUTH_NOT_HTTP:
130*7c478bd9Sstevel@tonic-gate errstr = gettext("When server_authentication is \"no\" "
131*7c478bd9Sstevel@tonic-gate "boot_logger must not specify a secure URL");
132*7c478bd9Sstevel@tonic-gate break;
133*7c478bd9Sstevel@tonic-gate default:
134*7c478bd9Sstevel@tonic-gate if ((chars = snprintf(errmsg, sizeof (errmsg),
135*7c478bd9Sstevel@tonic-gate gettext("Unknown error %d"),
136*7c478bd9Sstevel@tonic-gate handle->bc_error_code)) > 0 && chars < sizeof (errmsg)) {
137*7c478bd9Sstevel@tonic-gate errstr = errmsg;
138*7c478bd9Sstevel@tonic-gate }
139*7c478bd9Sstevel@tonic-gate }
140*7c478bd9Sstevel@tonic-gate
141*7c478bd9Sstevel@tonic-gate return (errstr);
142*7c478bd9Sstevel@tonic-gate }
143