Wrap the inclusion of openssl/engine.h with a protective check for
[openssl.git] / crypto / store / str_lib.c
index ab3fd423b72de186e0bec11e7aded7b04fe9a1da..c0ad763e9a1cc4068f03e97a61e54891681a4c83 100644 (file)
 #include <string.h>
 #include <openssl/bn.h>
 #include <openssl/err.h>
+#ifndef OPENSSL_NO_ENGINE
 #include <openssl/engine.h>
+#endif
+#include <openssl/sha.h>
+#include <openssl/x509.h>
 #include "str_locl.h"
 
 const char * const STORE_object_type_string[STORE_OBJECT_TYPE_NUM+1] =
@@ -69,7 +73,8 @@ const char * const STORE_object_type_string[STORE_OBJECT_TYPE_NUM+1] =
        "X.509 CRL",
        "Private Key",
        "Public Key",
-       "Number"
+       "Number",
+       "Arbitrary Data"
        };
 
 const int STORE_param_sizes[STORE_PARAM_TYPE_NUM+1] =
@@ -101,19 +106,20 @@ STORE *STORE_new_method(const STORE_METHOD *method)
        {
        STORE *ret;
 
-       ret=(STORE *)OPENSSL_malloc(sizeof(STORE));
-       if (ret == NULL)
+       if (method == NULL)
                {
-               STOREerr(STORE_F_STORE_NEW_METHOD,ERR_R_MALLOC_FAILURE);
+               STOREerr(STORE_F_STORE_NEW_METHOD,ERR_R_PASSED_NULL_PARAMETER);
                return NULL;
                }
-       if (method == NULL)
+
+       ret=(STORE *)OPENSSL_malloc(sizeof(STORE));
+       if (ret == NULL)
                {
-               STOREerr(STORE_F_STORE_NEW_METHOD,ERR_R_PASSED_NULL_PARAMETER);
+               STOREerr(STORE_F_STORE_NEW_METHOD,ERR_R_MALLOC_FAILURE);
                return NULL;
                }
-       else
-               ret->meth=method;
+
+       ret->meth=method;
 
        CRYPTO_new_ex_data(CRYPTO_EX_INDEX_STORE, ret, &ret->ex_data);
        if (ret->meth->init && !ret->meth->init(ret))
@@ -182,6 +188,19 @@ void STORE_free(STORE *store)
        OPENSSL_free(store);
        }
 
+int STORE_ctrl(STORE *store, int cmd, long i, void *p, void (*f)(void))
+       {
+       if (store == NULL)
+               {
+               STOREerr(STORE_F_STORE_CTRL,ERR_R_PASSED_NULL_PARAMETER);
+               return 0;
+               }
+       if (store->meth->ctrl)
+               return store->meth->ctrl(store, cmd, i, p, f);
+       STOREerr(STORE_F_STORE_CTRL,STORE_R_NO_CONTROL_FUNCTION);
+       return 0;
+       }
+
 
 int STORE_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
             CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
