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