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;
31 /****************************************************************************
32 create an error packet from a cached error.
33 ****************************************************************************/
34 int cached_error_packet(char *inbuf,char *outbuf,files_struct *fsp,int line)
36 write_bmpx_struct *wbmpx = fsp->wbmpx_ptr;
38 int32 eclass = wbmpx->wr_errclass;
39 int32 err = wbmpx->wr_error;
41 /* We can now delete the auxiliary struct */
43 fsp->wbmpx_ptr = NULL;
44 return error_packet(inbuf,outbuf,eclass,err,line);
55 {EPERM,ERRDOS,ERRnoaccess},
56 {EACCES,ERRDOS,ERRnoaccess},
57 {ENOENT,ERRDOS,ERRbadfile},
58 {ENOTDIR,ERRDOS,ERRbadpath},
59 {EIO,ERRHRD,ERRgeneral},
60 {EBADF,ERRSRV,ERRsrverror},
61 {EINVAL,ERRSRV,ERRsrverror},
62 {EEXIST,ERRDOS,ERRfilexists},
63 {ENFILE,ERRDOS,ERRnofids},
64 {EMFILE,ERRDOS,ERRnofids},
65 {ENOSPC,ERRHRD,ERRdiskfull},
67 {EDQUOT,ERRHRD,ERRdiskfull},
70 {ENOTEMPTY,ERRDOS,ERRnoaccess},
73 {EXDEV,ERRDOS,ERRdiffdevice},
75 {EROFS,ERRHRD,ERRnowrite},
79 /****************************************************************************
80 create an error packet from errno
81 ****************************************************************************/
82 int unix_error_packet(char *inbuf,char *outbuf,int def_class,uint32 def_code,int line)
88 if (unix_ERR_class != SMB_SUCCESS)
90 eclass = unix_ERR_class;
91 ecode = unix_ERR_code;
92 unix_ERR_class = SMB_SUCCESS;
97 while (unix_smb_errmap[i].smbclass != 0)
99 if (unix_smb_errmap[i].unixerror == errno)
101 eclass = unix_smb_errmap[i].smbclass;
102 ecode = unix_smb_errmap[i].smbcode;
109 return(error_packet(inbuf,outbuf,eclass,ecode,line));
113 /****************************************************************************
114 create an error packet. Normally called using the ERROR() macro
115 ****************************************************************************/
116 int error_packet(char *inbuf,char *outbuf,int error_class,uint32 error_code,int line)
118 int outsize = set_message(outbuf,0,0,True);
119 int cmd = CVAL(inbuf,smb_com);
120 int flgs2 = SVAL(outbuf,smb_flg2);
122 if ((flgs2 & FLAGS2_32_BIT_ERROR_CODES) == FLAGS2_32_BIT_ERROR_CODES)
124 SIVAL(outbuf,smb_rcls,error_code);
126 DEBUG( 3, ( "32 bit error packet at line %d cmd=%d (%s) eclass=%08x [%s]\n",
127 line, cmd, smb_fn_name(cmd), error_code, smb_errstr(outbuf) ) );
131 CVAL(outbuf,smb_rcls) = error_class;
132 SSVAL(outbuf,smb_err,error_code);
133 DEBUG( 3, ( "error packet at line %d cmd=%d (%s) eclass=%d ecode=%d\n",
135 (int)CVAL(inbuf,smb_com),
136 smb_fn_name(CVAL(inbuf,smb_com)),
143 DEBUG(3,("error string = %s\n",strerror(errno)));