53 lines
1.7 KiB
C
53 lines
1.7 KiB
C
#ifndef NSIGNER_SERVER_H
|
|
#define NSIGNER_SERVER_H
|
|
|
|
#include "dispatcher.h"
|
|
#include "policy.h"
|
|
#include <sys/types.h>
|
|
|
|
#define SERVER_SOCKET_NAME_MAX 108
|
|
#define SERVER_MAX_MSG_SIZE 65536
|
|
|
|
/* Caller identity */
|
|
typedef struct {
|
|
uid_t uid;
|
|
gid_t gid;
|
|
pid_t pid;
|
|
char caller_id[64]; /* "uid:<n>" */
|
|
} caller_identity_t;
|
|
|
|
/* Server context */
|
|
typedef struct {
|
|
char socket_name[SERVER_SOCKET_NAME_MAX]; /* abstract namespace name (without \0 prefix) */
|
|
char last_error[256];
|
|
int listen_fd;
|
|
int running;
|
|
dispatcher_ctx_t *dispatcher;
|
|
policy_table_t *policy;
|
|
int socket_name_explicit;
|
|
} server_ctx_t;
|
|
|
|
/* Initialize server context. socket_name is the abstract namespace name (e.g. "nsigner").
|
|
* socket_name_explicit should be non-zero when provided via --socket-name override. */
|
|
void server_init(server_ctx_t *ctx, const char *socket_name, int socket_name_explicit,
|
|
dispatcher_ctx_t *dispatcher, policy_table_t *policy);
|
|
|
|
/* Start listening. Returns 0 on success, -1 on error. */
|
|
int server_start(server_ctx_t *ctx);
|
|
|
|
/* Get human-readable description of last server error. */
|
|
const char *server_last_error(const server_ctx_t *ctx);
|
|
|
|
/* Handle one pending connection (non-blocking). Returns 1 if handled, 0 if nothing pending, -1 on error.
|
|
* activity_cb is called with a description string for the TUI activity log. */
|
|
typedef void (*server_activity_cb)(const char *message, void *user_data);
|
|
int server_handle_one(server_ctx_t *ctx, server_activity_cb cb, void *cb_data);
|
|
|
|
/* Stop server and close socket */
|
|
void server_stop(server_ctx_t *ctx);
|
|
|
|
/* Extract caller identity from connected fd */
|
|
int server_get_caller(int fd, caller_identity_t *out);
|
|
|
|
#endif /* NSIGNER_SERVER_H */
|