Skip to content

Commit a761ac5

Browse files
author
Steve French
committed
[CIFS] log better errors on failed mounts
Also returns more accurate errors to mount for the cases of account expired and password expired Acked-by: Jeff Layton <jlayton@redhat.com> Signed-off-by: Steve French <sfrench@us.ibm.com>
1 parent abb63d6 commit a761ac5

6 files changed

Lines changed: 35 additions & 26 deletions

File tree

‎fs/cifs/cifsproto.h‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ extern int SendReceive(const unsigned int /* xid */ , struct cifsSesInfo *,
5050
int * /* bytes returned */ , const int long_op);
5151
extern int SendReceive2(const unsigned int /* xid */ , struct cifsSesInfo *,
5252
struct kvec *, int /* nvec to send */,
53-
int * /* type of buf returned */ , const int long_op);
53+
int * /* type of buf returned */ , const int long_op,
54+
const int logError /* whether to log status code*/ );
5455
extern int SendReceiveBlockingLock(const unsigned int /* xid */ ,
5556
struct cifsTconInfo *,
5657
struct smb_hdr * /* input */ ,
@@ -65,7 +66,7 @@ extern unsigned int smbCalcSize_LE(struct smb_hdr *ptr);
6566
extern int decode_negTokenInit(unsigned char *security_blob, int length,
6667
enum securityEnum *secType);
6768
extern int cifs_inet_pton(int, char *source, void *dst);
68-
extern int map_smb_to_linux_error(struct smb_hdr *smb);
69+
extern int map_smb_to_linux_error(struct smb_hdr *smb, int logErr);
6970
extern void header_assemble(struct smb_hdr *, char /* command */ ,
7071
const struct cifsTconInfo *, int /* length of
7172
fixed section (word count) in two byte units */);

‎fs/cifs/cifssmb.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1446,9 +1446,8 @@ CIFSSMBRead(const int xid, struct cifsTconInfo *tcon, const int netfid,
14461446

14471447
iov[0].iov_base = (char *)pSMB;
14481448
iov[0].iov_len = pSMB->hdr.smb_buf_length + 4;
1449-
rc = SendReceive2(xid, tcon->ses, iov,
1450-
1 /* num iovecs */,
1451-
&resp_buf_type, 0);
1449+
rc = SendReceive2(xid, tcon->ses, iov, 1 /* num iovecs */,
1450+
&resp_buf_type, 0 /* not long op */, 1 /* log err */ );
14521451
cifs_stats_inc(&tcon->num_reads);
14531452
pSMBr = (READ_RSP *)iov[0].iov_base;
14541453
if (rc) {
@@ -1667,7 +1666,7 @@ CIFSSMBWrite2(const int xid, struct cifsTconInfo *tcon,
16671666

16681667

16691668
rc = SendReceive2(xid, tcon->ses, iov, n_vec + 1, &resp_buf_type,
1670-
long_op);
1669+
long_op, 0 /* do not log STATUS code */ );
16711670
cifs_stats_inc(&tcon->num_writes);
16721671
if (rc) {
16731672
cFYI(1, ("Send error Write2 = %d", rc));
@@ -3094,7 +3093,8 @@ CIFSSMBGetCIFSACL(const int xid, struct cifsTconInfo *tcon, __u16 fid,
30943093
iov[0].iov_base = (char *)pSMB;
30953094
iov[0].iov_len = pSMB->hdr.smb_buf_length + 4;
30963095

3097-
rc = SendReceive2(xid, tcon->ses, iov, 1 /* num iovec */, &buf_type, 0);
3096+
rc = SendReceive2(xid, tcon->ses, iov, 1 /* num iovec */, &buf_type,
3097+
0 /* not long op */, 0 /* do not log STATUS codes */ );
30983098
cifs_stats_inc(&tcon->num_acl_get);
30993099
if (rc) {
31003100
cFYI(1, ("Send error in QuerySecDesc = %d", rc));

‎fs/cifs/netmisc.c‎

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,16 @@ static const struct smb_to_posix_error mapping_table_ERRSRV[] = {
114114
{ERRusempx, -EIO},
115115
{ERRusestd, -EIO},
116116
{ERR_NOTIFY_ENUM_DIR, -ENOBUFS},
117-
{ERRaccountexpired, -EACCES},
117+
{ERRnoSuchUser, -EACCES},
118+
/* {ERRaccountexpired, -EACCES},
118119
{ERRbadclient, -EACCES},
119120
{ERRbadLogonTime, -EACCES},
120-
{ERRpasswordExpired, -EACCES},
121+
{ERRpasswordExpired, -EACCES},*/
122+
{ERRaccountexpired, -EKEYEXPIRED},
123+
{ERRbadclient, -EACCES},
124+
{ERRbadLogonTime, -EACCES},
125+
{ERRpasswordExpired, -EKEYEXPIRED},
126+
121127
{ERRnosupport, -EINVAL},
122128
{0, 0}
123129
};
@@ -270,7 +276,7 @@ static const struct {
270276
from NT_STATUS_NO_SUCH_USER to NT_STATUS_LOGON_FAILURE
271277
during the session setup } */
272278
{
273-
ERRDOS, ERRnoaccess, NT_STATUS_NO_SUCH_USER}, {
279+
ERRDOS, ERRnoaccess, NT_STATUS_NO_SUCH_USER}, { /* could map to 2238 */
274280
ERRHRD, ERRgeneral, NT_STATUS_GROUP_EXISTS}, {
275281
ERRHRD, ERRgeneral, NT_STATUS_NO_SUCH_GROUP}, {
276282
ERRHRD, ERRgeneral, NT_STATUS_MEMBER_IN_GROUP}, {
@@ -285,10 +291,10 @@ static const struct {
285291
ERRHRD, ERRgeneral, NT_STATUS_PASSWORD_RESTRICTION}, {
286292
ERRDOS, ERRnoaccess, NT_STATUS_LOGON_FAILURE}, {
287293
ERRHRD, ERRgeneral, NT_STATUS_ACCOUNT_RESTRICTION}, {
288-
ERRSRV, 2241, NT_STATUS_INVALID_LOGON_HOURS}, {
289-
ERRSRV, 2240, NT_STATUS_INVALID_WORKSTATION}, {
294+
ERRSRV, ERRbadLogonTime, NT_STATUS_INVALID_LOGON_HOURS}, {
295+
ERRSRV, ERRbadclient, NT_STATUS_INVALID_WORKSTATION}, {
290296
ERRSRV, ERRpasswordExpired, NT_STATUS_PASSWORD_EXPIRED}, {
291-
ERRSRV, 2239, NT_STATUS_ACCOUNT_DISABLED}, {
297+
ERRSRV, ERRaccountexpired, NT_STATUS_ACCOUNT_DISABLED}, {
292298
ERRHRD, ERRgeneral, NT_STATUS_NONE_MAPPED}, {
293299
ERRHRD, ERRgeneral, NT_STATUS_TOO_MANY_LUIDS_REQUESTED}, {
294300
ERRHRD, ERRgeneral, NT_STATUS_LUIDS_EXHAUSTED}, {
@@ -585,7 +591,7 @@ static const struct {
585591
ERRDOS, ERRnoaccess, NT_STATUS_TRUST_FAILURE}, {
586592
ERRHRD, ERRgeneral, NT_STATUS_MUTANT_LIMIT_EXCEEDED}, {
587593
ERRDOS, ERRnetlogonNotStarted, NT_STATUS_NETLOGON_NOT_STARTED}, {
588-
ERRSRV, 2239, NT_STATUS_ACCOUNT_EXPIRED}, {
594+
ERRSRV, ERRaccountexpired, NT_STATUS_ACCOUNT_EXPIRED}, {
589595
ERRHRD, ERRgeneral, NT_STATUS_POSSIBLE_DEADLOCK}, {
590596
ERRHRD, ERRgeneral, NT_STATUS_NETWORK_CREDENTIAL_CONFLICT}, {
591597
ERRHRD, ERRgeneral, NT_STATUS_REMOTE_SESSION_LIMIT}, {
@@ -754,7 +760,7 @@ ntstatus_to_dos(__u32 ntstatus, __u8 * eclass, __u16 * ecode)
754760
}
755761

756762
int
757-
map_smb_to_linux_error(struct smb_hdr *smb)
763+
map_smb_to_linux_error(struct smb_hdr *smb, int logErr)
758764
{
759765
unsigned int i;
760766
int rc = -EIO; /* if transport error smb error may not be set */
@@ -771,7 +777,9 @@ map_smb_to_linux_error(struct smb_hdr *smb)
771777
/* translate the newer STATUS codes to old style SMB errors
772778
* and then to POSIX errors */
773779
__u32 err = le32_to_cpu(smb->Status.CifsError);
774-
if (cifsFYI & CIFS_RC)
780+
if (logErr && (err != (NT_STATUS_MORE_PROCESSING_REQUIRED)))
781+
cifs_print_status(err);
782+
else if (cifsFYI & CIFS_RC)
775783
cifs_print_status(err);
776784
ntstatus_to_dos(err, &smberrclass, &smberrcode);
777785
} else {
@@ -813,7 +821,7 @@ map_smb_to_linux_error(struct smb_hdr *smb)
813821
}
814822
/* else ERRHRD class errors or junk - return EIO */
815823

816-
cFYI(1, (" !!Mapping smb error code %d to POSIX err %d !!",
824+
cFYI(1, ("Mapping smb error code %d to POSIX err %d",
817825
smberrcode, rc));
818826

819827
/* generic corrective action e.g. reconnect SMB session on

‎fs/cifs/sess.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,8 @@ CIFS_SessSetup(unsigned int xid, struct cifsSesInfo *ses, int first_time,
513513

514514
iov[1].iov_base = str_area;
515515
iov[1].iov_len = count;
516-
rc = SendReceive2(xid, ses, iov, 2 /* num_iovecs */, &resp_buf_type, 0);
516+
rc = SendReceive2(xid, ses, iov, 2 /* num_iovecs */, &resp_buf_type,
517+
0 /* not long op */, 1 /* log NT STATUS if any */ );
517518
/* SMB request buf freed in SendReceive2 */
518519

519520
cFYI(1, ("ssetup rc from sendrecv2 is %d", rc));

‎fs/cifs/smberr.h‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,10 @@
173173
#define ERRusestd 251 /* temporarily unable to use either raw
174174
or mpx */
175175
#define ERR_NOTIFY_ENUM_DIR 1024
176+
#define ERRnoSuchUser 2238 /* user account does not exist */
176177
#define ERRaccountexpired 2239
177-
#define ERRbadclient 2240
178-
#define ERRbadLogonTime 2241
178+
#define ERRbadclient 2240 /* can not logon from this client */
179+
#define ERRbadLogonTime 2241 /* logon hours do not allow this */
179180
#define ERRpasswordExpired 2242
180181
#define ERRnetlogonNotStarted 2455
181182
#define ERRnosupport 0xFFFF

‎fs/cifs/transport.c‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ static int wait_for_response(struct cifsSesInfo *ses,
418418
int
419419
SendReceive2(const unsigned int xid, struct cifsSesInfo *ses,
420420
struct kvec *iov, int n_vec, int *pRespBufType /* ret */,
421-
const int long_op)
421+
const int long_op, const int logError)
422422
{
423423
int rc = 0;
424424
unsigned int receive_len;
@@ -464,7 +464,6 @@ SendReceive2(const unsigned int xid, struct cifsSesInfo *ses,
464464
wake_up(&ses->server->request_q);
465465
return rc;
466466
}
467-
468467
rc = cifs_sign_smb2(iov, n_vec, ses->server, &midQ->sequence_number);
469468

470469
midQ->midState = MID_REQUEST_SUBMITTED;
@@ -567,8 +566,7 @@ SendReceive2(const unsigned int xid, struct cifsSesInfo *ses,
567566
}
568567

569568
/* BB special case reconnect tid and uid here? */
570-
/* BB special case Errbadpassword and pwdexpired here */
571-
rc = map_smb_to_linux_error(midQ->resp_buf);
569+
rc = map_smb_to_linux_error(midQ->resp_buf, logError);
572570

573571
/* convert ByteCount if necessary */
574572
if (receive_len >= sizeof(struct smb_hdr) - 4
@@ -747,7 +745,7 @@ SendReceive(const unsigned int xid, struct cifsSesInfo *ses,
747745
*pbytes_returned = out_buf->smb_buf_length;
748746

749747
/* BB special case reconnect tid and uid here? */
750-
rc = map_smb_to_linux_error(out_buf);
748+
rc = map_smb_to_linux_error(out_buf, 0 /* no log */ );
751749

752750
/* convert ByteCount if necessary */
753751
if (receive_len >= sizeof(struct smb_hdr) - 4
@@ -990,7 +988,7 @@ SendReceiveBlockingLock(const unsigned int xid, struct cifsTconInfo *tcon,
990988
*pbytes_returned = out_buf->smb_buf_length;
991989

992990
/* BB special case reconnect tid and uid here? */
993-
rc = map_smb_to_linux_error(out_buf);
991+
rc = map_smb_to_linux_error(out_buf, 0 /* no log */ );
994992

995993
/* convert ByteCount if necessary */
996994
if (receive_len >= sizeof(struct smb_hdr) - 4

0 commit comments

Comments
 (0)