Changin Sun EEPROM Passowrd via program

2007-12-25 8:10:00

Hi,

A couple of days ago I posted a request for information/assistance

regarding a program using ioctl's to change the eeprom password

on a Sun workstation. I got a couple of responses right off the

bat indicating that those persons would also like to see such a program.

After some creative thinking, and alot of help from one of my

colleagues, we arrived at the following program, epset.c. This program

will set the Sun EEPROM security-mode parameter to "command" and it

will set the EEPROM password to a parameter given on the command line.

Note that the program overwrites argv[1] so that the PROM password

is not seen in 'ps'.

I hope this is useful. If anyone has any suggestions or questions, please

post or send e-mail.

(Special thanks to Karl Morgan for original ideas and very helpful

 guidance in this endeavor)

-------------------------epset.c------------------------------------------

#include <stdio.h>

#include <sys/types.h>

#include <sys/stat.h>

#include <sundev/openpromio.h>

#include <fcntl.h>

#include <errno.h>

#define OPENPROM "/dev/openprom"

#define SECPASS "security-password"

#define SECMODE "security-mode"

#define SECMODEVAL "command"

main(argc,argv)

int argc;

char *argv[];

{

        int fd, prom_size,j;

        struct openpromio *secmode,*secpass;

        char passwd[10];

/* Copy Password from command line arguments */

        strcpy(passwd,argv[1]);

/* Zero out the contents of argv so password does not show

   in a 'ps' */

        *argv[1] = 0;

        for (j=1;j < strlen(passwd); j = j + 1) {

                *(argv[1] + j) = 0;

        }

/* Open the PROM Monitor device so we can write to it */

        if ((fd = open(OPENPROM, O_RDWR)) < 0) {

                (void) fprintf(stderr, "Can't open %s\n", OPENPROM);

                exit (1);

        }

/* Allocate space for the prom data structure */

        secmode = (struct openpromio *)malloc(sizeof(struct openpromio));

/* Set PROM security-mode=command */

        secmode->oprom_size = strlen(SECMODE) + strlen(SECMODEVAL) + 2;

        secmode->oprom_array[0] = malloc(1023);

        strcpy(secmode->oprom_array, SECMODE);

        strcat(secmode->oprom_array + strlen(SECMODE) + 1, SECMODEVAL);

        if (ioctl(fd, OPROMSETOPT2, secmode) == -1) {

                perror("Error in ioctl");

                exit (1);

        }

/* Allocate space for the prom data structure */

        secpass = (struct openpromio *)malloc(sizeof(struct openpromio));

/* Set PROM security-password= out password */

        secpass->oprom_size = strlen(SECPASS) + strlen(passwd) + 2;

        secpass->oprom_array[0] = malloc(1023);

        strcpy(secpass->oprom_array, SECPASS);

        strcat(secpass->oprom_array + strlen(SECPASS) + 1, passwd);

        if (ioctl(fd, OPROMSETOPT2, secpass) == -1) {

                perror("Error in ioctl");

                exit (1);

        }

/* Free the used data structures */

        free(secmode->oprom_array[0]);

        free(secpass->oprom_array[0]);

        free(secmode);

        free(secpass);

/* Close the PROM Monitor */

        close(fd);

/* Goodbye */

        exit (0);

}

-----------------------epset.c---------------------------------------------

===============================================================================

Blake Holman | "The one good thing about repeating your

Ericsson Network Systems, Inc. | mistakes is that you know when to

730 International Parkway, MS B-07 | cringe."

Richardson, Texas 75081 |

(214) 997-6784 | -- Author Unknown

e-mail: exubho@exu.ericsson.se |

===============================================================================

      _/_/_/_/ _/_/_/ _/ _/_/_/_/ _/_/_/_/ _/_/_/_/ _/_/_/_/ _/ _/

     _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/_/ _/

    _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/

   _/_/_/ _/_/ _/ _/ _/_/_/_/ _/_/_/_/ _/ _/ _/ _/ _/

  _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/

 _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/_/

_/_/_/_/ _/ _/ _/ _/_/_/_/ _/_/_/_/ _/_/_/_/ _/_/_/_/ _/ _/

===============================================================================

Comments

Got something to say?

You must be logged in to post a comment.