Development
This commit is contained in:
parent
969f4e26b8
commit
df159253cd
6
Makefile
6
Makefile
@ -4,7 +4,7 @@ OBJd := obj
|
|||||||
INCd := inc
|
INCd := inc
|
||||||
CC = gcc
|
CC = gcc
|
||||||
LDFLAGS =
|
LDFLAGS =
|
||||||
CFLAGS = -Iinclude -Iinc -Wall -O2 -g
|
CFLAGS = -Iinc -Wall -O2 -g
|
||||||
|
|
||||||
SRC = $(wildcard $(SRCd)/*.c)
|
SRC = $(wildcard $(SRCd)/*.c)
|
||||||
OBJ = $(SRC:$(SRCd)/%.c=$(OBJd)/%.o)
|
OBJ = $(SRC:$(SRCd)/%.c=$(OBJd)/%.o)
|
||||||
@ -13,7 +13,7 @@ TARGETS = $(SRC:$(SRCd)/%.c=$(BINd)/%)
|
|||||||
main: $(OBJ) $(OBJd)/nprint.o # The option of a single program instead of a suite. WARN: Requires modification of source to remove multiple main()
|
main: $(OBJ) $(OBJd)/nprint.o # The option of a single program instead of a suite. WARN: Requires modification of source to remove multiple main()
|
||||||
$(CC) $(LDFLAGS) -o $(BINd)/fex $^
|
$(CC) $(LDFLAGS) -o $(BINd)/fex $^
|
||||||
|
|
||||||
multi: $(TARGETS)
|
multi: $(TARGETS) # Makes a single executable per object instead of congealing them into a single "fex"
|
||||||
|
|
||||||
$(BINd)/%: $(OBJd)/%.o $(OBJd)/nprint.o
|
$(BINd)/%: $(OBJd)/%.o $(OBJd)/nprint.o
|
||||||
$(CC) $(LDFLAGS) -o $@ $^
|
$(CC) $(LDFLAGS) -o $@ $^
|
||||||
@ -28,4 +28,4 @@ $(OBJd)/nprint.o: $(INCd)/nprint.c $(INCd)/nprint.h
|
|||||||
clean:
|
clean:
|
||||||
rm -f $(OBJd)/*.o $(BINd)/*
|
rm -f $(OBJd)/*.o $(BINd)/*
|
||||||
|
|
||||||
.PHONY: all clean
|
.PHONY: main clean
|
10
inc/config.h
Normal file
10
inc/config.h
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
//
|
||||||
|
// Created by auric on 2/22/24.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef CONFIG_H
|
||||||
|
#define CONFIG_H
|
||||||
|
|
||||||
|
#define debugEnabled
|
||||||
|
|
||||||
|
#endif //CONFIG_H
|
16
inc/debug.h
Normal file
16
inc/debug.h
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
//
|
||||||
|
// Created by auric on 2/22/24.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef DEBUG_H
|
||||||
|
#define DEBUG_H
|
||||||
|
|
||||||
|
#include "nprint.h"
|
||||||
|
|
||||||
|
#ifdef debugEnabled
|
||||||
|
#define DEBUG_PRINT(fmt, ...) nprint("D", fmt, ##__VA_ARGS__)
|
||||||
|
#else
|
||||||
|
#define DEBUG_PRINT(fmg, ...) void(0)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif //DEBUG_H
|
13
inc/sanity.h
13
inc/sanity.h
@ -7,6 +7,17 @@
|
|||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
int sanity_check();
|
#define SANITY_SUCCESS 0 // 0000 - All checks passed
|
||||||
|
#define SANITY_CON_FAIL 1 // 0001 - /con check failed
|
||||||
|
#define SANITY_EXE_FAIL 2 // 0010 - /exe check failed
|
||||||
|
#define SANITY_UTI_FAIL 4 // 0100 - /uti check failed
|
||||||
|
|
||||||
|
/*typedef struct {
|
||||||
|
bool conEx;
|
||||||
|
bool exeEx;
|
||||||
|
bool utiEx;
|
||||||
|
} SanityCheckResult;*/
|
||||||
|
|
||||||
|
const int isSysSane();
|
||||||
|
|
||||||
#endif //SANITY_H
|
#endif //SANITY_H
|
||||||
|
BIN
obj/sanity.o
BIN
obj/sanity.o
Binary file not shown.
70
src/fex.c
70
src/fex.c
@ -6,31 +6,79 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <nprint.h>
|
#include <nprint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <sanity.h>
|
||||||
|
#include <config.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
char* opt = NULL;
|
|
||||||
void help() {
|
void help() {
|
||||||
nprint("E", "Usage: fex (OPT) (PACKAGES)");
|
nprint("E", "Usage: fex (OPT) (PACKAGES)");
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
|
int fIns = 0, fUpd = 0, fSrc = 0, fUin = 0, fLis = 0, fSer = 0, fVer = 0, fFrc = 0, fUpg = 0;
|
||||||
|
char* packages[argc - 1];
|
||||||
|
int pkgCount = 0;
|
||||||
if (argc < 2) {
|
if (argc < 2) {
|
||||||
help();
|
help();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argv[1][0] == '-' || argv[1][0] == '+' ) {
|
const char* flagNames[] = {"Install", "Update", "Source", "Remove", "List", "Search","Verbose", "Force", "Upgrade"};
|
||||||
opt = argv[1];
|
int* flagValues[] = {&fIns, &fUpd, &fSrc, &fUin, &fLis, &fSer, &fVer, &fFrc, &fUpg};
|
||||||
|
int flagCount = sizeof(flagNames) / sizeof(flagNames[0]); // This should match the number of flags
|
||||||
|
|
||||||
|
for(int i = 1; i < argc; i++) {
|
||||||
|
if(argv[i][0] == '-') {
|
||||||
|
for(int j = 1; argv[i][j] != '\0'; j++) {
|
||||||
|
switch(argv[i][j]) {
|
||||||
|
case 'i': // install
|
||||||
|
fIns = 1;
|
||||||
|
break;
|
||||||
|
case 'u': // update
|
||||||
|
fUpd = 1;
|
||||||
|
break;
|
||||||
|
case 'S': // source
|
||||||
|
fSrc = 1;
|
||||||
|
break;
|
||||||
|
case 'r': // remove
|
||||||
|
fUin = 1;
|
||||||
|
break;
|
||||||
|
case 'l': // list
|
||||||
|
fLis = 1;
|
||||||
|
break;
|
||||||
|
case 's': // search
|
||||||
|
fSer = 1;
|
||||||
|
break;
|
||||||
|
case 'v': // verbose
|
||||||
|
fVer = 1;
|
||||||
|
break;
|
||||||
|
case 'f': // force
|
||||||
|
fFrc = 1;
|
||||||
|
break;
|
||||||
|
case 'c': // upgrade; don't ask why I'm using 'c'
|
||||||
|
fUpg = 1;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
nprint("E", "Flag '%c' is unknown.", argv[i][j]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
nprint("E", "First argument must be OPT");
|
packages[pkgCount++] = argv[i];
|
||||||
return 1;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opt[0] == '+' && opt[1] != '\0') {
|
const int sysSanity = isSysSane();
|
||||||
nprint("D", "Placeholder");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (argc < 3) {
|
#ifdef debugEnabled
|
||||||
nprint("E", "No packages specified");
|
for(int i = 0; i < flagCount; i++) {
|
||||||
return 1;
|
nprint("D", "Flag %s: %d", flagNames[i], *flagValues[i]);
|
||||||
}
|
}
|
||||||
|
for(int i = 0; i < pkgCount; i++) {
|
||||||
|
nprint("D", "Package %d: %s", i, packages[i]);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
59
src/sanity.c
59
src/sanity.c
@ -1,28 +1,47 @@
|
|||||||
//
|
#include <sys/stat.h>
|
||||||
// Created by auric on 2/22/24.
|
#include <unistd.h>
|
||||||
//
|
#include <sanity.h>
|
||||||
|
#include <nprint.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 0: Success
|
* 0: success
|
||||||
* 1: Failure
|
* 1: con failure
|
||||||
* 2: Root check failure
|
* 2: exe failure
|
||||||
* 3: /con check failure
|
* 3: con and exe failure
|
||||||
* 4: /exe check filuse
|
* 4: uti failure
|
||||||
* 5: /con and /exe check failure
|
* 5: uti and con failure
|
||||||
|
* 6: uti and exe failure
|
||||||
|
* 7: total failure
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sanity.h>
|
/*SanityCheckResult isSane() {
|
||||||
#include <unistd.h>
|
struct stat conStat, exeStat, utiStat;
|
||||||
|
SanityCheckResult result = {true, true, true}; // Default to true, assume checks will pass*/
|
||||||
|
struct stat conStat;
|
||||||
|
struct stat exeStat;
|
||||||
|
struct stat utiStat;
|
||||||
|
int result;
|
||||||
|
|
||||||
bool isSane = true;
|
const int isSysSane() {
|
||||||
bool isRoot = false;
|
if (stat("/con", &conStat) != 0 || !(conStat.st_mode & S_IWUSR)) {
|
||||||
|
//result.conEx = false;
|
||||||
int sanity_check() {
|
result |= SANITY_CON_FAIL;
|
||||||
if (getuid() == 0) {
|
|
||||||
isRoot = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (stat("/exe", &exeStat) != 0 || !(exeStat.st_mode & S_IWUSR)) {
|
||||||
|
//result.exeEx = false;
|
||||||
return 0;
|
result |= SANITY_EXE_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (stat("/uti", &utiStat) != 0 || !(utiStat.st_mode & S_IWUSR)) {
|
||||||
|
//result.utiEx = false;
|
||||||
|
result |= SANITY_UTI_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*nprint("D", "con: %d", result.conEx);
|
||||||
|
nprint("D", "exe: %d", result.exeEx);
|
||||||
|
nprint("D", "uti: %d", result.utiEx);*/
|
||||||
|
//nprint("D", "Result: %d", sumResult);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user