FSTAB := rootfs/etc/fstab
RCS := rootfs/etc/init.d/rcS
PASSWD := rootfs/etc/passwd
+SHADOW := rootfs/etc/shadow
INITRD_FILES := $(FULLTEST_ELF):sbin/fulltest \
$(USER_BUILD)/cmds/init/init.elf:sbin/init \
$(foreach cmd,$(USER_BIN_NAMES),$(USER_BUILD)/cmds/$(cmd)/$(cmd).elf:bin/$(cmd)) \
$(LDSO_ELF):lib/ld.so $(ULIBC_SO):lib/libc.so \
$(PIE_SO):lib/libpietest.so $(PIE_ELF):bin/pie_test \
- $(FSTAB):etc/fstab $(RCS):etc/init.d/rcS $(PASSWD):etc/passwd
+ $(FSTAB):etc/fstab $(RCS):etc/init.d/rcS $(PASSWD):etc/passwd $(SHADOW):etc/shadow
-INITRD_DEPS := $(MKINITRD) $(FULLTEST_ELF) $(USER_CMD_ELFS) $(LDSO_ELF) $(ULIBC_SO) $(PIE_SO) $(PIE_ELF) $(FSTAB) $(RCS) $(PASSWD)
+INITRD_DEPS := $(MKINITRD) $(FULLTEST_ELF) $(USER_CMD_ELFS) $(LDSO_ELF) $(ULIBC_SO) $(PIE_SO) $(PIE_ELF) $(FSTAB) $(RCS) $(PASSWD) $(SHADOW)
# doom (build via 'make doom', included in initrd if present)
doom: $(DOOM_SENTINEL) $(ULIBC_LIB) $(ULIBC_SO)
#include <stddef.h>
/* /etc/passwd and /etc/group parsing with static fallback.
- * Format: name:passwd:uid:gid:gecos:dir:shell */
+ * Format: name:passwd:uid:gid:gecos:dir:shell
+ * /etc/shadow format: name:passwd:lastchg:min:max:warn:inactive:expire */
static struct passwd _root = {
.pw_name = "root",
if (_gr_idx == 0) { _gr_idx++; return &_root_grp; }
return (struct group*)0;
}
+
+/* Simple password verification against /etc/shadow (plaintext for now) */
+int check_password(const char* username, const char* password) {
+ if (!username || !password) return -1;
+
+ FILE* fp = fopen("/etc/shadow", "r");
+ if (!fp) return -1;
+
+ char line[256];
+ while (fgets(line, (int)sizeof(line), fp)) {
+ /* Parse shadow line: name:passwd:lastchg:min:max:warn:inactive:expire */
+ char* saveptr = NULL;
+ char* name = strtok_r(line, ":\n", &saveptr);
+ if (!name) continue;
+
+ if (strcmp(name, username) == 0) {
+ char* passwd = strtok_r(NULL, ":\n", &saveptr);
+ if (!passwd) { fclose(fp); return -1; }
+
+ /* '*' or '!' means locked account */
+ if (passwd[0] == '*' || passwd[0] == '!') {
+ fclose(fp);
+ return -1;
+ }
+
+ /* Simple plaintext comparison (TODO: add SHA256/crypt) */
+ int match = (strcmp(passwd, password) == 0);
+ fclose(fp);
+ return match ? 0 : -1;
+ }
+ }
+
+ fclose(fp);
+ return -1; /* User not found */
+}