summaryrefslogtreecommitdiff
path: root/tests/src/guest-account.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/src/guest-account.c')
-rw-r--r--tests/src/guest-account.c30
1 files changed, 12 insertions, 18 deletions
diff --git a/tests/src/guest-account.c b/tests/src/guest-account.c
index 0df3f092..5d3baf11 100644
--- a/tests/src/guest-account.c
+++ b/tests/src/guest-account.c
@@ -12,8 +12,6 @@ static GKeyFile *config;
int
main (int argc, char **argv)
{
- gchar *passwd_path;
-
#if !defined(GLIB_VERSION_2_36)
g_type_init ();
#endif
@@ -23,27 +21,25 @@ main (int argc, char **argv)
config = g_key_file_new ();
g_key_file_load_from_file (config, g_build_filename (g_getenv ("LIGHTDM_TEST_ROOT"), "script", NULL), G_KEY_FILE_NONE, NULL);
- passwd_path = g_build_filename (g_getenv ("LIGHTDM_TEST_ROOT"), "etc", "passwd", NULL);
+ g_autofree gchar *passwd_path = g_build_filename (g_getenv ("LIGHTDM_TEST_ROOT"), "etc", "passwd", NULL);
if (argc == 2 && strcmp (argv[1], "add") == 0)
{
- gchar *home_dir, *username, line[1024];
- gint max_uid = 1000;
- FILE *passwd;
-
/* Create a unique name */
- home_dir = g_build_filename (g_getenv ("LIGHTDM_TEST_ROOT"), "home", "guest-XXXXXX", NULL);
+ g_autofree gchar *home_dir = g_build_filename (g_getenv ("LIGHTDM_TEST_ROOT"), "home", "guest-XXXXXX", NULL);
if (!mkdtemp (home_dir))
{
g_printerr ("Failed to create home directory %s: %s\n", home_dir, strerror (errno));
return EXIT_FAILURE;
}
- username = strrchr (home_dir, '/') + 1;
+ const gchar *username = strrchr (home_dir, '/') + 1;
/* Get the largest UID */
- passwd = fopen (passwd_path, "r");
+ gint max_uid = 1000;
+ FILE *passwd = fopen (passwd_path, "r");
if (passwd)
{
+ gchar line[1024];
while (fgets (line, 1024, passwd))
{
g_auto(GStrv) tokens = g_strsplit (line, ":", -1);
@@ -71,20 +67,18 @@ main (int argc, char **argv)
}
else if (argc == 3 && strcmp (argv[1], "remove") == 0)
{
- gchar *username, *path, *prefix, line[1024];
- FILE *passwd, *new_passwd;
-
- username = argv[2];
+ const gchar *username = argv[2];
status_notify ("GUEST-ACCOUNT REMOVE USERNAME=%s", username);
/* Open a new file for writing */
- passwd = fopen (passwd_path, "r");
- path = g_strdup_printf ("%s~", passwd_path);
- new_passwd = fopen (path, "w");
+ FILE *passwd = fopen (passwd_path, "r");
+ g_autofree gchar *path = g_strdup_printf ("%s~", passwd_path);
+ FILE *new_passwd = fopen (path, "w");
/* Copy the old file, omitting our entry */
- prefix = g_strdup_printf ("%s:", username);
+ g_autofree gchar *prefix = g_strdup_printf ("%s:", username);
+ gchar line[1024];
while (fgets (line, 1024, passwd))
{
if (!g_str_has_prefix (line, prefix))