home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 5 / DATAFILE_PDCD5.iso / utilities / s1 / secure307 / InHere / !Secure3 / c / !SecureSrc / Secure < prev   
Text File  |  1994-01-05  |  23KB  |  812 lines

  1. /***************************************************************************/
  2. /***************************************************************************/
  3. /**                                                                       **/
  4. /**    Name : Secure3.                                                    **/
  5. /** Purpose : Desktop password protection.                                **/
  6. /**  Author : Anthony Brion, 1993,94.                                     **/
  7. /** Version : 3.05 (05 Jan 1993)                                          **/
  8. /**                                                                       **/
  9. /***************************************************************************/
  10. /***************************************************************************/
  11.  
  12. /***************************************************************************/
  13. /***************************************************************************/
  14. /**                                                                       **/
  15. /** Library #includes.                                                    **/
  16. /**                                                                       **/
  17. /***************************************************************************/
  18. /***************************************************************************/
  19.  
  20. #include "res.h"       /* Resources                                        */
  21. #include "resspr.h"    /* Sprite resources                                 */
  22. #include "msgs.h"      /* Provide support for message resource file        */
  23. #include "event.h"     /* Central processing for window system events      */
  24. #include "win.h"       /* Centraql management of RiscOS windows            */
  25. #include "werr.h"      /* Wimp error reporting                             */
  26. #include "dbox.h"      /* Creation/deletion/manipulation of dialogue boxes */
  27. #include "baricon.h"   /* Support placing of an icon on the icon bar       */
  28. #include "menu.h"      /* Menu creation/deletion/manipulation              */
  29. #include "os.h"        /* Low-level RiscOS routines                        */
  30. #include "wimpt.h"     /* Low-level wimp functionality                     */
  31. #include "kernel.h"    /* Machine-level RiscOS routines                    */
  32. #include "template.h"  /* Template file management                         */
  33. #include "wimp.h"      /* C interface to RiscOS wimp routines              */
  34.  
  35. #include <ctype.h>
  36. #include <stdlib.h>
  37. #include <string.h>
  38.  
  39. /***************************************************************************/
  40. /***************************************************************************/
  41. /**                                                                       **/
  42. /** Macros.                                                               **/
  43. /**                                                                       **/
  44. /***************************************************************************/
  45. /***************************************************************************/
  46.  
  47. #define UNUSED(x)         x = x
  48. #define BEEP              printf("\a")
  49.  
  50. #define VERSION           "Secure version 3.05"
  51. #define RETURN_key         13
  52. #define PASSWORD_max       17
  53. #define RESET_TYPE        253
  54. #define POWER_ON            1
  55.  
  56. /* Iconbar menu options */
  57. #define bar_info            1
  58. #define bar_setup           2
  59. #define bar_chgcode         3
  60. #define bar_quit            4
  61.  
  62. /* Password dialogue box fields */
  63. #define VERSION_field      22
  64. #define SVERSION_field      2
  65. #define NAME_field         19
  66. #define ADDRESS1_field     20
  67. #define ADDRESS2_field     18
  68. #define PHONE_field         3
  69. #define MODEL_field         4
  70. #define SERIAL_field        5
  71. #define PASSWORD_field      6
  72. #define STEXT_field         3
  73.  
  74. /***************************************************************************/
  75. /***************************************************************************/
  76. /**                                                                       **/
  77. /** Global data.                                                          **/
  78. /**                                                                       **/
  79. /***************************************************************************/
  80. /***************************************************************************/
  81.  
  82. /* Task handle */
  83. static wimp_t taskhandle;
  84.  
  85. /* Version string */
  86. static char secure_version[] = "3.05 (05 Jan 1994)";
  87.  
  88. /* Iconbar menu handle */
  89. static menu secure_menu;
  90.  
  91. /* Iconbar text */
  92. static char Iconbar_text[] = "Secure3";
  93.  
  94. /* Password dialogue box handle */
  95. static dbox secure;
  96.  
  97. /* Input password from dialogue box */
  98. static char input_password[PASSWORD_max + 1];
  99.  
  100. /* Break key status */
  101. static int break_status;
  102.  
  103. /* Setup file handle */
  104. static FILE *setup;
  105.  
  106. /* ID A */
  107. static char ida[10];
  108.  
  109. /* ID B */
  110. static char idb[10];
  111.  
  112. /* Setup file data */
  113. static char startup;
  114. static char ibar;
  115. static char poweron;
  116. static char password[PASSWORD_max + 1];
  117. static char name[36];
  118. static char add1[36];
  119. static char add2[36];
  120. static char tel[36];
  121. static char model[36];
  122. static char serial[36];
  123. static char text[28];
  124.  
  125. /***************************************************************************/
  126. /***************************************************************************/
  127. /**                                                                       **/
  128. /** Functions.                                                            **/
  129. /**                                                                       **/
  130. /***************************************************************************/
  131. /***************************************************************************/
  132.  
  133. /*************************************************************************-*/
  134. /* Encode/Decode data.                                                     */
  135. /*************************************************************************-*/
  136. static void eor_data(char *string)
  137. {
  138.   int count;
  139.  
  140.   for (count=0;count < 35;count++)
  141.   {
  142.     if (string[count] == NULL)
  143.       break;
  144.     
  145.     string[count] ^= '\001' + count;
  146.   }
  147.  
  148.   return;
  149. }
  150.  
  151. /***************************************************************************/
  152. /* Encode/Decode password.                                                 */
  153. /***************************************************************************/
  154. static void eor_password(void)
  155. {
  156.   int count;
  157.  
  158.   for (count=0;count < PASSWORD_max;count++)
  159.   {
  160.     if (password[count] == NULL)
  161.       break;
  162.     
  163.     password[count] ^= '\001' + count;
  164.   }
  165.  
  166.   return;
  167. }
  168.  
  169. /***************************************************************************/
  170. /* Read a string (including spaces) from a file.                           */
  171. /***************************************************************************/
  172. static void freadstring(char *string)
  173. {
  174.   int count = 0;
  175.   char c;
  176.  
  177.   do
  178.   {
  179.     c = fgetc(setup);
  180.     *(string + count++) = c;
  181.   }
  182.   while (c != NULL);
  183.  
  184.   return;
  185. }
  186.  
  187. /***************************************************************************/
  188. /* Load setup file.                                                        */
  189. /***************************************************************************/
  190. static void load_setup(void)
  191. {
  192.   int error;
  193.  
  194.   setup = fopen("<Secure3$dir>.setup","r");
  195.  
  196.   startup = fgetc(setup);
  197.   ibar    = fgetc(setup);
  198.   poweron = fgetc(setup);
  199.   freadstring(password); eor_password();   /* Decode password                      */
  200.   freadstring(name);     eor_data(name);   /* Decode name                          */
  201.   freadstring(add1);     eor_data(add1);   /* Decode address line one              */
  202.   freadstring(add2);     eor_data(add2);   /* Decode address line two              */
  203.   freadstring(tel);      eor_data(tel);    /* Decode telephone number              */
  204.   freadstring(model);    eor_data(model);  /* Decode modeel number                 */
  205.   freadstring(serial);   eor_data(serial); /* Decode serial number                 */
  206.   freadstring(text);
  207.  
  208.   error = fclose(setup);
  209.  
  210.   return;
  211. }
  212. /***************************************************************************/
  213. /* Save setup file.                                                        */
  214. /********************************************