Working as of 12/11
This commit is contained in:
1 parent
e591b71143
commit
e79c96a987
29 files changed
+664
-48
No files matched your search
@@ -0,0 +1,184 @@
|
||||
#include <errno.h>
|
||||
#include <linux/limits.h>
|
||||
#include <limits.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "common.h"
|
||||
#include "log.h"
|
||||
#include "pkg.h"
|
||||
|
||||
typedef enum
|
||||
{
|
||||
INDEX,
|
||||
STORE
|
||||
}
|
||||
index_store_t;
|
||||
|
||||
static const dir_t usr_index = { "/glacier/usr/index", 0700 };
|
||||
static const dir_t sys_index = { "/glacier/sys/index", 0700 };
|
||||
|
||||
static const dir_t usr_store = { "/glacier/usr/store", 0700 };
|
||||
static const dir_t sys_store = { "/glacier/sys/store", 0700 };
|
||||
|
||||
bool
|
||||
gl_usr_istore_exists(index_store_t index_or_store, int uid)
|
||||
{
|
||||
char path[PATH_MAX];
|
||||
struct stat st;
|
||||
|
||||
switch (index_or_store) {
|
||||
case INDEX:
|
||||
snprintf(path, sizeof(path), "%s/%d", usr_index.path, uid);
|
||||
break;
|
||||
case STORE:
|
||||
snprintf(path, sizeof(path), "%s/%d", usr_store.path, uid);
|
||||
break;
|
||||
default:
|
||||
printf("libglacier: argument index_or_store of function gl_usr_istore_exists must be INDEX or STORE\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (stat(path, &st) != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return S_ISDIR(st.st_mode);
|
||||
}
|
||||
|
||||
bool
|
||||
gl_sys_istore_exists(index_store_t index_or_store)
|
||||
{
|
||||
char path[PATH_MAX];
|
||||
struct stat st;
|
||||
|
||||
switch (index_or_store) {
|
||||
case INDEX:
|
||||
snprintf(path, sizeof(path), "%s", sys_index.path);
|
||||
break;
|
||||
case STORE:
|
||||
snprintf(path, sizeof(path), "%s", sys_store.path);
|
||||
break;
|
||||
default:
|
||||
printf("libglacier: argument index_or_store of function gl_sys_istore_exists must be INDEX or STORE\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (stat(path, &st) != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return S_ISDIR(st.st_mode);
|
||||
}
|
||||
|
||||
int
|
||||
gl_init_user(int uid)
|
||||
{
|
||||
if (uid < 1000) {
|
||||
return 2;
|
||||
}
|
||||
|
||||
char ind_path[PATH_MAX];
|
||||
char sto_path[PATH_MAX];
|
||||
|
||||
snprintf(ind_path, sizeof(ind_path), "%s/%d", usr_index.path, uid);
|
||||
snprintf(sto_path, sizeof(sto_path), "%s/%d", usr_store.path, uid);
|
||||
|
||||
if (mkdir(ind_path, 0700) == -1) {
|
||||
switch (errno) {
|
||||
case EACCES:
|
||||
lg_printf(2, "Cannot create index: permission denied");
|
||||
return 1;
|
||||
break;
|
||||
case EEXIST:
|
||||
lg_printf(2, "Cannot create index: directory already exists");
|
||||
return 1;
|
||||
break;
|
||||
case ENOENT:
|
||||
/* should never happen, but here for completeness */
|
||||
lg_printf(2, "Cannot create index: parent directory does not exist");
|
||||
return 1;
|
||||
break;
|
||||
case ENOSPC:
|
||||
lg_printf(2, "Cannot create index: no space left on device");
|
||||
return 1;
|
||||
break;
|
||||
case EROFS:
|
||||
lg_printf(2, "Cannot create index: read only filesystem");
|
||||
return 1;
|
||||
break;
|
||||
default:
|
||||
printf("libglacier: mkdir error in function gl_init_user\n");
|
||||
return -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (mkdir(sto_path, 0700) == -1) {
|
||||
switch (errno) {
|
||||
case EACCES:
|
||||
lg_printf(2, "Cannot create store: permission denied");
|
||||
return 1;
|
||||
break;
|
||||
case EEXIST:
|
||||
lg_printf(2, "Cannot create store: directory already exists");
|
||||
return 1;
|
||||
break;
|
||||
case ENOENT:
|
||||
/* should never happen, but here for completeness */
|
||||
lg_printf(2, "Cannot create store: parent directory does not exist");
|
||||
return 1;
|
||||
break;
|
||||
case ENOSPC:
|
||||
lg_printf(2, "Cannot create store: no space left on device");
|
||||
return 1;
|
||||
break;
|
||||
case EROFS:
|
||||
lg_printf(2, "Cannot create store: read only filesystem");
|
||||
return 1;
|
||||
break;
|
||||
default:
|
||||
printf("libglacier: mkdir error in function gl_init_user\n");
|
||||
return -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
trim(char *s)
|
||||
{
|
||||
char *p = s;
|
||||
while (*p && isspace((unsigned char)*p)) {
|
||||
p++;
|
||||
}
|
||||
|
||||
if (p != s) {
|
||||
memmove(s, p, strlen(p) + 1);
|
||||
}
|
||||
|
||||
size_t len = strlen(s);
|
||||
while (len && isspace((unsigned char)s[len - 1])) {
|
||||
s[len--] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static char
|
||||
*dupstr(const char *s)
|
||||
{
|
||||
size_t n = strlen(s);
|
||||
char *p = malloc(n + 1);
|
||||
if (!p) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memcpy(p, s, n + 1);
|
||||
return p;
|
||||
}
|
||||
|
||||
int
|
||||
gl_parse_index(struct gindex *idx, FILE *f)
|
||||
{}
|
||||
Reference in new issue
Block a user