1
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2
/* This program is free software; you can redistribute it and/or modify
3
* it under the terms of the GNU General Public License as published by
4
* the Free Software Foundation; either version 2 of the License, or
5
* (at your option) any later version.
7
* This program is distributed in the hope that it will be useful,
8
* but WITHOUT ANY WARRANTY; without even the implied warranty of
9
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
* GNU General Public License for more details.
12
* You should have received a copy of the GNU General Public License along
13
* with this program; if not, write to the Free Software Foundation, Inc.,
14
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16
* Copyright (C) 2012 Red Hat, Inc.
17
* Author: Dan Williams <dcbw@redhat.com>
21
#include <sys/types.h>
23
#include "nm-session-utils.h"
25
/********************************************************************/
28
nm_session_monitor_error_quark (void)
30
static GQuark ret = 0;
32
if (G_UNLIKELY (ret == 0))
33
ret = g_quark_from_static_string ("nm-session-monitor-error");
37
#define ENUM_ENTRY(NAME, DESC) { NAME, "" #NAME "", DESC }
40
nm_session_monitor_error_get_type (void)
42
static GType etype = 0;
45
static const GEnumValue values[] = {
46
/* Some I/O operation on the CK database failed */
47
ENUM_ENTRY (NM_SESSION_MONITOR_ERROR_IO_ERROR, "IOError"),
48
/* Error parsing the CK database */
49
ENUM_ENTRY (NM_SESSION_MONITOR_ERROR_MALFORMED_DATABASE, "MalformedDatabase"),
50
/* Username or UID could could not be found */
51
ENUM_ENTRY (NM_SESSION_MONITOR_ERROR_UNKNOWN_USER, "UnknownUser"),
52
/* No ConsoleKit database */
53
ENUM_ENTRY (NM_SESSION_MONITOR_ERROR_NO_DATABASE, "NoDatabase"),
57
etype = g_enum_register_static ("NMSessionMonitorError", values);
62
/********************************************************************/
65
nm_session_uid_to_user (uid_t uid, const char **out_user, GError **error)
72
NM_SESSION_MONITOR_ERROR,
73
NM_SESSION_MONITOR_ERROR_UNKNOWN_USER,
74
"Could not get username for UID %d",
80
*out_user = pw->pw_name;
85
nm_session_user_to_uid (const char *user, uid_t *out_uid, GError **error)
92
NM_SESSION_MONITOR_ERROR,
93
NM_SESSION_MONITOR_ERROR_UNKNOWN_USER,
94
"Could not get UID for username '%s'",
99
/* Ugly, but hey, use ConsoleKit */
101
*out_uid = pw->pw_uid;