mirror of
https://gitlab.com/mishakmak/pam-fprint-grosshack.git
synced 2026-04-08 20:03:34 +02:00
utils: Use auto-pointers
This commit is contained in:
committed by
Benjamin Berg
parent
827baff301
commit
38ba7199b7
@ -28,7 +28,7 @@ static GDBusConnection *connection = NULL;
|
|||||||
|
|
||||||
static void create_manager(void)
|
static void create_manager(void)
|
||||||
{
|
{
|
||||||
GError *error = NULL;
|
g_autoptr(GError) error = NULL;
|
||||||
|
|
||||||
connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
|
connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
|
||||||
if (connection == NULL) {
|
if (connection == NULL) {
|
||||||
@ -49,7 +49,7 @@ static void create_manager(void)
|
|||||||
|
|
||||||
static void delete_fingerprints (FprintDBusDevice *dev, const char *username)
|
static void delete_fingerprints (FprintDBusDevice *dev, const char *username)
|
||||||
{
|
{
|
||||||
GError *error = NULL;
|
g_autoptr(GError) error = NULL;
|
||||||
|
|
||||||
if (!fprint_dbus_device_call_claim_sync (dev, username, NULL, &error)) {
|
if (!fprint_dbus_device_call_claim_sync (dev, username, NULL, &error)) {
|
||||||
g_print("failed to claim device: %s\n", error->message);
|
g_print("failed to claim device: %s\n", error->message);
|
||||||
@ -76,12 +76,12 @@ static void delete_fingerprints (FprintDBusDevice *dev, const char *username)
|
|||||||
} else {
|
} else {
|
||||||
g_print ("No fingerprints to delete on %s\n",
|
g_print ("No fingerprints to delete on %s\n",
|
||||||
fprint_dbus_device_get_name (dev));
|
fprint_dbus_device_get_name (dev));
|
||||||
g_clear_error (&error);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
g_print ("Fingerprints deleted on %s\n",
|
g_print ("Fingerprints deleted on %s\n",
|
||||||
fprint_dbus_device_get_name (dev));
|
fprint_dbus_device_get_name (dev));
|
||||||
}
|
}
|
||||||
|
g_clear_error (&error);
|
||||||
|
|
||||||
if (!fprint_dbus_device_call_release_sync (dev, NULL, &error)) {
|
if (!fprint_dbus_device_call_release_sync (dev, NULL, &error)) {
|
||||||
g_print("ReleaseDevice failed: %s\n", error->message);
|
g_print("ReleaseDevice failed: %s\n", error->message);
|
||||||
@ -91,7 +91,7 @@ static void delete_fingerprints (FprintDBusDevice *dev, const char *username)
|
|||||||
|
|
||||||
static void process_devices(char **argv)
|
static void process_devices(char **argv)
|
||||||
{
|
{
|
||||||
GError *error = NULL;
|
g_autoptr(GError) error = NULL;
|
||||||
g_auto(GStrv) devices = NULL;
|
g_auto(GStrv) devices = NULL;
|
||||||
char *path;
|
char *path;
|
||||||
guint num_devices;
|
guint num_devices;
|
||||||
@ -122,10 +122,11 @@ static void process_devices(char **argv)
|
|||||||
path = devices[i];
|
path = devices[i];
|
||||||
g_print("Using device %s\n", path);
|
g_print("Using device %s\n", path);
|
||||||
|
|
||||||
|
/* NOTE: We should handle error cases! */
|
||||||
dev = fprint_dbus_device_proxy_new_sync (connection,
|
dev = fprint_dbus_device_proxy_new_sync (connection,
|
||||||
G_DBUS_PROXY_FLAGS_NONE,
|
G_DBUS_PROXY_FLAGS_NONE,
|
||||||
"net.reactivated.Fprint",
|
"net.reactivated.Fprint",
|
||||||
path, NULL, &error);
|
path, NULL, NULL);
|
||||||
|
|
||||||
for (j = 1; argv[j] != NULL; j++)
|
for (j = 1; argv[j] != NULL; j++)
|
||||||
delete_fingerprints (dev, argv[j]);
|
delete_fingerprints (dev, argv[j]);
|
||||||
|
|||||||
@ -35,7 +35,7 @@ static char **usernames = NULL;
|
|||||||
|
|
||||||
static void create_manager(void)
|
static void create_manager(void)
|
||||||
{
|
{
|
||||||
GError *error = NULL;
|
g_autoptr(GError) error = NULL;
|
||||||
|
|
||||||
connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
|
connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
|
||||||
if (connection == NULL) {
|
if (connection == NULL) {
|
||||||
@ -57,8 +57,8 @@ static void create_manager(void)
|
|||||||
static FprintDBusDevice *open_device (const char *username)
|
static FprintDBusDevice *open_device (const char *username)
|
||||||
{
|
{
|
||||||
g_autoptr(FprintDBusDevice) dev = NULL;
|
g_autoptr(FprintDBusDevice) dev = NULL;
|
||||||
GError *error = NULL;
|
g_autoptr(GError) error = NULL;
|
||||||
gchar *path;
|
g_autofree char *path = NULL;
|
||||||
|
|
||||||
if (!fprint_dbus_manager_call_get_default_device_sync (manager, &path,
|
if (!fprint_dbus_manager_call_get_default_device_sync (manager, &path,
|
||||||
NULL, &error)) {
|
NULL, &error)) {
|
||||||
@ -73,8 +73,6 @@ static FprintDBusDevice *open_device (const char *username)
|
|||||||
"net.reactivated.Fprint",
|
"net.reactivated.Fprint",
|
||||||
path, NULL, &error);
|
path, NULL, &error);
|
||||||
|
|
||||||
g_free (path);
|
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
g_print ("failed to connect to device: %s\n", error->message);
|
g_print ("failed to connect to device: %s\n", error->message);
|
||||||
exit (1);
|
exit (1);
|
||||||
@ -112,7 +110,7 @@ static void proxy_signal_cb (GDBusProxy *proxy,
|
|||||||
|
|
||||||
static void do_enroll (FprintDBusDevice *dev)
|
static void do_enroll (FprintDBusDevice *dev)
|
||||||
{
|
{
|
||||||
GError *error = NULL;
|
g_autoptr(GError) error = NULL;
|
||||||
gboolean enroll_completed = FALSE;
|
gboolean enroll_completed = FALSE;
|
||||||
gboolean found;
|
gboolean found;
|
||||||
guint i;
|
guint i;
|
||||||
@ -128,7 +126,7 @@ static void do_enroll (FprintDBusDevice *dev)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!found) {
|
if (!found) {
|
||||||
GString *s;
|
g_autoptr(GString) s = NULL;
|
||||||
|
|
||||||
s = g_string_new (NULL);
|
s = g_string_new (NULL);
|
||||||
g_string_append_printf (s, "Invalid finger name '%s'. Name must be one of ", finger_name);
|
g_string_append_printf (s, "Invalid finger name '%s'. Name must be one of ", finger_name);
|
||||||
@ -138,7 +136,6 @@ static void do_enroll (FprintDBusDevice *dev)
|
|||||||
g_string_append (s, ", ");
|
g_string_append (s, ", ");
|
||||||
}
|
}
|
||||||
g_warning ("%s", s->str);
|
g_warning ("%s", s->str);
|
||||||
g_string_free (s, TRUE);
|
|
||||||
exit (1);
|
exit (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -162,7 +159,7 @@ static void do_enroll (FprintDBusDevice *dev)
|
|||||||
|
|
||||||
static void release_device (FprintDBusDevice *dev)
|
static void release_device (FprintDBusDevice *dev)
|
||||||
{
|
{
|
||||||
GError *error = NULL;
|
g_autoptr(GError) error = NULL;
|
||||||
if (!fprint_dbus_device_call_release_sync (dev, NULL, &error)) {
|
if (!fprint_dbus_device_call_release_sync (dev, NULL, &error)) {
|
||||||
g_print("ReleaseDevice failed: %s\n", error->message);
|
g_print("ReleaseDevice failed: %s\n", error->message);
|
||||||
exit (1);
|
exit (1);
|
||||||
|
|||||||
16
utils/list.c
16
utils/list.c
@ -28,7 +28,7 @@ static GDBusConnection *connection = NULL;
|
|||||||
|
|
||||||
static void create_manager(void)
|
static void create_manager(void)
|
||||||
{
|
{
|
||||||
GError *error = NULL;
|
g_autoptr(GError) error = NULL;
|
||||||
|
|
||||||
connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
|
connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
|
||||||
if (connection == NULL) {
|
if (connection == NULL) {
|
||||||
@ -49,8 +49,8 @@ static void create_manager(void)
|
|||||||
|
|
||||||
static void list_fingerprints (FprintDBusDevice *dev, const char *username)
|
static void list_fingerprints (FprintDBusDevice *dev, const char *username)
|
||||||
{
|
{
|
||||||
GError *error = NULL;
|
g_autoptr(GError) error = NULL;
|
||||||
char **fingers;
|
g_auto(GStrv) fingers = NULL;
|
||||||
guint i;
|
guint i;
|
||||||
|
|
||||||
if (!fprint_dbus_device_call_list_enrolled_fingers_sync (dev, username,
|
if (!fprint_dbus_device_call_list_enrolled_fingers_sync (dev, username,
|
||||||
@ -69,9 +69,6 @@ static void list_fingerprints (FprintDBusDevice *dev, const char *username)
|
|||||||
if (!ignore_error) {
|
if (!ignore_error) {
|
||||||
g_print("ListEnrolledFingers failed: %s\n", error->message);
|
g_print("ListEnrolledFingers failed: %s\n", error->message);
|
||||||
exit (1);
|
exit (1);
|
||||||
} else {
|
|
||||||
g_clear_error (&error);
|
|
||||||
fingers = NULL;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,14 +86,12 @@ static void list_fingerprints (FprintDBusDevice *dev, const char *username)
|
|||||||
for (i = 0; fingers[i] != NULL; i++) {
|
for (i = 0; fingers[i] != NULL; i++) {
|
||||||
g_print(" - #%d: %s\n", i, fingers[i]);
|
g_print(" - #%d: %s\n", i, fingers[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_strfreev (fingers);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void process_devices(char **argv)
|
static void process_devices(char **argv)
|
||||||
{
|
{
|
||||||
g_auto(GStrv) devices = NULL;
|
g_auto(GStrv) devices = NULL;
|
||||||
GError *error = NULL;
|
g_autoptr(GError) error = NULL;
|
||||||
char *path;
|
char *path;
|
||||||
guint num_devices;
|
guint num_devices;
|
||||||
guint i;
|
guint i;
|
||||||
@ -126,10 +121,11 @@ static void process_devices(char **argv)
|
|||||||
path = devices[i];
|
path = devices[i];
|
||||||
g_print("Using device %s\n", path);
|
g_print("Using device %s\n", path);
|
||||||
|
|
||||||
|
/* NOTE: We should handle error cases! */
|
||||||
dev = fprint_dbus_device_proxy_new_sync (connection,
|
dev = fprint_dbus_device_proxy_new_sync (connection,
|
||||||
G_DBUS_PROXY_FLAGS_NONE,
|
G_DBUS_PROXY_FLAGS_NONE,
|
||||||
"net.reactivated.Fprint",
|
"net.reactivated.Fprint",
|
||||||
path, NULL, &error);
|
path, NULL, NULL);
|
||||||
|
|
||||||
for (j = 1; argv[j] != NULL; j++)
|
for (j = 1; argv[j] != NULL; j++)
|
||||||
list_fingerprints (dev, argv[j]);
|
list_fingerprints (dev, argv[j]);
|
||||||
|
|||||||
@ -55,8 +55,8 @@ static void create_manager(void)
|
|||||||
static FprintDBusDevice *open_device (const char *username)
|
static FprintDBusDevice *open_device (const char *username)
|
||||||
{
|
{
|
||||||
g_autoptr(FprintDBusDevice) dev = NULL;
|
g_autoptr(FprintDBusDevice) dev = NULL;
|
||||||
GError *error = NULL;
|
g_autoptr(GError) error = NULL;
|
||||||
gchar *path;
|
g_autofree char *path = NULL;
|
||||||
|
|
||||||
if (!fprint_dbus_manager_call_get_default_device_sync (manager, &path,
|
if (!fprint_dbus_manager_call_get_default_device_sync (manager, &path,
|
||||||
NULL, &error)) {
|
NULL, &error)) {
|
||||||
@ -71,8 +71,6 @@ static FprintDBusDevice *open_device (const char *username)
|
|||||||
"net.reactivated.Fprint",
|
"net.reactivated.Fprint",
|
||||||
path, NULL, &error);
|
path, NULL, &error);
|
||||||
|
|
||||||
g_free (path);
|
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
g_print ("failed to connect to device: %s\n", error->message);
|
g_print ("failed to connect to device: %s\n", error->message);
|
||||||
exit (1);
|
exit (1);
|
||||||
@ -88,8 +86,8 @@ static FprintDBusDevice *open_device (const char *username)
|
|||||||
|
|
||||||
static void find_finger (FprintDBusDevice *dev, const char *username)
|
static void find_finger (FprintDBusDevice *dev, const char *username)
|
||||||
{
|
{
|
||||||
GError *error = NULL;
|
g_autoptr(GError) error = NULL;
|
||||||
char **fingers;
|
g_auto(GStrv) fingers = NULL;
|
||||||
guint i;
|
guint i;
|
||||||
|
|
||||||
if (!fprint_dbus_device_call_list_enrolled_fingers_sync (dev, username,
|
if (!fprint_dbus_device_call_list_enrolled_fingers_sync (dev, username,
|
||||||
@ -120,8 +118,6 @@ static void find_finger (FprintDBusDevice *dev, const char *username)
|
|||||||
if (finger_name == NULL) {
|
if (finger_name == NULL) {
|
||||||
finger_name = g_strdup (fingers[0]);
|
finger_name = g_strdup (fingers[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_strfreev (fingers);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void verify_result(GObject *object, const char *result, gboolean done, void *user_data)
|
static void verify_result(GObject *object, const char *result, gboolean done, void *user_data)
|
||||||
@ -159,7 +155,7 @@ static void proxy_signal_cb (GDBusProxy *proxy,
|
|||||||
|
|
||||||
static void do_verify (FprintDBusDevice *dev)
|
static void do_verify (FprintDBusDevice *dev)
|
||||||
{
|
{
|
||||||
GError *error = NULL;
|
g_autoptr(GError) error = NULL;
|
||||||
gboolean verify_completed = FALSE;
|
gboolean verify_completed = FALSE;
|
||||||
|
|
||||||
g_signal_connect (dev, "g-signal", G_CALLBACK (proxy_signal_cb),
|
g_signal_connect (dev, "g-signal", G_CALLBACK (proxy_signal_cb),
|
||||||
@ -186,7 +182,7 @@ static void do_verify (FprintDBusDevice *dev)
|
|||||||
|
|
||||||
static void release_device (FprintDBusDevice *dev)
|
static void release_device (FprintDBusDevice *dev)
|
||||||
{
|
{
|
||||||
GError *error = NULL;
|
g_autoptr(GError) error = NULL;
|
||||||
if (!fprint_dbus_device_call_release_sync (dev, NULL, &error)) {
|
if (!fprint_dbus_device_call_release_sync (dev, NULL, &error)) {
|
||||||
g_print("ReleaseDevice failed: %s\n", error->message);
|
g_print("ReleaseDevice failed: %s\n", error->message);
|
||||||
exit (1);
|
exit (1);
|
||||||
@ -203,8 +199,8 @@ static const GOptionEntry entries[] = {
|
|||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
g_autoptr(FprintDBusDevice) dev = NULL;
|
g_autoptr(FprintDBusDevice) dev = NULL;
|
||||||
|
g_autoptr(GError) err = NULL;
|
||||||
GOptionContext *context;
|
GOptionContext *context;
|
||||||
GError *err = NULL;
|
|
||||||
const char *username = NULL;
|
const char *username = NULL;
|
||||||
|
|
||||||
setlocale (LC_ALL, "");
|
setlocale (LC_ALL, "");
|
||||||
@ -214,7 +210,6 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
if (g_option_context_parse (context, &argc, &argv, &err) == FALSE) {
|
if (g_option_context_parse (context, &argc, &argv, &err) == FALSE) {
|
||||||
g_print ("couldn't parse command-line options: %s\n", err->message);
|
g_print ("couldn't parse command-line options: %s\n", err->message);
|
||||||
g_error_free (err);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user