44
48
initgroups (const char *user, gid_t group)
59
getgroups (int size, gid_t list[])
61
const gchar *group_list;
65
/* Get groups we are a member of */
66
group_list = g_getenv ("LIGHTDM_TEST_GROUPS");
69
groups = g_strsplit (group_list, ",", -1);
70
groups_length = g_strv_length (groups);
76
if (groups_length > size)
81
for (i = 0; groups[i]; i++)
82
list[i] = atoi (groups[i]);
90
setgroups (size_t size, const gid_t *list)
95
group_list = g_string_new ("");
96
for (i = 0; i < size; i++)
99
g_string_append (group_list, ",");
100
g_string_append_printf (group_list, "%d", list[i]);
102
g_setenv ("LIGHTDM_TEST_GROUPS", group_list->str, TRUE);
103
g_string_free (group_list, TRUE);
76
_open = (int (*)(const char * pathname, int flags, mode_t mode)) dlsym (RTLD_NEXT, "open");
135
_open = (int (*)(const char * pathname, int flags, mode_t mode)) dlsym (RTLD_NEXT, "open");
77
136
if (strcmp (pathname, "/dev/console") == 0)
79
138
if (console_fd < 0)
149
208
user_entries = NULL;
150
209
getpwent_link = NULL;
152
g_file_get_contents (g_getenv ("LIGHTDM_TEST_PASSWD_FILE"), &data, NULL, &error);
211
path = g_build_filename (g_getenv ("LIGHTDM_TEST_ROOT"), "etc", "passwd", NULL);
212
g_file_get_contents (path, &data, NULL, &error);
154
215
g_warning ("Error loading passwd file: %s", error->message);
155
216
g_clear_error (&error);
257
318
return link->data;
322
free_group (gpointer data)
324
struct group *entry = data;
326
g_free (entry->gr_name);
327
g_free (entry->gr_passwd);
328
g_strfreev (entry->gr_mem);
335
gchar *path, *data = NULL, **lines;
337
GError *error = NULL;
339
g_list_free_full (group_entries, free_group);
340
group_entries = NULL;
342
path = g_build_filename (g_getenv ("LIGHTDM_TEST_ROOT"), "etc", "group", NULL);
343
g_file_get_contents (path, &data, NULL, &error);
346
g_warning ("Error loading group file: %s", error->message);
347
g_clear_error (&error);
352
lines = g_strsplit (data, "\n", -1);
355
for (i = 0; lines[i]; i++)
357
gchar *line, **fields;
359
line = g_strstrip (lines[i]);
360
fields = g_strsplit (line, ":", -1);
361
if (g_strv_length (fields) == 4)
363
struct group *entry = malloc (sizeof (struct group));
365
entry->gr_name = g_strdup (fields[0]);
366
entry->gr_passwd = g_strdup (fields[1]);
367
entry->gr_gid = atoi (fields[2]);
368
entry->gr_mem = g_strsplit (fields[3], ",", -1);
369
group_entries = g_list_append (group_entries, entry);
377
getgrnam (const char *name)
383
for (link = group_entries; link; link = link->next)
385
struct group *entry = link->data;
386
if (strcmp (entry->gr_name, name) == 0)
402
for (link = group_entries; link; link = link->next)
404
struct group *entry = link->data;
405
if (entry->gr_gid == gid)
261
415
pam_start (const char *service_name, const char *user, const struct pam_conv *conversation, pam_handle_t **pamh)
645
799
pam_putenv (pamh, e);
802
/* Join special groups if requested */
803
if (strcmp (pamh->user, "group-member") == 0 && flags & PAM_ESTABLISH_CRED)
809
group = getgrnam ("test-group");
812
groups_length = getgroups (0, NULL);
813
groups = malloc (sizeof (gid_t) * (groups_length + 1));
814
groups_length = getgroups (groups_length, groups);
815
groups[groups_length] = group->gr_gid;
817
setgroups (groups_length, groups);
821
/* We need to pass our group overrides down the child process - the environment via PAM seems the only way to do it easily */
822
pam_putenv (pamh, g_strdup_printf ("LIGHTDM_TEST_GROUPS=%s", g_getenv ("LIGHTDM_TEST_GROUPS")));
648
825
return PAM_SUCCESS;