xref: /onnv-gate/usr/src/lib/smbsrv/libsmb/common/smb_status_tbl.c (revision 12508:edb7861a1533)
1*12508Samw@Sun.COM /*
2*12508Samw@Sun.COM  * CDDL HEADER START
3*12508Samw@Sun.COM  *
4*12508Samw@Sun.COM  * The contents of this file are subject to the terms of the
5*12508Samw@Sun.COM  * Common Development and Distribution License (the "License").
6*12508Samw@Sun.COM  * You may not use this file except in compliance with the License.
7*12508Samw@Sun.COM  *
8*12508Samw@Sun.COM  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*12508Samw@Sun.COM  * or http://www.opensolaris.org/os/licensing.
10*12508Samw@Sun.COM  * See the License for the specific language governing permissions
11*12508Samw@Sun.COM  * and limitations under the License.
12*12508Samw@Sun.COM  *
13*12508Samw@Sun.COM  * When distributing Covered Code, include this CDDL HEADER in each
14*12508Samw@Sun.COM  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*12508Samw@Sun.COM  * If applicable, add the following below this CDDL HEADER, with the
16*12508Samw@Sun.COM  * fields enclosed by brackets "[]" replaced with your own identifying
17*12508Samw@Sun.COM  * information: Portions Copyright [yyyy] [name of copyright owner]
18*12508Samw@Sun.COM  *
19*12508Samw@Sun.COM  * CDDL HEADER END
20*12508Samw@Sun.COM  */
21*12508Samw@Sun.COM 
22*12508Samw@Sun.COM /*
23*12508Samw@Sun.COM  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24*12508Samw@Sun.COM  */
25*12508Samw@Sun.COM 
26*12508Samw@Sun.COM /*
27*12508Samw@Sun.COM  * This file provides a text translation service for NT status codes.
28*12508Samw@Sun.COM  */
29*12508Samw@Sun.COM 
30*12508Samw@Sun.COM #include <stdio.h>
31*12508Samw@Sun.COM #include <stdlib.h>
32*12508Samw@Sun.COM 
33*12508Samw@Sun.COM /*
34*12508Samw@Sun.COM  * Include the generated file with ntx_table[]
35*12508Samw@Sun.COM  * See smb_status_gen.awk
36*12508Samw@Sun.COM  */
37*12508Samw@Sun.COM #include "smb_status_tbl.h"
38*12508Samw@Sun.COM static const int ntx_rows = sizeof (ntx_table) / sizeof (ntx_table[0]);
39*12508Samw@Sun.COM 
40*12508Samw@Sun.COM /*
41*12508Samw@Sun.COM  * Comparison function for bsearch(3C).
42*12508Samw@Sun.COM  */
43*12508Samw@Sun.COM static int
xlate_compare(const void * vkey,const void * vrow)44*12508Samw@Sun.COM xlate_compare(const void *vkey, const void *vrow)
45*12508Samw@Sun.COM {
46*12508Samw@Sun.COM 	const smb_status_table_t *key = vkey;
47*12508Samw@Sun.COM 	const smb_status_table_t *row = vrow;
48*12508Samw@Sun.COM 
49*12508Samw@Sun.COM 	if (key->value == row->value)
50*12508Samw@Sun.COM 		return (0);
51*12508Samw@Sun.COM 	if (key->value < row->value)
52*12508Samw@Sun.COM 		return (-1);
53*12508Samw@Sun.COM 	return (1);
54*12508Samw@Sun.COM }
55*12508Samw@Sun.COM 
56*12508Samw@Sun.COM /*
57*12508Samw@Sun.COM  * Translate an ntstatus value to a meaningful text string. If there isn't
58*12508Samw@Sun.COM  * a corresponding text string in the table, the text representation of the
59*12508Samw@Sun.COM  * status value is returned. This uses a static buffer so there is a
60*12508Samw@Sun.COM  * possible concurrency issue if the caller hangs on to this pointer for a
61*12508Samw@Sun.COM  * while but it should be harmless and really remote since the value will
62*12508Samw@Sun.COM  * almost always be found in the table.
63*12508Samw@Sun.COM  */
64*12508Samw@Sun.COM const char *
xlate_nt_status(unsigned int ntstatus)65*12508Samw@Sun.COM xlate_nt_status(unsigned int ntstatus)
66*12508Samw@Sun.COM {
67*12508Samw@Sun.COM 	static char unknown[16];
68*12508Samw@Sun.COM 	smb_status_table_t key;
69*12508Samw@Sun.COM 	const smb_status_table_t *tep;
70*12508Samw@Sun.COM 
71*12508Samw@Sun.COM 	key.value = ntstatus;
72*12508Samw@Sun.COM 	key.name = NULL;
73*12508Samw@Sun.COM 	tep = bsearch(&key, ntx_table, ntx_rows,
74*12508Samw@Sun.COM 	    sizeof (*tep), xlate_compare);
75*12508Samw@Sun.COM 
76*12508Samw@Sun.COM 	if (tep != NULL)
77*12508Samw@Sun.COM 		return (tep->name);
78*12508Samw@Sun.COM 
79*12508Samw@Sun.COM 	(void) sprintf(unknown, "0x%08X", ntstatus);
80*12508Samw@Sun.COM 	return ((const char *)unknown);
81*12508Samw@Sun.COM }
82