Internal include file.
authorJarkko Sakkinen <ext-jarkko.2.sakkinen@nokia.com>
Wed, 24 Nov 2010 16:50:45 +0000 (08:50 -0800)
committerJarkko Sakkinen <ext-jarkko.2.sakkinen@nokia.com>
Wed, 24 Nov 2010 16:50:45 +0000 (08:50 -0800)
src/smack_labels.c
src/smack_rules.c
src/smack_xattr.c

index 31a2a19..0c6bfdc 100644 (file)
@@ -4,8 +4,8 @@
 #include <string.h>
 #include <uthash.h>
 #include "smack.h"
+#include "smack_internal.h"
 
-#define SMACK64_LEN 23
 struct smack_label {
        char *long_name;
        char *short_name;
index 7bbef86..b4df4c2 100644 (file)
 #include <stdio.h>
 #include <stdlib.h>
 #include <uthash.h>
-
-#define SMACK64_LEN 23
-
-#define SMACK_ACC_R 1
-#define SMACK_ACC_W 2
-#define SMACK_ACC_X 4
-#define SMACK_ACC_A 16
-#define SMACK_ACC_LEN 4
+#include "smack_internal.h"
 
 struct smack_object {
        char *object;
@@ -153,7 +146,7 @@ int smack_rule_set_save_to_file(SmackRuleSet handle, const char *path)
        struct smack_subject *s, *stmp;
        struct smack_object *o, *otmp;
        FILE *file;
-       char str[SMACK_ACC_LEN + 1];
+       char str[ACC_LEN + 1];
        int err = 0;
 
        file = fopen(path, "w+");
@@ -364,19 +357,19 @@ inline unsigned str_to_ac(const char *str)
                switch (str[i]) {
                case 'r':
                case 'R':
-                       access |= SMACK_ACC_R;
+                       access |= ACC_R;
                        break;
                case 'w':
                case 'W':
-                       access |= SMACK_ACC_W;
+                       access |= ACC_W;
                        break;
                case 'x':
                case 'X':
-                       access |= SMACK_ACC_X;
+                       access |= ACC_X;
                        break;
                case 'a':
                case 'A':
-                       access |= SMACK_ACC_A;
+                       access |= ACC_A;
                        break;
                default:
                        break;
@@ -389,23 +382,23 @@ inline void ac_to_config_str(unsigned access, char *str)
 {
        int i;
        i = 0;
-       if ((access & SMACK_ACC_R) != 0)
+       if ((access & ACC_R) != 0)
                str[i++] = 'r';
-       if ((access & SMACK_ACC_W) != 0)
+       if ((access & ACC_W) != 0)
                str[i++] = 'w';
-       if ((access & SMACK_ACC_X) != 0)
+       if ((access & ACC_X) != 0)
                str[i++] = 'x';
-       if ((access & SMACK_ACC_A) != 0)
+       if ((access & ACC_A) != 0)
                str[i++] = 'a';
        str[i] = '\0';
 }
 
 inline void ac_to_kernel_str(unsigned access, char *str)
 {
-       str[0] = ((access & SMACK_ACC_R) != 0) ? 'r' : '-';
-       str[1] = ((access & SMACK_ACC_W) != 0) ? 'w' : '-';
-       str[2] = ((access & SMACK_ACC_X) != 0) ? 'x' : '-';
-       str[3] = ((access & SMACK_ACC_A) != 0) ? 'a' : '-';
+       str[0] = ((access & ACC_R) != 0) ? 'r' : '-';
+       str[1] = ((access & ACC_W) != 0) ? 'w' : '-';
+       str[2] = ((access & ACC_X) != 0) ? 'x' : '-';
+       str[3] = ((access & ACC_A) != 0) ? 'a' : '-';
        str[4] = '\0';
 }
 
index 9cf09d6..36e8f4f 100644 (file)
  * Jarkko Sakkinen <ext-jarkko.2.sakkinen@nokia.com>
  */
 
-#include "smack.h"
 #include <sys/types.h>
 #include <attr/xattr.h>
 #include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <uthash.h>
-
-#define SMACK64_LEN 23
-#define SMACK_PROC_PATH "/proc/%d/attr/current"
-#define LINE_BUFFER_SIZE 255
+#include "smack.h"
+#include "smack_internal.h"
 
 int smack_xattr_set_to_file(const char *path, const char *attr,
                            const char *smack, SmackLabelSet labels)
@@ -84,16 +81,16 @@ int smack_xattr_get_from_file(const char *path, const char *attr,
 
 int smack_xattr_get_from_proc(int pid, char **smack, SmackLabelSet labels)
 {
-       char buf[LINE_BUFFER_SIZE];
+       char buf[512];
        FILE *file;
 
-       snprintf(buf, LINE_BUFFER_SIZE, SMACK_PROC_PATH, pid);
+       snprintf(buf, sizeof(buf), SMACK_PROC_PATH, pid);
 
        file = fopen(buf, "r");
        if (file == NULL)
                return -1;
 
-       if (fgets(buf, LINE_BUFFER_SIZE, file) == NULL) {
+       if (fgets(buf, sizeof(buf), file) == NULL) {
                fclose(file);
                return -1;
        }