25 #include <linux/module.h>
27 #include <linux/slab.h>
28 #include <linux/string.h>
29 #include <linux/kernel.h>
47 #define DNS_ERRORNO_OPTION "dnserror"
62 dns_resolver_instantiate(
struct key *
key,
struct key_preparsed_payload *prep)
67 size_t datalen = prep->datalen, result_len = 0;
70 kenter(
"%%%d,%s,'%*.*s',%zu",
71 key->serial, key->description,
72 (
int)datalen, (
int)datalen, data, datalen);
74 if (datalen <= 1 || !data || data[datalen - 1] !=
'\0')
80 opt =
memchr(data,
'#', datalen);
88 result_len = opt -
data;
90 kdebug(
"options: '%s'", opt);
93 int opt_len, opt_nlen, opt_vlen,
tmp;
96 opt_len = next_opt -
opt;
99 "Empty option to dns_resolver key %d\n",
107 opt_vlen = next_opt - eq;
109 tmp = opt_vlen >= 0 ? opt_vlen : 0;
110 kdebug(
"option '%*.*s' val '%*.*s'",
111 opt_nlen, opt_nlen, opt, tmp, tmp, eq);
117 kdebug(
"dns error number option");
119 goto bad_option_value;
123 goto bad_option_value;
125 if (derrno < 1 || derrno > 511)
126 goto bad_option_value;
128 kdebug(
"dns error no. = %lu", derrno);
129 key->type_data.x[0] = -derrno;
135 "Option '%*.*s' to dns_resolver key %d:"
136 " bad/missing value\n",
137 opt_nlen, opt_nlen, opt, key->serial);
139 }
while (opt = next_opt + 1, opt <
end);
144 if (key->type_data.x[0]) {
145 kleave(
" = 0 [h_error %ld]", key->type_data.x[0]);
160 upayload->
datalen = result_len;
162 upayload->
data[result_len] =
'\0';
191 if (slen <= 0 || dlen <= 0)
193 if (src[slen - 1] ==
'.')
195 if (
dsp[dlen - 1] ==
'.')
210 static void dns_resolver_describe(
const struct key *key,
struct seq_file *
m)
212 int err = key->type_data.x[0];
215 if (key_is_instantiated(key)) {
227 static long dns_resolver_read(
const struct key *key,
230 if (key->type_data.x[0])
231 return key->type_data.x[0];
237 .name =
"dns_resolver",
238 .instantiate = dns_resolver_instantiate,
239 .match = dns_resolver_match,
242 .describe = dns_resolver_describe,
243 .read = dns_resolver_read,
246 static int __init init_dns_resolver(
void)
264 (KEY_POS_ALL & ~KEY_POS_SETATTR) |
265 KEY_USR_VIEW | KEY_USR_READ,
266 KEY_ALLOC_NOT_IN_QUOTA);
267 if (IS_ERR(keyring)) {
268 ret = PTR_ERR(keyring);
269 goto failed_put_cred;
282 set_bit(KEY_FLAG_ROOT_CAN_CLEAR, &keyring->flags);
283 cred->thread_keyring = keyring;
285 dns_resolver_cache = cred;
287 kdebug(
"DNS resolver keyring: %d\n", key_serial(keyring));
297 static void __exit exit_dns_resolver(
void)
299 key_revoke(dns_resolver_cache->thread_keyring);
301 put_cred(dns_resolver_cache);