~ubuntu-branches/ubuntu/precise/linux-ti-omap4/precise

« back to all changes in this revision

Viewing changes to fs/cifs/connect.c

  • Committer: Bazaar Package Importer
  • Author(s): Paolo Pisati
  • Date: 2011-06-29 15:23:51 UTC
  • mfrom: (26.1.1 natty-proposed)
  • Revision ID: james.westby@ubuntu.com-20110629152351-xs96tm303d95rpbk
Tags: 3.0.0-1200.2
* Rebased against 3.0.0-6.7
* BSP from TI based on 3.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
57
57
 
58
58
extern mempool_t *cifs_req_poolp;
59
59
 
60
 
struct smb_vol {
61
 
        char *username;
62
 
        char *password;
63
 
        char *domainname;
64
 
        char *UNC;
65
 
        char *UNCip;
66
 
        char *iocharset;  /* local code page for mapping to and from Unicode */
67
 
        char source_rfc1001_name[RFC1001_NAME_LEN_WITH_NULL]; /* clnt nb name */
68
 
        char target_rfc1001_name[RFC1001_NAME_LEN_WITH_NULL]; /* srvr nb name */
69
 
        uid_t cred_uid;
70
 
        uid_t linux_uid;
71
 
        gid_t linux_gid;
72
 
        mode_t file_mode;
73
 
        mode_t dir_mode;
74
 
        unsigned secFlg;
75
 
        bool retry:1;
76
 
        bool intr:1;
77
 
        bool setuids:1;
78
 
        bool override_uid:1;
79
 
        bool override_gid:1;
80
 
        bool dynperm:1;
81
 
        bool noperm:1;
82
 
        bool no_psx_acl:1; /* set if posix acl support should be disabled */
83
 
        bool cifs_acl:1;
84
 
        bool no_xattr:1;   /* set if xattr (EA) support should be disabled*/
85
 
        bool server_ino:1; /* use inode numbers from server ie UniqueId */
86
 
        bool direct_io:1;
87
 
        bool strict_io:1; /* strict cache behavior */
88
 
        bool remap:1;      /* set to remap seven reserved chars in filenames */
89
 
        bool posix_paths:1; /* unset to not ask for posix pathnames. */
90
 
        bool no_linux_ext:1;
91
 
        bool sfu_emul:1;
92
 
        bool nullauth:1;   /* attempt to authenticate with null user */
93
 
        bool nocase:1;     /* request case insensitive filenames */
94
 
        bool nobrl:1;      /* disable sending byte range locks to srv */
95
 
        bool mand_lock:1;  /* send mandatory not posix byte range lock reqs */
96
 
        bool seal:1;       /* request transport encryption on share */
97
 
        bool nodfs:1;      /* Do not request DFS, even if available */
98
 
        bool local_lease:1; /* check leases only on local system, not remote */
99
 
        bool noblocksnd:1;
100
 
        bool noautotune:1;
101
 
        bool nostrictsync:1; /* do not force expensive SMBflush on every sync */
102
 
        bool fsc:1;     /* enable fscache */
103
 
        bool mfsymlinks:1; /* use Minshall+French Symlinks */
104
 
        bool multiuser:1;
105
 
        unsigned int rsize;
106
 
        unsigned int wsize;
107
 
        bool sockopt_tcp_nodelay:1;
108
 
        unsigned short int port;
109
 
        unsigned long actimeo; /* attribute cache timeout (jiffies) */
110
 
        char *prepath;
111
 
        struct sockaddr_storage srcaddr; /* allow binding to a local IP */
112
 
        struct nls_table *local_nls;
113
 
};
114
 
 
115
60
/* FIXME: should these be tunable? */
116
61
#define TLINK_ERROR_EXPIRE      (1 * HZ)
117
62
#define TLINK_IDLE_EXPIRE       (600 * HZ)
120
65
static int generic_ip_connect(struct TCP_Server_Info *server);
121
66
static void tlink_rb_insert(struct rb_root *root, struct tcon_link *new_tlink);
122
67
static void cifs_prune_tlinks(struct work_struct *work);
 
68
static int cifs_setup_volume_info(struct smb_vol *volume_info, char *mount_data,
 
69
                                        const char *devname);
123
70
 
124
71
/*
125
72
 * cifs tcp session reconnection
134
81
{
135
82
        int rc = 0;
136
83
        struct list_head *tmp, *tmp2;
137
 
        struct cifsSesInfo *ses;
138
 
        struct cifsTconInfo *tcon;
 
84
        struct cifs_ses *ses;
 
85
        struct cifs_tcon *tcon;
139
86
        struct mid_q_entry *mid_entry;
 
87
        struct list_head retry_list;
140
88
 
141
89
        spin_lock(&GlobalMid_Lock);
142
90
        if (server->tcpStatus == CifsExiting) {
156
104
        cFYI(1, "%s: marking sessions and tcons for reconnect", __func__);
157
105
        spin_lock(&cifs_tcp_ses_lock);
158
106
        list_for_each(tmp, &server->smb_ses_list) {
159
 
                ses = list_entry(tmp, struct cifsSesInfo, smb_ses_list);
 
107
                ses = list_entry(tmp, struct cifs_ses, smb_ses_list);
160
108
                ses->need_reconnect = true;
161
109
                ses->ipc_tid = 0;
162
110
                list_for_each(tmp2, &ses->tcon_list) {
163
 
                        tcon = list_entry(tmp2, struct cifsTconInfo, tcon_list);
 
111
                        tcon = list_entry(tmp2, struct cifs_tcon, tcon_list);
164
112
                        tcon->need_reconnect = true;
165
113
                }
166
114
        }
188
136
        mutex_unlock(&server->srv_mutex);
189
137
 
190
138
        /* mark submitted MIDs for retry and issue callback */
191
 
        cFYI(1, "%s: issuing mid callbacks", __func__);
 
139
        INIT_LIST_HEAD(&retry_list);
 
140
        cFYI(1, "%s: moving mids to private list", __func__);
192
141
        spin_lock(&GlobalMid_Lock);
193
142
        list_for_each_safe(tmp, tmp2, &server->pending_mid_q) {
194
143
                mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
195
144
                if (mid_entry->midState == MID_REQUEST_SUBMITTED)
196
145
                        mid_entry->midState = MID_RETRY_NEEDED;
 
146
                list_move(&mid_entry->qhead, &retry_list);
 
147
        }
 
148
        spin_unlock(&GlobalMid_Lock);
 
149
 
 
150
        cFYI(1, "%s: issuing mid callbacks", __func__);
 
151
        list_for_each_safe(tmp, tmp2, &retry_list) {
 
152
                mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
197
153
                list_del_init(&mid_entry->qhead);
198
154
                mid_entry->callback(mid_entry);
199
155
        }
200
 
        spin_unlock(&GlobalMid_Lock);
201
156
 
202
 
        while ((server->tcpStatus != CifsExiting) &&
203
 
               (server->tcpStatus != CifsGood)) {
 
157
        do {
204
158
                try_to_freeze();
205
159
 
206
160
                /* we should try only the port we connected to before */
212
166
                        atomic_inc(&tcpSesReconnectCount);
213
167
                        spin_lock(&GlobalMid_Lock);
214
168
                        if (server->tcpStatus != CifsExiting)
215
 
                                server->tcpStatus = CifsGood;
 
169
                                server->tcpStatus = CifsNeedNegotiate;
216
170
                        spin_unlock(&GlobalMid_Lock);
217
171
                }
218
 
        }
 
172
        } while (server->tcpStatus == CifsNeedReconnect);
219
173
 
220
174
        return rc;
221
175
}
248
202
        total_data_size = get_unaligned_le16(&pSMBt->t2_rsp.TotalDataCount);
249
203
        data_in_this_rsp = get_unaligned_le16(&pSMBt->t2_rsp.DataCount);
250
204
 
251
 
        remaining = total_data_size - data_in_this_rsp;
252
 
 
253
 
        if (remaining == 0)
 
205
        if (total_data_size == data_in_this_rsp)
254
206
                return 0;
255
 
        else if (remaining < 0) {
 
207
        else if (total_data_size < data_in_this_rsp) {
256
208
                cFYI(1, "total data %d smaller than data in frame %d",
257
209
                        total_data_size, data_in_this_rsp);
258
210
                return -EINVAL;
259
 
        } else {
260
 
                cFYI(1, "missing %d bytes from transact2, check next response",
261
 
                        remaining);
262
 
                if (total_data_size > maxBufSize) {
263
 
                        cERROR(1, "TotalDataSize %d is over maximum buffer %d",
264
 
                                total_data_size, maxBufSize);
265
 
                        return -EINVAL;
266
 
                }
267
 
                return remaining;
268
 
        }
 
211
        }
 
212
 
 
213
        remaining = total_data_size - data_in_this_rsp;
 
214
 
 
215
        cFYI(1, "missing %d bytes from transact2, check next response",
 
216
                remaining);
 
217
        if (total_data_size > maxBufSize) {
 
218
                cERROR(1, "TotalDataSize %d is over maximum buffer %d",
 
219
                        total_data_size, maxBufSize);
 
220
                return -EINVAL;
 
221
        }
 
222
        return remaining;
269
223
}
270
224
 
271
225
static int coalesce_t2(struct smb_hdr *psecond, struct smb_hdr *pTargetSMB)
275
229
        char *data_area_of_target;
276
230
        char *data_area_of_buf2;
277
231
        int remaining;
278
 
        __u16 byte_count, total_data_size, total_in_buf, total_in_buf2;
 
232
        unsigned int byte_count, total_in_buf;
 
233
        __u16 total_data_size, total_in_buf2;
279
234
 
280
235
        total_data_size = get_unaligned_le16(&pSMBt->t2_rsp.TotalDataCount);
281
236
 
288
243
        remaining = total_data_size - total_in_buf;
289
244
 
290
245
        if (remaining < 0)
291
 
                return -EINVAL;
 
246
                return -EPROTO;
292
247
 
293
248
        if (remaining == 0) /* nothing to do, ignore */
294
249
                return 0;
309
264
        data_area_of_target += total_in_buf;
310
265
 
311
266
        /* copy second buffer into end of first buffer */
312
 
        memcpy(data_area_of_target, data_area_of_buf2, total_in_buf2);
313
267
        total_in_buf += total_in_buf2;
 
268
        /* is the result too big for the field? */
 
269
        if (total_in_buf > USHRT_MAX)
 
270
                return -EPROTO;
314
271
        put_unaligned_le16(total_in_buf, &pSMBt->t2_rsp.DataCount);
315
 
        byte_count = get_bcc_le(pTargetSMB);
316
 
        byte_count += total_in_buf2;
317
 
        put_bcc_le(byte_count, pTargetSMB);
318
 
 
319
 
        byte_count = pTargetSMB->smb_buf_length;
320
 
        byte_count += total_in_buf2;
321
 
 
322
 
        /* BB also add check that we are not beyond maximum buffer size */
323
 
 
324
 
        pTargetSMB->smb_buf_length = byte_count;
 
272
 
 
273
        /* fix up the BCC */
 
274
        byte_count = get_bcc(pTargetSMB);
 
275
        byte_count += total_in_buf2;
 
276
        /* is the result too big for the field? */
 
277
        if (byte_count > USHRT_MAX)
 
278
                return -EPROTO;
 
279
        put_bcc(byte_count, pTargetSMB);
 
280
 
 
281
        byte_count = be32_to_cpu(pTargetSMB->smb_buf_length);
 
282
        byte_count += total_in_buf2;
 
283
        /* don't allow buffer to overflow */
 
284
        if (byte_count > CIFSMaxBufSize)
 
285
                return -ENOBUFS;
 
286
        pTargetSMB->smb_buf_length = cpu_to_be32(byte_count);
 
287
 
 
288
        memcpy(data_area_of_target, data_area_of_buf2, total_in_buf2);
325
289
 
