23 RCSID(
"$Id: e8ea254e769cfeedb1382a39faf547c22ba617e3 $")
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);
89 #ifdef _SC_GETPW_R_SIZE_MAX
92 sc_len = sysconf(_SC_GETPW_R_SIZE_MAX);
93 if (sc_len <= 0) sc_len = 1024;
100 buff = talloc_array(ctx,
uint8_t,
sizeof(
struct passwd) + len);
101 if (!
buff)
return -1;
107 while ((ret = getpwuid_r(uid, (
struct passwd *)
buff, (
char *)(
buff +
sizeof(
struct passwd)),
108 talloc_array_length(
buff) -
sizeof(
struct passwd),
out)) == ERANGE) {
109 buff = talloc_realloc_size(ctx,
buff, talloc_array_length(
buff) * 2);
112 if ((ret != 0) || !*
out) {
119 talloc_set_type(
buff,
struct passwd);
152 #ifdef _SC_GETPW_R_SIZE_MAX
155 sc_len = sysconf(_SC_GETPW_R_SIZE_MAX);
156 if (sc_len <= 0) sc_len = 1024;
163 buff = talloc_array(ctx,
uint8_t,
sizeof(
struct passwd) + len);
164 if (!
buff)
return -1;
170 while ((ret = getpwnam_r(
name, (
struct passwd *)
buff, (
char *)(
buff +
sizeof(
struct passwd)),
171 talloc_array_length(
buff) -
sizeof(
struct passwd),
out)) == ERANGE) {
172 buff = talloc_realloc_size(ctx,
buff, talloc_array_length(
buff) * 2);
175 if ((ret != 0) || !*
out) {
182 talloc_set_type(
buff,
struct passwd);
215 #ifdef _SC_GETGR_R_SIZE_MAX
218 sc_len = sysconf(_SC_GETGR_R_SIZE_MAX);
219 if (sc_len <= 0) sc_len = 1024;
226 buff = talloc_array(ctx,
uint8_t,
sizeof(
struct group) + len);
227 if (!
buff)
return -1;
233 while ((ret = getgrgid_r(gid, (
struct group *)
buff, (
char *)(
buff +
sizeof(
struct group)),
234 talloc_array_length(
buff) -
sizeof(
struct group),
out)) == ERANGE) {
235 buff = talloc_realloc_size(ctx,
buff, talloc_array_length(
buff) * 2);
238 if ((ret != 0) || !*
out) {
245 talloc_set_type(
buff,
struct group);
278 #ifdef _SC_GETGR_R_SIZE_MAX
281 sc_len = sysconf(_SC_GETGR_R_SIZE_MAX);
282 if (sc_len <= 0) sc_len = 1024;
289 buff = talloc_array(ctx,
uint8_t,
sizeof(
struct group) + len);
290 if (!
buff)
return -1;
296 while ((ret = getgrnam_r(
name, (
struct group *)
buff, (
char *)(
buff +
sizeof(
struct group)),
297 talloc_array_length(
buff) -
sizeof(
struct group),
out)) == ERANGE) {
298 buff = talloc_realloc_size(ctx,
buff, talloc_array_length(
buff) * 2);
301 if ((ret != 0) || !*
out) {
308 talloc_set_type(
buff,
struct group);
326 struct passwd *result;
329 if (ret < 0)
return -1;
331 *
out = result->pw_uid;
348 struct group *result;
351 if (ret < 0)
return -1;
353 *
out = result->gr_gid;
368 struct passwd *result;
387 struct group *result;
406 struct passwd *user = NULL;
407 struct group *group = NULL;
414 fr_strerror_printf(
"Effective user/group - %s:%s: %s", user->pw_name, group->gr_name, error);
strcpy(log_entry->msg, buffer)
int fr_perm_getgrnam(TALLOC_CTX *ctx, struct group **out, char const *name)
Resolve a group name to a group database entry.
char const * fr_perm_mode_to_oct(char out[static 5], mode_t mode)
char const * fr_perm_mode_to_str(char out[static 10], mode_t mode)
Convert mode_t into humanly readable permissions flags.
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.
char * fr_perm_uid_to_str(TALLOC_CTX *ctx, uid_t uid)
Print uid to a string.
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.
static size_t char ** out