#include "server.lsg.h"
#include "para.h"
#include "error.h"
+#include "lsu.h"
#include "crypt.h"
#include "sideband.h"
#include "command.h"
#include "string.h"
#include "afh.h"
#include "afs.h"
+#include "net.h"
#include "server.h"
#include "list.h"
#include "send.h"
#include "sched.h"
#include "vss.h"
-#include "net.h"
#include "daemon.h"
#include "fd.h"
#include "ipc.h"
}
/**
- * Send a sideband packet through a blocking file descriptor.
+ * Receive a sideband packet from a blocking file descriptor.
*
* \param scc fd and crypto keys.
* \param expected_band The expected band designator.
}
EXPORT_SERVER_CMD_HANDLER(stat);
-/* fixed-length, human readable permission string */
-const char *server_cmd_perms_str(unsigned int perms)
+const char *aux_info_cb(unsigned cmd_num, bool verbose)
{
- static char result[5];
-
- result[0] = perms & AFS_READ? 'a' : '-';
- result[1] = perms & AFS_WRITE? 'A' : '-';
- result[2] = perms & VSS_READ? 'v' : '-';
- result[3] = perms & VSS_WRITE? 'V' : '-';
- result[4] = '\0';
- return result;
-}
+ static char result[80];
+ unsigned perms = server_command_perms[cmd_num];
-static int send_list_of_commands(struct command_context *cc)
-{
- int i;
- const struct lls_command *cmd;
- char *msg = para_strdup("");
-
- for (i = 1; (cmd = lls_cmd(i, server_cmd_suite)); i++) {
- const char *perms = server_cmd_perms_str(server_command_perms[i]);
- char *tmp = make_message("%s%s\t%s\t%s\n", msg,
- lls_command_name(cmd), perms, lls_purpose(cmd));
- free(msg);
- msg = tmp;
+ if (verbose) {
+ /* permissions: VSS_READ | VSS_WRITE */
+ sprintf(result, "permissions: %s",
+ server_command_perms_txt[cmd_num]);
+ } else {
+ result[0] = perms & AFS_READ? 'a' : '-';
+ result[1] = perms & AFS_WRITE? 'A' : '-';
+ result[2] = perms & VSS_READ? 'v' : '-';
+ result[3] = perms & VSS_WRITE? 'V' : '-';
+ result[4] = '\0';
}
- return send_sb(&cc->scc, msg, strlen(msg), SBD_OUTPUT, false);
+ return result;
}
static int com_help(struct command_context *cc, struct lls_parse_result *lpr)
{
- const char *perms;
- char *long_help, *buf, *errctx;
+ char *buf;
int ret;
- const struct lls_command *cmd;
+ unsigned n;
+ bool long_help = SERVER_CMD_OPT_GIVEN(HELP, LONG, lpr);
- ret = lls(lls_check_arg_count(lpr, 0, 1, &errctx));
- if (ret < 0) {
- send_errctx(cc, errctx);
- return ret;
- }
- if (lls_num_inputs(lpr) == 0)
- return send_list_of_commands(cc);
- /* argument given for help */
- ret = lls(lls_lookup_subcmd(lls_input(0, lpr), server_cmd_suite,
- &errctx));
- if (ret < 0) {
- send_errctx(cc, errctx);
- return ret;
- }
- cmd = lls_cmd(ret, server_cmd_suite);
- perms = server_command_perms_txt[ret];
- long_help = lls_long_help(cmd);
- assert(long_help);
- ret = xasprintf(&buf, "%spermissions: %s\n", long_help, perms);
- free(long_help);
- return send_sb(&cc->scc, buf, ret, SBD_OUTPUT, false);
+ lsu_com_help(long_help, lpr, server_cmd_suite, aux_info_cb, &buf, &n);
+ ret = send_sb(&cc->scc, buf, n, SBD_OUTPUT, false);
+ return ret;
}
EXPORT_SERVER_CMD_HANDLER(help);
}
EXPORT_SERVER_CMD_HANDLER(nomore);
-static int com_ff(__a_unused struct command_context *cc,
- struct lls_parse_result *lpr)
+static int com_ff(struct command_context *cc, struct lls_parse_result *lpr)
{
long promille;
int ret, backwards = 0;
ret = -E_NO_AUDIO_FILE;
if (!mmd->afd.afhi.chunks_total || !mmd->afd.afhi.seconds_total)
goto out;
+ ret = 1;
promille = (1000 * mmd->current_chunk) / mmd->afd.afhi.chunks_total;
if (backwards)
promille -= 1000 * i / mmd->afd.afhi.seconds_total;
mmd->new_vss_status_flags |= VSS_REPOS;
mmd->new_vss_status_flags &= ~VSS_NEXT;
mmd->events++;
- ret = 1;
out:
mutex_unlock(mmd_mutex);
return ret;
}
EXPORT_SERVER_CMD_HANDLER(ff);
-static int com_jmp(__a_unused struct command_context *cc,
- struct lls_parse_result *lpr)
+static int com_jmp(struct command_context *cc, struct lls_parse_result *lpr)
{
long unsigned int i;
int ret;
*
* \return Standard.
*
- * \sa alarm(2), \ref crypt.c, \ref crypt.h.
+ * \sa alarm(2), \ref openssl.c, \ref crypt.h.
*/
int handle_connect(int fd)
{
int ret;
- unsigned char rand_buf[CHALLENGE_SIZE + 2 * SESSION_KEY_LEN];
+ unsigned char rand_buf[APC_CHALLENGE_SIZE + 2 * SESSION_KEY_LEN];
unsigned char challenge_hash[HASH_SIZE];
char *command = NULL, *buf = para_malloc(HANDSHAKE_BUFSIZE) /* must be on the heap */;
size_t numbytes;
goto net_err;
if (cc->u) {
get_random_bytes_or_die(rand_buf, sizeof(rand_buf));
- ret = pub_encrypt(cc->u->pubkey, rand_buf, sizeof(rand_buf),
+ ret = apc_pub_encrypt(cc->u->pubkey, rand_buf, sizeof(rand_buf),
(unsigned char *)buf);
if (ret < 0)
goto net_err;
get_random_bytes_or_die((unsigned char *)buf, numbytes);
}
PARA_DEBUG_LOG("sending %d byte challenge + session key (%zu bytes)\n",
- CHALLENGE_SIZE, numbytes);
+ APC_CHALLENGE_SIZE, numbytes);
ret = send_sb(&cc->scc, buf, numbytes, SBD_CHALLENGE, false);
buf = NULL;
if (ret < 0)
if (!cc->u)
goto net_err;
/*
- * The correct response is the hash of the first CHALLENGE_SIZE bytes
+ * The correct response is the hash of the first APC_CHALLENGE_SIZE bytes
* of the random data.
*/
ret = -E_BAD_AUTH;
if (numbytes != HASH_SIZE)
goto net_err;
- hash_function((char *)rand_buf, CHALLENGE_SIZE, challenge_hash);
+ hash_function((char *)rand_buf, APC_CHALLENGE_SIZE, challenge_hash);
if (memcmp(challenge_hash, buf, HASH_SIZE))
goto net_err;
/* auth successful */
alarm(0);
PARA_INFO_LOG("good auth for %s\n", cc->u->name);
/* init stream cipher keys with the second part of the random buffer */
- cc->scc.recv = sc_new(rand_buf + CHALLENGE_SIZE, SESSION_KEY_LEN);
- cc->scc.send = sc_new(rand_buf + CHALLENGE_SIZE + SESSION_KEY_LEN,
+ cc->scc.recv = sc_new(rand_buf + APC_CHALLENGE_SIZE, SESSION_KEY_LEN);
+ cc->scc.send = sc_new(rand_buf + APC_CHALLENGE_SIZE + SESSION_KEY_LEN,
SESSION_KEY_LEN);
ret = send_sb(&cc->scc, NULL, 0, SBD_PROCEED, false);
if (ret < 0)