diff options
Diffstat (limited to 'fs/cifs/cifssmb.c')
-rw-r--r-- | fs/cifs/cifssmb.c | 333 |
1 files changed, 198 insertions, 135 deletions
diff --git a/fs/cifs/cifssmb.c b/fs/cifs/cifssmb.c index 95fbba4ea7d4..9b8b4cfdf993 100644 --- a/fs/cifs/cifssmb.c +++ b/fs/cifs/cifssmb.c | |||
@@ -81,6 +81,40 @@ static struct { | |||
81 | #endif /* CONFIG_CIFS_WEAK_PW_HASH */ | 81 | #endif /* CONFIG_CIFS_WEAK_PW_HASH */ |
82 | #endif /* CIFS_POSIX */ | 82 | #endif /* CIFS_POSIX */ |
83 | 83 | ||
84 | /* Allocates buffer into dst and copies smb string from src to it. | ||
85 | * caller is responsible for freeing dst if function returned 0. | ||
86 | * returns: | ||
87 | * on success - 0 | ||
88 | * on failure - errno | ||
89 | */ | ||
90 | static int | ||
91 | cifs_strncpy_to_host(char **dst, const char *src, const int maxlen, | ||
92 | const bool is_unicode, const struct nls_table *nls_codepage) | ||
93 | { | ||
94 | int plen; | ||
95 | |||
96 | if (is_unicode) { | ||
97 | plen = UniStrnlen((wchar_t *)src, maxlen); | ||
98 | *dst = kmalloc(plen + 2, GFP_KERNEL); | ||
99 | if (!*dst) | ||
100 | goto cifs_strncpy_to_host_ErrExit; | ||
101 | cifs_strfromUCS_le(*dst, (__le16 *)src, plen, nls_codepage); | ||
102 | } else { | ||
103 | plen = strnlen(src, maxlen); | ||
104 | *dst = kmalloc(plen + 2, GFP_KERNEL); | ||
105 | if (!*dst) | ||
106 | goto cifs_strncpy_to_host_ErrExit; | ||
107 | strncpy(*dst, src, plen); | ||
108 | } | ||
109 | (*dst)[plen] = 0; | ||
110 | (*dst)[plen+1] = 0; /* harmless for ASCII case, needed for Unicode */ | ||
111 | return 0; | ||
112 | |||
113 | cifs_strncpy_to_host_ErrExit: | ||
114 | cERROR(1, ("Failed to allocate buffer for string\n")); | ||
115 | return -ENOMEM; | ||
116 | } | ||
117 | |||
84 | 118 | ||
85 | /* Mark as invalid, all open files on tree connections since they | 119 | /* Mark as invalid, all open files on tree connections since they |
86 | were closed when session to server was lost */ | 120 | were closed when session to server was lost */ |
@@ -1166,6 +1200,20 @@ static __u16 convert_disposition(int disposition) | |||
1166 | return ofun; | 1200 | return ofun; |
1167 | } | 1201 | } |
1168 | 1202 | ||
1203 | static int | ||
1204 | access_flags_to_smbopen_mode(const int access_flags) | ||
1205 | { | ||
1206 | int masked_flags = access_flags & (GENERIC_READ | GENERIC_WRITE); | ||
1207 | |||
1208 | if (masked_flags == GENERIC_READ) | ||
1209 | return SMBOPEN_READ; | ||
1210 | else if (masked_flags == GENERIC_WRITE) | ||
1211 | return SMBOPEN_WRITE; | ||
1212 | |||
1213 | /* just go for read/write */ | ||
1214 | return SMBOPEN_READWRITE; | ||
1215 | } | ||
1216 | |||
1169 | int | 1217 | int |
1170 | SMBLegacyOpen(const int xid, struct cifsTconInfo *tcon, | 1218 | SMBLegacyOpen(const int xid, struct cifsTconInfo *tcon, |
1171 | const char *fileName, const int openDisposition, | 1219 | const char *fileName, const int openDisposition, |
@@ -1207,13 +1255,7 @@ OldOpenRetry: | |||
1207 | pSMB->OpenFlags = cpu_to_le16(REQ_BATCHOPLOCK); | 1255 | pSMB->OpenFlags = cpu_to_le16(REQ_BATCHOPLOCK); |
1208 | 1256 | ||
1209 | pSMB->OpenFlags |= cpu_to_le16(REQ_MORE_INFO); | 1257 | pSMB->OpenFlags |= cpu_to_le16(REQ_MORE_INFO); |
1210 | /* BB fixme add conversion for access_flags to bits 0 - 2 of mode */ | 1258 | pSMB->Mode = cpu_to_le16(access_flags_to_smbopen_mode(access_flags)); |
1211 | /* 0 = read | ||
1212 | 1 = write | ||
1213 | 2 = rw | ||
1214 | 3 = execute | ||
1215 | */ | ||
1216 | pSMB->Mode = cpu_to_le16(2); | ||
1217 | pSMB->Mode |= cpu_to_le16(0x40); /* deny none */ | 1259 | pSMB->Mode |= cpu_to_le16(0x40); /* deny none */ |
1218 | /* set file as system file if special file such | 1260 | /* set file as system file if special file such |
1219 | as fifo and server expecting SFU style and | 1261 | as fifo and server expecting SFU style and |
@@ -1247,7 +1289,7 @@ OldOpenRetry: | |||
1247 | } else { | 1289 | } else { |
1248 | /* BB verify if wct == 15 */ | 1290 | /* BB verify if wct == 15 */ |
1249 | 1291 | ||
1250 | /* *pOplock = pSMBr->OplockLevel; */ /* BB take from action field BB */ | 1292 | /* *pOplock = pSMBr->OplockLevel; */ /* BB take from action field*/ |
1251 | 1293 | ||
1252 | *netfid = pSMBr->Fid; /* cifs fid stays in le */ | 1294 | *netfid = pSMBr->Fid; /* cifs fid stays in le */ |
1253 | /* Let caller know file was created so we can set the mode. */ | 1295 | /* Let caller know file was created so we can set the mode. */ |
@@ -1767,7 +1809,7 @@ CIFSSMBPosixLock(const int xid, struct cifsTconInfo *tcon, | |||
1767 | cFYI(1, ("Posix Lock")); | 1809 | cFYI(1, ("Posix Lock")); |
1768 | 1810 | ||
1769 | if (pLockData == NULL) | 1811 | if (pLockData == NULL) |
1770 | return EINVAL; | 1812 | return -EINVAL; |
1771 | 1813 | ||
1772 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); | 1814 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); |
1773 | 1815 | ||
@@ -1944,7 +1986,7 @@ renameRetry: | |||
1944 | /* protocol requires ASCII signature byte on Unicode string */ | 1986 | /* protocol requires ASCII signature byte on Unicode string */ |
1945 | pSMB->OldFileName[name_len + 1] = 0x00; | 1987 | pSMB->OldFileName[name_len + 1] = 0x00; |
1946 | name_len2 = | 1988 | name_len2 = |
1947 | cifsConvertToUCS((__le16 *) &pSMB->OldFileName[name_len + 2], | 1989 | cifsConvertToUCS((__le16 *)&pSMB->OldFileName[name_len + 2], |
1948 | toName, PATH_MAX, nls_codepage, remap); | 1990 | toName, PATH_MAX, nls_codepage, remap); |
1949 | name_len2 += 1 /* trailing null */ + 1 /* Signature word */ ; | 1991 | name_len2 += 1 /* trailing null */ + 1 /* Signature word */ ; |
1950 | name_len2 *= 2; /* convert to bytes */ | 1992 | name_len2 *= 2; /* convert to bytes */ |
@@ -2117,8 +2159,7 @@ copyRetry: | |||
2117 | cFYI(1, ("Send error in copy = %d with %d files copied", | 2159 | cFYI(1, ("Send error in copy = %d with %d files copied", |
2118 | rc, le16_to_cpu(pSMBr->CopyCount))); | 2160 | rc, le16_to_cpu(pSMBr->CopyCount))); |
2119 | } | 2161 | } |
2120 | if (pSMB) | 2162 | cifs_buf_release(pSMB); |
2121 | cifs_buf_release(pSMB); | ||
2122 | 2163 | ||
2123 | if (rc == -EAGAIN) | 2164 | if (rc == -EAGAIN) |
2124 | goto copyRetry; | 2165 | goto copyRetry; |
@@ -2207,8 +2248,7 @@ createSymLinkRetry: | |||
2207 | if (rc) | 2248 | if (rc) |
2208 | cFYI(1, ("Send error in SetPathInfo create symlink = %d", rc)); | 2249 | cFYI(1, ("Send error in SetPathInfo create symlink = %d", rc)); |
2209 | 2250 | ||
2210 | if (pSMB) | 2251 | cifs_buf_release(pSMB); |
2211 | cifs_buf_release(pSMB); | ||
2212 | 2252 | ||
2213 | if (rc == -EAGAIN) | 2253 | if (rc == -EAGAIN) |
2214 | goto createSymLinkRetry; | 2254 | goto createSymLinkRetry; |
@@ -2925,7 +2965,8 @@ setAclRetry: | |||
2925 | } | 2965 | } |
2926 | params = 6 + name_len; | 2966 | params = 6 + name_len; |
2927 | pSMB->MaxParameterCount = cpu_to_le16(2); | 2967 | pSMB->MaxParameterCount = cpu_to_le16(2); |
2928 | pSMB->MaxDataCount = cpu_to_le16(1000); /* BB find max SMB size from sess */ | 2968 | /* BB find max SMB size from sess */ |
2969 | pSMB->MaxDataCount = cpu_to_le16(1000); | ||
2929 | pSMB->MaxSetupCount = 0; | 2970 | pSMB->MaxSetupCount = 0; |
2930 | pSMB->Reserved = 0; | 2971 | pSMB->Reserved = 0; |
2931 | pSMB->Flags = 0; | 2972 | pSMB->Flags = 0; |
@@ -3322,7 +3363,8 @@ QPathInfoRetry: | |||
3322 | params = 2 /* level */ + 4 /* reserved */ + name_len /* includes NUL */; | 3363 | params = 2 /* level */ + 4 /* reserved */ + name_len /* includes NUL */; |
3323 | pSMB->TotalDataCount = 0; | 3364 | pSMB->TotalDataCount = 0; |
3324 | pSMB->MaxParameterCount = cpu_to_le16(2); | 3365 | pSMB->MaxParameterCount = cpu_to_le16(2); |
3325 | pSMB->MaxDataCount = cpu_to_le16(4000); /* BB find exact max SMB PDU from sess structure BB */ | 3366 | /* BB find exact max SMB PDU from sess structure BB */ |
3367 | pSMB->MaxDataCount = cpu_to_le16(4000); | ||
3326 | pSMB->MaxSetupCount = 0; | 3368 | pSMB->MaxSetupCount = 0; |
3327 | pSMB->Reserved = 0; | 3369 | pSMB->Reserved = 0; |
3328 | pSMB->Flags = 0; | 3370 | pSMB->Flags = 0; |
@@ -3388,7 +3430,7 @@ QPathInfoRetry: | |||
3388 | int | 3430 | int |
3389 | CIFSSMBUnixQPathInfo(const int xid, struct cifsTconInfo *tcon, | 3431 | CIFSSMBUnixQPathInfo(const int xid, struct cifsTconInfo *tcon, |
3390 | const unsigned char *searchName, | 3432 | const unsigned char *searchName, |
3391 | FILE_UNIX_BASIC_INFO * pFindData, | 3433 | FILE_UNIX_BASIC_INFO *pFindData, |
3392 | const struct nls_table *nls_codepage, int remap) | 3434 | const struct nls_table *nls_codepage, int remap) |
3393 | { | 3435 | { |
3394 | /* SMB_QUERY_FILE_UNIX_BASIC */ | 3436 | /* SMB_QUERY_FILE_UNIX_BASIC */ |
@@ -3679,6 +3721,7 @@ int CIFSFindNext(const int xid, struct cifsTconInfo *tcon, | |||
3679 | if (rc) { | 3721 | if (rc) { |
3680 | if (rc == -EBADF) { | 3722 | if (rc == -EBADF) { |
3681 | psrch_inf->endOfSearch = true; | 3723 | psrch_inf->endOfSearch = true; |
3724 | cifs_buf_release(pSMB); | ||
3682 | rc = 0; /* search probably was closed at end of search*/ | 3725 | rc = 0; /* search probably was closed at end of search*/ |
3683 | } else | 3726 | } else |
3684 | cFYI(1, ("FindNext returned = %d", rc)); | 3727 | cFYI(1, ("FindNext returned = %d", rc)); |
@@ -3856,25 +3899,112 @@ GetInodeNumOut: | |||
3856 | return rc; | 3899 | return rc; |
3857 | } | 3900 | } |
3858 | 3901 | ||
3902 | /* parses DFS refferal V3 structure | ||
3903 | * caller is responsible for freeing target_nodes | ||
3904 | * returns: | ||
3905 | * on success - 0 | ||
3906 | * on failure - errno | ||
3907 | */ | ||
3908 | static int | ||
3909 | parse_DFS_referrals(TRANSACTION2_GET_DFS_REFER_RSP *pSMBr, | ||
3910 | unsigned int *num_of_nodes, | ||
3911 | struct dfs_info3_param **target_nodes, | ||
3912 | const struct nls_table *nls_codepage) | ||
3913 | { | ||
3914 | int i, rc = 0; | ||
3915 | char *data_end; | ||
3916 | bool is_unicode; | ||
3917 | struct dfs_referral_level_3 *ref; | ||
3918 | |||
3919 | is_unicode = pSMBr->hdr.Flags2 & SMBFLG2_UNICODE; | ||
3920 | *num_of_nodes = le16_to_cpu(pSMBr->NumberOfReferrals); | ||
3921 | |||
3922 | if (*num_of_nodes < 1) { | ||
3923 | cERROR(1, ("num_referrals: must be at least > 0," | ||
3924 | "but we get num_referrals = %d\n", *num_of_nodes)); | ||
3925 | rc = -EINVAL; | ||
3926 | goto parse_DFS_referrals_exit; | ||
3927 | } | ||
3928 | |||
3929 | ref = (struct dfs_referral_level_3 *) &(pSMBr->referrals); | ||
3930 | if (ref->VersionNumber != 3) { | ||
3931 | cERROR(1, ("Referrals of V%d version are not supported," | ||
3932 | "should be V3", ref->VersionNumber)); | ||
3933 | rc = -EINVAL; | ||
3934 | goto parse_DFS_referrals_exit; | ||
3935 | } | ||
3936 | |||
3937 | /* get the upper boundary of the resp buffer */ | ||
3938 | data_end = (char *)(&(pSMBr->PathConsumed)) + | ||
3939 | le16_to_cpu(pSMBr->t2.DataCount); | ||
3940 | |||
3941 | cFYI(1, ("num_referrals: %d dfs flags: 0x%x ... \n", | ||
3942 | *num_of_nodes, | ||
3943 | le16_to_cpu(pSMBr->DFSFlags))); | ||
3944 | |||
3945 | *target_nodes = kzalloc(sizeof(struct dfs_info3_param) * | ||
3946 | *num_of_nodes, GFP_KERNEL); | ||
3947 | if (*target_nodes == NULL) { | ||
3948 | cERROR(1, ("Failed to allocate buffer for target_nodes\n")); | ||
3949 | rc = -ENOMEM; | ||
3950 | goto parse_DFS_referrals_exit; | ||
3951 | } | ||
3952 | |||
3953 | /* collect neccessary data from referrals */ | ||
3954 | for (i = 0; i < *num_of_nodes; i++) { | ||
3955 | char *temp; | ||
3956 | int max_len; | ||
3957 | struct dfs_info3_param *node = (*target_nodes)+i; | ||
3958 | |||
3959 | node->flags = le16_to_cpu(pSMBr->DFSFlags); | ||
3960 | node->path_consumed = le16_to_cpu(pSMBr->PathConsumed); | ||
3961 | node->server_type = le16_to_cpu(ref->ServerType); | ||
3962 | node->ref_flag = le16_to_cpu(ref->ReferralEntryFlags); | ||
3963 | |||
3964 | /* copy DfsPath */ | ||
3965 | temp = (char *)ref + le16_to_cpu(ref->DfsPathOffset); | ||
3966 | max_len = data_end - temp; | ||
3967 | rc = cifs_strncpy_to_host(&(node->path_name), temp, | ||
3968 | max_len, is_unicode, nls_codepage); | ||
3969 | if (rc) | ||
3970 | goto parse_DFS_referrals_exit; | ||
3971 | |||
3972 | /* copy link target UNC */ | ||
3973 | temp = (char *)ref + le16_to_cpu(ref->NetworkAddressOffset); | ||
3974 | max_len = data_end - temp; | ||
3975 | rc = cifs_strncpy_to_host(&(node->node_name), temp, | ||
3976 | max_len, is_unicode, nls_codepage); | ||
3977 | if (rc) | ||
3978 | goto parse_DFS_referrals_exit; | ||
3979 | |||
3980 | ref += ref->Size; | ||
3981 | } | ||
3982 | |||
3983 | parse_DFS_referrals_exit: | ||
3984 | if (rc) { | ||
3985 | free_dfs_info_array(*target_nodes, *num_of_nodes); | ||
3986 | *target_nodes = NULL; | ||
3987 | *num_of_nodes = 0; | ||
3988 | } | ||
3989 | return rc; | ||
3990 | } | ||
3991 | |||
3859 | int | 3992 | int |
3860 | CIFSGetDFSRefer(const int xid, struct cifsSesInfo *ses, | 3993 | CIFSGetDFSRefer(const int xid, struct cifsSesInfo *ses, |
3861 | const unsigned char *searchName, | 3994 | const unsigned char *searchName, |
3862 | unsigned char **targetUNCs, | 3995 | struct dfs_info3_param **target_nodes, |
3863 | unsigned int *number_of_UNC_in_array, | 3996 | unsigned int *num_of_nodes, |
3864 | const struct nls_table *nls_codepage, int remap) | 3997 | const struct nls_table *nls_codepage, int remap) |
3865 | { | 3998 | { |
3866 | /* TRANS2_GET_DFS_REFERRAL */ | 3999 | /* TRANS2_GET_DFS_REFERRAL */ |
3867 | TRANSACTION2_GET_DFS_REFER_REQ *pSMB = NULL; | 4000 | TRANSACTION2_GET_DFS_REFER_REQ *pSMB = NULL; |
3868 | TRANSACTION2_GET_DFS_REFER_RSP *pSMBr = NULL; | 4001 | TRANSACTION2_GET_DFS_REFER_RSP *pSMBr = NULL; |
3869 | struct dfs_referral_level_3 *referrals = NULL; | ||
3870 | int rc = 0; | 4002 | int rc = 0; |
3871 | int bytes_returned; | 4003 | int bytes_returned; |
3872 | int name_len; | 4004 | int name_len; |
3873 | unsigned int i; | ||
3874 | char *temp; | ||
3875 | __u16 params, byte_count; | 4005 | __u16 params, byte_count; |
3876 | *number_of_UNC_in_array = 0; | 4006 | *num_of_nodes = 0; |
3877 | *targetUNCs = NULL; | 4007 | *target_nodes = NULL; |
3878 | 4008 | ||
3879 | cFYI(1, ("In GetDFSRefer the path %s", searchName)); | 4009 | cFYI(1, ("In GetDFSRefer the path %s", searchName)); |
3880 | if (ses == NULL) | 4010 | if (ses == NULL) |
@@ -3921,7 +4051,8 @@ getDFSRetry: | |||
3921 | pSMB->DataCount = 0; | 4051 | pSMB->DataCount = 0; |
3922 | pSMB->DataOffset = 0; | 4052 | pSMB->DataOffset = 0; |
3923 | pSMB->MaxParameterCount = 0; | 4053 | pSMB->MaxParameterCount = 0; |
3924 | pSMB->MaxDataCount = cpu_to_le16(4000); /* BB find exact max SMB PDU from sess structure BB */ | 4054 | /* BB find exact max SMB PDU from sess structure BB */ |
4055 | pSMB->MaxDataCount = cpu_to_le16(4000); | ||
3925 | pSMB->MaxSetupCount = 0; | 4056 | pSMB->MaxSetupCount = 0; |
3926 | pSMB->Reserved = 0; | 4057 | pSMB->Reserved = 0; |
3927 | pSMB->Flags = 0; | 4058 | pSMB->Flags = 0; |
@@ -3943,103 +4074,26 @@ getDFSRetry: | |||
3943 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); | 4074 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
3944 | if (rc) { | 4075 | if (rc) { |
3945 | cFYI(1, ("Send error in GetDFSRefer = %d", rc)); | 4076 | cFYI(1, ("Send error in GetDFSRefer = %d", rc)); |
3946 | } else { /* decode response */ | 4077 | goto GetDFSRefExit; |
3947 | /* BB Add logic to parse referrals here */ | 4078 | } |
3948 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); | 4079 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
3949 | 4080 | ||
3950 | /* BB Also check if enough total bytes returned? */ | 4081 | /* BB Also check if enough total bytes returned? */ |
3951 | if (rc || (pSMBr->ByteCount < 17)) | 4082 | if (rc || (pSMBr->ByteCount < 17)) { |
3952 | rc = -EIO; /* bad smb */ | 4083 | rc = -EIO; /* bad smb */ |
3953 | else { | 4084 | goto GetDFSRefExit; |
3954 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); | 4085 | } |
3955 | __u16 data_count = le16_to_cpu(pSMBr->t2.DataCount); | ||
3956 | 4086 | ||
3957 | cFYI(1, | 4087 | cFYI(1, ("Decoding GetDFSRefer response BCC: %d Offset %d", |
3958 | ("Decoding GetDFSRefer response BCC: %d Offset %d", | 4088 | pSMBr->ByteCount, |
3959 | pSMBr->ByteCount, data_offset)); | 4089 | le16_to_cpu(pSMBr->t2.DataOffset))); |
3960 | referrals = | ||
3961 | (struct dfs_referral_level_3 *) | ||
3962 | (8 /* sizeof start of data block */ + | ||
3963 | data_offset + | ||
3964 | (char *) &pSMBr->hdr.Protocol); | ||
3965 | cFYI(1, ("num_referrals: %d dfs flags: 0x%x ... \n" | ||
3966 | "for referral one refer size: 0x%x srv " | ||
3967 | "type: 0x%x refer flags: 0x%x ttl: 0x%x", | ||
3968 | le16_to_cpu(pSMBr->NumberOfReferrals), | ||
3969 | le16_to_cpu(pSMBr->DFSFlags), | ||
3970 | le16_to_cpu(referrals->ReferralSize), | ||
3971 | le16_to_cpu(referrals->ServerType), | ||
3972 | le16_to_cpu(referrals->ReferralFlags), | ||
3973 | le16_to_cpu(referrals->TimeToLive))); | ||
3974 | /* BB This field is actually two bytes in from start of | ||
3975 | data block so we could do safety check that DataBlock | ||
3976 | begins at address of pSMBr->NumberOfReferrals */ | ||
3977 | *number_of_UNC_in_array = | ||
3978 | le16_to_cpu(pSMBr->NumberOfReferrals); | ||
3979 | |||
3980 | /* BB Fix below so can return more than one referral */ | ||
3981 | if (*number_of_UNC_in_array > 1) | ||
3982 | *number_of_UNC_in_array = 1; | ||
3983 | |||
3984 | /* get the length of the strings describing refs */ | ||
3985 | name_len = 0; | ||
3986 | for (i = 0; i < *number_of_UNC_in_array; i++) { | ||
3987 | /* make sure that DfsPathOffset not past end */ | ||
3988 | __u16 offset = | ||
3989 | le16_to_cpu(referrals->DfsPathOffset); | ||
3990 | if (offset > data_count) { | ||
3991 | /* if invalid referral, stop here and do | ||
3992 | not try to copy any more */ | ||
3993 | *number_of_UNC_in_array = i; | ||
3994 | break; | ||
3995 | } | ||
3996 | temp = ((char *)referrals) + offset; | ||
3997 | 4090 | ||
3998 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) { | 4091 | /* parse returned result into more usable form */ |
3999 | name_len += UniStrnlen((wchar_t *)temp, | 4092 | rc = parse_DFS_referrals(pSMBr, num_of_nodes, |
4000 | data_count); | 4093 | target_nodes, nls_codepage); |
4001 | } else { | ||
4002 | name_len += strnlen(temp, data_count); | ||
4003 | } | ||
4004 | referrals++; | ||
4005 | /* BB add check that referral pointer does | ||
4006 | not fall off end PDU */ | ||
4007 | } | ||
4008 | /* BB add check for name_len bigger than bcc */ | ||
4009 | *targetUNCs = | ||
4010 | kmalloc(name_len+1+(*number_of_UNC_in_array), | ||
4011 | GFP_KERNEL); | ||
4012 | if (*targetUNCs == NULL) { | ||
4013 | rc = -ENOMEM; | ||
4014 | goto GetDFSRefExit; | ||
4015 | } | ||
4016 | /* copy the ref strings */ | ||
4017 | referrals = (struct dfs_referral_level_3 *) | ||
4018 | (8 /* sizeof data hdr */ + data_offset + | ||
4019 | (char *) &pSMBr->hdr.Protocol); | ||
4020 | |||
4021 | for (i = 0; i < *number_of_UNC_in_array; i++) { | ||
4022 | temp = ((char *)referrals) + | ||
4023 | le16_to_cpu(referrals->DfsPathOffset); | ||
4024 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) { | ||
4025 | cifs_strfromUCS_le(*targetUNCs, | ||
4026 | (__le16 *) temp, | ||
4027 | name_len, | ||
4028 | nls_codepage); | ||
4029 | } else { | ||
4030 | strncpy(*targetUNCs, temp, name_len); | ||
4031 | } | ||
4032 | /* BB update target_uncs pointers */ | ||
4033 | referrals++; | ||
4034 | } | ||
4035 | temp = *targetUNCs; | ||
4036 | temp[name_len] = 0; | ||
4037 | } | ||
4038 | 4094 | ||
4039 | } | ||
4040 | GetDFSRefExit: | 4095 | GetDFSRefExit: |
4041 | if (pSMB) | 4096 | cifs_buf_release(pSMB); |
4042 | cifs_buf_release(pSMB); | ||
4043 | 4097 | ||
4044 | if (rc == -EAGAIN) | 4098 | if (rc == -EAGAIN) |
4045 | goto getDFSRetry; | 4099 | goto getDFSRetry; |
@@ -4229,7 +4283,8 @@ QFSAttributeRetry: | |||
4229 | params = 2; /* level */ | 4283 | params = 2; /* level */ |
4230 | pSMB->TotalDataCount = 0; | 4284 | pSMB->TotalDataCount = 0; |
4231 | pSMB->MaxParameterCount = cpu_to_le16(2); | 4285 | pSMB->MaxParameterCount = cpu_to_le16(2); |
4232 | pSMB->MaxDataCount = cpu_to_le16(1000); /* BB find exact max SMB PDU from sess structure BB */ | 4286 | /* BB find exact max SMB PDU from sess structure BB */ |
4287 | pSMB->MaxDataCount = cpu_to_le16(1000); | ||
4233 | pSMB->MaxSetupCount = 0; | 4288 | pSMB->MaxSetupCount = 0; |
4234 | pSMB->Reserved = 0; | 4289 | pSMB->Reserved = 0; |
4235 | pSMB->Flags = 0; | 4290 | pSMB->Flags = 0; |
@@ -4298,7 +4353,8 @@ QFSDeviceRetry: | |||
4298 | params = 2; /* level */ | 4353 | params = 2; /* level */ |
4299 | pSMB->TotalDataCount = 0; | 4354 | pSMB->TotalDataCount = 0; |
4300 | pSMB->MaxParameterCount = cpu_to_le16(2); | 4355 | pSMB->MaxParameterCount = cpu_to_le16(2); |
4301 | pSMB->MaxDataCount = cpu_to_le16(1000); /* BB find exact max SMB PDU from sess structure BB */ | 4356 | /* BB find exact max SMB PDU from sess structure BB */ |
4357 | pSMB->MaxDataCount = cpu_to_le16(1000); | ||
4302 | pSMB->MaxSetupCount = 0; | 4358 | pSMB->MaxSetupCount = 0; |
4303 | pSMB->Reserved = 0; | 4359 | pSMB->Reserved = 0; |
4304 | pSMB->Flags = 0; | 4360 | pSMB->Flags = 0; |
@@ -4369,7 +4425,8 @@ QFSUnixRetry: | |||
4369 | pSMB->DataCount = 0; | 4425 | pSMB->DataCount = 0; |
4370 | pSMB->DataOffset = 0; | 4426 | pSMB->DataOffset = 0; |
4371 | pSMB->MaxParameterCount = cpu_to_le16(2); | 4427 | pSMB->MaxParameterCount = cpu_to_le16(2); |
4372 | pSMB->MaxDataCount = cpu_to_le16(100); /* BB find exact max SMB PDU from sess structure BB */ | 4428 | /* BB find exact max SMB PDU from sess structure BB */ |
4429 | pSMB->MaxDataCount = cpu_to_le16(100); | ||
4373 | pSMB->MaxSetupCount = 0; | 4430 | pSMB->MaxSetupCount = 0; |
4374 | pSMB->Reserved = 0; | 4431 | pSMB->Reserved = 0; |
4375 | pSMB->Flags = 0; | 4432 | pSMB->Flags = 0; |
@@ -4444,7 +4501,8 @@ SETFSUnixRetry: | |||
4444 | offset = param_offset + params; | 4501 | offset = param_offset + params; |
4445 | 4502 | ||
4446 | pSMB->MaxParameterCount = cpu_to_le16(4); | 4503 | pSMB->MaxParameterCount = cpu_to_le16(4); |
4447 | pSMB->MaxDataCount = cpu_to_le16(100); /* BB find exact max SMB PDU from sess structure BB */ | 4504 | /* BB find exact max SMB PDU from sess structure BB */ |
4505 | pSMB->MaxDataCount = cpu_to_le16(100); | ||
4448 | pSMB->SetupCount = 1; | 4506 | pSMB->SetupCount = 1; |
4449 | pSMB->Reserved3 = 0; | 4507 | pSMB->Reserved3 = 0; |
4450 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FS_INFORMATION); | 4508 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FS_INFORMATION); |
@@ -4512,7 +4570,8 @@ QFSPosixRetry: | |||
4512 | pSMB->DataCount = 0; | 4570 | pSMB->DataCount = 0; |
4513 | pSMB->DataOffset = 0; | 4571 | pSMB->DataOffset = 0; |
4514 | pSMB->MaxParameterCount = cpu_to_le16(2); | 4572 | pSMB->MaxParameterCount = cpu_to_le16(2); |
4515 | pSMB->MaxDataCount = cpu_to_le16(100); /* BB find exact max SMB PDU from sess structure BB */ | 4573 | /* BB find exact max SMB PDU from sess structure BB */ |
4574 | pSMB->MaxDataCount = cpu_to_le16(100); | ||
4516 | pSMB->MaxSetupCount = 0; | 4575 | pSMB->MaxSetupCount = 0; |
4517 | pSMB->Reserved = 0; | 4576 | pSMB->Reserved = 0; |
4518 | pSMB->Flags = 0; | 4577 | pSMB->Flags = 0; |
@@ -4702,7 +4761,8 @@ CIFSSMBSetFileSize(const int xid, struct cifsTconInfo *tcon, __u64 size, | |||
4702 | 4761 | ||
4703 | count = sizeof(struct file_end_of_file_info); | 4762 | count = sizeof(struct file_end_of_file_info); |
4704 | pSMB->MaxParameterCount = cpu_to_le16(2); | 4763 | pSMB->MaxParameterCount = cpu_to_le16(2); |
4705 | pSMB->MaxDataCount = cpu_to_le16(1000); /* BB find max SMB PDU from sess */ | 4764 | /* BB find exact max SMB PDU from sess structure BB */ |
4765 | pSMB->MaxDataCount = cpu_to_le16(1000); | ||
4706 | pSMB->SetupCount = 1; | 4766 | pSMB->SetupCount = 1; |
4707 | pSMB->Reserved3 = 0; | 4767 | pSMB->Reserved3 = 0; |
4708 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); | 4768 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
@@ -4789,7 +4849,8 @@ CIFSSMBSetFileTimes(const int xid, struct cifsTconInfo *tcon, | |||
4789 | 4849 | ||
4790 | count = sizeof(FILE_BASIC_INFO); | 4850 | count = sizeof(FILE_BASIC_INFO); |
4791 | pSMB->MaxParameterCount = cpu_to_le16(2); | 4851 | pSMB->MaxParameterCount = cpu_to_le16(2); |
4792 | pSMB->MaxDataCount = cpu_to_le16(1000); /* BB find max SMB PDU from sess */ | 4852 | /* BB find max SMB PDU from sess */ |
4853 | pSMB->MaxDataCount = cpu_to_le16(1000); | ||
4793 | pSMB->SetupCount = 1; | 4854 | pSMB->SetupCount = 1; |
4794 | pSMB->Reserved3 = 0; | 4855 | pSMB->Reserved3 = 0; |
4795 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); | 4856 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
@@ -4856,7 +4917,8 @@ SetTimesRetry: | |||
4856 | params = 6 + name_len; | 4917 | params = 6 + name_len; |
4857 | count = sizeof(FILE_BASIC_INFO); | 4918 | count = sizeof(FILE_BASIC_INFO); |
4858 | pSMB->MaxParameterCount = cpu_to_le16(2); | 4919 | pSMB->MaxParameterCount = cpu_to_le16(2); |
4859 | pSMB->MaxDataCount = cpu_to_le16(1000); /* BB find exact max SMB PDU from sess structure BB */ | 4920 | /* BB find max SMB PDU from sess structure BB */ |
4921 | pSMB->MaxDataCount = cpu_to_le16(1000); | ||
4860 | pSMB->MaxSetupCount = 0; | 4922 | pSMB->MaxSetupCount = 0; |
4861 | pSMB->Reserved = 0; | 4923 | pSMB->Reserved = 0; |
4862 | pSMB->Flags = 0; | 4924 | pSMB->Flags = 0; |
@@ -4986,7 +5048,8 @@ setPermsRetry: | |||
4986 | params = 6 + name_len; | 5048 | params = 6 + name_len; |
4987 | count = sizeof(FILE_UNIX_BASIC_INFO); | 5049 | count = sizeof(FILE_UNIX_BASIC_INFO); |
4988 | pSMB->MaxParameterCount = cpu_to_le16(2); | 5050 | pSMB->MaxParameterCount = cpu_to_le16(2); |
4989 | pSMB->MaxDataCount = cpu_to_le16(1000); /* BB find exact max SMB PDU from sess structure BB */ | 5051 | /* BB find max SMB PDU from sess structure BB */ |
5052 | pSMB->MaxDataCount = cpu_to_le16(1000); | ||
4990 | pSMB->MaxSetupCount = 0; | 5053 | pSMB->MaxSetupCount = 0; |
4991 | pSMB->Reserved = 0; | 5054 | pSMB->Reserved = 0; |
4992 | pSMB->Flags = 0; | 5055 | pSMB->Flags = 0; |
@@ -5051,8 +5114,7 @@ setPermsRetry: | |||
5051 | if (rc) | 5114 | if (rc) |
5052 | cFYI(1, ("SetPathInfo (perms) returned %d", rc)); | 5115 | cFYI(1, ("SetPathInfo (perms) returned %d", rc)); |
5053 | 5116 | ||
5054 | if (pSMB) | 5117 | cifs_buf_release(pSMB); |
5055 | cifs_buf_release(pSMB); | ||
5056 | if (rc == -EAGAIN) | 5118 | if (rc == -EAGAIN) |
5057 | goto setPermsRetry; | 5119 | goto setPermsRetry; |
5058 | return rc; | 5120 | return rc; |
@@ -5169,7 +5231,8 @@ QAllEAsRetry: | |||
5169 | params = 2 /* level */ + 4 /* reserved */ + name_len /* includes NUL */; | 5231 | params = 2 /* level */ + 4 /* reserved */ + name_len /* includes NUL */; |
5170 | pSMB->TotalDataCount = 0; | 5232 | pSMB->TotalDataCount = 0; |
5171 | pSMB->MaxParameterCount = cpu_to_le16(2); | 5233 | pSMB->MaxParameterCount = cpu_to_le16(2); |
5172 | pSMB->MaxDataCount = cpu_to_le16(4000); /* BB find exact max SMB PDU from sess structure BB */ | 5234 | /* BB find exact max SMB PDU from sess structure BB */ |
5235 | pSMB->MaxDataCount = cpu_to_le16(4000); | ||
5173 | pSMB->MaxSetupCount = 0; | 5236 | pSMB->MaxSetupCount = 0; |
5174 | pSMB->Reserved = 0; | 5237 | pSMB->Reserved = 0; |
5175 | pSMB->Flags = 0; | 5238 | pSMB->Flags = 0; |
@@ -5273,8 +5336,7 @@ QAllEAsRetry: | |||
5273 | } | 5336 | } |
5274 | } | 5337 | } |
5275 | } | 5338 | } |
5276 | if (pSMB) | 5339 | cifs_buf_release(pSMB); |
5277 | cifs_buf_release(pSMB); | ||
5278 | if (rc == -EAGAIN) | 5340 | if (rc == -EAGAIN) |
5279 | goto QAllEAsRetry; | 5341 | goto QAllEAsRetry; |
5280 | 5342 | ||
@@ -5317,7 +5379,8 @@ QEARetry: | |||
5317 | params = 2 /* level */ + 4 /* reserved */ + name_len /* includes NUL */; | 5379 | params = 2 /* level */ + 4 /* reserved */ + name_len /* includes NUL */; |
5318 | pSMB->TotalDataCount = 0; | 5380 | pSMB->TotalDataCount = 0; |
5319 | pSMB->MaxParameterCount = cpu_to_le16(2); | 5381 | pSMB->MaxParameterCount = cpu_to_le16(2); |
5320 | pSMB->MaxDataCount = cpu_to_le16(4000); /* BB find exact max SMB PDU from sess structure BB */ | 5382 | /* BB find exact max SMB PDU from sess structure BB */ |
5383 | pSMB->MaxDataCount = cpu_to_le16(4000); | ||
5321 | pSMB->MaxSetupCount = 0; | 5384 | pSMB->MaxSetupCount = 0; |
5322 | pSMB->Reserved = 0; | 5385 | pSMB->Reserved = 0; |
5323 | pSMB->Flags = 0; | 5386 | pSMB->Flags = 0; |
@@ -5422,8 +5485,7 @@ QEARetry: | |||
5422 | } | 5485 | } |
5423 | } | 5486 | } |
5424 | } | 5487 | } |
5425 | if (pSMB) | 5488 | cifs_buf_release(pSMB); |
5426 | cifs_buf_release(pSMB); | ||
5427 | if (rc == -EAGAIN) | 5489 | if (rc == -EAGAIN) |
5428 | goto QEARetry; | 5490 | goto QEARetry; |
5429 | 5491 | ||
@@ -5475,7 +5537,8 @@ SetEARetry: | |||
5475 | 5537 | ||
5476 | count = sizeof(*parm_data) + ea_value_len + name_len; | 5538 | count = sizeof(*parm_data) + ea_value_len + name_len; |
5477 | pSMB->MaxParameterCount = cpu_to_le16(2); | 5539 | pSMB->MaxParameterCount = cpu_to_le16(2); |
5478 | pSMB->MaxDataCount = cpu_to_le16(1000); /* BB find max SMB size from sess */ | 5540 | /* BB find max SMB PDU from sess */ |
5541 | pSMB->MaxDataCount = cpu_to_le16(1000); | ||
5479 | pSMB->MaxSetupCount = 0; | 5542 | pSMB->MaxSetupCount = 0; |
5480 | pSMB->Reserved = 0; | 5543 | pSMB->Reserved = 0; |
5481 | pSMB->Flags = 0; | 5544 | pSMB->Flags = 0; |