PageRenderTime 49ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://www.minix3.org/
C | 192 lines | 113 code | 27 blank | 52 comment | 27 complexity | 5f0eb30ca71c7c5e37af61f095713324 MD5 | raw file
Possible License(s): MIT, WTFPL, AGPL-1.0, BSD-3-Clause, GPL-3.0, LGPL-2.0, JSON, 0BSD
  1. /* $NetBSD: context_s.c,v 1.1.1.2 2014/04/24 12:45:48 pettai Exp $ */
  2. /*
  3. * Copyright (c) 1997 - 2002 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 void
  37. set_funcs(kadm5_server_context *c)
  38. {
  39. #define SET(C, F) (C)->funcs.F = kadm5_s_ ## F
  40. SET(c, chpass_principal);
  41. SET(c, chpass_principal_with_key);
  42. SET(c, create_principal);
  43. SET(c, delete_principal);
  44. SET(c, destroy);
  45. SET(c, flush);
  46. SET(c, get_principal);
  47. SET(c, get_principals);
  48. SET(c, get_privs);
  49. SET(c, modify_principal);
  50. SET(c, randkey_principal);
  51. SET(c, rename_principal);
  52. }
  53. #ifndef NO_UNIX_SOCKETS
  54. static void
  55. set_socket_name(krb5_context context, struct sockaddr_un *un)
  56. {
  57. const char *fn = kadm5_log_signal_socket(context);
  58. memset(un, 0, sizeof(*un));
  59. un->sun_family = AF_UNIX;
  60. strlcpy (un->sun_path, fn, sizeof(un->sun_path));
  61. }
  62. #else
  63. static void
  64. set_socket_info(krb5_context context, struct addrinfo **info)
  65. {
  66. kadm5_log_signal_socket_info(context, 0, info);
  67. }
  68. #endif
  69. static kadm5_ret_t
  70. find_db_spec(kadm5_server_context *ctx)
  71. {
  72. krb5_context context = ctx->context;
  73. struct hdb_dbinfo *info, *d;
  74. krb5_error_code ret;
  75. if (ctx->config.realm) {
  76. /* fetch the databases */
  77. ret = hdb_get_dbinfo(context, &info);
  78. if (ret)
  79. return ret;
  80. d = NULL;
  81. while ((d = hdb_dbinfo_get_next(info, d)) != NULL) {
  82. const char *p = hdb_dbinfo_get_realm(context, d);
  83. /* match default (realm-less) */
  84. if(p != NULL && strcmp(ctx->config.realm, p) != 0)
  85. continue;
  86. p = hdb_dbinfo_get_dbname(context, d);
  87. if (p)
  88. ctx->config.dbname = strdup(p);
  89. p = hdb_dbinfo_get_acl_file(context, d);
  90. if (p)
  91. ctx->config.acl_file = strdup(p);
  92. p = hdb_dbinfo_get_mkey_file(context, d);
  93. if (p)
  94. ctx->config.stash_file = strdup(p);
  95. p = hdb_dbinfo_get_log_file(context, d);
  96. if (p)
  97. ctx->log_context.log_file = strdup(p);
  98. break;
  99. }
  100. hdb_free_dbinfo(context, &info);
  101. }
  102. /* If any of the values was unset, pick up the default value */
  103. if (ctx->config.dbname == NULL)
  104. ctx->config.dbname = strdup(hdb_default_db(context));
  105. if (ctx->config.acl_file == NULL)
  106. asprintf(&ctx->config.acl_file, "%s/kadmind.acl", hdb_db_dir(context));
  107. if (ctx->config.stash_file == NULL)
  108. asprintf(&ctx->config.stash_file, "%s/m-key", hdb_db_dir(context));
  109. if (ctx->log_context.log_file == NULL)
  110. asprintf(&ctx->log_context.log_file, "%s/log", hdb_db_dir(context));
  111. #ifndef NO_UNIX_SOCKETS
  112. set_socket_name(context, &ctx->log_context.socket_name);
  113. #else
  114. set_socket_info(context, &ctx->log_context.socket_info);
  115. #endif
  116. return 0;
  117. }
  118. kadm5_ret_t
  119. _kadm5_s_init_context(kadm5_server_context **ctx,
  120. kadm5_config_params *params,
  121. krb5_context context)
  122. {
  123. *ctx = malloc(sizeof(**ctx));
  124. if(*ctx == NULL)
  125. return ENOMEM;
  126. memset(*ctx, 0, sizeof(**ctx));
  127. set_funcs(*ctx);
  128. (*ctx)->context = context;
  129. krb5_add_et_list (context, initialize_kadm5_error_table_r);
  130. #define is_set(M) (params && params->mask & KADM5_CONFIG_ ## M)
  131. if(is_set(REALM))
  132. (*ctx)->config.realm = strdup(params->realm);
  133. else
  134. krb5_get_default_realm(context, &(*ctx)->config.realm);
  135. if(is_set(DBNAME))
  136. (*ctx)->config.dbname = strdup(params->dbname);
  137. if(is_set(ACL_FILE))
  138. (*ctx)->config.acl_file = strdup(params->acl_file);
  139. if(is_set(STASH_FILE))
  140. (*ctx)->config.stash_file = strdup(params->stash_file);
  141. find_db_spec(*ctx);
  142. /* PROFILE can't be specified for now */
  143. /* KADMIND_PORT is supposed to be used on the server also,
  144. but this doesn't make sense */
  145. /* ADMIN_SERVER is client only */
  146. /* ADNAME is not used at all (as far as I can tell) */
  147. /* ADB_LOCKFILE ditto */
  148. /* DICT_FILE */
  149. /* ADMIN_KEYTAB */
  150. /* MKEY_FROM_KEYBOARD is not supported */
  151. /* MKEY_NAME neither */
  152. /* ENCTYPE */
  153. /* MAX_LIFE */
  154. /* MAX_RLIFE */
  155. /* EXPIRATION */
  156. /* FLAGS */
  157. /* ENCTYPES */
  158. return 0;
  159. }
  160. HDB *
  161. _kadm5_s_get_db(void *server_handle)
  162. {
  163. kadm5_server_context *context = server_handle;
  164. return context->db;
  165. }