* Result handler for sending data to the para_client process.
*
* \param result The data to be sent.
- * \param private Pointer to rc4 context.
+ * \param private Pointer to the context.
*
- * \return The return value of the underlying call to rc4_send_bin_buffer().
+ * \return The return value of the underlying call to sc_send_bin_buffer().
*
- * \sa \ref callback_result_handler, \ref rc4_send_bin_buffer().
+ * \sa \ref callback_result_handler, \ref sc_send_bin_buffer().
*/
-int rc4_send_result(struct osl_object *result, void *private)
+int sc_send_result(struct osl_object *result, void *private)
{
- struct rc4_context *rc4c = private;
+ struct stream_cipher_context *scc = private;
if (!result->size)
return 1;
- return rc4_send_bin_buffer(rc4c, result->data, result->size);
+ return sc_send_bin_buffer(scc, result->data, result->size);
}
-int com_select(struct rc4_context *rc4c, int argc, char * const * const argv)
+int com_select(struct stream_cipher_context *scc, int argc, char * const * const argv)
{
struct osl_object query;
query.data = argv[1];
query.size = strlen(argv[1]) + 1;
return send_callback_request(com_select_callback, &query,
- &rc4_send_result, rc4c);
+ &sc_send_result, scc);
}
static void init_admissible_files(char *arg)
free(pb.buf);
}
-int com_init(struct rc4_context *rc4c, int argc, char * const * const argv)
+int com_init(struct stream_cipher_context *scc, int argc, char * const * const argv)
{
int i, j, ret;
uint32_t table_mask = (1 << (NUM_AFS_TABLES + 1)) - 1;
}
}
ret = send_callback_request(create_tables_callback, &query,
- rc4_send_result, rc4c);
+ sc_send_result, scc);
if (ret < 0)
- return rc4_send_va_buffer(rc4c, "%s\n", para_strerror(-ret));
+ return sc_send_va_buffer(scc, "%s\n", para_strerror(-ret));
return ret;
}
CHECK_PLAYLISTS = 4
};
-int com_check(struct rc4_context *rc4c, int argc, char * const * const argv)
+int com_check(struct stream_cipher_context *scc, int argc, char * const * const argv)
{
unsigned flags = 0;
int i, ret;
flags = ~0U;
if (flags & CHECK_AFT) {
ret = send_callback_request(aft_check_callback, NULL,
- rc4_send_result, rc4c);
+ sc_send_result, scc);
if (ret < 0)
return ret;
}
if (flags & CHECK_PLAYLISTS) {
ret = send_callback_request(playlist_check_callback,
- NULL, rc4_send_result, rc4c);
+ NULL, sc_send_result, scc);
if (ret < 0)
return ret;
}
if (flags & CHECK_MOODS) {
ret = send_callback_request(mood_check_callback, NULL,
- rc4_send_result, rc4c);
+ sc_send_result, scc);
if (ret < 0)
return ret;
}
---
T: add
N: add@member@
-O: int com_add@member@(struct rc4_context *rc4c, int argc, char * const * const argv);
+O: int com_add@member@(struct stream_cipher_context *scc, int argc, char * const * const argv);
P: AFS_READ | AFS_WRITE
D: Read data from stdin and add it as a blob to the @member@ table.
U: add@member@ @member@_name
---
T: cat
N: cat@member@
-O: int com_cat@member@(struct rc4_context *rc4c, int argc, char * const * const argv);
+O: int com_cat@member@(struct stream_cipher_context *scc, int argc, char * const * const argv);
P: AFS_READ
D: Dump the contents of a blob of type @member@ to stdout.
U: cat@member@ @member@_name
---
T: ls
N: ls@member@
-O: int com_ls@member@(struct rc4_context *rc4c, int argc, char * const * const argv);
+O: int com_ls@member@(struct stream_cipher_context *scc, int argc, char * const * const argv);
P: AFS_READ
D: List blobs of type @member@ matching a pattern.
U: ls@member@ [-i] [-l] [-r] [pattern]
---
T: rm
N: rm@member@
-O: int com_rm@member@(struct rc4_context *rc4c, int argc, char * const * const argv);
+O: int com_rm@member@(struct stream_cipher_context *scc, int argc, char * const * const argv);
P: AFS_READ | AFS_WRITE
D: Remove blob(s) of type @member@ from the @member@ table.
U: rm@member@ pattern...
---
T: mv
N: mv@member@
-O: int com_mv@member@(struct rc4_context *rc4c, int argc, char * const * const argv);
+O: int com_mv@member@(struct stream_cipher_context *scc, int argc, char * const * const argv);
P: AFS_READ | AFS_WRITE
D: Rename a blob of type @member@.
U: mv@member@ old_@member@_name new_@member@_name
* \sa \ref send_callback_request().
*/
typedef int callback_result_handler(struct osl_object *result, void *private);
-int rc4_send_result(struct osl_object *result, void *private);
+int sc_send_result(struct osl_object *result, void *private);
int pass_buffer_as_shm(char *buf, size_t size, void *fd_ptr);
__noreturn void afs_init(uint32_t cookie, int socket_fd);
/*
* TODO: flags -h (sort by hash)
*/
-int com_ls(struct rc4_context *rc4c, int argc, char * const * const argv)
+int com_ls(struct stream_cipher_context *scc, int argc, char * const * const argv)
{
int i, ret;
unsigned flags = 0;
opts.mode = mode;
opts.num_patterns = argc - i;
ret = send_option_arg_callback_request(&query, opts.num_patterns,
- argv + i, com_ls_callback, rc4_send_result, rc4c);
+ argv + i, com_ls_callback, sc_send_result, scc);
return ret;
}
/** Used by com_add(). */
struct private_add_data {
- /** The socket file descriptor, including rc4 keys. */
- struct rc4_context *rc4c;
+ /** The socket file descriptor, including stream cipher keys. */
+ struct stream_cipher_context *scc;
/** The given add flags. */
uint32_t flags;
};
ret = 1;
if (pb && (pad->flags & ADD_FLAG_LAZY)) { /* lazy is really cheap */
if (pad->flags & ADD_FLAG_VERBOSE)
- send_ret = rc4_send_va_buffer(pad->rc4c,
+ send_ret = sc_send_va_buffer(pad->scc,
"lazy-ignore: %s\n", path);
goto out_free;
}
ret = 1;
if (pb && hs && hs == pb && !(pad->flags & ADD_FLAG_FORCE)) {
if (pad->flags & ADD_FLAG_VERBOSE)
- send_ret = rc4_send_va_buffer(pad->rc4c,
+ send_ret = sc_send_va_buffer(pad->scc,
"%s exists, not forcing update\n", path);
goto out_unmap;
}
munmap(map.data, map.size);
close(fd);
if (pad->flags & ADD_FLAG_VERBOSE) {
- send_ret = rc4_send_va_buffer(pad->rc4c, "adding %s\n", path);
+ send_ret = sc_send_va_buffer(pad->scc, "adding %s\n", path);
if (send_ret < 0)
goto out_free;
}
save_add_callback_buffer(hash, path, afhi_ptr, pad->flags, format_num, &obj);
/* Ask afs to consider this entry for adding. */
- ret = send_callback_request(com_add_callback, &obj, rc4_send_result, pad->rc4c);
+ ret = send_callback_request(com_add_callback, &obj, sc_send_result, pad->scc);
goto out_free;
out_unmap:
munmap(map.data, map.size);
out_free:
if (ret < 0 && send_ret >= 0)
- send_ret = rc4_send_va_buffer(pad->rc4c,
+ send_ret = sc_send_va_buffer(pad->scc,
"failed to add %s (%s)\n", path, para_strerror(-ret));
free(obj.data);
if (afhi_ptr) {
return send_ret;
}
-int com_add(struct rc4_context *rc4c, int argc, char * const * const argv)
+int com_add(struct stream_cipher_context *scc, int argc, char * const * const argv)
{
int i, ret;
- struct private_add_data pad = {.rc4c = rc4c, .flags = 0};
+ struct private_add_data pad = {.scc = scc, .flags = 0};
struct stat statbuf;
for (i = 1; i < argc; i++) {
char *path;
ret = verify_path(argv[i], &path);
if (ret < 0) {
- ret = rc4_send_va_buffer(rc4c, "%s: %s\n", argv[i],
+ ret = sc_send_va_buffer(scc, "%s: %s\n", argv[i],
para_strerror(-ret));
if (ret < 0)
return ret;
}
ret = stat(path, &statbuf);
if (ret < 0) {
- ret = rc4_send_va_buffer(rc4c, "failed to stat %s (%s)\n", path,
+ ret = sc_send_va_buffer(scc, "failed to stat %s (%s)\n", path,
strerror(errno));
free(path);
if (ret < 0)
else
ret = add_one_audio_file(path, &pad);
if (ret < 0) {
- rc4_send_va_buffer(rc4c, "%s: %s\n", path, para_strerror(-ret));
+ sc_send_va_buffer(scc, "%s: %s\n", path, para_strerror(-ret));
free(path);
return ret;
}
free(tad.pb.buf);
}
-int com_touch(struct rc4_context *rc4c, int argc, char * const * const argv)
+int com_touch(struct stream_cipher_context *scc, int argc, char * const * const argv)
{
struct com_touch_options cto = {
.num_played = -1,
if (i >= argc)
return -E_AFT_SYNTAX;
ret = send_option_arg_callback_request(&query, argc - i,
- argv + i, com_touch_callback, rc4_send_result, rc4c);
+ argv + i, com_touch_callback, sc_send_result, scc);
if (ret < 0)
- rc4_send_va_buffer(rc4c, "%s\n", para_strerror(-ret));
+ sc_send_va_buffer(scc, "%s\n", para_strerror(-ret));
return ret;
}
}
/* TODO options: -r (recursive) */
-int com_rm(struct rc4_context *rc4c, int argc, char * const * const argv)
+int com_rm(struct stream_cipher_context *scc, int argc, char * const * const argv)
{
uint32_t flags = 0;
struct osl_object query = {.data = &flags, .size = sizeof(flags)};
if (i >= argc)
return -E_AFT_SYNTAX;
ret = send_option_arg_callback_request(&query, argc - i, argv + i,
- com_rm_callback, rc4_send_result, rc4c);
+ com_rm_callback, sc_send_result, scc);
if (ret < 0)
- rc4_send_va_buffer(rc4c, "%s\n", para_strerror(-ret));
+ sc_send_va_buffer(scc, "%s\n", para_strerror(-ret));
return ret;
}
free(cad.pb.buf);
}
-int com_cpsi(struct rc4_context *rc4c, int argc, char * const * const argv)
+int com_cpsi(struct stream_cipher_context *scc, int argc, char * const * const argv)
{
unsigned flags = 0;
int i, ret;
if (!(flags & ~CPSI_FLAG_VERBOSE)) /* no copy flags given */
flags = ~(unsigned)CPSI_FLAG_VERBOSE | flags;
ret = send_option_arg_callback_request(&options, argc - i, argv + i,
- com_cpsi_callback, rc4_send_result, rc4c);
+ com_cpsi_callback, sc_send_result, scc);
if (ret < 0)
- rc4_send_va_buffer(rc4c, "%s\n", para_strerror(-ret));
+ sc_send_va_buffer(scc, "%s\n", para_strerror(-ret));
return ret;
}
/**
* Get the current afs status items from the afs process and send it using RC4.
*
- * \param rc4c The rc4 context for data encryption.
+ * \param scc The stream cipher context for data encryption.
* \param parser_friendly Whether parser-friendly output format should be used.
*
* As the contents of the afs status items change in time and the command
* is used to pass the status items from the afs process to the command handler
* via a shared memory area and a pipe.
*/
-int send_afs_status(struct rc4_context *rc4c, int parser_friendly)
+int send_afs_status(struct stream_cipher_context *scc, int parser_friendly)
{
struct osl_object query = {.data = &parser_friendly,
.size = sizeof(parser_friendly)};
- return send_callback_request(afs_stat_callback, &query, rc4_send_result, rc4c);
+ return send_callback_request(afs_stat_callback, &query, sc_send_result, scc);
}
/* TODO: optionally fix problems by removing offending rows */
free(laad.pb.buf);
}
-int com_lsatt(struct rc4_context *rc4c, int argc, char * const * const argv)
+int com_lsatt(struct stream_cipher_context *scc, int argc, char * const * const argv)
{
unsigned flags = 0;
struct osl_object options = {.data = &flags, .size = sizeof(flags)};
}
}
ret = send_option_arg_callback_request(&options, argc - i, argv + i,
- com_lsatt_callback, rc4_send_result, rc4c);
+ com_lsatt_callback, sc_send_result, scc);
if (!ret) {
if (argc > 1)
- ret = rc4_send_va_buffer(rc4c, "no matches\n");
+ ret = sc_send_va_buffer(scc, "no matches\n");
} else if (ret < 0)
- rc4_send_va_buffer(rc4c, "%s\n", para_strerror(-ret));
+ sc_send_va_buffer(scc, "%s\n", para_strerror(-ret));
return ret;
}
PARA_NOTICE_LOG("%s\n", para_strerror(-ret));
}
-int com_setatt(__a_unused struct rc4_context *rc4c, int argc, char * const * const argv)
+int com_setatt(__a_unused struct stream_cipher_context *scc, int argc, char * const * const argv)
{
if (argc < 3)
return -E_ATTR_SYNTAX;
free(pb.buf);
}
-int com_addatt(struct rc4_context *rc4c, int argc, char * const * const argv)
+int com_addatt(struct stream_cipher_context *scc, int argc, char * const * const argv)
{
int ret;
if (argc < 2)
return -E_ATTR_SYNTAX;
ret = send_standard_callback_request(argc - 1, argv + 1, com_addatt_callback,
- rc4_send_result, rc4c);
+ sc_send_result, scc);
if (ret < 0)
- rc4_send_va_buffer(rc4c, "%s\n", para_strerror(-ret));
+ sc_send_va_buffer(scc, "%s\n", para_strerror(-ret));
return ret;
}
free(pb.buf);
}
-int com_mvatt(struct rc4_context *rc4c, int argc, char * const * const argv)
+int com_mvatt(struct stream_cipher_context *scc, int argc, char * const * const argv)
{
int ret;
if (argc != 3)
return -E_ATTR_SYNTAX;
ret = send_standard_callback_request(argc - 1, argv + 1, com_mvatt_callback,
- rc4_send_result, rc4c);
+ sc_send_result, scc);
if (ret < 0)
- rc4_send_va_buffer(rc4c, "%s\n", para_strerror(-ret));
+ sc_send_va_buffer(scc, "%s\n", para_strerror(-ret));
return ret;
}
free(raad.pb.buf);
}
-int com_rmatt(struct rc4_context *rc4c, int argc, char * const * const argv)
+int com_rmatt(struct stream_cipher_context *scc, int argc, char * const * const argv)
{
int ret;
if (argc < 2)
return -E_ATTR_SYNTAX;
ret = send_standard_callback_request(argc - 1, argv + 1, com_rmatt_callback,
- rc4_send_result, rc4c);
+ sc_send_result, scc);
if (ret < 0)
- rc4_send_va_buffer(rc4c, "%s\n", para_strerror(-ret));
+ sc_send_va_buffer(scc, "%s\n", para_strerror(-ret));
return ret;
}
free(lbad.pb.buf);
}
-static int com_lsblob(callback_function *f, struct rc4_context *rc4c, int argc, char * const * const argv)
+static int com_lsblob(callback_function *f, struct stream_cipher_context *scc, int argc, char * const * const argv)
{
uint32_t flags = 0;
struct osl_object options = {.data = &flags, .size = sizeof(flags)};
// if (argc > i)
// return -E_BLOB_SYNTAX;
return send_option_arg_callback_request(&options, argc - i,
- argv + i, f, rc4_send_result, rc4c);
+ argv + i, f, sc_send_result, scc);
}
static int cat_blob(struct osl_table *table, struct osl_row *row,
for_each_matching_row(&pmd);
}
-static int com_catblob(callback_function *f, struct rc4_context *rc4c, int argc,
+static int com_catblob(callback_function *f, struct stream_cipher_context *scc, int argc,
char * const * const argv)
{
if (argc < 2)
return -E_BLOB_SYNTAX;
return send_standard_callback_request(argc - 1, argv + 1, f,
- rc4_send_result, rc4c);
+ sc_send_result, scc);
}
/** Used for removing rows from a blob table. */
free(rmbd.pb.buf);
}
-static int com_rmblob(callback_function *f, struct rc4_context *rc4c, int argc,
+static int com_rmblob(callback_function *f, struct stream_cipher_context *scc, int argc,
char * const * const argv)
{
if (argc < 2)
return -E_MOOD_SYNTAX;
return send_option_arg_callback_request(NULL, argc - 1, argv + 1, f,
- rc4_send_result, rc4c);
+ sc_send_result, scc);
}
static void com_addblob_callback(struct osl_table *table, __a_unused int fd,
* write input from fd to dynamically allocated buffer,
* but maximal max_size byte.
*/
-static int fd2buf(struct rc4_context *rc4c, unsigned max_size, struct osl_object *obj)
+static int fd2buf(struct stream_cipher_context *scc, unsigned max_size, struct osl_object *obj)
{
const size_t chunk_size = 1024;
size_t size = 2048, received = 0;
char *buf = para_malloc(size);
for (;;) {
- ret = rc4_recv_bin_buffer(rc4c, buf + received, chunk_size);
+ ret = sc_recv_bin_buffer(scc, buf + received, chunk_size);
if (ret <= 0)
break;
received += ret;
/*
* Read data from a file descriptor, and send it to the afs process.
*
- * \param rc4c crypt context containing the file descriptor to read data from.
+ * \param scc crypt context containing the file descriptor to read data from.
* \param arg_obj Pointer to the arguments to \a f.
* \param f The callback function.
* \param max_len Don't read more than that many bytes from stdin.
* This function is used by commands that wish to let para_server store
* arbitrary data specified by the user (for instance the add_blob family of
* commands). First, at most \a max_len bytes are read and decrypted from the
- * file descriptor given by \a rc4c. The result is concatenated with the buffer
+ * file descriptor given by \a scc. The result is concatenated with the buffer
* given by \a arg_obj, and the combined buffer is made available to the afs
* process via the callback method. See \ref send_callback_request for details.
*
* \return Negative on errors, the return value of the underlying call to
* send_callback_request() otherwise.
*/
-static int stdin_command(struct rc4_context *rc4c, struct osl_object *arg_obj,
+static int stdin_command(struct stream_cipher_context *scc, struct osl_object *arg_obj,
callback_function *f, unsigned max_len,
callback_result_handler *result_handler,
void *private_result_data)
struct osl_object query, stdin_obj;
int ret;
- ret = rc4_send_buffer(rc4c, AWAITING_DATA_MSG);
+ ret = sc_send_buffer(scc, AWAITING_DATA_MSG);
if (ret < 0)
return ret;
- ret = fd2buf(rc4c, max_len, &stdin_obj);
+ ret = fd2buf(scc, max_len, &stdin_obj);
if (ret < 0)
return ret;
query.size = arg_obj->size + stdin_obj.size;
return ret;
}
-static int com_addblob(callback_function *f, struct rc4_context *rc4c, int argc,
+static int com_addblob(callback_function *f, struct stream_cipher_context *scc, int argc,
char * const * const argv)
{
struct osl_object arg_obj;
return -E_BLOB_SYNTAX;
arg_obj.size = strlen(argv[1]) + 1;
arg_obj.data = (char *)argv[1];
- return stdin_command(rc4c, &arg_obj, f, 10 * 1024 * 1024, NULL, NULL);
+ return stdin_command(scc, &arg_obj, f, 10 * 1024 * 1024, NULL, NULL);
}
/* FIXME: Print output to client, not to log file */
PARA_NOTICE_LOG("%s\n", para_strerror(-ret));
}
-static int com_mvblob(callback_function *f, __a_unused struct rc4_context *rc4c,
+static int com_mvblob(callback_function *f, __a_unused struct stream_cipher_context *scc,
int argc, char * const * const argv)
{
if (argc != 3)
{ \
return com_ ## cmd_name ## blob_callback(table_name ## _table, fd, query); \
} \
- int com_ ## cmd_name ## cmd_prefix(struct rc4_context *rc4c, int argc, char * const * const argv) \
+ int com_ ## cmd_name ## cmd_prefix(struct stream_cipher_context *scc, int argc, char * const * const argv) \
{ \
- return com_ ## cmd_name ## blob(com_ ## cmd_name ## cmd_prefix ## _callback, rc4c, argc, argv); \
+ return com_ ## cmd_name ## blob(com_ ## cmd_name ## cmd_prefix ## _callback, scc, argc, argv); \
}
static int blob_get_name_by_id(struct osl_table *table, uint32_t id,
struct client_task {
/** The state of the connection. */
int status;
- /** The file descriptor and the rc4 keys. */
- struct rc4_context rc4c;
+ /** The file descriptor and the session keys. */
+ struct stream_cipher_context scc;
/** The configuration (including the command). */
struct client_args_info conf;
/** The config file for client options. */
{
if (!ct)
return;
- if (ct->rc4c.fd >= 0)
- close(ct->rc4c.fd);
- stream_cipher_free(ct->rc4c.recv);
- stream_cipher_free(ct->rc4c.send);
+ if (ct->scc.fd >= 0)
+ close(ct->scc.fd);
+ sc_free(ct->scc.recv);
+ sc_free(ct->scc.send);
free(ct->user);
free(ct->config_file);
free(ct->key_file);
struct client_task *ct = container_of(t, struct client_task, task);
struct btr_node *btrn = ct->btrn;
- if (ct->rc4c.fd < 0)
+ if (ct->scc.fd < 0)
return;
switch (ct->status) {
case CL_CONNECTED:
case CL_SENT_AUTH:
case CL_SENT_CH_RESPONSE:
case CL_SENT_COMMAND:
- para_fd_set(ct->rc4c.fd, &s->rfds, &s->max_fileno);
+ para_fd_set(ct->scc.fd, &s->rfds, &s->max_fileno);
return;
case CL_RECEIVED_WELCOME:
case CL_RECEIVED_PROCEED:
- para_fd_set(ct->rc4c.fd, &s->wfds, &s->max_fileno);
+ para_fd_set(ct->scc.fd, &s->wfds, &s->max_fileno);
return;
case CL_RECEIVING:
if (ret < 0)
sched_min_delay(s);
else
- para_fd_set(ct->rc4c.fd, &s->rfds,
+ para_fd_set(ct->scc.fd, &s->rfds,
&s->max_fileno);
}
return;
if (ret < 0)
sched_min_delay(s);
else
- para_fd_set(ct->rc4c.fd, &s->wfds,
+ para_fd_set(ct->scc.fd, &s->wfds,
&s->max_fileno);
}
return;
int ret;
if (ct->status < CL_SENT_CH_RESPONSE)
- return read_nonblock(ct->rc4c.fd, buf, sz, rfds, n);
+ return read_nonblock(ct->scc.fd, buf, sz, rfds, n);
*n = 0;
- ret = rc4_recv_buffer(&ct->rc4c, buf, sz);
+ ret = sc_recv_buffer(&ct->scc, buf, sz);
/*
- * rc4_recv_buffer is used with blocking fds elsewhere, so it
+ * sc_recv_buffer is used with blocking fds elsewhere, so it
* does not use the nonblock-API. Therefore we need to
* check for EOF and EAGAIN.
*/
char buf[CLIENT_BUFSIZE];
t->error = 0;
- if (ct->rc4c.fd < 0)
+ if (ct->scc.fd < 0)
return;
switch (ct->status) {
case CL_CONNECTED: /* receive welcome message */
case CL_RECEIVED_WELCOME: /* send auth command */
sprintf(buf, AUTH_REQUEST_MSG "%s", ct->user);
PARA_INFO_LOG("--> %s\n", buf);
- if (!FD_ISSET(ct->rc4c.fd, &s->wfds))
+ if (!FD_ISSET(ct->scc.fd, &s->wfds))
return;
- ret = send_buffer(ct->rc4c.fd, buf);
+ ret = send_buffer(ct->scc.fd, buf);
if (ret < 0)
goto out;
ct->status = CL_SENT_AUTH;
return;
case CL_SENT_AUTH:
/*
- * Receive challenge and rc4 keys, decrypt the challenge and
+ * Receive challenge and session keys, decrypt the challenge and
* send back the hash of the decrypted challenge.
*/
{
- /* decrypted challenge/rc4 buffer */
+ /* decrypted challenge/session key buffer */
unsigned char crypt_buf[1024];
/* the SHA1 of the decrypted challenge */
unsigned char challenge_sha1[HASH_SIZE];
if (ret < 0)
goto out;
sha1_hash((char *)crypt_buf, CHALLENGE_SIZE, challenge_sha1);
- ct->rc4c.send = stream_cipher_new(crypt_buf + CHALLENGE_SIZE,
+ ct->scc.send = sc_new(crypt_buf + CHALLENGE_SIZE, RC4_KEY_LEN);
+ ct->scc.recv = sc_new(crypt_buf + CHALLENGE_SIZE + RC4_KEY_LEN,
RC4_KEY_LEN);
- ct->rc4c.recv = stream_cipher_new(crypt_buf + CHALLENGE_SIZE
- + RC4_KEY_LEN, RC4_KEY_LEN);
hash_to_asc(challenge_sha1, buf);
PARA_INFO_LOG("--> %s\n", buf);
- ret = send_bin_buffer(ct->rc4c.fd, (char *)challenge_sha1,
+ ret = send_bin_buffer(ct->scc.fd, (char *)challenge_sha1,
HASH_SIZE);
if (ret < 0)
goto out;
{
int i;
char *command = NULL;
- if (!FD_ISSET(ct->rc4c.fd, &s->wfds))
+ if (!FD_ISSET(ct->scc.fd, &s->wfds))
return;
for (i = 0; i < ct->conf.inputs_num; i++) {
char *tmp = command;
}
command = para_strcat(command, EOC_MSG "\n");
PARA_DEBUG_LOG("--> %s\n", command);
- ret = rc4_send_buffer(&ct->rc4c, command);
+ ret = sc_send_buffer(&ct->scc, command);
free(command);
if (ret < 0)
goto out;
goto out;
if (ret == 0)
return;
- if (!FD_ISSET(ct->rc4c.fd, &s->wfds))
+ if (!FD_ISSET(ct->scc.fd, &s->wfds))
return;
sz = btr_next_buffer(btrn, &buf2);
- ret = rc4_send_bin_buffer(&ct->rc4c, buf2, sz);
+ ret = sc_send_bin_buffer(&ct->scc, buf2, sz);
if (ret < 0)
goto out;
btr_consume(btrn, sz);
* The FD_ISSET() is not strictly necessary, but is allows us
* to skip the malloc below if there is nothing to read anyway.
*/
- if (!FD_ISSET(ct->rc4c.fd, &s->rfds))
+ if (!FD_ISSET(ct->scc.fd, &s->rfds))
return;
buf2 = para_malloc(CLIENT_BUFSIZE);
ret = client_recv_buffer(ct, &s->rfds, buf2, CLIENT_BUFSIZE, &n);
{
int ret;
- ct->rc4c.fd = -1;
+ ct->scc.fd = -1;
ret = para_connect_simple(IPPROTO_TCP, ct->conf.hostname_arg,
ct->conf.server_port_arg);
if (ret < 0)
return ret;
- ct->rc4c.fd = ret;
+ ct->scc.fd = ret;
ct->status = CL_CONNECTED;
- ret = mark_fd_nonblocking(ct->rc4c.fd);
+ ret = mark_fd_nonblocking(ct->scc.fd);
if (ret < 0)
goto err_out;
ct->task.pre_select = client_pre_select;
register_task(&ct->task);
return 1;
err_out:
- close(ct->rc4c.fd);
- ct->rc4c.fd = -1;
+ close(ct->scc.fd);
+ ct->scc.fd = -1;
return ret;
}
ct->btrn = btr_new_node(&(struct btr_node_description)
EMBRACE(.name = "client", .parent = parent, .child = child));
*ct_ptr = ct;
- ct->rc4c.fd = -1;
+ ct->scc.fd = -1;
ret = -E_CLIENT_SYNTAX;
if (client_cmdline_parser(argc, argv, &ct->conf))
goto out;
extern int mmd_mutex;
extern struct misc_meta_data *mmd;
extern struct sender senders[];
-int send_afs_status(struct rc4_context *rc4c, int parser_friendly);
+int send_afs_status(struct stream_cipher_context *scc, int parser_friendly);
const char *status_item_list[] = {STATUS_ITEM_ARRAY};
return 1;
}
-int com_sender(struct rc4_context *rc4c, int argc, char * const * argv)
+int com_sender(struct stream_cipher_context *scc, int argc, char * const * argv)
{
int i, ret;
char *msg = NULL;
free(msg);
msg = tmp;
}
- ret = rc4_send_buffer(rc4c, msg);
+ ret = sc_send_buffer(scc, msg);
free(msg);
return ret;
}
if (scd.sender_num < 0)
return ret;
msg = senders[scd.sender_num].help();
- ret = rc4_send_buffer(rc4c, msg);
+ ret = sc_send_buffer(scc, msg);
free(msg);
return ret;
}
}
/* server info */
-int com_si(struct rc4_context *rc4c, int argc, __a_unused char * const * argv)
+int com_si(struct stream_cipher_context *scc, int argc, __a_unused char * const * argv)
{
int i, ret;
char *ut;
free(info);
}
ut = uptime_str();
- ret = rc4_send_va_buffer(rc4c, "version: " GIT_VERSION "\n"
+ ret = sc_send_va_buffer(scc, "version: " GIT_VERSION "\n"
"up: %s\nplayed: %u\n"
"server_pid: %d\n"
"afs_pid: %d\n"
}
/* version */
-int com_version(struct rc4_context *rc4c, int argc, __a_unused char * const * argv)
+int com_version(struct stream_cipher_context *scc, int argc, __a_unused char * const * argv)
{
if (argc != 1)
return -E_COMMAND_SYNTAX;
- return rc4_send_buffer(rc4c, VERSION_TEXT("server")
+ return sc_send_buffer(scc, VERSION_TEXT("server")
"built: " BUILD_DATE "\n"
UNAME_RS ", " CC_VERSION "\n"
);
#undef EMPTY_STATUS_ITEMS
/* stat */
-int com_stat(struct rc4_context *rc4c, int argc, char * const * argv)
+int com_stat(struct stream_cipher_context *scc, int argc, char * const * argv)
{
int i, ret;
struct misc_meta_data tmp, *nmmd = &tmp;
for (;;) {
mmd_dup(nmmd);
s = get_status(nmmd, parser_friendly);
- ret = rc4_send_buffer(rc4c, s);
+ ret = sc_send_buffer(scc, s);
free(s);
if (ret < 0)
goto out;
static char *esi;
if (!esi)
esi = empty_status_items(parser_friendly);
- ret = rc4_send_buffer(rc4c, esi);
+ ret = sc_send_buffer(scc, esi);
if (ret < 0)
goto out;
} else
- send_afs_status(rc4c, parser_friendly);
+ send_afs_status(scc, parser_friendly);
ret = 1;
if (num > 0 && !--num)
goto out;
return ret;
}
-static int send_list_of_commands(struct rc4_context *rc4c, struct server_command *cmd,
+static int send_list_of_commands(struct stream_cipher_context *scc, struct server_command *cmd,
const char *handler)
{
int ret, i;
for (i = 1; cmd->name; cmd++, i++) {
char *perms = cmd_perms_itohuman(cmd->perms);
- ret = rc4_send_va_buffer(rc4c, "%s\t%s\t%s\t%s\n", cmd->name,
+ ret = sc_send_va_buffer(scc, "%s\t%s\t%s\t%s\n", cmd->name,
handler,
perms,
cmd->description);
}
/* help */
-int com_help(struct rc4_context *rc4c, int argc, char * const * argv)
+int com_help(struct stream_cipher_context *scc, int argc, char * const * argv)
{
struct server_command *cmd;
char *perms, *handler;
if (argc < 2) {
/* no argument given, print list of commands */
- if ((ret = send_list_of_commands(rc4c, server_cmds, "server")) < 0)
+ if ((ret = send_list_of_commands(scc, server_cmds, "server")) < 0)
return ret;
- return send_list_of_commands(rc4c, afs_cmds, "afs");
+ return send_list_of_commands(scc, afs_cmds, "afs");
}
/* argument given for help */
cmd = get_cmd_ptr(argv[1], &handler);
if (!cmd)
return -E_BAD_CMD;
perms = cmd_perms_itohuman(cmd->perms);
- ret = rc4_send_va_buffer(rc4c,
+ ret = sc_send_va_buffer(scc,
"%s - %s\n\n"
"handler: %s\n"
"permissions: %s\n"
}
/* hup */
-int com_hup(__a_unused struct rc4_context *rc4c, int argc, __a_unused char * const * argv)
+int com_hup(__a_unused struct stream_cipher_context *scc, int argc, __a_unused char * const * argv)
{
if (argc != 1)
return -E_COMMAND_SYNTAX;
}
/* term */
-int com_term(__a_unused struct rc4_context *rc4c, int argc, __a_unused char * const * argv)
+int com_term(__a_unused struct stream_cipher_context *scc, int argc, __a_unused char * const * argv)
{
if (argc != 1)
return -E_COMMAND_SYNTAX;
return 1;
}
-int com_play(__a_unused struct rc4_context *rc4c, int argc, __a_unused char * const * argv)
+int com_play(__a_unused struct stream_cipher_context *scc, int argc, __a_unused char * const * argv)
{
if (argc != 1)
return -E_COMMAND_SYNTAX;
}
/* stop */
-int com_stop(__a_unused struct rc4_context *rc4c, int argc, __a_unused char * const * argv)
+int com_stop(__a_unused struct stream_cipher_context *scc, int argc, __a_unused char * const * argv)
{
if (argc != 1)
return -E_COMMAND_SYNTAX;
}
/* pause */
-int com_pause(__a_unused struct rc4_context *rc4c, int argc, __a_unused char * const * argv)
+int com_pause(__a_unused struct stream_cipher_context *scc, int argc, __a_unused char * const * argv)
{
if (argc != 1)
return -E_COMMAND_SYNTAX;
}
/* next */
-int com_next(__a_unused struct rc4_context *rc4c, int argc, __a_unused char * const * argv)
+int com_next(__a_unused struct stream_cipher_context *scc, int argc, __a_unused char * const * argv)
{
if (argc != 1)
return -E_COMMAND_SYNTAX;
}
/* nomore */
-int com_nomore(__a_unused struct rc4_context *rc4c, int argc, __a_unused char * const * argv)
+int com_nomore(__a_unused struct stream_cipher_context *scc, int argc, __a_unused char * const * argv)
{
if (argc != 1)
return -E_COMMAND_SYNTAX;
}
/* ff */
-int com_ff(__a_unused struct rc4_context *rc4c, int argc, char * const * argv)
+int com_ff(__a_unused struct stream_cipher_context *scc, int argc, char * const * argv)
{
long promille;
int ret, backwards = 0;
}
/* jmp */
-int com_jmp(__a_unused struct rc4_context *rc4c, int argc, char * const * argv)
+int com_jmp(__a_unused struct stream_cipher_context *scc, int argc, char * const * argv)
{
long unsigned int i;
int ret;
return get_cmd_ptr(buf, NULL);
}
-static int read_command(struct rc4_context *rc4c, char **result)
+static int read_command(struct stream_cipher_context *scc, char **result)
{
int ret;
char buf[4096];
size_t numbytes;
char *p;
- ret = rc4_recv_buffer(rc4c, buf, sizeof(buf));
+ ret = sc_recv_buffer(scc, buf, sizeof(buf));
if (ret < 0)
goto out;
if (!ret)
* which terminates the function if the connection was not
* authenticated when the timeout expires.
*
- * \sa alarm(2), rc4(3), crypt.c, crypt.h
+ * \sa alarm(2), crypt.c, crypt.h
*/
__noreturn void handle_connect(int fd, const char *peername)
{
char **argv = NULL;
char *p, *command = NULL;
size_t numbytes;
- struct rc4_context rc4c = {.fd = fd};
+ struct stream_cipher_context scc = {.fd = fd};
reset_signals();
/* we need a blocking fd here as recv() might return EAGAIN otherwise. */
alarm(0);
PARA_INFO_LOG("good auth for %s\n", u->name);
/* init stream cipher keys with the second part of the random buffer */
- rc4c.recv = stream_cipher_new(rand_buf + CHALLENGE_SIZE, RC4_KEY_LEN);
- rc4c.send = stream_cipher_new(rand_buf + CHALLENGE_SIZE + RC4_KEY_LEN,
- RC4_KEY_LEN);
- ret = rc4_send_buffer(&rc4c, PROCEED_MSG);
+ scc.recv = sc_new(rand_buf + CHALLENGE_SIZE, RC4_KEY_LEN);
+ scc.send = sc_new(rand_buf + CHALLENGE_SIZE + RC4_KEY_LEN, RC4_KEY_LEN);
+ ret = sc_send_buffer(&scc, PROCEED_MSG);
if (ret < 0)
goto net_err;
- ret = read_command(&rc4c, &command);
+ ret = read_command(&scc, &command);
if (ret == -E_COMMAND_SYNTAX)
goto err_out;
if (ret < 0)
argc = ret;
PARA_NOTICE_LOG("calling com_%s() for %s@%s\n", cmd->name, u->name,
peername);
- ret = cmd->handler(&rc4c, argc, argv);
+ ret = cmd->handler(&scc, argc, argv);
free_argv(argv);
mutex_lock(mmd_mutex);
mmd->num_commands++;
if (ret >= 0)
goto out;
err_out:
- rc4_send_va_buffer(&rc4c, "%s\n", para_strerror(-ret));
+ sc_send_va_buffer(&scc, "%s\n", para_strerror(-ret));
net_err:
PARA_NOTICE_LOG("%s\n", para_strerror(-ret));
out:
free(command);
- stream_cipher_free(rc4c.recv);
- stream_cipher_free(rc4c.send);
+ sc_free(scc.recv);
+ sc_free(scc.send);
mutex_lock(mmd_mutex);
if (cmd && (cmd->perms & AFS_WRITE) && ret >= 0)
mmd->events++;
/** The name of the command. */
const char *name;
/** Pointer to the function that handles the command. */
- int (*handler)(struct rc4_context *, int, char * const * const);
+ int (*handler)(struct stream_cipher_context *, int, char * const * const);
/** The privileges a user must have to execute this command. */
unsigned int perms;
/** One-line description of the command. */
*
* \return A new stream cipher structure.
*/
-struct stream_cipher *stream_cipher_new(const unsigned char *data, int len)
+struct stream_cipher *sc_new(const unsigned char *data, int len)
{
struct stream_cipher *sc = para_malloc(sizeof(*sc));
RC4_set_key(&sc->key, len, data);
/**
* Deallocate a stream cipher structure.
*
- * \param sc A stream cipher previously obtained by stream_cipher_new().
+ * \param sc A stream cipher previously obtained by sc_new().
*/
-void stream_cipher_free(struct stream_cipher *sc)
+void sc_free(struct stream_cipher *sc)
{
free(sc);
}
/**
* Encrypt and send a buffer.
*
- * \param rc4c The rc4 crypt context.
+ * \param scc The context.
* \param buf The buffer to send.
* \param len The size of \a buf in bytes.
*
*
* \sa \ref write_all(), RC4(3).
*/
-int rc4_send_bin_buffer(struct rc4_context *rc4c, const char *buf, size_t len)
+int sc_send_bin_buffer(struct stream_cipher_context *scc, const char *buf,
+ size_t len)
{
int ret;
unsigned char *tmp;
assert(len);
tmp = para_malloc(l2);
- RC4(&rc4c->send->key, l1, (const unsigned char *)buf, tmp);
+ RC4(&scc->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);
+ RC4(&scc->send->key, len - l1, remainder, tmp + l1);
}
- ret = write_all(rc4c->fd, (char *)tmp, &len);
+ ret = write_all(scc->fd, (char *)tmp, &len);
free(tmp);
return ret;
}
/**
* Encrypt and send a \p NULL-terminated buffer.
*
- * \param rc4c The rc4 crypt context.
+ * \param scc The context.
* \param buf The buffer to send.
*
- * \return The return value of the underyling call to rc4_send_bin_buffer().
+ * \return The return value of the underyling call to sc_send_bin_buffer().
*/
-int rc4_send_buffer(struct rc4_context *rc4c, const char *buf)
+int sc_send_buffer(struct stream_cipher_context *scc, const char *buf)
{
- return rc4_send_bin_buffer(rc4c, buf, strlen(buf));
+ return sc_send_bin_buffer(scc, buf, strlen(buf));
}
/**
* Format, encrypt and send a buffer.
*
- * \param rc4c The rc4 crypt context.
+ * \param scc The context.
* \param fmt A format string.
*
- * \return The return value of the underyling call to rc4_send_buffer().
+ * \return The return value of the underyling call to sc_send_buffer().
*/
-__printf_2_3 int rc4_send_va_buffer(struct rc4_context *rc4c, const char *fmt, ...)
+__printf_2_3 int sc_send_va_buffer(struct stream_cipher_context *scc,
+ const char *fmt, ...)
{
char *msg;
int ret;
PARA_VSPRINTF(fmt, msg);
- ret = rc4_send_buffer(rc4c, msg);
+ ret = sc_send_buffer(scc, msg);
free(msg);
return ret;
}
/**
* Receive a buffer and decrypt it.
*
- * \param rc4c The rc4 crypt context.
+ * \param scc The context.
* \param buf The buffer to write the decrypted data to.
* \param size The size of \a buf.
*
*
* \sa recv(2), RC4(3).
*/
-int rc4_recv_bin_buffer(struct rc4_context *rc4c, char *buf, size_t size)
+int sc_recv_bin_buffer(struct stream_cipher_context *scc, char *buf,
+ size_t size)
{
unsigned char *tmp = para_malloc(size);
- ssize_t ret = recv(rc4c->fd, tmp, size, 0);
+ ssize_t ret = recv(scc->fd, tmp, size, 0);
if (ret > 0)
- RC4(&rc4c->recv->key, ret, tmp, (unsigned char *)buf);
+ RC4(&scc->recv->key, ret, tmp, (unsigned char *)buf);
else if (ret < 0)
ret = -ERRNO_TO_PARA_ERROR(errno);
free(tmp);
/**
* Receive a buffer, decrypt it and write terminating NULL byte.
*
- * \param rc4c The rc4 crypt context.
+ * \param scc The context.
* \param buf The buffer to write the decrypted data to.
* \param size The size of \a buf.
*
- * Read at most \a size - 1 bytes from file descriptor given by \a rc4c,
- * decrypt the received data and write a NULL byte at the end of the decrypted
- * data.
+ * Read at most \a size - 1 bytes from file descriptor given by \a scc, decrypt
+ * the received data and write a NULL byte at the end of the decrypted data.
*
* \return The return value of the underlying call to \ref
- * rc4_recv_bin_buffer().
+ * sc_recv_bin_buffer().
*/
-int rc4_recv_buffer(struct rc4_context *rc4c, char *buf, size_t size)
+int sc_recv_buffer(struct stream_cipher_context *scc, char *buf, size_t size)
{
int n;
assert(size);
- n = rc4_recv_bin_buffer(rc4c, buf, size - 1);
+ n = sc_recv_bin_buffer(scc, buf, size - 1);
if (n >= 0)
buf[n] = '\0';
else
* keys for the stream cipher and the file descriptor for which these keys
* should be used.
*/
-struct rc4_context {
+struct stream_cipher_context {
/** The socket file descriptor. */
int fd;
/** Key used for receiving data. */
struct stream_cipher *send;
};
-struct stream_cipher *stream_cipher_new(const unsigned char *data, int len);
-void stream_cipher_free(struct stream_cipher *sc);
-
-int rc4_send_bin_buffer(struct rc4_context *rc4c, const char *buf, size_t len);
-int rc4_send_buffer(struct rc4_context *rc4c, const char *buf);
-__printf_2_3 int rc4_send_va_buffer(struct rc4_context *rc4c, const char *fmt, ...);
-int rc4_recv_bin_buffer(struct rc4_context *rcc, char *buf, size_t size);
-int rc4_recv_buffer(struct rc4_context *rcc, char *buf, size_t size);
+struct stream_cipher *sc_new(const unsigned char *data, int len);
+void sc_free(struct stream_cipher *sc);
+
+int sc_send_bin_buffer(struct stream_cipher_context *scc, const char *buf,
+ size_t len);
+int sc_send_buffer(struct stream_cipher_context *scc, const char *buf);
+__printf_2_3 int sc_send_va_buffer(struct stream_cipher_context *scc,
+ const char *fmt, ...);
+int sc_recv_bin_buffer(struct stream_cipher_context *scc, char *buf,
+ size_t size);
+int sc_recv_buffer(struct stream_cipher_context *scc, char *buf, size_t size);
/** \cond used to distinguish between loading of private/public key */
#define LOAD_PUBLIC_KEY 0