Secure connections.
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <ehs.h>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cerrno>
#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
#ifdef HAVE_SYS_SOCKET_H
# include <sys/socket.h>
#endif
#ifdef HAVE_SYS_WAIT_H
# include <sys/wait.h>
#endif
#ifdef HAVE_NETINET_IN_H
# include <netinet/in.h>
#endif
#ifdef HAVE_ARPA_INET_H
#include <arpa/inet.h>
#endif
#include "common.h"
using namespace std;
#ifndef _WIN32
{
public:
virtual bool BindPrivilegedPort(int socket, const char *addr, const unsigned short port)
{
bool ret = false;
pid_t pid;
int status;
char buf[32];
pthread_mutex_lock(&mutex);
switch (pid = fork()) {
case 0:
sprintf(buf, "%08x%08x%04x", socket, inet_addr(addr), port);
execl("bindhelper", buf, ((void *)NULL));
exit(errno);
break;
case -1:
break;
default:
if (waitpid(pid, &status, 0) != -1) {
ret = (0 == status);
if (0 != status)
cerr << "bind: " << strerror(WEXITSTATUS(status)) << endl;
}
break;
}
pthread_mutex_unlock(&mutex);
return ret;
}
private:
static pthread_mutex_t mutex;
};
pthread_mutex_t MyHelper::mutex = PTHREAD_MUTEX_INITIALIZER;
#endif
int main(int argc, char ** argv)
{
cout << getEHSconfig() << endl;
if (argc != 4) {
cout << "Usage: " << basename(argv[0]) << " <port> <certificate file> <passphrase>" << endl;
return 0;
}
#ifndef _WIN32
MyHelper h;
#endif
EHSServerParameters oSP;
oSP["port"] = argv[1];
oSP["https"] = 1;
oSP["certificate"] = argv[2];
oSP["passphrase"] = argv[3];
oSP["mode"] = "threadpool";
try {
kbdio kbd;
cout << "Press q to terminate ..." << endl;
usleep(300000);
}
} catch (exception &e) {
cerr << "ERROR: " << e.what() << endl;
}
return 0;
}
EHS provides HTTP server functionality to a child class.
void SetBindHelper(PrivilegedBindHelper *helper)
Sets a PrivilegedBindHelper for use by the network abstraction layer.
void StopServer()
Shuts down this instance.
void StartServer(EHSServerParameters ¶ms)
Starts up this instance.
bool ShouldTerminate() const
Retrieve the server's exception status.
Helper class for binding of sockets to privileged ports.