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