summaryrefslogtreecommitdiff
path: root/tests/src/libsystem.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/src/libsystem.c')
-rw-r--r--tests/src/libsystem.c487
1 files changed, 150 insertions, 337 deletions
diff --git a/tests/src/libsystem.c b/tests/src/libsystem.c
index 62fe6480..b47b4523 100644
--- a/tests/src/libsystem.c
+++ b/tests/src/libsystem.c
@@ -106,27 +106,21 @@ initgroups (const char *user, gid_t group)
int
getgroups (int size, gid_t list[])
{
- const gchar *group_list;
- g_auto(GStrv) groups = NULL;
- gint groups_length;
-
/* Get groups we are a member of */
- group_list = g_getenv ("LIGHTDM_TEST_GROUPS");
+ const gchar *group_list = g_getenv ("LIGHTDM_TEST_GROUPS");
if (!group_list)
group_list = "";
- groups = g_strsplit (group_list, ",", -1);
- groups_length = g_strv_length (groups);
+ g_auto(GStrv) groups = g_strsplit (group_list, ",", -1);
+ gint groups_length = g_strv_length (groups);
if (size != 0)
{
- int i;
-
if (groups_length > size)
{
errno = EINVAL;
return -1;
}
- for (i = 0; groups[i]; i++)
+ for (int i = 0; groups[i]; i++)
list[i] = atoi (groups[i]);
}
@@ -136,11 +130,8 @@ getgroups (int size, gid_t list[])
int
setgroups (size_t size, const gid_t *list)
{
- size_t i;
- g_autoptr(GString) group_list = NULL;
-
- group_list = g_string_new ("");
- for (i = 0; i < size; i++)
+ g_autoptr(GString) group_list = g_string_new ("");
+ for (size_t i = 0; i < size; i++)
{
if (i != 0)
g_string_append (group_list, ",");
@@ -226,11 +217,7 @@ redirect_path (const gchar *path)
static int
open_wrapper (const char *func, const char *pathname, int flags, mode_t mode)
{
- int (*_open) (const char *pathname, int flags, mode_t mode);
- g_autofree gchar *new_path = NULL;
- int fd;
-
- _open = (int (*)(const char *pathname, int flags, mode_t mode)) dlsym (RTLD_NEXT, func);
+ int (*_open) (const char *pathname, int flags, mode_t mode) = dlsym (RTLD_NEXT, func);
if (strcmp (pathname, "/dev/tty0") == 0)
{
@@ -242,10 +229,8 @@ open_wrapper (const char *func, const char *pathname, int flags, mode_t mode)
return tty_fd;
}
- new_path = redirect_path (pathname);
- fd = _open (new_path, flags, mode);
-
- return fd;
+ g_autofree gchar *new_path = redirect_path (pathname);
+ return _open (new_path, flags, mode);
}
int
@@ -279,173 +264,122 @@ open64 (const char *pathname, int flags, ...)
FILE *
fopen (const char *path, const char *mode)
{
- FILE *(*_fopen) (const char *pathname, const char *mode);
- g_autofree gchar *new_path = NULL;
- FILE *result;
-
- _fopen = (FILE *(*)(const char *pathname, const char *mode)) dlsym (RTLD_NEXT, "fopen");
+ FILE *(*_fopen) (const char *pathname, const char *mode) = dlsym (RTLD_NEXT, "fopen");
- new_path = redirect_path (path);
- result = _fopen (new_path, mode);
-
- return result;
+ g_autofree gchar *new_path = redirect_path (path);
+ return _fopen (new_path, mode);
}
int
unlinkat (int dirfd, const char *pathname, int flags)
{
- int (*_unlinkat) (int dirfd, const char *pathname, int flags);
- g_autofree gchar *new_path = NULL;
- int result;
-
- _unlinkat = (int (*)(int dirfd, const char *pathname, int flags)) dlsym (RTLD_NEXT, "unlinkat");
+ int (*_unlinkat) (int dirfd, const char *pathname, int flags) = dlsym (RTLD_NEXT, "unlinkat");
- new_path = redirect_path (pathname);
- result = _unlinkat (dirfd, new_path, flags);
-
- return result;
+ g_autofree gchar *new_path = redirect_path (pathname);
+ return _unlinkat (dirfd, new_path, flags);
}
int
creat (const char *pathname, mode_t mode)
{
- int (*_creat) (const char *pathname, mode_t mode);
- g_autofree gchar *new_path = NULL;
- int result;
-
- _creat = (int (*)(const char *pathname, mode_t mode)) dlsym (RTLD_NEXT, "creat");
+ int (*_creat) (const char *pathname, mode_t mode) = dlsym (RTLD_NEXT, "creat");
- new_path = redirect_path (pathname);
- result = _creat (new_path, mode);
-
- return result;
+ g_autofree gchar *new_path = redirect_path (pathname);
+ return _creat (new_path, mode);
}
int
creat64 (const char *pathname, mode_t mode)
{
- int (*_creat64) (const char *pathname, mode_t mode);
- g_autofree gchar *new_path = NULL;
- int result;
-
- _creat64 = (int (*)(const char *pathname, mode_t mode)) dlsym (RTLD_NEXT, "creat64");
+ int (*_creat64) (const char *pathname, mode_t mode) = dlsym (RTLD_NEXT, "creat64");
- new_path = redirect_path (pathname);
- result = _creat64 (new_path, mode);
-
- return result;
+ g_autofree gchar *new_path = redirect_path (pathname);
+ return _creat64 (new_path, mode);
}
int
access (const char *pathname, int mode)
{
- int (*_access) (const char *pathname, int mode);
- g_autofree gchar *new_path = NULL;
-
- _access = (int (*)(const char *pathname, int mode)) dlsym (RTLD_NEXT, "access");
+ int (*_access) (const char *pathname, int mode) = dlsym (RTLD_NEXT, "access");
if (strcmp (pathname, "/dev/tty0") == 0)
return F_OK;
if (strcmp (pathname, "/sys/class/tty/tty0/active") == 0)
return F_OK;
- new_path = redirect_path (pathname);
+ g_autofree gchar *new_path = redirect_path (pathname);
return _access (new_path, mode);
}
int
stat (const char *path, struct stat *buf)
{
- int (*_stat) (const char *path, struct stat *buf);
- g_autofree gchar *new_path = NULL;
+ int (*_stat) (const char *path, struct stat *buf) = dlsym (RTLD_NEXT, "stat");
- _stat = (int (*)(const char *path, struct stat *buf)) dlsym (RTLD_NEXT, "stat");
-
- new_path = redirect_path (path);
+ g_autofree gchar *new_path = redirect_path (path);
return _stat (new_path, buf);
}
int
stat64 (const char *path, struct stat64 *buf)
{
- int (*_stat64) (const char *path, struct stat64 *buf);
- g_autofree gchar *new_path = NULL;
-
- _stat64 = (int (*)(const char *path, struct stat64 *buf)) dlsym (RTLD_NEXT, "stat64");
+ int (*_stat64) (const char *path, struct stat64 *buf) = dlsym (RTLD_NEXT, "stat64");
- new_path = redirect_path (path);
+ g_autofree gchar *new_path = redirect_path (path);
return _stat64 (new_path, buf);
}
int
__xstat (int version, const char *path, struct stat *buf)
{
- int (*___xstat) (int version, const char *path, struct stat *buf);
- g_autofree gchar *new_path = NULL;
+ int (*___xstat) (int version, const char *path, struct stat *buf) = dlsym (RTLD_NEXT, "__xstat");
- ___xstat = (int (*)(int version, const char *path, struct stat *buf)) dlsym (RTLD_NEXT, "__xstat");
-
- new_path = redirect_path (path);
+ g_autofree gchar *new_path = redirect_path (path);
return ___xstat (version, new_path, buf);
}
int
__xstat64 (int version, const char *path, struct stat64 *buf)
{
- int (*___xstat64) (int version, const char *path, struct stat64 *buf);
- g_autofree gchar *new_path = NULL;
-
- ___xstat64 = (int (*)(int version, const char *path, struct stat64 *buf)) dlsym (RTLD_NEXT, "__xstat64");
+ int (*___xstat64) (int version, const char *path, struct stat64 *buf) = dlsym (RTLD_NEXT, "__xstat64");
- new_path = redirect_path (path);
+ g_autofree gchar *new_path = redirect_path (path);
return ___xstat64 (version, new_path, buf);
}
int
__fxstatat(int ver, int dirfd, const char *pathname, struct stat *buf, int flags)
{
- int (*___fxstatat) (int ver, int dirfd, const char *pathname, struct stat *buf, int flags);
- g_autofree gchar *new_path = NULL;
+ int (*___fxstatat) (int ver, int dirfd, const char *pathname, struct stat *buf, int flags) = dlsym (RTLD_NEXT, "__fxstatat");
- ___fxstatat = (int (*)(int ver, int dirfd, const char *pathname, struct stat *buf, int flags)) dlsym (RTLD_NEXT, "__fxstatat");
-
- new_path = redirect_path (pathname);
+ g_autofree gchar *new_path = redirect_path (pathname);
return ___fxstatat (ver, dirfd, new_path, buf, flags);
}
int
__fxstatat64(int ver, int dirfd, const char *pathname, struct stat64 *buf, int flags)
{
- int (*___fxstatat64) (int ver, int dirfd, const char *pathname, struct stat64 *buf, int flags);
- g_autofree gchar *new_path = NULL;
-
- ___fxstatat64 = (int (*)(int ver, int dirfd, const char *pathname, struct stat64 *buf, int flags)) dlsym (RTLD_NEXT, "__fxstatat64");
+ int (*___fxstatat64) (int ver, int dirfd, const char *pathname, struct stat64 *buf, int flags) = dlsym (RTLD_NEXT, "__fxstatat64");
- new_path = redirect_path (pathname);
+ g_autofree gchar *new_path = redirect_path (pathname);
return ___fxstatat64 (ver, dirfd, new_path, buf, flags);
}
DIR *
opendir (const char *name)
{
- DIR *(*_opendir) (const char *name);
- g_autofree gchar *new_path = NULL;
+ DIR *(*_opendir) (const char *name) = dlsym (RTLD_NEXT, "opendir");
- _opendir = (DIR *(*)(const char *name)) dlsym (RTLD_NEXT, "opendir");
-
- new_path = redirect_path (name);
+ g_autofree gchar *new_path = redirect_path (name);
return _opendir (new_path);
}
int
mkdir (const char *pathname, mode_t mode)
{
- int (*_mkdir) (const char *pathname, mode_t mode);
- g_autofree gchar *new_path = NULL;
-
- _mkdir = (int (*)(const char *pathname, mode_t mode)) dlsym (RTLD_NEXT, "mkdir");
+ int (*_mkdir) (const char *pathname, mode_t mode) = dlsym (RTLD_NEXT, "mkdir");
- new_path = redirect_path (pathname);
+ g_autofree gchar *new_path = redirect_path (pathname);
return _mkdir (new_path, mode);
}
@@ -459,38 +393,31 @@ chown (const char *pathname, uid_t owner, gid_t group)
int
chmod (const char *path, mode_t mode)
{
- int (*_chmod) (const char *path, mode_t mode);
- g_autofree gchar *new_path = NULL;
+ int (*_chmod) (const char *path, mode_t mode) = dlsym (RTLD_NEXT, "chmod");
- _chmod = (int (*)(const char *path, mode_t mode)) dlsym (RTLD_NEXT, "chmod");
-
- new_path = redirect_path (path);
+ g_autofree gchar *new_path = redirect_path (path);
return _chmod (new_path, mode);
}
int
ioctl (int d, unsigned long request, ...)
{
- int (*_ioctl) (int d, int request, ...);
+ int (*_ioctl) (int d, int request, ...) = dlsym (RTLD_NEXT, "ioctl");
- _ioctl = (int (*)(int d, int request, ...)) dlsym (RTLD_NEXT, "ioctl");
if (d > 0 && d == tty_fd)
{
- struct vt_stat *vt_state;
- int vt;
va_list ap;
-
switch (request)
{
case VT_GETSTATE:
va_start (ap, request);
- vt_state = va_arg (ap, struct vt_stat *);
+ struct vt_stat *vt_state = va_arg (ap, struct vt_stat *);
va_end (ap);
vt_state->v_active = active_vt;
break;
case VT_ACTIVATE:
va_start (ap, request);
- vt = va_arg (ap, int);
+ int vt = va_arg (ap, int);
va_end (ap);
if (vt != active_vt)
{
@@ -507,10 +434,9 @@ ioctl (int d, unsigned long request, ...)
else
{
va_list ap;
- void *data;
va_start (ap, request);
- data = va_arg (ap, void *);
+ void *data = va_arg (ap, void *);
va_end (ap);
return _ioctl (d, request, data);
}
@@ -519,54 +445,39 @@ ioctl (int d, unsigned long request, ...)
static void
add_port_redirect (int requested_port, int redirected_port)
{
- g_autoptr(GKeyFile) file = NULL;
- g_autofree gchar *path = NULL;
- g_autofree gchar *name = NULL;
- g_autofree gchar *data = NULL;
-
- file = g_key_file_new ();
- path = g_build_filename (g_getenv ("LIGHTDM_TEST_ROOT"), ".port-redirects", NULL);
+ g_autoptr(GKeyFile) file = g_key_file_new ();
+ g_autofree gchar *path = g_build_filename (g_getenv ("LIGHTDM_TEST_ROOT"), ".port-redirects", NULL);
g_key_file_load_from_file (file, path, G_KEY_FILE_NONE, NULL);
- name = g_strdup_printf ("%d", requested_port);
+ g_autofree gchar *name = g_strdup_printf ("%d", requested_port);
g_key_file_set_integer (file, name, "redirected", redirected_port);
- data = g_key_file_to_data (file, NULL, NULL);
+ g_autofree gchar *data = g_key_file_to_data (file, NULL, NULL);
g_file_set_contents (path, data, -1, NULL);
}
static int
find_port_redirect (int port)
{
- g_autoptr(GKeyFile) file = NULL;
- g_autofree gchar *path = NULL;
- g_autofree gchar *name = NULL;
- int redirected_port;
-
- file = g_key_file_new ();
- path = g_build_filename (g_getenv ("LIGHTDM_TEST_ROOT"), ".port-redirects", NULL);
+ g_autoptr(GKeyFile) file = g_key_file_new ();
+ g_autofree gchar *path = g_build_filename (g_getenv ("LIGHTDM_TEST_ROOT"), ".port-redirects", NULL);
g_key_file_load_from_file (file, path, G_KEY_FILE_NONE, NULL);
- name = g_strdup_printf ("%d", port);
- redirected_port = g_key_file_get_integer (file, name, "redirected", NULL);
-
- return redirected_port;
+ g_autofree gchar *name = g_strdup_printf ("%d", port);
+ return g_key_file_get_integer (file, name, "redirected", NULL);
}
int
bind (int sockfd, const struct sockaddr *addr, socklen_t addrlen)
{
- int port = 0, redirected_port = 0;
- const char *path;
- int (*_bind) (int sockfd, const struct sockaddr *addr, socklen_t addrlen);
+ int (*_bind) (int sockfd, const struct sockaddr *addr, socklen_t addrlen) = dlsym (RTLD_NEXT, "bind");
+
const struct sockaddr *modified_addr = addr;
struct sockaddr_in temp_addr_in;
struct sockaddr_in6 temp_addr_in6;
struct sockaddr_un temp_addr_un;
- int retval;
-
- _bind = (int (*)(int sockfd, const struct sockaddr *addr, socklen_t addrlen)) dlsym (RTLD_NEXT, "bind");
-
+ int port = 0, redirected_port = 0;
+ const char *path;
switch (addr->sa_family)
{
case AF_UNIX:
@@ -601,7 +512,7 @@ bind (int sockfd, const struct sockaddr *addr, socklen_t addrlen)
break;
}
- retval = _bind (sockfd, modified_addr, addrlen);
+ int retval = _bind (sockfd, modified_addr, addrlen);
socklen_t temp_addr_len;
switch (addr->sa_family)
@@ -634,16 +545,14 @@ bind (int sockfd, const struct sockaddr *addr, socklen_t addrlen)
int
connect (int sockfd, const struct sockaddr *addr, socklen_t addrlen)
{
- int port, redirected_port;
- const char *path;
+ int (*_connect) (int sockfd, const struct sockaddr *addr, socklen_t addrlen) = dlsym (RTLD_NEXT, "connect");
+
const struct sockaddr *modified_addr = addr;
struct sockaddr_in temp_addr_in;
struct sockaddr_in6 temp_addr_in6;
struct sockaddr_un temp_addr_un;
- int (*_connect) (int sockfd, const struct sockaddr *addr, socklen_t addrlen);
-
- _connect = (int (*)(int sockfd, const struct sockaddr *addr, socklen_t addrlen)) dlsym (RTLD_NEXT, "connect");
-
+ int port = 0, redirected_port = 0;
+ const char *path;
switch (addr->sa_family)
{
case AF_UNIX:
@@ -684,16 +593,14 @@ connect (int sockfd, const struct sockaddr *addr, socklen_t addrlen)
ssize_t
sendto (int sockfd, const void *buf, size_t len, int flags, const struct sockaddr *dest_addr, socklen_t addrlen)
{
+ ssize_t (*_sendto) (int sockfd, const void *buf, size_t len, int flags, const struct sockaddr *dest_addr, socklen_t addrlen) = dlsym (RTLD_NEXT, "sendto");
+
int port, redirected_port;
const char *path;
const struct sockaddr *modified_addr = dest_addr;
struct sockaddr_in temp_addr_in;
struct sockaddr_in6 temp_addr_in6;
struct sockaddr_un temp_addr_un;
- ssize_t (*_sendto) (int sockfd, const void *buf, size_t len, int flags, const struct sockaddr *dest_addr, socklen_t addrlen);
-
- _sendto = (ssize_t (*)(int sockfd, const void *buf, size_t len, int flags, const struct sockaddr *dest_addr, socklen_t addrlen)) dlsym (RTLD_NEXT, "sendto");
-
switch (dest_addr->sa_family)
{
case AF_UNIX:
@@ -734,12 +641,10 @@ sendto (int sockfd, const void *buf, size_t len, int flags, const struct sockadd
int
close (int fd)
{
- int (*_close) (int fd);
-
if (fd > 0 && fd == tty_fd)
return 0;
- _close = (int (*)(int fd)) dlsym (RTLD_NEXT, "close");
+ int (*_close) (int fd) = dlsym (RTLD_NEXT, "close");
return _close (fd);
}
#endif
@@ -760,32 +665,25 @@ free_user (gpointer data)
static void
load_passwd_file (void)
{
- g_autofree gchar *path = NULL;
- g_autofree gchar *data = NULL;
- g_auto(GStrv) lines = NULL;
- gint i;
- g_autoptr(GError) error = NULL;
-
g_list_free_full (user_entries, free_user);
user_entries = NULL;
getpwent_link = NULL;
- path = g_build_filename (g_getenv ("LIGHTDM_TEST_ROOT"), "etc", "passwd", NULL);
+ g_autofree gchar *path = g_build_filename (g_getenv ("LIGHTDM_TEST_ROOT"), "etc", "passwd", NULL);
+ g_autofree gchar *data = NULL;
+ g_autoptr(GError) error = NULL;
if (!g_file_get_contents (path, &data, NULL, &error))
{
g_warning ("Error loading passwd file: %s", error->message);
return;
}
- lines = g_strsplit (data, "\n", -1);
+ g_auto(GStrv) lines = g_strsplit (data, "\n", -1);
- for (i = 0; lines[i]; i++)
+ for (gint i = 0; lines[i]; i++)
{
- const gchar *line;
- g_auto(GStrv) fields = NULL;
-
- line = g_strstrip (lines[i]);
- fields = g_strsplit (line, ":", -1);
+ const gchar *line = g_strstrip (lines[i]);
+ g_auto(GStrv) fields = g_strsplit (line, ":", -1);
if (g_strv_length (fields) == 7)
{
struct passwd *entry = malloc (sizeof (struct passwd));
@@ -837,39 +735,31 @@ endpwent (void)
struct passwd *
getpwnam (const char *name)
{
- GList *link;
-
load_passwd_file ();
- for (link = user_entries; link; link = link->next)
+ for (GList *link = user_entries; link; link = link->next)
{
struct passwd *entry = link->data;
if (strcmp (entry->pw_name, name) == 0)
- break;
+ return entry;
}
- if (!link)
- return NULL;
- return link->data;
+ return NULL;
}
struct passwd *
getpwuid (uid_t uid)
{
- GList *link;
-
load_passwd_file ();
- for (link = user_entries; link; link = link->next)
+ for (GList *link = user_entries; link; link = link->next)
{
struct passwd *entry = link->data;
if (entry->pw_uid == uid)
- break;
+ return entry;
}
- if (!link)
- return NULL;
- return link->data;
+ return NULL;
}
static void
@@ -886,31 +776,24 @@ free_group (gpointer data)
static void
load_group_file (void)
{
- g_autofree gchar *path = NULL;
- g_autofree gchar *data = NULL;
- g_auto(GStrv) lines = NULL;
- gint i;
- g_autoptr(GError) error = NULL;
-
g_list_free_full (group_entries, free_group);
group_entries = NULL;
- path = g_build_filename (g_getenv ("LIGHTDM_TEST_ROOT"), "etc", "group", NULL);
+ g_autofree gchar *path = g_build_filename (g_getenv ("LIGHTDM_TEST_ROOT"), "etc", "group", NULL);
+ g_autofree gchar *data = NULL;
+ g_autoptr(GError) error = NULL;
if (!g_file_get_contents (path, &data, NULL, &error))
{
g_warning ("Error loading group file: %s", error->message);
return;
}
- lines = g_strsplit (data, "\n", -1);
+ g_auto(GStrv) lines = g_strsplit (data, "\n", -1);
- for (i = 0; lines[i]; i++)
+ for (gint i = 0; lines[i]; i++)
{
- const gchar *line;
- g_auto(GStrv) fields = NULL;
-
- line = g_strstrip (lines[i]);
- fields = g_strsplit (line, ":", -1);
+ const gchar *line = g_strstrip (lines[i]);
+ g_auto(GStrv) fields = g_strsplit (line, ":", -1);
if (g_strv_length (fields) == 4)
{
struct group *entry = malloc (sizeof (struct group));
@@ -927,47 +810,37 @@ load_group_file (void)
struct group *
getgrnam (const char *name)
{
- GList *link;
-
load_group_file ();
- for (link = group_entries; link; link = link->next)
+ for (GList *link = group_entries; link; link = link->next)
{
struct group *entry = link->data;
if (strcmp (entry->gr_name, name) == 0)
- break;
+ return entry;
}
- if (!link)
- return NULL;
- return link->data;
+ return NULL;
}
struct group *
getgrgid (gid_t gid)
{
- GList *link;
-
load_group_file ();
- for (link = group_entries; link; link = link->next)
+ for (GList *link = group_entries; link; link = link->next)
{
struct group *entry = link->data;
if (entry->gr_gid == gid)
- break;
+ return entry;
}
- if (!link)
- return NULL;
- return link->data;
+ return NULL;
}
int
pam_start (const char *service_name, const char *user, const struct pam_conv *conversation, pam_handle_t **pamh)
{
- pam_handle_t *handle;
-
- handle = *pamh = malloc (sizeof (pam_handle_t));
+ pam_handle_t *handle = *pamh = malloc (sizeof (pam_handle_t));
if (handle == NULL)
return PAM_BUF_ERR;
@@ -979,9 +852,7 @@ pam_start (const char *service_name, const char *user, const struct pam_conv *co
connect_status ();
if (g_key_file_get_boolean (config, "test-pam", "log-events", NULL))
{
- g_autoptr(GString) status = NULL;
-
- status = g_string_new ("");
+ g_autoptr(GString) status = g_string_new ("");
g_string_append_printf (status, "%s START", handle->id);
g_string_append_printf (status, " SERVICE=%s", service_name);
if (user)
@@ -1005,15 +876,10 @@ pam_start (const char *service_name, const char *user, const struct pam_conv *co
int
pam_authenticate (pam_handle_t *pamh, int flags)
{
- struct passwd *entry;
- gboolean password_matches = FALSE;
-
connect_status ();
if (g_key_file_get_boolean (config, "test-pam", "log-events", NULL))
{
- g_autoptr(GString) status = NULL;
-
- status = g_string_new ("");
+ g_autoptr(GString) status = g_string_new ("");
g_string_append_printf (status, "%s AUTHENTICATE", pamh->id);
if (flags & PAM_SILENT)
g_string_append (status, " SILENT");
@@ -1023,17 +889,15 @@ pam_authenticate (pam_handle_t *pamh, int flags)
status_notify ("%s", status->str);
}
+ gboolean password_matches = FALSE;
if (strcmp (pamh->service_name, "test-remote") == 0)
{
- int result;
- struct pam_message **msg;
- struct pam_response *resp = NULL;
-
- msg = malloc (sizeof (struct pam_message *) * 1);
+ struct pam_message **msg = malloc (sizeof (struct pam_message *) * 1);
msg[0] = malloc (sizeof (struct pam_message));
msg[0]->msg_style = PAM_PROMPT_ECHO_ON;
msg[0]->msg = "remote-login:";
- result = pamh->conversation.conv (1, (const struct pam_message **) msg, &resp, pamh->conversation.appdata_ptr);
+ struct pam_response *resp = NULL;
+ int result = pamh->conversation.conv (1, (const struct pam_message **) msg, &resp, pamh->conversation.appdata_ptr);
free (msg[0]);
free (msg);
if (result != PAM_SUCCESS)
@@ -1088,15 +952,12 @@ pam_authenticate (pam_handle_t *pamh, int flags)
/* Prompt for username */
if (pamh->user == NULL)
{
- int result;
- struct pam_message **msg;
- struct pam_response *resp = NULL;
-
- msg = malloc (sizeof (struct pam_message *) * 1);
+ struct pam_message **msg = malloc (sizeof (struct pam_message *) * 1);
msg[0] = malloc (sizeof (struct pam_message));
msg[0]->msg_style = PAM_PROMPT_ECHO_ON;
msg[0]->msg = LOGIN_PROMPT;
- result = pamh->conversation.conv (1, (const struct pam_message **) msg, &resp, pamh->conversation.appdata_ptr);
+ struct pam_response *resp = NULL;
+ int result = pamh->conversation.conv (1, (const struct pam_message **) msg, &resp, pamh->conversation.appdata_ptr);
free (msg[0]);
free (msg);
if (result != PAM_SUCCESS)
@@ -1120,18 +981,15 @@ pam_authenticate (pam_handle_t *pamh, int flags)
kill (getpid (), SIGSEGV);
/* Look up password database */
- entry = getpwnam (pamh->user);
+ struct passwd *entry = getpwnam (pamh->user);
/* Prompt for password if required */
if (entry && strcmp (pamh->user, "always-password") != 0 && (strcmp (pamh->service_name, "lightdm-autologin") == 0 || strcmp (entry->pw_passwd, "") == 0))
password_matches = TRUE;
else
{
- int i, n_messages = 0, password_index, result;
- struct pam_message **msg;
- struct pam_response *resp = NULL;
-
- msg = malloc (sizeof (struct pam_message *) * 5);
+ struct pam_message **msg = malloc (sizeof (struct pam_message *) * 5);
+ int n_messages = 0;
if (strcmp (pamh->user, "info-prompt") == 0)
{
msg[n_messages] = malloc (sizeof (struct pam_message));
@@ -1164,10 +1022,11 @@ pam_authenticate (pam_handle_t *pamh, int flags)
msg[n_messages] = malloc (sizeof (struct pam_message));
msg[n_messages]->msg_style = PAM_PROMPT_ECHO_OFF;
msg[n_messages]->msg = "Password:";
- password_index = n_messages;
+ int password_index = n_messages;
n_messages++;
- result = pamh->conversation.conv (n_messages, (const struct pam_message **) msg, &resp, pamh->conversation.appdata_ptr);
- for (i = 0; i < n_messages; i++)
+ struct pam_response *resp = NULL;
+ int result = pamh->conversation.conv (n_messages, (const struct pam_message **) msg, &resp, pamh->conversation.appdata_ptr);
+ for (int i = 0; i < n_messages; i++)
free (msg[i]);
free (msg);
if (result != PAM_SUCCESS)
@@ -1187,7 +1046,7 @@ pam_authenticate (pam_handle_t *pamh, int flags)
if (password_matches && strcmp (pamh->user, "multi-prompt") == 0)
password_matches = strcmp ("blue", resp[0].resp) == 0;
- for (i = 0; i < n_messages; i++)
+ for (int i = 0; i < n_messages; i++)
{
if (resp[i].resp)
free (resp[i].resp);
@@ -1249,7 +1108,6 @@ static const char *
get_env_value (const char *name_value, const char *name)
{
int j;
-
for (j = 0; name[j] && name_value[j] && name[j] == name_value[j]; j++);
if (name[j] == '\0' && name_value[j] == '=')
return &name_value[j + 1];
@@ -1260,19 +1118,16 @@ get_env_value (const char *name_value, const char *name)
int
pam_putenv (pam_handle_t *pamh, const char *name_value)
{
- int i;
- gchar *name;
-
- name = strdup (name_value);
- for (i = 0; name[i]; i++)
+ g_autofree char *name = strdup (name_value);
+ for (int i = 0; name[i]; i++)
if (name[i] == '=')
name[i] = '\0';
+ int i;
for (i = 0; pamh->envlist[i]; i++)
{
if (get_env_value (pamh->envlist[i], name))
break;
}
- free (name);
if (pamh->envlist[i])
{
@@ -1292,12 +1147,9 @@ pam_putenv (pam_handle_t *pamh, const char *name_value)
const char *
pam_getenv (pam_handle_t *pamh, const char *name)
{
- int i;
-
- for (i = 0; pamh->envlist[i]; i++)
+ for (int i = 0; pamh->envlist[i]; i++)
{
- const char *value;
- value = get_env_value (pamh->envlist[i], name);
+ const char *value = get_env_value (pamh->envlist[i], name);
if (value)
return value;
}
@@ -1374,15 +1226,10 @@ pam_get_item (const pam_handle_t *pamh, int item_type, const void **item)
int
pam_open_session (pam_handle_t *pamh, int flags)
{
- g_autoptr(GVariant) result = NULL;
- g_autoptr(GError) error = NULL;
-
connect_status ();
if (g_key_file_get_boolean (config, "test-pam", "log-events", NULL))
{
- g_autoptr(GString) status = NULL;
-
- status = g_string_new ("");
+ g_autoptr(GString) status = g_string_new ("");
g_string_append_printf (status, "%s OPEN-SESSION", pamh->id);
if (flags & PAM_SILENT)
g_string_append (status, " SILENT");
@@ -1395,30 +1242,28 @@ pam_open_session (pam_handle_t *pamh, int flags)
if (strcmp (pamh->user, "make-home-dir") == 0)
{
- struct passwd *entry;
- entry = getpwnam (pamh->user);
+ struct passwd *entry = getpwnam (pamh->user);
g_mkdir_with_parents (entry->pw_dir, 0755);
}
/* Open logind session */
- result = g_dbus_connection_call_sync (g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, NULL),
- "org.freedesktop.login1",
- "/org/freedesktop/login1",
- "org.freedesktop.login1.Manager",
- "CreateSession",
- g_variant_new ("()", ""),
- G_VARIANT_TYPE ("(so)"),
- G_DBUS_CALL_FLAGS_NONE,
- G_MAXINT,
- NULL,
- &error);
+ g_autoptr(GError) error = NULL;
+ g_autoptr(GVariant) result = g_dbus_connection_call_sync (g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, NULL),
+ "org.freedesktop.login1",
+ "/org/freedesktop/login1",
+ "org.freedesktop.login1.Manager",
+ "CreateSession",
+ g_variant_new ("()", ""),
+ G_VARIANT_TYPE ("(so)"),
+ G_DBUS_CALL_FLAGS_NONE,
+ G_MAXINT,
+ NULL,
+ &error);
if (result)
{
- g_autofree gchar *e = NULL;
const gchar *id;
-
g_variant_get (result, "(&so)", &id, NULL);
- e = g_strdup_printf ("XDG_SESSION_ID=%s", id);
+ g_autofree gchar *e = g_strdup_printf ("XDG_SESSION_ID=%s", id);
pam_putenv (pamh, e);
}
else
@@ -1433,9 +1278,7 @@ pam_close_session (pam_handle_t *pamh, int flags)
connect_status ();
if (g_key_file_get_boolean (config, "test-pam", "log-events", NULL))
{
- g_autoptr(GString) status = NULL;
-
- status = g_string_new ("");
+ g_autoptr(GString) status = g_string_new ("");
g_string_append_printf (status, "%s CLOSE-SESSION", pamh->id);
if (flags & PAM_SILENT)
g_string_append (status, " SILENT");
@@ -1452,9 +1295,7 @@ pam_acct_mgmt (pam_handle_t *pamh, int flags)
connect_status ();
if (g_key_file_get_boolean (config, "test-pam", "log-events", NULL))
{
- g_autoptr(GString) status = NULL;
-
- status = g_string_new ("");
+ g_autoptr(GString) status = g_string_new ("");
g_string_append_printf (status, "%s ACCT-MGMT", pamh->id);
if (flags & PAM_SILENT)
g_string_append (status, " SILENT");
@@ -1480,17 +1321,10 @@ pam_acct_mgmt (pam_handle_t *pamh, int flags)
int
pam_chauthtok (pam_handle_t *pamh, int flags)
{
- struct passwd *entry;
- int result;
- struct pam_message **msg;
- struct pam_response *resp = NULL;
-
connect_status ();
if (g_key_file_get_boolean (config, "test-pam", "log-events", NULL))
{
- g_autoptr(GString) status = NULL;
-
- status = g_string_new ("");
+ g_autoptr(GString) status = g_string_new ("");
g_string_append_printf (status, "%s CHAUTHTOK", pamh->id);
if (flags & PAM_SILENT)
g_string_append (status, " SILENT");
@@ -1500,14 +1334,15 @@ pam_chauthtok (pam_handle_t *pamh, int flags)
status_notify ("%s", status->str);
}
- msg = malloc (sizeof (struct pam_message *) * 1);
+ struct pam_message **msg = malloc (sizeof (struct pam_message *) * 1);
msg[0] = malloc (sizeof (struct pam_message));
msg[0]->msg_style = PAM_PROMPT_ECHO_OFF;
if ((flags & PAM_CHANGE_EXPIRED_AUTHTOK) != 0)
msg[0]->msg = "Enter new password (expired):";
else
msg[0]->msg = "Enter new password:";
- result = pamh->conversation.conv (1, (const struct pam_message **) msg, &resp, pamh->conversation.appdata_ptr);
+ struct pam_response *resp = NULL;
+ int result = pamh->conversation.conv (1, (const struct pam_message **) msg, &resp, pamh->conversation.appdata_ptr);
free (msg[0]);
free (msg);
if (result != PAM_SUCCESS)
@@ -1522,7 +1357,7 @@ pam_chauthtok (pam_handle_t *pamh, int flags)
}
/* Update password database */
- entry = getpwnam (pamh->user);
+ struct passwd *entry = getpwnam (pamh->user);
free (entry->pw_passwd);
entry->pw_passwd = resp[0].resp;
free (resp);
@@ -1533,14 +1368,10 @@ pam_chauthtok (pam_handle_t *pamh, int flags)
int
pam_setcred (pam_handle_t *pamh, int flags)
{
- g_autofree gchar *e = NULL;
-
connect_status ();
if (g_key_file_get_boolean (config, "test-pam", "log-events", NULL))
{
- g_autoptr(GString) status = NULL;
-
- status = g_string_new ("");
+ g_autoptr(GString) status = g_string_new ("");
g_string_append_printf (status, "%s SETCRED", pamh->id);
if (flags & PAM_SILENT)
g_string_append (status, " SILENT");
@@ -1557,7 +1388,7 @@ pam_setcred (pam_handle_t *pamh, int flags)
}
/* Put the test directories into the path */
- 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"));
+ g_autofree gchar *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"));
pam_putenv (pamh, e);
if (strcmp (pamh->user, "cred-error") == 0)
@@ -1570,17 +1401,13 @@ pam_setcred (pam_handle_t *pamh, int flags)
/* Join special groups if requested */
if (strcmp (pamh->user, "group-member") == 0 && flags & PAM_ESTABLISH_CRED)
{
- struct group *group;
- gid_t *groups;
- int groups_length;
-
- group = getgrnam ("test-group");
+ struct group *group = getgrnam ("test-group");
if (group)
{
- groups_length = getgroups (0, NULL);
+ int groups_length = getgroups (0, NULL);
if (groups_length < 0)
return PAM_SYSTEM_ERR;
- groups = malloc (sizeof (gid_t) * (groups_length + 1));
+ gid_t *groups = malloc (sizeof (gid_t) * (groups_length + 1));
groups_length = getgroups (groups_length, groups);
if (groups_length < 0)
return PAM_SYSTEM_ERR;
@@ -1603,9 +1430,7 @@ pam_end (pam_handle_t *pamh, int pam_status)
connect_status ();
if (g_key_file_get_boolean (config, "test-pam", "log-events", NULL))
{
- g_autoptr(GString) status = NULL;
-
- status = g_string_new ("");
+ g_autoptr(GString) status = g_string_new ("");
g_string_append_printf (status, "%s END", pamh->id);
status_notify ("%s", status->str);
}
@@ -1713,9 +1538,7 @@ pututxline (const struct utmpx *ut)
connect_status ();
if (g_key_file_get_boolean (config, "test-utmp-config", "check-events", NULL))
{
- g_autoptr(GString) status = NULL;
-
- status = g_string_new ("UTMP");
+ g_autoptr(GString) status = g_string_new ("UTMP");
switch (ut->ut_type)
{
case INIT_PROCESS:
@@ -1758,9 +1581,7 @@ updwtmp (const char *wtmp_file, const struct utmp *ut)
connect_status ();
if (g_key_file_get_boolean (config, "test-utmp-config", "check-events", NULL))
{
- g_autoptr(GString) status = NULL;
-
- status = g_string_new ("WTMP");
+ g_autoptr(GString) status = g_string_new ("WTMP");
g_string_append_printf (status, " FILE=%s", wtmp_file);
switch (ut->ut_type)
{
@@ -1801,9 +1622,7 @@ struct xcb_connection_t
xcb_connection_t *
xcb_connect_to_display_with_auth_info (const char *display, xcb_auth_info_t *auth, int *screen)
{
- xcb_connection_t *c;
-
- c = malloc (sizeof (xcb_connection_t));
+ xcb_connection_t *c = malloc (sizeof (xcb_connection_t));
c->display = g_strdup (display);
c->error = 0;
@@ -1815,7 +1634,6 @@ xcb_connect_to_display_with_auth_info (const char *display, xcb_auth_info_t *aut
if (c->error == 0)
{
g_autoptr(GError) error = NULL;
-
c->socket = g_socket_new (G_SOCKET_FAMILY_UNIX, G_SOCKET_TYPE_STREAM, G_SOCKET_PROTOCOL_DEFAULT, &error);
if (c->socket == NULL)
{
@@ -1826,15 +1644,11 @@ xcb_connect_to_display_with_auth_info (const char *display, xcb_auth_info_t *aut
if (c->error == 0)
{
- g_autofree gchar *d = NULL;
- g_autofree gchar *socket_path = NULL;
- g_autoptr(GSocketAddress) address = NULL;
- g_autoptr(GError) error = NULL;
-
/* Skip the hostname, we'll assume it's localhost */
- d = g_strdup_printf (".x%s", strchr (display, ':'));
- socket_path = g_build_filename (g_getenv ("LIGHTDM_TEST_ROOT"), d, NULL);
- address = g_unix_socket_address_new (socket_path);
+ g_autofree gchar *d = g_strdup_printf (".x%s", strchr (display, ':'));
+ g_autofree gchar *socket_path = g_build_filename (g_getenv ("LIGHTDM_TEST_ROOT"), d, NULL);
+ g_autoptr(GSocketAddress) address = g_unix_socket_address_new (socket_path);
+ g_autoptr(GError) error = NULL;
if (!g_socket_connect (c->socket, address, NULL, &error))
{
g_printerr ("Failed to connect to X socket %s: %s\n", socket_path, error->message);
@@ -1890,12 +1704,11 @@ audit_log_acct_message (int audit_fd, int type, const char *pgname,
const char *op, const char *name, unsigned int id,
const char *host, const char *addr, const char *tty, int result)
{
- g_autofree gchar *type_string = NULL;
-
connect_status ();
if (!g_key_file_get_boolean (config, "test-audit-config", "check-events", NULL))
return 1;
+ g_autofree gchar *type_string = NULL;
switch (type)
{
case AUDIT_USER_LOGIN: