summaryrefslogtreecommitdiffstats
path: root/lib/libc/posix1e/mac_text.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libc/posix1e/mac_text.c')
-rw-r--r--lib/libc/posix1e/mac_text.c194
1 files changed, 5 insertions, 189 deletions
diff --git a/lib/libc/posix1e/mac_text.c b/lib/libc/posix1e/mac_text.c
index c244fdc..9c72c14 100644
--- a/lib/libc/posix1e/mac_text.c
+++ b/lib/libc/posix1e/mac_text.c
@@ -41,204 +41,20 @@
#include <sys/mac.h>
#include <errno.h>
-#include <stdio.h>
-#include <string.h>
-
-#include "mac_internal.h"
-
-/*
- * POSIX.1e does not define a text format for MAC label string conversions.
- * We use the following format:
- *
- * label: policyname/policyvalue{,...}
- *
- * Each policy is responsible for parsing policyvalue on its own, although
- * policies must not use '/' or ',' in their text representation. Currently
- * supported policies are "biba, "mls", "te".
- */
-
-#define STRING_LISTSEP ","
-#define STRING_ELEMENTSEP "/"
-
-#define STRING_BIBA "biba"
-#define STRING_MLS "mls"
-#define STRING_TE "te"
+#include <stdlib.h>
char *
mac_to_text(struct mac *mac_p, size_t *len_p)
{
- char *biba = NULL, *mls = NULL, *string = NULL, *te = NULL;
- int len = -1, before;
-
- biba = mac_biba_string_from_label(mac_p);
- if (biba == NULL)
- goto out;
-
- mls = mac_mls_string_from_label(mac_p);
- if (mls == NULL)
- goto out;
-
- te = mac_te_string_from_label(mac_p);
- if (te == NULL)
- goto out;
-
- len = 0;
- if (strlen(biba) != 0)
- len += strlen(STRING_LISTSEP) + strlen(STRING_BIBA) +
- strlen(STRING_ELEMENTSEP) + strlen(biba);
- if (strlen(mls) != 0)
- len += strlen(STRING_LISTSEP) + strlen(STRING_MLS) +
- strlen(STRING_ELEMENTSEP) + strlen(mls);
- if (strlen(te) != 0)
- len += strlen(STRING_LISTSEP) + strlen(STRING_TE) +
- strlen(STRING_ELEMENTSEP) + strlen(te);
-
- if (len == 0) {
- string = strdup("");
- goto out;
- }
-
- string = (char *) malloc(len+1);
- if (string == NULL)
- return (NULL);
- len = 0;
- before = 0;
-
- if (strlen(biba) != 0) {
- if (before)
- len += sprintf(string + len, "%s", STRING_LISTSEP);
- len += sprintf(string + len, "%s%s%s", STRING_BIBA,
- STRING_ELEMENTSEP, biba);
- before = 1;
- }
- if (strlen(mls) != 0) {
- if (before)
- len += sprintf(string + len, "%s", STRING_LISTSEP);
- len += sprintf(string + len, "%s%s%s", STRING_MLS,
- STRING_ELEMENTSEP, mls);
- before = 1;
- }
- if (strlen(te) != 0) {
- if (before)
- len += sprintf(string + len, "%s", STRING_LISTSEP);
- len += sprintf(string + len, "%s%s%s", STRING_TE,
- STRING_ELEMENTSEP, te);
- before = 1;
- }
-
-out:
- if (biba != NULL)
- free(biba);
- if (mls != NULL)
- free(mls);
- if (te != NULL)
- free(te);
-
- if (len != -1 && len_p != NULL)
- *len_p = len;
-
- return (string);
+ errno = EINVAL;
+ return (NULL);
}
struct mac *
mac_from_text(const char *text_p)
{
- struct mac *label;
- char *local_string, *next_token, *token, *tmp;
- char *policy_name, *policy_value;
- int biba_seen = 0, mls_seen = 0, te_seen = 0;
- int error;
-
- /*
- * Parse into three assignments, determine which assignments
- * they are and recurse appropriately, and reject if there are
- * not the right assignments (or duplicates).
- */
-
- label = (struct mac *) malloc(sizeof(*label));
- if (label == NULL) {
- errno = ENOMEM;
- goto exit1;
- }
- label->m_macflags = 0;
- label->m_macflags |= MAC_FLAG_INITIALIZED;
-
- local_string = strdup(text_p);
- if (local_string == NULL) {
- errno = ENOMEM;
- goto exit2;
- }
-
- next_token = local_string;
- while ((token = strsep(&next_token, STRING_LISTSEP)) != NULL) {
-
- policy_value = token;
- policy_name = strsep(&policy_value, STRING_ELEMENTSEP);
-
- if (strcmp(policy_name, STRING_BIBA) == 0) {
- error = mac_biba_label_from_string(policy_value,
- label);
- if (error) {
- errno = error;
- goto exit2;
- }
- biba_seen++;
- } else if (strcmp(policy_name, STRING_MLS) == 0) {
- error = mac_mls_label_from_string(policy_value,
- label);
- if (error) {
- errno = error;
- goto exit2;
- }
- mls_seen++;
- } else if (strcmp(policy_name, STRING_TE) == 0) {
- error = mac_te_label_from_string(policy_value, label);
- if (error) {
- errno = error;
- goto exit2;
- }
- te_seen++;
- } else {
- errno = EINVAL;
- goto exit2;
- }
- }
-
- if (biba_seen == 0) {
- error = mac_biba_label_from_string("", label);
- if (error) {
- errno = error;
- goto exit2;
- }
- }
- if (mls_seen == 0) {
- error = mac_mls_label_from_string("", label);
- if (error) {
- errno = error;
- goto exit2;
- }
- }
- if (te_seen == 0) {
- error = mac_te_label_from_string("", label);
- if (error) {
- errno = error;
- goto exit2;
- }
- }
-
- if (biba_seen > 1 || mls_seen > 1 || te_seen > 1) {
- errno = EINVAL;
- goto exit2;
- }
-
- /* Success. */
- goto exit1;
-exit2:
- free(label);
- label = NULL;
-exit1:
- free(local_string);
- return (label);
+ errno = EINVAL;
+ return (NULL);
}
OpenPOWER on IntegriCloud