diff --git a/src/lib/util/perm.c b/src/lib/util/perm.c index e8ea254e769c..c2cb38b91c3c 100644 --- a/src/lib/util/perm.c +++ b/src/lib/util/perm.c @@ -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 diff --git a/src/lib/util/perm.h b/src/lib/util/perm.h index 057e7133afe4..474db39bb215 100644 --- a/src/lib/util/perm.h +++ b/src/lib/util/perm.h @@ -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));