Compare commits
No commits in common. "a683e1783f6b774ce1102886cd0c19d9a3df59f5" and "19d04b9f494c2f19bf4c28725abb783f57d9c971" have entirely different histories.
a683e1783f
...
19d04b9f49
|
@ -35,10 +35,11 @@ AC_CHECK_INCLUDES_DEFAULT
|
|||
AC_C_CONST
|
||||
AC_C_INLINE
|
||||
|
||||
AC_CHECK_FUNCS_ONCE(strtoull)
|
||||
|
||||
AC_CHECK_HEADERS(m4_normalize([
|
||||
libgen.h
|
||||
getopt.h
|
||||
sys/random.h
|
||||
]))
|
||||
|
||||
AC_CHECK_TYPES([struct option], [], [],
|
||||
|
@ -48,8 +49,6 @@ AC_CHECK_TYPES([struct option], [], [],
|
|||
|
||||
AC_CHECK_FUNCS(m4_normalize([
|
||||
getopt_long
|
||||
strtoull
|
||||
getrandom
|
||||
]))
|
||||
|
||||
AC_CONFIG_FILES([Makefile
|
||||
|
|
|
@ -2,4 +2,4 @@ SUBDIRS = tests
|
|||
|
||||
noinst_LIBRARIES = libcrypto.a
|
||||
AM_CFLAGS = -I$(top_srcdir)
|
||||
libcrypto_a_SOURCES = hchacha.c xchacha.c random.c
|
||||
libcrypto_a_SOURCES = hchacha.c xchacha.c
|
|
@ -1,57 +0,0 @@
|
|||
#include "random.h"
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif /* HAVE_CONFIG_H */
|
||||
#ifdef _WIN32
|
||||
# include <windows.h>
|
||||
# include <ntsecapi.h>
|
||||
#else
|
||||
# ifdef HAVE_SYS_RANDOM_H
|
||||
# include <sys/random.h>
|
||||
# else
|
||||
# include <stdio.h>
|
||||
# endif /* HAVE_SYS_RANDOM_H */
|
||||
#endif /* _WIN32 */
|
||||
|
||||
int
|
||||
crypto_random(uint8_t *buff, size_t size)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
return (RtlGenRandom(buff, size));
|
||||
#else
|
||||
# ifdef HAVE_GETRANDOM
|
||||
ssize_t ret;
|
||||
|
||||
ret = getrandom(buff, size, 0)
|
||||
if (ret < size)
|
||||
{
|
||||
return (-1);
|
||||
}
|
||||
# else
|
||||
FILE *fp;
|
||||
size_t total;
|
||||
size_t byte_read;
|
||||
|
||||
fp = fopen("/dev/urandom", "rb");
|
||||
if (fp == NULL)
|
||||
{
|
||||
return (-1);
|
||||
}
|
||||
|
||||
total = 0;
|
||||
do {
|
||||
byte_read = fread(buff + total, 1, size - total, fp);
|
||||
if (byte_read == 0)
|
||||
{
|
||||
fclose(fp);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
total += byte_read;
|
||||
} while (total < size);
|
||||
|
||||
fclose(fp);
|
||||
# endif /* HAVE_GETRANDOM */
|
||||
#endif /* _WIN32 */
|
||||
return (0);
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
#ifndef CRYPTO_RANDOM_H
|
||||
# define CRYPTO_RANDOM_H 1
|
||||
|
||||
# include <stdint.h>
|
||||
|
||||
int crypto_random(uint8_t *buff, size_t size);
|
||||
|
||||
#endif /* CRYPTO_RANDOM_H */
|
|
@ -1,11 +1,9 @@
|
|||
TESTS = test_hchacha test_xchacha test_random
|
||||
check_PROGRAMS = test_hchacha test_xchacha test_random
|
||||
TESTS = test_hchacha test_xchacha
|
||||
check_PROGRAMS = test_hchacha test_xchacha
|
||||
|
||||
AM_CFLAGS = -I../
|
||||
LDADD = -lcmocka ../libcrypto.a
|
||||
|
||||
test_hchacha_SOURCES = test_hchacha.c
|
||||
|
||||
test_xchacha_SOURCES = test_xchacha.c
|
||||
|
||||
test_random_SOURCES = test_random.c
|
||||
test_xchacha_SOURCES = test_xchacha.c
|
|
@ -1,28 +0,0 @@
|
|||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <setjmp.h>
|
||||
#include <cmocka.h>
|
||||
|
||||
#include "random.h"
|
||||
|
||||
/* test from https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-xchacha-03#section-2.2 */
|
||||
|
||||
|
||||
static void
|
||||
test_random(void **state)
|
||||
{
|
||||
uint8_t buff[512];
|
||||
|
||||
assert_return_code(crypto_random(buff, 512), 0);
|
||||
}
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test(test_random),
|
||||
};
|
||||
|
||||
return cmocka_run_group_tests(tests, NULL, NULL);
|
||||
}
|
|
@ -8,7 +8,7 @@ bin_PROGRAMS = mkfs.stpd tools.stpd inspect.stpd
|
|||
mkfs_stpd_SOURCES = mkfs/main.c
|
||||
mkfs_stpd_LDADD = ../libfs/libfs.a mkfs/bootsector.o
|
||||
|
||||
tools_stpd_SOURCES = tools/main.c tools/ls.c tools/ls/colors.c tools/copy.c tools/mkdir.c tools/rm.c
|
||||
tools_stpd_SOURCES = tools/main.c tools/ls.c tools/copy.c tools/mkdir.c tools/rm.c
|
||||
|
||||
inspect_stpd_SOURCES = inspect/main.c
|
||||
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
#endif /* HAVE_GETOPT_H */
|
||||
#include <stupidfs.h>
|
||||
#include "libfs/fs.h"
|
||||
#include "ls/colors.h"
|
||||
|
||||
#ifdef HAVE_STRUCT_OPTION
|
||||
static struct option long_options[] = {
|
||||
|
@ -173,59 +172,26 @@ print_size(struct fs_inode *ip)
|
|||
static void
|
||||
print_name(struct stpdfs_dirent *dirent, struct fs_inode *ip)
|
||||
{
|
||||
enum COLORS type;
|
||||
|
||||
type = C_NORM;
|
||||
|
||||
if ((ip->inode.mode & STPDFS_S_IFMT) == STPDFS_S_IFREG)
|
||||
{
|
||||
type = C_FILE;
|
||||
}
|
||||
else if ((ip->inode.mode & STPDFS_S_IFMT) == STPDFS_S_IFDIR)
|
||||
{
|
||||
if (ip->inode.mode & (STPDFS_S_IWOTH | STPDFS_S_ISVTX))
|
||||
{
|
||||
type = C_STICKY_OTH_WRITABLE;
|
||||
}
|
||||
else if (ip->inode.mode & STPDFS_S_ISVTX)
|
||||
{
|
||||
type = C_STICKY;
|
||||
}
|
||||
else if (ip->inode.mode & STPDFS_S_IWOTH)
|
||||
{
|
||||
type = C_OTHER_WRITABLE;
|
||||
}
|
||||
else
|
||||
{
|
||||
type = C_DIR;
|
||||
}
|
||||
}
|
||||
else if ((ip->inode.mode & STPDFS_S_IFMT) == STPDFS_S_IFLNK)
|
||||
{
|
||||
type = C_LINK;
|
||||
}
|
||||
else if (ip->inode.mode & STPDFS_S_ISUID)
|
||||
{
|
||||
type = C_SETUID;
|
||||
}
|
||||
else if (ip->inode.mode & STPDFS_S_ISGID)
|
||||
{
|
||||
type = C_SETGID;
|
||||
}
|
||||
else if (ip->inode.mode & STPDFS_S_IXUSR)
|
||||
{
|
||||
type = C_EXEC;
|
||||
}
|
||||
|
||||
if (color)
|
||||
{
|
||||
printf("%s%s%s", ls_colors[C_LEFT], ls_colors[type], ls_colors[C_RIGHT]);
|
||||
if ((ip->inode.mode & STPDFS_S_IFMT) == STPDFS_S_IFDIR)
|
||||
{
|
||||
printf("\033[01;34m");
|
||||
}
|
||||
else if ((ip->inode.mode & STPDFS_S_IFMT) == STPDFS_S_IFLNK)
|
||||
{
|
||||
printf("\033[01;36m");
|
||||
}
|
||||
else if (ip->inode.mode & STPDFS_S_IXUSR)
|
||||
{
|
||||
printf("\033[01;32m");
|
||||
}
|
||||
}
|
||||
|
||||
printf("%s\n", dirent->filename);
|
||||
if (color)
|
||||
{
|
||||
printf("%s%s%s", ls_colors[C_LEFT], ls_colors[C_END], ls_colors[C_RIGHT]);
|
||||
printf("\033[0m");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -328,7 +294,6 @@ cmd_ls(int argc, char **argv)
|
|||
break;
|
||||
|
||||
case 'c':
|
||||
ls_parse_colors();
|
||||
color = 1;
|
||||
break;
|
||||
|
||||
|
|
|
@ -1,64 +0,0 @@
|
|||
#include "colors.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
char *ls_colors[] = {
|
||||
/* C_NORM */ "0",
|
||||
/* C_FILE */ "0",
|
||||
/* C_DIR */ "34",
|
||||
/* C_LINK */ "35",
|
||||
/* C_SETUID */ "30;41",
|
||||
/* C_SETGID */ "30;46",
|
||||
/* C_STICKY_OTH_WRITABLE */ "30;42",
|
||||
/* C_OTHER_WRITABLE */ "30;43",
|
||||
/* C_STICKY */ "0",
|
||||
/* C_EXEC */ "31",
|
||||
/* C_LEFT */ "\033[",
|
||||
/* C_RIGHT */ "m",
|
||||
/* C_END */ "0"
|
||||
};
|
||||
|
||||
static const struct {
|
||||
char *abrv;
|
||||
enum COLORS type;
|
||||
} abrv2type[] = {
|
||||
{"no=", C_NORM},
|
||||
{"fi=", C_FILE},
|
||||
{"di=", C_DIR},
|
||||
{"ln=", C_LINK},
|
||||
{"su=", C_SETUID},
|
||||
{"sg=", C_SETGID},
|
||||
{"tw=", C_STICKY_OTH_WRITABLE},
|
||||
{"ow=", C_OTHER_WRITABLE},
|
||||
{"st=", C_STICKY},
|
||||
{"ex=", C_EXEC},
|
||||
{"lc=", C_LEFT},
|
||||
{"rc=", C_RIGHT},
|
||||
{"ec=", C_END},
|
||||
{NULL, 0}
|
||||
};
|
||||
|
||||
void
|
||||
ls_parse_colors(void)
|
||||
{
|
||||
char *colors;
|
||||
char *line;
|
||||
int idx;
|
||||
|
||||
colors = getenv("LS_COLORS");
|
||||
if (colors == NULL) return;
|
||||
|
||||
line = strtok(colors, ":");
|
||||
while (line != NULL)
|
||||
{
|
||||
for (idx = 0; abrv2type[idx].abrv != NULL; idx++)
|
||||
{
|
||||
if (strncmp(abrv2type[idx].abrv, line, 3) == 0)
|
||||
{
|
||||
ls_colors[abrv2type[idx].type] = line + 3;
|
||||
break;
|
||||
}
|
||||
}
|
||||
line = strtok(NULL, ":");
|
||||
}
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
#ifndef TOOLS_LS_COLORS_H
|
||||
# define TOOLS_LS_COLORS_H 1
|
||||
|
||||
enum COLORS {
|
||||
C_NORM,
|
||||
C_FILE,
|
||||
C_DIR,
|
||||
C_LINK,
|
||||
C_SETUID,
|
||||
C_SETGID,
|
||||
C_STICKY_OTH_WRITABLE,
|
||||
C_OTHER_WRITABLE,
|
||||
C_STICKY,
|
||||
C_EXEC,
|
||||
C_LEFT,
|
||||
C_RIGHT,
|
||||
C_END
|
||||
};
|
||||
|
||||
extern char *ls_colors[];
|
||||
|
||||
void ls_parse_colors(void);
|
||||
|
||||
#endif /* !TOOLS_LS_COLORS_H */
|
Loading…
Reference in a new issue