mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-04-27 15:20:38 +02:00
core: split initializing host-id singleton out of nm_utils_host_id_get()
(cherry picked from commit e9887d4816)
This commit is contained in:
parent
4482c4d4af
commit
164d796cf8
1 changed files with 28 additions and 21 deletions
|
|
@ -2877,24 +2877,8 @@ typedef struct {
|
|||
bool is_good:1;
|
||||
} HostIdData;
|
||||
|
||||
/**
|
||||
* nm_utils_host_id_get:
|
||||
* @out_host_id: (out) (transfer none): the binary host key
|
||||
* @out_host_id_len: the length of the host key.
|
||||
*
|
||||
* This returns a per-host key that depends on /var/lib/NetworkManage/secret_key
|
||||
* and (depending on the version) on /etc/machine-id. If /var/lib/NetworkManage/secret_key
|
||||
* does not exist, it will be generated and persisted for next boot.
|
||||
*
|
||||
* Returns: %TRUE, if the host key is "good". Note that this function
|
||||
* will always succeed to return a host-key, and that this key
|
||||
* won't change during the run of the program (no matter what).
|
||||
* A %FALSE return possibly means, that the secret_key is not persisted
|
||||
* to disk, and/or that it was generated with bad randomness.
|
||||
*/
|
||||
gboolean
|
||||
nm_utils_host_id_get (const guint8 **out_host_id,
|
||||
gsize *out_host_id_len)
|
||||
static const HostIdData *
|
||||
_host_id_get (void)
|
||||
{
|
||||
static const HostIdData *volatile host_id_static;
|
||||
const HostIdData *host_id;
|
||||
|
|
@ -2915,6 +2899,31 @@ again:
|
|||
g_once_init_leave (&init_value, 1);
|
||||
}
|
||||
|
||||
return host_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_utils_host_id_get:
|
||||
* @out_host_id: (out) (transfer none): the binary host key
|
||||
* @out_host_id_len: the length of the host key.
|
||||
*
|
||||
* This returns a per-host key that depends on /var/lib/NetworkManage/secret_key
|
||||
* and (depending on the version) on /etc/machine-id. If /var/lib/NetworkManage/secret_key
|
||||
* does not exist, it will be generated and persisted for next boot.
|
||||
*
|
||||
* Returns: %TRUE, if the host key is "good". Note that this function
|
||||
* will always succeed to return a host-key, and that this key
|
||||
* won't change during the run of the program (no matter what).
|
||||
* A %FALSE return possibly means, that the secret_key is not persisted
|
||||
* to disk, and/or that it was generated with bad randomness.
|
||||
*/
|
||||
gboolean
|
||||
nm_utils_host_id_get (const guint8 **out_host_id,
|
||||
gsize *out_host_id_len)
|
||||
{
|
||||
const HostIdData *host_id;
|
||||
|
||||
host_id = _host_id_get ();
|
||||
*out_host_id = host_id->host_id;
|
||||
*out_host_id_len = host_id->host_id_len;
|
||||
return host_id->is_good;
|
||||
|
|
@ -2924,10 +2933,8 @@ gint64
|
|||
nm_utils_host_id_get_timestamp (void)
|
||||
{
|
||||
struct stat stat_buf;
|
||||
const guint8 *host_id;
|
||||
gsize host_id_len;
|
||||
|
||||
if (!nm_utils_host_id_get (&host_id, &host_id_len))
|
||||
if (!_host_id_get ()->is_good)
|
||||
return 0;
|
||||
|
||||
if (stat (SECRET_KEY_FILE, &stat_buf) != 0)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue