gss_rpc_xdr.c 17 KB

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