static kim_error kim_ui_plugin_context_allocate (kim_ui_plugin_context *out_context) { kim_error err = KIM_NO_ERROR; kim_ui_plugin_context context = NULL; if (!err && !out_context) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { context = malloc (sizeof (*context)); if (!context) { err = KIM_OUT_OF_MEMORY_ERR; } } if (!err) { err = krb5_error (NULL, krb5_init_context (&context->kcontext)); } if (!err) { PLUGIN_DIR_INIT(&context->plugins); context->ftable = NULL; context->ftables = NULL; context->plugin_context = NULL; *out_context = context; context = NULL; } kim_ui_plugin_context_free (&context); return check_error (err); }
kim_error kim_ui_plugin_init (kim_ui_context *io_context) { kim_error err = KIM_NO_ERROR; kim_ui_plugin_context context = NULL; if (!err && !io_context) { err = check_error (KIM_NULL_PARAMETER_ERR); } if (!err) { err = kim_ui_plugin_context_allocate (&context); } if (!err) { PLUGIN_DIR_INIT(&context->plugins); err = krb5_error (context->kcontext, krb5int_open_plugin_dirs (kim_ui_plugin_dirs, kim_ui_plugin_files, &context->plugins, &context->kcontext->err)); } if (!err) { err = krb5_error (context->kcontext, krb5int_get_plugin_dir_data (&context->plugins, "kim_ui_0", &context->ftables, &context->kcontext->err)); } if (!err && context->ftables) { int i; for (i = 0; context->ftables[i]; i++) { struct kim_ui_plugin_ftable_v0 *ftable = context->ftables[i]; context->plugin_context = NULL; err = ftable->init (&context->plugin_context); if (!err) { context->ftable = ftable; break; /* use first plugin that initializes correctly */ } err = KIM_NO_ERROR; /* ignore failed plugins */ } } if (!err && !context->ftable) { err = check_error (KRB5_PLUGIN_NO_HANDLE); } if (!err) { io_context->tcontext = context; context = NULL; } kim_ui_plugin_context_free (&context); return check_error (err); }
krb5_error_code krb5_os_init_context(krb5_context ctx, krb5_boolean kdc) { krb5_os_context os_ctx; krb5_error_code retval = 0; #ifdef _WIN32 WORD wVersionRequested; WSADATA wsaData; #endif /* _WIN32 */ os_ctx = &ctx->os_context; os_ctx->magic = KV5M_OS_CONTEXT; os_ctx->time_offset = 0; os_ctx->usec_offset = 0; os_ctx->os_flags = 0; os_ctx->default_ccname = 0; ctx->vtbl = 0; PLUGIN_DIR_INIT(&ctx->libkrb5_plugins); PLUGIN_DIR_INIT(&ctx->preauth_plugins); ctx->preauth_context = NULL; retval = os_init_paths(ctx, kdc); /* * If there's an error in the profile, return an error. Just * ignoring the error is a Bad Thing (tm). */ if (!retval) { krb5_cc_set_default_name(ctx, NULL); #ifdef _WIN32 /* We initialize winsock to version 1.1 but * we do not care if we succeed or fail. */ wVersionRequested = 0x0101; WSAStartup (wVersionRequested, &wsaData); #endif /* _WIN32 */ } return retval; }
krb5_error_code load_authdata_plugins(krb5_context context) { struct errinfo err; void **authdata_plugins_ftables = NULL; struct krb5plugin_authdata_ftable_v0 *ftable = NULL; int module_count, i, k; init_proc server_init_proc = NULL; memset(&err, 0, sizeof(err)); /* Attempt to load all of the authdata plugins we can find. */ PLUGIN_DIR_INIT(&authdata_plugins); if (PLUGIN_DIR_OPEN(&authdata_plugins) == 0) { if (krb5int_open_plugin_dirs(objdirs, NULL, &authdata_plugins, &err) != 0) { return KRB5_PLUGIN_NO_HANDLE; } } /* Get the method tables provided by the loaded plugins. */ authdata_plugins_ftables = NULL; n_authdata_systems = 0; if (krb5int_get_plugin_dir_data(&authdata_plugins, "authdata_server_0", &authdata_plugins_ftables, &err) != 0) { return KRB5_PLUGIN_NO_HANDLE; } /* Count the valid modules. */ module_count = sizeof(static_authdata_systems) / sizeof(static_authdata_systems[0]); if (authdata_plugins_ftables != NULL) { for (i = 0; authdata_plugins_ftables[i] != NULL; i++) { ftable = authdata_plugins_ftables[i]; if ((ftable->authdata_proc != NULL)) { module_count++; } } } /* Build the complete list of supported authdata options, and * leave room for a terminator entry. */ authdata_systems = calloc((module_count + 1), sizeof(krb5_authdata_systems) ); if (authdata_systems == NULL) { krb5int_free_plugin_dir_data(authdata_plugins_ftables); return ENOMEM; } /* Add the locally-supplied mechanisms to the dynamic list first. */ for (i = 0, k = 0; i < sizeof(static_authdata_systems) / sizeof(static_authdata_systems[0]); i++) { if (static_authdata_systems[i].type == -1) break; authdata_systems[k] = static_authdata_systems[i]; /* Try to initialize the authdata system. If it fails, we'll remove it * from the list of systems we'll be using. */ server_init_proc = static_authdata_systems[i].init; if ((server_init_proc != NULL) && ((*server_init_proc)(context, NULL /* &plugin_context */) != 0)) { memset(&authdata_systems[k], 0, sizeof(authdata_systems[k])); continue; } k++; } /* Now add the dynamically-loaded mechanisms to the list. */ if (authdata_plugins_ftables != NULL) { for (i = 0; authdata_plugins_ftables[i] != NULL; i++) { ftable = authdata_plugins_ftables[i]; if ((ftable->authdata_proc == NULL)) { continue; } server_init_proc = ftable->init_proc; krb5_error_code initerr; if ((server_init_proc != NULL) && ((initerr = (*server_init_proc)(context, NULL /* &plugin_context */)) != 0)) { const char *emsg; emsg = krb5_get_error_message(context, initerr); if (emsg) { krb5_klog_syslog(LOG_ERR, "authdata %s failed to initialize: %s", ftable->name, emsg); krb5_free_error_message(context, emsg); } memset(&authdata_systems[k], 0, sizeof(authdata_systems[k])); continue; } authdata_systems[k].name = ftable->name; authdata_systems[k].init = server_init_proc; authdata_systems[k].fini = ftable->fini_proc; authdata_systems[k].handle_authdata = ftable->authdata_proc; k++; } } n_authdata_systems = k; /* Add the end-of-list marker. */ authdata_systems[k].name = "[end]"; authdata_systems[k].type = -1; return 0; }
/* Load both v0 and v2 authdata plugins */ krb5_error_code load_authdata_plugins(krb5_context context) { void **authdata_plugins_ftables_v0 = NULL; void **authdata_plugins_ftables_v2 = NULL; size_t module_count; size_t i, k; init_proc server_init_proc = NULL; krb5_error_code code; /* Attempt to load all of the authdata plugins we can find. */ PLUGIN_DIR_INIT(&authdata_plugins); if (PLUGIN_DIR_OPEN(&authdata_plugins) == 0) { if (krb5int_open_plugin_dirs(objdirs, NULL, &authdata_plugins, &context->err) != 0) { return KRB5_PLUGIN_NO_HANDLE; } } /* Get the method tables provided by the loaded plugins. */ authdata_plugins_ftables_v0 = NULL; authdata_plugins_ftables_v2 = NULL; n_authdata_systems = 0; if (krb5int_get_plugin_dir_data(&authdata_plugins, "authdata_server_2", &authdata_plugins_ftables_v2, &context->err) != 0 || krb5int_get_plugin_dir_data(&authdata_plugins, "authdata_server_0", &authdata_plugins_ftables_v0, &context->err) != 0) { code = KRB5_PLUGIN_NO_HANDLE; goto cleanup; } /* Count the valid modules. */ module_count = 0; if (authdata_plugins_ftables_v2 != NULL) { struct krb5plugin_authdata_server_ftable_v2 *ftable; for (i = 0; authdata_plugins_ftables_v2[i] != NULL; i++) { ftable = authdata_plugins_ftables_v2[i]; if (ftable->authdata_proc != NULL) module_count++; } } if (authdata_plugins_ftables_v0 != NULL) { struct krb5plugin_authdata_server_ftable_v0 *ftable; for (i = 0; authdata_plugins_ftables_v0[i] != NULL; i++) { ftable = authdata_plugins_ftables_v0[i]; if (ftable->authdata_proc != NULL) module_count++; } } module_count += sizeof(static_authdata_systems) / sizeof(static_authdata_systems[0]); /* Build the complete list of supported authdata options, and * leave room for a terminator entry. */ authdata_systems = calloc(module_count + 1, sizeof(krb5_authdata_systems)); if (authdata_systems == NULL) { code = ENOMEM; goto cleanup; } k = 0; /* * Special case to ensure that handle_request_authdata is * first in the list, to make unenc_authdata available to * plugins. */ for (i = 0; i < (sizeof(static_authdata_systems) / sizeof(static_authdata_systems[0])); i++) { if ((static_authdata_systems[i].flags & AUTHDATA_FLAG_PRE_PLUGIN) == 0) continue; assert(static_authdata_systems[i].init == NULL); authdata_systems[k++] = static_authdata_systems[i]; } /* Add dynamically loaded V2 plugins */ if (authdata_plugins_ftables_v2 != NULL) { struct krb5plugin_authdata_server_ftable_v2 *ftable; for (i = 0; authdata_plugins_ftables_v2[i] != NULL; i++) { krb5_error_code initerr; void *pctx = NULL; ftable = authdata_plugins_ftables_v2[i]; if (ftable->authdata_proc == NULL) { continue; } server_init_proc = ftable->init_proc; if ((server_init_proc != NULL) && ((initerr = (*server_init_proc)(context, &pctx)) != 0)) { const char *emsg; emsg = krb5_get_error_message(context, initerr); krb5_klog_syslog(LOG_ERR, _("authdata %s failed to initialize: %s"), ftable->name, emsg); krb5_free_error_message(context, emsg); memset(&authdata_systems[k], 0, sizeof(authdata_systems[k])); continue; } authdata_systems[k].name = ftable->name; authdata_systems[k].type = AUTHDATA_SYSTEM_V2; authdata_systems[k].init = server_init_proc; authdata_systems[k].fini = ftable->fini_proc; authdata_systems[k].handle_authdata.v2 = ftable->authdata_proc; authdata_systems[k].plugin_context = pctx; k++; } } /* Add dynamically loaded V0 plugins */ if (authdata_plugins_ftables_v0 != NULL) { struct krb5plugin_authdata_server_ftable_v0 *ftable; for (i = 0; authdata_plugins_ftables_v0[i] != NULL; i++) { krb5_error_code initerr; void *pctx = NULL; ftable = authdata_plugins_ftables_v0[i]; if (ftable->authdata_proc == NULL) { continue; } server_init_proc = ftable->init_proc; if ((server_init_proc != NULL) && ((initerr = (*server_init_proc)(context, &pctx)) != 0)) { const char *emsg; emsg = krb5_get_error_message(context, initerr); krb5_klog_syslog(LOG_ERR, _("authdata %s failed to initialize: %s"), ftable->name, emsg); krb5_free_error_message(context, emsg); memset(&authdata_systems[k], 0, sizeof(authdata_systems[k])); continue; } authdata_systems[k].name = ftable->name; authdata_systems[k].type = AUTHDATA_SYSTEM_V0; authdata_systems[k].init = server_init_proc; authdata_systems[k].fini = ftable->fini_proc; authdata_systems[k].handle_authdata.v0 = ftable->authdata_proc; authdata_systems[k].plugin_context = pctx; k++; } } for (i = 0; i < sizeof(static_authdata_systems) / sizeof(static_authdata_systems[0]); i++) { if (static_authdata_systems[i].flags & AUTHDATA_FLAG_PRE_PLUGIN) continue; assert(static_authdata_systems[i].init == NULL); authdata_systems[k++] = static_authdata_systems[i]; } n_authdata_systems = k; /* Add the end-of-list marker. */ authdata_systems[k].name = "[end]"; authdata_systems[k].type = AUTHDATA_SYSTEM_UNKNOWN; code = 0; cleanup: if (authdata_plugins_ftables_v2 != NULL) krb5int_free_plugin_dir_data(authdata_plugins_ftables_v2); if (authdata_plugins_ftables_v0 != NULL) krb5int_free_plugin_dir_data(authdata_plugins_ftables_v0); return code; }