diff options
| author | me_desk <me_desk@fb96df88-216d-11de-830c-f3023f12d8ac> | 2012-07-09 20:11:09 +0000 |
|---|---|---|
| committer | me_desk <me_desk@fb96df88-216d-11de-830c-f3023f12d8ac> | 2012-07-09 20:11:09 +0000 |
| commit | 7f9ada392430df8b11ee198634b3fbff73276bcb (patch) | |
| tree | 0da5a76c3b9dc3fb9cbe694351bd52bf92038a80 | |
| parent | 502e5ea990ec8331e3919cb6c273e59123e62f1c (diff) | |
| download | pica-pica-7f9ada392430df8b11ee198634b3fbff73276bcb.tar.gz pica-pica-7f9ada392430df8b11ee198634b3fbff73276bcb.zip | |
registrar, continued
git-svn-id: svn://localhost/project_picapica/trunk@142 fb96df88-216d-11de-830c-f3023f12d8ac
| -rw-r--r-- | pica-registrar/PICA_registrar.cpp | 46 |
1 files changed, 43 insertions, 3 deletions
diff --git a/pica-registrar/PICA_registrar.cpp b/pica-registrar/PICA_registrar.cpp index 465c9de..9ffba7b 100644 --- a/pica-registrar/PICA_registrar.cpp +++ b/pica-registrar/PICA_registrar.cpp @@ -10,8 +10,11 @@ #include <unistd.h> #include <sys/errno.h> +#include <cstring> #include <map> +using namespace std; + #define PICA_REGISTRAR_PORT 2299 #define READ_BUF_SIZE 4096 char read_buf[READ_BUF_SIZE]; @@ -43,9 +46,10 @@ while (1) if (client_socket >= 0) { pos = 0; + disconnect_flag = 0; do { - ret = recv(client_socket, read_buf + pos, READ_BUF_SIZE - pos, 0); + ret = recv(client_socket, read_buf + pos, READ_BUF_SIZE - 1 - pos, 0); if (ret > 0) pos += ret; @@ -55,10 +59,46 @@ while (1) if (ret < 0) perror("recv"); } - + read_buf[pos + 1] = '\0'; + } + while(pos < READ_BUF_SIZE && !disconnect_flag && !std::strstr(read_buf, "-----END CERTIFICATE REQUEST-----")); + + if (disconnect_flag) + continue; + + { + FILE *csr_temp; + + std::string filename = (string("/tmp/CSR-") + inet_ntoa(sc.sin_addr) ); + + csr_temp = fopen(filename.c_str, "w"); + + if (!csr_temp) + { + perror("fopen"); + continue; } - while(); + + ret = fwrite(read_buf, pos, 1, csr_temp); + + if (ret != 1) + { + perror("fwrite"); + fclose(csr_temp); + remove(filename.c_str); + continue; + } + + fclose(csr_temp); + + //system(openssl ca) + + remove(filename.c_str); + } + } + else + perror("accept"); } |
