0 ? Store::row( $id ) : null; if ( null === $row || Comparison::OK === $row['status'] ) { return 'not_found'; } $unit = (string) $row['unit']; $path = (string) $row['path']; $was = (string) $row['status']; $root = Scanner::root_of( $unit ); $display = $roots->display( $root, $path ); $file = $roots->resolve( $root, $path ); $md5 = null; // resolve() already refused a path whose real location is outside its root. if ( null !== $file && is_file( $file ) ) { $size = (int) filesize( $file ); $md5 = $size <= Scanner::MAX_FILE_BYTES ? md5_file( $file ) : false; $md5 = is_string( $md5 ) ? $md5 : null; } if ( null === $md5 ) { // Missing (or unreadable, or outside its root): accept the // absence. There is nothing to vouch for. Store::delete( $id ); } else { Store::update( $id, array( 'source' => Store::SOURCE_ACCEPTED, 'expected' => $md5, 'status' => Comparison::OK, 'severity' => 0, 'actual_md5' => $md5, 'actual_size' => (int) filesize( (string) $file ), 'actual_mtime' => (int) filemtime( (string) $file ), ) ); } EventLogger::log( Scanner::EVENT_ACCEPTED, sprintf( 'Integrity finding accepted: %1$s (%2$s)', $display, $was ), 'integrity', $id, array( 'unit' => $unit, 'path' => $display, 'status' => $was, 'accepted' => null === $md5 ? 'absent' : $md5, ) ); return 'accepted'; } /** * Accept a plugin, theme or the plugins directory's loose files whole. * * @param string $unit Unit key. * @return string accepted_unit or not_found. */ public static function accept_unit( string $unit ): string { if ( ! Units::may_baseline( $unit ) || ( Units::PLUGINS_ROOT !== $unit && 1 !== preg_match( '/^(plugin|theme):[^\/]+$/', $unit ) ) ) { return 'not_found'; } $forgotten = Scanner::rebaseline( $unit ); EventLogger::log( Scanner::EVENT_ACCEPTED, sprintf( 'Integrity findings accepted for all of %s; it is re-baselined on the next scan', $unit ), 'integrity', null, array( 'unit' => $unit, 'all' => true, 'rows' => $forgotten, ) ); return 'accepted_unit'; } }