Slog &Slog::operator()(const char *ident, Class grp, Level lev) { ThreadImpl *thread = getPriv(); if(!thread) return *this; thread->_msgpos = 0; _enable = true; open(ident, grp); return this->operator()(lev, grp); }
void dAmnPrivClass::apply(QString commands) { QTextStream parser (&commands); while(!parser.atEnd()) { QString command; parser >> command; QString priv; int value; switch(command[0].toLatin1()) { case '+': priv = command.mid(1); value = 1; break; case '-': priv = command.mid(1); value = 0; break; default: QPair<QString, QString> pair = dAmnPacketParser::splitPair(command); priv = pair.first; value = pair.second.toInt(); } switch(getPriv(priv)) { case join: this->_joinpriv = value; break; case topic: this->_topicpriv = value; break; case title: this->_titlepriv = value; break; case kick: this->_kickpriv = value; break; case msg: this->_msgpriv = value; break; case shownotice:this->_shownoticepriv = value; break; case admin: this->_adminpriv = value; break; case images: this->_imagespriv = value; break; case smilies: this->_smiliespriv = value; break; case emoticons: this->_emoticonspriv = value; break; case thumbs: this->_thumbspriv = value; break; case avatars: this->_avatarspriv = value; break; case websites: this->_websitespriv = value; break; case objects: this->_objectspriv = value; break; case order: this->_order = (uint) value; break; case unknown: default: qt_noop(); } } }
void Slog::info(const char *format, ...) { ThreadImpl *thread = getPriv(); va_list args; if(!thread) return; va_start(args, format); overflow(EOF); info(); vsnprintf(thread->_msgbuf, sizeof(thread->_msgbuf), format, args); thread->_msgpos = strlen(thread->_msgbuf); overflow(EOF); va_end(args); }
int main( int argc, char *argv[] ) { int i, nPIDs, interactiveProcesses; DWORD bufNeeded; HANDLE hp; DWORD *pid = NULL; HINSTANCE hPsapi; HMODULE hm; char moduleName[MAX_PATH]; LARGE_INTEGER t0, t1, fr; pfEnumProcesses pfEP; pfEnumProcessModules pfEPM; pfGetModuleBaseName pfGMBN; if ( argc != 1 ) { printf( "\nUsage: %s\n", argv[0] ); puts( "\nThis program iterates over all processes in the system" ); puts( "(using EnumProcesses(), tries to open their process tokens," ); puts( "and dumps the SIDs in those tokens." ); return 1; } // try to acquire SeDebugPrivilege, if fail, then do without getPriv( SE_DEBUG_NAME ); hPsapi = LoadLibrary( "psapi.dll" ); if ( hPsapi == NULL ) { printf( "LoadLibrary( \"psapi.dll\" ): gle = %lu\n", gle ); return 1; } pfEP = (pfEnumProcesses) GetProcAddress( hPsapi, "EnumProcesses" ); pfEPM = (pfEnumProcessModules) GetProcAddress( hPsapi, "EnumProcessModules" ); pfGMBN = (pfGetModuleBaseName) GetProcAddress( hPsapi, "GetModuleBaseNameA" ); if ( pfEP == NULL || pfEPM == NULL || pfGMBN == NULL ) { printf( "GetProcAddress(): one or more PSAPI functions not found\n" ); return 1; } // here, we start with room for 16 DWORDS. If EnumProcesses() comes back // and tells us that the space was _all_ used, we try again with more, // until EP() doesn't fill all of it. That's when we know that we supplied // enough. QueryPerformanceCounter( &t0 ); interactiveProcesses = 0; nPIDs = 0; // starts with one increment more, actually pid = NULL; do { nPIDs += 16; free( pid ); pid = (DWORD *) malloc( nPIDs * sizeof DWORD ); if ( ! pfEP( pid, (DWORD) nPIDs * 4U, &bufNeeded ) ) { printf( "EnumProcesses(): gle = %lu\n", gle ); return 1; } } while ( (int) ( (DWORD) nPIDs * 4U - bufNeeded ) <= 0 ); // The next line computes the _actual_ number of PIDs retrieved (doh!). // Kudos to Chris Scheers <asi&airmail.net> for the bug report and this fix! nPIDs = bufNeeded / sizeof DWORD; if ( showInfo ) printf( "\n%d PIDs found.\n", nPIDs ); // for each PID: for ( i = 0; i < nPIDs; i ++ ) { // possibly attempt to add ourselves to the target's ACL? // SeDebugPrivilege makes this wholly unnecessary for this sample // open process hp = OpenProcess( PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pid[i] ); if ( isBadHandle( hp ) ) { if ( showInfo ) printf( "\nOpenProcess( pid = %lu ): gle = %lu\n", pid[i], gle ); continue; } // we only want the first HMODULE if ( showInfo && pfEPM( hp, &hm, sizeof hm, &bufNeeded ) ) { if ( ! pfGMBN( hp, hm, moduleName, sizeof moduleName ) ) strcpy( moduleName, "--unknown--" ); // this means, module list OK but no name } else strcpy( moduleName, "==unknown==" ); // this means, no module list if ( showInfo ) printf( "\npid %lu [%s]:\n", pid[i], moduleName ); // now, to the meat of the matter if ( dumpToken( hp, showInfo ) ) ++ interactiveProcesses; // close handle CloseHandle( hp ); } QueryPerformanceCounter( &t1 ); QueryPerformanceFrequency( &fr ); printf( "%d PIDs (of which %d are interactive) took %.3lf usec.\n", nPIDs, interactiveProcesses, 1000.0 * (double) ( t1.QuadPart - t0.QuadPart ) / (double) fr.QuadPart ); delete [] pid; FreeLibrary( hPsapi ); return 0; }
Slog &Slog::operator()(Level lev, Class grp) { ThreadImpl *thread = getPriv(); if(!thread) return *this; thread->_msgpos = 0; if(_level >= lev) _enable = true; else _enable = false; #ifdef HAVE_SYSLOG_H switch(lev) { case levelEmergency: priority = LOG_EMERG; break; case levelAlert: priority = LOG_ALERT; break; case levelCritical: priority = LOG_CRIT; break; case levelError: priority = LOG_ERR; break; case levelWarning: priority = LOG_WARNING; break; case levelNotice: priority = LOG_NOTICE; break; case levelInfo: priority = LOG_INFO; break; case levelDebug: priority = LOG_DEBUG; break; } switch(grp) { case classAudit: #ifdef LOG_AUTHPRIV priority |= LOG_AUTHPRIV; break; #endif case classSecurity: priority |= LOG_AUTH; break; case classUser: priority |= LOG_USER; break; case classDaemon: priority |= LOG_DAEMON; break; case classDefault: priority |= LOG_USER; break; case classLocal0: priority |= LOG_LOCAL0; break; case classLocal1: priority |= LOG_LOCAL1; break; case classLocal2: priority |= LOG_LOCAL2; break; case classLocal3: priority |= LOG_LOCAL3; break; case classLocal4: priority |= LOG_LOCAL4; break; case classLocal5: priority |= LOG_LOCAL5; break; case classLocal6: priority |= LOG_LOCAL6; break; case classLocal7: priority |= LOG_LOCAL7; break; } #else priority = lev; #endif return *this; }
int Slog::overflow(int c) { ThreadImpl *thread = getPriv(); if(!thread) return c; if(c == '\n' || !c || c == EOF) { if(!thread->_msgpos) return c; thread->_msgbuf[thread->_msgpos] = 0; if (_enable) #ifdef HAVE_SYSLOG_H syslog(priority, "%s", thread->_msgbuf); #else { time_t now; struct tm *dt; time(&now); dt = localtime(&now); char buf[256]; const char *p = "unknown"; switch(priority) { case levelEmergency: p = "emerg"; break; case levelInfo: p = "info"; break; case levelError: p = "error"; break; case levelAlert: p = "alert"; break; case levelDebug: p = "debug"; break; case levelNotice: p = "notice"; break; case levelWarning: p = "warn"; break; case levelCritical: p = "crit"; break; } lock.enterMutex(); snprintf(buf, sizeof(buf), "%04d-%02d-%02d %02d:%02d:%02d [%s] %s\n", dt->tm_year + 1900, dt->tm_mon + 1, dt->tm_mday, dt->tm_hour, dt->tm_min, dt->tm_sec, p, thread->_msgbuf); if(syslog) fputs(buf, syslog); // syslog << "[" << priority << "] " << thread->_msgbuf << endl; lock.leaveMutex(); } #endif thread->_msgpos = 0; if ( _enable && _clogEnable #ifndef WIN32 && (getppid() > 1) #endif ) clog << thread->_msgbuf << endl; _enable = true; return c; } if (thread->_msgpos < (int)(sizeof(thread->_msgbuf) - 1)) thread->_msgbuf[thread->_msgpos++] = c; return c; }