]> Git Repo - linux.git/blob - fs/cifs/link.c
cifs: secmech: use shash_desc directly, remove sdesc
[linux.git] / fs / cifs / link.c
1 // SPDX-License-Identifier: LGPL-2.1
2 /*
3  *
4  *   Copyright (C) International Business Machines  Corp., 2002,2008
5  *   Author(s): Steve French ([email protected])
6  *
7  */
8 #include <linux/fs.h>
9 #include <linux/stat.h>
10 #include <linux/slab.h>
11 #include <linux/namei.h>
12 #include "cifsfs.h"
13 #include "cifspdu.h"
14 #include "cifsglob.h"
15 #include "cifsproto.h"
16 #include "cifs_debug.h"
17 #include "cifs_fs_sb.h"
18 #include "cifs_unicode.h"
19 #include "smb2proto.h"
20 #include "cifs_ioctl.h"
21
22 /*
23  * M-F Symlink Functions - Begin
24  */
25
26 #define CIFS_MF_SYMLINK_LEN_OFFSET (4+1)
27 #define CIFS_MF_SYMLINK_MD5_OFFSET (CIFS_MF_SYMLINK_LEN_OFFSET+(4+1))
28 #define CIFS_MF_SYMLINK_LINK_OFFSET (CIFS_MF_SYMLINK_MD5_OFFSET+(32+1))
29 #define CIFS_MF_SYMLINK_LINK_MAXLEN (1024)
30 #define CIFS_MF_SYMLINK_FILE_SIZE \
31         (CIFS_MF_SYMLINK_LINK_OFFSET + CIFS_MF_SYMLINK_LINK_MAXLEN)
32
33 #define CIFS_MF_SYMLINK_LEN_FORMAT "XSym\n%04u\n"
34 #define CIFS_MF_SYMLINK_MD5_FORMAT "%16phN\n"
35 #define CIFS_MF_SYMLINK_MD5_ARGS(md5_hash) md5_hash
36
37 static int
38 symlink_hash(unsigned int link_len, const char *link_str, u8 *md5_hash)
39 {
40         int rc;
41         struct shash_desc *md5 = NULL;
42
43         rc = cifs_alloc_hash("md5", &md5);
44         if (rc)
45                 goto symlink_hash_err;
46
47         rc = crypto_shash_init(md5);
48         if (rc) {
49                 cifs_dbg(VFS, "%s: Could not init md5 shash\n", __func__);
50                 goto symlink_hash_err;
51         }
52         rc = crypto_shash_update(md5, link_str, link_len);
53         if (rc) {
54                 cifs_dbg(VFS, "%s: Could not update with link_str\n", __func__);
55                 goto symlink_hash_err;
56         }
57         rc = crypto_shash_final(md5, md5_hash);
58         if (rc)
59                 cifs_dbg(VFS, "%s: Could not generate md5 hash\n", __func__);
60
61 symlink_hash_err:
62         cifs_free_hash(&md5);
63         return rc;
64 }
65
66 static int
67 parse_mf_symlink(const u8 *buf, unsigned int buf_len, unsigned int *_link_len,
68                  char **_link_str)
69 {
70         int rc;
71         unsigned int link_len;
72         const char *md5_str1;
73         const char *link_str;
74         u8 md5_hash[16];
75         char md5_str2[34];
76
77         if (buf_len != CIFS_MF_SYMLINK_FILE_SIZE)
78                 return -EINVAL;
79
80         md5_str1 = (const char *)&buf[CIFS_MF_SYMLINK_MD5_OFFSET];
81         link_str = (const char *)&buf[CIFS_MF_SYMLINK_LINK_OFFSET];
82
83         rc = sscanf(buf, CIFS_MF_SYMLINK_LEN_FORMAT, &link_len);
84         if (rc != 1)
85                 return -EINVAL;
86
87         if (link_len > CIFS_MF_SYMLINK_LINK_MAXLEN)
88                 return -EINVAL;
89
90         rc = symlink_hash(link_len, link_str, md5_hash);
91         if (rc) {
92                 cifs_dbg(FYI, "%s: MD5 hash failure: %d\n", __func__, rc);
93                 return rc;
94         }
95
96         scnprintf(md5_str2, sizeof(md5_str2),
97                   CIFS_MF_SYMLINK_MD5_FORMAT,
98                   CIFS_MF_SYMLINK_MD5_ARGS(md5_hash));
99
100         if (strncmp(md5_str1, md5_str2, 17) != 0)
101                 return -EINVAL;
102
103         if (_link_str) {
104                 *_link_str = kstrndup(link_str, link_len, GFP_KERNEL);
105                 if (!*_link_str)
106                         return -ENOMEM;
107         }
108
109         *_link_len = link_len;
110         return 0;
111 }
112
113 static int
114 format_mf_symlink(u8 *buf, unsigned int buf_len, const char *link_str)
115 {
116         int rc;
117         unsigned int link_len;
118         unsigned int ofs;
119         u8 md5_hash[16];
120
121         if (buf_len != CIFS_MF_SYMLINK_FILE_SIZE)
122                 return -EINVAL;
123
124         link_len = strlen(link_str);
125
126         if (link_len > CIFS_MF_SYMLINK_LINK_MAXLEN)
127                 return -ENAMETOOLONG;
128
129         rc = symlink_hash(link_len, link_str, md5_hash);
130         if (rc) {
131                 cifs_dbg(FYI, "%s: MD5 hash failure: %d\n", __func__, rc);
132                 return rc;
133         }
134
135         scnprintf(buf, buf_len,
136                   CIFS_MF_SYMLINK_LEN_FORMAT CIFS_MF_SYMLINK_MD5_FORMAT,
137                   link_len,
138                   CIFS_MF_SYMLINK_MD5_ARGS(md5_hash));
139
140         ofs = CIFS_MF_SYMLINK_LINK_OFFSET;
141         memcpy(buf + ofs, link_str, link_len);
142
143         ofs += link_len;
144         if (ofs < CIFS_MF_SYMLINK_FILE_SIZE) {
145                 buf[ofs] = '\n';
146                 ofs++;
147         }
148
149         while (ofs < CIFS_MF_SYMLINK_FILE_SIZE) {
150                 buf[ofs] = ' ';
151                 ofs++;
152         }
153
154         return 0;
155 }
156
157 bool
158 couldbe_mf_symlink(const struct cifs_fattr *fattr)
159 {
160         if (!S_ISREG(fattr->cf_mode))
161                 /* it's not a symlink */
162                 return false;
163
164         if (fattr->cf_eof != CIFS_MF_SYMLINK_FILE_SIZE)
165                 /* it's not a symlink */
166                 return false;
167
168         return true;
169 }
170
171 static int
172 create_mf_symlink(const unsigned int xid, struct cifs_tcon *tcon,
173                   struct cifs_sb_info *cifs_sb, const char *fromName,
174                   const char *toName)
175 {
176         int rc;
177         u8 *buf;
178         unsigned int bytes_written = 0;
179
180         buf = kmalloc(CIFS_MF_SYMLINK_FILE_SIZE, GFP_KERNEL);
181         if (!buf)
182                 return -ENOMEM;
183
184         rc = format_mf_symlink(buf, CIFS_MF_SYMLINK_FILE_SIZE, toName);
185         if (rc)
186                 goto out;
187
188         if (tcon->ses->server->ops->create_mf_symlink)
189                 rc = tcon->ses->server->ops->create_mf_symlink(xid, tcon,
190                                         cifs_sb, fromName, buf, &bytes_written);
191         else
192                 rc = -EOPNOTSUPP;
193
194         if (rc)
195                 goto out;
196
197         if (bytes_written != CIFS_MF_SYMLINK_FILE_SIZE)
198                 rc = -EIO;
199 out:
200         kfree(buf);
201         return rc;
202 }
203
204 static int
205 query_mf_symlink(const unsigned int xid, struct cifs_tcon *tcon,
206                  struct cifs_sb_info *cifs_sb, const unsigned char *path,
207                  char **symlinkinfo)
208 {
209         int rc;
210         u8 *buf = NULL;
211         unsigned int link_len = 0;
212         unsigned int bytes_read = 0;
213
214         buf = kmalloc(CIFS_MF_SYMLINK_FILE_SIZE, GFP_KERNEL);
215         if (!buf)
216                 return -ENOMEM;
217
218         if (tcon->ses->server->ops->query_mf_symlink)
219                 rc = tcon->ses->server->ops->query_mf_symlink(xid, tcon,
220                                               cifs_sb, path, buf, &bytes_read);
221         else
222                 rc = -ENOSYS;
223
224         if (rc)
225                 goto out;
226
227         if (bytes_read == 0) { /* not a symlink */
228                 rc = -EINVAL;
229                 goto out;
230         }
231
232         rc = parse_mf_symlink(buf, bytes_read, &link_len, symlinkinfo);
233 out:
234         kfree(buf);
235         return rc;
236 }
237
238 int
239 check_mf_symlink(unsigned int xid, struct cifs_tcon *tcon,
240                  struct cifs_sb_info *cifs_sb, struct cifs_fattr *fattr,
241                  const unsigned char *path)
242 {
243         int rc;
244         u8 *buf = NULL;
245         unsigned int link_len = 0;
246         unsigned int bytes_read = 0;
247
248         if (!couldbe_mf_symlink(fattr))
249                 /* it's not a symlink */
250                 return 0;
251
252         buf = kmalloc(CIFS_MF_SYMLINK_FILE_SIZE, GFP_KERNEL);
253         if (!buf)
254                 return -ENOMEM;
255
256         if (tcon->ses->server->ops->query_mf_symlink)
257                 rc = tcon->ses->server->ops->query_mf_symlink(xid, tcon,
258                                               cifs_sb, path, buf, &bytes_read);
259         else
260                 rc = -ENOSYS;
261
262         if (rc)
263                 goto out;
264
265         if (bytes_read == 0) /* not a symlink */
266                 goto out;
267
268         rc = parse_mf_symlink(buf, bytes_read, &link_len, NULL);
269         if (rc == -EINVAL) {
270                 /* it's not a symlink */
271                 rc = 0;
272                 goto out;
273         }
274
275         if (rc != 0)
276                 goto out;
277
278         /* it is a symlink */
279         fattr->cf_eof = link_len;
280         fattr->cf_mode &= ~S_IFMT;
281         fattr->cf_mode |= S_IFLNK | S_IRWXU | S_IRWXG | S_IRWXO;
282         fattr->cf_dtype = DT_LNK;
283 out:
284         kfree(buf);
285         return rc;
286 }
287
288 #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
289 /*
290  * SMB 1.0 Protocol specific functions
291  */
292
293 int
294 cifs_query_mf_symlink(unsigned int xid, struct cifs_tcon *tcon,
295                       struct cifs_sb_info *cifs_sb, const unsigned char *path,
296                       char *pbuf, unsigned int *pbytes_read)
297 {
298         int rc;
299         int oplock = 0;
300         struct cifs_fid fid;
301         struct cifs_open_parms oparms;
302         struct cifs_io_parms io_parms = {0};
303         int buf_type = CIFS_NO_BUFFER;
304         FILE_ALL_INFO file_info;
305
306         oparms.tcon = tcon;
307         oparms.cifs_sb = cifs_sb;
308         oparms.desired_access = GENERIC_READ;
309         oparms.create_options = cifs_create_options(cifs_sb, CREATE_NOT_DIR);
310         oparms.disposition = FILE_OPEN;
311         oparms.path = path;
312         oparms.fid = &fid;
313         oparms.reconnect = false;
314
315         rc = CIFS_open(xid, &oparms, &oplock, &file_info);
316         if (rc)
317                 return rc;
318
319         if (file_info.EndOfFile != cpu_to_le64(CIFS_MF_SYMLINK_FILE_SIZE)) {
320                 rc = -ENOENT;
321                 /* it's not a symlink */
322                 goto out;
323         }
324
325         io_parms.netfid = fid.netfid;
326         io_parms.pid = current->tgid;
327         io_parms.tcon = tcon;
328         io_parms.offset = 0;
329         io_parms.length = CIFS_MF_SYMLINK_FILE_SIZE;
330
331         rc = CIFSSMBRead(xid, &io_parms, pbytes_read, &pbuf, &buf_type);
332 out:
333         CIFSSMBClose(xid, tcon, fid.netfid);
334         return rc;
335 }
336
337 int
338 cifs_create_mf_symlink(unsigned int xid, struct cifs_tcon *tcon,
339                        struct cifs_sb_info *cifs_sb, const unsigned char *path,
340                        char *pbuf, unsigned int *pbytes_written)
341 {
342         int rc;
343         int oplock = 0;
344         struct cifs_fid fid;
345         struct cifs_open_parms oparms;
346         struct cifs_io_parms io_parms = {0};
347
348         oparms.tcon = tcon;
349         oparms.cifs_sb = cifs_sb;
350         oparms.desired_access = GENERIC_WRITE;
351         oparms.create_options = cifs_create_options(cifs_sb, CREATE_NOT_DIR);
352         oparms.disposition = FILE_CREATE;
353         oparms.path = path;
354         oparms.fid = &fid;
355         oparms.reconnect = false;
356
357         rc = CIFS_open(xid, &oparms, &oplock, NULL);
358         if (rc)
359                 return rc;
360
361         io_parms.netfid = fid.netfid;
362         io_parms.pid = current->tgid;
363         io_parms.tcon = tcon;
364         io_parms.offset = 0;
365         io_parms.length = CIFS_MF_SYMLINK_FILE_SIZE;
366
367         rc = CIFSSMBWrite(xid, &io_parms, pbytes_written, pbuf);
368         CIFSSMBClose(xid, tcon, fid.netfid);
369         return rc;
370 }
371 #endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
372
373 /*
374  * SMB 2.1/SMB3 Protocol specific functions
375  */
376 int
377 smb3_query_mf_symlink(unsigned int xid, struct cifs_tcon *tcon,
378                       struct cifs_sb_info *cifs_sb, const unsigned char *path,
379                       char *pbuf, unsigned int *pbytes_read)
380 {
381         int rc;
382         struct cifs_fid fid;
383         struct cifs_open_parms oparms;
384         struct cifs_io_parms io_parms = {0};
385         int buf_type = CIFS_NO_BUFFER;
386         __le16 *utf16_path;
387         __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
388         struct smb2_file_all_info *pfile_info = NULL;
389
390         oparms.tcon = tcon;
391         oparms.cifs_sb = cifs_sb;
392         oparms.desired_access = GENERIC_READ;
393         oparms.create_options = cifs_create_options(cifs_sb, CREATE_NOT_DIR);
394         oparms.disposition = FILE_OPEN;
395         oparms.fid = &fid;
396         oparms.reconnect = false;
397
398         utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
399         if (utf16_path == NULL)
400                 return -ENOMEM;
401
402         pfile_info = kzalloc(sizeof(struct smb2_file_all_info) + PATH_MAX * 2,
403                              GFP_KERNEL);
404
405         if (pfile_info == NULL) {
406                 kfree(utf16_path);
407                 return  -ENOMEM;
408         }
409
410         rc = SMB2_open(xid, &oparms, utf16_path, &oplock, pfile_info, NULL,
411                        NULL, NULL);
412         if (rc)
413                 goto qmf_out_open_fail;
414
415         if (pfile_info->EndOfFile != cpu_to_le64(CIFS_MF_SYMLINK_FILE_SIZE)) {
416                 /* it's not a symlink */
417                 rc = -ENOENT; /* Is there a better rc to return? */
418                 goto qmf_out;
419         }
420
421         io_parms.netfid = fid.netfid;
422         io_parms.pid = current->tgid;
423         io_parms.tcon = tcon;
424         io_parms.offset = 0;
425         io_parms.length = CIFS_MF_SYMLINK_FILE_SIZE;
426         io_parms.persistent_fid = fid.persistent_fid;
427         io_parms.volatile_fid = fid.volatile_fid;
428         rc = SMB2_read(xid, &io_parms, pbytes_read, &pbuf, &buf_type);
429 qmf_out:
430         SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
431 qmf_out_open_fail:
432         kfree(utf16_path);
433         kfree(pfile_info);
434         return rc;
435 }
436
437 int
438 smb3_create_mf_symlink(unsigned int xid, struct cifs_tcon *tcon,
439                        struct cifs_sb_info *cifs_sb, const unsigned char *path,
440                        char *pbuf, unsigned int *pbytes_written)
441 {
442         int rc;
443         struct cifs_fid fid;
444         struct cifs_open_parms oparms;
445         struct cifs_io_parms io_parms = {0};
446         __le16 *utf16_path;
447         __u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
448         struct kvec iov[2];
449
450         cifs_dbg(FYI, "%s: path: %s\n", __func__, path);
451
452         utf16_path = cifs_convert_path_to_utf16(path, cifs_sb);
453         if (!utf16_path)
454                 return -ENOMEM;
455
456         oparms.tcon = tcon;
457         oparms.cifs_sb = cifs_sb;
458         oparms.desired_access = GENERIC_WRITE;
459         oparms.create_options = cifs_create_options(cifs_sb, CREATE_NOT_DIR);
460         oparms.disposition = FILE_CREATE;
461         oparms.fid = &fid;
462         oparms.reconnect = false;
463
464         rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL,
465                        NULL, NULL);
466         if (rc) {
467                 kfree(utf16_path);
468                 return rc;
469         }
470
471         io_parms.netfid = fid.netfid;
472         io_parms.pid = current->tgid;
473         io_parms.tcon = tcon;
474         io_parms.offset = 0;
475         io_parms.length = CIFS_MF_SYMLINK_FILE_SIZE;
476         io_parms.persistent_fid = fid.persistent_fid;
477         io_parms.volatile_fid = fid.volatile_fid;
478
479         /* iov[0] is reserved for smb header */
480         iov[1].iov_base = pbuf;
481         iov[1].iov_len = CIFS_MF_SYMLINK_FILE_SIZE;
482
483         rc = SMB2_write(xid, &io_parms, pbytes_written, iov, 1);
484
485         /* Make sure we wrote all of the symlink data */
486         if ((rc == 0) && (*pbytes_written != CIFS_MF_SYMLINK_FILE_SIZE))
487                 rc = -EIO;
488
489         SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
490
491         kfree(utf16_path);
492         return rc;
493 }
494
495 /*
496  * M-F Symlink Functions - End
497  */
498
499 int
500 cifs_hardlink(struct dentry *old_file, struct inode *inode,
501               struct dentry *direntry)
502 {
503         int rc = -EACCES;
504         unsigned int xid;
505         const char *from_name, *to_name;
506         void *page1, *page2;
507         struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
508         struct tcon_link *tlink;
509         struct cifs_tcon *tcon;
510         struct TCP_Server_Info *server;
511         struct cifsInodeInfo *cifsInode;
512
513         if (unlikely(cifs_forced_shutdown(cifs_sb)))
514                 return -EIO;
515
516         tlink = cifs_sb_tlink(cifs_sb);
517         if (IS_ERR(tlink))
518                 return PTR_ERR(tlink);
519         tcon = tlink_tcon(tlink);
520
521         xid = get_xid();
522         page1 = alloc_dentry_path();
523         page2 = alloc_dentry_path();
524
525         from_name = build_path_from_dentry(old_file, page1);
526         if (IS_ERR(from_name)) {
527                 rc = PTR_ERR(from_name);
528                 goto cifs_hl_exit;
529         }
530         to_name = build_path_from_dentry(direntry, page2);
531         if (IS_ERR(to_name)) {
532                 rc = PTR_ERR(to_name);
533                 goto cifs_hl_exit;
534         }
535
536 #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
537         if (tcon->unix_ext)
538                 rc = CIFSUnixCreateHardLink(xid, tcon, from_name, to_name,
539                                             cifs_sb->local_nls,
540                                             cifs_remap(cifs_sb));
541         else {
542 #else
543         {
544 #endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
545                 server = tcon->ses->server;
546                 if (!server->ops->create_hardlink) {
547                         rc = -ENOSYS;
548                         goto cifs_hl_exit;
549                 }
550                 rc = server->ops->create_hardlink(xid, tcon, from_name, to_name,
551                                                   cifs_sb);
552                 if ((rc == -EIO) || (rc == -EINVAL))
553                         rc = -EOPNOTSUPP;
554         }
555
556         d_drop(direntry);       /* force new lookup from server of target */
557
558         /*
559          * if source file is cached (oplocked) revalidate will not go to server
560          * until the file is closed or oplock broken so update nlinks locally
561          */
562         if (d_really_is_positive(old_file)) {
563                 cifsInode = CIFS_I(d_inode(old_file));
564                 if (rc == 0) {
565                         spin_lock(&d_inode(old_file)->i_lock);
566                         inc_nlink(d_inode(old_file));
567                         spin_unlock(&d_inode(old_file)->i_lock);
568
569                         /*
570                          * parent dir timestamps will update from srv within a
571                          * second, would it really be worth it to set the parent
572                          * dir cifs inode time to zero to force revalidate
573                          * (faster) for it too?
574                          */
575                 }
576                 /*
577                  * if not oplocked will force revalidate to get info on source
578                  * file from srv.  Note Samba server prior to 4.2 has bug -
579                  * not updating src file ctime on hardlinks but Windows servers
580                  * handle it properly
581                  */
582                 cifsInode->time = 0;
583
584                 /*
585                  * Will update parent dir timestamps from srv within a second.
586                  * Would it really be worth it to set the parent dir (cifs
587                  * inode) time field to zero to force revalidate on parent
588                  * directory faster ie
589                  *
590                  * CIFS_I(inode)->time = 0;
591                  */
592         }
593
594 cifs_hl_exit:
595         free_dentry_path(page1);
596         free_dentry_path(page2);
597         free_xid(xid);
598         cifs_put_tlink(tlink);
599         return rc;
600 }
601
602 const char *
603 cifs_get_link(struct dentry *direntry, struct inode *inode,
604               struct delayed_call *done)
605 {
606         int rc = -ENOMEM;
607         unsigned int xid;
608         const char *full_path;
609         void *page;
610         char *target_path = NULL;
611         struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
612         struct tcon_link *tlink = NULL;
613         struct cifs_tcon *tcon;
614         struct TCP_Server_Info *server;
615
616         if (!direntry)
617                 return ERR_PTR(-ECHILD);
618
619         xid = get_xid();
620
621         tlink = cifs_sb_tlink(cifs_sb);
622         if (IS_ERR(tlink)) {
623                 free_xid(xid);
624                 return ERR_CAST(tlink);
625         }
626         tcon = tlink_tcon(tlink);
627         server = tcon->ses->server;
628
629         page = alloc_dentry_path();
630         full_path = build_path_from_dentry(direntry, page);
631         if (IS_ERR(full_path)) {
632                 free_xid(xid);
633                 cifs_put_tlink(tlink);
634                 free_dentry_path(page);
635                 return ERR_CAST(full_path);
636         }
637
638         cifs_dbg(FYI, "Full path: %s inode = 0x%p\n", full_path, inode);
639
640         rc = -EACCES;
641         /*
642          * First try Minshall+French Symlinks, if configured
643          * and fallback to UNIX Extensions Symlinks.
644          */
645         if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MF_SYMLINKS)
646                 rc = query_mf_symlink(xid, tcon, cifs_sb, full_path,
647                                       &target_path);
648
649         if (rc != 0 && server->ops->query_symlink) {
650                 struct cifsInodeInfo *cifsi = CIFS_I(inode);
651                 bool reparse_point = false;
652
653                 if (cifsi->cifsAttrs & ATTR_REPARSE)
654                         reparse_point = true;
655
656                 rc = server->ops->query_symlink(xid, tcon, cifs_sb, full_path,
657                                                 &target_path, reparse_point);
658         }
659
660         free_dentry_path(page);
661         free_xid(xid);
662         cifs_put_tlink(tlink);
663         if (rc != 0) {
664                 kfree(target_path);
665                 return ERR_PTR(rc);
666         }
667         set_delayed_call(done, kfree_link, target_path);
668         return target_path;
669 }
670
671 int
672 cifs_symlink(struct user_namespace *mnt_userns, struct inode *inode,
673              struct dentry *direntry, const char *symname)
674 {
675         int rc = -EOPNOTSUPP;
676         unsigned int xid;
677         struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
678         struct tcon_link *tlink;
679         struct cifs_tcon *pTcon;
680         const char *full_path;
681         void *page;
682         struct inode *newinode = NULL;
683
684         if (unlikely(cifs_forced_shutdown(cifs_sb)))
685                 return -EIO;
686
687         page = alloc_dentry_path();
688         if (!page)
689                 return -ENOMEM;
690
691         xid = get_xid();
692
693         tlink = cifs_sb_tlink(cifs_sb);
694         if (IS_ERR(tlink)) {
695                 rc = PTR_ERR(tlink);
696                 goto symlink_exit;
697         }
698         pTcon = tlink_tcon(tlink);
699
700         full_path = build_path_from_dentry(direntry, page);
701         if (IS_ERR(full_path)) {
702                 rc = PTR_ERR(full_path);
703                 goto symlink_exit;
704         }
705
706         cifs_dbg(FYI, "Full path: %s\n", full_path);
707         cifs_dbg(FYI, "symname is %s\n", symname);
708
709         /* BB what if DFS and this volume is on different share? BB */
710         if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MF_SYMLINKS)
711                 rc = create_mf_symlink(xid, pTcon, cifs_sb, full_path, symname);
712 #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
713         else if (pTcon->unix_ext)
714                 rc = CIFSUnixCreateSymLink(xid, pTcon, full_path, symname,
715                                            cifs_sb->local_nls,
716                                            cifs_remap(cifs_sb));
717 #endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
718         /* else
719            rc = CIFSCreateReparseSymLink(xid, pTcon, fromName, toName,
720                                         cifs_sb_target->local_nls); */
721
722         if (rc == 0) {
723                 if (pTcon->posix_extensions)
724                         rc = smb311_posix_get_inode_info(&newinode, full_path, inode->i_sb, xid);
725                 else if (pTcon->unix_ext)
726                         rc = cifs_get_inode_info_unix(&newinode, full_path,
727                                                       inode->i_sb, xid);
728                 else
729                         rc = cifs_get_inode_info(&newinode, full_path, NULL,
730                                                  inode->i_sb, xid, NULL);
731
732                 if (rc != 0) {
733                         cifs_dbg(FYI, "Create symlink ok, getinodeinfo fail rc = %d\n",
734                                  rc);
735                 } else {
736                         d_instantiate(direntry, newinode);
737                 }
738         }
739 symlink_exit:
740         free_dentry_path(page);
741         cifs_put_tlink(tlink);
742         free_xid(xid);
743         return rc;
744 }
This page took 0.074373 seconds and 4 git commands to generate.