/System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/AE.framework/Versions/Current/Support/AEServer
 /System/Library/Frameworks/ApplicationServices.framework/Versions/Current/Frameworks/AE.framework/Versions/Current/Support/AEServer
 /System/Library/Frameworks/InstantMessage.framework/iChatAgent.app
+/System/Library/Frameworks/SecurityFoundation.framework/Resources/dotmacfx.app
 /System/Library/Frameworks/SecurityFoundation.framework/Resources/kcSync.app
 /System/Library/PreferencePanes/Mac.prefPane
+/System/Library/PreferencePanes/Mac.prefPane/Contents/Resources/dotMacPrefTool
 /System/Library/PrivateFrameworks/Admin.framework/Resources/writeconfig
 /System/Library/PrivateFrameworks/Admin.framework/Versions/A/Resources/writeconfig
 /System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport
 /System/Library/PrivateFrameworks/DMNotification.framework/Resources/dmnotifyd
 /System/Library/PrivateFrameworks/DMNotification.framework/Versions/A/Resources/dmnotifyd
 /System/Library/PrivateFrameworks/DMNotification.framework/Versions/Current/Resources/dmnotifyd
+/System/Library/PrivateFrameworks/Syndication.framework/Resources/SyndicationAgent.app/Contents/MacOS/SyndicationAgent
+/System/Library/PrivateFrameworks/Syndication.framework/Versions/A/Resources/SyndicationAgent.app/Contents/MacOS/SyndicationAgent
+/System/Library/PrivateFrameworks/Syndication.framework/Versions/Current/Resources/SyndicationAgent.app/Contents/MacOS/SyndicationAgent
 /System/Library/ScriptingAdditions/Keychain Scripting.app
 /sbin/mount_smbfs
 /sbin/mount_webdav
 
                        buildSettings = {
                                BUILD_VARIANTS = debug;
                                COPY_PHASE_STRIP = NO;
-                               CSSM_HEADERS = "$(BUILT_PRODUCTS_DIR)/Security.framework/Headers";
                                GCC_DYNAMIC_NO_PIC = NO;
                                GCC_ENABLE_FIX_AND_CONTINUE = YES;
                                GCC_GENERATE_DEBUGGING_SYMBOLS = YES;
                };
                4CA1FEAF052A3C5800F22E42 = {
                        buildSettings = {
-                               CSSM_HEADERS = "$(BUILT_PRODUCTS_DIR)/Security.framework/Headers";
                                DEAD_CODE_STRIPPING = YES;
                                GCC_DYNAMIC_NO_PIC = NO;
                                GCC_ENABLE_FIX_AND_CONTINUE = YES;
                        );
                        buildSettings = {
                                BUILD_VARIANTS = "normal debug";
-                               CURRENT_PROJECT_VERSION = 26692;
+                               CURRENT_PROJECT_VERSION = 27887;
                                FRAMEWORK_SEARCH_PATHS = "/usr/local/SecurityPieces/Frameworks /usr/local/SecurityPieces/Components/securityd $(SYSTEM_LIBRARY_DIR)/PrivateFrameworks";
                                INSTALL_PATH = /usr/sbin;
                                OPT_CPPXFLAGS = "$(OPT_CXFLAGS) -fno-enforce-eh-specs -fno-implement-inlines -fcoalesce-templates";
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                        shellPath = /bin/sh;
-                       shellScript = "THEADER=$BUILT_PRODUCTS_DIR/include/flip_gen.h\nTCPP=$BUILT_PRODUCTS_DIR/include/flip_gen.cpp\nmkdir -p $BUILT_PRODUCTS_DIR/include\nsrc/generate.pl src/generate.cf $THEADER.new $TCPP.new $CSSM_HEADERS/cssmtype.h\ncmp -s $THEADER.new $THEADER || mv $THEADER.new $THEADER\ncmp -s $TCPP.new $TCPP || mv $TCPP.new $TCPP\n";
+                       shellScript = "THEADER=$BUILT_PRODUCTS_DIR/include/flip_gen.h\nTCPP=$BUILT_PRODUCTS_DIR/include/flip_gen.cpp\nmkdir -p $BUILT_PRODUCTS_DIR/include\nsrc/generate.pl src/generate.cf $THEADER.new $TCPP.new cssmtype.h $CSSM_HEADERS\ncmp -s $THEADER.new $THEADER || mv $THEADER.new $THEADER\ncmp -s $TCPP.new $TCPP || mv $TCPP.new $TCPP\n";
                };
                4CDD4F7A053751FF00FEC36D = {
                        buildPhases = (
                                4CDD4F79053751FF00FEC36D,
                        );
                        buildSettings = {
-                               CSSM_HEADERS = "$(SYSTEM_LIBRARY_DIR)/Frameworks/Security.framework/Headers";
+                               CSSM_HEADERS = "$(BUILT_PRODUCTS_DIR)/Security.framework/Headers:$(SYSTEM_LIBRARY_DIR)/Frameworks/Security.framework/Headers";
                                OTHER_CFLAGS = "";
                                OTHER_LDFLAGS = "";
                                OTHER_REZFLAGS = "";
 
        virtual ~SecurityServerAcl();
 
     // validation calls restated
-       void validate(AclAuthorization auth, const AccessCredentials *cred, Database *relatedDatabase);
+   virtual void validate(AclAuthorization auth, const AccessCredentials *cred, Database *relatedDatabase);
        void validate(AclAuthorization auth, const Context &context, Database *relatedDatabase);
 
        // CSSM layer ACL calls
 
 class EntropyManager : public MachServer::Timer, private DevRandomGenerator {
     // all the parameters you ever (should) want to change :-)
     static const int collectInterval = 600; // collect every 10 minutes
-    static const int updateInterval = 3600; // update file every hour
+    static const int updateInterval = 3600 * 6; // update file every 6 hours
     static const int timingsToCollect = 40; // how many timings?
 
 public:
 
 #
 #
 #
-use strict;
+#use strict;
 
 my $disclaimer = "Automatically generated - do not edit on penalty of futility!";
 
 
 # arguments
-my ($configfile, $out_h, $out_cpp, $types) = @ARGV;
+my ($configfile, $out_h, $out_cpp, $types, $hdrpath) = @ARGV;
 
 
 # open configuration file
 open(CFG, "$configfile") || die "$configfile: $!";
 
 # open and load cssmtypes file
-open(TYPES, "$types") || die "$types: $!";
+for my $hdrdir (split (/:/, $hdrpath)) {
+  open(TYPES, "$hdrdir/$types") and last;
+}
+TYPES or die "cannot find $types in $hdrpath: $!";
 $/=undef;
 my $types_h = <TYPES>;
 close(TYPES); $/="\n";
 
 }
 
 
+//
+// Intercept Key validation and double-check that the keychain is (still) unlocked
+//
+void KeychainKey::validate(AclAuthorization auth, const AccessCredentials *cred,
+       Database *relatedDatabase)
+{
+       if (KeychainDatabase *db = dynamic_cast<KeychainDatabase *>(relatedDatabase))
+               db->unlockDb();
+       SecurityServerAcl::validate(auth, cred, relatedDatabase);
+}
+
+
 //
 // We're a key (duh)
 //
 
        void instantiateAcl();
        void changedAcl();
     Database *relatedDatabase();
+       void validate(AclAuthorization auth, const AccessCredentials *cred, Database *relatedDatabase);
 
 public:
        // SecurityServerAcl personality
 
 void Session::mergeCredentials(CredentialSet &creds)
 {
     secdebug("SSsession", "%p merge creds @%p", this, &creds);
+    CredentialSet updatedCredentials = creds;
        for (CredentialSet::const_iterator it = creds.begin(); it != creds.end(); it++)
                if (((*it)->isShared() && (*it)->isValid())) {
                        CredentialSet::iterator old = mSessionCreds.find(*it);
             } else {
                 // replace "new" with "old" in input set to retain synchronization
                                (*old)->merge(**it);
-                creds.erase(it);
-                creds.insert(*old);
+                updatedCredentials.erase(*it);
+                updatedCredentials.insert(*old);
             }
                }
+    creds.swap(updatedCredentials);
 }
 
 
 
                        return; // induce retry
                }
        // all others are non-recoverable
+       secdebug("tokendb", "non-recoverable error in Access(): %d", err.error);
        throw;
 }
 
        return parent<Token>();
 }
 
