home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.wizards
- Path: sparky!uunet!haven.umd.edu!darwin.sura.net!convex!news.utdallas.edu!corpgate!bnrgate!bcrka451!norm
- From: norm@bnr.ca (Norm MacNeil)
- Subject: Re: /etc/utmp trouble
- Message-ID: <1992Sep15.190255.18410@bcrka451.bnr.ca>
- Originator: norm@bcrks122
- Sender: 5E00 Corkstown News Server
- Reply-To: norm@bnr.ca
- Organization: Bell-Northern Research Ltd.
- References: <92259.131154KLAWITT@DMSWWU1A.UNI-MUENSTER.DE>
- Date: Tue, 15 Sep 1992 19:02:55 GMT
- Lines: 50
-
-
- In article <92259.131154KLAWITT@DMSWWU1A.UNI-MUENSTER.DE>, Holger Klawitter, Informatik <KLAWITT@DMSWWU1A.UNI-MUENSTER.DE> writes:
- > Hi!
- >
- > Since nobody in comp.unix.questions dared to answer my question ill try
- > this group. I am looking for a program to edit the /etc/utmp file
- > in order to change the ownership of the tty('s ?) of xdm.
- > (A patch into xdm would be even better.)
- > This tty should be given to the user; otherwise programs like printtool,
- > xlock(the MIT-one) or xvnews believe to belong to xdm.
- >
-
- Well, to read the tty file, you would use something like the following:
- /*--------------------------------------*/
- /* Given you've included the appropriate headers & defined:
- * char *TTYName;
- FILE *F;
- struct utmp *UP;
- */
- TTYName = (char *) ttyname(0);
- if ((F = fopen("/etc/utmp", "r")) != NULL) {
- if ((UP = (struct utmp *) malloc(sizeof(struct utmp))) != NULL) {
- while ((fread(UP, sizeof(struct utmp), 1, F) == 1)
- && (strcmp(UP->ut_line, TTYName) != 0));
- if (UP != NULL) {
- #if defined(SUN) || defined(SUNOS)
- printf("Username is %s\n", UP->ut_name);
- #else
- printf("Username is %s\n", UP->ut_user);
- #endif
- printf("Hostname is %s\n", UP->ut_host);
- /* etc... */
- /*--------------------------------------*/
-
- So, given the above to read the file, you could write the records to a new file
- and subsequently replace the above file with the new file after closing
- /etc/utmp. I'm not sure if this would work and not sure if it would royally
- screw things up but this is how you find info from utmp.
-
- BTW, I am aware of the getutmp() routines however, not every platform has them
- so I use the above for portability.
-
- Storm.
-
- --
- +-----------------------------------------------------------------------+
- Norm MacNeil Phone: (613) 763-7497
- CAD Operation Fax: (613) 763-3317
- Bell-Northern Research Ltd. EMail: norm@bnr.ca (INTERNET)
- #include <disclaimer.std> "Roller bladers do it in-line!"
-