mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-06 03:28:03 +02:00
libnm-core, core: add permission helpers
Add utility functions to get the number of users and the first user from the connection.permissions property of a connection. (cherry picked from commit59543620dc) (cherry picked from commit2fc662cc71) (cherry picked from commitabdf3385d6)
This commit is contained in:
parent
554e3a3e83
commit
d1a1db43b8
4 changed files with 61 additions and 0 deletions
|
|
@ -5474,3 +5474,14 @@ nm_utils_shorten_hostname(const char *hostname, char **shortened)
|
|||
*shortened = g_steal_pointer(&s);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
const char *
|
||||
nm_utils_get_connection_first_permissions_user(NMConnection *connection)
|
||||
{
|
||||
NMSettingConnection *s_con;
|
||||
|
||||
s_con = nm_connection_get_setting_connection(connection);
|
||||
nm_assert(s_con);
|
||||
|
||||
return _nm_setting_connection_get_first_permissions_user(s_con);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -490,4 +490,8 @@ uid_t nm_utils_get_nm_uid(void);
|
|||
|
||||
gid_t nm_utils_get_nm_gid(void);
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
const char *nm_utils_get_connection_first_permissions_user(NMConnection *connection);
|
||||
|
||||
#endif /* __NM_CORE_UTILS_H__ */
|
||||
|
|
|
|||
|
|
@ -431,6 +431,47 @@ nm_setting_connection_permissions_user_allowed_by_uid(NMSettingConnection *setti
|
|||
return _permissions_user_allowed(setting, NULL, uid);
|
||||
}
|
||||
|
||||
guint
|
||||
_nm_setting_connection_get_num_permissions_users(NMSettingConnection *setting)
|
||||
{
|
||||
NMSettingConnectionPrivate *priv;
|
||||
guint i;
|
||||
guint count = 0;
|
||||
|
||||
nm_assert(NM_IS_SETTING_CONNECTION(setting));
|
||||
priv = NM_SETTING_CONNECTION_GET_PRIVATE(setting);
|
||||
|
||||
for (i = 0; priv->permissions && i < priv->permissions->len; i++) {
|
||||
const Permission *permission = &nm_g_array_index(priv->permissions, Permission, i);
|
||||
|
||||
if (permission->ptype == PERM_TYPE_USER) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
const char *
|
||||
_nm_setting_connection_get_first_permissions_user(NMSettingConnection *setting)
|
||||
{
|
||||
NMSettingConnectionPrivate *priv;
|
||||
guint i;
|
||||
|
||||
nm_assert(NM_IS_SETTING_CONNECTION(setting));
|
||||
priv = NM_SETTING_CONNECTION_GET_PRIVATE(setting);
|
||||
|
||||
for (i = 0; priv->permissions && i < priv->permissions->len; i++) {
|
||||
const Permission *permission = &nm_g_array_index(priv->permissions, Permission, i);
|
||||
|
||||
if (permission->ptype == PERM_TYPE_USER) {
|
||||
return permission->item;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_setting_connection_add_permission:
|
||||
* @setting: the #NMSettingConnection
|
||||
|
|
|
|||
|
|
@ -1186,4 +1186,9 @@ gboolean nm_connection_need_secrets_for_rerequest(NMConnection *connection);
|
|||
|
||||
const GPtrArray *_nm_setting_ovs_port_get_trunks_arr(NMSettingOvsPort *self);
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
guint _nm_setting_connection_get_num_permissions_users(NMSettingConnection *setting);
|
||||
const char *_nm_setting_connection_get_first_permissions_user(NMSettingConnection *setting);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue