#include "user_list.h"
#include "server_command_list.h"
+/** commands including options must be shorter than this */
+#define MAX_COMMAND_LEN 4096
+
static RC4_KEY rc4_recv_key;
static RC4_KEY rc4_send_key;
static unsigned char rc4_buf[2 * RC4_KEY_LEN];
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)
{}
}
/* version */
-int com_version(int socket_fd, int argc, __a_unused char **argv)
+int com_version(int fd, int argc, __a_unused char **argv)
{
if (argc != 1)
return -E_COMMAND_SYNTAX;
- return send_buffer(socket_fd, "para_server-" PACKAGE_VERSION ", \""
- CODENAME "\"\n"
- COPYRIGHT "\n"
- "built: " BUILD_DATE "\n"
- SYSTEM ", " CC_VERSION "\n"
- );
+ return send_buffer(fd, VERSION_TEXT("server")
+ "built: " BUILD_DATE "\n"
+ SYSTEM ", " CC_VERSION "\n"
+ );
}
/* sc */
-int com_sc(int socket_fd, int argc, char **argv)
+int com_sc(int fd, int argc, char **argv)
{
char *name = NULL;
int ret, old = 0, count = -1; /* print af change forever */
}
mmd_unlock();
if (name) {
- ret = send_va_buffer(socket_fd, "%s\n", name);
+ ret = send_va_buffer(fd, "%s\n", name);
free(name);
name = NULL;
if (ret < 0)
}
/* sb */
-int com_sb(int socket_fd, int argc, char **argv)
+int com_sb(int fd, int argc, char **argv)
{
char *sb;
int ret, nr = -1; /* status bar will be printed that many
mmd_lock();
sb = get_sb_string(mmd);
mmd_unlock();
- ret = send_va_buffer(socket_fd, "%s\n", sb);
+ ret = send_va_buffer(fd, "%s\n", sb);
free(sb);
if (ret < 0)
return ret;
}
/* stat */
-int com_stat(int socket_fd, int argc, char **argv)
+int com_stat(int fd, int argc, char **argv)
{
int ret, num = 0;/* status will be printed that many
* times. num <= 0 means: print forever
mmd_dup(nmmd);
s = get_status(nmmd);
- ret = send_buffer(socket_fd, s);
+ ret = send_buffer(fd, s);
free(s);
if (ret < 0)
goto out;
}
/* hup */
-int com_hup(__a_unused int socket_fd, int argc, __a_unused char **argv)
+int com_hup(__a_unused int fd, int argc, __a_unused char **argv)
{
if (argc != 1)
return -E_COMMAND_SYNTAX;
}
/* term */
-int com_term(__a_unused int socket_fd, int argc, __a_unused char **argv)
+int com_term(__a_unused int fd, int argc, __a_unused char **argv)
{
if (argc != 1)
return -E_COMMAND_SYNTAX;
return 1;
}
-int com_play(__a_unused int socket_fd, int argc, __a_unused char **argv)
+int com_play(__a_unused int fd, int argc, __a_unused char **argv)
{
if (argc != 1)
return -E_COMMAND_SYNTAX;
}
/* stop */
-int com_stop(__a_unused int socket_fd, int argc, __a_unused char **argv)
+int com_stop(__a_unused int fd, int argc, __a_unused char **argv)
{
if (argc != 1)
return -E_COMMAND_SYNTAX;
}
/* pause */
-int com_pause(__a_unused int socket_fd, int argc, __a_unused char **argv)
+int com_pause(__a_unused int fd, int argc, __a_unused char **argv)
{
if (argc != 1)
return -E_COMMAND_SYNTAX;
}
/* next */
-int com_next(__a_unused int socket_fd, int argc, __a_unused char **argv)
+int com_next(__a_unused int fd, int argc, __a_unused char **argv)
{
if (argc != 1)
return -E_COMMAND_SYNTAX;
}
/* nomore */
-int com_nomore(__a_unused int socket_fd, int argc, __a_unused char **argv)
+int com_nomore(__a_unused int fd, int argc, __a_unused char **argv)
{
if (argc != 1)
return -E_COMMAND_SYNTAX;
}
/* ff */
-int com_ff(__a_unused int socket_fd, int argc, char **argv)
+int com_ff(__a_unused int fd, int argc, char **argv)
{
long promille;
int ret, backwards = 0;
}
/* jmp */
-int com_jmp(__a_unused int socket_fd, int argc, char **argv)
+int com_jmp(__a_unused int fd, int argc, char **argv)
{
long unsigned int i;
int ret;
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;
- char buf[STRINGSIZE];
+ char buf[4096];
unsigned char crypt_buf[MAXLINE];
struct user u;
struct server_command *cmd = NULL;
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 "
while ((numbytes = recv_buffer(fd, buf, sizeof(buf))) > 0) {
// PARA_INFO_LOG("recvd: %s (%d)\n", buf, numbytes);
ret = -E_COMMAND_SYNTAX;
- if (command && numbytes + strlen(command) > STRINGSIZE) /* DOS */
+ if (command && numbytes + strlen(command) > MAX_COMMAND_LEN) /* DOS */
goto err_out;
command = para_strcat(command, buf);
if ((p = strstr(command, EOC_MSG))) {