- {
- int to_return = 1;
- if(e == NULL)
- {
- ENGINEerr(ENGINE_F_ENGINE_REMOVE,
- ERR_R_PASSED_NULL_PARAMETER);
- return 0;
- }
- CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
- if(!engine_internal_check() || !engine_list_remove(e))
- {
- ENGINEerr(ENGINE_F_ENGINE_REMOVE,
- ENGINE_R_INTERNAL_LIST_ERROR);
- to_return = 0;
- }
- CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
- return to_return;
- }
-
-ENGINE *ENGINE_by_id(const char *id)
- {
- ENGINE *iterator = NULL, *cp = NULL;
- if(id == NULL)
- {
- ENGINEerr(ENGINE_F_ENGINE_BY_ID,
- ERR_R_PASSED_NULL_PARAMETER);
- return NULL;
- }
- CRYPTO_r_lock(CRYPTO_LOCK_ENGINE);
- if(!engine_internal_check())
- ENGINEerr(ENGINE_F_ENGINE_BY_ID,
- ENGINE_R_INTERNAL_LIST_ERROR);
- else
- {
- iterator = engine_list_head;
- while(iterator && (strcmp(id, iterator->id) != 0))
- iterator = iterator->next;
- if(iterator)
- {
- /* We need to return a structural reference. If this is
- * a "dynamic" ENGINE type, make a duplicate - otherwise
- * increment the existing ENGINE's reference count. */
- if(iterator->flags & ENGINE_FLAGS_BY_ID_COPY)
- {
- cp = ENGINE_new();
- if(!cp)
- iterator = NULL;
- else
- {
- ENGINE_cpy(cp, iterator);
- iterator = cp;
- }
- }
- else
- {
- iterator->struct_ref++;
- engine_ref_debug(iterator, 0, 1)
- }
- }
- }
- CRYPTO_r_unlock(CRYPTO_LOCK_ENGINE);
- if(iterator == NULL)
- ENGINEerr(ENGINE_F_ENGINE_BY_ID,
- ENGINE_R_NO_SUCH_ENGINE);
- return iterator;
- }
-
-ENGINE *ENGINE_new(void)
- {
- ENGINE *ret;
-
- ret = (ENGINE *)OPENSSL_malloc(sizeof(ENGINE));
- if(ret == NULL)
- {
- ENGINEerr(ENGINE_F_ENGINE_NEW, ERR_R_MALLOC_FAILURE);
- return NULL;
- }
- memset(ret, 0, sizeof(ENGINE));
- ret->struct_ref = 1;
- engine_ref_debug(ret, 0, 1)
- CRYPTO_new_ex_data(CRYPTO_EX_INDEX_ENGINE, ret, &ret->ex_data);
- return ret;
- }
-
-static int ENGINE_free_util(ENGINE *e, int locked)
- {
- int i;
-
- if(e == NULL)
- {
- ENGINEerr(ENGINE_F_ENGINE_FREE,
- ERR_R_PASSED_NULL_PARAMETER);
- return 0;
- }
- if(locked)
- i = CRYPTO_add(&e->struct_ref,-1,CRYPTO_LOCK_ENGINE);
- else
- i = --e->struct_ref;
- engine_ref_debug(e, 0, -1)
- if (i > 0) return 1;
-#ifdef REF_CHECK
- if (i < 0)
- {
- fprintf(stderr,"ENGINE_free, bad structural reference count\n");
- abort();
- }
-#endif
- /* Give the ENGINE a chance to do any structural cleanup corresponding
- * to allocation it did in its constructor (eg. unload error strings) */
- if(e->destroy)
- e->destroy(e);
- sk_ENGINE_EVP_CIPHER_pop_free(e->ciphers,ENGINE_free_engine_cipher);
- CRYPTO_free_ex_data(CRYPTO_EX_INDEX_ENGINE, e, &e->ex_data);
- OPENSSL_free(e);
- return 1;
- }
-
-int ENGINE_free(ENGINE *e)
- {
- return ENGINE_free_util(e, 1);
- }
-
-int ENGINE_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
- CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
- {
- return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_ENGINE, argl, argp,
- new_func, dup_func, free_func);
- }
-
-int ENGINE_set_ex_data(ENGINE *e, int idx, void *arg)
- {
- return(CRYPTO_set_ex_data(&e->ex_data, idx, arg));
- }
-
-void *ENGINE_get_ex_data(const ENGINE *e, int idx)
- {
- return(CRYPTO_get_ex_data(&e->ex_data, idx));
- }
-
-void ENGINE_cleanup(void)
- {
- ENGINE *iterator = engine_list_head;
-
- while(iterator != NULL)
- {
- ENGINE_remove(iterator);
- iterator = engine_list_head;
- }
- engine_list_flag = 0;
- /* Also unset any "default" ENGINEs that may have been set up (a default
- * constitutes a functional reference on an ENGINE and there's one for
- * each algorithm). */
- ENGINE_clear_defaults();
- return;
- }
-
-int ENGINE_set_id(ENGINE *e, const char *id)
- {
- if(id == NULL)
- {
- ENGINEerr(ENGINE_F_ENGINE_SET_ID,
- ERR_R_PASSED_NULL_PARAMETER);
- return 0;
- }
- e->id = id;
- return 1;
- }
-
-int ENGINE_set_name(ENGINE *e, const char *name)
- {
- if(name == NULL)
- {
- ENGINEerr(ENGINE_F_ENGINE_SET_NAME,
- ERR_R_PASSED_NULL_PARAMETER);
- return 0;
- }
- e->name = name;
- return 1;
- }
-
-int ENGINE_set_RSA(ENGINE *e, const RSA_METHOD *rsa_meth)
- {