va_end(argp);
}
-/* audioc does not use encryption */
-void (*crypt_function_recv)(unsigned long len, const unsigned char *indata, unsigned char *outdata) = NULL;
-void (*crypt_function_send)(unsigned long len, const unsigned char *indata, unsigned char *outdata) = NULL;
-
static char *concat_args(const int argc, char * const *argv)
{
int i; char *buf = NULL;
RC4(&pcd->rc4_recv_key, len, indata, outdata);
}
-void (*crypt_function_recv)(unsigned long len, const unsigned char *indata, unsigned char *outdata);
-void (*crypt_function_send)(unsigned long len, const unsigned char *indata, unsigned char *outdata);
-
-
static void append_str(char **data, const char* append)
{
if (*data) {
/* concat args */
for (i = 0; i < pcd->conf.inputs_num; i++)
append_str(&command, pcd->conf.inputs[i]);
- crypt_function_recv = NULL;
- crypt_function_send = NULL;
/* get the host info */
PARA_NOTICE_LOG("getting host info of %s\n",
pcd->conf.hostname_arg);
goto out;
RC4_set_key(&pcd->rc4_send_key, RC4_KEY_LEN, rc4_buf);
RC4_set_key(&pcd->rc4_recv_key, RC4_KEY_LEN, rc4_buf + RC4_KEY_LEN);
- PARA_INFO_LOG("rc4 encrytion activated: %x:%x:%x:%x\n",
+ PARA_INFO_LOG("rc4 encryption activated: %x:%x:%x:%x\n",
rc4_buf[0], rc4_buf[1], rc4_buf[2], rc4_buf[3]);
- crypt_function_recv = rc4_recv;
- crypt_function_send = rc4_send;
+ enable_crypt(pcd->fd, rc4_recv, rc4_send);
}
/* send command */
PARA_INFO_LOG("--> %s\n", command);
#include "daemon.h"
#include "string.h"
-void (*crypt_function_recv)(unsigned long len, const unsigned char *indata,
- unsigned char *outdata) = NULL;
-void (*crypt_function_send)(unsigned long len, const unsigned char *indata,
- unsigned char *outdata) = NULL;
static RC4_KEY rc4_recv_key;
static RC4_KEY rc4_send_key;
static unsigned char rc4_buf[2 * RC4_KEY_LEN];
ret = send_bin_buffer(fd, buf, numbytes);
if (ret < 0)
goto err_out;
- if (use_rc4) {
- crypt_function_recv = rc4_recv;
- crypt_function_send = rc4_send;
- PARA_INFO_LOG("%s", "rc4 encryption activated\n");
- }
+ if (use_rc4)
+ enable_crypt(fd, rc4_recv, rc4_send);
/* read command */
while ((numbytes = recv_buffer(fd, buf, sizeof(buf))) > 0) {
// PARA_INFO_LOG("recvd: %s (%d)\n", buf, numbytes);
#include "string.h"
#include "error.h"
-extern void (*crypt_function_recv)(unsigned long len, const unsigned char *indata, unsigned char *outdata);
-extern void (*crypt_function_send)(unsigned long len, const unsigned char *indata, unsigned char *outdata);
+static crypt_function **crypt_functions;
+static unsigned max_crypt_fd;
+
+void enable_crypt(int fd, crypt_function *recv, crypt_function *send)
+{
+ if (max_crypt_fd < fd) {
+ crypt_functions = para_realloc(crypt_functions,
+ 2 * (fd + 1) * sizeof(crypt_function*));
+ max_crypt_fd = fd;
+ }
+ crypt_functions[2 * fd] = recv;
+ crypt_functions[2 * fd + 1] = send;
+ PARA_INFO_LOG("rc4 encryption activated for fd %d\n", fd);
+}
+
+void disable_crypt(int fd)
+{
+ crypt_functions[2 * fd] = NULL;
+ crypt_functions[2 * fd + 1] = NULL;
+}
/**
int send_bin_buffer(int fd, const char *buf, size_t len)
{
int ret;
+ crypt_function *cf = NULL;
+
+ if (fd <= max_crypt_fd)
+ cf = crypt_functions[2 * fd + 1];
if (!len)
PARA_CRIT_LOG("%s", "len == 0\n");
- if (crypt_function_send) {
+ if (cf) {
unsigned char *outbuf = para_malloc(len);
- crypt_function_send(len, (unsigned char *)buf, outbuf);
+ (*cf)(len, (unsigned char *)buf, outbuf);
ret = sendall(fd, (char *)outbuf, &len);
free(outbuf);
} else
__must_check int recv_bin_buffer(int fd, char *buf, ssize_t size)
{
int n;
+ crypt_function *cf = NULL;
- if (crypt_function_recv) {
+ if (fd <= max_crypt_fd)
+ cf = crypt_functions[2 * fd];
+ if (cf) {
unsigned char *tmp = para_malloc(size);
n = recv(fd, tmp, size, 0);
if (n > 0)
- crypt_function_recv(n, tmp, (unsigned char *)buf);
+ (*cf)(n, tmp, (unsigned char *)buf);
free(tmp);
} else
n = recv(fd, buf, size, 0);
#define UNIX_PATH_MAX 108
#endif
+typedef void crypt_function(unsigned long len,
+ const unsigned char *indata, unsigned char *outdata);
+
#include <netdb.h> /* hostent */
int get_host_info(char *host, struct hostent **ret);
int get_socket(void);
ssize_t send_cred_buffer(int, char*);
int recv_pattern(int fd, const char *pattern, size_t bufsize);
int init_tcp_socket(int port);
+void enable_crypt(int fd, crypt_function *recv, crypt_function *send);
+void disable_crypt(int fd);
#include "recv.h"
#include "string.h"
-void (*crypt_function_recv)(unsigned long len, const unsigned char *indata, unsigned char *outdata) = NULL;
-void (*crypt_function_send)(unsigned long len, const unsigned char *indata, unsigned char *outdata) = NULL;
-
DEFINE_RECEIVER_ARRAY;
static void *parse_receiver_args(int receiver_num, char *options)
{