Newsgroups: bit.listserv.next-l
Date:         Mon, 12 Oct 1992 08:37:23 -0500
Reply-To:     sears@uh.edu
From:         "Paul S. Sears" <sears@TREE.EGR.UH.EDU>
Subject:      Re: MOTD work under 3.0? (a simple fix)

(This was sent to the list because this might be of general interest to
all users).

There is a problem with MOTD under 3.0.  As far as I could tell, it the
variable do_motdL is set to NO which means, don't display the MOTD window,
since the user has already seen it.  My hack simply consists of setting
the variable do_motdL to YES.  The side affect is that the MOTD window is
ALWAYS displayed on login (Actually, a good thing IMHO, since we sometimes
update our MOTD message more than once a day...)  I also modified the .nib
file so that it will have a larger window.

                               [NXApp setDo_Motd:(do_motdL = YES)];

Below is the MOTD_main.m file.  Recompile MOTD with the new main.m file
and everything should work ok.  My tiny hack is commented about 3/4 into
the file.  If anyone can figure out what is going on in the wtmp, or
defaults database (this is what MOTD checks to see if the user has logged
on since the MOTD messages was updated) feel free to fix it and send me
the patch...

---
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."



/* Program:
 *
 *              MOTD - 'Motto of the day' window
 *
 * Author:
 *
 *              Christopher Lane (lane@sumex-aim.stanford.edu)
 *              Symbolic Systems Resources Group
 *              Knowledge Systems Laboratory
 *              Stanford University
 *
 * Contributors:
 *
 *              Izumi Ohzawa (izumi@violet.berkeley.edu)
 *              Group in Neurobiology/School of Optometry
 *              University of California, Berkeley
 *
 *              Steve Hayman (sahayman@cs.indiana.edu)
 *              Computer Science Department Workstation Manager
 *
 * Date:
 *
 *              9 January 1991
 *
 * Copyright:
 *
 *              1989, 1990 & 1991 by The Leland Stanford Junior
University.
 *      May be distributed without restriction for non-commercial use.
 *
 */

#import "MOTD.h"

void timer(DPSTimedEntry teNumber, double now, id self)
{
        static int seconds = -1;

        static char string[] = "Hold (000)";


        if (seconds == -1) seconds = [self getWait];

        if ([self getHold] == NO) {
                if (seconds-- <= 0) [self terminate:self];
                else if ([self getDo_Motd]) {
                        (void) sprintf(string, "Hold (%3d)", seconds);
                        [[self getHoldButton] setTitle:string];
                        }
                }
}

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);

}
Comments: Gated by NETNEWS@AUVM.AMERICAN.EDU