2 Unix SMB/Netbios implementation.
5 Copyright (C) Andrew Tridgell 1992-1998
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.
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.
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.
24 extern int DEBUGLEVEL;
26 /* these can be set by some functions to override the error codes */
27 int unix_ERR_class=SMB_SUCCESS;
38 {EPERM,ERRDOS,ERRnoaccess},
39 {EACCES,ERRDOS,ERRnoaccess},
40 {ENOENT,ERRDOS,ERRbadfile},
41 {ENOTDIR,ERRDOS,ERRbadpath},
42 {EIO,ERRHRD,ERRgeneral},
43 {EBADF,ERRSRV,ERRsrverror},
44 {EINVAL,ERRSRV,ERRsrverror},
45 {EEXIST,ERRDOS,ERRfilexists},
46 {ENFILE,ERRDOS,ERRnofids},
47 {EMFILE,ERRDOS,ERRnofids},
48 {ENOSPC,ERRHRD,ERRdiskfull},
50 {EDQUOT,ERRHRD,ERRdiskfull},
53 {ENOTEMPTY,ERRDOS,ERRnoaccess},
56 {EXDEV,ERRDOS,ERRdiffdevice},
58 {EROFS,ERRHRD,ERRnowrite},
62 /****************************************************************************
63 create an error packet from errno
64 ****************************************************************************/
65 int unix_error_packet(char *outbuf,int def_class,uint32 def_code,int line)
71 if (unix_ERR_class != SMB_SUCCESS) {
72 eclass = unix_ERR_class;
73 ecode = unix_ERR_code;
74 unix_ERR_class = SMB_SUCCESS;
77 while (unix_smb_errmap[i].smbclass != 0) {
78 if (unix_smb_errmap[i].unixerror == errno) {
79 eclass = unix_smb_errmap[i].smbclass;
80 ecode = unix_smb_errmap[i].smbcode;
87 return error_packet(outbuf,0,eclass,ecode,line);
91 /****************************************************************************
92 create an error packet. Normally called using the ERROR() macro
93 ****************************************************************************/
94 int error_packet(char *outbuf,uint32 ntstatus,
95 uint8 eclass,uint32 ecode,int line)
97 int outsize = set_message(outbuf,0,0,True);
98 extern uint32 global_client_caps;
101 DEBUG(3,("error string = %s\n",strerror(errno)));
103 if (global_client_caps & CAP_STATUS32) {
104 if (ntstatus == 0 && eclass) {
105 ntstatus = dos_to_ntstatus(eclass, ecode);
107 SIVAL(outbuf,smb_rcls,ntstatus);
108 SSVAL(outbuf,smb_flg2, SVAL(outbuf,smb_flg2)|FLAGS2_32_BIT_ERROR_CODES);
109 DEBUG(3,("error packet at line %d cmd=%d (%s) %s\n",
111 (int)CVAL(outbuf,smb_com),
112 smb_fn_name(CVAL(outbuf,smb_com)),
113 get_nt_error_msg(ntstatus)));
117 if (eclass == 0 && ntstatus) {
118 ntstatus_to_dos(ntstatus, &eclass, &ecode);
121 SSVAL(outbuf,smb_flg2, SVAL(outbuf,smb_flg2)&~FLAGS2_32_BIT_ERROR_CODES);
122 SVAL(outbuf,smb_rcls) = eclass;
123 SSVAL(outbuf,smb_err,ecode);
125 DEBUG(3,("error packet at line %d cmd=%d (%s) eclass=%d ecode=%d\n",
127 (int)CVAL(outbuf,smb_com),
128 smb_fn_name(CVAL(outbuf,smb_com)),