mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-11 01:40:19 +01:00
session: merge nm-session-utils into nm-session-manager
Acked-By: Thomas Haller <thaller@redhat.com>
This commit is contained in:
parent
b52d21a68c
commit
335bbc6335
7 changed files with 42 additions and 70 deletions
|
|
@ -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 \
|
||||
|
|
|
|||
|
|
@ -26,7 +26,6 @@
|
|||
#include <gio/gio.h>
|
||||
#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;
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@
|
|||
#include <string.h>
|
||||
#include "nm-logging.h"
|
||||
|
||||
#include "nm-session-utils.h"
|
||||
#include "nm-session-monitor.h"
|
||||
|
||||
/* <internal>
|
||||
|
|
|
|||
|
|
@ -30,7 +30,6 @@
|
|||
#include <systemd/sd-login.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "nm-session-utils.h"
|
||||
#include "nm-session-monitor.h"
|
||||
#include "nm-logging.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -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 <dcbw@redhat.com>
|
||||
* Author: Pavel Šimerda <psimerda@redhat.com>
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <pwd.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#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;
|
||||
}
|
||||
|
||||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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 <dcbw@redhat.com>
|
||||
*/
|
||||
|
||||
#ifndef __NETWORKMANAGER_SESSION_UTILS_H__
|
||||
#define __NETWORKMANAGER_SESSION_UTILS_H__
|
||||
|
||||
#include <glib.h>
|
||||
#include <glib-object.h>
|
||||
|
||||
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 */
|
||||
Loading…
Add table
Reference in a new issue