Browse Source

Removed -config processing. Added checks for specification of -auth

or -id (but not both) with another command.


git-svn-id: https://svn.microneil.com/svn/SNFUtility/trunk@26 aa37657e-1934-4a5f-aa6d-2d8eab27ff7c
master
adeniz 11 years ago
parent
commit
a71d368b6f

+ 12
- 35
Common/UtilityConfig.cpp View File

@@ -152,21 +152,6 @@ UtilityConfig::UtilityConfig() :
}
void
UtilityConfig::CheckAndSetConfigFileName(const std::string DefaultFile) {
string SpecifiedConfigFile = GetConfigFileName();
if (SpecifiedConfigFile.length() > 0) {
return;
}
SetConfigFileName(DefaultFile);
}
void
UtilityConfig::CreateDefaultConfigFile(std::string SampleConfigFile) {
@@ -1495,8 +1480,17 @@ UtilityConfig::ProcessCommandLineItem(std::string OneInput) {
} else if (0 == OneInput.find(AuthenticationKey)) {
Authentication = Trim(OneInput.substr(AuthenticationKey.length()));
AuthenticationIsSpecified = true;
TempString = Trim(OneInput.substr(AuthenticationKey.length())); // Copy only if not null after trimming.
if (!TempString.empty()) {
Authentication = TempString;
AuthenticationIsSpecified = true;
} else {
ValidCommand = false;
}
} else {
@@ -1511,23 +1505,7 @@ UtilityConfig::ProcessCommandLineItem(std::string OneInput) {
bool
UtilityConfig::CommandLineIsOkay() {
std::string ConfigFile = GetConfigFileName();
bool NoCredentialSpecified = !(AuthenticationIsSpecified || LicenseIdIsSpecified);
int NumCommandsSpecified = 0;
if (UpdateCredentialsSpecified()) {
if (ConfigFile.length() > 0) {
return false;
}
NumCommandsSpecified++;
}
// AVD modified to here.
return true;
return (AuthenticationIsSpecified == LicenseIdIsSpecified);
}
@@ -1564,7 +1542,6 @@ UtilityConfig::HelpDescription(std::string ExclusiveCommandsHelp) {
Desc += " -auth=authentication Specifies the Authentication\n";
Desc += " -start Start the sniffer\n";
Desc += " -stop Stop the sniffer\n";
Desc += " -config=snf-config-file Specifies the configuration file\n";
Desc += " -v Provide verbose output\n";
Desc += " -explain Provide an explaination of the actions\n";
Desc += " without executing any commands\n";

+ 7
- 16
Common/UtilityConfig.hpp View File

@@ -36,26 +36,13 @@ public:
/// Object to back up and restore files.
FileBackup SaveFile;
/// Set the config file name to the default if it wasn't specified.
//
// If the configuration file wasn't specified by
// SetConfigFileName() on the command line, then this method sets
// the config file to the specified default.
//
// If the configuration file was specified by SetConfigFileName()
// or on the command line, then this method does nothing.
//
// \param[in] DefaultFile is the default file name.
//
void CheckAndSetConfigFileName(const std::string DefaultFile);
/// If the configuration file doesn't exist, create it from the
/// sample file. In any case, set the owner and mode.
//
// This method creates the default configuration file if the
// specified configuration file doesn't exist.
//
// The method CheckAndSetConfigFileName must be called before this
// The method SetConfigFileName must be called before this
// method.
//
// \param[in] SampleConfigFile is the name of the sample
@@ -207,7 +194,7 @@ public:
//
// \note The configuration information must be loaded before calling this method.
//
// \see CheckAndSetConfigFileName.
// \see SetConfigFileName.
//
// \see CreateDefaultConfigFile.
//
@@ -314,11 +301,15 @@ public:
/// Check whether the command-line parameters were specified
/// correctly.
//
// This function check that either both the LicenseID and
// This method checks that either both the LicenseID and
// Authentication were specified, or neither were.
//
// This method does not check for multiple commands specified on
// the command line.
//
// \returns if the command-line parameters were specified
// correctly, false otherwise.
//
bool CommandLineIsOkay(void);
/// Output the legal command-line input.

+ 7
- 8
SNFMilterConfig/SNFMilterConfig.cpp View File

@@ -95,10 +95,9 @@ SNFMilterConfig::DisplayHelp(std::string Version) {
<< UtilityConfig::HelpCommandLine(ExclusiveCommands) << "\n\n"
<< "SNFMilterConfig "
<< UtilityConfig::HelpDescription(ExclusiveCommandsHelp) << "\n"
<< "If snf-config-file is not specified, then the following file is used if it exists:\n\n"
<< "The configuration file name is:\n\n"
<< " " << DefaultConfigFile << "\n\n"
<< "If snf-config-file is not specified and the above file doesn't exist, then it is\n"
<< "copied from the following file:\n\n"
<< "If the above file doesn't exist, then it is copied from the following file:\n\n"
<< " " << SampleConfigFile << "\n\n"
<< "If integration with an MTA is specified, that MTA is started if it isn't running,\n"
<< "or the MTA's configuration is reloaded if it is running.\n\n";
@@ -175,7 +174,7 @@ SNFMilterConfig::GetCommandLineInput(int argc, char* argv[]) {
}
return (NumCommandsFound == 1);
return ( (NumCommandsFound == 1) && CommandLineIsOkay() );
}
@@ -186,7 +185,7 @@ SNFMilterConfig::ExecuteCommand() {
case SetupRepairCommand:
CheckAndSetConfigFileName(DefaultConfigFile); // Load the config file name if not specified.
SetConfigFileName(DefaultConfigFile);
CreateDefaultConfigFile(SampleConfigFile); // Create the file if it doesn't exist,
// Set owner and mode in any case.
LoadConfig();
@@ -200,7 +199,7 @@ SNFMilterConfig::ExecuteCommand() {
case UpdateCredentialsCommand:
CheckAndSetConfigFileName(DefaultConfigFile); // Load the config file name if not specified.
SetConfigFileName(DefaultConfigFile);
LoadConfig();
LoadInfo(); // Load the file paths.
LoadSocketInfo(); // Load the socket path.
@@ -227,7 +226,7 @@ SNFMilterConfig::ExecuteCommand() {
case StartSnifferCommand:
CheckAndSetConfigFileName(DefaultConfigFile);
SetConfigFileName(DefaultConfigFile);
LoadConfig();
LoadInfo();
LoadSocketInfo();
@@ -238,7 +237,7 @@ SNFMilterConfig::ExecuteCommand() {
case StopSnifferCommand:
CheckAndSetConfigFileName(DefaultConfigFile);
SetConfigFileName(DefaultConfigFile);
LoadConfig();
LoadInfo();
LoadSocketInfo();

+ 26
- 47
SNFMilterConfig/SNFMilterConfigTests.txt View File

@@ -37,11 +37,6 @@ SNFMilterConfig takes no action.

Result: Pass.

CONFLICT-05: Run with -config=SNFMilter_second.xml -start. Verify
that help message is output, and that SNFMilterConfig takes no action.

Result: Pass.

Setup/Repair functionality
--------------------------

@@ -61,24 +56,6 @@ SETUP-03: Repeat SETUP-01 with -explain and verify that files are not created.
Result: Pass? Exception thrown (as expected) when attempting to read
configuration file that doesn't exist.

Config file specification
-------------------------

CONF-01: Start with no configuration files, and copy the sample
configuration file to test.xml. Run with "-setup -config=test.xml",
and verify that all configuration files except
/etc/snf-milter/SNFMilter.xml are created.

Result: Pass.

CONF-02: Repeat with -v and verify the same behavior.

Result: Pass.

CONF-03: Repeat with -explain.

Result: Pass.

Credential Functionality
------------------------

@@ -128,9 +105,8 @@ CRED-05: Repeat CRED-04 with -explain and verify correct operation.
Start/stop functionality with XCI enabled
-----------------------------------------

START_STOP_XCI-01: Install default configuration files, and ensure
that SNFMilter is stoped. Create a configuration file
SNFMilter_xci.xml as follows:
START_STOP_XCI-01: Install configuration file SNFMilter_xci.xml with
the following configuration:

1) Enable XCI.

@@ -140,39 +116,42 @@ SNFMilter_xci.xml as follows:

Do the following, specifying the configuration file SNFMilter_xci.xml:

1) Run SNFMilterConfig with "-start", and verify that SNFMilter starts.
1) Run SNFMilterConfig with "-v -start", and verify that SNFMilter
starts.

2) Run SNFMilterConfig with "-start" again and verify that SNFMilter
is not started again.
2) Run SNFMilterConfig with "-start -v" again and verify that
SNFMilter is still running.

3) Run SNFMitlerConfig with "-stop" and verify that SNFMilter stops.
3) Run SNFMitlerConfig with "-stop -v" and verify that SNFMilter
stops.

4) Run SNFMitlerConfig with "-stop" again and verify that SNFMilter
is not stopped again.
4) Run SNFMitlerConfig with "-stop -v" again and verify that
SNFMilter is still stopped.

