diff --git a/src/Makefile.am b/src/Makefile.am index 808e59eb33..387d1caa70 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -327,8 +327,7 @@ nm_sources = \ nm-rfkill-manager.c \ nm-rfkill-manager.h \ nm-session-monitor.h \ - nm-session-utils.c \ - nm-session-utils.h \ + nm-session-monitor.c \ nm-sleep-monitor.h \ nm-types.h \ NetworkManagerUtils.c \ diff --git a/src/nm-session-monitor-ck.c b/src/nm-session-monitor-ck.c index 2a8a9e84de..4d4c360e8c 100644 --- a/src/nm-session-monitor-ck.c +++ b/src/nm-session-monitor-ck.c @@ -26,7 +26,6 @@ #include #include "nm-logging.h" -#include "nm-session-utils.h" #include "nm-session-monitor.h" #include "nm-errors.h" @@ -125,8 +124,14 @@ session_new (GKeyFile *keyfile, const char *group, GError **error) if (local) goto error; - if (!nm_session_uid_to_user (s->uid, &uname, error)) + if (!nm_session_monitor_uid_to_user (s->uid, &uname)) { + g_set_error (error, + NM_MANAGER_ERROR, + NM_MANAGER_ERROR_FAILED, + "Could not get username for UID %d", + s->uid); goto error; + } s->user = g_strdup (uname); return s; diff --git a/src/nm-session-monitor-null.c b/src/nm-session-monitor-null.c index bffb75d356..22d5dca0e2 100644 --- a/src/nm-session-monitor-null.c +++ b/src/nm-session-monitor-null.c @@ -23,7 +23,6 @@ #include #include "nm-logging.h" -#include "nm-session-utils.h" #include "nm-session-monitor.h" /* diff --git a/src/nm-session-monitor-systemd.c b/src/nm-session-monitor-systemd.c index dcb0004dcf..6d4da4840c 100644 --- a/src/nm-session-monitor-systemd.c +++ b/src/nm-session-monitor-systemd.c @@ -30,7 +30,6 @@ #include #include -#include "nm-session-utils.h" #include "nm-session-monitor.h" #include "nm-logging.h" diff --git a/src/nm-session-utils.c b/src/nm-session-monitor.c similarity index 52% rename from src/nm-session-utils.c rename to src/nm-session-monitor.c index eb156fad0e..d398056e69 100644 --- a/src/nm-session-utils.c +++ b/src/nm-session-monitor.c @@ -13,58 +13,55 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright (C) 2012 Red Hat, Inc. + * (C) Copyright 2008 - 2015 Red Hat, Inc. * Author: Dan Williams + * Author: Pavel Šimerda */ - -#include "config.h" - #include #include -#include "nm-session-utils.h" -#include "nm-errors.h" - -/********************************************************************/ +#include "nm-session-monitor.h" +/** + * nm_session_monitor_uid_to_user: + * @uid: UID. + * @out_user: Return location for user name. + * + * Translates a UID to a user name. + */ gboolean -nm_session_uid_to_user (uid_t uid, const char **out_user, GError **error) +nm_session_monitor_uid_to_user (uid_t uid, const char **out_user) { - struct passwd *pw; + struct passwd *pw = getpwuid (uid); - pw = getpwuid (uid); - if (!pw) { - g_set_error (error, - NM_MANAGER_ERROR, - NM_MANAGER_ERROR_FAILED, - "Could not get username for UID %d", - uid); + g_assert (out_user); + + if (!pw) return FALSE; - } - if (out_user) - *out_user = pw->pw_name; + *out_user = pw->pw_name; + return TRUE; } +/** + * nm_session_monitor_user_to_uid: + * @user: User naee. + * @out_uid: Return location for UID. + * + * Translates a user name to a UID. + */ gboolean -nm_session_user_to_uid (const char *user, uid_t *out_uid, GError **error) +nm_session_monitor_user_to_uid (const char *user, uid_t *out_uid) { - struct passwd *pw; + struct passwd *pw = getpwnam (user); - pw = getpwnam (user); - if (!pw) { - g_set_error (error, - NM_MANAGER_ERROR, - NM_MANAGER_ERROR_FAILED, - "Could not get UID for username '%s'", - user); + g_assert (out_uid); + + if (!pw) return FALSE; - } - /* Ugly, but hey, use ConsoleKit */ - if (out_uid) - *out_uid = pw->pw_uid; + *out_uid = pw->pw_uid; + return TRUE; } - diff --git a/src/nm-session-monitor.h b/src/nm-session-monitor.h index 3efe6eca6b..d05ee34512 100644 --- a/src/nm-session-monitor.h +++ b/src/nm-session-monitor.h @@ -41,6 +41,9 @@ typedef struct _NMSessionMonitorClass NMSessionMonitorClass; GType nm_session_monitor_get_type (void) G_GNUC_CONST; NMSessionMonitor *nm_session_monitor_get (void); +gboolean nm_session_monitor_uid_to_user (uid_t uid, const char **out_user); +gboolean nm_session_monitor_user_to_uid (const char *user, uid_t *out_uid); + gboolean nm_session_monitor_user_has_session (NMSessionMonitor *monitor, const char *username, uid_t *out_uid, diff --git a/src/nm-session-utils.h b/src/nm-session-utils.h deleted file mode 100644 index e626f52ae0..0000000000 --- a/src/nm-session-utils.h +++ /dev/null @@ -1,30 +0,0 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* 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 Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Copyright (C) 2012 Red Hat, Inc. - * Author: Dan Williams - */ - -#ifndef __NETWORKMANAGER_SESSION_UTILS_H__ -#define __NETWORKMANAGER_SESSION_UTILS_H__ - -#include -#include - -gboolean nm_session_uid_to_user (uid_t uid, const char **out_user, GError **error); - -gboolean nm_session_user_to_uid (const char *user, uid_t *out_uid, GError **error); - -#endif /* NM_SESSION_UTILS_H */