diff --git a/src/lib66/utils/name_isvalid.c b/src/lib66/utils/name_isvalid.c new file mode 100644 index 0000000000000000000000000000000000000000..457ad0c53691c374ad25defa4b42dd0e88b88d4b --- /dev/null +++ b/src/lib66/utils/name_isvalid.c @@ -0,0 +1,34 @@ +/* + * name_isvalid.c + * + * Copyright (c) 2018-2021 Eric Vidal <eric@obarun.org> + * + * All rights reserved. + * + * This file is part of Obarun. It is subject to the license terms in + * the LICENSE file found in the top-level directory of this + * distribution. + * This file may not be copied, modified, propagated, or distributed + * except according to the terms contained in the LICENSE file./ + */ + +#include <string.h> + +#include <oblibs/log.h> + +#include <66/constants.h> +#include <66/utils.h> + +void name_isvalid(char const *name) +{ + log_flow() ; + + if (!memcmp(name, SS_MASTER + 1, 6)) + log_die(LOG_EXIT_USER, "service name: ", name, ": starts with reserved prefix Master") ; + + if (!strcmp(name, SS_SERVICE)) + log_die(LOG_EXIT_USER, "service as service name is a reserved name") ; + + if (!strcmp(name, SS_SERVICE "@")) + log_die(LOG_EXIT_USER, "service@ as service name is a reserved name") ; +} diff --git a/src/lib66/utils/set_ownerhome.c b/src/lib66/utils/set_ownerhome.c index 9d948cfd7164ff2b482e63d52813178e8b3d6634..a69b0cbdf0b9ba5a806682cdf331c7d49ccce2ff 100644 --- a/src/lib66/utils/set_ownerhome.c +++ b/src/lib66/utils/set_ownerhome.c @@ -22,6 +22,7 @@ #include <skalibs/stralloc.h> #include <66/utils.h> +#include <66/constants.h> int set_ownerhome(stralloc *base,uid_t owner) { @@ -45,3 +46,30 @@ int set_ownerhome(stralloc *base,uid_t owner) return 1 ; } + +int set_ownerhome_stack(char *store) +{ + log_flow() ; + + char const *user_home = 0 ; + int e = errno ; + struct passwd *st = getpwuid(getuid()) ; + errno = 0 ; + if (!st) { + if (!errno) errno = ESRCH ; + return 0 ; + } + user_home = st->pw_dir ; + errno = e ; + if (!user_home) + return 0 ; + + if (strlen(user_home) + 1 > SS_MAX_PATH_LEN) { + errno = ENAMETOOLONG ; + return 0 ; + } + + auto_strings(store, user_home, "/") ; + + return 1 ; +} diff --git a/src/lib66/utils/set_ownersysdir.c b/src/lib66/utils/set_ownersysdir.c index ceb0eb6c98e30264d60bf7dbeb63128b486a2db3..494254dbd3aaa5382b768282069d50b31f873bec 100644 --- a/src/lib66/utils/set_ownersysdir.c +++ b/src/lib66/utils/set_ownersysdir.c @@ -52,3 +52,38 @@ int set_ownersysdir(stralloc *base, uid_t owner) return 1 ; } + +int set_ownersysdir_stack(char *base, uid_t owner) +{ + log_flow() ; + + char const *user_home = NULL ; + int e = errno ; + struct passwd *st = getpwuid(owner) ; + errno = 0 ; + + if (!st) { + + if (!errno) errno = ESRCH ; + return 0 ; + } + + user_home = st->pw_dir ; + + errno = e ; + + if (user_home == NULL) + return 0 ; + + if (strlen(user_home) + 1 + strlen(SS_USER_DIR) > SS_MAX_PATH_LEN) { + errno = ENAMETOOLONG ; + return 0 ; + } + + if(owner > 0) + auto_strings(base, user_home, "/", SS_USER_DIR) ; + else + auto_strings(base, SS_SYSTEM_DIR) ; + + return 1 ; +}