gss_rpc_xdr.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840
  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. /* 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. struct gssx_arg_accept_sec_context *arg)
  594. {
  595. int err;
  596. err = gssx_enc_call_ctx(xdr, &arg->call_ctx);
  597. if (err)
  598. goto done;
  599. /* arg->context_handle */
  600. if (arg->context_handle) {
  601. err = gssx_enc_ctx(xdr, arg->context_handle);
  602. if (err)
  603. goto done;
  604. } else {
  605. err = gssx_enc_bool(xdr, 0);
  606. }
  607. /* arg->cred_handle */
  608. if (arg->cred_handle) {
  609. err = gssx_enc_cred(xdr, arg->cred_handle);
  610. if (err)
  611. goto done;
  612. } else {
  613. err = gssx_enc_bool(xdr, 0);
  614. }
  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. if (err)
  623. goto done;
  624. } else {
  625. err = gssx_enc_bool(xdr, 0);
  626. }
  627. err = gssx_enc_bool(xdr, arg->ret_deleg_cred);
  628. if (err)
  629. goto done;
  630. /* leave options empty for now, will add once we have any options
  631. * to pass up at all */
  632. /* arg->options */
  633. err = dummy_enc_opt_array(xdr, &arg->options);
  634. xdr_inline_pages(&req->rq_rcv_buf,
  635. PAGE_SIZE/2 /* pretty arbitrary */,
  636. arg->pages, 0 /* page base */, arg->npages * PAGE_SIZE);
  637. done:
  638. if (err)
  639. dprintk("RPC: gssx_enc_accept_sec_context: %d\n", err);
  640. }
  641. int gssx_dec_accept_sec_context(struct rpc_rqst *rqstp,
  642. struct xdr_stream *xdr,
  643. struct gssx_res_accept_sec_context *res)
  644. {
  645. u32 value_follows;
  646. int err;
  647. /* res->status */
  648. err = gssx_dec_status(xdr, &res->status);
  649. if (err)
  650. return err;
  651. /* res->context_handle */
  652. err = gssx_dec_bool(xdr, &value_follows);
  653. if (err)
  654. return err;
  655. if (value_follows) {
  656. err = gssx_dec_ctx(xdr, res->context_handle);
  657. if (err)
  658. return err;
  659. } else {
  660. res->context_handle = NULL;
  661. }
  662. /* res->output_token */
  663. err = gssx_dec_bool(xdr, &value_follows);
  664. if (err)
  665. return err;
  666. if (value_follows) {
  667. err = gssx_dec_buffer(xdr, res->output_token);
  668. if (err)
  669. return err;
  670. } else {
  671. res->output_token = NULL;
  672. }
  673. /* res->delegated_cred_handle */
  674. err = gssx_dec_bool(xdr, &value_follows);
  675. if (err)
  676. return err;
  677. if (value_follows) {
  678. /* we do not support upcall servers sending this data. */
  679. return -EINVAL;
  680. }
  681. /* res->options */
  682. err = gssx_dec_option_array(xdr, &res->options);
  683. return err;
  684. }