10 #include <sys/ioctl.h>
15 #include <security/pam_appl.h>
24 #include <gio/gunixsocketaddress.h>
28 #define LOGIN_PROMPT "login:"
30 static int console_fd = -1;
32 static GList *user_entries = NULL;
33 static GList *getpwent_link = NULL;
35 static GList *group_entries = NULL;
37 static int active_vt = 7;
39 static gboolean status_connected = FALSE;
49 struct pam_conv conversation;
65 initgroups (const char *user, gid_t group)
76 getgroups (int size, gid_t list[])
78 const gchar *group_list;
82 /* Get groups we are a member of */
83 group_list = g_getenv ("LIGHTDM_TEST_GROUPS");
86 groups = g_strsplit (group_list, ",", -1);
87 groups_length = g_strv_length (groups);
93 if (groups_length > size)
98 for (i = 0; groups[i]; i++)
99 list[i] = atoi (groups[i]);
103 return groups_length;
107 setgroups (size_t size, const gid_t *list)
112 group_list = g_string_new ("");
113 for (i = 0; i < size; i++)
116 g_string_append (group_list, ",");
117 g_string_append_printf (group_list, "%d", list[i]);
119 g_setenv ("LIGHTDM_TEST_GROUPS", group_list->str, TRUE);
120 g_string_free (group_list, TRUE);
138 setresgid (gid_t rgid, gid_t ugid, gid_t sgid)
156 setresuid (uid_t ruid, uid_t uuid, uid_t suid)
162 redirect_path (const gchar *path)
164 // Don't redirect if inside the running directory
165 if (g_str_has_prefix (path, g_getenv ("LIGHTDM_TEST_ROOT")))
166 return g_strdup (path);
168 if (g_str_has_prefix (path, SYSCONFDIR))
169 return g_build_filename (g_getenv ("LIGHTDM_TEST_ROOT"), "etc", path + strlen (SYSCONFDIR), NULL);
171 if (g_str_has_prefix (path, LOCALSTATEDIR))
172 return g_build_filename (g_getenv ("LIGHTDM_TEST_ROOT"), "var", path + strlen (LOCALSTATEDIR), NULL);
174 if (g_str_has_prefix (path, DATADIR))
175 return g_build_filename (g_getenv ("LIGHTDM_TEST_ROOT"), "usr", "share", path + strlen (DATADIR), NULL);
177 // Don't redirect if inside the build directory
178 if (g_str_has_prefix (path, BUILDDIR))
179 return g_strdup (path);
181 if (g_str_has_prefix (path, "/tmp"))
182 return g_build_filename (g_getenv ("LIGHTDM_TEST_ROOT"), "tmp", path + strlen ("tmp"), NULL);
184 return g_strdup (path);
189 open_wrapper (const char *func, const char *pathname, int flags, mode_t mode)
191 int (*_open) (const char *pathname, int flags, mode_t mode);
192 gchar *new_path = NULL;
195 _open = (int (*)(const char *pathname, int flags, mode_t mode)) dlsym (RTLD_NEXT, func);
197 if (strcmp (pathname, "/dev/console") == 0)
201 console_fd = _open ("/dev/null", flags, mode);
202 fcntl (console_fd, F_SETFD, FD_CLOEXEC);
207 new_path = redirect_path (pathname);
208 fd = _open (new_path, flags, mode);
215 open (const char *pathname, int flags, ...)
221 va_start (ap, flags);
222 mode = va_arg (ap, mode_t);
225 return open_wrapper ("open", pathname, flags, mode);
229 open64 (const char *pathname, int flags, ...)
235 va_start (ap, flags);
236 mode = va_arg (ap, mode_t);
239 return open_wrapper ("open64", pathname, flags, mode);
243 fopen (const char *path, const char *mode)
245 FILE *(*_fopen) (const char *pathname, const char *mode);
246 gchar *new_path = NULL;
249 _fopen = (FILE *(*)(const char *pathname, const char *mode)) dlsym (RTLD_NEXT, "fopen");
251 new_path = redirect_path (path);
252 result = _fopen (new_path, mode);
259 creat (const char *pathname, mode_t mode)
261 int (*_creat) (const char *pathname, mode_t mode);
262 gchar *new_path = NULL;
265 _creat = (int (*)(const char *pathname, mode_t mode)) dlsym (RTLD_NEXT, "creat");
267 new_path = redirect_path (pathname);
268 result = _creat (new_path, mode);
275 creat64 (const char *pathname, mode_t mode)
277 int (*_creat64) (const char *pathname, mode_t mode);
278 gchar *new_path = NULL;
281 _creat64 = (int (*)(const char *pathname, mode_t mode)) dlsym (RTLD_NEXT, "creat64");
283 new_path = redirect_path (pathname);
284 result = _creat64 (new_path, mode);
291 access (const char *pathname, int mode)
293 int (*_access) (const char *pathname, int mode);
294 gchar *new_path = NULL;
297 /* Look like systemd is always running */
298 if (strcmp (pathname, "/run/systemd/seats/") == 0)
301 _access = (int (*)(const char *pathname, int mode)) dlsym (RTLD_NEXT, "access");
303 new_path = redirect_path (pathname);
304 ret = _access (new_path, mode);
311 stat (const char *path, struct stat *buf)
313 int (*_stat) (const char *path, struct stat *buf);
314 gchar *new_path = NULL;
317 _stat = (int (*)(const char *path, struct stat *buf)) dlsym (RTLD_NEXT, "stat");
319 new_path = redirect_path (path);
320 ret = _stat (new_path, buf);
327 stat64 (const char *path, struct stat64 *buf)
329 int (*_stat64) (const char *path, struct stat64 *buf);
330 gchar *new_path = NULL;
333 _stat64 = (int (*)(const char *path, struct stat64 *buf)) dlsym (RTLD_NEXT, "stat64");
335 new_path = redirect_path (path);
336 ret = _stat64 (new_path, buf);
343 __xstat (int version, const char *path, struct stat *buf)
345 int (*___xstat) (int version, const char *path, struct stat *buf);
346 gchar *new_path = NULL;
349 ___xstat = (int (*)(int version, const char *path, struct stat *buf)) dlsym (RTLD_NEXT, "__xstat");
351 new_path = redirect_path (path);
352 ret = ___xstat (version, new_path, buf);
359 __xstat64 (int version, const char *path, struct stat64 *buf)
361 int (*___xstat64) (int version, const char *path, struct stat64 *buf);
362 gchar *new_path = NULL;
365 ___xstat64 = (int (*)(int version, const char *path, struct stat64 *buf)) dlsym (RTLD_NEXT, "__xstat64");
367 new_path = redirect_path (path);
368 ret = ___xstat64 (version, new_path, buf);
375 opendir (const char *name)
377 DIR *(*_opendir) (const char *name);
378 gchar *new_path = NULL;
381 _opendir = (DIR *(*)(const char *name)) dlsym (RTLD_NEXT, "opendir");
383 new_path = redirect_path (name);
384 result = _opendir (new_path);
391 mkdir (const char *pathname, mode_t mode)
393 int (*_mkdir) (const char *pathname, mode_t mode);
394 gchar *new_path = NULL;
397 _mkdir = (int (*)(const char *pathname, mode_t mode)) dlsym (RTLD_NEXT, "mkdir");
399 new_path = redirect_path (pathname);
400 result = _mkdir (new_path, mode);
407 chown (const char *pathname, uid_t owner, gid_t group)
409 int (*_chown) (const char *pathname, uid_t owner, gid_t group);
410 gchar *new_path = NULL;
413 _chown = (int (*)(const char *pathname, uid_t owner, gid_t group)) dlsym (RTLD_NEXT, "chown");
415 new_path = redirect_path (pathname);
416 result = _chown (new_path, owner, group);
423 chmod (const char *path, mode_t mode)
425 int (*_chmod) (const char *path, mode_t mode);
426 gchar *new_path = NULL;
429 _chmod = (int (*)(const char *path, mode_t mode)) dlsym (RTLD_NEXT, "chmod");
431 new_path = redirect_path (path);
432 result = _chmod (new_path, mode);
439 ioctl (int d, unsigned long request, ...)
441 int (*_ioctl) (int d, int request, ...);
443 _ioctl = (int (*)(int d, int request, ...)) dlsym (RTLD_NEXT, "ioctl");
444 if (d > 0 && d == console_fd)
446 struct vt_stat *console_state;
453 va_start (ap, request);
454 console_state = va_arg (ap, struct vt_stat *);
456 console_state->v_active = active_vt;
459 va_start (ap, request);
460 vt = va_arg (ap, int);
465 if (!status_connected)
466 status_connected = status_connect (NULL);
467 status_notify ("VT ACTIVATE VT=%d", active_vt);
480 va_start (ap, request);
481 data = va_arg (ap, void *);
483 return _ioctl (d, request, data);
490 int (*_close) (int fd);
492 if (fd > 0 && fd == console_fd)
495 _close = (int (*)(int fd)) dlsym (RTLD_NEXT, "close");
501 free_user (gpointer data)
503 struct passwd *entry = data;
505 g_free (entry->pw_name);
506 g_free (entry->pw_passwd);
507 g_free (entry->pw_gecos);
508 g_free (entry->pw_dir);
509 g_free (entry->pw_shell);
514 load_passwd_file (void)
516 gchar *path, *data = NULL, **lines;
518 GError *error = NULL;
520 g_list_free_full (user_entries, free_user);
522 getpwent_link = NULL;
524 path = g_build_filename (g_getenv ("LIGHTDM_TEST_ROOT"), "etc", "passwd", NULL);
525 g_file_get_contents (path, &data, NULL, &error);
528 g_warning ("Error loading passwd file: %s", error->message);
529 g_clear_error (&error);
534 lines = g_strsplit (data, "\n", -1);
537 for (i = 0; lines[i]; i++)
539 gchar *line, **fields;
541 line = g_strstrip (lines[i]);
542 fields = g_strsplit (line, ":", -1);
543 if (g_strv_length (fields) == 7)
545 struct passwd *entry = malloc (sizeof (struct passwd));
547 entry->pw_name = g_strdup (fields[0]);
548 entry->pw_passwd = g_strdup (fields[1]);
549 entry->pw_uid = atoi (fields[2]);
550 entry->pw_gid = atoi (fields[3]);
551 entry->pw_gecos = g_strdup (fields[4]);
552 entry->pw_dir = g_strdup (fields[5]);
553 entry->pw_shell = g_strdup (fields[6]);
554 user_entries = g_list_append (user_entries, entry);
564 if (getpwent_link == NULL)
567 if (user_entries == NULL)
569 getpwent_link = user_entries;
573 if (getpwent_link->next == NULL)
575 getpwent_link = getpwent_link->next;
578 return getpwent_link->data;
584 getpwent_link = NULL;
590 getpwent_link = NULL;
594 getpwnam (const char *name)
603 for (link = user_entries; link; link = link->next)
605 struct passwd *entry = link->data;
606 if (strcmp (entry->pw_name, name) == 0)
622 for (link = user_entries; link; link = link->next)
624 struct passwd *entry = link->data;
625 if (entry->pw_uid == uid)
635 free_group (gpointer data)
637 struct group *entry = data;
639 g_free (entry->gr_name);
640 g_free (entry->gr_passwd);
641 g_strfreev (entry->gr_mem);
646 load_group_file (void)
648 gchar *path, *data = NULL, **lines;
650 GError *error = NULL;
652 g_list_free_full (group_entries, free_group);
653 group_entries = NULL;
655 path = g_build_filename (g_getenv ("LIGHTDM_TEST_ROOT"), "etc", "group", NULL);
656 g_file_get_contents (path, &data, NULL, &error);
659 g_warning ("Error loading group file: %s", error->message);
660 g_clear_error (&error);
665 lines = g_strsplit (data, "\n", -1);
668 for (i = 0; lines[i]; i++)
670 gchar *line, **fields;
672 line = g_strstrip (lines[i]);
673 fields = g_strsplit (line, ":", -1);
674 if (g_strv_length (fields) == 4)
676 struct group *entry = malloc (sizeof (struct group));
678 entry->gr_name = g_strdup (fields[0]);
679 entry->gr_passwd = g_strdup (fields[1]);
680 entry->gr_gid = atoi (fields[2]);
681 entry->gr_mem = g_strsplit (fields[3], ",", -1);
682 group_entries = g_list_append (group_entries, entry);
690 getgrnam (const char *name)
696 for (link = group_entries; link; link = link->next)
698 struct group *entry = link->data;
699 if (strcmp (entry->gr_name, name) == 0)
715 for (link = group_entries; link; link = link->next)
717 struct group *entry = link->data;
718 if (entry->gr_gid == gid)
728 pam_start (const char *service_name, const char *user, const struct pam_conv *conversation, pam_handle_t **pamh)
730 pam_handle_t *handle;
732 if (service_name == NULL || conversation == NULL || pamh == NULL)
733 return PAM_SYSTEM_ERR;
735 handle = *pamh = malloc (sizeof (pam_handle_t));
739 handle->service_name = strdup (service_name);
740 handle->user = user ? strdup (user) : NULL;
741 handle->authtok = NULL;
742 handle->ruser = NULL;
744 handle->conversation.conv = conversation->conv;
745 handle->conversation.appdata_ptr = conversation->appdata_ptr;
746 handle->envlist = malloc (sizeof (char *) * 1);
747 handle->envlist[0] = NULL;
753 send_info (pam_handle_t *pamh, const char *message)
755 struct pam_message **msg;
756 struct pam_response *resp = NULL;
758 msg = calloc (1, sizeof (struct pam_message *));
759 msg[0] = malloc (sizeof (struct pam_message));
760 msg[0]->msg_style = PAM_TEXT_INFO;
761 msg[0]->msg = message;
762 pamh->conversation.conv (1, (const struct pam_message **) msg, &resp, pamh->conversation.appdata_ptr);
774 pam_authenticate (pam_handle_t *pamh, int flags)
776 struct passwd *entry;
777 gboolean password_matches = FALSE;
780 return PAM_SYSTEM_ERR;
782 if (strcmp (pamh->service_name, "test-remote") == 0)
785 struct pam_message **msg;
786 struct pam_response *resp = NULL;
788 msg = malloc (sizeof (struct pam_message *) * 1);
789 msg[0] = malloc (sizeof (struct pam_message));
790 msg[0]->msg_style = PAM_PROMPT_ECHO_ON;
791 msg[0]->msg = "remote-login:";
792 result = pamh->conversation.conv (1, (const struct pam_message **) msg, &resp, pamh->conversation.appdata_ptr);
795 if (result != PAM_SUCCESS)
800 if (resp[0].resp == NULL)
808 pamh->ruser = strdup (resp[0].resp);
812 msg = malloc (sizeof (struct pam_message *) * 1);
813 msg[0] = malloc (sizeof (struct pam_message));
814 msg[0]->msg_style = PAM_PROMPT_ECHO_OFF;
815 msg[0]->msg = "remote-password:";
816 result = pamh->conversation.conv (1, (const struct pam_message **) msg, &resp, pamh->conversation.appdata_ptr);
819 if (result != PAM_SUCCESS)
824 if (resp[0].resp == NULL)
831 free (pamh->authtok);
832 pamh->authtok = strdup (resp[0].resp);
836 password_matches = strcmp (pamh->ruser, "remote-user") == 0 && strcmp (pamh->authtok, "password") == 0;
838 if (password_matches)
844 /* Prompt for username */
845 if (pamh->user == NULL)
848 struct pam_message **msg;
849 struct pam_response *resp = NULL;
851 msg = malloc (sizeof (struct pam_message *) * 1);
852 msg[0] = malloc (sizeof (struct pam_message));
853 msg[0]->msg_style = PAM_PROMPT_ECHO_ON;
854 msg[0]->msg = LOGIN_PROMPT;
855 result = pamh->conversation.conv (1, (const struct pam_message **) msg, &resp, pamh->conversation.appdata_ptr);
858 if (result != PAM_SUCCESS)
863 if (resp[0].resp == NULL)
869 pamh->user = strdup (resp[0].resp);
874 if (strcmp (pamh->user, "log-pam") == 0)
875 send_info (pamh, "pam_authenticate");
877 /* Crash on authenticate */
878 if (strcmp (pamh->user, "crash-authenticate") == 0)
879 kill (getpid (), SIGSEGV);
881 /* Look up password database */
882 entry = getpwnam (pamh->user);
884 /* Prompt for password if required */
885 if (entry && strcmp (pamh->user, "always-password") != 0 && (strcmp (pamh->service_name, "lightdm-autologin") == 0 || strcmp (entry->pw_passwd, "") == 0))
886 password_matches = TRUE;
889 int i, n_messages = 0, password_index, result;
890 struct pam_message **msg;
891 struct pam_response *resp = NULL;
893 msg = malloc (sizeof (struct pam_message *) * 5);
894 if (strcmp (pamh->user, "info-prompt") == 0)
896 msg[n_messages] = malloc (sizeof (struct pam_message));
897 msg[n_messages]->msg_style = PAM_TEXT_INFO;
898 msg[n_messages]->msg = "Welcome to LightDM";
901 if (strcmp (pamh->user, "multi-info-prompt") == 0)
903 msg[n_messages] = malloc (sizeof (struct pam_message));
904 msg[n_messages]->msg_style = PAM_TEXT_INFO;
905 msg[n_messages]->msg = "Welcome to LightDM";
907 msg[n_messages] = malloc (sizeof (struct pam_message));
908 msg[n_messages]->msg_style = PAM_ERROR_MSG;
909 msg[n_messages]->msg = "This is an error";
911 msg[n_messages] = malloc (sizeof (struct pam_message));
912 msg[n_messages]->msg_style = PAM_TEXT_INFO;
913 msg[n_messages]->msg = "You should have seen three messages";
916 if (strcmp (pamh->user, "multi-prompt") == 0)
918 msg[n_messages] = malloc (sizeof (struct pam_message));
919 msg[n_messages]->msg_style = PAM_PROMPT_ECHO_ON;
920 msg[n_messages]->msg = "Favorite Color:";
923 msg[n_messages] = malloc (sizeof (struct pam_message));
924 msg[n_messages]->msg_style = PAM_PROMPT_ECHO_OFF;
925 msg[n_messages]->msg = "Password:";
926 password_index = n_messages;
928 result = pamh->conversation.conv (n_messages, (const struct pam_message **) msg, &resp, pamh->conversation.appdata_ptr);
929 for (i = 0; i < n_messages; i++)
932 if (result != PAM_SUCCESS)
937 if (resp[password_index].resp == NULL)
944 password_matches = strcmp (entry->pw_passwd, resp[password_index].resp) == 0;
946 if (password_matches && strcmp (pamh->user, "multi-prompt") == 0)
947 password_matches = strcmp ("blue", resp[0].resp) == 0;
949 for (i = 0; i < n_messages; i++)
956 /* Do two factor authentication */
957 if (password_matches && strcmp (pamh->user, "two-factor") == 0)
959 msg = malloc (sizeof (struct pam_message *) * 1);
960 msg[0] = malloc (sizeof (struct pam_message));
961 msg[0]->msg_style = PAM_PROMPT_ECHO_ON;
962 msg[0]->msg = "OTP:";
964 result = pamh->conversation.conv (1, (const struct pam_message **) msg, &resp, pamh->conversation.appdata_ptr);
970 if (resp[0].resp == NULL)
975 password_matches = strcmp (resp[0].resp, "otp") == 0;
981 /* Special user has home directory created on login */
982 if (password_matches && strcmp (pamh->user, "mount-home-dir") == 0)
983 g_mkdir_with_parents (entry->pw_dir, 0755);
985 /* Special user 'change-user1' changes user on authentication */
986 if (password_matches && strcmp (pamh->user, "change-user1") == 0)
989 pamh->user = g_strdup ("change-user2");
992 /* Special user 'change-user-invalid' changes to an invalid user on authentication */
993 if (password_matches && strcmp (pamh->user, "change-user-invalid") == 0)
996 pamh->user = g_strdup ("invalid-user");
999 if (password_matches)
1002 return PAM_AUTH_ERR;
1006 get_env_value (const char *name_value, const char *name)
1010 for (j = 0; name[j] && name_value[j] && name[j] == name_value[j]; j++);
1011 if (name[j] == '\0' && name_value[j] == '=')
1012 return &name_value[j + 1];
1018 pam_putenv (pam_handle_t *pamh, const char *name_value)
1023 if (pamh == NULL || name_value == NULL)
1024 return PAM_SYSTEM_ERR;
1026 name = strdup (name_value);
1027 for (i = 0; name[i]; i++)
1030 for (i = 0; pamh->envlist[i]; i++)
1032 if (get_env_value (pamh->envlist[i], name))
1037 if (pamh->envlist[i])
1039 free (pamh->envlist[i]);
1040 pamh->envlist[i] = strdup (name_value);
1044 pamh->envlist = realloc (pamh->envlist, sizeof (char *) * (i + 2));
1045 pamh->envlist[i] = strdup (name_value);
1046 pamh->envlist[i + 1] = NULL;
1053 pam_getenv (pam_handle_t *pamh, const char *name)
1057 if (pamh == NULL || name == NULL)
1060 for (i = 0; pamh->envlist[i]; i++)
1063 value = get_env_value (pamh->envlist[i], name);
1072 pam_getenvlist (pam_handle_t *pamh)
1077 return pamh->envlist;
1081 pam_set_item (pam_handle_t *pamh, int item_type, const void *item)
1083 if (pamh == NULL || item == NULL)
1084 return PAM_SYSTEM_ERR;
1091 pamh->tty = strdup ((const char *) item);
1095 return PAM_BAD_ITEM;
1100 pam_get_item (const pam_handle_t *pamh, int item_type, const void **item)
1102 if (pamh == NULL || item == NULL)
1103 return PAM_SYSTEM_ERR;
1108 *item = pamh->service_name;
1116 *item = pamh->authtok;
1120 *item = pamh->ruser;
1123 case PAM_USER_PROMPT:
1124 *item = LOGIN_PROMPT;
1132 *item = &pamh->conversation;
1136 return PAM_BAD_ITEM;
1141 pam_open_session (pam_handle_t *pamh, int flags)
1144 return PAM_SYSTEM_ERR;
1146 if (strcmp (pamh->user, "session-error") == 0)
1147 return PAM_SESSION_ERR;
1149 if (strcmp (pamh->user, "log-pam") == 0)
1150 send_info (pamh, "pam_open_session");
1152 if (strcmp (pamh->user, "make-home-dir") == 0)
1154 struct passwd *entry;
1155 entry = getpwnam (pamh->user);
1156 g_mkdir_with_parents (entry->pw_dir, 0755);
1163 pam_close_session (pam_handle_t *pamh, int flags)
1166 return PAM_SYSTEM_ERR;
1168 if (strcmp (pamh->user, "log-pam") == 0)
1169 send_info (pamh, "pam_close_session");
1175 pam_acct_mgmt (pam_handle_t *pamh, int flags)
1178 return PAM_SYSTEM_ERR;
1181 return PAM_USER_UNKNOWN;
1183 if (strcmp (pamh->user, "log-pam") == 0)
1184 send_info (pamh, "pam_acct_mgmt");
1186 if (strcmp (pamh->user, "denied") == 0)
1187 return PAM_PERM_DENIED;
1188 if (strcmp (pamh->user, "expired") == 0)
1189 return PAM_ACCT_EXPIRED;
1190 if (strcmp (pamh->user, "new-authtok") == 0)
1191 return PAM_NEW_AUTHTOK_REQD;
1197 pam_chauthtok (pam_handle_t *pamh, int flags)
1199 struct passwd *entry;
1201 struct pam_message **msg;
1202 struct pam_response *resp = NULL;
1205 return PAM_SYSTEM_ERR;
1207 if (strcmp (pamh->user, "log-pam") == 0)
1208 send_info (pamh, "pam_chauthtok");
1210 msg = malloc (sizeof (struct pam_message *) * 1);
1211 msg[0] = malloc (sizeof (struct pam_message));
1212 msg[0]->msg_style = PAM_PROMPT_ECHO_OFF;
1213 msg[0]->msg = "Enter new password:";
1214 result = pamh->conversation.conv (1, (const struct pam_message **) msg, &resp, pamh->conversation.appdata_ptr);
1217 if (result != PAM_SUCCESS)
1221 return PAM_CONV_ERR;
1222 if (resp[0].resp == NULL)
1225 return PAM_CONV_ERR;
1228 /* Update password database */
1229 entry = getpwnam (pamh->user);
1230 free (entry->pw_passwd);
1231 entry->pw_passwd = resp[0].resp;
1238 pam_setcred (pam_handle_t *pamh, int flags)
1243 return PAM_SYSTEM_ERR;
1245 if (strcmp (pamh->user, "log-pam") == 0)
1246 send_info (pamh, "pam_setcred");
1248 /* Put the test directories into the path */
1249 e = g_strdup_printf ("PATH=%s/tests/src/.libs:%s/tests/src:%s/tests/src:%s/src:%s", BUILDDIR, BUILDDIR, SRCDIR, BUILDDIR, pam_getenv (pamh, "PATH"));
1250 pam_putenv (pamh, e);
1253 if (strcmp (pamh->user, "cred-error") == 0)
1254 return PAM_CRED_ERR;
1255 if (strcmp (pamh->user, "cred-expired") == 0)
1256 return PAM_CRED_EXPIRED;
1257 if (strcmp (pamh->user, "cred-unavail") == 0)
1258 return PAM_CRED_UNAVAIL;
1260 /* Join special groups if requested */
1261 if (strcmp (pamh->user, "group-member") == 0 && flags & PAM_ESTABLISH_CRED)
1263 struct group *group;
1267 group = getgrnam ("test-group");
1270 groups_length = getgroups (0, NULL);
1271 if (groups_length < 0)
1272 return PAM_SYSTEM_ERR;
1273 groups = malloc (sizeof (gid_t) * (groups_length + 1));
1274 groups_length = getgroups (groups_length, groups);
1275 if (groups_length < 0)
1276 return PAM_SYSTEM_ERR;
1277 groups[groups_length] = group->gr_gid;
1279 setgroups (groups_length, groups);
1283 /* We need to pass our group overrides down the child process - the environment via PAM seems the only way to do it easily */
1284 pam_putenv (pamh, g_strdup_printf ("LIGHTDM_TEST_GROUPS=%s", g_getenv ("LIGHTDM_TEST_GROUPS")));
1291 pam_end (pam_handle_t *pamh, int pam_status)
1294 return PAM_SYSTEM_ERR;
1296 free (pamh->service_name);
1300 free (pamh->authtok);
1311 pam_strerror (pam_handle_t *pamh, int errnum)
1321 return "Critical error - immediate abort";
1323 return "Failed to load module";
1324 case PAM_SYMBOL_ERR:
1325 return "Symbol not found";
1326 case PAM_SERVICE_ERR:
1327 return "Error in service module";
1328 case PAM_SYSTEM_ERR:
1329 return "System error";
1331 return "Memory buffer error";
1332 case PAM_PERM_DENIED:
1333 return "Permission denied";
1335 return "Authentication failure";
1336 case PAM_CRED_INSUFFICIENT:
1337 return "Insufficient credentials to access authentication data";
1338 case PAM_AUTHINFO_UNAVAIL:
1339 return "Authentication service cannot retrieve authentication info";
1340 case PAM_USER_UNKNOWN:
1341 return "User not known to the underlying authentication module";
1343 return "Have exhausted maximum number of retries for service";
1344 case PAM_NEW_AUTHTOK_REQD:
1345 return "Authentication token is no longer valid; new one required";
1346 case PAM_ACCT_EXPIRED:
1347 return "User account has expired";
1348 case PAM_SESSION_ERR:
1349 return "Cannot make/remove an entry for the specified session";
1350 case PAM_CRED_UNAVAIL:
1351 return "Authentication service cannot retrieve user credentials";
1352 case PAM_CRED_EXPIRED:
1353 return "User credentials expired";
1355 return "Failure setting user credentials";
1356 case PAM_NO_MODULE_DATA:
1357 return "No module specific data is present";
1359 return "Bad item passed to pam_*_item()";
1361 return "Conversation error";
1362 case PAM_AUTHTOK_ERR:
1363 return "Authentication token manipulation error";
1364 case PAM_AUTHTOK_RECOVERY_ERR:
1365 return "Authentication information cannot be recovered";
1366 case PAM_AUTHTOK_LOCK_BUSY:
1367 return "Authentication token lock busy";
1368 case PAM_AUTHTOK_DISABLE_AGING:
1369 return "Authentication token aging disabled";
1371 return "Failed preliminary check by password service";
1373 return "The return value should be ignored by PAM dispatch";
1374 case PAM_MODULE_UNKNOWN:
1375 return "Module is unknown";
1376 case PAM_AUTHTOK_EXPIRED:
1377 return "Authentication token expired";
1378 case PAM_CONV_AGAIN:
1379 return "Conversation is waiting for event";
1380 case PAM_INCOMPLETE:
1381 return "Application needs to call libpam again";
1383 return "Unknown PAM error";
1393 pututxline (const struct utmpx *ut)
1395 return (struct utmpx *)ut;
1403 struct xcb_connection_t
1411 xcb_connect_to_display_with_auth_info (const char *display, xcb_auth_info_t *auth, int *screen)
1413 xcb_connection_t *c;
1415 GError *error = NULL;
1417 c = malloc (sizeof (xcb_connection_t));
1418 c->display = g_strdup (display);
1421 if (display == NULL)
1422 display = getenv ("DISPLAY");
1423 if (display == NULL)
1424 c->error = XCB_CONN_CLOSED_PARSE_ERR;
1428 c->socket = g_socket_new (G_SOCKET_FAMILY_UNIX, G_SOCKET_TYPE_STREAM, G_SOCKET_PROTOCOL_DEFAULT, &error);
1430 g_printerr ("%s\n", error->message);
1431 g_clear_error (&error);
1432 if (c->socket == NULL)
1433 c->error = XCB_CONN_ERROR;
1439 GSocketAddress *address;
1441 /* Skip the hostname, we'll assume it's localhost */
1442 d = g_strdup_printf (".x%s", strchr (display, ':'));
1444 socket_path = g_build_filename (g_getenv ("LIGHTDM_TEST_ROOT"), d, NULL);
1446 address = g_unix_socket_address_new (socket_path);
1447 if (!g_socket_connect (c->socket, address, NULL, &error))
1448 c->error = XCB_CONN_ERROR;
1449 g_object_unref (address);
1451 g_printerr ("Failed to connect to X socket %s: %s\n", socket_path, error->message);
1452 g_free (socket_path);
1453 g_clear_error (&error);
1456 // FIXME: Send auth info
1465 xcb_connect (const char *displayname, int *screenp)
1467 return xcb_connect_to_display_with_auth_info(displayname, NULL, screenp);
1471 xcb_connection_has_error (xcb_connection_t *c)
1477 xcb_disconnect (xcb_connection_t *c)
1481 g_object_unref (c->socket);