The FreeRADIUS server $Id: f3670dba8951ca10eb4948feb3dc3db9423a334f $
Loading...
Searching...
No Matches
Functions
fd_open.c File Reference

BIO abstractions for opening file descriptors. More...

#include <freeradius-devel/bio/fd_priv.h>
#include <freeradius-devel/util/file.h>
#include <freeradius-devel/util/cap.h>
#include <freeradius-devel/util/rand.h>
#include <sys/stat.h>
#include <net/if.h>
#include <libgen.h>
#include <netinet/tcp.h>
#include <netinet/in.h>
+ Include dependency graph for fd_open.c:

Go to the source code of this file.

Functions

int fr_bio_fd_check_config (fr_bio_fd_config_t const *cfg)
 Checks the configuration without modifying anything.
 
static int fr_bio_fd_common_datagram (int fd, UNUSED fr_socket_t const *sock, fr_bio_fd_config_t const *cfg)
 Initialize common datagram information.
 
static int fr_bio_fd_common_tcp (int fd, UNUSED fr_socket_t const *sock, fr_bio_fd_config_t const *cfg)
 Initialize common datagram information.
 
static int fr_bio_fd_common_udp (int fd, fr_socket_t const *sock, fr_bio_fd_config_t const *cfg)
 Initialize a UDP socket.
 
void fr_bio_fd_name (fr_bio_fd_t *my)
 Set the name of an FD BIO.
 
int fr_bio_fd_open (fr_bio_t *bio, fr_bio_fd_config_t const *cfg)
 Opens a socket and updates sock->fd.
 
int fr_bio_fd_reopen (fr_bio_t *bio)
 Reopen a file BIO.
 
static int fr_bio_fd_server_ipv4 (int fd, fr_socket_t const *sock, fr_bio_fd_config_t const *cfg)
 Initialize an IPv4 server socket.
 
static int fr_bio_fd_server_ipv6 (int fd, fr_socket_t const *sock, fr_bio_fd_config_t const *cfg)
 Initialize an IPv6 server socket.
 
static int fr_bio_fd_server_tcp (int fd, UNUSED fr_socket_t const *sock)
 Initialize a TCP server socket.
 
static int fr_bio_fd_socket_bind (fr_bio_fd_t *my, fr_bio_fd_config_t const *cfg)
 
static int fr_bio_fd_socket_bind_to_device (fr_bio_fd_t *my, UNUSED fr_bio_fd_config_t const *cfg)
 This system is missing SO_BINDTODEVICE, IP_BOUND_IF, IPV6_BOUND_IF.
 
static int fr_bio_fd_socket_bind_unix (fr_bio_fd_t *my, fr_bio_fd_config_t const *cfg)
 Bind to a Unix domain socket.
 
static int fr_bio_fd_socket_unix_mkdir (int *dirfd, char const **filename, fr_bio_fd_config_t const *cfg)
 
static int fr_bio_fd_socket_unix_verify (int dirfd, char const *filename, fr_bio_fd_config_t const *cfg)
 Verify or clean up a pre-existing domain socket.
 
static int fr_bio_fd_unix_shutdown (fr_bio_t *bio)
 

Detailed Description

BIO abstractions for opening file descriptors.

Id
5ab9f78c48b4204ce7b89c6664755a47db437f06

Definition in file fd_open.c.

Function Documentation

◆ fr_bio_fd_check_config()

int fr_bio_fd_check_config ( fr_bio_fd_config_t const *  cfg)

Checks the configuration without modifying anything.

Definition at line 990 of file fd_open.c.

+ Here is the caller graph for this function:

◆ fr_bio_fd_common_datagram()

static int fr_bio_fd_common_datagram ( int  fd,
UNUSED fr_socket_t const *  sock,
fr_bio_fd_config_t const *  cfg 
)
static

Initialize common datagram information.

Definition at line 97 of file fd_open.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_bio_fd_common_tcp()

static int fr_bio_fd_common_tcp ( int  fd,
UNUSED fr_socket_t const *  sock,
fr_bio_fd_config_t const *  cfg 
)
static

Initialize common datagram information.

