Skip to content

Commit

Permalink
Add fr_perm_mode_from_str()
Browse files Browse the repository at this point in the history
  • Loading branch information
alandekok committed Nov 29, 2024
1 parent e0d9806 commit 83d573a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/lib/util/perm.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,24 @@ char const *fr_perm_mode_to_oct(char out[static 5], mode_t mode)
return out;
}

int fr_perm_mode_from_str(mode_t *out, char const *str)
{
if (*str == '0') {
unsigned long mode;
char *end = NULL;

mode = strtoul(str, &end, 7);
if (*end || (mode == ULONG_MAX)) {
return -1;
}

*out = mode;
return 0;
}

return -1;
}

/** Resolve a uid to a passwd entry
*
* Resolves a uid to a passwd entry. The memory to hold the
Expand Down
2 changes: 2 additions & 0 deletions src/lib/util/perm.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ char const *fr_perm_mode_to_str(char out[static 10], mode_t mode);

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) CC_HINT(nonnull);

int fr_perm_getpwuid(TALLOC_CTX *ctx, struct passwd **out, uid_t uid) CC_HINT(nonnull(2));

int fr_perm_getpwnam(TALLOC_CTX *ctx, struct passwd **out, char const *name) CC_HINT(nonnull(2,3));
Expand Down

0 comments on commit 83d573a

Please sign in to comment.