Result: Pass

START_STOP_XCI-02: Repeat START_STOP_XCI-01 but with "-v" in the command-line.
START_STOP_XCI-02: Repeat START_STOP_XCI-01 but without "-v" in the
command-line.

Result: Pass
Result:

START_STOP_XCI-03: Configure as for START_STOP_XCI-01, and do the following:

1) Run SNFMilterConfig with "-start -explain". Verify correct
output, and that SNFMilterConfig doesn't start SNFMilter.
output, and that SNFMilter isn't started.

2) Run SNFMilterConfig with "-stop -explain". Verify correct
output, and that SNFMilterConfig doesn't stop SNFMilter.
output, and that SNFMilter isn't started.

3) Start SNFMilter.

4) Run SNFMilterConfig with "-start -explain". Verify correct
output, and that SNFMilterConfig doesn't start SNFMilter.
output, and that SNFMilter is still running.

5) Run SNFMilterConfig with "-stop -explain". Verify correct
output, and that SNFMilterConfig doesn't stop SNFMilter.
output, and that SNFMilter is still running.

Result: Pass
Result:

Start/stop functionality with XCI disabled, status.second enabled
-----------------------------------------------------------------
@@ -294,20 +273,20 @@ SNFMilter_minute.xml as follows:

Do the following, specifying the configuration file SNFMilter_minute.xml:

1) Run "SNFMilterConfig -config=SNFMilter_minute.xml -start", and verify that SNFMilter starts.
1) Run "SNFMilterConfig -start -v", and verify that SNFMilter
starts.

2) Run "SNFMilterConfig -config=SNFMilter_minute.xml -start" again
and verify that SNFMilter is not started again.
2) Run "SNFMilterConfig -v -start" again and verify that SNFMilter
is not started again.

3) Run "SNFMilterConfig -config=SNFMilter_minute.xml -stop" and
verify that SNFMilter stops.
3) Run "SNFMilterConfig -v -stop" and verify that SNFMilter stops.

4) Run "SNFMilterConfig -config=SNFMilter_minute.xml -stop" again
and verify that SNFMilter is not stopped again.
4) Run "SNFMilterConfig -stop -v" again and verify that SNFMilter is
not stopped again.

Result:

START_STOP_MIN-02: Repeat START_STOP_MIN-01 but with "-v" in the
START_STOP_MIN-02: Repeat START_STOP_MIN-01 but without "-v" in the
command-line.

Result:

Loading…
Cancel
Save