Various utility functions.
More...
#include <pwd.h>
#include <grp.h>
#include <freeradius-devel/util/talloc.h>
Go to the source code of this file.
|
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...
|
|
int | rad_expand_xlat (request_t *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...
|
|
int | rad_filename_box_escape (fr_value_box_t *vb, UNUSED void *uxtc) |
|
int | rad_filename_box_make_safe (fr_value_box_t *vb, UNUSED void *uxtc) |
|
ssize_t | rad_filename_escape (UNUSED request_t *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...
|
|
ssize_t | rad_filename_make_safe (UNUSED request_t *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...
|
|
uint32_t | rad_pps (uint32_t *past, uint32_t *present, time_t *then, struct timeval *now) |
|
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) |
|
bool | rad_suid_is_down_permanent (void) |
| Return whether we've permanently dropped root privileges. More...
|
|
void | rad_suid_set_down_uid (uid_t uid) |
|
void | rad_suid_up (void) |
|
Various utility functions.
- Id
- 7c0485d583037ba0f103059322d4038ee75e96fd
- Copyright
- 2000,2006 The FreeRADIUS server project
Definition in file util.h.
◆ rad_ajoin()
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
- Parameters
-
ctx | to allocate buffer in. |
argv | array of substrings. |
argc | length of array. |
c | separation character. Optional, may be '\0' for no separator. |
- Returns
- the concatenation of the elements of argv, separated by c.
Definition at line 398 of file util.c.
◆ rad_expand_xlat()
int rad_expand_xlat |
( |
request_t * |
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.
- Parameters
-
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. |
- Returns
- argc or -1 on failure.
Definition at line 599 of file util.c.
◆ rad_filename_box_escape()
◆ rad_filename_box_make_safe()
◆ rad_filename_escape()
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.
- Note
- function takes additional arguments so that it may be used as an xlat escape function but it's fine to call it directly.
-
OSX/Unix/NTFS/VFAT have a max filename size of 255 bytes.
- Parameters
-
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 216 of file util.c.
◆ rad_filename_make_safe()
Ensures that a filename cannot walk up the directory structure.
Also sanitizes control chars.
- Parameters
-
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 96 of file util.c.
◆ rad_filename_unescape()
Converts data stored in a file name back to its original form.
- Parameters
-
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. |
- Returns
- Number of bytes written to output buffer
- offset where parse error occurred on failure.
Definition at line 336 of file util.c.
◆ rad_pps()
◆ rad_segid()
int rad_segid |
( |
gid_t |
gid | ) |
|
Alter the effective user id.
- Parameters
-
- Returns
- 0 on success.
- -1 on failure.
Definition at line 951 of file util.c.
◆ rad_seuid()
int rad_seuid |
( |
uid_t |
uid | ) |
|
Alter the effective user id.
- Parameters
-
- Returns
- 0 on success.
- -1 on failure.
Definition at line 929 of file util.c.
◆ rad_suid_down()
void rad_suid_down |
( |
void |
| ) |
|
◆ rad_suid_down_permanent()
void rad_suid_down_permanent |
( |
void |
| ) |
|
◆ rad_suid_is_down_permanent()
bool rad_suid_is_down_permanent |
( |
void |
| ) |
|
Return whether we've permanently dropped root privileges.
- Returns
- true if root privileges have been dropped.
- false if root privileges have not been dropped.
Definition at line 917 of file util.c.
◆ rad_suid_set_down_uid()
void rad_suid_set_down_uid |
( |
uid_t |
uid | ) |
|
◆ rad_suid_up()
void rad_suid_up |
( |
void |
| ) |
|
◆ reset_signal
void(*)(int) reset_signal(int signo, void(*func)(int)) |
( |
int |
signo, |
|
|
void(*)(int) |
func |
|
) |
| |