home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / pp / pp-6.0 / Src / submit / gen_warn.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-18  |  7.0 KB  |  281 lines

  1. /* gen_warn.c: generate warning messages */
  2.  
  3. # ifndef lint
  4. static char Rcsid[] = "@(#)$Header: /xtel/pp/pp-beta/Src/submit/RCS/gen_warn.c,v 6.0 1991/12/18 20:28:02 jpo Rel $";
  5. # endif
  6.  
  7. /*
  8.  * $Header: /xtel/pp/pp-beta/Src/submit/RCS/gen_warn.c,v 6.0 1991/12/18 20:28:02 jpo Rel $
  9.  *
  10.  * $Log: gen_warn.c,v $
  11.  * Revision 6.0  1991/12/18  20:28:02  jpo
  12.  * Release 6.0
  13.  *
  14.  */
  15.  
  16. #include "util.h"
  17. #include "q.h"
  18. #include "auth.h"
  19. #include "prm.h"
  20. #include "retcode.h"
  21. #include "expand.h"
  22.  
  23. extern char *getpostmaster(), *postmaster;
  24. extern char *loc_dom_mta;
  25. extern char *local_822_chan, *loc_dom_site;
  26. extern char *msg_unique;
  27. extern char *ia5_bp, *hdr_822_bp;
  28. extern char *wrndfldir;
  29.  
  30. extern void getfpath (), ad_log_print(), 
  31.     auth_start(), auth_log(), time_mgt();
  32.  
  33. static void gen_auth_warn (), setup_macros ();
  34. static int copy_warn_file();
  35.  
  36. void gen_warnings (qp, sender, recips)
  37. Q_struct *qp;
  38. ADDR *sender;
  39. ADDR *recips;
  40. {
  41.     ADDR    *ad;
  42.  
  43.     for (ad = recips; ad; ad = ad -> ad_next)
  44.         gen_auth_warn (qp, sender, ad);
  45. }
  46.  
  47. #define gval(x)            ((x -> ad_type) == AD_X400_TYPE ? \
  48.                  (x -> ad_r400adr) : (x -> ad_r822adr))    
  49.  
  50.  
  51. static void gen_auth_warn (qp, sender, ad)
  52. Q_struct *qp;
  53. ADDR    *sender, *ad;
  54. {
  55.     LIST_RCHAN     *lp = ad -> ad_outchan;
  56.  
  57.     if (lp == NULL || lp -> li_auth == NULL)
  58.         return;
  59.  
  60.     switch (lp -> li_auth -> status) {
  61.         case AUTH_OK:
  62.         case AUTH_DR_OK:
  63.         return;
  64.         case AUTH_FAILED_TEST:
  65.         case AUTH_DR_FAILED:
  66.         case AUTH_FAILED:
  67.         if (lp -> li_auth -> chan -> warnsender) {
  68.             send_warning (qp, sender, ad,
  69.                       lp -> li_auth -> chan -> warnsender,
  70.                       "sender", lp -> li_auth -> reason);
  71.             PP_OPER (NULLCP, ("%s '%s' from file '%s'",
  72.                       "Warning message to sender",
  73.                       gval (sender), 
  74.                       lp -> li_auth -> chan -> warnsender));
  75.         }
  76.         if (lp -> li_auth -> chan -> warnrecipient) {
  77.             send_warning (qp, ad, ad,
  78.                       lp -> li_auth -> chan -> warnrecipient,
  79.                       "recip", lp -> li_auth -> reason);
  80.             PP_OPER (NULLCP, ("%s '%s' from file '%s'",
  81.                       "Warning message to recipient",
  82.                       gval (ad), 
  83.                       lp -> li_auth -> chan -> warnsender));
  84.         }
  85.     }
  86.  
  87. }
  88.  
  89. send_warning (qporig, recip, ad, file, direction, reason)
  90. Q_struct *qporig;
  91. ADDR    *recip;
  92. ADDR    *ad;
  93. char    *file;
  94. char    *direction;
  95. char    *reason;
  96. {
  97.     struct prm_vars prm;
  98.     Q_struct que;
  99.     ADDR    *ap;
  100.     ADDR    *postie;
  101.     RP_Buf rps, *rp = &rps;
  102.     char buf[BUFSIZ];
  103.     char datebuf[LINESIZE];
  104.     UTC    ut;
  105.  
  106.     prm_init (&prm);
  107.     q_init (&que);
  108.     que.inbound = list_rchan_new (loc_dom_mta, local_822_chan);
  109.     list_bpt_add (&que.encodedinfo.eit_types, list_bpt_new(hdr_822_bp));
  110.     list_bpt_add (&que.encodedinfo.eit_types, list_bpt_new (ia5_bp));
  111.     ap = adr_new (recip -> ad_r822adr, AD_822_TYPE, 1);
  112.     postie = adr_new (getpostmaster(AD_822_TYPE), AD_822_TYPE, 0);
  113.     postie -> ad_resp = FALSE;
  114.     postie -> ad_status = AD_STAT_DONE;
  115.     postie -> ad_no = NULL;
  116.  
  117.     if (rp_isbad (cntrl_mgt (&prm, &que)) ||
  118.         rp_isbad (q_mgt (&que))) {
  119.         PP_LOG (LLOG_EXCEPTIONS, ("bad paramters"));
  120.         goto out;
  121.     }
  122.     if (rp_isbad (validate_sender (&que, postie, NULLCP, rp))) {
  123.         PP_LOG (LLOG_EXCEPTIONS, ("bad sender %s, %s",
  124.                       getpostmaster(AD_822_TYPE), rp -> rp_line));
  125.         goto out;
  126.     }
  127.     if (rp_isbad (validate_recip (ap, &que, rp))) {
  128.         PP_LOG (LLOG_EXCEPTIONS, ("bad recip %s, %s",
  129.                       ap -> ad_value, rp -> rp_line));
  130.         goto out;
  131.     }
  132.  
  133.     ad_log_print (ap);
  134.     auth_start (&que, postie, ap);
  135.     que.Oaddress = postie;
  136.     que.Raddress = ap;
  137.  
  138.     time_mgt(&que);
  139.  
  140.     if (rp_isbad (winit_q (rp))) {
  141.         PP_LOG (LLOG_EXCEPTIONS, ("Problem writing into the que: %s",
  142.                       rp -> rp_line));
  143.         goto out;
  144.     }
  145.  
  146.     if (rp_isbad (txt_init (&que)) ||
  147.         rp_isbad (txt_psetup (&que, hdr_822_bp, NULLCP))) {
  148.         PP_LOG (LLOG_EXCEPTIONS, ("Problem initialising text"));
  149.         goto out;
  150.     }
  151.     if (UTC2rfc (ut = utcnow(), datebuf) == NOTOK)
  152.         goto out;
  153.     free ((char *)ut);
  154.     (void) sprintf (buf, "To: %s\nFrom: %s\nDate: %s\n\
  155. Subject: Warning message\n",
  156.             recip -> ad_r822adr, postmaster, datebuf);
  157.     if (rp_isbad (txt_write (buf, strlen (buf)))) {
  158.         PP_LOG (LLOG_EXCEPTIONS, ("Problems writing text"));
  159.         goto out;
  160.     }
  161.     if (rp_isbad (txt_pfinish ())) {
  162.         PP_LOG (LLOG_EXCEPTIONS, ("Problems finishing hdr"));
  163.         goto out;
  164.     }
  165.  
  166.     (void) sprintf (datebuf, "1.%s", ia5_bp);
  167.     if (rp_isbad (txt_psetup (&que, datebuf, NULLCP))) {
  168.         PP_LOG (LLOG_EXCEPTIONS, ("Problems initialising for text"));
  169.         goto out;
  170.     }
  171.     setup_macros (&que, qporig, ad, direction, reason);
  172.  
  173.     if (copy_warn_file (file) == NOTOK)
  174.         goto out;
  175.     if (rp_isbad (txt_pfinish ()) ||
  176.         rp_isbad (txt_tend())) {
  177.         PP_LOG (LLOG_EXCEPTIONS, ("Problems finishing text"));
  178.         goto out;
  179.     }
  180.  
  181.     if (rp_isbad (auth_finish (&que, postie, ap))) {
  182.         PP_LOG (LLOG_EXCEPTIONS, ("Authorisation problems"));
  183.         goto out;
  184.     }
  185.  
  186.     setup_directories (&que);
  187.     gen_ndr (&que);
  188.     if (rp_isbad (write_q (&que, &prm, rp)) ||
  189.         rp_isbad (move_q (rp))) {
  190.         PP_LOG (LLOG_EXCEPTIONS,
  191.             ("Queue problems: %s", rp -> rp_line));
  192.         goto out;
  193.     }
  194.  
  195.     auth_log (&que, postie, ap, msg_unique);
  196.     tell_qmgr (msg_unique, &prm, &que, postie, ap, 1);
  197. out:;
  198.     que.Oaddress = que.Raddress = NULL;
  199.     if (ap)
  200.         adr_free (ap);
  201.     if (postie)
  202.         adr_free (postie);
  203.     q_free (&que);
  204.     prm_free (&prm);
  205.     return;
  206. }
  207.  
  208.  
  209. static Expand expand_macros[] = {
  210.         "sender",       NULLCP, /* 0 */
  211.         "822sender",    NULLCP, /* 1 */
  212.         "400sender",    NULLCP, /* 2 */
  213.         "ua-id",        NULLCP, /* 3 */
  214.         "p1-id",        NULLCP, /* 4 */
  215.         "recips",       NULLCP, /* 5 */
  216.         "822recips",    NULLCP, /* 6 */
  217.         "400recips",    NULLCP, /* 7 */
  218.         "locmta",       NULLCP, /* 8 */
  219.         "locsite",    NULLCP, /* 9 */
  220.     "reason",    NULLCP, /* 10 */
  221.     "direction",    NULLCP, /* 11 */
  222.         NULLCP, NULLCP};
  223.  
  224. static void setup_macros (qp, qporig, recip, direction, reason)
  225. Q_struct *qp;
  226. Q_struct *qporig;
  227. ADDR    *recip;
  228. char *direction;
  229. char *reason;
  230. {
  231.     expand_macros[0].expansion = qporig -> Oaddress -> ad_value;
  232.     expand_macros[1].expansion = qporig -> Oaddress -> ad_r822adr;
  233.     expand_macros[2].expansion = qporig -> Oaddress -> ad_r400adr;
  234.     expand_macros[3].expansion = qporig -> ua_id;
  235.     expand_macros[4].expansion = qporig -> msgid.mpduid_string;
  236.     expand_macros[5].expansion = recip -> ad_value;
  237.     expand_macros[6].expansion = recip -> ad_r822adr;
  238.     expand_macros[7].expansion = recip -> ad_r400adr;
  239.     expand_macros[8].expansion = loc_dom_mta;
  240.     expand_macros[9].expansion = loc_dom_site;
  241.     expand_macros[10].expansion = reason;
  242.     expand_macros[11].expansion = direction;
  243. }
  244.  
  245. static int copy_warn_file (file)
  246. char *file;
  247. {
  248.     char filename[MAXPATHLENGTH];
  249.     char buf[BUFSIZ], *cp;
  250.     FILE    *fp;
  251.     int retval = OK;
  252.  
  253.     getfpath (wrndfldir, file, filename);
  254.  
  255.     if ((fp = fopen (filename, "r")) == NULL) {
  256.         PP_SLOG (LLOG_EXCEPTIONS, filename, ("Can't open"));
  257.         return NOTOK;
  258.     }
  259.  
  260.     while (fgets (buf, sizeof buf, fp) != NULLCP) {
  261.         if (index (buf, '$')) {
  262.             cp = expand_dyn (buf, expand_macros);
  263.             if (rp_isbad(txt_write (cp, strlen(cp)))) {
  264.                 PP_LOG (LLOG_EXCEPTIONS, ("write error"));
  265.                 retval = NOTOK;
  266.                 break;
  267.             }
  268.             free (cp);
  269.         }
  270.         else {
  271.             if (rp_isbad(txt_write (buf, strlen(buf)))) {
  272.                 PP_LOG (LLOG_EXCEPTIONS, ("write error"));
  273.                 retval = NOTOK;
  274.                 break;
  275.             }
  276.         }
  277.     }
  278.     (void) fclose (fp);
  279.     return retval;
  280. }
  281.