rpcsec_gss_conf.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*-
  2. * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
  3. *
  4. * Copyright (c) 2008 Doug Rabson
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  17. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  18. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  19. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  20. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  21. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  22. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  23. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  24. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  25. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  26. * SUCH DAMAGE.
  27. */
  28. #include <sys/cdefs.h>
  29. __FBSDID("$FreeBSD$");
  30. #include <sys/param.h>
  31. #include <sys/systm.h>
  32. #include <sys/kobj.h>
  33. #include <sys/lock.h>
  34. #include <sys/malloc.h>
  35. #include <sys/mutex.h>
  36. #include <rpc/rpc.h>
  37. #include <rpc/rpcsec_gss.h>
  38. #include "rpcsec_gss_int.h"
  39. bool_t
  40. rpc_gss_mech_to_oid(const char *mech, gss_OID *oid_ret)
  41. {
  42. gss_OID oid = kgss_find_mech_by_name(mech);
  43. if (oid) {
  44. *oid_ret = oid;
  45. return (TRUE);
  46. }
  47. _rpc_gss_set_error(RPC_GSS_ER_SYSTEMERROR, ENOENT);
  48. return (FALSE);
  49. }
  50. bool_t
  51. rpc_gss_oid_to_mech(gss_OID oid, const char **mech_ret)
  52. {
  53. const char *name = kgss_find_mech_by_oid(oid);
  54. if (name) {
  55. *mech_ret = name;
  56. return (TRUE);
  57. }
  58. _rpc_gss_set_error(RPC_GSS_ER_SYSTEMERROR, ENOENT);
  59. return (FALSE);
  60. }
  61. bool_t
  62. rpc_gss_qop_to_num(const char *qop, const char *mech, u_int *num_ret)
  63. {
  64. if (!strcmp(qop, "default")) {
  65. *num_ret = GSS_C_QOP_DEFAULT;
  66. return (TRUE);
  67. }
  68. _rpc_gss_set_error(RPC_GSS_ER_SYSTEMERROR, ENOENT);
  69. return (FALSE);
  70. }
  71. const char *
  72. _rpc_gss_num_to_qop(const char *mech, u_int num)
  73. {
  74. if (num == GSS_C_QOP_DEFAULT)
  75. return "default";
  76. return (NULL);
  77. }
  78. const char **
  79. rpc_gss_get_mechanisms(void)
  80. {
  81. static const char **mech_names = NULL;
  82. struct kgss_mech *km;
  83. int count;
  84. if (mech_names)
  85. return (mech_names);
  86. count = 0;
  87. LIST_FOREACH(km, &kgss_mechs, km_link) {
  88. count++;
  89. }
  90. count++;
  91. mech_names = malloc(count * sizeof(const char *), M_RPC, M_WAITOK);
  92. count = 0;
  93. LIST_FOREACH(km, &kgss_mechs, km_link) {
  94. mech_names[count++] = km->km_mech_name;
  95. }
  96. mech_names[count++] = NULL;
  97. return (mech_names);
  98. }
  99. #if 0
  100. const char **
  101. rpc_gss_get_mech_info(const char *mech, rpc_gss_service_t *service)
  102. {
  103. struct mech_info *info;
  104. _rpc_gss_load_mech();
  105. _rpc_gss_load_qop();
  106. SLIST_FOREACH(info, &mechs, link) {
  107. if (!strcmp(mech, info->name)) {
  108. /*
  109. * I'm not sure what to do with service
  110. * here. The Solaris manpages are not clear on
  111. * the subject and the OpenSolaris code just
  112. * sets it to rpc_gss_svc_privacy
  113. * unconditionally with a comment noting that
  114. * it is bogus.
  115. */
  116. *service = rpc_gss_svc_privacy;
  117. return info->qops;
  118. }
  119. }
  120. _rpc_gss_set_error(RPC_GSS_ER_SYSTEMERROR, ENOENT);
  121. return (NULL);
  122. }
  123. #endif
  124. bool_t
  125. rpc_gss_get_versions(u_int *vers_hi, u_int *vers_lo)
  126. {
  127. *vers_hi = 1;
  128. *vers_lo = 1;
  129. return (TRUE);
  130. }
  131. bool_t
  132. rpc_gss_is_installed(const char *mech)
  133. {
  134. gss_OID oid = kgss_find_mech_by_name(mech);
  135. if (oid)
  136. return (TRUE);
  137. else
  138. return (FALSE);
  139. }