xref: /titanic_52/usr/src/common/net/wanboot/http_errorstr.c (revision 06e46062ef4f5f4b687cbafb4518fb123fe23920)
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 2002-2003 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include <unistd.h>
30 #include <string.h>
31 #include <errno.h>
32 #include <sys/types.h>
33 
34 #include <openssl/ssl.h>
35 #include <openssl/err.h>
36 
37 #include <boot_http.h>
38 
39 #ifndef _BOOT
40 extern	const char *hstrerror(int);
41 #endif
42 
43 static const char *errlist[] = {
44 	/* EHTTP_BADARG */	"One or more arguments are not valid",
45 	/* EHTTP_NOMEM */	"Insufficient memory",
46 	/* EHTTP_CONCLOSED */	"SSL connection is closed (but maybe not the"
47 				" underlying connection)",
48 	/* EHTTP_UNEXPECTED */	"SSL connection returned unexpected error",
49 	/* EHTTP_EOFERR */	"Unexpected/premature EOF",
50 	/* EHTTP_NOCERT */	"No certificate was presented",
51 	/* EHTTP_NOMATCH */	"'Peername' doesn't match 'host' or no "
52 				"matching entry",
53 	/* EHTTP_NODATA */	"No data was returned",
54 	/* EHTTP_NOT_1_1 */	"Not a HTTP/1.1 server",
55 	/* EHTTP_BADHDR */	"Invalid header",
56 	/* EHTTP_OORANGE */	"Request header line out of range",
57 	/* EHTTP_NORESP */	"No response or partial response received",
58 	/* EHTTP_BADRESP */	"Bad response or error response returned",
59 	/* EHTTP_NOHEADER */	"Chunked header expected but not found",
60 	/* EHTTP_NOBOUNDARY */	"Boundary line expected but not found",
61 	/* EHTTP_NOTMULTI */	"This is not a multipart transfer",
62 	/* EHTTP_BADSIZE */	"Could not determine msg body size"
63 };
64 static int	nerrs = { sizeof (errlist) / sizeof (errlist[0]) };
65 
66 /*
67  * http_errorstr - print the error associated with the source and errorcode
68  *
69  * Arguments:
70  *   errsrc	- Which library caused the error (as returned by
71  *		  http_get_lasterr())
72  *   error	- The error code returned
73  *
74  * Returns:
75  *   Pointer to error string for this error.
76  */
77 char const *
78 http_errorstr(uint_t errsrc, ulong_t error)
79 {
80 	char const *msg = NULL;
81 #ifdef _BOOT
82 	static char message[128];
83 #endif
84 	switch (errsrc) {
85 	case ERRSRC_SYSTEM:
86 		msg = strerror(error);
87 		if (msg == NULL)
88 			msg = "Unknown system error";
89 		break;
90 	case ERRSRC_LIBHTTP:
91 		if (error == 0 || error > nerrs)
92 			msg = "Unknown libhttp error";
93 		else
94 			msg = errlist[error - 1];
95 		break;
96 	case ERRSRC_RESOLVE:
97 #ifdef _BOOT
98 		(void) sprintf(message, "Host retrieval error %lu\n", error);
99 		msg = message;
100 #else
101 		msg = hstrerror(error);
102 #endif
103 		break;
104 	case ERRSRC_VERIFERR:
105 		msg = X509_verify_cert_error_string(error);
106 		break;
107 	case ERRSRC_LIBSSL:
108 		msg = ERR_error_string(error, NULL);
109 		break;
110 	default:
111 		msg = "Unknown error";
112 		break;
113 	}
114 
115 	return (msg);
116 }
117