2 Unix SMB/Netbios implementation.
4 client error handling routines
5 Copyright (C) Andrew Tridgell 1994-1998
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 /*****************************************************
27 RAP error codes - a small start but will be extended.
28 *******************************************************/
35 {5, "RAP5: User has insufficient privilege" },
36 {50, "RAP50: Not supported by server" },
37 {65, "RAP65: Access denied" },
38 {86, "RAP86: The specified password is invalid" },
39 {2220, "RAP2220: Group does not exist" },
40 {2221, "RAP2221: User does not exist" },
41 {2226, "RAP2226: Operation only permitted on a Primary Domain Controller" },
42 {2237, "RAP2237: User is not in group" },
43 {2242, "RAP2242: The password of this user has expired." },
44 {2243, "RAP2243: The password of this user cannot change." },
45 {2244, "RAP2244: This password cannot be used now (password history conflict)." },
46 {2245, "RAP2245: The password is shorter than required." },
47 {2246, "RAP2246: The password of this user is too recent to change."},
49 /* these really shouldn't be here ... */
50 {0x80, "Not listening on called name"},
51 {0x81, "Not listening for calling name"},
52 {0x82, "Called name not present"},
53 {0x83, "Called name present, but insufficient resources"},
58 /****************************************************************************
59 return a description of an SMB error
60 ****************************************************************************/
61 static char *cli_smb_errstr(struct cli_state
*cli
)
63 return smb_dos_errstr(cli
->inbuf
);
66 /***************************************************************************
67 Return an error message - either an NT error, SMB error or a RAP error.
68 Note some of the NT errors are actually warnings or "informational" errors
69 in which case they can be safely ignored.
70 ****************************************************************************/
72 char *cli_errstr(struct cli_state
*cli
)
74 static fstring cli_error_message
;
75 uint32 flgs2
= SVAL(cli
->inbuf
,smb_flg2
), errnum
;
79 if (!cli
->initialised
) {
80 fstrcpy(cli_error_message
, "[Programmer's error] cli_errstr called on unitialized cli_stat struct!\n");
81 return cli_error_message
;
85 /* Case #1: RAP error */
87 for (i
= 0; rap_errmap
[i
].message
!= NULL
; i
++) {
88 if (rap_errmap
[i
].err
== cli
->rap_error
) {
89 return rap_errmap
[i
].message
;
93 slprintf(cli_error_message
, sizeof(cli_error_message
) - 1, "RAP code %d",
96 return cli_error_message
;
99 /* Case #2: 32-bit NT errors */
100 if (flgs2
& FLAGS2_32_BIT_ERROR_CODES
) {
101 NTSTATUS status
= NT_STATUS(IVAL(cli
->inbuf
,smb_rcls
));
103 return get_nt_error_msg(status
);
106 cli_dos_error(cli
, &errclass
, &errnum
);
108 /* Case #3: SMB error */
110 return cli_smb_errstr(cli
);
114 /* Return the 32-bit NT status code from the last packet */
115 NTSTATUS
cli_nt_error(struct cli_state
*cli
)
117 int flgs2
= SVAL(cli
->inbuf
,smb_flg2
);
119 if (!(flgs2
& FLAGS2_32_BIT_ERROR_CODES
)) {
120 int class = CVAL(cli
->inbuf
,smb_rcls
);
121 int code
= SVAL(cli
->inbuf
,smb_err
);
122 return dos_to_ntstatus(class, code
);
125 return NT_STATUS(IVAL(cli
->inbuf
,smb_rcls
));
129 /* Return the DOS error from the last packet - an error class and an error
131 void cli_dos_error(struct cli_state
*cli
, uint8
*eclass
, uint32
*ecode
)
137 if(!cli
->initialised
) return;
139 flgs2
= SVAL(cli
->inbuf
,smb_flg2
);
141 if (flgs2
& FLAGS2_32_BIT_ERROR_CODES
) {
142 NTSTATUS ntstatus
= NT_STATUS(IVAL(cli
->inbuf
, smb_rcls
));
143 ntstatus_to_dos(ntstatus
, eclass
, ecode
);
147 rcls
= CVAL(cli
->inbuf
,smb_rcls
);
148 code
= SVAL(cli
->inbuf
,smb_err
);
150 if (eclass
) *eclass
= rcls
;
151 if (ecode
) *ecode
= code
;
154 /* Return a UNIX errno from a dos error class, error number tuple */
156 int cli_errno_from_dos(uint8 eclass
, uint32 num
)
158 if (eclass
== ERRDOS
) {
160 case ERRbadfile
: return ENOENT
;
161 case ERRbadpath
: return ENOTDIR
;
162 case ERRnoaccess
: return EACCES
;
163 case ERRfilexists
: return EEXIST
;
164 case ERRrename
: return EEXIST
;
165 case ERRbadshare
: return EBUSY
;
166 case ERRlock
: return EBUSY
;
167 case ERRinvalidname
: return ENOENT
;
168 case ERRnosuchshare
: return ENODEV
;
172 if (eclass
== ERRSRV
) {
174 case ERRbadpw
: return EPERM
;
175 case ERRaccess
: return EACCES
;
176 case ERRnoresource
: return ENOMEM
;
177 case ERRinvdevice
: return ENODEV
;
178 case ERRinvnetname
: return ENODEV
;
182 /* for other cases */
186 /* Return a UNIX errno from a NT status code */
191 {NT_STATUS_ACCESS_VIOLATION
, EACCES
},
192 {NT_STATUS_NO_SUCH_FILE
, ENOENT
},
193 {NT_STATUS_NO_SUCH_DEVICE
, ENODEV
},
194 {NT_STATUS_INVALID_HANDLE
, EBADF
},
195 {NT_STATUS_NO_MEMORY
, ENOMEM
},
196 {NT_STATUS_ACCESS_DENIED
, EACCES
},
197 {NT_STATUS_OBJECT_NAME_NOT_FOUND
, ENOENT
},
198 {NT_STATUS_SHARING_VIOLATION
, EBUSY
},
199 {NT_STATUS_OBJECT_PATH_INVALID
, ENOTDIR
},
200 {NT_STATUS_OBJECT_NAME_COLLISION
, EEXIST
},
201 {NT_STATUS_PATH_NOT_COVERED
, ENOENT
},
205 int cli_errno_from_nt(NTSTATUS status
)
208 DEBUG(10,("cli_errno_from_nt: 32 bit codes: code=%08x\n", NT_STATUS_V(status
)));
210 /* Status codes without this bit set are not errors */
212 if (!(NT_STATUS_V(status
) & 0xc0000000))
215 for (i
=0;nt_errno_map
[i
].error
;i
++) {
216 if (NT_STATUS_V(nt_errno_map
[i
].status
) ==
217 NT_STATUS_V(status
)) return nt_errno_map
[i
].error
;
220 /* for all other cases - a default code */
224 /* Return a UNIX errno appropriate for the error received in the last
227 int cli_errno(struct cli_state
*cli
)
231 if (cli_is_dos_error(cli
)) {
235 cli_dos_error(cli
, &eclass
, &ecode
);
236 return cli_errno_from_dos(eclass
, ecode
);
239 status
= cli_nt_error(cli
);
241 return cli_errno_from_nt(status
);
244 /* Return true if the last packet was in error */
246 BOOL
cli_is_error(struct cli_state
*cli
)
248 uint32 flgs2
= SVAL(cli
->inbuf
,smb_flg2
), rcls
= 0;
250 if (flgs2
& FLAGS2_32_BIT_ERROR_CODES
) {
251 /* Return error is error bits are set */
252 rcls
= IVAL(cli
->inbuf
, smb_rcls
);
253 return (rcls
& 0xF0000000) == 0xC0000000;
256 /* Return error if error class in non-zero */
258 rcls
= CVAL(cli
->inbuf
, smb_rcls
);
262 /* Return true if the last error was an NT error */
264 BOOL
cli_is_nt_error(struct cli_state
*cli
)
266 uint32 flgs2
= SVAL(cli
->inbuf
,smb_flg2
);
268 return cli_is_error(cli
) && (flgs2
& FLAGS2_32_BIT_ERROR_CODES
);
271 /* Return true if the last error was a DOS error */
273 BOOL
cli_is_dos_error(struct cli_state
*cli
)
275 uint32 flgs2
= SVAL(cli
->inbuf
,smb_flg2
);
277 return cli_is_error(cli
) && !(flgs2
& FLAGS2_32_BIT_ERROR_CODES
);