auth_gss_internal.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // SPDX-License-Identifier: BSD-3-Clause
  2. /*
  3. * linux/net/sunrpc/auth_gss/auth_gss_internal.h
  4. *
  5. * Internal definitions for RPCSEC_GSS client authentication
  6. *
  7. * Copyright (c) 2000 The Regents of the University of Michigan.
  8. * All rights reserved.
  9. *
  10. */
  11. #include <linux/err.h>
  12. #include <linux/string.h>
  13. #include <linux/sunrpc/xdr.h>
  14. static inline const void *
  15. simple_get_bytes(const void *p, const void *end, void *res, size_t len)
  16. {
  17. const void *q = (const void *)((const char *)p + len);
  18. if (unlikely(q > end || q < p))
  19. return ERR_PTR(-EFAULT);
  20. memcpy(res, p, len);
  21. return q;
  22. }
  23. static inline const void *
  24. simple_get_netobj(const void *p, const void *end, struct xdr_netobj *dest)
  25. {
  26. const void *q;
  27. unsigned int len;
  28. p = simple_get_bytes(p, end, &len, sizeof(len));
  29. if (IS_ERR(p))
  30. return p;
  31. q = (const void *)((const char *)p + len);
  32. if (unlikely(q > end || q < p))
  33. return ERR_PTR(-EFAULT);
  34. if (len) {
  35. dest->data = kmemdup(p, len, GFP_NOFS);
  36. if (unlikely(dest->data == NULL))
  37. return ERR_PTR(-ENOMEM);
  38. } else
  39. dest->data = NULL;
  40. dest->len = len;
  41. return q;
  42. }