aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortoni <matzeton@googlemail.com>2016-10-23 18:07:18 +0200
committertoni <matzeton@googlemail.com>2016-10-23 18:07:18 +0200
commit9e2ec145be20a5ba54ed8ce92bceb1b8eca86ee4 (patch)
tree8377ca83f72566c78dead7cee4c0113fbeb59c32
parent8fbadac6c72c461a639443ebade00372b8402402 (diff)
added uname feature
-rwxr-xr-xbuild/install-sh21
-rwxr-xr-xconfigure106
-rw-r--r--configure.ac40
-rw-r--r--src/Makefile.am3
-rw-r--r--src/Makefile.in7
-rw-r--r--src/aconfig.h.in6
-rw-r--r--src/config.h1
-rw-r--r--src/ui_nask.c35
-rw-r--r--src/utils.c22
-rw-r--r--src/utils.h5
10 files changed, 222 insertions, 24 deletions
diff --git a/build/install-sh b/build/install-sh
index 377bb86..756420d 100755
--- a/build/install-sh
+++ b/build/install-sh
@@ -345,34 +345,41 @@ do
# is incompatible with FreeBSD 'install' when (umask & 300) != 0.
;;
*)
+ # $RANDOM is not portable (e.g. dash); use it when possible to
+ # lower collision chance
tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$
- trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0
+ trap 'ret=$?; rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir" 2>/dev/null; exit $ret' 0
+ # As "mkdir -p" follows symlinks and we work in /tmp possibly; so
+ # create the $tmpdir first (and fail if unsuccessful) to make sure
+ # that nobody tries to guess the $tmpdir name.
if (umask $mkdir_umask &&
- exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1
+ $mkdirprog $mkdir_mode "$tmpdir" &&
+ exec $mkdirprog $mkdir_mode -p -- "$tmpdir/a/b") >/dev/null 2>&1
then
if test -z "$dir_arg" || {
# Check for POSIX incompatibilities with -m.
# HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or
# other-writable bit of parent directory when it shouldn't.
# FreeBSD 6.1 mkdir -m -p sets mode of existing directory.
- ls_ld_tmpdir=`ls -ld "$tmpdir"`
+ test_tmpdir="$tmpdir/a"
+ ls_ld_tmpdir=`ls -ld "$test_tmpdir"`
case $ls_ld_tmpdir in
d????-?r-*) different_mode=700;;
d????-?--*) different_mode=755;;
*) false;;
esac &&
- $mkdirprog -m$different_mode -p -- "$tmpdir" && {
- ls_ld_tmpdir_1=`ls -ld "$tmpdir"`
+ $mkdirprog -m$different_mode -p -- "$test_tmpdir" && {
+ ls_ld_tmpdir_1=`ls -ld "$test_tmpdir"`
test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1"
}
}
then posix_mkdir=:
fi
- rmdir "$tmpdir/d" "$tmpdir"
+ rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir"
else
# Remove any dirs left behind by ancient mkdir implementations.
- rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null
+ rmdir ./$mkdir_mode ./-p ./-- "$tmpdir" 2>/dev/null
fi
trap '' 0;;
esac;;
diff --git a/configure b/configure
index bfe648e..0889619 100755
--- a/configure
+++ b/configure
@@ -633,6 +633,8 @@ AM_CFLAGS
DEBUG_FALSE
DEBUG_TRUE
LIBOBJS
+UNAME_FALSE
+UNAME_TRUE
RESOLVE_FALSE
RESOLVE_TRUE
RANLIB
@@ -6442,6 +6444,8 @@ fi
done
+
+have_resolv="false"
for ac_header in resolv.h
do :
ac_fn_c_check_header_mongrel "$LINENO" "resolv.h" "ac_cv_header_resolv_h" "$ac_includes_default"
@@ -6517,12 +6521,25 @@ if ac_fn_c_try_compile "$LINENO"; then :
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }
+ have_resolv="true"
+
+else
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+
+fi
+
+done
+
+if test x"$have_resolv" = x"true" ; then
cat >>confdefs.h <<_ACEOF
#define HAVE_RESOLVE 1
_ACEOF
- if true; then
+ if true; then
RESOLVE_TRUE=
RESOLVE_FALSE='#'
else
@@ -6530,22 +6547,85 @@ else
RESOLVE_FALSE=
fi
-
else
+ if false; then
+ RESOLVE_TRUE=
+ RESOLVE_FALSE='#'
+else
+ RESOLVE_TRUE='#'
+ RESOLVE_FALSE=
+fi
- { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
+ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: *** DNS information disabled" >&5
+$as_echo "$as_me: WARNING: *** DNS information disabled" >&2;}
+fi
+
+have_uname="false"
+for ac_header in sys/utsname.h
+do :
+ ac_fn_c_check_header_mongrel "$LINENO" "sys/utsname.h" "ac_cv_header_sys_utsname_h" "$ac_includes_default"
+if test "x$ac_cv_header_sys_utsname_h" = xyes; then :
+ cat >>confdefs.h <<_ACEOF
+#define HAVE_SYS_UTSNAME_H 1
+_ACEOF
+
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for working uname" >&5
+$as_echo_n "checking for working uname... " >&6; }
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+#include <sys/utsname.h>
+int
+main ()
+{
+struct utsname nm;
+ uname(&nm);
+
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+ have_uname="true"
+else
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-else
- { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: *** DNS information disabled" >&5
-$as_echo "$as_me: WARNING: *** DNS information disabled" >&2;}
fi
done
+if test x"$have_uname" = x"true" ; then
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_UNAME 1
+_ACEOF
+
+ if true; then
+ UNAME_TRUE=
+ UNAME_FALSE='#'
+else
+ UNAME_TRUE='#'
+ UNAME_FALSE=
+fi
+
+else
+ if false; then
+ RESOLVE_TRUE=
+ RESOLVE_FALSE='#'
+else
+ RESOLVE_TRUE='#'
+ RESOLVE_FALSE=
+fi
+
+ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: *** uname information disabled" >&5
+$as_echo "$as_me: WARNING: *** uname information disabled" >&2;}
+fi
# Checks for typedefs, structures, and compiler characteristics.
if ac_fn_c_compute_int "$LINENO" "" "" ""; then :
@@ -9481,6 +9561,18 @@ if test -z "${RESOLVE_TRUE}" && test -z "${RESOLVE_FALSE}"; then
as_fn_error $? "conditional \"RESOLVE\" was never defined.
Usually this means the macro was only invoked conditionally." "$LINENO" 5
fi
+if test -z "${RESOLVE_TRUE}" && test -z "${RESOLVE_FALSE}"; then
+ as_fn_error $? "conditional \"RESOLVE\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
+if test -z "${UNAME_TRUE}" && test -z "${UNAME_FALSE}"; then
+ as_fn_error $? "conditional \"UNAME\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
+if test -z "${RESOLVE_TRUE}" && test -z "${RESOLVE_FALSE}"; then
+ as_fn_error $? "conditional \"RESOLVE\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
if test -z "${DEBUG_TRUE}" && test -z "${DEBUG_FALSE}"; then
as_fn_error $? "conditional \"DEBUG\" was never defined.
Usually this means the macro was only invoked conditionally." "$LINENO" 5
diff --git a/configure.ac b/configure.ac
index 63c6ac6..3ef0ce0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -34,6 +34,8 @@ AC_HEADER_STAT
AC_HEADER_DIRENT
AC_HEADER_ASSERT
AC_CHECK_HEADERS([glob.h stdio.h stdlib.h stdbool.h string.h unistd.h errno.h sys/stat.h sys/types.h sys/wait.h fcntl.h semaphore.h time.h mqueue.h syslog.h],[],[AC_MSG_ERROR([*** missing essential header files])])
+
+have_resolv="false"
AC_CHECK_HEADERS([resolv.h],
[
AC_CHECK_LIB([resolv], [__res_init], [], [AC_MSG_ERROR([__res_init not found int resolv])])
@@ -45,13 +47,39 @@ AC_CHECK_HEADERS([resolv.h],
)],
[
AC_MSG_RESULT([yes])
- AC_DEFINE_UNQUOTED([HAVE_RESOLVE], 1, [Define to 1 if you have libc resolv.])
- AM_CONDITIONAL(RESOLVE, true)
+ have_resolv="true"
],
- [
- AC_MSG_RESULT([no])
- ])
- ],[AC_MSG_WARN([*** DNS information disabled])])
+ [ AC_MSG_RESULT([no])])
+ ],[])
+if test x"$have_resolv" = x"true" ; then
+ AC_DEFINE_UNQUOTED([HAVE_RESOLVE], 1, [Define to 1 if you have libc resolv.])
+ AM_CONDITIONAL([RESOLVE], true)
+else
+ AM_CONDITIONAL([RESOLVE], false)
+ AC_MSG_WARN([*** DNS information disabled])
+fi
+
+have_uname="false"
+AC_CHECK_HEADERS([sys/utsname.h],
+ [
+ AC_MSG_CHECKING([for working uname])
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/utsname.h>]],
+ [[struct utsname nm;]]
+ [[uname(&nm);]]
+ )],
+ [
+ AC_MSG_RESULT([yes])
+ have_uname="true"
+ ],
+ [ AC_MSG_RESULT([no])])
+ ],[])
+if test x"$have_uname" = x"true" ; then
+ AC_DEFINE_UNQUOTED([HAVE_UNAME], 1, [Define to 1 if you have uname (sys/utsname.h) support.])
+ AM_CONDITIONAL([UNAME], true)
+else
+ AM_CONDITIONAL([RESOLVE], false)
+ AC_MSG_WARN([*** uname information disabled])
+fi
# Checks for typedefs, structures, and compiler characteristics.
AC_COMPUTE_INT
diff --git a/src/Makefile.am b/src/Makefile.am
index 8ad31f1..5538be2 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -11,3 +11,6 @@ endif
if RESOLVE
naskpass_CFLAGS+=-DHAVE_RESOLVE
endif
+if UNAME
+naskpass_CFLAGS+=-DHAVE_UNAME
+endif
diff --git a/src/Makefile.in b/src/Makefile.in
index 66bd91f..ab0543b 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -81,6 +81,7 @@ host_triplet = @host@
bin_PROGRAMS = naskpass$(EXEEXT) naskshell$(EXEEXT) \
naskpass_check$(EXEEXT)
@RESOLVE_TRUE@am__append_1 = -DHAVE_RESOLVE
+@UNAME_TRUE@am__append_2 = -DHAVE_UNAME
subdir = src
DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \
$(srcdir)/aconfig.h.in $(top_srcdir)/build/depcomp
@@ -279,8 +280,10 @@ naskpass_LDFLAGS =
naskpass_check_SOURCES = check/check.c
naskshell_SOURCES = shell/shell.c
@DEBUG_FALSE@naskpass_CFLAGS = -fPIC -fomit-frame-pointer \
-@DEBUG_FALSE@ -fexpensive-optimizations -Os $(am__append_1)
-@DEBUG_TRUE@naskpass_CFLAGS = -O0 -g3 -DDEBUG $(am__append_1)
+@DEBUG_FALSE@ -fexpensive-optimizations -Os $(am__append_1) \
+@DEBUG_FALSE@ $(am__append_2)
+@DEBUG_TRUE@naskpass_CFLAGS = -O0 -g3 -DDEBUG $(am__append_1) \
+@DEBUG_TRUE@ $(am__append_2)
all: aconfig.h
$(MAKE) $(AM_MAKEFLAGS) all-am
diff --git a/src/aconfig.h.in b/src/aconfig.h.in
index f9c5598..30f5796 100644
--- a/src/aconfig.h.in
+++ b/src/aconfig.h.in
@@ -174,6 +174,9 @@
/* Define to 1 if you have the <sys/types.h> header file. */
#undef HAVE_SYS_TYPES_H
+/* Define to 1 if you have the <sys/utsname.h> header file. */
+#undef HAVE_SYS_UTSNAME_H
+
/* Define to 1 if you have the <sys/wait.h> header file. */
#undef HAVE_SYS_WAIT_H
@@ -183,6 +186,9 @@
/* Define to 1 if you have the <time.h> header file. */
#undef HAVE_TIME_H
+/* Define to 1 if you have uname (sys/utsname.h) support. */
+#undef HAVE_UNAME
+
/* Define to 1 if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H
diff --git a/src/config.h b/src/config.h
index d20991f..1a7dafc 100644
--- a/src/config.h
+++ b/src/config.h
@@ -11,6 +11,7 @@
#define MSQ_INF "/naskpass-info"
#ifdef HAVE_CONFIG_H
+#include "aconfig.h"
#include "version.h"
#endif
diff --git a/src/ui_nask.c b/src/ui_nask.c
index 32a8dcc..aae9536 100644
--- a/src/ui_nask.c
+++ b/src/ui_nask.c
@@ -14,6 +14,8 @@
#include "utils.h"
#include "status.h"
+#include "config.h"
+
#define APP_TIMEOUT 60
#define APP_TIMEOUT_FMT "%02d"
#define NETUPD_INTERVAL 5
@@ -33,11 +35,12 @@
static struct input *pw_input;
static struct anic *heartbeat;
-static struct statusbar *higher, *lower, *netinfo;
+static struct statusbar *higher, *lower, *netinfo, *uninfo;
static struct txtwindow *busywnd, *errwnd;
static unsigned int atmout = APP_TIMEOUT;
static unsigned int netupd = 0;
static char *title = NULL;
+static char *untext = NULL;
static char busy_str[BSTR_LEN+1] = ".\0\0\0";
@@ -93,6 +96,29 @@ netinfo_statusbar_update(WINDOW *win, struct statusbar *bar, bool ui_timeout)
}
static int
+uninfo_statusbar_update(WINDOW *win, struct statusbar *bar, bool ui_timeout)
+{
+ if (untext == NULL) {
+#ifdef HAVE_UNAME
+ char *sysop;
+ char *sysrelease;
+ char *sysmachine;
+
+ if (utGetUnameInfo(&sysop, &sysrelease, &sysmachine) == 0) {
+ asprintf(&untext, "%s v%s (%s)", sysop, sysrelease, sysmachine);
+ free(sysop);
+ free(sysrelease);
+ free(sysmachine);
+ } else
+#endif
+ asprintf(&untext, "%s", "[unknown kernel]");
+
+ set_statusbar_text(bar, untext);
+ }
+ return DOUI_OK;
+}
+
+static int
busywnd_update(WINDOW *win, struct txtwindow *tw, bool ui_timeout)
{
if (ui_timeout == TRUE && tw->active == TRUE) {
@@ -192,8 +218,10 @@ init_ui_elements(unsigned int max_x, unsigned int max_y)
higher_statusbar_update);
lower = init_statusbar(max_y - 1, max_x, COLOR_PAIR(3),
lower_statusbar_update);
- netinfo = init_statusbar(1, max_x, COLOR_PAIR(2),
+ netinfo = init_statusbar(2, max_x, COLOR_PAIR(2),
netinfo_statusbar_update);
+ uninfo = init_statusbar(1, max_x, COLOR_PAIR(2),
+ uninfo_statusbar_update);
busywnd = init_txtwindow_centered(INFOWND_WIDTH, INFOWND_HEIGHT,
busywnd_update);
errwnd = init_txtwindow_centered(INFOWND_WIDTH, INFOWND_HEIGHT,
@@ -203,6 +231,7 @@ init_ui_elements(unsigned int max_x, unsigned int max_y)
register_statusbar(higher);
register_statusbar(lower);
register_statusbar(netinfo);
+ register_statusbar(uninfo);
register_anic_default(heartbeat);
register_txtwindow(busywnd);
register_txtwindow(errwnd);
@@ -216,6 +245,7 @@ free_ui_elements(void)
unregister_ui_elt(lower);
unregister_ui_elt(higher);
unregister_ui_elt(netinfo);
+ unregister_ui_elt(uninfo);
unregister_ui_elt(heartbeat);
unregister_ui_elt(pw_input);
free_input(pw_input);
@@ -223,6 +253,7 @@ free_ui_elements(void)
free_statusbar(higher);
free_statusbar(lower);
free_statusbar(netinfo);
+ free_statusbar(uninfo);
free_txtwindow(busywnd);
free_txtwindow(errwnd);
free_ui();
diff --git a/src/utils.c b/src/utils.c
index b7e421d..c9e7089 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -15,6 +15,9 @@
#ifdef HAVE_RESOLVE
#include <resolv.h>
#endif
+#ifdef HAVE_UNAME
+#include <sys/utsname.h>
+#endif
int
@@ -88,3 +91,22 @@ utGetDomainInfo(char **szDefDomain, char **szDefServer)
return 0;
}
#endif
+
+#ifdef HAVE_UNAME
+int
+utGetUnameInfo(char **sysop, char **sysrelease, char **sysmachine) {
+ struct utsname un;
+
+ memset(&un, '\0', sizeof(struct utsname));
+ if (uname(&un) != 0)
+ return 1;
+
+ *sysop = calloc(_UTSNAME_SYSNAME_LENGTH, sizeof(char));
+ memcpy(*sysop, un.sysname, _UTSNAME_SYSNAME_LENGTH);
+ *sysrelease = calloc(_UTSNAME_RELEASE_LENGTH, sizeof(char));
+ memcpy(*sysrelease, un.release, _UTSNAME_RELEASE_LENGTH);
+ *sysmachine = calloc(_UTSNAME_MACHINE_LENGTH, sizeof(char));
+ memcpy(*sysmachine, un.machine, _UTSNAME_MACHINE_LENGTH);
+ return 0;
+}
+#endif
diff --git a/src/utils.h b/src/utils.h
index ffde45d..cb1aaf4 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -12,4 +12,9 @@ int
utGetDomainInfo(char **szDefDomain, char **szDefServer);
#endif
+#ifdef HAVE_UNAME
+int
+utGetUnameInfo(char **sysop, char **sysrelease, char **sysmachine);
+#endif
+
#endif