~ubuntu-branches/ubuntu/karmic/libsmbios/karmic

« back to all changes in this revision

Viewing changes to supported-bins/verifySmiPassword.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jose Luis Tallon
  • Date: 2007-04-22 13:04:55 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20070422130455-t40zo63zf23cip6t
Tags: 0.13.6-1
* New upstream version
  - Adds complete support for EFI (i.e. intel-based Macs)

* Fixed FTBFS with gcc4.3 (missing includes) (Closes: #418621)

Show diffs side-by-side

added added

removed removed

Lines of Context:
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:
3
 
 *
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 
7
 
 * 
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.
12
 
 
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.
17
 
 */
18
 
 
19
 
// compat header should always be first header if including system headers
20
 
#include "smbios/compat.h"
21
 
 
22
 
#include <iostream>
23
 
 
24
 
#include "smbios/ISmi.h"
25
 
#include "smbios/SystemInfo.h"
26
 
#include "smbios/version.h"
27
 
#include "getopts.h"
28
 
 
29
 
// always include last if included.
30
 
#include "smbios/message.h"
31
 
 
32
 
using namespace std;
33
 
 
34
 
struct options opts[] =
35
 
{
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 }
40
 
};
41
 
 
42
 
int
43
 
main (int argc, char **argv)
44
 
{
45
 
    int retval = 0;
46
 
    try
47
 
    {
48
 
        string password("");
49
 
        bool rawPassword=false;
50
 
 
51
 
        int c;
52
 
        char *args = 0;
53
 
        while ( (c=getopts(argc, argv, opts, &args)) != 0 )
54
 
        {
55
 
            switch(c)
56
 
            {
57
 
            case 249:
58
 
                rawPassword = true;
59
 
                break;
60
 
            case 252:
61
 
                password = args;
62
 
                break;
63
 
            case 255:
64
 
                cout << "Libsmbios version:    " << LIBSMBIOS_RELEASE_VERSION << endl;
65
 
                exit(0);
66
 
                break;
67
 
            default:
68
 
                break;
69
 
            }
70
 
            free(args);
71
 
        }
72
 
 
73
 
        if((!rawPassword) && (1 == SMBIOSGetSmiPasswordCoding()) && strlen(password.c_str())>0)
74
 
        {
75
 
            cerr << endl;
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;
81
 
            cerr << endl;
82
 
 
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()));
86
 
            password = codedPass;
87
 
            delete []codedPass;
88
 
        }
89
 
 
90
 
        cout << "Please wait while verifying password with BIOS..." << endl;
91
 
        cout << "Verifying Password: " << flush;
92
 
 
93
 
        try
94
 
        {
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;
99
 
        }
100
 
        catch( const smi::PasswordVerificationFailed &e )
101
 
        {
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;
106
 
        }
107
 
 
108
 
        cout << endl;
109
 
 
110
 
    }
111
 
    catch( const smi::PasswordVerificationFailed &e )
112
 
    {
113
 
        cout << "Password installed. Password FAILED verification." << endl;
114
 
        cout << endl;
115
 
        retval = 1;
116
 
    }
117
 
    catch( const exception &e )
118
 
    {
119
 
        cerr << endl;
120
 
        cerr << "An Error occurred, cannot continue. The Error message is: " << endl;
121
 
        cerr << "    " << e.what() << endl;
122
 
        cerr << 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;
128
 
        cerr << 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;
133
 
        retval = 1;
134
 
    }
135
 
    catch ( ... )
136
 
    {
137
 
        cerr << endl << "An Unknown Error occurred. Aborting." << endl;
138
 
        retval = 2;
139
 
    }
140
 
 
141
 
    return retval;
142
 
}