Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!pt.cs.cmu.edu!andrew.cmu.edu!jm36+ From: jm36+@andrew.cmu.edu (John Gardiner Myers) Newsgroups: comp.sources.d Subject: Re: An idea for safer and portable unshar-ing Message-ID:Date: 3 Oct 89 20:56:34 GMT References: <1989Sep30.171114.12550@chance.UUCP> <8910020054.AA08811@cscwam.UMD.EDU> <2270@munnari.oz.au>, <923@cirrusl.UUCP> Organization: Mathematics, Carnegie Mellon, Pittsburgh, PA Lines: 58 In-Reply-To: <923@cirrusl.UUCP> I came up with an archive format with a rigid format which could be extracted by a relatively simple but secure unpacker and could also be fed to /bin/sh. The trick was to include a small C program in the archive to allow those who hadn't obtained the unpacking program to extract the files. A sample archive follows: #! /bin/sh # This is a mail archive. To unpack it, use the 'unmar' program from # comp.sources.unix. Alternatively, you can remove anything before this # line, then unpack it by saving it into a file and typing "sh file". # Contents: TEST # Wrapped by jm36@beak.andrew.cmu.edu on Tue Oct 3 16:32:24 1989 PATH=/bin:/usr/bin:/usr/ucb ; export PATH cat >,sunmar.c <<'EOF' #include char *mystrchr(p,c) char *p; int c; { while (*p && *p != c) p++; return *p ? p : 0;} main() { char *p, buf[4096]; FILE *ofile = NULL; while (fgets(buf, sizeof(buf), stdin)) { if (ofile) { if (!strcmp(buf, "END\n")) { fclose(ofile); ofile = NULL; } else fputs(buf+(buf[0]=='X'), ofile); } else { if (!strncmp(buf, "BEGIN ", 6)) { if (p = mystrchr(buf+6, ' ')) *p = '\0'; if (!(ofile = fopen(buf+6, "w"))) { perror(buf+6); } else printf("Extracting file %s\n", buf+6); } else if (!strncmp(buf, "DIRECTORY ", 10)) { if (p = mystrchr(buf+10, ' ')) *p = '\0'; strncpy(buf+4, "mkdir", 5); system(buf+4); }}}} EOF cc -o ,sunmar ,sunmar.c ./,sunmar <<'END_OF_ARCHIVE' BEGIN TEST - 16 XThis is a test. END END_ARCHIVE END_OF_ARCHIVE rm -f ,sunmar ,sunmar.c exit 0 I haven't released this format because it would give any reasonable implementation of "unshar" a severe case of indigestion. The format would only be worth releasing if it had a decent chance of becoming more common than the shar format. It would only become the standard if the moderators of the sources groups adopted it. The moderators will only adopt it if it becomes the de-facto standard. Catch-22. -- _.John G. Myers Internet: John.G.Myers@andrew.cmu.edu (412) 268-2984 LoseNet: ...!seismo!ihnp4!wiscvm.wisc.edu!give!up