From e24bfc17bed4e245ad88baa9420ed29423ccc17d Mon Sep 17 00:00:00 2001 From: Damien Miller Date: Wed, 28 Mar 2001 14:37:37 +1000 Subject: - (djm) Work around Solaris' broken struct dirent. Diagnosis and suggested fix from Philippe Levan --- ChangeLog | 4 +++- acconfig.h | 5 ++++- configure.in | 16 +++++++++++++++- sftp-glob.c | 22 ++++++++++++++++------ 4 files changed, 38 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9bbe782c..9de431e3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,8 @@ - (djm) Reorder tests and library inclusion for Krb4/AFS to try to resolve linking conflicts with libcrypto. Report and suggested fix from Holger Trapp + - (djm) Work around Solaris' broken struct dirent. Diagnosis and suggested + fix from Philippe Levan 20010327 - (djm) Reestablish PAM credentials (which can be supplemental group @@ -4683,4 +4685,4 @@ - Wrote replacements for strlcpy and mkdtemp - Released 1.0pre1 -$Id: ChangeLog,v 1.991.2.12 2001/03/28 03:04:13 djm Exp $ +$Id: ChangeLog,v 1.991.2.13 2001/03/28 04:37:37 djm Exp $ diff --git a/acconfig.h b/acconfig.h index 57b5e607..900fbb63 100644 --- a/acconfig.h +++ b/acconfig.h @@ -1,4 +1,4 @@ -/* $Id: acconfig.h,v 1.108 2001/03/17 01:15:38 mouring Exp $ */ +/* $Id: acconfig.h,v 1.108.2.1 2001/03/28 04:37:37 djm Exp $ */ #ifndef _CONFIG_H #define _CONFIG_H @@ -308,6 +308,9 @@ /* Define if your system glob() function has gl_matchc options in glob_t */ #undef GLOB_HAS_GL_MATCHC +/* Define in your struct dirent expects you to allocate extra space for d_name */ +#undef BROKEN_ONE_BYTE_DIRENT_D_NAME + @BOTTOM@ /* ******************* Shouldn't need to edit below this line ************** */ diff --git a/configure.in b/configure.in index 0e6bf134..2a891eb2 100644 --- a/configure.in +++ b/configure.in @@ -1,4 +1,4 @@ -# $Id: configure.in,v 1.267.2.1 2001/03/28 03:04:14 djm Exp $ +# $Id: configure.in,v 1.267.2.2 2001/03/28 04:37:38 djm Exp $ AC_INIT(ssh.c) @@ -404,6 +404,20 @@ AC_EGREP_CPP(FOUNDIT, ] ) +AC_MSG_CHECKING([whether struct dirent allocates space for d_name]) +AC_TRY_RUN( + [ +#include +#include +int main(void){struct dirent d;return(sizeof(d.d_name)<=sizeof(char));} + ], + [AC_MSG_RESULT(yes)], + [ + AC_MSG_RESULT(no) + AC_DEFINE(BROKEN_ONE_BYTE_DIRENT_D_NAME) + ] +) + # Check whether user wants S/Key support SKEY_MSG="no" AC_ARG_WITH(skey, diff --git a/sftp-glob.c b/sftp-glob.c index 79dca00f..f1252eec 100644 --- a/sftp-glob.c +++ b/sftp-glob.c @@ -65,7 +65,9 @@ void *fudge_opendir(const char *path) struct dirent *fudge_readdir(struct SFTP_OPENDIR *od) { - static struct dirent ret; + /* Solaris needs sizeof(dirent) + path length (see below) */ + static char buf[sizeof(struct dirent) + MAXPATHLEN]; + struct dirent *ret = (struct dirent *)buf; #ifdef __GNU_LIBRARY__ static int inum = 1; #endif /* __GNU_LIBRARY__ */ @@ -73,22 +75,30 @@ struct dirent *fudge_readdir(struct SFTP_OPENDIR *od) if (od->dir[od->offset] == NULL) return(NULL); - memset(&ret, 0, sizeof(ret)); - strlcpy(ret.d_name, od->dir[od->offset++]->filename, - sizeof(ret.d_name)); + memset(buf, 0, sizeof(buf)); + /* + * Solaris defines dirent->d_name as a one byte array and expects + * you to hack around it. + */ +#ifdef BROKEN_ONE_BYTE_DIRENT_D_NAME + strlcpy(ret->d_name, od->dir[od->offset++]->filename, MAXPATHLEN); +#else + strlcpy(ret->d_name, od->dir[od->offset++]->filename, + sizeof(ret->d_name)); +#endif #ifdef __GNU_LIBRARY__ /* * Idiot glibc uses extensions to struct dirent for readdir with * ALTDIRFUNCs. Not that this is documented anywhere but the * source... Fake an inode number to appease it. */ - ret.d_ino = inum++; + ret->d_ino = inum++; if (!inum) inum = 1; #endif /* __GNU_LIBRARY__ */ - return(&ret); + return(ret); } void fudge_closedir(struct SFTP_OPENDIR *od) -- cgit v1.2.3