Permalink
Browse files

Major rearrangement. Renamed directories: "fko" to "lib", "src" to "c…

…lient". Added "common" and "server" directories. Setup autoconf to allow disabling the server and/or client builds.

git-svn-id: file:///home/mbr/svn/fwknop/trunk@127 510a4753-2344-4c79-9c09-4d669213fbeb
  • Loading branch information...
1 parent 078661e commit 53b7fae8bb1b61ef5fc165819fd2ca14d96c3c86 Damien Stuart committed Aug 9, 2009
Showing with 327 additions and 222 deletions.
  1. +14 −1 Makefile.am
  2. +8 −0 client/Makefile.am
  3. 0 {src → client}/config_init.c
  4. 0 {src → client}/config_init.h
  5. +29 −132 {src → client}/fwknop.c
  6. 0 {src → client}/fwknop.h
  7. +7 −73 {src → client}/fwknop_common.h
  8. 0 {src → client}/getpasswd.c
  9. 0 {src → client}/getpasswd.h
  10. +140 −0 client/http_resolve_host.c
  11. 0 {src → client}/spa_comm.c
  12. 0 {src → client}/spa_comm.h
  13. 0 {src → client}/utils.c
  14. 0 {src → client}/utils.h
  15. +1 −0 common/Makefile.am
  16. +97 −0 common/common.h
  17. +31 −8 configure.ac
  18. 0 {fko → lib}/Makefile.am
  19. 0 {fko → lib}/base64.c
  20. 0 {fko → lib}/base64.h
  21. 0 {fko → lib}/cipher_funcs.c
  22. 0 {fko → lib}/cipher_funcs.h
  23. 0 {fko → lib}/digest.c
  24. 0 {fko → lib}/digest.h
  25. 0 {fko → lib}/fko.h
  26. 0 {fko → lib}/fko_client_timeout.c
  27. 0 {fko → lib}/fko_common.h
  28. 0 {fko → lib}/fko_context.h
  29. 0 {fko → lib}/fko_decode.c
  30. 0 {fko → lib}/fko_digest.c
  31. 0 {fko → lib}/fko_encode.c
  32. 0 {fko → lib}/fko_encryption.c
  33. 0 {fko → lib}/fko_error.c
  34. 0 {fko → lib}/fko_funcs.c
  35. 0 {fko → lib}/fko_limits.h
  36. 0 {fko → lib}/fko_message.c
  37. 0 {fko → lib}/fko_nat_access.c
  38. 0 {fko → lib}/fko_rand_value.c
  39. 0 {fko → lib}/fko_server_auth.c
  40. 0 {fko → lib}/fko_state.h
  41. 0 {fko → lib}/fko_timestamp.c
  42. 0 {fko → lib}/fko_user.c
  43. 0 {fko → lib}/fko_util.h
  44. 0 {fko → lib}/gpgme_funcs.c
  45. 0 {fko → lib}/gpgme_funcs.h
  46. 0 {fko → lib}/md5.c
  47. 0 {fko → lib}/md5.h
  48. 0 {fko → lib}/rijndael.c
  49. 0 {fko → lib}/rijndael.h
  50. 0 {fko → lib}/sha1.c
  51. 0 {fko → lib}/sha1.h
  52. 0 {fko → lib}/sha2.c
  53. 0 {fko → lib}/sha2.h
  54. 0 {fko → lib}/strlcat.c
  55. 0 {fko → lib}/strlcpy.c
  56. +0 −8 src/Makefile.am
