From dc5e9585215f34ec78b68fbb6da990a90d8f3a1b Mon Sep 17 00:00:00 2001 From: William Jon McCann Date: Tue, 6 Mar 2007 16:07:24 -0500 Subject: use paths.h if available --- configure.ac | 2 ++ pam-ck-connector/pam-ck-connector.c | 14 ++++++++++++-- pam-ck-connector/test-pam.c | 8 +++++++- src/ck-seat.c | 11 +++++++++-- src/getfd.c | 28 +++++++++++++++++++++------- src/proc-linux.c | 10 +++++++--- 6 files changed, 58 insertions(+), 15 deletions(-) diff --git a/configure.ac b/configure.ac index 4cd3b58..796186f 100644 --- a/configure.ac +++ b/configure.ac @@ -37,6 +37,8 @@ GLIB_REQUIRED_VERSION=2.7.0 GDK_REQUIRED_VERSION=2.8.0 AC_CHECK_HEADERS(unistd.h) +AC_CHECK_HEADERS(paths.h) + AC_TYPE_UID_T AC_CHECK_FUNCS([setresuid setenv unsetenv clearenv]) diff --git a/pam-ck-connector/pam-ck-connector.c b/pam-ck-connector/pam-ck-connector.c index 39c0332..5d4f7c0 100644 --- a/pam-ck-connector/pam-ck-connector.c +++ b/pam-ck-connector/pam-ck-connector.c @@ -26,6 +26,8 @@ * OTHER DEALINGS IN THE SOFTWARE. */ +#include "config.h" + #include #include #include @@ -39,6 +41,14 @@ #include #include +#ifdef HAVE_PATHS_H +#include +#endif /* HAVE_PATHS_H */ + +#ifndef _PATH_DEV +#define _PATH_DEV "/dev/" +#endif + #define PAM_SM_SESSION #include @@ -187,8 +197,8 @@ pam_sm_open_session (pam_handle_t *pamh, if (strchr (display_device, ':') != NULL) { x11_display = display_device; display_device = ""; - } else if (strncmp ("/dev/", display_device, 5) != 0) { - snprintf (ttybuf, sizeof (ttybuf), "/dev/%s", display_device); + } else if (strncmp (_PATH_DEV, display_device, 5) != 0) { + snprintf (ttybuf, sizeof (ttybuf), _PATH_DEV "%s", display_device); display_device = ttybuf; } diff --git a/pam-ck-connector/test-pam.c b/pam-ck-connector/test-pam.c index b5619b9..310a15f 100644 --- a/pam-ck-connector/test-pam.c +++ b/pam-ck-connector/test-pam.c @@ -24,6 +24,8 @@ * OTHER DEALINGS IN THE SOFTWARE. */ +#include "config.h" + #include #include #include @@ -31,6 +33,10 @@ #include #include +#ifdef HAVE_PATHS_H +#include +#endif /* HAVE_PATHS_H */ + #define PAM_MAX_LOGIN_TRIES 3 #define PAM_FAIL_CHECK if (retcode != PAM_SUCCESS) { \ fprintf (stderr, "\n%s\n", pam_strerror (pamh, retcode)); \ @@ -69,7 +75,7 @@ main (int argc, char *argv[]) ttyn = ttyname (0); - if (strncmp(ttyn, "/dev/", 5) == 0) { + if (strncmp (ttyn, _PATH_DEV, 5) == 0) { tty_name = ttyn + 5; } else { tty_name = ttyn; diff --git a/src/ck-seat.c b/src/ck-seat.c index 033dc2d..c980ad5 100644 --- a/src/ck-seat.c +++ b/src/ck-seat.c @@ -25,6 +25,13 @@ #include #include #include +#ifdef HAVE_PATHS_H +#include +#endif /* HAVE_PATHS_H */ + +#ifndef _PATH_TTY +#define _PATH_TTY "/dev/tty" +#endif #include #include @@ -196,7 +203,7 @@ _seat_activate_session (CkSeat *seat, ck_session_get_display_device (session, &device, NULL); - if (device == NULL || (sscanf (device, "/dev/tty%u", &num) != 1)) { + if (device == NULL || (sscanf (device, _PATH_TTY "%u", &num) != 1)) { GError *error; error = g_error_new (CK_SEAT_ERROR, CK_SEAT_ERROR_GENERAL, @@ -480,7 +487,7 @@ update_active_vt (CkSeat *seat, CkSession *session; char *device; - device = g_strdup_printf ("/dev/tty%u", num); + device = g_strdup_printf (_PATH_TTY "%u", num); ck_debug ("Active device: %s", device); diff --git a/src/getfd.c b/src/getfd.c index 2ddcf01..69c37a3 100644 --- a/src/getfd.c +++ b/src/getfd.c @@ -1,15 +1,21 @@ /* - * Copied from kbd-1.12 + * Adapted from kbd-1.12 * License: GPL * */ +#include "config.h" + #include #include #include #include #include +#ifdef HAVE_PATHS_H +#include +#endif /* HAVE_PATHS_H */ + /* * getfd.c * @@ -24,7 +30,7 @@ is_a_console (int fd) char arg; arg = 0; - return (ioctl(fd, KDGKBTYPE, &arg) == 0 + return (ioctl (fd, KDGKBTYPE, &arg) == 0 && ((arg == KB_101) || (arg == KB_84))); } @@ -33,10 +39,10 @@ open_a_console (char *fnam) { int fd; - fd = open(fnam, O_RDONLY); + fd = open (fnam, O_RDONLY); if (fd < 0 && errno == EACCES) fd = open(fnam, O_WRONLY); - if (fd < 0 || ! is_a_console(fd)) + if (fd < 0 || ! is_a_console (fd)) return -1; return fd; } @@ -45,16 +51,24 @@ int getfd (void) { int fd; - fd = open_a_console("/dev/tty"); + fd = open_a_console (_PATH_TTY); + if (fd >= 0) + return fd; + + fd = open_a_console ("/dev/tty"); + if (fd >= 0) + return fd; + + fd = open_a_console (_PATH_CONSOLE); if (fd >= 0) return fd; - fd = open_a_console("/dev/console"); + fd = open_a_console ("/dev/console"); if (fd >= 0) return fd; for (fd = 0; fd < 3; fd++) - if (is_a_console(fd)) + if (is_a_console (fd)) return fd; return -1; diff --git a/src/proc-linux.c b/src/proc-linux.c index 30e7d22..a247e75 100644 --- a/src/proc-linux.c +++ b/src/proc-linux.c @@ -28,6 +28,10 @@ #include #include +#ifdef HAVE_PATHS_H +#include +#endif /* HAVE_PATHS_H */ + #include "proc.h" /* adapted from procps */ @@ -107,7 +111,7 @@ load_drivers (void) buf[bytes] = '\0'; p = buf; - while ((p = strstr (p, " /dev/"))){ + while ((p = strstr (p, " " _PATH_DEV))){ tty_map_node *tmn; int len; char *end; @@ -188,7 +192,7 @@ driver_name (guint maj, tmn = tmn->next; } - tty = g_strdup_printf ("/dev/%s%d", tmn->name, min); /* like "/dev/ttyZZ255" */ + tty = g_strdup_printf (_PATH_DEV "%s%d", tmn->name, min); /* like "/dev/ttyZZ255" */ if (stat (tty, &sbuf) < 0){ g_free (tty); @@ -196,7 +200,7 @@ driver_name (guint maj, return NULL; } - tty = g_strdup_printf ("/dev/%s", tmn->name); /* like "/dev/ttyZZ255" */ + tty = g_strdup_printf (_PATH_DEV "%s", tmn->name); /* like "/dev/ttyZZ255" */ if (stat (tty, &sbuf) < 0) { g_free (tty); -- cgit