summaryrefslogtreecommitdiffstats
path: root/core/jni
diff options
context:
space:
mode:
authorKenny Root <kroot@android.com>2012-08-16 15:29:41 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2012-08-16 15:29:41 -0700
commita2e8365cc883de0d3e56e9f4af350ecfe1b8fc4c (patch)
tree402949d2d3cce35eceaf665ca547deb6a106d745 /core/jni
parent617ccc081f18f563aa953556c22ace10a1998f34 (diff)
parent9b0da58e3a30b760de37138cdd51d20f269c383e (diff)
downloadframeworks_base-a2e8365cc883de0d3e56e9f4af350ecfe1b8fc4c.zip
frameworks_base-a2e8365cc883de0d3e56e9f4af350ecfe1b8fc4c.tar.gz
frameworks_base-a2e8365cc883de0d3e56e9f4af350ecfe1b8fc4c.tar.bz2
am 9b0da58e: Merge "Introduce a restorecon JNI binding."
* commit '9b0da58e3a30b760de37138cdd51d20f269c383e': Introduce a restorecon JNI binding.
Diffstat (limited to 'core/jni')
-rw-r--r--core/jni/android_os_SELinux.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/core/jni/android_os_SELinux.cpp b/core/jni/android_os_SELinux.cpp
index 40443ff..e813c38 100644
--- a/core/jni/android_os_SELinux.cpp
+++ b/core/jni/android_os_SELinux.cpp
@@ -1,3 +1,19 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
#define LOG_TAG "SELinuxJNI"
#include <utils/Log.h>
@@ -6,6 +22,7 @@
#include "android_runtime/AndroidRuntime.h"
#ifdef HAVE_SELINUX
#include "selinux/selinux.h"
+#include "selinux/android.h"
#endif
#include <errno.h>
@@ -458,6 +475,27 @@ namespace android {
}
/*
+ * Function: native_restorecon
+ * Purpose: restore default SELinux security context
+ * Parameters: pathname: the pathname for the file to be relabeled
+ * Returns: boolean: (true) file label successfully restored, (false) otherwise
+ * Exceptions: none
+ */
+ static jboolean native_restorecon(JNIEnv *env, jobject clazz, jstring pathname) {
+#ifdef HAVE_SELINUX
+ if (isSELinuxDisabled)
+ return true;
+
+ const char *file = const_cast<char *>(env->GetStringUTFChars(pathname, NULL));
+ int ret = selinux_android_restorecon(file);
+ env->ReleaseStringUTFChars(pathname, file);
+ return (ret == 0);
+#else
+ return true;
+#endif
+ }
+
+ /*
* JNI registration.
*/
static JNINativeMethod method_table[] = {
@@ -472,6 +510,7 @@ namespace android {
{ "getPidContext" , "(I)Ljava/lang/String;" , (void*)getPidCon },
{ "isSELinuxEnforced" , "()Z" , (void*)isSELinuxEnforced},
{ "isSELinuxEnabled" , "()Z" , (void*)isSELinuxEnabled },
+ { "native_restorecon" , "(Ljava/lang/String;)Z" , (void*)native_restorecon},
{ "setBooleanValue" , "(Ljava/lang/String;Z)Z" , (void*)setBooleanValue },
{ "setFileContext" , "(Ljava/lang/String;Ljava/lang/String;)Z" , (void*)setFileCon },
{ "setFSCreateContext" , "(Ljava/lang/String;)Z" , (void*)setFSCreateCon },