mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-20 03:30:09 +01: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.
This commit is contained in:
parent
d8f143f601
commit
2739850b78
4 changed files with 61 additions and 0 deletions
|
|
@ -5624,3 +5624,14 @@ nm_rate_limit_check(NMRateLimit *rate_limit, gint32 window_sec, gint32 burst)
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -503,4 +503,8 @@ typedef struct {
|
||||||
|
|
||||||
gboolean nm_rate_limit_check(NMRateLimit *rate_limit, gint32 window_sec, gint32 burst);
|
gboolean nm_rate_limit_check(NMRateLimit *rate_limit, gint32 window_sec, gint32 burst);
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
const char *nm_utils_get_connection_first_permissions_user(NMConnection *connection);
|
||||||
|
|
||||||
#endif /* __NM_CORE_UTILS_H__ */
|
#endif /* __NM_CORE_UTILS_H__ */
|
||||||
|
|
|
||||||
|
|
@ -433,6 +433,47 @@ nm_setting_connection_permissions_user_allowed_by_uid(NMSettingConnection *setti
|
||||||
return _permissions_user_allowed(setting, NULL, uid);
|
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:
|
* nm_setting_connection_add_permission:
|
||||||
* @setting: the #NMSettingConnection
|
* @setting: the #NMSettingConnection
|
||||||
|
|
|
||||||
|
|
@ -1187,4 +1187,9 @@ gboolean nm_connection_need_secrets_for_rerequest(NMConnection *connection);
|
||||||
|
|
||||||
const GPtrArray *_nm_setting_ovs_port_get_trunks_arr(NMSettingOvsPort *self);
|
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
|
#endif
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue