#include <freeradius-devel/radiusd.h>
#include <freeradius-devel/rad_assert.h>
#include <ctype.h>
#include <sys/stat.h>
#include <fcntl.h>
Go to the source code of this file.
Macros | |
#define | USEC 1000000 |
Functions | |
char * | rad_ajoin (TALLOC_CTX *ctx, char const **argv, int argc, char c) |
talloc a buffer to hold the concatenated value of all elements of argv More... | |
char * | rad_asprint_gid (TALLOC_CTX *ctx, uid_t gid) |
Print gid to a string. More... | |
char * | rad_asprint_uid (TALLOC_CTX *ctx, uid_t uid) |
Print uid to a string. More... | |
void NEVER_RETURNS | rad_assert_fail (char const *file, unsigned int line, char const *expr) |
void | rad_const_free (void const *ptr) |
int | rad_copy_string (char *to, char const *from) |
int | rad_copy_string_bare (char *to, char const *from) |
int | rad_copy_variable (char *to, char const *from) |
char const * | rad_default_lib_dir (void) |
Return the default lib dir. More... | |
char const * | rad_default_log_dir (void) |
Return the default log dir. More... | |
char const * | rad_default_raddb_dir (void) |
Return the default raddb dir. More... | |
char const * | rad_default_run_dir (void) |
Return the default run dir. More... | |
char const * | rad_default_sbin_dir (void) |
Return the default sbin dir. More... | |
int | rad_expand_xlat (REQUEST *request, char const *cmd, int max_argc, char const *argv[], bool can_fail, size_t argv_buflen, char *argv_buf) |
Split string into words and expand each one. More... | |
void | rad_file_error (int num) |
Write a file access error to the fr_strerror buffer, including euid/egid. More... | |
size_t | rad_filename_escape (UNUSED REQUEST *request, char *out, size_t outlen, char const *in, UNUSED void *arg) |
Escapes the raw string such that it should be safe to use as part of a file path. More... | |
size_t | rad_filename_make_safe (UNUSED REQUEST *request, char *out, size_t outlen, char const *in, UNUSED void *arg) |
Ensures that a filename cannot walk up the directory structure. More... | |
ssize_t | rad_filename_unescape (char *out, size_t outlen, char const *in, size_t inlen) |
Converts data stored in a file name back to its original form. More... | |
int | rad_getgid (TALLOC_CTX *ctx, gid_t *out, char const *name) |
Resolve a group name to a GID. More... | |
int | rad_getgrgid (TALLOC_CTX *ctx, struct group **out, gid_t gid) |
Resolve a gid to a group database entry. More... | |
int | rad_getgrnam (TALLOC_CTX *ctx, struct group **out, char const *name) |
Resolve a group name to a group database entry. More... | |
int | rad_getpwnam (TALLOC_CTX *ctx, struct passwd **out, char const *name) |
Resolve a username to a passwd entry. More... | |
int | rad_getpwuid (TALLOC_CTX *ctx, struct passwd **out, uid_t uid) |
Resolve a uid to a passwd entry. More... | |
void * | rad_malloc (size_t size) |
int | rad_mkdir (char *dir, mode_t mode, uid_t uid, gid_t gid) |
Create possibly many directories. More... | |
void | rad_mode_to_oct (char out[5], mode_t mode) |
void | rad_mode_to_str (char out[10], mode_t mode) |
Convert mode_t into humanly readable permissions flags. More... | |
uint32_t | rad_pps (uint32_t *past, uint32_t *present, time_t *then, struct timeval *now) |
char const * | rad_radacct_dir (void) |
Return the default radacct dir. More... | |
int | rad_segid (gid_t gid) |
Alter the effective user id. More... | |
int | rad_seuid (uid_t uid) |
Alter the effective user id. More... | |
void | rad_suid_down (void) |
void | rad_suid_down_permanent (void) |
void | rad_suid_set_down_uid (uid_t uid) |
void | rad_suid_up (void) |
static void | verify_packet (char const *file, int line, REQUEST *request, RADIUS_PACKET *packet, char const *type) |
void | verify_request (char const *file, int line, REQUEST *request) |
Variables | |
void(*)(int) | reset_signal (int signo, void(*func)(int)) |
char* rad_ajoin | ( | TALLOC_CTX * | ctx, |
char const ** | argv, | ||
int | argc, | ||
char | c | ||
) |
talloc a buffer to hold the concatenated value of all elements of argv
ctx | to allocate buffer in. |
argv | array of substrings. |
argc | length of array. |
c | separation character. Optional, may be '\0' for no separator. |
Definition at line 441 of file util.c.
char* rad_asprint_gid | ( | TALLOC_CTX * | ctx, |
uid_t | gid | ||
) |
char* rad_asprint_uid | ( | TALLOC_CTX * | ctx, |
uid_t | uid | ||
) |
void NEVER_RETURNS rad_assert_fail | ( | char const * | file, |
unsigned int | line, | ||
char const * | expr | ||
) |
void rad_const_free | ( | void const * | ptr | ) |
int rad_copy_string | ( | char * | to, |
char const * | from | ||
) |
int rad_copy_string_bare | ( | char * | to, |
char const * | from | ||
) |
int rad_copy_variable | ( | char * | to, |
char const * | from | ||
) |
char const* rad_default_lib_dir | ( | void | ) |
char const* rad_default_log_dir | ( | void | ) |
char const* rad_default_raddb_dir | ( | void | ) |
char const* rad_default_run_dir | ( | void | ) |
char const* rad_default_sbin_dir | ( | void | ) |
int rad_expand_xlat | ( | REQUEST * | request, |
char const * | cmd, | ||
int | max_argc, | ||
char const * | argv[], | ||
bool | can_fail, | ||
size_t | argv_buflen, | ||
char * | argv_buf | ||
) |
Split string into words and expand each one.
request | Current request. |
cmd | string to split. |
max_argc | the maximum number of arguments to split into. |
argv | Where to write the pointers into argv_buf. |
can_fail | If false, stop processing if any of the xlat expansions fail. |
argv_buflen | size of argv_buf. |
argv_buf | temporary buffer we used to mangle/expand cmd. Pointers to offsets of this buffer will be written to argv. |
Definition at line 658 of file util.c.
void rad_file_error | ( | int | num | ) |
Write a file access error to the fr_strerror buffer, including euid/egid.
num | Usually num, unless the error is returned by the function. |
Definition at line 1306 of file util.c.
size_t rad_filename_escape | ( | UNUSED REQUEST * | request, |
char * | out, | ||
size_t | outlen, | ||
char const * | in, | ||
UNUSED void * | arg | ||
) |
Escapes the raw string such that it should be safe to use as part of a file path.
This function is designed to produce a string that's still readable but portable across the majority of file systems.
For security reasons it cannot remove characters from the name, and must not allow collisions to occur between different strings.
With that in mind '-' has been chosen as the escape character, and will be double escaped '-' -> '–' to avoid collisions.
Escaping should be reversible if the original string needs to be extracted.
request | Current request (may be NULL). |
out | Output buffer. |
outlen | Size of the output buffer. |
in | string to escape. |
arg | Context arguments (unused, should be NULL). |
Definition at line 269 of file util.c.
size_t rad_filename_make_safe | ( | UNUSED REQUEST * | request, |
char * | out, | ||
size_t | outlen, | ||
char const * | in, | ||
UNUSED void * | arg | ||
) |
Ensures that a filename cannot walk up the directory structure.
Also sanitizes control chars.
request | Current request (may be NULL). |
out | Output buffer. |
outlen | Size of the output buffer. |
in | string to escape. |
arg | Context arguments (unused, should be NULL). |
Definition at line 175 of file util.c.
ssize_t rad_filename_unescape | ( | char * | out, |
size_t | outlen, | ||
char const * | in, | ||
size_t | inlen | ||
) |
Converts data stored in a file name back to its original form.
out | Where to write the unescaped string (may be the same as in). |
outlen | Length of the output buffer. |
in | Input filename. |
inlen | Length of input. |
Definition at line 354 of file util.c.
int rad_getgid | ( | TALLOC_CTX * | ctx, |
gid_t * | out, | ||
char const * | name | ||
) |
int rad_getgrgid | ( | TALLOC_CTX * | ctx, |
struct group ** | out, | ||
gid_t | gid | ||
) |
Resolve a gid to a group database entry.
Resolves a gid to a group database entry. The memory to hold the group entry is talloced under ctx, and must be freed when no longer required.
ctx | to allocate passwd entry in. |
out | Where to write pointer to entry. |
gid | to resolve. |
Definition at line 1118 of file util.c.
int rad_getgrnam | ( | TALLOC_CTX * | ctx, |
struct group ** | out, | ||
char const * | name | ||
) |
Resolve a group name to a group database entry.
Resolves a group name to a group database entry. The memory to hold the group entry is talloced under ctx, and must be freed when no longer required.
ctx | to allocate passwd entry in. |
out | Where to write pointer to entry. |
name | to resolve. |
Definition at line 1185 of file util.c.
int rad_getpwnam | ( | TALLOC_CTX * | ctx, |
struct passwd ** | out, | ||
char const * | name | ||
) |
Resolve a username to a passwd entry.
Resolves a username to a passwd entry. The memory to hold the passwd entry is talloced under ctx, and must be freed when no longer required.
ctx | to allocate passwd entry in. |
out | Where to write pointer to entry. |
name | to resolve. |
Definition at line 1051 of file util.c.
int rad_getpwuid | ( | TALLOC_CTX * | ctx, |
struct passwd ** | out, | ||
uid_t | uid | ||
) |
Resolve a uid to a passwd entry.
Resolves a uid to a passwd entry. The memory to hold the passwd entry is talloced under ctx, and must be freed when no longer required.
ctx | to allocate passwd entry in. |
out | Where to write pointer to entry. |
uid | to resolve. |
Definition at line 984 of file util.c.
void* rad_malloc | ( | size_t | size | ) |
int rad_mkdir | ( | char * | dir, |
mode_t | mode, | ||
uid_t | uid, | ||
gid_t | gid | ||
) |
Create possibly many directories.
dir | path to directory to create. |
mode | for new directories. |
uid | to set on new directories, may be -1 to use effective uid. |
gid | to set on new directories, may be -1 to use effective gid. |
Definition at line 90 of file util.c.
void rad_mode_to_str | ( | char | out[10], |
mode_t | mode | ||
) |
uint32_t rad_pps | ( | uint32_t * | past, |
uint32_t * | present, | ||
time_t * | then, | ||
struct timeval * | now | ||
) |
char const* rad_radacct_dir | ( | void | ) |
int rad_segid | ( | gid_t | gid | ) |
int rad_seuid | ( | uid_t | uid | ) |
void rad_suid_down | ( | void | ) |
void rad_suid_down_permanent | ( | void | ) |
void rad_suid_up | ( | void | ) |
|
static |
void verify_request | ( | char const * | file, |
int | line, | ||
REQUEST * | request | ||
) |