|
|
@@ -53,6 +53,8 @@ static int shutting_down = 0;
|
|
|
#define TASK_TOMBSTONE_FIXUP_BACKEND "backend"
|
|
|
#define TASK_TOMBSTONE_FIXUP_SUFFIX "suffix"
|
|
|
#define TASK_TOMBSTONE_FIXUP_STRIPCSN "stripcsn"
|
|
|
+#define TASK_DES2AES "des2aes task"
|
|
|
+
|
|
|
|
|
|
#define LOG_BUFFER 256
|
|
|
/* if the cumul. log gets larger than this, it's truncated: */
|
|
|
@@ -83,8 +85,10 @@ static const char *fetch_attr(Slapi_Entry *e, const char *attrname,
|
|
|
const char *default_val);
|
|
|
static Slapi_Entry *get_internal_entry(Slapi_PBlock *pb, char *dn);
|
|
|
static void modify_internal_entry(char *dn, LDAPMod **mods);
|
|
|
-
|
|
|
static void fixup_tombstone_task_destructor(Slapi_Task *task);
|
|
|
+static void task_des2aes_thread(void *arg);
|
|
|
+static void des2aes_task_destructor(Slapi_Task *task);
|
|
|
+
|
|
|
|
|
|
/***********************************
|
|
|
* Public Functions
|
|
|
@@ -2425,6 +2429,345 @@ fixup_tombstone_task_destructor(Slapi_Task *task)
|
|
|
"fixup_tombstone_task_destructor <--\n" );
|
|
|
}
|
|
|
|
|
|
+/*
|
|
|
+ * des2aes Task
|
|
|
+ *
|
|
|
+ * Convert any DES passwords to AES
|
|
|
+ *
|
|
|
+ * dn: cn=convertPasswords, cn=des2aes,cn=tasks,cn=config
|
|
|
+ * objectclass: top
|
|
|
+ * objectclass: extensibleObject
|
|
|
+ * suffix: dc=example,dc=com (If empty all backends are checked)
|
|
|
+ * suffix: dc=other,dc=suffix
|
|
|
+ */
|
|
|
+struct task_des2aes_data
|
|
|
+{
|
|
|
+ char **suffixes;
|
|
|
+ Slapi_Task *task;
|
|
|
+};
|
|
|
+
|
|
|
+static int
|
|
|
+task_des2aes(Slapi_PBlock *pb, Slapi_Entry *e, Slapi_Entry *eAfter,
|
|
|
+ int *returncode, char *returntext, void *arg)
|
|
|
+{
|
|
|
+ struct task_des2aes_data *task_data = NULL;
|
|
|
+ PRThread *thread = NULL;
|
|
|
+ Slapi_Task *task = NULL;
|
|
|
+ char **suffix = NULL;
|
|
|
+ char **bases = NULL;
|
|
|
+ int rc = SLAPI_DSE_CALLBACK_OK;
|
|
|
+
|
|
|
+ /* Get the suffixes */
|
|
|
+ if((suffix = slapi_entry_attr_get_charray(e, "suffix"))){
|
|
|
+ int i;
|
|
|
+ for (i = 0; suffix && suffix[i]; i++){
|
|
|
+ /* Make sure "suffix" is NUL terminated string */
|
|
|
+ char *dn = slapi_create_dn_string("%s", suffix[i]);
|
|
|
+
|
|
|
+ if(dn){
|
|
|
+ if(slapi_dn_syntax_check(pb, dn, 1)){
|
|
|
+ /* invalid suffix name */
|
|
|
+ PR_snprintf(returntext, SLAPI_DSE_RETURNTEXT_SIZE,
|
|
|
+ "Invalid DN syntax (%s) specified for \"suffix\"\n",
|
|
|
+ suffix[i]);
|
|
|
+ *returncode = LDAP_INVALID_DN_SYNTAX;
|
|
|
+ slapi_ch_free_string(&dn);
|
|
|
+ rc = SLAPI_DSE_CALLBACK_ERROR;
|
|
|
+ goto error;
|
|
|
+ } else {
|
|
|
+ slapi_ch_array_add(&bases, dn);
|
|
|
+ }
|
|
|
+ } else{
|
|
|
+ PR_snprintf(returntext, SLAPI_DSE_RETURNTEXT_SIZE,
|
|
|
+ "Invalid DN (%s) specified for \"suffix\"\n", suffix[i]);
|
|
|
+ *returncode = LDAP_INVALID_DN_SYNTAX;
|
|
|
+ rc = SLAPI_DSE_CALLBACK_ERROR;
|
|
|
+ goto error;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /* Build the task data and fire off a thread to perform the conversion */
|
|
|
+ task = slapi_new_task(slapi_entry_get_ndn(e));
|
|
|
+
|
|
|
+ /* register our destructor for cleaning up our private data */
|
|
|
+ slapi_task_set_destructor_fn(task, des2aes_task_destructor);
|
|
|
+ task_data = (struct task_des2aes_data *)slapi_ch_calloc(1, sizeof(struct task_des2aes_data));
|
|
|
+ task_data->suffixes = bases;
|
|
|
+ task_data->task = task;
|
|
|
+
|
|
|
+ /* Start the conversion thread */
|
|
|
+ thread = PR_CreateThread(PR_USER_THREAD, task_des2aes_thread,
|
|
|
+ (void *)task_data, PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD,
|
|
|
+ PR_UNJOINABLE_THREAD, SLAPD_DEFAULT_THREAD_STACKSIZE);
|
|
|
+ if (thread == NULL) {
|
|
|
+ PR_snprintf(returntext, SLAPI_DSE_RETURNTEXT_SIZE,
|
|
|
+ "unable to create des2aes thread!\n");
|
|
|
+ slapi_log_error(SLAPI_LOG_FATAL, TASK_DES2AES,
|
|
|
+ "unable to create des2aes thread!\n");
|
|
|
+ *returncode = LDAP_OPERATIONS_ERROR;
|
|
|
+ slapi_task_finish(task, *returncode);
|
|
|
+ rc = SLAPI_DSE_CALLBACK_ERROR;
|
|
|
+ }
|
|
|
+
|
|
|
+error:
|
|
|
+ if (rc == SLAPI_DSE_CALLBACK_ERROR){
|
|
|
+ slapi_ch_array_free(bases);
|
|
|
+ slapi_ch_array_free(suffix);
|
|
|
+ slapi_ch_free((void **)&task_data);
|
|
|
+ }
|
|
|
+ return rc;
|
|
|
+}
|
|
|
+
|
|
|
+static void
|
|
|
+task_des2aes_thread(void *arg)
|
|
|
+{
|
|
|
+ struct task_des2aes_data *task_data = arg;
|
|
|
+ Slapi_PBlock *pb = NULL;
|
|
|
+ Slapi_Entry **entries = NULL;
|
|
|
+ Slapi_Task *task = task_data->task;
|
|
|
+ struct slapdplugin *plugin = NULL;
|
|
|
+ char **attrs = NULL;
|
|
|
+ char **backends = NULL;
|
|
|
+ char *val = NULL;
|
|
|
+ int converted_des_passwd = 0;
|
|
|
+ int result = -1;
|
|
|
+ int have_aes = 0;
|
|
|
+ int have_des = 0;
|
|
|
+ int i = 0, ii = 0, be_idx = 0;
|
|
|
+ int rc = 0;
|
|
|
+
|
|
|
+ /*
|
|
|
+ * Check that AES plugin is enabled, and grab all the unique
|
|
|
+ * password attributes.
|
|
|
+ */
|
|
|
+ for ( plugin = get_plugin_list(PLUGIN_LIST_REVER_PWD_STORAGE_SCHEME);
|
|
|
+ plugin != NULL;
|
|
|
+ plugin = plugin->plg_next )
|
|
|
+ {
|
|
|
+ char *plugin_arg = NULL;
|
|
|
+
|
|
|
+ if(plugin->plg_started && strcasecmp(plugin->plg_name, "AES") == 0){
|
|
|
+ /* We have the AES plugin, and its enabled */
|
|
|
+ have_aes = 1;
|
|
|
+ }
|
|
|
+ if(plugin->plg_started && strcasecmp(plugin->plg_name, "DES") == 0){
|
|
|
+ /* We have the DES plugin, and its enabled */
|
|
|
+ have_des = 1;
|
|
|
+ }
|
|
|
+ /* Gather all the unique password attributes from all the PBE plugins */
|
|
|
+ for ( i = 0, plugin_arg = plugin->plg_argv[i];
|
|
|
+ i < plugin->plg_argc;
|
|
|
+ plugin_arg = plugin->plg_argv[++i] )
|
|
|
+ {
|
|
|
+ if(charray_inlist(attrs, plugin_arg)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ charray_add(&attrs, slapi_ch_strdup(plugin_arg));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(have_aes && have_des){
|
|
|
+ if(task_data->suffixes == NULL){
|
|
|
+ /*
|
|
|
+ * Build a list of all the backend dn's
|
|
|
+ */
|
|
|
+ Slapi_Backend *be = NULL;
|
|
|
+ struct suffixlist *list;
|
|
|
+ char *cookie = NULL;
|
|
|
+
|
|
|
+ slapi_log_error(SLAPI_LOG_FATAL, TASK_DES2AES,
|
|
|
+ "Checking for DES passwords to convert to AES...\n");
|
|
|
+ slapi_task_log_notice(task,
|
|
|
+ "Checking for DES passwords to convert to AES...\n");
|
|
|
+
|
|
|
+ be = slapi_get_first_backend(&cookie);
|
|
|
+ while (be){
|
|
|
+ int suffix_idx = 0;
|
|
|
+ int count = slapi_counter_get_value(be->be_suffixcounter);
|
|
|
+
|
|
|
+ list = be->be_suffixlist;
|
|
|
+ for (suffix_idx = 0; list && suffix_idx < count; suffix_idx++) {
|
|
|
+ char *suffix = (char *)slapi_sdn_get_ndn(list->be_suffix);
|
|
|
+ if(charray_inlist(backends, suffix) || strlen(suffix) == 0){
|
|
|
+ list = list->next;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ charray_add(&backends, slapi_ch_strdup(suffix));
|
|
|
+ list = list->next;
|
|
|
+ }
|
|
|
+ be = slapi_get_next_backend (cookie);
|
|
|
+ }
|
|
|
+ slapi_ch_free ((void **)&cookie);
|
|
|
+ } else {
|
|
|
+ backends = task_data->suffixes;
|
|
|
+ }
|
|
|
+
|
|
|
+ /*
|
|
|
+ * Search for the password attributes
|
|
|
+ */
|
|
|
+ for (i = 0; attrs && attrs[i]; i++){
|
|
|
+ char *filter = PR_smprintf("%s=*", attrs[i]);
|
|
|
+ /*
|
|
|
+ * Loop over all the backends looking for the password attribute
|
|
|
+ */
|
|
|
+ for(be_idx = 0; backends && backends[be_idx]; be_idx++){
|
|
|
+ pb = slapi_pblock_new();
|
|
|
+ slapi_search_internal_set_pb(pb, backends[be_idx],
|
|
|
+ LDAP_SCOPE_SUBTREE, filter, NULL, 0, NULL, NULL,
|
|
|
+ (void *)plugin_get_default_component_id(),
|
|
|
+ SLAPI_OP_FLAG_IGNORE_UNINDEXED);
|
|
|
+ slapi_search_internal_pb(pb);
|
|
|
+ slapi_pblock_get(pb, SLAPI_PLUGIN_INTOP_RESULT, &result);
|
|
|
+ if (LDAP_SUCCESS != result) {
|
|
|
+ slapi_log_error(SLAPI_LOG_FATAL, "convert_pbe_des_to_aes: ",
|
|
|
+ "Failed to search for password attribute (%s) error (%d), skipping suffix (%s)\n",
|
|
|
+ attrs[i], result, backends[be_idx]);
|
|
|
+ slapi_task_log_notice(task,
|
|
|
+ "Failed to search for password attribute (%s) error (%d), skipping suffix (%s)\n",
|
|
|
+ attrs[i], result, backends[be_idx]);
|
|
|
+ slapi_free_search_results_internal(pb);
|
|
|
+ slapi_pblock_destroy(pb);
|
|
|
+ pb = NULL;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ slapi_pblock_get(pb, SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES, &entries);
|
|
|
+ for (ii = 0; entries && entries[ii]; ii++){
|
|
|
+ if((val = slapi_entry_attr_get_charptr(entries[ii], attrs[i]))){
|
|
|
+ if(strlen(val) >= 5 && strncmp(val,"{DES}", 5) == 0){
|
|
|
+ /*
|
|
|
+ * We have a DES encoded password, convert it AES
|
|
|
+ */
|
|
|
+ Slapi_PBlock *mod_pb = NULL;
|
|
|
+ Slapi_Value *sval = NULL;
|
|
|
+ LDAPMod mod_replace;
|
|
|
+ LDAPMod *mods[2];
|
|
|
+ char *replace_val[2];
|
|
|
+ char *passwd = NULL;
|
|
|
+
|
|
|
+ /* Decode the DES password */
|
|
|
+ if(pw_rever_decode(val, &passwd, attrs[i]) == -1){
|
|
|
+ slapi_log_error(SLAPI_LOG_FATAL, TASK_DES2AES,
|
|
|
+ "Failed to decode existing DES password for (%s)\n",
|
|
|
+ slapi_entry_get_dn(entries[ii]));
|
|
|
+ slapi_task_log_notice(task,
|
|
|
+ "Failed to decode existing DES password for (%s)\n",
|
|
|
+ slapi_entry_get_dn(entries[ii]));
|
|
|
+ rc = 1;
|
|
|
+ goto done;
|
|
|
+ }
|
|
|
+
|
|
|
+ /* Encode the password */
|
|
|
+ sval = slapi_value_new_string(passwd);
|
|
|
+ if(pw_rever_encode(&sval, attrs[i]) == -1){
|
|
|
+ slapi_log_error(SLAPI_LOG_FATAL, TASK_DES2AES,
|
|
|
+ "failed to encode AES password for (%s)\n",
|
|
|
+ slapi_entry_get_dn(entries[ii]));
|
|
|
+ slapi_task_log_notice(task,
|
|
|
+ "failed to encode AES password for (%s)\n",
|
|
|
+ slapi_entry_get_dn(entries[ii]));
|
|
|
+ slapi_ch_free_string(&passwd);
|
|
|
+ slapi_value_free(&sval);
|
|
|
+ rc = 1;
|
|
|
+ goto done;
|
|
|
+ }
|
|
|
+
|
|
|
+ /* Replace the attribute in the entry */
|
|
|
+ replace_val[0] = (char *)slapi_value_get_string(sval);
|
|
|
+ replace_val[1] = NULL;
|
|
|
+ mod_replace.mod_op = LDAP_MOD_REPLACE;
|
|
|
+ mod_replace.mod_type = attrs[i];
|
|
|
+ mod_replace.mod_values = replace_val;
|
|
|
+ mods[0] = &mod_replace;
|
|
|
+ mods[1] = 0;
|
|
|
+
|
|
|
+ mod_pb = slapi_pblock_new();
|
|
|
+ slapi_modify_internal_set_pb(mod_pb, slapi_entry_get_dn(entries[ii]),
|
|
|
+ mods, 0, 0, (void *)plugin_get_default_component_id(), 0);
|
|
|
+ slapi_modify_internal_pb(mod_pb);
|
|
|
+
|
|
|
+ slapi_pblock_get(pb, SLAPI_PLUGIN_INTOP_RESULT, &result);
|
|
|
+ if (LDAP_SUCCESS != result) {
|
|
|
+ slapi_log_error(SLAPI_LOG_FATAL, TASK_DES2AES,
|
|
|
+ "Failed to convert password for (%s) error (%d)\n",
|
|
|
+ slapi_entry_get_dn(entries[ii]), result);
|
|
|
+ slapi_task_log_notice(task,
|
|
|
+ "Failed to convert password for (%s) error (%d)\n",
|
|
|
+ slapi_entry_get_dn(entries[ii]), result);
|
|
|
+ rc = 1;
|
|
|
+ } else {
|
|
|
+ slapi_log_error(SLAPI_LOG_FATAL, TASK_DES2AES,
|
|
|
+ "Successfully converted password for (%s)\n",
|
|
|
+ slapi_entry_get_dn(entries[ii]));
|
|
|
+ slapi_task_log_notice(task,
|
|
|
+ "Successfully converted password for (%s)\n",
|
|
|
+ slapi_entry_get_dn(entries[ii]));
|
|
|
+ converted_des_passwd = 1;
|
|
|
+ }
|
|
|
+ slapi_ch_free_string(&passwd);
|
|
|
+ slapi_value_free(&sval);
|
|
|
+ slapi_pblock_destroy(mod_pb);
|
|
|
+ }
|
|
|
+ slapi_ch_free_string(&val);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ slapi_free_search_results_internal(pb);
|
|
|
+ slapi_pblock_destroy(pb);
|
|
|
+ pb = NULL;
|
|
|
+ }
|
|
|
+ slapi_ch_free_string(&filter);
|
|
|
+ }
|
|
|
+ if (!converted_des_passwd){
|
|
|
+ slapi_log_error(SLAPI_LOG_FATAL, TASK_DES2AES,
|
|
|
+ "No DES passwords found to convert.\n");
|
|
|
+ slapi_task_log_notice(task, "No DES passwords found to convert.\n");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ /* No AES/DES */
|
|
|
+ if (!have_des){
|
|
|
+ slapi_log_error(SLAPI_LOG_FATAL, TASK_DES2AES,
|
|
|
+ "DES plugin not enabled\n");
|
|
|
+ slapi_task_log_notice(task, "DES plugin not enabled\n");
|
|
|
+ }
|
|
|
+ if (!have_aes){
|
|
|
+ slapi_log_error(SLAPI_LOG_FATAL, TASK_DES2AES,
|
|
|
+ "AES plugin not enabled\n");
|
|
|
+ slapi_task_log_notice(task, "AES plugin not enabled\n");
|
|
|
+ }
|
|
|
+ slapi_log_error(SLAPI_LOG_FATAL, TASK_DES2AES,
|
|
|
+ "Unable to convert passwords\n");
|
|
|
+ slapi_task_log_notice(task, "Unable to convert passwords\n");
|
|
|
+ rc = 1;
|
|
|
+ }
|
|
|
+
|
|
|
+done:
|
|
|
+ charray_free(attrs);
|
|
|
+ charray_free(backends);
|
|
|
+ slapi_free_search_results_internal(pb);
|
|
|
+ slapi_pblock_destroy(pb);
|
|
|
+ slapi_task_finish(task, rc);
|
|
|
+}
|
|
|
+
|
|
|
+static void
|
|
|
+des2aes_task_destructor(Slapi_Task *task)
|
|
|
+{
|
|
|
+ slapi_log_error(SLAPI_LOG_TRACE, TASK_DES2AES,
|
|
|
+ "des2aes_task_destructor -->\n" );
|
|
|
+ if (task) {
|
|
|
+ struct task_des2aes_data *task_data = (struct task_des2aes_data *)slapi_task_get_data(task);
|
|
|
+ while (slapi_task_get_refcount(task) > 0) {
|
|
|
+ /* Yield to wait for the task to finish. */
|
|
|
+ DS_Sleep (PR_MillisecondsToInterval(100));
|
|
|
+ }
|
|
|
+ if (task_data) {
|
|
|
+ slapi_ch_array_free(task_data->suffixes);
|
|
|
+ slapi_ch_free((void **)&task_data);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ slapi_log_error(SLAPI_LOG_TRACE, TASK_DES2AES,
|
|
|
+ "des2aes_task_destructor <--\n" );
|
|
|
+}
|
|
|
+
|
|
|
/* cleanup old tasks that may still be in the DSE from a previous session
|
|
|
* (this can happen if the server crashes [no matter how unlikely we like
|
|
|
* to think that is].)
|
|
|
@@ -2506,6 +2849,7 @@ void task_init(void)
|
|
|
slapi_task_register_handler("upgradedb", task_upgradedb_add);
|
|
|
slapi_task_register_handler("sysconfig reload", task_sysconfig_reload_add);
|
|
|
slapi_task_register_handler("fixup tombstones", task_fixup_tombstones_add);
|
|
|
+ slapi_task_register_handler("des2aes", task_des2aes);
|
|
|
}
|
|
|
|
|
|
/* called when the server is shutting down -- abort all existing tasks */
|