Esempio n. 1
0
static VALUE
rg_can_truncate_p(VALUE self)
{
        return CBOOL2RVAL(g_seekable_can_truncate(_SELF(self)));
}
Esempio n. 2
0
    bool verify_and_strip_signatures()
    {
        g_debug( "CHECKING SIGNATURE(S)" );

        Signature::Info::List signatures;

        gsize signature_length = 0;

        // This means that the signatures are invalid or we had a problem
        // dealing with them. If there are no signatures, this will return
        // true and give us an empty list.

        if ( ! Signature::get_signatures( info.source_file.c_str(), signatures, &signature_length ) )
        {
            return false;
        }

        unsigned int found = 0;

        if ( signatures.empty() )
        {
            g_debug( "  NOT SIGNED" );
        }
        else
        {
            for ( Signature::Info::List::const_iterator it = signatures.begin(); it != signatures.end(); ++it )
            {
                info.fingerprints.insert( it->fingerprint );
            }

            // Now, see how many of the required ones are found in the signatures

            for ( StringSet::const_iterator it = info.required_fingerprints.begin(); it != info.required_fingerprints.end(); ++it )
            {
                found += info.fingerprints.count( *it );
            }
        }

        if ( found != info.required_fingerprints.size() )
        {
            // Signature(s) missing

            g_warning( "APP IS MISSING AT LEAST ONE REQUIRED SIGNATURE" );

            return false;
        }

        // If there were no signatures, we are done

        if ( signatures.empty() )
        {
            return true;
        }

        // Otherwise, we need to strip the signature block from the file

        bool result = false;

        GFile * file = g_file_new_for_path( info.source_file.c_str() );

        if ( file )
        {

            GFileIOStream * stream = g_file_open_readwrite( file, NULL, NULL );

            if ( stream )
            {
                GSeekable * seekable = G_SEEKABLE( stream );

                if ( g_seekable_can_seek( seekable ) && g_seekable_can_truncate( seekable ) )
                {
                    if ( g_seekable_seek( seekable, 0, G_SEEK_END, NULL, NULL ) )
                    {
                        goffset file_size = g_seekable_tell( seekable );

                        file_size -= signature_length;

                        if ( g_seekable_truncate( seekable, file_size, NULL, NULL ) )
                        {
                            g_debug( "TRUNCATING FILE TO %" G_GOFFSET_FORMAT " BYTES", file_size );
                            result = true;
                        }
                    }
                }

                g_io_stream_close( G_IO_STREAM( stream ), NULL, NULL );

                g_object_unref( G_OBJECT( stream ) );
            }

            g_object_unref( G_OBJECT( file ) );
        }

        if ( ! result )
        {
            g_warning( "FAILED TO STRIP SIGNATURE(S)" );
        }

        return result;
    }