Fixed regressions and new bugs in importing
[moonshot-ui.git] / src / moonshot-server.vala
index 54a5bff..ea3bd0c 100644 (file)
@@ -29,6 +29,9 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
 */
+
+using Gee;
+
 #if IPC_DBUS
 
 [DBus (name = "org.janet.Moonshot")]
@@ -200,9 +203,20 @@ public class MoonshotServer : Object {
         idcard.update_services(services);
         var ta = new TrustAnchor(ca_cert, server_cert, subject, subject_alt, false);
 
+        if (!ta.is_empty()) {
+            // We have to set the datetime_added here, because it isn't delivered via IPC.
+            string ta_datetime_added = TrustAnchor.format_datetime_now();
+            ta.set_datetime_added(ta_datetime_added);
+            logger.trace("install_id_card : Set ta_datetime_added for '%s' to '%s'; ca_cert='%s'; server_cert='%s'".printf(idcard.display_name, ta.datetime_added, ta.ca_cert, ta.server_cert));
+        }
+        idcard.set_trust_anchor_from_store(ta);
+
         logger.trace("install_id_card: Card '%s' has services: '%s'"
                      .printf(idcard.display_name, idcard.get_services_string("; ")));
 
+        logger.trace(@"Installing IdCard named '$(idcard.display_name)'; ca_cert='$(idcard.trust_anchor.ca_cert)'; server_cert='$(idcard.trust_anchor.server_cert)'");
+
+
         if (rules_patterns.length == rules_always_confirm.length)
         {
             /* workaround Centos vala array property bug: use temp array */
@@ -216,7 +230,17 @@ public class MoonshotServer : Object {
             idcard.rules = rules;
         }
 
-        return parent_app.add_identity(idcard, force_flat_file_store!=0);
+        ArrayList<IdCard>? old_duplicates = null;
+        var ret = parent_app.add_identity(idcard, (force_flat_file_store != 0), out old_duplicates);
+
+        if (old_duplicates != null) {
+            // Printing to stdout here is ugly behavior; but it's old behavior that
+            // may be expected. (TODO: Do we need to keep this?)
+            foreach (IdCard id_card in old_duplicates) {
+                stdout.printf("removed duplicate id for '%s'\n", id_card.nai);
+            }
+        }
+        return ret;
     }
 
 
@@ -493,10 +517,14 @@ public class MoonshotServer : Object {
 
         mutex.lock();
 
+        ArrayList<IdCard>? old_duplicates = null;
         // Defer addition to the main loop thread.
         Idle.add(() => {
                 mutex.lock();
-                success = parent_app.add_identity(idcard, force_flat_file_store);
+                success = parent_app.add_identity(idcard, force_flat_file_store, out old_duplicates);
+                foreach (IdCard id_card in old_duplicates) {
+                    stdout.printf("removing duplicate id for '%s'\n", new_card.nai);
+                }
                 cond.signal();
                 mutex.unlock();
                 return false;