summaryrefslogtreecommitdiffstats
path: root/rascontrol
diff options
context:
space:
mode:
authorConstantin Jucovschi <cj@ubuntu.localdomain>2009-04-24 07:20:22 -0400
committerConstantin Jucovschi <cj@ubuntu.localdomain>2009-04-24 07:20:22 -0400
commit8f27e65bddd7d4b8515ce620fb485fdd78fcdf89 (patch)
treebd328a4dd4f92d32202241b5e3a7f36177792c5f /rascontrol
downloadrasdaman-upstream-8f27e65bddd7d4b8515ce620fb485fdd78fcdf89.tar.gz
rasdaman-upstream-8f27e65bddd7d4b8515ce620fb485fdd78fcdf89.tar.xz
rasdaman-upstream-8f27e65bddd7d4b8515ce620fb485fdd78fcdf89.zip
Initial commitv8.0
Diffstat (limited to 'rascontrol')
-rw-r--r--rascontrol/Makefile.am53
-rw-r--r--rascontrol/rascontrol.cc341
-rw-r--r--rascontrol/rascontrol.hh164
-rw-r--r--rascontrol/rascontrol_class.cc398
-rw-r--r--rascontrol/rasmgr_tester.cc171
-rw-r--r--rascontrol/rasmgr_tester.hh85
-rw-r--r--rascontrol/rasmgr_utils_comm.cc359
-rw-r--r--rascontrol/rasmgr_utils_comm.hh127
-rw-r--r--rascontrol/rasmgr_utils_conf.cc71
-rw-r--r--rascontrol/rasmgr_utils_conf.hh61
-rw-r--r--rascontrol/raspasswd.cc241
-rw-r--r--rascontrol/raspasswd.hh89
-rw-r--r--rascontrol/test/rasmgrtest.cc178
-rw-r--r--rascontrol/test/rasmgrtester_conf.cc133
-rw-r--r--rascontrol/test/rasmgrtester_conf.hh79
15 files changed, 2550 insertions, 0 deletions
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 <http://www.gnu.org/licenses/>.
+#
+# Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
+# rasdaman GmbH.
+#
+# For more information please see <http://www.rasdaman.org>
+# or contact Peter Baumann via <baumann@rasdaman.com>.
+# *
+# * 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 <http://www.gnu.org/licenses/>.
+*
+* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
+rasdaman GmbH.
+*
+* For more information please see <http://www.rasdaman.org>
+* or contact Peter Baumann via <baumann@rasdaman.com>.
+*/
+/**
+ * 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 <fstream>
+#include <signal.h>
+
+#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."<<std::endl;
+ return 2;
+ }
+
+ if(!isatty(0) )
+ redirStdin =true;
+ if(!isatty(1))
+ redirStdout=true;
+
+ httpClient.setRasMgrHost(config.getRasMgrHost(), config.getRasMgrPort());
+
+ int loginOK = (config.getLoginModus()==LGIINTERACTIV) ? userLogin.interactiveLogin() : userLogin.environmentLogin();
+
+ if(loginOK<0)
+ {
+ std::cout<<"Login error."<<std::endl;
+ return LOGINERROR;
+ }
+
+ httpClient.setUserIdentification(userLogin.getUserName(),userLogin.getEncrPass());
+
+ int answer=NOERROR;
+ switch(config.getWorkModus())
+ {
+ case WKMINTERACTIV: answer=interactiveWork(); break;
+ case WKMLOGIN : answer=loginOnly(); break;
+ case WKMBATCH : answer=batchMode(); break;
+ case WKMTESTLOGIN : answer=testLogin(); break;
+ }
+
+ if(config.beQuiet()==false)
+ std::cout<< "rascontrol terminated." <<std::endl;
+
+ return answer;
+ } // main()
+
+// check whether command fits with given keyword (case insensitive), maybe after stripping leading whitespace
+bool isCommand( const char *command, const char *key)
+ {
+ bool result;
+
+ if (command == NULL || key == NULL)
+ result = false;
+ else
+ {
+ while (*command == ' ' || *command == '\t') // skip white space; newline cannot occur
+ command++;
+ result = strcasecmp( command, key );
+ }
+
+ return result;
+ }
+
+int interactiveWork()
+ {
+ int result = 0;
+ const char *answer = NULL;
+ int comm = COMM_CONT; // COMM_* values ; should be enum
+
+ std::ofstream history;
+ bool historyFile=config.histRequest();
+
+ comm = httpClient.sendMessageGetAnswer( RASMGRCMD_HELLO, &answer );
+
+ if(answer)
+ std::cout<<" "<<answer<<std::endl;
+
+ if(comm==COMM_ERR)
+ { std::cout<<"Cannot connect to main host "<<httpClient.getRasMgrHost()<<std::endl;
+ return CANTCONNECT;
+ }
+ if(comm==COMM_ACDN)
+ { //std::cout<<"Access denied."<<std::endl;
+ return ACCESSDENIED;
+ }
+
+ // shifted here, after return, so that it always will be closed
+ if(historyFile)
+ {
+ TALK( "RasControl::interactiveWork: using history file " << config.getHistFileName() );
+ history.open(config.getHistFileName(),std::ios::out|std::ios::trunc);
+ }
+
+ do{
+ TALK( "RasControl::interactiveWork: entering new request cycle." );
+
+ const char *command=editLine.interactiveCommand(config.getPrompt());
+ if(command == NULL || strlen(command)==0) // empty cmd line
+ continue;
+
+ if(historyFile)
+ history<<command<<std::endl;
+
+ TALK( "RasControl::interactiveWork: cmd=" << command );
+
+ // send message to rasmgr & receive answer
+ const char *answer = NULL;
+ if ( (isCommand(command,"exit") == 0)
+ || (isCommand(command,"quit") == 0)
+ || (isCommand(command,"bye" ) == 0) )
+ {
+ // normalize "quit", "bye" to "exit"; do so after history to maintain original cmd there
+ comm = httpClient.sendMessageGetAnswer( RASMGRCMD_EXIT, &answer );
+ comm = COMM_EXIT; // ignore any result, we have to terminate anyway
+ }
+ else
+ {
+ comm = httpClient.sendMessageGetAnswer( command, &answer );
+ }
+
+ if(answer!=0 && strlen(answer)>0)
+ std::cout<<" "<<answer<<std::endl;
+ else
+ answer = "Internal error: cannot decode rasmgr result.";
+
+ // EXPERIMENTAL: close socket as early and as always as possible
+ //TALK( "RasControl::interactiveWork: closing socket." );
+ //httpClient.closeSocket();
+
+ TALK( "RasControl::interactiveWork: comm=" << comm );
+
+ }while( comm != COMM_EXIT && comm != COMM_ACDN); // COMM_ERR is no reason to terminate interactive session
+
+ if(historyFile)
+ history.close();
+
+ switch(comm)
+ {
+ case COMM_ERR: result = CANTCONNECT; break;
+ case COMM_ACDN: result = ACCESSDENIED; break;
+ default: result = NOERROR; break;
+ }
+ return result;
+ }
+
+int loginOnly()
+ {
+ std::cout<<userLogin.getUserName()<<':'<<userLogin.getEncrPass()<<std::endl;
+ // Thats all
+ return NOERROR;
+ }
+int batchMode()
+ {
+ int result = 0; // COMM_* values
+
+ bool fromCommandLine = strlen(config.getCommand()) ? true: false;
+ const char *prompt = !redirStdin ? config.getPrompt():"";
+
+ //std::cout<<"batch mode "<<fromCommandLine<<" comm="<<config.getCommand()<<std::endl;
+
+ int comm=0;
+ do{
+ const char *command= fromCommandLine ? config.getCommand():editLine.fromStdinCommand(prompt);
+
+ TALK( "batch: Command=" << command );
+
+ if(command == NULL ) return CANTCONNECT;
+
+ if(strlen(command)==0 )
+ if( fromCommandLine)
+ return CANTCONNECT;
+ else
+ continue;
+
+ bool printCommand=false;
+
+ if( redirStdout ) printCommand = true;
+ else
+ { if(redirStdin) printCommand = true;
+ }
+
+ if(printCommand == true)
+ std::cout<<config.getPrompt()<<command<<std::endl;
+
+ // normalize "quit", "bye" to "exit"
+ const char *answer = NULL;
+ if ( (isCommand(command,"exit") == 0)
+ || (isCommand(command,"quit") == 0)
+ || (isCommand(command,"bye" ) == 0) )
+ {
+ // normalize "quit", "bye" to "exit"; do so after history to maintain original cmd there
+ comm = httpClient.sendMessageGetAnswer( RASMGRCMD_EXIT, &answer );
+ comm = COMM_EXIT; // ignore any result, we have to terminate anyway
+ }
+ else
+ {
+ comm = httpClient.sendMessageGetAnswer( command, &answer );
+ }
+
+ if(answer==0 || strlen(answer)==0)
+ answer = "Error: cannot decode rasmgr result.";
+ else
+ {
+ if(comm==COMM_ERR)
+ std::cout<<" "<<"Cannot connect to main host."<<std::endl;
+ else if(comm==COMM_ACDN)
+ std::cout<<" "<<"Access denied by rasmgr."<<std::endl;
+ else
+ std::cout<<" "<<answer<<std::endl;
+ }
+
+ }while(fromCommandLine==false && redirStdin
+ && comm != COMM_ERR
+ && comm != COMM_ACDN
+ && comm != COMM_EXIT); //process the whole "< file"
+
+ switch(comm)
+ {
+ case COMM_ERR: result = CANTCONNECT; break;
+ case COMM_ACDN: result = ACCESSDENIED; break;
+ default: result = NOERROR; break;
+ }
+ return result;
+ }
+
+int testLogin()
+ {
+ int comm = 0; // COMM_* values
+ const char *answer = NULL;
+
+ comm = httpClient.sendMessageGetAnswer( RASMGRCMD_HELLO, &answer );
+
+ if(comm==COMM_ERR)
+ { //std::cout<<"Cannot connect to main host "<<httpClient.getRasMgrHost()<<std::endl;
+ return CANTCONNECT;
+ }
+ if(comm==COMM_ACDN)
+ { //std::cout<<"Acces denied."<<std::endl;
+ return ACCESSDENIED;
+ }
+
+ std::cout<<"Login OK."<<std::endl;
+ return NOERROR;
+ }
+
diff --git a/rascontrol/rascontrol.hh b/rascontrol/rascontrol.hh
new file mode 100644
index 0000000..feb8ad7
--- /dev/null
+++ b/rascontrol/rascontrol.hh
@@ -0,0 +1,164 @@
+/*
+* 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 <http://www.gnu.org/licenses/>.
+*
+* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
+rasdaman GmbH.
+*
+* For more information please see <http://www.rasdaman.org>
+* or contact Peter Baumann via <baumann@rasdaman.com>.
+/
+/**
+ * SOURCE: rascontrol.hh
+ *
+ * MODULE: rascontrol
+ * CLASS:
+ *
+ * PURPOSE:
+ * RasControl is the remote control utility for the rasmgr
+ *
+ * COMMENTS:
+ *
+*/
+
+#ifndef RASCONTROL_H
+#define RASCONTROL_H
+
+#include <stdio.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netdb.h>
+#include <iostream>
+#include <string.h>
+#include <string>
+
+#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 <http://www.gnu.org/licenses/>.
+*
+* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
+rasdaman GmbH.
+*
+* For more information please see <http://www.rasdaman.org>
+* or contact Peter Baumann via <baumann@rasdaman.com>.
+/
+/**
+ * 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 <readline/readline.h>
+#include <readline/history.h>
+
+#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<<prompt<<std::flush;
+ char *rasp=fgets(line,MAXMSG-1,stdin);
+
+#endif
+
+ if(rasp==0) return 0;
+ strcpy(line, rasp);
+ return line;
+
+ }
+
+const char *EditLine::fromStdinCommand(const char* prompt)
+ {
+ if(prompt) std::cout<<prompt<<std::flush;
+ char *rasp=fgets(line,MAXMSG-1,stdin);
+
+ if(rasp==0) { return 0;}
+
+ int i;
+ for(i=0;line[i];i++)
+ {
+ if(line[i]=='\r' || line[i]=='\n') {line[i]=0; break;}
+ }
+
+ for(i=0;line[i];i++)
+ {
+ if(line[i]==' ' || line[i]=='\t') continue;
+ break;
+ }
+ return line +i;
+ }
+
+char * EditLine::rl_gets(const char *prompt)
+ {
+#ifdef READLINELIB
+ static char *line_read = (char *)NULL;
+
+ /* If the buffer has already been allocated, return the memory
+ to the free pool. */
+
+ if (line_read)
+ {
+ free (line_read);
+ line_read = (char *)NULL;
+ }
+
+ /* Get a line from the user. */
+ line_read = readline ((char*)prompt);
+
+ /* If the line has any text in it, save it on the history. */
+ if (line_read && *line_read)
+ add_history (line_read);
+
+ return (line_read);
+#else
+ return " ";
+#endif
+
+ }
+
+//################ Config ##################################
+RascontrolConfig::RascontrolConfig() :
+ cmlInter (CommandLineParser::getInstance()),
+ cmlHost (cmlInter.addStringParameter(CommandLineParser::noShortName,"host", "<name> name of host where master rasmgr runs", DEFAULT_HOSTNAME)),
+ cmlPort (cmlInter.addLongParameter(CommandLineParser::noShortName,"port", "<nnnn> 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", "<file-name> used to store your commands in file, as help for batch file.")),
+#endif
+ cmlPrompt (cmlInter.addStringParameter(CommandLineParser::noShortName, "prompt", "<nnn> 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 <rasmgr-cmd>\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 '<inputfile')")),
+ cmlHelp (cmlInter.addFlagParameter('h',"help", "this help"))
+ {
+ workModus = WKMINTERACTIV;
+ loginModus= LGIINTERACTIV;
+
+// done by default value of command line parameters
+// strcpy(rasmgrHost, cmlHost.getValueAsString());
+// rasmgrPort = cmlPort.getValueAsLong();
+
+ reqHist = false;
+ strcpy(histFileName,"rascontrol.hist");
+
+ promptType=PROMPTFULL;
+ prompt[0]= EOS_CHAR;
+ command[0]= EOS_CHAR;
+ quiet =false;
+ }
+
+bool RascontrolConfig::interpretArguments(int argc, char **argv)
+ {
+ //FIXME workarround for batch mode commands given to rascontrol
+ //in current version it is generated an error if a parameter has many values:
+ //e.g. -a c d f where c,d,f are values(not parameters)
+ int lastArg = argc;
+ string shortX = string("") + CommandLineParser::ShortSign + cmlExecute.getShortName();
+ string longX = string("") + CommandLineParser::LongSign + cmlExecute.getLongName();
+
+ for(lastArg = 1;lastArg<argc;lastArg++)
+ {
+ if( (strcmp(argv[lastArg], shortX.c_str())==0) ||
+ (strcmp(argv[lastArg], longX.c_str())==0) )
+ { lastArg++;
+ break;
+ }
+ }
+
+ //std::cout<<"argc="<<argc<<" lastarg="<<lastArg<<std::endl;
+
+ try
+ {
+ if(lastArg != argc)
+ cmlInter.processCommandLine(lastArg, argv);
+ else
+ cmlInter.processCommandLine(argc, argv);
+ }
+ catch(CmlException& err)
+ {
+ std::cout << "Command Line Parsing Error:" << std::endl << err.what() << std::endl;
+ return false;
+ }
+
+
+
+ if( cmlHelp.isPresent() ) {
+ //we stop processing
+ return true;
+ }
+
+ try
+ {
+ rasmgrPort = cmlPort.getValueAsLong();
+ }
+ catch(CmlException& err)
+ {
+ std::cout << "Command Line Parsing Error:" << std::endl << err.what() << std::endl;
+ return false;
+ }
+
+ strcpy(rasmgrHost, cmlHost.getValueAsString());
+
+ if( cmlLogin.isPresent() )
+ {
+ workModus = WKMLOGIN;
+ quiet = true;
+ }
+
+ if( cmlQuiet.isPresent() )
+ {
+ quiet = true;
+ }
+
+ if( cmlTestLogin.isPresent() )
+ {
+ if(workModus==WKMINTERACTIV) { workModus = WKMTESTLOGIN;
+ loginModus = LGIENVIRONM;
+ }
+ else return paramError();
+ quiet = true;
+ }
+
+ if( cmlInteractive.isPresent() )
+ {
+ if(workModus==WKMINTERACTIV) loginModus = LGIENVIRONM;
+ else return paramError();
+ }
+
+ if( cmlExecute.isPresent() )
+ {
+ if(workModus==WKMINTERACTIV)
+ { loginModus = LGIENVIRONM;
+ workModus = WKMBATCH;
+
+ for(int i=lastArg;i<argc;i++)
+ {
+ strcat(command,argv[i]);
+ strcat(command," ");
+ }
+ }
+ else return paramError();
+ }
+
+#ifdef NO_OFFICIAL_RELEASE
+ if( cmlHist.isPresent() )
+ {
+ reqHist = true;
+ strcpy(histFileName, cmlHist.getValueAsString());
+ }
+#endif
+
+ try
+ {
+ promptType = cmlPrompt.getValueAsLong();
+ }
+ catch(CmlException& err)
+ {
+ std::cout << "Command Line Parsing Error:" << std::endl << err.what() << std::endl;
+ return false;
+ }
+
+ if(promptType<PROMPTSING || promptType>PROMPTFULL) promptType=PROMPTFULL;
+
+ return true;
+ }
+
+bool RascontrolConfig::paramError()
+ {
+ std::cout<<"Invalid parameter combination in command line!"<<std::endl;
+ return false;
+ }
+
+void RascontrolConfig::printHelp()
+ {
+ std::cout <<"Usage: " << std::endl << "\trascontrol\t["
+ << CommandLineParser::LongSign << cmlHelp.getLongName() << "]["
+ << CommandLineParser::LongSign << cmlHost.getLongName() << "<mainhost>]["
+ << CommandLineParser::LongSign << cmlPort.getLongName() << " <nn>]["
+#ifdef NO_OFFICIAL_RELEASE
+ << CommandLineParser::LongSign << cmlHist.getLongName() << " <file>]["
+#endif
+ << CommandLineParser::LongSign << cmlPrompt.getLongName() << " <n>]["
+ << CommandLineParser::LongSign << cmlQuiet.getLongName() << "]\n\t\t\t["
+ << CommandLineParser::LongSign << cmlLogin.getLongName() << "|"
+ << CommandLineParser::LongSign << cmlTestLogin.getLongName() << "|"
+ << CommandLineParser::LongSign << cmlInteractive.getLongName() << "|"
+ << CommandLineParser::LongSign << cmlExecute.getLongName() << " <rasmgr-command>]"
+ << std::endl;
+ std::cout << "Option description:" << std::endl;
+ cmlInter.printHelp();
+ std::cout<<std::endl;
+ }
+
+int RascontrolConfig::getWorkModus()
+ { return workModus;
+ }
+int RascontrolConfig::getLoginModus()
+ { return loginModus;
+ }
+
+const char* RascontrolConfig::getRasMgrHost()
+ { return rasmgrHost;
+ }
+int RascontrolConfig::getRasMgrPort()
+ { return rasmgrPort;
+ }
+bool RascontrolConfig::histRequest()
+ { return reqHist;
+ }
+bool RascontrolConfig::beQuiet()
+ { return quiet;
+ }
+
+bool RascontrolConfig::showHelp()
+ { return cmlHelp.isPresent();
+ }
+
+const char* RascontrolConfig::getHistFileName()
+ { return histFileName;
+ }
+const char* RascontrolConfig::getPrompt()
+ {
+ if(prompt[0]!= EOS_CHAR) return prompt;
+
+ switch(promptType)
+ {
+ case PROMPTSING : strcpy(prompt,"> ");
+ 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<<std::endl<<"Login modus:...";
+ switch(loginModus)
+ {
+ case LGIUNKNOWN : std::cout<<"unknown";break;
+ case LGIINTERACTIV : std::cout<<"interactiv";break;
+ case LGIENVIRONM : std::cout<<"environm";break;
+ }
+
+ std::cout<<std::endl<<"Rasmgr:........"<<rasmgrHost<<":"<<rasmgrPort;
+
+ std::cout<<std::endl<<"History:......."<<(reqHist ? histFileName : "not requested");
+
+ std::cout<<std::endl<<"Prompt:........"<<getPrompt();
+
+ std::cout<<std::endl<<"Command:......."<<command;
+
+ std::cout<<std::endl;
+ }
+
diff --git a/rascontrol/rasmgr_tester.cc b/rascontrol/rasmgr_tester.cc
new file mode 100644
index 0000000..f9523d0
--- /dev/null
+++ b/rascontrol/rasmgr_tester.cc
@@ -0,0 +1,171 @@
+/*
+* 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 <http://www.gnu.org/licenses/>.
+*
+* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
+rasdaman GmbH.
+*
+* For more information please see <http://www.rasdaman.org>
+* or contact Peter Baumann via <baumann@rasdaman.com>.
+/
+/**
+ * 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:"<<modus<<endl;
+ //cout<<"E:"<<expect <<endl;
+ if(strcasecmp(modus,expect)!=0)
+ { //cout<<"RasMgr is not running in test modus, so we can't do the test!"<<endl;
+ return false;
+ }
+ return true;
+ }
+
+bool RasMgrTester::loadCommand(const char *x)
+ { strncpy(command,x,100);
+ return true;
+ }
+bool RasMgrTester::loadCommand(std::ifstream &ifs)
+ {
+ command[0] = EOS_CHAR;
+ ifs.getline(command,MAXCOMMAND);
+ clearCR(command);
+ return command[0] ? true:false;
+ }
+
+bool RasMgrTester::loadExpected(const char *x)
+ {
+ strncpy(expected,x,MAXMSGRASCONTROL);
+ clearFinalCRLF(expected);
+ return true;
+ }
+bool RasMgrTester::loadExpected(std::ifstream &ifs,char delim)
+ {
+ int i;
+ const std::streamoff off=-1;
+ for(i=0;i<MAXMSGRASCONTROL;i++)
+ { char c;
+ ifs.read(&c,1);
+ if(!ifs) break;
+
+ if(c==delim) { ifs.seekg(off, std::ios::cur);
+ break;
+ }
+ expected[i]=c;
+ }
+ expected[i]=0;
+
+ clearFinalCRLF(expected);
+
+ return strlen(expected) ? true:false;
+ }
+
+bool RasMgrTester::sendCommandGetAnswer()
+ {
+ int result = 0; // COMM_* values
+ const char *r = NULL;
+
+ result = rasmgrClient.sendMessageGetAnswer(command, &r );
+ if(r == NULL)
+ return false;
+
+ return true;
+ }
+
+bool RasMgrTester::isAnswerOK()
+ { const char *r=rasmgrClient.getBody();
+
+ return strcasecmp(r,expected)==0 ? true:false;
+ }
+const char* RasMgrTester::getCommand()
+ { return command;
+ }
+
+const char* RasMgrTester::getExpected()
+ { return expected;
+ }
+
+const char* RasMgrTester::getAnswer()
+ { return rasmgrClient.getBody();
+ }
+
+bool RasMgrTester::saveCommand(std::ofstream &ofs)
+ { ofs<<command<<endl;
+ return true;
+ }
+bool RasMgrTester::saveExpected(std::ofstream &ofs)
+ { ofs<<expected<<endl;
+ return true;
+ }
+bool RasMgrTester::saveAnswer(std::ofstream &ofs)
+ { ofs<<rasmgrClient.getBody()<<endl;
+ return true;
+ }
+
+void RasMgrTester::clearCR(char *line)
+ { // This func clears the CR from the end of the line read by getline
+ int len = strlen(line);
+ if(len==0) return;
+ if(line[len-1]=='\r') line[len-1]=0;
+ }
+void RasMgrTester::clearFinalCRLF(char *string)
+ { // reading the expected answer from a file can bring and ending CRLF, which has to be removed
+ int len = strlen(string);
+ if(len<2) return;
+ if(string[len-1]=='\r' || string[len-1]=='\n') string[len-1]=0;
+ if(string[len-2]=='\r' || string[len-2]=='\n') string[len-2]=0;
+ }
+
diff --git a/rascontrol/rasmgr_tester.hh b/rascontrol/rasmgr_tester.hh
new file mode 100644
index 0000000..b9d36f9
--- /dev/null
+++ b/rascontrol/rasmgr_tester.hh
@@ -0,0 +1,85 @@
+/*
+* 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 <http://www.gnu.org/licenses/>.
+*
+* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
+rasdaman GmbH.
+*
+* For more information please see <http://www.rasdaman.org>
+* or contact Peter Baumann via <baumann@rasdaman.com>.
+/
+/**
+ * SOURCE: rasmgr_tester.hh
+ *
+ * MODULE: rascontrol
+ * CLASS: RasMgrTester
+ *
+ * COMMENTS:
+ *
+ *
+*/
+
+#ifndef RASMGR_TESTER_HH
+#define RASMGR_TESTER_HH
+
+#include "rasmgr_utils_comm.hh"
+#include <fstream>
+
+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 <http://www.gnu.org/licenses/>.
+*
+* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
+rasdaman GmbH.
+*
+* For more information please see <http://www.rasdaman.org>
+* or contact Peter Baumann via <baumann@rasdaman.com>.
+/
+/**
+ * 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)<reqLen)
+ { closeSocket(); // redundant, but ok as safety measure^
+ TALK( "RasMgrClientComm::sendMessage: cannot write, socket closed." );
+ result = COMM_ERR;
+ }
+
+ LEAVE( "RasMgrClientComm::sendMessage: leave. result=" << result );
+ return result;
+ }
+
+const char* RasMgrClientComm::readMessage()
+ {
+ ENTER( "RasMgrClientComm::readMessage: enter." );
+
+ if(readWholeMessage(rasmgrSocket,answerMessage,MAXMSGRASCONTROL)<0)
+ { closeSocket(); // redundant, but ok as safety measure^
+ TALK( "RasMgrClientComm::readMessage: cannot read message from rasmgr." );
+ answerBody=answerMessage;
+ answerMessage[0] = EOS_CHAR;
+ return NULL;
+ }
+
+ answerMessage[MAXMSGRASCONTROL-1]='\0';
+
+ answerBody=strstr(answerMessage,"\r\n\r\n");
+ if(answerBody)
+ { *answerBody=0;
+ answerBody+=4;
+ }
+ else
+ answerBody=answerMessage+strlen(answerMessage);
+
+ LEAVE( "RasMgrClientComm::readMessage: leave. answerBody=" << answerBody );
+ return answerBody;
+ }
+
+const char* RasMgrClientComm::getHeader()
+ {
+ return answerMessage;
+ }
+
+const char* RasMgrClientComm::getBody()
+ {
+ return answerBody;
+ }
+
+// bugfix: socket was not closed in case of send or receive error (was done in subroutines, dispersed)
+int RasMgrClientComm::sendMessageGetAnswer(const char *message, const char **responsePtr)
+ {
+ int result = COMM_CONT; // actually, in the end COMM_* from rasmgr_utils_comm.hh; COMM_CONT means OK
+ const char *rcvMsg = NULL; // message ptr delivered by readMessage()
+
+ ENTER( "RasMgrClientComm::sendMessageGetAnswer: enter. message=" << message );
+
+ TALK( "RasMgrClientComm::sendMessageGetAnswer: opening socket." );
+ result = openSocket(); // open socket to rasmgr
+ if ( result < 0 ) // open went wrong?
+ {
+ TALK( "RasMgrClientComm::sendMessageGetAnswer: cannot open socket." );
+ result = COMM_ERR;
+ }
+ else // we have a good socket, proceed
+ {
+ result = sendMessage(message); // send message to rasmgr, get a COMM_* answer
+ if ( result == COMM_CONT ) // "continue, no error"
+ rcvMsg = readMessage(); // receive result from rasmgr
+ result = ( result == COMM_CONT && rcvMsg != NULL) ? COMM_CONT : COMM_ERR;
+ // FIXME: should be refined
+ TALK( "RasMgrClientComm::sendMessageGetAnswer: closing socket." );
+ closeSocket(); // close socket again, in any case
+ // (due to current implementation, may have been closed before, no problem)
+ }
+
+ if (result == COMM_CONT && rcvMsg != NULL)
+ {
+ rcvMsg = stripBlanks( rcvMsg );
+ *responsePtr = rcvMsg;
+ }
+
+ LEAVE( "RasMgrClientComm::sendMessageGetAnswer: leave. result=" << result );
+ return result;
+ }
+
+// strip leading blanks from message string
+const char* RasMgrClientComm::stripBlanks(const char *r)
+ {
+ if (r==NULL)
+ return NULL;
+
+ const char *s = r;
+ while ( *s == ' ' || *s == '\t' )
+ s++;
+
+ return s;
+ }
+
+int RasMgrClientComm::writeWholeMessage(int socket,char *destBuffer,int buffSize)
+ {
+ ENTER( "RasMgrClientComm::writeWholeMessage: enter. socket=" << socket );
+
+ // we write the whole message, including the ending '\0', which is already in
+ // the buffSize provided by the caller
+ int totalLength=0;
+ int writeNow;
+ while(1)
+ {
+ writeNow = write(socket,destBuffer+totalLength,buffSize-totalLength);
+ if(writeNow == -1)
+ { if(errno == EINTR) continue; // read was interrupted by signal
+
+ LEAVE( "RasMgrClientComm::writeWholeMessage: leave. EINTR." );
+ return -1; // another error
+ }
+ totalLength+=writeNow;
+
+ if( totalLength==buffSize ) break; // THE END
+ }
+
+ LEAVE( "RasMgrClientComm::writeWholeMessage: leave. totalLength=" << totalLength );
+ return totalLength;
+ }
+
+int RasMgrClientComm::readWholeMessage(int socket,char *destBuffer,int buffSize)
+ {
+ ENTER( "RasMgrClientComm::readWholeMessage: enter. socket=" << socket );
+
+ // we read what is comming in until we encounter a '\0'
+ // this is our end-sign.
+ int totalLength=0;
+ int redNow;
+ while(1)
+ {
+ redNow = read(socket,destBuffer+totalLength,buffSize-totalLength);
+ if(redNow == -1)
+ { if(errno == EINTR) continue; // read was interrupted by signal
+
+ LEAVE( "RasMgrClientComm::readWholeMessage: leave. EINTR." );
+ return -1; // another error
+ }
+ totalLength+=redNow;
+
+ if(destBuffer[totalLength-1]==0) break; // THE END
+ }
+
+ LEAVE( "RasMgrClientComm::readWholeMessage: leave. totalLength=" << totalLength );
+ return totalLength;
+ }
+
+
+
+//################################################################################
+UserLogin::UserLogin()
+ {
+ userName[0]= EOS_CHAR;
+ encrPass[0]= EOS_CHAR;
+ }
+UserLogin::~UserLogin()
+ {
+ }
+int UserLogin::interactiveLogin()
+ {
+ std::cerr<<"Login name: ";
+ char *rasp=fgets(userName,99,stdin);
+ if(!rasp) return -1;
+ //strtok(userName,"\r\n"); //removes the ending \r\n
+
+ for(int i=0;userName[i];i++)
+ {
+ if(userName[i]==' ' || userName[i]=='\t' || userName[i]=='\r' || userName[i]=='\n')
+ { userName[i]=0;break;
+ }
+ }
+
+ char *plainPass=getpass(" Password: ");
+ messageDigest(plainPass,encrPass,"MD5");
+ for(int i=0;i<strlen(plainPass);i++) plainPass[i]=0;
+ std::cerr<<std::endl;
+
+ // cout<<"name="<<username<<" pass="<<encrPass<<endl;
+ return 0;
+ }
+int UserLogin::environmentLogin()
+ {
+ char *s=getenv("RASLOGIN");
+ if(s==NULL) return -1;
+ int i;
+
+ for(i=0;i<99 && *s!=':' && *s ;i++,s++)
+ {
+ userName[i]=*s;
+ }
+ userName[i]=0;
+
+ if(*s != ':') return -1;
+
+ s++;
+ strcpy(encrPass,s);
+ return 0;
+ }
+
+int UserLogin::quickLogin()
+ {
+ strcpy(userName,"rasadmin");
+ messageDigest("rasadmin",encrPass,"MD5");
+ return 0;
+ }
+
+const char *UserLogin::getUserName()
+ {
+ return userName;
+ }
+const char *UserLogin::getEncrPass()
+ {
+ return encrPass;
+ }
+
diff --git a/rascontrol/rasmgr_utils_comm.hh b/rascontrol/rasmgr_utils_comm.hh
new file mode 100644
index 0000000..008ad3b
--- /dev/null
+++ b/rascontrol/rasmgr_utils_comm.hh
@@ -0,0 +1,127 @@
+/*
+* 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 <http://www.gnu.org/licenses/>.
+*
+* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
+rasdaman GmbH.
+*
+* For more information please see <http://www.rasdaman.org>
+* or contact Peter Baumann via <baumann@rasdaman.com>.
+/
+/**
+ * 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 <stdio.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netdb.h>
+#include <iostream>
+#include <string.h>
+
+#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 <http://www.gnu.org/licenses/>.
+*
+* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
+rasdaman GmbH.
+*
+* For more information please see <http://www.rasdaman.org>
+* or contact Peter Baumann via <baumann@rasdaman.com>.
+/
+/**
+ * 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<argc )
+ found = !strcmp( searchText, argv[i++] );
+
+ if( found && i<argc && !strchr(argv[i],'-') )
+ optionValueIndex = i;
+ else
+ optionValueIndex = 0;
+
+ return found;
+}
+
+
+void ConfigurationBase::printHelp()
+ {
+ std::cout<<"Help not available..."<< std::endl;
+ }
+
diff --git a/rascontrol/rasmgr_utils_conf.hh b/rascontrol/rasmgr_utils_conf.hh
new file mode 100644
index 0000000..676abed
--- /dev/null
+++ b/rascontrol/rasmgr_utils_conf.hh
@@ -0,0 +1,61 @@
+/*
+* 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 <http://www.gnu.org/licenses/>.
+*
+* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
+rasdaman GmbH.
+*
+* For more information please see <http://www.rasdaman.org>
+* or contact Peter Baumann via <baumann@rasdaman.com>.
+/
+/**
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <iostream>
+
+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 <http://www.gnu.org/licenses/>.
+*
+* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
+rasdaman GmbH.
+*
+* For more information please see <http://www.rasdaman.org>
+* or contact Peter Baumann via <baumann@rasdaman.com>.
+/
+/**
+ * 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 << "." <<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";
+
+ cout << "This software contains software which is in the public domain:" << endl;
+ cout << "- openssl 0.96c (C) 1998-2002 The OpenSSL Project, (C) 1995-1998 Eric A. Young, Tim J. Hudson" << endl;
+
+ if( config.interpretArguments(argc, argv) == false) return 0;
+
+ if(testIsMessageDigestAvailable("MD5")==false)
+ { cout<<"No MD5-Algorithm."<<endl;
+ return 2;
+ }
+
+ if(userLogin.interactiveLogin()<0) return 1;
+
+ rasmgrComm.setRasMgrHost(config.getRasMgrHost(),config.getRasMgrPort());
+ rasmgrComm.setUserIdentification(userLogin.getUserName(),userLogin.getEncrPass());
+
+ if(execute( RASMGRCMD_HELLO ) == false) return 3;
+
+ getPasswdKeyboard(" Type your new password: ",encrNewPass1);
+ getPasswdKeyboard(" Retype the new password: ",encrNewPass2);
+
+ if(strcmp(encrNewPass1,encrNewPass2)!=0)
+ { cout<<"Passwords don't match."<<endl;
+ return 2;
+ }
+
+ // cout<<"name="<<username<<" pass="<<encrPass<<endl;
+
+ sprintf(message,"change user %s -encrPasswd %s ",userLogin.getUserName(),encrNewPass1);
+
+ if(execute(message) == false) return 3;
+
+ return 0;
+}
+
+bool execute(const char *message)
+ {
+ bool result = true; // function result
+ int comm = 0; // COMM_* values
+ const char *answer = NULL; // rasmgr response
+
+ comm = rasmgrComm.sendMessageGetAnswer(message, &answer);
+
+ switch(comm)
+ {
+ case COMM_ERR:
+ cout << "Cannot connect to rasmgr host "<<config.getRasMgrHost() <<"." << endl;
+ result = false;
+ break;
+ case COMM_ACDN:
+ cout << "Access denied." << endl;
+ result = false;
+ break;
+ default: // then it's ok
+ break;
+ }
+ cout << rasmgrComm.getBody() << endl;
+
+ return result;
+ }
+
+const char* getPasswdKeyboard(const char*text, char*dest)
+ {
+ char *plainPass=getpass(text);
+ messageDigest(plainPass,dest,"MD5");
+ for(int i=0;i<strlen(plainPass);i++) plainPass[i]=0;
+ //cout<<endl;
+ return dest;
+ }
+
+
+bool exitbyerror(char* text)
+{ perror(text);return false;
+}
+
+//################ Config ##################################
+RasPasswdConfig::RasPasswdConfig() :
+ cmlInter (CommandLineParser::getInstance()),
+ cmlHost (cmlInter.addStringParameter(CommandLineParser::noShortName,"host", "<name> name of host where master rasmgr runs", DEFAULT_HOSTNAME)),
+ cmlPort (cmlInter.addLongParameter(CommandLineParser::noShortName,"port", "<nnnn> 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]"<<endl;
+ cout << "Options:" << endl;
+ cmlInter.printHelp();
+ cout<<endl;
+ }
+
+const char* RasPasswdConfig::getRasMgrHost()
+ { return rasmgrHost;
+ }
+int RasPasswdConfig::getRasMgrPort()
+ { return rasmgrPort;
+ }
+
+/*
+void RasPasswdConfig::printDebugInfo()
+ {
+ cout<<"Working modus:.";
+ switch(workModus)
+ {
+ case WKMUNKNOWN : cout<<"unknown";break;
+ case WKMINTERACTIV : cout<<"interactiv";break;
+ case WKMBATCH : cout<<"batch";break;
+ case WKMLOGIN : cout<<"login";break;
+ }
+
+ cout<<endl<<"Login modus:...";
+ switch(loginModus)
+ {
+ case LGIUNKNOWN : cout<<"unknown";break;
+ case LGIINTERACTIV : cout<<"interactiv";break;
+ case LGIENVIRONM : cout<<"environm";break;
+ }
+
+ cout<<endl<<"Rasmgr:........"<<rasmgrHost<<":"<<rasmgrPort;
+
+ cout<<endl<<"History:......."<<(reqHist ? histFileName : "not requested");
+
+ cout<<endl<<"Prompt:........"<<getPrompt();
+
+ cout<<endl<<"Command:......."<<command;
+
+ cout<<endl;
+ }
+*/
diff --git a/rascontrol/raspasswd.hh b/rascontrol/raspasswd.hh
new file mode 100644
index 0000000..e13a947
--- /dev/null
+++ b/rascontrol/raspasswd.hh
@@ -0,0 +1,89 @@
+/*
+* 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 <http://www.gnu.org/licenses/>.
+*
+* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
+rasdaman GmbH.
+*
+* For more information please see <http://www.rasdaman.org>
+* or contact Peter Baumann via <baumann@rasdaman.com>.
+/
+/**
+ * SOURCE: raspasswd.hh
+ *
+ * MODULE: rascontrol
+ * CLASS:
+ *
+ * PURPOSE:
+ * RasDaMan password utility
+ *
+ * COMMENTS:
+ *
+*/
+
+#ifndef RASPASSWD_HH
+#define RASPASSWD_HH
+
+#include<stdio.h>
+#include<errno.h>
+#include<stdlib.h>
+#include<unistd.h>
+#include<sys/types.h>
+#include<sys/socket.h>
+#include<netinet/in.h>
+#include<netdb.h>
+#include<iostream>
+#include<string.h>
+#include <string>
+
+#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 <http://www.gnu.org/licenses/>.
+*
+* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
+rasdaman GmbH.
+*
+* For more information please see <http://www.rasdaman.org>
+* or contact Peter Baumann via <baumann@rasdaman.com>.
+/
+/**
+ * SOURCE: rasmgrtest.cc
+ *
+ * MODULE: rascontrol
+ * CLASS:
+ *
+ * PURPOSE:
+ * Utility to test the rasmgr command language.
+ *
+ * COMMENTS:
+ *
+ *
+ */
+
+#include <fstream>
+#include <iomanip>
+
+#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?"<<endl;
+ return 1;
+ }
+
+ if(testIsMessageDigestAvailable("MD5")==false)
+ { cout<<"No MD5-Algorythm!"<<endl;
+ return 2;
+ }
+
+ rasmgrTester.setRasMgrHost(config.getRasMgrHost(), config.getRasMgrPort());
+
+ // tre sa testezi modul de lucru al rasmgr, sa nu faci test cind e activ!!
+ if(rasmgrTester.mayWeDoTest()==false)
+ { cout<<"Can't do test while RasMgr is not running in test modus"<<endl;
+ return 3;
+ }
+
+ if(config.getWorkModus() == WKMCREATE) createTestFile();
+
+ if(config.getWorkModus() == WKMTSLANG) testCommandLanguage();
+
+ return 0;
+ }
+
+void createTestFile()
+ { // preia history file si face din el testfile-ul
+ cout<<"Creating test file "<<config.getTestFile()<<" from command list file "<<config.getCommandListFile()<<endl;
+ std::ifstream history(config.getCommandListFile());
+ if(!history) { cout<<"Can't open command list file "<<config.getCommandListFile()<<endl;
+ return;
+ }
+
+ std::ofstream testofs(config.getTestFile(),ios::out|ios::trunc);
+ if(!testofs) { cout<<"Can't open test file "<<config.getTestFile()<<endl;
+ return;
+ }
+
+ while(rasmgrTester.loadCommand(history))
+ {
+ if(rasmgrTester.sendCommandGetAnswer()==false) break;
+
+ rasmgrTester.saveCommand(testofs);
+ rasmgrTester.saveAnswer(testofs);
+ testofs<<"§§§- new command -§§§"<<endl;
+ }
+
+ cout<<"OK"<<endl;
+ }
+
+void removeComments(std::ifstream &ifs)
+ {
+ char *line = new char[MAXCOMMAND];
+
+ for(;;)
+ {
+ std::streampos poz=ifs.tellg();
+ ifs.getline(line,MAXCOMMAND);
+ if(!ifs) break;
+ if(line[0]!=TESTERCOMMENT)
+ { ifs.seekg(poz, std::ios::beg);
+ break;
+ }
+ }
+ delete[] line;
+ }
+void testCommandLanguage()
+ {
+ bool quiet = config.beQuiet();
+
+ cout<<"Testing the command language"<<endl;
+ std::ifstream iftestfile(config.getTestFile());
+ if(!iftestfile) { cout<<"Can't find testfile: "<<config.getTestFile()<<endl;
+ return;
+ }
+ std::ofstream logfile(config.getLogFile(),ios::out|ios::trunc);
+ if(!logfile) { cout<<"Can't open logfile: "<<config.getLogFile()<<endl;
+ return;
+ }
+
+ int countOk = 0;
+ int countFailed = 0;
+ int countTotal = 0;
+
+ for(int i=0;;i++)
+ {
+ removeComments(iftestfile);
+ if(rasmgrTester.loadCommand(iftestfile) == false) break;
+ rasmgrTester.loadExpected(iftestfile,TESTERCOMMENT);
+ rasmgrTester.sendCommandGetAnswer();
+
+ if(!quiet) cout <<std::setw(3)<<i<<". "<<rasmgrTester.getCommand()<<" ... ";
+ logfile<<std::setw(3)<<i<<". "<<rasmgrTester.getCommand()<<" ... ";
+
+ if(rasmgrTester.isAnswerOK())
+ {
+ if(!quiet) cout <<"OK"<<endl;
+ logfile<<"OK"<<endl;
+ countOk++;
+ }
+ else
+ {
+ if(!quiet) cout <<"FAILED"<<endl;
+ logfile<<"FAILED"<<endl;
+ logfile<<"§expected:"<<endl<<rasmgrTester.getExpected()<<'*'<<endl;
+ logfile<<"$got:"<<endl<<rasmgrTester.getAnswer()<<endl;
+ countFailed++;
+ }
+
+ countTotal++;
+ }
+
+ iftestfile.close();
+ logfile.close();
+
+ cout<<"Total: "<<countTotal<<" Passed="<<countOk<<" Failed="<<countFailed<<endl;
+ }
+
diff --git a/rascontrol/test/rasmgrtester_conf.cc b/rascontrol/test/rasmgrtester_conf.cc
new file mode 100644
index 0000000..a6bf7cc
--- /dev/null
+++ b/rascontrol/test/rasmgrtester_conf.cc
@@ -0,0 +1,133 @@
+/*
+* 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 <http://www.gnu.org/licenses/>.
+*
+* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
+rasdaman GmbH.
+*
+* For more information please see <http://www.rasdaman.org>
+* or contact Peter Baumann via <baumann@rasdaman.com>.
+/
+/**
+ * SOURCE: rasmgrtester_conf.cc
+ *
+ * MODULE: rascontrol
+ * CLASS: TesterConf
+ *
+ * PURPOSE:
+ * Configuration from commandline and environment for rasmgrtest
+ *
+ * COMMENTS:
+ *
+*/
+
+
+#include "rasmgrtester_conf.hh"
+#include "rascontrol.hh"
+
+
+TesterConf::TesterConf()
+ {
+ strcpy(rasmgrHost,"localhost");
+ rasmgrPort = RASMGRPORT;
+
+ commandListFile[0] = EOS_CHAR;
+ testFile[0] = EOS_CHAR;
+
+ strcpy(logFile,"rasmgrtest.log");
+
+ workModus=WKMUNKNOWN;
+ quiet = false;
+ }
+
+bool TesterConf::interpretArguments(int argc, char **argv)
+ {
+ if(argc < 2) { printHelp(); return false;}
+
+ if(argv[1][0] != '-') strcpy(rasmgrHost,argv[1]);
+
+ int optionValueIndex;
+
+ if( checkArguments( argc, argv, "-h", optionValueIndex ) )
+ { printHelp();
+ return false;
+ }
+
+ if(checkArguments( argc, argv, "-port", optionValueIndex ) )
+ { if(optionValueIndex)
+ rasmgrPort = strtoul(argv[optionValueIndex],(char**)NULL,10);
+ }
+ if(checkArguments( argc, argv, "-cf", optionValueIndex ) )
+ { if(optionValueIndex)
+ strcpy(commandListFile,argv[optionValueIndex]);
+ }
+
+ if(checkArguments( argc, argv, "-tf", optionValueIndex ) )
+ { if(optionValueIndex)
+ strcpy(testFile,argv[optionValueIndex]);
+ }
+
+ if(checkArguments( argc, argv, "-lf", optionValueIndex ) )
+ { if(optionValueIndex)
+ strcpy(logFile,argv[optionValueIndex]);
+ }
+
+ if(checkArguments( argc, argv, "-quiet", optionValueIndex ) )
+ { quiet = true;
+ }
+
+ if( commandListFile[0] && testFile[0]) workModus = WKMCREATE;
+
+ else if(testFile[0]) workModus = WKMTSLANG;
+
+ return true;
+ }
+int TesterConf::getWorkModus()
+ { return workModus;
+ }
+const char* TesterConf::getRasMgrHost()
+ { return rasmgrHost;
+ }
+
+int TesterConf::getRasMgrPort()
+ { return rasmgrPort;
+ }
+
+const char* TesterConf::getCommandListFile()
+ { return commandListFile;
+ }
+const char* TesterConf::getTestFile()
+ { return testFile;
+ }
+const char* TesterConf::getLogFile()
+ { return logFile;
+ }
+
+bool TesterConf::beQuiet()
+ { return quiet;
+ }
+
+void TesterConf::printHelp()
+ {
+ cout<<"Usage: rasmgrtest mainhost [options]"<<endl;
+ cout<<"\tmainhost ... the hostname where the master RasMgr runs"<<endl;
+ cout<<"\t-port ... the listen port of the master RasMgr (default: "<<RASMGRPORT<<") "<<endl;
+ cout<<"\t-cf <file> ... command list file, from which the test file should be created"<<endl;
+ cout<<" (if none the test file is used to test the RasMgr)"<<endl;
+ cout<<"\t-tf <file> ... test file"<<endl;
+ cout<<"\t-lf <file> ... log file (default rasmgrtest.log)"<<endl;
+ cout<<endl;
+ }
+
diff --git a/rascontrol/test/rasmgrtester_conf.hh b/rascontrol/test/rasmgrtester_conf.hh
new file mode 100644
index 0000000..231508c
--- /dev/null
+++ b/rascontrol/test/rasmgrtester_conf.hh
@@ -0,0 +1,79 @@
+/*
+* 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 <http://www.gnu.org/licenses/>.
+*
+* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
+rasdaman GmbH.
+*
+* For more information please see <http://www.rasdaman.org>
+* or contact Peter Baumann via <baumann@rasdaman.com>.
+/
+/**
+ * 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