Commit | Line | Data |
---|---|---|
abdb1742 PA |
1 | // SPDX-License-Identifier: GPL-2.0 |
2 | /* | |
3 | * Copyright (c) 2022 Paulo Alcantara <palcantara@suse.de> | |
4 | */ | |
5 | ||
6 | #include "cifsproto.h" | |
7 | #include "cifs_debug.h" | |
8 | #include "dns_resolve.h" | |
9 | #include "fs_context.h" | |
10 | #include "dfs.h" | |
11 | ||
abdb1742 PA |
12 | /** |
13 | * dfs_parse_target_referral - set fs context for dfs target referral | |
14 | * | |
15 | * @full_path: full path in UNC format. | |
16 | * @ref: dfs referral pointer. | |
17 | * @ctx: smb3 fs context pointer. | |
18 | * | |
19 | * Return zero if dfs referral was parsed correctly, otherwise non-zero. | |
20 | */ | |
21 | int dfs_parse_target_referral(const char *full_path, const struct dfs_info3_param *ref, | |
22 | struct smb3_fs_context *ctx) | |
23 | { | |
24 | int rc; | |
25 | const char *prepath = NULL; | |
26 | char *path; | |
27 | ||
28 | if (!full_path || !*full_path || !ref || !ctx) | |
29 | return -EINVAL; | |
30 | ||
31 | if (WARN_ON_ONCE(!ref->node_name || ref->path_consumed < 0)) | |
32 | return -EINVAL; | |
33 | ||
34 | if (strlen(full_path) - ref->path_consumed) { | |
35 | prepath = full_path + ref->path_consumed; | |
36 | /* skip initial delimiter */ | |
37 | if (*prepath == '/' || *prepath == '\\') | |
38 | prepath++; | |
39 | } | |
40 | ||
41 | path = cifs_build_devname(ref->node_name, prepath); | |
42 | if (IS_ERR(path)) | |
43 | return PTR_ERR(path); | |
44 | ||
45 | rc = smb3_parse_devname(path, ctx); | |
46 | if (rc) | |
47 | goto out; | |
48 | ||
6d740164 | 49 | rc = dns_resolve_server_name_to_ip(path, (struct sockaddr *)&ctx->dstaddr, NULL); |
abdb1742 PA |
50 | |
51 | out: | |
52 | kfree(path); | |
53 | return rc; | |
54 | } |