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