diff options
author | Ray Lai <ray@cvs.openbsd.org> | 2009-06-06 04:46:27 +0000 |
---|---|---|
committer | Ray Lai <ray@cvs.openbsd.org> | 2009-06-06 04:46:27 +0000 |
commit | 3d437de8acae6df1eb23d33f24523bcbfc5e4e5e (patch) | |
tree | b2587029e4566d644b4ca7583115c192e9edb3a1 /usr.bin/sendbug | |
parent | 580e5001e3400f2df0f750c306d739aaf1cb6929 (diff) |
Include pcidump and acpidump output when sendbug is run as root,
to aid ACPI development. Output files are base64 encoded in the
report.
Add a -E flag to decode files from a report to the current directory.
Requested by deraadt, "Sweet!" marco, "Looks good to me." pirofti
Diffstat (limited to 'usr.bin/sendbug')
-rw-r--r-- | usr.bin/sendbug/sendbug.1 | 48 | ||||
-rw-r--r-- | usr.bin/sendbug/sendbug.c | 99 |
2 files changed, 123 insertions, 24 deletions
diff --git a/usr.bin/sendbug/sendbug.1 b/usr.bin/sendbug/sendbug.1 index 7045b69b903..a0749b88850 100644 --- a/usr.bin/sendbug/sendbug.1 +++ b/usr.bin/sendbug/sendbug.1 @@ -1,9 +1,9 @@ -.\" $OpenBSD: sendbug.1,v 1.17 2008/12/14 07:46:24 ray Exp $ +.\" $OpenBSD: sendbug.1,v 1.18 2009/06/06 04:46:26 ray Exp $ .\" .\" Written by Raymond Lai <ray@cyth.net>. .\" Public domain. .\" -.Dd $Mdocdate: December 14 2008 $ +.Dd $Mdocdate: June 6 2009 $ .Dt SENDBUG 1 .Os .Sh NAME @@ -12,23 +12,30 @@ .Ox .Sh SYNOPSIS .Nm -.Op Fl DPV +.Op Fl DEPV .Sh DESCRIPTION .Nm is used to submit problem reports (PRs) to the .Ox bugs database. A template PR is opened in a text editor -with some system information, +with some system information already filled in, such as machine architecture, -already filled in, -and a -.Xr dmesg 8 -attached. +.Xr dmesg 8 , +.Xr pcidump 8 , +and +.Xr acpidump 8 . +The +.Xr pcidump 8 +and +.Xr acpidump 8 +output are important for ACPI development and can only be included if +.Nm +is run as root. +.Pp Fields enclosed in .Sq \*(Lt\*(Gt should be completed by the user. -.Pp Once the PR is filled out, the user exits the editor and is presented with a choice: a)bort, e)dit, or s)end. @@ -54,14 +61,23 @@ or content. The options are as follows: .Bl -tag -width Ds .It Fl D -Do not attach a -.Xr dmesg 8 +Do not attach +.Xr dmesg 8 , +.Xr pcidump 8 , +and +.Xr acpidump 8 to report. -The -.Xr dmesg 8 -output is very helpful in reports, +This information is very helpful in reports, but may contain sensitive information about the sender. This flag helps protect users' privacy in those cases. +.It Fl E +The +.Xr acpidump 8 +output includes base64 encoded files. +This flag causes +.Nm +to read a PR from the standard input, decode the files, +and write them into the current directory. .It Fl P Generate and print the template with system information filled out. .It Fl V @@ -100,8 +116,10 @@ The default is temporary PR report .El .Sh SEE ALSO +.Xr acpidump 8 , .Xr crash 8 , -.Xr dmesg 8 +.Xr dmesg 8 , +.Xr pcidump 8 .Sh AUTHORS .Nm was written from scratch for the public domain by diff --git a/usr.bin/sendbug/sendbug.c b/usr.bin/sendbug/sendbug.c index 804e1a64020..dce62695d9d 100644 --- a/usr.bin/sendbug/sendbug.c +++ b/usr.bin/sendbug/sendbug.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sendbug.c,v 1.60 2009/01/28 20:43:24 ray Exp $ */ +/* $OpenBSD: sendbug.c,v 1.61 2009/06/06 04:46:26 ray Exp $ */ /* * Written by Ray Lai <ray@cyth.net>. @@ -28,10 +28,14 @@ #define _PATH_DMESG "/var/run/dmesg.boot" #define DMESG_START "OpenBSD " +#define BEGIN64 "begin-base64 " +#define END64 "====" int checkfile(const char *); +void debase(void); void dmesg(FILE *); int editit(const char *); +void hwdump(FILE *); void init(void); int matchline(const char *, const char *, size_t); int prompt(void); @@ -52,6 +56,7 @@ const char *comment[] = { struct passwd *pw; char os[BUFSIZ], rel[BUFSIZ], mach[BUFSIZ], details[BUFSIZ]; +const char *tmpdir; char *fullname, *tmppath; int Dflag, Pflag, wantcleanup; @@ -60,7 +65,7 @@ usage(void) { extern char *__progname; - fprintf(stderr, "usage: %s [-DPV]\n", __progname); + fprintf(stderr, "usage: %s [-DEPV]\n", __progname); exit(1); } @@ -76,17 +81,19 @@ int main(int argc, char *argv[]) { int ch, c, fd, ret = 1; - const char *tmpdir; struct stat sb; char *pr_form; time_t mtime; FILE *fp; - while ((ch = getopt(argc, argv, "DPV")) != -1) + while ((ch = getopt(argc, argv, "DEPV")) != -1) switch (ch) { case 'D': Dflag = 1; break; + case 'E': + debase(); + exit(0); case 'P': Pflag = 1; break; @@ -196,10 +203,6 @@ dmesg(FILE *fp) return; } - fputs("\n" - "SENDBUG: dmesg is attached.\n" - "SENDBUG: Feel free to delete or use the -D flag if it contains " - "sensitive information.\n", fp); /* Find last dmesg. */ for (;;) { off_t o; @@ -577,6 +580,84 @@ template(FILE *fp) fprintf(fp, ">Fix:\n"); fprintf(fp, "\t%s\n", comment[4]); - if (!Dflag) + if (!Dflag) { + int root; + + fprintf(fp, "\n"); + root = !geteuid(); + if (!root) + fprintf(fp, "SENDBUG: Run sendbug as root " + "if this is an ACPI report!\n"); + fprintf(fp, "SENDBUG: dmesg%s attached.\n" + "SENDBUG: Feel free to delete or use the -D flag if it " + "contains sensitive information.\n", + root ? ", pcidump, and acpidump are" : " is"); + fputs("\ndmesg:\n", fp); dmesg(fp); + if (root) + hwdump(fp); + } +} + +void +hwdump(FILE *ofp) +{ + char buf[BUFSIZ]; + FILE *ifp; + char *cmd, *acpidir; + size_t len; + + if (gethostname(buf, sizeof(buf)) == -1) + err(1, "gethostname"); + buf[strcspn(buf, ".")] = '\0'; + + if (asprintf(&acpidir, "%s%sp.XXXXXXXXXX", tmpdir, + tmpdir[strlen(tmpdir) - 1] == '/' ? "" : "/") == -1) + err(1, "asprintf"); + if (mkdtemp(acpidir) == NULL) + err(1, "mkdtemp"); + + if (asprintf(&cmd, "echo \"\\npcidump:\"; pcidump -xxv; " + "echo \"\\nacpidump:\"; cd %s && acpidump -o %s; " + "for i in *; do b64encode $i $i; done; rm -rf %s", + acpidir, buf, acpidir) == -1) + err(1, "asprintf"); + + if ((ifp = popen(cmd, "r")) != NULL) { + while (!feof(ifp)) { + len = fread(buf, 1, sizeof buf, ifp); + if (len == 0) + break; + if (fwrite(buf, 1, len, ofp) != len) + break; + } + pclose(ofp); + } + free(cmd); +} + +void +debase(void) +{ + char buf[BUFSIZ]; + FILE *fp = NULL; + size_t len; + + while (fgets(buf, sizeof(buf), stdin) != NULL) { + len = strlen(buf); + if (!strncmp(buf, BEGIN64, sizeof(BEGIN64) - 1)) { + if (fp) + errx(1, "double begin"); + fp = popen("b64decode", "w"); + if (!fp) + errx(1, "popen b64decode"); + } + if (fp && fwrite(buf, 1, len, fp) != len) + errx(1, "pipe error"); + if (!strncmp(buf, END64, sizeof(END64) - 1)) { + if (pclose(fp) == -1) + errx(1, "pclose b64decode"); + fp = NULL; + } + } } |