only catch filenames if the "/" is leading
[unix-history] / usr / src / usr.sbin / sendmail / src / recipient.c
index 839c507..737c875 100644 (file)
@@ -2,7 +2,7 @@
 # include "sendmail.h"
 # include <sys/stat.h>
 
 # include "sendmail.h"
 # include <sys/stat.h>
 
-static char SccsId[] = "@(#)recipient.c        3.29    %G%";
+SCCSID(@(#)recipient.c 3.33            %G%);
 
 /*
 **  SENDTO -- Designate a send list.
 
 /*
 **  SENDTO -- Designate a send list.
@@ -21,6 +21,10 @@ static char SccsId[] = "@(#)recipient.c      3.29    %G%";
 **             copyf -- the copy flag; passed to parse.
 **             ctladdr -- the address template for the person to
 **                     send to -- effective uid/gid are important.
 **             copyf -- the copy flag; passed to parse.
 **             ctladdr -- the address template for the person to
 **                     send to -- effective uid/gid are important.
+**                     This is typically the alias that caused this
+**                     expansion.
+**             sendq -- a pointer to the head of a queue to put
+**                     these people into.
 **             qflags -- special flags to set in the q_flags field.
 **
 **     Returns:
 **             qflags -- special flags to set in the q_flags field.
 **
 **     Returns:
@@ -37,6 +41,7 @@ sendto(list, copyf, ctladdr, qflags)
        char *list;
        int copyf;
        ADDRESS *ctladdr;
        char *list;
        int copyf;
        ADDRESS *ctladdr;
+       ADDRESS **sendq;
        u_short qflags;
 {
        register char *p;
        u_short qflags;
 {
        register char *p;
@@ -178,6 +183,9 @@ addrref(a, r)
 **
 **     Parameters:
 **             a -- the (preparsed) address header for the recipient.
 **
 **     Parameters:
 **             a -- the (preparsed) address header for the recipient.
+**             sendq -- a pointer to the head of a queue to put the
+**                     recipient in.  Duplicate supression is done
+**                     in this queue.
 **
 **     Returns:
 **             pointer to address actually inserted in send list.
 **
 **     Returns:
 **             pointer to address actually inserted in send list.
@@ -187,8 +195,9 @@ addrref(a, r)
 */
 
 ADDRESS *
 */
 
 ADDRESS *
-recipient(a)
+recipient(a, sendq)
        register ADDRESS *a;
        register ADDRESS *a;
+       register ADDRESS **sendq;
 {
        register ADDRESS *q;
        ADDRESS **pq;
 {
        register ADDRESS *q;
        ADDRESS **pq;
@@ -227,7 +236,7 @@ recipient(a)
                {
                        a->q_mailer = m = ProgMailer;
                        a->q_user++;
                {
                        a->q_mailer = m = ProgMailer;
                        a->q_user++;
-                       if (a->q_alias == NULL && Debug == 0 && !QueueRun)
+                       if (a->q_alias == NULL && Debug == 0 && !QueueRun && !ForceMail)
                        {
                                usrerr("Cannot mail directly to programs");
                                a->q_flags |= QDONTSEND;
                        {
                                usrerr("Cannot mail directly to programs");
                                a->q_flags |= QDONTSEND;
@@ -244,7 +253,7 @@ recipient(a)
        **      [Please note: the emphasis is on "hack."]
        */
 
        **      [Please note: the emphasis is on "hack."]
        */
 
-       for (pq = &m->m_sendq; (q = *pq) != NULL; pq = &q->q_next)
+       for (pq = sendq; (q = *pq) != NULL; pq = &q->q_next)
        {
                if (!ForceMail && sameaddr(q, a, FALSE))
                {
        {
                if (!ForceMail && sameaddr(q, a, FALSE))
                {
@@ -280,17 +289,17 @@ recipient(a)
                if (strncmp(a->q_user, ":include:", 9) == 0)
                {
                        a->q_flags |= QDONTSEND;
                if (strncmp(a->q_user, ":include:", 9) == 0)
                {
                        a->q_flags |= QDONTSEND;
-                       if (a->q_alias == NULL && Debug == 0 && !QueueRun)
+                       if (a->q_alias == NULL && Debug == 0 && !QueueRun && !ForceMail)
                                usrerr("Cannot mail directly to :include:s");
                        else
                        {
                                if (Verbose)
                                        message(Arpa_Info, "including file %s", &a->q_user[9]);
                                usrerr("Cannot mail directly to :include:s");
                        else
                        {
                                if (Verbose)
                                        message(Arpa_Info, "including file %s", &a->q_user[9]);
-                               include(&a->q_user[9], " sending", a);
+                               include(&a->q_user[9], " sending", a, sendq);
                        }
                }
                else
                        }
                }
                else
-                       alias(a);
+                       alias(a, sendq);
        }
 
        /*
        }
 
        /*
@@ -318,10 +327,11 @@ recipient(a)
                stripquotes(buf, TRUE);
 
                /* see if this is to a file */
                stripquotes(buf, TRUE);
 
                /* see if this is to a file */
-               if ((p = rindex(buf, '/')) != NULL)
+               if (buf[0] == '/')
                {
                {
+                       p = rindex(buf, '/');
                        /* check if writable or creatable */
                        /* check if writable or creatable */
-                       if (a->q_alias == NULL && Debug == 0 && !QueueRun)
+                       if (a->q_alias == NULL && Debug == 0 && !QueueRun && !ForceMail)
                        {
                                usrerr("Cannot mail directly to files");
                                a->q_flags |= QDONTSEND;
                        {
                                usrerr("Cannot mail directly to files");
                                a->q_flags |= QDONTSEND;
@@ -367,7 +377,7 @@ recipient(a)
                                if (nbuf[0] != '\0')
                                        a->q_fullname = newstr(nbuf);
                                if (!quoted)
                                if (nbuf[0] != '\0')
                                        a->q_fullname = newstr(nbuf);
                                if (!quoted)
-                                       forward(a);
+                                       forward(a, sendq);
                        }
                }
        }
                        }
                }
        }
@@ -489,6 +499,8 @@ writable(s)
 **             ctladdr -- address template to use to fill in these
 **                     addresses -- effective user/group id are
 **                     the important things.
 **             ctladdr -- address template to use to fill in these
 **                     addresses -- effective user/group id are
 **                     the important things.
+**             sendq -- a pointer to the head of the send queue
+**                     to put these addresses in.
 **
 **     Returns:
 **             none.
 **
 **     Returns:
 **             none.
@@ -498,10 +510,11 @@ writable(s)
 **             listed in that file.
 */
 
 **             listed in that file.
 */
 
-include(fname, msg, ctladdr)
+include(fname, msg, ctladdr, sendq)
        char *fname;
        char *msg;
        ADDRESS *ctladdr;
        char *fname;
        char *msg;
        ADDRESS *ctladdr;
+       ADDRESS **sendq;
 {
        char buf[MAXLINE];
        register FILE *fp;
 {
        char buf[MAXLINE];
        register FILE *fp;