326
290
        if (remaining == total_in_buf2) {
327
291
                cFYI(1, "found the last secondary response");
421
385
                pdu_length = 4; /* enough to get RFC1001 header */
422
386
 
423
387
incomplete_rcv:
424
 
                if (echo_retries > 0 &&
 
388
                if (echo_retries > 0 && server->tcpStatus == CifsGood &&
425
389
                    time_after(jiffies, server->lstrp +
426
390
                                        (echo_retries * SMB_ECHO_INTERVAL))) {
427
391
                        cERROR(1, "Server %s has not responded in %d seconds. "
486
450
                /* Note that FC 1001 length is big endian on the wire,
487
451
                but we convert it here so it is always manipulated
488
452
                as host byte order */
489
 
                pdu_length = be32_to_cpu((__force __be32)smb_buffer->smb_buf_length);
490
 
                smb_buffer->smb_buf_length = pdu_length;
 
453
                pdu_length = be32_to_cpu(smb_buffer->smb_buf_length);
491
454
 
492
455
                cFYI(1, "rfc1002 length 0x%x", pdu_length+4);
493
456
 
608
571
                list_for_each_safe(tmp, tmp2, &server->pending_mid_q) {
609
572
                        mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
610
573
 
611
 
                        if ((mid_entry->mid == smb_buffer->Mid) &&
612
 
                            (mid_entry->midState == MID_REQUEST_SUBMITTED) &&
613
 
                            (mid_entry->command == smb_buffer->Command)) {
614
 
                                if (length == 0 &&
615
 
                                   check2ndT2(smb_buffer, server->maxBuf) > 0) {
616
 
                                        /* We have a multipart transact2 resp */
617
 
                                        isMultiRsp = true;
618
 
                                        if (mid_entry->resp_buf) {
619
 
                                                /* merge response - fix up 1st*/
620
 
                                                if (coalesce_t2(smb_buffer,
621
 
                                                        mid_entry->resp_buf)) {
622
 
                                                        mid_entry->multiRsp =
623
 
                                                                 true;
624
 
                                                        break;
625
 
                                                } else {
626
 
                                                        /* all parts received */
627
 
                                                        mid_entry->multiEnd =
628
 
                                                                 true;
629
 
                                                        goto multi_t2_fnd;
630
 
                                                }
631
 
                                        } else {
632
 
                                                if (!isLargeBuf) {
633
 
                                                        cERROR(1, "1st trans2 resp needs bigbuf");
634
 
                                        /* BB maybe we can fix this up,  switch
635
 
                                           to already allocated large buffer? */
636
 
                                                } else {
637
 
                                                        /* Have first buffer */
638
 
                                                        mid_entry->resp_buf =
639
 
                                                                 smb_buffer;
640
 
                                                        mid_entry->largeBuf =
641
 
                                                                 true;
642
 
                                                        bigbuf = NULL;
643
 
                                                }
644
 
                                        }
645
 
                                        break;
 
574
                        if (mid_entry->mid != smb_buffer->Mid ||
 
575
                            mid_entry->midState != MID_REQUEST_SUBMITTED ||
 
576
                            mid_entry->command != smb_buffer->Command) {
 
577
                                mid_entry = NULL;
 
578
                                continue;
 
579
                        }
 
580
 
 
581
                        if (length == 0 &&
 
582
                            check2ndT2(smb_buffer, server->maxBuf) > 0) {
 
583
                                /* We have a multipart transact2 resp */
 
584
                                isMultiRsp = true;
 
585
                                if (mid_entry->resp_buf) {
 
586
                                        /* merge response - fix up 1st*/
 
587
                                        length = coalesce_t2(smb_buffer,
 
588
                                                        mid_entry->resp_buf);
 
589
                                        if (length > 0) {
 
590
                                                length = 0;
 
591
                                                mid_entry->multiRsp = true;
 
592
                                                break;
 
593
                                        } else {
 
594
                                                /* all parts received or
 
595
                                                 * packet is malformed
 
596
                                                 */
 
597
                                                mid_entry->multiEnd = true;
 
598
                                                goto multi_t2_fnd;
 
599
                                        }
 
600
                                } else {
 
601
                                        if (!isLargeBuf) {
 
602
                                                /*
 
603
                                                 * FIXME: switch to already
 
604
                                                 *        allocated largebuf?
 
605
                                                 */
 
606
                                                cERROR(1, "1st trans2 resp "
 
607
                                                          "needs bigbuf");
 
608
                                        } else {
 
609
                                                /* Have first buffer */
 
610
                                                mid_entry->resp_buf =
 
611
                                                         smb_buffer;
 
612
                                                mid_entry->largeBuf = true;
 
613
                                                bigbuf = NULL;
 
614
                                        }
646
615
                                }
647
 
                                mid_entry->resp_buf = smb_buffer;
648
 
                                mid_entry->largeBuf = isLargeBuf;
 
616
                                break;
 
617
                        }
 
618
                        mid_entry->resp_buf = smb_buffer;
 
619
                        mid_entry->largeBuf = isLargeBuf;
649
620
multi_t2_fnd:
650
 
                                if (length == 0)
651
 
                                        mid_entry->midState =
652
 
                                                        MID_RESPONSE_RECEIVED;
653
 
                                else
654
 
                                        mid_entry->midState =
655
 
                                                        MID_RESPONSE_MALFORMED;
 
621
                        if (length == 0)
 
622
                                mid_entry->midState = MID_RESPONSE_RECEIVED;
 
623
                        else
 
624
                                mid_entry->midState = MID_RESPONSE_MALFORMED;
656
625
#ifdef CONFIG_CIFS_STATS2
657
 
                                mid_entry->when_received = jiffies;
 
626
                        mid_entry->when_received = jiffies;
658
627
#endif
659
 
                                list_del_init(&mid_entry->qhead);
660
 
                                mid_entry->callback(mid_entry);
661
 
                                break;
662
 
                        }
663
 
                        mid_entry = NULL;
 
628
                        list_del_init(&mid_entry->qhead);
 
629
                        break;
664
630
                }
665
631
                spin_unlock(&GlobalMid_Lock);
666
632
 
667
633
                if (mid_entry != NULL) {
 
634
                        mid_entry->callback(mid_entry);
668
635
                        /* Was previous buf put in mpx struct for multi-rsp? */
669
636
                        if (!isMultiRsp) {
670
637
                                /* smb buffer will be freed by user thread */
722
689
                sock_release(csocket);
723
690
                server->ssocket = NULL;
724
691
        }
725
 
        /* buffer usuallly freed in free_mid - need to free it here on exit */
 
692
        /* buffer usually freed in free_mid - need to free it here on exit */
726
693
        cifs_buf_release(bigbuf);
727
694
        if (smallbuf) /* no sense logging a debug message if NULL */
728
695
                cifs_small_buf_release(smallbuf);
729
696
 
730
697
        if (!list_empty(&server->pending_mid_q)) {
 
698
                struct list_head dispose_list;
 
699
 
 
700
                INIT_LIST_HEAD(&dispose_list);
731
701
                spin_lock(&GlobalMid_Lock);
732
702
                list_for_each_safe(tmp, tmp2, &server->pending_mid_q) {
733
703
                        mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
734
 
                        cFYI(1, "Clearing Mid 0x%x - issuing callback",
735
 
                                         mid_entry->mid);
 
704
                        cFYI(1, "Clearing mid 0x%x", mid_entry->mid);
 
705
                        mid_entry->midState = MID_SHUTDOWN;
 
706
                        list_move(&mid_entry->qhead, &dispose_list);
 
707
                }
 
708
                spin_unlock(&GlobalMid_Lock);
 
709
 
 
710
                /* now walk dispose list and issue callbacks */
 
711
                list_for_each_safe(tmp, tmp2, &dispose_list) {
 
712
                        mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
 
713
                        cFYI(1, "Callback mid 0x%x", mid_entry->mid);
736
714
                        list_del_init(&mid_entry->qhead);
737
715
                        mid_entry->callback(mid_entry);
738
716
                }
739
 
                spin_unlock(&GlobalMid_Lock);
740
717
                /* 1/8th of sec is more than enough time for them to exit */
741
718
                msleep(125);
742
719
        }
805
782
}
806
783
 
807
784
static int
808
 
cifs_parse_mount_options(char *options, const char *devname,
 
785
cifs_parse_mount_options(const char *mountdata, const char *devname,
809
786
                         struct smb_vol *vol)
810
787
{
811
 
        char *value;
812
 
        char *data;
 
788
        char *value, *data, *end;
 
789
        char *mountdata_copy = NULL, *options;
813
790
        unsigned int  temp_len, i, j;
814
791
        char separator[2];
815
792
        short int override_uid = -1;
849
826
 
850
827
        vol->actimeo = CIFS_DEF_ACTIMEO;
851
828
 
852
 
        if (!options)
853
 
                return 1;
854
 
 
 
829
        if (!mountdata)
 
830
                goto cifs_parse_mount_err;
 
831
 
 
832
        mountdata_copy = kstrndup(mountdata, PAGE_SIZE, GFP_KERNEL);
 
833
        if (!mountdata_copy)
 
834
                goto cifs_parse_mount_err;
 
835
 
 
836
        options = mountdata_copy;
 
837
        end = options + strlen(options);
855
838
        if (strncmp(options, "sep=", 4) == 0) {
856
839
                if (options[4] != 0) {
857
840
                        separator[0] = options[4];
876
859
                        if (!value) {
877
860
                                printk(KERN_WARNING
878
861
                                       "CIFS: invalid or missing username\n");
879
 
                                return 1;       /* needs_arg; */
 
862
                                goto cifs_parse_mount_err;
880
863
                        } else if (!*value) {
881
864
                                /* null user, ie anonymous, authentication */
882
865
                                vol->nullauth = 1;
883
866
                        }
884
 
                        if (strnlen(value, 200) < 200) {
885
 
                                vol->username = value;
 
867
                        if (strnlen(value, MAX_USERNAME_SIZE) <
 
868
                                                MAX_USERNAME_SIZE) {
 
869
                                vol->username = kstrdup(value, GFP_KERNEL);
 
870
                                if (!vol->username) {
 
871
                                        printk(KERN_WARNING "CIFS: no memory "
 
872
                                                            "for username\n");
 
873
                                        goto cifs_parse_mount_err;
 
874
                                }
886
875
                        } else {
887
876
                                printk(KERN_WARNING "CIFS: username too long\n");
888
 
                                return 1;
 
877
                                goto cifs_parse_mount_err;
889
878
                        }
890
879
                } else if (strnicmp(data, "pass", 4) == 0) {
891
880
                        if (!value) {
916
905
                        the only illegal character in a password is null */
917
906
 
918
907
                        if ((value[temp_len] == 0) &&
 
908
                            (value + temp_len < end) &&
919
909
                            (value[temp_len+1] == separator[0])) {
920
910
                                /* reinsert comma */
921
911
                                value[temp_len] = separator[0];
948
938
                                if (vol->password == NULL) {
949
939
                                        printk(KERN_WARNING "CIFS: no memory "
950
940
                                                            "for password\n");
951
 
                                        return 1;
 
941
                                        goto cifs_parse_mount_err;
952
942
                                }
953
943
                                for (i = 0, j = 0; i < temp_len; i++, j++) {
954
944
                                        vol->password[j] = value[i];
964
954
                                if (vol->password == NULL) {
965
955
                                        printk(KERN_WARNING "CIFS: no memory "
966
956
                                                            "for password\n");
967
 
                                        return 1;
 
957
                                        goto cifs_parse_mount_err;
968
958
                                }
969
959
                                strcpy(vol->password, value);
970
960
                        }
974
964
                                vol->UNCip = NULL;
975
965
                        } else if (strnlen(value, INET6_ADDRSTRLEN) <
976
966
                                                        INET6_ADDRSTRLEN) {
977
 
                                vol->UNCip = value;
 
967
                                vol->UNCip = kstrdup(value, GFP_KERNEL);
 
968
                                if (!vol->UNCip) {
 
969
                                        printk(KERN_WARNING "CIFS: no memory "
 
970
                                                            "for UNC IP\n");
 
971
                                        goto cifs_parse_mount_err;
 
972
                                }
978
973
                        } else {
979
974
                                printk(KERN_WARNING "CIFS: ip address "
980
975
                                                    "too long\n");
981
 
                                return 1;
 
976
                                goto cifs_parse_mount_err;
982
977
                        }
983
978
                } else if (strnicmp(data, "sec", 3) == 0) {
984
979
                        if (!value || !*value) {
991
986
                                /* vol->secFlg |= CIFSSEC_MUST_SEAL |
992
987
                                        CIFSSEC_MAY_KRB5; */
993
988
                                cERROR(1, "Krb5 cifs privacy not supported");
994
 
                                return 1;
 
989
                                goto cifs_parse_mount_err;
995
990
                        } else if (strnicmp(value, "krb5", 4) == 0) {
996
991
                                vol->secFlg |= CIFSSEC_MAY_KRB5;
997
992
                        } else if (strnicmp(value, "ntlmsspi", 8) == 0) {
1021
1016
                                vol->nullauth = 1;
1022
1017
                        } else {
1023
1018
                                cERROR(1, "bad security option: %s", value);
1024
 
                                return 1;
 
1019
                                goto cifs_parse_mount_err;
 
1020
                        }
 
1021
                } else if (strnicmp(data, "vers", 3) == 0) {
 
1022
                        if (!value || !*value) {
 
1023
                                cERROR(1, "no protocol version specified"
 
1024
                                          " after vers= mount option");
 
1025
                        } else if ((strnicmp(value, "cifs", 4) == 0) ||
 
1026
                                   (strnicmp(value, "1", 1) == 0)) {
 
1027
                                /* this is the default */
 
1028
                                continue;
1025
1029
                        }
1026
1030
                } else if ((strnicmp(data, "unc", 3) == 0)
1027
1031
                           || (strnicmp(data, "target", 6) == 0)
1029
1033
                        if (!value || !*value) {
1030
1034
                                printk(KERN_WARNING "CIFS: invalid path to "
1031
1035
                                                    "network resource\n");
1032
 
                                return 1;       /* needs_arg; */
 
1036
                                goto cifs_parse_mount_err;
1033
1037
                        }
1034
1038
                        if ((temp_len = strnlen(value, 300)) < 300) {
1035
1039
                                vol->UNC = kmalloc(temp_len+1, GFP_KERNEL);
1036
1040
                                if (vol->UNC == NULL)
1037
 
                                        return 1;
 
1041
                                        goto cifs_parse_mount_err;
1038
1042
                                strcpy(vol->UNC, value);
1039
1043
                                if (strncmp(vol->UNC, "//", 2) == 0) {
1040
1044
                                        vol->UNC[0] = '\\';
1043
1047
                                        printk(KERN_WARNING
1044
1048
                                               "CIFS: UNC Path does not begin "
1045
1049
                                               "with // or \\\\ \n");
1046
 
                                        return 1;
 
1050
                                        goto cifs_parse_mount_err;
1047
1051
                                }
1048
1052
                        } else {
1049
1053
                                printk(KERN_WARNING "CIFS: UNC name too long\n");
1050
 
                                return 1;
 
1054
                                goto cifs_parse_mount_err;
1051
1055
                        }
1052
1056
                } else if ((strnicmp(data, "domain", 3) == 0)
1053
1057
                           || (strnicmp(data, "workgroup", 5) == 0)) {
1054
1058
                        if (!value || !*value) {
1055
1059
                                printk(KERN_WARNING "CIFS: invalid domain name\n");
1056
 
                                return 1;       /* needs_arg; */
 
1060
                                goto cifs_parse_mount_err;
1057
1061
                        }
1058
1062
                        /* BB are there cases in which a comma can be valid in
1059
1063
                        a domain name and need special handling? */
1060
1064
                        if (strnlen(value, 256) < 256) {
1061
 
                                vol->domainname = value;
 
1065
                                vol->domainname = kstrdup(value, GFP_KERNEL);
 
1066
                                if (!vol->domainname) {
 
1067
                                        printk(KERN_WARNING "CIFS: no memory "
 
1068
                                                            "for domainname\n");
 
1069
                                        goto cifs_parse_mount_err;
 
1070
                                }
1062
1071
                                cFYI(1, "Domain name set");
1063
1072
                        } else {
1064
1073
                                printk(KERN_WARNING "CIFS: domain name too "
1065
1074
                                                    "long\n");
1066
 
                                return 1;
 
1075
                                goto cifs_parse_mount_err;
1067
1076
                        }
1068
1077
                } else if (strnicmp(data, "srcaddr", 7) == 0) {
1069
1078
                        vol->srcaddr.ss_family = AF_UNSPEC;
1071
1080
                        if (!value || !*value) {
1072
1081
                                printk(KERN_WARNING "CIFS: srcaddr value"
1073
1082
                                       " not specified.\n");
1074
 
                                return 1;       /* needs_arg; */
 
1083
                                goto cifs_parse_mount_err;
1075
1084
                        }
1076
1085
                        i = cifs_convert_address((struct sockaddr *)&vol->srcaddr,
1077
1086
                                                 value, strlen(value));
1079
1088
                                printk(KERN_WARNING "CIFS:  Could not parse"
1080
1089
                                       " srcaddr: %s\n",
1081
1090
                                       value);
1082
 
                                return 1;
 
1091
                                goto cifs_parse_mount_err;
1083
1092
                        }
1084
1093
                } else if (strnicmp(data, "prefixpath", 10) == 0) {
1085
1094
                        if (!value || !*value) {
1086
1095
                                printk(KERN_WARNING
1087
1096
                                        "CIFS: invalid path prefix\n");
1088
 
                                return 1;       /* needs_argument */
 
1097
                                goto cifs_parse_mount_err;
1089
1098
                        }
1090
1099
                        if ((temp_len = strnlen(value, 1024)) < 1024) {
1091
1100
                                if (value[0] != '/')
1092
1101
                                        temp_len++;  /* missing leading slash */
1093
1102
                                vol->prepath = kmalloc(temp_len+1, GFP_KERNEL);
1094
1103
                                if (vol->prepath == NULL)
1095
 
                                        return 1;
 
1104
                                        goto cifs_parse_mount_err;
1096
1105
                                if (value[0] != '/') {
1097
1106
                                        vol->prepath[0] = '/';
1098
1107
                                        strcpy(vol->prepath+1, value);
1101
1110
                                cFYI(1, "prefix path %s", vol->prepath);
1102
1111
                        } else {
1103
1112
                                printk(KERN_WARNING "CIFS: prefix too long\n");
1104
 
                                return 1;
 
1113
                                goto cifs_parse_mount_err;
1105
1114
                        }
1106
1115
                } else if (strnicmp(data, "iocharset", 9) == 0) {
1107
1116
                        if (!value || !*value) {
1108
1117
                                printk(KERN_WARNING "CIFS: invalid iocharset "
1109
1118
                                                    "specified\n");
1110
 
                                return 1;       /* needs_arg; */
 
1119
                                goto cifs_parse_mount_err;
1111
1120
                        }
1112
1121
                        if (strnlen(value, 65) < 65) {
1113
 
                                if (strnicmp(value, "default", 7))
1114
 
                                        vol->iocharset = value;
 
1122
                                if (strnicmp(value, "default", 7)) {
 
1123
                                        vol->iocharset = kstrdup(value,
 
1124
                                                                 GFP_KERNEL);
 
1125
 
 
1126
                                        if (!vol->iocharset) {
 
1127
                                                printk(KERN_WARNING "CIFS: no "
 
1128
                                                                   "memory for"
 
1129
                                                                   "charset\n");
 
1130
                                                goto cifs_parse_mount_err;
 
1131
                                        }
 
1132
                                }
1115
1133
                                /* if iocharset not set then load_nls_default
1116
1134
                                   is used by caller */
1117
1135
                                cFYI(1, "iocharset set to %s", value);
1118
1136
                        } else {
1119
1137
                                printk(KERN_WARNING "CIFS: iocharset name "
1120
1138
                                                    "too long.\n");
1121
 
                                return 1;
 
1139
                                goto cifs_parse_mount_err;
1122
1140
                        }
1123
1141
                } else if (!strnicmp(data, "uid", 3) && value && *value) {
1124
1142
                        vol->linux_uid = simple_strtoul(value, &value, 0);
1231
1249
                                if (vol->actimeo > CIFS_MAX_ACTIMEO) {
1232
1250
                                        cERROR(1, "CIFS: attribute cache"
1233
1251
                                                        "timeout too large");
1234
 
                                        return 1;
 
1252
                                        goto cifs_parse_mount_err;
1235
1253
                                }
1236
1254
                        }
1237
1255
                } else if (strnicmp(data, "credentials", 4) == 0) {
1343
1361
                        vol->server_ino = 1;
1344
1362
                } else if (strnicmp(data, "noserverino", 9) == 0) {
1345
1363
                        vol->server_ino = 0;
 
1364
                } else if (strnicmp(data, "rwpidforward", 4) == 0) {
 
1365
                        vol->rwpidforward = 1;
1346
1366
                } else if (strnicmp(data, "cifsacl", 7) == 0) {
1347
1367
                        vol->cifs_acl = 1;
1348
1368
                } else if (strnicmp(data, "nocifsacl", 9) == 0) {
1373
1393
                                "/proc/fs/cifs/LookupCacheEnabled to 0\n");
1374
1394
                } else if (strnicmp(data, "fsc", 3) == 0) {
1375
1395
#ifndef CONFIG_CIFS_FSCACHE
1376
 
                        cERROR(1, "FS-Cache support needs CONFIG_CIFS_FSCACHE"
 
1396
                        cERROR(1, "FS-Cache support needs CONFIG_CIFS_FSCACHE "
1377
1397
                                  "kernel config option set");
1378
 
                        return 1;
 
1398
                        goto cifs_parse_mount_err;
1379
1399
#endif
1380
1400
                        vol->fsc = true;
1381
1401
                } else if (strnicmp(data, "mfsymlinks", 10) == 0) {
1390
1410
                if (devname == NULL) {
1391
1411
                        printk(KERN_WARNING "CIFS: Missing UNC name for mount "
1392
1412
                                                "target\n");
1393
 
                        return 1;
 
1413
                        goto cifs_parse_mount_err;
1394
1414
                }
1395
1415
                if ((temp_len = strnlen(devname, 300)) < 300) {
1396
1416
                        vol->UNC = kmalloc(temp_len+1, GFP_KERNEL);
1397
1417
                        if (vol->UNC == NULL)
1398
 
                                return 1;
 
1418
                                goto cifs_parse_mount_err;
1399
1419
                        strcpy(vol->UNC, devname);
1400
1420
                        if (strncmp(vol->UNC, "//", 2) == 0) {
1401
1421
                                vol->UNC[0] = '\\';
1403
1423
                        } else if (strncmp(vol->UNC, "\\\\", 2) != 0) {
1404
1424
                                printk(KERN_WARNING "CIFS: UNC Path does not "
1405
1425
                                                    "begin with // or \\\\ \n");
1406
 
                                return 1;
 
1426
                                goto cifs_parse_mount_err;
1407
1427
                        }
1408
1428
                        value = strpbrk(vol->UNC+2, "/\\");
1409
1429
                        if (value)
1410
1430
                                *value = '\\';
1411
1431
                } else {
1412
1432
                        printk(KERN_WARNING "CIFS: UNC name too long\n");
1413
 
                        return 1;
 
1433
                        goto cifs_parse_mount_err;
1414
1434
                }
1415
1435
        }
1416
1436
 
1417
1437
        if (vol->multiuser && !(vol->secFlg & CIFSSEC_MAY_KRB5)) {
1418
1438
                cERROR(1, "Multiuser mounts currently require krb5 "
1419
1439
                          "authentication!");
1420
 
                return 1;
 
1440
                goto cifs_parse_mount_err;
1421
1441
        }
1422
1442
 
1423
1443
        if (vol->UNCip == NULL)
1435
1455
                printk(KERN_NOTICE "CIFS: ignoring forcegid mount option "
1436
1456
                                   "specified with no gid= option.\n");
1437
1457
 
 
1458
        kfree(mountdata_copy);
1438
1459
        return 0;
 
1460
 
 
1461
cifs_parse_mount_err:
 
1462
        kfree(mountdata_copy);
 
1463
        return 1;
1439
1464
}
1440
1465
 
1441
1466
/** Returns true if srcaddr isn't specified and rhs isn't
1472
1497
static bool
1473
1498
match_port(struct TCP_Server_Info *server, struct sockaddr *addr)
1474
1499
{
1475
 
        unsigned short int port, *sport;
 
1500
        __be16 port, *sport;
1476
1501
 
1477
1502
        switch (addr->sa_family) {
1478
1503
        case AF_INET:
1572
1597
                return false;
1573
1598
        }
1574
1599
 
1575
 
        /* now check if signing mode is acceptible */
 
1600
        /* now check if signing mode is acceptable */
1576
1601
        if ((secFlags & CIFSSEC_MAY_SIGN) == 0 &&
1577
 
            (server->secMode & SECMODE_SIGN_REQUIRED))
 
1602
            (server->sec_mode & SECMODE_SIGN_REQUIRED))
1578
1603
                        return false;
1579
1604
        else if (((secFlags & CIFSSEC_MUST_SIGN) == CIFSSEC_MUST_SIGN) &&
1580
 
                 (server->secMode &
 
1605
                 (server->sec_mode &
1581
1606
                  (SECMODE_SIGN_ENABLED|SECMODE_SIGN_REQUIRED)) == 0)
1582
1607
                        return false;
1583
1608
 
1584
1609
        return true;
1585
1610
}
1586
1611
 
 
1612
static int match_server(struct TCP_Server_Info *server, struct sockaddr *addr,
 
1613
                         struct smb_vol *vol)
 
1614
{
 
1615
        if (!net_eq(cifs_net_ns(server), current->nsproxy->net_ns))
 
1616
                return 0;
 
1617
 
 
1618
        if (!match_address(server, addr,
 
1619
                           (struct sockaddr *)&vol->srcaddr))
 
1620
                return 0;
 
1621
 
 
1622
        if (!match_port(server, addr))
 
1623
                return 0;
 
1624
 
 
1625
        if (!match_security(server, vol))
 
1626
                return 0;
 
1627
 
 
1628
        return 1;
 
1629
}
 
1630
 
1587
1631
static struct TCP_Server_Info *
1588
1632
cifs_find_tcp_session(struct sockaddr *addr, struct smb_vol *vol)
1589
1633
{
1591
1635
 
1592
1636
        spin_lock(&cifs_tcp_ses_lock);
1593
1637
        list_for_each_entry(server, &cifs_tcp_ses_list, tcp_ses_list) {
1594
 
                if (!net_eq(cifs_net_ns(server), current->nsproxy->net_ns))
1595
 
                        continue;
1596
 
 
1597
 
                if (!match_address(server, addr,
1598
 
                                   (struct sockaddr *)&vol->srcaddr))
1599
 
                        continue;
1600
 
 
1601
 
                if (!match_port(server, addr))
1602
 
                        continue;
1603
 
 
1604
 
                if (!match_security(server, vol))
 
1638
                if (!match_server(server, addr, vol))
1605
1639
                        continue;
1606
1640
 
1607
1641
                ++server->srv_count;
1765
1799
                module_put(THIS_MODULE);
1766
1800
                goto out_err_crypto_release;
1767
1801
        }
 
1802
        tcp_ses->tcpStatus = CifsNeedNegotiate;
1768
1803
 
1769
1804
        /* thread spawned, put it on the list */
1770
1805
        spin_lock(&cifs_tcp_ses_lock);
1794
1829
        return ERR_PTR(rc);
1795
1830
}
1796
1831
 
1797
 
static struct cifsSesInfo *
 
1832
static int match_session(struct cifs_ses *ses, struct smb_vol *vol)
 
1833
{
 
1834
        switch (ses->server->secType) {
 
1835
        case Kerberos:
 
1836
                if (vol->cred_uid != ses->cred_uid)
 
1837
                        return 0;
 
1838
                break;
 
1839
        default:
 
1840
                /* anything else takes username/password */
 
1841
                if (ses->user_name == NULL)
 
1842
                        return 0;
 
1843
                if (strncmp(ses->user_name, vol->username,
 
1844
                            MAX_USERNAME_SIZE))
 
1845
                        return 0;
 
1846
                if (strlen(vol->username) != 0 &&
 
1847
                    ses->password != NULL &&
 
1848
                    strncmp(ses->password,
 
1849
                            vol->password ? vol->password : "",
 
1850
                            MAX_PASSWORD_SIZE))
 
1851
                        return 0;
 
1852
        }
 
1853
        return 1;
 
1854
}
 
1855
 
 
1856
static struct cifs_ses *
1798
1857
cifs_find_smb_ses(struct TCP_Server_Info *server, struct smb_vol *vol)
1799
1858
{
1800
 
        struct cifsSesInfo *ses;
 
1859
        struct cifs_ses *ses;
1801
1860
 
1802
1861
        spin_lock(&cifs_tcp_ses_lock);
1803
1862
        list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
1804
 
                switch (server->secType) {
1805
 
                case Kerberos:
1806
 
                        if (vol->cred_uid != ses->cred_uid)
1807
 
                                continue;
1808
 
                        break;
1809
 
                default:
1810
 
                        /* anything else takes username/password */
1811
 
                        if (strncmp(ses->userName, vol->username,
1812
 
                                    MAX_USERNAME_SIZE))
1813
 
                                continue;
1814
 
                        if (strlen(vol->username) != 0 &&
1815
 
                            ses->password != NULL &&
1816
 
                            strncmp(ses->password,
1817
 
                                    vol->password ? vol->password : "",
1818
 
                                    MAX_PASSWORD_SIZE))
1819
 
                                continue;
1820
 
                }
 
1863
                if (!match_session(ses, vol))
 
1864
                        continue;
1821
1865
                ++ses->ses_count;
1822
1866
                spin_unlock(&cifs_tcp_ses_lock);
1823
1867
                return ses;
1827
1871
}
1828
1872
 
1829
1873
static void
1830
 
cifs_put_smb_ses(struct cifsSesInfo *ses)
 
1874
cifs_put_smb_ses(struct cifs_ses *ses)
1831
1875
{
1832
1876
        int xid;
1833
1877
        struct TCP_Server_Info *server = ses->server;
1851
1895
        cifs_put_tcp_session(server);
1852
1896
}
1853
1897
 
1854
 
static struct cifsSesInfo *
 
1898
static bool warned_on_ntlm;  /* globals init to false automatically */
 
1899
 
 
1900
static struct cifs_ses *
1855
1901
cifs_get_smb_ses(struct TCP_Server_Info *server, struct smb_vol *volume_info)
1856
1902
{
1857
1903
        int rc = -ENOMEM, xid;
1858
 
        struct cifsSesInfo *ses;
 
1904
        struct cifs_ses *ses;
1859
1905
        struct sockaddr_in *addr = (struct sockaddr_in *)&server->dstaddr;
1860
1906
        struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)&server->dstaddr;
1861
1907
 
1906
1952
        else
1907
1953
                sprintf(ses->serverName, "%pI4", &addr->sin_addr);
1908
1954
 
1909
 
        if (volume_info->username)
1910
 
                strncpy(ses->userName, volume_info->username,
1911
 
                        MAX_USERNAME_SIZE);
 
1955
        if (volume_info->username) {
 
1956
                ses->user_name = kstrdup(volume_info->username, GFP_KERNEL);
 
1957
                if (!ses->user_name)
 
1958
                        goto get_ses_fail;
 
1959
        }
1912
1960
 
1913
1961
        /* volume_info->password freed at unmount */
1914
1962
        if (volume_info->password) {
1923
1971
        }
1924
1972
        ses->cred_uid = volume_info->cred_uid;
1925
1973
        ses->linux_uid = volume_info->linux_uid;
 
1974
 
 
1975
        /* ntlmv2 is much stronger than ntlm security, and has been broadly
 
1976
        supported for many years, time to update default security mechanism */
 
1977
        if ((volume_info->secFlg == 0) && warned_on_ntlm == false) {
 
1978
                warned_on_ntlm = true;
 
1979
                cERROR(1, "default security mechanism requested.  The default "
 
1980
                        "security mechanism will be upgraded from ntlm to "
 
1981
                        "ntlmv2 in kernel release 3.1");
 
1982
        }
1926
1983
        ses->overrideSecFlg = volume_info->secFlg;
1927
1984
 
1928
1985
        mutex_lock(&ses->session_mutex);
1947
2004
        return ERR_PTR(rc);
1948
2005
}
1949
2006
 
1950
 
static struct cifsTconInfo *
1951
 
cifs_find_tcon(struct cifsSesInfo *ses, const char *unc)
 
2007
static int match_tcon(struct cifs_tcon *tcon, const char *unc)
 
2008
{
 
2009
        if (tcon->tidStatus == CifsExiting)
 
2010
                return 0;
 
2011
        if (strncmp(tcon->treeName, unc, MAX_TREE_SIZE))
 
2012
                return 0;
 
2013
        return 1;
 
2014
}
 
2015
 
 
2016
static struct cifs_tcon *
 
2017
cifs_find_tcon(struct cifs_ses *ses, const char *unc)
1952
2018
{
1953
2019
        struct list_head *tmp;
1954
 
        struct cifsTconInfo *tcon;
 
2020
        struct cifs_tcon *tcon;
1955
2021
 
1956
2022
        spin_lock(&cifs_tcp_ses_lock);
1957
2023
        list_for_each(tmp, &ses->tcon_list) {
1958
 
                tcon = list_entry(tmp, struct cifsTconInfo, tcon_list);
1959
 
                if (tcon->tidStatus == CifsExiting)
1960
 
                        continue;
1961
 
                if (strncmp(tcon->treeName, unc, MAX_TREE_SIZE))
1962
 
                        continue;
1963
 
 
 
2024
                tcon = list_entry(tmp, struct cifs_tcon, tcon_list);
 
2025
                if (!match_tcon(tcon, unc))
 
2026
                        continue;
1964
2027
                ++tcon->tc_count;
1965
2028
                spin_unlock(&cifs_tcp_ses_lock);
1966
2029
                return tcon;
1970
2033
}
1971
2034
 
1972
2035
static void
1973
 
cifs_put_tcon(struct cifsTconInfo *tcon)
 
2036
cifs_put_tcon(struct cifs_tcon *tcon)
1974
2037
{
1975
2038
        int xid;
1976
 
        struct cifsSesInfo *ses = tcon->ses;
 
2039
        struct cifs_ses *ses = tcon->ses;
1977
2040
 
1978
2041
        cFYI(1, "%s: tc_count=%d\n", __func__, tcon->tc_count);
1979
2042
        spin_lock(&cifs_tcp_ses_lock);
1994
2057
        cifs_put_smb_ses(ses);
1995
2058
}
1996
2059
 
1997
 
static struct cifsTconInfo *
1998
 
cifs_get_tcon(struct cifsSesInfo *ses, struct smb_vol *volume_info)
 
2060
static struct cifs_tcon *
 
2061
cifs_get_tcon(struct cifs_ses *ses, struct smb_vol *volume_info)
1999
2062
{
2000
2063
        int rc, xid;
2001
 
        struct cifsTconInfo *tcon;
 
2064
        struct cifs_tcon *tcon;
2002
2065
 
2003
2066
        tcon = cifs_find_tcon(ses, volume_info->UNC);
2004
2067
        if (tcon) {
2087
2150
        return;
2088
2151
}
2089
2152
 
2090
 
int
2091
 
get_dfs_path(int xid, struct cifsSesInfo *pSesInfo, const char *old_path,
 
2153
static inline struct tcon_link *
 
2154
cifs_sb_master_tlink(struct cifs_sb_info *cifs_sb)
 
2155
{
 
2156
        return cifs_sb->master_tlink;
 
2157
}
 
2158
 
 
2159
static int
 
2160
compare_mount_options(struct super_block *sb, struct cifs_mnt_data *mnt_data)
 
2161
{
 
2162
        struct cifs_sb_info *old = CIFS_SB(sb);
 
2163
        struct cifs_sb_info *new = mnt_data->cifs_sb;
 
2164
 
 
2165
        if ((sb->s_flags & CIFS_MS_MASK) != (mnt_data->flags & CIFS_MS_MASK))
 
2166
                return 0;
 
2167
 
 
2168
        if ((old->mnt_cifs_flags & CIFS_MOUNT_MASK) !=
 
2169
            (new->mnt_cifs_flags & CIFS_MOUNT_MASK))
 
2170
                return 0;
 
2171
 
 
2172
        if (old->rsize != new->rsize)
 
2173
                return 0;
 
2174
 
 
2175
        /*
 
2176
         * We want to share sb only if we don't specify wsize or specified wsize
 
2177
         * is greater or equal than existing one.
 
2178
         */
 
2179
        if (new->wsize && new->wsize < old->wsize)
 
2180
                return 0;
 
2181
 
 
2182
        if (old->mnt_uid != new->mnt_uid || old->mnt_gid != new->mnt_gid)
 
2183
                return 0;
 
2184
 
 
2185
        if (old->mnt_file_mode != new->mnt_file_mode ||
 
2186
            old->mnt_dir_mode != new->mnt_dir_mode)
 
2187
                return 0;
 
2188
 
 
2189
        if (strcmp(old->local_nls->charset, new->local_nls->charset))
 
2190
                return 0;
 
2191
 
 
2192
        if (old->actimeo != new->actimeo)
 
2193
                return 0;
 
2194
 
 
2195
        return 1;
 
2196
}
 
2197
 
 
2198
int
 
2199
cifs_match_super(struct super_block *sb, void *data)
 
2200
{
 
2201
        struct cifs_mnt_data *mnt_data = (struct cifs_mnt_data *)data;
 
2202
        struct smb_vol *volume_info;
 
2203
        struct cifs_sb_info *cifs_sb;
 
2204
        struct TCP_Server_Info *tcp_srv;
 
2205
        struct cifs_ses *ses;
 
2206
        struct cifs_tcon *tcon;
 
2207
        struct tcon_link *tlink;
 
2208
        struct sockaddr_storage addr;
 
2209
        int rc = 0;
 
2210
 
 
2211
        memset(&addr, 0, sizeof(struct sockaddr_storage));
 
2212
 
 
2213
        spin_lock(&cifs_tcp_ses_lock);
 
2214
        cifs_sb = CIFS_SB(sb);
 
2215
        tlink = cifs_get_tlink(cifs_sb_master_tlink(cifs_sb));
 
2216
        if (IS_ERR(tlink)) {
 
2217
                spin_unlock(&cifs_tcp_ses_lock);
 
2218
                return rc;
 
2219
        }
 
2220
        tcon = tlink_tcon(tlink);
 
2221
        ses = tcon->ses;
 
2222
        tcp_srv = ses->server;
 
2223
 
 
2224
        volume_info = mnt_data->vol;
 
2225
 
 
2226
        if (!volume_info->UNCip || !volume_info->UNC)
 
2227
                goto out;
 
2228
 
 
2229
        rc = cifs_fill_sockaddr((struct sockaddr *)&addr,
 
2230
                                volume_info->UNCip,
 
2231
                                strlen(volume_info->UNCip),
 
2232
                                volume_info->port);
 
2233
        if (!rc)
 
2234
                goto out;
 
2235
 
 
2236
        if (!match_server(tcp_srv, (struct sockaddr *)&addr, volume_info) ||
 
2237
            !match_session(ses, volume_info) ||
 
2238
            !match_tcon(tcon, volume_info->UNC)) {
 
2239
                rc = 0;
 
2240
                goto out;
 
2241
        }
 
2242
 
 
2243
        rc = compare_mount_options(sb, mnt_data);
 
2244
out:
 
2245
        spin_unlock(&cifs_tcp_ses_lock);
 
2246
        cifs_put_tlink(tlink);
 
2247
        return rc;
 
2248
}
 
2249
 
 
2250
int
 
2251
get_dfs_path(int xid, struct cifs_ses *pSesInfo, const char *old_path,
2092
2252
             const struct nls_table *nls_codepage, unsigned int *pnum_referrals,
2093
2253
             struct dfs_info3_param **preferrals, int remap)
2094
2254
{
2249
2409
                smb_buf = (struct smb_hdr *)ses_init_buf;
2250
2410
 
2251
2411
                /* sizeof RFC1002_SESSION_REQUEST with no scope */
2252
 
                smb_buf->smb_buf_length = 0x81000044;
 
2412
                smb_buf->smb_buf_length = cpu_to_be32(0x81000044);
2253
2413
                rc = smb_send(server, smb_buf, 0x44);
2254
2414
                kfree(ses_init_buf);
2255
2415
                /*
2276
2436
generic_ip_connect(struct TCP_Server_Info *server)
2277
2437
{
2278
2438
        int rc = 0;
2279
 
        unsigned short int sport;
 
2439
        __be16 sport;
2280
2440
        int slen, sfamily;
2281
2441
        struct socket *socket = server->ssocket;
2282
2442
        struct sockaddr *saddr;
2316
2476
        if (rc < 0)
2317
2477
                return rc;
2318
2478
 
2319
 
        rc = socket->ops->connect(socket, saddr, slen, 0);
2320
 
        if (rc < 0) {
2321
 
                cFYI(1, "Error %d connecting to server", rc);
2322
 
                sock_release(socket);
2323
 
                server->ssocket = NULL;
2324
 
                return rc;
2325
 
        }
2326
 
 
2327
2479
        /*
2328
2480
         * Eventually check for other socket options to change from
2329
2481
         * the default. sock_setsockopt not used because it expects
2352
2504
                 socket->sk->sk_sndbuf,
2353
2505
                 socket->sk->sk_rcvbuf, socket->sk->sk_rcvtimeo);
2354
2506
 
 
2507
        rc = socket->ops->connect(socket, saddr, slen, 0);
 
2508
        if (rc < 0) {
 
2509
                cFYI(1, "Error %d connecting to server", rc);
 
2510
                sock_release(socket);
 
2511
                server->ssocket = NULL;
 
2512
                return rc;
 
2513
        }
 
2514
 
2355
2515
        if (sport == htons(RFC1001_PORT))
2356
2516
                rc = ip_rfc1001_connect(server);
2357
2517
 
2361
2521
static int
2362
2522
ip_connect(struct TCP_Server_Info *server)
2363
2523
{
2364
 
        unsigned short int *sport;
 
2524
        __be16 *sport;
2365
2525
        struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)&server->dstaddr;
2366
2526
        struct sockaddr_in *addr = (struct sockaddr_in *)&server->dstaddr;
2367
2527
 
2387
2547
        return generic_ip_connect(server);
2388
2548
}
2389
2549
 
2390
 
void reset_cifs_unix_caps(int xid, struct cifsTconInfo *tcon,
2391
 
                          struct super_block *sb, struct smb_vol *vol_info)
 
2550
void reset_cifs_unix_caps(int xid, struct cifs_tcon *tcon,
 
2551
                          struct cifs_sb_info *cifs_sb, struct smb_vol *vol_info)
2392
2552
{
2393
2553
        /* if we are reconnecting then should we check to see if
2394
2554
         * any requested capabilities changed locally e.g. via
2416
2576
 
2417
2577
        if (!CIFSSMBQFSUnixInfo(xid, tcon)) {
2418
2578
                __u64 cap = le64_to_cpu(tcon->fsUnixInfo.Capability);
2419
 
 
 
2579
                cFYI(1, "unix caps which server supports %lld", cap);
2420
2580
                /* check for reconnect case in which we do not
2421
2581
                   want to change the mount behavior if we can avoid it */
2422
2582
                if (vol_info == NULL) {
2434
2594
                        }
2435
2595
                }
2436
2596
 
 
2597
                if (cap & CIFS_UNIX_TRANSPORT_ENCRYPTION_MANDATORY_CAP)
 
2598
                        cERROR(1, "per-share encryption not supported yet");
 
2599
 
2437
2600
                cap &= CIFS_UNIX_CAP_MASK;
2438
2601
                if (vol_info && vol_info->no_psx_acl)
2439
2602
                        cap &= ~CIFS_UNIX_POSIX_ACL_CAP;
2440
2603
                else if (CIFS_UNIX_POSIX_ACL_CAP & cap) {
2441
2604
                        cFYI(1, "negotiated posix acl support");
2442
 
                        if (sb)
2443
 
                                sb->s_flags |= MS_POSIXACL;
 
2605
                        if (cifs_sb)
 
2606
                                cifs_sb->mnt_cifs_flags |=
 
2607
                                        CIFS_MOUNT_POSIXACL;
2444
2608
                }
2445
2609
 
2446
2610
                if (vol_info && vol_info->posix_paths == 0)
2447
2611
                        cap &= ~CIFS_UNIX_POSIX_PATHNAMES_CAP;
2448
2612
                else if (cap & CIFS_UNIX_POSIX_PATHNAMES_CAP) {
2449
2613
                        cFYI(1, "negotiate posix pathnames");
2450
 
                        if (sb)
2451
 
                                CIFS_SB(sb)->mnt_cifs_flags |=
 
2614
                        if (cifs_sb)
 
2615
                                cifs_sb->mnt_cifs_flags |=
2452
2616
                                        CIFS_MOUNT_POSIX_PATHS;
2453
2617
                }
2454
2618
 
2455
 
                /* We might be setting the path sep back to a different
2456
 
                form if we are reconnecting and the server switched its
2457
 
                posix path capability for this share */
2458
 
                if (sb && (CIFS_SB(sb)->prepathlen > 0))
2459
 
                        CIFS_SB(sb)->prepath[0] = CIFS_DIR_SEP(CIFS_SB(sb));
2460
 
 
2461
 
                if (sb && (CIFS_SB(sb)->rsize > 127 * 1024)) {
 
2619
                if (cifs_sb && (cifs_sb->rsize > 127 * 1024)) {
2462
2620
                        if ((cap & CIFS_UNIX_LARGE_READ_CAP) == 0) {
2463
 
                                CIFS_SB(sb)->rsize = 127 * 1024;
 
2621
                                cifs_sb->rsize = 127 * 1024;
2464
2622
                                cFYI(DBG2, "larger reads not supported by srv");
2465
2623
                        }
2466
2624
                }
2482
2640
                        cFYI(1, "very large read cap");
2483
2641
                if (cap & CIFS_UNIX_LARGE_WRITE_CAP)
2484
2642
                        cFYI(1, "very large write cap");
 
2643
                if (cap & CIFS_UNIX_TRANSPORT_ENCRYPTION_CAP)
 
2644
                        cFYI(1, "transport encryption cap");
 
2645
                if (cap & CIFS_UNIX_TRANSPORT_ENCRYPTION_MANDATORY_CAP)
 
2646
                        cFYI(1, "mandatory transport encryption cap");
2485
2647
#endif /* CIFS_DEBUG2 */
2486
2648
                if (CIFSSMBSetFSUnixInfo(xid, tcon, cap)) {
2487
2649
                        if (vol_info == NULL) {
2498
2660
        }
2499
2661
}
2500
2662
 
2501
 
static void
2502
 
convert_delimiter(char *path, char delim)
2503
 
{
2504
 
        int i;
2505
 
        char old_delim;
2506
 
 
2507
 
        if (path == NULL)
2508
 
                return;
2509
 
 
2510
 
        if (delim == '/')
2511
 
                old_delim = '\\';
2512
 
        else
2513
 
                old_delim = '/';
2514
 
 
2515
 
        for (i = 0; path[i] != '\0'; i++) {
2516
 
                if (path[i] == old_delim)
2517
 
                        path[i] = delim;
2518
 
        }
2519
 
}
2520
 
 
2521
 
static void setup_cifs_sb(struct smb_vol *pvolume_info,
2522
 
                          struct cifs_sb_info *cifs_sb)
 
2663
void cifs_setup_cifs_sb(struct smb_vol *pvolume_info,
 
2664
                        struct cifs_sb_info *cifs_sb)
2523
2665
{
2524
2666
        INIT_DELAYED_WORK(&cifs_sb->prune_tlinks, cifs_prune_tlinks);
2525
2667
 
 
2668
        spin_lock_init(&cifs_sb->tlink_tree_lock);
 
2669
        cifs_sb->tlink_tree = RB_ROOT;
 
2670
 
2526
2671
        if (pvolume_info->rsize > CIFSMaxBufSize) {
2527
2672
                cERROR(1, "rsize %d too large, using MaxBufSize",
2528
2673
                        pvolume_info->rsize);
2533
2678
        else /* default */
2534
2679
                cifs_sb->rsize = CIFSMaxBufSize;
2535
2680
 
2536
 
        if (pvolume_info->wsize > PAGEVEC_SIZE * PAGE_CACHE_SIZE) {
2537
 
                cERROR(1, "wsize %d too large, using 4096 instead",
2538
 
                          pvolume_info->wsize);
2539
 
                cifs_sb->wsize = 4096;
2540
 
        } else if (pvolume_info->wsize)
2541
 
                cifs_sb->wsize = pvolume_info->wsize;
2542
 
        else
2543
 
                cifs_sb->wsize = min_t(const int,
2544
 
                                        PAGEVEC_SIZE * PAGE_CACHE_SIZE,
2545
 
                                        127*1024);
2546
 
                /* old default of CIFSMaxBufSize was too small now
2547
 
                   that SMB Write2 can send multiple pages in kvec.
2548
 
                   RFC1001 does not describe what happens when frame
2549
 
                   bigger than 128K is sent so use that as max in
2550
 
                   conjunction with 52K kvec constraint on arch with 4K
2551
 
                   page size  */
2552
 
 
2553
2681
        if (cifs_sb->rsize < 2048) {
2554
2682
                cifs_sb->rsize = 2048;
2555
2683
                /* Windows ME may prefer this */
2556
2684
                cFYI(1, "readsize set to minimum: 2048");
2557
2685
        }
2558
 
        /* calculate prepath */
2559
 
        cifs_sb->prepath = pvolume_info->prepath;
2560
 
        if (cifs_sb->prepath) {
2561
 
                cifs_sb->prepathlen = strlen(cifs_sb->prepath);
2562
 
                /* we can not convert the / to \ in the path
2563
 
                separators in the prefixpath yet because we do not
2564
 
                know (until reset_cifs_unix_caps is called later)
2565
 
                whether POSIX PATH CAP is available. We normalize
2566
 
                the / to \ after reset_cifs_unix_caps is called */
2567
 
                pvolume_info->prepath = NULL;
2568
 
        } else
2569
 
                cifs_sb->prepathlen = 0;
 
2686
 
 
2687
        /*
 
2688
         * Temporarily set wsize for matching superblock. If we end up using
 
2689
         * new sb then cifs_negotiate_wsize will later negotiate it downward
 
2690
         * if needed.
 
2691
         */
 
2692
        cifs_sb->wsize = pvolume_info->wsize;
 
2693
 
2570
2694
        cifs_sb->mnt_uid = pvolume_info->linux_uid;
2571
2695
        cifs_sb->mnt_gid = pvolume_info->linux_gid;
2572
2696
        cifs_sb->mnt_file_mode = pvolume_info->file_mode;
2575
2699
                cifs_sb->mnt_file_mode, cifs_sb->mnt_dir_mode);
2576
2700
 
2577
2701
        cifs_sb->actimeo = pvolume_info->actimeo;
 
2702
        cifs_sb->local_nls = pvolume_info->local_nls;
2578
2703
 
2579
2704
        if (pvolume_info->noperm)
2580
2705
                cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_NO_PERM;
2594
2719
                cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_NOSSYNC;
2595
2720
        if (pvolume_info->mand_lock)
2596
2721
                cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_NOPOSIXBRL;
 
2722
        if (pvolume_info->rwpidforward)
 
2723
                cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_RWPIDFORWARD;
2597
2724
        if (pvolume_info->cifs_acl)
2598
2725
                cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_CIFS_ACL;
2599
2726
        if (pvolume_info->override_uid)
2627
2754
                           "mount option supported");
2628
2755
}
2629
2756
 
 
2757
/*
 
2758
 * When the server supports very large writes via POSIX extensions, we can
 
2759
 * allow up to 2^24-1, minus the size of a WRITE_AND_X header, not including
 
2760
 * the RFC1001 length.
 
2761
 *
 
2762
 * Note that this might make for "interesting" allocation problems during
 
2763
 * writeback however as we have to allocate an array of pointers for the
 
2764
 * pages. A 16M write means ~32kb page array with PAGE_CACHE_SIZE == 4096.
 
2765
 */
 
2766
#define CIFS_MAX_WSIZE ((1<<24) - 1 - sizeof(WRITE_REQ) + 4)
 
2767
 
 
2768
/*
 
2769
 * When the server doesn't allow large posix writes, only allow a wsize of
 
2770
 * 128k minus the size of the WRITE_AND_X header. That allows for a write up
 
2771
 * to the maximum size described by RFC1002.
 
2772
 */
 
2773
#define CIFS_MAX_RFC1002_WSIZE (128 * 1024 - sizeof(WRITE_REQ) + 4)
 
2774
 
 
2775
/*
 
2776
 * The default wsize is 1M. find_get_pages seems to return a maximum of 256
 
2777
 * pages in a single call. With PAGE_CACHE_SIZE == 4k, this means we can fill
 
2778
 * a single wsize request with a single call.
 
2779
 */
 
2780
#define CIFS_DEFAULT_WSIZE (1024 * 1024)
 
2781
 
 
2782
static unsigned int
 
2783
cifs_negotiate_wsize(struct cifs_tcon *tcon, struct smb_vol *pvolume_info)
 
2784
{
 
2785
        __u64 unix_cap = le64_to_cpu(tcon->fsUnixInfo.Capability);
 
2786
        struct TCP_Server_Info *server = tcon->ses->server;
 
2787
        unsigned int wsize = pvolume_info->wsize ? pvolume_info->wsize :
 
2788
                                CIFS_DEFAULT_WSIZE;
 
2789
 
 
2790
        /* can server support 24-bit write sizes? (via UNIX extensions) */
 
2791
        if (!tcon->unix_ext || !(unix_cap & CIFS_UNIX_LARGE_WRITE_CAP))
 
2792
                wsize = min_t(unsigned int, wsize, CIFS_MAX_RFC1002_WSIZE);
 
2793
 
 
2794
        /*
 
2795
         * no CAP_LARGE_WRITE_X or is signing enabled without CAP_UNIX set?
 
2796
         * Limit it to max buffer offered by the server, minus the size of the
 
2797
         * WRITEX header, not including the 4 byte RFC1001 length.
 
2798
         */
 
2799
        if (!(server->capabilities & CAP_LARGE_WRITE_X) ||
 
2800
            (!(server->capabilities & CAP_UNIX) &&
 
2801
             (server->sec_mode & (SECMODE_SIGN_ENABLED|SECMODE_SIGN_REQUIRED))))
 
2802
                wsize = min_t(unsigned int, wsize,
 
2803
                                server->maxBuf - sizeof(WRITE_REQ) + 4);
 
2804
 
 
2805
        /* hard limit of CIFS_MAX_WSIZE */
 
2806
        wsize = min_t(unsigned int, wsize, CIFS_MAX_WSIZE);
 
2807
 
 
2808
        return wsize;
 
2809
}
 
2810
 
2630
2811
static int
2631
 
is_path_accessible(int xid, struct cifsTconInfo *tcon,
 
2812
is_path_accessible(int xid, struct cifs_tcon *tcon,
2632
2813
                   struct cifs_sb_info *cifs_sb, const char *full_path)
2633
2814
{
2634
2815
        int rc;
2642
2823
                              0 /* not legacy */, cifs_sb->local_nls,
2643
2824
                              cifs_sb->mnt_cifs_flags &
2644
2825
                                CIFS_MOUNT_MAP_SPECIAL_CHR);
 
2826
 
 
2827
        if (rc == -EOPNOTSUPP || rc == -EINVAL)
 
2828
                rc = SMBQueryInformation(xid, tcon, full_path, pfile_info,
 
2829
                                cifs_sb->local_nls, cifs_sb->mnt_cifs_flags &
 
2830
                                  CIFS_MOUNT_MAP_SPECIAL_CHR);
2645
2831
        kfree(pfile_info);
2646
2832
        return rc;
2647
2833
}
2648
2834
 
2649
2835
static void
2650
 
cleanup_volume_info(struct smb_vol **pvolume_info)
 
2836
cleanup_volume_info_contents(struct smb_vol *volume_info)
2651
2837
{
2652
 
        struct smb_vol *volume_info;
2653
 
 
2654
 
        if (!pvolume_info || !*pvolume_info)
2655
 
                return;
2656
 
 
2657
 
        volume_info = *pvolume_info;
 
2838
        kfree(volume_info->username);
2658
2839
        kzfree(volume_info->password);
2659
2840
        kfree(volume_info->UNC);
 
2841
        kfree(volume_info->UNCip);
 
2842
        kfree(volume_info->domainname);
 
2843
        kfree(volume_info->iocharset);
2660
2844
        kfree(volume_info->prepath);
 
2845
}
 
2846
 
 
2847
void
 
2848
cifs_cleanup_volume_info(struct smb_vol *volume_info)
 
2849
{
 
2850
        if (!volume_info)
 
2851
                return;
 
2852
        cleanup_volume_info_contents(volume_info);
2661
2853
        kfree(volume_info);
2662
 
        *pvolume_info = NULL;
2663
 
        return;
2664
2854
}
2665
2855
 
 
2856
 
2666
2857
#ifdef CONFIG_CIFS_DFS_UPCALL
2667
2858
/* build_path_to_root returns full path to root when
2668
2859
 * we do not have an exiting connection (tcon) */
2669
2860
static char *
2670
 
build_unc_path_to_root(const struct smb_vol *volume_info,
 
2861
build_unc_path_to_root(const struct smb_vol *vol,
2671
2862
                const struct cifs_sb_info *cifs_sb)
2672
2863
{
2673
 
        char *full_path;
 
2864
        char *full_path, *pos;
 
2865
        unsigned int pplen = vol->prepath ? strlen(vol->prepath) : 0;
 
2866
        unsigned int unc_len = strnlen(vol->UNC, MAX_TREE_SIZE + 1);
2674
2867
 
2675
 
        int unc_len = strnlen(volume_info->UNC, MAX_TREE_SIZE + 1);
2676
 
        full_path = kmalloc(unc_len + cifs_sb->prepathlen + 1, GFP_KERNEL);
 
2868
        full_path = kmalloc(unc_len + pplen + 1, GFP_KERNEL);
2677
2869
        if (full_path == NULL)
2678
2870
                return ERR_PTR(-ENOMEM);
2679
2871
 
2680
 
        strncpy(full_path, volume_info->UNC, unc_len);
2681
 
        if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIX_PATHS) {
2682
 
                int i;
2683
 
                for (i = 0; i < unc_len; i++) {
2684
 
                        if (full_path[i] == '\\')
2685
 
                                full_path[i] = '/';
2686
 
                }
 
2872
        strncpy(full_path, vol->UNC, unc_len);
 
2873
        pos = full_path + unc_len;
 
2874
 
 
2875
        if (pplen) {
 
2876
                strncpy(pos, vol->prepath, pplen);
 
2877
                pos += pplen;
2687
2878
        }
2688
2879
 
2689
 
        if (cifs_sb->prepathlen)
2690
 
                strncpy(full_path + unc_len, cifs_sb->prepath,
2691
 
                                cifs_sb->prepathlen);
2692
 
 
2693
 
        full_path[unc_len + cifs_sb->prepathlen] = 0; /* add trailing null */
 
2880
        *pos = '\0'; /* add trailing null */
 
2881
        convert_delimiter(full_path, CIFS_DIR_SEP(cifs_sb));
 
2882
        cFYI(1, "%s: full_path=%s", __func__, full_path);
2694
2883
        return full_path;
2695
2884
}
2696
 
#endif
2697
2885
 
2698
 
int
2699
 
cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb,
2700
 
                char *mount_data_global, const char *devname)
 
2886
/*
 
2887
 * Perform a dfs referral query for a share and (optionally) prefix
 
2888
 *
 
2889
 * If a referral is found, cifs_sb->mountdata will be (re-)allocated
 
2890
 * to a string containing updated options for the submount.  Otherwise it
 
2891
 * will be left untouched.
 
2892
 *
 
2893
 * Returns the rc from get_dfs_path to the caller, which can be used to
 
2894
 * determine whether there were referrals.
 
2895
 */
 
2896
static int
 
2897
expand_dfs_referral(int xid, struct cifs_ses *pSesInfo,
 
2898
                    struct smb_vol *volume_info, struct cifs_sb_info *cifs_sb,
 
2899
                    int check_prefix)
2701
2900
{
2702
2901
        int rc;
2703
 
        int xid;
2704
 
        struct smb_vol *volume_info;
2705
 
        struct cifsSesInfo *pSesInfo;
2706
 
        struct cifsTconInfo *tcon;
2707
 
        struct TCP_Server_Info *srvTcp;
2708
 
        char   *full_path;
2709
 
        char *mount_data = mount_data_global;
2710
 
        struct tcon_link *tlink;
2711
 
#ifdef CONFIG_CIFS_DFS_UPCALL
 
2902
        unsigned int num_referrals = 0;
2712
2903
        struct dfs_info3_param *referrals = NULL;
2713
 
        unsigned int num_referrals = 0;
2714
 
        int referral_walks_count = 0;
2715
 
try_mount_again:
 
2904
        char *full_path = NULL, *ref_path = NULL, *mdata = NULL;
 
2905
 
 
2906
        full_path = build_unc_path_to_root(volume_info, cifs_sb);
 
2907
        if (IS_ERR(full_path))
 
2908
                return PTR_ERR(full_path);
 
2909
 
 
2910
        /* For DFS paths, skip the first '\' of the UNC */
 
2911
        ref_path = check_prefix ? full_path + 1 : volume_info->UNC + 1;
 
2912
 
 
2913
        rc = get_dfs_path(xid, pSesInfo , ref_path, cifs_sb->local_nls,
 
2914
                          &num_referrals, &referrals,
 
2915
                          cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
 
2916
 
 
2917
        if (!rc && num_referrals > 0) {
 
2918
                char *fake_devname = NULL;
 
2919
 
 
2920
                mdata = cifs_compose_mount_options(cifs_sb->mountdata,
 
2921
                                                   full_path + 1, referrals,
 
2922
                                                   &fake_devname);
 
2923
 
 
2924
                free_dfs_info_array(referrals, num_referrals);
 
2925
 
 
2926
                if (IS_ERR(mdata)) {
 
2927
                        rc = PTR_ERR(mdata);
 
2928
                        mdata = NULL;
 
2929
                } else {
 
2930
                        cleanup_volume_info_contents(volume_info);
 
2931
                        memset(volume_info, '\0', sizeof(*volume_info));
 
2932
                        rc = cifs_setup_volume_info(volume_info, mdata,
 
2933
                                                        fake_devname);
 
2934
                }
 
2935
                kfree(fake_devname);
 
2936
                kfree(cifs_sb->mountdata);
 
2937
                cifs_sb->mountdata = mdata;
 
2938
        }
 
2939
        kfree(full_path);
 
2940
        return rc;
 
2941
}
2716
2942
#endif
2717
 
        rc = 0;
2718
 
        tcon = NULL;
2719
 
        pSesInfo = NULL;
2720
 
        srvTcp = NULL;
2721
 
        full_path = NULL;
2722
 
        tlink = NULL;
2723
 
 
2724
 
        xid = GetXid();
2725
 
 
2726
 
        volume_info = kzalloc(sizeof(struct smb_vol), GFP_KERNEL);
2727
 
        if (!volume_info) {
2728
 
                rc = -ENOMEM;
2729
 
                goto out;
2730
 
        }
2731
 
 
2732
 
        if (cifs_parse_mount_options(mount_data, devname, volume_info)) {
2733
 
                rc = -EINVAL;
2734
 
                goto out;
2735
 
        }
 
2943
 
 
2944
static int
 
2945
cifs_setup_volume_info(struct smb_vol *volume_info, char *mount_data,
 
2946
                        const char *devname)
 
2947
{
 
2948
        int rc = 0;
 
2949
 
 
2950
        if (cifs_parse_mount_options(mount_data, devname, volume_info))
 
2951
                return -EINVAL;
2736
2952
 
2737
2953
        if (volume_info->nullauth) {
2738
2954
                cFYI(1, "null user");
2739
 
                volume_info->username = "";
 
2955
                volume_info->username = kzalloc(1, GFP_KERNEL);
 
2956
                if (volume_info->username == NULL)
 
2957
                        return -ENOMEM;
2740
2958
        } else if (volume_info->username) {
2741
2959
                /* BB fixme parse for domain name here */
2742
2960
                cFYI(1, "Username: %s", volume_info->username);
2744
2962
                cifserror("No username specified");
2745
2963
        /* In userspace mount helper we can get user name from alternate
2746
2964
           locations such as env variables and files on disk */
2747
 
                rc = -EINVAL;
2748
 
                goto out;
 
2965
                return -EINVAL;
2749
2966
        }
2750
2967
 
2751
2968
        /* this is needed for ASCII cp to Unicode converts */
2757
2974
                if (volume_info->local_nls == NULL) {
2758
2975
                        cERROR(1, "CIFS mount error: iocharset %s not found",
2759
2976
                                 volume_info->iocharset);
2760
 
                        rc = -ELIBACC;
2761
 
                        goto out;
 
2977
                        return -ELIBACC;
2762
2978
                }
2763
2979
        }
2764
 
        cifs_sb->local_nls = volume_info->local_nls;
 
2980
 
 
2981
        return rc;
 
2982
}
 
2983
 
 
2984
struct smb_vol *
 
2985
cifs_get_volume_info(char *mount_data, const char *devname)
 
2986
{
 
2987
        int rc;
 
2988
        struct smb_vol *volume_info;
 
2989
 
 
2990
        volume_info = kzalloc(sizeof(struct smb_vol), GFP_KERNEL);
 
2991
        if (!volume_info)
 
2992
                return ERR_PTR(-ENOMEM);
 
2993
 
 
2994
        rc = cifs_setup_volume_info(volume_info, mount_data, devname);
 
2995
        if (rc) {
 
2996
                cifs_cleanup_volume_info(volume_info);
 
2997
                volume_info = ERR_PTR(rc);
 
2998
        }
 
2999
 
 
3000
        return volume_info;
 
3001
}
 
3002
 
 
3003
int
 
3004
cifs_mount(struct cifs_sb_info *cifs_sb, struct smb_vol *volume_info)
 
3005
{
 
3006
        int rc = 0;
 
3007
        int xid;
 
3008
        struct cifs_ses *pSesInfo;
 
3009
        struct cifs_tcon *tcon;
 
3010
        struct TCP_Server_Info *srvTcp;
 
3011
        char   *full_path;
 
3012
        struct tcon_link *tlink;
 
3013
#ifdef CONFIG_CIFS_DFS_UPCALL
 
3014
        int referral_walks_count = 0;
 
3015
#endif
 
3016
 
 
3017
        rc = bdi_setup_and_register(&cifs_sb->bdi, "cifs", BDI_CAP_MAP_COPY);
 
3018
        if (rc)
 
3019
                return rc;
 
3020
 
 
3021
        cifs_sb->bdi.ra_pages = default_backing_dev_info.ra_pages;
 
3022
 
 
3023
#ifdef CONFIG_CIFS_DFS_UPCALL
 
3024
try_mount_again:
 
3025
        /* cleanup activities if we're chasing a referral */
 
3026
        if (referral_walks_count) {
 
3027
                if (tcon)
 
3028
                        cifs_put_tcon(tcon);
 
3029
                else if (pSesInfo)
 
3030
                        cifs_put_smb_ses(pSesInfo);
 
3031
 
 
3032
                FreeXid(xid);
 
3033
        }
 
3034
#endif
 
3035
        tcon = NULL;
 
3036
        pSesInfo = NULL;
 
3037
        srvTcp = NULL;
 
3038
        full_path = NULL;
 
3039
        tlink = NULL;
 
3040
 
 
3041
        xid = GetXid();
2765
3042
 
2766
3043
        /* get a reference to a tcp session */
2767
3044
        srvTcp = cifs_get_tcp_session(volume_info);
2768
3045
        if (IS_ERR(srvTcp)) {
2769
3046
                rc = PTR_ERR(srvTcp);
 
3047
                bdi_destroy(&cifs_sb->bdi);
2770
3048
                goto out;
2771
3049
        }
2772
3050
 
2778
3056
                goto mount_fail_check;
2779
3057
        }
2780
3058
 
2781
 
        setup_cifs_sb(volume_info, cifs_sb);
2782
 
        if (pSesInfo->capabilities & CAP_LARGE_FILES)
2783
 
                sb->s_maxbytes = MAX_LFS_FILESIZE;
2784
 
        else
2785
 
                sb->s_maxbytes = MAX_NON_LFS;
2786
 
 
2787
 
        /* BB FIXME fix time_gran to be larger for LANMAN sessions */
2788
 
        sb->s_time_gran = 100;
2789
 
 
2790
3059
        /* search for existing tcon to this server share */
2791
3060
        tcon = cifs_get_tcon(pSesInfo, volume_info);
2792
3061
        if (IS_ERR(tcon)) {
2795
3064
                goto remote_path_check;
2796
3065
        }
2797
3066
 
 
3067
        /* tell server which Unix caps we support */
 
3068
        if (tcon->ses->capabilities & CAP_UNIX) {
 
3069
                /* reset of caps checks mount to see if unix extensions
 
3070
                   disabled for just this mount */
 
3071
                reset_cifs_unix_caps(xid, tcon, cifs_sb, volume_info);
 
3072
                if ((tcon->ses->server->tcpStatus == CifsNeedReconnect) &&
 
3073
                    (le64_to_cpu(tcon->fsUnixInfo.Capability) &
 
3074
                     CIFS_UNIX_TRANSPORT_ENCRYPTION_MANDATORY_CAP)) {
 
3075
                        rc = -EACCES;
 
3076
                        goto mount_fail_check;
 
3077
                }
 
3078
        } else
 
3079
                tcon->unix_ext = 0; /* server does not support them */
 
3080
 
2798
3081
        /* do not care if following two calls succeed - informational */
2799
3082
        if (!tcon->ipc) {
2800
3083
                CIFSSMBQFSDeviceInfo(xid, tcon);
2801
3084
                CIFSSMBQFSAttributeInfo(xid, tcon);
2802
3085
        }
2803
3086
 
2804
 
        /* tell server which Unix caps we support */
2805
 
        if (tcon->ses->capabilities & CAP_UNIX)
2806
 
                /* reset of caps checks mount to see if unix extensions
2807
 
                   disabled for just this mount */
2808
 
                reset_cifs_unix_caps(xid, tcon, sb, volume_info);
2809
 
        else
2810
 
                tcon->unix_ext = 0; /* server does not support them */
2811
 
 
2812
 
        /* convert forward to back slashes in prepath here if needed */
2813
 
        if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIX_PATHS) == 0)
2814
 
                convert_delimiter(cifs_sb->prepath, CIFS_DIR_SEP(cifs_sb));
2815
 
 
2816
3087
        if ((tcon->unix_ext == 0) && (cifs_sb->rsize > (1024 * 127))) {
2817
3088
                cifs_sb->rsize = 1024 * 127;
2818
3089
                cFYI(DBG2, "no very large read support, rsize now 127K");
2819
3090
        }
2820
 
        if (!(tcon->ses->capabilities & CAP_LARGE_WRITE_X))
2821
 
                cifs_sb->wsize = min(cifs_sb->wsize,
2822
 
                               (tcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE));
2823
3091
        if (!(tcon->ses->capabilities & CAP_LARGE_READ_X))
2824
3092
                cifs_sb->rsize = min(cifs_sb->rsize,
2825
3093
                               (tcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE));
2826
3094
 
 
3095
        cifs_sb->wsize = cifs_negotiate_wsize(tcon, volume_info);
 
3096
 
2827
3097
remote_path_check:
2828
 
        /* check if a whole path (including prepath) is not remote */
 
3098
#ifdef CONFIG_CIFS_DFS_UPCALL
 
3099
        /*
 
3100
         * Perform an unconditional check for whether there are DFS
 
3101
         * referrals for this path without prefix, to provide support
 
3102
         * for DFS referrals from w2k8 servers which don't seem to respond
 
3103
         * with PATH_NOT_COVERED to requests that include the prefix.
 
3104
         * Chase the referral if found, otherwise continue normally.
 
3105
         */
 
3106
        if (referral_walks_count == 0) {
 
3107
                int refrc = expand_dfs_referral(xid, pSesInfo, volume_info,
 
3108
                                                cifs_sb, false);
 
3109
                if (!refrc) {
 
3110
                        referral_walks_count++;
 
3111
                        goto try_mount_again;
 
3112
                }
 
3113
        }
 
3114
#endif
 
3115
 
 
3116
        /* check if a whole path is not remote */
2829
3117
        if (!rc && tcon) {
2830
3118
                /* build_path_to_root works only when we have a valid tcon */
2831
 
                full_path = cifs_build_path_to_root(cifs_sb, tcon);
 
3119
                full_path = cifs_build_path_to_root(volume_info, cifs_sb, tcon);
2832
3120
                if (full_path == NULL) {
2833
3121
                        rc = -ENOMEM;
2834
3122
                        goto mount_fail_check;
2854
3142
                        rc = -ELOOP;
2855
3143
                        goto mount_fail_check;
2856
3144
                }
2857
 
                /* convert forward to back slashes in prepath here if needed */
2858
 
                if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIX_PATHS) == 0)
2859
 
                        convert_delimiter(cifs_sb->prepath,
2860
 
                                        CIFS_DIR_SEP(cifs_sb));
2861
 
                full_path = build_unc_path_to_root(volume_info, cifs_sb);
2862
 
                if (IS_ERR(full_path)) {
2863
 
                        rc = PTR_ERR(full_path);
2864
 
                        goto mount_fail_check;
2865
 
                }
2866
 
 
2867
 
                cFYI(1, "Getting referral for: %s", full_path);
2868
 
                rc = get_dfs_path(xid, pSesInfo , full_path + 1,
2869
 
                        cifs_sb->local_nls, &num_referrals, &referrals,
2870
 
                        cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
2871
 
                if (!rc && num_referrals > 0) {
2872
 
                        char *fake_devname = NULL;
2873
 
 
2874
 
                        if (mount_data != mount_data_global)
2875
 
                                kfree(mount_data);
2876
 
 
2877
 
                        mount_data = cifs_compose_mount_options(
2878
 
                                        cifs_sb->mountdata, full_path + 1,
2879
 
                                        referrals, &fake_devname);
2880
 
 
2881
 
                        free_dfs_info_array(referrals, num_referrals);
2882
 
                        kfree(fake_devname);
2883
 
                        kfree(full_path);
2884
 
 
2885
 
                        if (IS_ERR(mount_data)) {
2886
 
                                rc = PTR_ERR(mount_data);
2887
 
                                mount_data = NULL;
2888
 
                                goto mount_fail_check;
2889
 
                        }
2890
 
 
2891
 
                        if (tcon)
2892
 
                                cifs_put_tcon(tcon);
2893
 
                        else if (pSesInfo)
2894
 
                                cifs_put_smb_ses(pSesInfo);
2895
 
 
2896
 
                        cleanup_volume_info(&volume_info);
 
3145
 
 
3146
                rc = expand_dfs_referral(xid, pSesInfo, volume_info, cifs_sb,
 
3147
                                         true);
 
3148
 
 
3149
                if (!rc) {
2897
3150
                        referral_walks_count++;
2898
 
                        FreeXid(xid);
2899
3151
                        goto try_mount_again;
2900
3152
                }
 
3153
                goto mount_fail_check;
2901
3154
#else /* No DFS support, return error on mount */
2902
3155
                rc = -EOPNOTSUPP;
2903
3156
#endif
2930
3183
mount_fail_check:
2931
3184
        /* on error free sesinfo and tcon struct if needed */
2932
3185
        if (rc) {
2933
 
                if (mount_data != mount_data_global)
2934
 
                        kfree(mount_data);
2935
3186
                /* If find_unc succeeded then rc == 0 so we can not end */
2936
 
                /* up accidently freeing someone elses tcon struct */
 
3187
                /* up accidentally freeing someone elses tcon struct */
2937
3188
                if (tcon)
2938
3189
                        cifs_put_tcon(tcon);
2939
3190
                else if (pSesInfo)
2940
3191
                        cifs_put_smb_ses(pSesInfo);
2941
3192
                else
2942
3193
                        cifs_put_tcp_session(srvTcp);
 
3194
                bdi_destroy(&cifs_sb->bdi);
2943
3195
                goto out;
2944
3196
        }
2945
3197
 
2949
3201
        password will be freed at unmount time) */
2950
3202
out:
2951
3203
        /* zero out password before freeing */
2952
 
        cleanup_volume_info(&volume_info);
2953
3204
        FreeXid(xid);
2954
3205
        return rc;
2955
3206
}
2956
3207
 
 
3208
/*
 
3209
 * Issue a TREE_CONNECT request. Note that for IPC$ shares, that the tcon
 
3210
 * pointer may be NULL.
 
3211
 */
2957
3212
int
2958
 
CIFSTCon(unsigned int xid, struct cifsSesInfo *ses,
2959
 
         const char *tree, struct cifsTconInfo *tcon,
 
3213
CIFSTCon(unsigned int xid, struct cifs_ses *ses,
 
3214
         const char *tree, struct cifs_tcon *tcon,
2960
3215
         const struct nls_table *nls_codepage)
2961
3216
{
2962
3217
        struct smb_hdr *smb_buffer;
2988
3243
        pSMB->AndXCommand = 0xFF;
2989
3244
        pSMB->Flags = cpu_to_le16(TCON_EXTENDED_SECINFO);
2990
3245
        bcc_ptr = &pSMB->Password[0];
2991
 
        if ((ses->server->secMode) & SECMODE_USER) {
 
3246
        if (!tcon || (ses->server->sec_mode & SECMODE_USER)) {
2992
3247
                pSMB->PasswordLength = cpu_to_le16(1);  /* minimum */
2993
3248
                *bcc_ptr = 0; /* password is null byte */
2994
3249
                bcc_ptr++;              /* skip password */
3005
3260
                if ((global_secflags & CIFSSEC_MAY_LANMAN) &&
3006
3261
                    (ses->server->secType == LANMAN))
3007
3262
                        calc_lanman_hash(tcon->password, ses->server->cryptkey,
3008
 
                                         ses->server->secMode &
 
3263
                                         ses->server->sec_mode &
3009
3264
                                            SECMODE_PW_ENCRYPT ? true : false,
3010
3265
                                         bcc_ptr);
3011
3266
                else
3021
3276
                }
3022
3277
        }
3023
3278
 
3024
 
        if (ses->server->secMode &
 
3279
        if (ses->server->sec_mode &
3025
3280
                        (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED))
3026
3281
                smb_buffer->Flags2 |= SMBFLG2_SECURITY_SIGNATURE;
3027
3282
 
3047
3302
        bcc_ptr += strlen("?????");
3048
3303
        bcc_ptr += 1;
3049
3304
        count = bcc_ptr - &pSMB->Password[0];
3050
 
        pSMB->hdr.smb_buf_length += count;
 
3305
        pSMB->hdr.smb_buf_length = cpu_to_be32(be32_to_cpu(
 
3306
                                        pSMB->hdr.smb_buf_length) + count);
3051
3307
        pSMB->ByteCount = cpu_to_le16(count);
3052
3308
 
3053
3309
        rc = SendReceive(xid, ses, smb_buffer, smb_buffer_response, &length,
3110
3366
        return rc;
3111
3367
}
3112
3368
 
3113
 
int
3114
 
cifs_umount(struct super_block *sb, struct cifs_sb_info *cifs_sb)
 
3369
void
 
3370
cifs_umount(struct cifs_sb_info *cifs_sb)
3115
3371
{
3116
3372
        struct rb_root *root = &cifs_sb->tlink_tree;
3117
3373
        struct rb_node *node;
3118
3374
        struct tcon_link *tlink;
3119
 
        char *tmp;
3120
3375
 
3121
3376
        cancel_delayed_work_sync(&cifs_sb->prune_tlinks);
3122
3377
 
3133
3388
        }
3134
3389
        spin_unlock(&cifs_sb->tlink_tree_lock);
3135
3390
 
3136
 
        tmp = cifs_sb->prepath;
3137
 
        cifs_sb->prepathlen = 0;
3138
 
        cifs_sb->prepath = NULL;
3139
 
        kfree(tmp);
3140
 
 
3141
 
        return 0;
 
3391
        bdi_destroy(&cifs_sb->bdi);
 
3392
        kfree(cifs_sb->mountdata);
 
3393
        unload_nls(cifs_sb->local_nls);
 
3394
        kfree(cifs_sb);
3142
3395
}
3143
3396
 
3144
 
int cifs_negotiate_protocol(unsigned int xid, struct cifsSesInfo *ses)
 
3397
int cifs_negotiate_protocol(unsigned int xid, struct cifs_ses *ses)
3145
3398
{
3146
3399
        int rc = 0;
3147
3400
        struct TCP_Server_Info *server = ses->server;
3159
3412
        }
3160
3413
        if (rc == 0) {
3161
3414
                spin_lock(&GlobalMid_Lock);
3162
 
                if (server->tcpStatus != CifsExiting)
 
3415
                if (server->tcpStatus == CifsNeedNegotiate)
3163
3416
                        server->tcpStatus = CifsGood;
3164
3417
                else
3165
3418
                        rc = -EHOSTDOWN;
3171
3424
}
3172
3425
 
3173
3426
 
3174
 
int cifs_setup_session(unsigned int xid, struct cifsSesInfo *ses,
 
3427
int cifs_setup_session(unsigned int xid, struct cifs_ses *ses,
3175
3428
                        struct nls_table *nls_info)
3176
3429
{
3177
3430
        int rc = 0;
3183
3436
                ses->capabilities &= (~CAP_UNIX);
3184
3437
 
3185
3438
        cFYI(1, "Security Mode: 0x%x Capabilities: 0x%x TimeAdjust: %d",
3186
 
                 server->secMode, server->capabilities, server->timeAdj);
 
3439
                 server->sec_mode, server->capabilities, server->timeAdj);
3187
3440
 
3188
3441
        rc = CIFS_SessSetup(xid, ses, nls_info);
3189
3442
        if (rc) {
3215
3468
        return rc;
3216
3469
}
3217
3470
 
3218
 
static struct cifsTconInfo *
 
3471
static struct cifs_tcon *
3219
3472
cifs_construct_tcon(struct cifs_sb_info *cifs_sb, uid_t fsuid)
3220
3473
{
3221
 
        struct cifsTconInfo *master_tcon = cifs_sb_master_tcon(cifs_sb);
3222
 
        struct cifsSesInfo *ses;
3223
 
        struct cifsTconInfo *tcon = NULL;
 
3474
        struct cifs_tcon *master_tcon = cifs_sb_master_tcon(cifs_sb);
 
3475
        struct cifs_ses *ses;
 
3476
        struct cifs_tcon *tcon = NULL;
3224
3477
        struct smb_vol *vol_info;
3225
 
        char username[MAX_USERNAME_SIZE + 1];
 
3478
        char username[28]; /* big enough for "krb50x" + hex of ULONG_MAX 6+16 */
 
3479
                           /* We used to have this as MAX_USERNAME which is   */
 
3480
                           /* way too big now (256 instead of 32) */
3226
3481
 
3227
3482
        vol_info = kzalloc(sizeof(*vol_info), GFP_KERNEL);
3228
3483
        if (vol_info == NULL) {
3230
3485
                goto out;
3231
3486
        }
3232
3487
 
3233
 
        snprintf(username, MAX_USERNAME_SIZE, "krb50x%x", fsuid);
 
3488
        snprintf(username, sizeof(username), "krb50x%x", fsuid);
3234
3489
        vol_info->username = username;
3235
3490
        vol_info->local_nls = cifs_sb->local_nls;
3236
3491
        vol_info->linux_uid = fsuid;
3251
3506
 
3252
3507
        ses = cifs_get_smb_ses(master_tcon->ses->server, vol_info);
3253
3508
        if (IS_ERR(ses)) {
3254
 
                tcon = (struct cifsTconInfo *)ses;
 
3509
                tcon = (struct cifs_tcon *)ses;
3255
3510
                cifs_put_tcp_session(master_tcon->ses->server);
3256
3511
                goto out;
3257
3512
        }
3270
3525
        return tcon;
3271
3526
}
3272
3527
 
3273
 
static inline struct tcon_link *
3274
 
cifs_sb_master_tlink(struct cifs_sb_info *cifs_sb)
3275
 
{
3276
 
        return cifs_sb->master_tlink;
3277
 
}
3278
 
 
3279
 
struct cifsTconInfo *
 
3528
struct cifs_tcon *
3280
3529
cifs_sb_master_tcon(struct cifs_sb_info *cifs_sb)
3281
3530
{
3282
3531
        return tlink_tcon(cifs_sb_master_tlink(cifs_sb));