/* Compile with:
 * gcc -fPIC -shared -o weakcrypto.so weakcrypto.c -ldl
 */
#define _GNU_SOURCE
#include <krb5/krb5.h>
#include <dlfcn.h>
#include <errno.h>

krb5_error_code
wrap(krb5_context *context, const char *fn)
{
	krb5_error_code (*real_fn)(krb5_context *);
	krb5_error_code ret;

	real_fn = dlsym(RTLD_NEXT, fn);

	if (real_fn == NULL) {
		errno = ELIBACC;
		return -1;
	}

	ret = real_fn(context);

	krb5_allow_weak_crypto(*context, 1);

	return ret;
}

__attribute__((__visibility__("default")))
krb5_error_code
krb5_init_context(krb5_context *context) {
	return wrap(context, "krb5_init_context");
}

__attribute__((__visibility__("default")))
krb5_error_code
krb5_init_secure_context(krb5_context *context) {
	return wrap(context, "krb5_init_secure_context");
}
