hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/fs/cifs/netmisc.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * fs/cifs/netmisc.c
34 *
....@@ -6,20 +7,6 @@
67 *
78 * Error mapping routines from Samba libsmb/errormap.c
89 * Copyright (C) Andrew Tridgell 2001
9
- *
10
- * This program is free software; you can redistribute it and/or modify
11
- * it under the terms of the GNU General Public License as published by
12
- * the Free Software Foundation; either version 2 of the License, or
13
- * (at your option) any later version.
14
- *
15
- * This program is distributed in the hope that it will be useful,
16
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
18
- * the GNU General Public License for more details.
19
- *
20
- * You should have received a copy of the GNU General Public License
21
- * along with this program; if not, write to the Free Software
22
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2310 */
2411
2512 #include <linux/net.h>
....@@ -894,6 +881,33 @@
894881 return rc;
895882 }
896883
884
+int
885
+map_and_check_smb_error(struct mid_q_entry *mid, bool logErr)
886
+{
887
+ int rc;
888
+ struct smb_hdr *smb = (struct smb_hdr *)mid->resp_buf;
889
+
890
+ rc = map_smb_to_linux_error((char *)smb, logErr);
891
+ if (rc == -EACCES && !(smb->Flags2 & SMBFLG2_ERR_STATUS)) {
892
+ /* possible ERRBaduid */
893
+ __u8 class = smb->Status.DosError.ErrorClass;
894
+ __u16 code = le16_to_cpu(smb->Status.DosError.Error);
895
+
896
+ /* switch can be used to handle different errors */
897
+ if (class == ERRSRV && code == ERRbaduid) {
898
+ cifs_dbg(FYI, "Server returned 0x%x, reconnecting session...\n",
899
+ code);
900
+ spin_lock(&GlobalMid_Lock);
901
+ if (mid->server->tcpStatus != CifsExiting)
902
+ mid->server->tcpStatus = CifsNeedReconnect;
903
+ spin_unlock(&GlobalMid_Lock);
904
+ }
905
+ }
906
+
907
+ return rc;
908
+}
909
+
910
+
897911 /*
898912 * calculate the size of the SMB message based on the fixed header
899913 * portion, the number of word parameters and the data portion of the message
....@@ -958,8 +972,8 @@
958972 struct timespec64 cnvrtDosUnixTm(__le16 le_date, __le16 le_time, int offset)
959973 {
960974 struct timespec64 ts;
961
- time64_t sec;
962
- int min, days, month, year;
975
+ time64_t sec, days;
976
+ int min, day, month, year;
963977 u16 date = le16_to_cpu(le_date);
964978 u16 time = le16_to_cpu(le_time);
965979 SMB_TIME *st = (SMB_TIME *)&time;
....@@ -970,20 +984,20 @@
970984 sec = 2 * st->TwoSeconds;
971985 min = st->Minutes;
972986 if ((sec > 59) || (min > 59))
973
- cifs_dbg(VFS, "illegal time min %d sec %lld\n", min, sec);
987
+ cifs_dbg(VFS, "Invalid time min %d sec %lld\n", min, sec);
974988 sec += (min * 60);
975989 sec += 60 * 60 * st->Hours;
976990 if (st->Hours > 24)
977
- cifs_dbg(VFS, "illegal hours %d\n", st->Hours);
978
- days = sd->Day;
991
+ cifs_dbg(VFS, "Invalid hours %d\n", st->Hours);
992
+ day = sd->Day;
979993 month = sd->Month;
980
- if (days < 1 || days > 31 || month < 1 || month > 12) {
981
- cifs_dbg(VFS, "illegal date, month %d day: %d\n", month, days);
982
- days = clamp(days, 1, 31);
994
+ if (day < 1 || day > 31 || month < 1 || month > 12) {
995
+ cifs_dbg(VFS, "Invalid date, month %d day: %d\n", month, day);
996
+ day = clamp(day, 1, 31);
983997 month = clamp(month, 1, 12);
984998 }
985999 month -= 1;
986
- days += total_days_of_prev_months[month];
1000
+ days = day + total_days_of_prev_months[month];
9871001 days += 3652; /* account for difference in days between 1980 and 1970 */
9881002 year = sd->Year;
9891003 days += year * 365;