Usenet comp.sys.dec (1990-2013)
 help / color / mirror / Atom feed
From: arnej@Lise.Unit.NO (Arne Henrik Juul)
Subject: login and rlogind and ULTRIX brain-damage
Date: Fri, 7 Aug 92 14:07:37 GMT	[thread overview]
Message-ID: <1992Aug7.140737.1336@ugle.unit.no> (raw)
In-Reply-To: 1992Aug7.034507.9708@decuac.dec.com

In article <1992Aug7.034507.9708@decuac.dec.com>, mjr@hussar.dco.dec.com (Marcus J. Ranum) writes:
 > 
 > 	Funny you should ask that. I had exactly the same problem,
 > and I resorted to porting the BSD login/getty/telnetd/rlogind suite
 > to ULTRIX, so I could add a variety of mysterious things to them.
 > 
 > 	In my case, I *am* *not* over-using my license, so I consider
 > it acceptable to do this. After all, I am still following the terms
 > of my licensing agreement, even if the mechanism for enforcing it
 > has been disabled. Sources for my port of login/rlogind, etc are
 > available for FTP from decuac.dec.com in pub/sources/bsd-login.tar.Z
 > *BUT* it's your responsibility to maintain the terms of your
 > licensing agreement with Digital, or you're risking all sorts of
 > trouble.
 > [Note that my sources will disable DECnet login via dlogind and
 > will disable login via dxprompter. Neither of which I miss especially.
 > You mileage may vary.]
 > 
 > mjr.

I have earlier tried porting the BSD Networking-II login/rlogind to
Ultrix, and this thread caused me to take up that work again and look
closer at it.

The really big problem I had, was actually caused by the 'program
environment' option in Ultrix - it's really very brain-damaged!
(in my not-so-very-humble opinion).

The net-II rlogind uses the posix specific features quite extensively,
and so far I haven't had any luck with making it work without the -YPOSIX
option.

At first, it seems reasonable to compile with -YPOSIX - you get a
little different semantics on some functions, and if your program
is written for those semantics, all is fine. Right? Wrong!

Actually, the semantics of *system calls* are different, and worst
of all: The program environment is *inherited* between processes.

This means that a program compiled with -YPOSIX will put itself
(and children) in posix mode, a program compiled with -YSYSV will
put itself (and children) in system V mode, but:
a program compiled with -YBSD or without -Y option will only
inherit the parent's process mode.

This is bad.
It is even worse: It is inconsistent, buggy, badly documented, and
crashes important system programs.

Now the default shell (for root and users) on Ultrix is /bin/csh.
/bin/csh is *very* dependant upon BSD semantics on system calls, it
seems - my guess it uses some TIOCSPGRP features (or maybe setpgrp)
which only exists there.

When I compiled rlogind with -YPOSIX, rlogind exec'd /bin/login,
and login exec'd /bin/csh, csh *inherited* the process mode, and
promptly stopped working.

Now to the solution: Ugly as it was, I decided to switch
process mode before exec'ing /bin/login. After hunting through
those RTFMs, I found the call setsysinfo, which seemed to be
what I wanted. Now setsysinfo is a strange call doing
several different things, and to set the programming mode,
I needed to call with a 'name/value pair' inside a buffer.

What was nowhere documented was what datatype the corresponding
aruments was: char, short, int? Even worse, the corresponding
call getsysinfo() was not documented either. I decided to
give it a try and see what I actually got. The result was:
getsysinfo returns a short into the buffer.

OK, I thought, then probably setsysinfo(), also, uses shorts.
This did not work. So I experimented a bit with setsysinfo,
and found it actually needs ints (4-byte values).

After all this, I was a bit let down, so this was
my addition to the code:


#ifdef STUPID_UGLY_ULTRIX_BUG
			/*
                         *  This sets the 'program environment'
			 *  back to BSD (default) mode. It should
                         *  never have been necessary. You are not
                         *  expected to understand this.
                         */
                        setsysinfo(1,"\3\0\0\0\0\0\0\0",1,0,0);
#endif


...ah, the answer that noone wanted. Makes you barf...


Now in spite of my ranting, I hope someone at DEC has
read through all of this and can give the ULTRIX kernel
designers some hints:
  1) different execution modes for the exact same
     executable is a Bad Thing.
  2) it would be better just to link with different
     C libraries.
  3) if one *has* different execution modes, these should
     NOT be inherited when exec'ing.
  4) The implementation of setsysinfo()/getsysinfo()
     needs some polishing.
  5) The documentation of setsysinfo()/getsysinfo() needs
     a lot of polishing.


