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