Definition at line 53 of file fd_open.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_bio_fd_common_udp()

static int fr_bio_fd_common_udp ( int  fd,
fr_socket_t const *  sock,
fr_bio_fd_config_t const *  cfg 
)
static

Initialize a UDP socket.

Definition at line 159 of file fd_open.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_bio_fd_name()

void fr_bio_fd_name ( fr_bio_fd_t my)

Set the name of an FD BIO.

Definition at line 891 of file fd_open.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_bio_fd_open()

int fr_bio_fd_open ( fr_bio_t bio,
fr_bio_fd_config_t const *  cfg 
)

Opens a socket and updates sock->fd.

If the socket is asynchronous, it also calls connect()

Definition at line 1054 of file fd_open.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_bio_fd_reopen()

int fr_bio_fd_reopen ( fr_bio_t bio)

Reopen a file BIO.

e.g. for log files.

Definition at line 1388 of file fd_open.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_bio_fd_server_ipv4()

static int fr_bio_fd_server_ipv4 ( int  fd,
fr_socket_t const *  sock,
fr_bio_fd_config_t const *  cfg 
)
static

Initialize an IPv4 server socket.

Definition at line 250 of file fd_open.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_bio_fd_server_ipv6()

static int fr_bio_fd_server_ipv6 ( int  fd,
fr_socket_t const *  sock,
fr_bio_fd_config_t const *  cfg 
)
static

Initialize an IPv6 server socket.

Definition at line 263 of file fd_open.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_bio_fd_server_tcp()

static int fr_bio_fd_server_tcp ( int  fd,
UNUSED fr_socket_t const *  sock 
)
static

Initialize a TCP server socket.

Definition at line 235 of file fd_open.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_bio_fd_socket_bind()

static int fr_bio_fd_socket_bind ( fr_bio_fd_t my,
fr_bio_fd_config_t const *  cfg 
)
static

Definition at line 753 of file fd_open.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_bio_fd_socket_bind_to_device()

static int fr_bio_fd_socket_bind_to_device ( fr_bio_fd_t my,
UNUSED fr_bio_fd_config_t const *  cfg 
)
static

This system is missing SO_BINDTODEVICE, IP_BOUND_IF, IPV6_BOUND_IF.

@todo - FreeBSD IP_RECVIF and IP_SENDIF

Except that has to be done in recvmsg() and sendmsg().  And it only works on datagram sockets.

cmsg_len = sizeof(struct sockaddr_dl)
cmsg_level = IPPROTO_IP
cmsg_type = IP_RECVIF

Definition at line 742 of file fd_open.c.

+ Here is the caller graph for this function:

◆ fr_bio_fd_socket_bind_unix()

static int fr_bio_fd_socket_bind_unix ( fr_bio_fd_t my,
fr_bio_fd_config_t const *  cfg 
)
static

Bind to a Unix domain socket.

Todo:
  • this function only does a tiny bit of what fr_server_domain_socket_peercred() and fr_server_domain_socket_perm() do. Those functions do a lot more sanity checks.

The main question is whether or not those checks are useful. In many cases, fchmod() and fchown() are not possible on Unix sockets, so we shouldn't bother doing them,

Note that the listeners generally call these functions with wrappers of fr_suid_up() and fr_suid_down(). So these functions are running as "root", and will create files owned as "root".

Definition at line 549 of file fd_open.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_bio_fd_socket_unix_mkdir()

static int fr_bio_fd_socket_unix_mkdir ( int *  dirfd,
char const **  filename,
fr_bio_fd_config_t const *  cfg 
)
static

Definition at line 357 of file fd_open.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_bio_fd_socket_unix_verify()

static int fr_bio_fd_socket_unix_verify ( int  dirfd,
char const *  filename,
fr_bio_fd_config_t const *  cfg 
)
static

Verify or clean up a pre-existing domain socket.

Definition at line 290 of file fd_open.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_bio_fd_unix_shutdown()

static int fr_bio_fd_unix_shutdown ( fr_bio_t bio)
static

Definition at line 509 of file fd_open.c.

+ Here is the caller graph for this function: