58 lines
1.8 KiB
C
58 lines
1.8 KiB
C
#include <sys/stat.h>
|
|
#include "../inc/sanity.h"
|
|
#include "../inc/fex.h"
|
|
#include "../inc/nprint.h"
|
|
#include "../inc/config.h"
|
|
|
|
/*
|
|
* Uses bitwise operations to determine the sanity of the system's directory hierarchy. In particular, it checks if the directories of
|
|
* /con
|
|
* /exe
|
|
* /uti
|
|
* /uti/lib
|
|
* /uti/hdr
|
|
* exist, and if the owner can write to them. This notably does not check if the program is run as superuser.
|
|
*/
|
|
|
|
int isSysSane() {
|
|
struct stat conStat, exeStat, utiStat, libStat, hdrStat;
|
|
int result = 0;
|
|
|
|
char* directoryNames[] = {"/con", "/exe", "/uti", "/uti/lib", "/uti/hdr"};
|
|
struct stat* statVars[] = {&conStat, &exeStat, &utiStat, &libStat, &hdrStat};
|
|
int flags[] = {SANITY_CON_FAIL, SANITY_EXE_FAIL, SANITY_UTI_FAIL, SANITY_LIB_FAIL, SANITY_HDR_FAIL};
|
|
const int numDirectories = sizeof(directoryNames) / sizeof(directoryNames[0]);
|
|
|
|
for(int i = 0; i < numDirectories; i++) {
|
|
if(stat(directoryNames[i], statVars[i]) != 0 || !(statVars[i]->st_mode & S_IWUSR)) {
|
|
result |= flags[i];
|
|
}
|
|
};
|
|
|
|
return result;
|
|
}
|
|
|
|
int isSyntaxSane(unsigned int flags, int pkgCount) {
|
|
if((flags & FLAG_INSTALL) && (flags & FLAG_REMOVE)) {
|
|
nprint("E", "You cannot install and uninstall at the same time"); // Sequential parsing of flags would leave so many ambiguous cases and expand these checks greatly. Not worth it without extensive research
|
|
return ERROR;
|
|
}
|
|
|
|
if((flags & FLAG_INSTALL) && (pkgCount == 0)) {
|
|
nprint("E", "You must specify at least one package");
|
|
return ERROR;
|
|
}
|
|
|
|
if(flags == FLAG_FORCE) {
|
|
nprint("E", "Force may not be used alone");
|
|
return ERROR;
|
|
}
|
|
|
|
if(/*(flags == FLAG_LIST) || */flags == FLAG_SEARCH) {
|
|
nprint("E", "List and search must be used alone");
|
|
return ERROR;
|
|
}
|
|
|
|
return OK;
|
|
}
|