Changeset 223
- Timestamp:
- 06/21/08 14:11:41 (4 years ago)
- Files:
-
- 1 added
- 5 edited
- 19 copied
-
tags/onioncat-0.1.7 (copied) (copied from trunk)
-
tags/onioncat-0.1.7/ChangeLog (copied) (copied from trunk/ChangeLog)
-
tags/onioncat-0.1.7/Makefile.in (copied) (copied from trunk/Makefile.in)
-
tags/onioncat-0.1.7/TODO (copied) (copied from trunk/TODO)
-
tags/onioncat-0.1.7/config.h.in (copied) (copied from trunk/config.h.in)
-
tags/onioncat-0.1.7/configure (copied) (copied from trunk/configure)
-
tags/onioncat-0.1.7/configure.ac (copied) (copied from trunk/configure.ac)
-
tags/onioncat-0.1.7/onioncat-0.1.7.tar.gz.sign (added)
-
tags/onioncat-0.1.7/src/Makefile.am (copied) (copied from trunk/src/Makefile.am)
-
tags/onioncat-0.1.7/src/ocat.c (copied) (copied from trunk/src/ocat.c) (6 diffs)
-
tags/onioncat-0.1.7/src/ocat.h (copied) (copied from trunk/src/ocat.h) (3 diffs)
-
tags/onioncat-0.1.7/src/ocatcompat.c (copied) (copied from trunk/src/ocatcompat.c)
-
tags/onioncat-0.1.7/src/ocatlog.c (copied) (copied from trunk/src/ocatlog.c) (3 diffs)
-
tags/onioncat-0.1.7/src/ocatpeer.c (copied) (copied from trunk/src/ocatpeer.c)
-
tags/onioncat-0.1.7/src/ocatroute.c (copied) (copied from trunk/src/ocatroute.c) (4 diffs)
-
tags/onioncat-0.1.7/src/ocatthread.c (copied) (copied from trunk/src/ocatthread.c)
-
tags/onioncat-0.1.7/src/ocattun.c (copied) (copied from trunk/src/ocattun.c)
-
tags/onioncat-0.1.7/src/ocatv6conv.c (copied) (copied from trunk/src/ocatv6conv.c)
-
tags/onioncat-0.1.7/src/strlcat.c (copied) (copied from trunk/src/strlcat.c)
-
tags/onioncat-0.1.7/src/strlcpy.c (copied) (copied from trunk/src/strlcpy.c)
-
trunk/configure.ac (modified) (1 diff)
-
trunk/src/ocat.c (modified) (6 diffs)
-
trunk/src/ocat.h (modified) (3 diffs)
-
trunk/src/ocatlog.c (modified) (3 diffs)
-
trunk/src/ocatroute.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
tags/onioncat-0.1.7/src/ocat.c
r221 r223 40 40 41 41 extern int debug_level_; 42 char *usrname_ = OCAT_UNAME; 43 char onion_url_[ONION_NAME_SIZE]; 44 struct in6_addr ocat_addr_; 42 45 43 46 … … 72 75 int main(int argc, char *argv[]) 73 76 { 74 char tunname[IFNAMSIZ] = "", onion[ONION_NAME_SIZE],*s, ip6addr[INET6_ADDRSTRLEN];75 struct in6_addr addr;77 char tunname[IFNAMSIZ] = "", /*onion[ONION_NAME_SIZE],*/ *s, ip6addr[INET6_ADDRSTRLEN]; 78 //struct in6_addr addr; 76 79 int c, runasroot = 0; 77 char *usrname = OCAT_UNAME;78 80 struct passwd *pwd; 79 81 int urlconv = 0, test_only = 0, controller = 1; … … 128 130 129 131 case 'u': 130 usrname = optarg;132 usrname_ = optarg; 131 133 break; 132 134 … … 149 151 if (urlconv == 2) 150 152 { 151 if (inet_pton(AF_INET6, argv[optind], & addr) <= 0)153 if (inet_pton(AF_INET6, argv[optind], &ocat_addr_) <= 0) 152 154 log_msg(L_ERROR, "%s", strerror(errno)), exit(1); 153 if (!has_tor_prefix(& addr))155 if (!has_tor_prefix(&ocat_addr_)) 154 156 log_msg(L_ERROR, "address does not have TOR prefix"), exit(1); 155 ipv6tonion(& addr, onion);156 printf("%s.onion\n", onion );157 ipv6tonion(&ocat_addr_, onion_url_); 158 printf("%s.onion\n", onion_url_); 157 159 exit(0); 158 160 } 159 161 160 162 // convert parameter to IPv6 address 161 strncpy(onion , argv[optind], ONION_NAME_SIZE);162 if ((s = strchr(onion , '.')))163 strncpy(onion_url_, argv[optind], ONION_NAME_SIZE); 164 if ((s = strchr(onion_url_, '.'))) 163 165 *s = '\0'; 164 if (strlen(onion ) != 16)166 if (strlen(onion_url_) != 16) 165 167 log_msg(L_ERROR, "parameter seems not to be valid onion hostname"), exit(1); 166 if (oniontipv6(onion , &addr) == -1)168 if (oniontipv6(onion_url_, &ocat_addr_) == -1) 167 169 log_msg(L_ERROR, "parameter seems not to be valid onion hostname"), exit(1); 168 170 169 inet_ntop(AF_INET6, & addr, ip6addr, INET6_ADDRSTRLEN);171 inet_ntop(AF_INET6, &ocat_addr_, ip6addr, INET6_ADDRSTRLEN); 170 172 171 173 if (urlconv == 1) … … 179 181 #ifndef WITHOUT_TUN 180 182 // create TUN device 181 tunfd_[0] = tunfd_[1] = tun_alloc(tunname, addr);183 tunfd_[0] = tunfd_[1] = tun_alloc(tunname, ocat_addr_); 182 184 #ifdef TEST_TUN_HDR 183 185 test_tun_hdr(); … … 200 202 { 201 203 errno = 0; 202 if (!(pwd = getpwnam(usrname )))203 log_msg(L_FATAL, "can't get information for user \"%s\": \"%s\"", usrname , errno ? strerror(errno) : "user not found"), exit(1);204 205 log_msg(L_NOTICE, "running as root, changing uid/gid to %s (uid %d/gid %d)", usrname , pwd->pw_uid, pwd->pw_gid);204 if (!(pwd = getpwnam(usrname_))) 205 log_msg(L_FATAL, "can't get information for user \"%s\": \"%s\"", usrname_, errno ? strerror(errno) : "user not found"), exit(1); 206 207 log_msg(L_NOTICE, "running as root, changing uid/gid to %s (uid %d/gid %d)", usrname_, pwd->pw_uid, pwd->pw_gid); 206 208 if (setgid(pwd->pw_gid)) 207 209 log_msg(L_ERROR, "could not change gid: \"%s\"", strerror(errno)), exit(1); -
tags/onioncat-0.1.7/src/ocat.h
r221 r223 46 46 #define OCAT_UNAME "tor" 47 47 #define OCAT_UID 112 48 #define OCAT_URL "http://www.abenteuerland.at/onioncat/" 48 49 49 50 //! Maximum frame (packet) size, should be able to keep one maximum size ipv6-packet: 2^16 + 40 + 4 … … 194 195 extern uint16_t ocat_dest_port_; 195 196 extern int vrec_; 196 extern int tunfd_[2];197 197 198 198 #ifndef WITHOUT_TUN … … 204 204 extern pthread_mutex_t thread_mutex_; 205 205 extern OcatThread_t *octh_; 206 extern char *usrname_; 207 208 /* ocat.c */ 209 //extern int tunfd_[2]; 210 extern int tunfd_[]; 211 extern char onion_url_[]; 212 extern struct in6_addr ocat_addr_; 206 213 207 214 /* ocatlog.c */ -
tags/onioncat-0.1.7/src/ocatlog.c
r221 r223 29 29 #include "ocat.h" 30 30 31 #define TIMESTRLEN 64 31 32 32 33 int debug_level_ = 4; … … 40 41 time_t t; 41 42 FILE *out = stderr; 42 char timestr[ 32] = "";43 char timestr[TIMESTRLEN] = ""; 43 44 va_list ap; 44 45 const OcatThread_t *th = get_thread(); … … 50 51 tm = localtime(&t); 51 52 if (tm) 52 strftime(timestr, 32, "%c", tm); 53 //strftime(timestr, 32, "%c", tm); 54 strftime(timestr, TIMESTRLEN, "%a, %d %b %Y %H:%M:%S %z", tm); 53 55 54 56 pthread_mutex_lock(&log_mutex_); -
tags/onioncat-0.1.7/src/ocatroute.c
r221 r223 287 287 288 288 289 #define HANDLE_HTTP 290 #ifdef HANDLE_HTTP 291 #define BSTRLEN 1024 292 293 int handle_http(const OcatPeer_t *peer) 294 { 295 time_t t; 296 char response[BSTRLEN], timestr[BSTRLEN]; 297 struct tm tm; 298 299 // simple check if packet could be an HTTP request 300 if (strncmp(peer->fragbuf, "GET ", 4)) 301 return 0; 302 303 t = time(NULL); 304 (void) localtime_r(&t, &tm); 305 strftime(timestr, BSTRLEN, "%a, %d %b %Y %H:%M:%S %z", &tm); 306 snprintf(response, BSTRLEN, 307 "HTTP/1.0 301 HTTP not possible\r\nLocation: %s\r\nDate: %s\r\nContent-Type: text/html; charset=iso-8859-1\r\n\r\n" 308 "<html><body><h1>HTTP not possible!<br>OnionCat is running on this port at \"%s.onion\"</h1></body></html>\r\n", 309 OCAT_URL, timestr, onion_url_ 310 ); 311 log_msg(L_INFO, "request seems to be HTTP"); 312 if (send(peer->tcpfd, response, strlen(response), MSG_DONTWAIT) == -1) 313 log_msg(L_ERROR, "could not send html response"); 314 315 return 1; 316 } 317 #endif 318 319 289 320 void *socket_receiver(void *p) 290 321 { … … 405 436 if (!plen) 406 437 { 438 #ifdef HANDLE_HTTP 439 if (handle_http(peer)) 440 { 441 log_msg(L_NOTICE, "closing %d due to HTTP.", peer->tcpfd); 442 close(peer->tcpfd); 443 unlock_peer(peer); 444 lock_peers(); 445 delete_peer(peer); 446 unlock_peers(); 447 } 448 #endif 407 449 log_msg(L_DEBUG, "FRAGBUF RESET!"); 408 450 peer->fraglen = 0; … … 652 694 { 653 695 struct sockaddr_in in; 654 int fd, t ;696 int fd, t, len; 655 697 char buf[FRAME_SIZE], onion[ONION_NAME_SIZE]; 656 698 SocksHdr_t *shdr = (SocksHdr_t*) buf; … … 688 730 shdr->port = htons(ocat_dest_port_); 689 731 shdr->addr.s_addr = htonl(0x00000001); 690 strcpy(buf + sizeof(SocksHdr_t), "tor6"); 691 strcpy(buf + sizeof(SocksHdr_t) + 5, onion); 692 693 if (write(fd, shdr, sizeof(SocksHdr_t) + strlen(onion) + 6) != sizeof(SocksHdr_t) + strlen(onion) + 6) 732 /* 733 strlcpy(buf + sizeof(SocksHdr_t), usrname_, strlen(usrname_) + 1); 734 strlcpy(buf + sizeof(SocksHdr_t) + strlen(usrname_) + 1, onion, sizeof(onion)); 735 */ 736 memcpy(buf + sizeof(SocksHdr_t), usrname_, strlen(usrname_) + 1); 737 memcpy(buf + sizeof(SocksHdr_t) + strlen(usrname_) + 1, onion, strlen(onion) + 1); 738 len = sizeof(SocksHdr_t) + strlen(usrname_) + strlen(onion) + 2; 739 if (write(fd, shdr, len) != len) 694 740 // FIXME: there should be some additional error handling 695 log_msg(L_ERROR, "couldn't write %d bytes to SOCKS connection %d", sizeof(SocksHdr_t) + strlen(onion) + 6, fd);741 log_msg(L_ERROR, "couldn't write %d bytes to SOCKS connection %d", len, fd); 696 742 log_msg(L_DEBUG, "connect request sent"); 697 743 -
trunk/configure.ac
r221 r223 3 3 4 4 AC_PREREQ(2.61) 5 AC_INIT([onioncat], [0.1. 7], [rahra@cypherpunk.at])5 AC_INIT([onioncat], [0.1.8], [rahra@cypherpunk.at]) 6 6 AM_INIT_AUTOMAKE([-Wall -Werror]) 7 7 #AC_CONFIG_SRCDIR([ocatroute.c]) -
trunk/src/ocat.c
r221 r223 40 40 41 41 extern int debug_level_; 42 char *usrname_ = OCAT_UNAME; 43 char onion_url_[ONION_NAME_SIZE]; 44 struct in6_addr ocat_addr_; 42 45 43 46 … … 72 75 int main(int argc, char *argv[]) 73 76 { 74 char tunname[IFNAMSIZ] = "", onion[ONION_NAME_SIZE],*s, ip6addr[INET6_ADDRSTRLEN];75 struct in6_addr addr;77 char tunname[IFNAMSIZ] = "", /*onion[ONION_NAME_SIZE],*/ *s, ip6addr[INET6_ADDRSTRLEN]; 78 //struct in6_addr addr; 76 79 int c, runasroot = 0; 77 char *usrname = OCAT_UNAME;78 80 struct passwd *pwd; 79 81 int urlconv = 0, test_only = 0, controller = 1; … … 128 130 129 131 case 'u': 130 usrname = optarg;132 usrname_ = optarg; 131 133 break; 132 134 … … 149 151 if (urlconv == 2) 150 152 { 151 if (inet_pton(AF_INET6, argv[optind], & addr) <= 0)153 if (inet_pton(AF_INET6, argv[optind], &ocat_addr_) <= 0) 152 154 log_msg(L_ERROR, "%s", strerror(errno)), exit(1); 153 if (!has_tor_prefix(& addr))155 if (!has_tor_prefix(&ocat_addr_)) 154 156 log_msg(L_ERROR, "address does not have TOR prefix"), exit(1); 155 ipv6tonion(& addr, onion);156 printf("%s.onion\n", onion );157 ipv6tonion(&ocat_addr_, onion_url_); 158 printf("%s.onion\n", onion_url_); 157 159 exit(0); 158 160 } 159 161 160 162 // convert parameter to IPv6 address 161 strncpy(onion , argv[optind], ONION_NAME_SIZE);162 if ((s = strchr(onion , '.')))163 strncpy(onion_url_, argv[optind], ONION_NAME_SIZE); 164 if ((s = strchr(onion_url_, '.'))) 163 165 *s = '\0'; 164 if (strlen(onion ) != 16)166 if (strlen(onion_url_) != 16) 165 167 log_msg(L_ERROR, "parameter seems not to be valid onion hostname"), exit(1); 166 if (oniontipv6(onion , &addr) == -1)168 if (oniontipv6(onion_url_, &ocat_addr_) == -1) 167 169 log_msg(L_ERROR, "parameter seems not to be valid onion hostname"), exit(1); 168 170 169 inet_ntop(AF_INET6, & addr, ip6addr, INET6_ADDRSTRLEN);171 inet_ntop(AF_INET6, &ocat_addr_, ip6addr, INET6_ADDRSTRLEN); 170 172 171 173 if (urlconv == 1) … … 179 181 #ifndef WITHOUT_TUN 180 182 // create TUN device 181 tunfd_[0] = tunfd_[1] = tun_alloc(tunname, addr);183 tunfd_[0] = tunfd_[1] = tun_alloc(tunname, ocat_addr_); 182 184 #ifdef TEST_TUN_HDR 183 185 test_tun_hdr(); … … 200 202 { 201 203 errno = 0; 202 if (!(pwd = getpwnam(usrname )))203 log_msg(L_FATAL, "can't get information for user \"%s\": \"%s\"", usrname , errno ? strerror(errno) : "user not found"), exit(1);204 205 log_msg(L_NOTICE, "running as root, changing uid/gid to %s (uid %d/gid %d)", usrname , pwd->pw_uid, pwd->pw_gid);204 if (!(pwd = getpwnam(usrname_))) 205 log_msg(L_FATAL, "can't get information for user \"%s\": \"%s\"", usrname_, errno ? strerror(errno) : "user not found"), exit(1); 206 207 log_msg(L_NOTICE, "running as root, changing uid/gid to %s (uid %d/gid %d)", usrname_, pwd->pw_uid, pwd->pw_gid); 206 208 if (setgid(pwd->pw_gid)) 207 209 log_msg(L_ERROR, "could not change gid: \"%s\"", strerror(errno)), exit(1); -
trunk/src/ocat.h
r221 r223 46 46 #define OCAT_UNAME "tor" 47 47 #define OCAT_UID 112 48 #define OCAT_URL "http://www.abenteuerland.at/onioncat/" 48 49 49 50 //! Maximum frame (packet) size, should be able to keep one maximum size ipv6-packet: 2^16 + 40 + 4 … … 194 195 extern uint16_t ocat_dest_port_; 195 196 extern int vrec_; 196 extern int tunfd_[2];197 197 198 198 #ifndef WITHOUT_TUN … … 204 204 extern pthread_mutex_t thread_mutex_; 205 205 extern OcatThread_t *octh_; 206 extern char *usrname_; 207 208 /* ocat.c */ 209 //extern int tunfd_[2]; 210 extern int tunfd_[]; 211 extern char onion_url_[]; 212 extern struct in6_addr ocat_addr_; 206 213 207 214 /* ocatlog.c */ -
trunk/src/ocatlog.c
r221 r223 29 29 #include "ocat.h" 30 30 31 #define TIMESTRLEN 64 31 32 32 33 int debug_level_ = 4; … … 40 41 time_t t; 41 42 FILE *out = stderr; 42 char timestr[ 32] = "";43 char timestr[TIMESTRLEN] = ""; 43 44 va_list ap; 44 45 const OcatThread_t *th = get_thread(); … … 50 51 tm = localtime(&t); 51 52 if (tm) 52 strftime(timestr, 32, "%c", tm); 53 //strftime(timestr, 32, "%c", tm); 54 strftime(timestr, TIMESTRLEN, "%a, %d %b %Y %H:%M:%S %z", tm); 53 55 54 56 pthread_mutex_lock(&log_mutex_); -
trunk/src/ocatroute.c
r221 r223 287 287 288 288 289 #define HANDLE_HTTP 290 #ifdef HANDLE_HTTP 291 #define BSTRLEN 1024 292 293 int handle_http(const OcatPeer_t *peer) 294 { 295 time_t t; 296 char response[BSTRLEN], timestr[BSTRLEN]; 297 struct tm tm; 298 299 // simple check if packet could be an HTTP request 300 if (strncmp(peer->fragbuf, "GET ", 4)) 301 return 0; 302 303 t = time(NULL); 304 (void) localtime_r(&t, &tm); 305 strftime(timestr, BSTRLEN, "%a, %d %b %Y %H:%M:%S %z", &tm); 306 snprintf(response, BSTRLEN, 307 "HTTP/1.0 301 HTTP not possible\r\nLocation: %s\r\nDate: %s\r\nContent-Type: text/html; charset=iso-8859-1\r\n\r\n" 308 "<html><body><h1>HTTP not possible!<br>OnionCat is running on this port at \"%s.onion\"</h1></body></html>\r\n", 309 OCAT_URL, timestr, onion_url_ 310 ); 311 log_msg(L_INFO, "request seems to be HTTP"); 312 if (send(peer->tcpfd, response, strlen(response), MSG_DONTWAIT) == -1) 313 log_msg(L_ERROR, "could not send html response"); 314 315 return 1; 316 } 317 #endif 318 319 289 320 void *socket_receiver(void *p) 290 321 { … … 405 436 if (!plen) 406 437 { 438 #ifdef HANDLE_HTTP 439 if (handle_http(peer)) 440 { 441 log_msg(L_NOTICE, "closing %d due to HTTP.", peer->tcpfd); 442 close(peer->tcpfd); 443 unlock_peer(peer); 444 lock_peers(); 445 delete_peer(peer); 446 unlock_peers(); 447 } 448 #endif 407 449 log_msg(L_DEBUG, "FRAGBUF RESET!"); 408 450 peer->fraglen = 0; … … 652 694 { 653 695 struct sockaddr_in in; 654 int fd, t ;696 int fd, t, len; 655 697 char buf[FRAME_SIZE], onion[ONION_NAME_SIZE]; 656 698 SocksHdr_t *shdr = (SocksHdr_t*) buf; … … 688 730 shdr->port = htons(ocat_dest_port_); 689 731 shdr->addr.s_addr = htonl(0x00000001); 690 strcpy(buf + sizeof(SocksHdr_t), "tor6"); 691 strcpy(buf + sizeof(SocksHdr_t) + 5, onion); 692 693 if (write(fd, shdr, sizeof(SocksHdr_t) + strlen(onion) + 6) != sizeof(SocksHdr_t) + strlen(onion) + 6) 732 /* 733 strlcpy(buf + sizeof(SocksHdr_t), usrname_, strlen(usrname_) + 1); 734 strlcpy(buf + sizeof(SocksHdr_t) + strlen(usrname_) + 1, onion, sizeof(onion)); 735 */ 736 memcpy(buf + sizeof(SocksHdr_t), usrname_, strlen(usrname_) + 1); 737 memcpy(buf + sizeof(SocksHdr_t) + strlen(usrname_) + 1, onion, strlen(onion) + 1); 738 len = sizeof(SocksHdr_t) + strlen(usrname_) + strlen(onion) + 2; 739 if (write(fd, shdr, len) != len) 694 740 // FIXME: there should be some additional error handling 695 log_msg(L_ERROR, "couldn't write %d bytes to SOCKS connection %d", sizeof(SocksHdr_t) + strlen(onion) + 6, fd);741 log_msg(L_ERROR, "couldn't write %d bytes to SOCKS connection %d", len, fd); 696 742 log_msg(L_DEBUG, "connect request sent"); 697 743
Note: See TracChangeset
for help on using the changeset viewer.
