diff options
author | Steve French <sfrench@us.ibm.com> | 2008-01-10 12:10:23 -0500 |
---|---|---|
committer | Steve French <sfrench@us.ibm.com> | 2008-01-10 12:10:23 -0500 |
commit | 197c183f3526dc08aa52ca97ec66c268442d4b84 (patch) | |
tree | 63d857c72c7e301ae67afef59d0a9d52c8f9ac63 | |
parent | 6103335de8afa5d780dcd512abe85c696af7b040 (diff) |
[CIFS] Forgot to add two new files from previous commit
Thanks to Igor for noticing this.
CC: Igor Mammedov <niallain@gmail.com>
Signed-off-by: Steve French <sfrench@us.ibm.com>
-rw-r--r-- | fs/cifs/dns_resolve.c | 123 | ||||
-rw-r--r-- | fs/cifs/dns_resolve.h | 32 |
2 files changed, 155 insertions, 0 deletions
diff --git a/fs/cifs/dns_resolve.c b/fs/cifs/dns_resolve.c new file mode 100644 index 000000000000..777a086abd6f --- /dev/null +++ b/fs/cifs/dns_resolve.c | |||
@@ -0,0 +1,123 @@ | |||
1 | /* | ||
2 | * fs/cifs/dns_resolve.c | ||
3 | * | ||
4 | * Copyright (c) 2007 Igor Mammedov | ||
5 | * Author(s): Igor Mammedov (niallain@gmail.com) | ||
6 | * Steve French (sfrench@us.ibm.com) | ||
7 | * | ||
8 | * Contains the CIFS DFS upcall routines used for hostname to | ||
9 | * IP address translation. | ||
10 | * | ||
11 | * This library is free software; you can redistribute it and/or modify | ||
12 | * it under the terms of the GNU Lesser General Public License as published | ||
13 | * by the Free Software Foundation; either version 2.1 of the License, or | ||
14 | * (at your option) any later version. | ||
15 | * | ||
16 | * This library is distributed in the hope that it will be useful, | ||
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See | ||
19 | * the GNU Lesser General Public License for more details. | ||
20 | * | ||
21 | * You should have received a copy of the GNU Lesser General Public License | ||
22 | * along with this library; if not, write to the Free Software | ||
23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
24 | */ | ||
25 | |||
26 | #include <keys/user-type.h> | ||
27 | #include "dns_resolve.h" | ||
28 | #include "cifsglob.h" | ||
29 | #include "cifsproto.h" | ||
30 | #include "cifs_debug.h" | ||
31 | |||
32 | static int dns_resolver_instantiate(struct key *key, const void *data, | ||
33 | size_t datalen) | ||
34 | { | ||
35 | int rc = 0; | ||
36 | char *ip; | ||
37 | |||
38 | ip = kmalloc(datalen+1, GFP_KERNEL); | ||
39 | if (!ip) | ||
40 | return -ENOMEM; | ||
41 | |||
42 | memcpy(ip, data, datalen); | ||
43 | ip[datalen] = '\0'; | ||
44 | |||
45 | rcu_assign_pointer(key->payload.data, ip); | ||
46 | |||
47 | return rc; | ||
48 | } | ||
49 | |||
50 | struct key_type key_type_dns_resolver = { | ||
51 | .name = "dns_resolver", | ||
52 | .def_datalen = sizeof(struct in_addr), | ||
53 | .describe = user_describe, | ||
54 | .instantiate = dns_resolver_instantiate, | ||
55 | .match = user_match, | ||
56 | }; | ||
57 | |||
58 | |||
59 | /* Resolves server name to ip address. | ||
60 | * input: | ||
61 | * unc - server UNC | ||
62 | * output: | ||
63 | * *ip_addr - pointer to server ip, caller responcible for freeing it. | ||
64 | * return 0 on success | ||
65 | */ | ||
66 | int | ||
67 | dns_resolve_server_name_to_ip(const char *unc, char **ip_addr) { | ||
68 | int rc = -EAGAIN; | ||
69 | struct key *rkey; | ||
70 | char *name; | ||
71 | int len; | ||
72 | |||
73 | if ((!ip_addr) || (!unc)) | ||
74 | return -EINVAL; | ||
75 | |||
76 | /* search for server name delimiter */ | ||
77 | len = strlen(unc); | ||
78 | if (len < 3) { | ||
79 | cFYI(1, ("%s: unc is too short: %s", __FUNCTION__, unc)); | ||
80 | return -EINVAL; | ||
81 | } | ||
82 | len -= 2; | ||
83 | name = memchr(unc+2, '\\', len); | ||
84 | if (!name) { | ||
85 | cFYI(1, ("%s: probably server name is whole unc: %s", | ||
86 | __FUNCTION__, unc)); | ||
87 | } else { | ||
88 | len = (name - unc) - 2/* leading // */; | ||
89 | } | ||
90 | |||
91 | name = kmalloc(len+1, GFP_KERNEL); | ||
92 | if (!name) { | ||
93 | rc = -ENOMEM; | ||
94 | return rc; | ||
95 | } | ||
96 | memcpy(name, unc+2, len); | ||
97 | name[len] = 0; | ||
98 | |||
99 | rkey = request_key(&key_type_dns_resolver, name, ""); | ||
100 | if (!IS_ERR(rkey)) { | ||
101 | len = strlen(rkey->payload.data); | ||
102 | *ip_addr = kmalloc(len+1, GFP_KERNEL); | ||
103 | if (*ip_addr) { | ||
104 | memcpy(*ip_addr, rkey->payload.data, len); | ||
105 | (*ip_addr)[len] = '\0'; | ||
106 | cFYI(1, ("%s: resolved: %s to %s", __FUNCTION__, | ||
107 | rkey->description, | ||
108 | *ip_addr | ||
109 | )); | ||
110 | rc = 0; | ||
111 | } else { | ||
112 | rc = -ENOMEM; | ||
113 | } | ||
114 | key_put(rkey); | ||
115 | } else { | ||
116 | cERROR(1, ("%s: unable to resolve: %s", __FUNCTION__, name)); | ||
117 | } | ||
118 | |||
119 | kfree(name); | ||
120 | return rc; | ||
121 | } | ||
122 | |||
123 | |||
diff --git a/fs/cifs/dns_resolve.h b/fs/cifs/dns_resolve.h new file mode 100644 index 000000000000..073fdc3db419 --- /dev/null +++ b/fs/cifs/dns_resolve.h | |||
@@ -0,0 +1,32 @@ | |||
1 | /* | ||
2 | * fs/cifs/dns_resolve.h -- DNS Resolver upcall management for CIFS DFS | ||
3 | * Handles host name to IP address resolution | ||
4 | * | ||
5 | * Copyright (c) International Business Machines Corp., 2008 | ||
6 | * Author(s): Steve French (sfrench@us.ibm.com) | ||
7 | * | ||
8 | * This library is free software; you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU Lesser General Public License as published | ||
10 | * by the Free Software Foundation; either version 2.1 of the License, or | ||
11 | * (at your option) any later version. | ||
12 | * | ||
13 | * This library is distributed in the hope that it will be useful, | ||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See | ||
16 | * the GNU Lesser General Public License for more details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU Lesser General Public License | ||
19 | * along with this library; if not, write to the Free Software | ||
20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
21 | */ | ||
22 | |||
23 | #ifndef _DNS_RESOLVE_H | ||
24 | #define _DNS_RESOLVE_H | ||
25 | |||
26 | #ifdef __KERNEL__ | ||
27 | #include <linux/key-type.h> | ||
28 | extern struct key_type key_type_dns_resolver; | ||
29 | extern int dns_resolve_server_name_to_ip(const char *unc, char **ip_addr); | ||
30 | #endif /* KERNEL */ | ||
31 | |||
32 | #endif /* _DNS_RESOLVE_H */ | ||