Exemplo n.º 1
0
/* ----------------------------------------------------------------------------- */
static bool has_col( const VTable * tab, const char * colname )
{
    bool res = false;
    struct KNamelist * columns;
    rc_t rc = VTableListReadableColumns( tab, &columns );
    if ( rc == 0 )
    {
        uint32_t count;
        rc = KNamelistCount( columns, &count );
        if ( rc == 0 && count > 0 )
        {
            uint32_t idx;
            size_t colname_size = string_size( colname );
            for ( idx = 0; idx < count && rc == 0 && !res; ++idx )
            {
                const char * a_name;
                rc = KNamelistGet ( columns, idx, &a_name );
                if ( rc == 0 )
                {
                    int cmp;
                    size_t a_name_size = string_size( a_name );
                    uint32_t max_chars = ( uint32_t )colname_size;
                    if ( a_name_size > max_chars ) max_chars = ( uint32_t )a_name_size;
                    cmp = strcase_cmp ( colname, colname_size,
                                        a_name, a_name_size,
                                        max_chars );
                    res = ( cmp == 0 );
                }
            }
        }
        KNamelistRelease( columns );
    }
    return res;
}
Exemplo n.º 2
0
static
rc_t CC
XFS_KeyType_ZHR ( const char * EncType, KKeyType * Type )
{
    size_t B;
    const char * C;

    B = 0;
    C = NULL;

    XFS_CAN ( Type )
    * Type = kkeyNone;

    if ( EncType == NULL ) {
        * Type = KKeyTypeDefault;
        return 0;
    }

    B = string_size ( EncType );

    C = "AES128";
    if ( strcase_cmp ( C, string_size ( C ), EncType, B, B ) == 0 ) {
        * Type = kkeyAES128;
        return 0;
    }

    C = "AES192";
    if ( strcase_cmp ( C, string_size ( C ), EncType, B, B ) == 0 ) {
        * Type = kkeyAES192;
        return 0;
    }

    C = "AES256";
    if ( strcase_cmp ( C, string_size ( C ), EncType, B, B ) == 0 ) {
        * Type = kkeyAES256;
        return 0;
    }

    return XFS_RC ( rcInvalid );
}   /* XFS_KeyType_ZHR () */
Exemplo n.º 3
0
static rc_t CC scan_config_dir(const KDirectory* dir,
    uint32_t type, const char* name, void* data)
{
    rc_t rc = 0;
    assert(data);
    switch (type) {
        case kptFile:
        case kptFile | kptAlias: {
            size_t sz = strlen(name);
            if (sz >= 5 && strcase_cmp(&name[sz - 4], 4, ".kfg", 4, 4) == 0) {
                strcpy(data, name);
                rc = RC(rcExe, rcDirectory, rcListing, rcFile, rcExists);
            }
            break;
        }
    }
    return rc;
}
Exemplo n.º 4
0
static
rc_t CC KWGAEncFileRead	(const KWGAEncFile *cself,
                         uint64_t pos,
                         void *buffer,
                         size_t bsize,
                         size_t *num_read)
{
    KWGAEncFile * self = (KWGAEncFile *)cself; /* mutable values */
    rc_t rc = 0;

    assert (cself);
    assert (buffer);
    assert (num_read);


    *num_read = 0;

    /* are we even within the file? If not just say no. Drugs are bad Mmmkay */
    if (pos >= self->file_size)
    {}
    /* are we not reading from out what is already in the decrypted buffer space? */
    else
    {
        if ((self->buffer.valid == 0) ||
            (pos < self->buffer.offset) ||
            (pos >= (self->buffer.offset + self->buffer.valid)))
        {
            if (pos < self->block_size) /* we'll be reading from the first 'block' */
            {
                rc = KWGAEncFileReadInt (self, 0, self->block_size);
                if (rc)
                {
                    LOGERR (klogErr, rc, "error reading first data block of"
                            " encrypted file");
                    return rc;
                }
                if (self->buffer.valid > self->block_size)
                {
                    rc = RC (rcFS, rcFile, rcReading, rcBuffer, rcTooBig);
                    LOGERR (klogInt, rc, "read wrong amount for first block");
                    return rc;
                }
                else
                {
                    size_t md5_size;
                    size_t nudge = 0;
                    char md51_comp [32];

                    if (self->buffer.valid & (ECB_BYTES-1))
                        nudge = ECB_BYTES - (self->buffer.valid & (ECB_BYTES-1));
                    if (nudge)
                        memset (self->buffer.data + self->buffer.valid, 0, nudge);

                    md5_size = self->buffer.valid + nudge;

                    CalcMD5 (self->buffer.data, md5_size, md51_comp);

#if 1
                    if (strcase_cmp (self->md51, string_size(self->md51),
                                     md51_comp, string_size(md51_comp), 32) != 0)
#else
                    if (strncasecmp (self->md51, md51_comp, 32) != 0)
#endif
                    {
                        rc = RC (rcFS, rcFile, rcReading, rcConstraint, rcCorrupt);
                        LOGERR (klogErr, rc, "MD5 does not match in decryption");
                        return rc;
                    }
                }
            }
            else /* if (pos >= self->block_size) */
            {
                rc = KWGAEncFileReadInt (self, (pos & ~ ( uint64_t ) (16-1)),
                                         DEFAULT_BUFF_SIZE);
                if (rc)
                {
                    LOGERR (klogErr, rc, "error reading data block of"
                            " encrypted file");
                    return rc;
                }
            }  /* if (pos < self->block_size) */
        } /* if ((self->buffer.valid == 0) || etc. */
        /* if here we have a valid buffer and it contains the start pos requested */
/*     assert (pos >= self->buffer.offset); */
/*     assert (pos < (self->buffer.offset +self->buffer.valid)); */
        {
            size_t start;
            size_t limit;

            /* find offset of start for copy within the buffer */
            start = (size_t)(pos - self->buffer.offset);
            /* how many bytes available starting here */
            limit = self->buffer.valid - start;

            if (pos + limit > self->file_size)
                limit = self->file_size - pos;

            /* are we asking to read more than we have? is so trim the request */
            if (limit < bsize)
                bsize = limit;

            memmove (buffer, self->buffer.data + start, bsize);
            *num_read = bsize;
        }
    }
    return 0;
}
Exemplo n.º 5
0
static int rgn_str_cmp( const char *a, const char *b )
{
    size_t asize = string_size ( a );
    size_t bsize = string_size ( b );
    return strcase_cmp ( a, asize, b, bsize, ( asize > bsize ) ? asize : bsize );
}
Exemplo n.º 6
0
static int sized_str_cmp( const char *a, const char *b )
{
    size_t asize = string_size ( a );
    size_t bsize = string_size ( b );
    return strcase_cmp ( a, asize, b, bsize, (uint32_t) ( ( asize > bsize ) ? asize : bsize ) );
}