From: Jarkko Sakkinen Date: Wed, 24 Nov 2010 16:50:45 +0000 (-0800) Subject: Internal include file. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d4f3b8fc057291b540eeeb48addfc072d3fcf12f;p=framework%2Fsecurity%2Fsmack.git Internal include file. --- diff --git a/src/smack_labels.c b/src/smack_labels.c index 31a2a19..0c6bfdc 100644 --- a/src/smack_labels.c +++ b/src/smack_labels.c @@ -4,8 +4,8 @@ #include #include #include "smack.h" +#include "smack_internal.h" -#define SMACK64_LEN 23 struct smack_label { char *long_name; char *short_name; diff --git a/src/smack_rules.c b/src/smack_rules.c index 7bbef86..b4df4c2 100644 --- a/src/smack_rules.c +++ b/src/smack_rules.c @@ -28,14 +28,7 @@ #include #include #include - -#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'; } diff --git a/src/smack_xattr.c b/src/smack_xattr.c index 9cf09d6..36e8f4f 100644 --- a/src/smack_xattr.c +++ b/src/smack_xattr.c @@ -21,17 +21,14 @@ * Jarkko Sakkinen */ -#include "smack.h" #include #include #include #include #include #include - -#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; }