*BSD News Article 65149


Return to BSD News archive

Path: euryale.cc.adfa.oz.au!newshost.anu.edu.au!harbinger.cc.monash.edu.au!news.cs.su.oz.au!metro!metro!munnari.OZ.AU!news.ecn.uoknor.edu!news.ysu.edu!odin.oar.net!malgudi.oar.net!imci4!newsfeed.internetmci.com!in2.uu.net!news.u.washington.edu!raindrop!unger
From: unger@raindrop.seaslug.org (Thomas Unger)
Newsgroups: comp.unix.bsd.freebsd.misc
Subject: 'at' bug?
Date: Tue, 2 Apr 1996 03:32:14 GMT
Organization: Wet Weather Consulting
Lines: 95
Message-ID: <Dp7ttq.1En.0.raindrop.seaslug.org@raindrop.seaslug.org>
NNTP-Posting-Host: cs103-7.u.washington.edu


I've been wroking on an 'at' job (in perl) that will re-submit itself
by executing 'at' as part of the 'at' job.  But there were some
problems.  The perl script would run and submit the at job OK.  I
chould submit the at job from the command line and it would run OK and
re-submit the job.  But the at job submitted from within the at job
would not run.  'atrun' complained about "Userid %lu mismatch name %s
- aborting job %".


So, I halled out the source for 'atrun'.  It's really nifty having
source.  I've halled it out several times.  I usually just find that
I'm not using the program right.

I found that the mismatch is a mismatch between the userid that the at
job gets executed as (mine) and the username that 'at' plans to send
mail to when the job completes.  'atrun' gets the mailname from the
head of the batch file (written by 'at' when the job is submitted).
On jobs submitted from my login shell the mailname and execution UID
would match.  On jobs submitted from an 'at' job the mailname was
wrong.

So I took a look at the source for 'at'.  In at.c, 'at' finds the
mailname by looking in:

 1. getlogin ();
 2. getenv("LOGNAME");
 3. getpwuid(getuid())->pw_name;

Now, when the job is run from 'atrun' it does not have my login name,
getlogin() return "root".  So 'root' gets written as the mail name,
dooming the job to failure.

Further, at the point where 'at' determins the mailname it's running
with enhanced privleges so getuid() returns 1, "daemon".  

I fixed up my version of 'at.c' by:

 1. commenting out the line that gets mailname from getlogin();
 2. calling getpwuid with the varialbe real_uid, which is previously
    setup to be the user's uid.

Diffs appended to this message.

The second change (getpwuid) I do believe is a bug in at.c.  But is 
seldom, if ever, encoutered because 'at' generally manages to get a
mailname from getlogin() or "LOGNAME".

The first could be considered a bug in at.c or a bug in getlogin().
Should getlogin() return non NULL when this really is not a login
shell?  

Hope this is useful.

Tom Unger




raindrop# diff -c /cdrom/usr/src/usr.bin/at/at.c at.c
*** /cdrom/usr/src/usr.bin/at/at.c      Mon May 29 08:29:21 1995
--- at.c        Mon Apr  1 19:03:58 1996
***************
*** 274,288 ****
      /* Get the userid to mail to, first by trying getlogin(), which reads
       * /etc/utmp, then from LOGNAME, finally from getpwuid().
       */
!     mailname = getlogin();
!     if (mailname == NULL)
!       mailname = getenv("LOGNAME");
  
      if ((mailname == NULL) || (mailname[0] == '\0')
        || (strlen(mailname) > 8) || (getpwnam(mailname)==NULL))
      {
!       pass_entry = getpwuid(getuid());
!       if (pass_entry != NULL)
            mailname = pass_entry->pw_name;
      }
  
--- 274,287 ----
      /* Get the userid to mail to, first by trying getlogin(), which reads
       * /etc/utmp, then from LOGNAME, finally from getpwuid().
       */
!     /*mailname = getlogin();*/
!     mailname = getenv("LOGNAME");
  
      if ((mailname == NULL) || (mailname[0] == '\0')
        || (strlen(mailname) > 8) || (getpwnam(mailname)==NULL))
      {
!       pass_entry = getpwuid(real_uid);
!       if (pass_entry != NULL) 
            mailname = pass_entry->pw_name;
      }