~ubuntu-branches/ubuntu/maverick/gnome-keyring/maverick-proposed

« back to all changes in this revision

Viewing changes to pkcs11/gck/tests/dump-data-file.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2009-03-02 17:00:10 UTC
  • mto: (2.2.1 sid)
  • mto: This revision was merged to the branch mainline in revision 71.
  • Revision ID: james.westby@ubuntu.com-20090302170010-1bakcvrq713wq2q0
Tags: upstream-2.25.92
ImportĀ upstreamĀ versionĀ 2.25.92

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
 
2
/* dump-data-file.c: Dump a gck data file
 
3
 
 
4
   Copyright (C) 2009 Stefan Walter
 
5
 
 
6
   The Gnome Keyring Library is free software; you can redistribute it and/or
 
7
   modify it under the terms of the GNU Library General Public License as
 
8
   published by the Free Software Foundation; either version 2 of the
 
9
   License, or (at your option) any later version.
 
10
 
 
11
   The Gnome Keyring Library is distributed in the hope that it will be useful,
 
12
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
14
   Library General Public License for more details.
 
15
 
 
16
   You should have received a copy of the GNU Library General Public
 
17
   License along with the Gnome Library; see the file COPYING.LIB.  If not,
 
18
   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
19
   Boston, MA 02111-1307, USA.
 
20
 
 
21
   Author: Stef Walter <stef@memberwebs.com>
 
22
*/
 
23
 
 
24
#include "gck-crypto.h"
 
25
#include "gck-data-file.h"
 
26
 
 
27
#include "egg/egg-secure-memory.h"
 
28
 
 
29
#include <glib.h>
 
30
 
 
31
#include <errno.h>
 
32
#include <fcntl.h>
 
33
#include <stdarg.h>
 
34
#include <stdio.h>
 
35
#include <stdlib.h>
 
36
#include <string.h>
 
37
#include <unistd.h>
 
38
 
 
39
void egg_memory_lock (void) 
 
40
        { }
 
41
void egg_memory_unlock (void) 
 
42
        { }
 
43
void* egg_memory_fallback (void *p, size_t sz) 
 
44
        { return g_realloc (p, sz); }
 
45
 
 
46
static void G_GNUC_NORETURN
 
47
failure (const gchar* message, ...)
 
48
{
 
49
        va_list va;
 
50
        va_start (va, message);
 
51
        vfprintf (stderr, message, va);
 
52
        fputc ('\n', stderr);
 
53
        va_end (va);
 
54
        exit (1);
 
55
}
 
56
 
 
57
int 
 
58
main(int argc, char* argv[])
 
59
{
 
60
        const gchar *password;
 
61
        GckDataResult res;
 
62
        GckDataFile *file;
 
63
        GckLogin *login;
 
64
        int fd;
 
65
        
 
66
        g_type_init ();
 
67
        gck_crypto_initialize ();
 
68
        
 
69
        if (argc != 2) 
 
70
                failure ("usage: dump-data-file filename");
 
71
        
 
72
        fd = open (argv[1], O_RDONLY, 0);
 
73
        if (fd == -1)
 
74
                failure ("dump-data-file: couldn't open file: %s: %s", argv[1], g_strerror (errno));
 
75
        
 
76
        password = getpass ("Password: ");
 
77
        login = gck_login_new ((guchar*)password, strlen (password));
 
78
        
 
79
        file = gck_data_file_new ();
 
80
        res = gck_data_file_read_fd (file, fd, login);
 
81
        g_object_unref (login);
 
82
 
 
83
        switch(res) {
 
84
        case GCK_DATA_FAILURE:
 
85
                failure ("dump-data-file: failed to read file: %s", argv[1]);
 
86
        case GCK_DATA_LOCKED:
 
87
                failure ("dump-data-file: invalid password for file: %s", argv[1]);
 
88
        case GCK_DATA_UNRECOGNIZED:
 
89
                failure ("dump-data-file: unparseable file format: %s", argv[1]);
 
90
        case GCK_DATA_SUCCESS:
 
91
                break;
 
92
        default:
 
93
                g_assert_not_reached ();
 
94
        }
 
95
        
 
96
        gck_data_file_dump (file);
 
97
        g_object_unref (file);
 
98
        
 
99
        return 0;
 
100
}