libpriv/passwd: remove unused functions
This drops some functions that used to be part of C unit-tests but are currently dead code.
This commit is contained in:
parent
9b94e85e5b
commit
7283aef8af
@ -187,17 +187,6 @@ conv_group_ent_free (void *vptr)
|
||||
g_free (ptr);
|
||||
}
|
||||
|
||||
static void
|
||||
sysuser_ent_free (void *vptr)
|
||||
{
|
||||
auto ptr = static_cast<struct sysuser_ent *>(vptr);
|
||||
g_free (ptr->name);
|
||||
g_free (ptr->id);
|
||||
g_free (ptr->gecos);
|
||||
g_free (ptr->dir);
|
||||
g_free (ptr->shell);
|
||||
}
|
||||
|
||||
GPtrArray *
|
||||
rpmostree_passwd_data2groupents (const char *data)
|
||||
{
|
||||
@ -229,127 +218,6 @@ compare_group_ents (gconstpointer a, gconstpointer b)
|
||||
return strcmp ((*sa)->name, (*sb)->name);
|
||||
}
|
||||
|
||||
static int
|
||||
compare_sysuser_ents (gconstpointer a, gconstpointer b)
|
||||
{
|
||||
const struct sysuser_ent **sa = (const struct sysuser_ent **)a;
|
||||
const struct sysuser_ent **sb = (const struct sysuser_ent **)b;
|
||||
|
||||
/* g > u > m */
|
||||
if (!g_str_equal ((*sa)->type, (*sb)->type))
|
||||
{
|
||||
gboolean is_group_type = g_str_equal ((*sa)->type, "g") || g_str_equal ((*sa)->type, "g");
|
||||
if (is_group_type)
|
||||
return !strcmp ((*sa)->type, (*sb)->type); /* g is smaller than m and u, we want g > other type here*/
|
||||
|
||||
gboolean is_user_type = g_str_equal ((*sa)->type, "u") || g_str_equal ((*sb)->type, "u");
|
||||
if (is_user_type)
|
||||
return strcmp ((*sa)->type, (*sb)->type); /* u > m */
|
||||
}
|
||||
/* We sort the entry name if type happens to be the same */
|
||||
if (!g_str_equal ((*sa)->name, (*sb)->name))
|
||||
return strcmp ((*sa)->name, (*sb)->name);
|
||||
|
||||
/* This is a collision, when both name and type matches, could error out here */
|
||||
return 0;
|
||||
}
|
||||
|
||||
gboolean
|
||||
rpmostree_passwdents2sysusers (GPtrArray *passwd_ents,
|
||||
GPtrArray **out_sysusers_entries,
|
||||
GError **error)
|
||||
{
|
||||
/* Do the assignment inside the function so we don't need to expose sysuser_ent
|
||||
* to other files */
|
||||
GPtrArray *sysusers_array = NULL;
|
||||
sysusers_array = *out_sysusers_entries ?: g_ptr_array_new_with_free_func (sysuser_ent_free);
|
||||
|
||||
for (int counter = 0; counter < passwd_ents->len; counter++)
|
||||
{
|
||||
auto convent = static_cast<struct conv_passwd_ent *>(passwd_ents->pdata[counter]);
|
||||
struct sysuser_ent *sysent = g_new (struct sysuser_ent, 1);
|
||||
|
||||
/* Systemd-sysusers also supports uid:gid format. That case was used
|
||||
* when creating user and group pairs with different numeric UID and GID values.*/
|
||||
if (convent->uid != convent->gid)
|
||||
sysent->id = g_strdup_printf ("%u:%u", convent->uid, convent->gid);
|
||||
else
|
||||
sysent->id = g_strdup_printf ("%u", convent->uid);
|
||||
|
||||
sysent->type = "u";
|
||||
sysent->name = g_strdup (convent->name);
|
||||
|
||||
/* Gecos may contain multiple words, thus adding a quote here to make it as a 'word' */
|
||||
sysent->gecos = (g_str_equal (convent->pw_gecos, "")) ? NULL :
|
||||
g_strdup_printf ("\"%s\"", convent->pw_gecos);
|
||||
sysent->dir = (g_str_equal (convent->pw_dir, ""))? NULL :
|
||||
util::move_nullify (convent->pw_dir);
|
||||
sysent->shell = util::move_nullify (convent->pw_shell);
|
||||
|
||||
g_ptr_array_add (sysusers_array, sysent);
|
||||
}
|
||||
/* Do the assignment at the end if the sysusers_table was not initialized */
|
||||
if (*out_sysusers_entries == NULL)
|
||||
*out_sysusers_entries = util::move_nullify (sysusers_array);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
rpmostree_groupents2sysusers (GPtrArray *group_ents,
|
||||
GPtrArray **out_sysusers_entries,
|
||||
GError **error)
|
||||
{
|
||||
/* Similar to converting passwd to sysusers, we do assignment inside the function */
|
||||
GPtrArray *sysusers_array = NULL;
|
||||
sysusers_array = *out_sysusers_entries ?: g_ptr_array_new_with_free_func (sysuser_ent_free);
|
||||
|
||||
for (int counter = 0; counter < group_ents->len; counter++)
|
||||
{
|
||||
auto convent = static_cast<struct conv_group_ent *>(group_ents->pdata[counter]);
|
||||
struct sysuser_ent *sysent = g_new (struct sysuser_ent, 1);
|
||||
|
||||
sysent->type = "g";
|
||||
sysent->name = util::move_nullify (convent->name);
|
||||
sysent->id = g_strdup_printf ("%u", convent->gid);
|
||||
sysent->gecos = NULL;
|
||||
sysent->dir = NULL;
|
||||
sysent->shell = NULL;
|
||||
|
||||
g_ptr_array_add (sysusers_array, sysent);
|
||||
}
|
||||
/* Do the assignment at the end if the sysusers_array was not initialized */
|
||||
if (*out_sysusers_entries == NULL)
|
||||
*out_sysusers_entries = util::move_nullify (sysusers_array);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
rpmostree_passwd_sysusers2char (GPtrArray *sysusers_entries,
|
||||
char **out_content,
|
||||
GError **error)
|
||||
{
|
||||
|
||||
GString* sysuser_content = g_string_new (NULL);
|
||||
/* We do the sorting before conversion */
|
||||
g_ptr_array_sort (sysusers_entries, compare_sysuser_ents);
|
||||
for (int counter = 0; counter < sysusers_entries->len; counter++)
|
||||
{
|
||||
auto sysent = static_cast<struct sysuser_ent *>(sysusers_entries->pdata[counter]);
|
||||
const char *shell = sysent->shell ?: "-";
|
||||
const char *gecos = sysent->gecos ?: "-";
|
||||
const char *dir = sysent->dir ?: "-";
|
||||
g_autofree gchar* line_content = g_strjoin (" ", sysent->type, sysent->name,
|
||||
sysent->id, gecos, dir, shell, NULL);
|
||||
g_string_append_printf (sysuser_content, "%s\n", line_content);
|
||||
}
|
||||
if (out_content)
|
||||
*out_content = g_string_free(sysuser_content, FALSE);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* See "man 5 passwd" We just make sure the name and uid/gid match,
|
||||
and that none are missing. don't care about GECOS/dir/shell.
|
||||
*/
|
||||
|
@ -77,17 +77,4 @@ rpmostree_passwd_data2passwdents (const char *data);
|
||||
GPtrArray *
|
||||
rpmostree_passwd_data2groupents (const char *data);
|
||||
|
||||
gboolean
|
||||
rpmostree_passwdents2sysusers (GPtrArray *passwd_ents,
|
||||
GPtrArray **out_sysusers_entries,
|
||||
GError **error);
|
||||
gboolean
|
||||
rpmostree_groupents2sysusers (GPtrArray *group_ents,
|
||||
GPtrArray **out_sysusers_entries,
|
||||
GError **error);
|
||||
gboolean
|
||||
rpmostree_passwd_sysusers2char (GPtrArray *sysusers_entries,
|
||||
char **out_content,
|
||||
GError **error);
|
||||
|
||||
G_END_DECLS
|
||||
|
Loading…
Reference in New Issue
Block a user