home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / unix / wizards / 3915 < prev    next >
Encoding:
Text File  |  1992-09-15  |  2.4 KB  |  64 lines

  1. Newsgroups: comp.unix.wizards
  2. Path: sparky!uunet!haven.umd.edu!darwin.sura.net!convex!news.utdallas.edu!corpgate!bnrgate!bcrka451!norm
  3. From: norm@bnr.ca (Norm MacNeil)
  4. Subject: Re:    /etc/utmp trouble
  5. Message-ID: <1992Sep15.190255.18410@bcrka451.bnr.ca>
  6. Originator: norm@bcrks122
  7. Sender: 5E00 Corkstown News Server
  8. Reply-To: norm@bnr.ca
  9. Organization: Bell-Northern Research Ltd.
  10. References:  <92259.131154KLAWITT@DMSWWU1A.UNI-MUENSTER.DE>
  11. Date: Tue, 15 Sep 1992 19:02:55 GMT
  12. Lines: 50
  13.  
  14.  
  15. In article <92259.131154KLAWITT@DMSWWU1A.UNI-MUENSTER.DE>, Holger Klawitter, Informatik <KLAWITT@DMSWWU1A.UNI-MUENSTER.DE> writes:
  16. > Hi!
  17. > Since nobody in comp.unix.questions dared to answer my question ill try
  18. > this group. I am looking for a program to edit the /etc/utmp file
  19. > in order to change the ownership of the tty('s ?) of xdm.
  20. > (A patch into xdm would be even better.)
  21. > This tty should be given to the user; otherwise programs like printtool,
  22. > xlock(the MIT-one) or xvnews believe to belong to xdm.
  23.  
  24. Well, to read the tty file, you would use something like the following:
  25. /*--------------------------------------*/
  26. /* Given you've included the appropriate headers & defined:
  27.  * char *TTYName;
  28.    FILE *F;
  29.    struct utmp *UP;
  30.  */
  31.   TTYName = (char *) ttyname(0);
  32.   if ((F = fopen("/etc/utmp", "r")) != NULL) {
  33.     if ((UP = (struct utmp *) malloc(sizeof(struct utmp))) != NULL) {
  34.       while ((fread(UP, sizeof(struct utmp), 1, F) == 1)
  35.           && (strcmp(UP->ut_line, TTYName) != 0));
  36.       if (UP != NULL) {
  37. #if defined(SUN) || defined(SUNOS)
  38.   printf("Username is %s\n", UP->ut_name);
  39. #else
  40.   printf("Username is %s\n", UP->ut_user);
  41. #endif
  42.   printf("Hostname is %s\n", UP->ut_host);
  43. /* etc... */
  44. /*--------------------------------------*/
  45.  
  46.   So, given the above to read the file, you could write the records to a new file
  47.   and subsequently replace the above file with the new file after closing
  48.   /etc/utmp.  I'm not sure if this would work and not sure if it would royally
  49.   screw things up but this is how you find info from utmp.
  50.  
  51.   BTW, I am aware of the getutmp() routines however, not every platform has them
  52.   so I use the above for portability.
  53.  
  54.     Storm.
  55.   
  56. -- 
  57. +-----------------------------------------------------------------------+
  58.  Norm MacNeil                     Phone: (613) 763-7497
  59.  CAD Operation                      Fax: (613) 763-3317
  60.  Bell-Northern Research Ltd.      EMail: norm@bnr.ca (INTERNET)
  61.  #include <disclaimer.std>       "Roller bladers do it in-line!"
  62.