From owner-p4-projects@FreeBSD.ORG Mon Dec 8 12:20:26 2008 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 420E61065673; Mon, 8 Dec 2008 12:20:26 +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 E25C81065670 for ; Mon, 8 Dec 2008 12:20:25 +0000 (UTC) (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id CF25D8FC1D for ; Mon, 8 Dec 2008 12:20:25 +0000 (UTC) (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id mB8CKPvY035771 for ; Mon, 8 Dec 2008 12:20:25 GMT (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id mB8CKPrh035769 for perforce@freebsd.org; Mon, 8 Dec 2008 12:20:25 GMT (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Date: Mon, 8 Dec 2008 12:20:25 GMT Message-Id: <200812081220.mB8CKPrh035769@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 154332 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, 08 Dec 2008 12:20:26 -0000 http://perforce.freebsd.org/chv.cgi?CH=154332 Change 154332 by rwatson@rwatson_cinnamon on 2008/12/08 12:19:28 Implement au_strerror() more fully. Move definitions of au_bsm_to_errno() and au_errno_to_bsm() so that they will be available in-kernel on FreeBSD and Mac OS X. Define au_strerror() such that it isn't available in-kernel. Affected files ... .. //depot/projects/trustedbsd/openbsm/bsm/libbsm.h#37 edit .. //depot/projects/trustedbsd/openbsm/libbsm/au_errno.3#2 edit .. //depot/projects/trustedbsd/openbsm/libbsm/bsm_errno.c#7 edit .. //depot/projects/trustedbsd/openbsm/sys/bsm/audit_internal.h#5 edit .. //depot/projects/trustedbsd/openbsm/sys/bsm/audit_record.h#7 edit Differences ... ==== //depot/projects/trustedbsd/openbsm/bsm/libbsm.h#37 (text+ko) ==== @@ -26,7 +26,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/bsm/libbsm.h#36 $ + * $P4: //depot/projects/trustedbsd/openbsm/bsm/libbsm.h#37 $ */ #ifndef _LIBBSM_H_ @@ -824,6 +824,11 @@ __END_DECLS /* + * Functions relating to BSM<->errno conversion. + */ +char *au_strerror(u_char bsm_error); + +/* * The remaining APIs are associated with Apple's BSM implementation, in * particular as relates to Mach IPC auditing and triggers passed via Mach * IPC. ==== //depot/projects/trustedbsd/openbsm/libbsm/au_errno.3#2 (text+ko) ==== @@ -26,14 +26,15 @@ .\" 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/au_errno.3#1 $ +.\" $P4: //depot/projects/trustedbsd/openbsm/libbsm/au_errno.3#2 $ .\" -.Dd November 12, 2008 +.Dd December 8, 2008 .Dt AU_BSM_TO_ERRNO 3 .Os .Sh NAME .Nm au_bsm_to_errno , -.Nm au_errno_to_bsm +.Nm au_errno_to_bsm , +.Nm au_strerror .Nd "convert between BSM and local error numbers" .Sh LIBRARY .Lb libbsm @@ -43,6 +44,8 @@ .Fn au_bsm_to_errno "u_char bsm_error" "int *errorp" .Ft u_char .Fn au_errno_to_bsm "int error" +.Ft char * +.Fn au_strerror "int bsm_error" .Sh DESCRIPTION These interfaces may be used to convert between the local ( .Xr errno 2 ) @@ -67,12 +70,24 @@ value, and returns the BSM error number for it. This call cannot fail, and instead returns a BSM error number indicating to a later decoder that the error could not be encoded. +.Pp +The +.Fn au_strerror +converts a BSM error value to a string, generally by converting first to a +local error number and using the local +.Xr strerror 3 +function, but will also work for errors that are not locally defined. .Sh RETURN VALULES On success, .Fn au_bsm_to_errno returns 0 and a converted error value; on failure, it returns -1 but does not set .Xr errno 2 . +.Pp +On success, +.Fn au_strerror +returns a pointer to an error string; on failure it will return +.Dv NULL . .Sh SEE ALSO .Xr au_to_return 3 , .Xr au_to_return32 3 , ==== //depot/projects/trustedbsd/openbsm/libbsm/bsm_errno.c#7 (text+ko) ==== @@ -26,7 +26,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_errno.c#6 $ + * $P4: //depot/projects/trustedbsd/openbsm/libbsm/bsm_errno.c#7 $ */ #include @@ -50,6 +50,7 @@ #include #include +#include /* * Different operating systems use different numeric constants for different @@ -358,12 +359,20 @@ return (BSM_UNKNOWNERR); } +#if !defined(KERNEL) && !defined(_KERNEL) char * au_strerror(u_char bsm_error) { + int error; - switch (bsm_error) { + if (au_bsm_to_errno(bsm_error, &error) == 0) + return (strerror(error)); - - } + /* + * We need a duplicate error->string mapping for all error numbers + * here to handle non-local ones. For now, simply generate a warning + * indicating it's non-local. + */ + return ("Foreign BSM error"); } +#endif ==== //depot/projects/trustedbsd/openbsm/sys/bsm/audit_internal.h#5 (text+ko) ==== @@ -30,7 +30,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $P4: //depot/projects/trustedbsd/openbsm/sys/bsm/audit_internal.h#4 $ + * $P4: //depot/projects/trustedbsd/openbsm/sys/bsm/audit_internal.h#5 $ */ #ifndef _AUDIT_INTERNAL_H @@ -114,10 +114,4 @@ #define ADD_STRING(loc, data, size) ADD_MEM(loc, data, size) -/* - * Map between BSM and local constants for error numbers. - */ -int au_bsm_to_errno(u_char bsm_error, int *errorp); -u_char au_errno_to_bsm(int error); - #endif /* !_AUDIT_INTERNAL_H_ */ ==== //depot/projects/trustedbsd/openbsm/sys/bsm/audit_record.h#7 (text+ko) ==== @@ -26,7 +26,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $P4: //depot/projects/trustedbsd/openbsm/sys/bsm/audit_record.h#6 $ + * $P4: //depot/projects/trustedbsd/openbsm/sys/bsm/audit_record.h#7 $ */ #ifndef _BSM_AUDIT_RECORD_H_ @@ -279,6 +279,12 @@ token_t *au_to_trailer(int rec_size); token_t *au_to_zonename(const char *zonename); +/* + * BSM library routines for manipulating errno values. + */ +int au_bsm_to_errno(u_char bsm_error, int *errorp); +u_char au_errno_to_bsm(int error); + __END_DECLS #endif /* ! _BSM_AUDIT_RECORD_H_ */