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,
66 int line, const char *file)
72 if (unix_ERR_class != SMB_SUCCESS) {
73 eclass = unix_ERR_class;
74 ecode = unix_ERR_code;
75 unix_ERR_class = SMB_SUCCESS;
78 while (unix_smb_errmap[i].smbclass != 0) {
79 if (unix_smb_errmap[i].unixerror == errno) {
80 eclass = unix_smb_errmap[i].smbclass;
81 ecode = unix_smb_errmap[i].smbcode;
88 return error_packet(outbuf,NT_STATUS_OK,eclass,ecode,line,file);
92 /****************************************************************************
93 create an error packet. Normally called using the ERROR() macro
94 ****************************************************************************/
95 int error_packet(char *outbuf,NTSTATUS ntstatus,
96 uint8 eclass,uint32 ecode,int line, const char *file)
98 int outsize = set_message(outbuf,0,0,True);
99 extern uint32 global_client_caps;
102 DEBUG(3,("error string = %s\n",strerror(errno)));
104 if (global_client_caps & CAP_STATUS32) {
105 if (NT_STATUS_V(ntstatus) == 0 && eclass) {
106 ntstatus = dos_to_ntstatus(eclass, ecode);
108 SIVAL(outbuf,smb_rcls,NT_STATUS_V(ntstatus));
109 SSVAL(outbuf,smb_flg2, SVAL(outbuf,smb_flg2)|FLAGS2_32_BIT_ERROR_CODES);
110 DEBUG(3,("error packet at %s(%d) cmd=%d (%s) %s\n",
112 (int)CVAL(outbuf,smb_com),
113 smb_fn_name(CVAL(outbuf,smb_com)),
114 get_nt_error_msg(ntstatus)));
118 if (eclass == 0 && NT_STATUS_V(ntstatus)) {
119 ntstatus_to_dos(ntstatus, &eclass, &ecode);
122 SSVAL(outbuf,smb_flg2, SVAL(outbuf,smb_flg2)&~FLAGS2_32_BIT_ERROR_CODES);
123 SSVAL(outbuf,smb_rcls,eclass);
124 SSVAL(outbuf,smb_err,ecode);
126 DEBUG(3,("error packet at %s(%d) cmd=%d (%s) eclass=%d ecode=%d\n",
128 (int)CVAL(outbuf,smb_com),
129 smb_fn_name(CVAL(outbuf,smb_com)),