PERFORCE change 152891 for review

Robert Watson rwatson at FreeBSD.org
Wed Nov 12 12:13:32 PST 2008


http://perforce.freebsd.org/chv.cgi?CH=152891

Change 152891 by rwatson at rwatson_cinnamon on 2008/11/12 20:13:30

	Go back on decision I made this morning (already): require use the
	BSM error space for the argument to au_to_return(),
	au_to_return32(), and au_to_return64(), and return BSM error space
	values from parsed records.  Otherwise, we lose information if the
	local OS doesn't support a particular error and we parse and then
	reassemble a record.
	
	Instead, teach print_retval() to convert to a local error when
	trying to print an error string.
	
	Update test token generation to convert to the BSM space when
	generating return tokens.

Affected files ...

.. //depot/projects/trustedbsd/openbsm/libbsm/bsm_errno.c#6 edit
.. //depot/projects/trustedbsd/openbsm/libbsm/bsm_io.c#57 edit
.. //depot/projects/trustedbsd/openbsm/libbsm/bsm_token.c#74 edit
.. //depot/projects/trustedbsd/openbsm/sys/bsm/audit_internal.h#4 edit
.. //depot/projects/trustedbsd/openbsm/test/bsm/generate.c#10 edit

Differences ...

==== //depot/projects/trustedbsd/openbsm/libbsm/bsm_errno.c#6 (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#5 $
+ * $P4: //depot/projects/trustedbsd/openbsm/libbsm/bsm_errno.c#6 $
  */
 
 #include <sys/types.h>
@@ -326,21 +326,24 @@
 };
 static const int bsm_errors_count = sizeof(bsm_errors) / sizeof(bsm_errors[0]);
 
+/*
+ * Converstion from a BSM error to a local error number may fail if either
+ * OpenBSM doesn't recognize the error on the wire, or because there is no
+ * appropriate local mapping.  However, we don't allow conversion to BSM to
+ * fail, we just convert to BSM_UKNOWNERR.
+ */
 int
-au_bsm_to_errno(u_char bsm_error)
+au_bsm_to_errno(u_char bsm_error, int *errorp)
 {
 	int i;
 
 	for (i = 0; i < bsm_errors_count; i++) {
-		if (bsm_errors[i].be_bsm_error == bsm_error)
-			return (bsm_errors[i].be_os_error);
+		if (bsm_errors[i].be_bsm_error == bsm_error) {
+			*errorp = bsm_errors[i].be_os_error;
+			return (0);
+		}
 	}
-
-	/*
-	 * If there is no local match, return EINVAL.  Perhaps there is
-	 * something better we could be doing here?
-	 */
-	return (EINVAL);
+	return (-1);
 }
 
 u_char
@@ -350,7 +353,17 @@
 
 	for (i = 0; i < bsm_errors_count; i++) {
 		if (bsm_errors[i].be_os_error == error)
-			return (htobe32(bsm_errors[i].be_bsm_error));
+			return (bsm_errors[i].be_bsm_error);
 	}
 	return (BSM_UNKNOWNERR);
 }
+
+char *
+au_strerror(u_char bsm_error)
+{
+
+	switch (bsm_error) {
+
+
+	}
+}

==== //depot/projects/trustedbsd/openbsm/libbsm/bsm_io.c#57 (text+ko) ====

@@ -32,7 +32,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_io.c#56 $
+ * $P4: //depot/projects/trustedbsd/openbsm/libbsm/bsm_io.c#57 $
  */
 
 #include <sys/types.h>
@@ -771,13 +771,24 @@
 static void
 print_retval(FILE *fp, u_char status, char raw)
 {
+	int error;
+
 	if (raw)
 		fprintf(fp, "%u", status);
 	else {
-		if (status == 0)
-			fprintf(fp, "success");
-		else
-			fprintf(fp, "failure : %s", strerror(status));
+		/*
+		 * Convert to a local error number and print the OS's version
+		 * of the error string if possible.  We may want to provide
+		 * an au_strerror(3) in the future so that we can print
+		 * strings for non-local errors.
+		 */
+		if (au_bsm_to_errno(status, &error) == 0) {
+			if (error == 0)
+				fprintf(fp, "success");
+			else
+				fprintf(fp, "failure : %s", strerror(error));
+		} else
+			fprintf(fp, "failure: Unknown error: %d", status);
 	}
 }
 
@@ -2946,7 +2957,6 @@
 	READ_TOKEN_U_CHAR(buf, len, tok->tt.ret32.status, tok->len, err);
 	if (err)
 		return (-1);
-	tok->tt.ret32.status = au_bsm_to_errno(tok->tt.ret32.status);
 
 	READ_TOKEN_U_INT32(buf, len, tok->tt.ret32.ret, tok->len, err);
 	if (err)
@@ -2985,7 +2995,6 @@
 	READ_TOKEN_U_CHAR(buf, len, tok->tt.ret64.err, tok->len, err);
 	if (err)
 		return (-1);
-	tok->tt.ret64.err = au_bsm_to_errno(tok->tt.ret64.err);
 
 	READ_TOKEN_U_INT64(buf, len, tok->tt.ret64.val, tok->len, err);
 	if (err)

==== //depot/projects/trustedbsd/openbsm/libbsm/bsm_token.c#74 (text+ko) ====

@@ -30,7 +30,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_token.c#73 $
+ * $P4: //depot/projects/trustedbsd/openbsm/libbsm/bsm_token.c#74 $
  */
 
 #include <sys/types.h>
@@ -846,7 +846,6 @@
 	if (t == NULL)
 		return (NULL);
 
-	status = au_errno_to_bsm(status);
 	ADD_U_CHAR(dptr, AUT_RETURN32);
 	ADD_U_CHAR(dptr, status);
 	ADD_U_INT32(dptr, ret);
@@ -864,7 +863,6 @@
 	if (t == NULL)
 		return (NULL);
 
-	status = au_errno_to_bsm(status);
 	ADD_U_CHAR(dptr, AUT_RETURN64);
 	ADD_U_CHAR(dptr, status);
 	ADD_U_INT64(dptr, ret);

==== //depot/projects/trustedbsd/openbsm/sys/bsm/audit_internal.h#4 (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#3 $
+ * $P4: //depot/projects/trustedbsd/openbsm/sys/bsm/audit_internal.h#4 $
  */
 
 #ifndef _AUDIT_INTERNAL_H
@@ -117,7 +117,7 @@
 /*
  * Map between BSM and local constants for error numbers.
  */
-int	au_bsm_to_errno(u_char bsm_error);
+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/test/bsm/generate.c#10 (text+ko) ====

@@ -23,7 +23,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $P4: //depot/projects/trustedbsd/openbsm/test/bsm/generate.c#9 $
+ * $P4: //depot/projects/trustedbsd/openbsm/test/bsm/generate.c#10 $
  */
 
 /*
@@ -553,7 +553,7 @@
 	free(buf);
 }
 
-static char		 return32_status = 0xd7;
+static char		 return32_status = EINVAL;
 static uint32_t		 return32_ret = 0x12345678;
 
 static void
@@ -561,7 +561,8 @@
 {
 	token_t *return32_token;
 
-	return32_token = au_to_return32(return32_status, return32_ret);
+	return32_token = au_to_return32(au_errno_to_bsm(return32_status),
+	    return32_ret);
 	if (return32_token == NULL)
 		err(EX_UNAVAILABLE, "au_to_return32");
 	write_token(directory, token_filename, return32_token);
@@ -572,7 +573,8 @@
 {
 	token_t *return32_token;
 
-	return32_token = au_to_return32(return32_status, return32_ret);
+	return32_token = au_to_return32(au_errno_to_bsm(return32_status),
+	    return32_ret);
 	if (return32_token == NULL)
 		err(EX_UNAVAILABLE, "au_to_return32");
 	write_record(directory, record_filename, return32_token, AUE_NULL);


More information about the p4-projects mailing list