summaryrefslogtreecommitdiff
path: root/usr/src/common/net/wanboot/bootconf_errmsg.c
blob: a14a4ce70592ad57d77d458e761f579b34780154 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*
 * 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
 * or http://www.opensolaris.org/os/licensing.
 * 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"

#include <libintl.h>
#include <stdio.h>
#include "wanboot_conf.h"

/*
 * This function maps an error code (one of those defined in wanboot_conf.h)
 * into an error message.
 *
 * Returns: the error message string.
 */
char *
bootconf_errmsg(bc_handle_t *handle)
{
	static char	errmsg[256];
	char		*errstr;
	int		chars;

	errstr = gettext("bootconf_errmsg: internal error");

	switch (handle->bc_error_code) {
	case BC_E_NOERROR:
		errstr = gettext("No error");
		break;
	case BC_E_ACCESS:
		errstr = gettext("Can't open configuration file");
		break;
	case BC_E_NVLIST:
		errstr = gettext("Error creating/adding to nvlist");
		break;
	case BC_E_IOERR:
		errstr = gettext("Error reading/closing configuration file");
		break;
	case BC_E_TOO_LONG:
		if ((chars = snprintf(errmsg, sizeof (errmsg),
		    gettext("Line %d of configuration file is too long"),
		    handle->bc_error_pos)) > 0 && chars < sizeof (errmsg)) {
			errstr = errmsg;
		}
		break;
	case BC_E_SYNTAX:
		if ((chars = snprintf(errmsg, sizeof (errmsg),
		    gettext("Syntax error on line %d of configuration file"),
		    handle->bc_error_pos)) > 0 && chars < sizeof (errmsg)) {
			errstr = errmsg;
		}
		break;
	case BC_E_UNKNOWN_NAME:
		if ((chars = snprintf(errmsg, sizeof (errmsg),
		    gettext("Unknown name on line %d of configuration file"),
		    handle->bc_error_pos)) > 0 && chars < sizeof (errmsg)) {
			errstr = errmsg;
		}
		break;
	case BC_E_ENCRYPTION_ILLEGAL:
		errstr = gettext("Illegal encryption_type");
		break;
	case BC_E_SIGNATURE_ILLEGAL:
		errstr = gettext("Illegal signature_type");
		break;
	case BC_E_CLIENT_AUTH_ILLEGAL:
		errstr = gettext("Illegal client_authentication");
		break;
	case BC_E_SERVER_AUTH_ILLEGAL:
		errstr = gettext("Illegal server_authentication");
		break;
	case BC_E_ROOT_SERVER_BAD:
		errstr = gettext("The root_server URL is malformed");
		break;
	case BC_E_ROOT_SERVER_ABSENT:
		errstr = gettext("A root_server must be provided");
		break;
	case BC_E_ROOT_FILE_ABSENT:
		errstr = gettext("The root_server URL is malformed");
		break;
	case BC_E_BOOT_LOGGER_BAD:
		errstr = gettext("The boot_logger URL is malformed");
		break;
	case BC_E_ENCRYPTED_NOT_SIGNED:
		errstr = gettext("When encryption_type is specified "
		    "signature_type must also be specified");
		break;
	case BC_E_CLIENT_AUTH_NOT_ENCRYPTED:
		errstr = gettext("When client_authentication is \"yes\" "
		    "encryption_type must also be specified");
		break;
	case BC_E_CLIENT_AUTH_NOT_SERVER:
		errstr = gettext("When client_authentication is \"yes\" "
		    "server_authentication must also be \"yes\"");
		break;
	case BC_E_SERVER_AUTH_NOT_SIGNED:
		errstr = gettext("When server_authentication is \"yes\" "
		    "signature_type must also be specified");
		break;
	case BC_E_SERVER_AUTH_NOT_HTTPS:
		errstr = gettext("When server_authentication is \"yes\" "
		    "root_server must specify a secure URL");
		break;
	case BC_E_SERVER_AUTH_NOT_HTTP:
		errstr = gettext("When server_authentication is \"no\" "
		    "root_server must not specify a secure URL");
		break;
	case BC_E_BOOTLOGGER_AUTH_NOT_HTTP:
		errstr = gettext("When server_authentication is \"no\" "
		    "boot_logger must not specify a secure URL");
		break;
	default:
		if ((chars = snprintf(errmsg, sizeof (errmsg),
		    gettext("Unknown error %d"),
		    handle->bc_error_code)) > 0 && chars < sizeof (errmsg)) {
			errstr = errmsg;
		}
	}

	return (errstr);
}