From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10b612,bdfafa920547ff8d X-Google-Attributes: gid10b612,public X-Google-Thread: 1164f8,bdfafa920547ff8d X-Google-Attributes: gid1164f8,public X-Google-ArrivalTime: 1992-08-07 00:16:22 PST Xref: sparky comp.unix.ultrix:6103 comp.sys.dec:4396 Newsgroups: comp.unix.ultrix,comp.sys.dec Path: sparky!uunet!mcsun!sunic!ugle.unit.no!lise.unit.no!arnej From: arnej@Lise.Unit.NO (Arne Henrik Juul) Subject: login and rlogind and ULTRIX brain-damage Message-ID: <1992Aug7.140737.1336@ugle.unit.no> Keywords: ULTRIX,setsysinfo,getsysinfo Sender: news@ugle.unit.no (NetNews Administrator) Reply-To: arnej@lise.unit.no Organization: Norwegian Institute of Technology References: <1992Aug4.225700.19402@socrates.umd.edu> <1992Aug5.013952.5955@decuac.dec.com> <1992Aug5.082830.19956@cl.cam.ac.uk> <1992Aug7.034507.9708@decuac.dec.com> Date: Fri, 7 Aug 92 14:07:37 GMT 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 #include #include #include #include /* 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 #include #include #include #include #include /* 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