136 lines
3.5 KiB
C

/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 2; tab-width: 2 -*- */
/*
* Originally written by Alexander Vdolainen <avdolainen@gmail.com>
*/
#ifndef __DSBUS_DAEMON_H__
#define __DSBUS_DAEMON_H__
#include <dsbus/data.h>
#define SYS_MSG 0x0f0affee
#define USR_MSG 0x0afeeffe
#define NIL_MSG 0x0
#define MAX_QUEUE_SIZE 4096
#define MAX_QUEUE_POOL 256
#define MAX_BACKLOG_CONNECTIONS 8
#define DSBD_DAEMONIZE (1 << 1)
#define DSBD_SYSTEMSHIT (1 << 2)
#define DSBNL_CMDADDOBJ 0xf
#define DSBNL_CMDREMOVEOBJ 0xc
#define DSBNL_CMDSETLISTENTRY 0xa
#define DSBNL_CMDCLEANLISTENTRY 0xb
#define DSBNL_CMDUIDCAPADD 0x5
#define DSBNL_CMDUIDCAPREMOVE 0x7
#define DSBNL_CMDUIDCAPCHANGE 0x8
#define DSBACT_READ 1
#define DSBACT_WRITE 2
#define DSBACT_EXEC 3
#define DSBMASK_READ (1 << DSBACT_READ)
#define DSBMASK_WRITE (1 << DSBACT_WRITE)
#define DSBMASK_EXEC (1 << DSBACT_EXEC)
#define DSBMASK_SET (1 << 4)
#define DSBRID_UID 1
#define DSBRID_GID 2
#define DSBRID_OTHER 0 /* must be always zero */
#define DSBRID_MAX 2
#define DSBNL_UIDRULE DSBRID_UID
#define DSBNL_GIDRULE DSBRID_GID
#define DSBNL_OTHERRULE DSBRID_OTHER
struct dsbnl_policy_msg {
uint64_t hash;
uint32_t flags;
uint32_t uid;
uint32_t gid;
uint32_t cap;
uint8_t listno;
uint8_t cmd;
};
struct zst_queue_s;
/* dsbusd context */
struct dsbd_ctx {
dsb_secstore_t *storage; /* storage */
char *config_file; /* from old proposal, not used */
char *log_file; /* the same i.e. not actually used */
char *unixsck_path; /* path to unix socket */
struct zst_queue_s *uqueue; /* job queue */
void *priv; /* added to make it more flexible */
int flags;
};
struct _payload {
int scn;
char *pmsg;
};
typedef struct zst_msg_s {
void *data; /** < message payload */
unsigned int msgtype; /** < message type ID */
unsigned int qlength; /** < current queue length (actual on add moment),
* it makes no sense with few readers */
usrtc_node_t node;
} zst_msg_t;
typedef struct zst_queue_s {
unsigned int length;
/* sync */
pthread_mutex_t mutex;
pthread_cond_t cond;
/* queue data */
usrtc_t qtree;
/* cache */
usrtc_t msgcache;
} zst_queue_t;
/* This is actually internal API, it placed here just to avoid of one big
piece of C code */
/* Init job queue */
int zst_queue_init(zst_queue_t *queue);
/* Add message to queue */
int zst_queue_add(zst_queue_t *queue, void *data, unsigned int msgtype);
/* Get a message from jon queue */
int zst_queue_get(zst_queue_t *queue, const struct timespec *timeout,
zst_msg_t *msg);
unsigned int zst_queue_length(zst_queue_t *queue);
int zst_queue_destroy(zst_queue_t *queue, int freedata,
void (*free_msg)(void *));
/* this is a hash function to provide right hash from UUID and inode number */
unsigned long djb2_hash(unsigned char *str);
/* initialize storage backend */
int store_initbe(dsb_secstore_t *storage, void *priv);
/* initialize DSB link for storage */
int store_initdac(dsb_secstore_t *storage, void *priv);
int store_pushbe(dsb_secstore_t *storage, dsb_secinfo_t *info);
int store_pushdac(dsb_secstore_t *storage, dsb_secinfo_t *info);
/* convert uuid to string */
char *uuid2str(uint8_t uuid[16]);
/* free converted string from uuid */
void free_uuidstr(char *str);
/* send a message to netlink socket */
int netlink_senddsbmsg(dsb_secstore_t *storage, struct dsbnl_policy_msg *dsbmsg);
#endif /* __DSBUS_DAEMON_H__ */