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

Provide default environment directories.

These directories is used to properly define environment variable
at start of a scandir
parent adf7d14b
No related branches found
No related tags found
No related merge requests found
......@@ -49,16 +49,18 @@ static void set_info(ssexec_t *info)
log_die_nomem("stralloc") ;
if(r < 0)
log_die(LOG_EXIT_SYS, "scandir: ", info->scandir.s, " must be an absolute path") ;
if (!set_environment(&info->environment, info->owner))
log_dieusys(LOG_EXIT_ZERO, "set environment") ;
}
static void info_clean(ssexec_t *info)
{
info->base.len = 0 ;
info->live.len = 0 ;
info->scandir.len = 0 ;
info->treename.len = 0 ;
info->environment.len = 0 ;
}
int main(int argc, char const *const *argv)
......
......@@ -45,6 +45,8 @@ struct ssexec_s
//char treename[SS_MAX_SERVICE] ;
//size_t treenamelen ;
stralloc environment ;
uint8_t treeallow ; //1 yes , 0 no
uid_t owner ;
char ownerstr[UID_FMT] ;
......@@ -67,6 +69,7 @@ struct ssexec_s
.live = STRALLOC_ZERO, \
.scandir = STRALLOC_ZERO, \
.treename = STRALLOC_ZERO, \
.environment = STRALLOC_ZERO, \
.treeallow = 0, \
.owner = 0, \
.ownerstr = { 0 }, \
......
......@@ -40,6 +40,7 @@ extern int set_livetree(stralloc *live,uid_t owner) ;
extern int set_livestate(stralloc *live,uid_t owner) ;
extern int set_ownerhome(stralloc *base,uid_t owner) ;
extern int set_ownersysdir(stralloc *base,uid_t owner) ;
extern int set_environment(stralloc *env,uid_t owner) ;
extern int read_svfile(stralloc *sasv,char const *name,char const *src) ;
extern int sa_pointo(stralloc *sa, ssexec_t *info, int type, unsigned int where) ;
......
......@@ -93,6 +93,7 @@ int sanitize_system(ssexec_t *info)
auto_check(SS_SCRIPT_SYSDIR) ;
auto_check(SS_SEED_ADMDIR) ;
auto_check(SS_SEED_SYSDIR) ;
auto_check(SS_ENVIRONMENT_ADMDIR) ;
} else {
......@@ -121,6 +122,9 @@ int sanitize_system(ssexec_t *info)
auto_strings(target + homelen, SS_SEED_USERDIR) ;
auto_check(target) ;
auto_strings(target + homelen, SS_ENVIRONMENT_USERDIR) ;
auto_check(target) ;
}
auto_strings(dst, info->base.s, SS_SYSTEM, SS_RESOLVE, SS_SERVICE) ;
......
get_userhome.o
name_isvalid.o
read_svfile.o
set_environment.o
set_livedir.o
set_livescan.o
set_livestate.o
......
/*
* set_environment.c
*
* Copyright (c) 2018-2024 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 <sys/types.h>
#include <stddef.h>
#include <oblibs/log.h>
#include <oblibs/string.h>
#include <skalibs/stralloc.h>
#include <skalibs/types.h>
#include <66/constants.h>
#include <66/utils.h>
int set_environment(stralloc *sa, uid_t owner)
{
log_flow() ;
char ownerpack[UID_FMT] ;
if (!owner) {
if (!auto_stra(sa, SS_ENVIRONMENT_ADMDIR, "/"))
log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ;
} else {
size_t ownerlen = uid_fmt(ownerpack,owner) ;
ownerpack[ownerlen] = 0 ;
if (!set_ownerhome(sa, owner))
log_warnusys_return(LOG_EXIT_ZERO, "set home directory") ;
if (!auto_stra(sa, SS_ENVIRONMENT_USERDIR, "/"))
log_die_nomem("stralloc") ;
}
return 1 ;
}
\ No newline at end of file
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