home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Extra 1997 #5 / AmigaPlus_Extra-CD_5-97.iso / online-tools / mail / pgp_mip / pgpsendmail / source / rcs / pgpsendmail.c,v < prev    next >
Encoding:
Text File  |  1993-10-12  |  49.8 KB  |  1,871 lines

  1. head    1.28;
  2. access;
  3. symbols;
  4. locks
  5.     simons:1.28; strict;
  6. comment    @ * @;
  7.  
  8.  
  9. 1.28
  10. date    93.10.12.13.02.36;    author simons;    state Exp;
  11. branches;
  12. next    1.27;
  13.  
  14. 1.27
  15. date    93.10.06.12.42.50;    author simons;    state Exp;
  16. branches;
  17. next    1.26;
  18.  
  19. 1.26
  20. date    93.10.06.12.19.18;    author simons;    state Exp;
  21. branches;
  22. next    1.25;
  23.  
  24. 1.25
  25. date    93.09.25.02.37.43;    author simons;    state Stab;
  26. branches;
  27. next    1.24;
  28.  
  29. 1.24
  30. date    93.09.24.22.53.41;    author simons;    state Stab;
  31. branches;
  32. next    1.23;
  33.  
  34. 1.23
  35. date    93.09.14.22.06.02;    author simons;    state Stab;
  36. branches;
  37. next    1.22;
  38.  
  39. 1.22
  40. date    93.09.14.17.28.15;    author simons;    state Exp;
  41. branches;
  42. next    1.21;
  43.  
  44. 1.21
  45. date    93.09.13.17.29.49;    author simons;    state Exp;
  46. branches;
  47. next    1.20;
  48.  
  49. 1.20
  50. date    93.09.08.23.08.16;    author simons;    state Exp;
  51. branches;
  52. next    1.19;
  53.  
  54. 1.19
  55. date    93.09.08.23.03.48;    author simons;    state Exp;
  56. branches;
  57. next    1.18;
  58.  
  59. 1.18
  60. date    93.09.04.15.32.26;    author simons;    state Stab;
  61. branches;
  62. next    1.17;
  63.  
  64. 1.17
  65. date    93.09.03.14.35.08;    author simons;    state Stab;
  66. branches;
  67. next    1.16;
  68.  
  69. 1.16
  70. date    93.09.03.02.05.51;    author simons;    state Exp;
  71. branches;
  72. next    1.15;
  73.  
  74. 1.15
  75. date    93.09.03.01.33.35;    author simons;    state Exp;
  76. branches;
  77. next    1.14;
  78.  
  79. 1.14
  80. date    93.08.28.18.45.46;    author simons;    state Stab;
  81. branches;
  82. next    1.13;
  83.  
  84. 1.13
  85. date    93.08.28.17.59.56;    author simons;    state Stab;
  86. branches;
  87. next    1.12;
  88.  
  89. 1.12
  90. date    93.08.23.15.48.02;    author simons;    state Exp;
  91. branches;
  92. next    1.11;
  93.  
  94. 1.11
  95. date    93.08.23.15.21.19;    author simons;    state Exp;
  96. branches;
  97. next    1.10;
  98.  
  99. 1.10
  100. date    93.08.23.13.47.36;    author simons;    state Exp;
  101. branches;
  102. next    1.9;
  103.  
  104. 1.9
  105. date    93.08.23.13.12.32;    author simons;    state Exp;
  106. branches;
  107. next    1.8;
  108.  
  109. 1.8
  110. date    93.08.23.13.05.01;    author simons;    state Exp;
  111. branches;
  112. next    1.7;
  113.  
  114. 1.7
  115. date    93.08.22.17.53.02;    author simons;    state Stab;
  116. branches;
  117. next    1.6;
  118.  
  119. 1.6
  120. date    93.08.22.17.48.33;    author simons;    state Stab;
  121. branches;
  122. next    1.5;
  123.  
  124. 1.5
  125. date    93.08.22.17.46.12;    author simons;    state Stab;
  126. branches;
  127. next    1.4;
  128.  
  129. 1.4
  130. date    93.08.22.17.38.34;    author simons;    state stab;
  131. branches;
  132. next    1.3;
  133.  
  134. 1.3
  135. date    93.08.22.17.12.11;    author simons;    state Stab;
  136. branches;
  137. next    1.2;
  138.  
  139. 1.2
  140. date    93.08.21.19.32.47;    author simons;    state Exp;
  141. branches;
  142. next    1.1;
  143.  
  144. 1.1
  145. date    93.08.21.19.28.43;    author simons;    state Exp;
  146. branches;
  147. next    ;
  148.  
  149.  
  150. desc
  151. @This is a replacement for the UUCP command >sendmail<.
  152. PGPSendMail reads the incoming message from standard input,
  153. checks if a key for the receipients is availabe and if, sends
  154. the encrypted messagt to the original sendmail for handling.
  155. @
  156.  
  157.  
  158. 1.28
  159. log
  160. @The confirmation of encryption can now be controlled by the
  161. ConfirmEncryption keyword in the uulib:config file.
  162. @
  163. text
  164. @/*
  165.  *     $Filename: PGPSendMail.c $
  166.  *     $Revision: 1.27 $
  167.  *     $Date: 1993/10/06 12:42:50 $
  168.  *
  169.  *     This is a replacement for the UUCP command >sendmail<.
  170.  *     PGPSendMail reads the incoming message from standard input,
  171.  *     checks if a key for the receipients is availabe and if, sends
  172.  *     the encrypted messagt to the original sendmail for handling.
  173.  *
  174.  *     © Copyright 1993 Peter Simons, Germany
  175.  *       All Rights Reserved
  176.  *
  177.  *     $Id: PGPSendMail.c,v 1.27 1993/10/06 12:42:50 simons Exp simons $
  178.  *
  179.  * ------------------------------ log history ----------------------------
  180.  * $Log: PGPSendMail.c,v $
  181.  * Revision 1.27  1993/10/06  12:42:50  simons
  182.  * The name of the program handling the mail after encryption is now
  183.  * determined using the config-file or the appropiate env/local variable.
  184.  *
  185.  * Revision 1.25  1993/09/25  02:37:43  simons
  186.  * PGPSendMail terminates immediatly, when OS 2.04 is not available.
  187.  *
  188.  * Revision 1.24  1993/09/24  22:53:41  simons
  189.  * Moved TruncFile() to system.c.
  190.  * Added call to ConfirmEncryption(), to let the user decide if the mail
  191.  * should be encrypted or not.
  192.  *
  193.  * Revision 1.23  1993/09/14  22:06:02  simons
  194.  * Thanks to my own cres.o and _main() routine, the commandline is now
  195.  * provided to sendmail correctly.
  196.  *
  197.  * Revision 1.22  1993/09/14  17:28:15  simons
  198.  * Changed code to work with the new startup-main().
  199.  *
  200.  * Revision 1.21  1993/09/13  17:29:49  simons
  201.  * Minor optimizations in logfile handling.
  202.  *
  203.  * Revision 1.20  1993/09/08  23:08:16  simons
  204.  * The log message "Not all receipients have..." is not debug level 1.
  205.  *
  206.  * Revision 1.19  1993/09/08  23:03:48  simons
  207.  * FindKey() now calls a self-written routine stristr() instead of
  208.  * strstr(), because the latter routine compared the strings case-
  209.  * significant.
  210.  *
  211.  * Revision 1.18  1993/09/04  15:32:26  simons
  212.  * Corrected a few typing mistakes.
  213.  *
  214.  * Revision 1.17  1993/09/03  14:35:08  simons
  215.  * Added configfile support. Used keywords are UULib, Debug and LockDir.
  216.  * LogLevel is controlled by the configfile. Default is 0.
  217.  * Added various debug-messages.
  218.  *
  219.  * Revision 1.16  1993/09/03  02:05:51  simons
  220.  * Changed style of log-messages to fit better with the uucp package.
  221.  * Added a few log-messages.
  222.  * Set the debug value to 255 per default. Future versions might use an
  223.  * entry in a configfile.
  224.  *
  225.  * Revision 1.15  1993/09/03  01:33:35  simons
  226.  * Added logfile support.
  227.  * Straightened code concerning Amiga specific includes.
  228.  *
  229.  * Revision 1.14  1993/08/28  18:45:46  simons
  230.  * Added alias-expansion support.
  231.  *
  232.  * Revision 1.13  1993/08/28  17:59:56  simons
  233.  * PGPSendMail does not support the 'Bcc:'-line.
  234.  *
  235.  * Revision 1.12  1993/08/23  15:48:02  simons
  236.  * Removed bug in ArrayToLine(): The contents of argvline had been trashed!
  237.  * Removed some debugging output, as the routines are save now.
  238.  *
  239.  * Revision 1.11  1993/08/23  15:21:19  simons
  240.  * Added a kludge to let PGPSendMail understand PGP-key-aliases. FindKey()
  241.  * now searches for "pub " or "pub ". This may break with other versions
  242.  * of PGP or on other systems. However, it works fine. :-)
  243.  * Reduced the required amount of stack from 8k+ to less than 1200 byte.
  244.  *
  245.  * Revision 1.10  1993/08/23  13:47:36  simons
  246.  * PGPSendMail now perfectly understands multiple line headers.
  247.  *
  248.  * Revision 1.9  1993/08/23  13:12:32  simons
  249.  * Moved "PGPKey.lst"-file to "UULIB:".
  250.  * Known bugs: - PGP aliases are not recognized! If someone has generated
  251.  *               his key with another address than usenet, and created
  252.  *               an alias later, he will not be found in the keyfile,
  253.  *               because FindKey() only test lines beginning with "pub".
  254.  *
  255.  * Revision 1.8  1993/08/23  13:05:01  simons
  256.  * PGPSendMail now checks wether a public key for each receipient is
  257.  * available and sends the message unencrypted if not.
  258.  * The commandline is now preserved, even under error-condition.
  259.  * Known Bugs: - If the "To:" and "Cc:" lines are split over several
  260.  *               lines, SplitAddresses() won't recognize them correctly.
  261.  *
  262.  * Revision 1.7  1993/08/22  17:53:02  simons
  263.  * Known bugs: - If sendmail is called under an error-condition, the
  264.  *               original commandline is lost. Will be fixed soon.
  265.  *
  266.  * Revision 1.6  1993/08/22  17:48:33  simons
  267.  * Changed a few situations from fatal to non-fatal errors.
  268.  *
  269.  * Revision 1.5  1993/08/22  17:46:12  simons
  270.  * Error conditions are handled much better. If anything goes wrong, the
  271.  * original mail is sent to sendmail instead of the failed encrypted
  272.  * version.
  273.  *
  274.  * Revision 1.4  1993/08/22  17:38:34  simons
  275.  * PGPSendMail now calls sendmail with exactly the same parameters he
  276.  * has been called with.
  277.  * Known bugs: - currently does not correct the "Lines:" keyword
  278.  *
  279.  * Revision 1.3  1993/08/22  17:12:11  simons
  280.  * PGPSendMail works basically.
  281.  * Known bugs: - Aliases aren't expanded before PGPSendMail tries to
  282.  *               determine the receipient. Hence the addresses won't be
  283.  *               found in the keyring.
  284.  *             - When sending (and encrypting) mail for multiple
  285.  *               receipients, PGP does not return any warning if one of
  286.  *               the receipients has no public key available, is just
  287.  *               skips him. Though you should only use PGPSendmail with
  288.  *               receipients having a key available. I'll try to modify
  289.  *
  290.  * Revision 1.2  1993/08/21  19:32:47  simons
  291.  * The UUCP-message stuff is already working. I wrote a set of routines,
  292.  * that seperate the receipients of a message out of the header and
  293.  * skip anything but the address of them.
  294.  * Using the address for identifying the user seems to be more reliable
  295.  * than trying to get the realname.
  296.  * At the moment I have to use unbuffered IO, because I have to reset
  297.  * the position in the readfile several times, what is not supported
  298.  * with my routines yet.
  299.  *
  300.  * Revision 1.1  1993/08/21  19:28:43  simons
  301.  * Initial revision
  302.  */
  303.  
  304.  
  305.  
  306. /**************************************************************************
  307.  *                                                                        *
  308.  * Sektion: Macros, Definitions, Includes, Structures                     *
  309.  *                                                                        *
  310.  **************************************************************************/
  311.  
  312. /************************************* Includes ***********/
  313. #include <stdio.h>
  314. #include <stdlib.h>
  315. #include <fcntl.h>
  316. #include <string.h>
  317. #include <ctype.h>
  318.  
  319. #include <proto/dos.h>
  320. #include <exec/execbase.h>
  321. #include <dos/dos.h>
  322.  
  323. #include "expandalias.h"
  324. #include "SC:Sources/uucp.lib/include/config.h"
  325. #include "SC:Sources/uucp.lib/include/log.h"
  326.  
  327. /************************************* Defines ************/
  328. #define PGP             "PGP -fesa <%s >%s %s +batchmode"
  329. #define START_SENDMAIL  "%s <%s %s"
  330. #define PGPKEYLIST      "PGPKeys.lst"
  331.  
  332. #define HEADER_ID       "X-AutoEncrypt: PGPSendMail 1.x\n"
  333. #define BODY_ID         "Automatically encrypted message-body follows:\n\n"
  334.  
  335. #define MAX_RECEIPIENTS 256             /* max. number of receipients */
  336. #define LINEBUFFER      1024            /* max. line length */
  337. #define IOBUFSIZE       BUFSIZ*10       /* size of internal IO buffer */
  338.  
  339. #define CONFIRMENCRYPTION       "ConfirmEncryption"
  340.  
  341. #define my_ulog(level, name, msg) OpenLog(); ulog(level, name, msg); CloseLog();
  342. #define my_ulog2(level, msg) OpenLog(); ulog(level, msg); CloseLog();
  343.  
  344. /************************************* Prototypes *********/
  345. void NonFatalError(char *);
  346. void error(char *, int);
  347. int getline(FILE *,char []);
  348. int CopyUntilEOF(FILE *, FILE *);
  349. char **FindReceipients(FILE *);
  350. char *FindHeaderEntry(FILE *, char *);
  351. void ParseAddressLines(char **receipients);
  352. void SplitAddressLine(char *line, char *receipients[]);
  353. int TruncFile(char *, int);
  354. char *ArrayToLine(char *array[]);
  355. int FindKey(char *key, char *keylist);
  356. int CheckKeyAvailability(char *receipients[]);
  357. char *stristr(char *, char *);
  358. int ConfirmEncryption(void);
  359.  
  360. /************************************* global Variables ***/
  361. FILE *pipe1 = NULL, *pipe2 = NULL, *file = NULL;
  362. char PIPE1[L_tmpnam], PIPE2[L_tmpnam], FILENAME[L_tmpnam];
  363. char *argvline, *cmdbuf;
  364.  
  365. static const char __RCSId[] = "$Id: PGPSendMail.c,v 1.27 1993/10/06 12:42:50 simons Exp simons $";
  366.  
  367. /**************************************************************************
  368.  *                                                                        *
  369.  * Sektion: Hauptprogramm                                                 *
  370.  *                                                                        *
  371.  **************************************************************************/
  372.  
  373. int main(char *argv)
  374. {
  375.         extern struct ExecBase *SysBase;
  376.         char **receipients, *dummy;
  377.         int body_pos;
  378.  
  379.         if (SysBase->LibNode.lib_Version < 37)
  380.                 error("Kickstart 2.04 or later is required!", 20);
  381.  
  382.         if((cmdbuf = malloc(LINEBUFFER*4)) == NULL)
  383.                 error("Couldn't allocate my buffer!", 10);
  384.  
  385.  
  386.         /* Determine loglevel. */
  387.  
  388.         if ((dummy = FindConfig(DEBUGNAME)) == NULL)
  389.                 LogLevel = 0;
  390.         else
  391.                 LogLevel = atoi(dummy);
  392.  
  393.  
  394.         /*
  395.          * Copy the passed arguments into an global Variable, so
  396.          * NonFatalError() can access them.
  397.          */
  398.  
  399.         argvline = argv;
  400.  
  401.  
  402.         /*
  403.          * Make unique filenames for the temporary files
  404.          * and open them.
  405.          */
  406.  
  407.         tmpnam(PIPE1);
  408.         tmpnam(PIPE2);
  409.         tmpnam(FILENAME);
  410.  
  411.         if ((file = fopen(FILENAME, "w+")) == NULL)
  412.                 error("Can't open temporary file!", 10);
  413.  
  414.  
  415.         /*
  416.          * Copy standard input to a temporary file for security reasons.
  417.          */
  418.  
  419.         if (CopyUntilEOF(stdin, file) == 0)
  420.                 error("Can't write to my temporary file!", 10);
  421.         my_ulog(2, "PGPSendMail, original mail in '%s'", FILENAME);
  422.  
  423.  
  424.         /* Find receipients to determine who to encrypt to. */
  425.  
  426.         receipients = FindReceipients(file);
  427.         if (receipients == NULL || *receipients == NULL)
  428.                 NonFatalError("Can't determine receipient of message");
  429.         else
  430.                 my_ulog(2, "PGPSendMail, receipients (with aliases): %s", ArrayToLine(receipients));
  431.  
  432.         receipients = ExpandAliases(receipients);
  433.         if (receipients == NULL || *receipients == NULL)
  434.                 NonFatalError("Can't determine receipient of message");
  435.         else
  436.                 my_ulog(2, "PGPSendMail, receipients (aliases expanded): %s", ArrayToLine(receipients));
  437.  
  438.         if ((CheckKeyAvailability(receipients)) == 0) {
  439.                 my_ulog2(1, "Not all receipients have a valid public key");
  440.                 NonFatalError("");
  441.         }
  442.  
  443.         if ( !(dummy = FindConfig(CONFIRMENCRYPTION)) || *dummy == 'y' || *dummy == 'Y' ) {
  444.                 if (!(ConfirmEncryption()))
  445.                         NonFatalError("Encryption denied by user");
  446.         }
  447.  
  448.  
  449.         /* Copy messagebody for encryption. */
  450.  
  451.         fseek(file, 0L, SEEK_SET);
  452.         fflush(file);
  453.  
  454.         while((body_pos = getline(file, cmdbuf)) > 1)
  455.                 ;
  456.         body_pos = ftell(file);
  457.  
  458.         if ((pipe1 = fopen(PIPE1, "w")) == NULL)
  459.                 NonFatalError("Can't open temporary file!");
  460.         if (CopyUntilEOF(file, pipe1) == 0)
  461.                 NonFatalError("Can't write to my temporary file!");
  462.         my_ulog(2, "PGPSendMail, copied message-body to '%s' for encryption", PIPE1);
  463.  
  464.  
  465.         /* Encrypt message body. */
  466.  
  467.         sprintf(cmdbuf, PGP, PIPE1, PIPE2, ArrayToLine(receipients));
  468.         my_ulog(1, "PGPSendMail, starting `%s'", cmdbuf);
  469.         fprintf(stderr, "%s\n", cmdbuf);
  470.         fclose(pipe1); pipe1 = NULL;
  471.         if (system(cmdbuf) != 0)
  472.                 NonFatalError("PGP failed somehow");
  473.         remove(PIPE1);  /* Free some memory up. */
  474.  
  475.  
  476.         /* Insert encrytpted message instead of text-body */
  477.  
  478.         if ((pipe2 = fopen(PIPE2, "r")) == NULL)
  479.                 NonFatalError("Can't open temporary file!");
  480.         my_ulog(2, "PGPSendMail, copying modified mail to '%s'", FILENAME);
  481.         fseek(file, body_pos, SEEK_SET);
  482.         fflush(file);
  483.         fprintf(file, BODY_ID);
  484.         fflush(file);
  485.         if (CopyUntilEOF(pipe2, file) == 0)
  486.                 error("Can't write to my temporary file!", 10);
  487.         body_pos = ftell(file);
  488.  
  489.         fclose(pipe2); pipe2 = NULL; remove(PIPE2);
  490.         fclose(file); file = NULL;      /* Free up some memory. */
  491.  
  492.         if (TruncFile(FILENAME, body_pos) == 0)
  493.                 error("Truncating the original failed.", 10);
  494.         my_ulog(-1, "PGPSendMail, succesfully encrypted a mail for %s", ArrayToLine(receipients));
  495.  
  496.  
  497.         /* Call SendMail to handle the message. */
  498.  
  499.         sprintf(cmdbuf, START_SENDMAIL, GetConfigProgram(SENDMAIL), FILENAME, argvline);
  500.         my_ulog(2, "PGPSendMail, starting '%s'", cmdbuf);
  501.         body_pos = system(cmdbuf);
  502.  
  503.  
  504.         /* Delete temporary files and leave. */
  505.  
  506.         remove(FILENAME);
  507.         return body_pos;        /* Return the code, given by sendmail. */
  508. }
  509.  
  510.  
  511. /**************************************************************************
  512.  *                                                                        *
  513.  *                              Unterprogramme                            *
  514.  *                                                                        *
  515.  **************************************************************************/
  516.  
  517. void NonFatalError(char *message)
  518. {
  519.         if (strlen(message) > 0) {
  520.                 my_ulog(-1, "PGPSendMail, %s", message);
  521.                 fprintf(stderr, "PGPSendMail: %s\n", message);
  522.         }
  523.  
  524.         fclose(pipe1); remove(PIPE1);
  525.         fclose(pipe2); remove(PIPE2);
  526.         fclose(file);
  527.  
  528.         sprintf(cmdbuf, START_SENDMAIL, GetConfigProgram(SENDMAIL), FILENAME, argvline);
  529.         my_ulog(2, "PGPSendMail, starting '%s'", cmdbuf);
  530.         system(cmdbuf);
  531.  
  532.         remove(FILENAME);
  533.         exit(0);
  534. }
  535.  
  536. void error(char *message, int errorcode)
  537. {
  538.         my_ulog(-1, "PGPSendMail, %s", message);
  539.         fprintf(stderr, "PGPSendMail: %s\n", message);
  540.         exit(errorcode);
  541. }
  542.  
  543. int getline(FILE *file, char *buffer)
  544. {
  545.         int c, i = 0;
  546.  
  547.         do {
  548.                 c = fgetc(file);
  549.                 *buffer = c;
  550.                 i++; buffer++;
  551.         } while (i < LINEBUFFER && c != EOF && c != '\n');
  552.  
  553.         if (i >= LINEBUFFER)
  554.                 error("Buffer overflow!", 10);
  555.  
  556.         if (c == EOF && i == 1) {
  557.                 *(buffer-1) = '\0';
  558.                 return EOF;
  559.         }
  560.  
  561.         if (c == '\n') {
  562.                 *buffer = '\0';
  563.                 return i;
  564.         }
  565.  
  566. }
  567.  
  568.  
  569. int CopyUntilEOF(FILE *in, FILE *out)
  570. {
  571.         char *buffer;
  572.         int len;
  573.  
  574.         if ((buffer = malloc(IOBUFSIZE)) == NULL)
  575.                 return 0;
  576.  
  577.         if (in != stdin)
  578.                 lseek(fileno(in), ftell(in), 0);
  579.         if (out != stdout)
  580.                 lseek(fileno(out), ftell(out), 0);
  581.  
  582.         while ((len = read(fileno(in), buffer, IOBUFSIZE)) > 0)
  583.                 if (write(fileno(out), buffer, len) == -1) {
  584.                         free(buffer);
  585.                         return 0;
  586.                 }
  587.  
  588.         free(buffer);
  589.         return 1;
  590. }
  591.  
  592. char **FindReceipients(FILE *fh)
  593. {
  594.         char **receipients, *line;
  595.  
  596.         if ((receipients = malloc(sizeof(char *[MAX_RECEIPIENTS]))) == NULL)
  597.                 NonFatalError("Couldn't allocate my buffer!");
  598.         *receipients = NULL;
  599.  
  600.         if ((line = FindHeaderEntry(fh, "To: ")) != NULL)
  601.                 SplitAddressLine(line, receipients);
  602.         if ((line = FindHeaderEntry(fh, "Cc: ")) != NULL)
  603.                 SplitAddressLine(line, receipients);
  604.         ParseAddressLines(receipients);
  605.  
  606.         return receipients;
  607. }
  608.  
  609. char *FindHeaderEntry(FILE *fh, char *entry)
  610. {
  611.         char *line, *line_tmp;
  612.         int len;
  613.  
  614.         if ((line = malloc(LINEBUFFER*4)) == NULL)
  615.                 return NULL;
  616.         fflush(file);
  617.         len = fseek(fh, 0L, SEEK_SET);
  618.  
  619.         len = getline(fh, line);
  620.         while (len != 1 && len != EOF) {
  621.                 if (!strnicmp(line, entry, strlen(entry))) {
  622.                         line_tmp = line;
  623.  
  624.                         /*
  625.                          * If the last character in the line is a ',',
  626.                          * change the '\n' to ' ' and append the next
  627.                          * line.
  628.                          */
  629.  
  630.                         do {
  631.                                 line_tmp = line_tmp+len-2;
  632.                                 while (isspace(*line_tmp))
  633.                                         line_tmp--;
  634.                                 if (*line_tmp == ',') {
  635.                                         *(line_tmp+1) = ' ';
  636.                                         line_tmp += 2;
  637.                                         len = getline(fh, line_tmp);
  638.                                 }
  639.                                 else
  640.                                         return &line[strlen(entry)];
  641.                         } while (1);            /* Forever! */
  642.                 }
  643.                 len = getline(fh, line);
  644.         }
  645.         free(line);
  646.         return NULL;
  647. }
  648.  
  649. void SplitAddressLine(char *line, char *receipients[])
  650. {
  651.         int brackets, i;
  652.  
  653.         if (line == NULL || receipients == NULL)
  654.                 return;
  655.  
  656.         while (*receipients != NULL)
  657.                 receipients++;
  658.  
  659.         *receipients++ = line;
  660.  
  661.         for (i = 0, brackets = 0; line[i] != '\n'; i++) {
  662.                 if (line[i] == '(' && (i == 0 || isspace(line[i-1])))
  663.                         brackets = 1;
  664.                 if (line[i] == ')' && (line[i+1] == ',' || line[i+1] == '\n' || isspace(line[i+1])))
  665.                         brackets = 0;
  666.                 if (line[i] == ',' && brackets == 0) {
  667.                         line[i++] = '\0';
  668.                         while (isspace(line[i]))
  669.                                 i++;
  670.                         *receipients++ = &line[i];
  671.                 }
  672.         }
  673.         line[i] = '\0';
  674.         *receipients = NULL;
  675. }
  676.  
  677.  
  678. void ParseAddressLines(char **receipients)
  679. {
  680.         char line[LINEBUFFER];
  681.         int brackets, i, z;
  682.  
  683.         while (*receipients != NULL) {
  684.                 strcpy(line, *receipients);
  685.                 for (i = 0, z = 0, brackets = 0; line[i] != '\0'; i++) {
  686.                         if (line[i] == '(' && (i == 0 || isspace(line[i-1])))
  687.                                 brackets++;
  688.                         if (line[i] == ')' && (line[i+1] == '\0' || isspace(line[i+1])))
  689.                                 brackets--;
  690.                         if (line[i] == '<' && brackets == 0) {
  691.                                 i++;
  692.                                 while (1) {             /* Forever! */
  693.                                         if (line[i] == '>' && (line[i+1] == '\0' || isspace(line[i+1])))
  694.                                                 break;
  695.                                         (*receipients)[z++] = line[i++];
  696.                                 }
  697.                                 (*receipients)[z] = '\0';
  698.                                 break;
  699.                         }
  700.                 }
  701.                 if (z == 0) {   /* No <address> occured. */
  702.                         i = 0;
  703.                         while (!isspace((*receipients)[i]))
  704.                                 i++;
  705.                         (*receipients)[i] = '\0';
  706.                 }
  707.                 receipients++;
  708.         }
  709. }
  710.  
  711.  
  712. char *ArrayToLine(char *array[])
  713. {
  714.         char *line;
  715.  
  716.         if ((line = malloc(LINEBUFFER)) == NULL)
  717.                 return NULL;
  718.         line[0] = '\0';
  719.  
  720.         while (*array != NULL) {
  721.                 strcat(line, *array);
  722.                 strcat(line, " ");
  723.                 array++;
  724.         }
  725.         return line;
  726. }
  727.  
  728. int CheckKeyAvailability(char *receipients[])
  729. {
  730.         FILE *fh;
  731.         char *keylist, *filename;
  732.         int filelength;
  733.  
  734.         if (*receipients == NULL)
  735.                 return 0;               /* No receipient found! */
  736.  
  737.         filename = MakeConfigPath(UULIB, PGPKEYLIST);
  738.         LockFile(filename);
  739.  
  740.         if ((fh = fopen(filename, "r")) == NULL) {
  741.                 UnLockFile(filename);
  742.                 return 0;               /* Couldn't open keylist! */
  743.         }
  744.         fseek(fh, 0L, SEEK_END); filelength = ftell(fh);
  745.                                         /* Determine filelength. */
  746.  
  747.  
  748.         /* Allocate buffer and read keylist. */
  749.  
  750.         if (keylist = malloc(filelength+1)) {
  751.                 lseek(fileno(fh), 0, 0);
  752.                 if ((read(fileno(fh), keylist, filelength)) == -1) {
  753.                         fclose(fh);     /* Couldn't read keylist. */
  754.                         UnLockFile(filename);
  755.                         free(keylist);
  756.                         return 0;
  757.                 }
  758.                 else {          /* Read went fine. */
  759.                         fclose(fh);
  760.                         UnLockFile(filename);
  761.                         keylist[filelength] = '\0';
  762.  
  763.                         while (*receipients != NULL) {
  764.                                 if (FindKey(*receipients, keylist) == 0) {
  765.                                         free(keylist);
  766.                                         my_ulog(1, "PGPSendMail, No key available for <%s>", *receipients);
  767.                                         return 0;       /* Key is not in keylist. */
  768.                                 }
  769.                                 receipients++;
  770.                         }
  771.                 }
  772.         }
  773.         free(keylist);
  774.         return 1;                       /* Everything is fine. */
  775. }
  776.  
  777. int FindKey(char *key, char *keylist)
  778. {
  779.         char line[LINEBUFFER];
  780.         int i;
  781.  
  782.         while (*keylist != '\0') {
  783.  
  784.                 /* Is this a valid key-line? */
  785.  
  786.                 if (!strnicmp(keylist, "pub ", strlen("pub "))
  787.                         || !strnicmp(keylist, "    ", strlen("    ")))
  788.                 {
  789.                         for(i = 0; keylist[i] != '\n'; i++)
  790.                                 line[i] = keylist[i];
  791.                         line[i] = '\0';
  792.                         if (stristr(line, key))
  793.                                 return 1;
  794.                 }
  795.  
  796.  
  797.                 /* Find end of line or end of buffer. */
  798.  
  799.                 while (*keylist != '\n' && *keylist != '\0')
  800.                         keylist++;
  801.                 keylist++;
  802.         }
  803.         return 0;
  804. }
  805.  
  806. char *stristr(char *line, char *key)
  807. {
  808.         int i, cmplen = strlen(key), end = strlen(line)-cmplen;
  809.  
  810.         for (i = 0; i <= end; i++)
  811.                 if (strnicmp(&line[i], key, cmplen) == NULL)
  812.                         return &line[i];
  813.         return NULL;
  814. }
  815.  
  816. @
  817.  
  818.  
  819. 1.27
  820. log
  821. @The name of the program handling the mail after encryption is now
  822. determined using the config-file or the appropiate env/local variable.
  823. @
  824. text
  825. @d3 2
  826. a4 2
  827.  *     $Revision: 1.25 $
  828.  *     $Date: 1993/09/25 02:37:43 $
  829. d14 1
  830. a14 1
  831.  *     $Id: PGPSendMail.c,v 1.25 1993/09/25 02:37:43 simons Stab simons $
  832. d18 4
  833. d176 2
  834. d202 1
  835. a202 1
  836. static const char __RCSId[] = "$Id: PGPSendMail.c,v 1.25 1993/09/25 02:37:43 simons Stab simons $";
  837. d213 1
  838. a213 2
  839.         char **receipients;
  840.         char *debuglevel;
  841. d225 1
  842. a225 1
  843.         if ((debuglevel = FindConfig(DEBUGNAME)) == NULL)
  844. d228 1
  845. a228 1
  846.                 LogLevel = atoi(debuglevel);
  847. d280 5
  848. a284 2
  849.         if (!(ConfirmEncryption()))
  850.                 NonFatalError("Encryption denied by user");
  851. @
  852.  
  853.  
  854. 1.26
  855. log
  856. @Changed format of RCS-Header.
  857. @
  858. text
  859. @d162 1
  860. a162 1
  861. #define START_SENDMAIL  "sendmail <%s %s"
  862. d328 1
  863. a328 1
  864.         sprintf(cmdbuf, START_SENDMAIL, FILENAME, argvline);
  865. d357 1
  866. a357 1
  867.         sprintf(cmdbuf, START_SENDMAIL, FILENAME, argvline);
  868. @
  869.  
  870.  
  871. 1.25
  872. log
  873. @PGPSendMail terminates immediatly, when OS 2.04 is not available.
  874. @
  875. text
  876. @d1 135
  877. a135 132
  878. /**
  879.  **     $Filename: PGPSendMail.c $
  880.  **     $Revision: 1.24 $
  881.  **     $Date: 1993/09/24 22:53:41 $
  882.  **
  883.  **     This is a replacement for the UUCP command >sendmail<.
  884.  **     PGPSendMail reads the incoming message from standard input,
  885.  **     checks if a key for the receipients is availabe and if, sends
  886.  **     the encrypted messagt to the original sendmail for handling.
  887.  **
  888.  **     © Copyright 1993 Peter Simons, Germany
  889.  **       All Rights Reserved
  890.  **
  891.  **     $Id: PGPSendMail.c,v 1.24 1993/09/24 22:53:41 simons Stab simons $
  892.  **
  893.  ** ------------------------------ log history ----------------------------
  894.  ** $Log: PGPSendMail.c,v $
  895.  ** Revision 1.24  1993/09/24  22:53:41  simons
  896.  ** Moved TruncFile() to system.c.
  897.  ** Added call to ConfirmEncryption(), to let the user decide if the mail
  898.  ** should be encrypted or not.
  899.  **
  900.  ** Revision 1.23  1993/09/14  22:06:02  simons
  901.  ** Thanks to my own cres.o and _main() routine, the commandline is now
  902.  ** provided to sendmail correctly.
  903.  **
  904.  ** Revision 1.22  1993/09/14  17:28:15  simons
  905.  ** Changed code to work with the new startup-main().
  906.  **
  907.  ** Revision 1.21  1993/09/13  17:29:49  simons
  908.  ** Minor optimizations in logfile handling.
  909.  **
  910.  ** Revision 1.20  1993/09/08  23:08:16  simons
  911.  ** The log message "Not all receipients have..." is not debug level 1.
  912.  **
  913.  ** Revision 1.19  1993/09/08  23:03:48  simons
  914.  ** FindKey() now calls a self-written routine stristr() instead of
  915.  ** strstr(), because the latter routine compared the strings case-
  916.  ** significant.
  917.  **
  918.  ** Revision 1.18  1993/09/04  15:32:26  simons
  919.  ** Corrected a few typing mistakes.
  920.  **
  921.  ** Revision 1.17  1993/09/03  14:35:08  simons
  922.  ** Added configfile support. Used keywords are UULib, Debug and LockDir.
  923.  ** LogLevel is controlled by the configfile. Default is 0.
  924.  ** Added various debug-messages.
  925.  **
  926.  ** Revision 1.16  1993/09/03  02:05:51  simons
  927.  ** Changed style of log-messages to fit better with the uucp package.
  928.  ** Added a few log-messages.
  929.  ** Set the debug value to 255 per default. Future versions might use an
  930.  ** entry in a configfile.
  931.  **
  932.  ** Revision 1.15  1993/09/03  01:33:35  simons
  933.  ** Added logfile support.
  934.  ** Straightened code concerning Amiga specific includes.
  935.  **
  936.  ** Revision 1.14  1993/08/28  18:45:46  simons
  937.  ** Added alias-expansion support.
  938.  **
  939.  ** Revision 1.13  1993/08/28  17:59:56  simons
  940.  ** PGPSendMail does not support the 'Bcc:'-line.
  941.  **
  942.  ** Revision 1.12  1993/08/23  15:48:02  simons
  943.  ** Removed bug in ArrayToLine(): The contents of argvline had been trashed!
  944.  ** Removed some debugging output, as the routines are save now.
  945.  **
  946.  ** Revision 1.11  1993/08/23  15:21:19  simons
  947.  ** Added a kludge to let PGPSendMail understand PGP-key-aliases. FindKey()
  948.  ** now searches for "pub " or "pub ". This may break with other versions
  949.  ** of PGP or on other systems. However, it works fine. :-)
  950.  ** Reduced the required amount of stack from 8k+ to less than 1200 byte.
  951.  **
  952.  ** Revision 1.10  1993/08/23  13:47:36  simons
  953.  ** PGPSendMail now perfectly understands multiple line headers.
  954.  **
  955.  ** Revision 1.9  1993/08/23  13:12:32  simons
  956.  ** Moved "PGPKey.lst"-file to "UULIB:".
  957.  ** Known bugs: - PGP aliases are not recognized! If someone has generated
  958.  **               his key with another address than usenet, and created
  959.  **               an alias later, he will not be found in the keyfile,
  960.  **               because FindKey() only test lines beginning with "pub".
  961.  **
  962.  ** Revision 1.8  1993/08/23  13:05:01  simons
  963.  ** PGPSendMail now checks wether a public key for each receipient is
  964.  ** available and sends the message unencrypted if not.
  965.  ** The commandline is now preserved, even under error-condition.
  966.  ** Known Bugs: - If the "To:" and "Cc:" lines are split over several
  967.  **               lines, SplitAddresses() won't recognize them correctly.
  968.  **
  969.  ** Revision 1.7  1993/08/22  17:53:02  simons
  970.  ** Known bugs: - If sendmail is called under an error-condition, the
  971.  **               original commandline is lost. Will be fixed soon.
  972.  **
  973.  ** Revision 1.6  1993/08/22  17:48:33  simons
  974.  ** Changed a few situations from fatal to non-fatal errors.
  975.  **
  976.  ** Revision 1.5  1993/08/22  17:46:12  simons
  977.  ** Error conditions are handled much better. If anything goes wrong, the
  978.  ** original mail is sent to sendmail instead of the failed encrypted
  979.  ** version.
  980.  **
  981.  ** Revision 1.4  1993/08/22  17:38:34  simons
  982.  ** PGPSendMail now calls sendmail with exactly the same parameters he
  983.  ** has been called with.
  984.  ** Known bugs: - currently does not correct the "Lines:" keyword
  985.  **
  986.  ** Revision 1.3  1993/08/22  17:12:11  simons
  987.  ** PGPSendMail works basically.
  988.  ** Known bugs: - Aliases aren't expanded before PGPSendMail tries to
  989.  **               determine the receipient. Hence the addresses won't be
  990.  **               found in the keyring.
  991.  **             - When sending (and encrypting) mail for multiple
  992.  **               receipients, PGP does not return any warning if one of
  993.  **               the receipients has no public key available, is just
  994.  **               skips him. Though you should only use PGPSendmail with
  995.  **               receipients having a key available. I'll try to modify
  996.  **
  997.  ** Revision 1.2  1993/08/21  19:32:47  simons
  998.  ** The UUCP-message stuff is already working. I wrote a set of routines,
  999.  ** that seperate the receipients of a message out of the header and
  1000.  ** skip anything but the address of them.
  1001.  ** Using the address for identifying the user seems to be more reliable
  1002.  ** than trying to get the realname.
  1003.  ** At the moment I have to use unbuffered IO, because I have to reset
  1004.  ** the position in the readfile several times, what is not supported
  1005.  ** with my routines yet.
  1006.  **
  1007.  ** Revision 1.1  1993/08/21  19:28:43  simons
  1008.  ** Initial revision
  1009.  **/
  1010. d196 1
  1011. a196 1
  1012. static const char __RCSId[] = "$Id: PGPSendMail.c,v 1.24 1993/09/24 22:53:41 simons Stab simons $";
  1013. @
  1014.  
  1015.  
  1016. 1.24
  1017. log
  1018. @Moved TruncFile() to system.c.
  1019. Added call to ConfirmEncryption(), to let the user decide if the mail
  1020. should be encrypted or not.
  1021. @
  1022. text
  1023. @d3 2
  1024. a4 2
  1025.  **     $Revision: 1.23 $
  1026.  **     $Date: 1993/09/14 22:06:02 $
  1027. d14 1
  1028. a14 1
  1029.  **     $Id: PGPSendMail.c,v 1.23 1993/09/14 22:06:02 simons Stab simons $
  1030. d18 5
  1031. d149 2
  1032. d152 1
  1033. a152 1
  1034. #include <proto/dos.h>
  1035. d189 3
  1036. a191 3
  1037.         FILE *pipe1 = NULL, *pipe2 = NULL, *file = NULL;
  1038.         char PIPE1[L_tmpnam], PIPE2[L_tmpnam], FILENAME[L_tmpnam];
  1039.         char *argvline, *cmdbuf;
  1040. d193 1
  1041. a193 1
  1042.         static const char __RCSId[] = "$Id: PGPSendMail.c,v 1.23 1993/09/14 22:06:02 simons Stab simons $";
  1043. d203 1
  1044. d207 3
  1045. @
  1046.  
  1047.  
  1048. 1.23
  1049. log
  1050. @Thanks to my own cres.o and _main() routine, the commandline is now
  1051. provided to sendmail correctly.
  1052. @
  1053. text
  1054. @d3 2
  1055. a4 2
  1056.  **     $Revision: 1.22 $
  1057.  **     $Date: 1993/09/14 17:28:15 $
  1058. d14 1
  1059. a14 1
  1060.  **     $Id: PGPSendMail.c,v 1.22 1993/09/14 17:28:15 simons Exp simons $
  1061. d18 4
  1062. d179 1
  1063. d186 1
  1064. a186 1
  1065.         static const char __RCSId[] = "$Id: PGPSendMail.c,v 1.22 1993/09/14 17:28:15 simons Exp simons $";
  1066. d261 3
  1067. a525 16
  1068.  
  1069. int TruncFile(char *filename, int pos)
  1070.         /*
  1071.          * Function: This routine truncates a file at a given positition.
  1072.          * Comment : AmigaDOS v2.04+ is required.
  1073.          */
  1074. {
  1075.         BPTR fh;
  1076.  
  1077.         if ((fh = Open(FILENAME, MODE_OLDFILE)) == NULL)
  1078.                 return 0;
  1079.  
  1080.         pos = SetFileSize(fh, pos, OFFSET_BEGINNING);
  1081.         Close(fh);
  1082.         return (pos == -1) ? 0 : 1;
  1083. }
  1084. @
  1085.  
  1086.  
  1087. 1.22
  1088. log
  1089. @Changed code to work with the new startup-main().
  1090. @
  1091. text
  1092. @d3 2
  1093. a4 2
  1094.  **     $Revision: 1.21 $
  1095.  **     $Date: 1993/09/13 17:29:49 $
  1096. d14 1
  1097. a14 1
  1098.  **     $Id: PGPSendMail.c,v 1.21 1993/09/13 17:29:49 simons Exp simons $
  1099. d18 3
  1100. d181 1
  1101. a181 1
  1102.         static const char __RCSId[] = "$Id: PGPSendMail.c,v 1.21 1993/09/13 17:29:49 simons Exp simons $";
  1103. @
  1104.  
  1105.  
  1106. 1.21
  1107. log
  1108. @Minor optimizations in logfile handling.
  1109. @
  1110. text
  1111. @d3 2
  1112. a4 2
  1113.  **     $Revision: 1.20 $
  1114.  **     $Date: 1993/09/08 23:08:16 $
  1115. d14 1
  1116. a14 1
  1117.  **     $Id: PGPSendMail.c,v 1.20 1993/09/08 23:08:16 simons Exp simons $
  1118. d18 3
  1119. d178 1
  1120. a178 1
  1121.         static const char __RCSId[] = "$Id: PGPSendMail.c,v 1.20 1993/09/08 23:08:16 simons Exp simons $";
  1122. d186 1
  1123. a186 1
  1124. int main(int argc, char *argv[])
  1125. d209 1
  1126. a209 1
  1127.         argvline = ArrayToLine(&argv[1]);
  1128. @
  1129.  
  1130.  
  1131. 1.20
  1132. log
  1133. @The log message "Not all receipients have..." is not debug level 1.
  1134. @
  1135. text
  1136. @d3 2
  1137. a4 2
  1138.  **     $Revision: 1.19 $
  1139.  **     $Date: 1993/09/08 23:03:48 $
  1140. d14 1
  1141. a14 1
  1142.  **     $Id: PGPSendMail.c,v 1.19 1993/09/08 23:03:48 simons Exp simons $
  1143. d18 3
  1144. d152 2
  1145. a153 1
  1146. #define my_ulog(level, name, msg) OpenLog(); ulog(level, name, msg); CloseLog()
  1147. d175 1
  1148. a175 1
  1149.         static const char __RCSId[] = "$Id: PGPSendMail.c,v 1.19 1993/09/08 23:03:48 simons Exp simons $";
  1150. d246 1
  1151. a246 3
  1152.                 OpenLog();
  1153.                 ulog(1, "Not all receipients have a valid public key");
  1154.                 CloseLog();
  1155. @
  1156.  
  1157.  
  1158. 1.19
  1159. log
  1160. @FindKey() now calls a self-written routine stristr() instead of
  1161. strstr(), because the latter routine compared the strings case-
  1162. significant.
  1163. @
  1164. text
  1165. @d3 2
  1166. a4 2
  1167.  **     $Revision: 1.18 $
  1168.  **     $Date: 1993/09/04 15:32:26 $
  1169. d14 1
  1170. a14 1
  1171.  **     $Id: PGPSendMail.c,v 1.18 1993/09/04 15:32:26 simons Stab simons $
  1172. d18 5
  1173. d171 1
  1174. a171 1
  1175.         static const char __RCSId[] = "$Id: PGPSendMail.c,v 1.18 1993/09/04 15:32:26 simons Stab simons $";
  1176. d241 6
  1177. a246 2
  1178.         if ((CheckKeyAvailability(receipients)) == 0)
  1179.                 NonFatalError("Not all receipients have a valid public key");
  1180. @
  1181.  
  1182.  
  1183. 1.18
  1184. log
  1185. @Corrected a few typing mistakes.
  1186. @
  1187. text
  1188. @d3 2
  1189. a4 2
  1190.  **     $Revision: 1.17 $
  1191.  **     $Date: 1993/09/03 14:35:08 $
  1192. d14 1
  1193. a14 1
  1194.  **     $Id: PGPSendMail.c,v 1.17 1993/09/03 14:35:08 simons Stab simons $
  1195. d18 3
  1196. d159 1
  1197. d166 1
  1198. a166 1
  1199.         static const char __RCSId[] = "$Id: PGPSendMail.c,v 1.17 1993/09/03 14:35:08 simons Stab simons $";
  1200. a587 3
  1201.         if(line == NULL)
  1202.                 NonFatalError("Couldn't allocate my buffer!");
  1203.  
  1204. d598 1
  1205. a598 1
  1206.                         if (strstr(line, key))
  1207. d610 10
  1208. @
  1209.  
  1210.  
  1211. 1.17
  1212. log
  1213. @Added configfile support. Used keywords are UULib, Debug and LockDir.
  1214. LogLevel is controlled by the configfile. Default is 0.
  1215. Added varius debug-messages.
  1216. @
  1217. text
  1218. @d3 2
  1219. a4 2
  1220.  **     $Revision: 1.16 $
  1221.  **     $Date: 1993/09/03 02:05:51 $
  1222. d14 1
  1223. a14 1
  1224.  **     $Id: PGPSendMail.c,v 1.16 1993/09/03 02:05:51 simons Exp simons $
  1225. d18 5
  1226. d162 1
  1227. a162 1
  1228.         static const char __RCSId[] = "$Id: PGPSendMail.c,v 1.16 1993/09/03 02:05:51 simons Exp simons $";
  1229. d280 1
  1230. @
  1231.  
  1232.  
  1233. 1.16
  1234. log
  1235. @Changed style of log-messages to fit better with the uucp package.
  1236. Added a few log-messages.
  1237. Set the debug value to 255 per default. Future versions might use an
  1238. entry in a configfile.
  1239. @
  1240. text
  1241. @d3 2
  1242. a4 2
  1243.  **     $Revision: 1.15 $
  1244.  **     $Date: 1993/09/03 01:33:35 $
  1245. d14 1
  1246. a14 1
  1247.  **     $Id: PGPSendMail.c,v 1.15 1993/09/03 01:33:35 simons Exp simons $
  1248. d18 6
  1249. d117 5
  1250. d125 10
  1251. a134 10
  1252. #define PGP "PGP -fesa <%s >%s %s +batchmode"
  1253. #define SENDMAIL "sendmail <%s %s"
  1254. #define PGPKEYLIST "UULIB:PGPKeys.lst"
  1255.  
  1256. #define HEADER_ID "X-AutoEncrypt: PGPSendMail 1.x\n"
  1257. #define BODY_ID "Automatically encrypted message-body follows:\n\n"
  1258.  
  1259. #define MAX_RECEIPIENTS 256     /* max. number of receipients */
  1260. #define LINEBUFFER 1024         /* max. line length */
  1261. #define IOBUFSIZE BUFSIZ*10     /* size of internal IO buffer */
  1262. a138 5
  1263. #ifdef AMIGA
  1264. #include <proto/dos.h>
  1265. #endif
  1266. #include "expandalias.h"
  1267.  
  1268. d157 1
  1269. a157 1
  1270.         static const char __RCSId[] = "$Id: PGPSendMail.c,v 1.15 1993/09/03 01:33:35 simons Exp simons $";
  1271. d168 1
  1272. a170 2
  1273.         LogLevel = 255;
  1274.  
  1275. d175 8
  1276. d208 1
  1277. a208 1
  1278.         if (CopyUntilEOF(stdin, file) == NULL)
  1279. d210 1
  1280. d218 2
  1281. d224 2
  1282. d227 1
  1283. a227 1
  1284.         if ((CheckKeyAvailability(receipients)) == NULL)
  1285. d241 1
  1286. a241 1
  1287.         if (CopyUntilEOF(file, pipe1) == NULL)
  1288. d243 1
  1289. d252 1
  1290. a252 1
  1291.         if (system(cmdbuf) != NULL)
  1292. d261 1
  1293. d266 1
  1294. a266 1
  1295.         if (CopyUntilEOF(pipe2, file) == NULL)
  1296. d273 1
  1297. a273 1
  1298.         if (TruncFile(FILENAME, body_pos) == NULL)
  1299. d279 2
  1300. a280 1
  1301.         sprintf(cmdbuf, SENDMAIL, FILENAME, argvline);
  1302. d308 2
  1303. a309 1
  1304.         sprintf(cmdbuf, SENDMAIL, FILENAME, argvline);
  1305. d527 1
  1306. a527 1
  1307.         char *keylist;
  1308. d532 6
  1309. a537 1
  1310.         if ((fh = fopen(PGPKEYLIST, "r")) == NULL)
  1311. d539 1
  1312. d550 1
  1313. d556 1
  1314. d560 1
  1315. a560 1
  1316.                                 if (FindKey(*receipients, keylist) == NULL) {
  1317. @
  1318.  
  1319.  
  1320. 1.15
  1321. log
  1322. @Added logfile support.
  1323. Straightened code concerning Amiga specific includes.
  1324. @
  1325. text
  1326. @d3 2
  1327. a4 2
  1328.  **     $Revision: 1.14 $
  1329.  **     $Date: 1993/08/28 18:45:46 $
  1330. d14 1
  1331. a14 1
  1332.  **     $Id: PGPSendMail.c,v 1.14 1993/08/28 18:45:46 simons Stab simons $
  1333. d18 4
  1334. d151 1
  1335. a151 1
  1336.         static const char __RCSId[] = "$Id: PGPSendMail.c,v 1.14 1993/08/28 18:45:46 simons Stab simons $";
  1337. d164 2
  1338. d203 1
  1339. a203 1
  1340.                 NonFatalError("Can't determine receipient of message!");
  1341. d207 1
  1342. a207 1
  1343.                 NonFatalError("Can't determine receipient of message!");
  1344. d210 1
  1345. a210 1
  1346.                 NonFatalError("Not all receipients have a valid public key!");
  1347. d230 1
  1348. a230 1
  1349.         my_ulog(-1, "PGPSendMail, starting `%s'", cmdbuf);
  1350. d234 1
  1351. a234 1
  1352.                 NonFatalError("PGP failed somehow!");
  1353. d279 2
  1354. a280 4
  1355.                 OpenLog();
  1356.                 my_ulog(-1, "PGPRMail, %s", message);
  1357.                 fprintf(stderr, "PGPRMail: %s\n", message);
  1358.                 CloseLog();
  1359. d296 2
  1360. a297 4
  1361.         OpenLog();
  1362.         my_ulog(-1, "PGPRMail, %s", message);
  1363.         fprintf(stderr, "PGPRMail: %s\n", message);
  1364.         CloseLog();
  1365. d355 1
  1366. a355 1
  1367.                 NonFatalError("Failed allocating my buffers!");
  1368. d532 1
  1369. @
  1370.  
  1371.  
  1372. 1.14
  1373. log
  1374. @Added alias-expansion support.
  1375. @
  1376. text
  1377. @d3 2
  1378. a4 2
  1379.  **     $Revision: 1.13 $
  1380.  **     $Date: 1993/08/28 17:59:56 $
  1381. d14 1
  1382. a14 1
  1383.  **     $Id: PGPSendMail.c,v 1.13 1993/08/28 17:59:56 simons Exp simons $
  1384. d18 3
  1385. d107 1
  1386. a107 5
  1387.  
  1388. #ifdef AMIGA
  1389. #include <dos/exall.h>
  1390. #include <utility/tagitem.h>
  1391. #endif
  1392. d121 2
  1393. d147 1
  1394. a147 1
  1395.         static const char __RCSId[] = "$Id: PGPSendMail.c,v 1.13 1993/08/28 17:59:56 simons Exp simons $";
  1396. d224 1
  1397. d254 1
  1398. a254 1
  1399.         system(cmdbuf);
  1400. d260 1
  1401. a260 1
  1402.         return 0;
  1403. d272 6
  1404. a277 2
  1405.         if (strlen(message) > 0)
  1406.                 fprintf(stderr, "PGPSendMail: %s\n", message);
  1407. d292 2
  1408. d295 1
  1409. @
  1410.  
  1411.  
  1412. 1.13
  1413. log
  1414. @PGPSendMail does not support the 'Bcc:'-line.
  1415. @
  1416. text
  1417. @d3 2
  1418. a4 2
  1419.  **     $Revision: 1.12 $
  1420.  **     $Date: 1993/08/23 15:48:02 $
  1421. d14 1
  1422. a14 1
  1423.  **     $Id: PGPSendMail.c,v 1.12 1993/08/23 15:48:02 simons Exp simons $
  1424. d18 3
  1425. d126 1
  1426. d146 1
  1427. a146 1
  1428.         static const char __RCSId[] = "$Id: PGPSendMail.c,v 1.12 1993/08/23 15:48:02 simons Exp simons $";
  1429. d195 4
  1430. @
  1431.  
  1432.  
  1433. 1.12
  1434. log
  1435. @Removed bug in ArrayToLine(): The contents of argvline had been trashed!
  1436. Removed some debugging output, as the routines are save now.
  1437. @
  1438. text
  1439. @a0 8
  1440. echo; /*    Execute to compile with SAS/C v6.x
  1441.  
  1442. SC PGPSendMail.c DEFINE=AMIGA STARTUP=cres DEBUG=FF LINK STRICT PARAMETERS=REGISTERS ; NOSTACKCHECK STRINGMERGE OPTIMIZE OPTIMIZERSIZE NOOPTIMIZERINLINE OPTIMIZERCOMPLEXITY=5 OPTIMIZERDEPTH=5 OPTIMIZERRECURDEPTH=5
  1443. delete PGPSendMail.lnk PGPSendMail.o
  1444. quit
  1445.  
  1446. */
  1447.  
  1448. d3 2
  1449. a4 2
  1450.  **     $Revision: 1.11 $
  1451.  **     $Date: 1993/08/23 15:21:19 $
  1452. d14 1
  1453. a14 1
  1454.  **     $Id: PGPSendMail.c,v 1.11 1993/08/23 15:21:19 simons Exp simons $
  1455. d18 4
  1456. a102 1
  1457. #include <dos/dos.h>
  1458. a104 1
  1459. #include <proto/dos.h>
  1460. d120 4
  1461. d142 1
  1462. a151 1
  1463.         static const char __RCSId[] = "$Id: PGPSendMail.c,v 1.11 1993/08/23 15:21:19 simons Exp simons $";
  1464. @
  1465.  
  1466.  
  1467. 1.11
  1468. log
  1469. @Added a kludge to let PGPSendMail understand PGP-key-aliases. FindKey()
  1470. now searches for "pub " or "pub ". This may break with other versions
  1471. of PGP or on other systems. However, it works fine. :-)
  1472. Reduced the required amount of stack from 8k+ to less than 1200 byte.
  1473. @
  1474. text
  1475. @d11 2
  1476. a12 2
  1477.  **     $Revision: 1.10 $
  1478.  **     $Date: 1993/08/23 13:47:36 $
  1479. d22 1
  1480. a22 1
  1481.  **     $Id: PGPSendMail.c,v 1.10 1993/08/23 13:47:36 simons Exp simons $
  1482. d26 6
  1483. d153 1
  1484. a153 1
  1485.         static const char __RCSId[] = "$Id: PGPSendMail.c,v 1.10 1993/08/23 13:47:36 simons Exp simons $";
  1486. d471 1
  1487. a471 1
  1488.         char line[LINEBUFFER];
  1489. d473 2
  1490. @
  1491.  
  1492.  
  1493. 1.10
  1494. log
  1495. @PGPSendMail now perfectly understands multiple line headers.
  1496. @
  1497. text
  1498. @d3 1
  1499. a3 1
  1500. SC PGPSendMail.c DEFINE=AMIGA STARTUP=cres DEBUG=FF LINK STRICT PARAMETERS=REGISTERS NOSTACKCHECK STRINGMERGE ; OPTIMIZE OPTIMIZERSIZE NOOPTIMIZERINLINE OPTIMIZERCOMPLEXITY=5 OPTIMIZERDEPTH=5 OPTIMIZERRECURDEPTH=5
  1501. d11 2
  1502. a12 2
  1503.  **     $Revision: 1.9 $
  1504.  **     $Date: 1993/08/23 13:12:32 $
  1505. d22 1
  1506. a22 1
  1507.  **     $Id: PGPSendMail.c,v 1.9 1993/08/23 13:12:32 simons Exp simons $
  1508. d26 3
  1509. d136 1
  1510. a136 1
  1511.         char *argvline;
  1512. d147 2
  1513. a148 2
  1514.         static const char __RCSId[] = "$Id: PGPSendMail.c,v 1.9 1993/08/23 13:12:32 simons Exp simons $";
  1515.         char **receipients, cmdbuf[LINEBUFFER*4];
  1516. d151 4
  1517. d228 5
  1518. a232 1
  1519.         body_pos = ftell(file); fclose(file); file = NULL;
  1520. a238 2
  1521.         fclose(pipe2); remove(PIPE2); /* Free some memory up. */
  1522.         fclose(file);
  1523. a257 2
  1524.         char cmdbuf[LINEBUFFER*4];
  1525.  
  1526. d335 4
  1527. a338 4
  1528.         line = FindHeaderEntry(fh, "To: ");
  1529.         SplitAddressLine(line, receipients);
  1530.         line = FindHeaderEntry(fh, "Cc: ");
  1531.         SplitAddressLine(line, receipients);
  1532. d388 3
  1533. d465 1
  1534. a465 1
  1535.         char *line;
  1536. a466 2
  1537.         if((line = malloc(LINEBUFFER)) == NULL)
  1538.                 return NULL;
  1539. d501 1
  1540. a501 1
  1541.                         fclose(fh); fh = NULL;
  1542. d522 3
  1543. d529 3
  1544. a531 1
  1545.                 if (!strnicmp(keylist, "pub ", strlen("pub "))) {
  1546. d548 1
  1547. @
  1548.  
  1549.  
  1550. 1.9
  1551. log
  1552. @Moved "PGPKey.lst"-file to "UULIB:".
  1553. Known bugs: - PGP aliases are not recognized! If someone has generated
  1554.               his key with another address than usenet, and created
  1555.               an alias later, he will not be found in the keyfile,
  1556.               because FindKey() only test lines beginning with "pub".
  1557. @
  1558. text
  1559. @d11 2
  1560. a12 2
  1561.  **     $Revision: 1.8 $
  1562.  **     $Date: 1993/08/23 13:05:01 $
  1563. d22 1
  1564. a22 1
  1565.  **     $Id: PGPSendMail.c,v 1.8 1993/08/23 13:05:01 simons Exp simons $
  1566. d26 7
  1567. d38 1
  1568. a38 1
  1569.  **               lines, SplitAddresses won't recognize them correctly.
  1570. d113 1
  1571. a113 1
  1572. #define LINEBUFFER 256          /* max. line length */
  1573. d144 1
  1574. a144 1
  1575.         static const char __RCSId[] = "$Id: PGPSendMail.c,v 1.8 1993/08/23 13:05:01 simons Exp simons $";
  1576. d249 1
  1577. a249 1
  1578.         char cmdbuf[LINEBUFFER];
  1579. d339 1
  1580. a339 1
  1581.         char *line;
  1582. d342 1
  1583. a342 1
  1584.         if ((line = malloc(LINEBUFFER)) == NULL)
  1585. d349 22
  1586. a370 2
  1587.                 if (!strnicmp(line, entry, strlen(entry)))
  1588.                         return &line[strlen(entry)];
  1589. @
  1590.  
  1591.  
  1592. 1.8
  1593. log
  1594. @PGPSendMail now checks wether a public key for each receipient is
  1595. available and sends the message unencrypted if not.
  1596. The commandline is now preserved, even under error-condition.
  1597. Known Bugs: - If the "To:" and "Cc:" lines are split over several
  1598.               lines, SplitAddresses won't recognize them correctly.
  1599. @
  1600. text
  1601. @d11 2
  1602. a12 2
  1603.  **     $Revision: 1.7 $
  1604.  **     $Date: 1993/08/22 17:53:02 $
  1605. d22 1
  1606. a22 1
  1607.  **     $Id: PGPSendMail.c,v 1.7 1993/08/22 17:53:02 simons Stab simons $
  1608. d26 7
  1609. d100 1
  1610. a100 1
  1611. #define PGPKEYLIST "UUMAIL:PGPKeys.lst"
  1612. d137 1
  1613. a137 1
  1614.         static const char __RCSId[] = "$Id: PGPSendMail.c,v 1.7 1993/08/22 17:53:02 simons Stab simons $";
  1615. @
  1616.  
  1617.  
  1618. 1.7
  1619. log
  1620. @Known bugs: - If sendmail is called under an error-condition, the
  1621.               original commandline is lost. Will be fixed soon.
  1622. @
  1623. text
  1624. @d11 2
  1625. a12 2
  1626.  **     $Revision: 1.6 $
  1627.  **     $Date: 1993/08/22 17:48:33 $
  1628. d22 1
  1629. a22 1
  1630.  **     $Id: PGPSendMail.c,v 1.6 1993/08/22 17:48:33 simons Stab simons $
  1631. d26 4
  1632. d93 1
  1633. d113 2
  1634. d119 1
  1635. d130 1
  1636. a130 1
  1637.         static const char __RCSId[] = "$Id: PGPSendMail.c,v 1.6 1993/08/22 17:48:33 simons Stab simons $";
  1638. d135 8
  1639. d166 1
  1640. a166 1
  1641.         if (*receipients == NULL)
  1642. d169 2
  1643. d216 1
  1644. a216 1
  1645.         sprintf(cmdbuf, SENDMAIL, FILENAME, ArrayToLine(&argv[1]));
  1646. d244 1
  1647. a244 1
  1648.         sprintf(cmdbuf, SENDMAIL, FILENAME, "");
  1649. d435 66
  1650. @
  1651.  
  1652.  
  1653. 1.6
  1654. log
  1655. @Changed a few situations from fatal to non-fatal errors.
  1656. @
  1657. text
  1658. @d11 2
  1659. a12 2
  1660.  **     $Revision: 1.5 $
  1661.  **     $Date: 1993/08/22 17:46:12 $
  1662. d22 1
  1663. a22 1
  1664.  **     $Id: PGPSendMail.c,v 1.5 1993/08/22 17:46:12 simons Stab simons $
  1665. d26 3
  1666. d122 1
  1667. a122 1
  1668.         static const char __RCSId[] = "$Id: PGPSendMail.c,v 1.5 1993/08/22 17:46:12 simons Stab simons $";
  1669. d217 2
  1670. d226 1
  1671. a226 1
  1672.         sprintf(cmdbuf, SENDMAIL, FILENAME, ArrayToLine(&argv[1]));
  1673. @
  1674.  
  1675.  
  1676. 1.5
  1677. log
  1678. @Error conditions are handled much better. If anything goes wrong, the
  1679. original mail is sent to sendmail instead of the failed encrypted
  1680. version.
  1681. @
  1682. text
  1683. @d11 2
  1684. a12 2
  1685.  **     $Revision: 1.4 $
  1686.  **     $Date: 1993/08/22 17:38:34 $
  1687. d22 1
  1688. a22 1
  1689.  **     $Id: PGPSendMail.c,v 1.4 1993/08/22 17:38:34 simons stab simons $
  1690. d26 5
  1691. d119 1
  1692. a119 1
  1693.         static const char __RCSId[] = "$Id: PGPSendMail.c,v 1.4 1993/08/22 17:38:34 simons stab simons $";
  1694. d179 1
  1695. a179 1
  1696.                 error("Can't open temporary file!", 10);
  1697. @
  1698.  
  1699.  
  1700. 1.4
  1701. log
  1702. @PGPSendMail now calls sendmail with exactly the same parameters he
  1703. has been called with.
  1704. Known bugs: - currently does not correct the "Lines:" keyword
  1705. @
  1706. text
  1707. @d11 2
  1708. a12 2
  1709.  **     $Revision: 1.3 $
  1710.  **     $Date: 1993/08/22 17:12:11 $
  1711. d22 1
  1712. a22 1
  1713.  **     $Id: PGPSendMail.c,v 1.3 1993/08/22 17:12:11 simons Stab simons $
  1714. d26 5
  1715. d114 1
  1716. a114 1
  1717.         static const char __RCSId[] = "$Id: PGPSendMail.c,v 1.3 1993/08/22 17:12:11 simons Stab simons $";
  1718. d180 1
  1719. a180 1
  1720.                 NonFatalError("Can't write to my temporary file!");
  1721. d183 1
  1722. a183 1
  1723.                 NonFatalError("Truncating the original failed.");
  1724. d214 1
  1725. a214 1
  1726.         fclose(file); remove(FILENAME);
  1727. d216 4
  1728. a219 1
  1729.         fprintf(stderr, "Calling sendmail with unmodified file!\n");
  1730. @
  1731.  
  1732.  
  1733. 1.3
  1734. log
  1735. @PGPSendMail works basically.
  1736. Known bugs: - Aliases aren't expanded before PGPSendMail tries to
  1737.               determine the receipient. Hence the addresses won't be
  1738.               found in the keyring.
  1739.             - When sending (and encrypting) mail for multiple
  1740.               receipients, PGP does not return any warning if one of
  1741.               the receipients has no public key available, is just
  1742.               skips him. Though you should only use PGPSendmail with
  1743.               receipients having a key available. I'll try to modify
  1744. @
  1745. text
  1746. @d11 2
  1747. a12 2
  1748.  **     $Revision$
  1749.  **     $Date$
  1750. d22 1
  1751. a22 1
  1752.  **     $Id$
  1753. d26 11
  1754. d94 1
  1755. d109 2
  1756. a110 2
  1757.         static const char __RCSId[] = "$Id$"
  1758.         char **receipients, line[LINEBUFFER*4], cmdbuf[LINEBUFFER*4];
  1759. d146 1
  1760. a146 1
  1761.         while((body_pos = getline(file, line)) > 1)
  1762. d158 1
  1763. a158 8
  1764.         line[0] = '\0';
  1765.         while (*receipients != NULL) {
  1766.                 strcat(line, *receipients);
  1767.                 strcat(line, " ");
  1768.                 receipients++;
  1769.         }
  1770.  
  1771.         sprintf(cmdbuf, PGP, PIPE1, PIPE2, line);
  1772. d185 1
  1773. a185 2
  1774.         fprintf(stderr, "%s\n", cmdbuf);
  1775.         sprintf(cmdbuf, SENDMAIL, FILENAME, "");
  1776. d191 1
  1777. a191 1
  1778.         /* remove(FILENAME); */
  1779. d381 16
  1780. @
  1781.  
  1782.  
  1783. 1.2
  1784. log
  1785. @The UUCP-message stuff is already working. I wrote a set of routines,
  1786. that seperate the receipients of a message out of the header and
  1787. skip anything but the address of them.
  1788. Using the address for identifying the user seems to be more reliable
  1789. than trying to get the realname.
  1790. At the moment I have to use unbuffered IO, because I have to reset
  1791. the position in the readfile several times, what is not supported
  1792. with my routines yet.
  1793. @
  1794. text
  1795. @d3 1
  1796. a3 1
  1797. SC PGPSendMail.c STARTUP=cres DEBUG=FF LINK STRICT PARAMETERS=REGISTERS NOSTACKCHECK STRINGMERGE ; OPTIMIZE OPTIMIZERSIZE NOOPTIMIZERINLINE OPTIMIZERCOMPLEXITY=5 OPTIMIZERDEPTH=5 OPTIMIZERRECURDEPTH=5
  1798. d22 1
  1799. a22 1
  1800.  **     $Id $
  1801. d26 10
  1802. d55 6
  1803. d64 1
  1804. a64 1
  1805. #define RMAIL "SendMail <%s %s"
  1806. d67 1
  1807. d77 1
  1808. a77 1
  1809. int CopyUntilEOF(int, int);
  1810. d82 1
  1811. d85 1
  1812. a85 1
  1813.         FILE *pipe1, *pipe2, *file;
  1814. d97 3
  1815. a99 2
  1816.         static const char __RCSId[] = "$Id: PGPSendMail.c,v 1.1 1993/08/21 19:28:43 simons Exp simons $";
  1817.         char **receipients;
  1818. a109 4
  1819.         if ((pipe1 = fopen(PIPE1, "w")) == NULL)
  1820.                 error("Can't open temporary file!", 10);
  1821.         if ((pipe2 = fopen(PIPE2, "w")) == NULL)
  1822.                 error("Can't open temporary file!", 10);
  1823. d118 1
  1824. a118 1
  1825.         if (CopyUntilEOF(fileno(stdin), fileno(file)) == NULL)
  1826. d122 2
  1827. d125 8
  1828. d134 13
  1829. d148 3
  1830. a150 1
  1831.                 printf("%s\n", *receipients++);
  1832. d153 7
  1833. d161 1
  1834. a161 1
  1835.         /* Delete temporary files. */
  1836. d163 21
  1837. a183 1
  1838.         fprintf(stderr, "Calling sendmail with modified file!\n");
  1839. d185 1
  1840. a185 3
  1841.         fclose(pipe1); remove(PIPE1);
  1842.         fclose(pipe2); remove(PIPE2);
  1843.         fclose(file); remove(FILENAME);
  1844. d187 2
  1845. a188 1
  1846.         return 0;       /* flag contains the return code of rmail */
  1847. d243 1
  1848. a243 1
  1849. int CopyUntilEOF(int in, int out)
  1850. d251 7
  1851. a257 2
  1852.         while ((len = read(in, buffer, IOBUFSIZE)) > 0)
  1853.                 if (write(out, buffer, len) == -1) {
  1854. d290 1
  1855. d360 17
  1856. @
  1857.  
  1858.  
  1859. 1.1
  1860. log
  1861. @Initial revision
  1862. @
  1863. text
  1864. @d25 3
  1865. a27 1
  1866.  ** $Log$
  1867. d79 1
  1868. a79 1
  1869.         static const char __RCSId[] = "$Id$";
  1870. @
  1871.