summaryrefslogtreecommitdiffstats
path: root/usr.bin
diff options
context:
space:
mode:
authoreivind <eivind@FreeBSD.org>1998-04-21 02:31:09 +0000
committereivind <eivind@FreeBSD.org>1998-04-21 02:31:09 +0000
commitc8cdab147c8afdf383b7b10aa16ece0c738e8fe0 (patch)
tree79ecbb6f4001059328b928288d9723b9d9b3bd08 /usr.bin
parent3f128f8b371395d5b326b70580b9356459266636 (diff)
downloadFreeBSD-src-c8cdab147c8afdf383b7b10aa16ece0c738e8fe0.zip
FreeBSD-src-c8cdab147c8afdf383b7b10aa16ece0c738e8fe0.tar.gz
Make brandelf test for known brands, and introduce a '-f' option to
bypass the testing. Partially submitted by: Brian Feldman <green@feldman.dyn.ml.org>
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/brandelf/brandelf.19
-rw-r--r--usr.bin/brandelf/brandelf.c39
2 files changed, 40 insertions, 8 deletions
diff --git a/usr.bin/brandelf/brandelf.1 b/usr.bin/brandelf/brandelf.1
index 3948e28..e51a446 100644
--- a/usr.bin/brandelf/brandelf.1
+++ b/usr.bin/brandelf/brandelf.1
@@ -34,6 +34,7 @@
.Nd mark an ELF binary for a specific ABI
.Sh SYNOPSIS
.Nm brandelf
+.Op Fl f
.Op Fl v
.Op Fl t Ar string
.Ar file ...
@@ -43,6 +44,9 @@ This command marks an ELF binary to be run under a certain ABI for
.Pp
The options are as follows:
.Bl -tag -width Fl
+.It Fl f
+forces branding even if the brand requested is unknown, and disables
+warnings for unknown brands.
.It Fl v
turns on verbose reporting
.It Fl t Ar string
@@ -72,7 +76,10 @@ command:
.Dl % brandelf -t Linux file
.Sh DIAGNOSTICS
Exit status is 0 on success, and 1 if the command
-fails if a file doesn't exist, is too short, or fails to brand properly.
+fails if a file doesn't exist, is too short, fails to brand properly,
+or the brand requested is not 'Linux' or 'FreeBSD' and the
+.Fl f
+option is not set.
.Sh HISTORY
The
.Nm
diff --git a/usr.bin/brandelf/brandelf.c b/usr.bin/brandelf/brandelf.c
index 79970e8..a212aa8 100644
--- a/usr.bin/brandelf/brandelf.c
+++ b/usr.bin/brandelf/brandelf.c
@@ -25,7 +25,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.
*
- * $Id: brandelf.c,v 1.7 1997/06/23 06:47:12 charnier Exp $
+ * $Id: brandelf.c,v 1.8 1997/08/23 15:51:14 joerg Exp $
*/
#include <elf.h>
@@ -36,6 +36,7 @@
#include <unistd.h>
#include <err.h>
+static int iselftype(const char *);
static void usage __P((void));
int
@@ -44,10 +45,13 @@ main(int argc, char **argv)
const char *type = "FreeBSD";
int retval = 0;
- int ch, change = 0, verbose = 0;
+ int ch, change = 0, verbose = 0, force = 0;
- while ((ch = getopt(argc, argv, "t:v")) != -1)
+ while ((ch = getopt(argc, argv, "ft:v")) != -1)
switch (ch) {
+ case 'f':
+ force = 1;
+ break;
case 'v':
verbose = 1;
break;
@@ -62,6 +66,10 @@ main(int argc, char **argv)
argv += optind;
if (!argc)
errx(1, "no file(s) specified");
+
+ if (!force && !iselftype(type))
+ errx(1, "invalid ELF type '%s'", type);
+
while (argc) {
int fd;
char buffer[EI_NIDENT];
@@ -71,7 +79,6 @@ main(int argc, char **argv)
warn("error opening file %s", argv[0]);
retval = 1;
goto fail;
-
}
if (read(fd, buffer, EI_NIDENT) < EI_NIDENT) {
warnx("file '%s' too short", argv[0]);
@@ -83,13 +90,17 @@ main(int argc, char **argv)
warnx("file '%s' is not ELF format", argv[0]);
retval = 1;
goto fail;
- }
+ }
if (!change) {
bzero(string, sizeof(string));
strncpy(string, &buffer[EI_BRAND], EI_NIDENT-EI_BRAND);
if (strlen(string)) {
- fprintf(stdout, "File '%s' is of brand '%s'.\n",
+ fprintf(stdout,
+ "File '%s' is of brand '%s'.\n",
argv[0], string);
+ if (!force && !iselftype(string))
+ warnx("Brand '%s' is unknown",
+ string);
}
else
fprintf(stdout, "File '%s' has no branding.\n",
@@ -115,6 +126,20 @@ fail:
static void
usage()
{
- fprintf(stderr, "usage: brandelf [-t string] file ...\n");
+ fprintf(stderr, "usage: brandelf [-f] [-v] [-t string] file ...\n");
exit(1);
}
+
+int
+iselftype(const char *elftype) {
+ /* XXX - any more types? */
+ const char *elftypes[] = { "FreeBSD", "Linux" };
+ int elfwalk;
+
+ for (elfwalk = 0;
+ elfwalk < sizeof(elftypes)/sizeof(elftypes[0]);
+ elfwalk++)
+ if (strcmp(elftype, elftypes[elfwalk]) == 0)
+ return 1;
+ return 0;
+}
OpenPOWER on IntegriCloud