home *** CD-ROM | disk | FTP | other *** search
- echo; /* Execute to compile!
-
- SC PGPPager.c LINK STARTUP=cres PARAMETERS=REGISTERS STRINGMERGE NOSTACKCHECK OPTIMIZE OPTIMIZERSIZE NOOPTIMIZERINLINE OPTIMIZERCOMPLEXITY=5 OPTIMIZERDEPTH=5 OPTIMIZERRECURDEPTH=5
- delete PGPPager.lnk PGPPager.o
- quit
-
- */
-
- /* pgppager, designed to be possibly integrated with elm mail reader
- *
- * by Alessandro Bottonelli (c)1993, A.Bottonelli@it12.bull.it
- * version 1.0 - 29/Jan/93
- * version 1.1 - 29/Jun/93 with contribution from Ori Degani
- * (ori@marvin.technion.ac.il)
- * version 1.1.1 - 16/Sep/93 modified for AmigaOS by Peter Simons
- *
- * This program is put in the public domain and permission is granted
- * to use it for any purpose, provided this copyright notice is retained.
- * NO WARRANTIES expressed or implied are given. USE THIS PROGRAM AT
- * YOUR OWN RISK!
- *
- * This programs reads from a specified file or from stdin if no file is
- * specified and creates three temporary files (header, encrypted, and
- * trailer) as needed, in order to store the header portion in cleartext,
- * the encrypted portion still in cypher text, and the trailer portion of
- * the clear text. Then, if applicable, the cleartext header is outputted,
- * the encrypted portion is piped through pgp as needed, then the trailer
- * (if any) is outputted. THIS PROCESS IS TRANSPARENT TO NON PGP ENCRYPTED
- * TEXTS
- *
- * For use with ELM, it is necessary to specify the display to be:
- *
- * <whatever_path>/pgppager | pg
- *
- * in the elm option menu.
- *
- * What's NEW:
- *
- * 1.1 Now handles clear_signed messages (thanks Ori!)
- *
- * WARNING: this program assumes that all messages from pgp with "-f" are
- * outputted on standard output instead of standard error
- * as in the original code. Only the messages that are needed
- * to prompt the user are kept on the standard error even if
- * PGP is invoked with "-f" option.
- *
- * This is done in pgp code by testing for -f and touch "pgpout"
- * variable accordingly, then making sure you identify in the
- * original PGP code all user prompts and keep them on stderr
- * no matter whether -f is used or not.
- */
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
-
- void Exit(int);
-
-
- /*
- * you may need to customize the next DEFINEs
- */
-
- #define TMPDIR "T:"
- #define PGP "PGP -f +BATCHMODE"
- #define BEGIN "-----BEGIN PGP MESSAGE----"
- #define END "-----END PGP MESSAGE----"
- #define BEGINSIG "-----BEGIN PGP SIGNED MESSAGE----"
- #define ENDSIG "-----END PGP SIGNATURE----"
-
-
- #define CAT "type" /* -s option to avoid cat complaining */
- /* about missing files */
-
- /*
- * program should be invoked as "pgppager [file] | pg"
- * actually no check is made to verify that the program
- * is piped through "pg" or "more", just in case someone
- * wants to redirect it to a file or a printer.
- * BEWARE: redirecting it to a file or printer may be
- * not good for your security if the file or printer level
- * of security is unknown or poor ...
- */
-
- /*
- * This variables global to be visible to the Exit() routine
- */
-
- char fh[128]; /* Header temporary file */
- char fe[128]; /* Encrypted/clear_signed temporary file */
- char fr[128]; /* Trailer temporary file */
-
- static char _OSVersionString[] = "$VER: PGPPager 1.1.1 (16-Sep-93)\0";
-
- main(ac,av)
- int ac;
- char **av;
- {
-
- FILE *fp; /* File pointer to read file(s) */
- FILE *ft; /* File pointer to temp file(s) */
- char line[256]; /* Read/Write buffer */
- char cmd[128]; /* command string */
-
-
-
- /*
- * Must be invoked as "pgppager [file_name]"
- */
-
- if (ac > 2 || !strcmp("?", av[1]))
- {
- fprintf(stderr,"Usage: %s [file_name]\n", av[0]);
- Exit(1);
- }
-
-
- /*
- * File ( if specified ) must exist and be readable
- */
-
- if ( ac == 2 )
- {
- if ( ( fp = fopen( av[1], "r") ) == NULL )
- {
- fprintf(stderr,"%s: cannot read %s\n", av[0], av[1]);
- Exit(2);
- }
- }
- else
- fp=stdin; /* if no file specified assume standard input */
-
- /*
- * Build temporary file names
- *
- */
-
- sprintf ( fh, "%spgpm.head", TMPDIR);
- sprintf ( fe, "%spgpm.encr", TMPDIR);
- sprintf ( fr, "%spgpm.trai", TMPDIR);
-
-
- /*
- * READ file until Eof, redirect to "fe" only those portions of the
- * file that are between the BEGIN PGP and END PGP ... lines.
- *
- */
- if ( ( ft = fopen ( fh, "w") ) == NULL )
- {
- fprintf(stderr,"%s: error opening temp file\n", av[0]);
- Exit(4);
- }
-
- fprintf( ft, "\n"); /* Just to start with a blank line */
-
- while ( fgets( line, 128, fp) != NULL )
- {
- if ( !strncmp( BEGIN, line, strlen( BEGIN) ) )
- {
- fprintf(ft, "\n===PGP ENCRYPTED MESSAGE BEGINS===\n\n");
- fclose(ft);
-
- if ( ( ft = fopen ( fe, "w") ) == NULL )
- {
- fprintf(stderr,"%s: error opening temp file\n", av[0]);
- Exit(4);
- }
-
- }
-
- if ( !strncmp( BEGINSIG, line, strlen( BEGINSIG) ) )
- {
- fprintf(ft, "\n===PGP SIGNED MESSAGE BEGINS===\n\n");
- fclose(ft);
-
- if ( ( ft = fopen ( fe, "w") ) == NULL )
- {
- fprintf(stderr,"%s: error opening temp file\n", av[0]);
- Exit(4);
- }
-
- }
-
- fprintf( ft, "%s", line);
-
- if ( !strncmp( END, line, strlen( END) ))
- {
- fclose(ft);
-
- if ( ( ft = fopen ( fr, "w") ) == NULL )
- {
- fprintf(stderr,"%s: error opening temp file\n", av[0]);
- Exit(4);
- }
-
- fprintf(ft, "\n\n===PGP ENCRYPTED MESSAGE ENDS===\n");
- }
-
- if ( !strncmp( ENDSIG, line, strlen( ENDSIG) ))
- {
- fclose(ft);
-
- if ( ( ft = fopen ( fr, "w") ) == NULL )
- {
- fprintf(stderr,"%s: error opening temp file\n", av[0]);
- Exit(4);
- }
-
- fprintf(ft, "\n\n===PGP SIGNED MESSAGE ENDS===\n");
- }
- }
-
- fclose(fp);
- fclose(ft);
-
- sprintf( cmd, "%s %s", CAT, fh);
- system(cmd);
- fflush(stdout);
- sprintf( cmd, "%s <%s", PGP, fe);
- system(cmd);
- fflush(stdout);
- sprintf( cmd, "%s %s", CAT, fr);
- system(cmd);
-
- Exit(0); /* That's all folks ... */
- }
-
- /*
- * Exit(s) are centralized in this routine to make sure we wipe out
- * temporary files in any case ...
- */
-
- void Exit(int n) /* value to be returned to the shell (0 = OK) */
- {
- /*
- * Remove temporary files (if any)
- */
-
- unlink(fh);
- unlink(fe);
- unlink(fr);
-
- exit(n);
- }
-
-