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