Password Protection

The passwords for the different user levels are stored in a file. The file is set to require user level three and is only readable when MicroMonitor is at user level three. To secure the passwords, they are stored in scrambled form. The same scrambling algorithm can be used when someone enters a password. The scrambled version of what the user enters is compared to what is in the password file. Listing 5.15 is a very simple example of a scrambling function.

Listing 5.15: A Scrambling Function.
image from book
 static unsigned char *datatbl = "This_should_be_an_initialized_table_of_256_bytes_of_printable_ascii_characters ."; char * scrambler(char *string, char *setting, char *result) {     int offset, csum;     char *rp, *sp;     csum = 0;     sp = string;     while(*sp)         csum += *sp++;     rp = result;     /* Set up an offset into the data table that is based on the      * checksum of the incoming string plus the sum of the two      * setting characters...      */     offset = (csum + setting[0] + setting[1]) % 255;     /* For each character in the incoming string, replace it with a      * character in the data table.  If the incoming character has the      * 00001000 bit set, then use that character twice.      */     while(*string)     {         offset += (int)*string;         offset = offset % 255;         *rp = datatbl[offset];         if (*string & 8)         {             rp++;             offset += (int)*string;             offset = offset % 255;             *rp = datatbl[offset];         }         string++;         rp++;     }     *rp = 0;     return(result); } 
image from book
 

The ulvl command uses these two functions ( setCmdUlvl() and scrambler() ) for maintenance of the password file and for updating a commands user level.

Note 

When the system is first booted , the monrc file could contain all of the ulvl commands needed to adjust the current MicroMonitor user level and to configure the user level required to access certain commands. The monrc file is a file that is automatically executed by the monitor when booted (see Chapter 7).



Embedded Systems Firmware Demystified
Embedded Systems Firmware Demystified (With CD-ROM)
ISBN: 1578200997
EAN: 2147483647
Year: 2002
Pages: 118
Authors: Ed Sutter

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net