Commit 00b85cf3 authored by Jim Li's avatar Jim Li Committed by David Zeuthen
Browse files

add support for Solaris platform

Add support for Solaris platform. The patch contains some implement
for GNU library extentsion function which isn't support by Solaris,
for instance, vasprintf(), strndup(), clearenv(), and clearenv(). Also
rewriting some code which Sun compiler doesn't support, such as empty
union name.
parent 5bc86a14
......@@ -433,7 +433,7 @@ fi
AC_SUBST(PAM_MODULE_DIR)
AC_ARG_WITH(os-type, [ --with-os-type=<os> distribution or OS (redhat/suse/gentoo/pardus)])
AC_ARG_WITH(os-type, [ --with-os-type=<os> distribution or OS (redhat/suse/gentoo/pardus/solaris)])
#### Check our operating system (distro-tweaks required)
if test "z$with_os_type" = "z"; then
......@@ -458,6 +458,8 @@ if test x$with_os_type = x; then
with_os_type=gentoo
elif test x$operating_system = xpardus ; then
with_os_type=pardus
elif test x$operating_system = xsolaris ; then
with_os_type=solaris
else
with_os_type=unknown
fi
......@@ -469,6 +471,7 @@ AM_CONDITIONAL(OS_TYPE_RED_HAT, test x$with_os_type = xredhat, [Running on Red H
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_SALARIS, test x$with_os_type = xsolaris, [Running os Solaris OS'es])
AC_ARG_WITH(pam-include, [ --with-pam-include=<file> pam file to include])
......@@ -483,7 +486,7 @@ elif test x$with_os_type = xredhat -o x$with_os_type = xgentoo -o x$with_os_type
PAM_FILE_INCLUDE_ACCOUNT=system-auth
PAM_FILE_INCLUDE_PASSWORD=system-auth
PAM_FILE_INCLUDE_SESSION=system-auth
elif test x$with_os_type = xsuse ; then
elif test x$with_os_type = xsuse -o x$with_os_type = xsolaris ; then
PAM_FILE_INCLUDE_AUTH=common-auth
PAM_FILE_INCLUDE_ACCOUNT=common-account
PAM_FILE_INCLUDE_PASSWORD=common-password
......@@ -504,6 +507,17 @@ AC_DEFINE_UNQUOTED(PAM_FILE_INCLUDE_ACCOUNT, "$PAM_FILE_INCLUDE_ACCOUNT", [pam f
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])
dnl ---------------------------------------------------------------------------
dnl - check OS
dnl ---------------------------------------------------------------------------
case "$host_os" in
*linux*)
;;
*solaris*)
AC_DEFINE([HAVE_SOLARIS], 1, [Is this a Solaris system?])
;;
esac
# ********************
# Internationalisation
# ********************
......
......@@ -35,6 +35,9 @@
#define KIT_FILE_H
#include <kit/kit.h>
#ifdef HAVE_SOLARIS
#include <sys/types.h>
#endif
KIT_BEGIN_DECLS
......
......@@ -38,8 +38,13 @@
KIT_BEGIN_DECLS
#ifdef __sun
void kit_debug (const char *format, ...);
void kit_warning (const char *format, ...);
#else
void kit_debug (const char *format, ...) __attribute__((__format__ (__printf__, 1, 2)));
void kit_warning (const char *format, ...) __attribute__((__format__ (__printf__, 1, 2)));
#endif
KIT_END_DECLS
......
......@@ -156,9 +156,9 @@ out:
* @flags: A combination of flags from #KitSpawnFlags
* @argv: #NULL terminated argument vector
* @envp: #NULL terminated environment or #NULL to inherit parents;
* @stdin: String to write to stdin of child or #NULL
* @stdout: Return location for stdout from child or #NULL. Free with kit_free().
* @stderr: Return location for stderr from child or #NULL. Free with kit_free().
* @stdinp: String to write to stdin of child or #NULL
* @stdoutp: Return location for stdout from child or #NULL. Free with kit_free().
* @stderrp: Return location for stderr from child or #NULL. Free with kit_free().
* @out_exit_status: Return location for exit status
*
* Executes a child process and waits for the child process to exit
......@@ -175,9 +175,9 @@ kit_spawn_sync (const char *working_directory,
KitSpawnFlags flags,
char **argv,
char **envp,
char *stdin,
char **stdout,
char **stderr,
char *stdinp,
char **stdoutp,
char **stderrp,
int *out_exit_status)
{
kit_bool_t ret;
......@@ -191,28 +191,28 @@ kit_spawn_sync (const char *working_directory,
kit_return_val_if_fail (argv != NULL, FALSE);
kit_return_val_if_fail (out_exit_status != NULL, FALSE);
kit_return_val_if_fail (! ((flags & KIT_SPAWN_CHILD_INHERITS_STDIN) && stdin != NULL), FALSE);
kit_return_val_if_fail (! ((flags & KIT_SPAWN_STDOUT_TO_DEV_NULL) && stdout != NULL), FALSE);
kit_return_val_if_fail (! ((flags & KIT_SPAWN_STDERR_TO_DEV_NULL) && stderr != NULL), FALSE);
kit_return_val_if_fail (! ((flags & KIT_SPAWN_CHILD_INHERITS_STDIN) && stdinp != NULL), FALSE);
kit_return_val_if_fail (! ((flags & KIT_SPAWN_STDOUT_TO_DEV_NULL) && stdoutp != NULL), FALSE);
kit_return_val_if_fail (! ((flags & KIT_SPAWN_STDERR_TO_DEV_NULL) && stderrp != NULL), FALSE);
if (stdout != NULL)
*stdout = NULL;
if (stderr != NULL)
*stderr = NULL;
if (stdoutp != NULL)
*stdoutp = NULL;
if (stderrp != NULL)
*stderrp = NULL;
if (stdin != NULL) {
if (stdinp != NULL) {
if (pipe (stdin_pipe) != 0) {
goto out;
}
}
if (stdout != NULL) {
if (stdoutp != NULL) {
if (pipe (stdout_pipe) != 0) {
goto out;
}
}
if (stderr != NULL) {
if (stderrp != NULL) {
if (pipe (stderr_pipe) != 0) {
goto out;
}
......@@ -260,9 +260,9 @@ kit_spawn_sync (const char *working_directory,
}
}
/* set stdin, stdout and stderr */
/* set stdinp, stdoutp and stderrp */
if (stdin != NULL) {
if (stdinp != NULL) {
if (_sane_dup2 (stdin_pipe[0], 0) < 0) {
exit (128 + errno);
}
......@@ -272,7 +272,7 @@ kit_spawn_sync (const char *working_directory,
}
}
if (stdout != NULL) {
if (stdoutp != NULL) {
if (_sane_dup2 (stdout_pipe[1], 1) < 0) {
exit (128 + errno);
}
......@@ -282,7 +282,7 @@ kit_spawn_sync (const char *working_directory,
}
}
if (stderr != NULL) {
if (stderrp != NULL) {
if (_sane_dup2 (stderr_pipe[1], 2) < 0) {
exit (128 + errno);
}
......@@ -322,7 +322,7 @@ kit_spawn_sync (const char *working_directory,
close (stderr_pipe[1]);
}
wp = stdin;
wp = stdinp;
while (stdin_pipe[1] != -1 || stdout_pipe[0] != -1 || stderr_pipe[0] != -1) {
int ret;
......@@ -375,7 +375,7 @@ kit_spawn_sync (const char *working_directory,
}
if (stdout_pipe[0] != -1) {
num_read = _read_from (stdout_pipe[0], stdout);
num_read = _read_from (stdout_pipe[0], stdoutp);
if (num_read == 0) {
close (stdout_pipe[0]);
stdout_pipe[0] = -1;
......@@ -385,7 +385,7 @@ kit_spawn_sync (const char *working_directory,
}
if (stderr_pipe[0] != -1) {
num_read = _read_from (stderr_pipe[0], stderr);
num_read = _read_from (stderr_pipe[0], stderrp);
if (num_read == 0) {
close (stderr_pipe[0]);
stderr_pipe[0] = -1;
......@@ -424,13 +424,13 @@ out:
close (stderr_pipe[0]);
if (!ret) {
if (stdout != NULL) {
kit_free (*stdout);
*stdout = NULL;
if (stdoutp != NULL) {
kit_free (*stdoutp);
*stdoutp = NULL;
}
if (stderr != NULL) {
kit_free (*stderr);
*stderr = NULL;
if (stderrp != NULL) {
kit_free (*stderrp);
*stderrp = NULL;
}
}
......@@ -483,8 +483,8 @@ _run_test (void)
"echo -n \"$value\"" "\n"
"exit 0" "\n";
char *argv[] = {"/tmp/kit-spawn-test", NULL};
char *stdout;
char *stderr;
char *stdoutp;
char *stderrp;
int exit_status;
struct stat statbuf;
......@@ -495,14 +495,14 @@ _run_test (void)
argv,
NULL,
NULL,
&stdout,
&stderr,
&stdoutp,
&stderrp,
&exit_status)) {
kit_assert (WEXITSTATUS (exit_status) == 42);
kit_assert (stdout != NULL && strcmp (stdout, "Hello World\n") == 0);
kit_assert (stderr != NULL && strcmp (stderr, "Goodbye World\n") == 0);
kit_free (stdout);
kit_free (stderr);
kit_assert (stdoutp != NULL && strcmp (stdoutp, "Hello World\n") == 0);
kit_assert (stderrp != NULL && strcmp (stderrp, "Goodbye World\n") == 0);
kit_free (stdoutp);
kit_free (stderrp);
}
if (kit_spawn_sync ("/",
......@@ -526,12 +526,12 @@ _run_test (void)
argv,
NULL,
NULL,
&stdout,
&stderr,
&stdoutp,
&stderrp,
&exit_status)) {
kit_assert (WEXITSTATUS (exit_status) == 43);
kit_assert (stdout == NULL);
kit_assert (stderr == NULL);
kit_assert (stdoutp == NULL);
kit_assert (stderrp == NULL);
}
kit_assert (unlink (path) == 0);
......@@ -546,12 +546,12 @@ _run_test (void)
argv,
envp,
NULL,
&stdout,
&stdoutp,
NULL,
&exit_status)) {
kit_assert (WEXITSTATUS (exit_status) == 0);
kit_assert (stdout != NULL && strcmp (stdout, "some_value") == 0);
kit_free (stdout);
kit_assert (stdoutp != NULL && strcmp (stdoutp, "some_value") == 0);
kit_free (stdoutp);
}
kit_assert (unlink (path) == 0);
......@@ -606,12 +606,12 @@ _run_test (void)
argv,
NULL,
NULL,
&stdout,
&stdoutp,
NULL,
&exit_status)) {
kit_assert (WEXITSTATUS (exit_status) == 0);
kit_assert (stdout != NULL && strcmp (stdout, "/tmp\n") == 0);
kit_free (stdout);
kit_assert (stdoutp != NULL && strcmp (stdoutp, "/tmp\n") == 0);
kit_free (stdoutp);
}
kit_assert (stat ("/usr", &statbuf) == 0 && S_ISDIR (statbuf.st_mode));
......@@ -620,12 +620,12 @@ _run_test (void)
argv,
NULL,
NULL,
&stdout,
&stdoutp,
NULL,
&exit_status)) {
kit_assert (WEXITSTATUS (exit_status) == 0);
kit_assert (stdout != NULL && strcmp (stdout, "/usr\n") == 0);
kit_free (stdout);
kit_assert (stdoutp != NULL && strcmp (stdoutp, "/usr\n") == 0);
kit_free (stdoutp);
}
kit_assert (unlink (path) == 0);
......@@ -650,12 +650,12 @@ _run_test (void)
argv,
NULL,
"foobar0\nfoobar1",
&stdout,
&stdoutp,
NULL,
&exit_status)) {
kit_assert (WEXITSTATUS (exit_status) == 0);
kit_assert (stdout != NULL && strcmp (stdout, "foobar0 foobar1") == 0);
kit_free (stdout);
kit_assert (stdoutp != NULL && strcmp (stdoutp, "foobar0 foobar1") == 0);
kit_free (stdoutp);
}
kit_assert (unlink (path) == 0);
......
......@@ -57,9 +57,9 @@ kit_bool_t kit_spawn_sync (const char *working_directory,
KitSpawnFlags flags,
char **argv,
char **envp,
char *stdin,
char **stdout,
char **stderr,
char *stdinp,
char **stdoutp,
char **stderrp,
int *out_exit_status);
KIT_END_DECLS
......
......@@ -127,6 +127,26 @@ kit_strndup (const char *s, size_t n)
#endif /* KIT_BUILD_TESTS */
#ifdef HAVE_SOLARIS
int vasprintf(char **strp, const char *fmt, va_list ap)
{
int size;
va_list ap2;
char s;
*strp = NULL;
va_copy(ap2, ap);
size = vsnprintf(&s, 1, fmt, ap2);
va_end(ap2);
*strp = malloc(size + 1);
if (!*strp)
return -1;
vsnprintf(*strp, size + 1, fmt, ap);
return size;
}
#endif
/**
* kit_strdup_printf:
* @format: sprintf(3) format string
......
......@@ -40,7 +40,11 @@ KIT_BEGIN_DECLS
char *kit_strdup (const char *s);
char *kit_strndup (const char *s, size_t n);
#ifdef __sun
char *kit_strdup_printf (const char *format, ...);
#else
char *kit_strdup_printf (const char *format, ...) __attribute__((__format__ (__printf__, 1, 2)));
#endif
char *kit_strdup_vprintf (const char *format, va_list args);
char *kit_str_append (char *s, const char *s2);
......
......@@ -27,8 +27,15 @@
*
**************************************************************************/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#ifdef HAVE_SOLARIS
#include <sys/types.h>
#endif
#include <kit/kit-test.h>
#include <kit/kit-memory.h>
......
......@@ -72,6 +72,9 @@ typedef int kit_bool_t;
void kit_print_backtrace (void);
#ifdef HAVE_SOLARIS
#define __PRETTY_FUNCTION__ __func__
#endif
/**
* kit_assert:
* @expr: expression
......@@ -140,6 +143,9 @@ do {
#define _KIT_INSIDE_KIT_H 1
#ifdef HAVE_SOLARIS
#include <sys/types.h>
#endif
#include <kit/kit-memory.h>
#include <kit/kit-string.h>
#include <kit/kit-list.h>
......
......@@ -48,6 +48,10 @@
#include <utime.h>
#include <fcntl.h>
#include <dirent.h>
#ifdef HAVE_SOLARIS
#include <limits.h>
#define LOG_AUTHPRIV (10<<3)
#endif
#include <polkit-dbus/polkit-dbus.h>
#include <polkit/polkit-private.h>
......@@ -287,8 +291,15 @@ main (int argc, char *argv[])
#ifndef POLKIT_BUILD_TESTS
/* clear the entire environment to avoid attacks using with libraries honoring environment variables */
#ifdef HAVE_SOLARIS
extern char **environ;
if (environ != NULL)
environ[0] = NULL;
#else
if (clearenv () != 0)
goto out;
#endif
/* set a minimal environment */
setenv ("PATH", "/usr/sbin:/usr/bin:/sbin:/bin", 1);
#endif
......
......@@ -53,6 +53,10 @@
#include <polkit-dbus/polkit-dbus.h>
#include <polkit/polkit-private.h>
#ifdef HAVE_SOLARIS
#define LOG_AUTHPRIV (10<<3)
#define PATH_MAX 1024
#endif
int
main (int argc, char *argv[])
......@@ -72,8 +76,15 @@ main (int argc, char *argv[])
ret = 1;
/* clear the entire environment to avoid attacks using with libraries honoring environment variables */
#ifdef HAVE_SOLARIS
extern char **environ;
if (environ != NULL)
environ[0] = NULL;
#else
if (clearenv () != 0)
goto out;
#endif
/* set a minimal environment */
setenv ("PATH", "/usr/sbin:/usr/bin:/sbin:/bin", 1);
......
......@@ -54,6 +54,10 @@
#include <polkit/polkit-private.h>
#include <polkit-dbus/polkit-dbus.h>
#ifdef HAVE_SOLARIS
#define LOG_AUTHPRIV (10<<3)
#endif
static polkit_bool_t
set_default (const char *action_id, const char *any, const char *inactive, const char *active)
{
......@@ -126,8 +130,15 @@ main (int argc, char *argv[])
ret = 1;
/* clear the entire environment to avoid attacks using with libraries honoring environment variables */
#ifdef HAVE_SOLARIS
extern char **environ;
if (environ != NULL)
environ[0] = NULL;
#else
if (clearenv () != 0)
goto out;
#endif
/* set a minimal environment */
setenv ("PATH", "/usr/sbin:/usr/bin:/sbin:/bin", 1);
......
......@@ -52,6 +52,10 @@
#include <polkit-dbus/polkit-dbus.h>
#include <polkit/polkit-private.h>
#ifdef HAVE_SOLARIS
#define LOG_AUTHPRIV (10<<3)
#endif
int
main (int argc, char *argv[])
{
......@@ -66,8 +70,15 @@ main (int argc, char *argv[])
ret = 1;
/* clear the entire environment to avoid attacks using with libraries honoring environment variables */
#ifdef HAVE_SOLARIS
extern char **environ;
if (environ != NULL)
environ[0] = NULL;
#else
if (clearenv () != 0)
goto out;
#endif
/* set a minimal environment */
setenv ("PATH", "/usr/sbin:/usr/bin:/sbin:/bin", 1);
......
......@@ -28,6 +28,9 @@
**************************************************************************/
/* TODO: FIXME: XXX: this code needs security review before it can be released! */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdio.h>
#include <stdlib.h>
......@@ -38,6 +41,10 @@
#include <syslog.h>
#include <security/pam_appl.h>
#ifdef HAVE_SOLARIS
#define LOG_AUTHPRIV (10<<3)
#endif
/* 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,8 +67,15 @@ main (int argc, char *argv[])
pam_h = NULL;
/* clear the entire environment to avoid attacks using with libraries honoring environment variables */
#ifdef HAVE_SOLARIS
extern char **environ;
if (environ != NULL)
environ[0] = NULL;
#else
if (clearenv () != 0)
goto error;
#endif
/* set a minimal environment */
setenv ("PATH", "/usr/sbin:/usr/bin:/sbin:/bin", 1);
......
......@@ -60,6 +60,10 @@
#include <polkit-dbus/polkit-dbus.h>
// #include <polkit/polkit-grant-database.h>
#ifdef HAVE_SOLARIS
#define LOG_AUTHPRIV (10<<3)
#endif
/* Development aid: define PGH_DEBUG to get debugging output. Do _NOT_
* enable this in production builds; it may leak passwords and other
* sensitive information.
......@@ -560,8 +564,15 @@ main (int argc, char *argv[])
ret = 3;
/* clear the entire environment to avoid attacks using with libraries honoring environment variables */
#ifdef HAVE_SOLARIS
extern char **environ;
if (environ != NULL)
environ[0] = NULL;
#else
if (clearenv () != 0)
goto out;
#endif
/* set a minimal environment */
setenv ("PATH", "/usr/sbin:/usr/bin:/sbin:/bin", 1);
......
......@@ -35,6 +35,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/wait.h>
......@@ -542,6 +543,49 @@ error:
return FALSE;
}
#ifdef HAVE_SOLARIS
#define BUFFER_LEN 256
ssize_t getline (char **lineptr, size_t *n, FILE *f)
{
char ch;
size_t m = 0;
ssize_t buf_len = 0;
char * buf = NULL;
char * p = NULL;
while ( (ch = getc(f)) !=EOF )
{
if (errno != 0)
return -1;
if ( m++ >= buf_len )
{
buf_len += BUFFER_LEN;
buf = (char *) realloc(buf, buf_len + 1);
if ( buf == NULL )
{
return -1;
}