The FreeRADIUS server $Id: a4e7f8c94e8038b7627bcf52356b7ed15955c1d7 $
Loading...
Searching...
No Matches
Macros | 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.

Macros

#define FILE_PERMS(_cfg)
 

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_rcvsndbuf (int fd, fr_bio_fd_config_t const *cfg)
 
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.
 
static int fr_bio_fd_file_open (fr_bio_fd_t *my, fr_bio_fd_config_t const *cfg)
 Open a file.
 
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_tcp (int fd, UNUSED fr_socket_t const *sock)
 Initialize a TCP server socket.
 
static int fr_bio_fd_server_v6only (UNUSED int fd, UNUSED fr_socket_t const *sock)
 Stop a wildcard IPv6 listener from accepting IPv4 packets.
 
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_open (fr_bio_fd_t *my, fr_bio_fd_config_t const *cfg)
 Open a TCP or UDP socket.
 
static int fr_bio_fd_socket_unix_bind (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, mode_t dir_perm, uid_t uid)
 
static int fr_bio_fd_socket_unix_verify (int dirfd, char const *filename, fr_bio_fd_config_t const *cfg, uid_t uid)
 Verify or clean up a pre-existing domain socket.
 
static int fr_bio_fd_unix_open (fr_bio_fd_t *my, fr_bio_fd_config_t const *cfg)
 Open a Unix domain socket.
 
int fr_bio_fd_unix_shutdown (fr_bio_t *bio)
 Remove the Unix domain socket which this bio created.
 

Detailed Description

BIO abstractions for opening file descriptors.

Id
c0d76071ad0e43dc406af51f833961884a52fb56

Definition in file fd_open.c.

Macro Definition Documentation

◆ FILE_PERMS

#define FILE_PERMS (   _cfg)
Value:
do { \
file_perm = (_cfg)->perm ? (_cfg)->perm : S_IRGRP | S_IWGRP; \
file_perm |= S_IRUSR | S_IWUSR; \
dir_perm = file_perm & (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_ISGID | S_ISVTX); \
file_perm &= (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP); \
if ((dir_perm & (S_IRUSR | S_IWUSR)) != 0) dir_perm |= S_IXUSR; \
if ((dir_perm & (S_IRGRP | S_IWGRP)) != 0) dir_perm |= S_IXGRP; \
} while (0)
while(1)
Definition acutest.h:1009

Definition at line 535 of 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 996 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 128 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_rcvsndbuf()

static int fr_bio_fd_common_rcvsndbuf ( int  fd,
fr_bio_fd_config_t const *  cfg 
)
static

Definition at line 50 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 84 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 161 of file fd_open.c.

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

◆ fr_bio_fd_file_open()

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

Open a file.

The names /dev/stdout, /dev/stderr, and /dev/stdin are duplicates of the matching file descriptor, and are not opened by name.

Parameters
mythe FD bio
cfgthe configuration
Returns
  • <0 on error
  • the file descriptor

Definition at line 1194 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 897 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()

The caller must supply a cfg pointer which is long-lived. The FD BIO doesn't copy it, or its contents. fr_bio_fd_accept() uses the same pointer for accepted sockets.

Parameters
biothe FD bio
cfgconfiguration for the socket, which the caller owns and must keep alive
Returns
  • <0 on error
  • 0 on success

Definition at line 1293 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.

This will change the FD which is in the BIO.

Definition at line 1500 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 237 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_v6only()

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

Stop a wildcard IPv6 listener from accepting IPv4 packets.

Definition at line 267 of file fd_open.c.

+ 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 759 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 748 of file fd_open.c.

+ Here is the caller graph for this function:

◆ fr_bio_fd_socket_open()

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

Open a TCP or UDP socket.

The IP addresses and ports come from the configuration. The socket is not bound or connected here, as that depends on the fr_bio_fd_type_t.

Parameters
mythe FD bio
cfgthe configuration
Returns
  • <0 on error
  • the file descriptor

Definition at line 1089 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_bind()

static int fr_bio_fd_socket_unix_bind ( 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 557 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,
mode_t  dir_perm,
uid_t  uid 
)
static

Definition at line 344 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,
uid_t  uid 
)
static

Verify or clean up a pre-existing domain socket.

Definition at line 276 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_open()

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

Open a Unix domain socket.

The socket is not bound or connected here, as that depends on the fr_bio_fd_type_t.

Permissions are

Parameters
mythe FD bio
cfgthe configuration
Returns
  • <0 on error
  • the file descriptor

Definition at line 1263 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()

int fr_bio_fd_unix_shutdown ( fr_bio_t *  bio)

Remove the Unix domain socket which this bio created.

Called from fr_bio_fd_shutdown() for every Unix domain bio.

Definition at line 499 of file fd_open.c.

+ Here is the caller graph for this function: