From 2db7e7236c61f8ee346800c82c800eafcd65de4e Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Sun, 5 Apr 2015 14:05:28 +0300 Subject: [PATCH] Some fixes in C-C++ bridge in rlm_stg. --- projects/rlm_stg/event.h | 57 ---------- projects/rlm_stg/iface.cpp | 104 +++++++++++++++--- projects/rlm_stg/iface.h | 16 +-- projects/rlm_stg/rlm_stg.c | 182 +++++++++++++++++++------------- projects/rlm_stg/stg_client.cpp | 29 ++--- projects/rlm_stg/stg_client.h | 35 ++---- projects/rlm_stg/stgpair.c | 6 ++ projects/rlm_stg/stgpair.h | 4 + 8 files changed, 242 insertions(+), 191 deletions(-) delete mode 100644 projects/rlm_stg/event.h create mode 100644 projects/rlm_stg/stgpair.c diff --git a/projects/rlm_stg/event.h b/projects/rlm_stg/event.h deleted file mode 100644 index 83a72d01..00000000 --- a/projects/rlm_stg/event.h +++ /dev/null @@ -1,57 +0,0 @@ -#ifndef FR_EVENT_H -#define FR_EVENT_H - -/* - * event.h Simple event queue - * - * Version: $Id: event.h,v 1.1 2010/08/14 04:13:52 faust Exp $ - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA - * - * Copyright 2007 The FreeRADIUS server project - * Copyright 2007 Alan DeKok - */ - -//#include -//RCSIDH(event_h, "$Id: event.h,v 1.1 2010/08/14 04:13:52 faust Exp $") - -typedef struct fr_event_list_t fr_event_list_t; -typedef struct fr_event_t fr_event_t; - -typedef void (*fr_event_callback_t)(void *); -typedef void (*fr_event_status_t)(struct timeval *); -typedef void (*fr_event_fd_handler_t)(fr_event_list_t *el, int sock, void *ctx); - -fr_event_list_t *fr_event_list_create(fr_event_status_t status); -void fr_event_list_free(fr_event_list_t *el); - -int fr_event_list_num_elements(fr_event_list_t *el); - -int fr_event_insert(fr_event_list_t *el, - fr_event_callback_t callback, - void *ctx, struct timeval *when, fr_event_t **ev_p); -int fr_event_delete(fr_event_list_t *el, fr_event_t **ev_p); - -int fr_event_run(fr_event_list_t *el, struct timeval *when); - -int fr_event_now(fr_event_list_t *el, struct timeval *when); - -int fr_event_fd_insert(fr_event_list_t *el, int type, int fd, - fr_event_fd_handler_t handler, void *ctx); -int fr_event_fd_delete(fr_event_list_t *el, int type, int fd); -int fr_event_loop(fr_event_list_t *el); -void fr_event_loop_exit(fr_event_list_t *el, int code); - -#endif /* FR_HASH_H */ diff --git a/projects/rlm_stg/iface.cpp b/projects/rlm_stg/iface.cpp index a74f3259..40a96f72 100644 --- a/projects/rlm_stg/iface.cpp +++ b/projects/rlm_stg/iface.cpp @@ -1,41 +1,115 @@ #include "iface.h" -#include "thriftclient.h" +#include "stg_client.h" -int stgInstantiateImpl(const char * server, uint16_t port, const char * password) +namespace { - if (STG_CLIENT_ST::Get().Configure(server, port, password)) + +STG_PAIR* toPairs(const PAIRS& source) +{ + STG_PAIR * pairs = new STG_PAIR[source.size() + 1]; + for (size_t pos = 0; pos < source.size(); ++pos) { + bzero(pairs[pos].key, sizeof(STG_PAIR::key)); + bzero(pairs[pos].value, sizeof(STG_PAIR::value)); + strncpy(pairs[pos].key, source[pos].first.c_str(), sizeof(STG_PAIR::key)); + strncpy(pairs[pos].value, source[pos].second.c_str(), sizeof(STG_PAIR::value)); + ++pos; + } + bzero(pairs[sources.size()].key, sizeof(STG_PAIR::key)); + bzero(pairs[sources.size()].value, sizeof(STG_PAIR::value)); + + return pairs; +} + +} + +int stgInstantiateImpl(const char* server, uint16_t port, const char* password) +{ + if (STG_CLIENT::configure(server, port, password)) return 1; return 0; } -const STG_PAIR * stgAuthorizeImpl(const char * userName, const char * serviceType) +const STG_PAIR* stgAuthorizeImpl(const char* userName, const char* serviceType) { - return STG_CLIENT_ST::Get().Authorize(userName, serviceType); + STG_CLIENT* client = STG_CLIENT::get(); + if (client == NULL) { + // TODO: log "Not configured" + return NULL; + } + return toPairs(client->authorize(userName, serviceType)); } -const STG_PAIR * stgAuthenticateImpl(const char * userName, const char * serviceType) +const STG_PAIR* stgAuthenticateImpl(const char* userName, const char* serviceType) { - return STG_CLIENT_ST::Get().Authenticate(userName, serviceType); + STG_CLIENT* client = STG_CLIENT::get(); + if (client == NULL) { + // TODO: log "Not configured" + return NULL; + } + return toPairs(client->authenticate(userName, serviceType)); } -const STG_PAIR * stgPostAuthImpl(const char * userName, const char * serviceType) +const STG_PAIR* stgPostAuthImpl(const char* userName, const char* serviceType) { - return STG_CLIENT_ST::Get().PostAuth(userName, serviceType); + STG_CLIENT* client = STG_CLIENT::get(); + if (client == NULL) { + // TODO: log "Not configured" + return NULL; + } + return toPairs(client->postAuth(userName, serviceType)); } -/*const STG_PAIR * stgPreAcctImpl(const char * userName, const char * serviceType) +const STG_PAIR* stgPreAcctImpl(const char* userName, const char* serviceType) { - return STG_CLIENT_ST::Get().PreAcct(userName, serviceType); -}*/ + STG_CLIENT* client = STG_CLIENT::get(); + if (client == NULL) { + // TODO: log "Not configured" + return NULL; + } + return toPairs(client->preAcct(userName, serviceType)); +} + +const STG_PAIR* stgAccountingImpl(const char* userName, const char* serviceType, const char* statusType, const char* sessionId) +{ + STG_CLIENT* client = STG_CLIENT::get(); + if (client == NULL) { + // TODO: log "Not configured" + return NULL; + } + return toPairs(client->account(userName, serviceType, statusType, sessionId)); +} + +int countValuePairs(const VALUE_PAIR* pairs) +{ + unsigned count = 0; + while (pairs != NULL) { + ++count; + pairs = pairs->next; + } + return count; +} -const STG_PAIR * stgAccountingImpl(const char * userName, const char * serviceType, const char * statusType, const char * sessionId) +STG_PAIR* fromValuePairs(const VALUE_PAIR* pairs) { - return STG_CLIENT_ST::Get().Account(userName, serviceType, statusType, sessionId); + unsigned size = countValuePairs(pairs); + STG_PAIR* res = new STG_PAIR[size + 1]; + size_t pos = 0; + while (pairs != NULL) { + bzero(res[pos].key, sizeof(STG_PAIR::key)); + bzero(res[pos].value, sizeof(STG_PAIR::value)); + strncpy(res[pos].key, pairs->name, sizeof(STG_PAIR::key)); + strncpy(res[pos].value, pairs->data.strvalue, sizeof(STG_PAIR::value)); + ++pos; + pairs = pairs->next; + } + bzero(res[pos].key, sizeof(STG_PAIR::key)); + bzero(res[pos].value, sizeof(STG_PAIR::value)); + return res; } -void deletePairs(const STG_PAIR * pairs) +void deletePairs(const STG_PAIR* pairs) { delete[] pairs; } diff --git a/projects/rlm_stg/iface.h b/projects/rlm_stg/iface.h index 831c3123..e4504b6c 100644 --- a/projects/rlm_stg/iface.h +++ b/projects/rlm_stg/iface.h @@ -9,14 +9,16 @@ extern "C" { #endif -int stgInstantiateImpl(const char * server, uint16_t port, const char * password); -const STG_PAIR * stgAuthorizeImpl(const char * userName, const char * serviceType); -const STG_PAIR * stgAuthenticateImpl(const char * userName, const char * serviceType); -const STG_PAIR * stgPostAuthImpl(const char * userName, const char * serviceType); -/*const STG_PAIR * stgPreAcctImpl(const char * userName, const char * serviceType);*/ -const STG_PAIR * stgAccountingImpl(const char * userName, const char * serviceType, const char * statusType, const char * sessionId); +int stgInstantiateImpl(const char* server, uint16_t port, const char* password); +const STG_PAIR* stgAuthorizeImpl(const char* userName, const char* serviceType); +const STG_PAIR* stgAuthenticateImpl(const char* userName, const char* serviceType); +const STG_PAIR* stgPostAuthImpl(const char* userName, const char* serviceType); +const STG_PAIR* stgPreAcctImpl(const char* userName, const char* serviceType); +const STG_PAIR* stgAccountingImpl(const char* userName, const char* serviceType, const char* statusType, const char* sessionId); -void deletePairs(const STG_PAIR * pairs); +void deletePairs(const STG_PAIR* pairs); +STG_PAIR* fromValuePairs(const VALUE_PAIR* pairs); +int countValuePairs(const VALUE_PAIR* pairs); #ifdef __cplusplus } diff --git a/projects/rlm_stg/rlm_stg.c b/projects/rlm_stg/rlm_stg.c index e1caf575..3c6e9c9b 100644 --- a/projects/rlm_stg/rlm_stg.c +++ b/projects/rlm_stg/rlm_stg.c @@ -34,13 +34,13 @@ #undef NDEBUG #endif -#include "stgpair.h" #include "iface.h" +#include "stgpair.h" typedef struct rlm_stg_t { - char * server; + char* server; uint16_t port; - char * password; + char* password; } rlm_stg_t; static const CONF_PARSER module_config[] = { @@ -51,8 +51,6 @@ static const CONF_PARSER module_config[] = { { NULL, -1, 0, NULL, NULL } /* end the list */ }; -int emptyPair(const STG_PAIR * pair); - /* * Do any per-module initialization that is separate to each * configured instance of the module. e.g. set up connections @@ -63,17 +61,17 @@ int emptyPair(const STG_PAIR * pair); * that must be referenced in later calls, store a handle to it * in *instance otherwise put a null pointer there. */ -static int stg_instantiate(CONF_SECTION *conf, void **instance) +static int stg_instantiate(CONF_SECTION* conf, void** instance) { - rlm_stg_t *data; + rlm_stg_t* data; /* * Set up a storage area for instance data */ data = rad_malloc(sizeof(*data)); - if (!data) { + if (!data) return -1; - } + memset(data, 0, sizeof(*data)); /* @@ -101,31 +99,30 @@ static int stg_instantiate(CONF_SECTION *conf, void **instance) * from the database. The authentication code only needs to check * the password, the rest is done here. */ -static int stg_authorize(void *, REQUEST *request) +static int stg_authorize(void*, REQUEST* request) { - const STG_PAIR * pairs; - const STG_PAIR * pair; + const STG_PAIR* pairs; + const STG_PAIR* pair; size_t count = 0; + const char* username = NULL; + const char* password = NULL; instance = instance; DEBUG("rlm_stg: stg_authorize()"); if (request->username) { - DEBUG("rlm_stg: stg_authorize() request username field: '%s'", request->username->vp_strvalue); + username = request->username->data.strvalue; + DEBUG("rlm_stg: stg_authorize() request username field: '%s'", username); } + if (request->password) { - DEBUG("rlm_stg: stg_authorize() request password field: '%s'", request->password->vp_strvalue); - } - // Here we need to define Framed-Protocol - VALUE_PAIR * svc = pairfind(request->packet->vps, PW_SERVICE_TYPE); - if (svc) { - DEBUG("rlm_stg: stg_authorize() Service-Type defined as '%s'", svc->vp_strvalue); - pairs = stgAuthorizeImpl((const char *)request->username->vp_strvalue, (const char *)svc->vp_strvalue); - } else { - DEBUG("rlm_stg: stg_authorize() Service-Type undefined"); - pairs = stgAuthorizeImpl((const char *)request->username->vp_strvalue, ""); + password = request->password->data.strvalue; + DEBUG("rlm_stg: stg_authorize() request password field: '%s'", password); } + + pairs = stgAuthorizeImpl(username, password, request->packet->vps); + if (!pairs) { DEBUG("rlm_stg: stg_authorize() failed."); return RLM_MODULE_REJECT; @@ -133,8 +130,8 @@ static int stg_authorize(void *, REQUEST *request) pair = pairs; while (!emptyPair(pair)) { - VALUE_PAIR * pwd = pairmake(pair->key, pair->value, T_OP_SET); - pairadd(&request->config_items, pwd); + VALUE_PAIR* vp = pairmake(pair->key, pair->value, T_OP_SET); + pairadd(&request->config_items, vp); DEBUG("Adding pair '%s': '%s'", pair->key, pair->value); ++pair; ++count; @@ -150,24 +147,30 @@ static int stg_authorize(void *, REQUEST *request) /* * Authenticate the user with the given password. */ -static int stg_authenticate(void *, REQUEST *request) +static int stg_authenticate(void*, REQUEST* request) { - const STG_PAIR * pairs; - const STG_PAIR * pair; + const STG_PAIR* pairs; + const STG_PAIR* pair; size_t count = 0; + const char* username = NULL; + const char* password = NULL; instance = instance; DEBUG("rlm_stg: stg_authenticate()"); - VALUE_PAIR * svc = pairfind(request->packet->vps, PW_SERVICE_TYPE); - if (svc) { - DEBUG("rlm_stg: stg_authenticate() Service-Type defined as '%s'", svc->vp_strvalue); - pairs = stgAuthenticateImpl((const char *)request->username->vp_strvalue, (const char *)svc->vp_strvalue); - } else { - DEBUG("rlm_stg: stg_authenticate() Service-Type undefined"); - pairs = stgAuthenticateImpl((const char *)request->username->vp_strvalue, ""); + if (request->username) { + username = request->username->data.strvalue; + DEBUG("rlm_stg: stg_authenticate() request username field: '%s'", username); + } + + if (request->password) { + password = request->password->data.strvalue; + DEBUG("rlm_stg: stg_authenticate() request password field: '%s'", password); } + + pairs = stgAuthenticateImpl(username, password, request->packet->vps); + if (!pairs) { DEBUG("rlm_stg: stg_authenticate() failed."); return RLM_MODULE_REJECT; @@ -175,8 +178,8 @@ static int stg_authenticate(void *, REQUEST *request) pair = pairs; while (!emptyPair(pair)) { - VALUE_PAIR * pwd = pairmake(pair->key, pair->value, T_OP_SET); - pairadd(&request->reply->vps, pwd); + VALUE_PAIR* vp = pairmake(pair->key, pair->value, T_OP_SET); + pairadd(&request->reply->vps, vp); ++pair; ++count; } @@ -191,31 +194,66 @@ static int stg_authenticate(void *, REQUEST *request) /* * Massage the request before recording it or proxying it */ -static int stg_preacct(void *, REQUEST *) +static int stg_preacct(void*, REQUEST*) { + const STG_PAIR* pairs; + const STG_PAIR* pair; + size_t count = 0; + const char* username = NULL; + const char* password = NULL; + DEBUG("rlm_stg: stg_preacct()"); instance = instance; - return RLM_MODULE_OK; + if (request->username) { + username = request->username->data.strvalue; + DEBUG("rlm_stg: stg_preacct() request username field: '%s'", username); + } + + if (request->password) { + password = request->password->data.strvalue; + DEBUG("rlm_stg: stg_preacct() request password field: '%s'", password); + } + + pairs = stgPreAcctImpl(username, password, request->packet->vps); + + if (!pairs) { + DEBUG("rlm_stg: stg_preacct() failed."); + return RLM_MODULE_REJECT; + } + + pair = pairs; + while (!emptyPair(pair)) { + VALUE_PAIR* vp = pairmake(pair->key, pair->value, T_OP_SET); + pairadd(&request->reply->vps, vp); + ++pair; + ++count; + } + deletePairs(pairs); + + if (count) + return RLM_MODULE_UPDATED; + + return RLM_MODULE_NOOP; } /* * Write accounting information to this modules database. */ -static int stg_accounting(void *, REQUEST * request) +static int stg_accounting(void*, REQUEST* request) { - const STG_PAIR * pairs; - const STG_PAIR * pair; + const STG_PAIR* pairs; + const STG_PAIR* pair; size_t count = 0; instance = instance; DEBUG("rlm_stg: stg_accounting()"); - VALUE_PAIR * svc = pairfind(request->packet->vps, PW_SERVICE_TYPE); - VALUE_PAIR * sessid = pairfind(request->packet->vps, PW_ACCT_SESSION_ID); - VALUE_PAIR * sttype = pairfind(request->packet->vps, PW_ACCT_STATUS_TYPE); + VALUE_PAIR* svc = pairfind(request->packet->vps, PW_SERVICE_TYPE); + VALUE_PAIR* sessid = pairfind(request->packet->vps, PW_ACCT_SESSION_ID); + VALUE_PAIR* sttype = pairfind(request->packet->vps, PW_ACCT_STATUS_TYPE); if (!sessid) { DEBUG("rlm_stg: stg_accounting() Acct-Session-ID undefined"); @@ -223,13 +261,13 @@ static int stg_accounting(void *, REQUEST * request) } if (sttype) { - DEBUG("Acct-Status-Type := %s", sttype->vp_strvalue); + DEBUG("Acct-Status-Type := %s", sttype->data.strvalue); if (svc) { - DEBUG("rlm_stg: stg_accounting() Service-Type defined as '%s'", svc->vp_strvalue); - pairs = stgAccountingImpl((const char *)request->username->vp_strvalue, (const char *)svc->vp_strvalue, (const char *)sttype->vp_strvalue, (const char *)sessid->vp_strvalue); + DEBUG("rlm_stg: stg_accounting() Service-Type defined as '%s'", svc->data.strvalue); + pairs = stgAccountingImpl((const char*)request->username->data.strvalue, (const char*)svc->data.strvalue, (const char*)sttype->data.strvalue, (const char*)sessid->data.strvalue); } else { DEBUG("rlm_stg: stg_accounting() Service-Type undefined"); - pairs = stgAccountingImpl((const char *)request->username->vp_strvalue, "", (const char *)sttype->vp_strvalue, (const char *)sessid->vp_strvalue); + pairs = stgAccountingImpl((const char*)request->username->data.strvalue, "", (const char*)sttype->data.strvalue, (const char*)sessid->data.strvalue); } } else { DEBUG("rlm_stg: stg_accounting() Acct-Status-Type := NULL"); @@ -242,7 +280,7 @@ static int stg_accounting(void *, REQUEST * request) pair = pairs; while (!emptyPair(pair)) { - VALUE_PAIR * pwd = pairmake(pair->key, pair->value, T_OP_SET); + VALUE_PAIR* pwd = pairmake(pair->key, pair->value, T_OP_SET); pairadd(&request->reply->vps, pwd); ++pair; ++count; @@ -265,35 +303,35 @@ static int stg_accounting(void *, REQUEST * request) * max. number of logins, do a second pass and validate all * logins by querying the terminal server (using eg. SNMP). */ -static int stg_checksimul(void *, REQUEST *request) +static int stg_checksimul(void*, REQUEST* request) { DEBUG("rlm_stg: stg_checksimul()"); instance = instance; - request->simul_count=0; + request->simul_count = 0; return RLM_MODULE_OK; } -static int stg_postauth(void *, REQUEST *request) +static int stg_postauth(void*, REQUEST* request) { - const STG_PAIR * pairs; - const STG_PAIR * pair; + const STG_PAIR* pairs; + const STG_PAIR* pair; size_t count = 0; instance = instance; DEBUG("rlm_stg: stg_postauth()"); - VALUE_PAIR * svc = pairfind(request->packet->vps, PW_SERVICE_TYPE); + VALUE_PAIR* svc = pairfind(request->packet->vps, PW_SERVICE_TYPE); if (svc) { - DEBUG("rlm_stg: stg_postauth() Service-Type defined as '%s'", svc->vp_strvalue); - pairs = stgPostAuthImpl((const char *)request->username->vp_strvalue, (const char *)svc->vp_strvalue); + DEBUG("rlm_stg: stg_postauth() Service-Type defined as '%s'", svc->data.strvalue); + pairs = stgPostAuthImpl((const char*)request->username->data.strvalue, (const char*)svc->data.strvalue); } else { DEBUG("rlm_stg: stg_postauth() Service-Type undefined"); - pairs = stgPostAuthImpl((const char *)request->username->vp_strvalue, ""); + pairs = stgPostAuthImpl((const char*)request->username->data.strvalue, ""); } if (!pairs) { DEBUG("rlm_stg: stg_postauth() failed."); @@ -302,7 +340,7 @@ static int stg_postauth(void *, REQUEST *request) pair = pairs; while (!emptyPair(pair)) { - VALUE_PAIR * pwd = pairmake(pair->key, pair->value, T_OP_SET); + VALUE_PAIR* pwd = pairmake(pair->key, pair->value, T_OP_SET); pairadd(&request->reply->vps, pwd); ++pair; ++count; @@ -315,9 +353,9 @@ static int stg_postauth(void *, REQUEST *request) return RLM_MODULE_NOOP; } -static int stg_detach(void *instance) +static int stg_detach(void* instance) { - free(((struct rlm_stg_t *)instance)->server); + free(((struct rlm_stg_t*)instance)->server); free(instance); return 0; } @@ -334,17 +372,17 @@ static int stg_detach(void *instance) module_t rlm_stg = { RLM_MODULE_INIT, "stg", - RLM_TYPE_THREAD_SAFE, /* type */ - stg_instantiate, /* instantiation */ - stg_detach, /* detach */ + RLM_TYPE_THREAD_SAFE, /* type */ + stg_instantiate, /* instantiation */ + stg_detach, /* detach */ { - stg_authenticate, /* authentication */ + stg_authenticate, /* authentication */ stg_authorize, /* authorization */ - stg_preacct, /* preaccounting */ - stg_accounting, /* accounting */ - stg_checksimul, /* checksimul */ - NULL, /* pre-proxy */ - NULL, /* post-proxy */ - stg_postauth /* post-auth */ + stg_preacct, /* preaccounting */ + stg_accounting, /* accounting */ + stg_checksimul, /* checksimul */ + stg_pre_proxy, /* pre-proxy */ + stg_post_proxy, /* post-proxy */ + stg_postauth /* post-auth */ }, }; diff --git a/projects/rlm_stg/stg_client.cpp b/projects/rlm_stg/stg_client.cpp index 113e71c9..c04f177d 100644 --- a/projects/rlm_stg/stg_client.cpp +++ b/projects/rlm_stg/stg_client.cpp @@ -39,7 +39,11 @@ #include "stg_client.h" -typedef std::vector > PAIRS; +namespace { + +STG_CLIENT* stgClient = NULL; + +} //----------------------------------------------------------------------------- @@ -150,7 +154,7 @@ return 0;*/ //----------------------------------------------------------------------------- -const STG_PAIRS * STG_CLIENT::Authorize(const std::string & login, const std::string & svc) +const STG_PAIRS * STG_CLIENT::Authorize(const PAIRS& pairs) { /*RAD_PACKET packet; @@ -170,7 +174,7 @@ pairs.push_back(std::make_pair("Cleartext-Password", userPassword)); return ToSTGPairs(pairs); } -const STG_PAIRS * STG_CLIENT::Authenticate(const std::string & login, const std::string & svc) +const STG_PAIRS * STG_CLIENT::Authenticate(const PAIRS& pairs) { /*RAD_PACKET packet; @@ -187,7 +191,7 @@ PAIRS pairs; return ToSTGPairs(pairs); } -const STG_PAIRS * STG_CLIENT::PostAuth(const std::string & login, const std::string & svc) +const STG_PAIRS * STG_CLIENT::PostAuth(const PAIRS& pairs) { /*RAD_PACKET packet; @@ -210,14 +214,14 @@ pairs.push_back(std::make_pair("Framed-IP-Address", inet_ntostring(framedIP))); return ToSTGPairs(pairs); } -const STG_PAIRS * STG_CLIENT::PreAcct(const std::string & login, const std::String & service) +const STG_PAIRS * STG_CLIENT::PreAcct(const PAIRS& pairs) { PAIRS pairs; return ToSTGPairs(pairs); } -const STG_PAIRS * STG_CLIENT::Account(const std::string & type, const std::string & login, const std::string & svc, const std::string & sessid) +const STG_PAIRS * STG_CLIENT::Account(const PAIRS& pairs) { /*RAD_PACKET packet; @@ -261,19 +265,16 @@ std::string STG_CLIENT_ST::m_password; //----------------------------------------------------------------------------- -STG_CLIENT * STG_CLIENT_ST::Get() +STG_CLIENT* STG_CLIENT::get() { - static STG_CLIENT * stgClient = NULL; - if ( stgClient == NULL ) - stgClient = new STG_CLIENT(m_host, m_port, m_password); return stgClient; } -void STG_CLIENT_ST::Configure(const std::string & host, uint16_t port, const std::string & password) +void STG_CLIENT::configure(const std::string& server, uint16_t port, const std::string& password) { - m_host = host; - m_port = port; - m_password = password; + if ( stgClient != NULL ) + delete stgClient; + stgClient = new STG_CLIENT(server, port, password); } //----------------------------------------------------------------------------- diff --git a/projects/rlm_stg/stg_client.h b/projects/rlm_stg/stg_client.h index 5ee000c7..680d0883 100644 --- a/projects/rlm_stg/stg_client.h +++ b/projects/rlm_stg/stg_client.h @@ -38,7 +38,7 @@ #include "stg/blowfish.h" #include "stg/rad_packets.h" -#include "stgpair.h" +typedef std::vector > PAIRS; class STG_CLIENT { @@ -46,33 +46,16 @@ public: STG_CLIENT(const std::string & host, uint16_t port, const std::string & password); ~STG_CLIENT(); - const STG_PAIR * Authorize(const std::string & login, const std::string & service); - const STG_PAIR * Authenticate(const std::string & login, const std::string & service); - const STG_PAIR * PostAuth(const std::string & login, const std::string & service); - const STG_PAIR * PreAcct(const std::string & login, const std::string & service); - const STG_PAIR * Account(const std::string & type, const std::string & login, const std::string & service, const std::string & sessionId); + static STG_CLIENT* get(); + static void configure(const std::string& server, uint16_t port, const std::string& password); -private: - std::string password; - - int PrepareNet(); - - int Request(RAD_PACKET * packet, const std::string & login, const std::string & svc, uint8_t packetType); - - int RecvData(RAD_PACKET * packet); - int Send(const RAD_PACKET & packet); -}; - -struct STG_CLIENT_ST -{ - public: - static void Configure(const std::string & host, uint16_t port, const std::string & password); - static STG_CLIENT * Get(); + PAIRS authorize(const PAIRS& pairs); + PAIRS authenticate(const PAIRS& pairs); + PAIRS postAuth(const PAIRS& pairs); + PAIRS preAcct(const PAIRS& pairs); + PAIRS account(const PAIRS& pairs); - private: - static std::string m_host; - static uint16_t m_port; - static std::string m_password; +private: }; #endif diff --git a/projects/rlm_stg/stgpair.c b/projects/rlm_stg/stgpair.c new file mode 100644 index 00000000..2dfb59d6 --- /dev/null +++ b/projects/rlm_stg/stgpair.c @@ -0,0 +1,6 @@ +#include "stgpair.h" + +int emptyPair(const STG_PAIR* pair) +{ + return pair != NULL && pair->key[0] != '\0' && pair->value[0] != '\0'; +} diff --git a/projects/rlm_stg/stgpair.h b/projects/rlm_stg/stgpair.h index 19b42bc1..046d06bf 100644 --- a/projects/rlm_stg/stgpair.h +++ b/projects/rlm_stg/stgpair.h @@ -1,6 +1,8 @@ #ifndef __STG_STGPAIR_H__ #define __STG_STGPAIR_H__ +#include // VALUE_PAIR + #define STGPAIR_KEYLENGTH 64 #define STGPAIR_VALUELENGTH 256 @@ -9,4 +11,6 @@ typedef struct STG_PAIR { char value[STGPAIR_VALUELENGTH]; } STG_PAIR; +int emptyPair(const STG_PAIR* pair); + #endif -- 2.43.2