- fixed stroke error output to starter
This commit is contained in:
@@ -520,7 +520,7 @@ static void stroke_receive(private_stroke_t *this)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO: BAD: does not work for starter, charon crashes!! FIX this */
|
/* setup a logger which writes status to the unix socket */
|
||||||
this->stroke_logger = logger_create("-", CONTROL|ERROR, FALSE, strokefile);
|
this->stroke_logger = logger_create("-", CONTROL|ERROR, FALSE, strokefile);
|
||||||
|
|
||||||
this->logger->log_bytes(this->logger, RAW, "stroke message", (void*)msg, msg_length);
|
this->logger->log_bytes(this->logger, RAW, "stroke message", (void*)msg, msg_length);
|
||||||
|
|||||||
@@ -55,16 +55,6 @@ typedef struct stroke_t stroke_t;
|
|||||||
*/
|
*/
|
||||||
struct stroke_t {
|
struct stroke_t {
|
||||||
|
|
||||||
/**
|
|
||||||
* Implements policy_store_t interface
|
|
||||||
*/
|
|
||||||
policy_store_t policies;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Implements credential_store_t interfacce
|
|
||||||
*/
|
|
||||||
credential_store_t credentials;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Destroy a stroke_t instance.
|
* @brief Destroy a stroke_t instance.
|
||||||
*
|
*
|
||||||
|
|||||||
+74
-63
@@ -38,54 +38,65 @@
|
|||||||
|
|
||||||
static char* push_string(stroke_msg_t **strm, char *string)
|
static char* push_string(stroke_msg_t **strm, char *string)
|
||||||
{
|
{
|
||||||
stroke_msg_t *stroke_msg;
|
stroke_msg_t *stroke_msg;
|
||||||
size_t string_length;
|
size_t string_length;
|
||||||
|
|
||||||
if (string == NULL)
|
if (string == NULL)
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
stroke_msg = *strm;
|
stroke_msg = *strm;
|
||||||
string_length = strlen(string) + 1;
|
string_length = strlen(string) + 1;
|
||||||
stroke_msg->length += string_length;
|
stroke_msg->length += string_length;
|
||||||
|
|
||||||
stroke_msg = realloc(stroke_msg, stroke_msg->length);
|
stroke_msg = realloc(stroke_msg, stroke_msg->length);
|
||||||
strcpy((char*)stroke_msg + stroke_msg->length - string_length, string);
|
strcpy((char*)stroke_msg + stroke_msg->length - string_length, string);
|
||||||
|
|
||||||
*strm = stroke_msg;
|
*strm = stroke_msg;
|
||||||
return (char*)(u_int)stroke_msg->length - string_length;
|
return (char*)(u_int)stroke_msg->length - string_length;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
send_stroke_msg (stroke_msg_t *msg)
|
send_stroke_msg (stroke_msg_t *msg)
|
||||||
{
|
{
|
||||||
struct sockaddr_un ctl_addr = { AF_UNIX, CHARON_CTL_FILE };
|
struct sockaddr_un ctl_addr = { AF_UNIX, CHARON_CTL_FILE };
|
||||||
int sock;
|
int sock;
|
||||||
|
int byte_count;
|
||||||
|
char buffer[64];
|
||||||
|
|
||||||
sock = socket(AF_UNIX, SOCK_STREAM, 0);
|
sock = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||||
if (sock < 0)
|
if (sock < 0)
|
||||||
{
|
{
|
||||||
plog("socket() failed: %s", strerror(errno));
|
plog("socket() failed: %s", strerror(errno));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (connect(sock, (struct sockaddr *)&ctl_addr,
|
if (connect(sock, (struct sockaddr *)&ctl_addr,
|
||||||
offsetof(struct sockaddr_un, sun_path) + strlen(ctl_addr.sun_path)) < 0)
|
offsetof(struct sockaddr_un, sun_path) + strlen(ctl_addr.sun_path)) < 0)
|
||||||
{
|
{
|
||||||
plog("connect(charon_ctl) failed: %s", strerror(errno));
|
plog("connect(charon_ctl) failed: %s", strerror(errno));
|
||||||
close(sock);
|
close(sock);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* send message */
|
/* send message */
|
||||||
if (write(sock, msg, msg->length) != msg->length)
|
if (write(sock, msg, msg->length) != msg->length)
|
||||||
{
|
{
|
||||||
plog("write(charon_ctl) failed: %s", strerror(errno));
|
plog("write(charon_ctl) failed: %s", strerror(errno));
|
||||||
close(sock);
|
close(sock);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
while ((byte_count = read(sock, buffer, sizeof(buffer)-1)) > 0)
|
||||||
|
{
|
||||||
|
buffer[byte_count] = '\0';
|
||||||
|
plog("%s", buffer);
|
||||||
|
}
|
||||||
|
if (byte_count < 0)
|
||||||
|
{
|
||||||
|
plog(stderr, "read() failed: %s", strerror(errno));
|
||||||
|
}
|
||||||
|
|
||||||
close(sock);
|
close(sock);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
@@ -105,57 +116,57 @@ connection_name(starter_conn_t *conn)
|
|||||||
|
|
||||||
int starter_stroke_add_conn(starter_conn_t *conn)
|
int starter_stroke_add_conn(starter_conn_t *conn)
|
||||||
{
|
{
|
||||||
stroke_msg_t *msg = malloc(sizeof(stroke_msg_t));
|
stroke_msg_t *msg = malloc(sizeof(stroke_msg_t));
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
msg->length = sizeof(stroke_msg_t);
|
msg->length = sizeof(stroke_msg_t);
|
||||||
msg->type = STR_ADD_CONN;
|
msg->type = STR_ADD_CONN;
|
||||||
|
|
||||||
msg->add_conn.name = push_string(&msg, connection_name(conn));
|
msg->add_conn.name = push_string(&msg, connection_name(conn));
|
||||||
|
|
||||||
msg->add_conn.me.id = push_string(&msg, conn->left.id);
|
msg->add_conn.me.id = push_string(&msg, conn->left.id);
|
||||||
msg->add_conn.me.cert = push_string(&msg, conn->left.cert);
|
msg->add_conn.me.cert = push_string(&msg, conn->left.cert);
|
||||||
msg->add_conn.me.address = push_string(&msg, inet_ntoa(conn->left.addr.u.v4.sin_addr));
|
msg->add_conn.me.address = push_string(&msg, inet_ntoa(conn->left.addr.u.v4.sin_addr));
|
||||||
msg->add_conn.me.subnet = push_string(&msg, inet_ntoa(conn->left.subnet.addr.u.v4.sin_addr));
|
msg->add_conn.me.subnet = push_string(&msg, inet_ntoa(conn->left.subnet.addr.u.v4.sin_addr));
|
||||||
msg->add_conn.me.subnet_mask = conn->left.subnet.maskbits;
|
msg->add_conn.me.subnet_mask = conn->left.subnet.maskbits;
|
||||||
|
|
||||||
msg->add_conn.other.id = push_string(&msg, conn->right.id);
|
msg->add_conn.other.id = push_string(&msg, conn->right.id);
|
||||||
msg->add_conn.other.cert = push_string(&msg, conn->right.cert);
|
msg->add_conn.other.cert = push_string(&msg, conn->right.cert);
|
||||||
msg->add_conn.other.address = push_string(&msg, inet_ntoa(conn->right.addr.u.v4.sin_addr));
|
msg->add_conn.other.address = push_string(&msg, inet_ntoa(conn->right.addr.u.v4.sin_addr));
|
||||||
msg->add_conn.other.subnet = push_string(&msg, inet_ntoa(conn->right.subnet.addr.u.v4.sin_addr));
|
msg->add_conn.other.subnet = push_string(&msg, inet_ntoa(conn->right.subnet.addr.u.v4.sin_addr));
|
||||||
msg->add_conn.other.subnet_mask = conn->right.subnet.maskbits;
|
msg->add_conn.other.subnet_mask = conn->right.subnet.maskbits;
|
||||||
|
|
||||||
res = send_stroke_msg(msg);
|
res = send_stroke_msg(msg);
|
||||||
free(msg);
|
free(msg);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
int starter_stroke_del_conn(starter_conn_t *conn)
|
int starter_stroke_del_conn(starter_conn_t *conn)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
int starter_stroke_route_conn(starter_conn_t *conn)
|
int starter_stroke_route_conn(starter_conn_t *conn)
|
||||||
{
|
{
|
||||||
stroke_msg_t *msg = malloc(sizeof(stroke_msg_t));
|
stroke_msg_t *msg = malloc(sizeof(stroke_msg_t));
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
msg->length = sizeof(stroke_msg_t);
|
msg->length = sizeof(stroke_msg_t);
|
||||||
msg->type = STR_INSTALL;
|
msg->type = STR_INSTALL;
|
||||||
msg->install.name = push_string(&msg, connection_name(conn));
|
msg->install.name = push_string(&msg, connection_name(conn));
|
||||||
res = send_stroke_msg(msg);
|
res = send_stroke_msg(msg);
|
||||||
free(msg);
|
free(msg);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
int starter_stroke_initiate_conn(starter_conn_t *conn)
|
int starter_stroke_initiate_conn(starter_conn_t *conn)
|
||||||
{
|
{
|
||||||
stroke_msg_t *msg = malloc(sizeof(stroke_msg_t));
|
stroke_msg_t *msg = malloc(sizeof(stroke_msg_t));
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
msg->length = sizeof(stroke_msg_t);
|
msg->length = sizeof(stroke_msg_t);
|
||||||
msg->type = STR_INITIATE;
|
msg->type = STR_INITIATE;
|
||||||
msg->initiate.name = push_string(&msg, connection_name(conn));
|
msg->initiate.name = push_string(&msg, connection_name(conn));
|
||||||
res = send_stroke_msg(msg);
|
res = send_stroke_msg(msg);
|
||||||
free(msg);
|
free(msg);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user