Browse Source

reimplement cryptinit as shell script (add new files)

Waldemar Brodkorb 14 years ago
parent
commit
1bd2bb0a91
2 changed files with 78 additions and 0 deletions
  1. 61 0
      package/cryptinit/src/cryptinit
  2. 17 0
      package/cryptinit/src/p.c

+ 61 - 0
package/cryptinit/src/cryptinit

@@ -0,0 +1,61 @@
+#!/bin/sh
+
+load_modules() {
+	(sed "s,^[^#][^[:space:]]*,insmod /lib/modules/$(uname -r)/&.ko," $* | sh 2>&- || :)
+}
+
+echo -n "Kernel currently running: "
+uname -rsmo
+echo -n "Kernel parameters: "; cat /proc/cmdline
+for word in $(cat /proc/cmdline) ; do
+    case $word in
+         [a-z]*=*)
+             eval "export $word"
+             ;;
+    esac
+done
+
+echo 0 > /proc/sys/kernel/printk
+
+load_modules /etc/modules
+for f in /etc/modules.d/*; do
+	[[ -e $f ]] && load_modules /etc/modules.d/*
+	break
+done
+
+fail=0
+count=0
+while true; do
+	echo -n "Password: "
+	stty -echo
+	read passphrase
+	stty echo
+	echo ""
+	echo $passphrase |cryptsetup --batch-mode luksOpen $swap swapcrypt
+	if [ $? = 0 ];then
+		break
+	fi
+	if [ $count = 2 ];then
+		echo "You are not allowed"
+		sleep 3
+		fail=1
+		break
+	fi
+	count=$(($count+1))
+done
+
+if [ $fail -eq 1 ];then
+	echo "Poweroff."
+	p
+fi
+
+echo "Try to resume from hibernation"
+echo "254:0" > /sys/power/resume
+
+echo $passphrase |cryptsetup --batch-mode luksOpen $root rootcrypt
+swapon /dev/mapper/swapcrypt
+mount /dev/mapper/rootcrypt /mnt
+umount /proc
+umount /sys
+umount /dev/pts
+umount /tmp

+ 17 - 0
package/cryptinit/src/p.c

@@ -0,0 +1,17 @@
+#include <stdio.h>
+#include <sys/reboot.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <unistd.h>
+
+int main() {
+	int pid;
+
+	sync();
+	if((pid=fork()) == 0) {
+		reboot(0x4321fedc);
+		_exit(0);
+	}
+	waitpid(pid, NULL, 0);
+	return(0);
+}