I am trying to get StartUp-Manager to write the grub password in encrypted form to menu.lst. Currently it writes the password in plain-text and that is not too clever...
This is the function I currently use:
And here is the "change_con fig" function:
I have tried this:
Which would corrupt the textfile.
This:
Which does not nuke the textfile, but grub (the bootloader reading the textfile) does not recognise the encrypted password.
So now I am thinking about using the grub-md5-crypt(it is the program recommended for creating this md5).
Instead of using my change_config function, do something like this:
Now the problem is that I have no clue how to pass the password to grub-md5-crypt as it is interactive. Observe:
And from the man page for grub-md5-crypt
it does not seem like it is possible to send the password as an argument.
I feel stuck here. Any help is appreciated.
This is the function I currently use:
Code:
def on_update_password_button_clicked(self, widget):
if self.password_entry.get_text() == self.confirm_password_entry.get_text():
password=self.password_entry.get_text()
if self.password_protect_check.get_active():
change_config("password", None, "password "+password+"\n")
else:
change_config("password", None, "#password "+password+"\n")
...snip
Code:
def change_config(identifier, old_value, new_value):
"""Changes the configuration file based on the passed values."""
line_number=get_line_number(identifier)
lines=get_lines_of_file(Config.menu)
line=lines[line_number]
if old_value == None:
lines[line_number]=new_value
elif old_value == "vga=":
place=line.find(old_value)
if place != -1:
line=line[:place]+new_value+line[place+7:]
else:
place=line.find("\n")
line=line[:-1]+" "+new_value+"\n"
lines[line_number]=line
else:
if old_value[0] != "#" and line.find(" "+old_value) != -1:
old_value=" "+old_value
if old_value[0] == "#" and line.find("# "+old_value[1:]) != -1:
old_value="# "+old_value[1:]
line=line.replace(old_value, new_value)
lines[line_number]=line
output_file=open(Config.menu, 'w')
for out_line in lines:
output_file.write(out_line)
output_file.close()
Code:
snip...
import md5
password=md5.new(password).digest()
change_config("password", None, "password --md5 "+password+"\n")
...snip
This:
Code:
snip...
import md5
password=md5.new(password).hexdigest()
change_config("password", None, "password --md5 "+password+"\n")
...snip
So now I am thinking about using the grub-md5-crypt(it is the program recommended for creating this md5).
Instead of using my change_config function, do something like this:
Code:
os.system('grub-md5-crypt | some cool sed thing')
Code:
jimmy@ubuntu:~$ grub-md5-crypt Password: Retype password: $1$nWkej1$2zfBZK52J4hSlxI5x5EV/0
Code:
DESCRIPTION
Encrypt a password in MD5 format.
-h, --help
print this message and exit
-v, --version
print the version information and exit
--grub-shell=FILE
use FILE as the grub shell
I feel stuck here. Any help is appreciated.
Comment