r884: convert samba4 to use [u]int32_t instead of [u]int32
[bbaumbach/samba-autobuild/.git] / source4 / libcli / util / clierror.c
1 /* 
2    Unix SMB/CIFS implementation.
3    client error handling routines
4    Copyright (C) Andrew Tridgell 1994-1998
5    Copyright (C) James Myers 2003
6    
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11    
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16    
17    You should have received a copy of the GNU General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22 #include "includes.h"
23
24
25 /***************************************************************************
26  Return an error message from the last response
27 ****************************************************************************/
28 const char *cli_errstr(struct cli_tree *tree)
29 {   
30         switch (tree->session->transport->error.etype) {
31         case ETYPE_DOS:
32                 return dos_errstr(
33                         tree->session->transport->error.e.dos.eclass, 
34                         tree->session->transport->error.e.dos.ecode);
35         case ETYPE_NT:
36                 return nt_errstr(tree->session->transport->error.e.nt_status);
37
38         case ETYPE_SOCKET:
39                 return "socket_error";
40
41         case ETYPE_NBT:
42                 return "nbt_error";
43
44         case ETYPE_NONE:
45                 return "no_error";
46         }
47         return NULL;
48 }
49
50
51 /* Return the 32-bit NT status code from the last packet */
52 NTSTATUS cli_nt_error(struct cli_tree *tree)
53 {
54         switch (tree->session->transport->error.etype) {
55         case ETYPE_NT:
56                 return tree->session->transport->error.e.nt_status;
57
58         case ETYPE_DOS:
59                 return dos_to_ntstatus(
60                         tree->session->transport->error.e.dos.eclass,
61                         tree->session->transport->error.e.dos.ecode);
62         case ETYPE_SOCKET:
63                 return NT_STATUS_UNSUCCESSFUL;
64
65         case ETYPE_NBT:
66                 return NT_STATUS_UNSUCCESSFUL;
67
68         case ETYPE_NONE:
69                 return NT_STATUS_OK;
70         }
71
72         return NT_STATUS_UNSUCCESSFUL;
73 }
74
75
76 /* Return the DOS error from the last packet - an error class and an error
77    code. */
78 void cli_dos_error(struct cli_state *cli, uint8 *eclass, uint32_t *ecode)
79 {
80         if (cli->transport->error.etype == ETYPE_DOS) {
81                 ntstatus_to_dos(cli->transport->error.e.nt_status, 
82                                 eclass, ecode);
83                 return;
84         }
85
86         if (eclass) *eclass = cli->transport->error.e.dos.eclass;
87         if (ecode)  *ecode  = cli->transport->error.e.dos.ecode;
88 }
89
90
91 /* Return true if the last packet was an error */
92 BOOL cli_is_error(struct cli_tree *tree)
93 {
94         return NT_STATUS_IS_ERR(cli_nt_error(tree));
95 }
96
97 /* Return true if the last error was a DOS error */
98 BOOL cli_is_dos_error(struct cli_tree *tree)
99 {
100         return tree->session->transport->error.etype == ETYPE_DOS;
101 }