head 1.24; access; symbols; locks simons:1.24; comment @ ** @; 1.24 date 93.09.22.23.08.20; author simons; state Exp; branches; next 1.23; 1.23 date 93.09.22.23.04.47; author simons; state Exp; branches; next 1.22; 1.22 date 93.09.21.17.32.56; author simons; state Stab; branches; next 1.21; 1.21 date 93.09.21.17.27.17; author simons; state Exp; branches; next 1.20; 1.20 date 93.09.19.13.25.27; author simons; state Stab; branches; next 1.19; 1.19 date 93.09.18.18.08.52; author simons; state Stab; branches; next 1.18; 1.18 date 93.09.14.23.16.39; author simons; state Exp; branches; next 1.17; 1.17 date 93.09.14.22.43.20; author simons; state Exp; branches; next 1.16; 1.16 date 93.09.13.17.40.04; author simons; state Exp; branches; next 1.15; 1.15 date 93.09.11.21.58.49; author simons; state Exp; branches; next 1.14; 1.14 date 93.08.25.01.11.28; author simons; state Exp; branches; next 1.13; 1.13 date 93.08.22.17.39.54; author simons; state stab; branches; next 1.12; 1.12 date 93.08.22.17.26.58; author simons; state Exp; branches; next 1.11; 1.11 date 93.08.21.15.32.45; author simons; state Stab; branches; next 1.10; 1.10 date 93.08.21.15.15.34; author simons; state Exp; branches; next 1.9; 1.9 date 93.08.21.13.40.27; author simons; state Exp; branches; next 1.8; 1.8 date 93.08.16.21.51.05; author simons; state Stab; branches; next 1.7; 1.7 date 93.08.10.17.02.30; author simons; state Stab; branches; next 1.6; 1.6 date 93.08.10.16.31.52; author simons; state Stab; branches; next 1.5; 1.5 date 93.08.10.16.13.05; author simons; state Stab; branches; next 1.4; 1.4 date 93.08.10.02.51.39; author simons; state Exp; branches; next 1.3; 1.3 date 93.08.10.02.34.31; author simons; state Exp; branches; next 1.2; 1.2 date 93.08.10.00.10.28; author simons; state Exp; branches; next 1.1; 1.1 date 93.08.09.22.33.14; author simons; state Exp; branches; next ; desc @This is a replacement for the UUCP command >rmail<. PGPRMail reads the incoming message from standard input, and prints the plaintext to a pipe, calling the original rmail with this set to standard input. PGP-encrypted parts of the e-mail will be piped to PGP and will be replaced with the plaintext. @ 1.24 log @BUG: PGPRMail doesn't really support buffer-overflow checking!! I changed the buffer to 10k size, however, this is nasty and needs to be fixed ASAP! @ text @/** ** $Filename: PGPRMail.c $ ** $Revision: 1.23 $ ** $Date: 1993/09/22 23:04:47 $ ** ** This is a replacement for the UUCP command >rmail<. PGPRMail ** reads the incoming message from standard input, and prints ** the plaintext to a pipe, calling the original rmail with this ** set to standard input. ** ** PGP-encrypted parts of the e-mail will be piped to PGP and will ** be replaced with the plaintext. ** ** © Copyright 1993 Peter Simons, Germany ** All Rights Reserved ** ** $Id: PGPRMail.c,v 1.23 1993/09/22 23:04:47 simons Exp simons $ ** ** ------------------------------ log history ---------------------------- ** $Log: PGPRMail.c,v $ ** Revision 1.23 1993/09/22 23:04:47 simons ** Removed the ArrayToLine() routine, because it isn't needed anymore. ** ** Revision 1.22 1993/09/21 17:32:56 simons ** Added more debug-output at startup-time. ** ** Revision 1.21 1993/09/21 17:27:17 simons ** "my_ulog" is extended to several lines and therefore requires brackets ** around the actual commands or it will break certain statements. ** ** Revision 1.20 1993/09/19 13:25:27 simons ** Another major bug found: Due to wrong placed brackets, a loop was ** not executed completly. ** ** Revision 1.19 1993/09/18 18:08:52 simons ** PGPRMail recognized a missing parameter, but didn't terminate. :-) ** ** Revision 1.18 1993/09/14 23:16:39 simons ** Added log message when PGPRMail was started without parameters. ** ** Revision 1.17 1993/09/14 22:43:20 simons ** Now using my modified startup code for less overhead. Therefore had to ** change a few things in the source, no `real' modification. ** ** Revision 1.16 1993/09/13 17:40:04 simons ** Added logfile support and various log- and debug-messages. ** ** Revision 1.15 1993/09/11 21:58:49 simons ** The command started by PGPRMail has been renamed to 'rmail'. ** ** Revision 1.14 1993/08/25 01:11:28 simons ** Mega bug fixed: PGPRMail did not check if the receipient of the mail ** is located on this system. Though, it tried to decrypt mail, that is ** routed via the home-system!! ** ** The current fix is more like a workaround, because I do not know for ** shure, how this is to determine easily. (See comments in the source.) ** ** Revision 1.13 1993/08/22 17:39:54 simons ** PGPRMail used to call rmail with argv[0] as parameter also. This has ** been fixed. ** Known bugs: - currently does not correct the "Lines:" keyword ** ** Revision 1.12 1993/08/22 17:26:58 simons ** PGPRMail didn't support multiple copies of one mail. It does now. :-) ** ** Revision 1.11 1993/08/21 15:32:45 simons ** Added define for the internal IO buffer size and set it to BUFSIZ*10, ** what seemed to be the best value in several tests. ** ** Revision 1.10 1993/08/21 15:15:34 simons ** Added buffering to getline(), what should result in a major speedup. ** ** Revision 1.9 1993/08/21 13:40:27 simons ** The first copying-process has been rewritten to use the low-level IO ** routines, what gained a lot of speed. (25 seconds on a 800k file!) ** ** Revision 1.8 1993/08/16 21:51:05 simons ** removed some debugging output ** ** Revision 1.7 1993/08/10 17:02:30 simons ** Changed the commandline PGP is called with. ** ** Revision 1.6 1993/08/10 16:31:52 simons ** If an disk-full error occurs after the standard input has been read ** completely, PGPRMail doe not terminate, but call rmail with the ** original file as parameter. ** Data-loss seems impossible now! ** Status turned to stable. ** ** Revision 1.5 1993/08/10 16:13:05 simons ** PGPRMail now returns the code, rmail returnes. ** A 10 (instead of 5) is returned for fatal errors. ** Added security checks, just in case the disk holding the temporary ** files is full. ** Changed getline(): EOF is now only returned if no more characters are ** available. The previous version returned EOF is no ** complete (\n terminated) line was available. ** ** Revision 1.4 1993/08/10 02:51:39 simons ** Added RCS Id string to the executable. ** The temporary file for PGP messages is now deleted every time, a ** message has been decoded successfully. Otherwise PGP would have ** decoded the previous message again. ** ** Revision 1.3 1993/08/10 02:34:31 simons ** Changed filename to PGPRMail. ** Replaced all pipes with 'ordinary' temporary files. This should increase ** the programs security and make it easier for me to handle errors. ** Added several error messages and security checks. ** PGPRMail recognizes damaged PGP message blocks. ** PGPRMail recognizes errorcodes returned by PGP. ** ** Revision 1.2 1993/08/10 00:10:28 simons ** The program works just fine, but I do a minimum of error-checking. ** This is dangerous and may cause data loss in the current revision. ** ** Revision 1.1 1993/08/09 22:33:14 simons ** Initial revision **/ /************************************************************************** * * * Sektion: Macros, Definitions, Includes, Structures * * * **************************************************************************/ /************************************* Includes ***********/ #include #include #include #include #include "SC:Sources/uucp.lib/include/config.h" #include "SC:Sources/uucp.lib/include/log.h" /************************************* Defines ************/ #define PGP "PGP -f <%s >>%s +batchmode" #define START_RMAIL "rmail <%s %s" #define MSG_BEGIN "-----BEGIN PGP MESSAGE----" #define MSG_END "-----END PGP MESSAGE----" #define DECRYPT_BEGIN "==== begin of decrypted PGP message ====\n" #define DECRYPT_END "==== end of decrypted PGP message ====\n" #define LINEBUFFER 1024*10 /* max. line length */ #define IOBUFSIZE BUFSIZ*10 /* size of internal IO buffer */ #define my_ulog(level, name, msg) { OpenLog(); ulog(level, name, msg); CloseLog(); } #define my_ulog2(level, msg) { OpenLog(); ulog(level, msg); CloseLog(); } /************************************* Prototypes *********/ void error(char *, int); int getline(FILE *,char buffer[]); int CopyUntilEOF(int in, int out); static const char __RCSId[] = "$Id: PGPRMail.c,v 1.23 1993/09/22 23:04:47 simons Exp simons $"; /************************************************************************** * * * Sektion: Hauptprogramm * * * **************************************************************************/ int main(char *argv) { FILE *pipe1, *pipe2, *file; int flag, i; char *line, PIPE1[L_tmpnam], PIPE2[L_tmpnam]; char FILENAME[L_tmpnam], *debuglevel; /* Determine loglevel. */ if ((debuglevel = FindConfig(DEBUGNAME)) == NULL) LogLevel = 0; else LogLevel = atoi(debuglevel); /* Tell the world we are here! */ my_ulog(4, "PGPRMail, started with commandline `%s'", argv); my_ulog(4, "PGPRMail, loglevel is %d", LogLevel); /* Allocate internal buffer */ if (!(line = malloc(LINEBUFFER))) error("failed allocating internal buffer", 20); /* Make unique filenames for the temporary files and open them. */ tmpnam(PIPE1); tmpnam(PIPE2); tmpnam(FILENAME); if ((pipe1 = fopen(PIPE1, "w")) == NULL) error("Can't open temporary file!", 10); if ((pipe2 = fopen(PIPE2, "w")) == NULL) error("Can't open temporary file!", 10); if ((file = fopen(FILENAME, "w+")) == NULL) error("Can't open temporary file!", 10); /* * Copy standard input to a temporary file for security reasons. */ if (CopyUntilEOF(fileno(stdin), fileno(file)) == NULL) error("Can't write to my temporary file!", 10); my_ulog(2, "PGPRMail, original mail in '%s'", FILENAME); /* * Check is the receipient of the mail is on this system!! * * The specified addresses MUST NOT contain a '!' or '@@', because * this means that the mail will be routed to another system. * Hence, we must not touch this message! */ if ((flag = strlen(argv)) > 0) { for (i = 0; i < flag; i++) { if (argv[i] == '!' || argv[i] == '@@') { my_ulog2(1, "PGPRMail, mail is routed to another machine and therefore not decrypted"); flag = 0; break; } } } else my_ulog2(1, "PGPRMail, no parameters provided --> TERMINATED"); /* Browse through the file for PGP messages. */ if (flag > 0) { fseek(file, 0L, SEEK_SET); while (flag != EOF) { if ((flag = getline(file, line)) != EOF) { if (!strncmp(MSG_BEGIN, line, strlen(MSG_BEGIN))) { my_ulog(3, "PGPRMail, found \"%s\"", MSG_BEGIN); if ((fprintf(pipe1, DECRYPT_BEGIN)) < 0) { flag = 0; break; } my_ulog(2, "PGPRMail, modified mail in '%s'", PIPE1); if ((fprintf(pipe2, "%s", line)) < 0) { flag = 0; break; } if ((flag = getline(file, line)) == EOF) { flag = 0; break; } while (strncmp(MSG_END, line, strlen(MSG_END))) { if ((fprintf(pipe2, "%s", line)) < 0) { flag = 0; break; } if ((flag = getline(file, line)) == EOF) { flag = 0; break; } } my_ulog(3, "PGPRMail, found \"%s\"", MSG_END); my_ulog(2, "PGPRMail, encrypted block in '%s'", PIPE2); /* * If an EOF occured during the PGP message * scan, the message seems to be damaged. * Break here and use the original! */ if (flag == 0) break; /* Everything is fine! Call PGP. */ if ((fprintf(pipe2, "%s", line)) < 0) { flag = 0; break; } sprintf(line, PGP, PIPE2, PIPE1); fprintf(stderr, "%s\n", line); fclose(pipe1); pipe1 = NULL; fclose(pipe2); pipe2 = NULL; my_ulog(1, "PGPRMail, starting '%s'", line); if (system(line)) { my_ulog2(1, "PGPRMail, PGP failed somehow"); flag = 0; break; } if ((pipe1 = fopen(PIPE1, "a")) == NULL) break; /* Do not append new data to pipe2!! */ if ((pipe2 = fopen(PIPE2, "w")) == NULL) break; if ((fprintf(pipe1, DECRYPT_END)) < 0) { flag = 0; break; } my_ulog2(2, "PGPRMail, decrypted text joined to mail-body"); } else if ((fprintf(pipe1, "%s", line)) < 0) { flag = 0; break; } } } } /* Close temporary files, so rmail can open them. */ fclose(pipe1); fclose(pipe2); fclose(file); /* * If the loop has been interrupted due to an error, use * the original file for input. * * If everything went fine, pipe the generated textfile. */ if (flag == 0 || pipe1 == NULL || pipe2 == NULL) { fprintf(stderr, "PGPRMail: Nonfatal error occured!\n"); my_ulog2(-1, "PGPRMail, decrypting process failed"); sprintf(line, START_RMAIL, FILENAME, argv); my_ulog(2, "PGPRMail, starting '%s'", line); flag = system(line); } else { sprintf(line, START_RMAIL, PIPE1, argv); my_ulog(2, "PGPRMail, starting '%s'", line); flag = system(line); } /* Delete temporary files. */ remove(PIPE1); remove(PIPE2); remove(FILENAME); return flag; /* flag contains the return code of rmail */ } /************************************************************************** * * * Unterprogramme * * * **************************************************************************/ void error(char *message, int errorcode) { my_ulog(-1, "PGPRMail, %s", message); fprintf(stderr, "PGPRMail: %s\n", message); exit(errorcode); } int getline(FILE *file, char *buffer) { int i = 0; static char *gl_buffer = NULL; static int counter = 0, len = 0; /* If allocating buffer fails, exit immediatly. */ if (gl_buffer == NULL) if ((gl_buffer = malloc(IOBUFSIZE)) == NULL) error("Can't allocate my buffers!", 10); /* * Copy buffered characters until buffer is empty or and * end-of-line is reached. */ while (1) { /* Forever!*/ while (counter < len) { i++; if ((*buffer++ = gl_buffer[counter++]) == '\n') break; } if (counter < len) { *buffer = '\0'; /* Everything went fine. */ return i; } /* Buffer went out of data before end-of-line was found. */ if ((len = read(fileno(file), gl_buffer, IOBUFSIZE)) <= 0) if (i > 0) { *buffer = '\0'; return i; } else return EOF; counter = 0; } } int CopyUntilEOF(int in, int out) { char *buffer; int len; if ((buffer = malloc(IOBUFSIZE)) == NULL) return 0; while ((len = read(in, buffer, IOBUFSIZE)) > 0) if (write(out, buffer, len) == -1) { free(buffer); return 0; } free(buffer); return 1; } @ 1.23 log @Removed the ArrayToLine() routine, because it isn't needed anymore. @ text @d3 2 a4 2 ** $Revision: 1.22 $ ** $Date: 1993/09/21 17:32:56 $ d17 1 a17 1 ** $Id: PGPRMail.c,v 1.22 1993/09/21 17:32:56 simons Stab simons $ d21 3 d149 1 a149 1 #define LINEBUFFER 256 /* max. line length */ d160 1 a160 1 static const char __RCSId[] = "$Id: PGPRMail.c,v 1.22 1993/09/21 17:32:56 simons Stab simons $"; d172 1 a172 1 char line[LINEBUFFER], PIPE1[L_tmpnam], PIPE2[L_tmpnam]; d188 6 @ 1.22 log @Added more debug-output at startup-time. @ text @d3 2 a4 2 ** $Revision: 1.21 $ ** $Date: 1993/09/21 17:27:17 $ d17 1 a17 1 ** $Id: PGPRMail.c,v 1.21 1993/09/21 17:27:17 simons Exp simons $ d21 3 a155 1 char *ArrayToLine(char *array[]); d157 1 a157 1 static const char __RCSId[] = "$Id: PGPRMail.c,v 1.21 1993/09/21 17:27:17 simons Exp simons $"; a426 16 char *ArrayToLine(char *array[]) { char *line; if((line = malloc(LINEBUFFER)) == NULL) return NULL; line[0] = '\0'; while (*array != NULL) { strcat(line, *array); strcat(line, " "); array++; } return line; } @ 1.21 log @"my_ulog" is extended to several lines and therefore requires brackets around the actual commands or it will break certain statements. @ text @d3 2 a4 2 ** $Revision: 1.20 $ ** $Date: 1993/09/19 13:25:27 $ d17 1 a17 1 ** $Id: PGPRMail.c,v 1.20 1993/09/19 13:25:27 simons Stab simons $ d21 4 d155 1 a155 1 static const char __RCSId[] = "$Id: PGPRMail.c,v 1.20 1993/09/19 13:25:27 simons Stab simons $"; d177 6 @ 1.20 log @Another major bug found: Due to wrong placed brackets, a loop was not executed completly. @ text @d3 2 a4 2 ** $Revision: 1.19 $ ** $Date: 1993/09/18 18:08:52 $ d17 1 a17 1 ** $Id: PGPRMail.c,v 1.19 1993/09/18 18:08:52 simons Stab simons $ d21 4 d142 2 a143 2 #define my_ulog(level, name, msg) OpenLog(); ulog(level, name, msg); CloseLog(); #define my_ulog2(level, msg) OpenLog(); ulog(level, msg); CloseLog(); d151 1 a151 1 static const char __RCSId[] = "$Id: PGPRMail.c,v 1.19 1993/09/18 18:08:52 simons Stab simons $"; @ 1.19 log @PGPRMail recognized a missing parameter, but didn't terminate. :-) @ text @d3 2 a4 2 ** $Revision: 1.18 $ ** $Date: 1993/09/14 23:16:39 $ d17 1 a17 1 ** $Id: PGPRMail.c,v 1.18 1993/09/14 23:16:39 simons Exp simons $ d21 3 d147 1 a147 1 static const char __RCSId[] = "$Id: PGPRMail.c,v 1.18 1993/09/14 23:16:39 simons Exp simons $"; d202 2 a203 2 if ((flag = strlen(argv)) > 0) for (i = 0; i < flag; i++) d209 3 a211 1 else { a212 2 flag = 0; } @ 1.18 log @Added log message when PGPRMail was started without parameters. @ text @d3 2 a4 2 ** $Revision: 1.17 $ ** $Date: 1993/09/14 22:43:20 $ d17 1 a17 1 ** $Id: PGPRMail.c,v 1.17 1993/09/14 22:43:20 simons Exp simons $ d21 3 d144 1 a144 1 static const char __RCSId[] = "$Id: PGPRMail.c,v 1.17 1993/09/14 22:43:20 simons Exp simons $"; d206 1 a206 1 else d208 2 a209 1 @ 1.17 log @Now using my modified startup code for less overhead. Therefore had to change a few things in the source, no `real' modification. @ text @d3 2 a4 2 ** $Revision: 1.16 $ ** $Date: 1993/09/13 17:40:04 $ d17 1 a17 1 ** $Id: PGPRMail.c,v 1.16 1993/09/13 17:40:04 simons Exp simons $ d21 4 d141 1 a141 1 static const char __RCSId[] = "$Id: PGPRMail.c,v 1.16 1993/09/13 17:40:04 simons Exp simons $"; d203 2 @ 1.16 log @Added logfile support and various log- and debug-messages. @ text @a0 8 echo; /* Execute to compile with SAS/C v6.x SC PGPRMail.c STARTUP=cres LIB=LIB:uucp.lib DEBUG=FF LINK PARAMETERS=REGISTERS NOSTACKCHECK STRINGMERGE ; OPTIMIZE OPTIMIZERSIZE NOOPTIMIZERINLINE OPTIMIZERCOMPLEXITY=5 OPTIMIZERDEPTH=5 OPTIMIZERRECURDEPTH=5 delete PGPRMail.lnk PGPRMail.o quit */ d3 2 a4 2 ** $Revision: 1.15 $ ** $Date: 1993/09/11 21:58:49 $ d17 1 a17 1 ** $Id: PGPRMail.c,v 1.15 1993/09/11 21:58:49 simons Exp simons $ d21 3 d137 1 a137 1 static const char __RCSId[] = "$Id: PGPRMail.c,v 1.15 1993/09/11 21:58:49 simons Exp simons $"; d145 1 a145 1 int main(int argc, char *argv[]) d148 1 a148 1 int flag, i, z; d150 1 a150 1 char FILENAME[L_tmpnam], *strptr, *debuglevel; d192 6 a197 8 flag = 1; if (argc > 1) { for (i = 1; i <= argc && flag == 1; i++) { for(z = 0, strptr = argv[i]; strptr[z] != '\0'; z++) { if (strptr[z] == '!' || strptr[z] == '@@') { flag = 0; break; } a198 4 } } else flag = 0; d203 1 a203 1 if (flag == 1) { d302 1 a302 1 sprintf(line, START_RMAIL, FILENAME, ArrayToLine(&argv[1])); d307 1 a307 1 sprintf(line, START_RMAIL, PIPE1, ArrayToLine(&argv[1])); @ 1.15 log @The command started by PGPRMail has been renamed to 'rmail'. @ text @d3 1 a3 1 SC PGPRMail.c STARTUP=cres DEBUG=FF LINK STRICT ANSI PARAMETERS=REGISTERS NOSTACKCHECK STRINGMERGE ; OPTIMIZE OPTIMIZERSIZE NOOPTIMIZERINLINE OPTIMIZERCOMPLEXITY=5 OPTIMIZERDEPTH=5 OPTIMIZERRECURDEPTH=5 d11 2 a12 2 ** $Revision: 1.14 $ ** $Date: 1993/08/25 01:11:28 $ d25 1 a25 1 ** $Id: PGPRMail.c,v 1.14 1993/08/25 01:11:28 simons Exp simons $ d29 3 d117 2 d122 1 a122 1 #define RMAIL "rmail <%s %s" d133 3 d142 1 a142 1 static const char __RCSId[] = "$Id: PGPRMail.c,v 1.14 1993/08/25 01:11:28 simons Exp simons $"; d155 4 a158 1 char FILENAME[L_tmpnam], *strptr; d160 5 d166 1 a166 4 /* * Make unique filenames for the temporary files * and open them. */ d186 1 d219 1 d224 1 d243 2 d262 1 a262 1 sprintf( line, PGP, PIPE2, PIPE1); d266 1 d268 1 d285 1 d312 3 a314 1 sprintf(line, RMAIL, FILENAME, ArrayToLine(&argv[1])); d318 2 a319 1 sprintf(line, RMAIL, PIPE1, ArrayToLine(&argv[1])); d341 1 @ 1.14 log @Mega bug fixed: PGPRMail did not check if the receipient of the mail is located on this system. Though, it tried to decrypt mail, that is routed via the home-system!! The current fix is more like a workaround, because I do not know for shure, how this is to determine easily. (See comments in the source.) @ text @d11 2 a12 2 ** $Revision: 1.13 $ ** $Date: 1993/08/22 17:39:54 $ d25 1 a25 1 ** $Id: PGPRMail.c,v 1.13 1993/08/22 17:39:54 simons stab simons $ d29 8 d117 1 a117 1 #define RMAIL "rmail.exe <%s %s" d134 1 a143 2 static const char __RCSId[] = "$Id: PGPRMail.c,v 1.13 1993/08/22 17:39:54 simons stab simons $"; @ 1.13 log @PGPRMail used to call rmail with argv[0] as parameter also. This has been fixed. Known bugs: - currently does not correct the "Lines:" keyword @ text @d11 2 a12 2 ** $Revision: 1.12 $ ** $Date: 1993/08/22 17:26:58 $ d25 1 a25 1 ** $Id: PGPRMail.c,v 1.12 1993/08/22 17:26:58 simons Exp simons $ d29 5 d135 1 a135 1 static const char __RCSId[] = "$Id: PGPRMail.c,v 1.12 1993/08/22 17:26:58 simons Exp simons $"; d138 1 a138 1 int flag; d140 1 a140 1 char FILENAME[L_tmpnam]; d168 7 a174 1 /* Browse through the file for PGP messages. */ d176 5 a180 6 flag = fseek(file, 0L, SEEK_SET); flag = 0; while (flag != EOF) { if ((flag = getline(file, line)) != EOF) { if (!strncmp(MSG_BEGIN, line, strlen(MSG_BEGIN))) { if ((fprintf(pipe1, DECRYPT_BEGIN)) < 0) { d184 18 a201 9 if ((fprintf(pipe2, "%s", line)) < 0) { flag = 0; break; } if ((flag = getline(file, line)) == EOF) { flag = 0; break; } while (strncmp(MSG_END, line, strlen(MSG_END))) { d210 10 a219 1 } d221 5 a225 5 /* * If an EOF occured during the PGP message * scan, the message seems to be damaged. * Break here and use the original! */ d227 2 a228 2 if (flag == 0) break; d231 1 a231 1 /* Everything is fine! Call PGP. */ d233 12 a244 12 if ((fprintf(pipe2, "%s", line)) < 0) { flag = 0; break; } sprintf( line, PGP, PIPE2, PIPE1); fprintf(stderr, "%s\n", line); fclose(pipe1); pipe1 = NULL; fclose(pipe2); pipe2 = NULL; if (system(line)) { flag = 0; break; } d246 2 a247 2 if ((pipe1 = fopen(PIPE1, "a")) == NULL) break; d250 1 a250 1 /* Do not append new data to pipe2!! */ d252 6 a257 5 if ((pipe2 = fopen(PIPE2, "w")) == NULL) break; if ((fprintf(pipe1, DECRYPT_END)) < 0) { flag = 0; break; d259 5 a264 5 else if ((fprintf(pipe1, "%s", line)) < 0) { flag = 0; break; } a266 1 @ 1.12 log @PGPRMail didn't support multiple copies of one mail. It does now. :-) @ text @d11 2 a12 2 ** $Revision: 1.11 $ ** $Date: 1993/08/21 15:32:45 $ d25 1 a25 1 ** $Id: PGPRMail.c,v 1.11 1993/08/21 15:32:45 simons Stab simons $ d29 3 d130 1 a130 1 static const char __RCSId[] = "$Id: PGPRMail.c,v 1.11 1993/08/21 15:32:45 simons Stab simons $"; d256 1 a256 1 sprintf(line, RMAIL, FILENAME, ArrayToLine(argv)); d260 1 a260 1 sprintf(line, RMAIL, PIPE1, ArrayToLine(argv)); @ 1.11 log @Added define for the internal IO buffer size and set it to BUFSIZ*10, what seemed to be the best value in several tests. @ text @d3 1 a3 1 SC PGPRMail.c STARTUP=cres DEBUG=FF LINK STRICT ANSI d11 2 a12 2 ** $Revision: 1.10 $ ** $Date: 1993/08/21 15:15:34 $ d25 1 a25 1 ** $Id: PGPRMail.c,v 1.10 1993/08/21 15:15:34 simons Exp simons $ d29 4 d116 1 d127 1 a127 1 static const char __RCSId[] = "$Id: PGPRMail.c,v 1.10 1993/08/21 15:15:34 simons Exp simons $"; a134 6 /* Is the commandline correct? */ if (argc != 2) error("Syntax is incorrect!", 10); d253 1 a253 1 sprintf(line, RMAIL, FILENAME, argv[1]); d257 1 a257 1 sprintf(line, RMAIL, PIPE1, argv[1]); d346 16 @ 1.10 log @Added buffering to getline(), what should result in a major speedup. @ text @d12 1 a12 1 ** $Date: 1993/08/21 15:10:16 $ d25 1 a25 1 ** $Id: PGPRMail.c,v 1.10 1993/08/21 15:10:16 simons Exp simons $ d29 3 d105 2 a106 3 #define LINEBUFFER 256 #define STDIN 0 #define STDOUT 1 d122 1 a122 1 static const char __RCSId[] = "$Id: PGPRMail.c,v 1.10 1993/08/21 15:10:16 simons Exp simons $"; d293 1 a293 1 if ((gl_buffer = malloc(BUFSIZ*5)) == NULL) d317 1 a317 1 if ((len = read(fileno(file), gl_buffer, BUFSIZ*5)) <= 0) d334 1 a334 1 if ((buffer = malloc(BUFSIZ*10)) == NULL) d337 1 a337 1 while ((len = read(in, buffer, BUFSIZ*10)) > 0) @ 1.9 log @The first copying-process has been rewritten to use the low-level IO routines, what gained a lot of speed. (25 seconds on a 800k file!) @ text @d11 2 a12 2 ** $Revision: 1.8 $ ** $Date: 1993/08/16 21:51:05 $ d25 1 a25 1 ** $Id: PGPRMail.c,v 1.8 1993/08/16 21:51:05 simons Stab simons $ d29 4 d120 1 a120 1 static const char __RCSId[] = "$Id: PGPRMail.c,v 1.8 1993/08/16 21:51:05 simons Stab simons $"; d284 28 a311 1 int c, i = 0; d313 9 a321 13 do { c = fgetc(file); *buffer = c; i++; buffer++; } while (i < LINEBUFFER && c != EOF && c != '\n'); if (i >= LINEBUFFER) error("Buffer overflow!", 10); if (c == EOF && i == 1) { *(buffer-1) = '\0'; return EOF; } d323 1 a323 3 if (c == '\n') { *buffer = '\0'; return i; a324 1 @ 1.8 log @removed some debugging output @ text @d11 2 a12 2 ** $Revision: 1.7 $ ** $Date: 1993/08/10 17:02:30 $ d25 1 a25 1 ** $Id: PGPRMail.c,v 1.7 1993/08/10 17:02:30 simons Stab simons $ d29 3 d84 1 d99 2 a100 1 d105 1 d116 1 a116 1 static const char __RCSId[] = "$Id: PGPRMail.c,v 1.7 1993/08/10 17:02:30 simons Stab simons $"; d151 2 a152 3 while ((flag = getchar()) != EOF) if ((fputc(flag, file)) == EOF) error("Can't write to my temporary file!", 10); d301 18 @ 1.7 log @Changed the commandline PGP is called with. @ text @d11 2 a12 2 ** $Revision: 1.6 $ ** $Date: 1993/08/10 16:31:52 $ d25 1 a25 1 ** $Id: PGPRMail.c,v 1.6 1993/08/10 16:31:52 simons Stab simons $ d29 3 d110 1 a110 1 static const char __RCSId[] = "$Id: PGPRMail.c,v 1.6 1993/08/10 16:31:52 simons Stab simons $"; a243 1 fprintf(stderr, "%s\n", line); a247 1 fprintf(stderr, "%s\n", line); @ 1.6 log @If an disk-full error occurs after the standard input has been read completely, PGPRMail doe not terminate, but call rmail with the original file as parameter. Data-loss seems impossible now! Status turned to stable. @ text @d11 2 a12 2 ** $Revision: 1.5 $ ** $Date: 1993/08/10 16:13:05 $ d25 1 a25 1 ** $Id: PGPRMail.c,v 1.5 1993/08/10 16:13:05 simons Stab simons $ d29 7 d82 1 a82 1 #define PGP "PGP -f <%s >>%s +BATCH" d107 1 a107 1 static const char __RCSId[] = "$Id: PGPRMail.c,v 1.5 1993/08/10 16:13:05 simons Stab simons $"; @ 1.5 log @PGPRMail now returns the code, rmail returnes. A 10 (instead of 5) is returned for fatal errors. Added security checks, just in case the disk holding the temporary files is full. Changed getline(): EOF is now only returned if no more characters are available. The previous version returned EOF is no complete (\n terminated) line was available. @ text @d3 1 a3 1 SC PGPRMail.c DEBUG=FF LINK STRICT ANSI d11 2 a12 2 ** $Revision: 1.4 $ ** $Date: 1993/08/10 02:51:39 $ d25 1 a25 1 ** $Id: PGPRMail.c,v 1.4 1993/08/10 02:51:39 simons Exp simons $ d29 9 d100 1 a100 1 static const char __RCSId[] = "$Id: PGPRMail.c,v 1.4 1993/08/10 02:51:39 simons Exp simons $"; d147 8 a154 4 if ((fprintf(pipe1, DECRYPT_BEGIN)) < 0) error("Can't write to my temporary file!", 10); if ((fprintf(pipe2, "%s", line)) < 0) error("Can't write to my temporary file!", 10); d160 4 a163 2 if ((fprintf(pipe2, "%s", line)) < 0) error("Can't write to my temporary file!", 10); d182 4 a185 2 if ((fprintf(pipe2, "%s", line)) < 0) error("Can't write to my temporary file!", 10); d203 4 a206 2 if ((fprintf(pipe1, DECRYPT_END)) < 0) error("Can't write to my temporary file!", 10); d209 4 a212 2 if ((fprintf(pipe1, "%s", line)) < 0) error("Can't write to my temporary file!", 10); @ 1.4 log @Added RCS Id string to the executable. The temporary file for PGP messages is now deleted every time, a message has been decoded successfully. Otherwise PGP would have decoded the previous message again. @ text @d11 2 a12 2 ** $Revision: 1.3 $ ** $Date: 1993/08/10 02:34:31 $ d25 1 a25 1 ** $Id: PGPRMail.c,v 1.3 1993/08/10 02:34:31 simons Exp simons $ d29 6 d91 1 a91 1 static const char __RCSId[] = "$Id$"; d102 1 a102 1 error("Syntax is incorrect!", 5); d115 1 a115 1 error("Can't open temporary file!", 5); d117 1 a117 1 error("Can't open temporary file!", 5); d119 1 a119 1 error("Can't open temporary file!", 5); d127 2 a128 1 fputc(flag, file); d136 1 a136 4 if ((flag = getline(file, line)) == EOF) { fprintf(pipe1, "%s", line); } else { d138 4 a141 2 fprintf(pipe1, DECRYPT_BEGIN); fprintf(pipe2, "%s", line); d147 2 a148 1 fprintf(pipe2, "%s", line); d167 2 a168 1 fprintf(pipe2, "%s", line); d186 2 a187 1 fprintf(pipe1, DECRYPT_END); d190 2 a191 1 fprintf(pipe1, "%s", line); d214 1 a214 1 system(line); d219 1 a219 1 system(line); d228 1 a228 1 return 0; d255 6 a260 1 error("Buffer overflow!", 5); a266 4 if (c == EOF) { *(buffer-1) = '\0'; return EOF; } @ 1.3 log @Changed filename to PGPRMail. Replaced all pipes with 'ordinary' temporary files. This should increase the programs security and make it easier for me to handle errors. Added several error messages and security checks. PGPRMail recognizes damaged PGP message blocks. PGPRMail recognizes errorcodes returned by PGP. @ text @d11 2 a12 2 ** $Revision: 1.2 $ ** $Date: 1993/08/10 00:10:28 $ d25 1 a25 1 ** $Id: PGPrmail.c,v 1.2 1993/08/10 00:10:28 simons Exp simons $ d28 9 a36 1 ** $Log: PGPrmail.c,v $ d85 2 d169 1 d172 5 a176 1 if ((pipe2 = fopen(PIPE2, "a")) == NULL) @ 1.2 log @The program works just fine, but I do a minimum of error-checking. This is dangerous and may cause data loss in the current revision. @ text @d11 2 a12 2 ** $Revision: 1.1 $ ** $Date: 1993/08/09 22:33:14 $ d25 1 a25 1 ** $Id: PGPrmail.c,v 1.1 1993/08/09 22:33:14 simons Exp simons $ d29 4 a34 1 ** d53 2 a60 3 #define PIPE1 "PIPE:PGPRMail1" #define PIPE2 "PIPE:PGPRMail2" d66 1 a66 1 int getline(char buffer[]); d77 11 a87 3 FILE *pipe1, *pipe2; int flag = 0; char *line; d89 9 a97 2 if ((line = malloc(LINEBUFFER)) == NULL) error("Can't allocate my textbuffer!", 5); d99 1 a99 1 error("Can't open my pipe!", 5); d101 14 a114 1 error("Can't open my pipe!", 5); d116 2 d119 1 a119 1 if ((flag = getline(line)) == EOF) { d126 4 a129 1 getline(line); d132 4 a135 1 getline(line); d137 13 d153 6 a158 3 fclose(pipe1); fclose(pipe2); system(line); d160 1 a160 1 error("Can't open my pipe!", 5); d162 1 a162 1 error("Can't open my pipe!", 5); d170 2 a171 1 fprintf(stderr, "rmail starten\n"); d175 28 d219 1 a219 1 int getline(char *buffer) d224 1 a224 1 c = getchar(); @ 1.1 log @Initial revision @ text @d11 2 a12 2 ** $Revision: 0.2 $ ** $Date: 1993/07/30 16:07:58 $ d25 1 a25 1 ** $Id$ d28 3 a30 1 ** $Log$ d49 1 a49 1 #define PGP "PGP -f <%s >%s +BATCH" d53 3 d59 2 d63 1 a63 1 void error(char *); d75 1 a75 1 FILE *pipe1, pipe2; d77 1 d79 36 d116 4 d130 1 a130 1 void error(char *message) d133 25 @