grab_vcsa.pp 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. program grab_vcsa;
  2. {
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 2005 by Daniël Mantione
  5. member of the Free Pascal development team.
  6. VCSA grabber program for Linux.
  7. See the file COPYING.FPC, included in this distribution,
  8. for details about the copyright.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. }
  13. uses baseunix,termio;
  14. {This program helps the video unit to use /dev/vcsa* to provide high
  15. quality output.
  16. Normally, when you login, the owner of the tty you are running on,
  17. /dev/tty0-31 is set to your username. Weird enough, this is not done
  18. with the video buffer devices belonging to that tty, /dev/vcs0-31
  19. and /dev/vcsa0-31. This makes it impossible to do high quality text
  20. mode video output.
  21. This program, designed to be run suid root, reads the owner and mode
  22. of the tty, and assigns them to the corresponding vcs and vcsa device.}
  23. {Security design:
  24. - It has been checked if the user can provide any input to the program.
  25. The only input in the program is stdinputhandle, which cannot be
  26. controlled by the user. The user has therefore no control in any way
  27. about the code flow in the program; the code that is going to be
  28. executed is fixed no matter what a user does.
  29. - Outputs are the file permissions of /dev/vcs* and /dev/vcsa*. It has
  30. been considered if users could use the program this way to gain rights
  31. they should not have. By having access to /dev/vcs* and /dev/vcsa*
  32. the user can garble his own screen. This should not be a problem.
  33. After the user has logged out /dev/vcs* and /dev/vcsa* are automatically
  34. changed back to root. This removes the need for us to change permissions
  35. back again. If we would change permissions back, it would be useless, the
  36. user can kill the process before it changes back permissions.
  37. - Normal users cannot write to /dev/ and can therefore not use the program
  38. do change the permissions of other files than the actual devices.
  39. }
  40. const result_success=0;
  41. result_not_on_console=1;
  42. result_stat_error=2;
  43. result_chown_error=3;
  44. result_chmod_error=4;
  45. var thistty:string;
  46. vcs,vcsa:string;
  47. ttystat:stat;
  48. begin
  49. exitcode:=result_not_on_console;
  50. thistty:=ttyname(stdinputhandle);
  51. if isatty(stdinputhandle)=1 then
  52. begin
  53. { running on a tty, find out whether locally or remotely }
  54. if (length(thistty)>=9) and
  55. (copy(thistty,1,8)='/dev/tty') and
  56. (thistty[9] in ['0'..'9']) then
  57. begin
  58. {We are running on the Linux console}
  59. if fpstat(thistty,ttystat)<>0 then
  60. halt(result_stat_error);
  61. vcs:='/dev/vcs'+copy(thistty,9,255);
  62. vcsa:='/dev/vcsa'+copy(thistty,9,255);
  63. {Change owner and group to that of /dev/tty??.}
  64. if fpchown(vcs,ttystat.uid,ttystat.gid)<>0 then
  65. halt(result_chown_error);
  66. if fpchown(vcsa,ttystat.uid,ttystat.gid)<>0 then
  67. halt(result_chown_error);
  68. {Change permissions to that of /dev/tty??.}
  69. if fpchmod(vcs,ttystat.mode)<>0 then
  70. halt(result_chmod_error);
  71. if fpchmod(vcsa,ttystat.mode)<>0 then
  72. halt(result_chmod_error);
  73. exitcode:=result_success;
  74. end;
  75. end;
  76. end.