23RCSID(
"$Id: 6d1c02a5ae3ea9e98b85743130ba13552614262b $")
25#include <freeradius-devel/util/perm.h>
26#include <freeradius-devel/util/strerror.h>
27#include <freeradius-devel/util/syserror.h>
38 static char const *rwx[] = {
"---",
"--x",
"-w-",
"-wx",
"r--",
"r-x",
"rw-",
"rwx"};
43 if (mode & S_ISUID)
out[2] = (mode & 0100) ?
's' :
'S';
44 if (mode & S_ISGID)
out[5] = (mode & 0010) ?
's' :
'l';
45 if (mode & S_ISVTX)
out[8] = (mode & 0100) ?
't' :
'T';
53 out[0] =
'0' + ((mode >> 9) & 0x07);
54 out[1] =
'0' + ((mode >> 6) & 0x07);
55 out[2] =
'0' + ((mode >> 3) & 0x07);
56 out[3] =
'0' + (mode & 0x07);
78 if (strlen(str) != 4)
goto fail;
80 value = strtoul(str, &end, 8);
81 if (*end || (
value == ULONG_MAX)) {
111 }
else if (*p ==
'u') {
112 if (p[1] !=
'=')
goto expected_set;
117 }
else if (*p ==
'o') {
118 if (p[1] !=
'=')
goto expected_set;
128 for ( ; *p !=
'\0'; p++) {
155 if (isalpha((
uint8_t) *p))
goto redo;
169 if ((mode &
mask) != 0) {
181 if ((mode & S_IWOTH) != 0) {
217#ifdef _SC_GETPW_R_SIZE_MAX
220 sc_len = sysconf(_SC_GETPW_R_SIZE_MAX);
221 if (sc_len <= 0) sc_len = 1024;
228 buff = talloc_array(ctx,
uint8_t,
sizeof(
struct passwd) + len);
229 if (!
buff)
return -1;
235 while ((ret = getpwuid_r(uid, (
struct passwd *)
buff, (
char *)(
buff +
sizeof(
struct passwd)),
236 talloc_array_length(
buff) -
sizeof(
struct passwd),
out)) == ERANGE) {
237 buff = talloc_realloc_size(ctx,
buff, talloc_array_length(
buff) * 2);
240 if ((ret != 0) || !*
out) {
247 talloc_set_type(
buff,
struct passwd);
280#ifdef _SC_GETPW_R_SIZE_MAX
283 sc_len = sysconf(_SC_GETPW_R_SIZE_MAX);
284 if (sc_len <= 0) sc_len = 1024;
291 buff = talloc_array(ctx,
uint8_t,
sizeof(
struct passwd) + len);
292 if (!
buff)
return -1;
298 while ((ret = getpwnam_r(
name, (
struct passwd *)
buff, (
char *)(
buff +
sizeof(
struct passwd)),
299 talloc_array_length(
buff) -
sizeof(
struct passwd),
out)) == ERANGE) {
300 buff = talloc_realloc_size(ctx,
buff, talloc_array_length(
buff) * 2);
303 if ((ret != 0) || !*
out) {
310 talloc_set_type(
buff,
struct passwd);
343#ifdef _SC_GETGR_R_SIZE_MAX
346 sc_len = sysconf(_SC_GETGR_R_SIZE_MAX);
347 if (sc_len <= 0) sc_len = 1024;
354 buff = talloc_array(ctx,
uint8_t,
sizeof(
struct group) + len);
355 if (!
buff)
return -1;
361 while ((ret = getgrgid_r(gid, (
struct group *)
buff, (
char *)(
buff +
sizeof(
struct group)),
362 talloc_array_length(
buff) -
sizeof(
struct group),
out)) == ERANGE) {
363 buff = talloc_realloc_size(ctx,
buff, talloc_array_length(
buff) * 2);
366 if ((ret != 0) || !*
out) {
373 talloc_set_type(
buff,
struct group);
406#ifdef _SC_GETGR_R_SIZE_MAX
409 sc_len = sysconf(_SC_GETGR_R_SIZE_MAX);
410 if (sc_len <= 0) sc_len = 1024;
417 buff = talloc_array(ctx,
uint8_t,
sizeof(
struct group) + len);
418 if (!
buff)
return -1;
424 while ((ret = getgrnam_r(
name, (
struct group *)
buff, (
char *)(
buff +
sizeof(
struct group)),
425 talloc_array_length(
buff) -
sizeof(
struct group),
out)) == ERANGE) {
426 buff = talloc_realloc_size(ctx,
buff, talloc_array_length(
buff) * 2);
429 if ((ret != 0) || !*
out) {
436 talloc_set_type(
buff,
struct group);
454 struct passwd *result;
457 if (ret < 0)
return -1;
459 *
out = result->pw_uid;
476 struct group *result;
479 if (ret < 0)
return -1;
481 *
out = result->gr_gid;
496 struct passwd *result;
515 struct group *result;
534 struct passwd *user = NULL;
535 struct group *group = NULL;
542 fr_strerror_printf(
"Effective user/group - %s:%s: %s", user->pw_name, group->gr_name, error);
strcpy(log_entry->msg, buffer)
#define FALL_THROUGH
clang 10 doesn't recognised the FALL-THROUGH comment anymore
#define check(_handle, _len_p)
int fr_perm_getgrnam(TALLOC_CTX *ctx, struct group **out, char const *name)
Resolve a group name to a group database entry.
char * fr_perm_uid_to_str(TALLOC_CTX *ctx, uid_t uid)
Print uid to a string.
char const * fr_perm_mode_to_str(char out[static 10], mode_t mode)
Convert mode_t into humanly readable permissions flags.
char const * fr_perm_mode_to_oct(char out[static 5], mode_t mode)
int fr_perm_mode_from_str(mode_t *out, char const *str)
char * fr_perm_gid_to_str(TALLOC_CTX *ctx, uid_t gid)
Print gid to a string.
int fr_perm_getgrgid(TALLOC_CTX *ctx, struct group **out, gid_t gid)
Resolve a gid to a group database entry.
int fr_perm_getpwnam(TALLOC_CTX *ctx, struct passwd **out, char const *name)
Resolve a username to a passwd entry.
int fr_perm_uid_from_str(TALLOC_CTX *ctx, uid_t *out, char const *name)
Resolve a user name to a GID.
int fr_perm_getpwuid(TALLOC_CTX *ctx, struct passwd **out, uid_t uid)
Resolve a uid to a passwd entry.
int fr_perm_gid_from_str(TALLOC_CTX *ctx, gid_t *out, char const *name)
Resolve a group name to a GID.
void fr_perm_file_error(int num)
Write a file access error to the fr_strerror buffer, including euid/egid.
static char buff[sizeof("18446744073709551615")+3]
char const * fr_syserror(int num)
Guaranteed to be thread-safe version of strerror.
char * talloc_typed_strdup(TALLOC_CTX *ctx, char const *p)
Call talloc_strdup, setting the type on the new chunk correctly.
#define fr_strerror_printf(_fmt,...)
Log to thread local error buffer.
#define fr_strerror_const(_msg)
static size_t char ** out