>From 8f0209cb995fd88e71e96efb0b98a0256df58d5d Mon Sep 17 00:00:00 2001
From: Dmitri Pal <dpal@dpal.csb>
Date: Sun, 7 Sep 2014 16:43:31 +0200
Subject: [PATCH 4/6] [INI] Refactored access control check

The patch includes implementation of the new internal function.
---
 ini/ini_fileobj.c |   66 +++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 47 insertions(+), 19 deletions(-)

diff --git a/ini/ini_fileobj.c b/ini/ini_fileobj.c
index da8339e..252c23e 100644
--- a/ini/ini_fileobj.c
+++ b/ini/ini_fileobj.c
@@ -705,14 +705,13 @@ const struct stat *ini_config_get_stat(struct ini_cfgfile *file_ctx)
     return ret;
 }
 
-
 /* Check access */
-int ini_config_access_check(struct ini_cfgfile *file_ctx,
-                            uint32_t flags,
-                            uid_t uid,
-                            gid_t gid,
-                            mode_t mode,
-                            mode_t mask)
+int access_check_int(struct stat *file_stats,
+                     uint32_t flags,
+                     uid_t uid,
+                     gid_t gid,
+                     mode_t mode,
+                     mode_t mask)
 {
     mode_t st_mode;
 
@@ -722,23 +721,18 @@ int ini_config_access_check(struct ini_cfgfile *file_ctx,
              INI_ACCESS_CHECK_GID |
              INI_ACCESS_CHECK_UID;
 
-    if ((file_ctx == NULL) || (flags == 0)) {
+    if (flags == 0) {
         TRACE_ERROR_NUMBER("Invalid parameter.", EINVAL);
         return EINVAL;
     }
 
-    if (file_ctx->stats_read == 0) {
-        TRACE_ERROR_NUMBER("Stats were not collected.", EINVAL);
-        return EINVAL;
-    }
-
     /* Check mode */
     if (flags & INI_ACCESS_CHECK_MODE) {
 
         TRACE_INFO_NUMBER("File mode as saved.",
-                          file_ctx->file_stats.st_mode);
+                          file_stats->st_mode);
 
-        st_mode = file_ctx->file_stats.st_mode;
+        st_mode = file_stats->st_mode;
         st_mode &= S_IRWXU | S_IRWXG | S_IRWXO;
         TRACE_INFO_NUMBER("File mode adjusted.", st_mode);
 
@@ -761,8 +755,8 @@ int ini_config_access_check(struct ini_cfgfile *file_ctx,
 
     /* Check uid */
     if (flags & INI_ACCESS_CHECK_UID) {
-        if (file_ctx->file_stats.st_uid != uid) {
-            TRACE_ERROR_NUMBER("GID:", file_ctx->file_stats.st_uid);
+        if (file_stats->st_uid != uid) {
+            TRACE_ERROR_NUMBER("GID:", file_stats->st_uid);
             TRACE_ERROR_NUMBER("GID passed in.", uid);
             TRACE_ERROR_NUMBER("Access denied.", EACCES);
             return EACCES;
@@ -771,8 +765,8 @@ int ini_config_access_check(struct ini_cfgfile *file_ctx,
 
     /* Check gid */
     if (flags & INI_ACCESS_CHECK_GID) {
-        if (file_ctx->file_stats.st_gid != gid) {
-            TRACE_ERROR_NUMBER("GID:", file_ctx->file_stats.st_gid);
+        if (file_stats->st_gid != gid) {
+            TRACE_ERROR_NUMBER("GID:", file_stats->st_gid);
             TRACE_ERROR_NUMBER("GID passed in.", gid);
             TRACE_ERROR_NUMBER("Access denied.", EACCES);
             return EACCES;
@@ -784,6 +778,40 @@ int ini_config_access_check(struct ini_cfgfile *file_ctx,
 
 }
 
+/* Check access */
+int ini_config_access_check(struct ini_cfgfile *file_ctx,
+                            uint32_t flags,
+                            uid_t uid,
+                            gid_t gid,
+                            mode_t mode,
+                            mode_t mask)
+{
+    int error = EOK;
+
+    TRACE_FLOW_ENTRY();
+
+    if (file_ctx == NULL) {
+        TRACE_ERROR_NUMBER("Invalid parameter.", EINVAL);
+        return EINVAL;
+    }
+
+    if (file_ctx->stats_read == 0) {
+        TRACE_ERROR_NUMBER("Stats were not collected.", EINVAL);
+        return EINVAL;
+    }
+
+    error =  access_check_int(&(file_ctx->file_stats),
+                              flags,
+                              uid,
+                              gid,
+                              mode,
+                              mask);
+
+    TRACE_FLOW_EXIT();
+    return error;
+
+}
+
 /* Determines if two file contexts are different by comparing:
  * - time stamp
  * - device ID
-- 
1.7.1

