mirror of
https://github.com/troglobit/finit.git
synced 2026-11-19 19:40:50 +00:00
Refactor; common nomenclature, ordering, possib. security fix
- Use _PATH_foo for all condition paths, *with* trailing / - Read condition file first, may not exist, in which case we save time - Change from libte makepath() to mkpath(), this changes from hard-coded 0777 perms on all cond dirs to 0755 -- possible security fix Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
1 parent
32ca117949
commit
e3c8febe3b
4 files changed
+23
-21
No files matched your search
+11
-10
@@ -99,13 +99,13 @@ static void cond_bump_reconf(void)
|
|||||||
unsigned int rgen;
|
unsigned int rgen;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If %COND_RECONF does not exist, cond_get_gen() returns 0
|
* If %_PATH_RECONF does not exist, cond_get_gen() returns 0
|
||||||
* meaning that rgen++ is always what we want.
|
* meaning that rgen++ is always what we want.
|
||||||
*/
|
*/
|
||||||
rgen = cond_get_gen(COND_RECONF);
|
rgen = cond_get_gen(_PATH_RECONF);
|
||||||
rgen++;
|
rgen++;
|
||||||
|
|
||||||
cond_set_gen(COND_RECONF, rgen);
|
cond_set_gen(_PATH_RECONF, rgen);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int cond_checkpath(const char *path)
|
static int cond_checkpath(const char *path)
|
||||||
@@ -119,7 +119,7 @@ static int cond_checkpath(const char *path)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (makepath(dir) && errno != EEXIST) {
|
if (mkpath(dir, 0755) && errno != EEXIST) {
|
||||||
_pe("Failed creating dir '%s' for condition '%s'", dir, path);
|
_pe("Failed creating dir '%s' for condition '%s'", dir, path);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -134,7 +134,7 @@ int cond_set_path(const char *path, enum cond_state new)
|
|||||||
|
|
||||||
_d("%s", path);
|
_d("%s", path);
|
||||||
|
|
||||||
rgen = cond_get_gen(COND_RECONF);
|
rgen = cond_get_gen(_PATH_RECONF);
|
||||||
if (!rgen) {
|
if (!rgen) {
|
||||||
_e("Unable to read configuration generation (%s)", path);
|
_e("Unable to read configuration generation (%s)", path);
|
||||||
return -1;
|
return -1;
|
||||||
@@ -201,7 +201,8 @@ void cond_set_oneshot(const char *name)
|
|||||||
if (cond_checkpath(path))
|
if (cond_checkpath(path))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
symlink(COND_RECONF, path);
|
if (symlink(_PATH_RECONF, path) && errno != EEXIST)
|
||||||
|
_pe("Failed creating onshot cond %s", name);
|
||||||
cond_update(name);
|
cond_update(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -234,13 +235,13 @@ static int reassert(const char *fpath, const struct stat *sb, int tflg, struct F
|
|||||||
if (tflg != FTW_F)
|
if (tflg != FTW_F)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
nm = strstr((char *)fpath, COND_DIR);
|
nm = strstr((char *)fpath, COND_BASE);
|
||||||
if (!nm) {
|
if (!nm) {
|
||||||
_e("Incorrect condtion path %s, cannot reassert", fpath);
|
_e("Incorrect condtion path %s, cannot reassert", fpath);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
nm += sizeof(COND_DIR);
|
nm += strlen(COND_BASE);
|
||||||
_d("Reasserting %s => %s", fpath, nm);
|
_d("Reasserting %s => %s", fpath, nm);
|
||||||
cond_set(nm);
|
cond_set(nm);
|
||||||
|
|
||||||
@@ -261,8 +262,8 @@ void cond_init(void)
|
|||||||
{
|
{
|
||||||
char path[MAX_ARG_LEN];
|
char path[MAX_ARG_LEN];
|
||||||
|
|
||||||
if (makepath(pid_runpath(COND_PATH, path, sizeof(path))) && errno != EEXIST) {
|
if (mkpath(pid_runpath(_PATH_COND, path, sizeof(path)), 0755) && errno != EEXIST) {
|
||||||
_pe("Failed creating condition base directory '%s'", COND_PATH);
|
_pe("Failed creating condition base directory '%s'", _PATH_COND);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+5
-5
@@ -45,7 +45,7 @@ const char *cond_path(const char *name)
|
|||||||
static char path[256];
|
static char path[256];
|
||||||
char tmp[MAX_ARG_LEN];
|
char tmp[MAX_ARG_LEN];
|
||||||
|
|
||||||
snprintf(tmp, sizeof(tmp), COND_PATH "/%s", name);
|
snprintf(tmp, sizeof(tmp), _PATH_COND "%s", name);
|
||||||
|
|
||||||
return pid_runpath(tmp, path, sizeof(path));
|
return pid_runpath(tmp, path, sizeof(path));
|
||||||
}
|
}
|
||||||
@@ -74,14 +74,14 @@ enum cond_state cond_get_path(const char *path)
|
|||||||
{
|
{
|
||||||
int cgen, rgen;
|
int cgen, rgen;
|
||||||
|
|
||||||
rgen = cond_get_gen(COND_RECONF);
|
|
||||||
if (!rgen)
|
|
||||||
return COND_OFF;
|
|
||||||
|
|
||||||
cgen = cond_get_gen(path);
|
cgen = cond_get_gen(path);
|
||||||
if (!cgen)
|
if (!cgen)
|
||||||
return COND_OFF;
|
return COND_OFF;
|
||||||
|
|
||||||
|
rgen = cond_get_gen(_PATH_RECONF);
|
||||||
|
if (!rgen)
|
||||||
|
return COND_OFF;
|
||||||
|
|
||||||
return (cgen == rgen) ? COND_ON : COND_FLUX;
|
return (cgen == rgen) ? COND_ON : COND_FLUX;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+6
-3
@@ -4,9 +4,12 @@
|
|||||||
#include <paths.h>
|
#include <paths.h>
|
||||||
#include <svc.h>
|
#include <svc.h>
|
||||||
|
|
||||||
#define COND_DIR "finit/cond"
|
#define COND_BASE "finit/cond"
|
||||||
#define COND_PATH _PATH_VARRUN COND_DIR
|
#define COND_USR "usr/"
|
||||||
#define COND_RECONF COND_PATH "/reconf"
|
|
||||||
|
#define _PATH_COND _PATH_VARRUN COND_BASE "/"
|
||||||
|
#define _PATH_CONDUSR _PATH_COND COND_USR
|
||||||
|
#define _PATH_RECONF _PATH_COND "reconf"
|
||||||
|
|
||||||
typedef enum cond_state {
|
typedef enum cond_state {
|
||||||
COND_OFF = 0,
|
COND_OFF = 0,
|
||||||
|
|||||||
+1
-3
@@ -42,8 +42,6 @@
|
|||||||
#include "service.h"
|
#include "service.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
#define _PATH_COND _PATH_VARRUN "finit/cond/"
|
|
||||||
|
|
||||||
#define NONE " "
|
#define NONE " "
|
||||||
#define PIPE plain ? "|" : "│"
|
#define PIPE plain ? "|" : "│"
|
||||||
#define FORK plain ? "|-" : "├─"
|
#define FORK plain ? "|-" : "├─"
|
||||||
@@ -256,7 +254,7 @@ static int dump_one_cond(const char *fpath, const struct stat *sb, int tflag, st
|
|||||||
if (tflag != FTW_F)
|
if (tflag != FTW_F)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (!strcmp(fpath, _PATH_COND "reconf"))
|
if (!strcmp(fpath, _PATH_RECONF))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
asserted = condstr(cond_get_path(fpath));
|
asserted = condstr(cond_get_path(fpath));
|
||||||
|
|||||||
Reference in new issue
Block a user