remoted: moar code, still doing nothing
This commit is contained in:
parent
7fbd7e98df
commit
929392cff5
@ -34,9 +34,7 @@ int srv_init (int argc, char **argv, char **env
|
|||||||
// gets the service path
|
// gets the service path
|
||||||
service_path (srv->spath, sname, srv->index, srv->version);
|
service_path (srv->spath, sname, srv->index, srv->version);
|
||||||
|
|
||||||
usock_init (&srv->service_fd, srv->spath);
|
return usock_init (&srv->service_fd, srv->spath);
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int srv_accept (struct service *srv, struct process *p)
|
int srv_accept (struct service *srv, struct process *p)
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
#ifndef __ERROR_H__
|
#ifndef __ERROR_H__
|
||||||
#define __ERROR_H__
|
#define __ERROR_H__
|
||||||
|
|
||||||
|
#include "logger.h"
|
||||||
|
|
||||||
#define handle_error(msg) \
|
#define handle_error(msg) \
|
||||||
do { perror(msg); exit(EXIT_FAILURE); } while (0)
|
do { log_error (msg); exit(EXIT_FAILURE); } while (0)
|
||||||
|
|
||||||
#define handle_err(fun,msg)\
|
#define handle_err(fun,msg)\
|
||||||
fprintf (stderr, "%s: file %s line %d %s\n", fun, __FILE__, __LINE__, msg);
|
do { log_error ("%s: file %s line %d %s", fun, __FILE__, __LINE__, msg); } while (0)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
44
core/logger.c
Normal file
44
core/logger.c
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
#include "logger.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
void log_format (const char* tag, const char* message, va_list args) {
|
||||||
|
time_t now;
|
||||||
|
|
||||||
|
time(&now);
|
||||||
|
|
||||||
|
char * date =ctime(&now);
|
||||||
|
date[strlen(date) - 1] = '\0';
|
||||||
|
printf("%s:%s: ", date, tag);
|
||||||
|
vprintf(message, args);
|
||||||
|
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void log_error (const char* message, ...) {
|
||||||
|
va_list args;
|
||||||
|
va_start(args, message);
|
||||||
|
|
||||||
|
log_format("error", message, args);
|
||||||
|
|
||||||
|
va_end(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
void log_info (const char* message, ...) {
|
||||||
|
va_list args;
|
||||||
|
va_start(args, message);
|
||||||
|
|
||||||
|
log_format("info", message, args);
|
||||||
|
va_end(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
void log_debug (const char* message, ...) {
|
||||||
|
va_list args;
|
||||||
|
va_start(args, message);
|
||||||
|
|
||||||
|
log_format("debug", message, args);
|
||||||
|
|
||||||
|
va_end(args);
|
||||||
|
}
|
15
core/logger.h
Normal file
15
core/logger.h
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#ifndef __LOGGER_H__
|
||||||
|
#define __LOGGER_H__
|
||||||
|
|
||||||
|
#define LOG
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
void log_error (const char* message, ...);
|
||||||
|
void log_info (const char* message, ...);
|
||||||
|
void log_debug (const char* message, ...);
|
||||||
|
|
||||||
|
// please use previous functions
|
||||||
|
void log_format (const char* tag, const char* message, va_list args);
|
||||||
|
|
||||||
|
#endif
|
@ -8,10 +8,15 @@ This service creates a path on the relevent remote location, going through anyth
|
|||||||
|
|
||||||
The idea is to have a simple configuration file for authentication of remote connections, such as:
|
The idea is to have a simple configuration file for authentication of remote connections, such as:
|
||||||
|
|
||||||
|
table dynusers # dynamic user table
|
||||||
|
|
||||||
clients = { "client123", alice.example.com, john@doe.com }
|
clients = { "client123", alice.example.com, john@doe.com }
|
||||||
|
localclients = { pamuser1, <dynusers> }
|
||||||
|
|
||||||
level1services = { pongd, weather }
|
level1services = { pongd, weather }
|
||||||
|
|
||||||
ifext = enp0s25
|
ifext = enp0s25
|
||||||
pass in on $ifext from any for all to local services $level1services
|
pass in on $ifext from any for all to local services $level1services
|
||||||
pass in on $ifext from any for all to local services $level1services
|
pass out on $ifext from local for $localclients to any services $level1services
|
||||||
|
|
||||||
|
block all
|
||||||
|
@ -55,16 +55,13 @@ void main_loop (int argc, char **argv, char **env
|
|||||||
(void) argv;
|
(void) argv;
|
||||||
(void) env;
|
(void) env;
|
||||||
|
|
||||||
|
#if 0
|
||||||
struct service srv;
|
struct service srv;
|
||||||
memset (&srv, 0, sizeof (struct service));
|
memset (&srv, 0, sizeof (struct service));
|
||||||
|
|
||||||
remote_connection (argc, argv, env, &srv);
|
remote_connection (argc, argv, env, &srv);
|
||||||
printf ("connected\n");
|
printf ("connected\n");
|
||||||
|
|
||||||
if (strncmp (cmd, "sub", 3) == 0) {
|
|
||||||
chan_sub (&srv, chan);
|
|
||||||
}
|
|
||||||
|
|
||||||
printf ("main_loop\n");
|
printf ("main_loop\n");
|
||||||
|
|
||||||
struct remote_msg msg;
|
struct remote_msg msg;
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
#include "../lib/remoted.h"
|
#include "../lib/remoted.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "../../core/logger.h"
|
||||||
|
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/un.h>
|
#include <sys/un.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@ -19,20 +21,34 @@ void handle_signal (int signalnumber)
|
|||||||
handle_error("srv_close < 0");
|
handle_error("srv_close < 0");
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf (stderr, "received a signal %d\n", signalnumber);
|
log_info ("remoted received a signal %d\n", signalnumber);
|
||||||
exit (EXIT_SUCCESS);
|
exit (EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
void remoted_init ()
|
/* TODO: handle command line arguments */
|
||||||
|
void remoted_cmd_args (int argc, char **argv, char **env
|
||||||
|
, struct remoted_ctx *ctx)
|
||||||
{
|
{
|
||||||
/* TODO
|
(void) argc;
|
||||||
* handle authorizations
|
(void) argv;
|
||||||
*/
|
(void) env;
|
||||||
|
(void) ctx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* TODO: handle authorizations */
|
||||||
|
int remoted_auth_conf (struct remoted_ctx *ctx)
|
||||||
|
{
|
||||||
|
(void) ctx;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char **argv, char **env)
|
main(int argc, char **argv, char **env)
|
||||||
{
|
{
|
||||||
|
struct remoted_ctx ctx;
|
||||||
|
memset (&ctx, 0, sizeof (struct remoted_ctx));
|
||||||
|
|
||||||
memset (&srv, 0, sizeof (struct service));
|
memset (&srv, 0, sizeof (struct service));
|
||||||
srv.index = 0;
|
srv.index = 0;
|
||||||
srv.version = 0;
|
srv.version = 0;
|
||||||
@ -41,15 +57,22 @@ main(int argc, char **argv, char **env)
|
|||||||
signal(SIGINT, handle_signal);
|
signal(SIGINT, handle_signal);
|
||||||
signal(SIGQUIT, handle_signal);
|
signal(SIGQUIT, handle_signal);
|
||||||
|
|
||||||
remoted_init ();
|
remoted_cmd_args (argc, argv, env, &ctx);
|
||||||
|
|
||||||
|
log_info ("remoted started");
|
||||||
|
// load configuration
|
||||||
|
if (remoted_auth_conf (&ctx)) {
|
||||||
|
log_error ("remoted cannot load configuration");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
log_info ("remoted configuration loaded");
|
||||||
|
|
||||||
if (srv_init (argc, argv, env, &srv, REMOTED_SERVICE_NAME) < 0) {
|
if (srv_init (argc, argv, env, &srv, REMOTED_SERVICE_NAME) < 0) {
|
||||||
handle_error("srv_init < 0");
|
handle_error("srv_init < 0");
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
}
|
||||||
printf ("Listening on %s.\n", srv.spath);
|
log_info ("remoted listening on %s", srv.spath);
|
||||||
|
|
||||||
printf("MAIN: server created\n" );
|
// TODO: here comes pledge (openbsd)
|
||||||
|
|
||||||
// the service will loop until the end of time, a specific message, a signal
|
// the service will loop until the end of time, a specific message, a signal
|
||||||
remoted_main_loop (&srv);
|
remoted_main_loop (&srv);
|
||||||
@ -58,6 +81,7 @@ main(int argc, char **argv, char **env)
|
|||||||
if (srv_close (&srv) < 0) {
|
if (srv_close (&srv) < 0) {
|
||||||
handle_error("srv_close < 0");
|
handle_error("srv_close < 0");
|
||||||
}
|
}
|
||||||
|
log_info ("remoted ended");
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include "../../core/process.h"
|
#include "../../core/process.h"
|
||||||
#include "../../core/utils.h"
|
#include "../../core/utils.h"
|
||||||
#include "../../core/error.h"
|
#include "../../core/error.h"
|
||||||
|
#include "../../core/logger.h"
|
||||||
|
|
||||||
#include "remoted.h"
|
#include "remoted.h"
|
||||||
|
|
||||||
@ -13,5 +14,6 @@
|
|||||||
void remoted_main_loop (struct service *srv)
|
void remoted_main_loop (struct service *srv)
|
||||||
{
|
{
|
||||||
(void) srv;
|
(void) srv;
|
||||||
|
log_debug ("remoted entering main loop");
|
||||||
/* TODO */
|
/* TODO */
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,10 @@
|
|||||||
|
|
||||||
#define REMOTED_SERVICE_NAME "remoted"
|
#define REMOTED_SERVICE_NAME "remoted"
|
||||||
|
|
||||||
|
struct remoted_ctx {
|
||||||
|
/* TODO */
|
||||||
|
};
|
||||||
|
|
||||||
void remoted_main_loop (struct service *srv);
|
void remoted_main_loop (struct service *srv);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user