From: sears@tree.egr.uh.edu (Paul S. Sears)
Newsgroups: comp.sys.next.sysadmin
Subject: Re: having problem with MOTD
Date: 15 Dec 1992 16:04:10 GMT
Organization: University of Houston
Reply-To: sears@tree.egr.uh.edu
NNTP-Posting-Host: thanatos.egr.uh.edu

In article <1992Dec13.030652.4636@moksha.uucp> mgb@moksha.uucp (Michael  
Branton) writes:
#In article <1992Dec11.113707.24229@dmu.ac.uk> sfch@dmu.ac.uk (Simon  
Harwood)  
#writes:
#> In article <1992Dec7.010703.3457@utagraph.uta.edu> root@mecad.uta.edu  
#(Operator) writes:
#> >
#> There is a MOTD application which you can anonymous ftp available on
#> sonata.cc.purdue.edu. There are at least 2 versions available which are
#> 
#> 	pub/next/2.0-release/source/MOTD.tar.Z
#> and
#> 	pub/next/1.0-release/source/MOTD.tar.Z
#> 
#> 		Simon..
#
#
#I've got this. It worked fine under 2.0, but under 3.0, it seems be  
broken. I  
#get notification of new mail, but not the motd.  Anyone else have this  
problem  
#? Anyone know how to fix it ?
#

Yes.  There is a bug in MOTD_main.m that has to do with the OnlyOnce  
default.

I have included the revelant section of code in MOTD_main.m.  The hack is  
commented in the code.  This is main() from MOTD_main.m.  However, this is  
just a quick hack, and it has the side effect of causing MOTD to _always_  
display the motd messages on every login.  For my site, this is a good  
thing, as sometimes news changes quite often, plus we have some class  
accounts and not everyone was seeing the messages before...

void main(int argc, char *argv[])
{
        FILE *f_utmp;
        struct stat s_stat;
        struct utmp s_utmp;
        struct passwd *p_passwd;
        BOOL flag, do_motdL = YES;
        MailLevel maillevelL = NONE;
        char pathnamebuf[MAXPATHLEN];

        NXApp = [MOTD new];
    
        if (!(flag = (--argc && (p_passwd = getpwnam(argv[argc])) !=  
NULL))) p_passwd = getpwuid((int) getuid());

        [[[NXApp setLoginHook:flag] setMailLevel:maillevelL]  
setDo_Motd:do_motdL];

        if (p_passwd != NULL) {
                [[NXApp setUserName:p_passwd->pw_name]  
setUID:p_passwd->pw_uid];                
                if (flag) { /* only check if LoginHook */
                        (void) strcpy(pathnamebuf, MAILDIR); /* check for  
mail arrival */
                        (void) strcat(pathnamebuf, [NXApp getUserName]);
                        if (stat(pathnamebuf, &s_stat) != CERROR &&  
s_stat.st_size != 0)
                        [NXApp setMailLevel:(maillevelL = (s_stat.st_atime  
<= s_stat.st_mtime) ? NEW : OLD)];
                        }

                if (strncmp(getDefault("OnlyOnce"), "Yes", 1) == EQ &&
                        stat([NXApp getFile], &s_stat) != CERROR &&  
(f_utmp = fopen(WTMPFILE, "r")) != NULL) {
                        while(fread(&s_utmp, sizeof(s_utmp), 1, f_utmp))
                                if (s_stat.st_mtime < s_utmp.ut_time &&
                                        strncmp(s_utmp.ut_name, [NXApp  
getUserName], sizeof(s_utmp.ut_name)) == EQ)
                                        if ((flag &&  
strncmp(s_utmp.ut_line, TTYDEVICE, sizeof(s_utmp.ut_line)) == EQ) ||
                                                (strncmp(s_utmp.ut_line,  
FTPPREFIX, sizeof(s_utmp.ut_line)) != EQ)) {
/* Modified for NS 3.0.  MOTD is always display
   when a user logs on.  To revert to original
   state, change do_motdL = YES to do_motdL = NO
*/
                                                [NXApp  
setDo_Motd:(do_motdL = YES)];
                                                break; /* while() */
                                                }
                        (void) fclose(f_utmp);
                        }
                }

      
        if (do_motdL || maillevelL != NONE) { /* if motd file not seen yet  
OR if there is mail */
                [NXApp loadNibSection:"MOTD.nib" owner:NXApp];
                if (do_motdL) [[NXApp getCancelButton] setEnabled:flag];    
                [[NXApp run] free];
                }
        else [NXApp free];
        exit(EXIT_SUCCESS);     
}


#-Michael
#  mgb@moksha.UUCP
#  mgb@stetson.BITNET
#
#  NeXT mail welcome !

--
Paul S. Sears                *  sears@uh.edu (NeXT Mail OK)
The University of Houston    *  suggestions@tree.egr.uh.edu (NeXT
Engineering Computing Center *  comments, complaints, questions)
NeXT System Administration   *  DoD#1967 '83 NightHawk 650SC 
          >>> SSI Diving Certification #755020059 <<<
"Programming is like sex: One mistake and you support it a lifetime."
Newsgroups: comp.sys.next.sysadmin