|
20 | 20 | #include <linux/ceph/decode.h> |
21 | 21 | #include <linux/ceph/mon_client.h> |
22 | 22 | #include <linux/ceph/auth.h> |
| 23 | +#include "crypto.h" |
23 | 24 |
|
24 | 25 |
|
25 | 26 |
|
@@ -117,9 +118,29 @@ int ceph_compare_options(struct ceph_options *new_opt, |
117 | 118 | if (ret) |
118 | 119 | return ret; |
119 | 120 |
|
120 | | - ret = strcmp_null(opt1->secret, opt2->secret); |
121 | | - if (ret) |
122 | | - return ret; |
| 121 | + if (opt1->key && !opt2->key) |
| 122 | + return -1; |
| 123 | + if (!opt1->key && opt2->key) |
| 124 | + return 1; |
| 125 | + if (opt1->key && opt2->key) { |
| 126 | + if (opt1->key->type != opt2->key->type) |
| 127 | + return -1; |
| 128 | + if (opt1->key->created.tv_sec != opt2->key->created.tv_sec) |
| 129 | + return -1; |
| 130 | + if (opt1->key->created.tv_nsec != opt2->key->created.tv_nsec) |
| 131 | + return -1; |
| 132 | + if (opt1->key->len != opt2->key->len) |
| 133 | + return -1; |
| 134 | + if (opt1->key->key && !opt2->key->key) |
| 135 | + return -1; |
| 136 | + if (!opt1->key->key && opt2->key->key) |
| 137 | + return 1; |
| 138 | + if (opt1->key->key && opt2->key->key) { |
| 139 | + ret = memcmp(opt1->key->key, opt2->key->key, opt1->key->len); |
| 140 | + if (ret) |
| 141 | + return ret; |
| 142 | + } |
| 143 | + } |
123 | 144 |
|
124 | 145 | /* any matching mon ip implies a match */ |
125 | 146 | for (i = 0; i < opt1->num_mon; i++) { |
@@ -203,7 +224,10 @@ void ceph_destroy_options(struct ceph_options *opt) |
203 | 224 | { |
204 | 225 | dout("destroy_options %p\n", opt); |
205 | 226 | kfree(opt->name); |
206 | | - kfree(opt->secret); |
| 227 | + if (opt->key) { |
| 228 | + ceph_crypto_key_destroy(opt->key); |
| 229 | + kfree(opt->key); |
| 230 | + } |
207 | 231 | kfree(opt); |
208 | 232 | } |
209 | 233 | EXPORT_SYMBOL(ceph_destroy_options); |
@@ -295,9 +319,14 @@ int ceph_parse_options(struct ceph_options **popt, char *options, |
295 | 319 | GFP_KERNEL); |
296 | 320 | break; |
297 | 321 | case Opt_secret: |
298 | | - opt->secret = kstrndup(argstr[0].from, |
299 | | - argstr[0].to-argstr[0].from, |
300 | | - GFP_KERNEL); |
| 322 | + opt->key = kzalloc(sizeof(*opt->key), GFP_KERNEL); |
| 323 | + if (!opt->key) { |
| 324 | + err = -ENOMEM; |
| 325 | + goto out; |
| 326 | + } |
| 327 | + err = ceph_crypto_key_unarmor(opt->key, argstr[0].from); |
| 328 | + if (err < 0) |
| 329 | + goto out; |
301 | 330 | break; |
302 | 331 |
|
303 | 332 | /* misc */ |
|
0 commit comments