In case anyone else needs it, I have written to small programs
setmode and showmode to set and display the execution enviroment
bits for you, which also demonstrate how to use the setsysinfo()
and getsysinfo() calls for this purpose. These two programs should
be a bit more readable. I know a friend of mine really struggled
with this some time ago, so it's probably something you need
to know when compiling with -YPOSIX.


/* showmode.c */

#include <sys/types.h>
#include <sys/sysinfo.h>
#include <sys/exec.h>
#include <errno.h>
#include <stdio.h>

/* Brain damage alert! While getsysinfo returns a short into the
   buffer, as you can see, the corresponding call setsysinfo() needs
   4-byte ints! */

int main(argc, argv)
     int argc;
     char **argv;
{
     short sysmode;
     
     getsysinfo(GSI_PROG_ENV,(char *)&sysmode,2,0,0);
     switch (sysmode) {
       case A_BSD:
          printf("Current execution mode is BSD\n");
          break;
       case A_SYSV:
          printf("Current execution mode is SYSTEM_FIVE\n");
          break;
       case A_POSIX:
          printf("Current execution mode is POSIX\n");
          break;
       default:
          printf("Error: Execution mode is unknown (%d)\n", sysmode);
          exit(errno);
     }
     exit(0);
}



/* setmode.c */

#include <sys/types.h>
#include <sys/sysinfo.h>
#include <sys/exec.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>

/*
  Brain damage alert!
  The setsysinfo() call used here takes 'name/value pairs' when
  using the SSI_NVPAIRS op. Actually, pairs of 4-byte ints
  are used, but this is nowhere documented.
  
  Even worse:
  Programs compiled with -YSYSTEM_FIVE or -YPOSIX will set their
  own execution mode as shown here, so you can't force them
  to BSD mode with this program. Programs compiled with -YBSD,
  however, will inherit the mode from their parent, so you
  can use this program to set their mode back to BSD, since many
  of them actually needs this - such as DECs /bin/csh.
*/

int main(argc, argv)
     int argc;
     char **argv;
{
     int namerep;
     int sysmode;
     int pair[2];
     
     if (argc < 3) {
          fprintf(stderr, "Usage: %s bsd|sysv|posix program parameters ...\n",
                  argv[0]);
          exit(1);
     }
     
     namerep = SSIN_PROG_ENV;
     argv++;
     if (!strcmp(*argv, "bsd"))
          sysmode = A_BSD;
     else if (!strcmp(*argv, "sysv"))
          sysmode = A_SYSV;
     else if (!strcmp(*argv, "posix"))
          sysmode = A_POSIX;
     else {
          fprintf(stderr, "Unknown execution mode %s\n", *argv);
          exit(1);
     }
     
     pair[0]=namerep;
     pair[1]=sysmode;
     if (setsysinfo(SSI_NVPAIRS,(char *)pair,1,0,0))
          perror("setsysinfo() call failed");
     
     argv++;
     execvp(*argv, argv);
     fprintf(stderr,"execvp failed for ");
     perror(*argv);
     exit(errno);
}




In the hope that someone actually reads this...

Arne H. Juul  --  arnej@lise.unit.no  --  University of Trondheim, Norway


  reply	other threads:[~1992-08-07 14:07 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1992-08-04 22:57 # of users allowed on ULTRIX workstation Mike Santangelo (UNIX/VMS Sysmgr)
1992-08-05  1:39 ` Marcus J. Ranum
1992-08-05  8:28   ` Martyn Johnson
1992-08-07  3:45     ` Marcus J. Ranum
1992-08-07 14:07       ` Arne Henrik Juul [this message]
1992-08-09 18:14         ` login and rlogind and ULTRIX brain-damage Marcus J. Ranum
1992-08-07 20:22       ` # of users allowed on ULTRIX workstation Thor Lancelot Simon
1992-08-09 18:28         ` Marcus J. Ranum
1992-08-10 14:17           ` Joel Andrew Huddleston
1992-08-10 20:50             ` Dale Cook
1992-08-07  9:35   ` Philip Leverton
1992-08-10 17:11   ` J. Daniel Smith
1992-08-05  1:50 ` Matt Thomas
1992-08-05  6:03 ` Thor Lancelot Simon
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox