From owner-p4-projects@FreeBSD.ORG Wed Jan 14 05:31:52 2009 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id AEC6B1065673; Wed, 14 Jan 2009 05:31:52 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 6C00C106566B for ; Wed, 14 Jan 2009 05:31:52 +0000 (UTC) (envelope-from sson@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 5B3778FC0A for ; Wed, 14 Jan 2009 05:31:52 +0000 (UTC) (envelope-from sson@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id n0E5Vq3p084827 for ; Wed, 14 Jan 2009 05:31:52 GMT (envelope-from sson@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id n0E5VqUA084825 for perforce@freebsd.org; Wed, 14 Jan 2009 05:31:52 GMT (envelope-from sson@FreeBSD.org) Date: Wed, 14 Jan 2009 05:31:52 GMT Message-Id: <200901140531.n0E5VqUA084825@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to sson@FreeBSD.org using -f From: Stacey Son To: Perforce Change Reviews Cc: Subject: PERFORCE change 156137 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 14 Jan 2009 05:31:53 -0000 http://perforce.freebsd.org/chv.cgi?CH=156137 Change 156137 by sson@sson_amd64 on 2009/01/14 05:31:06 Change au_poltosr() and au_strtopol() to use a table for parsing and building policy strings. Submitted by: mm w (openspecies at gmail com) Affected files ... .. //depot/projects/trustedbsd/openbsm/libbsm/bsm_control.c#26 edit Differences ... ==== //depot/projects/trustedbsd/openbsm/libbsm/bsm_control.c#26 (text+ko) ==== @@ -27,7 +27,7 @@ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - * $P4: //depot/projects/trustedbsd/openbsm/libbsm/bsm_control.c#25 $ + * $P4: //depot/projects/trustedbsd/openbsm/libbsm/bsm_control.c#26 $ */ #include @@ -65,6 +65,32 @@ #endif /* + * Audit policy string token table for au_poltostr() and au_strtopol(). + */ +struct audit_polstr { + long ap_policy; + const char *ap_str; +}; + +static struct audit_polstr au_polstr[] = { + { AUDIT_CNT, "cnt" }, + { AUDIT_AHLT, "ahlt" }, + { AUDIT_ARGV, "argv" }, + { AUDIT_ARGE, "arge" }, + { AUDIT_SEQ, "seq" }, + { AUDIT_WINDATA, "windata" }, + { AUDIT_USER, "user" }, + { AUDIT_GROUP, "group" }, + { AUDIT_TRAIL, "trail" }, + { AUDIT_PATH, "path" }, + { AUDIT_SCNT, "scnt" }, + { AUDIT_PUBLIC, "public" }, + { AUDIT_ZONENAME, "zonename" }, + { AUDIT_PERZONE, "perzone" }, + { -1, NULL } +}; + +/* * Returns the string value corresponding to the given label from the * configuration file. * @@ -119,135 +145,24 @@ ssize_t au_poltostr(long policy, size_t maxsize, char *buf) { - int first; + int first = 1; + int i = 0; if (maxsize < 1) return (-1); - first = 1; buf[0] = '\0'; - if (policy & AUDIT_CNT) { - if (strlcat(buf, "cnt", maxsize) >= maxsize) - return (-1); - first = 0; - } - if (policy & AUDIT_AHLT) { - if (!first) { - if (strlcat(buf, ",", maxsize) >= maxsize) + do { + if (policy & au_polstr[i].ap_policy) { + if (!first && strlcat(buf, ",", maxsize) >= maxsize) return (-1); - } - if (strlcat(buf, "ahlt", maxsize) >= maxsize) - return (-1); - first = 0; - } - if (policy & AUDIT_ARGV) { - if (!first) { - if (strlcat(buf, ",", maxsize) >= maxsize) + if (strlcat(buf, au_polstr[i].ap_str, maxsize) >= + maxsize) return (-1); + first = 0; } - if (strlcat(buf, "argv", maxsize) >= maxsize) - return (-1); - first = 0; - } - if (policy & AUDIT_ARGE) { - if (!first) { - if (strlcat(buf, ",", maxsize) >= maxsize) - return (-1); - } - if (strlcat(buf, "arge", maxsize) >= maxsize) - return (-1); - first = 0; - } - if (policy & AUDIT_SEQ) { - if (!first) { - if (strlcat(buf, ",", maxsize) >= maxsize) - return (-1); - } - if (strlcat(buf, "seq", maxsize) >= maxsize) - return (-1); - first = 0; - } - if (policy & AUDIT_WINDATA) { - if (!first) { - if (strlcat(buf, ",", maxsize) >= maxsize) - return (-1); - } - if (strlcat(buf, "windata", maxsize) >= maxsize) - return (-1); - first = 0; - } - if (policy & AUDIT_USER) { - if (!first) { - if (strlcat(buf, ",", maxsize) >= maxsize) - return (-1); - } - if (strlcat(buf, "user", maxsize) >= maxsize) - return (-1); - first = 0; - } - if (policy & AUDIT_GROUP) { - if (!first) { - if (strlcat(buf, ",", maxsize) >= maxsize) - return (-1); - } - if (strlcat(buf, "group", maxsize) >= maxsize) - return (-1); - first = 0; - } - if (policy & AUDIT_TRAIL) { - if (!first) { - if (strlcat(buf, ",", maxsize) >= maxsize) - return (-1); - } - if (strlcat(buf, "trail", maxsize) >= maxsize) - return (-1); - first = 0; - } - if (policy & AUDIT_PATH) { - if (!first) { - if (strlcat(buf, ",", maxsize) >= maxsize) - return (-1); - } - if (strlcat(buf, "path", maxsize) >= maxsize) - return (-1); - first = 0; - } - if (policy & AUDIT_SCNT) { - if (!first) { - if (strlcat(buf, ",", maxsize) >= maxsize) - return (-1); - } - if (strlcat(buf, "scnt", maxsize) >= maxsize) - return (-1); - first = 0; - } - if (policy & AUDIT_PUBLIC) { - if (!first) { - if (strlcat(buf, ",", maxsize) >= maxsize) - return (-1); - } - if (strlcat(buf, "public", maxsize) >= maxsize) - return (-1); - first = 0; - } - if (policy & AUDIT_ZONENAME) { - if (!first) { - if (strlcat(buf, ",", maxsize) >= maxsize) - return (-1); - } - if (strlcat(buf, "zonename", maxsize) >= maxsize) - return (-1); - first = 0; - } - if (policy & AUDIT_PERZONE) { - if (!first) { - if (strlcat(buf, ",", maxsize) >= maxsize) - return (-1); - } - if (strlcat(buf, "perzone", maxsize) >= maxsize) - return (-1); - first = 0; - } + } while (NULL != au_polstr[++i].ap_str); + return (strlen(buf)); } @@ -260,6 +175,7 @@ { char *bufp, *string; char *buffer; + int i, matched; *policy = 0; buffer = strdup(polstr); @@ -268,35 +184,17 @@ bufp = buffer; while ((string = strsep(&bufp, ",")) != NULL) { - if (strcmp(string, "cnt") == 0) - *policy |= AUDIT_CNT; - else if (strcmp(string, "ahlt") == 0) - *policy |= AUDIT_AHLT; - else if (strcmp(string, "argv") == 0) - *policy |= AUDIT_ARGV; - else if (strcmp(string, "arge") == 0) - *policy |= AUDIT_ARGE; - else if (strcmp(string, "seq") == 0) - *policy |= AUDIT_SEQ; - else if (strcmp(string, "winau_fstat") == 0) - *policy |= AUDIT_WINDATA; - else if (strcmp(string, "user") == 0) - *policy |= AUDIT_USER; - else if (strcmp(string, "group") == 0) - *policy |= AUDIT_GROUP; - else if (strcmp(string, "trail") == 0) - *policy |= AUDIT_TRAIL; - else if (strcmp(string, "path") == 0) - *policy |= AUDIT_PATH; - else if (strcmp(string, "scnt") == 0) - *policy |= AUDIT_SCNT; - else if (strcmp(string, "public") == 0) - *policy |= AUDIT_PUBLIC; - else if (strcmp(string, "zonename") == 0) - *policy |= AUDIT_ZONENAME; - else if (strcmp(string, "perzone") == 0) - *policy |= AUDIT_PERZONE; - else { + matched = i = 0; + + do { + if (strcmp(string, au_polstr[i].ap_str) == 0) { + *policy |= au_polstr[i].ap_policy; + matched = 1; + break; + } + } while (NULL != au_polstr[++i].ap_str); + + if (!matched) { free(buffer); errno = EINVAL; return (-1);