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"
27
#include "smbios/ISmi.h" // only needed if you want to use fake input (memdump.dat)
28
#include "smbios/SystemInfo.h" // this is the main header to include to use the C interface
29
#include "smbios/version.h"
32
// always include last if included.
33
#include "smbios/message.h" // not needed outside of this lib. (mainly for gettext i18n)
37
struct options opts[] =
40
250, "set", "Set Dell Property Tag", "s", 1
42
{ 252, "password", "BIOS setup password", "p", 1 },
43
{ 249, "rawpassword", "Do not auto-convert password to scancodes", NULL, 0 },
44
{ 255, "version", "Display libsmbios version information", "v", 0 },
45
{ 0, NULL, NULL, NULL, 0 }
49
main (int argc, char **argv)
60
bool rawPassword=false;
62
while ( (c=getopts(argc, argv, opts, &args)) != 0 )
68
// Property tag can be at most 80 chars (plus '\0')
78
cout << "Libsmbios version: " << LIBSMBIOS_RELEASE_VERSION << endl;
87
if(setVal && (!rawPassword) && (1 == SMBIOSGetSmiPasswordCoding()) && strlen(password.c_str())>0)
90
cerr << "BIOS Password encoding has been detected as SCAN CODE format." << endl;
91
cerr << "Automatically changing password from ASCII coding to en_US scancode format." << endl;
92
cerr << "Use the --rawpassword option to disable this, for example, if you have " << endl;
93
cerr << "another language keyboard, then manually convert the ASCII password to" << endl;
94
cerr << "scan code format." << endl;
97
char *codedPass = new char[strlen(password.c_str())+1];
98
memset(codedPass, 0, strlen(password.c_str())+1);
99
SMBIOSMapAsciiTo_en_US_ScanCode(codedPass, password.c_str(), strlen(password.c_str()));
100
password = codedPass;
104
#define PROP_TAG_SIZE 80
105
char propertyTag[PROP_TAG_SIZE + 1] =
109
smi::getPropertyOwnershipTag(propertyTag, PROP_TAG_SIZE);
110
cout << "Existing Property Ownership Tag: " << propertyTag << endl;
114
cout << "Changing Property Ownership Tag: " << newTag << endl;
117
smi::setPropertyOwnershipTag(password, newTag.c_str(), strlen(newTag.c_str()));
118
cout << "Change Successful. The changes may not take effect until reboot, depending on system type." << endl;
120
catch( const smi::PasswordVerificationFailed &)
123
if( strlen(password.c_str())>0 )
125
cerr << "Could not set tag. BIOS setup password is enabled but the password" << endl;
126
cerr << "given was not accepted by BIOS as the correct password." << endl;
127
cerr << " -- Verify the password and try again." << endl;
131
cerr << "Could not set tag. BIOS setup password is enabled but no password was given." << endl;
132
cerr << " -- Try using the '--password' option to specify the BIOS setup password." << endl;
137
catch( const smi::SmiExecutedWithError &)
140
cerr << "Could not set tag. Common problems are:" << endl;
142
cerr << " -- Insufficient permissions to perform operation." << endl;
143
cerr << " Try running as a more privileged account." << endl;
144
cerr << " Linux : run as 'root' user" << endl;
145
cerr << " Windows: run as 'administrator' user" << endl;
147
cerr << " -- dcdbas device driver not loaded." << endl;
148
cerr << " Try loading the dcdbas driver" << endl;
149
cerr << " Linux : insmod dcdbas" << endl;
150
cerr << " Windows: dcdbas driver not yet available." << endl;
156
catch( const smi::UnsupportedSmi &e )
159
cerr << "An Error occurred. The Error message is: " << endl;
160
cerr << " " << e.what() << endl;
162
cerr << "It appears that this system does not support Property Ownership Tags." << endl;
167
catch( const exception &e )
170
cerr << "An Error occurred. The Error message is: " << endl;
171
cerr << " " << e.what() << endl;
173
cerr << "Problem reading or writing tag. Common problems are:" << endl;
175
cerr << " -- Insufficient permissions to perform operation." << endl;
176
cerr << " Try running as a more privileged account." << endl;
177
cerr << " Linux : run as 'root' user" << endl;
178
cerr << " Windows: run as 'administrator' user" << endl;
180
cerr << " -- dcdbas device driver not loaded." << endl;
181
cerr << " Try loading the dcdbas driver" << endl;
182
cerr << " Linux : insmod dcdbas" << endl;
183
cerr << " Windows: dcdbas driver not yet available." << endl;
191
cerr << "An Unknown Error occurred. Aborting." << endl;