@@ -261,15 +280,16 @@ X509 *STORE_get_certificate(STORE *s, OPENSSL_ITEM attributes[],
 int STORE_store_certificate(STORE *s, X509 *data, OPENSSL_ITEM attributes[],
        OPENSSL_ITEM parameters[])
        {
-       STORE_OBJECT *object = STORE_OBJECT_new();
+       STORE_OBJECT *object;
        int i;
 
        check_store(s,STORE_F_STORE_CERTIFICATE,
                store_object,STORE_R_NO_STORE_OBJECT_FUNCTION);
 
+       object = STORE_OBJECT_new();
        if (!object)
                {
-               STOREerr(STORE_F_STORE_CERTIFICATE,
+               STOREerr(STORE_F_STORE_STORE_CERTIFICATE,
                        ERR_R_MALLOC_FAILURE);
                return 0;
                }
@@ -287,13 +307,31 @@ int STORE_store_certificate(STORE *s, X509 *data, OPENSSL_ITEM attributes[],
 
        if (!i)
                {
-               STOREerr(STORE_F_STORE_CERTIFICATE,
+               STOREerr(STORE_F_STORE_STORE_CERTIFICATE,
                        STORE_R_FAILED_STORING_CERTIFICATE);
                return 0;
                }
        return 1;
        }
 
+int STORE_modify_certificate(STORE *s, OPENSSL_ITEM search_attributes[],
+       OPENSSL_ITEM add_attributes[], OPENSSL_ITEM modify_attributes[],
+       OPENSSL_ITEM delete_attributes[], OPENSSL_ITEM parameters[])
+       {
+       check_store(s,STORE_F_STORE_MODIFY_CERTIFICATE,
+               modify_object,STORE_R_NO_MODIFY_OBJECT_FUNCTION);
+
+       if (!s->meth->modify_object(s, STORE_OBJECT_TYPE_X509_CERTIFICATE,
+                   search_attributes, add_attributes, modify_attributes,
+                   delete_attributes, parameters))
+               {
+               STOREerr(STORE_F_STORE_MODIFY_CERTIFICATE,
+                       STORE_R_FAILED_MODIFYING_CERTIFICATE);
+               return 0;
+               }
+       return 1;
+       }
+
 int STORE_revoke_certificate(STORE *s, OPENSSL_ITEM attributes[],
        OPENSSL_ITEM parameters[])
        {
@@ -452,22 +490,23 @@ EVP_PKEY *STORE_get_private_key(STORE *s, OPENSSL_ITEM attributes[],
 int STORE_store_private_key(STORE *s, EVP_PKEY *data, OPENSSL_ITEM attributes[],
        OPENSSL_ITEM parameters[])
        {
-       STORE_OBJECT *object = STORE_OBJECT_new();
+       STORE_OBJECT *object;
        int i;
 
-       check_store(s,STORE_F_STORE_PRIVATE_KEY,
+       check_store(s,STORE_F_STORE_STORE_PRIVATE_KEY,
                store_object,STORE_R_NO_STORE_OBJECT_FUNCTION);
 
+       object = STORE_OBJECT_new();
        if (!object)
                {
-               STOREerr(STORE_F_STORE_PRIVATE_KEY,
+               STOREerr(STORE_F_STORE_STORE_PRIVATE_KEY,
                        ERR_R_MALLOC_FAILURE);
                return 0;
                }
        object->data.key = EVP_PKEY_new();
        if (!object->data.key)
                {
-               STOREerr(STORE_F_STORE_PRIVATE_KEY,
+               STOREerr(STORE_F_STORE_STORE_PRIVATE_KEY,
                        ERR_R_MALLOC_FAILURE);
                return 0;
                }
@@ -485,13 +524,31 @@ int STORE_store_private_key(STORE *s, EVP_PKEY *data, OPENSSL_ITEM attributes[],
 
        if (!i)
                {
-               STOREerr(STORE_F_STORE_PRIVATE_KEY,
+               STOREerr(STORE_F_STORE_STORE_PRIVATE_KEY,
                        STORE_R_FAILED_STORING_KEY);
                return 0;
                }
        return i;
        }
 
+int STORE_modify_private_key(STORE *s, OPENSSL_ITEM search_attributes[],
+       OPENSSL_ITEM add_attributes[], OPENSSL_ITEM modify_attributes[],
+       OPENSSL_ITEM delete_attributes[], OPENSSL_ITEM parameters[])
+       {
+       check_store(s,STORE_F_STORE_MODIFY_PRIVATE_KEY,
+               modify_object,STORE_R_NO_MODIFY_OBJECT_FUNCTION);
+
+       if (!s->meth->modify_object(s, STORE_OBJECT_TYPE_PRIVATE_KEY,
+                   search_attributes, add_attributes, modify_attributes,
+                   delete_attributes, parameters))
+               {
+               STOREerr(STORE_F_STORE_MODIFY_PRIVATE_KEY,
+                       STORE_R_FAILED_MODIFYING_PRIVATE_KEY);
+               return 0;
+               }
+       return 1;
+       }
+
 int STORE_revoke_private_key(STORE *s, OPENSSL_ITEM attributes[],
        OPENSSL_ITEM parameters[])
        {
@@ -628,22 +685,23 @@ EVP_PKEY *STORE_get_public_key(STORE *s, OPENSSL_ITEM attributes[],
 int STORE_store_public_key(STORE *s, EVP_PKEY *data, OPENSSL_ITEM attributes[],
        OPENSSL_ITEM parameters[])
        {
-       STORE_OBJECT *object = STORE_OBJECT_new();
+       STORE_OBJECT *object;
        int i;
 
-       check_store(s,STORE_F_STORE_PUBLIC_KEY,
+       check_store(s,STORE_F_STORE_STORE_PUBLIC_KEY,
                store_object,STORE_R_NO_STORE_OBJECT_FUNCTION);
 
+       object = STORE_OBJECT_new();
        if (!object)
                {
-               STOREerr(STORE_F_STORE_PUBLIC_KEY,
+               STOREerr(STORE_F_STORE_STORE_PUBLIC_KEY,
                        ERR_R_MALLOC_FAILURE);
                return 0;
                }
        object->data.key = EVP_PKEY_new();
        if (!object->data.key)
                {
-               STOREerr(STORE_F_STORE_PUBLIC_KEY,
+               STOREerr(STORE_F_STORE_STORE_PUBLIC_KEY,
                        ERR_R_MALLOC_FAILURE);
                return 0;
                }
@@ -661,13 +719,31 @@ int STORE_store_public_key(STORE *s, EVP_PKEY *data, OPENSSL_ITEM attributes[],
 
        if (!i)
                {
-               STOREerr(STORE_F_STORE_PUBLIC_KEY,
+               STOREerr(STORE_F_STORE_STORE_PUBLIC_KEY,
                        STORE_R_FAILED_STORING_KEY);
                return 0;
                }
        return i;
        }
 
+int STORE_modify_public_key(STORE *s, OPENSSL_ITEM search_attributes[],
+       OPENSSL_ITEM add_attributes[], OPENSSL_ITEM modify_attributes[],
+       OPENSSL_ITEM delete_attributes[], OPENSSL_ITEM parameters[])
+       {
+       check_store(s,STORE_F_STORE_MODIFY_PUBLIC_KEY,
+               modify_object,STORE_R_NO_MODIFY_OBJECT_FUNCTION);
+
+       if (!s->meth->modify_object(s, STORE_OBJECT_TYPE_PUBLIC_KEY,
+                   search_attributes, add_attributes, modify_attributes,
+                   delete_attributes, parameters))
+               {
+               STOREerr(STORE_F_STORE_MODIFY_PUBLIC_KEY,
+                       STORE_R_FAILED_MODIFYING_PUBLIC_KEY);
+               return 0;
+               }
+       return 1;
+       }
+
 int STORE_revoke_public_key(STORE *s, OPENSSL_ITEM attributes[],
        OPENSSL_ITEM parameters[])
        {
@@ -830,15 +906,16 @@ X509_CRL *STORE_get_crl(STORE *s, OPENSSL_ITEM attributes[],
 int STORE_store_crl(STORE *s, X509_CRL *data, OPENSSL_ITEM attributes[],
        OPENSSL_ITEM parameters[])
        {
-       STORE_OBJECT *object = STORE_OBJECT_new();
+       STORE_OBJECT *object;
        int i;
 
-       check_store(s,STORE_F_STORE_CRL,
+       check_store(s,STORE_F_STORE_STORE_CRL,
                store_object,STORE_R_NO_STORE_OBJECT_FUNCTION);
 
+       object = STORE_OBJECT_new();
        if (!object)
                {
-               STOREerr(STORE_F_STORE_CRL,
+               STOREerr(STORE_F_STORE_STORE_CRL,
                        ERR_R_MALLOC_FAILURE);
                return 0;
                }
@@ -856,13 +933,31 @@ int STORE_store_crl(STORE *s, X509_CRL *data, OPENSSL_ITEM attributes[],
 
        if (!i)
                {
-               STOREerr(STORE_F_STORE_CRL,
+               STOREerr(STORE_F_STORE_STORE_CRL,
                        STORE_R_FAILED_STORING_KEY);
                return 0;
                }
        return i;
        }
 
+int STORE_modify_crl(STORE *s, OPENSSL_ITEM search_attributes[],
+       OPENSSL_ITEM add_attributes[], OPENSSL_ITEM modify_attributes[],
+       OPENSSL_ITEM delete_attributes[], OPENSSL_ITEM parameters[])
+       {
+       check_store(s,STORE_F_STORE_MODIFY_CRL,
+               modify_object,STORE_R_NO_MODIFY_OBJECT_FUNCTION);
+
+       if (!s->meth->modify_object(s, STORE_OBJECT_TYPE_X509_CRL,
+                   search_attributes, add_attributes, modify_attributes,
+                   delete_attributes, parameters))
+               {
+               STOREerr(STORE_F_STORE_MODIFY_CRL,
+                       STORE_R_FAILED_MODIFYING_CRL);
+               return 0;
+               }
+       return 1;
+       }
+
 int STORE_delete_crl(STORE *s, OPENSSL_ITEM attributes[],
        OPENSSL_ITEM parameters[])
        {
@@ -953,15 +1048,16 @@ int STORE_list_crl_endp(STORE *s, void *handle)
 int STORE_store_number(STORE *s, BIGNUM *data, OPENSSL_ITEM attributes[],
        OPENSSL_ITEM parameters[])
        {
-       STORE_OBJECT *object = STORE_OBJECT_new();
+       STORE_OBJECT *object;
        int i;
 
-       check_store(s,STORE_F_STORE_NUMBER,
+       check_store(s,STORE_F_STORE_STORE_NUMBER,
                store_object,STORE_R_NO_STORE_OBJECT_NUMBER_FUNCTION);
 
+       object = STORE_OBJECT_new();
        if (!object)
                {
-               STOREerr(STORE_F_STORE_NUMBER,
+               STOREerr(STORE_F_STORE_STORE_NUMBER,
                        ERR_R_MALLOC_FAILURE);
                return 0;
                }
@@ -975,13 +1071,31 @@ int STORE_store_number(STORE *s, BIGNUM *data, OPENSSL_ITEM attributes[],
 
        if (!i)
                {
-               STOREerr(STORE_F_STORE_NUMBER,
+               STOREerr(STORE_F_STORE_STORE_NUMBER,
                        STORE_R_FAILED_STORING_NUMBER);
                return 0;
                }
        return 1;
        }
 
+int STORE_modify_number(STORE *s, OPENSSL_ITEM search_attributes[],
+       OPENSSL_ITEM add_attributes[], OPENSSL_ITEM modify_attributes[],
+       OPENSSL_ITEM delete_attributes[], OPENSSL_ITEM parameters[])
+       {
+       check_store(s,STORE_F_STORE_MODIFY_NUMBER,
+               modify_object,STORE_R_NO_MODIFY_OBJECT_FUNCTION);
+
+       if (!s->meth->modify_object(s, STORE_OBJECT_TYPE_NUMBER,
+                   search_attributes, add_attributes, modify_attributes,
+                   delete_attributes, parameters))
+               {
+               STOREerr(STORE_F_STORE_MODIFY_NUMBER,
+                       STORE_R_FAILED_MODIFYING_NUMBER);
+               return 0;
+               }
+       return 1;
+       }
+
 BIGNUM *STORE_get_number(STORE *s, OPENSSL_ITEM attributes[],
        OPENSSL_ITEM parameters[])
        {
@@ -1024,15 +1138,16 @@ int STORE_delete_number(STORE *s, OPENSSL_ITEM attributes[],
 int STORE_store_arbitrary(STORE *s, BUF_MEM *data, OPENSSL_ITEM attributes[],
        OPENSSL_ITEM parameters[])
        {
-       STORE_OBJECT *object = STORE_OBJECT_new();
+       STORE_OBJECT *object;
        int i;
 
-       check_store(s,STORE_F_STORE_ARBITRARY,
+       check_store(s,STORE_F_STORE_STORE_ARBITRARY,
                store_object,STORE_R_NO_STORE_OBJECT_ARBITRARY_FUNCTION);
 
+       object = STORE_OBJECT_new();
        if (!object)
                {
-               STOREerr(STORE_F_STORE_ARBITRARY,
+               STOREerr(STORE_F_STORE_STORE_ARBITRARY,
                        ERR_R_MALLOC_FAILURE);
                return 0;
                }
@@ -1046,13 +1161,31 @@ int STORE_store_arbitrary(STORE *s, BUF_MEM *data, OPENSSL_ITEM attributes[],
 
        if (!i)
                {
-               STOREerr(STORE_F_STORE_ARBITRARY,
+               STOREerr(STORE_F_STORE_STORE_ARBITRARY,
                        STORE_R_FAILED_STORING_ARBITRARY);
                return 0;
                }
        return 1;
        }
 
+int STORE_modify_arbitrary(STORE *s, OPENSSL_ITEM search_attributes[],
+       OPENSSL_ITEM add_attributes[], OPENSSL_ITEM modify_attributes[],
+       OPENSSL_ITEM delete_attributes[], OPENSSL_ITEM parameters[])
+       {
+       check_store(s,STORE_F_STORE_MODIFY_ARBITRARY,
+               modify_object,STORE_R_NO_MODIFY_OBJECT_FUNCTION);
+
+       if (!s->meth->modify_object(s, STORE_OBJECT_TYPE_ARBITRARY,
+                   search_attributes, add_attributes, modify_attributes,
+                   delete_attributes, parameters))
+               {
+               STOREerr(STORE_F_STORE_MODIFY_ARBITRARY,
+                       STORE_R_FAILED_MODIFYING_ARBITRARY);
+               return 0;
+               }
+       return 1;
+       }
+
 BUF_MEM *STORE_get_arbitrary(STORE *s, OPENSSL_ITEM attributes[],
        OPENSSL_ITEM parameters[])
        {
@@ -1283,7 +1416,7 @@ int STORE_ATTR_INFO_set_sha1str(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code,
                            (unsigned char *)BUF_memdup(sha1str,
                                    sha1str_size)))
                        return 1;
-               STOREerr(STORE_F_STORE_ATTR_INFO_SET_CSTR,
+               STOREerr(STORE_F_STORE_ATTR_INFO_SET_SHA1STR,
                        ERR_R_MALLOC_FAILURE);
                return 0;
                }
@@ -1303,7 +1436,7 @@ int STORE_ATTR_INFO_set_dn(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code,
                {
                if ((attrs->values[code].dn = X509_NAME_dup(dn)))
                        return 1;
-               STOREerr(STORE_F_STORE_ATTR_INFO_SET_CSTR,
+               STOREerr(STORE_F_STORE_ATTR_INFO_SET_DN,
                        ERR_R_MALLOC_FAILURE);
                return 0;
                }
@@ -1323,7 +1456,7 @@ int STORE_ATTR_INFO_set_number(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code,
                {
                if ((attrs->values[code].number = BN_dup(number)))
                        return 1;
-               STOREerr(STORE_F_STORE_ATTR_INFO_SET_CSTR,
+               STOREerr(STORE_F_STORE_ATTR_INFO_SET_NUMBER,
                        ERR_R_MALLOC_FAILURE);
                return 0;
                }
@@ -1412,11 +1545,11 @@ void *STORE_parse_attrs_start(OPENSSL_ITEM *attributes)
                if (context)
                        context->attributes = attributes;
                else
-                       STOREerr(STORE_F_STORE_PARSE_ATTRS_END,
+                       STOREerr(STORE_F_STORE_PARSE_ATTRS_START,
                                ERR_R_MALLOC_FAILURE);
                return context;
                }
-       STOREerr(STORE_F_STORE_PARSE_ATTRS_END, ERR_R_PASSED_NULL_PARAMETER);
+       STOREerr(STORE_F_STORE_PARSE_ATTRS_START, ERR_R_PASSED_NULL_PARAMETER);
        return 0;
        }
 STORE_ATTR_INFO *STORE_parse_attrs_next(void *handle)
@@ -1532,25 +1665,98 @@ int STORE_parse_attrs_endp(void *handle)
                {
                return context->attributes->code == STORE_ATTR_END;
                }
-       STOREerr(STORE_F_STORE_PARSE_ATTRS_END, ERR_R_PASSED_NULL_PARAMETER);
+       STOREerr(STORE_F_STORE_PARSE_ATTRS_ENDP, ERR_R_PASSED_NULL_PARAMETER);
        return 0;
        }
 
-int STORE_ATTR_INFO_compare(STORE_ATTR_INFO *a, STORE_ATTR_INFO *b)
+static int attr_info_compare_compute_range(
+       unsigned char *abits, unsigned char *bbits,
+       unsigned int *alowp, unsigned int *ahighp,
+       unsigned int *blowp, unsigned int *bhighp)
        {
-       unsigned char *abits, *bbits;
-       int i;
+       unsigned int alow = (unsigned int)-1, ahigh = 0;
+       unsigned int blow = (unsigned int)-1, bhigh = 0;
+       int i, res = 0;
 
-       if (a == b) return 0;
-       if (!a) return -1;
-       if (!b) return 1;
-       abits = a->set;
-       bbits = b->set;
        for (i = 0; i < (STORE_ATTR_TYPE_NUM + 8) / 8; i++, abits++, bbits++)
                {
-               if (*abits < *bbits) return -1;
-               if (*abits > *bbits) return 1;
+               if (res == 0)
+                       {
+                       if (*abits < *bbits) res = -1;
+                       if (*abits > *bbits) res = 1;
+                       }
+               if (*abits)
+                       {
+                       if (alow == (unsigned int)-1)
+                               {
+                               alow = i * 8;
+                               if (!(*abits & 0x01)) alow++;
+                               if (!(*abits & 0x02)) alow++;
+                               if (!(*abits & 0x04)) alow++;
+                               if (!(*abits & 0x08)) alow++;
+                               if (!(*abits & 0x10)) alow++;
+                               if (!(*abits & 0x20)) alow++;
+                               if (!(*abits & 0x40)) alow++;
+                               }
+                       ahigh = i * 8 + 7;
+                       if (!(*abits & 0x80)) ahigh++;
+                       if (!(*abits & 0x40)) ahigh++;
+                       if (!(*abits & 0x20)) ahigh++;
+                       if (!(*abits & 0x10)) ahigh++;
+                       if (!(*abits & 0x08)) ahigh++;
+                       if (!(*abits & 0x04)) ahigh++;
+                       if (!(*abits & 0x02)) ahigh++;
+                       }
+               if (*bbits)
+                       {
+                       if (blow == (unsigned int)-1)
+                               {
+                               blow = i * 8;
+                               if (!(*bbits & 0x01)) blow++;
+                               if (!(*bbits & 0x02)) blow++;
+                               if (!(*bbits & 0x04)) blow++;
+                               if (!(*bbits & 0x08)) blow++;
+                               if (!(*bbits & 0x10)) blow++;
+                               if (!(*bbits & 0x20)) blow++;
+                               if (!(*bbits & 0x40)) blow++;
+                               }
+                       bhigh = i * 8 + 7;
+                       if (!(*bbits & 0x80)) bhigh++;
+                       if (!(*bbits & 0x40)) bhigh++;
+                       if (!(*bbits & 0x20)) bhigh++;
+                       if (!(*bbits & 0x10)) bhigh++;
+                       if (!(*bbits & 0x08)) bhigh++;
+                       if (!(*bbits & 0x04)) bhigh++;
+                       if (!(*bbits & 0x02)) bhigh++;
+                       }
                }
+       if (ahigh + alow < bhigh + blow) res = -1;
+       if (ahigh + alow > bhigh + blow) res = 1;
+       if (alowp) *alowp = alow;
+       if (ahighp) *ahighp = ahigh;
+       if (blowp) *blowp = blow;
+       if (bhighp) *bhighp = bhigh;
+       return res;
+       }
+
+int STORE_ATTR_INFO_compare(STORE_ATTR_INFO *a, STORE_ATTR_INFO *b)
+       {
+       if (a == b) return 0;
+       if (!a) return -1;
+       if (!b) return 1;
+       return attr_info_compare_compute_range(a->set, b->set, 0, 0, 0, 0);
+       }
+int STORE_ATTR_INFO_in_range(STORE_ATTR_INFO *a, STORE_ATTR_INFO *b)
+       {
+       unsigned int alow, ahigh, blow, bhigh;
+
+       if (a == b) return 1;
+       if (!a) return 0;
+       if (!b) return 0;
+       attr_info_compare_compute_range(a->set, b->set,
+               &alow, &ahigh, &blow, &bhigh);
+       if (alow >= blow && ahigh <= bhigh)
+               return 1;
        return 0;
        }
 int STORE_ATTR_INFO_in(STORE_ATTR_INFO *a, STORE_ATTR_INFO *b)
@@ -1565,7 +1771,7 @@ int STORE_ATTR_INFO_in(STORE_ATTR_INFO *a, STORE_ATTR_INFO *b)
        bbits = b->set;
        for (i = 0; i < (STORE_ATTR_TYPE_NUM + 8) / 8; i++, abits++, bbits++)
                {
-               if (*abits && *bbits != *abits)
+               if (*abits && (*bbits & *abits) != *abits)
                        return 0;
                }
        return 1;