gss_rpc_xdr.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849
  1. /*
  2. * GSS Proxy upcall module
  3. *
  4. * Copyright (C) 2012 Simo Sorce <simo@redhat.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. */
  20. #include <linux/sunrpc/svcauth.h>
  21. #include "gss_rpc_xdr.h"
  22. static int gssx_enc_bool(struct xdr_stream *xdr, int v)
  23. {
  24. __be32 *p;
  25. p = xdr_reserve_space(xdr, 4);
  26. if (unlikely(p == NULL))
  27. return -ENOSPC;
  28. *p = v ? xdr_one : xdr_zero;
  29. return 0;
  30. }
  31. static int gssx_dec_bool(struct xdr_stream *xdr, u32 *v)
  32. {
  33. __be32 *p;
  34. p = xdr_inline_decode(xdr, 4);
  35. if (unlikely(p == NULL))
  36. return -ENOSPC;
  37. *v = be32_to_cpu(*p);
  38. return 0;
  39. }
  40. static int gssx_enc_buffer(struct xdr_stream *xdr,
  41. gssx_buffer *buf)
  42. {
  43. __be32 *p;
  44. p = xdr_reserve_space(xdr, sizeof(u32) + buf->len);
  45. if (!p)
  46. return -ENOSPC;
  47. xdr_encode_opaque(p, buf->data, buf->len);
  48. return 0;
  49. }
  50. static int gssx_enc_in_token(struct xdr_stream *xdr,
  51. struct gssp_in_token *in)
  52. {
  53. __be32 *p;
  54. p = xdr_reserve_space(xdr, 4);
  55. if (!p)
  56. return -ENOSPC;
  57. *p = cpu_to_be32(in->page_len);
  58. /* all we need to do is to write pages */
  59. xdr_write_pages(xdr, in->pages, in->page_base, in->page_len);
  60. return 0;
  61. }
  62. static int gssx_dec_buffer(struct xdr_stream *xdr,
  63. gssx_buffer *buf)
  64. {
  65. u32 length;
  66. __be32 *p;
  67. p = xdr_inline_decode(xdr, 4);
  68. if (unlikely(p == NULL))
  69. return -ENOSPC;
  70. length = be32_to_cpup(p);
  71. p = xdr_inline_decode(xdr, length);
  72. if (unlikely(p == NULL))
  73. return -ENOSPC;
  74. if (buf->len == 0) {
  75. /* we intentionally are not interested in this buffer */
  76. return 0;
  77. }
  78. if (length > buf->len)
  79. return -ENOSPC;
  80. if (!buf->data) {
  81. buf->data = kmemdup(p, length, GFP_KERNEL);
  82. if (!buf->data)
  83. return -ENOMEM;
  84. } else {
  85. memcpy(buf->data, p, length);
  86. }
  87. buf->len = length;
  88. return 0;
  89. }
  90. static int gssx_enc_option(struct xdr_stream *xdr,
  91. struct gssx_option *opt)
  92. {
  93. int err;
  94. err = gssx_enc_buffer(xdr, &opt->option);
  95. if (err)
  96. return err;
  97. err = gssx_enc_buffer(xdr, &opt->value);
  98. return err;
  99. }
  100. static int gssx_dec_option(struct xdr_stream *xdr,
  101. struct gssx_option *opt)
  102. {
  103. int err;
  104. err = gssx_dec_buffer(xdr, &opt->option);
  105. if (err)
  106. return err;
  107. err = gssx_dec_buffer(xdr, &opt->value);
  108. return err;
  109. }
  110. static int dummy_enc_opt_array(struct xdr_stream *xdr,
  111. struct gssx_option_array *oa)
  112. {
  113. __be32 *p;
  114. if (oa->count != 0)
  115. return -EINVAL;
  116. p = xdr_reserve_space(xdr, 4);
  117. if (!p)
  118. return -ENOSPC;
  119. *p = 0;
  120. return 0;
  121. }
  122. static int dummy_dec_opt_array(struct xdr_stream *xdr,
  123. struct gssx_option_array *oa)
  124. {
  125. struct gssx_option dummy;
  126. u32 count, i;
  127. __be32 *p;
  128. p = xdr_inline_decode(xdr, 4);
  129. if (unlikely(p == NULL))
  130. return -ENOSPC;
  131. count = be32_to_cpup(p++);
  132. memset(&dummy, 0, sizeof(dummy));
  133. for (i = 0; i < count; i++) {
  134. gssx_dec_option(xdr, &dummy);
  135. }
  136. oa->count = 0;
  137. oa->data = NULL;
  138. return 0;
  139. }
  140. static int get_host_u32(struct xdr_stream *xdr, u32 *res)
  141. {
  142. __be32 *p;
  143. p = xdr_inline_decode(xdr, 4);
  144. if (!p)
  145. return -EINVAL;
  146. /* Contents of linux creds are all host-endian: */
  147. memcpy(res, p, sizeof(u32));
  148. return 0;
  149. }
  150. static int gssx_dec_linux_creds(struct xdr_stream *xdr,
  151. struct svc_cred *creds)
  152. {
  153. u32 length;
  154. __be32 *p;
  155. u32 tmp;
  156. u32 N;
  157. int i, err;
  158. p = xdr_inline_decode(xdr, 4);
  159. if (unlikely(p == NULL))
  160. return -ENOSPC;
  161. length = be32_to_cpup(p);
  162. if (length > (3 + NGROUPS_MAX) * sizeof(u32))
  163. return -ENOSPC;
  164. /* uid */
  165. err = get_host_u32(xdr, &tmp);
  166. if (err)
  167. return err;
  168. creds->cr_uid = make_kuid(&init_user_ns, tmp);
  169. /* gid */
  170. err = get_host_u32(xdr, &tmp);
  171. if (err)
  172. return err;
  173. creds->cr_gid = make_kgid(&init_user_ns, tmp);
  174. /* number of additional gid's */
  175. err = get_host_u32(xdr, &tmp);
  176. if (err)
  177. return err;
  178. N = tmp;
  179. if ((3 + N) * sizeof(u32) != length)
  180. return -EINVAL;
  181. creds->cr_group_info = groups_alloc(N);
  182. if (creds->cr_group_info == NULL)
  183. return -ENOMEM;
  184. /* gid's */
  185. for (i = 0; i < N; i++) {
  186. kgid_t kgid;
  187. err = get_host_u32(xdr, &tmp);
  188. if (err)
  189. goto out_free_groups;
  190. err = -EINVAL;
  191. kgid = make_kgid(&init_user_ns, tmp);
  192. if (!gid_valid(kgid))
  193. goto out_free_groups;
  194. GROUP_AT(creds->cr_group_info, i) = kgid;
  195. }
  196. return 0;
  197. out_free_groups:
  198. groups_free(creds->cr_group_info);
  199. return err;
  200. }
  201. static int gssx_dec_option_array(struct xdr_stream *xdr,
  202. struct gssx_option_array *oa)
  203. {
  204. struct svc_cred *creds;
  205. u32 count, i;
  206. __be32 *p;
  207. int err;
  208. p = xdr_inline_decode(xdr, 4);
  209. if (unlikely(p == NULL))
  210. return -ENOSPC;
  211. count = be32_to_cpup(p++);
  212. if (!count)
  213. return 0;
  214. /* we recognize only 1 currently: CREDS_VALUE */
  215. oa->count = 1;
  216. oa->data = kmalloc(sizeof(struct gssx_option), GFP_KERNEL);
  217. if (!oa->data)
  218. return -ENOMEM;
  219. creds = kmalloc(sizeof(struct svc_cred), GFP_KERNEL);
  220. if (!creds) {
  221. kfree(oa->data);
  222. return -ENOMEM;
  223. }
  224. oa->data[0].option.data = CREDS_VALUE;
  225. oa->data[0].option.len = sizeof(CREDS_VALUE);
  226. oa->data[0].value.data = (void *)creds;
  227. oa->data[0].value.len = 0;
  228. for (i = 0; i < count; i++) {
  229. gssx_buffer dummy = { 0, NULL };
  230. u32 length;
  231. /* option buffer */
  232. p = xdr_inline_decode(xdr, 4);
  233. if (unlikely(p == NULL))
  234. return -ENOSPC;
  235. length = be32_to_cpup(p);
  236. p = xdr_inline_decode(xdr, length);
  237. if (unlikely(p == NULL))
  238. return -ENOSPC;
  239. if (length == sizeof(CREDS_VALUE) &&
  240. memcmp(p, CREDS_VALUE, sizeof(CREDS_VALUE)) == 0) {
  241. /* We have creds here. parse them */
  242. err = gssx_dec_linux_creds(xdr, creds);
  243. if (err)
  244. return err;
  245. oa->data[0].value.len = 1; /* presence */
  246. } else {
  247. /* consume uninteresting buffer */
  248. err = gssx_dec_buffer(xdr, &dummy);
  249. if (err)
  250. return err;
  251. }
  252. }
  253. return 0;
  254. }
  255. static int gssx_dec_status(struct xdr_stream *xdr,
  256. struct gssx_status *status)
  257. {
  258. __be32 *p;
  259. int err;
  260. /* status->major_status */
  261. p = xdr_inline_decode(xdr, 8);
  262. if (unlikely(p == NULL))
  263. return -ENOSPC;
  264. p = xdr_decode_hyper(p, &status->major_status);
  265. /* status->mech */
  266. err = gssx_dec_buffer(xdr, &status->mech);
  267. if (err)
  268. return err;
  269. /* status->minor_status */
  270. p = xdr_inline_decode(xdr, 8);
  271. if (unlikely(p == NULL))
  272. return -ENOSPC;
  273. p = xdr_decode_hyper(p, &status->minor_status);
  274. /* status->major_status_string */
  275. err = gssx_dec_buffer(xdr, &status->major_status_string);
  276. if (err)
  277. return err;
  278. /* status->minor_status_string */
  279. err = gssx_dec_buffer(xdr, &status->minor_status_string);
  280. if (err)
  281. return err;
  282. /* status->server_ctx */
  283. err = gssx_dec_buffer(xdr, &status->server_ctx);
  284. if (err)
  285. return err;
  286. /* we assume we have no options for now, so simply consume them */
  287. /* status->options */
  288. err = dummy_dec_opt_array(xdr, &status->options);
  289. return err;
  290. }
  291. static int gssx_enc_call_ctx(struct xdr_stream *xdr,
  292. struct gssx_call_ctx *ctx)
  293. {
  294. struct gssx_option opt;
  295. __be32 *p;
  296. int err;
  297. /* ctx->locale */
  298. err = gssx_enc_buffer(xdr, &ctx->locale);
  299. if (err)
  300. return err;
  301. /* ctx->server_ctx */
  302. err = gssx_enc_buffer(xdr, &ctx->server_ctx);
  303. if (err)
  304. return err;
  305. /* we always want to ask for lucid contexts */
  306. /* ctx->options */
  307. p = xdr_reserve_space(xdr, 4);
  308. *p = cpu_to_be32(2);
  309. /* we want a lucid_v1 context */
  310. opt.option.data = LUCID_OPTION;
  311. opt.option.len = sizeof(LUCID_OPTION);
  312. opt.value.data = LUCID_VALUE;
  313. opt.value.len = sizeof(LUCID_VALUE);
  314. err = gssx_enc_option(xdr, &opt);
  315. /* ..and user creds */
  316. opt.option.data = CREDS_OPTION;
  317. opt.option.len = sizeof(CREDS_OPTION);
  318. opt.value.data = CREDS_VALUE;
  319. opt.value.len = sizeof(CREDS_VALUE);
  320. err = gssx_enc_option(xdr, &opt);
  321. return err;
  322. }
  323. static int gssx_dec_name_attr(struct xdr_stream *xdr,
  324. struct gssx_name_attr *attr)
  325. {
  326. int err;
  327. /* attr->attr */
  328. err = gssx_dec_buffer(xdr, &attr->attr);
  329. if (err)
  330. return err;
  331. /* attr->value */
  332. err = gssx_dec_buffer(xdr, &attr->value);
  333. if (err)
  334. return err;
  335. /* attr->extensions */
  336. err = dummy_dec_opt_array(xdr, &attr->extensions);
  337. return err;
  338. }
  339. static int dummy_enc_nameattr_array(struct xdr_stream *xdr,
  340. struct gssx_name_attr_array *naa)
  341. {
  342. __be32 *p;
  343. if (naa->count != 0)
  344. return -EINVAL;
  345. p = xdr_reserve_space(xdr, 4);
  346. if (!p)
  347. return -ENOSPC;
  348. *p = 0;
  349. return 0;
  350. }
  351. static int dummy_dec_nameattr_array(struct xdr_stream *xdr,
  352. struct gssx_name_attr_array *naa)
  353. {
  354. struct gssx_name_attr dummy = { .attr = {.len = 0} };
  355. u32 count, i;
  356. __be32 *p;
  357. p = xdr_inline_decode(xdr, 4);
  358. if (unlikely(p == NULL))
  359. return -ENOSPC;
  360. count = be32_to_cpup(p++);
  361. for (i = 0; i < count; i++) {
  362. gssx_dec_name_attr(xdr, &dummy);
  363. }
  364. naa->count = 0;
  365. naa->data = NULL;
  366. return 0;
  367. }
  368. static struct xdr_netobj zero_netobj = {};
  369. static struct gssx_name_attr_array zero_name_attr_array = {};
  370. static struct gssx_option_array zero_option_array = {};
  371. static int gssx_enc_name(struct xdr_stream *xdr,
  372. struct gssx_name *name)
  373. {
  374. int err;
  375. /* name->display_name */
  376. err = gssx_enc_buffer(xdr, &name->display_name);
  377. if (err)
  378. return err;
  379. /* name->name_type */
  380. err = gssx_enc_buffer(xdr, &zero_netobj);
  381. if (err)
  382. return err;
  383. /* name->exported_name */
  384. err = gssx_enc_buffer(xdr, &zero_netobj);
  385. if (err)
  386. return err;
  387. /* name->exported_composite_name */
  388. err = gssx_enc_buffer(xdr, &zero_netobj);
  389. if (err)
  390. return err;
  391. /* leave name_attributes empty for now, will add once we have any
  392. * to pass up at all */
  393. /* name->name_attributes */
  394. err = dummy_enc_nameattr_array(xdr, &zero_name_attr_array);
  395. if (err)
  396. return err;
  397. /* leave options empty for now, will add once we have any options
  398. * to pass up at all */
  399. /* name->extensions */
  400. err = dummy_enc_opt_array(xdr, &zero_option_array);
  401. return err;
  402. }
  403. static int gssx_dec_name(struct xdr_stream *xdr,
  404. struct gssx_name *name)
  405. {
  406. struct xdr_netobj dummy_netobj = { .len = 0 };
  407. struct gssx_name_attr_array dummy_name_attr_array = { .count = 0 };
  408. struct gssx_option_array dummy_option_array = { .count = 0 };
  409. int err;
  410. /* name->display_name */
  411. err = gssx_dec_buffer(xdr, &name->display_name);
  412. if (err)
  413. return err;
  414. /* name->name_type */
  415. err = gssx_dec_buffer(xdr, &dummy_netobj);
  416. if (err)
  417. return err;
  418. /* name->exported_name */
  419. err = gssx_dec_buffer(xdr, &dummy_netobj);
  420. if (err)
  421. return err;
  422. /* name->exported_composite_name */
  423. err = gssx_dec_buffer(xdr, &dummy_netobj);
  424. if (err)
  425. return err;
  426. /* we assume we have no attributes for now, so simply consume them */
  427. /* name->name_attributes */
  428. err = dummy_dec_nameattr_array(xdr, &dummy_name_attr_array);
  429. if (err)
  430. return err;
  431. /* we assume we have no options for now, so simply consume them */
  432. /* name->extensions */
  433. err = dummy_dec_opt_array(xdr, &dummy_option_array);
  434. return err;
  435. }
  436. static int dummy_enc_credel_array(struct xdr_stream *xdr,
  437. struct gssx_cred_element_array *cea)
  438. {
  439. __be32 *p;
  440. if (cea->count != 0)
  441. return -EINVAL;
  442. p = xdr_reserve_space(xdr, 4);
  443. if (!p)
  444. return -ENOSPC;
  445. *p = 0;
  446. return 0;
  447. }
  448. static int gssx_enc_cred(struct xdr_stream *xdr,
  449. struct gssx_cred *cred)
  450. {
  451. int err;
  452. /* cred->desired_name */
  453. err = gssx_enc_name(xdr, &cred->desired_name);
  454. if (err)
  455. return err;
  456. /* cred->elements */
  457. err = dummy_enc_credel_array(xdr, &cred->elements);
  458. if (err)
  459. return err;
  460. /* cred->cred_handle_reference */
  461. err = gssx_enc_buffer(xdr, &cred->cred_handle_reference);
  462. if (err)
  463. return err;
  464. /* cred->needs_release */
  465. err = gssx_enc_bool(xdr, cred->needs_release);
  466. return err;
  467. }
  468. static int gssx_enc_ctx(struct xdr_stream *xdr,
  469. struct gssx_ctx *ctx)
  470. {
  471. __be32 *p;
  472. int err;
  473. /* ctx->exported_context_token */
  474. err = gssx_enc_buffer(xdr, &ctx->exported_context_token);
  475. if (err)
  476. return err;
  477. /* ctx->state */
  478. err = gssx_enc_buffer(xdr, &ctx->state);
  479. if (err)
  480. return err;
  481. /* ctx->need_release */
  482. err = gssx_enc_bool(xdr, ctx->need_release);
  483. if (err)
  484. return err;
  485. /* ctx->mech */
  486. err = gssx_enc_buffer(xdr, &ctx->mech);
  487. if (err)
  488. return err;
  489. /* ctx->src_name */
  490. err = gssx_enc_name(xdr, &ctx->src_name);
  491. if (err)
  492. return err;
  493. /* ctx->targ_name */
  494. err = gssx_enc_name(xdr, &ctx->targ_name);
  495. if (err)
  496. return err;
  497. /* ctx->lifetime */
  498. p = xdr_reserve_space(xdr, 8+8);
  499. if (!p)
  500. return -ENOSPC;
  501. p = xdr_encode_hyper(p, ctx->lifetime);
  502. /* ctx->ctx_flags */
  503. p = xdr_encode_hyper(p, ctx->ctx_flags);
  504. /* ctx->locally_initiated */
  505. err = gssx_enc_bool(xdr, ctx->locally_initiated);
  506. if (err)
  507. return err;
  508. /* ctx->open */
  509. err = gssx_enc_bool(xdr, ctx->open);
  510. if (err)
  511. return err;
  512. /* leave options empty for now, will add once we have any options
  513. * to pass up at all */
  514. /* ctx->options */
  515. err = dummy_enc_opt_array(xdr, &ctx->options);
  516. return err;
  517. }
  518. static int gssx_dec_ctx(struct xdr_stream *xdr,
  519. struct gssx_ctx *ctx)
  520. {
  521. __be32 *p;
  522. int err;
  523. /* ctx->exported_context_token */
  524. err = gssx_dec_buffer(xdr, &ctx->exported_context_token);
  525. if (err)
  526. return err;
  527. /* ctx->state */
  528. err = gssx_dec_buffer(xdr, &ctx->state);
  529. if (err)
  530. return err;
  531. /* ctx->need_release */
  532. err = gssx_dec_bool(xdr, &ctx->need_release);
  533. if (err)
  534. return err;
  535. /* ctx->mech */
  536. err = gssx_dec_buffer(xdr, &ctx->mech);
  537. if (err)
  538. return err;
  539. /* ctx->src_name */
  540. err = gssx_dec_name(xdr, &ctx->src_name);
  541. if (err)
  542. return err;
  543. /* ctx->targ_name */
  544. err = gssx_dec_name(xdr, &ctx->targ_name);
  545. if (err)
  546. return err;
  547. /* ctx->lifetime */
  548. p = xdr_inline_decode(xdr, 8+8);
  549. if (unlikely(p == NULL))
  550. return -ENOSPC;
  551. p = xdr_decode_hyper(p, &ctx->lifetime);
  552. /* ctx->ctx_flags */
  553. p = xdr_decode_hyper(p, &ctx->ctx_flags);
  554. /* ctx->locally_initiated */
  555. err = gssx_dec_bool(xdr, &ctx->locally_initiated);
  556. if (err)
  557. return err;
  558. /* ctx->open */
  559. err = gssx_dec_bool(xdr, &ctx->open);
  560. if (err)
  561. return err;
  562. /* we assume we have no options for now, so simply consume them */
  563. /* ctx->options */
  564. err = dummy_dec_opt_array(xdr, &ctx->options);
  565. return err;
  566. }
  567. static int gssx_enc_cb(struct xdr_stream *xdr, struct gssx_cb *cb)
  568. {
  569. __be32 *p;
  570. int err;
  571. /* cb->initiator_addrtype */
  572. p = xdr_reserve_space(xdr, 8);
  573. if (!p)
  574. return -ENOSPC;
  575. p = xdr_encode_hyper(p, cb->initiator_addrtype);
  576. /* cb->initiator_address */
  577. err = gssx_enc_buffer(xdr, &cb->initiator_address);
  578. if (err)
  579. return err;
  580. /* cb->acceptor_addrtype */
  581. p = xdr_reserve_space(xdr, 8);
  582. if (!p)
  583. return -ENOSPC;
  584. p = xdr_encode_hyper(p, cb->acceptor_addrtype);
  585. /* cb->acceptor_address */
  586. err = gssx_enc_buffer(xdr, &cb->acceptor_address);
  587. if (err)
  588. return err;
  589. /* cb->application_data */
  590. err = gssx_enc_buffer(xdr, &cb->application_data);
  591. return err;
  592. }
  593. void gssx_enc_accept_sec_context(struct rpc_rqst *req,
  594. struct xdr_stream *xdr,
  595. struct gssx_arg_accept_sec_context *arg)
  596. {
  597. int err;
  598. err = gssx_enc_call_ctx(xdr, &arg->call_ctx);
  599. if (err)
  600. goto done;
  601. /* arg->context_handle */
  602. if (arg->context_handle)
  603. err = gssx_enc_ctx(xdr, arg->context_handle);
  604. else
  605. err = gssx_enc_bool(xdr, 0);
  606. if (err)
  607. goto done;
  608. /* arg->cred_handle */
  609. if (arg->cred_handle)
  610. err = gssx_enc_cred(xdr, arg->cred_handle);
  611. else
  612. err = gssx_enc_bool(xdr, 0);
  613. if (err)
  614. goto done;
  615. /* arg->input_token */
  616. err = gssx_enc_in_token(xdr, &arg->input_token);
  617. if (err)
  618. goto done;
  619. /* arg->input_cb */
  620. if (arg->input_cb)
  621. err = gssx_enc_cb(xdr, arg->input_cb);
  622. else
  623. err = gssx_enc_bool(xdr, 0);
  624. if (err)
  625. goto done;
  626. err = gssx_enc_bool(xdr, arg->ret_deleg_cred);
  627. if (err)
  628. goto done;
  629. /* leave options empty for now, will add once we have any options
  630. * to pass up at all */
  631. /* arg->options */
  632. err = dummy_enc_opt_array(xdr, &arg->options);
  633. xdr_inline_pages(&req->rq_rcv_buf,
  634. PAGE_SIZE/2 /* pretty arbitrary */,
  635. arg->pages, 0 /* page base */, arg->npages * PAGE_SIZE);
  636. done:
  637. if (err)
  638. dprintk("RPC: gssx_enc_accept_sec_context: %d\n", err);
  639. }
  640. int gssx_dec_accept_sec_context(struct rpc_rqst *rqstp,
  641. struct xdr_stream *xdr,
  642. struct gssx_res_accept_sec_context *res)
  643. {
  644. u32 value_follows;
  645. int err;
  646. struct page *scratch;
  647. scratch = alloc_page(GFP_KERNEL);
  648. if (!scratch)
  649. return -ENOMEM;
  650. xdr_set_scratch_buffer(xdr, page_address(scratch), PAGE_SIZE);
  651. /* res->status */
  652. err = gssx_dec_status(xdr, &res->status);
  653. if (err)
  654. goto out_free;
  655. /* res->context_handle */
  656. err = gssx_dec_bool(xdr, &value_follows);
  657. if (err)
  658. goto out_free;
  659. if (value_follows) {
  660. err = gssx_dec_ctx(xdr, res->context_handle);
  661. if (err)
  662. goto out_free;
  663. } else {
  664. res->context_handle = NULL;
  665. }
  666. /* res->output_token */
  667. err = gssx_dec_bool(xdr, &value_follows);
  668. if (err)
  669. goto out_free;
  670. if (value_follows) {
  671. err = gssx_dec_buffer(xdr, res->output_token);
  672. if (err)
  673. goto out_free;
  674. } else {
  675. res->output_token = NULL;
  676. }
  677. /* res->delegated_cred_handle */
  678. err = gssx_dec_bool(xdr, &value_follows);
  679. if (err)
  680. goto out_free;
  681. if (value_follows) {
  682. /* we do not support upcall servers sending this data. */
  683. err = -EINVAL;
  684. goto out_free;
  685. }
  686. /* res->options */
  687. err = gssx_dec_option_array(xdr, &res->options);
  688. out_free:
  689. __free_page(scratch);
  690. return err;
  691. }