Smack labels for databases are restored after database removal
authorKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Mon, 11 Mar 2013 14:00:06 +0000 (15:00 +0100)
committerGerrit Code Review <gerrit2@kim11>
Thu, 21 Mar 2013 09:14:38 +0000 (18:14 +0900)
[Issue#] N/A
[Feature/Bug] N/A
[Problem] After calling wrt_reset_all.sh wrt database labels are reset to "_"
[Cause] Db files are removed and created with default label
[Solution] Old label is stored and applied to newly created files

[Verification]
1.Check /opt/dbspace/.wrt.db* labels with chsmack [filename]. It should be
"wrt-commons::db_wrt"
2.Run wrt_reset_all.sh. Check labels again. They should be the same.

Change-Id: I885638d482c921fadea0a74d773ce8a548387483

etc/wrt_commons_create_clean_db.sh

index d333d9d..f1287c2 100755 (executable)
 
 for name in wrt wrt_autosave wrt_custom_handler
 do
 
 for name in wrt wrt_autosave wrt_custom_handler
 do
+    # extract smack label before removal
+    DB_LABEL=""
+    if [ -f /opt/dbspace/.$name.db ]
+    then
+        DB_LABEL=`chsmack /opt/dbspace/.$name.db | sed -r "s/.*access=\"([^\"]+)\"/\1/"`
+    fi
     rm -f /opt/dbspace/.$name.db
     rm -f /opt/dbspace/.$name.db
+
+    # extract smack label before removal
+    JOURNAL_LABEL=""
+    if [ -f /opt/dbspace/.$name.db-journal ]
+    then
+        JOURNAL_LABEL=`chsmack /opt/dbspace/.$name.db-journal | sed -r "s/.*access=\"([^\"]+)\"/\1/"`
+    fi
     rm -f /opt/dbspace/.$name.db-journal
     rm -f /opt/dbspace/.$name.db-journal
+
     SQL="PRAGMA journal_mode = PERSIST;"
     sqlite3 /opt/dbspace/.$name.db "$SQL"
     SQL=".read /usr/share/wrt-engine/"$name"_db.sql"
     SQL="PRAGMA journal_mode = PERSIST;"
     sqlite3 /opt/dbspace/.$name.db "$SQL"
     SQL=".read /usr/share/wrt-engine/"$name"_db.sql"
@@ -27,7 +41,20 @@ do
     chown 0:6026 /opt/dbspace/.$name.db-journal
     chmod 660 /opt/dbspace/.$name.db
     chmod 660 /opt/dbspace/.$name.db-journal
     chown 0:6026 /opt/dbspace/.$name.db-journal
     chmod 660 /opt/dbspace/.$name.db
     chmod 660 /opt/dbspace/.$name.db-journal
+
     pkill -9 security-serv
     pkill -9 security-serv
+
+    # restore smack label
+    if [ -n "$DB_LABEL" ]
+    then
+        chsmack -a $DB_LABEL /opt/dbspace/.$name.db
+    fi
+
+    # restore smack label
+    if [ -n "$JOURNAL_LABEL" ]
+    then
+        chsmack -a $JOURNAL_LABEL /opt/dbspace/.$name.db-journal
+    fi
 done
 
 
 done