From owner-p4-projects@FreeBSD.ORG Mon Jul 4 12:34:35 2005 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 36C5816A420; Mon, 4 Jul 2005 12:34:35 +0000 (GMT) X-Original-To: perforce@freebsd.org 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 0FC7416A41C for ; Mon, 4 Jul 2005 12:34:35 +0000 (GMT) (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id E597F43D55 for ; Mon, 4 Jul 2005 12:34:34 +0000 (GMT) (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.1/8.13.1) with ESMTP id j64CYYAM062037 for ; Mon, 4 Jul 2005 12:34:34 GMT (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.1/8.13.1/Submit) id j64CYY4O062034 for perforce@freebsd.org; Mon, 4 Jul 2005 12:34:34 GMT (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Date: Mon, 4 Jul 2005 12:34:34 GMT Message-Id: <200507041234.j64CYY4O062034@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to bb+lists.freebsd.perforce@cyrus.watson.org using -f From: Robert Watson To: Perforce Change Reviews Cc: Subject: PERFORCE change 79543 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: Mon, 04 Jul 2005 12:34:36 -0000 http://perforce.freebsd.org/chv.cgi?CH=79543 Change 79543 by rwatson@rwatson_zoo on 2005/07/04 12:34:18 Further integrate trustedbsd_sebsd to pick up changes in the MAC branch. Affected files ... .. //depot/projects/trustedbsd/sebsd/sys/security/mac_portacl/mac_portacl.c#7 integrate .. //depot/projects/trustedbsd/sebsd/usr.sbin/getfhash/setfhash.8#2 integrate Differences ... ==== //depot/projects/trustedbsd/sebsd/sys/security/mac_portacl/mac_portacl.c#7 (text+ko) ==== @@ -48,7 +48,7 @@ * you will probably want to twiddle the net.inet sysctl listed above. * Then use sysctl(8) to modify the rules string: * - * # sysctl security.mac.portacl.rules="uid:425:tcp:80,uid:425:tcp:79" + * # sysctl security.mac.portacl.rules="all:uid:425:tcp:80,uid:425:tcp:79" * * This ruleset, for example, permits uid 425 to bind TCP ports 80 (http) * and 79 (finger). User names and group names can't be used directly @@ -76,6 +76,7 @@ #include #include #include +#include #include #include @@ -117,11 +118,14 @@ #define MAC_RULE_STRING_LEN 1024 +#define RULE_IGNORE 0 +#define RULE_SYSTEM -1 #define RULE_GID 1 #define RULE_UID 2 #define RULE_PROTO_TCP 1 #define RULE_PROTO_UDP 2 struct rule { + int r_pr_id; id_t r_id; int r_idtype; u_int16_t r_port; @@ -130,6 +134,8 @@ TAILQ_ENTRY(rule) r_entries; }; +#define SYSTEM_STRING "none" +#define IGNORE_STRING "all" #define GID_STRING "gid" #define TCP_STRING "tcp" #define UID_STRING "uid" @@ -138,7 +144,7 @@ /* * Text format for the rule string is that a rule consists of a * comma-seperated list of elements. Each element is in the form - * idtype:id:protocol:portnumber, and constitutes granting of permission + * prison:idtype:id:protocol:portnumber, and constitutes granting of permission * for the specified binding. */ @@ -183,18 +189,46 @@ static int parse_rule_element(char *element, struct rule **rule) { - char *idtype, *id, *protocol, *portnumber, *p; + char *idtype, *id, *rtype, *portnumber, *prison, *p; struct rule *new; int error; error = 0; new = malloc(sizeof(*new), M_PORTACL, M_ZERO | M_WAITOK); - idtype = strsep(&element, ":"); - if (idtype == NULL) { + idtype = NULL; + + prison = strsep(&element, ":"); + if (prison == NULL) { error = EINVAL; goto out; } + + if (strcmp(prison, IGNORE_STRING) == 0) + new->r_pr_id = RULE_IGNORE; + else if (strcmp(prison, SYSTEM_STRING) == 0) + new->r_pr_id = RULE_SYSTEM; + else if (strcmp(prison, UID_STRING) && + strcmp(prison, GID_STRING)) { + new->r_pr_id = strtol(prison, &p, 10); + if (*p != '\0' || new->r_pr_id < 0) { + error = EINVAL; + goto out; + } + } else { + new->r_pr_id = RULE_IGNORE; + idtype = prison; + } + + if (idtype == NULL) { + idtype = strsep(&element, ":"); + + if (idtype == NULL) { + error = EINVAL; + goto out; + } + } + id = strsep(&element, ":"); if (id == NULL) { error = EINVAL; @@ -213,12 +247,15 @@ error = EINVAL; goto out; } + protocol = strsep(&element, ":"); if (protocol == NULL) { error = EINVAL; goto out; } - if (strcmp(protocol, TCP_STRING) == 0) + if (strcmp(protocol, IGNORE_STRING) == 0) + new->r_protocol = RULE_IGNORE; + else if (strcmp(protocol, TCP_STRING) == 0) new->r_protocol = RULE_PROTO_TCP; else if (strcmp(protocol, UDP_STRING) == 0) new->r_protocol = RULE_PROTO_UDP; @@ -292,6 +329,9 @@ } switch (rule->r_protocol) { + case RULE_IGNORE: + protocol = IGNORE_STRING; + break; case RULE_PROTO_TCP: protocol = TCP_STRING; break; @@ -302,8 +342,9 @@ panic("rule_printf: unknown protocol (%d)\n", rule->r_protocol); } - sbuf_printf(sb, "%s:%jd:%s:%d", idtype, (intmax_t)rule->r_id, - protocol, rule->r_port); + + sbuf_printf(sb, "%d:%s:%jd:%s:%d", rule->r_pr_id, idtype, + (intmax_t)rule->r_id, protocol, rule->r_port); } static char * @@ -401,12 +442,24 @@ for (rule = TAILQ_FIRST(&rule_head); rule != NULL; rule = TAILQ_NEXT(rule, r_entries)) { - if (type == SOCK_DGRAM && rule->r_protocol != RULE_PROTO_UDP) + if (rule->r_protocol != RULE_IGNORE) { + if (type == SOCK_DGRAM && rule->r_protocol != RULE_PROTO_UDP) + continue; + if (type == SOCK_STREAM && rule->r_protocol != RULE_PROTO_TCP) + continue; + } + + if (port != rule->r_port) continue; - if (type == SOCK_STREAM && rule->r_protocol != RULE_PROTO_TCP) + + if ((rule->r_pr_id == RULE_SYSTEM) && cred->cr_prison) continue; - if (port != rule->r_port) - continue; + else if (rule->r_pr_id != RULE_IGNORE) { + if (!cred->cr_prison || + (cred->cr_prison->pr_id != rule->r_pr_id)) + continue; + } + if (rule->r_idtype == RULE_UID) { if (cred->cr_uid == rule->r_id) { error = 0; ==== //depot/projects/trustedbsd/sebsd/usr.sbin/getfhash/setfhash.8#2 (text+ko) ==== @@ -54,7 +54,8 @@ When setting dependencies, they must be listed previous to the system object which requires them. Multiple dependencies may exist and must be separated by a -colon when entered. +colon when entered. It should be noted that dependency pathnames +will be looked up relative to the calling process's root. .El .Sh EXAMPLES To set the hash on