From owner-p4-projects@FreeBSD.ORG Sun Aug 8 12:50:54 2010 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 99CB21065678; Sun, 8 Aug 2010 12:50:54 +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 5E93B1065676 for ; Sun, 8 Aug 2010 12:50:54 +0000 (UTC) (envelope-from trasz@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 3180B8FC18 for ; Sun, 8 Aug 2010 12:50:54 +0000 (UTC) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.4/8.14.4) with ESMTP id o78Cos8r002533 for ; Sun, 8 Aug 2010 12:50:54 GMT (envelope-from trasz@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.4/8.14.4/Submit) id o78CosSk002531 for perforce@freebsd.org; Sun, 8 Aug 2010 12:50:54 GMT (envelope-from trasz@freebsd.org) Date: Sun, 8 Aug 2010 12:50:54 GMT Message-Id: <201008081250.o78CosSk002531@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to trasz@freebsd.org using -f From: Edward Tomasz Napierala To: Perforce Change Reviews Precedence: bulk Cc: Subject: PERFORCE change 182076 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 08 Aug 2010 12:50:54 -0000 http://p4web.freebsd.org/@@182076?ac=10 Change 182076 by trasz@trasz_victim on 2010/08/08 12:50:33 Use expand_number(3) in hrl(8). Affected files ... .. //depot/projects/soc2009/trasz_limits/TODO#26 edit .. //depot/projects/soc2009/trasz_limits/usr.sbin/hrl/Makefile#6 edit .. //depot/projects/soc2009/trasz_limits/usr.sbin/hrl/hrl.c#25 edit Differences ... ==== //depot/projects/soc2009/trasz_limits/TODO#26 (text+ko) ==== @@ -82,5 +82,3 @@ - Should priv(9) checking be done by HRL, or by the callers? - - Use expand_number(3) in hrl(8). - ==== //depot/projects/soc2009/trasz_limits/usr.sbin/hrl/Makefile#6 (text+ko) ==== @@ -3,6 +3,9 @@ PROG= hrl MAN= hrl.8 +DPADD= ${LIBUTIL} +LDADD= -lutil + WARNS?= 6 .include ==== //depot/projects/soc2009/trasz_limits/usr.sbin/hrl/hrl.c#25 (text+ko) ==== @@ -29,11 +29,13 @@ #include #include +#include #include #include #include #include #include +#include #include #include #include @@ -129,6 +131,48 @@ } /* + * This routine replaces "human-readable" number with its expanded form. + */ +static char * +expand_amount(char *rule) +{ + int64_t num; + const char *subject, *subject_id, *resource, *action, *amount, *per; + char *copy, *expanded; + + copy = strdup(rule); + if (copy == NULL) + err(1, "strdup"); + + subject = strsep(©, ":"); + subject_id = strsep(©, ":"); + resource = strsep(©, ":"); + action = strsep(©, "=/"); + amount = strsep(©, "/"); + per = copy; + + if (amount == NULL || strlen(amount) == 0) { + free(copy); + return (rule); + } + + assert(subject != NULL); + assert(subject_id != NULL); + assert(resource != NULL); + assert(action != NULL); + + if (expand_number(amount, &num)) + err(1, "expand_number"); + + if (per == NULL) + asprintf(&expanded, "%s:%s:%s:%s=%ld", subject, subject_id, resource, action, num); + else + asprintf(&expanded, "%s:%s:%s:%s=%ld/%s", subject, subject_id, resource, action, num, per); + + return (expanded); +} + +/* * Print rules, one per line, */ static void print_rules(char *rules) @@ -330,6 +374,7 @@ "at the same time"); rule = resolve_ids(rule); + rule = expand_amount(rule); if (aflag) { add_rule(rule);