-** SETFROM -- set the person who this message is from
-**
-** Under certain circumstances allow the user to say who
-** s/he is (using -f or -r). These are:
-** 1. The user's uid is zero (root).
-** 2. The user's login name is in an approved list (typically
-** from a network server).
-** 3. The address the user is trying to claim has a
-** "!" character in it (since #2 doesn't do it for
-** us if we are dialing out for UUCP).
-** A better check to replace #3 would be if the
-** effective uid is "UUCP" -- this would require me
-** to rewrite getpwent to "grab" uucp as it went by,
-** make getname more nasty, do another passwd file
-** scan, or compile the UID of "UUCP" into the code,
-** all of which are reprehensible.
-**
-** Assuming all of these fail, we figure out something
-** ourselves.
-**
-** Parameters:
-** from -- the person it is from.
-** realname -- the actual person executing sendmail.
-** If NULL, then take whoever we previously
-** thought was the from person.
-**
-** Returns:
-** none.
-**
-** Side Effects:
-** sets sendmail's notion of who the from person is.
-*/
-
-setfrom(from, realname)
- char *from;
- char *realname;
-{
- register char **pvp;
- char frombuf[MAXNAME];
- extern char **prescan();
- extern char *index();
-
- if (realname == NULL)
- realname = CurEnv->e_from.q_paddr;
-
-# ifdef DEBUG
- if (tTd(1, 1))
- printf("setfrom(%s, %s)\n", from, realname);
-# endif DEBUG
-
- /*
- ** Do validation to determine whether this user is allowed
- ** to change the sender name.
- */
-
- if (from != NULL)
- {
- extern bool trusteduser();
-
- if (!trusteduser(realname) &&
-# ifdef DEBUG
- (!tTd(1, 9) || getuid() != geteuid()) &&
-# endif DEBUG
- index(from, '!') == NULL && getuid() != 0)
- {
- /* network sends -r regardless (why why why?) */
- /* syserr("%s, you cannot use the -f flag", realname); */
- from = NULL;
- }
- }
-
- /*
- ** Parse the sender name.
- ** Arrange to send return messages to the same person.
- ** Set up some environment info.
- */
-
- SuprErrs = TRUE;
- if (from == NULL || parse(from, &CurEnv->e_from, 1) == NULL)
- {
- from = newstr(realname);
- (void) parse(from, &CurEnv->e_from, 1);
- }
- else
- FromFlag = TRUE;
- CurEnv->e_returnto = &CurEnv->e_from;
- SuprErrs = FALSE;
- CurEnv->e_from.q_uid = getuid();
- CurEnv->e_from.q_gid = getgid();
-# ifndef V6
- CurEnv->e_from.q_home = getenv("HOME");
-# endif V6
- if (CurEnv->e_from.q_uid != 0)
- {
- DefUid = CurEnv->e_from.q_uid;
- DefGid = CurEnv->e_from.q_gid;
- }
-
- /*
- ** Rewrite the from person to dispose of possible implicit
- ** links in the net.
- */
-
- pvp = prescan(from, '\0');
- if (pvp == NULL)
- {
- syserr("cannot prescan from (%s)", from);
- finis();
- }
- rewrite(pvp, 3);
- rewrite(pvp, 1);
- cataddr(pvp, frombuf, sizeof frombuf);
- define('f', newstr(frombuf));
-
- /* save the domain spec if this mailer wants it */
- if (bitset(M_CANONICAL, CurEnv->e_from.q_mailer->m_flags))
- {
- extern char **copyplist();
-
- while (*pvp != NULL && strcmp(*pvp, "@") != 0)
- pvp++;
- if (*pvp != NULL)
- CurEnv->e_fromdomain = copyplist(pvp, TRUE);
- }
-}
-\f/*
-** TRUSTEDUSER -- tell us if this user is to be trusted.
-**
-** Parameters:
-** user -- the user to be checked.
-**
-** Returns:
-** TRUE if the user is in an approved list.
-** FALSE otherwise.
-**
-** Side Effects:
-** none.
-*/
-
-bool
-trusteduser(user)
- char *user;
-{
- register char **ulist;
- extern char *TrustedUsers[];
-
- for (ulist = TrustedUsers; *ulist != NULL; ulist++)
- if (strcmp(*ulist, user) == 0)
- return (TRUE);
- return (FALSE);
-}
-\f/*