summaryrefslogtreecommitdiff
path: root/src/udiskscrypttabentry.c
blob: 228c735958155ea939e30d646d248718cec580ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
 *
 * Copyright (C) 2008 David Zeuthen <zeuthen@gmail.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 */

#include "config.h"
#include <glib/gi18n-lib.h>

#include <stdlib.h>
#include <stdio.h>
#include <signal.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <mntent.h>

#include <glib.h>
#include <glib-object.h>

#include "udiskscrypttabentry.h"
#include "udisksprivate.h"

/**
 * UDisksCrypttabEntry:
 *
 * The #UDisksCrypttabEntry structure contains only private data and should
 * only be accessed using the provided API.
 */
struct _UDisksCrypttabEntry
{
  GObject parent_instance;

  gchar *name;
  gchar *device;
  gchar *passphrase_path;
  gchar *options;
};

typedef struct _UDisksCrypttabEntryClass UDisksCrypttabEntryClass;

struct _UDisksCrypttabEntryClass
{
  GObjectClass parent_class;
};

G_DEFINE_TYPE (UDisksCrypttabEntry, udisks_crypttab_entry, G_TYPE_OBJECT);

static void
udisks_crypttab_entry_finalize (GObject *object)
{
  UDisksCrypttabEntry *entry = UDISKS_CRYPTTAB_ENTRY (object);

  g_free (entry->name);
  g_free (entry->device);
  g_free (entry->passphrase_path);
  g_free (entry->options);

  if (G_OBJECT_CLASS (udisks_crypttab_entry_parent_class)->finalize)
    G_OBJECT_CLASS (udisks_crypttab_entry_parent_class)->finalize (object);
}

static void
udisks_crypttab_entry_init (UDisksCrypttabEntry *crypttab_entry)
{
}

static void
udisks_crypttab_entry_class_init (UDisksCrypttabEntryClass *klass)
{
  GObjectClass *gobject_class;

  gobject_class = G_OBJECT_CLASS (klass);
  gobject_class->finalize = udisks_crypttab_entry_finalize;
}

UDisksCrypttabEntry *
_udisks_crypttab_entry_new (const gchar *name,
                            const gchar *device,
                            const gchar *passphrase_path,
                            const gchar *options)
{
  UDisksCrypttabEntry *entry;

  entry = UDISKS_CRYPTTAB_ENTRY (g_object_new (UDISKS_TYPE_CRYPTTAB_ENTRY, NULL));
  entry->name = g_strdup (name);
  entry->device = g_strdup (device);
  entry->passphrase_path = g_strdup (passphrase_path);
  entry->options = g_strdup (options);

  return entry;
}

/**
 * udisks_crypttab_entry_compare:
 * @entry: A #UDisksCrypttabEntry
 * @other_entry: Another #UDisksCrypttabEntry.
 *
 * Comparison function for comparing two #UDisksCrypttabEntry objects.
 *
 * Returns: Negative value if @entry < @other_entry; zero if @entry = @other_entry; positive value if @entry > @other_entry.
 */
gint
udisks_crypttab_entry_compare (UDisksCrypttabEntry  *entry,
                               UDisksCrypttabEntry  *other_entry)
{
  gint ret;

  g_return_val_if_fail (UDISKS_IS_CRYPTTAB_ENTRY (entry), 0);
  g_return_val_if_fail (UDISKS_IS_CRYPTTAB_ENTRY (other_entry), 0);

  ret = g_strcmp0 (other_entry->name, entry->name);
  if (ret != 0)
    goto out;

  ret = g_strcmp0 (other_entry->device, entry->device);
  if (ret != 0)
    goto out;

  ret = g_strcmp0 (other_entry->passphrase_path, entry->passphrase_path);
  if (ret != 0)
    goto out;

  ret = g_strcmp0 (other_entry->options, entry->options);

 out:
  return ret;
}

/**
 * udisks_crypttab_entry_get_name:
 * @entry: A #UDisksCrypttabEntry.
 *
 * Gets the name field of @entry.
 *
 * Returns: The name field.
 */
const gchar *
udisks_crypttab_entry_get_name (UDisksCrypttabEntry *entry)
{
  g_return_val_if_fail (UDISKS_IS_CRYPTTAB_ENTRY (entry), NULL);
  return entry->name;
}

/**
 * udisks_crypttab_entry_get_device:
 * @entry: A #UDisksCrypttabEntry.
 *
 * Gets the device field of @entry.
 *
 * Returns: The device field.
 */
const gchar *
udisks_crypttab_entry_get_device (UDisksCrypttabEntry *entry)
{
  g_return_val_if_fail (UDISKS_IS_CRYPTTAB_ENTRY (entry), NULL);
  return entry->device;
}

/**
 * udisks_crypttab_entry_get_passphrase_path:
 * @entry: A #UDisksCrypttabEntry.
 *
 * Gets the passphrase path field of @entry.
 *
 * Returns: The passphrase path field.
 */
const gchar *
udisks_crypttab_entry_get_passphrase_path (UDisksCrypttabEntry *entry)
{
  g_return_val_if_fail (UDISKS_IS_CRYPTTAB_ENTRY (entry), NULL);
  return entry->passphrase_path;
}

/**
 * udisks_crypttab_entry_get_options:
 * @entry: A #UDisksCrypttabEntry.
 *
 * Gets the options field of @entry.
 *
 * Returns: The options field.
 */
const gchar *
udisks_crypttab_entry_get_options (UDisksCrypttabEntry *entry)
{
  g_return_val_if_fail (UDISKS_IS_CRYPTTAB_ENTRY (entry), NULL);
  return entry->options;
}