From b164da388f4dfa7e0caf3511a8a2aeb1758660fd Mon Sep 17 00:00:00 2001 From: Mark Janssen Date: Tue, 22 Jan 2008 22:56:15 +0000 Subject: [PATCH] Re-Indenting git-svn-id: https://proxytunnel.svn.sourceforge.net/svnroot/proxytunnel/trunk/proxytunnel@200 bc163920-b10d-0410-b2c5-a5491ca2ceef --- messages.c | 12 +-- ntlm.c | 138 ++++++++++++---------------- proxytunnel.c | 228 ++++++++++++++++++----------------------------- ptstream.c | 105 +++++++--------------- readpassphrase.c | 12 +-- setproctitle.c | 10 +-- strlcat.c | 3 +- strlcpy.c | 3 +- 8 files changed, 193 insertions(+), 318 deletions(-) diff --git a/messages.c b/messages.c index e302b4a..803f664 100644 --- a/messages.c +++ b/messages.c @@ -1,4 +1,4 @@ -/* Proxytunnel - (C) 2001-2006 Jos Visser / Mark Janssen */ +/* Proxytunnel - (C) 2001-2008 Jos Visser / Mark Janssen */ /* Contact: josv@osp.nl / maniac@maniac.nl */ /* @@ -27,8 +27,7 @@ /* * Give a message to the user */ -void message( char *s, ... ) -{ +void message( char *s, ... ) { va_list ap; char buf[1024]; @@ -42,11 +41,8 @@ void message( char *s, ... ) fputs( buf, stderr ); } -/* - * My own perror function (uses the internal message) - */ -void my_perror( char *msg ) -{ +/* My own perror function (uses the internal message) */ +void my_perror( char *msg ) { if (errno == 0) { message( "error: %s.\n", msg ); } else { diff --git a/ntlm.c b/ntlm.c index e539108..53f3304 100644 --- a/ntlm.c +++ b/ntlm.c @@ -1,4 +1,4 @@ -/* Proxytunnel - (C) 2001-2006 Jos Visser / Mark Janssen */ +/* Proxytunnel - (C) 2001-2008 Jos Visser / Mark Janssen */ /* Contact: josv@osp.nl / maniac@maniac.nl */ /* @@ -88,8 +88,7 @@ void build_type1() { } -int parse_type2(unsigned char *buf) -{ +int parse_type2(unsigned char *buf) { int len = unbase64(t2_buf, buf, TYPE2_BUF_SIZE); ntlm_type2 *t2 = (ntlm_type2 *)t2_buf; int i; @@ -128,19 +127,16 @@ int parse_type2(unsigned char *buf) if( args_info.verbose_flag ) message("NTLM Got Domain: %s\n", domain); - if( args_info.domain_given ) - { + if( args_info.domain_given ) { if( ! args_info.quiet_flag ) message( "NTLM Overriding domain: %s\n", args_info.domain_arg ); - for( i = 0; i < strlen(args_info.domain_arg); i++ ) - { + for( i = 0; i < strlen(args_info.domain_arg); i++ ) { domain[i] = args_info.domain_arg[i]; } domain[i] = 0; } - if( args_info.verbose_flag ) - { + if( args_info.verbose_flag ) { message("NTLM Domain: %s\n", domain); message("NTLM Got Challenge: "); @@ -238,9 +234,6 @@ void build_type3_response() { return; } - - - /* ** Function: hmac_md5 */ @@ -253,67 +246,57 @@ unsigned char* key; /* pointer to authentication key */ int key_len; /* length of authentication key */ unsigned char digest[16]; /* caller digest to be filled in */ { - MD5_CTX context; - unsigned char k_ipad[65]; /* inner padding - - * key XORd with ipad - */ - unsigned char k_opad[65]; /* outer padding - - * key XORd with opad - */ - unsigned char tk[16]; - int i; + MD5_CTX context; + unsigned char k_ipad[65]; /* inner padding - key XORd with ipad */ + unsigned char k_opad[65]; /* outer padding - key XORd with opad */ + unsigned char tk[16]; + int i; - /* if key is longer than 64 bytes reset it to key=MD5(key) */ - if (key_len > 64) { + /* if key is longer than 64 bytes reset it to key=MD5(key) */ + if (key_len > 64) { + MD5_CTX tctx; + MD5_Init( &tctx ); + MD5_Update( &tctx, key, key_len ); + MD5_Final( tk, &tctx ); - MD5_CTX tctx; - MD5_Init(&tctx); - MD5_Update(&tctx, key, key_len); - MD5_Final(tk, &tctx); + key = tk; + key_len = 16; + } - key = tk; - key_len = 16; - } + /* + * the HMAC_MD5 transform looks like: + * + * MD5(K XOR opad, MD5(K XOR ipad, text)) + * + * where K is an n byte key + * ipad is the byte 0x36 repeated 64 times + * opad is the byte 0x5c repeated 64 times + * and text is the data being protected + */ - /* - * the HMAC_MD5 transform looks like: - * - * MD5(K XOR opad, MD5(K XOR ipad, text)) - * - * where K is an n byte key - * ipad is the byte 0x36 repeated 64 times - * opad is the byte 0x5c repeated 64 times - * and text is the data being protected - */ + /* start out by storing key in pads */ + bzero( k_ipad, sizeof k_ipad); + bzero( k_opad, sizeof k_opad); + bcopy( key, k_ipad, key_len); + bcopy( key, k_opad, key_len); - /* start out by storing key in pads */ - bzero( k_ipad, sizeof k_ipad); - bzero( k_opad, sizeof k_opad); - bcopy( key, k_ipad, key_len); - bcopy( key, k_opad, key_len); + /* XOR key with ipad and opad values */ + for (i=0; i<64; i++) { + k_ipad[i] ^= 0x36; + k_opad[i] ^= 0x5c; + } - /* XOR key with ipad and opad values */ - for (i=0; i<64; i++) { - k_ipad[i] ^= 0x36; - k_opad[i] ^= 0x5c; - } - /* - * perform inner MD5 - */ - MD5_Init(&context); /* init context for 1st - * pass */ - MD5_Update(&context, k_ipad, 64); /* start with inner pad */ - MD5_Update(&context, text, text_len); /* then text of datagram */ - MD5_Final(digest, &context); /* finish up 1st pass */ - /* - * perform outer MD5 - */ - MD5_Init(&context); /* init context for 2nd - * pass */ - MD5_Update(&context, k_opad, 64); /* start with outer pad */ - MD5_Update(&context, digest, 16); /* then results of 1st - * hash */ - MD5_Final(digest, &context); /* finish up 2nd pass */ + /* perform inner MD5 */ + MD5_Init(&context); /* init context for 1st pass */ + MD5_Update(&context, k_ipad, 64); /* start with inner pad */ + MD5_Update(&context, text, text_len); /* then text of datagram */ + MD5_Final(digest, &context); /* finish up 1st pass */ + + /* perform outer MD5 */ + MD5_Init(&context); /* init context for 2nd pass */ + MD5_Update(&context, k_opad, 64); /* start with outer pad */ + MD5_Update(&context, digest, 16); /* then results of 1st hash */ + MD5_Final(digest, &context); /* finish up 2nd pass */ } void build_ntlm2_response() { @@ -348,8 +331,7 @@ void build_ntlm2_response() { MD4_Update (&passcontext, unipasswd, passlen); MD4_Final (passdigest, &passcontext); - if( args_info.verbose_flag ) - { + if( args_info.verbose_flag ) { message("NTLM: MD4 of password is: "); for( i = 0; i < 16; i++) message("%02X", passdigest[i]); @@ -389,8 +371,7 @@ void build_ntlm2_response() { } } - if( args_info.verbose_flag ) - { + if( args_info.verbose_flag ) { message("userdom is: "); for( i = 0; i < userdomlen; i++) message("%02X", userdom[i]); @@ -401,8 +382,7 @@ void build_ntlm2_response() { free(userdom); - if( args_info.verbose_flag ) - { + if( args_info.verbose_flag ) { message("HMAC_MD5 of userdom keyed with MD4 pass is: "); for( i = 0; i < 16; i++) message("%02X", userdomdigest[i]); @@ -431,8 +411,10 @@ void build_ntlm2_response() { b->signature = 0x00000101; - // This is nasty, also not sure all this 64bit arithmetic will work all the time.. basically the spec says you - // need the number of 10ths of microseconds since jan 1, 1601. + /* This is nasty, also not sure all this 64bit arithmetic will + * work all the time.. basically the spec says you need the + * number of 10ths of microseconds since jan 1, 1601. + */ gettimeofday(&t, NULL); b->timestamp = (long long)t.tv_sec; @@ -445,8 +427,7 @@ void build_ntlm2_response() { for (i = 0; i < 8; i++) b->client_challenge[i] = (unsigned char) ((256.0 * rand()) / (RAND_MAX + 1.0)) ; - if( args_info.verbose_flag ) - { + if( args_info.verbose_flag ) { message("client_challenge is: "); for( i = 0; i < 8; i++) message("%02X", b->client_challenge[i]); @@ -460,8 +441,7 @@ void build_ntlm2_response() { for(i = 0; i < 16; i++) b->digest[i] = responsedigest[i]; - if( args_info.verbose_flag ) - { + if( args_info.verbose_flag ) { message("HMAC is: "); for( i = 0; i < 16; i++) message("%02X", responsedigest[i]); diff --git a/proxytunnel.c b/proxytunnel.c index 546db9e..a681ce9 100644 --- a/proxytunnel.c +++ b/proxytunnel.c @@ -1,5 +1,5 @@ -/* Proxytunnel - (C) 2001-2006 Jos Visser / Mark Janssen */ -/* Contact: josv@osp.nl / maniac@maniac.nl */ +/* Proxytunnel - (C) 2001-2008 Jos Visser / Mark Janssen */ +/* Contact: josv@osp.nl / maniac@maniac.nl */ /* * This program is free software; you can redistribute it and/or modify @@ -49,14 +49,13 @@ #endif /* Globals */ -int read_fd=0; /* The file descriptor to read from */ -int write_fd=1; /* The file destriptor to write to */ +int read_fd=0; /* The file descriptor to read from */ +int write_fd=1; /* The file destriptor to write to */ /* * Kill the program (signal handler) */ -void signal_handler( int signal ) -{ +void signal_handler( int signal ) { if( args_info.verbose_flag ) message( "Tunnel received signal %d. Ignoring signal.\n", signal ); // closeall(); @@ -74,68 +73,56 @@ int tunnel_connect() { /* * Create the socket */ - if( ( sd = socket( AF_INET, SOCK_STREAM, 0 ) ) < 0 ) - { + if( ( sd = socket( AF_INET, SOCK_STREAM, 0 ) ) < 0 ) { my_perror("Can not create socket"); exit(1); } - /* - * Lookup the IP address of the proxy - */ - if( ! ( he = gethostbyname( args_info.proxyhost_arg ) ) ) - { -// FIXME: my_perror("Local proxy %s could not be resolved", args_info.proxyhost_arg); + /* Lookup the IP address of the proxy */ + if( ! ( he = gethostbyname( args_info.proxyhost_arg ) ) ) { my_perror("Local proxy could not be resolved." ); exit(1); } char ip[16]; snprintf(ip, 16, "%d.%d.%d.%d", he->h_addr[0] & 255, he->h_addr[1] & 255, he->h_addr[2] & 255, he->h_addr[3] & 255); - if( args_info.verbose_flag && strcmp(args_info.proxyhost_arg, ip)) - { + if( args_info.verbose_flag && strcmp(args_info.proxyhost_arg, ip)) { message( "Local proxy %s resolves to %d.%d.%d.%d\n", - args_info.proxyhost_arg, - he->h_addr[0] & 255, - he->h_addr[1] & 255, - he->h_addr[2] & 255, - he->h_addr[3] & 255 ); + args_info.proxyhost_arg, + he->h_addr[0] & 255, + he->h_addr[1] & 255, + he->h_addr[2] & 255, + he->h_addr[3] & 255 ); } - /* - * Set up the structure to connect to the proxy port of the proxy host - */ + /* Set up the structure to connect to the proxy port of the proxy host */ memset( &sa, '\0', sizeof( sa ) ); - sa.sin_family = AF_INET; - memcpy( &sa.sin_addr.s_addr, he->h_addr, 4); - sa.sin_port = htons( args_info.proxyport_arg ); + sa.sin_family = AF_INET; + memcpy( &sa.sin_addr.s_addr, he->h_addr, 4); + sa.sin_port = htons( args_info.proxyport_arg ); - /* - * Connect the socket - */ - if( connect( sd, (struct sockaddr*) &sa, sizeof( sa ) ) < 0 ) - { + /* Connect the socket */ + if( connect( sd, (struct sockaddr*) &sa, sizeof( sa ) ) < 0 ) { my_perror("connect() failed"); exit(1); } - if( ! args_info.quiet_flag ) - { - if ( ! args_info.verbose_flag ) { - if ( args_info.remproxy_given ) { - message( "Via %s -> %s -> %s\n", - args_info.proxy_arg, - args_info.remproxy_arg, - args_info.dest_arg ); - } else { - message( "Via %s -> %s\n", - args_info.proxy_arg, - args_info.dest_arg ); - } - } else { - message( "Connected to %s (local proxy)\n", args_info.proxy_arg ); - } - } + if( ! args_info.quiet_flag ) { + if ( ! args_info.verbose_flag ) { + if ( args_info.remproxy_given ) { + message( "Via %s -> %s -> %s\n", + args_info.proxy_arg, + args_info.remproxy_arg, + args_info.dest_arg ); + } else { + message( "Via %s -> %s\n", + args_info.proxy_arg, + args_info.dest_arg ); + } + } else { + message( "Connected to %s (local proxy)\n", args_info.proxy_arg ); + } + } { /* Increase interactivity of tunnel, patch by Ingo Molnar */ int flag = 1; @@ -151,19 +138,12 @@ int tunnel_connect() { } -/* - * Leave a goodbye message - */ +/* Leave a goodbye message */ void closeall() { -// message( "In closeall\n"); - #ifndef CYGWIN - closelog(); + closelog(); #endif - - /* - * Close all streams - */ + /* Close all streams */ if (stunnel) { stream_close(stunnel); @@ -174,51 +154,44 @@ void closeall() { stream_close(std); std = NULL; } - if( args_info.verbose_flag ) { message( "Tunnel closed.\n" ); } - } -/* - * Run as a standalone daemon - */ +/* Run as a standalone daemon */ void do_daemon() { - int listen_sd; - int one = 1; - struct sockaddr_in sa_serv; - struct sockaddr_in sa_cli; - socklen_t client_len; - int pid = 0; - int sd_client; - char buf[80]; - unsigned char addr[4]; + int listen_sd; + int one = 1; + struct sockaddr_in sa_serv; + struct sockaddr_in sa_cli; + socklen_t client_len; + int pid = 0; + int sd_client; + char buf[80]; + unsigned char addr[4]; /* Socket descriptor */ int sd; - if ( ( listen_sd = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP ) ) < 0 ) - { + if ( ( listen_sd = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP ) ) < 0 ) { my_perror( "Server socket creation failed" ); exit(1); } -#ifdef SO_REUSEPORT /* doesnt exist everywhere... */ - setsockopt(listen_sd, SOL_SOCKET, SO_REUSEPORT, &one, sizeof (one)); +#ifdef SO_REUSEPORT /* doesnt exist everywhere... */ + setsockopt(listen_sd, SOL_SOCKET, SO_REUSEPORT, &one, sizeof(one)); #endif setsockopt(listen_sd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)); - memset( &sa_serv, '\0', sizeof( sa_serv ) ); sa_serv.sin_family = AF_INET; sa_serv.sin_addr.s_addr = htonl(INADDR_ANY); sa_serv.sin_port = htons( args_info.standalone_arg ); - if ( bind( listen_sd, (struct sockaddr * )&sa_serv, sizeof( struct sockaddr ) ) < 0) - { + if ( bind( listen_sd, (struct sockaddr * )&sa_serv, sizeof( struct sockaddr ) ) < 0) { my_perror("Server socket bind failed"); exit(1); } @@ -243,26 +216,23 @@ void do_daemon() */ #ifndef CYGWIN /* - if ( ( pid = fork( ) ) < 0 ) - { + if ( ( pid = fork( ) ) < 0 ) { my_perror( "Cannot fork into the background" ); - exit( 1 ); - } - else if ( pid > 0 ) - { - message( "Forked into the background with pid %d\n", pid ); - exit(0); + exit(1); + } else if ( pid > 0 ) { + message( "Forked into the background with pid %d\n", pid ); + exit(0); } */ openlog( program_name, LOG_CONS|LOG_PID,LOG_DAEMON ); i_am_daemon = 1; #endif /* CYGWIN */ + atexit( closeall ); listen( listen_sd, 8 ); - while (1==1) - { + while (1==1) { /* 2002/04/21 * * Workaround a CYGWIN bug, see: @@ -280,19 +250,15 @@ void do_daemon() sd_client = accept( listen_sd, (struct sockaddr *)&sa_cli, &client_len ); - if ( sd_client < 0 ) - { - my_perror( "accept() failed. Bailing out..." ); - exit(1); + if ( sd_client < 0 ) { + my_perror( "accept() failed. Bailing out..." ); + exit(1); } - if ( ( pid = fork() ) < 0 ) - { - my_perror( "Cannot fork worker" ); - } - else if ( pid == 0 ) - { - read_fd = write_fd = sd_client; + if ( ( pid = fork() ) < 0 ) { + my_perror( "Cannot fork worker" ); + } else if ( pid == 0 ) { + read_fd = write_fd = sd_client; /* Create a stdin/out stream */ std = stream_open(read_fd, write_fd); @@ -301,20 +267,21 @@ void do_daemon() sd = tunnel_connect(); stunnel = stream_open(sd, sd); - /* If --encrypt-proxy is specified, connect to the proxy using SSL */ #ifdef USE_SSL + /* If --encrypt-proxy is specified, connect to the proxy using SSL */ if ( args_info.encryptproxy_flag ) stream_enable_ssl(stunnel); -#endif +#endif /* USE_SSL */ /* Open the tunnel */ proxy_protocol(stunnel); - /* If --encrypt is specified, wrap all traffic after the proxy handoff in SSL */ #ifdef USE_SSL + /* If --encrypt is specified, wrap all traffic after the proxy handoff in SSL */ if( args_info.encrypt_flag ) stream_enable_ssl(stunnel); -#endif +#endif /* USE_SSL */ + #ifdef SETPROCTITLE if( ! args_info.proctitle_given ) setproctitle( "[cpio]\0" ); @@ -323,7 +290,7 @@ void do_daemon() #else if( args_info.proctitle_given ) message( "Setting process-title is not supported in this build\n"); -#endif +#endif /* SETPROCTITLE */ /* Run the tunnel - we should stay here indefinitely */ cpio(std, stunnel); @@ -332,18 +299,14 @@ void do_daemon() memcpy( &addr, &sa_cli.sin_addr.s_addr, 4 ); snprintf( (char *) buf, 16, "%u.%u.%u.%u", addr[0], addr[1], addr[2], addr[3] ); - message( "Started tunnel pid=%d for connection from %s", - pid, buf ); + message( "Started tunnel pid=%d for connection from %s", pid, buf ); close( sd_client ); } } -/* - * We begin at the beginning - */ -int main( int argc, char *argv[] ) -{ +/* We begin at the beginning */ +int main( int argc, char *argv[] ) { /* Socket descriptor */ int sd; @@ -353,10 +316,6 @@ int main( int argc, char *argv[] ) program_name = argv[0]; - /* - * New and improved option handling, using GNU getopts -- Maniac - */ - cmdline_parser( argc, argv, &args_info ); #ifdef SETPROCTITLE initsetproctitle( argc, argv ); @@ -376,20 +335,17 @@ int main( int argc, char *argv[] ) signal( SIGHUP, signal_handler ); /* If the usename is given, but password is not, prompt for it */ - if( args_info.user_given && !args_info.pass_given ) - { + if( args_info.user_given && !args_info.pass_given ) { char *cp; cp = getpass_x ("Enter proxy password:"); - if (cp != NULL && strlen (cp) > 0) - { + if (cp != NULL && strlen (cp) > 0) { args_info.pass_arg = strdup (cp); args_info.pass_given = 1; memset (cp, 0, strlen(cp)); } } - if( args_info.user_given && args_info.pass_given ) - { + if( args_info.user_given && args_info.pass_given ) { if (args_info.ntlm_flag) { build_type1(); if ( args_info.verbose_flag ) @@ -398,27 +354,20 @@ int main( int argc, char *argv[] ) make_basicauth(); } - /* - * Only one of -E (SSL encrypt client to proxy connection) or -e (SSL encrypt tunnel data) - * can be specified. - */ - if (args_info.encryptproxy_flag && args_info.encrypt_flag) - { + /* Only one of -E (SSL encrypt client to proxy connection) or + * -e (SSL encrypt tunnel data) can be specified. */ + if (args_info.encryptproxy_flag && args_info.encrypt_flag) { message("Error: only one of --encrypt-proxy and --encrypt can be specified for a tunnel\n"); exit( 1 ); } /* Do we need to run as a standalone daemon? */ - if ( args_info.standalone_arg > 0 ) - { + if ( args_info.standalone_arg > 0 ) { /* Do processing in the other mainline... */ do_daemon(); - } - else - { + } else { /* Inetd trick */ - if( args_info.inetd_flag ) - { + if( args_info.inetd_flag ) { write_fd=0; } @@ -433,7 +382,7 @@ int main( int argc, char *argv[] ) #ifdef USE_SSL if ( args_info.encryptproxy_flag ) stream_enable_ssl(stunnel); -#endif +#endif /* USE_SSL */ /* Open the tunnel */ proxy_protocol(stunnel); @@ -442,7 +391,8 @@ int main( int argc, char *argv[] ) #ifdef USE_SSL if( args_info.encrypt_flag ) stream_enable_ssl(stunnel); -#endif +#endif /* USE_SSL */ + #ifdef SETPROCTITLE if( ! args_info.proctitle_given ) setproctitle( "[cpio]\0" ); @@ -451,7 +401,7 @@ int main( int argc, char *argv[] ) #else if( args_info.proctitle_given ) message( "Setting process-title is not supported in this build\n"); -#endif +#endif /* SETPROCTITLE */ /* Run the tunnel - we should stay here indefinitely */ cpio(std, stunnel); diff --git a/ptstream.c b/ptstream.c index eb5ae64..3a09187 100644 --- a/ptstream.c +++ b/ptstream.c @@ -1,4 +1,4 @@ -/* Proxytunnel - (C) 2001-2006 Jos Visser / Mark Janssen */ +/* Proxytunnel - (C) 2001-2008 Jos Visser / Mark Janssen */ /* Contact: josv@osp.nl / maniac@maniac.nl */ /* @@ -33,8 +33,7 @@ * Open a stream for incoming and outgoing data with the specified fds */ -PTSTREAM *stream_open(int incoming_fd, int outgoing_fd) -{ +PTSTREAM *stream_open(int incoming_fd, int outgoing_fd) { PTSTREAM *pts; /* Initialise the structure and store the file descriptor */ @@ -53,16 +52,14 @@ PTSTREAM *stream_open(int incoming_fd, int outgoing_fd) * Close a stream */ -int stream_close(PTSTREAM *pts) -{ +int stream_close(PTSTREAM *pts) { /* Destroy the SSL context */ - if (pts->ssl) - { + if (pts->ssl) { #ifdef USE_SSL SSL_shutdown (pts->ssl); SSL_free (pts->ssl); SSL_CTX_free (pts->ctx); -#endif +#endif /* USE_SSL */ } /* Close the incoming fd */ @@ -70,7 +67,7 @@ int stream_close(PTSTREAM *pts) /* Close the outgoing fd */ close(pts->outgoing_fd); - + /* Free the structure */ free(pts); @@ -78,58 +75,45 @@ int stream_close(PTSTREAM *pts) } -/* - * Read from a stream - */ +/* Read from a stream */ -int stream_read(PTSTREAM *pts, void *buf, size_t len) -{ +int stream_read(PTSTREAM *pts, void *buf, size_t len) { /* Read up to the specified number of bytes into the buffer */ int bytes_read; - if (!pts->ssl) - { + if (!pts->ssl) { /* For a non-SSL stream... */ bytes_read = read(pts->incoming_fd, buf, len); - } - else - { + } else { #ifdef USE_SSL /* For an SSL stream... */ bytes_read = SSL_read(pts->ssl, buf, len); #else /* No SSL support, so must use a non-SSL stream */ bytes_read = read(pts->incoming_fd, buf, len); -#endif +#endif /* USE_SSL */ } return bytes_read; } -/* - * Write to a stream - */ - -int stream_write(PTSTREAM *pts, void *buf, size_t len) -{ +/* * Write to a stream */ +int stream_write(PTSTREAM *pts, void *buf, size_t len) { /* Write the specified number of bytes from the buffer */ int bytes_written; - if (!pts->ssl) - { + if (!pts->ssl) { /* For a non-SSL stream... */ bytes_written = write(pts->outgoing_fd, buf, len); - } - else - { + } else { #ifdef USE_SSL /* For an SSL stream... */ bytes_written = SSL_write(pts->ssl, buf, len); #else /* No SSL support, so must use a non-SSL stream */ bytes_written = write(pts->outgoing_fd, buf, len); -#endif +#endif /* USE_SSL */ } return bytes_written; @@ -140,49 +124,33 @@ int stream_write(PTSTREAM *pts, void *buf, size_t len) * Copy a block of data from one stream to another. A true * return code signifies EOF on the from socket descriptor. */ - -int stream_copy(PTSTREAM *pts_from, PTSTREAM *pts_to) -{ +int stream_copy(PTSTREAM *pts_from, PTSTREAM *pts_to) { char buf[SIZE]; int n; - /* - * Read a buffer from the source socket - */ - if ( ( n = stream_read( pts_from, buf, SIZE ) ) < 0 ) - { + /* Read a buffer from the source socket */ + if ( ( n = stream_read( pts_from, buf, SIZE ) ) < 0 ) { my_perror( "Socket read error" ); exit( 1 ); } - /* - * If we have read 0 bytes, there is an EOF on src - */ + /* If we have read 0 bytes, there is an EOF on src */ if( n==0 ) return 1; - /* - * Write the buffer to the destination socket - */ - if ( stream_write( pts_to, buf, n ) != n ) - { + /* Write the buffer to the destination socket */ + if ( stream_write( pts_to, buf, n ) != n ) { my_perror( "Socket write error" ); exit( 1 ); } - /* - * We're not yet at EOF - */ + /* We're not yet at EOF */ return 0; } -/* - * Initiate an SSL handshake on this stream and encrypt all subsequent data - */ - -int stream_enable_ssl(PTSTREAM *pts) -{ +/* Initiate an SSL handshake on this stream and encrypt all subsequent data */ +int stream_enable_ssl(PTSTREAM *pts) { #ifdef USE_SSL SSL_METHOD *meth; SSL *ssl; @@ -204,18 +172,14 @@ int stream_enable_ssl(PTSTREAM *pts) pts->ctx = ctx; #else message("Warning: stream_open(): SSL stream requested but no SSL support available; using unencrypted connection"); -#endif +#endif /* USE_SSL */ return 1; } -/* - * Return the incoming_fd for a given stream - */ - -int stream_get_incoming_fd(PTSTREAM *pts) -{ +/* Return the incoming_fd for a given stream */ +int stream_get_incoming_fd(PTSTREAM *pts) { if (!pts->ssl) return pts->incoming_fd; @@ -224,16 +188,11 @@ int stream_get_incoming_fd(PTSTREAM *pts) return SSL_get_rfd(pts->ssl); #else return pts->incoming_fd; -#endif +#endif /* USE_SSL */ } - -/* - * Return the outgoing_fd for a given stream - */ - -int stream_get_outgoing_fd(PTSTREAM *pts) -{ +/* Return the outgoing_fd for a given stream */ +int stream_get_outgoing_fd(PTSTREAM *pts) { if (!pts->ssl) return pts->outgoing_fd; @@ -242,7 +201,7 @@ int stream_get_outgoing_fd(PTSTREAM *pts) return SSL_get_wfd(pts->ssl); #else return pts->outgoing_fd; -#endif +#endif /* USE_SSL */ } // vim:noet diff --git a/readpassphrase.c b/readpassphrase.c index c2b1b73..594e988 100644 --- a/readpassphrase.c +++ b/readpassphrase.c @@ -71,8 +71,7 @@ static volatile sig_atomic_t signo; static void handler(int); char * -readpassphrase(const char *prompt, char *buf, size_t bufsiz, int flags) -{ +readpassphrase(const char *prompt, char *buf, size_t bufsiz, int flags) { ssize_t nr; int input, output, save_errno; char ch, *p, *end; @@ -93,7 +92,7 @@ restart: * stdin and write to stderr unless a tty is required. */ if ((flags & RPP_STDIN) || - (input = output = open(_PATH_TTY, O_RDWR)) == -1) { + (input = output = open(_PATH_TTY, O_RDWR)) == -1) { if (flags & RPP_REQUIRE_TTY) { errno = ENOTTY; return(NULL); @@ -194,16 +193,13 @@ restart: } char * -getpass_x(const char *prompt) -{ +getpass_x(const char *prompt) { static char buf[_PASSWORD_LEN + 1]; return(readpassphrase(prompt, buf, sizeof(buf), RPP_ECHO_OFF)); } -static void handler(int s) -{ - +static void handler(int s) { signo = s; } #endif /* HAVE_READPASSPHRASE */ diff --git a/setproctitle.c b/setproctitle.c index 9ad5b05..2dc67fc 100644 --- a/setproctitle.c +++ b/setproctitle.c @@ -67,8 +67,7 @@ static size_t argv_env_len = 0; #endif /* HAVE_SETPROCTITLE */ -void initsetproctitle(int argc, char *argv[]) -{ +void initsetproctitle(int argc, char *argv[]) { #if defined(SPT_TYPE) && SPT_TYPE == SPT_REUSEARGV extern char **environ; char *lastargv = NULL; @@ -121,8 +120,7 @@ void initsetproctitle(int argc, char *argv[]) #ifndef HAVE_SETPROCTITLE void -setproctitle(const char *fmt, ...) -{ +setproctitle(const char *fmt, ...) { #if SPT_TYPE != SPT_NONE va_list ap; char buf[1024]; @@ -139,11 +137,9 @@ setproctitle(const char *fmt, ...) if( args_info.proctitle_given ) strlcpy(buf, args_info.proctitle_arg, sizeof(buf)); - else - { + else { strlcpy(buf, __progname, sizeof(buf)); strlcat(buf, ": ", sizeof(buf)); - } diff --git a/strlcat.c b/strlcat.c index 912767a..8185d56 100644 --- a/strlcat.c +++ b/strlcat.c @@ -42,8 +42,7 @@ static char *rcsid = "$OpenBSD: strlcat.c,v 1.11 2003/06/17 21:56:24 millert Exp * If retval >= siz, truncation occurred. */ size_t -strlcat(char *dst, const char *src, size_t siz) -{ +strlcat(char *dst, const char *src, size_t siz) { register char *d = dst; register const char *s = src; register size_t n = siz; diff --git a/strlcpy.c b/strlcpy.c index 18dca7f..6ef3291 100644 --- a/strlcpy.c +++ b/strlcpy.c @@ -40,8 +40,7 @@ static char *rcsid = "$OpenBSD: strlcpy.c,v 1.8 2003/06/17 21:56:24 millert Exp * Returns strlen(src); if retval >= siz, truncation occurred. */ size_t -strlcpy(char *dst, const char *src, size_t siz) -{ +strlcpy(char *dst, const char *src, size_t siz) { register char *d = dst; register const char *s = src; register size_t n = siz;