auth_none.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. * Copyright (c) 2010, Oracle America, Inc.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are
  6. * met:
  7. *
  8. * * Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * * Redistributions in binary form must reproduce the above
  11. * copyright notice, this list of conditions and the following
  12. * disclaimer in the documentation and/or other materials
  13. * provided with the distribution.
  14. * * Neither the name of the "Oracle America, Inc." nor the names of its
  15. * contributors may be used to endorse or promote products derived
  16. * from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  21. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  22. * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  23. * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  24. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  25. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  26. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  27. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  28. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  29. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. */
  31. /*
  32. * auth_none.c
  33. * Creates a client authentication handle for passing "null"
  34. * credentials and verifiers to remote systems.
  35. */
  36. #include <rpc/rpc.h>
  37. #include <libc-lock.h>
  38. #include <shlib-compat.h>
  39. #define MAX_MARSHAL_SIZE 20
  40. /*
  41. * Authenticator operations routines
  42. */
  43. static void authnone_verf (AUTH *);
  44. static void authnone_destroy (AUTH *);
  45. static bool_t authnone_marshal (AUTH *, XDR *);
  46. static bool_t authnone_validate (AUTH *, struct opaque_auth *);
  47. static bool_t authnone_refresh (AUTH *);
  48. static const struct auth_ops ops = {
  49. authnone_verf,
  50. authnone_marshal,
  51. authnone_validate,
  52. authnone_refresh,
  53. authnone_destroy
  54. };
  55. /* Internal data and routines */
  56. struct authnone_private_s {
  57. AUTH no_client;
  58. char marshalled_client[MAX_MARSHAL_SIZE];
  59. u_int mcnt;
  60. };
  61. static struct authnone_private_s authnone_private;
  62. __libc_once_define(static, authnone_private_guard);
  63. static void authnone_create_once (void);
  64. static void
  65. authnone_create_once (void)
  66. {
  67. struct authnone_private_s *ap;
  68. XDR xdr_stream;
  69. XDR *xdrs;
  70. ap = &authnone_private;
  71. ap->no_client.ah_cred = ap->no_client.ah_verf = _null_auth;
  72. ap->no_client.ah_ops = (struct auth_ops *) &ops;
  73. xdrs = &xdr_stream;
  74. xdrmem_create (xdrs, ap->marshalled_client,
  75. (u_int) MAX_MARSHAL_SIZE, XDR_ENCODE);
  76. (void) xdr_opaque_auth (xdrs, &ap->no_client.ah_cred);
  77. (void) xdr_opaque_auth (xdrs, &ap->no_client.ah_verf);
  78. ap->mcnt = XDR_GETPOS (xdrs);
  79. XDR_DESTROY (xdrs);
  80. }
  81. AUTH *
  82. authnone_create (void)
  83. {
  84. __libc_once (authnone_private_guard, authnone_create_once);
  85. return &authnone_private.no_client;
  86. }
  87. libc_hidden_nolink_sunrpc (authnone_create, GLIBC_2_0)
  88. static bool_t
  89. authnone_marshal (AUTH *client, XDR *xdrs)
  90. {
  91. struct authnone_private_s *ap;
  92. /* authnone_create returned authnone_private->no_client, which is
  93. the first field of struct authnone_private_s. */
  94. ap = (struct authnone_private_s *) client;
  95. if (ap == NULL)
  96. return FALSE;
  97. return (*xdrs->x_ops->x_putbytes) (xdrs, ap->marshalled_client, ap->mcnt);
  98. }
  99. static void
  100. authnone_verf (AUTH *auth)
  101. {
  102. }
  103. static bool_t
  104. authnone_validate (AUTH *auth, struct opaque_auth *oa)
  105. {
  106. return TRUE;
  107. }
  108. static bool_t
  109. authnone_refresh (AUTH *auth)
  110. {
  111. return FALSE;
  112. }
  113. static void
  114. authnone_destroy (AUTH *auth)
  115. {
  116. }