From 60f3a5bad3479251ba9b75178269f0d3302fd4f2 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Sun, 24 Apr 2016 13:38:57 -0400 Subject: [PATCH] Continued the war against cruft. Don't touch utmp anymore; always use the output of 'who am i' for the client's hostname. Also replaced old hand-coded extraction with a call to our library function stripallbut(). --- textclient/configure.ac | 22 +--------- textclient/src/getutline.c | 39 ----------------- textclient/src/routines.c | 85 ++------------------------------------ 3 files changed, 6 insertions(+), 140 deletions(-) delete mode 100644 textclient/src/getutline.c diff --git a/textclient/configure.ac b/textclient/configure.ac index daee0dc2c..a979aa5d7 100644 --- a/textclient/configure.ac +++ b/textclient/configure.ac @@ -642,7 +642,7 @@ dnl dnl TODO: for the DB header checks, we should check whether the headers dnl define db_env_create, somehow dnl -AC_CHECK_HEADERS(dl.h fcntl.h limits.h malloc.h termios.h sys/ioctl.h sys/select.h sys/stat.h sys/time.h sys/prctl.h syslog.h unistd.h utmp.h utmpx.h paths.h db.h db4/db.h pthread.h netinet/in.h arpa/nameser.h arpa/nameser_compat.h syscall.h sys/syscall.h) +AC_CHECK_HEADERS(dl.h fcntl.h limits.h malloc.h termios.h sys/ioctl.h sys/select.h sys/stat.h sys/time.h sys/prctl.h syslog.h unistd.h paths.h db.h db4/db.h pthread.h netinet/in.h arpa/nameser.h arpa/nameser_compat.h syscall.h sys/syscall.h) AC_CHECK_HEADER(resolv.h,AC_DEFINE(HAVE_RESOLV_H, [], [define this if you have the resolv.h header file.]),, [#ifdef HAVE_SYS_TYPES_H @@ -665,14 +665,6 @@ AC_HEADER_TIME dnl defined in acinclude.m4: CIT_STRUCT_TM -AC_CACHE_CHECK([for ut_type in struct utmp], ac_cv_struct_ut_type, -[AC_TRY_COMPILE([#include -#include ], [struct utmp ut; ut.ut_type;], -ac_cv_struct_ut_type=yes, ac_cv_struct_ut_type=no)]) -if test $ac_cv_struct_ut_type = yes; then - AC_DEFINE(HAVE_UT_TYPE, [], [define this if struct utmp has an ut_type member]) -fi - AC_CACHE_CHECK( [for call semantics from getpwuid_r], ac_cv_call_getpwuid_r, @@ -735,20 +727,12 @@ esac -AC_CACHE_CHECK([for ut_host in struct utmp], ac_cv_struct_ut_host, -[AC_TRY_COMPILE([#include -#include ], [struct utmp ut; ut.ut_host;], -ac_cv_struct_ut_host=yes, ac_cv_struct_ut_host=no)]) -if test $ac_cv_struct_ut_host = yes; then - AC_DEFINE(HAVE_UT_HOST, [], [define this if struct utmp has an ut_host member]) -fi - dnl Checks for library functions. AC_FUNC_GETPGRP AC_PROG_GCC_TRADITIONAL AC_TYPE_SIGNAL AC_FUNC_VPRINTF -AC_CHECK_FUNCS(getspnam getutxline mkdir mkfifo mktime rmdir select socket strerror strcasecmp strncasecmp) +AC_CHECK_FUNCS(getspnam mkdir mkfifo mktime rmdir select socket strerror strcasecmp strncasecmp) dnl Now check for pthreads @@ -832,8 +816,6 @@ AC_CACHE_CHECK([under the bed], ac_cv_under_the_bed, [ ]) -STRUCT_UCRED - dnl Done! Now write the Makefile and sysdep.h AC_SUBST(RESOLV) AC_SUBST(TARGETS) diff --git a/textclient/src/getutline.c b/textclient/src/getutline.c deleted file mode 100644 index 7c6b78e2f..000000000 --- a/textclient/src/getutline.c +++ /dev/null @@ -1,39 +0,0 @@ -/* - * getutline.c: not-quite-compatible replacement for getutline(3) - * by nathan bryant, feb 1999 - */ - -#include "sysdep.h" -#ifdef HAVE_UTMP_H -#include -#include -#include -#ifdef HAVE_PATHS_H -#include -#endif -#include - -struct utmp *getutline(struct utmp *ut) -{ - static struct utmp retval; - FILE *utmp; - -#ifdef UTMP_FILE - if ((utmp = fopen(UTMP_FILE, "rb")) == NULL) -#else - if ((utmp = fopen(_PATH_UTMP, "rb")) == NULL) -#endif - return NULL; - - do - if (!fread(&retval, sizeof retval, 1, utmp)) - { - fclose(utmp); - return NULL; - } - while (strcmp(ut->ut_line, retval.ut_line)); - - fclose(utmp); - return &retval; -} -#endif /* HAVE_UTMP_H */ diff --git a/textclient/src/routines.c b/textclient/src/routines.c index 3ec4a3c98..856475911 100644 --- a/textclient/src/routines.c +++ b/textclient/src/routines.c @@ -1,7 +1,7 @@ /* * Client-side support functions. * - * Copyright (c) 1987-2012 by the citadel.org team + * Copyright (c) 1987-2016 by the citadel.org team * * This program is open source software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3. @@ -40,25 +40,13 @@ #ifdef HAVE_LIMITS_H #include #endif -#ifdef HAVE_UTMP_H -#include -#endif -#ifdef HAVE_UTMPX_H -#include -#endif #include -///#include "citadel.h" #include "citadel_ipc.h" #include "screen.h" -#ifndef HAVE_GETUTLINE -struct utmp *getutline(struct utmp *ut); -#endif - #define ROUTINES_C -///#include "citadel.h" #include "routines.h" #include "commands.h" #include "citadel_decls.h" @@ -462,79 +450,14 @@ void progress(CtdlIPC* ipc, unsigned long curr, unsigned long cmax) */ void locate_host(CtdlIPC* ipc, char *hbuf) { -#ifndef HAVE_UTMP_H - char buf[SIZ]; - FILE *who; - int a,b; - - who = (FILE *)popen("who am i","r"); + FILE *who = (FILE *)popen("who am i","r"); if (who==NULL) { strcpy(hbuf, ipc->ServInfo.fqdn); return; } - fgets(buf,sizeof buf,who); + fgets(hbuf, SIZ, who); pclose(who); - - b = 0; - for (a=0; !IsEmptyStr(&buf[a]); ++a) { - if ((buf[a]=='(')||(buf[a]==')')) ++b; - } - if (b<2) { - strcpy(hbuf, ipc->ServInfo.fqdn); - return; - } - - for (a=0; aServInfo.fqdn); - else strncpy(hbuf,buf,24); -#else - char *tty = ttyname(0); -#ifdef HAVE_GETUTXLINE - struct utmpx ut, *put; -#else - struct utmp ut, *put; -#endif - - if (tty == NULL) { - fail: - safestrncpy(hbuf, ipc->ServInfo.fqdn, 24); - return; - } - - if (strncmp(tty, "/dev/", 5)) - goto fail; - - safestrncpy(ut.ut_line, &tty[5], sizeof ut.ut_line); - -#ifdef HAVE_GETUTXLINE /* Solaris uses this */ - if ((put = getutxline(&ut)) == NULL) -#else - if ((put = getutline(&ut)) == NULL) -#endif - goto fail; - -#if defined(HAVE_UT_TYPE) || defined(HAVE_GETUTXLINE) - if (put->ut_type == USER_PROCESS) { -#endif -#if defined(HAVE_UT_HOST) || defined(HAVE_GETUTXLINE) - if (*put->ut_host) - safestrncpy(hbuf, put->ut_host, 24); - else -#endif - safestrncpy(hbuf, put->ut_line, 24); -#if defined(HAVE_UT_TYPE) || defined(HAVE_GETUTXLINE) - } - else goto fail; -#endif -#endif /* HAVE_UTMP_H */ + stripallbut(hbuf, '(' , ')' ); } /* -- 2.30.2