home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / machack / Hacks96 / PanelHack.sit / PanelHack / panelhack.c < prev    next >
C/C++ Source or Header  |  1996-06-23  |  2KB  |  112 lines

  1. /*
  2.     PanelHack - a hack on the Apple Network Server (AIX)
  3.     ====================================================
  4.  
  5.     Mike Webb
  6.     Stuart S. Schmukler
  7.     Rob Hagopian
  8.     Oleg Kiselyov
  9.     and random other folk that helped us get the machine up, but weren't around
  10.     when I typed in this comment.
  11.  
  12.     This hack writes silly strings to the display panel on the front of
  13.     the Apple Network Server (AIX) box.
  14.  
  15.     panelhack -h            dumps the panel hack usage string to the display panel
  16.     panelhack <string>        dumps <string> to the display panel
  17.     panelhack                dumps a random string to the display panel
  18.  
  19.     You need root privilige to do this.
  20.  
  21.     This is a hack.  It is only a hack.  It does nasty things to NVRAM, so be careful
  22.     if you twiddle things so that you don't fry your system by writing into some other
  23.     part of NVRAM.
  24.  
  25. */
  26.  
  27. #include <stdlib.h>
  28. #include <stdio.h>
  29. #include <sys/types.h>
  30. #include <sys/cfgdb.h>
  31. #include <sys/cfgodm.h>
  32. #include <cf.h>
  33. #include <fcntl.h>
  34.  
  35. #define _APPLE
  36. #include <sys/mdio.h>
  37.  
  38. #define max(x, y) ((x) > (y) ? (x) : (y))
  39. #define min(x, y) ((x) < (y) ? (x) : (y))
  40. #define PANEL "/dev/nvram"
  41.  
  42. /* main function code */
  43.  
  44. static
  45. char* strings[]=
  46. {
  47.     " Welcome to MacHack This is Panel Hack, ---- the Un-PDA ----",
  48.     "Yes, but this hack goes to eleven.",
  49.     "login: \001",
  50.     "segmentation fault, core dumped",
  51.     "Dammit Jim, I'm a display panel not a console.",
  52.     "C> _",
  53.     "(dbx) \001",
  54.     "] \001",
  55.     "$ \001",
  56.     "Dave, my mind is going. I can feel it going Dave. Dave? dave? d a v e...",
  57.     "Panelhack 1.0.99a update 233 rel 5.2b"
  58. };
  59.  
  60. main(argc, argv, envp)
  61. int     argc;
  62. char    *argv[];
  63. char    *envp[];
  64. {
  65.  
  66.     char    gStr[80];
  67.     char    buffer[32767];
  68.  
  69.     MACH_DD_IO mddRecord;
  70.  
  71.     int    fd;
  72.  
  73.     int idx = 0;
  74.     int len;
  75.  
  76.     if (argc > 1)
  77.     {
  78.         strcpy(buffer, argv[1]);
  79.  
  80.         if (strcmp(buffer, "-h") == 0)
  81.         {
  82.             strcpy(buffer, " Usage: panelhack [-h|<String>]");
  83.         }
  84.     }
  85.     else
  86.     {
  87.         /* And people think Lisp has too many parentheses... */
  88.     
  89.         strcpy(buffer, strings[(time(0) % (sizeof(strings) / sizeof(strings[0])))]);
  90.     }
  91.  
  92.     len = strlen(buffer);
  93.  
  94.     strncpy(gStr, &buffer[idx], min(len, sizeof(gStr)));
  95.     printf("%s\n", gStr);
  96.  
  97.     if (0 > (fd = open(PANEL, O_RDWR)))
  98.     {
  99.         exit -1;
  100.     }
  101.  
  102.     mddRecord.md_ofstring = (unsigned long)gStr;
  103.     mddRecord.md_ofbuflen = sizeof(gStr);
  104.     mddRecord.md_incr     = MV_BYTE;
  105.     mddRecord.md_ofbuf    = gStr;
  106.  
  107.     if (0 > ioctl(fd, MIOLCDSTRING, &mddRecord))
  108.     {
  109.         exit -2;
  110.     }
  111. }
  112.