/** \file command.c does client authentication and executes server commands */
#include <sys/time.h> /* gettimeofday */
-#include "crypt.h"
#include "server.cmdline.h"
#include "db.h"
#include "server.h"
#include "daemon.h"
#include "string.h"
#include "fd.h"
+#include "user_list.h"
static RC4_KEY rc4_recv_key;
static RC4_KEY rc4_send_key;
server_cmdline_objs="server.cmdline"
server_errlist_objs="server mp3_afh afs command net string signal random_selector
time daemon stat crypt http_send db close_on_fork playlist_selector
- ipc dccp dccp_send fd"
+ ipc dccp dccp_send fd user_list"
server_ldflags=""
server_audio_formats=" mp3"
SS_ALSA_WRITE,
SS_FILE_WRITE,
SS_OSX_WRITE,
+ SS_USER_LIST,
NUM_SS
};
/* these do not need error handling (yet) */
+#define SERVER_ERRORS
#define CLIENT_ERRORS
#define WAV_ERRORS
#define COMPRESS_ERRORS
extern const char **para_errlist[];
/** \endcond */
-#define SERVER_ERRORS \
+#define USER_LIST_ERRORS \
PARA_ERROR(USERLIST, "failed to open user list file"), \
PARA_ERROR(BAD_USER, "you don't exist. Go away."), \
SS_ENUM(CLIENT);
SS_ENUM(CLIENT_COMMON);
SS_ENUM(AUDIOC);
+SS_ENUM(USER_LIST);
/** \endcond */
#undef PARA_ERROR
/* rest of the world only sees the error text */
#include "error.h"
#include "net.h"
#include "string.h"
+#include "user_list.h"
/** pointer to the shared memory area */
extern struct misc_meta_data *mmd;
#include "net.h"
#include "string.h"
#include "ipc.h"
+#include "user_list.h"
/**
* structure used for transmission of the playlist
#include "string.h"
#include "ipc.h"
#include "fd.h"
-#include "crypt.h"
+#include "user_list.h"
/** define the array of error lists needed by para_server */
INIT_SERVER_ERRLISTS;
*/
struct server_args_info conf;
char *user_list_file = NULL;
-struct list_head user_list;
extern void dccp_send_init(struct sender *);
extern void http_send_init(struct sender *);
extern void ortp_send_init(struct sender *);
}
}
-/*
- * lookup user in user list file. Fills in a user struct containing
- * filename of the user's public key as well as the permissions of that user.
- * Returns 1 on success, 0 if user does not exist and < 0 on errors.
- */
-static void populate_user_list(void) {
- FILE *file_ptr = NULL;
- char *char_ptr;
- char line[MAXLINE];
- /* keyword, user, key, perms */
- char w[MAXLINE], n[MAXLINE], k[MAXLINE], p[MAXLINE], tmp[4][MAXLINE];
- int num, ret;
-
- file_ptr = fopen(user_list_file, "r");
- ret = -E_USERLIST;
- if (!file_ptr)
- goto out;
- for (;;) {
- struct user *u;
- ret = para_fgets(line, MAXLINE, file_ptr);
- if (ret < 0)
- PARA_ERROR_LOG("%s\n", PARA_STRERROR(-ret));
- if (ret <= 0)
- break;
- if (sscanf(line,"%200s %200s %200s %200s", w, n, k, p) < 3)
- continue;
- if (strcmp(w, "user"))
- continue;
- PARA_DEBUG_LOG("found entry for %s\n", n);
- u = para_malloc(sizeof(struct user));
- u->name = para_strdup(n);
- u->rsa = para_malloc(sizeof(RSA));
- ret = get_rsa_key(k, &u->rsa, LOAD_PUBLIC_KEY);
- if (ret < 0)
- break;
- u->perms = 0;
- char_ptr = p;
- num = sscanf(char_ptr, "%200[A-Z_],%200[A-Z_],%200[A-Z_],%200[A-Z_]",
- tmp[0], tmp[1], tmp[2], tmp[3]);
- PARA_DEBUG_LOG("found %i perm entries\n", num);
- u->perms = 0;
- while (num > 0) {
- num--;
- if (!strcmp(tmp[num], "AFS_READ"))
- u->perms |= AFS_READ;
- else if (!strcmp(tmp[num], "AFS_WRITE"))
- u->perms |= AFS_WRITE;
- else if (!strcmp(tmp[num], "DB_READ"))
- u->perms |= DB_READ;
- else if (!strcmp(tmp[num], "DB_WRITE"))
- u->perms |= DB_WRITE;
- else /* unknown permission */
- PARA_WARNING_LOG("unknown permission: %s\n",
- tmp[num]);
- }
- para_list_add(&u->node, &user_list);
- }
-out:
- if (file_ptr)
- fclose(file_ptr);
- if (ret >= 0)
- return;
- PARA_EMERG_LOG("%s\n", PARA_STRERROR(-ret));
- exit(EXIT_FAILURE);
-}
-
-static void init_user_list(void)
-{
- struct user *u, *tmp;
- static int initialized;
-
- if (initialized) {
- list_for_each_entry_safe(u, tmp, &user_list, node) {
- list_del(&u->node);
- free(u->name);
- free(u->rsa);
- free(u);
- }
- } else
- INIT_LIST_HEAD(&user_list);
- initialized = 1;
- populate_user_list();
-}
-
-/**
- * lookup user in user_list.
- *
- * \param user: must initially contain the name of the user and is filled
- * in by this function on success.
- *
- * \return 1 on success and < 0 on errors.
- */
-int get_user(struct user *user)
-{
- struct user *u;
- list_for_each_entry(u, &user_list, node) {
- if (strcmp(u->name, user->name))
- continue;
- *user = *u;
- return 1;
- }
- return -E_BAD_USER;
-}
-
static void init_selector(void)
{
int i, ret;
log_welcome("para_server", conf.loglevel_arg);
shm_init(); /* init mmd struct */
server_uptime(UPTIME_SET); /* reset server uptime */
- init_user_list();
+ init_user_list(user_list_file);
/* become daemon */
if (conf.daemon_given)
daemon_init();
/** size of the selector_info and audio_file info strings of struct misc_meta_data */
#define MMD_INFO_SIZE 16384
-/**
- * permission flags that can be set individually for any server command
- *
- * - DB_READ: command reads from the database
- * - DB_WRITE: command changes the contents of the database
- * - AFS_READ: command reads information about the current audio stream
- * - AFS_WRITE: command changes the current audio stream
- */
-enum {DB_READ = 1, DB_WRITE = 2, AFS_READ = 4, AFS_WRITE = 8};
-
-/**
- * data needed to authenticate the user
- */
-struct user {
- /** the position of this user in the list of users */
- struct list_head node;
- /** the username */
- char *name;
- /** the public RSA key */
- RSA *rsa;
- /** the privileges that this user has */
- unsigned int perms;
-};
-
/**
* defines one command of para_server
*/
extern struct server_args_info conf;
int handle_connect(int fd, struct sockaddr_in *addr);
-int get_user(struct user *user);
void mmd_unlock(void);
void mmd_lock(void);
--- /dev/null
+/*
+ * Copyright (C) 2006 Andre Noll <maan@systemlinux.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
+ */
+
+/** \file user_list.c user handling for para_server */
+
+#include "para.h"
+#include "error.h"
+#include "fd.h"
+#include "string.h"
+#include "user_list.h"
+
+static struct list_head user_list;
+
+/*
+ * lookup user in user list file. Fills in a user struct containing
+ * filename of the user's public key as well as the permissions of that user.
+ * Returns 1 on success, 0 if user does not exist and < 0 on errors.
+ */
+static void populate_user_list(char *user_list_file)
+{
+ FILE *file_ptr = NULL;
+ char *char_ptr;
+ char line[MAXLINE];
+ /* keyword, user, key, perms */
+ char w[MAXLINE], n[MAXLINE], k[MAXLINE], p[MAXLINE], tmp[4][MAXLINE];
+ int num, ret;
+
+ file_ptr = fopen(user_list_file, "r");
+ ret = -E_USERLIST;
+ if (!file_ptr)
+ goto out;
+ for (;;) {
+ struct user *u;
+ ret = para_fgets(line, MAXLINE, file_ptr);
+ if (ret < 0)
+ PARA_ERROR_LOG("%s\n", PARA_STRERROR(-ret));
+ if (ret <= 0)
+ break;
+ if (sscanf(line,"%200s %200s %200s %200s", w, n, k, p) < 3)
+ continue;
+ if (strcmp(w, "user"))
+ continue;
+ PARA_DEBUG_LOG("found entry for %s\n", n);
+ u = para_malloc(sizeof(struct user));
+ u->name = para_strdup(n);
+ u->rsa = para_malloc(sizeof(RSA));
+ ret = get_rsa_key(k, &u->rsa, LOAD_PUBLIC_KEY);
+ if (ret < 0)
+ break;
+ u->perms = 0;
+ char_ptr = p;
+ num = sscanf(char_ptr, "%200[A-Z_],%200[A-Z_],%200[A-Z_],%200[A-Z_]",
+ tmp[0], tmp[1], tmp[2], tmp[3]);
+ PARA_DEBUG_LOG("found %i perm entries\n", num);
+ u->perms = 0;
+ while (num > 0) {
+ num--;
+ if (!strcmp(tmp[num], "AFS_READ"))
+ u->perms |= AFS_READ;
+ else if (!strcmp(tmp[num], "AFS_WRITE"))
+ u->perms |= AFS_WRITE;
+ else if (!strcmp(tmp[num], "DB_READ"))
+ u->perms |= DB_READ;
+ else if (!strcmp(tmp[num], "DB_WRITE"))
+ u->perms |= DB_WRITE;
+ else /* unknown permission */
+ PARA_WARNING_LOG("unknown permission: %s\n",
+ tmp[num]);
+ }
+ para_list_add(&u->node, &user_list);
+ }
+out:
+ if (file_ptr)
+ fclose(file_ptr);
+ if (ret >= 0)
+ return;
+ PARA_EMERG_LOG("%s\n", PARA_STRERROR(-ret));
+ exit(EXIT_FAILURE);
+}
+
+void init_user_list(char *user_list_file)
+{
+ struct user *u, *tmp;
+ static int initialized;
+
+ if (initialized) {
+ list_for_each_entry_safe(u, tmp, &user_list, node) {
+ list_del(&u->node);
+ free(u->name);
+ free(u->rsa);
+ free(u);
+ }
+ } else
+ INIT_LIST_HEAD(&user_list);
+ initialized = 1;
+ populate_user_list(user_list_file);
+}
+
+/**
+ * lookup user in user_list.
+ *
+ * \param user: must initially contain the name of the user and is filled
+ * in by this function on success.
+ *
+ * \return 1 on success and < 0 on errors.
+ */
+int get_user(struct user *user)
+{
+ struct user *u;
+ list_for_each_entry(u, &user_list, node) {
+ if (strcmp(u->name, user->name))
+ continue;
+ *user = *u;
+ return 1;
+ }
+ return -E_BAD_USER;
+}
--- /dev/null
+/*
+ * Copyright (C) 2006 Andre Noll <maan@systemlinux.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
+ */
+
+/** \file user_list.h exported functions from user_list.c */
+
+#include "list.h"
+#include "crypt.h"
+
+/**
+ * permission flags that can be set individually for any server command
+ *
+ * - DB_READ: command reads from the database
+ * - DB_WRITE: command changes the contents of the database
+ * - AFS_READ: command reads information about the current audio stream
+ * - AFS_WRITE: command changes the current audio stream
+ */
+enum {DB_READ = 1, DB_WRITE = 2, AFS_READ = 4, AFS_WRITE = 8};
+
+/**
+ * data needed to authenticate the user
+ */
+struct user {
+ /** the position of this user in the list of users */
+ struct list_head node;
+ /** the username */
+ char *name;
+ /** the public RSA key */
+ RSA *rsa;
+ /** the privileges that this user has */
+ unsigned int perms;
+};
+
+void init_user_list(char *user_list_file);
+int get_user(struct user *user);