22 #include <linux/net.h>
23 #include <linux/string.h>
24 #include <linux/list.h>
25 #include <linux/wait.h>
26 #include <linux/slab.h>
28 #include <linux/ctype.h>
29 #include <linux/utsname.h>
37 #include <asm/uaccess.h>
38 #include <asm/processor.h>
40 #include <linux/module.h>
57 #define RFC1001_PORT 139
62 #define TLINK_ERROR_EXPIRE (1 * HZ)
63 #define TLINK_IDLE_EXPIRE (600 * HZ)
283 static void tlink_rb_insert(
struct rb_root *root,
struct tcon_link *new_tlink);
285 static int cifs_setup_volume_info(
struct smb_vol *volume_info,
char *mount_data,
286 const char *devname);
316 #ifdef CONFIG_CIFS_SMB2
317 server->max_read = 0;
320 cFYI(1,
"Reconnecting tcp session");
324 cFYI(1,
"%s: marking sessions and tcons for reconnect", __func__);
338 cFYI(1,
"%s: tearing down socket", __func__);
341 cFYI(1,
"State: 0x%x Flags: 0x%lx", server->
ssocket->state,
344 cFYI(1,
"Post shutdown state: 0x%x Flags: 0x%lx",
359 INIT_LIST_HEAD(&retry_list);
360 cFYI(1,
"%s: moving mids to private list", __func__);
366 list_move(&mid_entry->
qhead, &retry_list);
370 cFYI(1,
"%s: issuing mid callbacks", __func__);
373 list_del_init(&mid_entry->
qhead);
381 rc = generic_ip_connect(server);
383 cFYI(1,
"reconnect error %d", rc);
410 if (!server->
ops->need_neg || server->
ops->need_neg(server) ||
411 (server->
ops->can_echo && !server->
ops->can_echo(server)) ||
415 rc = server->
ops->echo ? server->
ops->echo(server) : -
ENOSYS;
417 cFYI(1,
"Unable to send echo request to server: %s",
430 cERROR(1,
"No memory for large SMB response");
443 cERROR(1,
"No memory for SMB response");
473 cERROR(1,
"Server %s has not responded in %d seconds. "
474 "Reconnecting...", server->
hostname,
497 kvec_array_init(
struct kvec *
new,
struct kvec *
iov,
unsigned int nr_segs,
502 while (bytes || !iov->
iov_len) {
513 memcpy(
new, iov,
sizeof(*iov) * nr_segs);
514 new->iov_base += base;
515 new->iov_len -= base;
522 struct kvec *new_iov;
524 if (server->
iov && nr_segs <= server->nr_iov)
531 server->
iov = new_iov;
539 unsigned int nr_segs,
unsigned int to_read)
547 iov = get_server_iovec(server, nr_segs);
554 for (total_read = 0; to_read; total_read +=
length, to_read -=
length) {
557 if (server_unresponsive(server)) {
562 segs = kvec_array_init(iov, iov_orig, nr_segs, total_read);
565 iov, segs, to_read, 0);
585 }
else if (length <= 0) {
586 cFYI(1,
"Received no data or error: expecting %d "
587 "got %d", to_read, length);
598 unsigned int to_read)
621 cFYI(1,
"RFC 1002 session keep alive");
624 cFYI(1,
"RFC 1002 positive session response");
631 cFYI(1,
"RFC 1002 negative session response");
645 cERROR(1,
"RFC 1002 unknown response type 0x%x", type);
655 #ifdef CONFIG_CIFS_STATS2
663 list_del_init(&mid->
qhead);
669 char *
buf,
int malformed)
671 if (server->
ops->check_trans2 &&
672 server->
ops->check_trans2(mid, server, buf, malformed))
727 INIT_LIST_HEAD(&dispose_list);
731 cFYI(1,
"Clearing mid 0x%llx", mid_entry->
mid);
733 list_move(&mid_entry->
qhead, &dispose_list);
740 cFYI(1,
"Callback mid 0x%llx", mid_entry->
mid);
741 list_del_init(&mid_entry->
qhead);
757 cFYI(1,
"Wait for exit from demultiplex thread");
780 unsigned int pdu_length = get_rfc1002_length(buf);
784 cERROR(1,
"SMB response too long (%u bytes)",
816 length = server->
ops->check_message(buf, server->
total_read);
821 if (server->
ops->is_status_pending &&
822 server->
ops->is_status_pending(buf, server, length))
828 handle_mid(mid, server, buf, length);
833 cifs_demultiplex_thread(
void *
p)
843 cFYI(1,
"Demultiplex PID: %d", task_pid_nr(
current));
855 if (!allocate_buffers(server))
871 pdu_length = get_rfc1002_length(buf);
873 cFYI(1,
"RFC1002 header 0x%x", pdu_length);
874 if (!is_smb_response(server, buf[0]))
879 cERROR(1,
"SMB response too short (%u bytes)",
893 mid_entry = server->
ops->find_mid(server, buf);
895 if (!mid_entry || !mid_entry->
receive)
896 length = standard_receive3(server, mid_entry);
898 length = mid_entry->
receive(server, mid_entry);
907 if (mid_entry !=
NULL) {
910 }
else if (!server->
ops->is_oplock_break ||
911 !server->
ops->is_oplock_break(buf, server)) {
912 cERROR(1,
"No task to wake, unknown frame received! "
916 #ifdef CONFIG_CIFS_DEBUG2
917 if (server->
ops->dump_detail)
918 server->
ops->dump_detail(buf);
931 clean_demultiplex_info(server);
936 while (!signal_pending(
current)) {
948 extract_hostname(
const char *unc)
959 delim =
strchr(src,
'\\');
982 rc = kstrtoul(
string, 0, option);
989 static int cifs_parse_security_flavors(
char *
value,
995 switch (
match_token(value, cifs_secflavor_tokens, args)) {
1004 cERROR(1,
"Krb5 cifs privacy not supported");
1025 #ifdef CONFIG_CIFS_WEAK_PW_HASH
1034 cERROR(1,
"bad security option: %s", value);
1042 cifs_parse_cache_flavor(
char *value,
struct smb_vol *vol)
1046 switch (
match_token(value, cifs_cacheflavor_tokens, args)) {
1060 cERROR(1,
"bad cache= option: %s", value);
1067 cifs_parse_smb_version(
char *value,
struct smb_vol *vol)
1071 switch (
match_token(value, cifs_smb_version_tokens, args)) {
1076 #ifdef CONFIG_CIFS_SMB2
1087 cERROR(1,
"Unknown vers= option specified: %s", value);
1094 cifs_parse_mount_options(
const char *mountdata,
const char *devname,
1099 unsigned int temp_len,
i,
j;
1101 short int override_uid = -1;
1102 short int override_gid = -1;
1103 bool uid_specified =
false;
1104 bool gid_specified =
false;
1105 bool sloppy =
false;
1107 char *nodename = utsname()->nodename;
1108 char *
string =
NULL;
1109 char *tmp_end, *
value;
1114 delim = separator[0];
1152 goto cifs_parse_mount_err;
1155 if (!mountdata_copy)
1156 goto cifs_parse_mount_err;
1158 options = mountdata_copy;
1159 end = options +
strlen(options);
1161 if (
strncmp(options,
"sep=", 4) == 0) {
1162 if (options[4] != 0) {
1163 separator[0] = options[4];
1166 cFYI(1,
"Null separator not allowed");
1172 while ((data =
strsep(&options, separator)) !=
NULL) {
1180 token =
match_token(data, cifs_mount_option_tokens, args);
1336 "supported. Instead set "
1337 "/proc/fs/cifs/LookupCacheEnabled to 0\n");
1340 #ifndef CONFIG_CIFS_FSCACHE
1341 cERROR(1,
"FS-Cache support needs CONFIG_CIFS_FSCACHE "
1342 "kernel config option set");
1343 goto cifs_parse_mount_err;
1359 if (get_option_ul(args, &option)) {
1360 cERROR(1,
"%s: Invalid backupuid value",
1362 goto cifs_parse_mount_err;
1368 if (get_option_ul(args, &option)) {
1369 cERROR(1,
"%s: Invalid backupgid value",
1371 goto cifs_parse_mount_err;
1377 if (get_option_ul(args, &option)) {
1378 cERROR(1,
"%s: Invalid uid value",
1380 goto cifs_parse_mount_err;
1383 uid_specified =
true;
1386 if (get_option_ul(args, &option)) {
1387 cERROR(1,
"%s: Invalid cruid value",
1389 goto cifs_parse_mount_err;
1394 if (get_option_ul(args, &option)) {
1395 cERROR(1,
"%s: Invalid gid value",
1397 goto cifs_parse_mount_err;
1400 gid_specified =
true;
1403 if (get_option_ul(args, &option)) {
1404 cERROR(1,
"%s: Invalid file_mode value",
1406 goto cifs_parse_mount_err;
1411 if (get_option_ul(args, &option)) {
1412 cERROR(1,
"%s: Invalid dir_mode value",
1414 goto cifs_parse_mount_err;
1419 if (get_option_ul(args, &option)) {
1420 cERROR(1,
"%s: Invalid port value",
1422 goto cifs_parse_mount_err;
1427 if (get_option_ul(args, &option)) {
1428 cERROR(1,
"%s: Invalid rsize value",
1430 goto cifs_parse_mount_err;
1435 if (get_option_ul(args, &option)) {
1436 cERROR(1,
"%s: Invalid wsize value",
1438 goto cifs_parse_mount_err;
1443 if (get_option_ul(args, &option)) {
1444 cERROR(1,
"%s: Invalid actimeo value",
1446 goto cifs_parse_mount_err;
1450 cERROR(1,
"CIFS: attribute cache"
1451 "timeout too large");
1452 goto cifs_parse_mount_err;
1471 goto cifs_parse_mount_err;
1477 goto cifs_parse_mount_err;
1490 value =
strchr(data,
'=');
1494 tmp_end = (
char *) value +
strlen(value);
1500 if (tmp_end < end && tmp_end[1] == delim) {
1506 while ((tmp_end =
strchr(tmp_end, delim))
1507 !=
NULL && (tmp_end[1] == delim)) {
1508 tmp_end = (
char *) &tmp_end[2];
1514 options = (
char *) &tmp_end[1];
1522 temp_len =
strlen(value);
1527 goto cifs_parse_mount_err;
1530 for (i = 0, j = 0; i < temp_len; i++, j++) {
1532 if ((value[i] == delim) &&
1533 value[i+1] == delim)
1551 goto cifs_parse_mount_err;
1557 goto cifs_parse_mount_err;
1565 temp_len =
strnlen(
string, 300);
1566 if (temp_len == 300) {
1568 goto cifs_parse_mount_err;
1574 goto cifs_parse_mount_err;
1578 if (
strncmp(
string,
"//", 2) == 0) {
1581 }
else if (
strncmp(
string,
"\\\\", 2) != 0) {
1583 "begin with // or \\\\\n");
1584 goto cifs_parse_mount_err;
1593 if (
strnlen(
string, 256) == 256) {
1596 goto cifs_parse_mount_err;
1602 "for domainname\n");
1603 goto cifs_parse_mount_err;
1605 cFYI(1,
"Domain name set");
1614 string,
strlen(
string))) {
1616 " srcaddr: %s\n",
string);
1617 goto cifs_parse_mount_err;
1625 temp_len =
strnlen(
string, 1024);
1626 if (
string[0] !=
'/')
1628 if (temp_len > 1024) {
1630 goto cifs_parse_mount_err;
1636 "for path prefix\n");
1637 goto cifs_parse_mount_err;
1640 if (
string[0] !=
'/') {
1652 if (
strnlen(
string, 1024) >= 65) {
1655 goto cifs_parse_mount_err;
1658 if (
strnicmp(
string,
"default", 7) != 0) {
1664 goto cifs_parse_mount_err;
1670 cFYI(1,
"iocharset set to %s",
string);
1677 if (
strnicmp(
string,
"TCP_NODELAY", 11) == 0) {
1679 "sockopt=TCP_NODELAY option has been "
1680 "deprecated and will be removed "
1706 if (i == RFC1001_NAME_LEN &&
string[i] != 0)
1708 " longer than 15 truncated.\n");
1727 for (i = 0; i < 15; i++) {
1734 if (i == RFC1001_NAME_LEN &&
string[i] != 0)
1736 "biosname longer than 15 truncated.\n");
1743 if (
strnicmp(
string,
"1", 1) == 0) {
1750 goto cifs_parse_mount_err;
1756 if (cifs_parse_smb_version(
string, vol) != 0)
1757 goto cifs_parse_mount_err;
1764 if (cifs_parse_security_flavors(
string, vol) != 0)
1765 goto cifs_parse_mount_err;
1772 if (cifs_parse_cache_flavor(
string, vol) != 0)
1773 goto cifs_parse_mount_err;
1789 if (!sloppy && invalid) {
1791 goto cifs_parse_mount_err;
1797 cERROR(1,
"Multiuser mounts require kernels with "
1798 "CONFIG_KEYS enabled.");
1799 goto cifs_parse_mount_err;
1808 else if (override_uid == 1)
1810 "specified with no uid= option.\n");
1814 else if (override_gid == 1)
1816 "specified with no gid= option.\n");
1818 kfree(mountdata_copy);
1823 cifs_parse_mount_err:
1825 kfree(mountdata_copy);
1887 return port == *sport;
1930 unsigned int secFlags;
1981 if (!net_eq(cifs_net_ns(server),
current->nsproxy->net_ns))
1984 if (!match_address(server, addr,
1988 if (!match_port(server, addr))
1991 if (!match_security(server, vol))
2004 if (!match_server(server, addr, vol))
2009 cFYI(1,
"Existing tcp session with server found");
2027 put_net(cifs_net_ns(server));
2051 cifs_get_tcp_session(
struct smb_vol *volume_info)
2061 cFYI(1,
"UNC: %s ip: %s", volume_info->
UNC, volume_info->
UNCip);
2063 if (volume_info->
UNCip && volume_info->
UNC) {
2073 }
else if (volume_info->
UNCip) {
2076 cERROR(1,
"Connecting to DFS root not implemented yet");
2080 cERROR(1,
"CIFS mount error: No UNC path (e.g. -o "
2081 "unc=//192.168.1.100/public) specified");
2087 tcp_ses = cifs_find_tcp_session((
struct sockaddr *)&addr, volume_info);
2099 cERROR(1,
"could not setup hash structures rc %d", rc);
2103 tcp_ses->
ops = volume_info->
ops;
2105 cifs_set_net_ns(tcp_ses, get_net(
current->nsproxy->net_ns));
2106 tcp_ses->
hostname = extract_hostname(volume_info->
UNC);
2109 goto out_err_crypto_release;
2144 cFYI(1,
"attempting ipv6 connect");
2153 rc = ip_connect(tcp_ses);
2155 cERROR(1,
"Error connecting to socket. Aborting operation");
2156 goto out_err_crypto_release;
2166 if (IS_ERR(tcp_ses->
tsk)) {
2167 rc = PTR_ERR(tcp_ses->
tsk);
2168 cERROR(1,
"error %d create cifsd thread", rc);
2170 goto out_err_crypto_release;
2186 out_err_crypto_release:
2189 put_net(cifs_net_ns(tcp_ses));
2204 switch (ses->
server->secType) {
2239 if (!match_session(ses, vol))
2250 cifs_put_smb_ses(
struct cifs_ses *ses)
2267 server->
ops->logoff(xid, ses);
2271 cifs_put_tcp_session(server);
2277 #define CIFSCREDS_DESC_SIZE (7 + INET6_ADDRSTRLEN + 1)
2297 switch (server->
dstaddr.ss_family) {
2307 cFYI(1,
"Bad ss_family (%hu)", server->
dstaddr.ss_family);
2312 cFYI(1,
"%s: desc=%s", __func__, desc);
2316 cFYI(1,
"domainName is NULL");
2323 cFYI(1,
"%s: desc=%s", __func__, desc);
2332 upayload = key->payload.
data;
2333 if (IS_ERR_OR_NULL(upayload)) {
2334 rc = upayload ? PTR_ERR(upayload) : -
EINVAL;
2339 payload = (
char *)upayload->
data;
2341 cFYI(1,
"payload=%s", payload);
2343 cFYI(1,
"Unable to find ':' in payload (datalen=%d)",
2351 cFYI(1,
"Bad value from username search (len=%zd)", len);
2358 cFYI(1,
"Unable to allocate %zd bytes for username", len);
2364 len = key->datalen - (len + 1);
2366 cFYI(1,
"Bad len for password search (len=%zd)", len);
2376 cFYI(1,
"Unable to allocate %zd bytes for password", len);
2388 cFYI(1,
"%s: returning %d", __func__, rc);
2400 static bool warned_on_ntlm;
2413 ses = cifs_find_smb_ses(server, volume_info);
2415 cFYI(1,
"Existing smb sess found (status=%d)", ses->
status);
2422 cifs_put_smb_ses(ses);
2427 cFYI(1,
"Session needs reconnect");
2433 cifs_put_smb_ses(ses);
2441 cifs_put_tcp_session(server);
2446 cFYI(1,
"Existing smb sess not found");
2480 if ((volume_info->
secFlg == 0) && warned_on_ntlm ==
false) {
2481 warned_on_ntlm =
true;
2482 cERROR(1,
"default security mechanism requested. The default "
2483 "security mechanism will be upgraded from ntlm to "
2484 "ntlmv2 in kernel release 3.3");
2510 static int match_tcon(
struct cifs_tcon *tcon,
const char *unc)
2520 cifs_find_tcon(
struct cifs_ses *ses,
const char *unc)
2528 if (!match_tcon(tcon, unc))
2555 if (ses->
server->ops->tree_disconnect)
2556 ses->
server->ops->tree_disconnect(xid, tcon);
2561 cifs_put_smb_ses(ses);
2570 tcon = cifs_find_tcon(ses, volume_info->
UNC);
2572 cFYI(1,
"Found match on UNC path");
2574 cifs_put_smb_ses(ses);
2575 if (tcon->
seal != volume_info->
seal)
2576 cERROR(1,
"transport encryption setting "
2577 "conflicts with existing tid");
2581 if (!ses->
server->ops->tree_connect) {
2603 cERROR(1,
"Missing share name");
2613 rc = ses->
server->ops->tree_connect(xid, ses, volume_info->
UNC, tcon,
2616 cFYI(1,
"Tcon rc = %d", rc);
2620 if (volume_info->
nodfs) {
2622 cFYI(1,
"DFS disabled (%d)", tcon->
Flags);
2651 if (!tlink || IS_ERR(tlink))
2660 if (!IS_ERR(tlink_tcon(tlink)))
2661 cifs_put_tcon(tlink_tcon(tlink));
2689 if (new->wsize && new->wsize < old->
wsize)
2692 if (new->rsize && new->rsize < old->
rsize)
2695 if (old->
mnt_uid != new->mnt_uid || old->
mnt_gid != new->mnt_gid)
2705 if (old->
actimeo != new->actimeo)
2727 cifs_sb = CIFS_SB(sb);
2728 tlink = cifs_get_tlink(cifs_sb_master_tlink(cifs_sb));
2729 if (IS_ERR(tlink)) {
2733 tcon = tlink_tcon(tlink);
2737 volume_info = mnt_data->
vol;
2739 if (!volume_info->
UNCip || !volume_info->
UNC)
2749 if (!match_server(tcp_srv, (
struct sockaddr *)&addr, volume_info) ||
2750 !match_session(ses, volume_info) ||
2751 !match_tcon(tcon, volume_info->
UNC)) {
2756 rc = compare_mount_options(sb, mnt_data);
2765 const struct nls_table *nls_codepage,
unsigned int *num_referrals,
2771 if (!ses->
server->ops->tree_connect || !ses->
server->ops->get_dfs_refer)
2781 if (temp_unc ==
NULL)
2787 rc = ses->
server->ops->tree_connect(xid, ses, temp_unc,
NULL,
2789 cFYI(1,
"Tcon rc = %d ipc_tid = %d", rc, ses->
ipc_tid);
2793 rc = ses->
server->ops->get_dfs_refer(xid, ses, old_path,
2794 referrals, num_referrals,
2795 nls_codepage, remap);
2804 #ifdef CONFIG_DEBUG_LOCK_ALLOC
2811 struct sock *
sk = sock->
sk;
2814 &cifs_slock_key[0],
"sk_lock-AF_INET-CIFS", &cifs_key[0]);
2818 cifs_reclassify_socket6(
struct socket *sock)
2820 struct sock *sk = sock->
sk;
2823 &cifs_slock_key[1],
"sk_lock-AF_INET6-CIFS", &cifs_key[1]);
2827 cifs_reclassify_socket4(
struct socket *sock)
2832 cifs_reclassify_socket6(
struct socket *sock)
2838 static void rfc1002mangle(
char *
target,
char *
source,
unsigned int length)
2842 for (i = 0, j = 0; i < (
length); i++) {
2844 target[
j] =
'A' + (0x0F & (source[
i] >> 4));
2845 target[j+1] =
'A' + (0x0F & source[
i]);
2858 rc = socket->
ops->bind(socket,
2868 "Failed to bind to: %pI6c, error: %d",
2872 "Failed to bind to: %pI4, error: %d",
2893 ses_init_buf->trailer.session_req.
called_len = 32;
2897 rfc1002mangle(ses_init_buf->trailer.
2902 rfc1002mangle(ses_init_buf->trailer.
2907 ses_init_buf->trailer.session_req.
calling_len = 32;
2915 rfc1002mangle(ses_init_buf->trailer.
2920 rfc1002mangle(ses_init_buf->trailer.
2925 ses_init_buf->trailer.session_req.
scope1 = 0;
2926 ses_init_buf->trailer.session_req.
scope2 = 0;
2927 smb_buf = (
struct smb_hdr *)ses_init_buf;
2931 rc =
smb_send(server, smb_buf, 0x44);
2932 kfree(ses_init_buf);
2959 struct socket *socket = server->
ssocket;
2974 if (socket ==
NULL) {
2978 cERROR(1,
"Error %d creating socket", rc);
2984 cFYI(1,
"Socket created");
2988 cifs_reclassify_socket6(socket);
2990 cifs_reclassify_socket4(socket);
2993 rc = bind_socket(server);
3002 socket->
sk->sk_rcvtimeo = 7 *
HZ;
3003 socket->
sk->sk_sndtimeo = 5 *
HZ;
3007 if (socket->
sk->sk_sndbuf < (200 * 1024))
3008 socket->
sk->sk_sndbuf = 200 * 1024;
3009 if (socket->
sk->sk_rcvbuf < (140 * 1024))
3010 socket->
sk->sk_rcvbuf = 140 * 1024;
3016 (
char *)&val,
sizeof(val));
3018 cFYI(1,
"set TCP_NODELAY socket option error %d", rc);
3021 cFYI(1,
"sndbuf %d rcvbuf %d rcvtimeo 0x%lx",
3022 socket->
sk->sk_sndbuf,
3023 socket->
sk->sk_rcvbuf, socket->
sk->sk_rcvtimeo);
3025 rc = socket->
ops->connect(socket, saddr, slen, 0);
3027 cFYI(1,
"Error %d connecting to server", rc);
3034 rc = ip_rfc1001_connect(server);
3057 rc = generic_ip_connect(server);
3065 return generic_ip_connect(server);
3085 cFYI(1,
"Linux protocol extensions disabled");
3087 }
else if (vol_info)
3091 cFYI(1,
"Unix extensions disabled so not set on reconnect");
3097 cFYI(1,
"unix caps which server supports %lld", cap);
3100 if (vol_info ==
NULL) {
3104 cap &= ~CIFS_UNIX_POSIX_ACL_CAP;
3106 if (cap & CIFS_UNIX_POSIX_PATHNAMES_CAP)
3107 cERROR(1,
"POSIXPATH support change");
3108 cap &= ~CIFS_UNIX_POSIX_PATHNAMES_CAP;
3109 }
else if ((cap & CIFS_UNIX_POSIX_PATHNAMES_CAP) == 0) {
3110 cERROR(1,
"possible reconnect error");
3111 cERROR(1,
"server disabled POSIX path support");
3116 cERROR(1,
"per-share encryption not supported yet");
3122 cFYI(1,
"negotiated posix acl support");
3131 cFYI(1,
"negotiate posix pathnames");
3137 cFYI(1,
"Negotiate caps 0x%x", (
int)cap);
3138 #ifdef CONFIG_CIFS_DEBUG2
3140 cFYI(1,
"FCNTL cap");
3142 cFYI(1,
"EXTATTR cap");
3143 if (cap & CIFS_UNIX_POSIX_PATHNAMES_CAP)
3144 cFYI(1,
"POSIX path cap");
3146 cFYI(1,
"XATTR cap");
3148 cFYI(1,
"POSIX ACL cap");
3150 cFYI(1,
"very large read cap");
3152 cFYI(1,
"very large write cap");
3154 cFYI(1,
"transport encryption cap");
3155 if (cap & CIFS_UNIX_TRANSPORT_ENCRYPTION_MANDATORY_CAP)
3156 cFYI(1,
"mandatory transport encryption cap");
3159 if (vol_info ==
NULL) {
3160 cFYI(1,
"resetting capabilities failed");
3162 cERROR(1,
"Negotiating Unix capabilities "
3163 "with the server failed. Consider "
3164 "mounting with the Unix Extensions "
3165 "disabled if problems are found "
3166 "by specifying the nounix mount "
3192 cFYI(1,
"file mode: 0x%hx dir mode: 0x%hx",
3198 if (pvolume_info->
noperm)
3204 if (pvolume_info->
remap)
3210 if (pvolume_info->
nobrl)
3234 if (pvolume_info->
fsc)
3242 cFYI(1,
"mounting share using direct i/o");
3247 cERROR(1,
"mount option mfsymlinks ignored if sfu "
3248 "mount option is used");
3255 cERROR(1,
"mount option dynperm ignored if cifsacl "
3256 "mount option supported");
3260 cleanup_volume_info_contents(
struct smb_vol *volume_info)
3264 if (volume_info->
UNCip != volume_info->
UNC + 2)
3277 cleanup_volume_info_contents(volume_info);
3282 #ifdef CONFIG_CIFS_DFS_UPCALL
3286 build_unc_path_to_root(
const struct smb_vol *vol,
3289 char *full_path, *
pos;
3294 if (full_path ==
NULL)
3298 pos = full_path + unc_len;
3306 convert_delimiter(full_path, CIFS_DIR_SEP(cifs_sb));
3307 cFYI(1,
"%s: full_path=%s", __func__, full_path);
3322 expand_dfs_referral(
const unsigned int xid,
struct cifs_ses *ses,
3327 unsigned int num_referrals = 0;
3329 char *full_path =
NULL, *ref_path =
NULL, *mdata =
NULL;
3331 full_path = build_unc_path_to_root(volume_info, cifs_sb);
3332 if (IS_ERR(full_path))
3333 return PTR_ERR(full_path);
3336 ref_path = check_prefix ? full_path + 1 : volume_info->
UNC + 1;
3339 &num_referrals, &referrals,
3342 if (!rc && num_referrals > 0) {
3343 char *fake_devname =
NULL;
3346 full_path + 1, referrals,
3349 free_dfs_info_array(referrals, num_referrals);
3351 if (IS_ERR(mdata)) {
3352 rc = PTR_ERR(mdata);
3355 cleanup_volume_info_contents(volume_info);
3356 memset(volume_info,
'\0',
sizeof(*volume_info));
3357 rc = cifs_setup_volume_info(volume_info, mdata,
3360 kfree(fake_devname);
3370 cifs_setup_volume_info(
struct smb_vol *volume_info,
char *mount_data,
3371 const char *devname)
3375 if (cifs_parse_mount_options(mount_data, devname, volume_info))
3380 cFYI(1,
"Anonymous login");
3383 }
else if (volume_info->
username) {
3400 cERROR(1,
"CIFS mount error: iocharset %s not found",
3419 rc = cifs_setup_volume_info(volume_info, mount_data, devname);
3422 volume_info = ERR_PTR(rc);
3438 #ifdef CONFIG_CIFS_DFS_UPCALL
3439 int referral_walks_count = 0;
3446 #ifdef CONFIG_CIFS_DFS_UPCALL
3449 if (referral_walks_count) {
3451 cifs_put_tcon(tcon);
3453 cifs_put_smb_ses(ses);
3468 server = cifs_get_tcp_session(volume_info);
3469 if (IS_ERR(server)) {
3470 rc = PTR_ERR(server);
3476 ses = cifs_get_smb_ses(server, volume_info);
3480 goto mount_fail_check;
3484 tcon = cifs_get_tcon(ses, volume_info);
3488 goto remote_path_check;
3492 if (cap_unix(tcon->
ses)) {
3500 goto mount_fail_check;
3506 if (!tcon->
ipc && server->
ops->qfs_tcon)
3507 server->
ops->qfs_tcon(xid, tcon);
3509 cifs_sb->
wsize = server->
ops->negotiate_wsize(tcon, volume_info);
3510 cifs_sb->
rsize = server->
ops->negotiate_rsize(tcon, volume_info);
3516 #ifdef CONFIG_CIFS_DFS_UPCALL
3524 if (referral_walks_count == 0) {
3525 int refrc = expand_dfs_referral(xid, ses, volume_info, cifs_sb,
3528 referral_walks_count++;
3529 goto try_mount_again;
3536 if (!server->
ops->is_path_accessible) {
3538 goto mount_fail_check;
3541 full_path = build_path_to_root(volume_info, cifs_sb, tcon);
3542 if (full_path ==
NULL) {
3544 goto mount_fail_check;
3546 rc = server->
ops->is_path_accessible(xid, tcon, cifs_sb,
3548 if (rc != 0 && rc != -
EREMOTE) {
3550 goto mount_fail_check;
3557 #ifdef CONFIG_CIFS_DFS_UPCALL
3566 goto mount_fail_check;
3569 rc = expand_dfs_referral(xid, ses, volume_info, cifs_sb,
true);
3572 referral_walks_count++;
3573 goto try_mount_again;
3575 goto mount_fail_check;
3582 goto mount_fail_check;
3586 if (tlink ==
NULL) {
3588 goto mount_fail_check;
3599 tlink_rb_insert(&cifs_sb->
tlink_tree, tlink);
3611 cifs_put_tcon(tcon);
3613 cifs_put_smb_ses(ses);
3615 cifs_put_tcp_session(server);
3634 struct smb_hdr *smb_buffer_response;
3637 unsigned char *bcc_ptr;
3646 if (smb_buffer ==
NULL)
3649 smb_buffer_response = smb_buffer;
3654 smb_buffer->
Mid = get_next_mid(ses->
server);
3656 pSMB = (TCONX_REQ *) smb_buffer;
3657 pSMBr = (TCONX_RSP *) smb_buffer_response;
3659 pSMB->AndXCommand = 0xFF;
3661 bcc_ptr = &pSMB->Password[0];
3675 #ifdef CONFIG_CIFS_WEAK_PW_HASH
3685 bcc_ptr, nls_codepage);
3695 if (ses->
server->sec_mode &
3710 ( + 256 ), nls_codepage);
3715 bcc_ptr +=
strlen(tree) + 1;
3717 strcpy(bcc_ptr,
"?????");
3718 bcc_ptr +=
strlen(
"?????");
3720 count = bcc_ptr - &pSMB->Password[0];
3722 pSMB->hdr.smb_buf_length) + count);
3725 rc =
SendReceive(xid, ses, smb_buffer, smb_buffer_response, &length,
3729 if ((rc == 0) && (tcon !=
NULL)) {
3734 tcon->
tid = smb_buffer_response->
Tid;
3735 bcc_ptr =
pByteArea(smb_buffer_response);
3736 bytes_left = get_bcc(smb_buffer_response);
3737 length =
strnlen(bcc_ptr, bytes_left - 2);
3746 if ((bcc_ptr[0] ==
'I') && (bcc_ptr[1] ==
'P') &&
3747 (bcc_ptr[2] ==
'C')) {
3748 cFYI(1,
"IPC connection");
3751 }
else if (length == 2) {
3752 if ((bcc_ptr[0] ==
'A') && (bcc_ptr[1] ==
':')) {
3754 cFYI(1,
"disk share connection");
3757 bcc_ptr += length + 1;
3758 bytes_left -= (length + 1);
3764 bytes_left, is_unicode,
3769 if ((smb_buffer_response->
WordCount == 3) ||
3775 cFYI(1,
"Tcon flags: 0x%x ", tcon->
Flags);
3776 }
else if ((rc == 0) && tcon ==
NULL) {
3797 cifs_get_tlink(tlink);
3819 if (!server->
ops->need_neg || !server->
ops->negotiate)
3823 if (!server->
ops->need_neg(server))
3826 set_credits(server, 1);
3828 rc = server->
ops->negotiate(xid, ses);
3853 cFYI(1,
"Security Mode: 0x%x Capabilities: 0x%x TimeAdjust: %d",
3856 if (server->
ops->sess_setup)
3857 rc = server->
ops->sess_setup(xid, ses, nls_info);
3860 cERROR(1,
"Send error in SessSetup = %d", rc);
3872 cFYI(1,
"CIFS Session Established successfully");
3891 switch (ses->
server->secType) {
3909 return cifs_set_cifscreds(vol, ses);
3921 vol_info = kzalloc(
sizeof(*vol_info),
GFP_KERNEL);
3922 if (vol_info ==
NULL)
3934 rc = cifs_set_vol_auth(vol_info, master_tcon->
ses);
3942 ++master_tcon->
ses->server->srv_count;
3945 ses = cifs_get_smb_ses(master_tcon->
ses->server, vol_info);
3948 cifs_put_tcp_session(master_tcon->
ses->server);
3952 tcon = cifs_get_tcon(ses, vol_info);
3954 cifs_put_smb_ses(ses);
3971 return tlink_tcon(cifs_sb_master_tlink(cifs_sb));
3975 cifs_sb_tcon_pending_wait(
void *
unused)
3993 else if (tlink->
tl_uid < uid)
4013 new = &((*new)->rb_left);
4015 new = &((*new)->rb_right);
4018 rb_link_node(&new_tlink->
tl_rbnode, parent,
new);
4046 return cifs_get_tlink(cifs_sb_master_tlink(cifs_sb));
4049 tlink = tlink_rb_search(&cifs_sb->
tlink_tree, fsuid);
4051 cifs_get_tlink(tlink);
4054 if (tlink ==
NULL) {
4055 newtlink = kzalloc(
sizeof(*tlink),
GFP_KERNEL);
4056 if (newtlink ==
NULL)
4058 newtlink->
tl_uid = fsuid;
4062 cifs_get_tlink(newtlink);
4066 tlink = tlink_rb_search(&cifs_sb->
tlink_tree, fsuid);
4068 cifs_get_tlink(tlink);
4071 goto wait_for_construction;
4074 tlink_rb_insert(&cifs_sb->
tlink_tree, tlink);
4077 wait_for_construction:
4079 cifs_sb_tcon_pending_wait,
4083 return ERR_PTR(ret);
4097 goto wait_for_construction;
4100 tlink->
tl_tcon = cifs_construct_tcon(cifs_sb, fsuid);
4135 while (node !=
NULL) {
4145 cifs_get_tlink(tlink);