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