Changeset 835:2dd85f8453a7 in roaraudio for libroar/socket.c


Ignore:
Timestamp:
09/27/08 02:32:53 (16 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

get a username from the system, send the current user via SOCKS4x

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libroar/socket.c

    r834 r835  
    599599 int    i; 
    600600 int    fh = -1; 
     601 char * user = NULL, * pw = NULL, * opts = NULL; 
     602 static struct passwd * passwd; 
    601603 int (* code)(int mode, int fh, char * host, int port, char * user, char * pw, char * opts) = NULL; 
     604 
     605 if ( passwd == NULL ) { 
     606  passwd = getpwuid(getuid()); 
     607 } 
     608 
     609 if ( passwd != NULL ) 
     610  user = passwd->pw_name; 
     611 
     612 if ( user == NULL ) 
     613  user = getenv("USER"); 
    602614 
    603615 // TODO: change this so we support listen() proxys (ssh -R) 
     
    652664 
    653665 if ( code != NULL ) { 
    654   if ( code(mode, fh, host, port, NULL, NULL, NULL) == -1 ) { 
     666  if ( code(mode, fh, host, port, user, pw, opts) == -1 ) { 
    655667   close(fh); 
    656668   return -1; 
     
    699711int roar_socket_open_socks4x(int mode, int fh, char host[4], int port, char * app, size_t app_len, char * user) { 
    700712 char buf[9]; 
     713 int len; 
    701714 
    702715 buf[0] = 0x04; 
     
    704717 *((uint16_t*)&buf[2]) = htons(port); 
    705718 memcpy(buf+4, host, 4); 
    706  buf[8] = 0x00; 
    707  
    708  if ( write(fh, buf, 9) != 9 ) 
    709   return -1; 
     719 
     720 if ( user == NULL ) { 
     721  buf[8] = 0x00; 
     722  len = 9; 
     723 } else { 
     724  len = 8; 
     725 } 
     726 
     727 if ( write(fh, buf, len) != len ) 
     728  return -1; 
     729 
     730 if ( user != NULL ) { 
     731  len = strlen(user) + 1; 
     732  if ( write(fh, user, len) != len ) 
     733   return -1; 
     734 } 
    710735 
    711736 if ( app_len > 0 ) 
Note: See TracChangeset for help on using the changeset viewer.