From owner-p4-projects Sat Aug 3 7:51:51 2002 Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id B1E4837B401; Sat, 3 Aug 2002 07:51:40 -0700 (PDT) Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 28AC537B400 for ; Sat, 3 Aug 2002 07:51:40 -0700 (PDT) Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id BA19743E42 for ; Sat, 3 Aug 2002 07:51:39 -0700 (PDT) (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: from freefall.freebsd.org (perforce@localhost [127.0.0.1]) by freefall.freebsd.org (8.12.4/8.12.4) with ESMTP id g73EpdJU091577 for ; Sat, 3 Aug 2002 07:51:39 -0700 (PDT) (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: (from perforce@localhost) by freefall.freebsd.org (8.12.4/8.12.4/Submit) id g73Epd98091566 for perforce@freebsd.org; Sat, 3 Aug 2002 07:51:39 -0700 (PDT) Date: Sat, 3 Aug 2002 07:51:39 -0700 (PDT) Message-Id: <200208031451.g73Epd98091566@freefall.freebsd.org> X-Authentication-Warning: freefall.freebsd.org: perforce set sender to bb+lists.freebsd.perforce@cyrus.watson.org using -f From: Robert Watson Subject: PERFORCE change 15484 for review To: Perforce Change Reviews Sender: owner-p4-projects@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG http://people.freebsd.org/~peter/p4db/chv.cgi?CH=15484 Change 15484 by rwatson@rwatson_curry on 2002/08/03 07:51:32 Prod a bit at the userland MAC library to accept partial MAC labels in which not all policies are present, and to print partial labels without policies with null labels. Affected files ... .. //depot/projects/trustedbsd/mac/lib/libc/posix1e/mac_te.c#5 edit .. //depot/projects/trustedbsd/mac/lib/libc/posix1e/mac_text.c#22 edit Differences ... ==== //depot/projects/trustedbsd/mac/lib/libc/posix1e/mac_te.c#5 (text+ko) ==== @@ -54,8 +54,6 @@ { bzero(&label->m_te, sizeof(label->m_te)); - if (strlen(string) == 0) - return (EINVAL); if (strlcpy(label->m_te.mt_type, string, sizeof(label->m_te.mt_type)) >= sizeof(label->m_te.mt_type)) return (EINVAL); ==== //depot/projects/trustedbsd/mac/lib/libc/posix1e/mac_text.c#22 (text+ko) ==== @@ -68,7 +68,7 @@ mac_to_text(struct mac *mac_p, size_t *len_p) { char *biba = NULL, *mls = NULL, *string = NULL, *te = NULL; - int len = -1; + int len = -1, before; biba = mac_biba_string_from_label(mac_p); if (biba == NULL) @@ -82,10 +82,49 @@ if (te == NULL) goto out; - len = asprintf(&string, "%s%s%s%s%s%s%s%s%s%s%s", - STRING_BIBA, STRING_ELEMENTSEP, biba, STRING_LISTSEP, - STRING_MLS, STRING_ELEMENTSEP, mls, STRING_LISTSEP, - STRING_TE, STRING_ELEMENTSEP, te); + 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(STIRNG_ELEMENTSEP) + strlen(te); + + if (len == 0) { + string = strdup(""); + goto out; + } + + string = (char *) malloc(len+1); + if (string == NULL) + return (NULL); + + len = 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) @@ -165,7 +204,29 @@ } } - if (biba_seen != 1 || mls_seen != 1 || te_seen != 1) { + 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; } To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe p4-projects" in the body of the message