From 747017e39d73c3948c988b0d0cf6f1a18e25c4b3 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Wed, 8 Dec 2010 16:45:18 +0200 Subject: [PATCH 01/16] =?utf8?q?=D0=92=20=D0=BA=D0=BE=D0=BD=D1=81=D0=BE?= =?utf8?q?=D0=BB=D1=8C=D0=BD=D0=BE=D0=BC=20=D0=B0=D0=B2=D1=82=D0=BE=D1=80?= =?utf8?q?=D0=B8=D0=B7=D0=B0=D1=82=D0=BE=D1=80=D0=B5=20=D1=83=D0=B1=D1=80?= =?utf8?q?=D0=B0=D0=BD=D0=B0=20=D0=BD=D0=B5=D0=B8=D1=81=D0=BF=D0=BE=D0=BB?= =?utf8?q?=D1=8C=D0=B7=D1=83=D0=B5=D0=BC=D0=B0=D1=8F=20=D1=84=D1=83=D0=BD?= =?utf8?q?=D0=BA=D1=86=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- projects/sgauth/main.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/projects/sgauth/main.cpp b/projects/sgauth/main.cpp index 1aae7aa6..b19ff6ed 100644 --- a/projects/sgauth/main.cpp +++ b/projects/sgauth/main.cpp @@ -303,12 +303,6 @@ void Usage() printf("sgauth \n"); //TODO change to correct } //----------------------------------------------------------------------------- -void EventsFn(int) -{ -LOADSTAT ls; -clnp->GetStat(&ls); -} -//----------------------------------------------------------------------------- void SetDirName(const vector & dn, void *) { for (int j = 0; j < DIR_NUM; j++) -- 2.44.2 From 6e1ab8de7a8bb7ebc1bd4a0e55592cc2b4499a0e Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Wed, 8 Dec 2010 16:45:41 +0200 Subject: [PATCH 02/16] =?utf8?q?=D0=92=20=D0=BA=D0=BE=D0=BD=D1=81=D0=BE?= =?utf8?q?=D0=BB=D1=8C=D0=BD=D0=BE=D0=BC=20=D0=B0=D0=B2=D1=82=D0=BE=D1=80?= =?utf8?q?=D0=B8=D0=B7=D0=B0=D1=82=D0=BE=D1=80=D0=B5=20=D1=83=D0=B1=D1=80?= =?utf8?q?=D0=B0=D0=BD=D0=B0=20=D0=BA=D0=BE=D0=BC=D0=BF=D0=BE=D0=BD=D0=BE?= =?utf8?q?=D0=B2=D0=BA=D0=B0=20=D1=81=20-lexpat=20=D0=B8=20-ldl?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- projects/sgauth/Makefile | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/projects/sgauth/Makefile b/projects/sgauth/Makefile index 47488cc2..7f597b95 100644 --- a/projects/sgauth/Makefile +++ b/projects/sgauth/Makefile @@ -15,11 +15,9 @@ STGLIBS = -lconffiles \ -lia_auth_c \ -lcommon_settings -LIBS += $(LIB_THREAD) \ - -lexpat +LIBS += $(LIB_THREAD) ifeq ($(OS),linux) -LIBS += -ldl else LIBS += -lintl \ -lc @@ -93,5 +91,3 @@ deps: $(SRCS) ../../Makefile.conf sgauth.css echo "`$(CC) $(CXXFLAGS) $(SEARCH_DIRS) -MM $$file` Makefile" >> deps ;\ echo -e '\t$$(CC) -c $$< $(CXXFLAGS) $(SEARCH_DIRS) $(DEFS)' >> deps ;\ done - - -- 2.44.2 From 4744fe9d82281dd743a92bec37e27e1b4777ba66 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Wed, 8 Dec 2010 16:53:45 +0200 Subject: [PATCH 03/16] =?utf8?q?=D0=98=D0=B7=20Stargazer=20=D1=83=D0=B1?= =?utf8?q?=D1=80=D0=B0=D0=BD=D0=B0=20=D0=BF=D0=BE=D0=BB=D0=BD=D0=BE=D1=81?= =?utf8?q?=D1=82=D1=8C=D1=8E=20=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D1=8F?= =?utf8?q?=20=D0=BF=D0=B5=D1=80=D0=B5=D1=85=D0=B2=D0=B0=D1=82=D0=B0=20?= =?utf8?q?=D1=81=D0=B8=D0=B3=D0=BD=D0=B0=D0=BB=D0=B0=20=D0=BF=D1=80=D0=BE?= =?utf8?q?=D1=84=D0=B8=D0=BB=D0=B8=D1=80=D0=BE=D0=B2=D1=89=D0=B8=D0=BA?= =?utf8?q?=D0=B0=20(SIGPROF)=20=D0=B8=20=D0=BF=D0=BE=D0=BB=D0=BD=D0=BE?= =?utf8?q?=D1=81=D1=82=D1=8C=D1=8E=20=D1=81=D0=BA=D1=80=D1=8B=D1=82=D0=B0?= =?utf8?q?=20=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D1=8F=20=D0=BF=D0=B5?= =?utf8?q?=D1=80=D0=B5=D1=85=D0=B2=D0=B0=D1=82=D0=B0=20=D1=81=D0=B8=D0=B3?= =?utf8?q?=D0=BD=D0=B0=D0=BB=D0=B0=20SIGSEGV?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- projects/stargazer/main.cpp | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/projects/stargazer/main.cpp b/projects/stargazer/main.cpp index 7c9945b0..26eba647 100644 --- a/projects/stargazer/main.cpp +++ b/projects/stargazer/main.cpp @@ -128,12 +128,6 @@ else } } //----------------------------------------------------------------------------- -void CatchPROF(int) -{ -/*STG_LOGGER & WriteServLog = GetStgLogger(); -WriteServLog("CatchPROF");*/ -} -//----------------------------------------------------------------------------- void CatchUSR1(int) { @@ -203,10 +197,10 @@ if (childPid == stgChildPid) childExited = true; } } -//----------------------------------------------------------------------------- +/*//----------------------------------------------------------------------------- void CatchSEGV(int, siginfo_t *, void *) { -/*char fileName[50]; +char fileName[50]; sprintf(fileName, "/tmp/stg_segv.%d", getpid()); FILE * f = fopen(fileName, "wt"); if (f) @@ -254,8 +248,8 @@ segv_action.sa_sigaction = NULL; segv_action.sa_flags = SA_SIGINFO; segv_action.sa_restorer = NULL; -sigaction(SIGSEGV, &segv_action, &segv_action_old);*/ -} +sigaction(SIGSEGV, &segv_action, &segv_action_old); +}*/ //----------------------------------------------------------------------------- static void SetSignalHandlers() { @@ -282,13 +276,6 @@ newsa.sa_handler = CatchTERM; newsa.sa_mask = sigmask; newsa.sa_flags = 0; sigaction(SIGINT, &newsa, &oldsa); -/*/////// -sigemptyset(&sigmask); -sigaddset(&sigmask, SIGPROF); -newsa.sa_handler = CatchPROF; -newsa.sa_mask = sigmask; -newsa.sa_flags = 0; -sigaction(SIGPROF, &newsa, &oldsa);*/ ////// sigemptyset(&sigmask); sigaddset(&sigmask, SIGPIPE); -- 2.44.2 From 75cd69d3fca8b0a59d2335384f95091ad89b998c Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Wed, 8 Dec 2010 16:58:05 +0200 Subject: [PATCH 04/16] =?utf8?q?=D0=9D=D0=B5=D0=B1=D0=BE=D0=BB=D1=8C=D1=88?= =?utf8?q?=D0=B0=D1=8F=20=D1=87=D0=B8=D1=81=D1=82=D0=BA=D0=B0=20=D0=BA?= =?utf8?q?=D0=BE=D0=B4=D0=B0=20=D0=B1=D0=B8=D0=B1=D0=BB=D0=B8=D0=BE=D1=82?= =?utf8?q?=D0=B5=D0=BA=D0=B8=20conffiles?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- stglibs/conffiles.lib/conffiles.cpp | 20 +++++--------------- stglibs/conffiles.lib/conffiles.h | 7 +------ 2 files changed, 6 insertions(+), 21 deletions(-) diff --git a/stglibs/conffiles.lib/conffiles.cpp b/stglibs/conffiles.lib/conffiles.cpp index 549cb22d..a6fbe6d6 100644 --- a/stglibs/conffiles.lib/conffiles.cpp +++ b/stglibs/conffiles.lib/conffiles.cpp @@ -28,11 +28,13 @@ */ //--------------------------------------------------------------------------- -#include -#include -#include +#include +#include +#include + #include #include + #include "conffiles.h" #include "common.h" @@ -133,16 +135,6 @@ error = 0; return e; } //--------------------------------------------------------------------------- -int CONFIGFILE::FindParameter(const string ¶meter, string * value) const -{ -it = param_val.find(parameter); -if (it == param_val.end()) - return -1; - -*value = param_val[parameter]; -return 0; -} -//--------------------------------------------------------------------------- int CONFIGFILE::Flush() { fstream f(fileName.c_str(), ios::out); @@ -451,5 +443,3 @@ Flush(); return 0; } //--------------------------------------------------------------------------- - - diff --git a/stglibs/conffiles.lib/conffiles.h b/stglibs/conffiles.lib/conffiles.h index ee575d65..83a16d9b 100644 --- a/stglibs/conffiles.lib/conffiles.h +++ b/stglibs/conffiles.lib/conffiles.h @@ -31,8 +31,7 @@ #ifndef ConfFilesH #define ConfFilesH -#include -#include + #include #include @@ -40,8 +39,6 @@ using namespace std; //--------------------------------------------------------------------------- -//#define CONF_STR_LEN 300 -//typedef char STRING[CONF_STR_LEN]; typedef bool (*StringCaseCmp_t)(const string & str1, const string & str2); @@ -67,8 +64,6 @@ public: int ReadString(const string & param, char * val, int * maxLen, const char * defaultVal) const; int ReadString(const string & param, string * val, const string & defaultVal) const; - int FindParameter(const string ¶meter, string * value) const; - int ReadTime (const string & param, time_t *, time_t) const; int ReadShortInt (const string & param, short int *, short int) const; -- 2.44.2 From 959549949c215dc3ef0eae08ae298a0836f85d65 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Wed, 8 Dec 2010 17:02:09 +0200 Subject: [PATCH 05/16] =?utf8?q?=D0=92=D1=80=D0=B5=D0=BC=D0=B5=D0=BD=D0=BD?= =?utf8?q?=D0=BE=20=D0=B7=D0=B0=D0=BA=D0=BE=D0=BC=D0=BC=D0=B5=D0=BD=D1=82?= =?utf8?q?=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=20=D0=BC=D0=B5=D1=82=D0=BE?= =?utf8?q?=D0=B4=20GetConfModeDir=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=B0?= =?utf8?q?=20=D0=BD=D0=B0=D1=81=D1=82=D1=80=D0=BE=D0=B5=D0=BA=20=D0=BF?= =?utf8?q?=D0=BB=D0=B0=D0=B3=D0=B8=D0=BD=D0=B0=20=D1=84=D0=B0=D0=B9=D0=BB?= =?utf8?q?=D0=BE=D0=B2=D0=BE=D0=B3=D0=BE=20=D1=85=D1=80=D0=B0=D0=BD=D0=B8?= =?utf8?q?=D0=BB=D0=B8=D1=89=D0=B0.=20=D0=9D=D1=83=D0=B6=D0=BD=D0=BE=20?= =?utf8?q?=D1=80=D0=B0=D0=B7=D0=BE=D0=B1=D1=80=D0=B0=D1=82=D1=8C=D1=81?= =?utf8?q?=D1=8F=20=D0=B3=D0=B4=D0=B5=20=D0=B5=D0=B3=D0=BE=20=D0=BD=D0=B0?= =?utf8?q?=D0=B4=D0=BE=20=D0=B8=D1=81=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE?= =?utf8?q?=D0=B2=D0=B0=D1=82=D1=8C.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- projects/stargazer/plugins/store/files/file_store.cpp | 4 ++-- projects/stargazer/plugins/store/files/file_store.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/projects/stargazer/plugins/store/files/file_store.cpp b/projects/stargazer/plugins/store/files/file_store.cpp index a49ca977..fe5ed230 100644 --- a/projects/stargazer/plugins/store/files/file_store.cpp +++ b/projects/stargazer/plugins/store/files/file_store.cpp @@ -438,7 +438,7 @@ mode_t FILES_STORE_SETTINGS::GetConfMode() const { return confMode; } -//----------------------------------------------------------------------------- +/*//----------------------------------------------------------------------------- mode_t FILES_STORE_SETTINGS::GetConfModeDir() const { mode_t mode = confMode; @@ -446,7 +446,7 @@ if (statMode & S_IRUSR) mode |= S_IXUSR; if (statMode & S_IRGRP) mode |= S_IXGRP; if (statMode & S_IROTH) mode |= S_IXOTH; return mode; -} +}*/ //----------------------------------------------------------------------------- uid_t FILES_STORE_SETTINGS::GetConfUID() const { diff --git a/projects/stargazer/plugins/store/files/file_store.h b/projects/stargazer/plugins/store/files/file_store.h index cb3abdb3..13c3a3fa 100644 --- a/projects/stargazer/plugins/store/files/file_store.h +++ b/projects/stargazer/plugins/store/files/file_store.h @@ -59,7 +59,7 @@ public: gid_t GetStatGID() const; mode_t GetConfMode() const; - mode_t GetConfModeDir() const; + //mode_t GetConfModeDir() const; uid_t GetConfUID() const; gid_t GetConfGID() const; -- 2.44.2 From 38adf7483e39539384d78e7044c7f7cd9f09bebf Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Wed, 8 Dec 2010 17:07:37 +0200 Subject: [PATCH 06/16] =?utf8?q?=D0=92=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81?= =?utf8?q?=D0=B5=20=D1=82=D0=B0=D1=80=D0=B8=D1=84=D0=B0=20=D1=83=D0=B4?= =?utf8?q?=D0=B0=D0=BB=D0=B5=D0=BD=20=D0=BD=D0=B5=D0=B8=D1=81=D0=BF=D0=BE?= =?utf8?q?=D0=BB=D1=8C=D0=B7=D1=83=D0=B5=D0=BC=D1=8B=D0=B9=20=D0=BC=D0=B5?= =?utf8?q?=D1=82=D0=BE=D0=B4=20GetDirPrice?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- projects/stargazer/tariff.cpp | 5 ----- projects/stargazer/tariff.h | 1 - 2 files changed, 6 deletions(-) diff --git a/projects/stargazer/tariff.cpp b/projects/stargazer/tariff.cpp index 088cb53d..70b75576 100644 --- a/projects/stargazer/tariff.cpp +++ b/projects/stargazer/tariff.cpp @@ -88,11 +88,6 @@ void TARIFF::PrintTariff() const //printfd(__FILE__, "Free: %8.3f\n", tariffConf.free); } //----------------------------------------------------------------------------- -void TARIFF::GetDirPrice(int dir, DIRPRICE_DATA * dd) const -{ -*dd = tariffData.dirPrice[dir]; -} -//----------------------------------------------------------------------------- void TARIFF::GetTariffData(TARIFF_DATA * td) const { *td = tariffData; diff --git a/projects/stargazer/tariff.h b/projects/stargazer/tariff.h index 830863eb..ed61e015 100644 --- a/projects/stargazer/tariff.h +++ b/projects/stargazer/tariff.h @@ -62,7 +62,6 @@ public: int dir, time_t t) const; double GetFreeMb() const { return tariffData.tariffConf.free; }; - void GetDirPrice(int dir, DIRPRICE_DATA * dd) const; double GetPassiveCost() const { return tariffData.tariffConf.passiveCost; }; double GetFee() const { return tariffData.tariffConf.fee; }; double GetFree() const { return tariffData.tariffConf.free; }; -- 2.44.2 From 931cbc356d8e2cf226026d8d327c1bdd7bd82b71 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Wed, 8 Dec 2010 17:18:24 +0200 Subject: [PATCH 07/16] =?utf8?q?=D0=92=20=D0=BA=D0=BE=D0=BD=D1=81=D0=BE?= =?utf8?q?=D0=BB=D1=8C=D0=BD=D0=BE=D0=BC=20=D0=B0=D0=B2=D1=82=D0=BE=D1=80?= =?utf8?q?=D0=B8=D0=B7=D0=B0=D1=82=D0=BE=D1=80=D0=B5=20=D0=B2=20=D0=BA?= =?utf8?q?=D0=BB=D0=B0=D1=81=D1=81=D0=B5=20=D0=BD=D0=B0=D1=81=D1=82=D1=80?= =?utf8?q?=D0=BE=D0=B5=D0=BA=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?utf8?q?=D0=BD=D0=B0=20=D0=B8=D0=BD=D0=B8=D1=86=D0=B8=D0=B0=D0=BB=D0=B8?= =?utf8?q?=D0=B7=D0=B0=D1=86=D0=B8=D1=8F=20=D1=87=D0=BB=D0=B5=D0=BD=D0=BE?= =?utf8?q?=D0=B2=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=B0=20=D1=87=D0=B5?= =?utf8?q?=D1=80=D0=B5=D0=B7=20=D0=BA=D0=BE=D0=BD=D1=81=D1=82=D1=80=D1=83?= =?utf8?q?=D0=BA=D1=82=D0=BE=D1=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- projects/sgauth/main.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/projects/sgauth/main.cpp b/projects/sgauth/main.cpp index b19ff6ed..c7b2bfdc 100644 --- a/projects/sgauth/main.cpp +++ b/projects/sgauth/main.cpp @@ -105,6 +105,14 @@ private: }; //----------------------------------------------------------------------------- SETTINGS::SETTINGS() + : port(0), + localPort(0), + listenWebIP(0), + refreshPeriod(0), + daemon(false), + noWeb(false), + reconnect(false), + showPid(false) { confFile = "/etc/sgauth.conf"; } -- 2.44.2 From 307532819d6117d154436da4131ca645f7691a63 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Wed, 8 Dec 2010 17:19:12 +0200 Subject: [PATCH 08/16] =?utf8?q?=D0=92=20=D0=BA=D0=BE=D0=BD=D1=81=D0=BE?= =?utf8?q?=D0=BB=D1=8C=D0=BD=D0=BE=D0=BC=20=D0=B0=D0=B2=D1=82=D0=BE=D1=80?= =?utf8?q?=D0=B8=D0=B7=D0=B0=D1=82=D0=BE=D1=80=D0=B5=20=D0=B2=20=D0=BA?= =?utf8?q?=D0=BB=D0=B0=D1=81=D1=81=D0=B5=20=D0=BE=D1=82=D0=B2=D0=B5=D1=87?= =?utf8?q?=D0=B0=D1=8E=D1=89=D0=B5=D0=BC=20=D0=B7=D0=B0=20WEB-=D0=B8=D0=BD?= =?utf8?q?=D1=82=D0=B5=D1=80=D1=84=D0=B5=D0=B9=D1=81=20=D0=BF=D1=80=D0=BE?= =?utf8?q?=D0=B2=D0=B5=D0=B4=D0=B5=D0=BD=20=D1=80=D0=B5=D1=84=D0=B0=D0=BA?= =?utf8?q?=D1=82=D0=BE=D1=80=D0=B8=D0=BD=D0=B3=20=D0=BA=D0=BE=D0=B4=D0=B0,?= =?utf8?q?=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B0=20?= =?utf8?q?=D0=B8=D0=BD=D0=B8=D1=86=D0=B8=D0=B0=D0=BB=D0=B8=D0=B7=D0=B0?= =?utf8?q?=D1=86=D0=B8=D1=8F=20=D0=BD=D0=B5=D0=BA=D0=BE=D1=82=D0=BE=D1=80?= =?utf8?q?=D1=8B=D1=85=20=D1=87=D0=BB=D0=B5=D0=BD=D0=BE=D0=B2,=20=D1=83?= =?utf8?q?=D0=BC=D0=B5=D0=BD=D1=8C=D1=88=D0=B5=D0=BD=D0=B0=20=D0=BE=D0=B1?= =?utf8?q?=D0=BB=D0=B0=D1=81=D1=82=D1=8C=20=D0=B2=D0=B8=D0=B4=D0=B8=D0=BC?= =?utf8?q?=D0=BE=D1=81=D1=82=D0=B8=20=D0=BF=D0=B5=D1=80=D0=B5=D0=BC=D0=B5?= =?utf8?q?=D0=BD=D0=BD=D1=8B=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- projects/sgauth/web.cpp | 15 +++++++++++---- projects/sgauth/web.h | 31 ++++++++++--------------------- 2 files changed, 21 insertions(+), 25 deletions(-) diff --git a/projects/sgauth/web.cpp b/projects/sgauth/web.cpp index caec33a0..ffab862b 100644 --- a/projects/sgauth/web.cpp +++ b/projects/sgauth/web.cpp @@ -56,8 +56,7 @@ WEB::WEB() listenSocket(0), outerSocket(0), refreshPeriod(0), - listenWebAddr(0), - outerAddrLen(0) + listenWebAddr(0) { #ifdef WIN32 res = WSAStartup(MAKEWORD(2,0), &wsaData); @@ -89,6 +88,8 @@ pthread_create(&thread, NULL, RunWeb, NULL); void WEB::PrepareNet() { listenSocket = socket(PF_INET, SOCK_STREAM, 0); + +struct sockaddr_in listenAddr; listenAddr.sin_family = AF_INET; listenAddr.sin_port = htons(LISTEN_PORT); listenAddr.sin_addr.s_addr = listenWebAddr; @@ -120,8 +121,6 @@ if (res == -1) printf("Listen failed.\n"); exit(0); } - -outerAddrLen = sizeof(outerAddr); } //--------------------------------------------------------------------------- void WEB::SetRefreshPagePeriod(int p) @@ -142,6 +141,14 @@ PrepareNet(); char recvBuffer[4096]; while (1) { + struct sockaddr_in outerAddr; + + #ifndef WIN32 + socklen_t outerAddrLen = sizeof(outerAddr); + #else + int outerAddrLen = sizeof(outerAddr); + #endif + outerSocket = accept(listenSocket, (struct sockaddr*)&outerAddr, &outerAddrLen); if (outerSocket == -1) { diff --git a/projects/sgauth/web.h b/projects/sgauth/web.h index b734f16b..be9e158d 100644 --- a/projects/sgauth/web.h +++ b/projects/sgauth/web.h @@ -65,8 +65,10 @@ public: void UpdateStat(const LOADSTAT & ls); void Start(); private: - void PrepareNet(); + int SendReply(); + int SendCSS(); + int Redirect(const char * url); #ifdef WIN32 WSADATA wsaData; @@ -74,28 +76,15 @@ private: pthread_t thread; #endif - int SendReply(); - int SendCSS(); - int Redirect(const char * url); - - string dirName[DIR_NUM]; - int res; - int listenSocket; - int outerSocket; - struct sockaddr_in listenAddr; - struct sockaddr_in outerAddr; - int refreshPeriod; + string dirName[DIR_NUM]; + int res; + int listenSocket; + int outerSocket; + int refreshPeriod; - uint32_t listenWebAddr; - LOADSTAT ls; + uint32_t listenWebAddr; + LOADSTAT ls; list messages; - - #ifndef WIN32 - socklen_t outerAddrLen; - #else - int outerAddrLen; - #endif }; //----------------------------------------------------------------------------- - -- 2.44.2 From 75c3db512c67ff8f548d5fdd0e07c9f780973bcb Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Wed, 8 Dec 2010 17:23:49 +0200 Subject: [PATCH 09/16] =?utf8?q?=D0=9A=D0=BE=D1=81=D0=BC=D0=B5=D1=82=D0=B8?= =?utf8?q?=D1=87=D0=B5=D1=81=D0=BA=D0=B8=D0=B5=20=D0=B8=D0=B7=D0=BC=D0=B5?= =?utf8?q?=D0=BD=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=B2=20=D0=BA=D0=BE=D0=B4?= =?utf8?q?=D0=B5=20=D0=BF=D0=BE=D0=B4=D0=B4=D0=B5=D1=80=D0=B6=D0=BA=D0=B8?= =?utf8?q?=20WEB-=D0=B8=D0=BD=D1=82=D0=B5=D1=80=D1=84=D0=B5=D0=B9=D1=81?= =?utf8?q?=D0=B0=20=D0=BA=D0=BE=D0=BD=D1=81=D0=BE=D0=BB=D1=8C=D0=BD=D0=BE?= =?utf8?q?=D0=B3=D0=BE=20=D0=B0=D0=B2=D1=82=D0=BE=D1=80=D0=B8=D0=B7=D0=B0?= =?utf8?q?=D1=82=D0=BE=D1=80=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- projects/sgauth/web.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/projects/sgauth/web.cpp b/projects/sgauth/web.cpp index ffab862b..edafc9d8 100644 --- a/projects/sgauth/web.cpp +++ b/projects/sgauth/web.cpp @@ -94,9 +94,8 @@ listenAddr.sin_family = AF_INET; listenAddr.sin_port = htons(LISTEN_PORT); listenAddr.sin_addr.s_addr = listenWebAddr; -int lng = 1; - #ifndef WIN32 +int lng = 1; if (0 != setsockopt(listenSocket, SOL_SOCKET, SO_REUSEADDR, &lng, 4)) { printf("Setsockopt Fail\n"); -- 2.44.2 From 105771be792a6c3c909b8780540004f3c27238b8 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Wed, 8 Dec 2010 17:26:40 +0200 Subject: [PATCH 10/16] =?utf8?q?=D0=92=20=D0=BA=D0=BE=D0=BD=D1=81=D0=BE?= =?utf8?q?=D0=BB=D1=8C=D0=BD=D0=BE=D0=BC=20=D0=BA=D0=BE=D0=BD=D1=84=D0=B8?= =?utf8?q?=D0=B3=D1=83=D1=80=D0=B0=D1=82=D0=BE=D1=80=D0=B5=20=D0=B8=D1=81?= =?utf8?q?=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=20=D0=BF=D0=BE=D1=82?= =?utf8?q?=D0=B5=D0=BD=D1=86=D0=B8=D0=B0=D0=BB=D1=8C=D0=BD=D1=8B=D0=B9=20?= =?utf8?q?=D0=B2=D1=8B=D1=85=D0=BE=D0=B4=20=D0=B7=D0=B0=20=D0=BF=D1=80?= =?utf8?q?=D0=B5=D0=B4=D0=B5=D0=BB=D1=8B=20=D0=BC=D0=B0=D1=81=D1=81=D0=B8?= =?utf8?q?=D0=B2=D0=B0=20=D0=BF=D1=80=D0=B8=20=D1=80=D0=B0=D0=B7=D0=B1?= =?utf8?q?=D0=BE=D1=80=D0=B5=20=D0=B7=D0=BD=D0=B0=D1=87=D0=B5=D0=BD=D0=B8?= =?utf8?q?=D1=8F=20cash?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- projects/sgconf/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/projects/sgconf/main.cpp b/projects/sgconf/main.cpp index d2671be4..5e52d37d 100644 --- a/projects/sgconf/main.cpp +++ b/projects/sgconf/main.cpp @@ -181,9 +181,9 @@ double ParseCash(const char * c, string * message) double cash; char * msg; char * str; -str = new char[strlen(c)]; +str = new char[strlen(c) + 1]; -strcpy(str, c); +strncpy(str, c, strlen(c)); msg = strchr(str, ':'); if (msg) -- 2.44.2 From 0bd1fc824f16d5eca4db5c3901e8c20ade408786 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Wed, 8 Dec 2010 17:28:48 +0200 Subject: [PATCH 11/16] =?utf8?q?=D0=A1=D1=83=D0=B4=D1=8F=20=D0=BF=D0=BE=20?= =?utf8?q?=D0=B2=D1=81=D0=B5=D0=BC=20=D1=84=D0=B0=D0=B9=D0=BB=20sginfo.cpp?= =?utf8?q?=20=D0=BA=D0=BE=D0=BD=D1=81=D0=BE=D0=BB=D1=8C=D0=BD=D0=BE=D0=B3?= =?utf8?q?=D0=BE=20=D0=BA=D0=BE=D0=BD=D1=84=D0=B8=D0=B3=D1=83=D1=80=D0=B0?= =?utf8?q?=D1=82=D0=BE=D1=80=D0=B0=20=D0=BD=D0=B5=20=D0=B8=D1=81=D0=BF?= =?utf8?q?=D0=BE=D0=BB=D1=8C=D0=B7=D1=83=D0=B5=D1=82=D1=81=D1=8F,=20=20=20?= =?utf8?q?=20=20=D0=BD=D0=BE=20=D0=BF=D0=BE=D0=BA=D0=B0=20=D1=8D=D1=82?= =?utf8?q?=D0=BE=20=D0=BD=D0=B5=20=D0=B1=D1=83=D0=B4=D0=B5=D1=82=20=D1=83?= =?utf8?q?=D1=81=D1=82=D0=B0=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5=D0=BD=D0=BE=20?= =?utf8?q?=D0=B4=D0=BE=D1=81=D1=82=D0=BE=D0=B2=D0=B5=D1=80=D0=BD=D0=BE=20?= =?utf8?q?=D1=82=D0=BE=20=D0=B8=20=D1=82=D1=83=D1=82=20=D0=B8=D1=81=D0=BF?= =?utf8?q?=D1=80=D0=B0=D0=B2=D0=B8=D0=BB=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA?= =?utf8?q?=D1=83=20=20=20=20=20=D1=81=20=D0=BF=D0=B5=D1=80=D0=B5=D0=BF?= =?utf8?q?=D0=BE=D0=BB=D0=BD=D0=B5=D0=BD=D0=B8=D0=B5=D0=BC=20=D0=B1=D1=83?= =?utf8?q?=D1=84=D0=B5=D1=80=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- projects/sgconf/sginfo.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/projects/sgconf/sginfo.cpp b/projects/sgconf/sginfo.cpp index 86352599..c5ab3eaf 100644 --- a/projects/sgconf/sginfo.cpp +++ b/projects/sgconf/sginfo.cpp @@ -182,9 +182,9 @@ double ParseCash(const char * c, string * message) double cash; char * msg; char * str; -str = new char[strlen(c)]; +str = new char[strlen(c) + 1]; -strcpy(str, c); +strncpy(str, c, strlen(c)); msg = strchr(str, ':'); if (msg) -- 2.44.2 From 6f2241f81b1c3e826b7a677a31925950423a6d0c Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Thu, 9 Dec 2010 12:44:04 +0200 Subject: [PATCH 12/16] =?utf8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?utf8?q?=D0=B5=D0=BD=D0=BE=20=D1=84=D0=BE=D1=80=D0=BC=D0=B0=D1=82=D0=B8?= =?utf8?q?=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20=D0=B2=20=D0=BA?= =?utf8?q?=D0=BE=D0=B4=D0=B5=20rlm=5Fstg.=20=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0?= =?utf8?q?=D0=BD=D0=B8=D0=B5=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=B0=20STG?= =?utf8?q?=5FCLIENT=20=D0=BC=D0=BE=D0=B4=D0=B8=D1=84=D0=B8=D1=86=D0=B8?= =?utf8?q?=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=BE=20=D0=B4=D0=BB=D1=8F=20?= =?utf8?q?=D0=BF=D0=B5=D1=80=D0=B5=D0=B4=D0=B0=D1=87=D0=B8=20=D0=BF=D0=B0?= =?utf8?q?=D1=80=D0=B0=D0=BC=D0=B5=D1=82=D1=80=D0=BE=D0=B2=20=D1=87=D0=B5?= =?utf8?q?=D1=80=D0=B5=D0=B7=20=D0=BA=D0=BE=D0=BD=D1=81=D1=82=D1=80=D1=83?= =?utf8?q?=D0=BA=D1=82=D0=BE=D1=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- projects/rlm_stg/rlm_stg.cpp | 435 ++++++++++++++++++----------------- 1 file changed, 220 insertions(+), 215 deletions(-) diff --git a/projects/rlm_stg/rlm_stg.cpp b/projects/rlm_stg/rlm_stg.cpp index c5b5d7d9..1cb652d7 100644 --- a/projects/rlm_stg/rlm_stg.cpp +++ b/projects/rlm_stg/rlm_stg.cpp @@ -30,6 +30,8 @@ #include #include +#include + extern "C" { #include "radius.h" #include "modules.h" @@ -42,11 +44,11 @@ STG_CLIENT * cli; volatile time_t stgTime; /* - * Define a structure for our module configuration. + * Define a structure for our module configuration. * - * These variables do not need to be in a structure, but it's - * a lot cleaner to do so, and a pointer to the structure can - * be used as the instance handle. + * These variables do not need to be in a structure, but it's + * a lot cleaner to do so, and a pointer to the structure can + * be used as the instance handle. */ typedef struct rlm_stg_t { char * server; @@ -56,13 +58,13 @@ typedef struct rlm_stg_t { } rlm_stg_t; /* - * A mapping of configuration file names to internal variables. + * A mapping of configuration file names to internal variables. * - * Note that the string is dynamically allocated, so it MUST - * be freed. When the configuration file parse re-reads the string, - * it free's the old one, and strdup's the new one, placing the pointer - * to the strdup'd string into 'config.string'. This gets around - * buffer over-flows. + * Note that the string is dynamically allocated, so it MUST + * be freed. When the configuration file parse re-reads the string, + * it free's the old one, and strdup's the new one, placing the pointer + * to the strdup'd string into 'config.string'. This gets around + * buffer over-flows. */ static CONF_PARSER module_config[] = { { "password", PW_TYPE_STRING_PTR, offsetof(rlm_stg_t,password), NULL, NULL}, @@ -70,277 +72,280 @@ static CONF_PARSER module_config[] = { { "port", PW_TYPE_INTEGER, offsetof(rlm_stg_t,port), NULL, "5555" }, { "local_port", PW_TYPE_INTEGER, offsetof(rlm_stg_t,localPort), NULL, "0" }, - { NULL, -1, 0, NULL, NULL } /* end the list */ + { NULL, -1, 0, NULL, NULL } /* end the list */ }; /* - * Do any per-module initialization that is separate to each - * configured instance of the module. e.g. set up connections - * to external databases, read configuration files, set up - * dictionary entries, etc. + * Do any per-module initialization that is separate to each + * configured instance of the module. e.g. set up connections + * to external databases, read configuration files, set up + * dictionary entries, etc. * - * If configuration information is given in the config section - * that must be referenced in later calls, store a handle to it - * in *instance otherwise put a null pointer there. + * If configuration information is given in the config section + * 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) { - rlm_stg_t *data; + rlm_stg_t *data; - /* - * Set up a storage area for instance data - */ + /* + * Set up a storage area for instance data + */ DEBUG("rlm_stg: stg_instantiate()"); - data = (rlm_stg_t *)rad_malloc(sizeof(rlm_stg_t)); - if (!data) { - return -1; - } - memset(data, 0, sizeof(rlm_stg_t)); - - /* - * If the configuration parameters can't be parsed, then - * fail. - */ - if (cf_section_parse(conf, data, module_config) < 0) { - free(data); - return -1; - } - - cli = new STG_CLIENT(); - cli->SetServer(data->server); - cli->SetPort(data->port); - cli->SetLocalPort(data->localPort); - cli->SetPassword(data->password); - if (cli->Start()) { - DEBUG("rlm_stg: stg_instantiate() error: '%s'", cli->GetError().c_str()); - return -1; - } - - *instance = data; - - return 0; + data = (rlm_stg_t *)rad_malloc(sizeof(rlm_stg_t)); + if (!data) { + return -1; + } + memset(data, 0, sizeof(rlm_stg_t)); + + /* + * If the configuration parameters can't be parsed, then + * fail. + */ + if (cf_section_parse(conf, data, module_config) < 0) { + free(data); + return -1; + } + + try { + cli = new STG_CLIENT(data->server, data->port, data->localPort, data->password); + } + catch (std::exception & ex) { + DEBUG("rlm_stg: stg_instantiate() error: '%s'", ex.what()); + return -1; + } + + if (cli->Start()) { + DEBUG("rlm_stg: stg_instantiate() error: '%s'", cli->GetError().c_str()); + return -1; + } + + *instance = data; + + return 0; } /* - * Find the named user in this modules database. Create the set - * of attribute-value pairs to check and reply with for this user - * from the database. The authentication code only needs to check - * the password, the rest is done here. + * Find the named user in this modules database. Create the set + * of attribute-value pairs to check and reply with for this user + * from the database. The authentication code only needs to check + * the password, the rest is done here. */ static int stg_authorize(void *instance, REQUEST *request) { - VALUE_PAIR *uname; - VALUE_PAIR *pwd; - VALUE_PAIR *svc; - DEBUG("rlm_stg: stg_authorize()"); - - /* quiet the compiler */ - instance = instance; - request = request; - - uname = pairfind(request->packet->vps, PW_USER_NAME); - if (uname) { - DEBUG("rlm_stg: stg_authorize() user name defined as '%s'", uname->vp_strvalue); - } else { - DEBUG("rlm_stg: stg_authorize() user name undefined"); - return RLM_MODULE_FAIL; - } - if (request->username) { - DEBUG("rlm_stg: stg_authorize() request username field: '%s'", request->username->vp_strvalue); - } - if (request->password) { - DEBUG("rlm_stg: stg_authorize() request password field: '%s'", request->password->vp_strvalue); + VALUE_PAIR *uname; + VALUE_PAIR *pwd; + VALUE_PAIR *svc; + DEBUG("rlm_stg: stg_authorize()"); + + /* quiet the compiler */ + instance = instance; + request = request; + + uname = pairfind(request->packet->vps, PW_USER_NAME); + if (uname) { + DEBUG("rlm_stg: stg_authorize() user name defined as '%s'", uname->vp_strvalue); + } else { + DEBUG("rlm_stg: stg_authorize() user name undefined"); + return RLM_MODULE_FAIL; + } + if (request->username) { + DEBUG("rlm_stg: stg_authorize() request username field: '%s'", request->username->vp_strvalue); + } + if (request->password) { + DEBUG("rlm_stg: stg_authorize() request password field: '%s'", request->password->vp_strvalue); + } + // Here we need to define Framed-Protocol + svc = pairfind(request->packet->vps, PW_SERVICE_TYPE); + if (svc) { + DEBUG("rlm_stg: stg_authorize() Service-Type defined as '%s'", svc->vp_strvalue); + if (cli->Authorize((const char *)request->username->vp_strvalue, (const char *)svc->vp_strvalue)) { + DEBUG("rlm_stg: stg_authorize() stg status: '%s'", cli->GetError().c_str()); + return RLM_MODULE_REJECT; } - // Here we need to define Framed-Protocol - svc = pairfind(request->packet->vps, PW_SERVICE_TYPE); - if (svc) { - DEBUG("rlm_stg: stg_authorize() Service-Type defined as '%s'", svc->vp_strvalue); - if (cli->Authorize((const char *)request->username->vp_strvalue, (const char *)svc->vp_strvalue)) { - DEBUG("rlm_stg: stg_authorize() stg status: '%s'", cli->GetError().c_str()); - return RLM_MODULE_REJECT; - } - } else { - DEBUG("rlm_stg: stg_authorize() Service-Type undefined"); - if (cli->Authorize((const char *)request->username->vp_strvalue, "")) { - DEBUG("rlm_stg: stg_authorize() stg status: '%s'", cli->GetError().c_str()); - return RLM_MODULE_REJECT; - } + } else { + DEBUG("rlm_stg: stg_authorize() Service-Type undefined"); + if (cli->Authorize((const char *)request->username->vp_strvalue, "")) { + DEBUG("rlm_stg: stg_authorize() stg status: '%s'", cli->GetError().c_str()); + return RLM_MODULE_REJECT; } - pwd = pairmake("Cleartext-Password", cli->GetUserPassword().c_str(), T_OP_SET); - pairadd(&request->config_items, pwd); - //pairadd(&request->reply->vps, uname); + } + pwd = pairmake("Cleartext-Password", cli->GetUserPassword().c_str(), T_OP_SET); + pairadd(&request->config_items, pwd); + //pairadd(&request->reply->vps, uname); - return RLM_MODULE_UPDATED; + return RLM_MODULE_UPDATED; } /* - * Authenticate the user with the given password. + * Authenticate the user with the given password. */ static int stg_authenticate(void *instance, REQUEST *request) { - /* quiet the compiler */ - VALUE_PAIR *svc; - instance = instance; - request = request; - DEBUG("rlm_stg: stg_authenticate()"); - svc = pairfind(request->packet->vps, PW_SERVICE_TYPE); - if (svc) { - DEBUG("rlm_stg: stg_authenticate() Service-Type defined as '%s'", svc->vp_strvalue); - if (cli->Authenticate((char *)request->username->vp_strvalue, (const char *)svc->vp_strvalue)) { - DEBUG("rlm_stg: stg_authenticate() stg status: '%s'", cli->GetError().c_str()); - return RLM_MODULE_REJECT; - } - } else { - DEBUG("rlm_stg: stg_authenticate() Service-Type undefined"); - if (cli->Authenticate((char *)request->username->vp_strvalue, "")) { - DEBUG("rlm_stg: stg_authenticate() stg status: '%s'", cli->GetError().c_str()); - return RLM_MODULE_REJECT; - } + /* quiet the compiler */ + VALUE_PAIR *svc; + instance = instance; + request = request; + DEBUG("rlm_stg: stg_authenticate()"); + svc = pairfind(request->packet->vps, PW_SERVICE_TYPE); + if (svc) { + DEBUG("rlm_stg: stg_authenticate() Service-Type defined as '%s'", svc->vp_strvalue); + if (cli->Authenticate((char *)request->username->vp_strvalue, (const char *)svc->vp_strvalue)) { + DEBUG("rlm_stg: stg_authenticate() stg status: '%s'", cli->GetError().c_str()); + return RLM_MODULE_REJECT; } + } else { + DEBUG("rlm_stg: stg_authenticate() Service-Type undefined"); + if (cli->Authenticate((char *)request->username->vp_strvalue, "")) { + DEBUG("rlm_stg: stg_authenticate() stg status: '%s'", cli->GetError().c_str()); + return RLM_MODULE_REJECT; + } + } - return RLM_MODULE_NOOP; + return RLM_MODULE_NOOP; } /* - * Massage the request before recording it or proxying it + * Massage the request before recording it or proxying it */ static int stg_preacct(void *instance, REQUEST *request) { - /* quiet the compiler */ - instance = instance; - request = request; - DEBUG("rlm_stg: stg_preacct()"); + /* quiet the compiler */ + instance = instance; + request = request; + DEBUG("rlm_stg: stg_preacct()"); - return RLM_MODULE_OK; + return RLM_MODULE_OK; } /* - * Write accounting information to this modules database. + * Write accounting information to this modules database. */ static int stg_accounting(void *instance, REQUEST *request) { - /* quiet the compiler */ - VALUE_PAIR * sttype; - VALUE_PAIR * svc; - VALUE_PAIR * sessid; - svc = pairfind(request->packet->vps, PW_SERVICE_TYPE); - instance = instance; - request = request; - DEBUG("rlm_stg: stg_accounting()"); - - sessid = pairfind(request->packet->vps, PW_ACCT_SESSION_ID); - if (!sessid) { - DEBUG("rlm_stg: stg_accounting() Acct-Session-ID undefined"); - return RLM_MODULE_FAIL; - } - sttype = pairfind(request->packet->vps, PW_ACCT_STATUS_TYPE); - if (sttype) { - DEBUG("Acct-Status-Type := %s", sttype->vp_strvalue); - if (svc) { - DEBUG("rlm_stg: stg_accounting() Service-Type defined as '%s'", svc->vp_strvalue); - if (cli->Account((const char *)sttype->vp_strvalue, (const char *)request->username->vp_strvalue, (const char *)svc->vp_strvalue, (const char *)sessid->vp_strvalue)) { - DEBUG("rlm_stg: stg_accounting error: '%s'", cli->GetError().c_str()); - return RLM_MODULE_FAIL; - } - } else { - DEBUG("rlm_stg: stg_accounting() Service-Type undefined"); - if (cli->Account((const char *)sttype->vp_strvalue, (const char *)request->username->vp_strvalue, "", (const char *)sessid->vp_strvalue)) { - DEBUG("rlm_stg: stg_accounting error: '%s'", cli->GetError().c_str()); - return RLM_MODULE_FAIL; - } + /* quiet the compiler */ + VALUE_PAIR * sttype; + VALUE_PAIR * svc; + VALUE_PAIR * sessid; + svc = pairfind(request->packet->vps, PW_SERVICE_TYPE); + instance = instance; + request = request; + DEBUG("rlm_stg: stg_accounting()"); + + sessid = pairfind(request->packet->vps, PW_ACCT_SESSION_ID); + if (!sessid) { + DEBUG("rlm_stg: stg_accounting() Acct-Session-ID undefined"); + return RLM_MODULE_FAIL; + } + sttype = pairfind(request->packet->vps, PW_ACCT_STATUS_TYPE); + if (sttype) { + DEBUG("Acct-Status-Type := %s", sttype->vp_strvalue); + if (svc) { + DEBUG("rlm_stg: stg_accounting() Service-Type defined as '%s'", svc->vp_strvalue); + if (cli->Account((const char *)sttype->vp_strvalue, (const char *)request->username->vp_strvalue, (const char *)svc->vp_strvalue, (const char *)sessid->vp_strvalue)) { + DEBUG("rlm_stg: stg_accounting error: '%s'", cli->GetError().c_str()); + return RLM_MODULE_FAIL; } } else { - DEBUG("Acct-Status-Type := NULL"); + DEBUG("rlm_stg: stg_accounting() Service-Type undefined"); + if (cli->Account((const char *)sttype->vp_strvalue, (const char *)request->username->vp_strvalue, "", (const char *)sessid->vp_strvalue)) { + DEBUG("rlm_stg: stg_accounting error: '%s'", cli->GetError().c_str()); + return RLM_MODULE_FAIL; + } } + } else { + DEBUG("Acct-Status-Type := NULL"); + } - return RLM_MODULE_OK; + return RLM_MODULE_OK; } /* - * See if a user is already logged in. Sets request->simul_count to the - * current session count for this user and sets request->simul_mpp to 2 - * if it looks like a multilink attempt based on the requested IP - * address, otherwise leaves request->simul_mpp alone. + * See if a user is already logged in. Sets request->simul_count to the + * current session count for this user and sets request->simul_mpp to 2 + * if it looks like a multilink attempt based on the requested IP + * address, otherwise leaves request->simul_mpp alone. * - * Check twice. If on the first pass the user exceeds his - * max. number of logins, do a second pass and validate all - * logins by querying the terminal server (using eg. SNMP). + * Check twice. If on the first pass the user exceeds his + * 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 *instance, REQUEST *request) { - instance = instance; - DEBUG("rlm_stg: stg_checksimul()"); + instance = instance; + DEBUG("rlm_stg: stg_checksimul()"); - request->simul_count=0; + request->simul_count=0; - return RLM_MODULE_OK; + return RLM_MODULE_OK; } static int stg_postauth(void *instance, REQUEST *request) { - instance = instance; - VALUE_PAIR *fia; - VALUE_PAIR *svc; - struct in_addr fip; - DEBUG("rlm_stg: stg_postauth()"); - svc = pairfind(request->packet->vps, PW_SERVICE_TYPE); - if (svc) { - DEBUG("rlm_stg: stg_postauth() Service-Type defined as '%s'", svc->vp_strvalue); - if (cli->PostAuthenticate((const char *)request->username->vp_strvalue, (const char *)svc->vp_strvalue)) { - DEBUG("rlm_stg: stg_postauth() error: '%s'", cli->GetError().c_str()); - return RLM_MODULE_FAIL; - } - } else { - DEBUG("rlm_stg: stg_postauth() Service-Type undefined"); - if (cli->PostAuthenticate((const char *)request->username->vp_strvalue, "")) { - DEBUG("rlm_stg: stg_postauth() error: '%s'", cli->GetError().c_str()); - return RLM_MODULE_FAIL; - } + instance = instance; + VALUE_PAIR *fia; + VALUE_PAIR *svc; + struct in_addr fip; + DEBUG("rlm_stg: stg_postauth()"); + svc = pairfind(request->packet->vps, PW_SERVICE_TYPE); + if (svc) { + DEBUG("rlm_stg: stg_postauth() Service-Type defined as '%s'", svc->vp_strvalue); + if (cli->PostAuthenticate((const char *)request->username->vp_strvalue, (const char *)svc->vp_strvalue)) { + DEBUG("rlm_stg: stg_postauth() error: '%s'", cli->GetError().c_str()); + return RLM_MODULE_FAIL; } - if (strncmp((const char *)svc->vp_strvalue, "Framed-User", 11) == 0) { - fip.s_addr = cli->GetFramedIP(); - DEBUG("rlm_stg: stg_postauth() ip = '%s'", inet_ntostring(fip.s_addr).c_str()); - fia = pairmake("Framed-IP-Address", inet_ntostring(fip.s_addr).c_str(), T_OP_SET); - pairadd(&request->reply->vps, fia); + } else { + DEBUG("rlm_stg: stg_postauth() Service-Type undefined"); + if (cli->PostAuthenticate((const char *)request->username->vp_strvalue, "")) { + DEBUG("rlm_stg: stg_postauth() error: '%s'", cli->GetError().c_str()); + return RLM_MODULE_FAIL; } - - return RLM_MODULE_UPDATED; + } + if (strncmp((const char *)svc->vp_strvalue, "Framed-User", 11) == 0) { + fip.s_addr = cli->GetFramedIP(); + DEBUG("rlm_stg: stg_postauth() ip = '%s'", inet_ntostring(fip.s_addr).c_str()); + fia = pairmake("Framed-IP-Address", inet_ntostring(fip.s_addr).c_str(), T_OP_SET); + pairadd(&request->reply->vps, fia); + } + + return RLM_MODULE_UPDATED; } static int stg_detach(void *instance) { - DEBUG("rlm_stg: stg_detach()"); - cli->Stop(); - delete cli; - free(((struct rlm_stg_t *)instance)->server); - free(((struct rlm_stg_t *)instance)->password); - free(instance); - return 0; + DEBUG("rlm_stg: stg_detach()"); + cli->Stop(); + delete cli; + free(((struct rlm_stg_t *)instance)->server); + free(((struct rlm_stg_t *)instance)->password); + free(instance); + return 0; } /* - * The module name should be the only globally exported symbol. - * That is, everything else should be 'static'. + * The module name should be the only globally exported symbol. + * That is, everything else should be 'static'. * - * If the module needs to temporarily modify it's instantiation - * data, the type should be changed to RLM_TYPE_THREAD_UNSAFE. - * The server will then take care of ensuring that the module - * is single-threaded. + * If the module needs to temporarily modify it's instantiation + * data, the type should be changed to RLM_TYPE_THREAD_UNSAFE. + * The server will then take care of ensuring that the module + * is single-threaded. */ module_t rlm_stg = { - RLM_MODULE_INIT, - "stg", - RLM_TYPE_THREAD_SAFE, /* type */ - stg_instantiate, /* instantiation */ - stg_detach, /* detach */ - { - 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 */ - }, + RLM_MODULE_INIT, + "stg", + RLM_TYPE_THREAD_SAFE, /* type */ + stg_instantiate, /* instantiation */ + stg_detach, /* detach */ + { + 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 */ + }, }; -- 2.44.2 From fd082d2de4f5e845c09676b21b58cb5de7e05837 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Thu, 9 Dec 2010 14:20:44 +0200 Subject: [PATCH 13/16] =?utf8?q?=D0=A0=D0=B5=D1=84=D0=B0=D0=BA=D1=82=D0=BE?= =?utf8?q?=D1=80=D0=B8=D0=BD=D0=B3=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=B0?= =?utf8?q?=20STG=5FCLIENT=20=D0=BF=D0=BB=D0=B0=D0=B3=D0=B8=D0=BD=D0=B0=20r?= =?utf8?q?lm=5Fstg?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- projects/rlm_stg/stg_client.cpp | 94 ++++++++++++--------------------- projects/rlm_stg/stg_client.h | 13 +---- 2 files changed, 36 insertions(+), 71 deletions(-) diff --git a/projects/rlm_stg/stg_client.cpp b/projects/rlm_stg/stg_client.cpp index 7be0a55e..75d443ad 100644 --- a/projects/rlm_stg/stg_client.cpp +++ b/projects/rlm_stg/stg_client.cpp @@ -29,8 +29,12 @@ #include #include #include // close + +#include #include +#include + #include "stg_client.h" using namespace std; @@ -38,35 +42,36 @@ using namespace std; //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- -STG_CLIENT::STG_CLIENT() - : port(0), - localPort(0), - sock(0) +STG_CLIENT::STG_CLIENT(const std::string & host, uint16_t port, uint16_t lp, const std::string & pass) + : localPort(lp), + password(pass), + framedIP(0) { +sock = socket(AF_INET, SOCK_DGRAM, 0); +if (sock == -1) + { + std::string message = strerror(errno); + message = "Socket create error: '" + message + "'"; + throw std::runtime_error(message); + } + +struct hostent * he = NULL; +he = gethostbyname(host.c_str()); +if (he == NULL) + { + throw std::runtime_error("gethostbyname error"); + } + +outerAddr.sin_family = AF_INET; +outerAddr.sin_port = htons(port); +outerAddr.sin_addr.s_addr = *(uint32_t *)he->h_addr; + +InitEncrypt(); } //----------------------------------------------------------------------------- STG_CLIENT::~STG_CLIENT() { -} -//----------------------------------------------------------------------------- -void STG_CLIENT::SetServer(const string & host) -{ -STG_CLIENT::host = host; -} -//----------------------------------------------------------------------------- -void STG_CLIENT::SetPort(uint16_t port) -{ -STG_CLIENT::port = port; -} -//----------------------------------------------------------------------------- -void STG_CLIENT::SetLocalPort(uint16_t port) -{ -STG_CLIENT::localPort = port; -} -//----------------------------------------------------------------------------- -void STG_CLIENT::SetPassword(const string & password) -{ -STG_CLIENT::password = password; +close(sock); } //----------------------------------------------------------------------------- uint32_t STG_CLIENT::GetFramedIP() const @@ -74,6 +79,7 @@ uint32_t STG_CLIENT::GetFramedIP() const return framedIP; } //----------------------------------------------------------------------------- +inline void STG_CLIENT::InitEncrypt() { unsigned char keyL[RAD_PASSWORD_LEN]; @@ -84,21 +90,6 @@ Blowfish_Init(&ctx, keyL, RAD_PASSWORD_LEN); //----------------------------------------------------------------------------- int STG_CLIENT::PrepareNet() { -sock = socket(AF_INET, SOCK_DGRAM, 0); -if (sock == -1) - { - errorStr = "Socket create error"; - return -1; - } - -struct hostent * he = NULL; -he = gethostbyname(host.c_str()); -if (he == NULL) - { - errorStr = "gethostbyname error"; - return -1; - } - if (localPort != 0) { struct sockaddr_in localAddr; @@ -112,32 +103,16 @@ if (localPort != 0) return -1; } } - -outerAddr.sin_family = AF_INET; -outerAddr.sin_port = htons(port); -outerAddr.sin_addr.s_addr = *(uint32_t *)he->h_addr; - -outerAddrLen = sizeof(struct sockaddr_in); - return 0; } //----------------------------------------------------------------------------- -void STG_CLIENT::FinalizeNet() -{ -close(sock); -} -//----------------------------------------------------------------------------- int STG_CLIENT::Start() { -InitEncrypt(); - return PrepareNet(); } //----------------------------------------------------------------------------- int STG_CLIENT::Stop() { -FinalizeNet(); - return 0; } //----------------------------------------------------------------------------- @@ -152,7 +127,7 @@ char buf[RAD_MAX_PACKET_LEN]; Encrypt(buf, (char *)&packet, sizeof(RAD_PACKET) / 8); -int res = sendto(sock, buf, sizeof(RAD_PACKET), 0, (struct sockaddr *)&outerAddr, outerAddrLen); +int res = sendto(sock, buf, sizeof(RAD_PACKET), 0, (struct sockaddr *)&outerAddr, sizeof(outerAddr)); if (res == -1) errorStr = "Error sending data"; @@ -165,9 +140,10 @@ int STG_CLIENT::RecvData(RAD_PACKET * packet) char buf[RAD_MAX_PACKET_LEN]; int res; -outerAddrLen = sizeof(struct sockaddr_in); +struct sockaddr_in addr; +socklen_t len = sizeof(struct sockaddr_in); -res = recvfrom(sock, buf, RAD_MAX_PACKET_LEN, 0, (struct sockaddr *)&outerAddr, &outerAddrLen); +res = recvfrom(sock, buf, RAD_MAX_PACKET_LEN, 0, reinterpret_cast(&addr), &len); if (res == -1) { errorStr = "Error receiving data"; @@ -307,7 +283,7 @@ if (dst != src) for (int i = 0; i < len8; i++) Blowfish_Encrypt(&ctx, (uint32_t *)(dst + i*8), (uint32_t *)(dst + i*8 + 4)); } -//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- void STG_CLIENT::Decrypt(char * dst, const char * src, int len8) { // len8 - длина в 8-ми байтовых блоках diff --git a/projects/rlm_stg/stg_client.h b/projects/rlm_stg/stg_client.h index 60ed6af8..253b262f 100644 --- a/projects/rlm_stg/stg_client.h +++ b/projects/rlm_stg/stg_client.h @@ -41,14 +41,9 @@ class STG_CLIENT { public: - STG_CLIENT(); + STG_CLIENT(const std::string & host, uint16_t port, uint16_t lp, const std::string & pass); ~STG_CLIENT(); - void SetServer(const std::string & host); - void SetPort(uint16_t port); - void SetLocalPort(uint16_t port); - void SetPassword(const std::string & password); - int Start(); int Stop(); @@ -61,19 +56,15 @@ public: uint32_t GetFramedIP() const; - const std::string & GetError() const { return errorStr; }; private: - std::string host; - uint16_t port; uint16_t localPort; std::string password; int sock; std::string errorStr; struct sockaddr_in outerAddr; - socklen_t outerAddrLen; std::string userPassword; @@ -82,7 +73,6 @@ private: BLOWFISH_CTX ctx; int PrepareNet(); - void FinalizeNet(); void InitEncrypt(); void Encrypt(char * dst, const char * src, int len8); @@ -92,7 +82,6 @@ private: int RecvData(RAD_PACKET * packet); int Send(const RAD_PACKET & packet); - }; #endif -- 2.44.2 From 2c1686d0b3dee0f327cda1b55ac7e42b21446416 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Thu, 9 Dec 2010 14:51:01 +0200 Subject: [PATCH 14/16] =?utf8?q?=D0=9D=D0=B5=D0=B1=D0=BE=D0=BB=D1=8C=D1=88?= =?utf8?q?=D0=BE=D0=B9=20=D1=80=D0=B5=D1=84=D0=B0=D0=BA=D1=82=D0=BE=D1=80?= =?utf8?q?=D0=B8=D0=BD=D0=B3=20=D0=BF=D0=BB=D0=B0=D0=B3=D0=B8=D0=BD=D0=B0?= =?utf8?q?=20radius?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../stargazer/plugins/other/radius/radius.cpp | 38 ++---------------- .../stargazer/plugins/other/radius/radius.h | 39 ++++++++++--------- 2 files changed, 24 insertions(+), 53 deletions(-) diff --git a/projects/stargazer/plugins/other/radius/radius.cpp b/projects/stargazer/plugins/other/radius/radius.cpp index 8c7d53d1..4dd18c46 100644 --- a/projects/stargazer/plugins/other/radius/radius.cpp +++ b/projects/stargazer/plugins/other/radius/radius.cpp @@ -26,8 +26,8 @@ * */ +#include #include -#include #include "radius.h" #include "common.h" @@ -71,35 +71,6 @@ return radc.GetPlugin(); //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- -uint16_t RAD_SETTINGS::GetPort() const -{ -return port; -} -//----------------------------------------------------------------------------- -int RAD_SETTINGS::GetPassword(string * password) const -{ -*password = RAD_SETTINGS::password; -return 0; -} -//----------------------------------------------------------------------------- -int RAD_SETTINGS::GetAuthServices(list * svcs) const -{ -*svcs = authServices; -return 0; -} -//----------------------------------------------------------------------------- -int RAD_SETTINGS::GetAcctServices(list * svcs) const -{ -*svcs = acctServices; -return 0; -} -//----------------------------------------------------------------------------- -int RAD_SETTINGS::ParseIP(const string & str, uint32_t * IP) -{ -*IP = inet_addr(str.c_str()); -return *IP == INADDR_NONE ? -1 : 0; -} -//----------------------------------------------------------------------------- int RAD_SETTINGS::ParseIntInRange(const string & str, int min, int max, int * val) { if (str2x(str.c_str(), *val)) @@ -279,11 +250,10 @@ return 0; //----------------------------------------------------------------------------- int RADIUS::Start() { -string password; +string password(radSettings.GetPassword()); -radSettings.GetPassword(&password); -radSettings.GetAuthServices(&authServices); -radSettings.GetAcctServices(&acctServices); +authServices = radSettings.GetAuthServices(); +acctServices = radSettings.GetAcctServices(); InitEncrypt(&ctx, password); diff --git a/projects/stargazer/plugins/other/radius/radius.h b/projects/stargazer/plugins/other/radius/radius.h index 8d37ab14..e13a7a7f 100644 --- a/projects/stargazer/plugins/other/radius/radius.h +++ b/projects/stargazer/plugins/other/radius/radius.h @@ -29,11 +29,12 @@ #ifndef RADIUS_H #define RADIUS_H +#include + +#include +#include #include #include -#include -#include -#include #include "os_int.h" #include "base_auth.h" @@ -55,24 +56,24 @@ class RADIUS; class RAD_SETTINGS { public: - virtual ~RAD_SETTINGS(){}; - const string& GetStrError() const { return errorStr; }; - int ParseSettings(const MODULE_SETTINGS & s); - uint16_t GetPort() const; - int GetPassword(string * password) const; - int GetAuthServices(list * svcs) const; - int GetAcctServices(list * svcs) const; + RAD_SETTINGS() : port(0) {} + virtual ~RAD_SETTINGS() {} + const string & GetStrError() const { return errorStr; } + int ParseSettings(const MODULE_SETTINGS & s); + uint16_t GetPort() const { return port; } + const std::string & GetPassword() const { return password; } + const list & GetAuthServices() const { return authServices; } + const list & GetAcctServices() const { return acctServices; } private: - int ParseIntInRange(const string & str, int min, int max, int * val); - int ParseIP(const string & str, uint32_t * routerIP); - int ParseServices(const vector & str, list * lst); - - uint16_t port; - string errorStr; - string password; - list authServices; - list acctServices; + int ParseIntInRange(const string & str, int min, int max, int * val); + int ParseServices(const vector & str, list * lst); + + uint16_t port; + string errorStr; + string password; + list authServices; + list acctServices; }; //----------------------------------------------------------------------------- struct RAD_SESSION { -- 2.44.2 From 3b56895a961ab712e2dacd85636baec808c1ac8d Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Thu, 9 Dec 2010 14:58:32 +0200 Subject: [PATCH 15/16] =?utf8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?utf8?q?=D0=B5=D0=BD=D0=B0=20=D1=83=D1=82=D0=B5=D1=87=D0=BA=D0=B0=20?= =?utf8?q?=D1=80=D0=B5=D1=81=D1=83=D1=80=D1=81=D0=B0=20(=D1=84=D0=B0=D0=B9?= =?utf8?q?=D0=BB=D0=BE=D0=B2=D1=8B=D0=B9=20=D0=B4=D0=B5=D1=81=D0=BA=D1=80?= =?utf8?q?=D0=B8=D0=BF=D1=82=D0=BE=D1=80)=20=D0=B2=20=D0=BF=D0=BB=D0=B0?= =?utf8?q?=D0=B3=D0=B8=D0=BD=D0=B5=20store=5Ffiles.=20=D0=A3=D1=82=D0=B5?= =?utf8?q?=D1=87=D0=BA=D0=B0=20=D0=BF=D1=80=D0=BE=D0=B8=D1=81=D1=85=D0=BE?= =?utf8?q?=D0=B4=D0=B8=D0=BB=D0=B0=20=D0=BF=D1=80=D0=B8=20=D0=B2=D0=BE?= =?utf8?q?=D0=B7=D0=BD=D0=B8=D0=BA=D0=BD=D0=BE=D0=B2=D0=B5=D0=BD=D0=B8?= =?utf8?q?=D0=B8=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D0=B8,=20=D0=BF=D0=BE=20?= =?utf8?q?=D1=8D=D1=82=D0=BE=D0=BC=D1=83=20=D0=BD=D0=B8=D0=BA=D0=BE=D0=B3?= =?utf8?q?=D0=B4=D0=B0=20=D0=BD=D0=B5=20=D0=BF=D1=80=D0=BE=D1=8F=D0=B2?= =?utf8?q?=D0=BB=D1=8F=D0=BB=D0=B0=D1=81=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../plugins/store/files/file_store.cpp | 2 ++ .../plugins/store/files/file_store.h | 21 +++++++++++-------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/projects/stargazer/plugins/store/files/file_store.cpp b/projects/stargazer/plugins/store/files/file_store.cpp index fe5ed230..57f825d6 100644 --- a/projects/stargazer/plugins/store/files/file_store.cpp +++ b/projects/stargazer/plugins/store/files/file_store.cpp @@ -1921,6 +1921,7 @@ while (stIter != statTree.end()) errorStr += strerror(errno); errorStr += "'"; printfd(__FILE__, "FILES_STORE::WriteDetailStat - fprintf failed. Message: '%s'\n", strerror(errno)); + fclose(statFile); return -1; } #else @@ -1936,6 +1937,7 @@ while (stIter != statTree.end()) errorStr += strerror(errno); errorStr += "'"; printfd(__FILE__, "FILES_STORE::WriteDetailStat - fprintf failed. Message: '%s'\n", strerror(errno)); + fclose(statFile); return -1; } #endif diff --git a/projects/stargazer/plugins/store/files/file_store.h b/projects/stargazer/plugins/store/files/file_store.h index 13c3a3fa..bf9fbf00 100644 --- a/projects/stargazer/plugins/store/files/file_store.h +++ b/projects/stargazer/plugins/store/files/file_store.h @@ -28,9 +28,10 @@ #ifndef FILE_STORE_H #define FILE_STORE_H -#include #include +#include + #include "base_settings.h" #include "base_store.h" #include "conffiles.h" @@ -80,6 +81,7 @@ private: int ParseGroup(const vector & moduleParams, const string & group, uid_t * uid); int ParseMode(const vector & moduleParams, const string & modeStr, mode_t * mode); int ParseYesNo(const string & value, bool * val); + string errorStr; string workDir; @@ -181,8 +183,8 @@ public: virtual int DelService(const string &) const {return 0;}; //virtual BASE_SETTINGS * GetStoreSettings(); - virtual void SetSettings(const MODULE_SETTINGS & s); - virtual int ParseSettings(); + virtual void SetSettings(const MODULE_SETTINGS & s); + virtual int ParseSettings(); virtual const string & GetVersion() const; private: @@ -191,12 +193,13 @@ private: virtual int WriteLogString(const string & str, const string & login) const; virtual int WriteLog2String(const string & str, const string & login) const; - int RemoveDir(const char * path) const; - int GetFilesList(vector * filesList, const string & directory, mode_t mode, const string & ext) const; - mutable string errorStr; - string version; - FILES_STORE_SETTINGS storeSettings; - MODULE_SETTINGS settings; + int RemoveDir(const char * path) const; + int GetFilesList(vector * filesList, const string & directory, mode_t mode, const string & ext) const; + + mutable string errorStr; + string version; + FILES_STORE_SETTINGS storeSettings; + MODULE_SETTINGS settings; mutable pthread_mutex_t mutex; }; //----------------------------------------------------------------------------- -- 2.44.2 From 3dfd70b31d34532a4d2e92fb4d4ee611c1518f18 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Thu, 9 Dec 2010 15:37:57 +0200 Subject: [PATCH 16/16] =?utf8?q?=D0=A0=D0=B5=D1=84=D0=B0=D0=BA=D1=82=D0=BE?= =?utf8?q?=D1=80=D0=B8=D0=BD=D0=B3=20=D0=BA=D0=BE=D0=B4=D0=B0=20=D0=BA?= =?utf8?q?=D0=BB=D0=B0=D1=81=D1=81=D0=BE=D0=B2=20NETTRANSACT=20=D0=B8=20SE?= =?utf8?q?RVCONF=20=D0=B1=D0=B8=D0=B1=D0=BB=D0=B8=D0=BE=D1=82=D0=B5=D0=BA?= =?utf8?q?=D0=B8=20=D0=BF=D0=BE=D0=B4=D0=B4=D0=B5=D1=80=D0=B6=D0=BA=D0=B8?= =?utf8?q?=20=D0=BF=D1=80=D0=BE=D1=82=D0=BE=D0=BA=D0=BE=D0=BB=D0=B0=20?= =?utf8?q?=D0=BA=D0=BE=D0=BD=D1=84=D0=B8=D0=B3=D1=83=D1=80=D0=B0=D1=82?= =?utf8?q?=D0=BE=D1=80=D0=B0,=20=D1=81=D1=82=D1=80=D0=BE=D0=BA=D0=BE=D0=B2?= =?utf8?q?=D1=8B=D0=B5=20=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B=D0=B5=20=D0=BF?= =?utf8?q?=D1=80=D0=B5=D0=B4=D1=81=D1=82=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD?= =?utf8?q?=D1=8B=20=D1=81=D1=82=D1=80=D0=BE=D0=BA=D0=B0=D0=BC=D0=B8=20C++?= =?utf8?q?=20=D0=B0=20=D0=BD=D0=B5=20=D0=BE=D0=B1=D1=8B=D1=87=D0=BD=D1=8B?= =?utf8?q?=D0=BC=D0=B8=20=D1=81=D1=82=D1=80=D0=BE=D0=BA=D0=B0=D0=BC=D0=B8?= =?utf8?q?=20C=20=D0=BA=D0=B0=D0=BA=20=D1=80=D0=B0=D0=BD=D0=B5=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- stglibs/srvconf.lib/netunit.cpp | 55 ++++++++++++++--------------- stglibs/srvconf.lib/netunit.h | 7 ++-- stglibs/srvconf.lib/servconf.cpp | 60 ++++++++++++++------------------ stglibs/srvconf.lib/servconf.h | 10 +++--- 4 files changed, 63 insertions(+), 69 deletions(-) diff --git a/stglibs/srvconf.lib/netunit.cpp b/stglibs/srvconf.lib/netunit.cpp index ec796f7f..8d559193 100644 --- a/stglibs/srvconf.lib/netunit.cpp +++ b/stglibs/srvconf.lib/netunit.cpp @@ -25,12 +25,13 @@ */ //--------------------------------------------------------------------------- -#include -#include #include #include #include +#include +#include + #include "netunit.h" #include "common.h" @@ -56,15 +57,13 @@ NETTRANSACT::NETTRANSACT() RxCallBack(NULL), dataRxCallBack(NULL) { - memset(server, 0, SERVER_NAME_LEN); memset(login, 0, ADM_LOGIN_LEN); memset(password, 0, ADM_PASSWD_LEN); - memset(errorMsg, 0, MAX_ERR_STR_LEN); } //----------------------------------------------------------------------------- void NETTRANSACT::EnDecryptInit(const char * passwd, int, BLOWFISH_CTX *ctx) { -unsigned char * keyL = NULL; // ��� ������ +unsigned char * keyL = NULL; keyL = new unsigned char[PASSWD_LEN]; @@ -94,7 +93,7 @@ int ret; outerSocket = socket(PF_INET, SOCK_STREAM, 0); if (outerSocket < 0) { - strcpy(errorMsg, CREATE_SOCKET_ERROR); + errorMsg = CREATE_SOCKET_ERROR; return st_conn_fail; } @@ -105,14 +104,14 @@ struct hostent he; struct hostent * phe; unsigned long ip; -ip = inet_addr(server); +ip = inet_addr(server.c_str()); if (ip == INADDR_NONE) { - phe = gethostbyname(server); + phe = gethostbyname(server.c_str()); if (phe == NULL) { - sprintf(errorMsg, "DNS error.\nCan not reslove %s", server); + errorMsg = "DNS error.\nCan not reslove " + server; return st_dns_err; } @@ -127,7 +126,7 @@ ret = connect(outerSocket, (struct sockaddr*)&outerAddr, sizeof(outerAddr)); if (ret < 0) { - strcpy(errorMsg, CONNECT_FAILED); + errorMsg = CONNECT_FAILED; close(outerSocket); return st_conn_fail; } @@ -200,7 +199,7 @@ int ret; ret = send(outerSocket, STG_HEADER, strlen(STG_HEADER), 0); if (ret <= 0) { - strcpy(errorMsg, SEND_HEADER_ERROR); + errorMsg = SEND_HEADER_ERROR; return st_send_fail; } @@ -215,7 +214,7 @@ int ret; ret = recv(outerSocket, buffer, strlen(OK_HEADER), 0); if (ret <= 0) { - strcpy(errorMsg, RECV_HEADER_ANSWER_ERROR); + errorMsg = RECV_HEADER_ANSWER_ERROR; return st_recv_fail; } @@ -227,12 +226,12 @@ else { if (strncmp(ERR_HEADER, buffer, strlen(ERR_HEADER)) == 0) { - strcpy(errorMsg, INCORRECT_HEADER); + errorMsg = INCORRECT_HEADER; return st_header_err; } else { - strcpy(errorMsg, UNKNOWN_ERROR); + errorMsg = UNKNOWN_ERROR; return st_unknown_err; } } @@ -249,7 +248,7 @@ ret = send(outerSocket, loginZ, ADM_LOGIN_LEN, 0); if (ret <= 0) { - strcpy(errorMsg, SEND_LOGIN_ERROR); + errorMsg = SEND_LOGIN_ERROR; return st_send_fail; } @@ -259,12 +258,12 @@ return st_ok; int NETTRANSACT::RxLoginAnswer() { char buffer[sizeof(OK_LOGIN)+1]; -int ret;//, we; +int ret; ret = recv(outerSocket, buffer, strlen(OK_LOGIN), 0); if (ret <= 0) { - strcpy(errorMsg, RECV_LOGIN_ANSWER_ERROR); + errorMsg = RECV_LOGIN_ANSWER_ERROR; return st_recv_fail; } @@ -276,12 +275,12 @@ else { if (strncmp(ERR_LOGIN, buffer, strlen(ERR_LOGIN)) == 0) { - strcpy(errorMsg, INCORRECT_LOGIN); + errorMsg = INCORRECT_LOGIN; return st_login_err; } else { - strcpy(errorMsg, UNKNOWN_ERROR); + errorMsg = UNKNOWN_ERROR; return st_unknown_err; } } @@ -305,7 +304,7 @@ for (int j = 0; j < ADM_LOGIN_LEN / ENC_MSG_LEN; j++) ret = send(outerSocket, ct, ENC_MSG_LEN, 0); if (ret <= 0) { - strcpy(errorMsg, SEND_LOGIN_ERROR); + errorMsg = SEND_LOGIN_ERROR; return st_send_fail; } } @@ -321,7 +320,7 @@ int ret; ret = recv(outerSocket, buffer, strlen(OK_LOGINS), 0); if (ret <= 0) { - strcpy(errorMsg, RECV_LOGIN_ANSWER_ERROR); + errorMsg = RECV_LOGIN_ANSWER_ERROR; return st_recv_fail; } @@ -333,12 +332,12 @@ else { if (strncmp(ERR_LOGINS, buffer, strlen(ERR_LOGINS)) == 0) { - strcpy(errorMsg, INCORRECT_LOGIN); + errorMsg = INCORRECT_LOGIN; return st_logins_err; } else { - strcpy(errorMsg, UNKNOWN_ERROR); + errorMsg = UNKNOWN_ERROR; return st_unknown_err; } } @@ -364,7 +363,7 @@ for (j = 0; j < n; j++) ret = send(outerSocket, ct, ENC_MSG_LEN, 0); if (ret <= 0) { - strcpy(errorMsg, SEND_DATA_ERROR); + errorMsg = SEND_DATA_ERROR; return st_send_fail; } } @@ -379,7 +378,7 @@ Encrypt(ct, textZ, &ctx); ret = send(outerSocket, ct, ENC_MSG_LEN, 0); if (ret <= 0) { - strcpy(errorMsg, SEND_DATA_ERROR); + errorMsg = SEND_DATA_ERROR; return st_send_fail; } @@ -429,7 +428,7 @@ while (1) if (ret <= 0) { close(outerSocket); - strcpy(errorMsg, RECV_DATA_ANSWER_ERROR); + errorMsg = RECV_DATA_ANSWER_ERROR; return st_recv_fail; } @@ -470,7 +469,7 @@ strncpy(password, p, ADM_PASSWD_LEN); //--------------------------------------------------------------------------- void NETTRANSACT::SetServer(const char * serverName) { -strncpy(server, serverName, SERVER_NAME_LEN); +server = serverName; } //--------------------------------------------------------------------------- void NETTRANSACT::SetServerPort(short unsigned p) @@ -484,7 +483,7 @@ RxCallBack = cb; dataRxCallBack = data; } //--------------------------------------------------------------------------- -char * NETTRANSACT::GetError() +const std::string & NETTRANSACT::GetError() const { return errorMsg; } diff --git a/stglibs/srvconf.lib/netunit.h b/stglibs/srvconf.lib/netunit.h index f5161503..007dc8c5 100644 --- a/stglibs/srvconf.lib/netunit.h +++ b/stglibs/srvconf.lib/netunit.h @@ -30,6 +30,7 @@ #include #include #include + #include #include @@ -80,7 +81,7 @@ class NETTRANSACT public: NETTRANSACT(); int Transact(const char * data); - char *GetError(); + const std::string & GetError() const; void SetRxCallback(void * data, RxCallback_t); @@ -111,7 +112,7 @@ private: void EnDecryptInit(const char * passwd, int passwdLen, BLOWFISH_CTX *ctx); void Decrypt(char * d, const char * s, BLOWFISH_CTX *ctx); - char server[SERVER_NAME_LEN]; + std::string server; short unsigned port; char login[ADM_LOGIN_LEN]; char password[ADM_PASSWD_LEN]; @@ -119,7 +120,7 @@ private: std::list answerList; RxCallback_t RxCallBack; void * dataRxCallBack; - char errorMsg[MAX_ERR_STR_LEN]; + std::string errorMsg; }; //--------------------------------------------------------------------------- #endif diff --git a/stglibs/srvconf.lib/servconf.cpp b/stglibs/srvconf.lib/servconf.cpp index 8061d7aa..8074801e 100644 --- a/stglibs/srvconf.lib/servconf.cpp +++ b/stglibs/srvconf.lib/servconf.cpp @@ -24,8 +24,8 @@ $Author: faust $ */ -#include -#include +#include +#include #include "servconf.h" @@ -63,12 +63,9 @@ while (node != list1->end()) if (XML_Parse(sc->parser, ans, len, done) == XML_STATUS_ERROR) { - snprintf(sc->errorMsg, MAX_ERR_STR_LEN, "XML parse error at line %d: %s", - static_cast(XML_GetCurrentLineNumber(sc->parser)), - XML_ErrorString(XML_GetErrorCode(sc->parser))); - printf(sc->errorMsg, "XML parse error at line %d: %s", - XML_GetCurrentLineNumber(sc->parser), - XML_ErrorString(XML_GetErrorCode(sc->parser))); + strprintf(&sc->errorMsg, "XML parse error at line %d: %s", + static_cast(XML_GetCurrentLineNumber(sc->parser)), + XML_ErrorString(XML_GetErrorCode(sc->parser))); return st_xml_parse_error; } ++node; @@ -132,17 +129,17 @@ nt.SetRxCallback(this, AnsRecv); if ((ret = nt.Connect()) != st_ok) { - strncpy(errorMsg, nt.GetError(), MAX_ERR_STR_LEN); + errorMsg = nt.GetError(); return ret; } if ((ret = nt.Transact(request)) != st_ok) { - strncpy(errorMsg, nt.GetError(), MAX_ERR_STR_LEN); + errorMsg = nt.GetError(); return ret; } if ((ret = nt.Disconnect()) != st_ok) { - strncpy(errorMsg, nt.GetError(), MAX_ERR_STR_LEN); + errorMsg = nt.GetError(); return ret; } @@ -162,17 +159,17 @@ nt.SetRxCallback(this, AnsRecv); if ((ret = nt.Connect()) != st_ok) { - strncpy(errorMsg, nt.GetError(), MAX_ERR_STR_LEN); + errorMsg = nt.GetError(); return ret; } if ((ret = nt.Transact(request)) != st_ok) { - strncpy(errorMsg, nt.GetError(), MAX_ERR_STR_LEN); + errorMsg = nt.GetError(); return ret; } if ((ret = nt.Disconnect()) != st_ok) { - strncpy(errorMsg, nt.GetError(), MAX_ERR_STR_LEN); + errorMsg = nt.GetError(); return ret; } @@ -195,17 +192,17 @@ nt.SetRxCallback(this, AnsRecv); if ((ret = nt.Connect()) != st_ok) { - strncpy(errorMsg, nt.GetError(), MAX_ERR_STR_LEN); + errorMsg = nt.GetError(); return ret; } if ((ret = nt.Transact(request)) != st_ok) { - strncpy(errorMsg, nt.GetError(), MAX_ERR_STR_LEN); + errorMsg = nt.GetError(); return ret; } if ((ret = nt.Disconnect()) != st_ok) { - strncpy(errorMsg, nt.GetError(), MAX_ERR_STR_LEN); + errorMsg = nt.GetError(); return ret; } @@ -225,17 +222,17 @@ nt.SetRxCallback(this, AnsRecv); if ((ret = nt.Connect()) != st_ok) { - strncpy(errorMsg, nt.GetError(), MAX_ERR_STR_LEN); + errorMsg = nt.GetError(); return ret; } if ((ret = nt.Transact(request)) != st_ok) { - strncpy(errorMsg, nt.GetError(), MAX_ERR_STR_LEN); + errorMsg = nt.GetError(); return ret; } if ((ret = nt.Disconnect()) != st_ok) { - strncpy(errorMsg, nt.GetError(), MAX_ERR_STR_LEN); + errorMsg = nt.GetError(); return ret; } @@ -254,20 +251,17 @@ nt.SetRxCallback(this, AnsRecv); if ((ret = nt.Connect()) != st_ok) { - strncpy(errorMsg, nt.GetError(), MAX_ERR_STR_LEN); - printfd(__FILE__, "Error on connect: '%s'\n", errorMsg); + errorMsg = nt.GetError(); return ret; } if ((ret = nt.Transact(request)) != st_ok) { - strncpy(errorMsg, nt.GetError(), MAX_ERR_STR_LEN); - printfd(__FILE__, "Error on transact: '%s'\n", errorMsg); + errorMsg = nt.GetError(); return ret; } if ((ret = nt.Disconnect()) != st_ok) { - strncpy(errorMsg, nt.GetError(), MAX_ERR_STR_LEN); - printfd(__FILE__, "Error on disconnect: '%s'\n", errorMsg); + errorMsg = nt.GetError(); return ret; } @@ -288,17 +282,17 @@ nt.SetRxCallback(this, AnsRecv); if ((ret = nt.Connect()) != st_ok) { - strncpy(errorMsg, nt.GetError(), MAX_ERR_STR_LEN); + errorMsg = nt.GetError(); return ret; } if ((ret = nt.Transact(request)) != st_ok) { - strncpy(errorMsg, nt.GetError(), MAX_ERR_STR_LEN); + errorMsg = nt.GetError(); return ret; } if ((ret = nt.Disconnect()) != st_ok) { - strncpy(errorMsg, nt.GetError(), MAX_ERR_STR_LEN); + errorMsg = nt.GetError(); return ret; } @@ -319,17 +313,17 @@ nt.SetRxCallback(this, AnsRecv); if ((ret = nt.Connect()) != st_ok) { - strncpy(errorMsg, nt.GetError(), MAX_ERR_STR_LEN); + errorMsg = nt.GetError(); return ret; } if ((ret = nt.Transact(request)) != st_ok) { - strncpy(errorMsg, nt.GetError(), MAX_ERR_STR_LEN); + errorMsg = nt.GetError(); return ret; } if ((ret = nt.Disconnect()) != st_ok) { - strncpy(errorMsg, nt.GetError(), MAX_ERR_STR_LEN); + errorMsg = nt.GetError(); return ret; } @@ -383,7 +377,7 @@ RecvSendMessageCb = f; sendMessageDataCb = data; } //----------------------------------------------------------------------------- -char * SERVCONF::GetStrError() +const std::string & SERVCONF::GetStrError() const { return errorMsg; } diff --git a/stglibs/srvconf.lib/servconf.h b/stglibs/srvconf.lib/servconf.h index 874b6ab1..9edbe6dd 100644 --- a/stglibs/srvconf.lib/servconf.h +++ b/stglibs/srvconf.lib/servconf.h @@ -250,8 +250,8 @@ public: int GetServerInfo(); int CheckUser(const char * login, const char * password); - char * GetStrError(); - int GetError(); + const std::string & GetStrError() const; + int GetError(); int Start(const char *el, const char **attr); void End(const char *el); @@ -269,9 +269,9 @@ private: int parseDepth; USERDATA ud; - char errorMsg[MAX_ERR_STR_LEN]; - int error; - XML_Parser parser; + std::string errorMsg; + int error; + XML_Parser parser; RecvUserDataCb_t RecvUserDataCb; RecvUserDataCb_t RecvGetUserDataCb; -- 2.44.2