mirror of
git://git.gnupg.org/gnupg.git
synced 2025-03-21 21:39:58 +01:00
* argparse.c, dotlock.c, fileutil.c, iobuf.c, miscutil.c,
simple-gettext.c, errors.c, http.c, memory.c, secmem.c, ttyio.c: Edit all preprocessor instructions to remove whitespace before the '#'. This is not required by C89, but there are some compilers out there that don't like it.
This commit is contained in:
parent
b4fc8ec5f5
commit
b357540659
@ -1,3 +1,11 @@
|
|||||||
|
2003-05-21 David Shaw <dshaw@jabberwocky.com>
|
||||||
|
|
||||||
|
* argparse.c, dotlock.c, fileutil.c, iobuf.c, miscutil.c,
|
||||||
|
simple-gettext.c, errors.c, http.c, memory.c, secmem.c, ttyio.c:
|
||||||
|
Edit all preprocessor instructions to remove whitespace before the
|
||||||
|
'#'. This is not required by C89, but there are some compilers
|
||||||
|
out there that don't like it.
|
||||||
|
|
||||||
2003-05-21 Werner Koch <wk@gnupg.org>
|
2003-05-21 Werner Koch <wk@gnupg.org>
|
||||||
|
|
||||||
* fileutil.c (is_file_compressed): Fix the check for the "-" file
|
* fileutil.c (is_file_compressed): Fix the check for the "-" file
|
||||||
|
@ -441,7 +441,7 @@ find_long_option( ARGPARSE_ARGS *arg,
|
|||||||
for(i=0; opts[i].short_opt; i++ )
|
for(i=0; opts[i].short_opt; i++ )
|
||||||
if( opts[i].long_opt && !strcmp( opts[i].long_opt, keyword) )
|
if( opts[i].long_opt && !strcmp( opts[i].long_opt, keyword) )
|
||||||
return i;
|
return i;
|
||||||
#if 0
|
#if 0
|
||||||
{
|
{
|
||||||
ALIAS_DEF a;
|
ALIAS_DEF a;
|
||||||
/* see whether it is an alias */
|
/* see whether it is an alias */
|
||||||
@ -453,7 +453,7 @@ find_long_option( ARGPARSE_ARGS *arg,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
/* not found, see whether it is an abbreviation */
|
/* not found, see whether it is an abbreviation */
|
||||||
/* aliases may not be abbreviated */
|
/* aliases may not be abbreviated */
|
||||||
n = strlen( keyword );
|
n = strlen( keyword );
|
||||||
|
@ -80,9 +80,9 @@ create_dotlock( const char *file_to_lock )
|
|||||||
DOTLOCK h;
|
DOTLOCK h;
|
||||||
int fd = -1;
|
int fd = -1;
|
||||||
char pidstr[16];
|
char pidstr[16];
|
||||||
#if !defined (HAVE_DOSISH_SYSTEM)
|
#if !defined (HAVE_DOSISH_SYSTEM)
|
||||||
struct utsname utsbuf;
|
struct utsname utsbuf;
|
||||||
#endif
|
#endif
|
||||||
const char *nodename;
|
const char *nodename;
|
||||||
const char *dirpart;
|
const char *dirpart;
|
||||||
int dirpartlen;
|
int dirpartlen;
|
||||||
@ -97,9 +97,9 @@ create_dotlock( const char *file_to_lock )
|
|||||||
h = m_alloc_clear( sizeof *h );
|
h = m_alloc_clear( sizeof *h );
|
||||||
if( never_lock ) {
|
if( never_lock ) {
|
||||||
h->disable = 1;
|
h->disable = 1;
|
||||||
#ifdef _REENTRANT
|
#ifdef _REENTRANT
|
||||||
/* fixme: aquire mutex on all_lockfiles */
|
/* fixme: aquire mutex on all_lockfiles */
|
||||||
#endif
|
#endif
|
||||||
h->next = all_lockfiles;
|
h->next = all_lockfiles;
|
||||||
all_lockfiles = h;
|
all_lockfiles = h;
|
||||||
return h;
|
return h;
|
||||||
@ -134,9 +134,9 @@ create_dotlock( const char *file_to_lock )
|
|||||||
dirpart = file_to_lock;
|
dirpart = file_to_lock;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef _REENTRANT
|
#ifdef _REENTRANT
|
||||||
/* fixme: aquire mutex on all_lockfiles */
|
/* fixme: aquire mutex on all_lockfiles */
|
||||||
#endif
|
#endif
|
||||||
h->next = all_lockfiles;
|
h->next = all_lockfiles;
|
||||||
all_lockfiles = h;
|
all_lockfiles = h;
|
||||||
|
|
||||||
@ -164,9 +164,9 @@ create_dotlock( const char *file_to_lock )
|
|||||||
}
|
}
|
||||||
if( write(fd, pidstr, 11 ) != 11 ) {
|
if( write(fd, pidstr, 11 ) != 11 ) {
|
||||||
all_lockfiles = h->next;
|
all_lockfiles = h->next;
|
||||||
#ifdef _REENTRANT
|
#ifdef _REENTRANT
|
||||||
/* release mutex */
|
/* release mutex */
|
||||||
#endif
|
#endif
|
||||||
log_fatal( "error writing to `%s': %s\n", h->tname, strerror(errno) );
|
log_fatal( "error writing to `%s': %s\n", h->tname, strerror(errno) );
|
||||||
close(fd);
|
close(fd);
|
||||||
unlink(h->tname);
|
unlink(h->tname);
|
||||||
@ -176,9 +176,9 @@ create_dotlock( const char *file_to_lock )
|
|||||||
}
|
}
|
||||||
if( close(fd) ) {
|
if( close(fd) ) {
|
||||||
all_lockfiles = h->next;
|
all_lockfiles = h->next;
|
||||||
#ifdef _REENTRANT
|
#ifdef _REENTRANT
|
||||||
/* release mutex */
|
/* release mutex */
|
||||||
#endif
|
#endif
|
||||||
log_error( "error closing `%s': %s\n", h->tname, strerror(errno));
|
log_error( "error closing `%s': %s\n", h->tname, strerror(errno));
|
||||||
unlink(h->tname);
|
unlink(h->tname);
|
||||||
m_free(h->tname);
|
m_free(h->tname);
|
||||||
@ -186,9 +186,9 @@ create_dotlock( const char *file_to_lock )
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef _REENTRANT
|
#ifdef _REENTRANT
|
||||||
/* release mutex */
|
/* release mutex */
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
h->lockname = m_alloc( strlen(file_to_lock) + 6 );
|
h->lockname = m_alloc( strlen(file_to_lock) + 6 );
|
||||||
strcpy(stpcpy(h->lockname, file_to_lock), EXTSEP_S "lock");
|
strcpy(stpcpy(h->lockname, file_to_lock), EXTSEP_S "lock");
|
||||||
@ -271,10 +271,10 @@ make_dotlock( DOTLOCK h, long timeout )
|
|||||||
else if( kill(pid, 0) && errno == ESRCH ) {
|
else if( kill(pid, 0) && errno == ESRCH ) {
|
||||||
#ifndef __riscos__
|
#ifndef __riscos__
|
||||||
maybe_dead = " - probably dead";
|
maybe_dead = " - probably dead";
|
||||||
#if 0 /* we should not do this without checking the permissions */
|
#if 0 /* we should not do this without checking the permissions */
|
||||||
/* and the hostname */
|
/* and the hostname */
|
||||||
log_info( "removing stale lockfile (created by %d)", pid );
|
log_info( "removing stale lockfile (created by %d)", pid );
|
||||||
#endif
|
#endif
|
||||||
#else /* __riscos__ */
|
#else /* __riscos__ */
|
||||||
/* we are *pretty* sure that the other task is dead and therefore
|
/* we are *pretty* sure that the other task is dead and therefore
|
||||||
we remove the other lock file */
|
we remove the other lock file */
|
||||||
@ -359,9 +359,9 @@ release_dotlock( DOTLOCK h )
|
|||||||
static int
|
static int
|
||||||
read_lockfile( const char *name )
|
read_lockfile( const char *name )
|
||||||
{
|
{
|
||||||
#if defined (HAVE_DOSISH_SYSTEM)
|
#if defined (HAVE_DOSISH_SYSTEM)
|
||||||
return 0;
|
return 0;
|
||||||
#else
|
#else
|
||||||
int fd, pid;
|
int fd, pid;
|
||||||
char pidstr[16];
|
char pidstr[16];
|
||||||
|
|
||||||
@ -390,14 +390,14 @@ read_lockfile( const char *name )
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return pid;
|
return pid;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
remove_lockfiles()
|
remove_lockfiles()
|
||||||
{
|
{
|
||||||
#if !defined (HAVE_DOSISH_SYSTEM)
|
#if !defined (HAVE_DOSISH_SYSTEM)
|
||||||
DOTLOCK h, h2;
|
DOTLOCK h, h2;
|
||||||
|
|
||||||
h = all_lockfiles;
|
h = all_lockfiles;
|
||||||
@ -415,6 +415,5 @@ remove_lockfiles()
|
|||||||
m_free(h);
|
m_free(h);
|
||||||
h = h2;
|
h = h2;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ g10_errstr( int err )
|
|||||||
static char buf[50];
|
static char buf[50];
|
||||||
const char *p;
|
const char *p;
|
||||||
|
|
||||||
#define X(n,s) case G10ERR_##n : p = s; break;
|
#define X(n,s) case G10ERR_##n : p = s; break;
|
||||||
switch( err ) {
|
switch( err ) {
|
||||||
case -1: p = "eof"; break;
|
case -1: p = "eof"; break;
|
||||||
case 0: p = "okay"; break;
|
case 0: p = "okay"; break;
|
||||||
@ -107,7 +107,6 @@ g10_errstr( int err )
|
|||||||
X(KEYSERVER ,N_("keyserver error"))
|
X(KEYSERVER ,N_("keyserver error"))
|
||||||
default: p = buf; sprintf(buf, "g10err=%d", err); break;
|
default: p = buf; sprintf(buf, "g10err=%d", err); break;
|
||||||
}
|
}
|
||||||
#undef X
|
#undef X
|
||||||
return _(p);
|
return _(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,10 +73,10 @@ make_dirname(const char *filepath)
|
|||||||
char *p;
|
char *p;
|
||||||
|
|
||||||
if ( !(p=strrchr(filepath, DIRSEP_C)) )
|
if ( !(p=strrchr(filepath, DIRSEP_C)) )
|
||||||
#ifdef HAVE_DRIVE_LETTERS
|
#ifdef HAVE_DRIVE_LETTERS
|
||||||
if ( !(p=strrchr(filepath, '\\')) )
|
if ( !(p=strrchr(filepath, '\\')) )
|
||||||
if ( !(p=strrchr(filepath, ':')) )
|
if ( !(p=strrchr(filepath, ':')) )
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
return m_strdup(EXTSEP_S);
|
return m_strdup(EXTSEP_S);
|
||||||
}
|
}
|
||||||
@ -143,11 +143,11 @@ compare_filenames( const char *a, const char *b )
|
|||||||
* resolve symlinks?
|
* resolve symlinks?
|
||||||
*/
|
*/
|
||||||
#ifndef __riscos__
|
#ifndef __riscos__
|
||||||
#ifdef HAVE_DRIVE_LETTERS
|
#ifdef HAVE_DRIVE_LETTERS
|
||||||
return ascii_strcasecmp(a,b);
|
return ascii_strcasecmp(a,b);
|
||||||
#else
|
#else
|
||||||
return strcmp(a,b);
|
return strcmp(a,b);
|
||||||
#endif
|
#endif
|
||||||
#else /* __riscos__ */
|
#else /* __riscos__ */
|
||||||
int c = 0;
|
int c = 0;
|
||||||
char *abuf, *bbuf;
|
char *abuf, *bbuf;
|
||||||
@ -236,5 +236,3 @@ leave:
|
|||||||
iobuf_close( a );
|
iobuf_close( a );
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
38
util/http.c
38
util/http.c
@ -27,16 +27,16 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
#ifdef __MINGW32__
|
#ifdef __MINGW32__
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#else
|
#else
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
@ -46,11 +46,11 @@
|
|||||||
#include "http.h"
|
#include "http.h"
|
||||||
|
|
||||||
#ifdef __riscos__
|
#ifdef __riscos__
|
||||||
#define HTTP_PROXY_ENV "GnuPG$HttpProxy"
|
#define HTTP_PROXY_ENV "GnuPG$HttpProxy"
|
||||||
#define HTTP_PROXY_ENV_PRINTABLE "<GnuPG$HttpProxy>"
|
#define HTTP_PROXY_ENV_PRINTABLE "<GnuPG$HttpProxy>"
|
||||||
#else
|
#else
|
||||||
#define HTTP_PROXY_ENV "http_proxy"
|
#define HTTP_PROXY_ENV "http_proxy"
|
||||||
#define HTTP_PROXY_ENV_PRINTABLE "$http_proxy"
|
#define HTTP_PROXY_ENV_PRINTABLE "$http_proxy"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __MINGW32__
|
#ifdef __MINGW32__
|
||||||
@ -66,7 +66,7 @@
|
|||||||
"!\"#$%&'()*+,-./:;<=>?[\\]^_{|}~"
|
"!\"#$%&'()*+,-./:;<=>?[\\]^_{|}~"
|
||||||
|
|
||||||
#ifndef EAGAIN
|
#ifndef EAGAIN
|
||||||
#define EAGAIN EWOULDBLOCK
|
#define EAGAIN EWOULDBLOCK
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static int parse_uri( PARSED_URI *ret_uri, const char *uri );
|
static int parse_uri( PARSED_URI *ret_uri, const char *uri );
|
||||||
@ -172,11 +172,11 @@ http_wait_response( HTTP_HD hd, unsigned int *ret_status )
|
|||||||
|
|
||||||
http_start_data( hd ); /* make sure that we are in the data */
|
http_start_data( hd ); /* make sure that we are in the data */
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
hd->sock = dup( hd->sock );
|
hd->sock = dup( hd->sock );
|
||||||
if( hd->sock == -1 )
|
if( hd->sock == -1 )
|
||||||
return G10ERR_GENERAL;
|
return G10ERR_GENERAL;
|
||||||
#endif
|
#endif
|
||||||
iobuf_ioctl (hd->fp_write, 1, 1, NULL); /* keep the socket open */
|
iobuf_ioctl (hd->fp_write, 1, 1, NULL); /* keep the socket open */
|
||||||
iobuf_close (hd->fp_write);
|
iobuf_close (hd->fp_write);
|
||||||
hd->fp_write = NULL;
|
hd->fp_write = NULL;
|
||||||
@ -785,7 +785,7 @@ write_server( int sock, const char *data, size_t length )
|
|||||||
|
|
||||||
nleft = length;
|
nleft = length;
|
||||||
while( nleft > 0 ) {
|
while( nleft > 0 ) {
|
||||||
#ifdef __MINGW32__
|
#ifdef __MINGW32__
|
||||||
int nwritten;
|
int nwritten;
|
||||||
|
|
||||||
nwritten = send (sock, data, nleft, 0);
|
nwritten = send (sock, data, nleft, 0);
|
||||||
@ -793,7 +793,7 @@ write_server( int sock, const char *data, size_t length )
|
|||||||
log_info ("write failed: ec=%d\n", (int)WSAGetLastError ());
|
log_info ("write failed: ec=%d\n", (int)WSAGetLastError ());
|
||||||
return G10ERR_NETWORK;
|
return G10ERR_NETWORK;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
int nwritten = write( sock, data, nleft );
|
int nwritten = write( sock, data, nleft );
|
||||||
if( nwritten == -1 ) {
|
if( nwritten == -1 ) {
|
||||||
if( errno == EINTR )
|
if( errno == EINTR )
|
||||||
@ -809,7 +809,7 @@ write_server( int sock, const char *data, size_t length )
|
|||||||
log_info("write failed: %s\n", strerror(errno));
|
log_info("write failed: %s\n", strerror(errno));
|
||||||
return G10ERR_NETWORK;
|
return G10ERR_NETWORK;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
nleft -=nwritten;
|
nleft -=nwritten;
|
||||||
data += nwritten;
|
data += nwritten;
|
||||||
}
|
}
|
||||||
|
139
util/iobuf.c
139
util/iobuf.c
@ -30,7 +30,7 @@
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#ifdef HAVE_DOSISH_SYSTEM
|
#ifdef HAVE_DOSISH_SYSTEM
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#endif
|
#endif
|
||||||
#ifdef __riscos__
|
#ifdef __riscos__
|
||||||
#include <kernel.h>
|
#include <kernel.h>
|
||||||
@ -44,18 +44,18 @@
|
|||||||
#undef FILE_FILTER_USES_STDIO
|
#undef FILE_FILTER_USES_STDIO
|
||||||
|
|
||||||
#ifdef HAVE_DOSISH_SYSTEM
|
#ifdef HAVE_DOSISH_SYSTEM
|
||||||
#define USE_SETMODE 1
|
#define USE_SETMODE 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef FILE_FILTER_USES_STDIO
|
#ifdef FILE_FILTER_USES_STDIO
|
||||||
#define my_fileno(a) fileno ((a))
|
#define my_fileno(a) fileno ((a))
|
||||||
#define my_fopen_ro(a,b) fopen ((a),(b))
|
#define my_fopen_ro(a,b) fopen ((a),(b))
|
||||||
#define my_fopen(a,b) fopen ((a),(b))
|
#define my_fopen(a,b) fopen ((a),(b))
|
||||||
typedef FILE *FILEP_OR_FD;
|
typedef FILE *FILEP_OR_FD;
|
||||||
#define INVALID_FP NULL
|
#define INVALID_FP NULL
|
||||||
#define FILEP_OR_FD_FOR_STDIN (stdin)
|
#define FILEP_OR_FD_FOR_STDIN (stdin)
|
||||||
#define FILEP_OR_FD_FOR_STDOUT (stdout)
|
#define FILEP_OR_FD_FOR_STDOUT (stdout)
|
||||||
typedef struct {
|
typedef struct {
|
||||||
FILE *fp; /* open file handle */
|
FILE *fp; /* open file handle */
|
||||||
int keep_open;
|
int keep_open;
|
||||||
int no_cache;
|
int no_cache;
|
||||||
@ -63,22 +63,22 @@
|
|||||||
char fname[1]; /* name of the file */
|
char fname[1]; /* name of the file */
|
||||||
} file_filter_ctx_t ;
|
} file_filter_ctx_t ;
|
||||||
#else
|
#else
|
||||||
#define my_fileno(a) (a)
|
#define my_fileno(a) (a)
|
||||||
#define my_fopen_ro(a,b) fd_cache_open ((a),(b))
|
#define my_fopen_ro(a,b) fd_cache_open ((a),(b))
|
||||||
#define my_fopen(a,b) direct_open ((a),(b))
|
#define my_fopen(a,b) direct_open ((a),(b))
|
||||||
#ifdef HAVE_DOSISH_SYSTEM
|
#ifdef HAVE_DOSISH_SYSTEM
|
||||||
typedef HANDLE FILEP_OR_FD;
|
typedef HANDLE FILEP_OR_FD;
|
||||||
#define INVALID_FP ((HANDLE)-1)
|
#define INVALID_FP ((HANDLE)-1)
|
||||||
#define FILEP_OR_FD_FOR_STDIN (GetStdHandle (STD_INPUT_HANDLE))
|
#define FILEP_OR_FD_FOR_STDIN (GetStdHandle (STD_INPUT_HANDLE))
|
||||||
#define FILEP_OR_FD_FOR_STDOUT (GetStdHandle (STD_OUTPUT_HANDLE))
|
#define FILEP_OR_FD_FOR_STDOUT (GetStdHandle (STD_OUTPUT_HANDLE))
|
||||||
#undef USE_SETMODE
|
#undef USE_SETMODE
|
||||||
#else
|
#else
|
||||||
typedef int FILEP_OR_FD;
|
typedef int FILEP_OR_FD;
|
||||||
#define INVALID_FP (-1)
|
#define INVALID_FP (-1)
|
||||||
#define FILEP_OR_FD_FOR_STDIN (0)
|
#define FILEP_OR_FD_FOR_STDIN (0)
|
||||||
#define FILEP_OR_FD_FOR_STDOUT (1)
|
#define FILEP_OR_FD_FOR_STDOUT (1)
|
||||||
#endif
|
#endif
|
||||||
typedef struct {
|
typedef struct {
|
||||||
FILEP_OR_FD fp; /* open file handle */
|
FILEP_OR_FD fp; /* open file handle */
|
||||||
int keep_open;
|
int keep_open;
|
||||||
int no_cache;
|
int no_cache;
|
||||||
@ -147,11 +147,11 @@ fd_cache_invalidate (const char *fname)
|
|||||||
if ( cc->fp != INVALID_FP && !strcmp (cc->fname, fname) ) {
|
if ( cc->fp != INVALID_FP && !strcmp (cc->fname, fname) ) {
|
||||||
if( DBG_IOBUF )
|
if( DBG_IOBUF )
|
||||||
log_debug (" did (%s)\n", cc->fname);
|
log_debug (" did (%s)\n", cc->fname);
|
||||||
#ifdef HAVE_DOSISH_SYSTEM
|
#ifdef HAVE_DOSISH_SYSTEM
|
||||||
CloseHandle (cc->fp);
|
CloseHandle (cc->fp);
|
||||||
#else
|
#else
|
||||||
close(cc->fp);
|
close(cc->fp);
|
||||||
#endif
|
#endif
|
||||||
cc->fp = INVALID_FP;
|
cc->fp = INVALID_FP;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -284,18 +284,18 @@ fd_cache_open (const char *fname, const char *mode)
|
|||||||
cc->fp = INVALID_FP;
|
cc->fp = INVALID_FP;
|
||||||
if( DBG_IOBUF )
|
if( DBG_IOBUF )
|
||||||
log_debug ("fd_cache_open (%s) using cached fp\n", fname);
|
log_debug ("fd_cache_open (%s) using cached fp\n", fname);
|
||||||
#ifdef HAVE_DOSISH_SYSTEM
|
#ifdef HAVE_DOSISH_SYSTEM
|
||||||
if (SetFilePointer (fp, 0, NULL, FILE_BEGIN) == 0xffffffff ) {
|
if (SetFilePointer (fp, 0, NULL, FILE_BEGIN) == 0xffffffff ) {
|
||||||
log_error ("rewind file failed on handle %p: ec=%d\n",
|
log_error ("rewind file failed on handle %p: ec=%d\n",
|
||||||
fp, (int)GetLastError () );
|
fp, (int)GetLastError () );
|
||||||
fp = INVALID_FP;
|
fp = INVALID_FP;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if ( lseek (fp, 0, SEEK_SET) == (off_t)-1 ) {
|
if ( lseek (fp, 0, SEEK_SET) == (off_t)-1 ) {
|
||||||
log_error("can't rewind fd %d: %s\n", fp, strerror(errno) );
|
log_error("can't rewind fd %d: %s\n", fp, strerror(errno) );
|
||||||
fp = INVALID_FP;
|
fp = INVALID_FP;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return fp;
|
return fp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -398,7 +398,7 @@ file_filter(void *opaque, int control, IOBUF chain, byte *buf, size_t *ret_len)
|
|||||||
*ret_len = 0;
|
*ret_len = 0;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
#ifdef HAVE_DOSISH_SYSTEM
|
#ifdef HAVE_DOSISH_SYSTEM
|
||||||
unsigned long nread;
|
unsigned long nread;
|
||||||
|
|
||||||
nbytes = 0;
|
nbytes = 0;
|
||||||
@ -417,7 +417,7 @@ file_filter(void *opaque, int control, IOBUF chain, byte *buf, size_t *ret_len)
|
|||||||
nbytes = nread;
|
nbytes = nread;
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
@ -439,13 +439,13 @@ file_filter(void *opaque, int control, IOBUF chain, byte *buf, size_t *ret_len)
|
|||||||
else {
|
else {
|
||||||
nbytes = n;
|
nbytes = n;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
*ret_len = nbytes;
|
*ret_len = nbytes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if( control == IOBUFCTRL_FLUSH ) {
|
else if( control == IOBUFCTRL_FLUSH ) {
|
||||||
if( size ) {
|
if( size ) {
|
||||||
#ifdef HAVE_DOSISH_SYSTEM
|
#ifdef HAVE_DOSISH_SYSTEM
|
||||||
byte *p = buf;
|
byte *p = buf;
|
||||||
unsigned long n;
|
unsigned long n;
|
||||||
|
|
||||||
@ -461,7 +461,7 @@ file_filter(void *opaque, int control, IOBUF chain, byte *buf, size_t *ret_len)
|
|||||||
nbytes -= n;
|
nbytes -= n;
|
||||||
} while ( nbytes );
|
} while ( nbytes );
|
||||||
nbytes = p - buf;
|
nbytes = p - buf;
|
||||||
#else
|
#else
|
||||||
byte *p = buf;
|
byte *p = buf;
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
@ -480,7 +480,7 @@ file_filter(void *opaque, int control, IOBUF chain, byte *buf, size_t *ret_len)
|
|||||||
rc = G10ERR_WRITE_FILE;
|
rc = G10ERR_WRITE_FILE;
|
||||||
}
|
}
|
||||||
nbytes = p - buf;
|
nbytes = p - buf;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
*ret_len = nbytes;
|
*ret_len = nbytes;
|
||||||
}
|
}
|
||||||
@ -493,14 +493,14 @@ file_filter(void *opaque, int control, IOBUF chain, byte *buf, size_t *ret_len)
|
|||||||
*(char**)buf = "file_filter(fd)";
|
*(char**)buf = "file_filter(fd)";
|
||||||
}
|
}
|
||||||
else if ( control == IOBUFCTRL_FREE ) {
|
else if ( control == IOBUFCTRL_FREE ) {
|
||||||
#ifdef HAVE_DOSISH_SYSTEM
|
#ifdef HAVE_DOSISH_SYSTEM
|
||||||
if ( f != FILEP_OR_FD_FOR_STDIN && f != FILEP_OR_FD_FOR_STDOUT ) {
|
if ( f != FILEP_OR_FD_FOR_STDIN && f != FILEP_OR_FD_FOR_STDOUT ) {
|
||||||
if( DBG_IOBUF )
|
if( DBG_IOBUF )
|
||||||
log_debug("%s: close handle %p\n", a->fname, f );
|
log_debug("%s: close handle %p\n", a->fname, f );
|
||||||
if (!a->keep_open)
|
if (!a->keep_open)
|
||||||
fd_cache_close (a->no_cache?NULL:a->fname, f);
|
fd_cache_close (a->no_cache?NULL:a->fname, f);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if ( (int)f != 0 && (int)f != 1 ) {
|
if ( (int)f != 0 && (int)f != 1 ) {
|
||||||
if( DBG_IOBUF )
|
if( DBG_IOBUF )
|
||||||
log_debug("%s: close fd %d\n", a->fname, f );
|
log_debug("%s: close fd %d\n", a->fname, f );
|
||||||
@ -508,7 +508,7 @@ file_filter(void *opaque, int control, IOBUF chain, byte *buf, size_t *ret_len)
|
|||||||
fd_cache_close (a->no_cache?NULL:a->fname, f);
|
fd_cache_close (a->no_cache?NULL:a->fname, f);
|
||||||
}
|
}
|
||||||
f = INVALID_FP;
|
f = INVALID_FP;
|
||||||
#endif
|
#endif
|
||||||
m_free (a); /* we can free our context now */
|
m_free (a); /* we can free our context now */
|
||||||
}
|
}
|
||||||
#endif /* !stdio implementation */
|
#endif /* !stdio implementation */
|
||||||
@ -950,18 +950,18 @@ iobuf_cancel( IOBUF a )
|
|||||||
const char *s;
|
const char *s;
|
||||||
IOBUF a2;
|
IOBUF a2;
|
||||||
int rc;
|
int rc;
|
||||||
#if defined(HAVE_DOSISH_SYSTEM) || defined(__riscos__)
|
#if defined(HAVE_DOSISH_SYSTEM) || defined(__riscos__)
|
||||||
char *remove_name = NULL;
|
char *remove_name = NULL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if( a && a->use == 2 ) {
|
if( a && a->use == 2 ) {
|
||||||
s = iobuf_get_real_fname(a);
|
s = iobuf_get_real_fname(a);
|
||||||
if( s && *s ) {
|
if( s && *s ) {
|
||||||
#if defined(HAVE_DOSISH_SYSTEM) || defined(__riscos__)
|
#if defined(HAVE_DOSISH_SYSTEM) || defined(__riscos__)
|
||||||
remove_name = m_strdup ( s );
|
remove_name = m_strdup ( s );
|
||||||
#else
|
#else
|
||||||
remove(s);
|
remove(s);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -974,14 +974,14 @@ iobuf_cancel( IOBUF a )
|
|||||||
}
|
}
|
||||||
|
|
||||||
rc = iobuf_close(a);
|
rc = iobuf_close(a);
|
||||||
#if defined(HAVE_DOSISH_SYSTEM) || defined(__riscos__)
|
#if defined(HAVE_DOSISH_SYSTEM) || defined(__riscos__)
|
||||||
if ( remove_name ) {
|
if ( remove_name ) {
|
||||||
/* Argg, MSDOS does not allow to remove open files. So
|
/* Argg, MSDOS does not allow to remove open files. So
|
||||||
* we have to do it here */
|
* we have to do it here */
|
||||||
remove ( remove_name );
|
remove ( remove_name );
|
||||||
m_free ( remove_name );
|
m_free ( remove_name );
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1056,9 +1056,9 @@ iobuf_open( const char *fname )
|
|||||||
|
|
||||||
if( !fname || (*fname=='-' && !fname[1]) ) {
|
if( !fname || (*fname=='-' && !fname[1]) ) {
|
||||||
fp = FILEP_OR_FD_FOR_STDIN;
|
fp = FILEP_OR_FD_FOR_STDIN;
|
||||||
#ifdef USE_SETMODE
|
#ifdef USE_SETMODE
|
||||||
setmode ( my_fileno(fp) , O_BINARY );
|
setmode ( my_fileno(fp) , O_BINARY );
|
||||||
#endif
|
#endif
|
||||||
fname = "[stdin]";
|
fname = "[stdin]";
|
||||||
print_only = 1;
|
print_only = 1;
|
||||||
}
|
}
|
||||||
@ -1159,9 +1159,9 @@ iobuf_create( const char *fname )
|
|||||||
|
|
||||||
if( !fname || (*fname=='-' && !fname[1]) ) {
|
if( !fname || (*fname=='-' && !fname[1]) ) {
|
||||||
fp = FILEP_OR_FD_FOR_STDOUT;
|
fp = FILEP_OR_FD_FOR_STDOUT;
|
||||||
#ifdef USE_SETMODE
|
#ifdef USE_SETMODE
|
||||||
setmode ( my_fileno(fp) , O_BINARY );
|
setmode ( my_fileno(fp) , O_BINARY );
|
||||||
#endif
|
#endif
|
||||||
fname = "[stdout]";
|
fname = "[stdout]";
|
||||||
print_only = 1;
|
print_only = 1;
|
||||||
}
|
}
|
||||||
@ -1261,22 +1261,22 @@ iobuf_ioctl ( IOBUF a, int cmd, int intval, void *ptrval )
|
|||||||
b->keep_open = intval;
|
b->keep_open = intval;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#ifdef __MINGW32__
|
#ifdef __MINGW32__
|
||||||
else if( !a->chain && a->filter == sock_filter ) {
|
else if( !a->chain && a->filter == sock_filter ) {
|
||||||
sock_filter_ctx_t *b = a->filter_ov;
|
sock_filter_ctx_t *b = a->filter_ov;
|
||||||
b->keep_open = intval;
|
b->keep_open = intval;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else if ( cmd == 2 ) { /* invalidate cache */
|
else if ( cmd == 2 ) { /* invalidate cache */
|
||||||
if( DBG_IOBUF )
|
if( DBG_IOBUF )
|
||||||
log_debug("iobuf-*.*: ioctl `%s' invalidate\n",
|
log_debug("iobuf-*.*: ioctl `%s' invalidate\n",
|
||||||
ptrval? (char*)ptrval:"?");
|
ptrval? (char*)ptrval:"?");
|
||||||
if ( !a && !intval && ptrval ) {
|
if ( !a && !intval && ptrval ) {
|
||||||
#ifndef FILE_FILTER_USES_STDIO
|
#ifndef FILE_FILTER_USES_STDIO
|
||||||
fd_cache_invalidate (ptrval);
|
fd_cache_invalidate (ptrval);
|
||||||
#endif
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1290,13 +1290,13 @@ iobuf_ioctl ( IOBUF a, int cmd, int intval, void *ptrval )
|
|||||||
b->no_cache = intval;
|
b->no_cache = intval;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#ifdef __MINGW32__
|
#ifdef __MINGW32__
|
||||||
else if( !a->chain && a->filter == sock_filter ) {
|
else if( !a->chain && a->filter == sock_filter ) {
|
||||||
sock_filter_ctx_t *b = a->filter_ov;
|
sock_filter_ctx_t *b = a->filter_ov;
|
||||||
b->no_cache = intval;
|
b->no_cache = intval;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
@ -1841,7 +1841,6 @@ off_t
|
|||||||
iobuf_get_filelength( IOBUF a )
|
iobuf_get_filelength( IOBUF a )
|
||||||
{
|
{
|
||||||
struct stat st;
|
struct stat st;
|
||||||
const char *s;
|
|
||||||
|
|
||||||
if( a->directfp ) {
|
if( a->directfp ) {
|
||||||
FILE *fp = a->directfp;
|
FILE *fp = a->directfp;
|
||||||
@ -1947,18 +1946,18 @@ iobuf_seek( IOBUF a, off_t newpos )
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
#ifdef HAVE_DOSISH_SYSTEM
|
#ifdef HAVE_DOSISH_SYSTEM
|
||||||
if (SetFilePointer (b->fp, newpos, NULL, FILE_BEGIN) == 0xffffffff ) {
|
if (SetFilePointer (b->fp, newpos, NULL, FILE_BEGIN) == 0xffffffff ) {
|
||||||
log_error ("SetFilePointer failed on handle %p: ec=%d\n",
|
log_error ("SetFilePointer failed on handle %p: ec=%d\n",
|
||||||
b->fp, (int)GetLastError () );
|
b->fp, (int)GetLastError () );
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if ( lseek (b->fp, newpos, SEEK_SET) == (off_t)-1 ) {
|
if ( lseek (b->fp, newpos, SEEK_SET) == (off_t)-1 ) {
|
||||||
log_error("can't lseek: %s\n", strerror(errno) );
|
log_error("can't lseek: %s\n", strerror(errno) );
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
a->d.len = 0; /* discard buffer */
|
a->d.len = 0; /* discard buffer */
|
||||||
@ -2142,7 +2141,7 @@ iobuf_read_line( IOBUF a, byte **addr_of_buffer,
|
|||||||
int
|
int
|
||||||
iobuf_translate_file_handle ( int fd, int for_write )
|
iobuf_translate_file_handle ( int fd, int for_write )
|
||||||
{
|
{
|
||||||
#ifdef __MINGW32__
|
#ifdef __MINGW32__
|
||||||
{
|
{
|
||||||
int x;
|
int x;
|
||||||
|
|
||||||
@ -2158,17 +2157,17 @@ iobuf_translate_file_handle ( int fd, int for_write )
|
|||||||
fd = x;
|
fd = x;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
translate_file_handle ( int fd, int for_write )
|
translate_file_handle ( int fd, int for_write )
|
||||||
{
|
{
|
||||||
#ifdef __MINGW32__
|
#ifdef __MINGW32__
|
||||||
#ifdef FILE_FILTER_USES_STDIO
|
#ifdef FILE_FILTER_USES_STDIO
|
||||||
fd = iobuf_translate_file_handle (fd, for_write);
|
fd = iobuf_translate_file_handle (fd, for_write);
|
||||||
#else
|
#else
|
||||||
{
|
{
|
||||||
int x;
|
int x;
|
||||||
|
|
||||||
@ -2187,9 +2186,7 @@ translate_file_handle ( int fd, int for_write )
|
|||||||
|
|
||||||
fd = x;
|
fd = x;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
121
util/memory.c
121
util/memory.c
@ -48,9 +48,9 @@
|
|||||||
* replace this guard stuff with one provided by a modern malloc library
|
* replace this guard stuff with one provided by a modern malloc library
|
||||||
*/
|
*/
|
||||||
#if SIZEOF_UNSIGNED_LONG == 8
|
#if SIZEOF_UNSIGNED_LONG == 8
|
||||||
#define EXTRA_ALIGN 4
|
#define EXTRA_ALIGN 4
|
||||||
#else
|
#else
|
||||||
#define EXTRA_ALIGN 0
|
#define EXTRA_ALIGN 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(M_DEBUG) || defined(M_GUARD)
|
#if defined(M_DEBUG) || defined(M_GUARD)
|
||||||
@ -59,32 +59,32 @@
|
|||||||
|
|
||||||
#ifdef M_DEBUG
|
#ifdef M_DEBUG
|
||||||
|
|
||||||
#ifndef M_GUARD
|
#ifndef M_GUARD
|
||||||
#define M_GUARD 1
|
#define M_GUARD 1
|
||||||
#endif
|
#endif
|
||||||
#undef m_alloc
|
#undef m_alloc
|
||||||
#undef m_alloc_clear
|
#undef m_alloc_clear
|
||||||
#undef m_alloc_secure
|
#undef m_alloc_secure
|
||||||
#undef m_alloc_secure_clear
|
#undef m_alloc_secure_clear
|
||||||
#undef m_realloc
|
#undef m_realloc
|
||||||
#undef m_free
|
#undef m_free
|
||||||
#undef m_check
|
#undef m_check
|
||||||
#undef m_strdup
|
#undef m_strdup
|
||||||
#define FNAME(a) m_debug_ ##a
|
#define FNAME(a) m_debug_ ##a
|
||||||
#define FNAMEPRT , const char *info
|
#define FNAMEPRT , const char *info
|
||||||
#define FNAMEARG , info
|
#define FNAMEARG , info
|
||||||
#ifndef __riscos__
|
#ifndef __riscos__
|
||||||
#define store_len(p,n,m) do { add_entry(p,n,m, \
|
#define store_len(p,n,m) do { add_entry(p,n,m, \
|
||||||
info, __FUNCTION__); } while(0)
|
info, __FUNCTION__); } while(0)
|
||||||
#else
|
|
||||||
#define store_len(p,n,m) do { add_entry(p,n,m, \
|
|
||||||
info, __func__ ); } while(0)
|
|
||||||
#endif
|
|
||||||
#else
|
#else
|
||||||
#define FNAME(a) m_ ##a
|
#define store_len(p,n,m) do { add_entry(p,n,m, \
|
||||||
#define FNAMEPRT
|
info, __func__ ); } while(0)
|
||||||
#define FNAMEARG
|
#endif
|
||||||
#define store_len(p,n,m) do { ((byte*)p)[EXTRA_ALIGN+0] = n; \
|
#else
|
||||||
|
#define FNAME(a) m_ ##a
|
||||||
|
#define FNAMEPRT
|
||||||
|
#define FNAMEARG
|
||||||
|
#define store_len(p,n,m) do { ((byte*)p)[EXTRA_ALIGN+0] = n; \
|
||||||
((byte*)p)[EXTRA_ALIGN+1] = n >> 8 ; \
|
((byte*)p)[EXTRA_ALIGN+1] = n >> 8 ; \
|
||||||
((byte*)p)[EXTRA_ALIGN+2] = n >> 16 ; \
|
((byte*)p)[EXTRA_ALIGN+2] = n >> 16 ; \
|
||||||
((byte*)p)[EXTRA_ALIGN+3] = m? MAGIC_SEC_BYTE \
|
((byte*)p)[EXTRA_ALIGN+3] = m? MAGIC_SEC_BYTE \
|
||||||
@ -332,11 +332,11 @@ check_allmem( const char *info )
|
|||||||
|
|
||||||
for( e = memtbl, n = 0; n < memtbl_len; n++, e++ ) {
|
for( e = memtbl, n = 0; n < memtbl_len; n++, e++ ) {
|
||||||
if( e->inuse ) {
|
if( e->inuse ) {
|
||||||
#ifndef __riscos__
|
#ifndef __riscos__
|
||||||
check_mem(e->user_p-4-EXTRA_ALIGN, info);
|
check_mem(e->user_p-4-EXTRA_ALIGN, info);
|
||||||
#else
|
#else
|
||||||
check_mem((const byte *) e->user_p-4-EXTRA_ALIGN, info);
|
check_mem((const byte *) e->user_p-4-EXTRA_ALIGN, info);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -354,10 +354,10 @@ membug( const char *fmt, ... )
|
|||||||
vfprintf(stderr,fmt,arg_ptr) ;
|
vfprintf(stderr,fmt,arg_ptr) ;
|
||||||
va_end(arg_ptr);
|
va_end(arg_ptr);
|
||||||
fflush(stderr);
|
fflush(stderr);
|
||||||
#ifdef M_DEBUG
|
#ifdef M_DEBUG
|
||||||
if( DBG_MEMSTAT )
|
if( DBG_MEMSTAT )
|
||||||
dump_table();
|
dump_table();
|
||||||
#endif
|
#endif
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -365,7 +365,7 @@ membug( const char *fmt, ... )
|
|||||||
void
|
void
|
||||||
m_print_stats( const char *prefix )
|
m_print_stats( const char *prefix )
|
||||||
{
|
{
|
||||||
#ifdef M_DEBUG
|
#ifdef M_DEBUG
|
||||||
unsigned n;
|
unsigned n;
|
||||||
struct memtbl_entry *e;
|
struct memtbl_entry *e;
|
||||||
ulong sum = 0, chunks =0;
|
ulong sum = 0, chunks =0;
|
||||||
@ -379,19 +379,19 @@ m_print_stats( const char *prefix )
|
|||||||
|
|
||||||
log_debug( "%s%smemstat: %8lu bytes in %ld chunks used\n",
|
log_debug( "%s%smemstat: %8lu bytes in %ld chunks used\n",
|
||||||
prefix? prefix:"", prefix? ": ":"", sum, chunks );
|
prefix? prefix:"", prefix? ": ":"", sum, chunks );
|
||||||
#elif defined(M_GUARD)
|
#elif defined(M_GUARD)
|
||||||
log_debug( "%s%smemstat: %8ld bytes\n",
|
log_debug( "%s%smemstat: %8ld bytes\n",
|
||||||
prefix? prefix:"", prefix? ": ":"", used_memory );
|
prefix? prefix:"", prefix? ": ":"", used_memory );
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
m_dump_table( const char *prefix )
|
m_dump_table( const char *prefix )
|
||||||
{
|
{
|
||||||
#ifdef M_DEBUG
|
#ifdef M_DEBUG
|
||||||
fprintf(stderr,"Memory-Table-Dump: %s\n", prefix);
|
fprintf(stderr,"Memory-Table-Dump: %s\n", prefix);
|
||||||
dump_table();
|
dump_table();
|
||||||
#endif
|
#endif
|
||||||
m_print_stats( prefix );
|
m_print_stats( prefix );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -418,7 +418,7 @@ FNAME(alloc)( size_t n FNAMEPRT )
|
|||||||
{
|
{
|
||||||
char *p;
|
char *p;
|
||||||
|
|
||||||
#ifdef M_GUARD
|
#ifdef M_GUARD
|
||||||
if(!n)
|
if(!n)
|
||||||
out_of_core(n,0); /* should never happen */
|
out_of_core(n,0); /* should never happen */
|
||||||
if( !(p = malloc( n + EXTRA_ALIGN+5 )) )
|
if( !(p = malloc( n + EXTRA_ALIGN+5 )) )
|
||||||
@ -427,7 +427,7 @@ FNAME(alloc)( size_t n FNAMEPRT )
|
|||||||
used_memory += n;
|
used_memory += n;
|
||||||
p[4+EXTRA_ALIGN+n] = MAGIC_END_BYTE;
|
p[4+EXTRA_ALIGN+n] = MAGIC_END_BYTE;
|
||||||
return p+EXTRA_ALIGN+4;
|
return p+EXTRA_ALIGN+4;
|
||||||
#else
|
#else
|
||||||
/* mallocing zero bytes is undefined by ISO-C, so we better make
|
/* mallocing zero bytes is undefined by ISO-C, so we better make
|
||||||
sure that it won't happen */
|
sure that it won't happen */
|
||||||
if (!n)
|
if (!n)
|
||||||
@ -435,7 +435,7 @@ FNAME(alloc)( size_t n FNAMEPRT )
|
|||||||
if( !(p = malloc( n )) )
|
if( !(p = malloc( n )) )
|
||||||
out_of_core(n,0);
|
out_of_core(n,0);
|
||||||
return p;
|
return p;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************
|
/****************
|
||||||
@ -447,7 +447,7 @@ FNAME(alloc_secure)( size_t n FNAMEPRT )
|
|||||||
{
|
{
|
||||||
char *p;
|
char *p;
|
||||||
|
|
||||||
#ifdef M_GUARD
|
#ifdef M_GUARD
|
||||||
if(!n)
|
if(!n)
|
||||||
out_of_core(n,1); /* should never happen */
|
out_of_core(n,1); /* should never happen */
|
||||||
if( !(p = secmem_malloc( n +EXTRA_ALIGN+ 5 )) )
|
if( !(p = secmem_malloc( n +EXTRA_ALIGN+ 5 )) )
|
||||||
@ -455,7 +455,7 @@ FNAME(alloc_secure)( size_t n FNAMEPRT )
|
|||||||
store_len(p,n,1);
|
store_len(p,n,1);
|
||||||
p[4+EXTRA_ALIGN+n] = MAGIC_END_BYTE;
|
p[4+EXTRA_ALIGN+n] = MAGIC_END_BYTE;
|
||||||
return p+EXTRA_ALIGN+4;
|
return p+EXTRA_ALIGN+4;
|
||||||
#else
|
#else
|
||||||
/* mallocing zero bytes is undefined by ISO-C, so we better make
|
/* mallocing zero bytes is undefined by ISO-C, so we better make
|
||||||
sure that it won't happen */
|
sure that it won't happen */
|
||||||
if (!n)
|
if (!n)
|
||||||
@ -463,7 +463,7 @@ FNAME(alloc_secure)( size_t n FNAMEPRT )
|
|||||||
if( !(p = secmem_malloc( n )) )
|
if( !(p = secmem_malloc( n )) )
|
||||||
out_of_core(n,1);
|
out_of_core(n,1);
|
||||||
return p;
|
return p;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void *
|
void *
|
||||||
@ -493,7 +493,7 @@ FNAME(realloc)( void *a, size_t n FNAMEPRT )
|
|||||||
{
|
{
|
||||||
void *b;
|
void *b;
|
||||||
|
|
||||||
#ifdef M_GUARD
|
#ifdef M_GUARD
|
||||||
if( a ) {
|
if( a ) {
|
||||||
unsigned char *p = a;
|
unsigned char *p = a;
|
||||||
size_t len = m_size(a);
|
size_t len = m_size(a);
|
||||||
@ -510,7 +510,7 @@ FNAME(realloc)( void *a, size_t n FNAMEPRT )
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
b = FNAME(alloc)(n FNAMEARG);
|
b = FNAME(alloc)(n FNAMEARG);
|
||||||
#else
|
#else
|
||||||
if( m_is_secure(a) ) {
|
if( m_is_secure(a) ) {
|
||||||
if( !(b = secmem_realloc( a, n )) )
|
if( !(b = secmem_realloc( a, n )) )
|
||||||
out_of_core(n,1);
|
out_of_core(n,1);
|
||||||
@ -519,7 +519,7 @@ FNAME(realloc)( void *a, size_t n FNAMEPRT )
|
|||||||
if( !(b = realloc( a, n )) )
|
if( !(b = realloc( a, n )) )
|
||||||
out_of_core(n,0);
|
out_of_core(n,0);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
@ -536,9 +536,9 @@ FNAME(free)( void *a FNAMEPRT )
|
|||||||
|
|
||||||
if( !p )
|
if( !p )
|
||||||
return;
|
return;
|
||||||
#ifdef M_DEBUG
|
#ifdef M_DEBUG
|
||||||
free_entry(p-EXTRA_ALIGN-4, info);
|
free_entry(p-EXTRA_ALIGN-4, info);
|
||||||
#elif defined M_GUARD
|
#elif defined M_GUARD
|
||||||
m_check(p);
|
m_check(p);
|
||||||
if( m_is_secure(a) )
|
if( m_is_secure(a) )
|
||||||
secmem_free(p-EXTRA_ALIGN-4);
|
secmem_free(p-EXTRA_ALIGN-4);
|
||||||
@ -546,57 +546,57 @@ FNAME(free)( void *a FNAMEPRT )
|
|||||||
used_memory -= m_size(a);
|
used_memory -= m_size(a);
|
||||||
free(p-EXTRA_ALIGN-4);
|
free(p-EXTRA_ALIGN-4);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if( m_is_secure(a) )
|
if( m_is_secure(a) )
|
||||||
secmem_free(p);
|
secmem_free(p);
|
||||||
else
|
else
|
||||||
free(p);
|
free(p);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
FNAME(check)( const void *a FNAMEPRT )
|
FNAME(check)( const void *a FNAMEPRT )
|
||||||
{
|
{
|
||||||
#ifdef M_GUARD
|
#ifdef M_GUARD
|
||||||
const byte *p = a;
|
const byte *p = a;
|
||||||
|
|
||||||
#ifdef M_DEBUG
|
#ifdef M_DEBUG
|
||||||
if( p )
|
if( p )
|
||||||
check_mem(p-EXTRA_ALIGN-4, info);
|
check_mem(p-EXTRA_ALIGN-4, info);
|
||||||
else
|
else
|
||||||
check_allmem(info);
|
check_allmem(info);
|
||||||
#else
|
#else
|
||||||
if( !p )
|
if( !p )
|
||||||
return;
|
return;
|
||||||
if( !(p[-1] == MAGIC_NOR_BYTE || p[-1] == MAGIC_SEC_BYTE) )
|
if( !(p[-1] == MAGIC_NOR_BYTE || p[-1] == MAGIC_SEC_BYTE) )
|
||||||
membug("memory at %p corrupted (underflow=%02x)\n", p, p[-1] );
|
membug("memory at %p corrupted (underflow=%02x)\n", p, p[-1] );
|
||||||
else if( p[m_size(p)] != MAGIC_END_BYTE )
|
else if( p[m_size(p)] != MAGIC_END_BYTE )
|
||||||
membug("memory at %p corrupted (overflow=%02x)\n", p, p[-1] );
|
membug("memory at %p corrupted (overflow=%02x)\n", p, p[-1] );
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
size_t
|
size_t
|
||||||
m_size( const void *a )
|
m_size( const void *a )
|
||||||
{
|
{
|
||||||
#ifndef M_GUARD
|
#ifndef M_GUARD
|
||||||
log_debug("dummy m_size called\n");
|
log_debug("dummy m_size called\n");
|
||||||
return 0;
|
return 0;
|
||||||
#else
|
#else
|
||||||
const byte *p = a;
|
const byte *p = a;
|
||||||
size_t n;
|
size_t n;
|
||||||
|
|
||||||
#ifdef M_DEBUG
|
#ifdef M_DEBUG
|
||||||
n = check_mem(p-EXTRA_ALIGN-4, "m_size")->user_n;
|
n = check_mem(p-EXTRA_ALIGN-4, "m_size")->user_n;
|
||||||
#else
|
#else
|
||||||
n = ((byte*)p)[-4];
|
n = ((byte*)p)[-4];
|
||||||
n |= ((byte*)p)[-3] << 8;
|
n |= ((byte*)p)[-3] << 8;
|
||||||
n |= ((byte*)p)[-2] << 16;
|
n |= ((byte*)p)[-2] << 16;
|
||||||
#endif
|
#endif
|
||||||
return n;
|
return n;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -631,4 +631,3 @@ FNAME(strdup)( const char *a FNAMEPRT )
|
|||||||
strcpy(p, a);
|
strcpy(p, a);
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#ifdef HAVE_LANGINFO_H
|
#ifdef HAVE_LANGINFO_H
|
||||||
#include <langinfo.h>
|
#include <langinfo.h>
|
||||||
#endif
|
#endif
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
@ -143,9 +143,9 @@ const char *
|
|||||||
asctimestamp( u32 stamp )
|
asctimestamp( u32 stamp )
|
||||||
{
|
{
|
||||||
static char buffer[50];
|
static char buffer[50];
|
||||||
#if defined (HAVE_STRFTIME) && defined (HAVE_NL_LANGINFO)
|
#if defined (HAVE_STRFTIME) && defined (HAVE_NL_LANGINFO)
|
||||||
static char fmt[50];
|
static char fmt[50];
|
||||||
#endif
|
#endif
|
||||||
struct tm *tp;
|
struct tm *tp;
|
||||||
time_t atime = stamp;
|
time_t atime = stamp;
|
||||||
|
|
||||||
@ -155,23 +155,23 @@ asctimestamp( u32 stamp )
|
|||||||
}
|
}
|
||||||
|
|
||||||
tp = localtime( &atime );
|
tp = localtime( &atime );
|
||||||
#ifdef HAVE_STRFTIME
|
#ifdef HAVE_STRFTIME
|
||||||
#if defined(HAVE_NL_LANGINFO)
|
#if defined(HAVE_NL_LANGINFO)
|
||||||
mem2str( fmt, nl_langinfo(D_T_FMT), DIM(fmt)-3 );
|
mem2str( fmt, nl_langinfo(D_T_FMT), DIM(fmt)-3 );
|
||||||
if( strstr( fmt, "%Z" ) == NULL )
|
if( strstr( fmt, "%Z" ) == NULL )
|
||||||
strcat( fmt, " %Z");
|
strcat( fmt, " %Z");
|
||||||
strftime( buffer, DIM(buffer)-1, fmt, tp );
|
strftime( buffer, DIM(buffer)-1, fmt, tp );
|
||||||
#else
|
#else
|
||||||
/* fixme: we should check whether the locale appends a " %Z"
|
/* fixme: we should check whether the locale appends a " %Z"
|
||||||
* These locales from glibc don't put the " %Z":
|
* These locales from glibc don't put the " %Z":
|
||||||
* fi_FI hr_HR ja_JP lt_LT lv_LV POSIX ru_RU ru_SU sv_FI sv_SE zh_CN
|
* fi_FI hr_HR ja_JP lt_LT lv_LV POSIX ru_RU ru_SU sv_FI sv_SE zh_CN
|
||||||
*/
|
*/
|
||||||
strftime( buffer, DIM(buffer)-1, "%c %Z", tp );
|
strftime( buffer, DIM(buffer)-1, "%c %Z", tp );
|
||||||
#endif
|
#endif
|
||||||
buffer[DIM(buffer)-1] = 0;
|
buffer[DIM(buffer)-1] = 0;
|
||||||
#else
|
#else
|
||||||
mem2str( buffer, asctime(tp), DIM(buffer) );
|
mem2str( buffer, asctime(tp), DIM(buffer) );
|
||||||
#endif
|
#endif
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,15 +26,15 @@
|
|||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#if defined(HAVE_MLOCK) || defined(HAVE_MMAP)
|
#if defined(HAVE_MLOCK) || defined(HAVE_MMAP)
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#ifdef USE_CAPABILITIES
|
#ifdef USE_CAPABILITIES
|
||||||
#include <sys/capability.h>
|
#include <sys/capability.h>
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_PLOCK
|
#ifdef HAVE_PLOCK
|
||||||
#include <sys/lock.h>
|
#include <sys/lock.h>
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
@ -43,11 +43,11 @@
|
|||||||
#include "i18n.h"
|
#include "i18n.h"
|
||||||
|
|
||||||
#if defined(MAP_ANON) && !defined(MAP_ANONYMOUS)
|
#if defined(MAP_ANON) && !defined(MAP_ANONYMOUS)
|
||||||
#define MAP_ANONYMOUS MAP_ANON
|
#define MAP_ANONYMOUS MAP_ANON
|
||||||
#endif
|
#endif
|
||||||
/* It seems that Slackware 7.1 does not know about EPERM */
|
/* It seems that Slackware 7.1 does not know about EPERM */
|
||||||
#if !defined(EPERM) && defined(ENOMEM)
|
#if !defined(EPERM) && defined(ENOMEM)
|
||||||
#define EPERM ENOMEM
|
#define EPERM ENOMEM
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
@ -95,7 +95,7 @@ print_warn(void)
|
|||||||
static void
|
static void
|
||||||
lock_pool( void *p, size_t n )
|
lock_pool( void *p, size_t n )
|
||||||
{
|
{
|
||||||
#if defined(USE_CAPABILITIES) && defined(HAVE_MLOCK)
|
#if defined(USE_CAPABILITIES) && defined(HAVE_MLOCK)
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
cap_set_proc( cap_from_text("cap_ipc_lock+ep") );
|
cap_set_proc( cap_from_text("cap_ipc_lock+ep") );
|
||||||
@ -106,30 +106,30 @@ lock_pool( void *p, size_t n )
|
|||||||
|
|
||||||
if( err ) {
|
if( err ) {
|
||||||
if( errno != EPERM
|
if( errno != EPERM
|
||||||
#ifdef EAGAIN /* OpenBSD returns this */
|
#ifdef EAGAIN /* OpenBSD returns this */
|
||||||
&& errno != EAGAIN
|
&& errno != EAGAIN
|
||||||
#endif
|
#endif
|
||||||
#ifdef ENOSYS /* Some SCOs return this (function not implemented) */
|
#ifdef ENOSYS /* Some SCOs return this (function not implemented) */
|
||||||
&& errno != ENOSYS
|
&& errno != ENOSYS
|
||||||
#endif
|
#endif
|
||||||
#ifdef ENOMEM /* Linux can return this */
|
#ifdef ENOMEM /* Linux can return this */
|
||||||
&& errno != ENOMEM
|
&& errno != ENOMEM
|
||||||
#endif
|
#endif
|
||||||
)
|
)
|
||||||
log_error("can't lock memory: %s\n", strerror(err));
|
log_error("can't lock memory: %s\n", strerror(err));
|
||||||
show_warning = 1;
|
show_warning = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif defined(HAVE_MLOCK)
|
#elif defined(HAVE_MLOCK)
|
||||||
uid_t uid;
|
uid_t uid;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
uid = getuid();
|
uid = getuid();
|
||||||
|
|
||||||
#ifdef HAVE_BROKEN_MLOCK
|
#ifdef HAVE_BROKEN_MLOCK
|
||||||
/* ick. but at least we get secured memory. about to lock
|
/* ick. but at least we get secured memory. about to lock
|
||||||
entire data segment. */
|
entire data segment. */
|
||||||
#ifdef HAVE_PLOCK
|
#ifdef HAVE_PLOCK
|
||||||
err = plock( DATLOCK );
|
err = plock( DATLOCK );
|
||||||
if( err && errno )
|
if( err && errno )
|
||||||
err = errno;
|
err = errno;
|
||||||
@ -143,12 +143,12 @@ lock_pool( void *p, size_t n )
|
|||||||
if( err && errno )
|
if( err && errno )
|
||||||
err = errno;
|
err = errno;
|
||||||
}
|
}
|
||||||
#endif /*!HAVE_PLOCK*/
|
#endif /*!HAVE_PLOCK*/
|
||||||
#else
|
#else
|
||||||
err = mlock( p, n );
|
err = mlock( p, n );
|
||||||
if( err && errno )
|
if( err && errno )
|
||||||
err = errno;
|
err = errno;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if( uid && !geteuid() ) {
|
if( uid && !geteuid() ) {
|
||||||
/* check that we really dropped the privs.
|
/* check that we really dropped the privs.
|
||||||
@ -159,38 +159,38 @@ lock_pool( void *p, size_t n )
|
|||||||
|
|
||||||
if( err ) {
|
if( err ) {
|
||||||
if( errno != EPERM
|
if( errno != EPERM
|
||||||
#ifdef EAGAIN /* OpenBSD returns this */
|
#ifdef EAGAIN /* OpenBSD returns this */
|
||||||
&& errno != EAGAIN
|
&& errno != EAGAIN
|
||||||
#endif
|
#endif
|
||||||
#ifdef ENOSYS /* Some SCOs return this (function not implemented) */
|
#ifdef ENOSYS /* Some SCOs return this (function not implemented) */
|
||||||
&& errno != ENOSYS
|
&& errno != ENOSYS
|
||||||
#endif
|
#endif
|
||||||
#ifdef ENOMEM /* Linux can return this */
|
#ifdef ENOMEM /* Linux can return this */
|
||||||
&& errno != ENOMEM
|
&& errno != ENOMEM
|
||||||
#endif
|
#endif
|
||||||
)
|
)
|
||||||
log_error("can't lock memory: %s\n", strerror(err));
|
log_error("can't lock memory: %s\n", strerror(err));
|
||||||
show_warning = 1;
|
show_warning = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif defined ( __QNX__ )
|
#elif defined ( __QNX__ )
|
||||||
/* QNX does not page at all, so the whole secure memory stuff does
|
/* QNX does not page at all, so the whole secure memory stuff does
|
||||||
* not make much sense. However it is still of use because it
|
* not make much sense. However it is still of use because it
|
||||||
* wipes out the memory on a free().
|
* wipes out the memory on a free().
|
||||||
* Therefore it is sufficient to suppress the warning
|
* Therefore it is sufficient to suppress the warning
|
||||||
*/
|
*/
|
||||||
#elif defined (HAVE_DOSISH_SYSTEM) || defined (__CYGWIN__)
|
#elif defined (HAVE_DOSISH_SYSTEM) || defined (__CYGWIN__)
|
||||||
/* It does not make sense to print such a warning, given the fact that
|
/* It does not make sense to print such a warning, given the fact that
|
||||||
* this whole Windows !@#$% and their user base are inherently insecure
|
* this whole Windows !@#$% and their user base are inherently insecure
|
||||||
*/
|
*/
|
||||||
#elif defined (__riscos__)
|
#elif defined (__riscos__)
|
||||||
/* no virtual memory on RISC OS, so no pages are swapped to disc,
|
/* no virtual memory on RISC OS, so no pages are swapped to disc,
|
||||||
* besides we don't have mmap, so we don't use it! ;-)
|
* besides we don't have mmap, so we don't use it! ;-)
|
||||||
* But don't complain, as explained above.
|
* But don't complain, as explained above.
|
||||||
*/
|
*/
|
||||||
#else
|
#else
|
||||||
log_info("Please note that you don't have secure memory on this system\n");
|
log_info("Please note that you don't have secure memory on this system\n");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -204,18 +204,18 @@ init_pool( size_t n)
|
|||||||
if( disable_secmem )
|
if( disable_secmem )
|
||||||
log_bug("secure memory is disabled");
|
log_bug("secure memory is disabled");
|
||||||
|
|
||||||
#ifdef HAVE_GETPAGESIZE
|
#ifdef HAVE_GETPAGESIZE
|
||||||
pgsize = getpagesize();
|
pgsize = getpagesize();
|
||||||
#else
|
#else
|
||||||
pgsize = 4096;
|
pgsize = 4096;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_MMAP
|
#ifdef HAVE_MMAP
|
||||||
poolsize = (poolsize + pgsize -1 ) & ~(pgsize-1);
|
poolsize = (poolsize + pgsize -1 ) & ~(pgsize-1);
|
||||||
#ifdef MAP_ANONYMOUS
|
#ifdef MAP_ANONYMOUS
|
||||||
pool = mmap( 0, poolsize, PROT_READ|PROT_WRITE,
|
pool = mmap( 0, poolsize, PROT_READ|PROT_WRITE,
|
||||||
MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
|
MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
|
||||||
#else /* map /dev/zero instead */
|
#else /* map /dev/zero instead */
|
||||||
{ int fd;
|
{ int fd;
|
||||||
|
|
||||||
fd = open("/dev/zero", O_RDWR);
|
fd = open("/dev/zero", O_RDWR);
|
||||||
@ -228,7 +228,7 @@ init_pool( size_t n)
|
|||||||
MAP_PRIVATE, fd, 0);
|
MAP_PRIVATE, fd, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if( pool == (void*)-1 )
|
if( pool == (void*)-1 )
|
||||||
log_info("can't mmap pool of %u bytes: %s - using malloc\n",
|
log_info("can't mmap pool of %u bytes: %s - using malloc\n",
|
||||||
(unsigned)poolsize, strerror(errno));
|
(unsigned)poolsize, strerror(errno));
|
||||||
@ -237,7 +237,7 @@ init_pool( size_t n)
|
|||||||
pool_okay = 1;
|
pool_okay = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
if( !pool_okay ) {
|
if( !pool_okay ) {
|
||||||
pool = malloc( poolsize );
|
pool = malloc( poolsize );
|
||||||
if( !pool )
|
if( !pool )
|
||||||
@ -288,11 +288,11 @@ secmem_init( size_t n )
|
|||||||
{
|
{
|
||||||
if( !n ) {
|
if( !n ) {
|
||||||
#ifndef __riscos__
|
#ifndef __riscos__
|
||||||
#ifdef USE_CAPABILITIES
|
#ifdef USE_CAPABILITIES
|
||||||
/* drop all capabilities */
|
/* drop all capabilities */
|
||||||
cap_set_proc( cap_from_text("all-eip") );
|
cap_set_proc( cap_from_text("all-eip") );
|
||||||
|
|
||||||
#elif !defined(HAVE_DOSISH_SYSTEM)
|
#elif !defined(HAVE_DOSISH_SYSTEM)
|
||||||
uid_t uid;
|
uid_t uid;
|
||||||
|
|
||||||
disable_secmem=1;
|
disable_secmem=1;
|
||||||
@ -301,7 +301,7 @@ secmem_init( size_t n )
|
|||||||
if( setuid( uid ) || getuid() != geteuid() || !setuid(0) )
|
if( setuid( uid ) || getuid() != geteuid() || !setuid(0) )
|
||||||
log_fatal("failed to drop setuid\n" );
|
log_fatal("failed to drop setuid\n" );
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#endif /* !__riscos__ */
|
#endif /* !__riscos__ */
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -443,10 +443,10 @@ secmem_term()
|
|||||||
wipememory2( pool, 0xaa, poolsize);
|
wipememory2( pool, 0xaa, poolsize);
|
||||||
wipememory2( pool, 0x55, poolsize);
|
wipememory2( pool, 0x55, poolsize);
|
||||||
wipememory2( pool, 0x00, poolsize);
|
wipememory2( pool, 0x00, poolsize);
|
||||||
#ifdef HAVE_MMAP
|
#ifdef HAVE_MMAP
|
||||||
if( pool_is_mmapped )
|
if( pool_is_mmapped )
|
||||||
munmap( pool, poolsize );
|
munmap( pool, poolsize );
|
||||||
#endif
|
#endif
|
||||||
pool = NULL;
|
pool = NULL;
|
||||||
pool_okay = 0;
|
pool_okay = 0;
|
||||||
poolsize=0;
|
poolsize=0;
|
||||||
@ -465,4 +465,3 @@ secmem_dump_stats()
|
|||||||
cur_alloced, max_alloced, cur_blocks, max_blocks,
|
cur_alloced, max_alloced, cur_blocks, max_blocks,
|
||||||
(ulong)poollen, (ulong)poolsize );
|
(ulong)poollen, (ulong)poolsize );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -235,11 +235,11 @@ set_gettext_file( const char *filename )
|
|||||||
|
|
||||||
if( filename && *filename ) {
|
if( filename && *filename ) {
|
||||||
if( filename[0] == '/'
|
if( filename[0] == '/'
|
||||||
#ifdef HAVE_DRIVE_LETTERS
|
#ifdef HAVE_DRIVE_LETTERS
|
||||||
|| ( isalpha(filename[0])
|
|| ( isalpha(filename[0])
|
||||||
&& filename[1] == ':'
|
&& filename[1] == ':'
|
||||||
&& (filename[2] == '/' || filename[2] == '\\') )
|
&& (filename[2] == '/' || filename[2] == '\\') )
|
||||||
#endif
|
#endif
|
||||||
) {
|
) {
|
||||||
/* absolute path - use it as is */
|
/* absolute path - use it as is */
|
||||||
domain = load_domain( filename );
|
domain = load_domain( filename );
|
||||||
|
67
util/ttyio.c
67
util/ttyio.c
@ -25,23 +25,23 @@
|
|||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#ifdef HAVE_TCGETATTR
|
#ifdef HAVE_TCGETATTR
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
#else
|
#else
|
||||||
#ifdef HAVE_TERMIO_H
|
#ifdef HAVE_TERMIO_H
|
||||||
/* simulate termios with termio */
|
/* simulate termios with termio */
|
||||||
#include <termio.h>
|
#include <termio.h>
|
||||||
#define termios termio
|
#define termios termio
|
||||||
#define tcsetattr ioctl
|
#define tcsetattr ioctl
|
||||||
#define TCSAFLUSH TCSETAF
|
#define TCSAFLUSH TCSETAF
|
||||||
#define tcgetattr(A,B) ioctl(A,TCGETA,B)
|
#define tcgetattr(A,B) ioctl(A,TCGETA,B)
|
||||||
#define HAVE_TCGETATTR
|
#define HAVE_TCGETATTR
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#ifdef __MINGW32__ /* use the odd Win32 functions */
|
#ifdef __MINGW32__ /* use the odd Win32 functions */
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#ifdef HAVE_TCGETATTR
|
#ifdef HAVE_TCGETATTR
|
||||||
#error mingw32 and termios
|
#error mingw32 and termios
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
@ -194,7 +194,7 @@ tty_printf( const char *fmt, ... )
|
|||||||
init_ttyfp();
|
init_ttyfp();
|
||||||
|
|
||||||
va_start( arg_ptr, fmt ) ;
|
va_start( arg_ptr, fmt ) ;
|
||||||
#ifdef __MINGW32__
|
#ifdef __MINGW32__
|
||||||
{
|
{
|
||||||
char *buf = NULL;
|
char *buf = NULL;
|
||||||
int n;
|
int n;
|
||||||
@ -211,10 +211,10 @@ tty_printf( const char *fmt, ... )
|
|||||||
last_prompt_len += n;
|
last_prompt_len += n;
|
||||||
m_free (buf);
|
m_free (buf);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
last_prompt_len += vfprintf(ttyfp,fmt,arg_ptr) ;
|
last_prompt_len += vfprintf(ttyfp,fmt,arg_ptr) ;
|
||||||
fflush(ttyfp);
|
fflush(ttyfp);
|
||||||
#endif
|
#endif
|
||||||
va_end(arg_ptr);
|
va_end(arg_ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -231,7 +231,7 @@ tty_print_string( byte *p, size_t n )
|
|||||||
if( !initialized )
|
if( !initialized )
|
||||||
init_ttyfp();
|
init_ttyfp();
|
||||||
|
|
||||||
#ifdef __MINGW32__
|
#ifdef __MINGW32__
|
||||||
/* not so effective, change it if you want */
|
/* not so effective, change it if you want */
|
||||||
for( ; n; n--, p++ )
|
for( ; n; n--, p++ )
|
||||||
if( iscntrl( *p ) ) {
|
if( iscntrl( *p ) ) {
|
||||||
@ -244,7 +244,7 @@ tty_print_string( byte *p, size_t n )
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
tty_printf("%c", *p);
|
tty_printf("%c", *p);
|
||||||
#else
|
#else
|
||||||
for( ; n; n--, p++ )
|
for( ; n; n--, p++ )
|
||||||
if( iscntrl( *p ) ) {
|
if( iscntrl( *p ) ) {
|
||||||
putc('\\', ttyfp);
|
putc('\\', ttyfp);
|
||||||
@ -257,7 +257,7 @@ tty_print_string( byte *p, size_t n )
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
putc(*p, ttyfp);
|
putc(*p, ttyfp);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -302,9 +302,9 @@ static char *
|
|||||||
do_get( const char *prompt, int hidden )
|
do_get( const char *prompt, int hidden )
|
||||||
{
|
{
|
||||||
char *buf;
|
char *buf;
|
||||||
#ifndef __riscos__
|
#ifndef __riscos__
|
||||||
byte cbuf[1];
|
byte cbuf[1];
|
||||||
#endif
|
#endif
|
||||||
int c, n, i;
|
int c, n, i;
|
||||||
|
|
||||||
if( batchmode ) {
|
if( batchmode ) {
|
||||||
@ -325,7 +325,7 @@ do_get( const char *prompt, int hidden )
|
|||||||
buf = m_alloc(n=50);
|
buf = m_alloc(n=50);
|
||||||
i = 0;
|
i = 0;
|
||||||
|
|
||||||
#ifdef __MINGW32__ /* windoze version */
|
#ifdef __MINGW32__ /* windoze version */
|
||||||
if( hidden )
|
if( hidden )
|
||||||
SetConsoleMode(con.in, HID_INPMODE );
|
SetConsoleMode(con.in, HID_INPMODE );
|
||||||
|
|
||||||
@ -359,7 +359,7 @@ do_get( const char *prompt, int hidden )
|
|||||||
if( hidden )
|
if( hidden )
|
||||||
SetConsoleMode(con.in, DEF_INPMODE );
|
SetConsoleMode(con.in, DEF_INPMODE );
|
||||||
|
|
||||||
#elif defined(__riscos__)
|
#elif defined(__riscos__)
|
||||||
do {
|
do {
|
||||||
c = riscos_getchar();
|
c = riscos_getchar();
|
||||||
if (c == 0xa || c == 0xd) { /* Return || Enter */
|
if (c == 0xa || c == 0xd) { /* Return || Enter */
|
||||||
@ -399,9 +399,9 @@ do_get( const char *prompt, int hidden )
|
|||||||
}
|
}
|
||||||
} while (c != '\n');
|
} while (c != '\n');
|
||||||
i = (i>0) ? i-1 : 0;
|
i = (i>0) ? i-1 : 0;
|
||||||
#else /* unix version */
|
#else /* unix version */
|
||||||
if( hidden ) {
|
if( hidden ) {
|
||||||
#ifdef HAVE_TCGETATTR
|
#ifdef HAVE_TCGETATTR
|
||||||
struct termios term;
|
struct termios term;
|
||||||
|
|
||||||
if( tcgetattr(fileno(ttyfp), &termsave) )
|
if( tcgetattr(fileno(ttyfp), &termsave) )
|
||||||
@ -411,7 +411,7 @@ do_get( const char *prompt, int hidden )
|
|||||||
term.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL);
|
term.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL);
|
||||||
if( tcsetattr( fileno(ttyfp), TCSAFLUSH, &term ) )
|
if( tcsetattr( fileno(ttyfp), TCSAFLUSH, &term ) )
|
||||||
log_fatal("tcsetattr() failed: %s\n", strerror(errno) );
|
log_fatal("tcsetattr() failed: %s\n", strerror(errno) );
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/* fixme: How can we avoid that the \n is echoed w/o disabling
|
/* fixme: How can we avoid that the \n is echoed w/o disabling
|
||||||
@ -442,13 +442,13 @@ do_get( const char *prompt, int hidden )
|
|||||||
|
|
||||||
|
|
||||||
if( hidden ) {
|
if( hidden ) {
|
||||||
#ifdef HAVE_TCGETATTR
|
#ifdef HAVE_TCGETATTR
|
||||||
if( tcsetattr(fileno(ttyfp), TCSAFLUSH, &termsave) )
|
if( tcsetattr(fileno(ttyfp), TCSAFLUSH, &termsave) )
|
||||||
log_error("tcsetattr() failed: %s\n", strerror(errno) );
|
log_error("tcsetattr() failed: %s\n", strerror(errno) );
|
||||||
restore_termios = 0;
|
restore_termios = 0;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#endif /* end unix version */
|
#endif /* end unix version */
|
||||||
buf[i] = 0;
|
buf[i] = 0;
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
@ -480,9 +480,9 @@ tty_kill_prompt()
|
|||||||
last_prompt_len = 0;
|
last_prompt_len = 0;
|
||||||
if( !last_prompt_len )
|
if( !last_prompt_len )
|
||||||
return;
|
return;
|
||||||
#ifdef __MINGW32__
|
#ifdef __MINGW32__
|
||||||
tty_printf("\r%*s\r", last_prompt_len, "");
|
tty_printf("\r%*s\r", last_prompt_len, "");
|
||||||
#else
|
#else
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
putc('\r', ttyfp);
|
putc('\r', ttyfp);
|
||||||
@ -491,7 +491,7 @@ tty_kill_prompt()
|
|||||||
putc('\r', ttyfp);
|
putc('\r', ttyfp);
|
||||||
fflush(ttyfp);
|
fflush(ttyfp);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
last_prompt_len = 0;
|
last_prompt_len = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -506,4 +506,3 @@ tty_get_answer_is_yes( const char *prompt )
|
|||||||
m_free(p);
|
m_free(p);
|
||||||
return yes;
|
return yes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user