--- configure.in.orig 2007-11-25 15:43:40.000000000 -0500
+++ configure.in 2007-12-23 00:34:37.000000000 -0500
@@ -169,7 +169,7 @@ PKG_CHECK_MODULES(DBUS_GLIB, [dbus-glib-
AC_SUBST(DBUS_GLIB_CFLAGS)
AC_SUBST(DBUS_GLIB_LIBS)
-AC_CHECK_FUNCS(getgrouplist)
+AC_CHECK_FUNCS(getgrouplist clearenv strndup getline readdir64)
EXPAT_LIB=""
AC_ARG_WITH(expat, [ --with-expat=
Use expat from here],
@@ -406,6 +406,7 @@ AM_CONDITIONAL(OS_TYPE_RED_HAT, test x$w
AM_CONDITIONAL(OS_TYPE_SUSE, test x$with_os_type = xsuse, [Running on SUSE OS'es])
AM_CONDITIONAL(OS_TYPE_GENTOO, test x$with_os_type = xgentoo, [Running on Gentoo OS'es])
AM_CONDITIONAL(OS_TYPE_PARDUS, test x$with_os_type = xpardus, [Running on Pardus OS'es])
+AM_CONDITIONAL(OS_TYPE_FREEBSD, test x$with_os_type = xfreebsd, [Running on FreeBSD OS'es])
AC_ARG_WITH(pam-include, [ --with-pam-include= pam file to include])
@@ -425,6 +426,11 @@ elif test x$with_os_type = xsuse ; then
PAM_FILE_INCLUDE_ACCOUNT=common-account
PAM_FILE_INCLUDE_PASSWORD=common-password
PAM_FILE_INCLUDE_SESSION=common-session
+elif test x$with_os_type = xfreebsd ; then
+ PAM_FILE_INCLUDE_AUTH=system
+ PAM_FILE_INCLUDE_ACCOUNT=system
+ PAM_FILE_INCLUDE_PASSWORD=system
+ PAM_FILE_INCLUDE_SESSION=system
else
PAM_FILE_INCLUDE_AUTH=system-auth
PAM_FILE_INCLUDE_ACCOUNT=system-auth
@@ -441,6 +447,25 @@ AC_DEFINE_UNQUOTED(PAM_FILE_INCLUDE_ACCO
AC_DEFINE_UNQUOTED(PAM_FILE_INCLUDE_PASSWORD, "$PAM_FILE_INCLUDE_PASSWORD", [pam file password])
AC_DEFINE_UNQUOTED(PAM_FILE_INCLUDE_SESSION, "$PAM_FILE_INCLUDE_SESSION", [pam file session])
+have_inotify=no
+AC_CHECK_HEADERS([linux/inotify.h], [have_inotify=yes])
+AC_CHECK_HEADERS([sys/inotify.h], [have_inotify=yes])
+
+AM_CONDITIONAL(HAVE_INOTIFY, test "x$have_inotify" = "xyes")
+
+if test "x$have_inotify" = "xyes" ; then
+ AC_DEFINE([HAVE_INOTIFY], 1, [Enable Linux inotify() usage])
+fi
+
+have_kqueue=yes
+AC_CHECK_FUNCS([kqueue],,have_kqueue=no)
+
+AM_CONDITIONAL(HAVE_KQUEUE, test "x$have_kqueue" = "xyes")
+
+if test "x$have_kqueue" = "xyes" ; then
+ AC_DEFINE([HAVE_KQUEUE], 1, [Enable BSD kqueue() usage])
+fi
+
# ********************
# Internationalisation
# ********************
--- src/kit/kit-file.c.orig 2007-11-28 16:32:08.000000000 -0500
+++ src/kit/kit-file.c 2007-12-24 14:48:35.000000000 -0500
@@ -283,7 +283,11 @@ _kit_get_num_fd (void)
DIR *dir;
char buf[128];
ssize_t num;
+#ifdef HAVE_READDIR64
struct dirent64 *d;
+#else
+ struct dirent *d;
+#endif
num = -1;
@@ -296,7 +300,11 @@ _kit_get_num_fd (void)
}
num = -2;
+#ifdef HAVE_READDIR64
while ((d = readdir64 (dir)) != NULL) {
+#else
+ while ((d = readdir (dir)) != NULL) {
+#endif
if (d->d_name == NULL)
continue;
num++;
--- src/kit/kit-file.h.orig 2007-12-22 19:14:03.000000000 -0500
+++ src/kit/kit-file.h 2007-12-22 19:14:13.000000000 -0500
@@ -34,6 +34,7 @@
#ifndef KIT_FILE_H
#define KIT_FILE_H
+#include
#include
KIT_BEGIN_DECLS
--- src/kit/kit-spawn.c.orig 2007-12-23 00:22:49.000000000 -0500
+++ src/kit/kit-spawn.c 2007-12-23 00:22:58.000000000 -0500
@@ -40,6 +40,7 @@
#include
#include
#include
+#include
#include
#include "kit-test.h"
--- src/kit/kit-string.c.orig 2007-12-23 00:42:03.000000000 -0500
+++ src/kit/kit-string.c 2007-12-23 00:41:26.000000000 -0500
@@ -77,7 +77,15 @@ kit_strdup (const char *s)
out:
return p;
}
+#else /* !KIT_BUILD_TESTS */
+char *
+kit_strdup (const char *s)
+{
+ return strdup (s);
+}
+#endif /* KIT_BUILD_TESTS */
+#if defined(KIT_BUILD_TESTS) || !defined(HAVE_STRNDUP)
/**
* kit_strndup:
* @s: string
@@ -111,13 +119,7 @@ out:
return p;
}
-#else
-
-char *
-kit_strdup (const char *s)
-{
- return strdup (s);
-}
+#else /* !KIT_BUILD_TESTS || HAVE_STRNDUP */
char *
kit_strndup (const char *s, size_t n)
@@ -125,7 +127,7 @@ kit_strndup (const char *s, size_t n)
return strndup (s, n);
}
-#endif /* KIT_BUILD_TESTS */
+#endif /* KIT_BUILD_TESTS || !HAVE_STRNDUP */
/**
* kit_strdup_printf:
--- src/polkit-dbus/polkit-read-auth-helper.c.orig 2007-11-28 23:33:10.000000000 -0500
+++ src/polkit-dbus/polkit-read-auth-helper.c 2007-12-24 14:53:38.000000000 -0500
@@ -39,6 +39,7 @@
#include
#include
#include
+#include
#include
#include
#include
@@ -156,7 +157,11 @@ dump_auths_all (const char *root)
{
DIR *dir;
int dfd;
+#ifdef HAVE_READDIR64
struct dirent64 *d;
+#else
+ struct dirent *d;
+#endif
polkit_bool_t ret;
ret = FALSE;
@@ -173,7 +178,11 @@ dump_auths_all (const char *root)
goto out;
}
+#ifdef HAVE_READDIR64
while ((d = readdir64(dir)) != NULL) {
+#else
+ while ((d = readdir(dir)) != NULL) {
+#endif
unsigned int n, m;
uid_t uid;
size_t name_len;
@@ -282,7 +291,7 @@ main (int argc, char *argv[])
#ifndef POLKIT_BUILD_TESTS
/* clear the entire environment to avoid attacks using with libraries honoring environment variables */
- if (clearenv () != 0)
+ if (polkit_sysdeps_clearenv () != 0)
goto out;
/* set a minimal environment */
setenv ("PATH", "/usr/sbin:/usr/bin:/sbin:/bin", 1);
--- src/polkit-dbus/polkit-set-default-helper.c.orig 2007-12-23 01:21:04.000000000 -0500
+++ src/polkit-dbus/polkit-set-default-helper.c 2007-12-23 01:21:11.000000000 -0500
@@ -127,7 +127,7 @@ main (int argc, char *argv[])
ret = 1;
/* clear the entire environment to avoid attacks using with libraries honoring environment variables */
- if (clearenv () != 0)
+ if (polkit_sysdeps_clearenv () != 0)
goto out;
/* set a minimal environment */
setenv ("PATH", "/usr/sbin:/usr/bin:/sbin:/bin", 1);
--- src/polkit-grant/Makefile.am.orig 2007-12-23 01:40:02.000000000 -0500
+++ src/polkit-grant/Makefile.am 2007-12-23 01:40:27.000000000 -0500
@@ -47,7 +47,7 @@ polkit_grant_helper_SOURCES = polkit-gra
polkit_grant_helper_LDADD = @GLIB_LIBS@ @DBUS_LIBS@ $(top_builddir)/src/polkit/libpolkit.la $(top_builddir)/src/polkit-dbus/libpolkit-dbus.la libpolkit-grant.la
polkit_grant_helper_pam_SOURCES = polkit-grant-helper-pam.c
-polkit_grant_helper_pam_LDADD = @AUTH_LIBS@
+polkit_grant_helper_pam_LDADD = @AUTH_LIBS@ $(top_builddir)/src/polkit/libpolkit.la
polkit_explicit_grant_helper_SOURCES = polkit-explicit-grant-helper.c
polkit_explicit_grant_helper_CFLAGS = @DBUS_CFLAGS@
--- src/polkit-grant/polkit-explicit-grant-helper.c.orig 2007-12-23 01:24:19.000000000 -0500
+++ src/polkit-grant/polkit-explicit-grant-helper.c 2007-12-23 01:24:24.000000000 -0500
@@ -67,7 +67,7 @@ main (int argc, char *argv[])
ret = 1;
/* clear the entire environment to avoid attacks using with libraries honoring environment variables */
- if (clearenv () != 0)
+ if (polkit_sysdeps_clearenv () != 0)
goto out;
/* set a minimal environment */
setenv ("PATH", "/usr/sbin:/usr/bin:/sbin:/bin", 1);
--- src/polkit-grant/polkit-grant-helper-pam.c.orig 2007-11-28 16:28:31.000000000 -0500
+++ src/polkit-grant/polkit-grant-helper-pam.c 2007-12-23 02:01:46.000000000 -0500
@@ -38,6 +38,8 @@
#include
#include
+#include
+
/* Development aid: define PGH_DEBUG to get debugging output. Do _NOT_
* enable this in production builds; it may leak passwords and other
* sensitive information.
@@ -60,7 +62,7 @@ main (int argc, char *argv[])
pam_h = NULL;
/* clear the entire environment to avoid attacks using with libraries honoring environment variables */
- if (clearenv () != 0)
+ if (polkit_sysdeps_clearenv () != 0)
goto error;
/* set a minimal environment */
setenv ("PATH", "/usr/sbin:/usr/bin:/sbin:/bin", 1);
--- src/polkit-grant/polkit-grant-helper.c.orig 2007-12-23 01:23:13.000000000 -0500
+++ src/polkit-grant/polkit-grant-helper.c 2007-12-23 01:23:19.000000000 -0500
@@ -546,7 +546,7 @@ main (int argc, char *argv[])
ret = 3;
/* clear the entire environment to avoid attacks using with libraries honoring environment variables */
- if (clearenv () != 0)
+ if (polkit_sysdeps_clearenv () != 0)
goto out;
/* set a minimal environment */
setenv ("PATH", "/usr/sbin:/usr/bin:/sbin:/bin", 1);
--- src/polkit-grant/polkit-grant.c.orig 2007-11-28 16:29:25.000000000 -0500
+++ src/polkit-grant/polkit-grant.c 2007-12-23 01:25:08.000000000 -0500
@@ -38,6 +38,7 @@
#include
#include
#include
+#include
#include
#include "polkit-grant.h"
@@ -301,7 +302,7 @@ polkit_grant_io_func (PolKitGrant *polki
g_return_if_fail (polkit_grant != NULL);
g_return_if_fail (polkit_grant->helper_is_running);
- while (getline (&line, &line_len, polkit_grant->child_stdout_f) != -1) {
+ while (polkit_sysdeps_getline (&line, &line_len, polkit_grant->child_stdout_f) != -1) {
if (strlen (line) > 0 &&
line[strlen (line) - 1] == '\n')
line[strlen (line) - 1] = '\0';
--- src/polkit-grant/polkit-revoke-helper.c.orig 2007-12-23 01:22:38.000000000 -0500
+++ src/polkit-grant/polkit-revoke-helper.c 2007-12-23 01:22:47.000000000 -0500
@@ -109,7 +109,7 @@ main (int argc, char *argv[])
#ifndef POLKIT_BUILD_TESTS
/* clear the entire environment to avoid attacks using with libraries honoring environment variables */
- if (clearenv () != 0)
+ if (polkit_sysdeps_clearenv () != 0)
goto out;
/* set a minimal environment */
setenv ("PATH", "/usr/sbin:/usr/bin:/sbin:/bin", 1);
--- src/polkit/polkit-config.c.orig 2007-12-23 00:25:46.000000000 -0500
+++ src/polkit/polkit-config.c 2007-12-23 00:25:51.000000000 -0500
@@ -39,7 +39,6 @@
#include
#include
#include
-#include
#include
#include
#include
--- src/polkit/polkit-context.c.orig 2007-12-04 20:22:41.000000000 -0500
+++ src/polkit/polkit-context.c 2007-12-23 00:24:45.000000000 -0500
@@ -39,7 +39,13 @@
#include
#include
#include
+#ifdef HAVE_INOTIFY
#include
+#elif HAVE_KQUEUE
+#include
+#include
+#include
+#endif
#include
#include "polkit-config.h"
@@ -106,11 +112,19 @@ struct _PolKitContext
polkit_bool_t load_descriptions;
+#ifdef HAVE_INOTIFY
int inotify_fd;
int inotify_fd_watch_id;
int inotify_config_wd;
int inotify_policy_wd;
int inotify_grant_perm_wd;
+#elif HAVE_KQUEUE
+ int kqueue_fd;
+ int kqueue_fd_watch_id;
+ int kqueue_config_fd;
+ int kqueue_policy_fd;
+ int kqueue_grant_perm_fd;
+#endif
};
/**
@@ -144,6 +158,10 @@ polkit_context_new (void)
polkit_bool_t
polkit_context_init (PolKitContext *pk_context, PolKitError **error)
{
+#ifdef HAVE_KQUEUE
+ struct kevent ev;
+#endif
+
kit_return_val_if_fail (pk_context != NULL, FALSE);
pk_context->policy_dir = kit_strdup (PACKAGE_DATA_DIR "/PolicyKit/policy");
@@ -153,6 +171,7 @@ polkit_context_init (PolKitContext *pk_c
/* NOTE: we don't load the configuration file until it's needed */
+#ifdef HAVE_INOTIFY
if (pk_context->io_add_watch_func != NULL) {
pk_context->inotify_fd = inotify_init ();
if (pk_context->inotify_fd < 0) {
@@ -203,6 +222,88 @@ polkit_context_init (PolKitContext *pk_c
goto error;
}
}
+#elif HAVE_KQUEUE
+ if (pk_context->io_add_watch_func != NULL) {
+ pk_context->kqueue_fd = kqueue ();
+ if (pk_context->kqueue_fd < 0) {
+ _pk_debug ("failed to initialize kqueue: %s", strerror (errno));
+ /* TODO: set error */
+ goto error;
+ }
+
+ /* Watch the /etc/PolicyKit/PolicyKit.conf file */
+ pk_context->kqueue_config_fd = open (PACKAGE_SYSCONF_DIR "/PolicyKit/PolicyKit.conf", O_RDONLY);
+ if (pk_context->kqueue_config_fd < 0) {
+ _pk_debug ("failed '" PACKAGE_SYSCONF_DIR "/PolicyKit/PolicyKit.conf' for reading: %s",
+ strerror (errno));
+ /* TODO: set error */
+ goto error;
+ }
+
+ EV_SET (&ev, pk_context->kqueue_config_fd, EVFILT_VNODE,
+ EV_ADD | EV_ENABLE | EV_CLEAR,
+ NOTE_DELETE | NOTE_EXTEND | NOTE_WRITE | NOTE_RENAME,
+ 0, 0);
+ if (kevent (pk_context->kqueue_fd, &ev, 1, NULL, 0, NULL) == -1) {
+ _pk_debug ("failed to add watch on file '" PACKAGE_SYSCONF_DIR "/PolicyKit/PolicyKit.conf': %s",
+ strerror (errno));
+ close (pk_context->kqueue_config_fd);
+ /* TODO: set error */
+ goto error;
+ }
+
+ /* Watch the /usr/share/PolicyKit/policy directory */
+ pk_context->kqueue_policy_fd = open (PACKAGE_DATA_DIR "/PolicyKit/policy", O_RDONLY);
+ if (pk_context->kqueue_policy_fd < 0) {
+ _pk_debug ("failed to open '" PACKAGE_DATA_DIR "/PolicyKit/policy for reading: %s",
+ strerror (errno));
+ /* TODO: set error */
+ goto error;
+ }
+
+ EV_SET (&ev, pk_context->kqueue_policy_fd, EVFILT_VNODE,
+ EV_ADD | EV_ENABLE | EV_CLEAR,
+ NOTE_DELETE | NOTE_EXTEND | NOTE_WRITE | NOTE_RENAME,
+ 0, 0);
+ if (kevent (pk_context->kqueue_fd, &ev, 1, NULL, 0, NULL) == -1) {
+ _pk_debug ("failed to add watch on directory '" PACKAGE_DATA_DIR "/PolicyKit/policy': %s",
+ strerror (errno));
+ close (pk_context->kqueue_policy_fd);
+ /* TODO: set error */
+ goto error;
+ }
+
+#ifdef POLKIT_AUTHDB_DEFAULT
+ /* Watch the /var/lib/misc/PolicyKit.reload file */
+ pk_context->kqueue_grant_perm_fd = open (PACKAGE_LOCALSTATE_DIR "/lib/misc/PolicyKit.reload", O_RDONLY);
+ if (pk_context->kqueue_grant_perm_fd < 0) {
+ _pk_debug ("failed to open '" PACKAGE_LOCALSTATE_DIR "/lib/misc/PolicyKit.reload' for reading: %s",
+ strerror (errno));
+ /* TODO: set error */
+ goto error;
+ }
+
+ EV_SET (&ev, pk_context->kqueue_grant_perm_fd, EVFILT_VNODE,
+ EV_ADD | EV_ENABLE | EV_CLEAR,
+ NOTE_DELETE | NOTE_EXTEND | NOTE_WRITE | NOTE_RENAME,
+ 0, 0);
+ if (kevent (pk_context->kqueue_fd, &ev, 1, NULL, 0, NULL) == -1) {
+ _pk_debug ("failed to add watch on file '" PACKAGE_LOCALSTATE_DIR "/lib/misc/PolicyKit.reload': %s",
+ strerror (errno));
+ close (pk_context->kqueue_grant_perm_fd);
+ /* TODO: set error */
+ goto error;
+ }
+#endif
+
+ pk_context->kqueue_fd_watch_id = pk_context->io_add_watch_func (pk_context, pk_context->kqueue_fd);
+ if (pk_context->kqueue_fd_watch_id == 0) {
+ _pk_debug ("failed to add io watch");
+ /* TODO: set error */
+ goto error;
+ }
+ }
+#endif
return TRUE;
error:
@@ -296,6 +397,7 @@ polkit_context_io_func (PolKitContext *p
config_changed = FALSE;
+#ifdef HAVE_INOTIFY
if (fd == pk_context->inotify_fd) {
/* size of the event structure, not counting name */
#define EVENT_SIZE (sizeof (struct inotify_event))
@@ -327,6 +429,36 @@ again:
i += EVENT_SIZE + event->len;
}
}
+#elif HAVE_KQUEUE
+ if (fd == pk_context->kqueue_fd) {
+ struct kevent ev[1024];
+ struct timespec nullts = { 0, 0 };
+ int res;
+ int i = 0;
+
+ res = kevent (fd, NULL, 0, ev, 1024, &nullts);
+
+ if (res > 0) {
+ /* Sleep for a half-second to avoid potential races
+ * during install/uninstall. */
+ usleep (500000);
+
+ while (i < res) {
+ struct kevent *evptr;
+
+ evptr = &ev[i];
+ _pk_debug ("ident=%d filter=%d flags=%u fflags=%u",
+ evptr->ident, evptr->filter, evptr->flags, evptr->fflags);
+ _pk_debug ("config changed!");
+ config_changed = TRUE;
+
+ i++;
+ }
+ } else {
+ _pk_debug ("failed to read kqueue event: %s", strerror (errno));
+ }
+ }
+#endif
if (config_changed) {
polkit_context_force_reload (pk_context);
--- src/polkit/polkit-policy-cache.c.orig 2007-11-29 01:14:09.000000000 -0500
+++ src/polkit/polkit-policy-cache.c 2007-12-24 14:51:04.000000000 -0500
@@ -98,7 +98,11 @@ PolKitPolicyCache *
_polkit_policy_cache_new (const char *dirname, polkit_bool_t load_descriptions, PolKitError **error)
{
DIR *dir;
+#ifdef HAVE_READDIR64
struct dirent64 *d;
+#else
+ struct dirent *d;
+#endif
PolKitPolicyCache *pc;
dir = NULL;
@@ -119,7 +123,11 @@ _polkit_policy_cache_new (const char *di
goto out;
}
+#ifdef HAVE_READDIR64
while ((d = readdir64 (dir)) != NULL) {
+#else
+ while ((d = readdir (dir)) != NULL) {
+#endif
char *path;
PolKitPolicyFile *pf;
PolKitError *pk_error;
--- src/polkit/polkit-sysdeps.c.orig 2007-11-28 16:26:14.000000000 -0500
+++ src/polkit/polkit-sysdeps.c 2008-01-02 00:42:47.000000000 -0500
@@ -39,7 +39,6 @@
#include
#include
#include
-#include
#include
#include "polkit-sysdeps.h"
@@ -82,7 +81,11 @@ polkit_sysdeps_get_start_time_for_pid (p
start_time = 0;
contents = NULL;
+#ifdef __FreeBSD__
+ filename = kit_strdup_printf ("/proc/%d/status", pid);
+#else
filename = kit_strdup_printf ("/proc/%d/stat", pid);
+#endif
if (filename == NULL) {
errno = ENOMEM;
goto out;
@@ -93,6 +96,35 @@ polkit_sysdeps_get_start_time_for_pid (p
goto out;
}
+#ifdef __FreeBSD__
+ tokens = kit_strsplit (contents, ' ', &num_tokens);
+ if (tokens == NULL)
+ goto out;
+ if (num_tokens < 8) {
+ kit_strfreev (tokens);
+ goto out;
+ }
+
+ p = kit_strdup (tokens[7]);
+ kit_strfreev (tokens);
+
+ tokens = kit_strsplit (p, ',', &num_tokens);
+ if (tokens == NULL)
+ goto out;
+ if (num_tokens >= 1) {
+ start_time = strtoll (tokens[0], &endp, 10);
+ if (endp == tokens[0]) {
+ kit_strfreev (tokens);
+ goto out;
+ }
+ } else {
+ kit_strfreev (tokens);
+ goto out;
+ }
+
+ kit_strfreev (tokens);
+#else
+
/* start time is the 19th token after the '(process name)' entry */
p = strchr (contents, ')');
@@ -118,6 +150,7 @@ polkit_sysdeps_get_start_time_for_pid (p
}
kit_strfreev (tokens);
+#endif
out:
kit_free (filename);
@@ -153,7 +186,11 @@ polkit_sysdeps_get_exe_for_pid (pid_t pi
ret = 0;
+#ifdef __FreeBSD__
+ snprintf (proc_name, sizeof (proc_name), "/proc/%d/file", pid);
+#else
snprintf (proc_name, sizeof (proc_name), "/proc/%d/exe", pid);
+#endif
ret = readlink (proc_name, out_buf, buf_size - 1);
if (ret == -1) {
strncpy (out_buf, "(unknown)", buf_size);
@@ -166,6 +203,108 @@ out:
return ret;
}
+#ifndef HAVE_GETLINE
+/* Taken from GNU sed. */
+/* Read up to (and including) a '\n' from STREAM into *LINEPTR
+ (and null-terminate it). *LINEPTR is a pointer returned from malloc (or
+ NULL), pointing to *N characters of space. It is realloc'd as
+ necessary. Returns the number of characters read (not including the
+ null terminator), or -1 on error or EOF. */
+
+ssize_t
+polkit_sysdeps_getline (char **lineptr, size_t *n, FILE *stream)
+{
+ char *line, *p;
+ long size, copy;
+
+ if (lineptr == NULL || n == NULL) {
+ errno = EINVAL;
+ return (ssize_t) -1;
+ }
+
+ if (ferror (stream))
+ return (ssize_t) -1;
+
+ /* Make sure we have a line buffer to start with. */
+ if (*lineptr == NULL || *n < 2) /* !seen and no buf yet need 2 chars. */ {
+#ifndef MAX_CANON
+#define MAX_CANON 256
+#endif
+ if (!*lineptr)
+ line = (char *) malloc (MAX_CANON);
+ else
+ line = (char *) realloc (*lineptr, MAX_CANON);
+ if (line == NULL)
+ return (ssize_t) -1;
+ *lineptr = line;
+ *n = MAX_CANON;
+ }
+
+ line = *lineptr;
+ size = *n;
+
+ copy = size;
+ p = line;
+
+ while (1) {
+ long len;
+
+ while (--copy > 0) {
+ int c = getc (stream);
+
+ if (c == EOF)
+ goto lose;
+ else if ((*p++ = c) == '\n')
+ goto win;
+ }
+
+ /* Need to enlarge the line buffer. */
+ len = p - line;
+ size *= 2;
+ line = (char *) realloc (line, size);
+ if (line == NULL)
+ goto lose;
+ *lineptr = line;
+ *n = size;
+ p = line + len;
+ copy = size - len;
+ }
+
+lose:
+ if (p == *lineptr)
+ return (ssize_t) -1;
+
+ /* Return a partial line since we got an error in the middle. */
+win:
+ *p = '\0';
+ return p - *lineptr;
+}
+#else
+ssize_t
+polkit_sysdeps_getline (char **lineptr, size_t *n, FILE *stream)
+{
+ return getline (lineptr, n, stream);
+}
+#endif
+
+#ifndef HAVE_CLEARENV
+extern char **environ;
+int
+polkit_sysdeps_clearenv (void)
+{
+ if (environ != NULL) {
+ environ[0] = NULL;
+ }
+ return 0;
+}
+#else
+int
+polkit_sysdeps_clearenv (void)
+{
+ return clearenv ();
+}
+#endif
+
#ifdef POLKIT_BUILD_TESTS
static polkit_bool_t
--- src/polkit/polkit-sysdeps.h.orig 2007-12-23 01:46:49.000000000 -0500
+++ src/polkit/polkit-sysdeps.h 2007-12-23 01:48:22.000000000 -0500
@@ -35,6 +35,7 @@
#define POLKIT_SYSDEPS_H
#include
+#include
#include
POLKIT_BEGIN_DECLS
@@ -43,6 +44,9 @@ polkit_uint64_t polkit_sysdeps_get_start
int polkit_sysdeps_get_exe_for_pid (pid_t pid, char *out_buf, size_t buf_size);
+ssize_t polkit_sysdeps_getline (char **lineptr, size_t *n, FILE *stream);
+
+int polkit_sysdeps_clearenv (void);
POLKIT_END_DECLS
--- tools/polkit-auth.c.orig 2007-12-05 22:30:18.000000000 -0500
+++ tools/polkit-auth.c 2007-12-23 01:43:36.000000000 -0500
@@ -37,12 +37,13 @@
#include
#include
#include
+#include
#include
#include
#include
#include
#include
#include
#include
@@ -107,7 +109,7 @@ conversation_select_admin_user (PolKitGr
}
printf ("\n");
printf ("Select user: ");
- getline (&lineptr, &linelen, stdin);
+ polkit_sysdeps_getline (&lineptr, &linelen, stdin);
user = strdup (lineptr);
free (lineptr);
return user;
@@ -133,7 +135,7 @@ conversation_pam_prompt_echo_off (PolKit
exit (1);
}
- getline (&lineptr, &linelen, stdin);
+ polkit_sysdeps_getline (&lineptr, &linelen, stdin);
/* Restore terminal. */
tcsetattr (fileno (stdout), TCSAFLUSH, &old);
@@ -151,7 +153,7 @@ conversation_pam_prompt_echo_on (PolKitG
size_t linelen = 0;
char *result;
printf ("%s", request);
- getline (&lineptr, &linelen, stdin);
+ polkit_sysdeps_getline (&lineptr, &linelen, stdin);
result = strdup (lineptr);
free (lineptr);
printf ("\n");
@@ -189,7 +191,7 @@ conversation_override_grant_type (PolKit
case POLKIT_RESULT_ONLY_VIA_SELF_AUTH_KEEP_SESSION:
printf ("Keep this privilege for the session? [no/session]?\n");
again:
- getline (&lineptr, &linelen, stdin);
+ polkit_sysdeps_getline (&lineptr, &linelen, stdin);
if (g_str_has_prefix (lineptr, "no")) {
;
} else if (g_str_has_prefix (lineptr, "session")) {
@@ -204,7 +206,7 @@ conversation_override_grant_type (PolKit
case POLKIT_RESULT_ONLY_VIA_SELF_AUTH_KEEP_ALWAYS:
printf ("Keep this privilege for the session or always? [no/session/always]?\n");
again2:
- getline (&lineptr, &linelen, stdin);
+ polkit_sysdeps_getline (&lineptr, &linelen, stdin);
if (g_str_has_prefix (lineptr, "no")) {
;
} else if (g_str_has_prefix (lineptr, "session")) {