r4627: - simplified the dcerpc auth code using a common function
[samba.git] / source4 / librpc / rpc / dcerpc_error.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    dcerpc fault functions
5
6    Copyright (C) Stefan Metzmacher 2004
7    
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12    
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17    
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 #include "includes.h"
24
25 struct dcerpc_fault_table {
26         const char *errstr;
27         uint32_t faultcode;
28 };
29
30 static const struct dcerpc_fault_table dcerpc_faults[] =
31 {
32         { "DCERPC_FAULT_OP_RNG_ERROR",          DCERPC_FAULT_OP_RNG_ERROR },
33         { "DCERPC_FAULT_UNK_IF",                DCERPC_FAULT_UNK_IF },
34         { "DCERPC_FAULT_NDR",                   DCERPC_FAULT_NDR },
35         { "DCERPC_FAULT_INVALID_TAG",           DCERPC_FAULT_INVALID_TAG },
36         { "DCERPC_FAULT_CONTEXT_MISMATCH",      DCERPC_FAULT_CONTEXT_MISMATCH },
37         { "DCERPC_FAULT_OTHER",                 DCERPC_FAULT_OTHER },
38         { "DCERPC_FAULT_LOGON_FAILURE",         DCERPC_FAULT_LOGON_FAILURE },
39
40         { NULL,                                 0}      
41 };
42
43 const char *dcerpc_errstr(TALLOC_CTX *mem_ctx, uint32_t fault_code)
44 {
45         int idx = 0;
46
47         while (dcerpc_faults[idx].errstr != NULL) {
48                 if (dcerpc_faults[idx].faultcode == fault_code) {
49                         return dcerpc_faults[idx].errstr;
50                 }
51                 idx++;
52         }
53
54         return talloc_asprintf(mem_ctx, "DCERPC fault 0x%08x", fault_code);
55 }