1
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2
* vim:expandtab:autoindent:tabstop=4:shiftwidth=4:filetype=c:cindent:textwidth=0:
4
* Copyright (C) 2005 Dell Inc.
5
* by Michael Brown <Michael_E_Brown@dell.com>
6
* Licensed under the Open Software License version 2.1
8
* Alternatively, you can redistribute it and/or modify
9
* it under the terms of the GNU General Public License as published
10
* by the Free Software Foundation; either version 2 of the License,
11
* or (at your option) any later version.
13
* This program is distributed in the hope that it will be useful, but
14
* WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
* See the GNU General Public License for more details.
19
// compat header should always be first header if including system headers
20
#include "smbios/compat.h"
24
#include "smbios/ISmi.h"
25
#include "smbios/SystemInfo.h"
26
#include "smbios/version.h"
29
// always include last if included.
30
#include "smbios/message.h"
34
struct options opts[] =
36
{ 252, "password", "BIOS setup password", "p", 1 },
37
{ 249, "rawpassword", "Do not auto-convert password to scancodes", NULL, 0 },
38
{ 255, "version", "Display libsmbios version information", "v", 0 },
39
{ 0, NULL, NULL, NULL, 0 }
43
main (int argc, char **argv)
49
bool rawPassword=false;
53
while ( (c=getopts(argc, argv, opts, &args)) != 0 )
64
cout << "Libsmbios version: " << LIBSMBIOS_RELEASE_VERSION << endl;
73
if((!rawPassword) && (1 == SMBIOSGetSmiPasswordCoding()) && strlen(password.c_str())>0)
76
cerr << "BIOS Password encoding has been detected as SCAN CODE format." << endl;
77
cerr << "Automatically changing password from ASCII coding to en_US scancode format." << endl;
78
cerr << "Use the --rawpassword option to disable this, for example, if you have " << endl;
79
cerr << "another language keyboard, then manually convert the ASCII password to" << endl;
80
cerr << "scan code format." << endl;
83
char *codedPass = new char[strlen(password.c_str())+1];
84
memset(codedPass, 0, strlen(password.c_str())+1);
85
SMBIOSMapAsciiTo_en_US_ScanCode(codedPass, password.c_str(), strlen(password.c_str()));
90
cout << "Please wait while verifying password with BIOS..." << endl;
91
cout << "Verifying Password: " << flush;
95
// try with no password to see if password protection enabled.
96
smi::getAuthenticationKey("");
97
// only get here if no exception... ie. no password
98
cout << "Password NOT installed." << endl;
100
catch( const smi::PasswordVerificationFailed &e )
102
// ok, now try real password
103
smi::getAuthenticationKey(password);
104
// if we get here, it is only because no exception thrown above.
105
cout << "Password installed. Password PASSED verification." << endl;
111
catch( const smi::PasswordVerificationFailed &e )
113
cout << "Password installed. Password FAILED verification." << endl;
117
catch( const exception &e )
120
cerr << "An Error occurred, cannot continue. The Error message is: " << endl;
121
cerr << " " << e.what() << endl;
123
cerr << "Could not verify password. Common problems are:" << endl;
124
cerr << " -- Insufficient permissions to perform operation." << endl;
125
cerr << " Try running as a more privileged account." << endl;
126
cerr << " Linux : run as 'root' user" << endl;
127
cerr << " Windows: run as 'administrator' user" << endl;
129
cerr << " -- dcdbas device driver not loaded." << endl;
130
cerr << " Try loading the dcdbas driver" << endl;
131
cerr << " Linux : insmod dcdbas" << endl;
132
cerr << " Windows: dcdbas driver not yet available." << endl;
137
cerr << endl << "An Unknown Error occurred. Aborting." << endl;