-** 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 "network" (mail from
-** a network server).
-** 3. The user's login name is "uucp" (mail from the
-** uucp network).
-** 4. The address the user is trying to claim has a
-** "!" character in it (since #3 doesn't do it for
-** us if we are dialing out).
-** A better check to replace #3 & #4 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();
- extern char *macvalue();
-
- if (realname == NULL)
- realname = CurEnv->e_from.q_paddr;
-
-# ifdef DEBUG
- if (tTd(1, 2))
- 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)
- {
- if (strcmp(realname, "network") != 0 &&
- strcmp(realname, "uucp") != 0 &&
- strcmp(realname, "daemon") != 0 &&
-# ifdef DEBUG
- (!tTd(1, 1) || 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;
- }
-
- /*
- ** Set up the $r and $s macros to show who it came from.
- */
-
- if (macvalue('s') == NULL && CurEnv->e_from.q_host != NULL &&
- CurEnv->e_from.q_host[0] != '\0')
- {
- define('s', CurEnv->e_from.q_host);
-
- /* should determine network type here */
- }
-
- /*
- ** 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, 1);
- cataddr(pvp, frombuf, sizeof frombuf);
- define('f', newstr(frombuf));
-}
-\f/*