-string TokenDbCommon::dbName() const
+const std::string &TokenDbCommon::dbName() const
 {
-       return token().printName().c_str();
+       return token().printName();
 }
 
 
                access().authenticate(CSSM_DB_ACCESS_READ, cred);
                secdebug("tokendb", "%p remote validation successful", this);
                return true;
-       } catch (...) {
+       }
+       catch (...) {
                secdebug("tokendb", "%p remote validation failed", this);
-               return false;
+       //      return false;
+       throw;  // try not to mask error
        }
 }
 
 //
 void TokenDatabase::authenticate(CSSM_DB_ACCESS_TYPE mode, const AccessCredentials *cred)
 {
+       Access access(token());
+       TRY
+       GUARD
        if (mode != CSSM_DB_ACCESS_RESET && cred) {
+               secdebug("tokendb", "%p authenticate calling validate", this);
                int pin;
                if (sscanf(cred->EntryTag, "PIN%d", &pin) == 1)
                        return validate(CSSM_ACL_AUTHORIZATION_PREAUTH(pin), cred);
        }
 
-       Access access(token());
        access().authenticate(mode, cred);
        switch (mode) {
        case CSSM_DB_ACCESS_RESET:
                break;
        }
        }
+       DONE
 }
 
-
 //
 // Data access interface.
 //
 
        Token &token() const;
        
        uint32 subservice() const { return token().subservice(); }
-       std::string dbName() const;
+       const std::string &dbName() const;
 
        Adornable &store();
        void resetAcls();