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