Browse Source

* rename source file

* downgrade plugin interface to v1
master
Alex 'AdUser' Z 9 years ago
parent
commit
41ccd869cf
  1. 50
      src/plugin.c

50
src/main.c → src/plugin.c

@ -7,7 +7,7 @@
#include "config.h" #include "config.h"
#include "ldapauth.h" #include "ldapauth.h"
static const char *OAL_NAME = "openvpn-ldap-auth"; /* static const char *OAL_NAME = "openvpn-ldap-auth"; */
/** /**
* Given an environmental variable name, search * Given an environmental variable name, search
@ -34,47 +34,45 @@ get_env (const char *name, const char *envp[]) {
return NULL; return NULL;
} }
OPENVPN_EXPORT int openvpn_plugin_min_version_required_v1(void)
{
return 3;
}
OPENVPN_EXPORT int OPENVPN_EXPORT int
openvpn_plugin_open_v3 (const int v3structver, openvpn_plugin_min_version_required_v1(void) { return 1; }
struct openvpn_plugin_args_open_in const *args,
struct openvpn_plugin_args_open_return *ret) OPENVPN_EXPORT openvpn_plugin_handle_t
openvpn_plugin_open_v1 (unsigned int *type_mask,
const char *argv[],
const char *envp[])
{ {
oal_config_t *config; oal_config_t *config;
if (v3structver != OPENVPN_PLUGINv3_STRUCTVER) if (!argv[1]) {
return OPENVPN_PLUGIN_FUNC_ERROR; fprintf(stderr, "no config provided");
return NULL;
}
config = (oal_config_t *) calloc (1, sizeof (oal_config_t)); config = (oal_config_t *) calloc (1, sizeof (oal_config_t));
if (parse_config(config, args->argv[0]) != 0) { if (parse_config(config, argv[1]) != 0) {
args->callbacks->plugin_log(PLOG_ERR, OAL_NAME, fprintf(stderr, "config parser failed: %s", config->error);
"config parser failed: %s", config->error); return NULL;
return OPENVPN_PLUGIN_FUNC_ERROR;
} }
ret->type_mask = OPENVPN_PLUGIN_MASK (OPENVPN_PLUGIN_AUTH_USER_PASS_VERIFY); *type_mask = OPENVPN_PLUGIN_MASK (OPENVPN_PLUGIN_AUTH_USER_PASS_VERIFY);
ret->handle = (void *) config; return (openvpn_plugin_handle_t) config;
return OPENVPN_PLUGIN_FUNC_SUCCESS;
} }
OPENVPN_EXPORT int OPENVPN_EXPORT int
openvpn_plugin_func_v3 (const int version, openvpn_plugin_func_v1 (openvpn_plugin_handle_t handle,
struct openvpn_plugin_args_func_in const *args, const int type,
struct openvpn_plugin_args_func_return *retptr) const char *argv[],
const char *envp[])
{ {
oal_config_t *config = (oal_config_t *) args->handle; oal_config_t *config = (oal_config_t *) handle;
/* get username/password from envp string array */ /* get username/password from envp string array */
const char *username = get_env("username", args->envp); const char *username = get_env("username", envp);
const char *password = get_env("password", args->envp); const char *password = get_env("password", envp);
if (args->type == OPENVPN_PLUGIN_AUTH_USER_PASS_VERIFY) { if (type == OPENVPN_PLUGIN_AUTH_USER_PASS_VERIFY) {
/* check entered username/password against what we require */ /* check entered username/password against what we require */
if (check_against_ldap(config, username, password) == 0) if (check_against_ldap(config, username, password) == 0)
return OPENVPN_PLUGIN_FUNC_SUCCESS; return OPENVPN_PLUGIN_FUNC_SUCCESS;
Loading…
Cancel
Save