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.
27 extern int DEBUGLEVEL
;
30 /*****************************************************
31 RAP error codes - a small start but will be extended.
32 *******************************************************/
40 {5, "User has insufficient privilege" },
41 {86, "The specified password is invalid" },
42 {2226, "Operation only permitted on a Primary Domain Controller" },
43 {2242, "The password of this user has expired." },
44 {2243, "The password of this user cannot change." },
45 {2244, "This password cannot be used now (password history conflict)." },
46 {2245, "The password is shorter than required." },
47 {2246, "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_errstr(cli
->inbuf
);
66 /******************************************************
67 Return an error message - either an SMB error or a RAP
69 *******************************************************/
71 char *cli_errstr(struct cli_state
*cli
)
73 static fstring error_message
;
80 * Errors are of three kinds - smb errors,
81 * dealt with by cli_smb_errstr, NT errors,
82 * whose code is in cli.nt_error, and rap
83 * errors, whose error code is in cli.rap_error.
86 cli_error(cli
, &errclass
, &errnum
, &nt_rpc_error
);
90 return cli_smb_errstr(cli
);
94 * Was it an NT error ?
99 char *nt_msg
= (char *)get_nt_error_msg(nt_rpc_error
);
103 slprintf(error_message
, sizeof(fstring
) - 1, "NT code %d", nt_rpc_error
);
107 fstrcpy(error_message
, nt_msg
);
110 return error_message
;
114 * Must have been a rap error.
117 slprintf(error_message
, sizeof(error_message
) - 1, "code %d", cli
->rap_error
);
119 for (i
= 0; rap_errmap
[i
].message
!= NULL
; i
++)
121 if (rap_errmap
[i
].err
== cli
->rap_error
)
123 fstrcpy( error_message
, rap_errmap
[i
].message
);
128 return error_message
;
132 /****************************************************************************
133 return error codes for the last packet
134 returns 0 if there was no error and the best approx of a unix errno
137 for 32 bit "warnings", a return code of 0 is expected.
139 ****************************************************************************/
140 int cli_error(struct cli_state
*cli
, uint8
*eclass
, uint32
*num
, uint32
*nt_rpc_error
)
146 if (eclass
) *eclass
= 0;
148 if (nt_rpc_error
) *nt_rpc_error
= 0;
150 if(!cli
->initialised
)
156 flgs2
= SVAL(cli
->inbuf
,smb_flg2
);
157 if (nt_rpc_error
) *nt_rpc_error
= cli
->nt_error
;
159 if (flgs2
& FLAGS2_32_BIT_ERROR_CODES
) {
160 /* 32 bit error codes detected */
161 uint32 nt_err
= IVAL(cli
->inbuf
,smb_rcls
);
162 if (num
) *num
= nt_err
;
163 DEBUG(10,("cli_error: 32 bit codes: code=%08x\n", nt_err
));
164 if (!(nt_err
& 0xc0000000))
168 case NT_STATUS_ACCESS_VIOLATION
: return EACCES
;
169 case NT_STATUS_NO_SUCH_FILE
: return ENOENT
;
170 case NT_STATUS_NO_SUCH_DEVICE
: return ENODEV
;
171 case NT_STATUS_INVALID_HANDLE
: return EBADF
;
172 case NT_STATUS_NO_MEMORY
: return ENOMEM
;
173 case NT_STATUS_ACCESS_DENIED
: return EACCES
;
174 case NT_STATUS_OBJECT_NAME_NOT_FOUND
: return ENOENT
;
175 case NT_STATUS_SHARING_VIOLATION
: return EBUSY
;
176 case NT_STATUS_OBJECT_PATH_INVALID
: return ENOTDIR
;
177 case NT_STATUS_OBJECT_NAME_COLLISION
: return EEXIST
;
180 /* for all other cases - a default code */
184 rcls
= CVAL(cli
->inbuf
,smb_rcls
);
185 code
= SVAL(cli
->inbuf
,smb_err
);
186 if (rcls
== 0) return 0;
188 if (eclass
) *eclass
= rcls
;
189 if (num
) *num
= code
;
191 if (rcls
== ERRDOS
) {
193 case ERRbadfile
: return ENOENT
;
194 case ERRbadpath
: return ENOTDIR
;
195 case ERRnoaccess
: return EACCES
;
196 case ERRfilexists
: return EEXIST
;
197 case ERRrename
: return EEXIST
;
198 case ERRbadshare
: return EBUSY
;
199 case ERRlock
: return EBUSY
;
200 case ERROR_INVALID_NAME
: return ENOENT
;
201 case ERRnosuchshare
: return ENODEV
;
204 if (rcls
== ERRSRV
) {
206 case ERRbadpw
: return EPERM
;
207 case ERRaccess
: return EACCES
;
208 case ERRnoresource
: return ENOMEM
;
209 case ERRinvdevice
: return ENODEV
;
210 case ERRinvnetname
: return ENODEV
;
213 /* for other cases */