View
@@ -1,4 +1,17 @@
-SUBDIRS = fko src doc
+if WANT_CLIENT
+ CLIENT_DIR = client
+endif
+
+if WANT_SERVER
+ SERVER_DIR = server
+endif
+
+SUBDIRS = \
+ lib \
+ common \
+ $(CLIENT_DIR) \
+ $(SERVER_DIR) \
+ doc
EXTRA_DIST = \
perl/FKO/README \
View
@@ -0,0 +1,8 @@
+bin_PROGRAMS = fwknop
+
+fwknop_SOURCES = fwknop.c fwknop.h config_init.c config_init.h \
+ fwknop_common.h spa_comm.c spa_comm.h utils.c utils.h \
+ http_resolve_host.c getpasswd.c getpasswd.h
+
+fwknop_LDADD = $(top_builddir)/lib/libfko.la
+fwknop_CPPFLAGS = -I $(top_srcdir)/lib -I $(top_srcdir)/common
File renamed without changes.
File renamed without changes.
@@ -40,7 +40,10 @@ static int set_message_type(fko_ctx_t ctx, fko_cli_options_t *options);
static int set_nat_access(fko_ctx_t ctx, fko_cli_options_t *options);
static int get_rand_port(fko_ctx_t ctx);
static void dump_transmit_options(fko_cli_options_t *options);
-static void resolve_ip_http(fko_cli_options_t *options);
+
+int resolve_ip_http(fko_cli_options_t *options);
+
+
int
main(int argc, char **argv)
@@ -69,7 +72,7 @@ main(int argc, char **argv)
if(res != FKO_SUCCESS)
{
errmsg("fko_new", res);
- return(1);
+ return(EXIT_FAILURE);
}
/* Display version info and exit.
@@ -80,7 +83,7 @@ main(int argc, char **argv)
fprintf(stdout, "[+] fwknop client %s, FKO protocol version %s\n",
MY_VERSION, version);
- return(0);
+ return(EXIT_SUCCESS);
}
/* Set client timeout
@@ -91,7 +94,7 @@ main(int argc, char **argv)
if(res != FKO_SUCCESS)
{
errmsg("fko_set_spa_client_timeout", res);
- return(1);
+ return(EXIT_FAILURE);
}
}
@@ -101,7 +104,7 @@ main(int argc, char **argv)
if(res != FKO_SUCCESS)
{
errmsg("fko_set_spa_message_type", res);
- return(1);
+ return(EXIT_FAILURE);
}
if(options.server_command[0] != 0x0)
@@ -114,8 +117,12 @@ main(int argc, char **argv)
}
else
{
+ /* Resolve the client's public facing IP address if requestesd.
+ * if this fails, consider it fatal.
+ */
if (options.resolve_ip_http)
- resolve_ip_http(&options);
+ if(resolve_ip_http(&options) < 0)
+ return(EXIT_FAILURE);
/* Set a message string by combining the allow IP and the
* port/protocol. The fwknopd server allows no port/protocol
@@ -137,7 +144,7 @@ main(int argc, char **argv)
if(res != FKO_SUCCESS)
{
errmsg("fko_set_spa_message", res);
- return(1);
+ return(EXIT_FAILURE);
}
/* Set NAT access string
@@ -148,7 +155,7 @@ main(int argc, char **argv)
if(res != FKO_SUCCESS)
{
errmsg("fko_set_nat_access_str", res);
- return(1);
+ return(EXIT_FAILURE);
}
}
@@ -160,7 +167,7 @@ main(int argc, char **argv)
if(res != FKO_SUCCESS)
{
errmsg("fko_set_username", res);
- return(1);
+ return(EXIT_FAILURE);
}
}
@@ -180,7 +187,7 @@ main(int argc, char **argv)
if(res != FKO_SUCCESS)
{
errmsg("fko_set_spa_encryption_type", res);
- return(1);
+ return(EXIT_FAILURE);
}
/* If a GPG home dir was specified, set it here. Note: Setting
@@ -193,7 +200,7 @@ main(int argc, char **argv)
if(res != FKO_SUCCESS)
{
errmsg("fko_set_gpg_home_dir", res);
- return(1);
+ return(EXIT_FAILURE);
}
}
@@ -204,7 +211,7 @@ main(int argc, char **argv)
if(IS_GPG_ERROR(res))
fprintf(stderr, "GPG ERR: %s\n", fko_gpg_errorstr(ctx));
- return(1);
+ return(EXIT_FAILURE);
}
if(options.gpg_signer_key != NULL && strlen(options.gpg_signer_key))
@@ -217,7 +224,7 @@ main(int argc, char **argv)
if(IS_GPG_ERROR(res))
fprintf(stderr, "GPG ERR: %s\n", fko_gpg_errorstr(ctx));
- return(1);
+ return(EXIT_FAILURE);
}
}
}
@@ -230,7 +237,7 @@ main(int argc, char **argv)
if(res != FKO_SUCCESS)
{
errmsg("fko_set_spa_digest_type", res);
- return(1);
+ return(EXIT_FAILURE);
}
}
@@ -244,7 +251,7 @@ main(int argc, char **argv)
if(IS_GPG_ERROR(res))
fprintf(stderr, "GPG ERR: %s\n", fko_gpg_errorstr(ctx));
- return(1);
+ return(EXIT_FAILURE);
}
/* Display the context data.
@@ -274,7 +281,7 @@ main(int argc, char **argv)
if(res < 0)
{
fprintf(stderr, "[*] send_spa_packet: packet not sent.\n");
- return(1);
+ return(EXIT_FAILURE);
}
else
{
@@ -292,7 +299,7 @@ main(int argc, char **argv)
if(res != FKO_SUCCESS)
{
errmsg("fko_get_spa_data", res);
- return(1);
+ return(EXIT_FAILURE);
}
/* If gpg-home-dir is specified, we have to defer decrypting if we
@@ -307,7 +314,7 @@ main(int argc, char **argv)
if(res != FKO_SUCCESS)
{
errmsg("fko_new_with_data", res);
- return(1);
+ return(EXIT_FAILURE);
}
/* See if we are using gpg and if we need to set the GPG home dir.
@@ -320,7 +327,7 @@ main(int argc, char **argv)
if(res != FKO_SUCCESS)
{
errmsg("fko_set_gpg_home_dir", res);
- return(1);
+ return(EXIT_FAILURE);
}
}
}
@@ -343,10 +350,10 @@ main(int argc, char **argv)
debugging purposes. */
fprintf(stderr, "GPG ERR: %s\n%s\n", fko_gpg_errorstr(ctx2),
"[*] No access to recipient private key?\n");
- return(0);
+ return(EXIT_SUCCESS);
}
- return(1);
+ return(EXIT_FAILURE);
}
printf("\nDump of the Decoded Data\n");
@@ -357,7 +364,7 @@ main(int argc, char **argv)
fko_destroy(ctx);
- return(0);
+ return(EXIT_SUCCESS);
}
static void
@@ -448,116 +455,6 @@ ipv4_str_has_port(char *str)
return rv;
}
-static void resolve_ip_http(fko_cli_options_t *options)
-{
- int sock, res, error, http_buf_len, i;
- struct addrinfo *result, *rp, hints;
- char http_buf[HTTP_MAX_REQUEST_LEN];
- char http_response[HTTP_MAX_RESPONSE_LEN];
-
- /* Build our HTTP request to resolve the external IP (this is similar to
- * to contacting whatismyip.org, but using a different URL).
- */
- snprintf(http_buf, HTTP_MAX_REQUEST_LEN,
- "%s%s%s%s%s%s%s",
- "GET ",
- HTTP_RESOLVE_URL,
- " HTTP/1.0\r\nUser-Agent: ",
- options->http_user_agent,
- "\r\nAccept: */*\r\nHost: ",
- HTTP_RESOLVE_HOST,
- "\r\nConnection: Keep-Alive\r\n\r\n"
- );
- http_buf_len = strlen(http_buf);
-
- memset(&hints, 0, sizeof(struct addrinfo));
-
- hints.ai_family = AF_UNSPEC; /* Allow IPv4 or IPv6 */
- hints.ai_socktype = SOCK_STREAM;
- hints.ai_protocol = IPPROTO_TCP;
-
- error = getaddrinfo(HTTP_RESOLVE_HOST, "80", &hints, &result);
- if (error != 0)
- {
- fprintf(stderr, "[*] error in getaddrinfo: %s\n", gai_strerror(error));
- exit(EXIT_FAILURE);
- }
-
- for (rp = result; rp != NULL; rp = rp->ai_next) {
- sock = socket(rp->ai_family, rp->ai_socktype,
- rp->ai_protocol);
- if (sock < 0)
- continue;
-
- if (error = connect(sock, rp->ai_addr, rp->ai_addrlen) != -1)
- break; /* made it */
-
-#ifdef WIN32
- closesocket(sock);
-#else
- close(sock);
-#endif
- }
-
- if (rp == NULL) {
- perror("[*] resolve_ip_http: Could not create socket: ");
- exit(EXIT_FAILURE);
- }
-
- freeaddrinfo(result);
-
- res = send(sock, http_buf, http_buf_len, 0);
-
- if(res < 0)
- {
- perror("[*] resolve_ip_http: write error: ");
- }
- else if(res != http_buf_len)
- {
- fprintf(stderr,
- "[#] Warning: bytes sent (%i) not spa data length (%i).\n",
- res, http_buf_len
- );
- }
-
- res = recv(sock, http_response, HTTP_MAX_RESPONSE_LEN, 0);
- http_response[HTTP_MAX_RESPONSE_LEN-1] = '\0';
-
-#ifdef WIN32
- closesocket(sock);
-#else
- close(sock);
-#endif
-
- /* Now parse the response for the IP address (which should be at
- * the end of the string
- */
- for (i=res-3; i >= 0; i--)
- {
- if(http_response[i] == '\n')
- break;
- if(http_response[i] != '.' && ! isdigit(http_response[i]))
- {
- fprintf(stderr, "[*] Invalid IP in HTTP response.\n");
- exit(EXIT_FAILURE);
- }
- }
- if (i < MIN_IP_STR_LEN)
- {
- fprintf(stderr, "[*] Invalid IP in HTTP response.\n");
- exit(EXIT_FAILURE);
- }
- http_response[res-1] = '\0';
-
- strlcpy(options->allow_ip_str,
- (http_response + i+1), (res - (i+2)));
-
- printf("[+] Resolved external IP (via http://%s%s) as: %s\n",
- HTTP_RESOLVE_HOST, HTTP_RESOLVE_URL, options->allow_ip_str);
-
- return;
-}
-
/* Set NAT access string
*/
static int
File renamed without changes.
Oops, something went wrong.

0 comments on commit 53b7fae

Please sign in to comment.