Skip to content
Snippets Groups Projects
Commit f3c59c89 authored by Eric Vidal's avatar Eric Vidal :speech_balloon:
Browse files

add name_isvalid(), set_ownersysdir_stack(), set_ownerhome_stack() functions

parent e37666f9
No related branches found
No related tags found
No related merge requests found
/*
* 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") ;
}
......@@ -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 ;
}
......@@ -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 ;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment