Date: Mon, 8 Dec 2008 12:20:25 GMT From: Robert Watson <rwatson@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 154332 for review Message-ID: <200812081220.mB8CKPrh035769@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
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 <sys/types.h> @@ -50,6 +50,7 @@ #include <bsm/audit_errno.h> #include <errno.h> +#include <string.h> /* * 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_ */
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200812081220.mB8CKPrh035769>