2 * Copyright (C) 1996-2014 The Squid Software Foundation and contributors
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
9 /* UNIX SMBlib NetBIOS implementation
12 SMBlib Error values etc ...
14 Copyright (C) Richard Sharpe, Andrew Tridgell, and Merik Karman, 1996
18 This program is free software; you can redistribute it and/or modify
19 it under the terms of the GNU General Public License as published by
20 the Free Software Foundation; either version 2 of the License, or
21 (at your option) any later version.
23 This program is distributed in the hope that it will be useful,
24 but WITHOUT ANY WARRANTY; without even the implied warranty of
25 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 GNU General Public License for more details.
28 You should have received a copy of the GNU General Public License
29 along with this program; if not, write to the Free Software
30 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
33 /* This code ripped out of smbclient, where it was attributed to Merik */
34 /* Karman merik@blackadder.dsh.oz.au */
35 /* Modified by Richard Sharpe to try to make it more bullit proof and */
36 /* ensure we don't overwrite strings when not passed enough space. Also */
37 /* added code to say unknown error codes if we see any */
47 /* Dos Error Messages */
48 err_code_struct dos_msgs
[] = {
49 {"ERRbadfunc",1,"Invalid function."},
50 {"ERRbadfile",2,"File not found."},
51 {"ERRbadpath",3,"Directory invalid."},
52 {"ERRnofids",4,"No file descriptors available"},
53 {"ERRnoaccess",5,"Access denied."},
54 {"ERRbadfid",6,"Invalid file handle."},
55 {"ERRbadmcb",7,"Memory control blocks destroyed."},
56 {"ERRnomem",8,"Insufficient server memory to perform the requested function."}
58 {"ERRbadmem",9,"Invalid memory block address."},
59 {"ERRbadenv",10,"Invalid environment."},
60 {"ERRbadformat",11,"Invalid format."},
61 {"ERRbadaccess",12,"Invalid open mode."},
62 {"ERRbaddata",13,"Invalid data."},
63 {"ERR",14,"reserved."},
64 {"ERRbaddrive",15,"Invalid drive specified."},
65 {"ERRremcd",16,"A Delete Directory request attempted to remove the server's current directory."},
66 {"ERRdiffdevice",17,"Not same device."},
67 {"ERRnofiles",18,"A File Search command can find no more files matching the specified criteria."},
68 {"ERRbadshare",32,"The sharing mode specified for an Open conflicts with existing FIDs on the file."},
69 {"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."},
70 {"ERRbaddevtyp",66,"The device type is incorrect for a tree connect."},
71 {"ERRbadnetnam",67,"The network name is incorrect or inappropriate."},
72 {"ERRfilexists",80,"The file named in a Create Directory, Make New File or Link request already exists."},
73 {"ERRbadpipe",230,"Pipe invalid."},
74 {"ERRpipebusy",231,"All instances of the requested pipe are busy."},
75 {"ERRpipeclosing",232,"Pipe close in progress."},
76 {"ERRnotconnected",233,"No process on other end of pipe."},
77 {"ERRmoredata",234,"There is more data to be returned."},
78 {"ERRinvapi", 2142, "The API is invalid."},
82 /* Server Error Messages */
83 err_code_struct server_msgs
[] = {
84 {"ERRerror",1,"Non-specific error code."},
85 {"ERRbadpw",2,"Bad password - name/password pair in a Tree Connect or Session Setup are invalid."},
86 {"ERRbadtype",3,"reserved."},
87 {"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."},
88 {"ERRinvnid",5,"The tree ID (TID) specified in a command was invalid."},
89 {"ERRinvnetname",6,"Invalid network name in tree connect."},
90 {"ERRinvdevice",7,"Invalid device - printer request made to non-printer connection or non-printer request made to printer connection."},
91 {"ERRqfull",49,"Print queue full (files) -- returned by open print file."},
92 {"ERRqtoobig",50,"Print queue full -- no space."},
93 {"ERRqeof",51,"EOF on print queue dump."},
94 {"ERRinvpfid",52,"Invalid print file FID."},
95 {"ERRsmbcmd",64,"The server did not recognize the command received."},
96 {"ERRsrverror",65,"The server encountered an internal error, e.g., system file unavailable."},
97 {"ERRfilespecs",67,"The file handle (FID) and pathname parameters contained an invalid combination of values."},
98 {"ERRreserved",68,"reserved."},
99 {"ERRbadpermits",69,"The access permissions specified for a file or directory are not a valid combination. The server cannot set the requested attribute."},
100 {"ERRreserved",70,"reserved."},
101 {"ERRsetattrmode",71,"The attribute mode in the Set File Attribute request is invalid."},
102 {"ERRpaused",81,"Server is paused."},
103 {"ERRmsgoff",82,"Not receiving messages."},
104 {"ERRnoroom",83,"No room to buffer message."},
105 {"ERRrmuns",87,"Too many remote user names."},
106 {"ERRtimeout",88,"Operation timed out."},
107 {"ERRnoresource",89,"No resources currently available for request."},
108 {"ERRtoomanyuids",90,"Too many UIDs active on this session."},
109 {"ERRbaduid",91,"The UID is not known as a valid ID on this session."},
110 {"ERRusempx",250,"Temp unable to support Raw, use MPX mode."},
111 {"ERRusestd",251,"Temp unable to support Raw, use standard read/write."},
112 {"ERRcontmpx",252,"Continue in MPX mode."},
113 {"ERRreserved",253,"reserved."},
114 {"ERRreserved",254,"reserved."},
115 {"ERRpwdexp",2242,"Password has expired."},
116 {"ERRnosupport",0xFFFF,"Function not supported."},
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,"A 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 {"ERRdiskfull",39,"The disk is full."},
147 err_code_struct
*err_msgs
;
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
},
161 /* Return in the string an error message after decoding the class and code */
163 int SMB_Get_SMB_Error_Msg(int err_class
, int err_code
, char *msg_buf
, int len
)
167 char internal_buf
[80];
169 for (i
=0; err_classes
[i
].class; i
++)
171 if (err_classes
[i
].code
== err_class
) {
173 if (err_classes
[i
].err_msgs
) {
175 err_code_struct
*err
= err_classes
[i
].err_msgs
;
177 for (j
=0; err
[j
].name
; j
++)
179 if (err_code
== err
[j
].code
) {
181 /* Put together the message */
183 strncpy(msg_buf
, err_classes
[i
].class, len
);
184 strncat(msg_buf
, " - ", len
- strlen(msg_buf
));
185 strncat(msg_buf
, err
[j
].name
, len
- strlen(msg_buf
));
186 strncat(msg_buf
, " (", len
- strlen(msg_buf
));
187 strncat(msg_buf
, err
[j
].message
, len
- strlen(msg_buf
));
188 strncat(msg_buf
, ").", len
- strlen(msg_buf
));
190 return(strlen(msg_buf
));
193 /* We only get here if the error code is one we don't know about */
194 /* Just print out the code etc ... */
196 strncpy(msg_buf
, err_classes
[i
].class, len
);
197 strncat(msg_buf
, " - ", len
- strlen(msg_buf
));
198 snprintf(internal_buf
, sizeof(internal_buf
)-1, "%d", err_code
);
199 strncat(msg_buf
, internal_buf
, len
- strlen(msg_buf
));
200 strncat(msg_buf
, " (Unknown error code).", len
- strlen(msg_buf
));
202 return(strlen(msg_buf
));
206 strncpy(msg_buf
, err_classes
[i
].class, len
);
207 strncat(msg_buf
, " - ", len
- strlen(msg_buf
));
208 snprintf(internal_buf
, sizeof(internal_buf
)-1, "%d", err_code
);
209 strncat(msg_buf
, internal_buf
, len
- strlen(msg_buf
));
211 return(strlen(msg_buf
));
217 /* If we get here, we did not recognize the error class */
219 snprintf(internal_buf
, sizeof(internal_buf
)-1, "%d", err_class
);
220 strncat(msg_buf
, internal_buf
, len
- strlen(msg_buf
));
221 strncat(msg_buf
, " (Unknown Error Class) - ", len
- strlen(msg_buf
));
222 snprintf(internal_buf
, sizeof(internal_buf
)-1, "%d", err_code
);
223 strncat(msg_buf
, internal_buf
, len
- strlen(msg_buf
));
224 strncat(msg_buf
, "(error code).", len
- strlen(msg_buf
));
226 return(strlen(msg_buf
));