/crypto/external/bsd/heimdal/dist/lib/kadm5/init_s.c

http://www.minix3.org/ · C · 250 lines · 196 code · 21 blank · 33 comment · 17 complexity · 2c66edb8323ae469b66e8bb9d39c25b4 MD5 · raw file

  1. /* $NetBSD: init_s.c,v 1.1.1.2 2014/04/24 12:45:48 pettai Exp $ */
  2. /*
  3. * Copyright (c) 1997 - 2000 Kungliga Tekniska Hรถgskolan
  4. * (Royal Institute of Technology, Stockholm, Sweden).
  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. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. *
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in the
  16. * documentation and/or other materials provided with the distribution.
  17. *
  18. * 3. Neither the name of the Institute nor the names of its contributors
  19. * may be used to endorse or promote products derived from this software
  20. * without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
  23. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
  26. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  27. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  28. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  29. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  30. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  31. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  32. * SUCH DAMAGE.
  33. */
  34. #include "kadm5_locl.h"
  35. __RCSID("NetBSD");
  36. static kadm5_ret_t
  37. kadm5_s_init_with_context(krb5_context context,
  38. const char *client_name,
  39. const char *service_name,
  40. kadm5_config_params *realm_params,
  41. unsigned long struct_version,
  42. unsigned long api_version,
  43. void **server_handle)
  44. {
  45. kadm5_ret_t ret;
  46. kadm5_server_context *ctx;
  47. ret = _kadm5_s_init_context(&ctx, realm_params, context);
  48. if(ret)
  49. return ret;
  50. assert(ctx->config.dbname != NULL);
  51. assert(ctx->config.stash_file != NULL);
  52. assert(ctx->config.acl_file != NULL);
  53. assert(ctx->log_context.log_file != NULL);
  54. #ifndef NO_UNIX_SOCKETS
  55. assert(ctx->log_context.socket_name.sun_path[0] != '\0');
  56. #else
  57. assert(ctx->log_context.socket_info != NULL);
  58. #endif
  59. ret = hdb_create(ctx->context, &ctx->db, ctx->config.dbname);
  60. if(ret)
  61. return ret;
  62. ret = hdb_set_master_keyfile (ctx->context,
  63. ctx->db, ctx->config.stash_file);
  64. if(ret)
  65. return ret;
  66. ctx->log_context.log_fd = -1;
  67. #ifndef NO_UNIX_SOCKETS
  68. ctx->log_context.socket_fd = socket (AF_UNIX, SOCK_DGRAM, 0);
  69. #else
  70. ctx->log_context.socket_fd = socket (ctx->log_context.socket_info->ai_family,
  71. ctx->log_context.socket_info->ai_socktype,
  72. ctx->log_context.socket_info->ai_protocol);
  73. #endif
  74. ret = krb5_parse_name(ctx->context, client_name, &ctx->caller);
  75. if(ret)
  76. return ret;
  77. ret = _kadm5_acl_init(ctx);
  78. if(ret)
  79. return ret;
  80. *server_handle = ctx;
  81. return 0;
  82. }
  83. kadm5_ret_t
  84. kadm5_s_init_with_password_ctx(krb5_context context,
  85. const char *client_name,
  86. const char *password,
  87. const char *service_name,
  88. kadm5_config_params *realm_params,
  89. unsigned long struct_version,
  90. unsigned long api_version,
  91. void **server_handle)
  92. {
  93. return kadm5_s_init_with_context(context,
  94. client_name,
  95. service_name,
  96. realm_params,
  97. struct_version,
  98. api_version,
  99. server_handle);
  100. }
  101. kadm5_ret_t
  102. kadm5_s_init_with_password(const char *client_name,
  103. const char *password,
  104. const char *service_name,
  105. kadm5_config_params *realm_params,
  106. unsigned long struct_version,
  107. unsigned long api_version,
  108. void **server_handle)
  109. {
  110. krb5_context context;
  111. kadm5_ret_t ret;
  112. kadm5_server_context *ctx;
  113. ret = krb5_init_context(&context);
  114. if (ret)
  115. return ret;
  116. ret = kadm5_s_init_with_password_ctx(context,
  117. client_name,
  118. password,
  119. service_name,
  120. realm_params,
  121. struct_version,
  122. api_version,
  123. server_handle);
  124. if(ret){
  125. krb5_free_context(context);
  126. return ret;
  127. }
  128. ctx = *server_handle;
  129. ctx->my_context = 1;
  130. return 0;
  131. }
  132. kadm5_ret_t
  133. kadm5_s_init_with_skey_ctx(krb5_context context,
  134. const char *client_name,
  135. const char *keytab,
  136. const char *service_name,
  137. kadm5_config_params *realm_params,
  138. unsigned long struct_version,
  139. unsigned long api_version,
  140. void **server_handle)
  141. {
  142. return kadm5_s_init_with_context(context,
  143. client_name,
  144. service_name,
  145. realm_params,
  146. struct_version,
  147. api_version,
  148. server_handle);
  149. }
  150. kadm5_ret_t
  151. kadm5_s_init_with_skey(const char *client_name,
  152. const char *keytab,
  153. const char *service_name,
  154. kadm5_config_params *realm_params,
  155. unsigned long struct_version,
  156. unsigned long api_version,
  157. void **server_handle)
  158. {
  159. krb5_context context;
  160. kadm5_ret_t ret;
  161. kadm5_server_context *ctx;
  162. ret = krb5_init_context(&context);
  163. if (ret)
  164. return ret;
  165. ret = kadm5_s_init_with_skey_ctx(context,
  166. client_name,
  167. keytab,
  168. service_name,
  169. realm_params,
  170. struct_version,
  171. api_version,
  172. server_handle);
  173. if(ret){
  174. krb5_free_context(context);
  175. return ret;
  176. }
  177. ctx = *server_handle;
  178. ctx->my_context = 1;
  179. return 0;
  180. }
  181. kadm5_ret_t
  182. kadm5_s_init_with_creds_ctx(krb5_context context,
  183. const char *client_name,
  184. krb5_ccache ccache,
  185. const char *service_name,
  186. kadm5_config_params *realm_params,
  187. unsigned long struct_version,
  188. unsigned long api_version,
  189. void **server_handle)
  190. {
  191. return kadm5_s_init_with_context(context,
  192. client_name,
  193. service_name,
  194. realm_params,
  195. struct_version,
  196. api_version,
  197. server_handle);
  198. }
  199. kadm5_ret_t
  200. kadm5_s_init_with_creds(const char *client_name,
  201. krb5_ccache ccache,
  202. const char *service_name,
  203. kadm5_config_params *realm_params,
  204. unsigned long struct_version,
  205. unsigned long api_version,
  206. void **server_handle)
  207. {
  208. krb5_context context;
  209. kadm5_ret_t ret;
  210. kadm5_server_context *ctx;
  211. ret = krb5_init_context(&context);
  212. if (ret)
  213. return ret;
  214. ret = kadm5_s_init_with_creds_ctx(context,
  215. client_name,
  216. ccache,
  217. service_name,
  218. realm_params,
  219. struct_version,
  220. api_version,
  221. server_handle);
  222. if(ret){
  223. krb5_free_context(context);
  224. return ret;
  225. }
  226. ctx = *server_handle;
  227. ctx->my_context = 1;
  228. return 0;
  229. }