summaryrefslogtreecommitdiffstats
path: root/pica-registrar
diff options
context:
space:
mode:
authorme_desk <me_desk@fb96df88-216d-11de-830c-f3023f12d8ac>2012-07-26 21:20:52 +0000
committerme_desk <me_desk@fb96df88-216d-11de-830c-f3023f12d8ac>2012-07-26 21:20:52 +0000
commit6f28d7631eb9be214934e38190452953df24235d (patch)
tree08aecae6265834d1aa7ea438da9801d5f1314e6f /pica-registrar
parent97193b2a96803e2106d00450bd27c85e508253e5 (diff)
downloadpica-pica-6f28d7631eb9be214934e38190452953df24235d.tar.gz
pica-pica-6f28d7631eb9be214934e38190452953df24235d.zip
multiprocess registrar implementation. New process is started for each client
git-svn-id: svn://localhost/project_picapica/trunk@153 fb96df88-216d-11de-830c-f3023f12d8ac
Diffstat (limited to 'pica-registrar')
-rw-r--r--pica-registrar/PICA_registrar.cpp89
1 files changed, 79 insertions, 10 deletions
diff --git a/pica-registrar/PICA_registrar.cpp b/pica-registrar/PICA_registrar.cpp
index 03c41c9..4da4673 100644
--- a/pica-registrar/PICA_registrar.cpp
+++ b/pica-registrar/PICA_registrar.cpp
@@ -11,6 +11,7 @@
#include <sys/errno.h>
#include <sys/stat.h>
#include <time.h>
+#include <signal.h>
#include <cstring>
#include <cstdlib>
@@ -192,9 +193,12 @@ ret = bind(s,(struct sockaddr*)&sd,sizeof(sd));
ret = listen(s, 60);
+signal(SIGCHLD, SIG_IGN);
+
while (1)
{
socklen_t sockaddr_size = sizeof(sc);
+ pid_t pid;
memset(&sc, 0, sizeof(sc));
@@ -208,27 +212,96 @@ while (1)
close(client_socket);
continue;
}
+
+
+ pid = fork();
+ if (pid > 0)
+ {
+ current_id++;
+ baninfo_update(&sc);
+ continue;
+ }
+
+ if (pid == -1)
+ {
+ perror("fork() failed");
+ continue;
+ }
+ //now we are in the child process
+
+
disconnect_flag = read_CSR(client_socket, &bytes_read);
if (disconnect_flag)
{
shutdown(client_socket, SHUT_RDWR);
close(client_socket);
- continue;
+ exit(1);
}
-
-
std::string filename = (string("/tmp/CSR-") + inet_ntoa(sc.sin_addr) );
if (store_CSR(filename, bytes_read))
{
shutdown(client_socket, SHUT_RDWR);
close(client_socket);
- continue;
+ exit(1);
}
+
+ //prepare ca environment
+ std::string ca_dir;
+ {
+ char pidstr[16];
+ sprintf(pidstr, "%u", getpid());
+ FILE *f;
+
+ ca_dir = (string)"/tmp/ca_dir." + pidstr;
+ if (-1 == mkdir(ca_dir.c_str(), S_IRUSR | S_IWUSR | S_IXUSR))
+ {
+ perror("mkdir() failed");
+ close(client_socket);
+ remove(filename.c_str());
+ exit(1);
+ }
+
+ if (-1 == chdir(ca_dir.c_str()))
+ {
+ perror("chdir() failed");
+ close(client_socket);
+ remove(filename.c_str());
+ rmdir(ca_dir.c_str());
+ exit(1);
+ }
+
+ f = fopen((ca_dir + '/' + "serial").c_str(), "w");
+
+ if (!f)
+ {
+ perror("unable to create serial file");
+ close(client_socket);
+ remove(filename.c_str());
+ rmdir(ca_dir.c_str());
+ exit(1);
+ }
+
+ fprintf(f, "%X", current_id);
+ fclose(f);
+
+ f = fopen((ca_dir + '/' + "database").c_str(), "w");
+
+ if (!f)
+ {
+ perror("unable to create database file");
+ close(client_socket);
+ remove(filename.c_str());
+ rmdir(ca_dir.c_str());
+ exit(1);
+ }
+
+ fclose(f);
+ }
char current_id_str[256];
@@ -236,7 +309,7 @@ while (1)
std::string cert_filename = (string)(current_id_str) + ".pem";
- std::string sign_command = (string)"openssl ca -config ca_config.txt -utf8 -subj /CN=" + current_id_str + "\\#tester -batch -notext -out " + cert_filename + " -in " + filename;
+ std::string sign_command = (string)"openssl ca -config /home/root_jr/temp/catest/ca_config.txt -utf8 -subj /CN=" + current_id_str + "\\#tester -batch -notext -out " + cert_filename + " -in " + filename;
puts(sign_command.c_str());//debug
@@ -246,10 +319,6 @@ while (1)
goto freeres_1;
- current_id++;
- baninfo_update(&sc);
-
-
freeres_1:
remove(cert_filename.c_str());
@@ -260,7 +329,7 @@ while (1)
shutdown(client_socket, SHUT_RDWR);
close(client_socket);
-
+ exit(0);//exiting from the child process
}
else
perror("accept");