Add to wait for lazymount when user is krate 61/89061/2
authorSungbae Yoo <sungbae.yoo@samsung.com>
Thu, 22 Sep 2016 02:49:34 +0000 (11:49 +0900)
committerSungbae Yoo <sungbae.yoo@samsung.com>
Thu, 22 Sep 2016 05:00:30 +0000 (14:00 +0900)
Signed-off-by: Sungbae Yoo <sungbae.yoo@samsung.com>
Change-Id: If8427749f902ad78088644772cc3c26e5ff8a444

module/krate.cpp

index ff21670..b81a901 100644 (file)
@@ -14,6 +14,7 @@
  *  limitations under the License
  */
 
+#include <dlfcn.h>
 #include <syslog.h>
 #include <security/pam_ext.h>
 #include <security/pam_modules.h>
 #include <klay/xml/parser.h>
 #include <klay/xml/document.h>
 
+#define KRATE_UID_MIN 60001
+#define KRATE_UID_MAX 60100
+
 #define LAZYMOUNT_EXTERN extern
+#define LAZYMOUNT_LIB "/usr/lib/liblazymount.so.0"
 
 std::string buildKrateManifestPath(const std::string& name)
 {
@@ -49,6 +54,45 @@ std::string getKrateName(pam_handle_t* handle)
        return static_cast<const char*>(retItem);
 }
 
+static int wait_condition(void)
+{
+    int r;
+    void *h;
+
+    int (*wait_mount_user)(void);
+
+    r = access(LAZYMOUNT_LIB,F_OK);
+    if (r < 0){
+        fprintf(stderr, "cannot find lazymount module - No support lazymount\n");
+        return 0;
+    }
+
+    h = dlopen(LAZYMOUNT_LIB, RTLD_LAZY);
+    if (!h) {
+        fprintf(stderr, "lazymount module dlopen error\n");
+        return -1;
+    }
+
+       do{
+        wait_mount_user = (int (*)())dlsym(h,"wait_mount_user");
+        if (!wait_mount_user) {
+            fprintf(stderr, "dlsym wait_mount_user error\n");
+            dlclose(h);
+            return -1;
+        }
+    } while (0);
+
+    r = wait_mount_user();
+    if (r < 0) {
+        fprintf(stderr, "wait_mout_user failed\n");
+        dlclose(h);
+        return r;
+    }
+
+    dlclose(h);
+    return 0;
+}
+
 extern "C" {
 LAZYMOUNT_EXTERN  __attribute__((visibility("default")))
 int container_preprocess(char* id) {
@@ -63,6 +107,10 @@ int container_preprocess(char* id) {
                        builder.unshareNamespace();
                };
                createSession(user, sessionBuilder);
+
+               if (user.getUid() >= KRATE_UID_MIN && user.getUid() <= KRATE_UID_MAX ) {
+                       wait_condition();
+               }
        } catch (runtime::Exception& e) {
                std::cerr << "krate error : " << e.what() <<std::endl << std::flush;
                return -1;