2 Unix SMB/CIFS implementation.
3 client error handling routines
4 Copyright (C) Andrew Tridgell 1994-1998
5 Copyright (C) Jelmer Vernooij 2003
6 Copyright (C) Jeremy Allison 2006
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 3 of the License, or
11 (at your option) any later version.
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.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "libsmb/libsmb.h"
24 #include "../libcli/smb/smbXcli_base.h"
26 /****************************************************************************
27 Return the 32-bit NT status code from the last packet.
28 ****************************************************************************/
30 NTSTATUS
cli_nt_error(struct cli_state
*cli
)
32 /* Deal with socket errors first. */
33 if (!cli_state_is_connected(cli
)) {
34 return NT_STATUS_CONNECTION_DISCONNECTED
;
37 if (NT_STATUS_IS_DOS(cli
->raw_status
)) {
38 int e_class
= NT_STATUS_DOS_CLASS(cli
->raw_status
);
39 int code
= NT_STATUS_DOS_CODE(cli
->raw_status
);
40 return dos_to_ntstatus(e_class
, code
);
43 return cli
->raw_status
;
47 /****************************************************************************
48 Return the DOS error from the last packet - an error class and an error
50 ****************************************************************************/
52 void cli_dos_error(struct cli_state
*cli
, uint8_t *eclass
, uint32_t *ecode
)
54 if (!cli_state_is_connected(cli
)) {
56 *ecode
= ERRnotconnected
;
60 if (!NT_STATUS_IS_DOS(cli
->raw_status
)) {
61 ntstatus_to_dos(cli
->raw_status
, eclass
, ecode
);
65 *eclass
= NT_STATUS_DOS_CLASS(cli
->raw_status
);
66 *ecode
= NT_STATUS_DOS_CODE(cli
->raw_status
);
70 /* Return a UNIX errno appropriate for the error received in the last
73 int cli_errno(struct cli_state
*cli
)
77 if (cli_is_nt_error(cli
)) {
78 status
= cli_nt_error(cli
);
79 return map_errno_from_nt_status(status
);
82 if (cli_is_dos_error(cli
)) {
86 cli_dos_error(cli
, &eclass
, &ecode
);
87 status
= dos_to_ntstatus(eclass
, ecode
);
88 return map_errno_from_nt_status(status
);
92 * Yuck! A special case for this Vista error. Since its high-order
93 * byte isn't 0xc0, it doesn't match cli_is_nt_error() above.
95 status
= cli_nt_error(cli
);
96 if (NT_STATUS_V(status
) == NT_STATUS_V(NT_STATUS_INACCESSIBLE_SYSTEM_SHORTCUT
)) {
100 /* for other cases */
104 /* Return true if the last packet was in error */
106 bool cli_is_error(struct cli_state
*cli
)
108 /* A socket error is always an error. */
109 if (!cli_state_is_connected(cli
)) {
113 if (NT_STATUS_IS_DOS(cli
->raw_status
)) {
114 /* Return error if error class in non-zero */
115 uint8_t rcls
= NT_STATUS_DOS_CLASS(cli
->raw_status
);
119 return NT_STATUS_IS_ERR(cli
->raw_status
);
122 /* Return true if the last error was an NT error */
124 bool cli_is_nt_error(struct cli_state
*cli
)
126 /* A socket error is always an NT error. */
127 if (!cli_state_is_connected(cli
)) {
131 return cli_is_error(cli
) && !NT_STATUS_IS_DOS(cli
->raw_status
);
134 /* Return true if the last error was a DOS error */
136 bool cli_is_dos_error(struct cli_state
*cli
)
138 /* A socket error is always a DOS error. */
139 if (!cli_state_is_connected(cli
)) {
143 return cli_is_error(cli
) && NT_STATUS_IS_DOS(cli
->raw_status
);
146 bool cli_state_is_connected(struct cli_state
*cli
)
152 if (!cli
->initialised
) {
156 return smbXcli_conn_is_connected(cli
->conn
);