not all versions of env like more than one argument...
[Samba.git] / source3 / libsmb / smberr.c
blobf4a13983f01e01cf7c935b67d4a654ca3f9937c9
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 3 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, see <http://www.gnu.org/licenses/>.
19 #include "includes.h"
21 /* error code stuff - put together by Merik Karman
22 merik@blackadder.dsh.oz.au */
25 /* There is a big list of error codes and their meanings at:
27 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/debug/errlist_7oz7.asp
29 and if you don't like MSDN try:
31 http://www.siris.gr/computers/library/error.htm
35 typedef const struct
37 const char *name;
38 int code;
39 const char *message;
40 } err_code_struct;
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}};
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}};
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}};
140 const struct
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}};
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)
163 char *result;
164 int i,j;
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;
175 result = talloc_asprintf(talloc_tos(), "%d", num);
176 SMB_ASSERT(result != NULL);
177 return result;
180 result = talloc_asprintf(talloc_tos(), "Error: Unknown error class "
181 "(%d,%d)", e_class,num);
182 SMB_ASSERT(result != NULL);
183 return result;
186 /* Return a string for a DOS error */
188 const 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 const char *smb_dos_err_class(uint8 e_class)
202 char *result;
203 int i;
205 for (i=0;err_classes[i].e_class;i++) {
206 if (err_classes[i].code == e_class) {
207 return err_classes[i].e_class;
211 result = talloc_asprintf(talloc_tos(), "Error: Unknown class (%d)",
212 e_class);
213 SMB_ASSERT(result != NULL);
214 return result;
217 /****************************************************************************
218 return a SMB string from an SMB buffer
219 ****************************************************************************/
220 char *smb_dos_errstr(char *inbuf)
222 char *result;
223 int e_class = CVAL(inbuf,smb_rcls);
224 int num = SVAL(inbuf,smb_err);
225 int i,j;
227 for (i=0;err_classes[i].e_class;i++)
228 if (err_classes[i].code == e_class) {
229 if (err_classes[i].err_msgs) {
230 err_code_struct *err = err_classes[i].err_msgs;
231 for (j=0;err[j].name;j++)
232 if (num == err[j].code) {
233 if (DEBUGLEVEL > 0)
234 result = talloc_asprintf(
235 talloc_tos(), "%s - %s (%s)",
236 err_classes[i].e_class,
237 err[j].name,err[j].message);
238 else
239 result = talloc_asprintf(
240 talloc_tos(), "%s - %s",
241 err_classes[i].e_class,
242 err[j].name);
243 goto done;
247 result = talloc_asprintf(talloc_tos(), "%s - %d",
248 err_classes[i].e_class, num);
249 goto done;
252 result = talloc_asprintf(talloc_tos(), "Error: Unknown error (%d,%d)",
253 e_class, num);
254 done:
255 SMB_ASSERT(result != NULL);
256 return result;
259 /*****************************************************************************
260 map a unix errno to a win32 error
261 *****************************************************************************/
262 WERROR map_werror_from_unix(int error)
264 NTSTATUS status = map_nt_error_from_unix(error);
265 return ntstatus_to_werror(status);