RIP BOOL. Convert BOOL -> bool. I found a few interesting
[kai/samba.git] / source / libsmb / smberr.c
1 /* 
2    Unix SMB/CIFS implementation.
3    Copyright (C) Andrew Tridgell 1998
4    
5    This program is free software; you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation; either version 3 of the License, or
8    (at your option) any later version.
9    
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU General Public License for more details.
14    
15    You should have received a copy of the GNU General Public License
16    along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #include "includes.h"
20
21 /* error code stuff - put together by Merik Karman
22    merik@blackadder.dsh.oz.au */
23
24
25 /* There is a big list of error codes and their meanings at:
26
27    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/debug/errlist_7oz7.asp
28
29    and if you don't like MSDN try:
30
31    http://www.siris.gr/computers/library/error.htm
32
33 */
34
35 typedef const struct
36 {
37   const char *name;
38   int code;
39   const char *message;
40 } err_code_struct;
41
42 /* Dos Error Messages */
43 err_code_struct dos_msgs[] = {
44   {"ERRbadfunc",ERRbadfunc,"Invalid function."},
45   {"ERRbadfile",ERRbadfile,"File not found."},
46   {"ERRbadpath",ERRbadpath,"Directory invalid."},
47   {"ERRnofids",ERRnofids,"No file descriptors available"},
48   {"ERRnoaccess",ERRnoaccess,"Access denied."},
49   {"ERRbadfid",ERRbadfid,"Invalid file handle."},
50   {"ERRbadmcb",ERRbadmcb,"Memory control blocks destroyed."},
51   {"ERRnomem",ERRnomem,"Insufficient server memory to perform the requested function."},
52   {"ERRbadmem",ERRbadmem,"Invalid memory block address."},
53   {"ERRbadenv",ERRbadenv,"Invalid environment."},
54   {"ERRbadformat",11,"Invalid format."},
55   {"ERRbadaccess",ERRbadaccess,"Invalid open mode."},
56   {"ERRbaddata",ERRbaddata,"Invalid data."},
57   {"ERRres",ERRres,"reserved."},
58   {"ERRbaddrive",ERRbaddrive,"Invalid drive specified."},
59   {"ERRremcd",ERRremcd,"A Delete Directory request attempted  to  remove  the  server's  current directory."},
60   {"ERRdiffdevice",ERRdiffdevice,"Not same device."},
61   {"ERRnofiles",ERRnofiles,"A File Search command can find no more files matching the specified criteria."},
62   {"ERRbadshare",ERRbadshare,"The sharing mode specified for an Open conflicts with existing  FIDs  on the file."},
63   {"ERRlock",ERRlock,"A Lock request conflicted with an existing lock or specified an  invalid mode,  or an Unlock requested attempted to remove a lock held by another process."},
64   {"ERRunsup", ERRunsup, "The operation is unsupported"},
65   {"ERRnosuchshare", ERRnosuchshare, "You specified an invalid share name"},
66   {"ERRfilexists",ERRfilexists,"The file named in a Create Directory, Make  New  File  or  Link  request already exists."},
67   {"ERRinvalidname",ERRinvalidname, "Invalid name"},
68   {"ERRbadpipe",ERRbadpipe,"Pipe invalid."},
69   {"ERRpipebusy",ERRpipebusy,"All instances of the requested pipe are busy."},
70   {"ERRpipeclosing",ERRpipeclosing,"Pipe close in progress."},
71   {"ERRnotconnected",ERRnotconnected,"No process on other end of pipe."},
72   {"ERRmoredata",ERRmoredata,"There is more data to be returned."},
73   {"ERRinvgroup",ERRinvgroup,"Invalid workgroup (try the -W option)"},
74   {"ERRlogonfailure",ERRlogonfailure,"Logon failure"},
75   {"ERRdiskfull",ERRdiskfull,"Disk full"},
76   {"ERRgeneral",ERRgeneral, "General failure"},
77   {"ERRbaddirectory", ERRbaddirectory, "Bad directory name"},
78   {"ERRunknownlevel",ERRunknownlevel, "Unknown info level"},
79   {NULL,-1,NULL}};
80
81 /* Server Error Messages */
82 err_code_struct server_msgs[] = {
83   {"ERRerror",1,"Non-specific error code."},
84   {"ERRbadpw",2,"Bad password - name/password pair in a Tree Connect or Session Setup are invalid."},
85   {"ERRbadtype",3,"reserved."},
86   {"ERRaccess",4,"The requester does not have  the  necessary  access  rights  within  the specified  context for the requested function. The context is defined by the TID or the UID."},
87   {"ERRinvnid",5,"The tree ID (TID) specified in a command was invalid."},
88   {"ERRinvnetname",6,"Invalid network name in tree connect."},
89   {"ERRinvdevice",7,"Invalid device - printer request made to non-printer connection or  non-printer request made to printer connection."},
90   {"ERRqfull",49,"Print queue full (files) -- returned by open print file."},
91   {"ERRqtoobig",50,"Print queue full -- no space."},
92   {"ERRqeof",51,"EOF on print queue dump."},
93   {"ERRinvpfid",52,"Invalid print file FID."},
94   {"ERRsmbcmd",64,"The server did not recognize the command received."},
95   {"ERRsrverror",65,"The server encountered an internal error, e.g., system file unavailable."},
96   {"ERRfilespecs",67,"The file handle (FID) and pathname parameters contained an invalid  combination of values."},
97   {"ERRreserved",68,"reserved."},
98   {"ERRbadpermits",69,"The access permissions specified for a file or directory are not a valid combination.  The server cannot set the requested attribute."},
99   {"ERRreserved",70,"reserved."},
100   {"ERRsetattrmode",71,"The attribute mode in the Set File Attribute request is invalid."},
101   {"ERRpaused",81,"Server is paused."},
102   {"ERRmsgoff",82,"Not receiving messages."},
103   {"ERRnoroom",83,"No room to buffer message."},
104   {"ERRrmuns",87,"Too many remote user names."},
105   {"ERRtimeout",88,"Operation timed out."},
106   {"ERRnoresource",89,"No resources currently available for request."},
107   {"ERRtoomanyuids",90,"Too many UIDs active on this session."},
108   {"ERRbaduid",91,"The UID is not known as a valid ID on this session."},
109   {"ERRusempx",250,"Temp unable to support Raw, use MPX mode."},
110   {"ERRusestd",251,"Temp unable to support Raw, use standard read/write."},
111   {"ERRcontmpx",252,"Continue in MPX mode."},
112   {"ERRreserved",253,"reserved."},
113   {"ERRreserved",254,"reserved."},
114   {"ERRnosupport",0xFFFF,"Function not supported."},
115   {NULL,-1,NULL}};
116
117 /* Hard Error Messages */
118 err_code_struct hard_msgs[] = {
119   {"ERRnowrite",19,"Attempt to write on write-protected diskette."},
120   {"ERRbadunit",20,"Unknown unit."},
121   {"ERRnotready",21,"Drive not ready."},
122   {"ERRbadcmd",22,"Unknown command."},
123   {"ERRdata",23,"Data error (CRC)."},
124   {"ERRbadreq",24,"Bad request structure length."},
125   {"ERRseek",25 ,"Seek error."},
126   {"ERRbadmedia",26,"Unknown media type."},
127   {"ERRbadsector",27,"Sector not found."},
128   {"ERRnopaper",28,"Printer out of paper."},
129   {"ERRwrite",29,"Write fault."},
130   {"ERRread",30,"Read fault."},
131   {"ERRgeneral",31,"General failure."},
132   {"ERRbadshare",32,"An open conflicts with an existing open."},
133   {"ERRlock",33,"A Lock request conflicted with an existing lock or specified an invalid mode, or an Unlock requested attempted to remove a lock held by another process."},
134   {"ERRwrongdisk",34,"The wrong disk was found in a drive."},
135   {"ERRFCBUnavail",35,"No FCBs are available to process request."},
136   {"ERRsharebufexc",36,"A sharing buffer has been exceeded."},
137   {NULL,-1,NULL}};
138
139
140 const struct
141 {
142   int code;
143   const char *e_class;
144   err_code_struct *err_msgs;
145 } err_classes[] = { 
146   {0,"SUCCESS",NULL},
147   {0x01,"ERRDOS",dos_msgs},
148   {0x02,"ERRSRV",server_msgs},
149   {0x03,"ERRHRD",hard_msgs},
150   {0x04,"ERRXOS",NULL},
151   {0xE1,"ERRRMX1",NULL},
152   {0xE2,"ERRRMX2",NULL},
153   {0xE3,"ERRRMX3",NULL},
154   {0xFF,"ERRCMD",NULL},
155   {-1,NULL,NULL}};
156
157
158 /****************************************************************************
159 return a SMB error name from a class and code
160 ****************************************************************************/
161 const char *smb_dos_err_name(uint8 e_class, uint16 num)
162 {
163         static pstring ret;
164         int i,j;
165         
166         for (i=0;err_classes[i].e_class;i++)
167                 if (err_classes[i].code == e_class) {
168                         if (err_classes[i].err_msgs) {
169                                 err_code_struct *err = err_classes[i].err_msgs;
170                                 for (j=0;err[j].name;j++)
171                                         if (num == err[j].code) {
172                                                 return err[j].name;
173                                         }
174                         }
175                         slprintf(ret, sizeof(ret) - 1, "%d",num);
176                         return ret;
177                 }
178         
179         slprintf(ret, sizeof(ret) - 1, "Error: Unknown error class (%d,%d)",e_class,num);
180         return(ret);
181 }
182
183 /* Return a string for a DOS error */
184
185 const char *get_dos_error_msg(WERROR result)
186 {
187         uint16 errnum;
188
189         errnum = W_ERROR_V(result);
190
191         return smb_dos_err_name(ERRDOS, errnum);
192 }
193
194 /****************************************************************************
195 return a SMB error class name as a string.
196 ****************************************************************************/
197 const char *smb_dos_err_class(uint8 e_class)
198 {
199         static pstring ret;
200         int i;
201         
202         for (i=0;err_classes[i].e_class;i++) {
203                 if (err_classes[i].code == e_class) {
204                         return err_classes[i].e_class;
205                 }
206         }
207                 
208         slprintf(ret, sizeof(ret) - 1, "Error: Unknown class (%d)",e_class);
209         return(ret);
210 }
211
212 /****************************************************************************
213 return a SMB string from an SMB buffer
214 ****************************************************************************/
215 char *smb_dos_errstr(char *inbuf)
216 {
217         static pstring ret;
218         int e_class = CVAL(inbuf,smb_rcls);
219         int num = SVAL(inbuf,smb_err);
220         int i,j;
221         
222         for (i=0;err_classes[i].e_class;i++)
223                 if (err_classes[i].code == e_class) {
224                         if (err_classes[i].err_msgs) {
225                                 err_code_struct *err = err_classes[i].err_msgs;
226                                 for (j=0;err[j].name;j++)
227                                         if (num == err[j].code) {
228                                                 if (DEBUGLEVEL > 0)
229                                                         slprintf(ret, sizeof(ret) - 1, "%s - %s (%s)",
230                                                                  err_classes[i].e_class,
231                                                                  err[j].name,err[j].message);
232                                                 else
233                                                         slprintf(ret, sizeof(ret) - 1, "%s - %s",
234                                                                  err_classes[i].e_class,err[j].name);
235                                                 return ret;
236                                         }
237                         }
238                         
239                         slprintf(ret, sizeof(ret) - 1, "%s - %d",err_classes[i].e_class,num);
240                         return ret;
241                 }
242         
243         slprintf(ret, sizeof(ret) - 1, "Error: Unknown error (%d,%d)",e_class,num);
244         return(ret);
245 }
246
247 /*****************************************************************************
248 map a unix errno to a win32 error
249  *****************************************************************************/
250 WERROR map_werror_from_unix(int error)
251 {
252         NTSTATUS status = map_nt_error_from_unix(error);
253         return ntstatus_to_werror(status);
254 }