1 /* 2 * Copyright (c) 2003 Anil Madhavapeddy <anil@recoil.org> 3 * 4 * Permission to use, copy, modify, and distribute this software for any 5 * purpose with or without fee is hereby granted, provided that the above 6 * copyright notice and this permission notice appear in all copies. 7 * 8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 */ 16 17 #include <sys/types.h> 18 #include <sys/socket.h> 19 #include <sys/poll.h> 20 21 /* Privilege separation */ 22 int priv_init(char *, int, int, int, char **); 23 int priv_open_tty(const char *); 24 int priv_open_log(const char *); 25 FILE *priv_open_utmp(void); 26 FILE *priv_open_config(void); 27 void priv_config_parse_done(void); 28 int priv_config_modified(void); 29 int priv_gethostserv(char *, char *, struct sockaddr *, size_t); 30 int priv_gethostbyaddr(char *, int, int, char *, size_t); 31 32 /* Terminal message */ 33 char *ttymsg(struct iovec *, int, char *, int); 34 35 /* File descriptor send/recv */ 36 void send_fd(int, int); 37 int receive_fd(int); 38 39 /* The list of domain sockets */ 40 #define MAXFUNIX 21 41 extern int nfunix; 42 extern char *funixn[MAXFUNIX]; 43 extern char *ctlsock_path; 44 45 #define dprintf if (Debug) printf 46 extern int Debug; 47 extern int Startup; 48 49 /* fds to poll */ 50 #define PFD_KLOG 0 /* Offset of /dev/klog entry */ 51 #define PFD_INET 1 /* Offset of inet socket entry */ 52 #define PFD_CTLSOCK 2 /* Offset of control socket entry */ 53 #define PFD_CTLCONN 3 /* Offset of control connection entry */ 54 #define PFD_INET6 4 /* Offset of inet6 socket entry */ 55 #define PFD_UNIX_0 5 /* Start of Unix socket entries */ 56 #define N_PFD (PFD_UNIX_0 + MAXFUNIX) /* # of pollfd entries */ 57 extern struct pollfd pfd[N_PFD]; 58 59 struct ringbuf { 60 char *buf; 61 size_t len, start, end; 62 }; 63 64 struct ringbuf *ringbuf_init(size_t); 65 void ringbuf_free(struct ringbuf *); 66 void ringbuf_clear(struct ringbuf *); 67 size_t ringbuf_used(struct ringbuf *); 68 int ringbuf_append_line(struct ringbuf *, char *); 69 ssize_t ringbuf_to_string(char *, size_t, struct ringbuf *); 70