-/* read_authz returns a newly allocated buffer with authz data */
-static unsigned char *read_authz(const char *file, size_t *authz_length)
- {
- BIO *authz_in = NULL;
- unsigned char *authz = NULL;
- /* Allow authzs up to 64KB. */
- static const size_t authz_limit = 65536;
- size_t read_length;
- unsigned char *ret = NULL;
-
- authz_in = BIO_new(BIO_s_file_internal());
- if (authz_in == NULL)
- {
- SSLerr(SSL_F_READ_AUTHZ,ERR_R_BUF_LIB);
- goto end;
- }
-
- if (BIO_read_filename(authz_in,file) <= 0)
- {
- SSLerr(SSL_F_READ_AUTHZ,ERR_R_SYS_LIB);
- goto end;
- }
-
- authz = OPENSSL_malloc(authz_limit);
- read_length = BIO_read(authz_in, authz, authz_limit);
- if (read_length == authz_limit || read_length <= 0)
- {
- SSLerr(SSL_F_READ_AUTHZ,SSL_R_AUTHZ_DATA_TOO_LARGE);
- OPENSSL_free(authz);
- goto end;
- }
- *authz_length = read_length;
- ret = authz;
-end:
- if (authz_in != NULL) BIO_free(authz_in);
- return ret;
- }
-
-int SSL_CTX_use_authz_file(SSL_CTX *ctx, const char *file)
- {
- unsigned char *authz = NULL;
- size_t authz_length = 0;
- int ret;
-
- authz = read_authz(file, &authz_length);
- if (authz == NULL)
- return 0;
-
- ret = SSL_CTX_use_authz(ctx, authz, authz_length);
- /* SSL_CTX_use_authz makes a local copy of the authz. */
- OPENSSL_free(authz);
- return ret;
- }
-
-int SSL_use_authz_file(SSL *ssl, const char *file)
- {
- unsigned char *authz = NULL;
- size_t authz_length = 0;
- int ret;
-
- authz = read_authz(file, &authz_length);
- if (authz == NULL)
- return 0;
-
- ret = SSL_use_authz(ssl, authz, authz_length);
- /* SSL_use_authz makes a local copy of the authz. */
- OPENSSL_free(authz);
- return ret;
- }
-