/include/rpc/rpcsec_gss.h

https://bitbucket.org/freebsd/freebsd-head/ · C++ Header · 179 lines · 94 code · 20 blank · 65 comment · 0 complexity · da692011f2ab8f783ca6ff40b4262c72 MD5 · raw file

  1. /*-
  2. * Copyright (c) 2008 Doug Rabson
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. *
  14. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  15. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  16. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  17. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  18. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  19. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  20. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  21. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  22. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  23. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  24. * SUCH DAMAGE.
  25. *
  26. * $FreeBSD$
  27. */
  28. #ifndef _RPCSEC_GSS_H
  29. #define _RPCSEC_GSS_H
  30. #include <gssapi/gssapi.h>
  31. #ifndef MAX_GSS_MECH
  32. #define MAX_GSS_MECH 64
  33. #endif
  34. /*
  35. * Define the types of security service required for rpc_gss_seccreate().
  36. */
  37. typedef enum {
  38. rpc_gss_svc_default = 0,
  39. rpc_gss_svc_none = 1,
  40. rpc_gss_svc_integrity = 2,
  41. rpc_gss_svc_privacy = 3
  42. } rpc_gss_service_t;
  43. /*
  44. * Structure containing options for rpc_gss_seccreate().
  45. */
  46. typedef struct {
  47. int req_flags; /* GSS request bits */
  48. int time_req; /* requested credential lifetime */
  49. gss_cred_id_t my_cred; /* GSS credential */
  50. gss_channel_bindings_t input_channel_bindings;
  51. } rpc_gss_options_req_t;
  52. /*
  53. * Structure containing options returned by rpc_gss_seccreate().
  54. */
  55. typedef struct {
  56. int major_status;
  57. int minor_status;
  58. u_int rpcsec_version;
  59. int ret_flags;
  60. int time_req;
  61. gss_ctx_id_t gss_context;
  62. char actual_mechanism[MAX_GSS_MECH];
  63. } rpc_gss_options_ret_t;
  64. /*
  65. * Client principal type. Used as an argument to
  66. * rpc_gss_get_principal_name(). Also referenced by the
  67. * rpc_gss_rawcred_t structure.
  68. */
  69. typedef struct {
  70. int len;
  71. char name[1];
  72. } *rpc_gss_principal_t;
  73. /*
  74. * Structure for raw credentials used by rpc_gss_getcred() and
  75. * rpc_gss_set_callback().
  76. */
  77. typedef struct {
  78. u_int version; /* RPC version number */
  79. const char *mechanism; /* security mechanism */
  80. const char *qop; /* quality of protection */
  81. rpc_gss_principal_t client_principal; /* client name */
  82. const char *svc_principal; /* server name */
  83. rpc_gss_service_t service; /* service type */
  84. } rpc_gss_rawcred_t;
  85. /*
  86. * Unix credentials derived from raw credentials. Returned by
  87. * rpc_gss_getcred().
  88. */
  89. typedef struct {
  90. uid_t uid; /* user ID */
  91. gid_t gid; /* group ID */
  92. short gidlen;
  93. gid_t *gidlist; /* list of groups */
  94. } rpc_gss_ucred_t;
  95. /*
  96. * Structure used to enforce a particular QOP and service.
  97. */
  98. typedef struct {
  99. bool_t locked;
  100. rpc_gss_rawcred_t *raw_cred;
  101. } rpc_gss_lock_t;
  102. /*
  103. * Callback structure used by rpc_gss_set_callback().
  104. */
  105. typedef struct {
  106. u_int program; /* RPC program number */
  107. u_int version; /* RPC version number */
  108. /* user defined callback */
  109. bool_t (*callback)(struct svc_req *req,
  110. gss_cred_id_t deleg,
  111. gss_ctx_id_t gss_context,
  112. rpc_gss_lock_t *lock,
  113. void **cookie);
  114. } rpc_gss_callback_t;
  115. /*
  116. * Structure used to return error information by rpc_gss_get_error()
  117. */
  118. typedef struct {
  119. int rpc_gss_error;
  120. int system_error; /* same as errno */
  121. } rpc_gss_error_t;
  122. /*
  123. * Values for rpc_gss_error
  124. */
  125. #define RPC_GSS_ER_SUCCESS 0 /* no error */
  126. #define RPC_GSS_ER_SYSTEMERROR 1 /* system error */
  127. __BEGIN_DECLS
  128. AUTH *rpc_gss_seccreate(CLIENT *clnt, const char *principal,
  129. const char *mechanism, rpc_gss_service_t service, const char *qop,
  130. rpc_gss_options_req_t *options_req, rpc_gss_options_ret_t *options_ret);
  131. bool_t rpc_gss_set_defaults(AUTH *auth, rpc_gss_service_t service,
  132. const char *qop);
  133. int rpc_gss_max_data_length(AUTH *handle, int max_tp_unit_len);
  134. void rpc_gss_get_error(rpc_gss_error_t *error);
  135. bool_t rpc_gss_mech_to_oid(const char *mech, gss_OID *oid_ret);
  136. bool_t rpc_gss_oid_to_mech(gss_OID oid, const char **mech_ret);
  137. bool_t rpc_gss_qop_to_num(const char *qop, const char *mech, u_int *num_ret);
  138. const char **rpc_gss_get_mechanisms(void);
  139. const char **rpc_gss_get_mech_info(const char *mech, rpc_gss_service_t *service);
  140. bool_t rpc_gss_get_versions(u_int *vers_hi, u_int *vers_lo);
  141. bool_t rpc_gss_is_installed(const char *mech);
  142. bool_t rpc_gss_set_svc_name(const char *principal, const char *mechanism,
  143. u_int req_time, u_int program, u_int version);
  144. bool_t rpc_gss_getcred(struct svc_req *req, rpc_gss_rawcred_t **rcred,
  145. rpc_gss_ucred_t **ucred, void **cookie);
  146. bool_t rpc_gss_set_callback(rpc_gss_callback_t *cb);
  147. bool_t rpc_gss_get_principal_name(rpc_gss_principal_t *principal,
  148. const char *mech, const char *name, const char *node, const char *domain);
  149. int rpc_gss_svc_max_data_length(struct svc_req *req, int max_tp_unit_len);
  150. /*
  151. * Internal interface from the RPC implementation.
  152. */
  153. bool_t __rpc_gss_wrap(AUTH *auth, void *header, size_t headerlen,
  154. XDR* xdrs, xdrproc_t xdr_args, void *args_ptr);
  155. bool_t __rpc_gss_unwrap(AUTH *auth, XDR* xdrs, xdrproc_t xdr_args,
  156. void *args_ptr);
  157. bool_t __rpc_gss_set_error(int rpc_gss_error, int system_error);
  158. __END_DECLS
  159. #endif /* !_RPCSEC_GSS_H */