From 8f27e65bddd7d4b8515ce620fb485fdd78fcdf89 Mon Sep 17 00:00:00 2001 From: Constantin Jucovschi Date: Fri, 24 Apr 2009 07:20:22 -0400 Subject: Initial commit --- rascontrol/Makefile.am | 53 +++++ rascontrol/rascontrol.cc | 341 ++++++++++++++++++++++++++++++ rascontrol/rascontrol.hh | 164 +++++++++++++++ rascontrol/rascontrol_class.cc | 398 +++++++++++++++++++++++++++++++++++ rascontrol/rasmgr_tester.cc | 171 +++++++++++++++ rascontrol/rasmgr_tester.hh | 85 ++++++++ rascontrol/rasmgr_utils_comm.cc | 359 +++++++++++++++++++++++++++++++ rascontrol/rasmgr_utils_comm.hh | 127 +++++++++++ rascontrol/rasmgr_utils_conf.cc | 71 +++++++ rascontrol/rasmgr_utils_conf.hh | 61 ++++++ rascontrol/raspasswd.cc | 241 +++++++++++++++++++++ rascontrol/raspasswd.hh | 89 ++++++++ rascontrol/test/rasmgrtest.cc | 178 ++++++++++++++++ rascontrol/test/rasmgrtester_conf.cc | 133 ++++++++++++ rascontrol/test/rasmgrtester_conf.hh | 79 +++++++ 15 files changed, 2550 insertions(+) create mode 100644 rascontrol/Makefile.am create mode 100644 rascontrol/rascontrol.cc create mode 100644 rascontrol/rascontrol.hh create mode 100644 rascontrol/rascontrol_class.cc create mode 100644 rascontrol/rasmgr_tester.cc create mode 100644 rascontrol/rasmgr_tester.hh create mode 100644 rascontrol/rasmgr_utils_comm.cc create mode 100644 rascontrol/rasmgr_utils_comm.hh create mode 100644 rascontrol/rasmgr_utils_conf.cc create mode 100644 rascontrol/rasmgr_utils_conf.hh create mode 100644 rascontrol/raspasswd.cc create mode 100644 rascontrol/raspasswd.hh create mode 100644 rascontrol/test/rasmgrtest.cc create mode 100644 rascontrol/test/rasmgrtester_conf.cc create mode 100644 rascontrol/test/rasmgrtester_conf.hh (limited to 'rascontrol') diff --git a/rascontrol/Makefile.am b/rascontrol/Makefile.am new file mode 100644 index 0000000..16d4ee0 --- /dev/null +++ b/rascontrol/Makefile.am @@ -0,0 +1,53 @@ +# +# This file is part of rasdaman community. +# +# Rasdaman community 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 3 of the License, or +# (at your option) any later version. +# +# Rasdaman community 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 rasdaman community. If not, see . +# +# Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann / +# rasdaman GmbH. +# +# For more information please see +# or contact Peter Baumann via . +# * +# * MODULE: rascontrol +# * CLASS: +# * +# * COMMENTS: +# * +######################## Defines ############################### + +CRYPTO=../rasmgr/ras_crypto.o + +SRCCXX=rascontrol.cc rasmgr_utils_comm.cc rasmgrtest.cc raspasswd.cc \ + rascontrol_class.cc rasmgr_tester.cc rasmgr_utils_conf.cc rasmgrtester_conf.cc + +bin_PROGRAMS=rascontrol raspasswd + +rascontrol_SOURCES=rascontrol.cc rascontrol_class.cc rascontrol.hh \ + ../rasmgr/ras_crypto.cc ../rasmgr/ras_crypto.hh \ + rasmgr_utils_conf.cc rasmgr_utils_conf.hh \ + rasmgr_utils_comm.cc rasmgr_utils_comm.hh +rascontrol_LDADD = ../network/libnetwork.a ../commline/libcommline.a + +raspasswd_SOURCES=raspasswd.cc raspasswd.hh \ + ../rasmgr/ras_crypto.cc ../rasmgr/ras_crypto.hh \ + rasmgr_utils_comm.cc rasmgr_utils_comm.hh \ + rasmgr_utils_conf.cc rasmgr_utils_conf.hh +raspasswd_LDADD = ../network/libnetwork.a ../commline/libcommline.a + +SUBDIRS=../network ../commline + +$(RECURSIVE_CLEAN_TARGETS): + @$(MAKE) $(AM_MAKEFLAGS) `echo $@ | sed s/-recursive/-am/` + diff --git a/rascontrol/rascontrol.cc b/rascontrol/rascontrol.cc new file mode 100644 index 0000000..0b186f9 --- /dev/null +++ b/rascontrol/rascontrol.cc @@ -0,0 +1,341 @@ +/* +* This file is part of rasdaman community. +* +* Rasdaman community 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 3 of the License, or +* (at your option) any later version. +* +* Rasdaman community 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 rasdaman community. If not, see . +* +* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann / +rasdaman GmbH. +* +* For more information please see +* or contact Peter Baumann via . +*/ +/** + * SOURCE: rascontrol.cc + * + * MODULE: rascontrol + * CLASS: + * + * PURPOSE: + * RasControl is the remote control utility for the rasmgr + * + * COMMENTS: + * - should normalize cmd interpretation with rasmgr: strcmp vs strncmp +*/ + +#define DEBUG_MAIN // to allocate static vars for trace macros +#include "debug-clt.hh" + +#include "rascontrol.hh" +#include +#include + +#ifndef RMANVERSION +#error "Please specify RMANVERSION variable!" +#endif + +#ifndef COMPDATE +#error "Please specify the COMPDATE variable!" +/* +COMPDATE=`date +"%d.%m.%Y %H:%M:%S"` + +and -DCOMPDATE="\"$(COMPDATE)\"" when compiling +*/ +#endif + +UserLogin userLogin; +EditLine editLine; +RasMgrClientComm httpClient; +RascontrolConfig config; + +bool redirStdin = false; +bool redirStdout = false; + +const int NOERROR = 0; +const int CANTCONNECT = 1; +const int LOGINERROR = 2; +const int ACCESSDENIED = 3; + +// flag to indicate whether conf or auth file have been modified. +// if true files must be saved before terminating. +static bool confFileDirty = false; +static bool authFileDirty = false; + +int interactiveWork(); +int loginOnly(); +int batchMode(); +int testLogin(); + +int main(int argc, char **argv) +{ + if(config.interpretArguments(argc,argv)==false) return 1; + + // /*for debug only: */ config.printDebugInfo(); return 0; + if(config.beQuiet()==false) + { + std::cout << "rascontrol: rasdaman server remote control utility. rasdaman v" << RMANVERSION / 1000. << " -- generated on " << COMPDATE << "." << std::endl; + std::cout << " Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann rasdaman GmbH." << std::endl + << "Rasdaman community 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 3 of the License, or " + "(at your option) any later version. \n" + "Rasdaman community 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. \n\n"; + std::cout << "This software contains software which is in the public domain:" << std::endl; + std::cout << "- openssl 0.96c (C) 1998-2002 The OpenSSL Project, (C) 1995-1998 Eric A. Young, Tim J. Hudson" << std::endl; + } + if(config.showHelp()) + { + config.printHelp(); + return 0; + } + + if(testIsMessageDigestAvailable("MD5")==false) + { + std::cout<<"Error: Message Digest MD5 not available."<0) + std::cout<<" "<. +* +* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann / +rasdaman GmbH. +* +* For more information please see +* or contact Peter Baumann via . +/ +/** + * SOURCE: rascontrol.hh + * + * MODULE: rascontrol + * CLASS: + * + * PURPOSE: + * RasControl is the remote control utility for the rasmgr + * + * COMMENTS: + * +*/ + +#ifndef RASCONTROL_H +#define RASCONTROL_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "commline/cmlparser.hh" + +#include "../rasmgr/ras_crypto.hh" +#include "rasmgr_utils_comm.hh" +#include "rasmgr_utils_conf.hh" + +const int WKMUNKNOWN = 0; +const int WKMINTERACTIV = 1; +const int WKMBATCH = 2; +const int WKMLOGIN = 3; +const int WKMTESTLOGIN = 4; +const int WKMCREATE = 5; +const int WKMTSLANG = 6; + +const int LGIUNKNOWN = 0; +const int LGIINTERACTIV = 1; +const int LGIENVIRONM = 2; + +const int PROMPTSING = 0; +const int PROMPTRASC = 1; +const int PROMPTFULL = 2; + + +// ---------------- +// global constants +// ---------------- + +#define EOS_CHAR '\0' + +// rasmgr command words +#define RASMGRCMD_EXIT "exit" +#define RASMGRCMD_HELLO "Hello" +#define RASMGRCMD_LIST_MODUS "list modus" + + +// interim debug solution, should be replaced by std rasdaman mechanism -- now with ../rasmgr/debug.hh +// #define TALK(a) cout << a << endl; +//#define TALK(a) { /* TALK(a) */ } + +void printCommandLineHelp(); +int getCommand(); + +int sendCommandandPrintAnswer(const char*); +bool exitbyerror(char*); +int createSocket(); + +class EditLine + { + public: + EditLine(); + ~EditLine(); + + const char *interactiveCommand(const char *prompt); + const char *fromStdinCommand(const char *prompt); + + private: + char *rl_gets(const char *prompt); + char line[MAXMSG]; + + }; + +class RascontrolConfig:public ConfigurationBase + { + public: + RascontrolConfig(); + + // false means program shouldn't continue + bool interpretArguments(int argc, char **argv); + + int getWorkModus(); + int getLoginModus(); + const char* getRasMgrHost(); + int getRasMgrPort(); + bool histRequest(); + const char* getHistFileName(); + const char* getPrompt(); + const char* getCommand(); + bool beQuiet(); + bool showHelp(); + + void printDebugInfo(); + + void printHelp(); + private: + + bool paramError(); + + int workModus; + int loginModus; + + char rasmgrHost[100]; + int rasmgrPort; + bool reqHist; + char histFileName[100]; + + int promptType; + char prompt[100]; + char command[100]; + bool quiet; + + bool isCommand( const char *command, const char *key ); + + //-- parameters of this program + CommandLineParser &cmlInter; + CommandLineParameter &cmlHelp, &cmlHost, &cmlPort, &cmlLogin; +#ifdef NO_OFFICIAL_RELEASE + CommandLineParameter &cmlHist; +#endif + CommandLineParameter &cmlPrompt, &cmlTestLogin; + CommandLineParameter &cmlInteractive, &cmlQuiet, &cmlExecute; + + }; + +#endif diff --git a/rascontrol/rascontrol_class.cc b/rascontrol/rascontrol_class.cc new file mode 100644 index 0000000..dd3be0d --- /dev/null +++ b/rascontrol/rascontrol_class.cc @@ -0,0 +1,398 @@ +/* +* This file is part of rasdaman community. +* +* Rasdaman community 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 3 of the License, or +* (at your option) any later version. +* +* Rasdaman community 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 rasdaman community. If not, see . +* +* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann / +rasdaman GmbH. +* +* For more information please see +* or contact Peter Baumann via . +/ +/** + * SOURCE: rascontrol_class.hh + * + * MODULE: rascontrol + * CLASS: EditLine, RascontrolConfig + * + * PURPOSE: + * RasControl helper classes + * + * COMMENTS: + * +*/ + +#include "debug-clt.hh" + +#include "globals.hh" + +#include "rascontrol.hh" + +#include +#include + +#define READLINELIB + +/* +// if we have readline library on this machine ... +#ifdef READLINELIB + +extern "C" +{ +char * rl_gets (char *prompt); +char * readline(char *prompt); +void add_history (char * line_read); +int rl_insert(); +int rl_bind_key (int KEY, int (*FUNCTION)()); +void using_history (); +} + +#endif +*/ + +extern UserLogin userLogin; + +//int readWholeMessage(int socket,char *destBuffer,int buffSize); +//int writeWholeMessage(int socket,char *destBuffer,int buffSize); + +EditLine::EditLine() + { + line[0]= EOS_CHAR; + +#ifdef READLINELIB + using_history (); + rl_bind_key ('\t', rl_insert); +#endif + } +EditLine::~EditLine() + { + } + +const char *EditLine::interactiveCommand(const char *prompt) + { +#ifdef READLINELIB + char *rasp=rl_gets (prompt); + +#else + std::cout< name of host where master rasmgr runs", DEFAULT_HOSTNAME)), + cmlPort (cmlInter.addLongParameter(CommandLineParser::noShortName,"port", " rasmgr port",DEFAULT_PORT)), + cmlLogin (cmlInter.addFlagParameter('l',"login", "just login prompt, used to set the environment variable RASLOGIN")), + cmlTestLogin (cmlInter.addFlagParameter('t',"testlogin", "test if environment variable RASLOGIN is OK to login")), + cmlInteractive (cmlInter.addFlagParameter('e',"interactive", "interactive mode, login from environment variable RASLOGIN")), + cmlQuiet (cmlInter.addFlagParameter('q',"quiet", "quiet, don't print header (default on for -login and -testlogin)")), +#ifdef NO_OFFICIAL_RELEASE + cmlHist (cmlInter.addStringParameter(CommandLineParser::noShortName, "hist", " used to store your commands in file, as help for batch file.")), +#endif + cmlPrompt (cmlInter.addStringParameter(CommandLineParser::noShortName, "prompt", " change rascontrol prompt as following:\n\t\t 0 - prompt '>'\n\t\t 1 - prompt 'rasc>'\n\t\t 2 - prompt 'user:host>'","2")), + cmlExecute (cmlInter.addFlagParameter('x',"execute", "batch mode, login from environment variable RASLOGIN\n \ta rasmgr command (only in batch mode)\n\t\tif no command if provided, command is read from stdin\n\t\t(used for batch mode with 'PROMPTFULL) promptType=PROMPTFULL; + + return true; + } + +bool RascontrolConfig::paramError() + { + std::cout<<"Invalid parameter combination in command line!"<][" + << CommandLineParser::LongSign << cmlPort.getLongName() << " ][" +#ifdef NO_OFFICIAL_RELEASE + << CommandLineParser::LongSign << cmlHist.getLongName() << " ][" +#endif + << CommandLineParser::LongSign << cmlPrompt.getLongName() << " ][" + << CommandLineParser::LongSign << cmlQuiet.getLongName() << "]\n\t\t\t[" + << CommandLineParser::LongSign << cmlLogin.getLongName() << "|" + << CommandLineParser::LongSign << cmlTestLogin.getLongName() << "|" + << CommandLineParser::LongSign << cmlInteractive.getLongName() << "|" + << CommandLineParser::LongSign << cmlExecute.getLongName() << " ]" + << std::endl; + std::cout << "Option description:" << std::endl; + cmlInter.printHelp(); + std::cout< "); + break; + case PROMPTRASC : strcpy(prompt,"rasc> "); + break; + case PROMPTFULL : sprintf(prompt,"%s:%s> ",userLogin.getUserName(),rasmgrHost); + break; + } + return prompt; + } +const char* RascontrolConfig::getCommand() + { return command; + } + +void RascontrolConfig::printDebugInfo() + { + std::cout<<"Working modus:."; + switch(workModus) + { + case WKMUNKNOWN : std::cout<<"unknown";break; + case WKMINTERACTIV : std::cout<<"interactiv";break; + case WKMBATCH : std::cout<<"batch";break; + case WKMLOGIN : std::cout<<"login";break; + } + + std::cout<. +* +* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann / +rasdaman GmbH. +* +* For more information please see +* or contact Peter Baumann via . +/ +/** + * SOURCE: rasmgr_tester.cc + * + * MODULE: rascontrol + * CLASS: RasMgrTester + * + * PURPOSE: + * + * COMMENTS: + * +*/ + +#include "debug-clt.hh" +#include "rascontrol.hh" +#include "rasmgr_tester.hh" + + +RasMgrTester::RasMgrTester() + { + + command = new char[MAXCOMMAND]; + expected= new char[MAXMSGRASCONTROL]; + + } +RasMgrTester::~RasMgrTester() + { + delete[] command; + delete[] expected; + } + +void RasMgrTester::setRasMgrHost(const char *rasmgrHost, int rasmgrPort) + { + rasmgrClient.setRasMgrHost(rasmgrHost, rasmgrPort); // The first argument is the RasMgr host + userLogin.quickLogin(); + rasmgrClient.setUserIdentification(userLogin.getUserName(),userLogin.getEncrPass()); + } + +bool RasMgrTester::mayWeDoTest() + { + int result = 0; // COMM_* values + const char *modus = NULL; + + result = rasmgrClient.sendMessageGetAnswer( RASMGRCMD_LIST_MODUS, &modus ); + const char *expect = "RasMGR running as master in test modus"; + if(modus == NULL) return false; //if connection refused, no rasmgr running + //cout<<"A:"<. +* +* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann / +rasdaman GmbH. +* +* For more information please see +* or contact Peter Baumann via . +/ +/** + * SOURCE: rasmgr_tester.hh + * + * MODULE: rascontrol + * CLASS: RasMgrTester + * + * COMMENTS: + * + * +*/ + +#ifndef RASMGR_TESTER_HH +#define RASMGR_TESTER_HH + +#include "rasmgr_utils_comm.hh" +#include + +class RasMgrTester + { + public: + RasMgrTester(); + ~RasMgrTester(); + void setRasMgrHost(const char *rasmgrHost, int port); + bool mayWeDoTest(); + + // load command from string + bool loadCommand(const char*); + + // load command from file, one line only + bool loadCommand(std::ifstream&); + + // load expected from string + bool loadExpected(const char*); + + // load expected from file, until delim, without it + // if delim==0, until EOF + bool loadExpected(std::ifstream&,char delim); + + bool sendCommandGetAnswer(); + + bool isAnswerOK(); + + const char* getCommand(); + const char* getExpected(); + const char* getAnswer(); + + bool saveCommand(std::ofstream&); + bool saveExpected(std::ofstream&); + bool saveAnswer(std::ofstream&); + + private: + // STL ifstream::getline() drops the '\n', but let's a '\r' live + // so this function clears this stupid '\r' + void clearCR(char *line); + void clearFinalCRLF(char *string); + UserLogin userLogin; + RasMgrClientComm rasmgrClient; + + char *command; + char *expected; + + }; +#endif diff --git a/rascontrol/rasmgr_utils_comm.cc b/rascontrol/rasmgr_utils_comm.cc new file mode 100644 index 0000000..01b504c --- /dev/null +++ b/rascontrol/rasmgr_utils_comm.cc @@ -0,0 +1,359 @@ +/* +* This file is part of rasdaman community. +* +* Rasdaman community 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 3 of the License, or +* (at your option) any later version. +* +* Rasdaman community 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 rasdaman community. If not, see . +* +* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann / +rasdaman GmbH. +* +* For more information please see +* or contact Peter Baumann via . +/ +/** + * SOURCE: rasmgr_utils_comm.cc + * + * MODULE: rascontrol + * CLASS: RasMgrClientComm, UserLogin + * + * PURPOSE: + * rasmgr-Client communication and login classes + * + * COMMENTS: + * + * +*/ + +// trace macros +#include "debug-clt.hh" + +#include "globals.hh" + +#include "rasmgr_utils_comm.hh" +#include "rascontrol.hh" + + +RasMgrClientComm::RasMgrClientComm() + { + rasmgrSocket=-1; + userName[0]= EOS_CHAR; + encrPass[0]= EOS_CHAR; + rasmgrHost[0]= EOS_CHAR; + answerBody=answerMessage; + answerMessage[0]= EOS_CHAR; + } + +RasMgrClientComm::~RasMgrClientComm() + { + } +void RasMgrClientComm::setRasMgrHost(const char *rasmgrHost, int rasmgrPort) + { + strcpy(this->rasmgrHost,rasmgrHost); + this->rasmgrPort=rasmgrPort; + } + +const char* RasMgrClientComm::getRasMgrHost() + { return rasmgrHost; + } + +void RasMgrClientComm::setUserIdentification(const char *userName, const char *encrPass) + { + strcpy(this->userName,userName); + strcpy(this->encrPass,encrPass); + } + +int RasMgrClientComm::openSocket() + { + ENTER("RasMgrClientComm::openSocket: enter." ); + + // if open already, close beforehand + if(rasmgrSocket!=-1) + { + TALK ("RasMgrClientComm::openSocket: socket was open, closing it." ); + closeSocket(); + } + + struct protoent *getprotoptr = getprotoptr=getprotobyname("tcp"); // FIXME: what is this??? + struct hostent *hostinfo = gethostbyname(rasmgrHost); + + if(hostinfo==NULL) + { + TALK ("RasMgrClientComm::openSocket: leave. unknown host " << rasmgrHost ); + return -1; + } + + sockaddr_in internetAddress; + internetAddress.sin_family=AF_INET; + internetAddress.sin_port=htons(rasmgrPort); + internetAddress.sin_addr=*(struct in_addr*)hostinfo->h_addr; + + rasmgrSocket=socket(PF_INET,SOCK_STREAM,getprotoptr->p_proto); + + if(rasmgrSocket<0) + { + int tempErrno = errno; + TALK ("RasMgrClientComm::openSocket: leave. error opening socket: " << strerror(tempErrno ) ); + return -1; + } + + if(0>connect(rasmgrSocket,(struct sockaddr*)&internetAddress,sizeof(internetAddress))) + { + int tempErrno = errno; + TALK ("RasMgrClientComm::openSocket: leave. error connecting socket: " << strerror(tempErrno ) ); + return -1; + } + + LEAVE( "RasMgrClientComm::openSocket: leave. ok." ); + return 0; + } + +void RasMgrClientComm::closeSocket() + { + ENTER( "RasMgrClientComm::closeSocket. enter." ); + if(rasmgrSocket >0) + { + TALK( "RasMgrClientComm::closeSocket. closing, socket=" << rasmgrSocket ); + close(rasmgrSocket); + rasmgrSocket=-1; + } + LEAVE( "RasMgrClientComm::closeSocket. leave." ); + } + +int RasMgrClientComm::sendMessage(const char *message) + { + char request[MAXMSG]; + int result = COMM_CONT; // was: 0, but this is same value + + ENTER( "RasMgrClientComm::sendMessage: enter. message=" << message ); + + sprintf(request, "POST rascontrol HTTP/1.1\r\nAccept: text/plain\r\nUserAgent: rascontrol/2.0"); + sprintf(request+strlen(request),"\r\nAuthorization: ras %s:%s",userName,encrPass);//"rasadmin","d293a15562d3e70b6fdc5ee452eaed40"); + sprintf(request+strlen(request),"\r\nContent length: %d\r\n\r\n%s ",strlen(message)+1,message); + + int reqLen=strlen(request)+1; // including final '\0'!! + if(writeWholeMessage(rasmgrSocket,request,reqLen). +* +* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann / +rasdaman GmbH. +* +* For more information please see +* or contact Peter Baumann via . +/ +/** + * SOURCE: rasmgr_utils_comm.hh + * + * MODULE: rascontrol + * CLASS: RasMgrClientComm, UserLogin + * + * PURPOSE: + * rasmgr-Client communication and login classes + * + * COMMENTS: + * - RASMGRPORT should have central definition outside + * +*/ +#ifndef RASMGR_UTILS_COMM_HH +#define RASMGR_UTILS_COMM_HH + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "../rasmgr/ras_crypto.hh" + +// now defined vid -D as compile flag -- PB 2003-sep-03 +// const int RMANVERSION = 5100; + +const int RASMGRPORT = 7001; +extern const char* RASMGRPORTS; +extern const char* RASMGRHOST; + + +const int MAXMSG = 2048; +const int MAXCOMMAND = 100; +const int MAXMSGRASCONTROL = 20000; + +const int MAXUSERNAME = 100; +const int MAXENCRPASS = 35; +const int MAXHOSTNAME = 100; + +const int COMM_CONT = 0; +const int COMM_SEND = 1; +const int COMM_EXIT = 2; +const int COMM_ERR = 3; +const int COMM_ACDN = 4; + +class RasMgrClientComm + { + public: + RasMgrClientComm(); + ~RasMgrClientComm(); + + void setRasMgrHost(const char *rasmgrHost, int rasmgrPort); + const char* getRasMgrHost(); + void setUserIdentification(const char *userName, const char *encrPass); + + int openSocket(); + void closeSocket(); + + int sendMessage(const char *message); + int sendMessageGetAnswer(const char *message, const char **responsePtr); + const char* readMessage(); + const char* getHeader(); + const char* getBody(); + + private: + int writeWholeMessage(int socket,char *destBuffer,int buffSize); + int readWholeMessage(int socket,char *destBuffer,int buffSize); + const char *stripBlanks(const char*); + + char answerMessage[MAXMSGRASCONTROL]; + char *answerBody; + + char userName[MAXUSERNAME]; + char encrPass[MAXENCRPASS]; + + int rasmgrSocket; + char rasmgrHost[MAXHOSTNAME]; + int rasmgrPort; + }; + +//##################################################################### +class UserLogin + { + public: + UserLogin(); + ~UserLogin(); + int interactiveLogin(); + int environmentLogin(); + int quickLogin(); + const char *getUserName(); + const char *getEncrPass(); + private: + + char userName[MAXUSERNAME]; + char encrPass[MAXENCRPASS]; + }; + +#endif diff --git a/rascontrol/rasmgr_utils_conf.cc b/rascontrol/rasmgr_utils_conf.cc new file mode 100644 index 0000000..8cb3775 --- /dev/null +++ b/rascontrol/rasmgr_utils_conf.cc @@ -0,0 +1,71 @@ +/* +* This file is part of rasdaman community. +* +* Rasdaman community 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 3 of the License, or +* (at your option) any later version. +* +* Rasdaman community 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 rasdaman community. If not, see . +* +* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann / +rasdaman GmbH. +* +* For more information please see +* or contact Peter Baumann via . +/ +/** + * SOURCE: rasmgr_utils_conf.hh + * + * MODULE: rascontrol + * CLASS: ConfigurationBase + * + * PURPOSE: + * Base class for other configuration classes, to interpret commandline arguments and environment settings + * + * COMMENTS: + * +*/ + +#include "debug-clt.hh" + +#include "rasmgr_utils_conf.hh" + +ConfigurationBase::ConfigurationBase() + { + } + +bool ConfigurationBase::interpretArguments(int argc, char **argv) + { + return false; + } + + +int ConfigurationBase::checkArguments( int argc, char** argv, const char* searchText, int& optionValueIndex ) +{ + int found = 0; + int i=1; + + while( !found && i. +* +* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann / +rasdaman GmbH. +* +* For more information please see +* or contact Peter Baumann via . +/ +/** + * SOURCE: rasmgr_utils_conf.hh + * + * MODULE: rascontrol + * CLASS: ConfigurationBase + * + * PURPOSE: + * Base class for other configuration classes, to interpret commandline arguments and environment settings + * + * COMMENTS: + * + * +*/ +#ifndef RASMGR_UTILS_CONF_HH +#define RASMGR_UTILS_CONF_HH + +// This is the base class for every programs configuration class +#include +#include +#include +#include + +class ConfigurationBase + { + public: + ConfigurationBase(); + + // false means program shouldn't continue + virtual bool interpretArguments(int argc, char **argv); + + protected: + + int checkArguments( int argc, char** argv, const char* searchText, int& optionValueIndex ); + + virtual void printHelp(); + + }; + +#endif diff --git a/rascontrol/raspasswd.cc b/rascontrol/raspasswd.cc new file mode 100644 index 0000000..be7c91a --- /dev/null +++ b/rascontrol/raspasswd.cc @@ -0,0 +1,241 @@ +/* +* This file is part of rasdaman community. +* +* Rasdaman community 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 3 of the License, or +* (at your option) any later version. +* +* Rasdaman community 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 rasdaman community. If not, see . +* +* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann / +rasdaman GmbH. +* +* For more information please see +* or contact Peter Baumann via . +/ +/** + * SOURCE: raspasswd.cc + * + * MODULE: rascontrol + * CLASS: + * + * PURPOSE: + * RasDaMan password utility + * + * COMMENTS: + * + * +*/ + +// for trace macros +#define DEBUG_MAIN +#include "debug-clt.hh" + +#include "globals.hh" + +#include "rascontrol.hh" +#include "raspasswd.hh" +#include "rasmgr_utils_comm.hh" + +#ifndef RMANVERSION +#error "Please specify the RMANVERSION variable!" +#endif + +#ifndef COMPDATE +#error "Please specify the COMPDATE variable!" +/* +COMPDATE=`date +"%d.%m.%Y %H:%M:%S"` + +and -DCOMPDATE="\"$(COMPDATE)\"" when compiling +*/ +#endif + +RasPasswdConfig config; +UserLogin userLogin; +RasMgrClientComm rasmgrComm; + +char message[100]; +char encrNewPass1[35]; +char encrNewPass2[35]; + + +int main(int argc, char **argv) +{ + cout << "raspasswd: rasdaman password utility. rasdaman v" << RMANVERSION / 1000. << " -- generated on " << COMPDATE << "." < name of host where master rasmgr runs", DEFAULT_HOSTNAME)), + cmlPort (cmlInter.addLongParameter(CommandLineParser::noShortName,"port", " the rasmgr port", DEFAULT_PORT )), + cmlHelp (cmlInter.addFlagParameter('h',"help","this help")) + { +// done by default value of commandlineparser +// strcpy(rasmgrHost,RASMGRHOST.c_str()); +// rasmgrPort = RASMGRPORT; + } + +bool RasPasswdConfig::interpretArguments(int argc, char **argv) + { + try { + cmlInter.processCommandLine(argc, argv); + } + catch(CmlException& err) { + cerr << "Command Line Parsing Error:" << endl << err.what() << endl; + return false; + } + + if( cmlHelp.isPresent() ) { + printHelp(); + return false; + } + + try { + rasmgrPort = cmlPort.getValueAsLong(); + } + catch(CmlException& err) { + cerr << "Command Line Parsing Error:" << endl << err.what() << endl; + return false; + } + + strcpy(rasmgrHost, cmlHost.getValueAsString()); + + return true; + } + +void RasPasswdConfig::printHelp() + { + cout << "Usage: raspasswd [options]"<. +* +* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann / +rasdaman GmbH. +* +* For more information please see +* or contact Peter Baumann via . +/ +/** + * SOURCE: raspasswd.hh + * + * MODULE: rascontrol + * CLASS: + * + * PURPOSE: + * RasDaMan password utility + * + * COMMENTS: + * +*/ + +#ifndef RASPASSWD_HH +#define RASPASSWD_HH + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "commline/cmlparser.hh" + +#include "../rasmgr/ras_crypto.hh" +#include "rasmgr_utils_conf.hh" + +using namespace std; + +void printCommandLineHelp(); + +bool exitbyerror(char*); + +const char* getPasswdKeyboard(const char*text,char*dest); +bool execute(const char *message); + +class RasPasswdConfig:public ConfigurationBase + { + public: + RasPasswdConfig(); + + // false means program shouldn't continue + bool interpretArguments(int argc, char **argv); + + const char* getRasMgrHost(); + int getRasMgrPort(); + // void printDebugInfo(); + private: + + void printHelp(); + //bool paramError(); + + char rasmgrHost[100]; + int rasmgrPort; + + //-- parameters of this program + CommandLineParser &cmlInter; + CommandLineParameter &cmlHost, &cmlPort, &cmlHelp; + }; + +#endif diff --git a/rascontrol/test/rasmgrtest.cc b/rascontrol/test/rasmgrtest.cc new file mode 100644 index 0000000..3a969f6 --- /dev/null +++ b/rascontrol/test/rasmgrtest.cc @@ -0,0 +1,178 @@ +/* +* This file is part of rasdaman community. +* +* Rasdaman community 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 3 of the License, or +* (at your option) any later version. +* +* Rasdaman community 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 rasdaman community. If not, see . +* +* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann / +rasdaman GmbH. +* +* For more information please see +* or contact Peter Baumann via . +/ +/** + * SOURCE: rasmgrtest.cc + * + * MODULE: rascontrol + * CLASS: + * + * PURPOSE: + * Utility to test the rasmgr command language. + * + * COMMENTS: + * + * + */ + +#include +#include + +#define DEBUG_MAIN +#include "debug-clt.hh" + +#include "rascontrol.hh" +#include "rasmgr_tester.hh" +#include "rasmgrtester_conf.hh" + +TesterConf config; + +RasMgrTester rasmgrTester; + +#define TESTERCOMMENT '§' + +void testCommandLanguage(); +void createTestFile(); + +int main(int argc, char **argv) +{ + + if(config.interpretArguments(argc,argv) == false) return 0; + + if(config.getWorkModus() == WKMUNKNOWN ) + { cout << "And what should I do?"< ... command list file, from which the test file should be created"< ... test file"< ... log file (default rasmgrtest.log)"<. +* +* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann / +rasdaman GmbH. +* +* For more information please see +* or contact Peter Baumann via . +/ +/** + * SOURCE: rasmgrtester_conf.hh + * + * MODULE: rascontrol + * CLASS: TesterConf + * + * PURPOSE: + * Configuration from commandline and environment for rasmgrtest + * + * COMMENTS: + * + * +*/ + +#ifndef RASMGRTESTER_CONF_HH +#define RASMGRTESTER_CONF_HH + +#include "rasmgr_utils_conf.hh" +#include "rasmgr_utils_comm.hh" + +#define MAXFILENAME 200 + +// This is the base class for every programs configuration class +class TesterConf:public ConfigurationBase + { + public: + TesterConf(); + + bool interpretArguments(int argc, char **argv); + + const char* getRasMgrHost(); + int getRasMgrPort(); + + int getWorkModus(); + const char* getCommandListFile(); + const char* getTestFile(); + const char* getLogFile(); + bool beQuiet(); + private: + + void printHelp(); + + char rasmgrHost[MAXHOSTNAME]; + int rasmgrPort; + + char commandListFile[MAXFILENAME]; + char testFile[MAXFILENAME]; + char logFile[MAXFILENAME]; + + int workModus; + bool quiet; + + }; + +extern TesterConf config; + +#endif -- cgit