mirror of
https://github.com/proxytunnel/proxytunnel.git
synced 2026-01-23 02:34:59 +00:00
Fosdem changes
git-svn-id: https://proxytunnel.svn.sourceforge.net/svnroot/proxytunnel/trunk/proxytunnel@120 bc163920-b10d-0410-b2c5-a5491ca2ceef
This commit is contained in:
parent
04a85a5e8b
commit
7f7f772444
15 changed files with 344 additions and 428 deletions
19
LICENSE.txt
19
LICENSE.txt
|
|
@ -1,6 +1,6 @@
|
|||
Proxytunnel is covered by the GNU GPL included below. Most of the code
|
||||
was written by Jos Visser and Mark Janssen, the snippet of base64 code
|
||||
came from mutt, and was written by: Brendan Cully <brendan@kublai.com>
|
||||
Proxytunnel is covered by the GNU GPL, version 2, included below. Most of
|
||||
the code was written by Jos Visser and Mark Janssen, the snippet of base64
|
||||
code came from mutt, and was written by: Brendan Cully <brendan@kublai.com>
|
||||
and came with the following copyright notice:
|
||||
|
||||
/*
|
||||
|
|
@ -15,10 +15,12 @@ and came with the following copyright notice:
|
|||
* redistribution of source.
|
||||
*/
|
||||
|
||||
The setproctitle code came from sendmail, and comes with the following
|
||||
license-text (it's a 4-clause BSD license)
|
||||
The setproctitle code (including strlcat/strlcpy) came from openssh, and
|
||||
comes with the following license-text (it's a 3-clause BSD license)
|
||||
|
||||
/* Based on conf.c from UCB sendmail 8.8.8 */
|
||||
/*
|
||||
* Copyright 2003 Damien Miller
|
||||
* Copyright (c) 1983, 1995-1997 Eric P. Allman
|
||||
* Copyright (c) 1988, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
|
|
@ -31,11 +33,7 @@ license-text (it's a 4-clause BSD license)
|
|||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* 3. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
|
|
@ -53,6 +51,7 @@ license-text (it's a 4-clause BSD license)
|
|||
*/
|
||||
|
||||
|
||||
|
||||
Other contributors can be found in the CREDITS file
|
||||
|
||||
|
||||
|
|
|
|||
27
Makefile
27
Makefile
|
|
@ -2,10 +2,27 @@
|
|||
#
|
||||
# Please uncomment the appropriate settings
|
||||
|
||||
CC ?= gcc
|
||||
CFLAGS ?= -Wall -O2 -g
|
||||
CFLAGS += -DHAVE_GETOPT_LONG -DUSE_SSL
|
||||
CFLAGS += -DSETPROCTITLE -DSPT_TYPE=1
|
||||
CC ?= cc
|
||||
CFLAGS ?= -Wall -O2 -ggdb
|
||||
CFLAGS += -DHAVE_GETOPT_LONG # Comment on non-gnu systems
|
||||
CFLAGS += -DUSE_SSL # Comment if you don't have/want ssl
|
||||
# Most systems
|
||||
CFLAGS += -DSETPROCTITLE -DSPT_TYPE=2
|
||||
|
||||
# System dependant blocks... if your system is listed below, uncomment
|
||||
# the relevant lines
|
||||
|
||||
# OpenBSD
|
||||
#CFLAGS += -DHAVE_SYS_PSTAT_H
|
||||
# DARWIN
|
||||
#CFLAGS += -DDARWIN
|
||||
# CYGWIN
|
||||
#CFLAGS += -DCYGWIN
|
||||
# SOLARIS
|
||||
#LDFLAGS += -lsocket -lnsl
|
||||
#LDFLAGS += -L/usr/local/ssl/lib # Path to your SSL lib dir
|
||||
|
||||
# END system dependant block
|
||||
|
||||
SSL_LIBS := $(shell pkg-config --libs libssl 2>/dev/null)
|
||||
ifeq ($(SSL_LIBS),)
|
||||
|
|
@ -23,6 +40,8 @@ MANDIR = $(PREFIX)/man/man1
|
|||
PROGNAME = proxytunnel
|
||||
OBJ = proxytunnel.o \
|
||||
base64.o \
|
||||
strlcpy.o \
|
||||
strlcat.o \
|
||||
setproctitle.o \
|
||||
io.o \
|
||||
http.o \
|
||||
|
|
|
|||
|
|
@ -1,33 +0,0 @@
|
|||
# Makefile for proxytunnel
|
||||
#
|
||||
# Please uncomment the appropriate settings
|
||||
|
||||
CC ?= gcc
|
||||
CFLAGS ?= -Wall -DHAVE_GETOPT_LONG -DCYGWIN
|
||||
CFLAGS += -DUSE_SSL
|
||||
CFLAGS += -DSETPROCTITLE
|
||||
LDFLAGS ?= -lssl -lcrypto
|
||||
INSTALLPATH ?= $(DESTDIR)/usr/local/bin
|
||||
MANPATH ?= $(DESTDIR)/usr/local/man/man1
|
||||
|
||||
PROGNAME = proxytunnel
|
||||
OBJ = proxytunnel.o \
|
||||
base64.o \
|
||||
io.o \
|
||||
http.o \
|
||||
ntlm.o \
|
||||
basicauth.o \
|
||||
messages.o \
|
||||
setproctitle.o \
|
||||
cmdline.o
|
||||
|
||||
proxytunnel: $(OBJ)
|
||||
$(CC) -o $(PROGNAME) -static $(OBJ) $(LDFLAGS)
|
||||
|
||||
clean:
|
||||
@rm -f $(PROGNAME) $(OBJ)
|
||||
|
||||
install:
|
||||
mkdir -p $(INSTALLPATH)
|
||||
install -g root -m755 -o root $(PROGNAME) $(INSTALLPATH)/$(PROGNAME)
|
||||
install -g root -m644 -o root debian/$(PROGNAME).1 $(MANPATH)/$(PROGNAME).1
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
# Makefile for proxytunnel
|
||||
#
|
||||
# Please uncomment the appropriate settings
|
||||
|
||||
CC ?= gcc
|
||||
CFLAGS ?= -Wall -DDARWIN -DHAVE_GETOPT_LONG
|
||||
CFLAGS += -DUSE_SSL
|
||||
CFLAGS += -DSETPROCTITLE
|
||||
LDFLAGS ?= -lcrypto -lssl
|
||||
INSTALLPATH ?= $(DESTDIR)/usr/local/bin
|
||||
MANPATH ?= $(DESTDIR)/usr/local/man/man1
|
||||
|
||||
PROGNAME = proxytunnel
|
||||
OBJ = proxytunnel.o \
|
||||
base64.o \
|
||||
io.o \
|
||||
ntlm.o \
|
||||
http.o \
|
||||
basicauth.o \
|
||||
messages.o \
|
||||
cmdline.o
|
||||
|
||||
proxytunnel: $(OBJ)
|
||||
$(CC) -o $(PROGNAME) $(OBJ) $(LDFLAGS)
|
||||
|
||||
clean:
|
||||
@rm -f $(PROGNAME) $(OBJ)
|
||||
|
||||
install:
|
||||
mkdir -p $(INSTALLPATH)
|
||||
install -g root -m755 -o root $(PROGNAME) $(INSTALLPATH)/$(PROGNAME)
|
||||
install -g root -m644 -o root debian/$(PROGNAME).1 $(MANPATH)/$(PROGNAME).1
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
# Makefile for proxytunnel
|
||||
#
|
||||
# Please uncomment the appropriate settings
|
||||
|
||||
CC ?= cc
|
||||
CFLAGS ?=
|
||||
CFLAGS += -DUSE_SSL
|
||||
CFLAGS += -DPROCTITLE
|
||||
LDFLAGS += -lssl -lcrypto
|
||||
INSTALLPATH ?= $(DESTDIR)/usr/bin
|
||||
|
||||
PROGNAME = proxytunnel
|
||||
OBJ = proxytunnel.o \
|
||||
base64.o \
|
||||
io.o \
|
||||
setproctitle.o \
|
||||
http.o \
|
||||
ntlm.o \
|
||||
basicauth.o \
|
||||
messages.o \
|
||||
cmdline.o
|
||||
|
||||
proxytunnel: $(OBJ)
|
||||
$(CC) -o $(PROGNAME) $(OBJ) $(LDFLAGS)
|
||||
|
||||
clean:
|
||||
@rm -f $(PROGNAME) $(OBJ)
|
||||
|
||||
install:
|
||||
mkdir -p $(INSTALLPATH)
|
||||
install -g root -m755 -o root $(PROGNAME) $(INSTALLPATH)/$(PROGNAME)
|
||||
|
|
@ -1,38 +0,0 @@
|
|||
# Makefile for proxytunnel
|
||||
#
|
||||
# Please uncomment the appropriate settings
|
||||
|
||||
CC ?= gcc
|
||||
CFLAGS ?= -Wall -O2
|
||||
CFLAGS += -DUSE_SSL
|
||||
CFLAGS += -DSETPROCTITLE
|
||||
LDFLAGS += -lssl -lcrypto
|
||||
|
||||
PREFIX =/usr/local
|
||||
BINDIR = $(PREFIX)/bin
|
||||
DATADIR = $(PREFIX)/share
|
||||
MANDIR = $(DATADIR)/man
|
||||
|
||||
DESTDIR =
|
||||
|
||||
PROGNAME = proxytunnel
|
||||
OBJ = proxytunnel.o \
|
||||
base64.o \
|
||||
setproctitle.o \
|
||||
io.o \
|
||||
http.o \
|
||||
basicauth.o \
|
||||
messages.o \
|
||||
cmdline.o \
|
||||
ntlm.o
|
||||
|
||||
proxytunnel: $(OBJ)
|
||||
$(CC) -o $(PROGNAME) $(CFLAGS) $(OBJ) $(LDFLAGS)
|
||||
|
||||
clean:
|
||||
@rm -f $(PROGNAME) $(OBJ)
|
||||
|
||||
install:
|
||||
mkdir -p $(INSTALLPATH) $(INSTALLMANPATH)
|
||||
install -D -m755 $(PROGNAME) $(DESTDIR)$(BINDIR)/$(PROGNAME)
|
||||
install -D -m644 debian/$(PROGNAME).1 $(DESTDIR)$(MANDIR))/$(PROGNAME).1
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
# Makefile for proxytunnel
|
||||
#
|
||||
# Please uncomment the appropriate settings
|
||||
|
||||
CC ?= gcc
|
||||
CFLAGS ?= -Wall -I/usr/local/ssl/include
|
||||
CFLAGS += -DUSE_SSL
|
||||
CFLAGS += -DSETPROCTITLE
|
||||
LDFLAGS = -lsocket -lnsl -L/usr/local/ssl/lib -lssl -lcrypto
|
||||
INSTALLPATH = /usr/local/bin
|
||||
|
||||
PROGNAME = proxytunnel
|
||||
OBJ = proxytunnel.o \
|
||||
base64.o \
|
||||
io.o \
|
||||
http.o \
|
||||
ntlm.o \
|
||||
basicauth.o \
|
||||
setproctitle.o \
|
||||
messages.o \
|
||||
cmdline.o
|
||||
|
||||
proxytunnel: $(OBJ)
|
||||
$(CC) -o $(PROGNAME) $(OBJ) $(LDFLAGS)
|
||||
|
||||
clean:
|
||||
@rm -f $(PROGNAME) $(OBJ)
|
||||
|
||||
install:
|
||||
mkdir -p $(INSTALLPATH)
|
||||
install -g root -m755 -o root $(PROGNAME) $(INSTALLPATH)/$(PROGNAME)
|
||||
15
cmdline.c
15
cmdline.c
|
|
@ -32,7 +32,6 @@
|
|||
|
||||
#include "cmdline.h"
|
||||
|
||||
|
||||
void
|
||||
cmdline_parser_print_version (void)
|
||||
{
|
||||
|
|
@ -404,10 +403,11 @@ if (args_info->proxy_given )
|
|||
char * phost;
|
||||
int pport;
|
||||
|
||||
phost = malloc( 51 );
|
||||
phost = malloc( 50+1 );
|
||||
|
||||
/* fprintf( stderr, "%s: proxyhost (pre parse) given, it is: '%s'\n", PACKAGE, args_info->proxy_arg ); */
|
||||
r = sscanf( args_info->proxy_arg, "%50[^:]:%d", phost, &pport );
|
||||
//fprintf( stderr, "%s: proxyhost (pre parse) given, it is: '%s'\n", PACKAGE, args_info->proxy_arg );
|
||||
|
||||
r = sscanf( args_info->proxy_arg, "%50[^:]:%5u", phost, &pport );
|
||||
if ( r == 2 )
|
||||
{
|
||||
args_info->proxyhost_arg = phost;
|
||||
|
|
@ -415,7 +415,12 @@ if (args_info->proxy_given )
|
|||
args_info->proxyhost_given = 1;
|
||||
args_info->proxyport_given = 1;
|
||||
}
|
||||
/* fprintf( stderr, "%s: proxyhost (post parse) is '%s':'%d'\n", PACKAGE, args_info->proxyhost_arg, args_info->proxyport_arg ); */
|
||||
else
|
||||
{
|
||||
message( "parse_cmdline: couln't find your proxy hostname/ip\n" );
|
||||
missing_required_options++;
|
||||
}
|
||||
//message( "%s: proxyhost (post parse) is '%s':'%d'\n", PACKAGE, args_info->proxyhost_arg, args_info->proxyport_arg );
|
||||
}
|
||||
|
||||
if ( missing_required_options )
|
||||
|
|
|
|||
3
http.c
3
http.c
|
|
@ -161,7 +161,8 @@ void proxy_protocol()
|
|||
*/
|
||||
analyze_HTTP();
|
||||
|
||||
if (args_info.remproxy_given ) {
|
||||
if (args_info.remproxy_given )
|
||||
{
|
||||
/*
|
||||
* Clean buffer for next analysis
|
||||
*/
|
||||
|
|
|
|||
25
io.c
25
io.c
|
|
@ -295,28 +295,5 @@ void cpio()
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Close all files we deal with
|
||||
*/
|
||||
close( read_fd );
|
||||
#ifdef USE_SSL
|
||||
if( args_info.encrypt_flag )
|
||||
{
|
||||
SSL_free (ssl);
|
||||
SSL_CTX_free (ctx);
|
||||
}
|
||||
#else
|
||||
close( sd );
|
||||
#endif
|
||||
|
||||
if( read_fd != write_fd ) /* When not running from inetd */
|
||||
{
|
||||
close( write_fd );
|
||||
}
|
||||
|
||||
if( args_info.verbose_flag )
|
||||
{
|
||||
message( "Tunnel closed\n" );
|
||||
}
|
||||
closeall();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -61,14 +61,8 @@ SSL_METHOD *meth;
|
|||
*/
|
||||
void signal_handler( int signal )
|
||||
{
|
||||
close(0);
|
||||
close(1);
|
||||
|
||||
if ( sd != 0 )
|
||||
close( sd );
|
||||
|
||||
message( "Tunnel closed on signal %d\n", signal );
|
||||
exit(1);
|
||||
closeall();
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -157,13 +151,46 @@ void do_ssl()
|
|||
/*
|
||||
* Leave a goodbye message
|
||||
*/
|
||||
void einde() {
|
||||
void closeall() {
|
||||
message( "In closeall\n");
|
||||
|
||||
if( args_info.verbose_flag )
|
||||
{
|
||||
message( "Tunnel closed\n" );
|
||||
}
|
||||
|
||||
#ifdef CYGWIN
|
||||
message( "Goodbye" );
|
||||
#else
|
||||
syslog(LOG_NOTICE,"Goodbye...");
|
||||
closelog();
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Close all files we deal with
|
||||
*/
|
||||
close(0);
|
||||
close(1);
|
||||
|
||||
if ( sd != 0 )
|
||||
close( sd );
|
||||
|
||||
|
||||
#ifdef USE_SSL
|
||||
if( args_info.encrypt_flag )
|
||||
{
|
||||
SSL_free (ssl);
|
||||
SSL_CTX_free (ctx);
|
||||
}
|
||||
#else
|
||||
close( sd );
|
||||
#endif
|
||||
|
||||
if( read_fd != write_fd ) /* When not running from inetd */
|
||||
{
|
||||
close( write_fd );
|
||||
}
|
||||
close( read_fd );
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -200,6 +227,14 @@ void do_daemon()
|
|||
signal(SIGHUP,SIG_IGN);
|
||||
signal(SIGCHLD,SIG_IGN);
|
||||
|
||||
#ifdef SETPROCTITLE
|
||||
if( args_info.proctitle_given )
|
||||
setproctitle( "%s [daemon]\0", args_info.proctitle_arg );
|
||||
#else
|
||||
if( args_info.proctitle_given )
|
||||
message( "Setting process-title is not supported in this build\n");
|
||||
#endif
|
||||
|
||||
/* For the moment, turn of forking into background on the cygwin platform
|
||||
* so users can run it in a command window and ctrl-c it to cancel.
|
||||
* Also so we can put logging there, since there's nog syslog on cygwin (AFAIK)
|
||||
|
|
@ -220,7 +255,7 @@ void do_daemon()
|
|||
openlog( program_name, LOG_CONS|LOG_PID,LOG_DAEMON );
|
||||
i_am_daemon = 1;
|
||||
#endif /* CYGWIN */
|
||||
atexit( einde );
|
||||
atexit( closeall );
|
||||
listen( listen_sd, 5 );
|
||||
|
||||
while (1==1)
|
||||
|
|
@ -261,6 +296,18 @@ void do_daemon()
|
|||
proxy_protocol();
|
||||
proxy_protocol();
|
||||
}
|
||||
|
||||
#ifdef USE_SSL
|
||||
if( args_info.encrypt_flag )
|
||||
do_ssl();
|
||||
#endif
|
||||
#ifdef SETPROCTITLE
|
||||
if( args_info.proctitle_given )
|
||||
setproctitle( "%s [child]\0", args_info.proctitle_arg );
|
||||
#else
|
||||
if( args_info.proctitle_given )
|
||||
message( "Setting process-title is not supported in this build\n");
|
||||
#endif
|
||||
cpio();
|
||||
exit( 0 );
|
||||
}
|
||||
|
|
@ -283,7 +330,7 @@ void do_daemon()
|
|||
/*
|
||||
* We begin at the beginning
|
||||
*/
|
||||
int main( int argc, char *argv[], char *envp[] )
|
||||
int main( int argc, char *argv[] )
|
||||
{
|
||||
program_name = argv[0];
|
||||
|
||||
|
|
@ -293,7 +340,7 @@ int main( int argc, char *argv[], char *envp[] )
|
|||
|
||||
cmdline_parser( argc, argv, &args_info );
|
||||
#ifdef SETPROCTITLE
|
||||
initsetproctitle( argc, argv, envp );
|
||||
initsetproctitle( argc, argv );
|
||||
#endif
|
||||
|
||||
/*
|
||||
|
|
@ -355,7 +402,7 @@ int main( int argc, char *argv[], char *envp[] )
|
|||
#endif
|
||||
#ifdef SETPROCTITLE
|
||||
if( args_info.proctitle_given )
|
||||
setproctitle( "%s\0", args_info.proctitle_arg );
|
||||
setproctitle( "%s [cpio]\0", args_info.proctitle_arg );
|
||||
#else
|
||||
if( args_info.proctitle_given )
|
||||
message( "Setting process-title is not supported in this build\n");
|
||||
|
|
|
|||
|
|
@ -35,11 +35,13 @@ void tunnel_connect();
|
|||
void analyze_HTTP();
|
||||
void proxy_protocol();
|
||||
void do_ssl();
|
||||
void einde();
|
||||
void closeall();
|
||||
void do_daemon();
|
||||
int initsetproctitle(int argc, char *argv[], char* envp[]);
|
||||
void initsetproctitle(int argc, char *argv[]);
|
||||
void setproctitle(const char *fmt, ...);
|
||||
int main( int argc, char *argv[], char *envp[] );
|
||||
size_t strlcat(char *dst, const char *src, size_t siz);
|
||||
size_t strlcpy(char *dst, const char *src, size_t siz);
|
||||
int main( int argc, char *argv[] );
|
||||
|
||||
/* Globals */
|
||||
int sd; /* The tunnel's socket descriptor */
|
||||
|
|
|
|||
299
setproctitle.c
299
setproctitle.c
|
|
@ -1,4 +1,7 @@
|
|||
/* Based on conf.c from UCB sendmail 8.8.8 */
|
||||
|
||||
/*
|
||||
* Copyright 2003 Damien Miller
|
||||
* Copyright (c) 1983, 1995-1997 Eric P. Allman
|
||||
* Copyright (c) 1988, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
|
|
@ -11,11 +14,7 @@
|
|||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* 3. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
|
|
@ -32,242 +31,134 @@
|
|||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifdef SETPROCTITLE
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/param.h>
|
||||
|
||||
#include <stdarg.h>
|
||||
#include "proxytunnel.h"
|
||||
|
||||
#define VA_LOCAL_DECL va_list ap;
|
||||
#define VA_START(f) va_start(ap, f)
|
||||
#define VA_END va_end(ap)
|
||||
|
||||
/* return number of bytes left in a buffer */
|
||||
#define SPACELEFT(buf, ptr) (sizeof buf - ((ptr) - buf))
|
||||
|
||||
/*
|
||||
** SETPROCTITLE -- set process title for ps
|
||||
**
|
||||
** Parameters:
|
||||
** fmt -- a printf style format string.
|
||||
** a, b, c -- possible parameters to fmt.
|
||||
**
|
||||
** Returns:
|
||||
** none.
|
||||
**
|
||||
** Side Effects:
|
||||
** Clobbers argv of our main procedure so ps(1) will
|
||||
** display the title.
|
||||
*/
|
||||
#ifndef HAVE_SETPROCTITLE
|
||||
|
||||
#define SPT_NONE 0 /* don't use it at all */
|
||||
#define SPT_REUSEARGV 1 /* cover argv with title information */
|
||||
#define SPT_BUILTIN 2 /* use libc builtin */
|
||||
#define SPT_PSTAT 3 /* use pstat(PSTAT_SETCMD, ...) */
|
||||
#define SPT_PSSTRINGS 4 /* use PS_STRINGS->... */
|
||||
#define SPT_SYSMIPS 5 /* use sysmips() supported by NEWS-OS 6 */
|
||||
#define SPT_SCO 6 /* write kernel u. area */
|
||||
#define SPT_CHANGEARGV 7 /* write our own strings into argv[] */
|
||||
#define SPT_PSTAT 1 /* use pstat(PSTAT_SETCMD, ...) */
|
||||
#define SPT_REUSEARGV 2 /* cover argv with title information */
|
||||
|
||||
#define MAXLINE 2048 /* max line length */
|
||||
#include <unistd.h>
|
||||
#ifdef HAVE_SYS_PSTAT_H
|
||||
#include <sys/pstat.h>
|
||||
#define SPT_TYPE SPT_PSTAT
|
||||
#endif
|
||||
|
||||
#ifndef SPT_TYPE
|
||||
# define SPT_TYPE SPT_NONE
|
||||
#endif
|
||||
|
||||
#if SPT_TYPE != SPT_NONE && SPT_TYPE != SPT_BUILTIN
|
||||
#ifndef SPT_PADCHAR
|
||||
# define SPT_PADCHAR '\0'
|
||||
#endif
|
||||
|
||||
# if SPT_TYPE == SPT_PSTAT
|
||||
# include <sys/pstat.h>
|
||||
# endif
|
||||
# if SPT_TYPE == SPT_PSSTRINGS
|
||||
# include <machine/vmparam.h>
|
||||
# include <sys/exec.h>
|
||||
# ifndef PS_STRINGS /* hmmmm.... apparently not available after all */
|
||||
# undef SPT_TYPE
|
||||
# define SPT_TYPE SPT_REUSEARGV
|
||||
# else
|
||||
# ifndef NKPDE /* FreeBSD 2.0 */
|
||||
# define NKPDE 63
|
||||
typedef unsigned int *pt_entry_t;
|
||||
# endif
|
||||
# endif
|
||||
# endif
|
||||
#if SPT_TYPE == SPT_REUSEARGV
|
||||
static char *argv_start = NULL;
|
||||
static size_t argv_env_len = 0;
|
||||
#endif
|
||||
|
||||
# if SPT_TYPE == SPT_PSSTRINGS || SPT_TYPE == SPT_CHANGEARGV
|
||||
# define SETPROC_STATIC static
|
||||
# else
|
||||
# define SETPROC_STATIC
|
||||
# endif
|
||||
#endif /* HAVE_SETPROCTITLE */
|
||||
|
||||
# if SPT_TYPE == SPT_SYSMIPS
|
||||
# include <sys/sysmips.h>
|
||||
# include <sys/sysnews.h>
|
||||
# endif
|
||||
|
||||
# if SPT_TYPE == SPT_SCO
|
||||
# include <sys/immu.h>
|
||||
# include <sys/dir.h>
|
||||
# include <sys/user.h>
|
||||
# include <sys/fs/s5param.h>
|
||||
# if PSARGSZ > MAXLINE
|
||||
# define SPT_BUFSIZE PSARGSZ
|
||||
# endif
|
||||
# endif
|
||||
|
||||
# ifndef SPT_PADCHAR
|
||||
# define SPT_PADCHAR '\0'
|
||||
# endif
|
||||
|
||||
# ifndef SPT_BUFSIZE
|
||||
# define SPT_BUFSIZE MAXLINE
|
||||
# endif
|
||||
|
||||
#endif /* SPT_TYPE != SPT_NONE && SPT_TYPE != SPT_BUILTIN */
|
||||
|
||||
/*
|
||||
** Pointers for setproctitle.
|
||||
** This allows "ps" listings to give more useful information.
|
||||
*/
|
||||
|
||||
char **Argv = NULL; /* pointer to argument vector */
|
||||
char *LastArgv = NULL; /* end of argv */
|
||||
|
||||
int
|
||||
initsetproctitle(argc, argv, envp)
|
||||
int argc;
|
||||
char **argv;
|
||||
char **envp;
|
||||
void initsetproctitle(int argc, char *argv[])
|
||||
{
|
||||
register int i, envpsize = 0;
|
||||
#if defined(SPT_TYPE) && SPT_TYPE == SPT_REUSEARGV
|
||||
extern char **environ;
|
||||
char *lastargv = NULL;
|
||||
char **envp = environ;
|
||||
int i;
|
||||
|
||||
/*
|
||||
** Move the environment so setproctitle can use the space at
|
||||
** the top of memory.
|
||||
*/
|
||||
* NB: This assumes that argv has already been copied out of the
|
||||
* way. This is true for sshd, but may not be true for other
|
||||
* programs. Beware.
|
||||
*/
|
||||
|
||||
if (argc == 0 || argv[0] == NULL)
|
||||
return;
|
||||
|
||||
/* Fail if we can't allocate room for the new environment */
|
||||
for (i = 0; envp[i] != NULL; i++)
|
||||
envpsize += strlen(envp[i]) + 1;
|
||||
environ = (char **) malloc(sizeof (char *) * (i + 1));
|
||||
if (environ == NULL)
|
||||
return -1;
|
||||
/* ---> removed some macro calls */
|
||||
for (i = 0; envp[i] != NULL; i++) {
|
||||
size_t len = strlen(envp[i]) + 1;
|
||||
char *p = malloc(len);
|
||||
if (p == NULL)
|
||||
return -1;
|
||||
environ[i] = strncpy(p, envp[i], len);
|
||||
p[len - 1] = (int)NULL;
|
||||
;
|
||||
if ((environ = malloc(sizeof(*environ) * (i + 1))) == NULL) {
|
||||
environ = envp; /* put it back */
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Find the last argv string or environment variable within
|
||||
* our process memory area.
|
||||
*/
|
||||
for (i = 0; i < argc; i++) {
|
||||
if (lastargv == NULL || lastargv + 1 == argv[i])
|
||||
lastargv = argv[i] + strlen(argv[i]);
|
||||
}
|
||||
for (i = 0; envp[i] != NULL; i++) {
|
||||
if (lastargv + 1 == envp[i])
|
||||
lastargv = envp[i] + strlen(envp[i]);
|
||||
}
|
||||
|
||||
argv[1] = NULL;
|
||||
argv_start = argv[0];
|
||||
argv_env_len = lastargv - argv[0] - 1;
|
||||
|
||||
/*
|
||||
* Copy environment
|
||||
* XXX - will truncate env on strdup fail
|
||||
*/
|
||||
for (i = 0; envp[i] != NULL; i++)
|
||||
environ[i] = strdup(envp[i]);
|
||||
environ[i] = NULL;
|
||||
|
||||
/*
|
||||
** Save start and extent of argv for setproctitle.
|
||||
*/
|
||||
|
||||
Argv = argv;
|
||||
|
||||
/*
|
||||
** Find the last environment variable within sendmail's
|
||||
** process memory area.
|
||||
*/
|
||||
while (i > 0 && (envp[i - 1] < argv[0] ||
|
||||
envp[i - 1] > (argv[argc - 1] +
|
||||
strlen(argv[argc - 1]) + 1 + envpsize)))
|
||||
i--;
|
||||
|
||||
if (i > 0)
|
||||
LastArgv = envp[i - 1] + strlen(envp[i - 1]);
|
||||
else
|
||||
LastArgv = argv[argc - 1] + strlen(argv[argc - 1]);
|
||||
|
||||
return 0;
|
||||
#endif /* SPT_REUSEARGV */
|
||||
}
|
||||
|
||||
#if SPT_TYPE != SPT_BUILTIN
|
||||
|
||||
|
||||
/*VARARGS1*/
|
||||
#ifndef HAVE_SETPROCTITLE
|
||||
void
|
||||
setproctitle(const char *fmt, ...)
|
||||
{
|
||||
# if SPT_TYPE != SPT_NONE
|
||||
register char *p;
|
||||
register int i;
|
||||
SETPROC_STATIC char buf[SPT_BUFSIZE];
|
||||
VA_LOCAL_DECL
|
||||
# if SPT_TYPE == SPT_PSTAT
|
||||
#if SPT_TYPE != SPT_NONE
|
||||
va_list ap;
|
||||
char buf[1024];
|
||||
size_t len;
|
||||
extern char *__progname;
|
||||
#if SPT_TYPE == SPT_PSTAT
|
||||
union pstun pst;
|
||||
# endif
|
||||
# if SPT_TYPE == SPT_SCO
|
||||
off_t seek_off;
|
||||
static int kmem = -1;
|
||||
static int kmempid = -1;
|
||||
struct user u;
|
||||
# endif
|
||||
#endif
|
||||
|
||||
p = buf;
|
||||
#if SPT_TYPE == SPT_REUSEARGV
|
||||
if (argv_env_len <= 0)
|
||||
return;
|
||||
#endif
|
||||
|
||||
/* print the argument string */
|
||||
VA_START(fmt);
|
||||
vsnprintf(p, SPACELEFT(buf, p), fmt, ap);
|
||||
VA_END;
|
||||
strlcpy(buf, __progname, sizeof(buf));
|
||||
|
||||
i = strlen(buf);
|
||||
va_start(ap, fmt);
|
||||
if (fmt != NULL) {
|
||||
len = strlcat(buf, ": ", sizeof(buf));
|
||||
if (len < sizeof(buf))
|
||||
vsnprintf(buf + len, sizeof(buf) - len , fmt, ap);
|
||||
}
|
||||
va_end(ap);
|
||||
|
||||
# if SPT_TYPE == SPT_PSTAT
|
||||
#if SPT_TYPE == SPT_PSTAT
|
||||
pst.pst_command = buf;
|
||||
pstat(PSTAT_SETCMD, pst, i, 0, 0);
|
||||
# endif
|
||||
# if SPT_TYPE == SPT_PSSTRINGS
|
||||
PS_STRINGS->ps_nargvstr = 1;
|
||||
PS_STRINGS->ps_argvstr = buf;
|
||||
# endif
|
||||
# if SPT_TYPE == SPT_SYSMIPS
|
||||
sysmips(SONY_SYSNEWS, NEWS_SETPSARGS, buf);
|
||||
# endif
|
||||
# if SPT_TYPE == SPT_SCO
|
||||
if (kmem < 0 || kmempid != getpid())
|
||||
{
|
||||
if (kmem >= 0)
|
||||
close(kmem);
|
||||
kmem = open(_PATH_KMEM, O_RDWR, 0);
|
||||
if (kmem < 0)
|
||||
return;
|
||||
(void) fcntl(kmem, F_SETFD, 1);
|
||||
kmempid = getpid();
|
||||
}
|
||||
buf[PSARGSZ - 1] = '\0';
|
||||
seek_off = UVUBLK + (off_t) u.u_psargs - (off_t) &u;
|
||||
if (lseek(kmem, (off_t) seek_off, SEEK_SET) == seek_off)
|
||||
(void) write(kmem, buf, PSARGSZ);
|
||||
# endif
|
||||
# if SPT_TYPE == SPT_REUSEARGV
|
||||
if (i > LastArgv - Argv[0] - 2)
|
||||
{
|
||||
i = LastArgv - Argv[0] - 2;
|
||||
buf[i] = '\0';
|
||||
}
|
||||
(void) strcpy(Argv[0], buf);
|
||||
p = &Argv[0][i];
|
||||
while (p < LastArgv)
|
||||
*p++ = SPT_PADCHAR;
|
||||
Argv[1] = NULL;
|
||||
# endif
|
||||
# if SPT_TYPE == SPT_CHANGEARGV
|
||||
Argv[0] = buf;
|
||||
Argv[1] = 0;
|
||||
# endif
|
||||
# endif /* SPT_TYPE != SPT_NONE */
|
||||
pstat(PSTAT_SETCMD, pst, strlen(buf), 0, 0);
|
||||
#elif SPT_TYPE == SPT_REUSEARGV
|
||||
/* debug("setproctitle: copy \"%s\" into len %d",
|
||||
buf, argv_env_len); */
|
||||
len = strlcpy(argv_start, buf, argv_env_len);
|
||||
for(; len < argv_env_len; len++)
|
||||
argv_start[len] = SPT_PADCHAR;
|
||||
#endif
|
||||
|
||||
#endif /* SPT_NONE */
|
||||
}
|
||||
|
||||
#endif /* SPT_TYPE != SPT_BUILTIN */
|
||||
|
||||
#endif /* SETPROCTITLE */
|
||||
#endif /* HAVE_SETPROCTITLE */
|
||||
|
|
|
|||
72
strlcat.c
Normal file
72
strlcat.c
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
/* OPENBSD ORIGINAL: lib/libc/string/strlcat.c */
|
||||
|
||||
/* $OpenBSD: strlcat.c,v 1.11 2003/06/17 21:56:24 millert Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/param.h>
|
||||
|
||||
#ifndef HAVE_STRLCAT
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char *rcsid = "$OpenBSD: strlcat.c,v 1.11 2003/06/17 21:56:24 millert Exp $";
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
* Appends src to string dst of size siz (unlike strncat, siz is the
|
||||
* full size of dst, not space left). At most siz-1 characters
|
||||
* will be copied. Always NUL terminates (unless siz <= strlen(dst)).
|
||||
* Returns strlen(src) + MIN(siz, strlen(initial dst)).
|
||||
* If retval >= siz, truncation occurred.
|
||||
*/
|
||||
size_t
|
||||
strlcat(char *dst, const char *src, size_t siz)
|
||||
{
|
||||
register char *d = dst;
|
||||
register const char *s = src;
|
||||
register size_t n = siz;
|
||||
size_t dlen;
|
||||
|
||||
/* Find the end of dst and adjust bytes left but don't go past end */
|
||||
while (n-- != 0 && *d != '\0')
|
||||
d++;
|
||||
dlen = d - dst;
|
||||
n = siz - dlen;
|
||||
|
||||
if (n == 0)
|
||||
return(dlen + strlen(s));
|
||||
while (*s != '\0') {
|
||||
if (n != 1) {
|
||||
*d++ = *s;
|
||||
n--;
|
||||
}
|
||||
s++;
|
||||
}
|
||||
*d = '\0';
|
||||
|
||||
return(dlen + (s - src)); /* count does not include NUL */
|
||||
}
|
||||
|
||||
#endif /* !HAVE_STRLCAT */
|
||||
68
strlcpy.c
Normal file
68
strlcpy.c
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
/* OPENBSD ORIGINAL: lib/libc/string/strlcpy.c */
|
||||
|
||||
/* $OpenBSD: strlcpy.c,v 1.8 2003/06/17 21:56:24 millert Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/param.h>
|
||||
|
||||
#ifndef HAVE_STRLCPY
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char *rcsid = "$OpenBSD: strlcpy.c,v 1.8 2003/06/17 21:56:24 millert Exp $";
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
* Copy src to string dst of size siz. At most siz-1 characters
|
||||
* will be copied. Always NUL terminates (unless siz == 0).
|
||||
* Returns strlen(src); if retval >= siz, truncation occurred.
|
||||
*/
|
||||
size_t
|
||||
strlcpy(char *dst, const char *src, size_t siz)
|
||||
{
|
||||
register char *d = dst;
|
||||
register const char *s = src;
|
||||
register size_t n = siz;
|
||||
|
||||
/* Copy as many bytes as will fit */
|
||||
if (n != 0 && --n != 0) {
|
||||
do {
|
||||
if ((*d++ = *s++) == 0)
|
||||
break;
|
||||
} while (--n != 0);
|
||||
}
|
||||
|
||||
/* Not enough room in dst, add NUL and traverse rest of src */
|
||||
if (n == 0) {
|
||||
if (siz != 0)
|
||||
*d = '\0'; /* NUL-terminate dst */
|
||||
while (*s++)
|
||||
;
|
||||
}
|
||||
|
||||
return(s - src - 1); /* count does not include NUL */
|
||||
}
|
||||
|
||||
#endif /* !HAVE_STRLCPY */
|
||||
Loading…
Add table
Add a link
Reference in a new issue