KGRKJGETMRETU895U-589TY5MIGM5JGB5SDFESFREWTGR54TY
Server : Apache/2.2.17 (Unix) mod_ssl/2.2.17 OpenSSL/0.9.8e-fips-rhel5 DAV/2 PHP/5.2.17
System : Linux localhost 2.6.18-419.el5 #1 SMP Fri Feb 24 22:47:42 UTC 2017 x86_64
User : nobody ( 99)
PHP Version : 5.2.17
Disable Function : NONE
Directory :  /proc/21573/root/usr/lib/python2.4/site-packages/setroubleshoot/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //proc/21573/root/usr/lib/python2.4/site-packages/setroubleshoot/avc_audit.pyo
mò
3ÔUc@s9ddgZdkZdkZdkZdkZdkZdkZdkZ	dk
TdkZdkZdk
Z
dkZdkZdklZdkTdkTdkTdkTeddeƒZyeedƒWnej
ode_nXeeiƒd	ƒZd
„Zdfd„ƒYZdei fd„ƒYZ!dS(
tAuditSocketReceiverThreadtAuditRecordReceiverN(t*(s
get_configtgeneraltuse_auparset	AUDIT_EOEi(icCsˆ|iidjp|iidjotSnti|iijo@tidt|iƒtid|i	i
ƒƒtidƒnt
S(NsUsetroubleshoot generated AVC, exiting to avoid recursion, context=%s, AVC scontext=%ssaudit event
%si(tavctscontextttypetNonettcontexttFalset
my_contexttlog_programterrortaudit_eventtformattsystexittTrue(R((t</usr/lib/python2.4/site-packages/setroubleshoot/avc_audit.pyt
verify_avc7s&cBs†tZdZdZd„Zd„Zd„Zd„Zd„Zd„Z	d„Z
d	„Zed
„Z
ed„Zd„Zd
„ZRS(sO
    The audit system emits messages about a single event
    independently. Thus one single auditable event may be composed
    from one or more individual audit messages. Each audit message is
    prefixed with a unique event id, which includes a timestamp. The
    last audit message associated with an event is not marked in any
    fashion. Audit messages for a specific event may arrive
    interleaved with audit messages for other events. It is the job of
    higher level software (this code) to assemble the audit messages
    into events. The AuditEvent class is used for assembly. When a new
    event id is seen a new AuditEvent object is created, then
    every time an audit message arrives with that event id it is added
    to that object. The AuditEvent object contains the timestamp
    associated with the audit event as well as other data items useful
    for processing and handling the event.

    The audit system does not tell us when the last message belonging
    to an event has been emitted so we have no explicit way of knowing
    when the audit event has been fully assembled from its constituent
    message parts. We use the heuristic if a sufficient length of
    time has expired since we last saw a message for this event, then
    it must be complete

    Thus when audit events are created we place them in a cache where
    they will reside until their time to live has expired at which
    point we will assume they are complete and emit the event.

    Events are expired in the flush_cache() method. The events
    resident in the cache are sorted by their timestamps. A time
    threshold is established. Any events in the cache older than the
    time threshold are flushed from the cache as complete events.

    When should flushes be performed? The moment when a new message is
    added would seem a likely candidate moment to perform a sweep of
    the cache. But this is costly and does not improve how quickly
    events are expired. We could wait some interval of time (something
    much greater than how long we expect it would take for messages
    percolate) and this has good behavior, except for the following
    case. Sometimes messages are emitted by audit in rapid
    succession. If we swept the cache once a second then the cache may
    have grown quite large. Since it is very likely that any given audit
    event is complete by the time the next several events start
    arriving we can optimize by tracking how many messages have
    arrived since the last time we swept the cache.

    The the heuristic for when to sweep the cache becomes:

    If we've seen a sufficient number of messages then sweep -or- if
    a sufficient length of time has elapsed then we sweep

    Note that when audit messages are injected via log file scanning
    elapsed wall clock time has no meaning relative to when to perform
    the cache sweep. However, the timestamp for an event remains a
    critical factor when deciding if an event is complete (have we
    scanned far enough ahead such we're confident we won't see any
    more messages for this event?). Thus the threshold for when to
    expire an event from the cache during static log file scanning is
    determined not by wall clock time but rather by the oldest
    timestamp in the cache (e.g.there is enough spread between
    timestamps in the cache its reasonable to assume the event is
    complete). One might ask in the case of log file scanning why not
    fill the cache until EOF is reached and then sweep the cache?
    Because in log files it is not unusual to have thousands or tens
    of thousands of events and the cache would grown needlessly
    large. Because we have to deal with the real time case we already
    have code to keep only the most recent events in the cache so we
    might as well use that logic, keep the code paths the same and
    minimize resource usage.
    f0.0050000000000000001cCs2d|_d|_h|_g|_|iƒdS(Nii(tselft
flush_sizetflush_counttcacheteventstreset_statistics(R((Rt__init__s
				cCs
t|iƒS(N(tlenRR(R((Rtnum_cached_events–scCsd|_d|_dS(Ni(Rtmax_cache_lengthtevent_count(R((RR™s	cCs#tƒ}||it|iƒ<|S(N(t
AuditEventRRRtstrtrecordtevent_id(RR#R((Rtinsert_new_events	cCs|iit|iƒdƒS(N(RRtgetR"R#R$R	(RR#((Rtget_event_from_record¢scCs”totid|ii|ƒn|i|ƒ}|idjo |o|i	|ƒndSn|djo|i|ƒ}n|i|ƒdS(Ns%s.add_record_to_cache(): %stEOE(
tdebugtlog_avcRt	__class__t__name__R#R'Rtrecord_typetflush_eventR	R%t
add_record(RR#R((Rtadd_record_to_cache¥s
cCs&|id7_|iid|ƒdS(Nii(RR RtinsertR(RR((Rt
emit_event²scCs$|i|ƒ|it|iƒ=dS(N(RR2RRR"R$(RR((RR.¶s
cstˆiƒdjodSntˆiƒˆijotˆiƒˆ_nˆiiƒ}|djo3x(|D] }ˆi|}ˆi	|ƒqpWdSn|i
‡d†ƒ|djoˆi|diˆi
}nx<|D]4}ˆi|}|i|joˆi	|ƒqâqâWdS(slFlush events from the cache if they are older than the threshold age.
        If the threshold age is None then the threshold age is set to the age
        of the newest event in the cache minus the cache time to live, in other
        words anything in the cache which is older than the time to live relative
        to the most current event is flushed.
        iNcs!tˆi|iˆi|iƒS(N(tcmpRRtat	timestamptb(R4R6(R(Rt<lambda>Ósiÿÿÿÿ(RRRRtkeyst	event_idst
threshold_ageR$RR.tsortR	R5tcache_time_to_live(RR:RR$R9((RRtflush_cacheºs(



ccsK|i|ƒd|_x.t|iƒdjo|iiƒ}|VqWdS(Ni(RR=R:RRRtpopR(RR:R((RtflushÜs
	ccs"x|idƒD]
}|VqWdS(s{Emit every event in the cache irrespective of its
        timestamp. This means we're done, nothing should remain buffered.iN(RR?R(RR((Rtcloseãsccs»totid|ii|ƒn|id7_|idjo|i|ƒn|i|i	jox|i
ƒD]
}|VqtWnx.t|i
ƒd	jo|i
iƒ}|Vq‰Wd
S(s9Accept a new audit record into the system for processing.s%s.feed() got %s'itAVCtAVC_PATHtSYSCALLtCWDtPATHR(iN(sAVCRBRCRDsPATHsEOE(R)R*RR+R,R#RR-R0RR?RRRR>(RR#R((Rtfeedês
(R,t
__module__t__doc__R<RRRR%R'R0R2R.R	R=R?R@RF(((RRDsE						
		"	cBs>tZd„Zd„Zd„Zd„Zd„Zd„ZRS(NcCsctii|ƒ||_||_tƒ|_tddt	ƒ|_
|iƒd|_t
|_dS(Ntaudittretry_intervali(t	threadingtThreadRRtqueuetreport_receiverRtrecord_receivert
get_configtintRJtget_socket_pathsttimeout_intervalRt
has_audit_eoe(RRMRN((RRÿs		
	cCsKg|_tddƒ}|ii|ƒtddƒ}|ii|ƒdS(NRIttext_protocol_socket_pathtbinary_protocol_socket_path(Rtaudit_socket_pathsRPtaudit_socket_pathtappend(RRX((RRRs
	cCs­x¦tožy
xä|iD]Ù|_|idj	oÀyyt|iƒ}t|ƒ|_t	i
t	it	iƒ|_
|i
i|iƒ|i
iƒ|_tid|iƒdSWqðt	ij
o1}t|ƒ\}}tid|i|ƒqðXqqWtiddi|iƒ|iƒWnzt	ij
o7}t|ƒ\}}tid|i||iƒn6tj
o)}tid|i|d|iƒnXti|iƒqWdS(Nsaudit socket (%s) connecteds4attempt to open audit socket (%s) failed, error='%s's:could not open any audit sockets (%s), retry in %d secondss, s9audit socket (%s) failed, error='%s', retry in %d secondsi(RRRWRXR	tderive_record_formatt
record_formattAuditRecordReadert
record_readertSockettsockettAF_UNIXtSOCK_STREAMtaudit_sockettconnecttmakefiletaudit_socket_fdR*tinfoRtetget_error_from_socket_exceptionterrnotstrerrortwarningtjoinRJtOSErrorttimetsleep(RRgRiRjR[((RRcs8
					cCsPt|||||ƒ}|iƒx'|i	i
|ƒD]}|i|ƒq5WdS(s"called to enter a new audit recordN(
tAuditRecordR-R$t	body_texttfieldstline_numbertaudit_recordtaudispd_rectifyRRORFRtnew_audit_event_handler(RR-R$RqRrRsRRt((Rtnew_audit_record_handler5s
cCs‡totid|ƒn|iƒo[|iƒoM|iƒdjo:t|ƒ}t|ƒo|i
i||ifƒqƒndS(Ns!new_audit_event_handler: event=%si(
R)R*Rtis_avct
is_grantedtnum_recordsRARRRRMtputRN(RRR((RRv=s.
c
Csc|iƒ|i}xItoAti|iggg|ƒ\}}}y]|i|joòt
i|ii
ƒdƒ}|djo&totidƒn|iƒq totid|iiƒƒn|ip
|i}nx½|ii|ƒD]N\}}}}
}|djot|_d}n|i||||
|ƒqóWnXx4|iitiƒ|iƒD]}|i |ƒqiW|iiƒdjo
d}nWqt!j
o4}	totid|i#i$ƒnt%i&ƒqt'j
o4}	totid|i#i$ƒnt%i&ƒqt(j
o,}	ti)d	|	i#i$t*|	ƒƒdSqXqWdS(
Nitsaudit socket connection droppedscached audit event count = %dR(is!KeyboardInterrupt exception in %ssSystemExit exception in %ssexception %s: %s(+RRcRSttimeoutRtselectRbtinListtoutListterrListtostreadRetfilenotnew_dataR)R*RORRTR]RFR-R$RqRrRsR	RwR?RnRRvtKeyboardInterruptRgR+R,tthreadtinterrupt_maint
SystemExitt	Exceptiont	exceptionR"(
RRsR€RqR-RR$R…RRgRrR}R((RtrunGsL
	'



	
! (R,RGRRRRcRwRvRŒ(((RRþs				!		
("t__all__RIRitErrnoR‚treR~tselinuxR_R^tstattstructRR‡RKRntsetroubleshoot.configRPtsetroubleshoot.errcodetsetroubleshoot.logtsetroubleshoot.utiltsetroubleshoot.audit_datatboolRtgetattrtAttributeErrorRt
AvcContexttgetconRRRRLR(RRŽRR~RR’RRRRR^RRPRIR‡RR‚RKRn((Rt?s6												
	
º

Anon7 - 2021