summary refs log tree commit diff
path: root/crypt.awk
diff options
context:
space:
mode:
authorpulux <pulux@pf4sh.de>2015-01-07 16:57:05 +0100
committerpulux <pulux@pf4sh.de>2015-01-07 16:57:05 +0100
commit644afccb4778474c4688de7aff75008a838b3ffb (patch)
tree0782e2030aa761f93a26df371b870f73ce39deb2 /crypt.awk
parent7988fd1e20d9eeff0d6d0a80792388333acbece7 (diff)
downloadrunit-void-644afccb4778474c4688de7aff75008a838b3ffb.tar.gz
runit-void-644afccb4778474c4688de7aff75008a838b3ffb.tar.xz
runit-void-644afccb4778474c4688de7aff75008a838b3ffb.zip
clean the parser function
Diffstat (limited to 'crypt.awk')
-rw-r--r--crypt.awk127
1 files changed, 76 insertions, 51 deletions
diff --git a/crypt.awk b/crypt.awk
index dcb0476..e333504 100644
--- a/crypt.awk
+++ b/crypt.awk
@@ -7,71 +7,96 @@ NF>4 { print "a valid crypttab has max 4 cols not " NF >"/dev/stderr"; next }
     else src=o_src[1];
 
     # no password or none is given, ask fo it
-    if ( NF == 2 ) system("cryptsetup luksOpen " src " " $1);
-    else if (NF == 3 )
-    {
+    if ( NF == 2 ) {
+        ccmd="cryptsetup luksOpen " src " " $1;
+        system(ccmd);
+        ccmd="";
+    }
+    else if (NF == 3 ) {
+        dest=$1
+        key=$3
         split($3, po, "=");
-        if ( po[1] == "none") system("cryptsetup luksOpen " src " " $1);
-        else system("cryptsetup luksOpen -d " $3 " " src" " $1);
+        if ( po[1] == "none") ccmd="cryptsetup luksOpen " src " " dest;
+        else ccmd="cryptsetup luksOpen -d " key " " src" " dest;
+        system(ccmd);
+        ccmd="";
     }
-    else
+    else {
     # the option fild is not empty parse the options
-    {
+        dest=$1
+        key=$3
         split($4, opts, ",");
-        for(i in opts)
-        {
+        for(i in opts) {
             split(opts[i], para, "=");
-            if ( para[1] == "readonly" ) cmd=cmd "-r ";
-            else if ( para[1] == "cipher" ) cmd=cmd "-c " para[2] " ";
-            else if ( para[1] == "size" ) cmd=cmd "-s " para[2] " ";
-            else if ( para[1] == "hash" ) cmd=cmd "-h " para[2] " ";
-            else if ( para[1] == "offset" ) cmd=cmd "-o " para[2] " ";
-            else if ( para[1] == "skip" ) cmd=cmd "-p " para[2] " ";
-            else if ( para[1] == "tries" ) cmd=cmd "-T " para[2] " ";
-            else if ( para[1] == "verify" ) cmd=cmd "-y ";
-            else if ( para[1] == "discard" ) cmd=cmd "--allow-discards ";
-            else if ( para[1] == "swap" ) makeswap="y";
-            else if ( para[1] == "tmp" ) maketmp="y";
-            else if ( para[1] == "luks" ) useluks="y";
-            else if ( para[1] == "keyscript" ) keyscript=para[2];
-            else if ( para[1] == "keyslot" ) luksparams="--key-slot " para[2] " ";
-            else
-            {
-                print "no valid option " para[1] >"/dev/stderr";
+            par=para[1];
+            val=para[2]
+            if ( par == "readonly" || par == "read-only") cmd=cmd "-r ";
+            else if ( par == "cipher" ) cmd=cmd "-c " val " ";
+            else if ( par == "size" ) cmd=cmd "-s " val " ";
+            else if ( par == "hash" ) cmd=cmd "-h " val " ";
+            else if ( par == "offset" ) cmd=cmd "-o " val " ";
+            else if ( par == "skip" ) cmd=cmd "-p " val " ";
+            else if ( par == "tries" ) cmd=cmd "-T " val " ";
+            else if ( par == "verify" ) cmd=cmd "-y ";
+            else if ( par == "discard" ) cmd=cmd "--allow-discards ";
+            else if ( par == "swap" ) makeswap="y";
+            else if ( par == "luks" ) use_luks="y";
+            #else if ( par == "noauto" )
+            #else if ( par == "nofail" )
+            #else if ( par == "plain" )
+            #else if ( par == "timeout" )
+            #else if ( par == "tmp" )
+            else if ( par == "keyscript" ) {use_keyscript="y"; keyscript=val;}
+            else if ( par == "keyslot" || par == "key-slot" ) luksparams=luksparams "-S " val " ";
+            else {
+                print "option: " par " not supported " >"/dev/stderr";
                 cmd="";
                 makeswap="";
-                maketmp="";
-                useluks="";
+                use_luks="";
+                use_keyscript="";
                 luksparams="";
                 next;
             }
         }
-        if ( makeswap == "y" )
-        {
-            system("cryptsetup " cmd " -d " $3 " create " src " " $1);
-            system("mkswap /dev/mapper/" $1 );
+        if ( makeswap == "y" && use_luks != "y" ) {
+            ccmd="cryptsetup " cmd " -d " key " create " src " " dest1;
+            ccmd_2="mkswap /dev/mapper/" dest;
+            cmd="";
+            makeswap="";
+            usekeyscript="";
+            luksparams="";
+            system(ccmd);
+            system(ccmd_2);
+            ccmd="";
+            ccmd_2="";
+            next;
         }
-        else if ( maketmp == "y" )
-        {
-            system("cryptsetup " cmd " -d " $3 " create " src " " $1"_unformatted");
-            system("mkefs -t ext4 -q /dev/mapper/" $1"_unformatted" );
-            mdir="/run/cryptsetup/" $1;
-            system("mkdir -p " mdir);
-            system("mount /dev/mapper/" $1 "_unformatted  " mdir);
-            system("chmod 1777 " mdir);
-            system("umount " mdir);
-            #system("rmdir" mdir);
-            system("dmsetup rename " $1"_unformated " $1)
+        if ( use_luks == "y" && makeswap != "y" ){
+            if ( use_keyscript == "y") {
+                ccmd=keyscript " | cryptsetup" luksparams " luksOpen -d - " src " " dest;
+                use_keyscript="";
+            }
+            else {
+                if ( key == "none" ){
+                    ccmd="cryptsetup" luksparams " luksOpen " src " " dest;
+                }
+                else {
+                    ccmd="cryptsetup" luksparams " luksOpen -d " key " " src " " dest;
+                }
+            }
         }
-        else if ( system("cryptsetup isLuks " src ) )
-        {
-            print "options are invalid for LUKS partitions" >"/dev/stderr";
-            system("cryptsetup Open -d " $3 " " src " " $1);
+        else {
+            print "use swap OR luks as option" >"/dev/stderr";
+            ccmd="";
         }
-        else if (para[1] == "keyscript" )
-        {
-            system( keyscript "| cryptsetup luksOpen -d - " src " " $1);
+        cmd="";
+        makeswap="";
+        use_luks="";
+        use_keyscript="";
+        luksparams="";
+        if ( ccmd != ""){
+            system(ccmd);
+            ccmd=""
         }
-        else print "other" >"/dev/stderr";
     }
 }