localserv/include/server.h

32 lines
1.1 KiB
C

#include <sys/stat.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <unistd.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <pwd.h>
#include <signal.h>
// TODO: I looked at https://man7.org/linux/man-pages/man3/cmsg.3.html to get this value, but I really don't know if it's right...
#define CONTROL_BUFFER_SIZE CMSG_SPACE(sizeof(struct ucred))
// expect clients' paths to be 6 chars long (auto-assigned sockets are a null first byte plus 5 [0-9a-f] characters)
#define CLIENT_PATH_LENGTH 6
// run this before using anything else
// path: filesystem path to create a unix socket at (can't be in use)
int server_init(char* path);
// blocks until a request is received
int server_listen();
// once a request is received, get it
// the memory will be freed next time you listen,
// so copy it if you need it
char* server_get_request();
// get the uid of the last successful request
uid_t server_get_uid();
// get the username associated with a uid
char* server_get_username(uid_t uid);
// send back a response
int server_respond(char* response);