Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include "openvpn-plugin.h"
- #include <curl/curl.h>
- typedef char* string;
- typedef int BOOL;
- #define AppendString(x, y) x[strlen(x)] = y
- #define FALSE 0
- #define TRUE 1
- #define ENABLE_CRYPTO
- #define SERVER_TOKEN "temp"
- #define HOST "localhost////?server_token=" SERVER_TOKEN "&"
- OPENVPN_EXPORT int openvpn_plugin_func_v3(
- const int version,
- struct openvpn_plugin_args_func_in const* args,
- struct openvpn_plugin_args_func_return* retptr)
- {
- if (args->type == OPENVPN_PLUGIN_AUTH_USER_PASS_VERIFY) {
- CURL *curl;
- CURLcode res;
- curl = curl_easy_init();
- if (!curl) {
- return OPENVPN_PLUGIN_FUNC_ERROR;
- }
- const char* _username = get_env("username", args->envp);
- const char* _password = get_env("password", args->envp);
- const char* username = curl_easy_escape(curl, _username, strlen(_username));
- const char* password = curl_easy_escape(curl, _password, strlen(_username));
- char* url = HOST;
- AppendString(url, "username=");
- AppendString(url, username);
- AppendString(url, "&password=");
- AppendString(url, password);
- curl_easy_setopt(curl, CURLOPT_URL, url);
- res = curl_easy_perform(curl);
- if (res != CURLE_OK) {
- return OPENVPN_PLUGIN_FUNC_ERROR;
- }
- else {
- return OPENVPN_PLUGIN_FUNC_SUCCESS;
- }
- }
- }
- static string get_env(
- string env[],
- string name)
- {
- for (int i = 0; env[i] != NULL; i++) {
- if (StartsWith(env[i], name) == TRUE) {
- return (string)(&env[i][0] + StringLength(name));
- }
- }
- return NULL;
- }
- static BOOL StartsWith(
- string sig,
- string to_match)
- {
- int sig_length = strlen(sig);
- int to_match_length = strlen(to_match);
- if (sig_length < to_match_length) {
- return FALSE;
- }
- for (int i = 0; i < to_match_length; i++) {
- if (sig[i] != to_match[i]) {
- return FALSE;
- }
- }
- return TRUE;
- }
- static int strlen(
- string string)
- {
- int length = 0;
- while (string[length++] != '\0');
- return length - 1;
- }
- static string urlencode(
- string data)
- {
- string output = "";
- string temp = "";
- int length = strlen(data);
- for (int i = 0; i < length; i++) {
- if ((data[i] > 'a' || data[i] < 'Z') || (data[i] > '1' || data[i] < '0')) {
- AppendString(output, data[i]);
- }
- else {
- temp = "\0\0\0\0";
- sprintf(temp, "%X", data[i]);
- if (strlgn(temp) == 2) {
- temp[0] = '%';
- temp[2] = temp[1];
- temp[1] = '0';
- }
- AppendString(output, temp);
- }
- }
- temp = "\0\0\0\0";
- return output;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement