2023-12-18 23:13:56 +03:00
/*
2002-01-30 09:08:46 +03:00
Unix SMB / CIFS implementation .
2000-04-25 18:04:06 +04:00
client error handling routines
Copyright ( C ) Andrew Tridgell 1994 - 1998
2003-04-15 18:42:06 +04:00
Copyright ( C ) Jelmer Vernooij 2003
2006-02-24 08:05:09 +03:00
Copyright ( C ) Jeremy Allison 2006
2011-06-25 17:14:25 +04:00
2000-04-25 18:04:06 +04:00
This program is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
2007-07-09 23:25:36 +04:00
the Free Software Foundation ; either version 3 of the License , or
2000-04-25 18:04:06 +04:00
( at your option ) any later version .
2011-06-25 17:14:25 +04:00
2000-04-25 18:04:06 +04:00
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
2011-06-25 17:14:25 +04:00
2000-04-25 18:04:06 +04:00
You should have received a copy of the GNU General Public License
2007-07-10 04:52:41 +04:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2000-04-25 18:04:06 +04:00
*/
# include "includes.h"
2011-05-06 13:47:43 +04:00
# include "libsmb/libsmb.h"
2011-09-22 23:09:00 +04:00
# include "../libcli/smb/smbXcli_base.h"
2000-04-25 18:04:06 +04:00
2006-02-24 08:05:09 +03:00
/****************************************************************************
Return the 32 - bit NT status code from the last packet .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2001-08-27 21:52:23 +04:00
NTSTATUS cli_nt_error ( struct cli_state * cli )
2001-08-10 10:00:33 +04:00
{
2006-02-24 08:05:09 +03:00
/* Deal with socket errors first. */
2011-07-11 18:25:18 +04:00
if ( ! cli_state_is_connected ( cli ) ) {
2011-07-08 11:45:05 +04:00
return NT_STATUS_CONNECTION_DISCONNECTED ;
2006-02-24 08:05:09 +03:00
}
2011-07-08 12:52:22 +04:00
if ( NT_STATUS_IS_DOS ( cli - > raw_status ) ) {
int e_class = NT_STATUS_DOS_CLASS ( cli - > raw_status ) ;
int code = NT_STATUS_DOS_CODE ( cli - > raw_status ) ;
2005-06-25 00:25:18 +04:00
return dos_to_ntstatus ( e_class , code ) ;
2011-07-08 12:52:22 +04:00
}
2001-08-10 10:00:33 +04:00
2011-07-08 12:52:22 +04:00
return cli - > raw_status ;
2001-08-10 10:00:33 +04:00
}
2020-12-15 19:05:34 +03:00
int cli_status_to_errno ( NTSTATUS status )
{
int err ;
if ( NT_STATUS_IS_DOS ( status ) ) {
uint8_t eclass = NT_STATUS_DOS_CLASS ( status ) ;
uint32_t ecode = NT_STATUS_DOS_CODE ( status ) ;
status = dos_to_ntstatus ( eclass , ecode ) ;
}
2021-10-14 16:08:55 +03:00
if ( NT_STATUS_EQUAL ( status , NT_STATUS_STOPPED_ON_SYMLINK ) ) {
2020-12-15 19:05:34 +03:00
/*
* Legacy code from cli_errno , see Samba up to 4.13 : A
* special case for this Vista error . Since its
* high - order byte isn ' t 0xc0 , it won ' t match
* correctly in map_errno_from_nt_status ( ) .
*/
err = EACCES ;
} else {
err = map_errno_from_nt_status ( status ) ;
}
DBG_NOTICE ( " 0x% " PRIx32 " -> %d \n " , NT_STATUS_V ( status ) , err ) ;
return err ;
}
2001-08-10 10:00:33 +04:00
/* Return a UNIX errno appropriate for the error received in the last
packet . */
int cli_errno ( struct cli_state * cli )
{
2020-12-15 19:05:34 +03:00
bool connected ;
int err ;
2006-02-24 08:47:19 +03:00
2020-12-15 19:05:34 +03:00
connected = cli_state_is_connected ( cli ) ;
if ( ! connected ) {
return EPIPE ;
2006-02-24 08:05:09 +03:00
}
2001-08-10 10:00:33 +04:00
2020-12-15 19:05:34 +03:00
err = cli_status_to_errno ( cli - > raw_status ) ;
return err ;
2001-08-10 10:00:33 +04:00
}
/* Return true if the last packet was in error */
2007-10-19 04:40:25 +04:00
bool cli_is_error ( struct cli_state * cli )
2001-08-10 10:00:33 +04:00
{
2006-02-24 08:05:09 +03:00
/* A socket error is always an error. */
2011-07-11 18:25:18 +04:00
if ( ! cli_state_is_connected ( cli ) ) {
return true ;
2006-02-24 08:05:09 +03:00
}
2003-07-30 22:57:37 +04:00
2011-07-08 12:52:22 +04:00
if ( NT_STATUS_IS_DOS ( cli - > raw_status ) ) {
/* Return error if error class in non-zero */
uint8_t rcls = NT_STATUS_DOS_CLASS ( cli - > raw_status ) ;
return rcls ! = 0 ;
}
2001-08-10 10:00:33 +04:00
2011-07-08 12:52:22 +04:00
return NT_STATUS_IS_ERR ( cli - > raw_status ) ;
2001-08-10 10:00:33 +04:00
}
2010-03-25 15:20:56 +03:00
bool cli_state_is_connected ( struct cli_state * cli )
{
if ( cli = = NULL ) {
return false ;
}
if ( ! cli - > initialised ) {
return false ;
}
2011-09-22 23:09:00 +04:00
return smbXcli_conn_is_connected ( cli - > conn ) ;
2010-03-25 15:20:56 +03:00
}