X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=command.c;h=21131248c29cd894c8bb74cb13801cd54205e066;hp=77908bf09e8fc09b073e48372ff6749a764de118;hb=41c4f81a98b916d134c1dcd4593e1c013041a06b;hpb=93232d81798a269d4e4b6ec73588be5caa3c1e25 diff --git a/command.c b/command.c index 77908bf0..21131248 100644 --- a/command.c +++ b/command.c @@ -43,7 +43,6 @@ extern struct misc_meta_data *mmd; extern struct audio_file_selector selectors[]; extern struct sender senders[]; extern char *user_list; -struct sockaddr_in *in_addr; static void dummy(__a_unused int s) {} @@ -72,14 +71,14 @@ static char *vss_status_tohuman(unsigned int flags) /* * return human readable permission string. Never returns NULL. */ -char *cmd_perms_itohuman(unsigned int perms) +static char *cmd_perms_itohuman(unsigned int perms) { - char *msg = para_malloc(7 * sizeof(char)); + char *msg = para_malloc(5 * sizeof(char)); - msg[0] = perms & DB_READ? 'd' : '-'; - msg[1] = perms & DB_WRITE? 'D' : '-'; - msg[2] = perms & VSS_READ? 'a' : '-'; - msg[3] = perms & VSS_WRITE? 'A' : '-'; + msg[0] = perms & DB_READ? 'a' : '-'; + msg[1] = perms & DB_WRITE? 'A' : '-'; + msg[2] = perms & VSS_READ? 'v' : '-'; + msg[3] = perms & VSS_WRITE? 'V' : '-'; msg[4] = '\0'; return msg; } @@ -102,7 +101,7 @@ static char *vss_get_status_flags(unsigned int flags) /* * compute status bar string. Never returns NULL */ -char *get_sb_string(struct misc_meta_data *nmmd) +static char *get_sb_string(struct misc_meta_data *nmmd) { char *base, *ret; long long unsigned secs = 0, rsecs = 0, percent = 0; @@ -510,20 +509,17 @@ int com_help(int fd, int argc, char **argv) } perms = cmd_perms_itohuman(cmd->perms); ret = send_va_buffer(fd, - "NAME\n\t%s - %s\n" - "SYNOPSIS\n\t para_client %s\n" - "DESCRIPTION\n%s\n" - "HANDLER\n" - "This command is handled by %s.\n\n" - "PERMISSIONS\n" - "Needed privileges for %s: %s\n", + "%s - %s\n\n" + "handler: %s\n" + "permissions: %s\n" + "usage: %s\n\n" + "%s\n", argv[1], cmd->description, - cmd->synopsis, - cmd->help, handler, - argv[1], - perms + perms, + cmd->usage, + cmd->help ); free(perms); free(handler); @@ -730,7 +726,7 @@ static struct server_command *parse_cmd(const char *cmdstr) return get_cmd_ptr(buf, NULL); } -long int para_rand(long unsigned max) +static long int para_rand(long unsigned max) { return (long int) ((max + 0.0) * (random() / (RAND_MAX + 1.0))); } @@ -760,6 +756,37 @@ static void rc4_send(unsigned long len, const unsigned char *indata, RC4(&rc4_send_key, len, indata, outdata); } +/** + * perform user authentication and execute a command + * + * \param fd the file descriptor to send output to + * \param addr socket address info of peer + * + * \return EXIT_SUCCESS or EXIT_FAILURE + * + * Whenever para_server accepts an incoming tcp connection on + * the port it listens on, it forks and the resulting child + * calls this function. + * + * An RSA-based challenge/response is used to authenticate + * the peer. It that authentication succeeds, a random RC4 + * session key is generated and sent back to the peer, + * encrypted with its RSA public key. From this point on, + * all transfers are crypted with this session key. + * + * Next it is checked if the peer supplied a valid server + * command or a command for the audio file selector currently + * in use. If yes, and if the user has sufficient + * permissions to execute that command, the function calls + * the corresponding command handler which does argument + * checking and further processing. + * + * In order to cope with a DOS attacks, a timeout is set up + * which terminates the function if the connection was not + * authenticated when the timeout expires. + * + * \sa alarm(2), rc4(3), crypt.c, crypt.h + */ int handle_connect(int fd, struct sockaddr_in *addr) { int numbytes, ret, argc, use_rc4 = 0; @@ -777,7 +804,6 @@ int handle_connect(int fd, struct sockaddr_in *addr) signal(SIGHUP, SIG_DFL); signal(SIGUSR1, SIG_IGN); - in_addr = addr; challenge_nr = random(); /* send Welcome message */ ret = send_va_buffer(fd, "This is para_server, version "