/* we need a blocking fd here as recv() might return EAGAIN otherwise. */
ret = mark_fd_blocking(fd);
if (ret < 0)
- goto err_out;
+ goto net_err;
/* send Welcome message */
ret = send_va_buffer(fd, "This is para_server, version "
PACKAGE_VERSION ".\n" );
if (ret < 0)
- goto err_out;
+ goto net_err;
/* recv auth request line */
ret = recv_buffer(fd, buf, sizeof(buf));
if (ret < 0)
- goto err_out;
+ goto net_err;
if (ret < 10) {
ret = -E_AUTH_REQUEST;
- goto err_out;
+ goto net_err;
}
numbytes = ret;
ret = -E_AUTH_REQUEST;
if (strncmp(buf, AUTH_REQUEST_MSG, strlen(AUTH_REQUEST_MSG)))
- goto err_out;
+ goto net_err;
p = buf + strlen(AUTH_REQUEST_MSG);
PARA_DEBUG_LOG("received auth request for user %s\n", p);
ret = -E_BAD_USER;
ret = para_encrypt_buffer(u->rsa, rand_buf, sizeof(rand_buf),
(unsigned char *)buf);
if (ret < 0)
- goto err_out;
+ goto net_err;
numbytes = ret;
} else {
/*
return ret < 0? -E_ENCRYPT : ret;
}
+#define RC4_ALIGN 8
+
/**
* Encrypt and send a buffer.
*
{
int ret;
unsigned char *tmp;
+ static unsigned char remainder[RC4_ALIGN];
+ size_t l1 = ROUND_DOWN(len, RC4_ALIGN), l2 = ROUND_UP(len, RC4_ALIGN);
assert(len);
- tmp = para_malloc(len + 8);
- RC4(&rc4c->send_key, len, (const unsigned char *)buf, tmp);
+ tmp = para_malloc(l2);
+ RC4(&rc4c->send_key, l1, (const unsigned char *)buf, tmp);
+ if (len > l1) {
+ memcpy(remainder, buf + l1, len - l1);
+ RC4(&rc4c->send_key, len - l1, remainder, tmp + l1);
+ }
ret = write_all(rc4c->fd, (char *)tmp, &len);
free(tmp);
return ret;
return ((max + 0.0) * (random() / (RAND_MAX + 1.0)));
}
+/** Round up x to next multiple of y. */
+#define ROUND_UP(x, y) ({ \
+ const typeof(y) _divisor = y; \
+ ((x) + _divisor - 1) / _divisor * _divisor; })
+
+/** Round down x to multiple of y. */
+#define ROUND_DOWN(x, y) ({ \
+ const typeof(y) _divisor = y; \
+ (x) / _divisor * _divisor; })
+
/** Divide and round up to next integer. */
#define DIV_ROUND_UP(x, y) ({ \
typeof(y) _divisor = y; \
*/
static int score_compare(const struct osl_object *obj1, const struct osl_object *obj2)
{
- int d1 = *(int*)obj1->data;
- int d2 = *(int*)obj2->data;
+ long d1 = *(long *)obj1->data;
+ long d2 = *(long *)obj2->data;
int ret = NUM_COMPARE(d2, d1);
if (ret)
size = score_table_desc.column_descriptions[SCORECOL_SCORE].data_size;
score_objs[SCORECOL_SCORE].data = para_malloc(size);
score_objs[SCORECOL_SCORE].size = size;
- *(int *)(score_objs[SCORECOL_SCORE].data) = score;
+ *(long *)(score_objs[SCORECOL_SCORE].data) = score;
// PARA_DEBUG_LOG("adding %p\n", *(void **) (score_objs[SCORECOL_AFT_ROW].data));
ret = osl(osl_add_row(score_table, score_objs));