]> git.ipfire.org Git - thirdparty/squid.git/blob - lib/smblib/smb-errors.c
Merge from trunk. and Save Comm::Connection in IoCallback
[thirdparty/squid.git] / lib / smblib / smb-errors.c
1 #include "config.h"
2
3 /* UNIX SMBlib NetBIOS implementation
4
5 Version 1.0
6 SMBlib Error values etc ...
7
8 Copyright (C) Richard Sharpe, Andrew Tridgell, and Merik Karman, 1996
9
10 */
11
12 /*
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version.
17
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 */
27
28 /* This code ripped out of smbclient, where it was attributed to Merik */
29 /* Karman merik@blackadder.dsh.oz.au */
30 /* Modified by Richard Sharpe to try to make it more bullit proof and */
31 /* ensure we don't overwrite strings when not passed enough space. Also */
32 /* added code to say unknown error codes if we see any */
33
34
35 #include <stdio.h>
36
37 typedef struct {
38 char *name;
39 int code;
40 char *message;
41 } err_code_struct;
42
43 /* Dos Error Messages */
44 err_code_struct dos_msgs[] = {
45 {"ERRbadfunc",1,"Invalid function."},
46 {"ERRbadfile",2,"File not found."},
47 {"ERRbadpath",3,"Directory invalid."},
48 {"ERRnofids",4,"No file descriptors available"},
49 {"ERRnoaccess",5,"Access denied."},
50 {"ERRbadfid",6,"Invalid file handle."},
51 {"ERRbadmcb",7,"Memory control blocks destroyed."},
52 {"ERRnomem",8,"Insufficient server memory to perform the requested function."}
53 ,
54 {"ERRbadmem",9,"Invalid memory block address."},
55 {"ERRbadenv",10,"Invalid environment."},
56 {"ERRbadformat",11,"Invalid format."},
57 {"ERRbadaccess",12,"Invalid open mode."},
58 {"ERRbaddata",13,"Invalid data."},
59 {"ERR",14,"reserved."},
60 {"ERRbaddrive",15,"Invalid drive specified."},
61 {"ERRremcd",16,"A Delete Directory request attempted to remove the server's current directory."},
62 {"ERRdiffdevice",17,"Not same device."},
63 {"ERRnofiles",18,"A File Search command can find no more files matching the specified criteria."},
64 {"ERRbadshare",32,"The sharing mode specified for an Open conflicts with existing FIDs on the file."},
65 {"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."},
66 {"ERRbaddevtyp",66,"The device type is incorrect for a tree connect."},
67 {"ERRbadnetnam",67,"The network name is incorrect or inappropriate."},
68 {"ERRfilexists",80,"The file named in a Create Directory, Make New File or Link request already exists."},
69 {"ERRbadpipe",230,"Pipe invalid."},
70 {"ERRpipebusy",231,"All instances of the requested pipe are busy."},
71 {"ERRpipeclosing",232,"Pipe close in progress."},
72 {"ERRnotconnected",233,"No process on other end of pipe."},
73 {"ERRmoredata",234,"There is more data to be returned."},
74 {"ERRinvapi", 2142, "The API is invalid."},
75 {NULL,-1,NULL}
76 };
77
78 /* Server Error Messages */
79 err_code_struct server_msgs[] = {
80 {"ERRerror",1,"Non-specific error code."},
81 {"ERRbadpw",2,"Bad password - name/password pair in a Tree Connect or Session Setup are invalid."},
82 {"ERRbadtype",3,"reserved."},
83 {"ERRaccess",4,"Network access denied. 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."},
84 {"ERRinvnid",5,"The tree ID (TID) specified in a command was invalid."},
85 {"ERRinvnetname",6,"Invalid network name in tree connect."},
86 {"ERRinvdevice",7,"Invalid device - printer request made to non-printer connection or non-printer request made to printer connection."},
87 {"ERRqfull",49,"Print queue full (files) -- returned by open print file."},
88 {"ERRqtoobig",50,"Print queue full -- no space."},
89 {"ERRqeof",51,"EOF on print queue dump."},
90 {"ERRinvpfid",52,"Invalid print file FID."},
91 {"ERRsmbcmd",64,"The server did not recognize the command received."},
92 {"ERRsrverror",65,"The server encountered an internal error, e.g., system file unavailable."},
93 {"ERRfilespecs",67,"The file handle (FID) and pathname parameters contained an invalid combination of values."},
94 {"ERRreserved",68,"reserved."},
95 {"ERRbadpermits",69,"The access permissions specified for a file or directory are not a valid combination. The server cannot set the requested attribute."},
96 {"ERRreserved",70,"reserved."},
97 {"ERRsetattrmode",71,"The attribute mode in the Set File Attribute request is invalid."},
98 {"ERRpaused",81,"Server is paused."},
99 {"ERRmsgoff",82,"Not receiving messages."},
100 {"ERRnoroom",83,"No room to buffer message."},
101 {"ERRrmuns",87,"Too many remote user names."},
102 {"ERRtimeout",88,"Operation timed out."},
103 {"ERRnoresource",89,"No resources currently available for request."},
104 {"ERRtoomanyuids",90,"Too many UIDs active on this session."},
105 {"ERRbaduid",91,"The UID is not known as a valid ID on this session."},
106 {"ERRusempx",250,"Temp unable to support Raw, use MPX mode."},
107 {"ERRusestd",251,"Temp unable to support Raw, use standard read/write."},
108 {"ERRcontmpx",252,"Continue in MPX mode."},
109 {"ERRreserved",253,"reserved."},
110 {"ERRreserved",254,"reserved."},
111 {"ERRpwdexp",2242,"Password has expired."},
112 {"ERRnosupport",0xFFFF,"Function not supported."},
113 {NULL,-1,NULL}
114 };
115
116 /* Hard Error Messages */
117 err_code_struct hard_msgs[] = {
118 {"ERRnowrite",19,"Attempt to write on write-protected diskette."},
119 {"ERRbadunit",20,"Unknown unit."},
120 {"ERRnotready",21,"Drive not ready."},
121 {"ERRbadcmd",22,"Unknown command."},
122 {"ERRdata",23,"Data error (CRC)."},
123 {"ERRbadreq",24,"Bad request structure length."},
124 {"ERRseek",25 ,"Seek error."},
125 {"ERRbadmedia",26,"Unknown media type."},
126 {"ERRbadsector",27,"Sector not found."},
127 {"ERRnopaper",28,"Printer out of paper."},
128 {"ERRwrite",29,"Write fault."},
129 {"ERRread",30,"Read fault."},
130 {"ERRgeneral",31,"General failure."},
131 {"ERRbadshare",32,"A open conflicts with an existing open."},
132 {"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."},
133 {"ERRwrongdisk",34,"The wrong disk was found in a drive."},
134 {"ERRFCBUnavail",35,"No FCBs are available to process request."},
135 {"ERRsharebufexc",36,"A sharing buffer has been exceeded."},
136 {"ERRdiskfull",39,"The disk is full."},
137 {NULL,-1,NULL}
138 };
139
140 struct {
141 int code;
142 char *class;
143 err_code_struct *err_msgs;
144 } err_classes[] = {
145 {0,"SUCCESS",NULL},
146 {0x01,"ERRDOS",dos_msgs},
147 {0x02,"ERRSRV",server_msgs},
148 {0x03,"ERRHRD",hard_msgs},
149 {0x04,"ERRXOS",NULL},
150 {0xE1,"ERRRMX1",NULL},
151 {0xE2,"ERRRMX2",NULL},
152 {0xE3,"ERRRMX3",NULL},
153 {0xFF,"ERRCMD",NULL},
154 {-1,NULL,NULL}
155 };
156
157 /* Return in the string an error message after decoding the class and code */
158
159 int SMB_Get_SMB_Error_Msg(int err_class, int err_code, char *msg_buf, int len)
160
161 {
162 int i,j;
163 char internal_buf[80];
164
165 for (i=0; err_classes[i].class; i++)
166
167 if (err_classes[i].code == err_class) {
168
169 if (err_classes[i].err_msgs) {
170
171 err_code_struct *err = err_classes[i].err_msgs;
172
173 for (j=0; err[j].name; j++)
174
175 if (err_code == err[j].code) {
176
177 /* Put together the message */
178
179 strncpy(msg_buf, err_classes[i].class, len);
180 strncat(msg_buf, " - ", len - strlen(msg_buf));
181 strncat(msg_buf, err[j].name, len - strlen(msg_buf));
182 strncat(msg_buf, " (", len - strlen(msg_buf));
183 strncat(msg_buf, err[j].message, len - strlen(msg_buf));
184 strncat(msg_buf, ").", len - strlen(msg_buf));
185
186 return(strlen(msg_buf));
187 }
188
189 /* We only get here if the error code is one we don't know about */
190 /* Just print out the code etc ... */
191
192 strncpy(msg_buf, err_classes[i].class, len);
193 strncat(msg_buf, " - ", len - strlen(msg_buf));
194 sprintf(internal_buf, "%d", err_code);
195 strncat(msg_buf, internal_buf, len - strlen(msg_buf));
196 strncat(msg_buf, " (Unknown error code).", len - strlen(msg_buf));
197
198 return(strlen(msg_buf));
199
200 } else {
201
202 strncpy(msg_buf, err_classes[i].class, len);
203 strncat(msg_buf, " - ", len - strlen(msg_buf));
204 sprintf(internal_buf, "%d", err_code);
205 strncat(msg_buf, internal_buf, len - strlen(msg_buf));
206
207 return(strlen(msg_buf));
208
209 }
210
211 }
212
213 /* If we get here, we did not recognize the error class */
214
215 sprintf(internal_buf, "%d", err_class);
216 strncat(msg_buf, internal_buf, len - strlen(msg_buf));
217 strncat(msg_buf, " (Unknown Error Class) - ", len - strlen(msg_buf));
218 sprintf(internal_buf, "%d", err_code);
219 strncat(msg_buf, internal_buf, len - strlen(msg_buf));
220 strncat(msg_buf, "(error code).", len - strlen(msg_buf));
221
222 return(strlen(msg_buf));
223
224 }