X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=command.c;h=481fd0f637352fb21ff97536d426ece42ec0fda3;hp=a72a524fa179e605e152adc32b6a37305162b70f;hb=0c7c4d80673854527ce3c3786dd581169565b5e6;hpb=0ce0301d8184fcebb1aafda396d6a9ae71bf1301 diff --git a/command.c b/command.c index a72a524f..481fd0f6 100644 --- a/command.c +++ b/command.c @@ -16,18 +16,19 @@ #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" @@ -278,7 +279,7 @@ static int check_sender_args(struct command_context *cc, } /** - * 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. @@ -552,63 +553,35 @@ out: } 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]; + static char result[80]; + unsigned perms = server_command_perms[cmd_num]; - 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 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); @@ -687,12 +660,10 @@ static int com_nomore(__a_unused struct command_context *cc, } 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; - unsigned i; + int i, ret; char c, *errctx; ret = lls(lls_check_arg_count(lpr, 1, 1, &errctx)); @@ -700,19 +671,33 @@ static int com_ff(__a_unused struct command_context *cc, send_errctx(cc, errctx); return ret; } - if (!(ret = sscanf(lls_input(0, lpr), "%u%c", &i, &c))) - return -E_COMMAND_SYNTAX; - if (ret > 1 && c == '-') - backwards = 1; /* jmp backwards */ + ret = para_atoi32(lls_input(0, lpr), &i); + if (ret < 0) { + if (ret != -E_ATOI_JUNK_AT_END) + return ret; + /* + * Compatibility code to keep the historic syntax (ff 30-) + * working. This can be removed after 0.7.0. + */ + ret = sscanf(lls_input(0, lpr), "%i%c", &i, &c); + if (ret <= 0) + return -E_COMMAND_SYNTAX; + if (ret > 1 && c == '-') { + PARA_WARNING_LOG("use of obsolete syntax\n"); + i = -i; + } + } mutex_lock(mmd_mutex); 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; - else - promille += 1000 * i / mmd->afd.afhi.seconds_total; + /* + * We need this cast because without it the expression on the right + * hand side is of unsigned type. + */ + promille += 1000 * i / (int)mmd->afd.afhi.seconds_total; if (promille < 0) promille = 0; if (promille > 1000) { @@ -723,15 +708,13 @@ static int com_ff(__a_unused struct command_context *cc, 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; @@ -784,7 +767,7 @@ struct connection_features { int dummy; /* none at the moment */ }; -static int parse_auth_request(char *buf, int len, struct user **u, +static int parse_auth_request(char *buf, int len, const struct user **u, struct connection_features *cf) { int ret; @@ -818,7 +801,7 @@ static int parse_auth_request(char *buf, int len, struct user **u, } } PARA_DEBUG_LOG("received auth request for user %s\n", username); - *u = lookup_user(username); + *u = user_list_lookup(username); ret = 1; out: free_argv(features); @@ -900,12 +883,14 @@ static int run_command(struct command_context *cc, struct iovec *iov) * the function if the connection was not authenticated when the timeout * expires. * - * \sa alarm(2), \ref crypt.c, \ref crypt.h. + * \return Standard. + * + * \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; @@ -935,7 +920,7 @@ int handle_connect(int fd) 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; @@ -950,7 +935,7 @@ int handle_connect(int fd) 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) @@ -966,21 +951,21 @@ int handle_connect(int fd) 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)