summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md25
-rw-r--r--builddeps/limine.conf2
-rw-r--r--builddeps/wallpaper.jpgbin0 -> 203867 bytes
-rw-r--r--configure.ac2
-rw-r--r--etc/passwd2
-rwxr-xr-xhyra-build.sh2
-rw-r--r--lib/libc/Makefile1
-rw-r--r--lib/libc/include/crypto/sha256.h62
-rw-r--r--lib/libc/include/string.h1
-rw-r--r--lib/libc/include/unistd.h3
-rw-r--r--lib/libc/src/crypto/sha256.c242
-rw-r--r--lib/libc/src/string/strdup.c51
-rw-r--r--lib/libc/src/unistd/getlogin.c109
-rw-r--r--lib/libc/src/unistd/getuid.c38
-rw-r--r--sys/arch/amd64/isa/i8042.c6
-rw-r--r--sys/dev/cons/cons.c2
-rw-r--r--sys/dev/random/chacha20.c97
-rw-r--r--sys/dev/random/entropy.c55
-rw-r--r--sys/dev/random/random.c88
-rw-r--r--sys/dev/random/siphash.c116
-rw-r--r--sys/fs/initramfs.c6
-rw-r--r--sys/include/dev/random/chacha20.h47
-rw-r--r--sys/include/dev/random/entropy.h40
-rw-r--r--sys/include/dev/random/siphash.h34
-rw-r--r--sys/include/sys/limits.h1
-rw-r--r--sys/include/sys/syscall.h1
-rw-r--r--sys/include/sys/ucred.h2
-rw-r--r--sys/include/sys/vnode.h24
-rw-r--r--sys/kern/exec_elf64.c2
-rw-r--r--sys/kern/kern_cred.c19
-rw-r--r--sys/kern/kern_descrip.c2
-rw-r--r--sys/kern/kern_exit.c16
-rw-r--r--sys/kern/kern_syscall.c1
-rw-r--r--sys/kern/vfs_lookup.c4
-rw-r--r--sys/kern/vfs_subr.c6
-rw-r--r--sys/kern/vfs_syscalls.c2
-rw-r--r--sys/vm/vm_vnode.c2
-rw-r--r--tools/omar/omar.c41
-rw-r--r--usr.bin/Makefile1
-rw-r--r--usr.bin/date/date.c51
-rw-r--r--usr.bin/fetch/fetch.c9
-rw-r--r--usr.bin/getconf/getconf.c5
-rw-r--r--usr.bin/login/login.c103
-rw-r--r--usr.bin/osh/osh.c4
-rw-r--r--usr.bin/sleep/Makefile6
-rw-r--r--usr.bin/sleep/sleep.c55
46 files changed, 1321 insertions, 67 deletions
diff --git a/README.md b/README.md
index 1d7f9a9..13bff62 100644
--- a/README.md
+++ b/README.md
@@ -23,6 +23,31 @@ After running the configure script, you can now actually build Hyra:
This will generate a new `Hyra.iso` file.
+
+Default User:
+----------------
+Upon booting, the `login` program will ask for user credentials. The default username is `root` and the default
+password is also `root`.
+
+Programs:
+----------------
+The Hyra userspace provides the user various programs that they can run, examples of
+such programs include:
+
+- ``beep`` - Play a tone
+- ``cat`` - Print files to stdout
+- ``date`` - Get the current date or set system time
+- ``echo`` - Print a line of text
+- ``elfdump`` - Get information about an ELF binary
+- ``fetch`` - System fetch! A must have :~)
+- ``getconf`` - Get system configuration values
+- ``mex`` - OSMORA hexdump utility
+- ``sleep`` - Sleep for a number of seconds
+- ``kmsg`` - Read the kernel message buffer
+- ``readcore`` - Read coredump files
+
+And more! See ``usr.bin/*``
+
Documentation:
--------------
Documentation will be in the form of comments throughout the codebase and can also be found in the share/ directory within the project root.
diff --git a/builddeps/limine.conf b/builddeps/limine.conf
index d5ed978..1ad040c 100644
--- a/builddeps/limine.conf
+++ b/builddeps/limine.conf
@@ -1,5 +1,5 @@
timeout=10
-${WALLPAPER_PATH}=boot():/boot/tree.jpg
+${WALLPAPER_PATH}=boot():/boot/wallpaper.jpg
wallpaper: ${WALLPAPER_PATH}
interface_branding_color: 1
term_background: 40000000
diff --git a/builddeps/wallpaper.jpg b/builddeps/wallpaper.jpg
new file mode 100644
index 0000000..5d69f53
--- /dev/null
+++ b/builddeps/wallpaper.jpg
Binary files differ
diff --git a/configure.ac b/configure.ac
index 61f5b54..aec0464 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,4 +1,4 @@
-AC_INIT([Hyra], [2.2], [ian@osmora.org])
+AC_INIT([Hyra], [2.3], [ian@osmora.org])
TARGET="amd64"
QEMU="qemu-system-x86_64"
diff --git a/etc/passwd b/etc/passwd
index 298e923..7855b99 100644
--- a/etc/passwd
+++ b/etc/passwd
@@ -1 +1 @@
-root:x:0:0:Not a ruler:/root:/usr/bin/osh
+root:4813494d137e1631bba301d5acab6e7bb7aa74ce1185d456565ef51d737677b2:0:0:Not a ruler:/root:/usr/bin/osh
diff --git a/hyra-build.sh b/hyra-build.sh
index 68f415f..1ebc3bb 100755
--- a/hyra-build.sh
+++ b/hyra-build.sh
@@ -67,7 +67,7 @@ gen_iso_root() {
cp $RAMFS_NAME iso_root/boot/
cp builddeps/limine.conf stand/limine/limine-bios.sys \
stand/limine/limine-bios-cd.bin stand/limine/limine-uefi-cd.bin iso_root/
- cp builddeps/tree.jpg iso_root/boot/
+ cp builddeps/wallpaper.jpg iso_root/boot/
}
##################################
diff --git a/lib/libc/Makefile b/lib/libc/Makefile
index b5bd01e..be693bd 100644
--- a/lib/libc/Makefile
+++ b/lib/libc/Makefile
@@ -30,6 +30,7 @@ headers: sys/include/machine
cp -f include/*.h $(USRDIR)/include/
cp -f include/stdlib/*.h $(USRDIR)/include/
cp -rf include/ousi $(USRDIR)/include/
+ cp -rf include/crypto $(USRDIR)/include/
.PHONY:
build/:
diff --git a/lib/libc/include/crypto/sha256.h b/lib/libc/include/crypto/sha256.h
new file mode 100644
index 0000000..6bd1077
--- /dev/null
+++ b/lib/libc/include/crypto/sha256.h
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Hyra nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _CRYPTO_SHA256_H
+#define _CRYPTO_SHA256_H 1
+
+#include <stddef.h>
+#include <stdint.h>
+
+#define SHA256_HEX_SIZE (64 + 1)
+#define SHA256_BYTES_SIZE 32
+
+/*
+ * Compute the SHA-256 checksum of a memory region given a pointer and
+ * the size of that memory region.
+ * The output is a hexadecimal string of 65 characters.
+ * The last character will be the null-character.
+ */
+void sha256_hex(const void *src, size_t n_bytes, char *dst_hex65);
+
+void sha256_bytes(const void *src, size_t n_bytes, void *dst_bytes32);
+
+typedef struct sha256 {
+ uint32_t state[8];
+ uint8_t buffer[64];
+ uint64_t n_bits;
+ uint8_t buffer_counter;
+} sha256;
+
+/* Functions to compute streaming SHA-256 checksums. */
+void sha256_init(struct sha256 *sha);
+void sha256_append(struct sha256 *sha, const void *data, size_t n_bytes);
+void sha256_finalize_hex(struct sha256 *sha, char *dst_hex65);
+void sha256_finalize_bytes(struct sha256 *sha, void *dst_bytes32);
+
+#endif /* !_CRYPTO_SHA256_H */
diff --git a/lib/libc/include/string.h b/lib/libc/include/string.h
index 50981c4..4ab1e45 100644
--- a/lib/libc/include/string.h
+++ b/lib/libc/include/string.h
@@ -35,6 +35,7 @@
size_t strlen(const char *s);
char *strtok(char *s, const char *delim);
+char *strdup(const char *s);
void *memset(void *dst, int c, size_t n);
int memcmp(const void *s1, const void *s2, size_t n);
diff --git a/lib/libc/include/unistd.h b/lib/libc/include/unistd.h
index db56ecd..b9c9f5e 100644
--- a/lib/libc/include/unistd.h
+++ b/lib/libc/include/unistd.h
@@ -47,6 +47,9 @@ __BEGIN_DECLS
int sysconf(int name);
int setuid(uid_t new);
+uid_t getuid(void);
+char *getlogin(void);
+
ssize_t read(int fd, void *buf, size_t count);
ssize_t write(int fd, const void *buf, size_t count);
diff --git a/lib/libc/src/crypto/sha256.c b/lib/libc/src/crypto/sha256.c
new file mode 100644
index 0000000..c722026
--- /dev/null
+++ b/lib/libc/src/crypto/sha256.c
@@ -0,0 +1,242 @@
+/*
+ * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Hyra nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <crypto/sha256.h>
+#include <stdint.h>
+#include <stddef.h>
+
+static inline uint32_t
+rotr(uint32_t x, int n)
+{
+ return (x >> n) | (x << (32 - n));
+}
+
+static inline uint32_t
+step1(uint32_t e, uint32_t f, uint32_t g)
+{
+ return (rotr(e, 6) ^ rotr(e, 11) ^ rotr(e, 25)) + ((e & f) ^ ((~ e) & g));
+}
+
+static inline uint32_t
+step2(uint32_t a, uint32_t b, uint32_t c)
+{
+ return (rotr(a, 2) ^ rotr(a, 13) ^ rotr(a, 22)) + ((a & b) ^ (a & c) ^ (b & c));
+}
+
+static inline void
+update_w(uint32_t *w, int i, const uint8_t *buffer)
+{
+ int j;
+ for (j = 0; j < 16; j++) {
+ if (i < 16){
+ w[j] =
+ ((uint32_t)buffer[0] << 24) |
+ ((uint32_t)buffer[1] << 16) |
+ ((uint32_t)buffer[2] << 8) |
+ ((uint32_t)buffer[3]);
+ buffer += 4;
+ }else {
+ uint32_t a = w[(j + 1) & 15];
+ uint32_t b = w[(j + 14) & 15];
+ uint32_t s0 = (rotr(a, 7) ^ rotr(a, 18) ^ (a >> 3));
+ uint32_t s1 = (rotr(b, 17) ^ rotr(b, 19) ^ (b >> 10));
+ w[j] += w[(j + 9) & 15] + s0 + s1;
+ }
+ }
+}
+
+static void
+sha256_block(struct sha256 *sha)
+{
+ uint32_t *state = sha->state;
+
+ static const uint32_t k[8 * 8] = {
+ 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
+ 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
+ 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
+ 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
+ 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
+ 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
+ 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
+ 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
+ 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
+ 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
+ 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
+ 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
+ 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
+ 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
+ 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
+ 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
+ };
+
+ uint32_t a = state[0];
+ uint32_t b = state[1];
+ uint32_t c = state[2];
+ uint32_t d = state[3];
+ uint32_t e = state[4];
+ uint32_t f = state[5];
+ uint32_t g = state[6];
+ uint32_t h = state[7];
+
+ uint32_t w[16];
+
+ int i, j;
+ for (i = 0; i < 64; i += 16) {
+ update_w(w, i, sha->buffer);
+
+ for (j = 0; j < 16; j += 4) {
+ uint32_t temp;
+ temp = h + step1(e, f, g) + k[i + j + 0] + w[j + 0];
+ h = temp + d;
+ d = temp + step2(a, b, c);
+ temp = g + step1(h, e, f) + k[i + j + 1] + w[j + 1];
+ g = temp + c;
+ c = temp + step2(d, a, b);
+ temp = f + step1(g, h, e) + k[i + j + 2] + w[j + 2];
+ f = temp + b;
+ b = temp + step2(c, d, a);
+ temp = e + step1(f, g, h) + k[i + j + 3] + w[j + 3];
+ e = temp + a;
+ a = temp + step2(b, c, d);
+ }
+ }
+
+ state[0] += a;
+ state[1] += b;
+ state[2] += c;
+ state[3] += d;
+ state[4] += e;
+ state[5] += f;
+ state[6] += g;
+ state[7] += h;
+}
+
+void
+sha256_init(struct sha256 *sha)
+{
+ sha->state[0] = 0x6a09e667;
+ sha->state[1] = 0xbb67ae85;
+ sha->state[2] = 0x3c6ef372;
+ sha->state[3] = 0xa54ff53a;
+ sha->state[4] = 0x510e527f;
+ sha->state[5] = 0x9b05688c;
+ sha->state[6] = 0x1f83d9ab;
+ sha->state[7] = 0x5be0cd19;
+ sha->n_bits = 0;
+ sha->buffer_counter = 0;
+}
+
+void
+sha256_append_byte(struct sha256 *sha, uint8_t byte)
+{
+ sha->buffer[sha->buffer_counter++] = byte;
+ sha->n_bits += 8;
+
+ if (sha->buffer_counter == 64) {
+ sha->buffer_counter = 0;
+ sha256_block(sha);
+ }
+}
+
+void
+sha256_append(struct sha256 *sha, const void *src, size_t n_bytes)
+{
+ const uint8_t *bytes = (const uint8_t*)src;
+ size_t i;
+
+ for (i = 0; i < n_bytes; i++) {
+ sha256_append_byte(sha, bytes[i]);
+ }
+}
+
+void
+sha256_finalize(struct sha256 *sha)
+{
+ int i;
+ uint64_t n_bits = sha->n_bits;
+
+ sha256_append_byte(sha, 0x80);
+
+ while (sha->buffer_counter != 56) {
+ sha256_append_byte(sha, 0);
+ }
+
+ for (i = 7; i >= 0; i--) {
+ uint8_t byte = (n_bits >> 8 * i) & 0xff;
+ sha256_append_byte(sha, byte);
+ }
+}
+
+void
+sha256_finalize_hex(struct sha256 *sha, char *dst_hex65)
+{
+ int i, j;
+ sha256_finalize(sha);
+
+ for (i = 0; i < 8; i++) {
+ for (j = 7; j >= 0; j--) {
+ uint8_t nibble = (sha->state[i] >> j * 4) & 0xf;
+ *dst_hex65++ = "0123456789abcdef"[nibble];
+ }
+ }
+
+ *dst_hex65 = '\0';
+}
+
+void
+sha256_finalize_bytes(struct sha256 *sha, void *dst_bytes32)
+{
+ uint8_t *ptr = (uint8_t*)dst_bytes32;
+ int i, j;
+ sha256_finalize(sha);
+
+ for (i = 0; i < 8; i++) {
+ for (j = 3; j >= 0; j--) {
+ *ptr++ = (sha->state[i] >> j * 8) & 0xff;
+ }
+ }
+}
+
+void
+sha256_hex(const void *src, size_t n_bytes, char *dst_hex65)
+{
+ struct sha256 sha;
+
+ sha256_init(&sha);
+ sha256_append(&sha, src, n_bytes);
+ sha256_finalize_hex(&sha, dst_hex65);
+}
+
+void sha256_bytes(const void *src, size_t n_bytes, void *dst_bytes32){
+ struct sha256 sha;
+
+ sha256_init(&sha);
+ sha256_append(&sha, src, n_bytes);
+ sha256_finalize_bytes(&sha, dst_bytes32);
+}
diff --git a/lib/libc/src/string/strdup.c b/lib/libc/src/string/strdup.c
new file mode 100644
index 0000000..e5b0910
--- /dev/null
+++ b/lib/libc/src/string/strdup.c
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Hyra nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <string.h>
+#include <stdlib.h>
+
+char *
+strdup(const char *s)
+{
+ char *new_s;
+ size_t s_len;
+
+ if (s == NULL) {
+ return NULL;
+ }
+
+ s_len = strlen(s);
+ new_s = malloc(s_len + 1);
+ if (new_s == NULL) {
+ return NULL;
+ }
+
+ memcpy(new_s, s, s_len);
+ return new_s;
+}
diff --git a/lib/libc/src/unistd/getlogin.c b/lib/libc/src/unistd/getlogin.c
new file mode 100644
index 0000000..dd74261
--- /dev/null
+++ b/lib/libc/src/unistd/getlogin.c
@@ -0,0 +1,109 @@
+/*
+ * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Hyra nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/types.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <string.h>
+
+#define UNKNOWN_USER "unknown"
+
+static char *ucache = NULL;
+
+static int
+match_entry(uid_t uid, char *entry)
+{
+ char uidstr[16];
+ char *username = NULL;
+ char *p;
+ size_t len;
+ uint8_t row = 0;
+
+ if (itoa(uid, uidstr, 10) == NULL) {
+ return -1;
+ }
+
+ p = strtok(entry, ":");
+ if (p == NULL) {
+ return -1;
+ }
+
+ while (p != NULL) {
+ switch (row) {
+ case 0:
+ username = p;
+ break;
+ case 2:
+ /*
+ * If the user ID matches, we'll cache the
+ * username.
+ */
+ if (strcmp(uidstr, p) == 0) {
+ ucache = strdup(username);
+ return 0;
+ }
+ break;
+ }
+
+ p = strtok(NULL, ":");
+ ++row;
+ }
+
+ return -1;
+}
+
+char *
+getlogin(void)
+{
+ FILE *fp;
+ char entry[256];
+ int retval;
+ uid_t uid = getuid();
+
+ /* Get the user from the cache */
+ if (ucache != NULL) {
+ return ucache;
+ }
+
+ fp = fopen("/etc/passwd", "r");
+ if (fp == NULL) {
+ return UNKNOWN_USER;
+ }
+
+ while (fgets(entry, sizeof(entry), fp) != NULL) {
+ if (match_entry(uid, entry) == 0) {
+ fclose(fp);
+ return ucache;
+ }
+ }
+
+ fclose(fp);
+ return UNKNOWN_USER;
+}
diff --git a/lib/libc/src/unistd/getuid.c b/lib/libc/src/unistd/getuid.c
new file mode 100644
index 0000000..644faa5
--- /dev/null
+++ b/lib/libc/src/unistd/getuid.c
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Hyra nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/types.h>
+#include <sys/syscall.h>
+#include <unistd.h>
+
+uid_t
+getuid(void)
+{
+ return syscall(SYS_getuid);
+}
diff --git a/sys/arch/amd64/isa/i8042.c b/sys/arch/amd64/isa/i8042.c
index 69d9f92..cde70ff 100644
--- a/sys/arch/amd64/isa/i8042.c
+++ b/sys/arch/amd64/isa/i8042.c
@@ -33,6 +33,7 @@
#include <sys/syslog.h>
#include <sys/spinlock.h>
#include <sys/param.h>
+#include <sys/ascii.h>
#include <sys/proc.h>
#include <sys/reboot.h>
#include <sys/queue.h>
@@ -75,7 +76,7 @@ static int i8042_kb_getc(uint8_t sc, char *chr);
static void i8042_drain(void);
static char keytab[] = {
- '\0', '\0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0',
+ '\0', '\x1B', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0',
'-', '=', '\b', '\t', 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i',
'o', 'p', '[', ']', '\n', '\0', 'a', 's', 'd', 'f', 'g', 'h',
'j', 'k', 'l', ';', '\'', '`', '\0', '\\', 'z', 'x', 'c', 'v',
@@ -276,6 +277,9 @@ i8042_kb_getc(uint8_t sc, char *chr)
bool release = ISSET(sc, BIT(7));
switch (sc) {
+ case 0x76:
+ *chr = ASCII_ESC;
+ return 0;
/* Caps lock [press] */
case 0x3A:
/*
diff --git a/sys/dev/cons/cons.c b/sys/dev/cons/cons.c
index 7407ec1..88cbcbe 100644
--- a/sys/dev/cons/cons.c
+++ b/sys/dev/cons/cons.c
@@ -375,7 +375,6 @@ dev_read(dev_t dev, struct sio_txn *sio, int flags)
}
cons_attach();
- spinlock_acquire(&g_root_scr.lock);
for (;;) {
/* Buffer too small */
if (n == 0) {
@@ -392,7 +391,6 @@ dev_read(dev_t dev, struct sio_txn *sio, int flags)
break;
}
}
- spinlock_release(&g_root_scr.lock);
return sio->len;
}
diff --git a/sys/dev/random/chacha20.c b/sys/dev/random/chacha20.c
new file mode 100644
index 0000000..41f823c
--- /dev/null
+++ b/sys/dev/random/chacha20.c
@@ -0,0 +1,97 @@
+/*
+ * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Hyra nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <dev/random/chacha20.h>
+
+static const char sigma[16] = "expand 32-byte k";
+
+void chacha20_init(uint32_t state[16], const uint8_t key[32],
+ const uint8_t nonce[12], uint32_t counter)
+{
+ state[0] = ((uint32_t *)sigma)[0];
+ state[1] = ((uint32_t *)sigma)[1];
+ state[2] = ((uint32_t *)sigma)[2];
+ state[3] = ((uint32_t *)sigma)[3];
+
+ for (int i = 0; i < 8; ++i) {
+ state[4 + i] = ((uint32_t *)key)[i];
+ }
+
+ state[12] = counter;
+ state[13] = ((uint32_t *)nonce)[0];
+ state[14] = ((uint32_t *)nonce)[1];
+ state[15] = ((uint32_t *)nonce)[2];
+}
+
+void
+chacha20_block(uint32_t state[16], uint8_t out[64])
+{
+ uint32_t x[16];
+ memcpy(x, state, sizeof(x));
+
+ for (int i = 0; i < 10; i++) {
+
+ QR(x[0], x[4], x[8], x[12]);
+ QR(x[1], x[5], x[9], x[13]);
+ QR(x[2], x[6], x[10], x[14]);
+ QR(x[3], x[7], x[11], x[15]);
+
+ QR(x[0], x[5], x[10], x[15]);
+ QR(x[1], x[6], x[11], x[12]);
+ QR(x[2], x[7], x[8], x[13]);
+ QR(x[3], x[4], x[9], x[14]);
+ }
+
+ for (int i = 0; i < 16; ++i) {
+ x[i] += state[i];
+ ((uint32_t *)out)[i] = x[i];
+ }
+
+ state[12]++;
+}
+
+void
+chacha20_encrypt(uint32_t state[16], uint8_t *in,
+ uint8_t *out, size_t len)
+{
+ uint8_t block[64];
+ size_t offset = 0;
+
+ while (len > 0) {
+ chacha20_block(state, block);
+ size_t n = len > 64 ? 64 : len;
+
+ for (size_t i = 0; i < n; ++i) {
+ out[offset + i] = in ? in[offset + i] ^ block[i] : block[i];
+ }
+
+ offset += n;
+ len -= n;
+ }
+}
diff --git a/sys/dev/random/entropy.c b/sys/dev/random/entropy.c
new file mode 100644
index 0000000..d392b9c
--- /dev/null
+++ b/sys/dev/random/entropy.c
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Hyra nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdint.h>
+#include <string.h>
+#include <dev/random/entropy.h>
+#include <dev/random/siphash.h>
+
+void
+mix_entropy(struct entropy_pool *ep, const uint8_t *input,
+ size_t input_len, uint32_t input_entropy_bits)
+{
+ char key[16] = {0,1,2,3,4,5,6,7,8,9,0xa,0xb,0xc,0xd,0xe,0xf};
+ uint64_t hash_result;
+ uint8_t buffer[ENTROPY_POOL_SIZE + input_len];
+ memcpy(buffer, ep->pool, ENTROPY_POOL_SIZE);
+ memcpy(buffer + ENTROPY_POOL_SIZE, input, input_len);
+
+ hash_result = siphash24(buffer, sizeof(buffer), key);
+
+ for (int i = 0; i < 8; ++i) {
+ ep->pool[i] ^= (hash_result >> (i * 8)) & 0xFF;
+ }
+
+ ep->entropy_bits += input_entropy_bits;
+ if (ep->entropy_bits > ENTROPY_POOL_SIZE * 8) {
+ ep->entropy_bits = ENTROPY_POOL_SIZE * 8;
+ }
+}
diff --git a/sys/dev/random/random.c b/sys/dev/random/random.c
new file mode 100644
index 0000000..d79df69
--- /dev/null
+++ b/sys/dev/random/random.c
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Hyra nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/sio.h>
+#include <sys/device.h>
+#include <sys/driver.h>
+#include <dev/random/chacha20.h>
+#include <dev/random/siphash.h>
+#include <dev/random/entropy.h>
+#include <fs/devfs.h>
+#include <string.h>
+
+static struct cdevsw random_cdevsw;
+static struct entropy_pool entropy;
+
+uint8_t key[32] = {0};
+uint8_t nonce[12] = {0};
+uint32_t state[16];
+uint32_t tsc;
+
+static inline uint64_t
+read_tsc(void)
+{
+ uint32_t lo, hi;
+ __asm__ volatile ("rdtsc" : "=a"(lo), "=d"(hi));
+ return ((uint64_t)hi << 32) | lo;
+}
+
+static int
+random_read(dev_t dev, struct sio_txn *sio, int flags)
+{
+ tsc = read_tsc();
+ mix_entropy(&entropy, (uint8_t *)&tsc, sizeof(tsc), 1);
+
+ chacha20_init(state, entropy.pool, nonce, 0);
+ chacha20_encrypt(state, NULL, sio->buf, sio->len);
+
+ return sio->len;
+}
+
+static int
+random_init(void)
+{
+ char devname[] = "random";
+ devmajor_t major;
+ dev_t dev;
+
+ /* Register the device here */
+ major = dev_alloc_major();
+ dev = dev_alloc(major);
+ dev_register(major, dev, &random_cdevsw);
+ devfs_create_entry(devname, major, dev, 0444);
+
+ return 0;
+}
+
+static struct cdevsw random_cdevsw = {
+ .read = random_read,
+ .write = nowrite
+};
+
+DRIVER_EXPORT(random_init, "random");
diff --git a/sys/dev/random/siphash.c b/sys/dev/random/siphash.c
new file mode 100644
index 0000000..2b2243f
--- /dev/null
+++ b/sys/dev/random/siphash.c
@@ -0,0 +1,116 @@
+/* <MIT License>
+ Copyright (c) 2013 Marek Majkowski <marek@popcount.org>
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
+ </MIT License>
+
+ Original location:
+ https://github.com/majek/csiphash/
+
+ Solution inspired by code from:
+ Samuel Neves (supercop/crypto_auth/siphash24/little)
+ djb (supercop/crypto_auth/siphash24/little2)
+ Jean-Philippe Aumasson (https://131002.net/siphash/siphash24.c)
+*/
+
+#include <dev/random/siphash.h>
+#include <stdint.h>
+
+#if defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && \
+ __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
+# define _le64toh(x) ((uint64_t)(x))
+#elif defined(_WIN32)
+/* Windows is always little endian, unless you're on xbox360
+ http://msdn.microsoft.com/en-us/library/b0084kay(v=vs.80).aspx */
+# define _le64toh(x) ((uint64_t)(x))
+#elif defined(__APPLE__)
+# include <libkern/OSByteOrder.h>
+# define _le64toh(x) OSSwapLittleToHostInt64(x)
+#else
+
+/* See: http://sourceforge.net/p/predef/wiki/Endianness/ */
+# if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
+# include <sys/endian.h>
+# else
+# include <endian.h>
+# endif
+# if defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && \
+ __BYTE_ORDER == __LITTLE_ENDIAN
+# define _le64toh(x) ((uint64_t)(x))
+# else
+# define _le64toh(x) le64toh(x)
+# endif
+
+#endif
+
+
+#define ROTATE(x, b) (uint64_t)( ((x) << (b)) | ( (x) >> (64 - (b))) )
+
+#define HALF_ROUND(a,b,c,d,s,t) \
+ a += b; c += d; \
+ b = ROTATE(b, s) ^ a; \
+ d = ROTATE(d, t) ^ c; \
+ a = ROTATE(a, 32);
+
+#define DOUBLE_ROUND(v0,v1,v2,v3) \
+ HALF_ROUND(v0,v1,v2,v3,13,16); \
+ HALF_ROUND(v2,v1,v0,v3,17,21); \
+ HALF_ROUND(v0,v1,v2,v3,13,16); \
+ HALF_ROUND(v2,v1,v0,v3,17,21);
+
+
+uint64_t siphash24(const void *src, unsigned long src_sz, const char key[16]) {
+ const uint64_t *_key = (uint64_t *)key;
+ uint64_t k0 = _le64toh(_key[0]);
+ uint64_t k1 = _le64toh(_key[1]);
+ uint64_t b = (uint64_t)src_sz << 56;
+ const uint64_t *in = (uint64_t*)src;
+
+ uint64_t v0 = k0 ^ 0x736f6d6570736575ULL;
+ uint64_t v1 = k1 ^ 0x646f72616e646f6dULL;
+ uint64_t v2 = k0 ^ 0x6c7967656e657261ULL;
+ uint64_t v3 = k1 ^ 0x7465646279746573ULL;
+
+ while (src_sz >= 8) {
+ uint64_t mi = _le64toh(*in);
+ in += 1; src_sz -= 8;
+ v3 ^= mi;
+ DOUBLE_ROUND(v0,v1,v2,v3);
+ v0 ^= mi;
+ }
+
+ uint64_t t = 0; uint8_t *pt = (uint8_t *)&t; uint8_t *m = (uint8_t *)in;
+ switch (src_sz) {
+ case 7: pt[6] = m[6];
+ case 6: pt[5] = m[5];
+ case 5: pt[4] = m[4];
+ case 4: *((uint32_t*)&pt[0]) = *((uint32_t*)&m[0]); break;
+ case 3: pt[2] = m[2];
+ case 2: pt[1] = m[1];
+ case 1: pt[0] = m[0];
+ }
+ b |= _le64toh(t);
+
+ v3 ^= b;
+ DOUBLE_ROUND(v0,v1,v2,v3);
+ v0 ^= b; v2 ^= 0xff;
+ DOUBLE_ROUND(v0,v1,v2,v3);
+ DOUBLE_ROUND(v0,v1,v2,v3);
+ return (v0 ^ v1) ^ (v2 ^ v3);
+}
diff --git a/sys/fs/initramfs.c b/sys/fs/initramfs.c
index c41deb4..beb2e84 100644
--- a/sys/fs/initramfs.c
+++ b/sys/fs/initramfs.c
@@ -61,12 +61,16 @@ struct initramfs_node {
* @magic: Header magic ("OMAR")
* @len: Length of the file
* @namelen: Length of the filename
+ * @rev: OMAR revision
+ * @mode: File permissions
*/
struct __packed omar_hdr {
char magic[4];
uint8_t type;
uint8_t namelen;
uint32_t len;
+ uint8_t rev;
+ uint32_t mode;
};
static volatile struct limine_module_request mod_req = {
@@ -140,7 +144,7 @@ initramfs_get_file(const char *path, struct initramfs_node *res)
p += hdr->namelen;
if (strcmp(namebuf, path) == 0) {
- node.mode = 0700;
+ node.mode = hdr->mode;
node.size = hdr->len;
node.data = (void *)p;
*res = node;
diff --git a/sys/include/dev/random/chacha20.h b/sys/include/dev/random/chacha20.h
new file mode 100644
index 0000000..d35702a
--- /dev/null
+++ b/sys/include/dev/random/chacha20.h
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Hyra nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdint.h>
+#include <stddef.h>
+#include <string.h>
+
+#define ROTL(a,b) (((a) << (b)) | ((a) >> (32 - (b))))
+
+#define QR(a,b,c,d) \
+ a += b; d ^= a; d = ROTL(d, 16); \
+ c += d; b ^= c; b = ROTL(b, 12); \
+ a += b; d ^= a; d = ROTL(d, 8); \
+ c += d; b ^= c; b = ROTL(b, 7);
+
+void chacha20_init(uint32_t state[16], const uint8_t key[32],
+ const uint8_t nonce[12], uint32_t counter);
+
+void chacha20_block(uint32_t state[16], uint8_t out[64]);
+void chacha20_encrypt(uint32_t state[16], uint8_t *in, uint8_t *out, size_t len);
+
diff --git a/sys/include/dev/random/entropy.h b/sys/include/dev/random/entropy.h
new file mode 100644
index 0000000..34d86df
--- /dev/null
+++ b/sys/include/dev/random/entropy.h
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Hyra nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdint.h>
+
+#define ENTROPY_POOL_SIZE 32
+
+struct entropy_pool {
+ uint8_t pool[ENTROPY_POOL_SIZE];
+ uint32_t entropy_bits;
+};
+
+void mix_entropy(struct entropy_pool *ep, const uint8_t *input,
+ size_t input_len, uint32_t input_entropy_bits);
diff --git a/sys/include/dev/random/siphash.h b/sys/include/dev/random/siphash.h
new file mode 100644
index 0000000..ecabb4a
--- /dev/null
+++ b/sys/include/dev/random/siphash.h
@@ -0,0 +1,34 @@
+/* <MIT License>
+ Copyright (c) 2013 Marek Majkowski <marek@popcount.org>
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
+ </MIT License>
+
+ Original location:
+ https://github.com/majek/csiphash/
+
+ Solution inspired by code from:
+ Samuel Neves (supercop/crypto_auth/siphash24/little)
+ djb (supercop/crypto_auth/siphash24/little2)
+ Jean-Philippe Aumasson (https://131002.net/siphash/siphash24.c)
+*/
+
+#include <stdint.h>
+
+uint64_t siphash24(const void *src, unsigned long src_sz, const char k[16]);
diff --git a/sys/include/sys/limits.h b/sys/include/sys/limits.h
index f56958e..5b97b68 100644
--- a/sys/include/sys/limits.h
+++ b/sys/include/sys/limits.h
@@ -31,6 +31,7 @@
#define _SYS_LIMITS_H_
#define PATH_MAX 1024
+#define NAME_MAX 256
#define SSIZE_MAX 32767
#define ARG_MAX 4096
#define CHAR_BIT 8
diff --git a/sys/include/sys/syscall.h b/sys/include/sys/syscall.h
index 05288f4..51c2579 100644
--- a/sys/include/sys/syscall.h
+++ b/sys/include/sys/syscall.h
@@ -57,6 +57,7 @@
#define SYS_getpid 16
#define SYS_getppid 17
#define SYS_setuid 18
+#define SYS_getuid 19
#if defined(_KERNEL)
/* Syscall return value and arg type */
diff --git a/sys/include/sys/ucred.h b/sys/include/sys/ucred.h
index b44a7fe..f8cbbe0 100644
--- a/sys/include/sys/ucred.h
+++ b/sys/include/sys/ucred.h
@@ -48,8 +48,10 @@ struct ucred {
};
int setuid(uid_t new);
+uid_t getuid(void);
#if defined(_KERNEL)
scret_t sys_setuid(struct syscall_args *scargs);
+scret_t sys_getuid(struct syscall_args *scargs);
#endif
#endif /* !_SYS_UCRED_H_ */
diff --git a/sys/include/sys/vnode.h b/sys/include/sys/vnode.h
index b135433..3402b02 100644
--- a/sys/include/sys/vnode.h
+++ b/sys/include/sys/vnode.h
@@ -92,6 +92,16 @@ struct vop_create_args {
struct vnode **vpp; /* Result vnode */
};
+struct vop_getattr_args {
+ struct vnode *vp; /* Target vnode */
+ struct vattr *res; /* Result vattr */
+};
+
+struct vop_readdir_args {
+ struct vnode *vp; /* Target vnode */
+ struct sio_txn *sio; /* SIO data to read into */
+};
+
/*
* A field in this structure is unavailable
* if it has a value of VNOVAL.
@@ -101,14 +111,10 @@ struct vattr {
size_t size;
};
-struct vop_getattr_args {
- struct vnode *vp;
- struct vattr *res;
-};
-
struct vops {
int(*lookup)(struct vop_lookup_args *args);
int(*getattr)(struct vop_getattr_args *args);
+ int(*readdir)(struct vop_readdir_args *args);
int(*read)(struct vnode *vp, struct sio_txn *sio);
int(*write)(struct vnode *vp, struct sio_txn *sio);
int(*reclaim)(struct vnode *vp);
@@ -117,19 +123,21 @@ struct vops {
extern struct vnode *g_root_vnode;
+/* Vnode cache operations */
int vfs_vcache_type(void);
int vfs_vcache_migrate(int newtype);
-
int vfs_vcache_enter(struct vnode *vp);
struct vnode *vfs_recycle_vnode(void);
+/* Vnode operations */
int vfs_alloc_vnode(struct vnode **res, int type);
int vfs_release_vnode(struct vnode *vp);
-int vfs_vop_lookup(struct vnode *vp, struct vop_lookup_args *args);
+/* Vnode operation wrappers */
+int vfs_vop_lookup(struct vop_lookup_args *args);
+int vfs_vop_getattr(struct vop_getattr_args *args);
int vfs_vop_read(struct vnode *vp, struct sio_txn *sio);
int vfs_vop_write(struct vnode *vp, struct sio_txn *sio);
-int vfs_vop_getattr(struct vnode *vp, struct vop_getattr_args *args);
#endif /* _KERNEL */
#endif /* !_SYS_VNODE_H_ */
diff --git a/sys/kern/exec_elf64.c b/sys/kern/exec_elf64.c
index 9706e77..8dc87dc 100644
--- a/sys/kern/exec_elf64.c
+++ b/sys/kern/exec_elf64.c
@@ -112,7 +112,7 @@ elf_get_file(const char *pathname, struct elf_file *res)
getattr_args.res = &vattr;
getattr_args.vp = vp;
- status = vfs_vop_getattr(vp, &getattr_args);
+ status = vfs_vop_getattr(&getattr_args);
if (status != 0)
goto done;
diff --git a/sys/kern/kern_cred.c b/sys/kern/kern_cred.c
index e1202fc..017b22a 100644
--- a/sys/kern/kern_cred.c
+++ b/sys/kern/kern_cred.c
@@ -56,6 +56,19 @@ setuid(uid_t new)
return 0;
}
+uid_t
+getuid(void)
+{
+ struct proc *td;
+
+ td = this_td();
+ if (td == NULL) {
+ return -1;
+ }
+
+ return td->cred.ruid;
+}
+
/*
* setuid() syscall
*
@@ -66,3 +79,9 @@ sys_setuid(struct syscall_args *scargs)
{
return setuid(scargs->arg0);
}
+
+scret_t
+sys_getuid(struct syscall_args *scargs)
+{
+ return getuid();
+}
diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c
index 0fb026f..b5ff144 100644
--- a/sys/kern/kern_descrip.c
+++ b/sys/kern/kern_descrip.c
@@ -351,7 +351,7 @@ fd_seek(int fildes, off_t offset, int whence)
getattr_args.vp = tmp->vp;
getattr_args.res = &attr;
- if ((vfs_vop_getattr(tmp->vp, &getattr_args)) < 0) {
+ if ((vfs_vop_getattr(&getattr_args)) < 0) {
return -EPIPE;
}
diff --git a/sys/kern/kern_exit.c b/sys/kern/kern_exit.c
index a4bf0f9..b1bd9ba 100644
--- a/sys/kern/kern_exit.c
+++ b/sys/kern/kern_exit.c
@@ -31,6 +31,8 @@
#include <sys/sched.h>
#include <sys/syslog.h>
#include <sys/panic.h>
+#include <sys/filedesc.h>
+#include <sys/vnode.h>
#include <vm/physmem.h>
#include <vm/dynalloc.h>
#include <vm/vm.h>
@@ -83,9 +85,23 @@ void
proc_reap(struct proc *td)
{
struct pcb *pcbp;
+ struct filedesc *fdp;
vaddr_t stack_va;
paddr_t stack_pa;
+ /* Clear out all fds */
+ for (size_t i = 4; i < PROC_MAX_FILEDES; ++i) {
+ fdp = td->fds[i];
+ if (fdp == NULL) {
+ continue;
+ }
+ if (fdp->refcnt == 1) {
+ vfs_release_vnode(fdp->vp);
+ dynfree(fdp);
+ fdp = NULL;
+ }
+ }
+
pcbp = &td->pcb;
unload_td(td);
diff --git a/sys/kern/kern_syscall.c b/sys/kern/kern_syscall.c
index 276c7c7..a28d2dd 100644
--- a/sys/kern/kern_syscall.c
+++ b/sys/kern/kern_syscall.c
@@ -58,6 +58,7 @@ scret_t(*g_sctab[])(struct syscall_args *) = {
sys_getpid, /* SYS_getpid */
sys_getppid, /* SYS_getppid */
sys_setuid, /* SYS_setuid */
+ sys_getuid, /* SYS_getuid */
};
const size_t MAX_SYSCALLS = NELEM(g_sctab);
diff --git a/sys/kern/vfs_lookup.c b/sys/kern/vfs_lookup.c
index d88c447..7320102 100644
--- a/sys/kern/vfs_lookup.c
+++ b/sys/kern/vfs_lookup.c
@@ -181,7 +181,7 @@ namei_mp_search(struct mount *mp, const char *path, struct nameidata *ndp)
lookup_args.dirvp = vp;
lookup_args.vpp = &vp;
- status = vfs_vop_lookup(vp, &lookup_args);
+ status = vfs_vop_lookup(&lookup_args);
dynfree(name);
if (status != 0) {
@@ -234,7 +234,7 @@ namei(struct nameidata *ndp)
lookup_args.name = path;
lookup_args.dirvp = g_root_vnode;
lookup_args.vpp = &vp;
- status = vfs_vop_lookup(lookup_args.dirvp, &lookup_args);
+ status = vfs_vop_lookup(&lookup_args);
/* Did we find it in the root */
if (status == 0) {
diff --git a/sys/kern/vfs_subr.c b/sys/kern/vfs_subr.c
index da0a4f9..69417d0 100644
--- a/sys/kern/vfs_subr.c
+++ b/sys/kern/vfs_subr.c
@@ -141,8 +141,9 @@ vfs_release_vnode(struct vnode *vp)
}
int
-vfs_vop_lookup(struct vnode *vp, struct vop_lookup_args *args)
+vfs_vop_lookup(struct vop_lookup_args *args)
{
+ const struct vnode *vp = args->dirvp;
const struct vops *vops = vp->vops;
if (vops == NULL)
@@ -180,8 +181,9 @@ vfs_vop_write(struct vnode *vp, struct sio_txn *sio)
}
int
-vfs_vop_getattr(struct vnode *vp, struct vop_getattr_args *args)
+vfs_vop_getattr(struct vop_getattr_args *args)
{
+ const struct vnode *vp = args->vp;
const struct vops *vops = vp->vops;
if (vops == NULL)
diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c
index 0d51331..d15ecf1 100644
--- a/sys/kern/vfs_syscalls.c
+++ b/sys/kern/vfs_syscalls.c
@@ -68,7 +68,7 @@ vfs_dostat(const char *path, struct stat *sbuf)
vp = nd.vp;
gattr.vp = vp;
gattr.res = &attr;
- error = vfs_vop_getattr(vp, &gattr);
+ error = vfs_vop_getattr(&gattr);
if (error != 0) {
return error;
diff --git a/sys/vm/vm_vnode.c b/sys/vm/vm_vnode.c
index 27defc9..777b382 100644
--- a/sys/vm/vm_vnode.c
+++ b/sys/vm/vm_vnode.c
@@ -73,7 +73,7 @@ vn_io(struct vnode *vp, struct vm_page **pgs, unsigned int npages, int rw)
args.res = &vattr;
c = MAX(vattr.size / DEFAULT_PAGESIZE, 1);
- if ((err = vfs_vop_getattr(vp, &args)) != 0) {
+ if ((err = vfs_vop_getattr(&args)) != 0) {
return err;
}
diff --git a/tools/omar/omar.c b/tools/omar/omar.c
index 129303e..a4c7ad6 100644
--- a/tools/omar/omar.c
+++ b/tools/omar/omar.c
@@ -53,6 +53,9 @@
#define OMAR_ARCHIVE 0
#define OMAR_EXTRACT 1
+/* Revision */
+#define OMAR_REV 2
+
#define ALIGN_UP(value, align) (((value) + (align)-1) & ~((align)-1))
#define BLOCK_SIZE 512
@@ -68,12 +71,16 @@ static const char *outpath = NULL;
* @magic: Header magic ("OMAR")
* @len: Length of the file
* @namelen: Length of the filename
+ * @rev: OMAR revision
+ * @mode: File permissions
*/
struct omar_hdr {
char magic[4];
uint8_t type;
uint8_t namelen;
uint32_t len;
+ uint8_t rev;
+ uint32_t mode;
} __attribute__((packed));
static inline void
@@ -112,7 +119,7 @@ strip_root(const char *path)
* Recursive mkdir
*/
static void
-mkpath(const char *path)
+mkpath(struct omar_hdr *hdr, const char *path)
{
size_t len;
char buf[256];
@@ -126,12 +133,12 @@ mkpath(const char *path)
for (p = (char *)buf + 1; *p != '\0'; ++p) {
if (*p == '/') {
*p = '\0';
- mkdir(buf, 0700);
+ mkdir(buf, hdr->mode);
*p = '/';
}
}
- mkdir(buf, 0700);
+ mkdir(buf, hdr->mode);
}
/*
@@ -166,9 +173,11 @@ file_push(const char *pathname, const char *name)
if (S_ISDIR(sb.st_mode)) {
hdr.type = OMAR_DIR;
}
+ hdr.mode = sb.st_mode;
}
hdr.len = (pathname == NULL) ? 0 : sb.st_size;
+ hdr.rev = OMAR_REV;
hdr.namelen = strlen(name);
/*
@@ -282,16 +291,17 @@ archive_create(const char *base, const char *dirname)
/*
* Extract a single file
*
+ * @hp: File header
* @data: Data to extract
* @len: Length of data
* @path: Path to output file
*/
static int
-extract_single(char *data, size_t len, const char *path)
+extract_single(struct omar_hdr *hp, char *data, size_t len, const char *path)
{
int fd;
- if ((fd = open(path, O_WRONLY | O_CREAT, 0700)) < 0) {
+ if ((fd = open(path, O_WRONLY | O_CREAT, hp->mode)) < 0) {
return fd;
}
@@ -312,8 +322,10 @@ archive_extract(void)
struct stat sb;
struct omar_hdr *hdr;
int fd, error;
+ size_t len;
off_t off;
char namebuf[256];
+ char pathbuf[256];
if ((fd = open(inpath, O_RDONLY)) < 0) {
perror("open");
@@ -351,20 +363,31 @@ archive_extract(void)
fprintf(stderr, "bad magic\n");
break;
}
+ if (hdr->rev != OMAR_REV) {
+ fprintf(stderr, "cannot extract rev %d archive\n", hdr->rev);
+ fprintf(stderr, "current OMAR revision: %d\n", OMAR_REV);
+ }
name = (char *)hdr + sizeof(struct omar_hdr);
memcpy(namebuf, name, hdr->namelen);
namebuf[hdr->namelen] = '\0';
- printf("unpacking %s\n", namebuf);
+
+ /* Get the full path */
+ len = snprintf(pathbuf, sizeof(pathbuf), "%s/%s", outpath, namebuf);
+ if (len < 0) {
+ free(buf);
+ return len;
+ }
+ printf("unpacking %s\n", pathbuf);
if (hdr->type == OMAR_DIR) {
off = 512;
- mkpath(namebuf);
+ mkpath(hdr, pathbuf);
} else {
- off = ALIGN_UP(sizeof(hdr) + hdr->namelen + hdr->len, BLOCK_SIZE);
+ off = ALIGN_UP(sizeof(*hdr) + hdr->namelen + hdr->len, BLOCK_SIZE);
p = (char *)hdr + sizeof(struct omar_hdr);
p += hdr->namelen;
- extract_single(p, hdr->len, namebuf);
+ extract_single(hdr, p, hdr->len, pathbuf);
}
hdr = (struct omar_hdr *)((char *)hdr + off);
diff --git a/usr.bin/Makefile b/usr.bin/Makefile
index 4c17ddf..e84831a 100644
--- a/usr.bin/Makefile
+++ b/usr.bin/Makefile
@@ -19,3 +19,4 @@ all:
make -C echo/ $(ARGS)
make -C readcore/ $(ARGS)
make -C login/ $(ARGS)
+ make -C sleep/ $(ARGS)
diff --git a/usr.bin/date/date.c b/usr.bin/date/date.c
index a47e3eb..ab26c4c 100644
--- a/usr.bin/date/date.c
+++ b/usr.bin/date/date.c
@@ -32,6 +32,7 @@
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
+#include <string.h>
#define MONTHS_PER_YEAR 12
#define DAYS_PER_WEEK 7
@@ -51,19 +52,63 @@ static const char *daytab[] = {
"Fri"
};
+static int
+set_time(int clock_fd, struct date *dp, char *timestr)
+{
+ uint32_t hour, min, sec;
+ char *p;
+
+ /* Hour */
+ p = strtok(timestr, ":");
+ if (p == NULL)
+ return -1;
+ hour = atoi(p);
+
+ /* Minute */
+ p = strtok(NULL, ":");
+ if (p == NULL)
+ return -1;
+ min = atoi(p);
+
+ /* Second */
+ p = strtok(NULL, ":");
+ if (p == NULL)
+ return -1;
+ sec = atoi(p);
+
+ /* Set the time */
+ dp->hour = hour;
+ dp->min = min;
+ dp->sec = sec;
+ write(clock_fd, dp, sizeof(*dp));
+ return 0;
+}
+
int
-main(void)
+main(int argc, char **argv)
{
const char *day, *month;
char date_str[32];
struct date d;
- int rtc_fd;
+ int rtc_fd, error = 0;
- if ((rtc_fd = open("/dev/rtc", O_RDONLY)) < 0) {
+ if ((rtc_fd = open("/dev/rtc", O_RDWR)) < 0) {
return rtc_fd;
}
+
read(rtc_fd, &d, sizeof(d));
+
+ /*
+ * If a time was specified to be set in the
+ * 'hh:mm:ss' format, attempt to write it.
+ */
+ if (argc > 1) {
+ error = set_time(rtc_fd, &d, argv[1]);
+ if (error < 0)
+ printf("bad time specified, not set\n");
+ }
+
close(rtc_fd);
/* This should not happen */
diff --git a/usr.bin/fetch/fetch.c b/usr.bin/fetch/fetch.c
index 42c2825..175cd0e 100644
--- a/usr.bin/fetch/fetch.c
+++ b/usr.bin/fetch/fetch.c
@@ -32,18 +32,19 @@
#include <string.h>
#include <stdio.h>
+static const char *user = "unknown";
+
#define ASCII_ART \
" ____ \n" \
" | \\__\\ \n" \
- " | /\\ \\ user: root\n" \
+ " | /\\ \\ user: %s\n" \
" |/ \\ \\ OS: Hyra/amd64 v"_OSVER"\n" \
" \\ R. \\ \\ arch: "_OSARCH"\n" \
- " \\ I. \\ \\"
-
+ " \\ I. \\ \\\n"
int
main(void)
{
- puts(ASCII_ART);
+ printf(ASCII_ART, getlogin());
return 0;
}
diff --git a/usr.bin/getconf/getconf.c b/usr.bin/getconf/getconf.c
index c60bf5d..f028e76 100644
--- a/usr.bin/getconf/getconf.c
+++ b/usr.bin/getconf/getconf.c
@@ -37,12 +37,15 @@
struct sysvar {
const char *var;
uint8_t auxv : 1;
- uint8_t val;
+ uint32_t val;
};
static struct sysvar vartab[] = {
{ "PAGESIZE", 1, AT_PAGESIZE },
{ "CHAR_BIT", 0, CHAR_BIT },
+ { "NAME_MAX", 0, NAME_MAX },
+ { "PATH_MAX", 0, PATH_MAX },
+ { "SSIZE_MAX", 0, SSIZE_MAX },
{ NULL, 0, 0 }
};
diff --git a/usr.bin/login/login.c b/usr.bin/login/login.c
index c5af6c0..e9b5e88 100644
--- a/usr.bin/login/login.c
+++ b/usr.bin/login/login.c
@@ -30,6 +30,7 @@
#include <sys/spawn.h>
#include <sys/types.h>
#include <sys/errno.h>
+#include <crypto/sha256.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -46,11 +47,11 @@
#define is_ascii(C) ((C) >= 0 && (C) <= 128)
#define is_digit(C) ((C >= '0' && C <= '9'))
-#define USERNAME "root"
#define DEFAULT_SHELL "/usr/bin/osh"
static char buf[64];
static uint8_t buf_i;
+static short echo_chars = 1;
/*
* Verify a UID is valid
@@ -83,20 +84,25 @@ check_uid(const char *uid)
* (username)
*
* @alias: Alias to lookup
+ * @hash: Password hash
* @entry: /etc/passwd entry
*
* Returns -1 on failure
* Returns 0 if the entry matches
*/
static int
-check_user(char *alias, char *entry)
+check_user(char *alias, char *hash, char *entry)
{
- const char *p, *shell;
+ const char *p;
+ char shell_path[256];
char *shell_argv[] = { DEFAULT_SHELL, NULL };
char *envp[] = { NULL };
- size_t row = 0;
- short retval = -1;
+ size_t len, row = 0;
size_t line = 1;
+ short have_user = 0;
+ short have_pw = 0;
+ short have_uid = 0;
+ short have_shell = 0;
uid_t uid = -1;
if (alias == NULL || entry == NULL) {
@@ -115,9 +121,14 @@ check_user(char *alias, char *entry)
switch (row) {
case ROW_USERNAME:
if (strcmp(p, alias) == 0) {
- retval = 0;
+ have_user = 1;
}
break; /* UNREACHABLE */
+ case ROW_HASH:
+ if (strcmp(p, hash) == 0) {
+ have_pw = 1;
+ }
+ break;
case ROW_USERID:
if (check_uid(p) != 0) {
printf("bad uid @ line %d\n", line);
@@ -125,9 +136,18 @@ check_user(char *alias, char *entry)
}
uid = atoi(p);
+ have_uid = 1;
break;
case ROW_SHELL:
- /* TODO */
+ len = strlen(p) - 1;
+ if (len >= sizeof(shell_path) - 1) {
+ printf("bad shell path @ line %d\n", line);
+ return -1;
+ }
+
+ memcpy(shell_path, p, len);
+ shell_path[len] = '\0';
+ have_shell = 1;
break;
}
@@ -136,31 +156,34 @@ check_user(char *alias, char *entry)
++line;
}
- if (uid < 0) {
- printf("failed to set uid\n");
+ /*
+ * We need to have found the password hash,
+ * the username, AND the UID. If we have not,
+ * then this has failed.
+ */
+ if (!have_pw || !have_user || !have_uid) {
return -1;
}
- if (shell == NULL) {
- printf("failed to read shell path\n");
+
+ /* Do we have the shell path? */
+ if (!have_shell) {
return -1;
}
- if (retval == 0) {
- setuid(uid);
- spawn(shell_argv[0], shell_argv, envp, SPAWN_WAIT);
- }
- return retval;
+ setuid(uid);
+ shell_argv[0] = shell_path;
+ spawn(shell_argv[0], shell_argv, envp, SPAWN_WAIT);
+ return 0;
}
static char *
getstr(void)
{
- char c;
+ char c, printc;
int input;
buf_i = 0;
-
for (;;) {
if ((input = getchar()) < 0) {
continue;
@@ -171,6 +194,13 @@ getstr(void)
continue;
}
+ /*
+ * If we want to echo characters, 'printc' becomes
+ * exactly the character we got. Otherwise, just
+ * print little stars to redact it.
+ */
+ printc = echo_chars ? c : '*';
+
/* return on newline */
if (c == '\n') {
buf[buf_i] = '\0';
@@ -187,7 +217,7 @@ getstr(void)
} else if (is_ascii(c) && buf_i < sizeof(buf) - 1) {
/* write to fd and add to buffer */
buf[buf_i++] = c;
- putchar(c);
+ putchar(printc);
}
}
}
@@ -195,24 +225,50 @@ getstr(void)
static int
getuser(FILE *fp)
{
- char *alias;
+ char *pwtmp, *alias, *p;
char entry[256];
+ char pwhash[SHA256_HEX_SIZE];
int retval;
printf("username: ");
- alias = getstr();
+ p = getstr();
+ alias = strdup(p);
+
+ /* Grab the password now */
+ echo_chars = 0;
+ printf("password: ");
+ p = getstr();
+ pwtmp = strdup(p);
+ sha256_hex(pwtmp, strlen(pwtmp), pwhash);
+
+ /* Paranoia */
+ memset(pwtmp, 0, strlen(pwtmp));
+ buf_i = 0;
+ memset(buf, 0, sizeof(buf));
+
+ /* Clean up */
+ free(pwtmp);
+ pwtmp = NULL;
+
+ /* See if anything matches */
while (fgets(entry, sizeof(entry), fp) != NULL) {
- retval = check_user(alias, entry);
+ retval = check_user(alias, pwhash, entry);
if (retval == 0) {
printf("login: successful\n");
+ free(alias);
return 0;
}
}
- printf("bad username \"%s\"\n", alias);
+ /* If we reach this point, bad creds */
+ free(alias);
+ alias = NULL;
+
+ printf("bad username or password\n");
fseek(fp, 0, SEEK_SET);
memset(buf, 0, sizeof(buf));
buf_i = 0;
+ echo_chars = 1;
return -1;
}
@@ -228,7 +284,6 @@ main(void)
}
printf("- Please authenticate yourself -\n");
- printf("Default user 'root'\n");
for (;;) {
if (getuser(fp) == 0) {
break;
diff --git a/usr.bin/osh/osh.c b/usr.bin/osh/osh.c
index 0bce357..5bcd2e2 100644
--- a/usr.bin/osh/osh.c
+++ b/usr.bin/osh/osh.c
@@ -60,7 +60,7 @@
"clear - Clear the screen\n" \
"exit - Exit the shell"
-#define PROMPT "[root::osmora]~ "
+#define PROMPT "[%s::osmora]~ "
static char buf[64];
static uint8_t buf_i;
@@ -394,7 +394,7 @@ main(int argc, char **argv)
puts(WELCOME);
while (running) {
memset(prog_argv, 0, sizeof(prog_argv));
- fputs(PROMPT, stdout);
+ printf(PROMPT, getlogin());
input = getstr();
if (input[0] == '\0') {
diff --git a/usr.bin/sleep/Makefile b/usr.bin/sleep/Makefile
new file mode 100644
index 0000000..5bfd04f
--- /dev/null
+++ b/usr.bin/sleep/Makefile
@@ -0,0 +1,6 @@
+include user.mk
+
+CFILES = $(shell find . -name "*.c")
+
+$(ROOT)/base/usr/bin/sleep:
+ gcc $(CFILES) -o $@ $(INTERNAL_CFLAGS)
diff --git a/usr.bin/sleep/sleep.c b/usr.bin/sleep/sleep.c
new file mode 100644
index 0000000..f7d07f8
--- /dev/null
+++ b/usr.bin/sleep/sleep.c
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Hyra nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <time.h>
+#include <string.h>
+#include <stdio.h>
+
+int
+main(int argc, char **argv)
+{
+ struct timespec ts;
+ uint16_t nsec = 0;
+
+ if (argc < 2) {
+ printf("sleep: usage: sleep <seconds>\n");
+ return -1;
+ }
+
+ nsec = atoi(argv[1]);
+ if (nsec == 0) {
+ printf("sleep: bad argument\n");
+ return -1;
+ }
+
+ ts.tv_nsec = 0;
+ ts.tv_sec = nsec;
+ sleep(&ts, &ts);
+ return 0;
+}