Skip to content
Extraits de code Groupes Projets
Vérifiée Valider f42dfffa rédigé par Kubat's avatar Kubat
Parcourir les fichiers

Adding the __restart command

parent 56ed52ab
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!51User access control and management
......@@ -92,3 +92,6 @@ bool command_set_playback_option(struct lkt_state *srv,
/* Authentificate users */
bool command_password(struct lkt_state *srv, size_t c, char *argv[LKT_MESSAGE_ARGS_MAX]);
bool command_user_add(sqlite3 *db, char *argv[LKT_MESSAGE_ARGS_MAX]);
/* Program management control */
bool command_restart(struct lkt_state *srv, size_t c);
......@@ -88,6 +88,8 @@ CREATE TABLE IF NOT EXISTS users
, PRIMARY KEY (username, password)
) WITHOUT ROWID;
INSERT INTO users (username, password) VALUES ('sakura', 'hashire');
-- Some useful values:
-- last_update is the timestamp of the last time the table of kara has been
......
......@@ -13,6 +13,35 @@
#include <string.h>
#include <strings.h>
#include <limits.h>
#include <unistd.h>
#define SELF_EXECUTABLE_LINUX "/proc/self/exe"
#define SELF_EXECUTABLE_FREEBSD "/proc/curproc/file"
#define SELF_EXECUTABLE_SOLARIS "/proc/self/path/a.out"
inline bool
command_restart(struct lkt_state *srv, size_t c)
{
char exe[PATH_MAX];
char *const argv[] = { exe, NULL };
if (!lkt_client_auth(srv, c, false)) {
fprintf(stderr, " ! command_restart: Failed to restart, user not authentificated %lu\n", c);
return false;
}
if (readlink(SELF_EXECUTABLE_LINUX, exe, PATH_MAX - 1) > 0)
execv(exe, argv);
if (readlink(SELF_EXECUTABLE_FREEBSD, exe, PATH_MAX - 1) > 0)
execv(exe, argv);
if (readlink(SELF_EXECUTABLE_SOLARIS, exe, PATH_MAX - 1) > 0)
execv(exe, argv);
fprintf(stderr, " ! command_restart: Failed to exec lektor or OS not supported\n");
return false;
}
bool
command_currentsong(struct lkt_state *srv, size_t c)
......
......@@ -144,6 +144,9 @@ handle_simple_command(struct lkt_state *srv, size_t c, struct lkt_command cmd)
} else if (!strcmp(cmd.name, "password")) {
err = !command_password(srv, c, cmd.args);
break;
} else if (!strcmp(cmd.name, "__restart")) {
err = !command_restart(srv, c);
break;
}
}
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter