summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr/src/cmd/cdrw/bstream.c76
-rw-r--r--usr/src/cmd/cdrw/bstream.h18
-rw-r--r--usr/src/cmd/cdrw/write_image.c4
3 files changed, 91 insertions, 7 deletions
diff --git a/usr/src/cmd/cdrw/bstream.c b/usr/src/cmd/cdrw/bstream.c
index 9e1abf6401..77cc3db53c 100644
--- a/usr/src/cmd/cdrw/bstream.c
+++ b/usr/src/cmd/cdrw/bstream.c
@@ -19,7 +19,7 @@
* CDDL HEADER END
*/
/*
- * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -68,6 +68,10 @@ str_errno_to_string(int serrno)
return (gettext("Unsupported wav format"));
case STR_ERR_WAV_BAD_HEADER:
return (gettext("Bad wav header"));
+ case STR_ERR_ISO_READ_ERR:
+ return (gettext("Unable to read ISO header"));
+ case STR_ERR_ISO_BAD_HEADER:
+ return (gettext("Invalid ISO header or not an ISO"));
default:
return (gettext("unknown error"));
}
@@ -280,6 +284,76 @@ open_file_read_stream(char *file)
}
bstreamhandle
+open_iso_read_stream(char *fname)
+{
+ bstreamhandle h;
+ off_t iso_size = 0;
+ char iso_desc[ISO9660_PRIMARY_DESC_SIZE];
+
+ h = open_file_read_stream(fname);
+
+ /* If we don't have a valid handle immediately return NULL */
+ if (h == NULL)
+ return (NULL);
+
+ if (debug)
+ (void) printf("Checking the ISO 9660 file header\n");
+
+ /* Check to see if we have a valid sized ISO image */
+ h->bstr_size(h, &iso_size);
+ if (iso_size < ISO9660_HEADER_SIZE) {
+ if (debug)
+ (void) printf("ISO 9660 header size not sane.\n");
+ h->bstr_close(h);
+ str_errno = STR_ERR_ISO_BAD_HEADER;
+ return (NULL);
+ }
+
+ if (debug)
+ (void) printf("ISO 9660 header size is sane.\n");
+
+ /* Skip over the boot block sector of the ISO. */
+ (void) lseek(h->bstr_fd, ISO9660_BOOT_BLOCK_SIZE, SEEK_SET);
+
+ /*
+ * Try to read in the ISO Descriptor and validate this
+ * is in fact an ISO 9660 image.
+ */
+ if (read(h->bstr_fd, iso_desc, ISO9660_PRIMARY_DESC_SIZE) ==
+ ISO9660_PRIMARY_DESC_SIZE) {
+ /*
+ * Bytes one through five of a valid ISO 9660 cd image
+ * should contain the string CD001. High Sierra format,
+ * the ISO 9660 predecessor, fills this field with the
+ * string CDROM. If neither is the case then we should
+ * close the stream, set str_errno, and return NULL.
+ */
+ if (strncmp(iso_desc + ISO9660_STD_IDENT_OFFSET, "CD001",
+ 5) != 0 && strncmp(iso_desc + ISO9660_STD_IDENT_OFFSET,
+ "CDROM", 5) != 0) {
+ if (debug)
+ (void) printf("Invalid ISO 9660 identifier.\n");
+ h->bstr_close(h);
+ str_errno = STR_ERR_ISO_BAD_HEADER;
+ return (NULL);
+ }
+ } else {
+ h->bstr_close(h);
+ str_errno = STR_ERR_ISO_READ_ERR;
+ return (NULL);
+ }
+
+ /*
+ * Our ISO image is valid rewind the stream
+ * and return the handle.
+ */
+ if (debug)
+ (void) printf("ISO 9660 header is sane.\n");
+ h->bstr_rewind(h);
+ return (h);
+}
+
+bstreamhandle
open_stdin_read_stream(void)
{
bstreamhandle h;
diff --git a/usr/src/cmd/cdrw/bstream.h b/usr/src/cmd/cdrw/bstream.h
index 734ea069a6..4ef2f1428e 100644
--- a/usr/src/cmd/cdrw/bstream.h
+++ b/usr/src/cmd/cdrw/bstream.h
@@ -2,9 +2,8 @@
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
@@ -20,7 +19,7 @@
* CDDL HEADER END
*/
/*
- * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -59,9 +58,20 @@ extern int str_errno;
#define STR_ERR_WAV_READ_ERR 6
#define STR_ERR_WAV_UNSUPPORTED_FORMAT 7
#define STR_ERR_WAV_BAD_HEADER 8
+#define STR_ERR_ISO_BAD_HEADER 9
+#define STR_ERR_ISO_READ_ERR 10
+
+/*
+ * Constants for the ISO 9660 standard
+ */
+#define ISO9660_HEADER_SIZE 34816
+#define ISO9660_BOOT_BLOCK_SIZE 32768
+#define ISO9660_PRIMARY_DESC_SIZE 2048
+#define ISO9660_STD_IDENT_OFFSET 1
bstreamhandle open_stdin_read_stream();
bstreamhandle open_file_read_stream(char *file);
+bstreamhandle open_iso_read_stream(char *fname);
bstreamhandle open_au_read_stream(char *fname);
bstreamhandle open_wav_read_stream(char *fname);
bstreamhandle open_aur_read_stream(char *fname);
diff --git a/usr/src/cmd/cdrw/write_image.c b/usr/src/cmd/cdrw/write_image.c
index a6ba50a533..cc001d2a63 100644
--- a/usr/src/cmd/cdrw/write_image.c
+++ b/usr/src/cmd/cdrw/write_image.c
@@ -19,7 +19,7 @@
* CDDL HEADER END
*/
/*
- * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -74,7 +74,7 @@ write_image(void)
write_init(TRACK_MODE_DATA);
if (image_file) {
- h = open_file_read_stream(image_file);
+ h = open_iso_read_stream(image_file);
} else {
h = open_stdin_read_stream();
}