Development

This commit is contained in:
John Barns 2024-02-22 23:34:30 -06:00
parent 969f4e26b8
commit df159253cd
9 changed files with 141 additions and 37 deletions

View File

@ -4,7 +4,7 @@ OBJd := obj
INCd := inc
CC = gcc
LDFLAGS =
CFLAGS = -Iinclude -Iinc -Wall -O2 -g
CFLAGS = -Iinc -Wall -O2 -g
SRC = $(wildcard $(SRCd)/*.c)
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()
$(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
$(CC) $(LDFLAGS) -o $@ $^
@ -28,4 +28,4 @@ $(OBJd)/nprint.o: $(INCd)/nprint.c $(INCd)/nprint.h
clean:
rm -f $(OBJd)/*.o $(BINd)/*
.PHONY: all clean
.PHONY: main clean

BIN
bin/fex

Binary file not shown.

10
inc/config.h Normal file
View 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
View 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

View File

@ -5,8 +5,19 @@
#ifndef SANITY_H
#define SANITY_H
# 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

BIN
obj/fex.o

Binary file not shown.

Binary file not shown.

View File

@ -6,31 +6,79 @@
#include <stdio.h>
#include <string.h>
#include <nprint.h>
#include <stdbool.h>
#include <sanity.h>
#include <config.h>
char* opt = NULL;
void help() {
nprint("E", "Usage: fex (OPT) (PACKAGES)");
}
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) {
help();
return 1;
}
if (argv[1][0] == '-' || argv[1][0] == '+' ) {
opt = argv[1];
} else {
nprint("E", "First argument must be OPT");
return 1;
const char* flagNames[] = {"Install", "Update", "Source", "Remove", "List", "Search","Verbose", "Force", "Upgrade"};
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 {
packages[pkgCount++] = argv[i];
}
}
if (opt[0] == '+' && opt[1] != '\0') {
nprint("D", "Placeholder");
}
const int sysSanity = isSysSane();
if (argc < 3) {
nprint("E", "No packages specified");
return 1;
}
#ifdef debugEnabled
for(int i = 0; i < flagCount; i++) {
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;
}

View File

@ -1,28 +1,47 @@
//
// Created by auric on 2/22/24.
//
#include <sys/stat.h>
#include <unistd.h>
#include <sanity.h>
#include <nprint.h>
/*
* 0: Success
* 1: Failure
* 2: Root check failure
* 3: /con check failure
* 4: /exe check filuse
* 5: /con and /exe check failure
* 0: success
* 1: con failure
* 2: exe failure
* 3: con and exe failure
* 4: uti failure
* 5: uti and con failure
* 6: uti and exe failure
* 7: total failure
*/
#include <sanity.h>
#include <unistd.h>
/*SanityCheckResult isSane() {
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;
bool isRoot = false;
int sanity_check() {
if (getuid() == 0) {
isRoot = true;
const int isSysSane() {
if (stat("/con", &conStat) != 0 || !(conStat.st_mode & S_IWUSR)) {
//result.conEx = false;
result |= SANITY_CON_FAIL;
}
if (stat("/exe", &exeStat) != 0 || !(exeStat.st_mode & S_IWUSR)) {
//result.exeEx = false;
result |= SANITY_EXE_FAIL;
}
if (stat("/uti", &utiStat) != 0 || !(utiStat.st_mode & S_IWUSR)) {
//result.utiEx = false;
result |= SANITY_UTI_FAIL;
}
return 0;
/*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;
}