PersistentSystemOptions PersistentSystemOptions::ReadSystemSettings() { char *sid = getSid(); std::string system = "\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System"; std::string explorer = "\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer"; std::string power = "SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Power"; //if(! sid = getSid()) { // return false; //} PersistentSystemOptions retval; retval.hasChangePassword = !ReadRegistryKey(HKEY_USERS, _T(sid + system), _T("DisableChangePassword"), false); retval.hasLockComputer = !ReadRegistryKey(HKEY_USERS, _T(sid + system), _T("DisableLockWorkstation"), false); retval.hasLogOff = !ReadRegistryKey(HKEY_USERS, _T(sid + explorer), _T("NoLogoff"), false); retval.hasSwitchUser = !ReadRegistryKey(HKEY_LOCAL_MACHINE, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System"), _T("HideFastUserSwitching"), false); retval.hasTaskManager = !ReadRegistryKey(HKEY_USERS, _T(sid + system), _T("DisableTaskMgr"), false); retval.hasPower = !ReadRegistryKey(HKEY_USERS, _T(sid + explorer), _T("NoClose"), false); retval.hasFilterKeysHotkey = ReadFilterKeysHotkey(); retval.hasMouseKeysHotkey = ReadMouseKeysHotkey(); retval.hasStickyKeysHotkey = ReadStickyKeysHotkey(); retval.hasToggleKeysHotkey = ReadToggleKeysHotkey(); retval.hasHighContrastHotkey = ReadHighContrastHotkey(); retval.hasFastBootHotKey = !ReadRegistryKey(HKEY_LOCAL_MACHINE, _T("SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Power"), _T("HiberbootEnabled"), false); return retval; }
void Struct::addTypeId(const TypeIdPtr &typeIdPtr) { StructPtr sp = StructPtr::dynamicCast(typeIdPtr->getTypePtr()); if(sp) { if(sp->getSid() == getSid()) { g_parse->error("struct can't take self as member data"); } } for(size_t i = 0; i < _members.size(); i++) { if(_members[i]->getId() == typeIdPtr->getId()) { g_parse->error("data member '" + typeIdPtr->getId() + "' duplicate definition"); } if(_members[i]->getTag() == typeIdPtr->getTag()) { g_parse->error("data member '" + typeIdPtr->getId() + "' has equal tag with '" + _members[i]->getId() + "'"); } if(_members[i]->getTag() > typeIdPtr->getTag()) { _members.insert(_members.begin() + i, typeIdPtr); return; } } _members.push_back(typeIdPtr); }
// . ***** META LIST DELETE LOOP ***** // . scan for meta lists to remove from syncdb // . check every D KEY // . must NOT have any "need to send request" keys (a bit set) // . must NOT have any "need to recv request" keys (b bit set) // . must NOT have our "need to add" key (c bit set) void Syncdb::loop3 ( ) { // . loop over the meta lists we need to delete // . these are "d" keys // . use a "tid" of 0 key128_t sk = makeKey ( 0,0,0,1,0,0,0,0 ); key128_t ek = makeKey ( 0,0,0,1,0,0xffffffff,0xffffffffffffffffLL,1 ); // get the first node in sequence, if any long nn = m_qt.getNextNode ( 0 , (char *)&sk ); // do the loop for ( ; nn >= 0 ; nn = m_qt.getNextNode ( nn ) ) { // breathe QUICKPOLL ( MAX_NICENESS ); // get key key128_t k = *(key128_t *)m_qt.getKey ( nn ); // stop when we hit the end if ( k > ek ) break; // get zid uint64_t zid = getZid ( &k ); // get sid uint32_t sid = getSid ( &k ); // have we sent/recvd all checkoff requests required? have // we added the meta list? if so, we can nuke it from syncdb if ( ! canDeleteMetaList ( sid, zid ) ) { // no use banging away at this sid any more since we // are missing another action for this one sid++; // find the key of the FIRST meta list we need to add // for this new senderId, "sid" key128_t nk = makeKey ( 0,0,0,1,0,sid,0,0 ); // undo the m_qt.getNextNode(nn) we call in for loop nn = m_qt.getPrevNode ( 0 , (char *)&nk ); // sanity check if ( nn < 0 ) { char *xx=NULL;*xx=0; } // get next key from this new sid continue; } // . make the negative key for syncdb // . it just uses a negative "c" key, with a tid of 0 key128_t dk = makeKey ( 0,0,1,0,0,sid,zid,0); // . add it to syncdb to signifiy a delete // . this returns false and sets g_errno on error if(!m_rdb.addRecord((collnum_t)0,(char *)&dk,NULL,0, MAX_NICENESS)) return; // delete it from quick tree now that we added the negative // key successfully to syncdb long dn = m_qt.getNode ( 0, (char *)&k ); // must be there! if ( ! dn ) { char *xx=NULL;*xx=0; } // nuke it m_qt.deleteNode ( dn , true ); } // . success // . do not recall until big loop completes a round m_calledLoop3 = true; }
bool PersistentSystemOptions::WriteToStorage() const { char* sid = getSid(); std::string options = "\\PersistentSystemOptions"; std::string sep = "\\"; std::string dest = sid + sep + REGISTRY_SETTINGS_LOCATION + options; bool allWorked = true; if(!WriteRegistryKey(HKEY_USERS, _T(dest), _T("hasChangePassword"), hasChangePassword)) allWorked = false; if(!WriteRegistryKey(HKEY_USERS, _T(dest), _T("hasLockComputer"), hasLockComputer)) allWorked = false; if(!WriteRegistryKey(HKEY_USERS, _T(dest), _T("hasLogOff"), hasLogOff)) allWorked = false; if(!WriteRegistryKey(HKEY_USERS, _T(dest), _T("hasSwitchUser"), hasSwitchUser)) allWorked = false; if(!WriteRegistryKey(HKEY_USERS, _T(dest), _T("hasTaskManager"), hasTaskManager)) allWorked = false; if(!WriteRegistryKey(HKEY_USERS, _T(dest), _T("hasPower"), hasPower)) allWorked = false; if(!WriteRegistryKey(HKEY_USERS, _T(dest), _T("hasFilterKeysHotkey"), hasFilterKeysHotkey)) allWorked = false; if(!WriteRegistryKey(HKEY_USERS, _T(dest), _T("hasMouseKeysHotkey"), hasMouseKeysHotkey)) allWorked = false; if(!WriteRegistryKey(HKEY_USERS, _T(dest), _T("hasStickyKeysHotkey"), hasStickyKeysHotkey)) allWorked = false; if(!WriteRegistryKey(HKEY_USERS, _T(dest), _T("hasToggleKeysHotkey"), hasToggleKeysHotkey)) allWorked = false; if(!WriteRegistryKey(HKEY_USERS, _T(dest), _T("hasHighContrastHotkey"), hasHighContrastHotkey)) allWorked = false; if(!WriteRegistryKey(HKEY_USERS, _T(dest), _T("hasFastBootHotkey"), !hasFastBootHotKey)) allWorked = false; return allWorked; }
JingleSession::JingleSession(const Jid &AThisParty, const Jid &AOtherParty, const QString &AApplicationNS): QObject(FJingle->appByNS(AApplicationNS)->instance()),FValid(false), FOutgoing(true), FApplicationNamespace(AApplicationNS),FThisParty(AThisParty), FOtherParty(AOtherParty), FSid(getSid(AThisParty)), FActionId(), FAction(IJingle::NoAction), FReason(IJingle::NoReason) { FSessions[FThisParty].insert(FSid, this); if (FThisParty.isValid() && FOtherParty.isValid()) { FValid=true; connect(this,SIGNAL(sessionInitiated(Jid,QString)),parent(),SLOT(onSessionInitiated(Jid,QString))); connect(this,SIGNAL(sessionAccepted(Jid,QString)),parent(),SLOT(onSessionAccepted(Jid,QString))); connect(this,SIGNAL(sessionConnected(Jid,QString)),parent(),SLOT(onSessionConnected(Jid,QString))); connect(this,SIGNAL(sessionTerminated(Jid,QString,IJingle::SessionStatus,IJingle::Reason)),parent(),SLOT(onSessionTerminated(Jid,QString,IJingle::SessionStatus,IJingle::Reason))); connect(this,SIGNAL(sessionInformed(QDomElement)),parent(),SLOT(onSessionInformed(QDomElement))); connect(this,SIGNAL(receivingData(Jid,QString)),parent(),SLOT(onDataReceived(Jid,QString))); connect(this,SIGNAL(actionAcknowledged(Jid,QString,IJingle::Action,IJingle::CommandRespond,IJingle::SessionStatus,Jid,IJingle::Reason)),parent(),SLOT(onActionAcknowledged(Jid,QString,IJingle::Action,IJingle::CommandRespond,IJingle::SessionStatus,Jid,IJingle::Reason))); } }
PersistentSystemOptions PersistentSystemOptions::ReadFromStorage() { char* sid = getSid(); std::string options = "\\PersistentSystemOptions"; std::string sep = "\\"; std::string dest = sid + sep + REGISTRY_SETTINGS_LOCATION + options; PersistentSystemOptions retval; retval.hasChangePassword = ReadRegistryKey(HKEY_USERS, _T(dest), _T("hasChangePassword"), true); retval.hasLockComputer = ReadRegistryKey(HKEY_USERS, _T(dest), _T("hasLockComputer"), true); retval.hasLogOff = ReadRegistryKey(HKEY_USERS, _T(dest), _T("hasLogOff"), true); retval.hasSwitchUser = ReadRegistryKey(HKEY_USERS, _T(dest), _T("hasSwitchUser"), true); retval.hasTaskManager = ReadRegistryKey(HKEY_USERS, _T(dest), _T("hasTaskManager"), true); retval.hasPower = ReadRegistryKey(HKEY_USERS, _T(dest), _T("hasPower"), true); retval.hasFilterKeysHotkey = ReadRegistryKey(HKEY_USERS, _T(dest), _T("hasFilterKeysHotkey"), true); retval.hasMouseKeysHotkey = ReadRegistryKey(HKEY_USERS, _T(dest), _T("hasMouseKeysHotkey"), true); retval.hasStickyKeysHotkey = ReadRegistryKey(HKEY_USERS, _T(dest), _T("hasStickyKeysHotkey"), true); retval.hasToggleKeysHotkey = ReadRegistryKey(HKEY_USERS, _T(dest), _T("hasToggleKeysHotkey"), true); retval.hasHighContrastHotkey = ReadRegistryKey(HKEY_USERS, _T(dest), _T("hasHighContrastHotkey"), true); retval.hasFastBootHotKey = ReadRegistryKey(HKEY_USERS, _T(dest), _T("hasFastBootHotkey"), true); return retval; }
bool PersistentSystemOptions::WriteSystemSettings() const { bool allWorked = true; char* sid = getSid(); std::string system = "\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System"; std::string explorer = "\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer"; std::string power = "SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Power"; //if(!sid = getSid()) { // return false; //} if(!WriteRegistryKey(HKEY_USERS, _T(sid + system), _T("DisableChangePassword"), !hasChangePassword)) { allWorked = false; Tcout << _T("Error DisableChangePassword") << std::endl; } if(!WriteRegistryKey(HKEY_USERS, _T(sid + system), _T("DisableLockWorkstation"), !hasLockComputer)) { allWorked = false; Tcout << _T("Error DisableLockWorkstation") << std::endl; } if(!WriteRegistryKey(HKEY_USERS, _T(sid + explorer), _T("NoLogoff"), !hasLogOff)) { allWorked = false; Tcout << _T("Error NoLogoff") << std::endl; } if(!WriteRegistryKey(HKEY_LOCAL_MACHINE, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System"), _T("HideFastUserSwitching"), !hasSwitchUser)) { allWorked = false; Tcout << _T("Error HideFastUserSwitching") << std::endl; } #ifndef DEBUG if(!WriteRegistryKey(HKEY_USERS, _T(sid + system), _T("DisableTaskMgr"), !hasTaskManager)) { allWorked = false; Tcout << _T("Error DisableTaskMgr") << std::endl; } #endif // DEBUG if(!WriteRegistryKey(HKEY_USERS, _T(sid + explorer), _T("NoClose"), !hasPower)) { allWorked = false; Tcout << _T("Error NoClose") << std::endl; } if(!WriteFilterKeysHotkey(hasFilterKeysHotkey)) { allWorked = false; Tcout << _T("Error FilterKeysHotkey") << std::endl; } if(!WriteMouseKeysHotkey(hasMouseKeysHotkey)) { allWorked = false; Tcout << _T("Error MouseKeysHotkey") << std::endl; } if(!WriteStickyKeysHotkey(hasStickyKeysHotkey)) { allWorked = false; Tcout << _T("Error StickyKeysHotkey") << std::endl; } if(!WriteToggleKeysHotkey(hasToggleKeysHotkey)) { allWorked = false; Tcout << _T("Error ToggleKeysHotkey") << std::endl; } if(!WriteHighContrastHotkey(hasHighContrastHotkey)) { allWorked = false; Tcout << _T("Error HighContrastHotkey") << std::endl; } if(!WriteRegistryKey(HKEY_LOCAL_MACHINE, _T("SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Power"), _T("HiberbootEnabled"), hasFastBootHotKey)) { allWorked = false; Tcout << _T("Error FastBootHotKey") << std::endl; } return allWorked; }
// . ***** CHECKOFF LOOP ***** // . loop over the checkoff requests TO SEND // . send checkoff requests out that we need to send and have not yet got // a reply for. when we get a reply for them the "need to send checkoff // request" key is immediately deleted // . make a big list then call msg1 with an rdbId of RDB_SYNCDB // . do not include dead hosts void Syncdb::loop5 ( ) { // make the start key key128_t k = m_nextk; // end key key128_t ek; ek = makeKey(1,0,0,0,0xffffffff,0xffffffff,0xffffffffffffffffLL,1); // reset m_nk = 0; // get it long nn = m_qt.getNextNode ( 0 , (char *)&k ); // do one tid at a time uint32_t startTid = getTid ( &k ); // do the loop for ( ; nn >= 0 ; nn = m_qt.getNextNode ( nn ) ) { // breathe QUICKPOLL ( MAX_NICENESS ); // get key key128_t k = *(key128_t *)m_qt.getKey ( nn ); // save it m_nextk = k; // add one m_nextk += 1; // stop when we hit the end if ( k > ek ) break; // get twin id uint32_t tid = getTid ( &k ); // stop if tid changed if ( tid != startTid && m_nk >= 0 ) break; // skip if tid is dead if ( g_hostdb.isDead ( tid ) ) { // skip to next tid! tid++; // . find the key of the FIRST meta list we need to add // for this new senderId, "sid" // . mdw: i reset sid to 0 key128_t nk = makeKey ( 1,0,0,0,tid,0,0,0 ); // undo the m_qt.getNextNode(nn) we call in for loop nn = m_qt.getPrevNode ( 0 , (char *)&nk ); // bail if no good if ( nn < 0 ) break; // get next key from this new sid continue; } // get zid uint64_t zid = getZid ( &k ); // get sid uint32_t sid = getSid ( &k ); // note it log("sync: storing key for meta request list sid=%lu zid=%llu " "from twin hostid #%li",(unsigned long)sid, (unsigned long long)zid,(long)tid); // make the key. make NEGATIVE "b" keys. m_keys [ m_nk++ ] = makeKey ( 0,1,0,0,0,sid,zid,0 ); // stop if full if ( m_nk >= MAX_CHECKOFF_KEYS ) break; } // all done? if ( k <= ek && m_nk <= 0 ) { m_calledLoop5 = true; return; } // . add the whole list at once // . make our own msg1 request to send to just one host if ( g_udpServer.sendRequest ( (char *)m_keys , m_nk * 16 , 0x5d , // SYNCDB REQUEST 0 , // ip 0 , // port startTid , // hostId NULL , // retSlot NULL , // state addedListWrapper5 , // wrapper 60 , // timeout -1 , // backoff -1 , // maxWait NULL , // replyBuf 0 , // replyBufSize MAX_NICENESS )) // it blocked, return now return; // i guess we had an error... if ( ! addedList5() ) return; }
// . ***** SYNC LOOP ***** // . loop over the checkoff requests we are waiting for. "b" keys. // . send out msg0 requests for meta lists we need // . if we got a 60+ sec old checkoff recvd but never got the meta list // ourselves, then request it!! bool Syncdb::loop4 ( ) { // make the start key. a "b" key key128_t k = m_syncKey; // end key key128_t ek; ek = makeKey(0,1,0,0,0xffffffff,0xffffffff,0xffffffffffffffffLL,1); // get next node long nn = m_qt.getNode ( 0 , (char *)&k ); // get group we are in //Host *group = g_hostdb.getMyShard(); // use this for determining approximate age of meta lists long long nowms = gettimeofdayInMilliseconds(); // do the loop for ( ; nn >= 0 ; nn = m_qt.getNextNode ( nn ) ) { // breathe QUICKPOLL ( MAX_NICENESS ); // give other loops some time so we can digest these // meta lists we added if ( m_addCount >= 100 ) break; // get key key128_t k = *(key128_t *)m_qt.getKey ( nn ); // stop when we hit the end if ( k > ek ) break; // update m_syncKey = k; // get twin id uint32_t tid = getTid ( &k ); // skip if tid is dead if ( g_hostdb.isDead ( tid ) ) { // skip to next tid! tid++; // . find the key of the FIRST meta list we need to add // for this new senderId, "sid" // . mdw: i reset sid to 0 key128_t nk = makeKey ( 0,1,0,0,tid,0,0,0 ); // undo the m_qt.getNextNode(nn) we call in for loop nn = m_qt.getPrevNode ( 0 , (char *)&nk ); // sanity check if ( nn < 0 ) { char *xx=NULL;*xx=0; } // get next key from this new sid continue; } // . skip if delbit set // . the delbit set means we got the meta list and are // waiting to receive the checkoff request from twin #sid // . when it comes in it will annihilate with this key! // . right now we are only interested in *negative* keys, // those with their delbit cleared if ( (k.n0 & 0x01) == 0x01 ) continue; // . ok we got checkoff request from tid for this sid/zid // . and we have not got the meta list ourselves yet cuz // we would have had k with the delbit set. // . get zid uint64_t zid = getZid ( &k ); // get sid uint32_t sid = getSid ( &k ); // get its approximate age long long age = nowms - zid; // go to next sid if not 60 seconds yet for this one if ( age < 60000 ) { // no use banging away at this sid any more since we // are missing another action for this one sid++; // find the key of the FIRST meta list we need to add // for this new senderId, "sid". make the "b" key. key128_t nk = makeKey ( 0,1,0,0,tid,sid,0,0 ); // undo the m_qt.getNextNode(nn) we call in for loop nn = m_qt.getPrevNode ( 0 , (char *)&nk ); // sanity check if ( nn < 0 ) { char *xx=NULL;*xx=0; } // get next key from this new sid continue; } // make the "d" key to see if we got the meta list just // to make sure! we do not want to re-add a meta list! key128_t dk = makeKey(0,0,0,1,0,sid,zid,1); if ( m_qt.getNode ( 0 , (char *)&dk ) >= 0 ) continue; // note it log("sync: requesting meta list sid=%lu zid=%llu age=%llu " "from twin hostid #%li", (unsigned long)sid, (unsigned long long)zid, (unsigned long long)age, (long)tid); // i guess we are out of sync g_hostdb.m_myHost->m_inSync = false; // do not let sleep ticker call bigLoop m_outstanding = true; // record the sid m_requestedSid = sid; // make the c key range key128_t sk2 = makeKey(0,0,1,0,0,sid,zid,0); key128_t ek2 = makeKey(0,0,1,0,0,sid,zid,1); // ok, ask tid for this meta list if ( ! m_msg0.getList ( tid , // hostId 0 , // ip 0 , // port 0 , // maxCacheAge false , // addToCache RDB_SYNCDB , 0 , // collnum &m_list , (char *)&sk2 , (char *)&ek2 , 999 , // minRecSizes NULL , gotListWrapper4 , MAX_NICENESS , false ))// err correction? return false; // stop on error. return true with g_errno set on error if ( ! gotList4() ) return true; } // we completed m_calledLoop4 = true; return true; }
// . ***** META LIST PRE-ADD LOOP ***** // . scan for meta lists to add // . scan m_qt (quickTree) for keys with the "c" bit set // . the "c" bit means we need to add the meta list for that sid/zid // . add meta list keys to the m_addme[] array so loop2() can loop over syncdb // itself and add the meta lists corresponding to the keys in m_addme[] // since the meta list may be on disk cuz they are very big (32k+) // . call this once per second or so, or back-to-back if we "did something" // . this loop will set the m_addme[] array to keys in syncdb of metalists // that we can finally add! void Syncdb::loop1 ( ) { // do not re-call this loop this round in bigLoop() function m_calledLoop1 = true; // how many hosts in our group are alive? long alive = 0; // get group we are in Host *group = g_hostdb.getMyShard(); // number hosts in group long nh = g_hostdb.getNumHostsPerShard(); // count alive for ( long i = 0 ; i < nh ; i++ ) if ( ! g_hostdb.isDead ( &group[i] ) ) alive++; // reset m_na = 0; m_ia = 0; // . if we do NOT have 2+ alive hosts, including ourselves, bail // . at least two twins a group must be alive to do an add otherwise // we risk serious data loss, since hard drives tend to die mostly // when writing! if ( alive <= 1 ) return; // . loop over the meta lists we need to add // . use a "tid" of 0 long tid = 0; key128_t sk = makeKey(0,0,1,0,tid,0,0,0); key128_t ek = makeKey(0,0,1,0,tid,0xffffffff,0xffffffffffffffffLL,1); // get the first node in sequence, if any. 0 = collnum long nn = m_qt.getNextNode ( 0 , (char *)&sk ); // do the loop for ( ; nn >= 0 ; nn = m_qt.getNextNode ( nn ) ) { // breathe QUICKPOLL ( MAX_NICENESS ); // get key key128_t k = *(key128_t *)m_qt.getKey ( nn ); // stop when we hit the end if ( k > ek ) break; // get zid uint64_t zid = getZid ( &k ); // get sid uint32_t sid = getSid ( &k ); // . if we have a "need to send checkoff request" key still // present in quicktree, that means we never received a good // reply for it! and we reqire that! // . if a host is dead and we need to send a checkoff request // to him, then we do not count that here... if ( ! sentAllCheckoffRequests ( sid , zid ) ) { // no use banging away at this sid any more since we // are missing a checkoff reply from an alive twin sid++; // find the key of the FIRST meta list we need to add // for this new senderId, "sid" key128_t nk = makeKey ( 0,0,1,0,tid,sid,0,0 ); // undo the m_qt.getNextNode(nn) we call in for loop nn = m_qt.getPrevNode ( 0 , (char *)&nk ); // sanity check if ( nn < 0 ) { char *xx=NULL; *xx=0; } // get next key from this new sid continue; } // schedule it for an add in loop2() below m_addMe [ m_na++ ] = k; // crap no room! wait for it to be used up! if ( m_na >= MAX_TO_ADD ) return; } }