Changeset 2637

Show
Ignore:
Timestamp:
02/08/09 12:17:37 (2 years ago)
Author:
kuhlmann
Message:

move socks 5 settings to connection specific options

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • climm/doc/climmrc.5

    r2628 r2637  
    122122Remote control FIFOs do not use this setting. 
    123123.RE 
    124 .SH GENERAL 
    125 The 
    126 .B General 
    127 section includes the options for SOCKS 5, that may be eventually 
    128 moved to their own section, general options, and some strings to override. 
    129 .TP 
    130 .BI s5_use \ <number> 
    131 Set 
    132 .I number 
    133 to 0 to disable and 1 to enable. 
     124.TP 
     125.BI options \ <options> 
     126Define options for this server connection. These give default values for the 
     127contacts belonging to this server connection, as well as the following 
     128server specific settings: 
     129.RS 
     130.TP 
     131.BI s5_use 
     132Enable the use of a socks 5 proxy. 
    134133.TP 
    135134.BI s5_host \ <host> 
     
    140139Connect to socks 5 proxy listening on port 
    141140.IR port . 
    142 .TP 
    143 .BI s5_auth \ <number> 
    144 Set 
    145 .I number 
    146 to 0 to omit authentication and 1 to do authentication. 
    147141.TP 
    148142.BI s5_name \ <name> 
     
    155149.I password 
    156150to socks 5 proxy. 
     151.RE 
     152.SH GENERAL 
     153The 
     154.B General 
     155section includes general options and some strings to override. 
    157156.PP 
    158157A few book-keeping options are usually placed at the beginning of 
  • climm/include/connection.h

    r2574 r2637  
    131131UWORD          ConnectionServerNType (const char *type, char del); 
    132132val_t          ConnectionPrefVal (Server *conn, UDWORD flag); 
     133const char    *ConnectionPrefStr (Server *conn, UDWORD flag); 
    133134 
    134135#define ConnectionC(t)       ConnectionC (t DEBUGARGS) 
  • climm/include/preferences.h

    r2488 r2637  
    99struct Preferences_s 
    1010{ 
    11     char  *s5Host;      /* socks 5 settings */ 
    12     char  *s5Name; 
    13     char  *s5Pass; 
    14     UWORD  s5Port; 
    15     BOOL   s5Use; 
    16     BOOL   s5Auth; 
    17  
    1811    char  *locale;      /* the used locale (stripped of encoding) */ 
    1912    char  *locale_orig; /* the original locale (as from ENV) */ 
     
    4336    SBYTE  autoupdate; 
    4437 
    45     char  *prompt_strftime;    /* user define prompt */ 
    46     char  *prompt;             /* user define prompt */ 
     38    char  *prompt_strftime;    /* user defined prompt */ 
     39    char  *prompt;             /* user defined prompt */ 
    4740 
    4841#ifdef ENABLE_TCL 
  • climm/include/util_opts.h

    r2536 r2637  
    8888 
    8989#define CO_SCRIPT        (COF_BOOL    | CO_GLOBAL  | 0x000104UL) /* open a scripting connection       */ 
     90#define CO_S5USE         (COF_BOOL    | CO_SERVER  | 0x000404UL) /* use Socks 5 proxy                 */ 
    9091 
    9192#define CO_ENCODING      (COF_NUMERIC | CO_CONTACT | 0x06UL) /* the default encoding for this contact */ 
     
    119120 
    120121#define CO_OTRPOLICY     (COF_STRING  | CO_CONTACT | 0x40UL) /* OTR policy for a contact */ 
     122 
     123#define CO_S5HOST        (COF_STRING  | CO_SERVER  | 0x50UL) /* the Socks 5 host */ 
     124#define CO_S5PORT        (COF_NUMERIC | CO_SERVER  | 0x51UL) /* the Socks 5 port */ 
     125#define CO_S5NAME        (COF_STRING  | CO_SERVER  | 0x52UL) /* the Socks 5 user name */ 
     126#define CO_S5PASS        (COF_STRING  | CO_SERVER  | 0x53UL) /* the Socks 5 user password */ 
    121127 
    122128#define CO_COLORNONE     (COF_COLOR   | CO_GLOBAL  | 0x80UL) /* the escape sequence to print for no color              */ 
  • climm/src/connection.c

    r2601 r2637  
    504504} 
    505505 
     506/* 
     507 * Query an option for a contact group 
     508 */ 
     509const char *ConnectionPrefStr (Server *serv, UDWORD flag) 
     510{ 
     511    const char *res = 0; 
     512    if (serv->contacts && OptGetStr (&serv->copts, flag, &res)) 
     513        return res; 
     514    if (OptGetStr (&prG->copts, flag, &res)) 
     515        return res; 
     516    return 0; 
     517} 
     518 
  • climm/src/file_util.c

    r2598 r2637  
    237237    } 
    238238 
    239     prG->s5Use = 0; 
    240     prG->s5Port = 0; 
    241  
    242239    rl_print (i18n (1784, "If you are firewalled, you may need to use a SOCKS5 server. If you do, please enter its hostname or IP address. Otherwise, or if unsure, just press return.\n")); 
    243240    rl_printf ("%s ", i18n (1094, "SOCKS5 server:")); 
     
    249246        if (strchr (line->txt, ':')) 
    250247        { 
    251             prG->s5Host = strdup (line->txt); 
    252             t = strchr (prG->s5Host, ':'); 
    253             prG->s5Port = atoi (t + 1); 
     248            char *tmp = strdup (line->txt); 
     249            t = strchr (tmp, ':'); 
     250            OptSetVal (&prG->copts, CO_S5PORT, atoi (t + 1)); 
    254251            *t = '\0'; 
     252            OptSetStr (&prG->copts, CO_S5HOST, tmp); 
     253            free (tmp); 
    255254        } 
    256255        else 
    257256        { 
    258             prG->s5Host = strdup (line->txt); 
     257            UWORD p = 0; 
     258            OptSetStr (&prG->copts, CO_S5HOST, line->txt); 
    259259            rl_print (i18n (1786, "I also need the port the socks server listens on. If unsure, press return for the default port.\n")); 
    260260            rl_printf ("%s ", i18n (1095, "SOCKS5 port:")); 
     
    262262            line = UtilIOReadline (stdin); 
    263263            if (line) 
    264                 sscanf (line->txt, "%hu", &prG->s5Port); 
     264                sscanf (line->txt, "%hu", &p); 
     265            if (!p) 
     266                p = 1080; 
     267            OptSetVal (&prG->copts, CO_S5PORT, p); 
    265268        } 
    266         if (!prG->s5Port) 
    267             prG->s5Port = 1080; 
    268  
    269         prG->s5Use = 1; 
    270         prG->s5Auth = 0; 
    271         prG->s5Pass = NULL; 
    272         prG->s5Name = NULL; 
     269        OptSetVal (&prG->copts, CO_S5USE, 1); 
    273270 
    274271        rl_print ("\n"); 
     
    279276        if (line && line->len) 
    280277        { 
    281             prG->s5Auth = 1; 
    282             prG->s5Name = strdup (line->txt); 
     278            OptSetStr (&prG->copts, CO_S5NAME, line->txt); 
    283279            rl_print (i18n (1788, "Now I also need the password for this user.\n")); 
    284280            rl_printf ("%s ", i18n (1097, "SOCKS5 password:")); 
     
    286282            line = UtilIOReadline (stdin); 
    287283            if (line && line->len) 
    288                 prG->s5Pass = strdup (line->txt); 
     284                OptSetStr (&prG->copts, CO_S5PASS, line->txt); 
    289285        } 
    290286    } 
     
    531527                { 
    532528                    PrefParseInt (i); 
    533                     prG->s5Use = i; 
     529                    OptSetVal (&prG->copts, CO_S5USE, i ? 1 : 0); 
     530                    dep = 55; 
    534531                } 
    535532                else if (!strcasecmp (cmd, "s5_host")) 
    536533                { 
    537534                    PrefParse (tmp); 
    538                     prG->s5Host = strdup (tmp); 
     535                    OptSetStr (&prG->copts, CO_S5HOST, tmp); 
     536                    dep = 55; 
    539537                } 
    540538                else if (!strcasecmp (cmd, "s5_port")) 
    541539                { 
    542540                    PrefParseInt (i); 
    543                     prG->s5Port = i; 
     541                    OptSetVal (&prG->copts, CO_S5PORT, i); 
     542                    dep = 55; 
    544543                } 
    545544                else if (!strcasecmp (cmd, "s5_auth")) 
    546545                { 
    547546                    PrefParseInt (i); 
    548                     prG->s5Auth = i
     547                    dep = 55
    549548                } 
    550549                else if (!strcasecmp (cmd, "s5_name")) 
    551550                { 
    552551                    PrefParse (tmp); 
    553                     prG->s5Name = strdup (tmp); 
     552                    OptSetStr (&prG->copts, CO_S5NAME, tmp); 
     553                    dep = 55; 
    554554                } 
    555555                else if (!strcasecmp (cmd, "s5_pass")) 
    556556                { 
    557557                    PrefParse (tmp); 
    558                     prG->s5Pass = strdup (tmp); 
     558                    OptSetStr (&prG->copts, CO_S5PASS, tmp); 
     559                    dep = 55; 
    559560                } 
    560561                else if (!strcasecmp (cmd, "verbose")) 
     
    12541255            case TYPE_SERVER: 
    12551256                serv->c_open = &ConnectionInitServer; 
    1256                 if (prG->s5Use && !serv->pref_version) 
     1257                if (!serv->pref_version) 
    12571258                    serv->pref_version = 2; 
    12581259                break; 
     
    17611762    } 
    17621763 
    1763     fprintf (rcf, "\n[General]\n# Support for SOCKS5 server\n"); 
    1764     fprintf (rcf, "s5_use %d\n", prG->s5Use); 
    1765     if (!prG->s5Host) 
    1766         fprintf (rcf, "s5_host \"[none]\"\n"); 
    1767     else 
    1768         fprintf (rcf, "s5_host %s\n", s_quote (prG->s5Host)); 
    1769     fprintf (rcf, "s5_port %d\n", prG->s5Port); 
    1770     fprintf (rcf, "# If you need authentication, put 1 for s5_auth and fill your name/password\n"); 
    1771     fprintf (rcf, "s5_auth %d\n", prG->s5Auth); 
    1772     if (!prG->s5Name) 
    1773         fprintf (rcf, "s5_name \"[none]\"\n"); 
    1774     else 
    1775         fprintf (rcf, "s5_name %s\n", s_quote (prG->s5Name)); 
    1776     if (!prG->s5Pass) 
    1777         fprintf (rcf, "s5_pass \"[none]\"\n"); 
    1778     else 
    1779         fprintf (rcf, "s5_pass %s\n", s_quote (prG->s5Pass)); 
    1780  
     1764    fprintf (rcf, "\n[General]\n"); 
    17811765    fprintf (rcf, "\n#in seconds\nauto_away %lu\n", UD2UL (prG->away_time)); 
    17821766    fprintf (rcf, "\n#For dumb terminals that don't wrap set this."); 
  • climm/src/oscar_dc.c

    r2567 r2637  
    282282    peer->dispatch    = &TCPDispatchShake; 
    283283 
    284     if (prG->s5Use
     284    if (ConnectionPrefVal (list->serv, CO_S5USE)
    285285    { 
    286286        peer->sok = list->sok; 
  • climm/src/util_io.c

    r2574 r2637  
    113113        rl_print (i18n (1056, "Socket created, attempting to connect.\n")); 
    114114 
    115     if (prG->s5Use
     115    if (ConnectionPrefVal (conn->serv, CO_S5USE)
    116116    { 
    117117        sin.sin_addr.s_addr = INADDR_ANY; 
     
    131131        s5OurPort = ntohs (sin.sin_port); 
    132132 
    133         s5sin.sin_addr.s_addr = inet_addr (prG->s5Host); 
     133        s5sin.sin_addr.s_addr = inet_addr (ConnectionPrefStr (conn->serv, CO_S5HOST)); 
    134134        if (!~s5sin.sin_addr.s_addr)        /* name isn't n.n.n.n so must be DNS */ 
    135135        { 
    136             host_struct = gethostbyname (prG->s5Host); 
     136            host_struct = gethostbyname (ConnectionPrefStr (conn->serv, CO_S5HOST)); 
    137137            if (!host_struct) 
    138138            { 
    139139                if (prG->verbose || (conn->serv && conn == conn->serv->conn)) 
    140140                { 
    141                     rl_printf (i18n (1596, "[SOCKS] Can't find hostname %s: %s."), prG->s5Host, hstrerror (h_errno)); 
     141                    rl_printf (i18n (1596, "[SOCKS] Can't find hostname %s: %s."), ConnectionPrefStr (conn->serv, CO_S5HOST), hstrerror (h_errno)); 
    142142                    rl_print ("\n"); 
    143143                } 
     
    148148        } 
    149149        s5sin.sin_family = AF_INET;     /* we're using the inet not appletalk */ 
    150         s5sin.sin_port = htons (prG->s5Port);        /* port */ 
     150        s5sin.sin_port = htons (ConnectionPrefVal (conn->serv, CO_S5PORT));        /* port */ 
    151151        s5Sok = socket (AF_INET, SOCK_STREAM, 0);       /* create the unconnected socket */ 
    152152        if (s5Sok < 0) 
     
    170170        buf[0] = 5;             /* protocol version */ 
    171171        buf[1] = 1;             /* number of methods */ 
    172         if (!*prG->s5Name || !*prG->s5Pass || !prG->s5Auth
     172        if (!ConnectionPrefStr (conn->serv, CO_S5NAME) || !ConnectionPrefStr (conn->serv, CO_S5PASS)
    173173            buf[2] = 0;         /* no authorization required */ 
    174174        else 
     
    176176        send (s5Sok, buf, 3, 0); 
    177177        res = recv (s5Sok, buf, 2, 0); 
    178         if (strlen (prG->s5Name) && strlen (prG->s5Pass) && prG->s5Auth
     178        if (buf[2]
    179179        { 
    180180            if (res != 2 || buf[0] != 5 || buf[1] != 2) /* username/password authentication */ 
     
    190190            } 
    191191            buf[0] = 1;         /* version of subnegotiation */ 
    192             buf[1] = strlen (prG->s5Name); 
    193             memcpy (&buf[2], prG->s5Name, buf[1]); 
    194             buf[2 + buf[1]] = strlen (prG->s5Pass); 
    195             memcpy (&buf[3 + buf[1]], prG->s5Pass, buf[2 + buf[1]]); 
     192            buf[1] = strlen (ConnectionPrefStr (conn->serv, CO_S5NAME)); 
     193            memcpy (&buf[2], ConnectionPrefStr (conn->serv, CO_S5NAME), buf[1]); 
     194            buf[2 + buf[1]] = strlen (ConnectionPrefStr (conn->serv, CO_S5PASS)); 
     195            memcpy (&buf[3 + buf[1]], ConnectionPrefStr (conn->serv, CO_S5PASS), buf[2 + buf[1]]); 
    196196            send (s5Sok, buf, buf[1] + buf[2 + buf[1]] + 3, 0); 
    197197            res = recv (s5Sok, buf, 2, 0); 
     
    267267    sin.sin_port = htons (conn->port); 
    268268 
    269     if (prG->s5Use
     269    if (ConnectionPrefVal (conn->serv, CO_S5USE)
    270270    { 
    271271        memcpy (&sin.sin_addr.s_addr, &buf[4], 4); 
     
    357357    if (rc == -1) 
    358358        CONN_FAIL_RC (i18n (1950, "Couldn't set socket nonblocking")); 
    359     if (conn->server || conn->ip || prG->s5Use
    360     { 
    361         if (prG->s5Use
     359    if (conn->server || conn->ip || ConnectionPrefVal (conn->serv, CO_S5USE)
     360    { 
     361        if (ConnectionPrefVal (conn->serv, CO_S5USE) && ConnectionPrefStr (conn->serv, CO_S5HOST)
    362362        { 
    363363            origserver = conn->server; 
    364364            origip     = conn->ip; 
    365365            origport   = conn->port; 
    366             conn->server = prG->s5Host
    367             conn->port   = prG->s5Port
     366            conn->server = strdup (ConnectionPrefStr (conn->serv, CO_S5HOST))
     367            conn->port   = ConnectionPrefVal (conn->serv, CO_S5PORT)
    368368            conn->ip     = -1; 
    369369        } 
     
    387387        sin.sin_addr.s_addr = htonl (conn->ip); 
    388388         
    389         if (prG->s5Use) 
    390         { 
     389        if (ConnectionPrefVal (conn->serv, CO_S5USE)) 
     390        { 
     391            free (conn->server); 
    391392            conn->server = origserver; 
    392393            conn->port   = origport; 
     
    409410                if (rl_pos () > 0) 
    410411                     rl_print (i18n (1634, "ok.\n")); 
    411             if (prG->s5Use
     412            if (ConnectionPrefVal (conn->serv, CO_S5USE)
    412413            { 
    413414                QueueEnqueueData (conn, QUEUE_CON_TIMEOUT, conn->ip, 
     
    572573                conn->connect += CONNECT_SOCKS_ADD; 
    573574            case 1: 
    574                 if (!prG->s5Use
     575                if (!ConnectionPrefVal (conn->serv, CO_S5USE)
    575576                    CONN_OK 
    576577 
     
    578579                conn->connect |= CONNECT_SELECT_R; 
    579580                conn->connect &= ~CONNECT_SELECT_W & ~CONNECT_SELECT_X; 
    580                 sockwrite (conn->sok, prG->s5Auth ? "\x05\x02\x02\x00" : "\x05\x01\x00", prG->s5Auth ? 4 : 3); 
     581                if (ConnectionPrefVal (conn->serv, CO_S5NAME) && ConnectionPrefVal (conn->serv, CO_S5PASS)) 
     582                    sockwrite (conn->sok, "\x05\x02\x02\x00", 4); 
     583                else 
     584                    sockwrite (conn->sok, "\x05\x01\x00", 3); 
    581585                return; 
    582586            case 2: 
    583587                rc = sockread (conn->sok, buf, 2); 
    584588                CONN_CHECK (i18n (1601, "[SOCKS] General SOCKS server failure")); 
    585                 if (buf[0] != 5 || !(buf[1] == 0 || (buf[1] == 2 && prG->s5Auth))) 
     589                if (buf[0] != 5 || !(buf[1] == 0 || (buf[1] == 2 && ConnectionPrefVal (conn->serv, CO_S5NAME) && ConnectionPrefVal (conn->serv, CO_S5PASS)))) 
    586590                    CONN_FAIL (i18n (1599, "[SOCKS] Authentication method incorrect")); 
    587591 
     
    589593                if (buf[1] == 2) 
    590594                { 
    591                     snprintf (buf, sizeof (buf), "%c%c%s%c%s%n", 1, (char) strlen (prG->s5Name),  
    592                               prG->s5Name, (char) strlen (prG->s5Pass), prG->s5Pass, &len); 
     595                    snprintf (buf, sizeof (buf), "%c%c%s%c%s%n", 1, (char) strlen (ConnectionPrefStr (conn->serv, CO_S5NAME)),  
     596                              ConnectionPrefStr (conn->serv, CO_S5NAME), (char) strlen (ConnectionPrefStr (conn->serv, CO_S5PASS)), ConnectionPrefStr (conn->serv, CO_S5NAME), &len); 
    593597                    sockwrite (conn->sok, buf, len); 
    594598                    return; 
     
    934938    UBYTE *body = NULL, *data = pak->data; 
    935939 
    936     if (prG->s5Use
     940    if (ConnectionPrefVal (conn->serv, CO_S5USE)
    937941    { 
    938942        s5len = 10; 
     
    965969    int s5len; 
    966970     
    967     s5len = prG->s5Use ? 10 : 0; 
     971    s5len = ConnectionPrefVal (conn->serv, CO_S5USE) ? 10 : 0; 
    968972    pak = PacketC (); 
    969973     
    970     pak->len = sockread (conn->sok, prG->s5Use ? pak->socks : pak->data, sizeof (pak->data) + s5len); 
     974    pak->len = sockread (conn->sok, ConnectionPrefVal (conn->serv, CO_S5USE) ? pak->socks : pak->data, sizeof (pak->data) + s5len); 
    971975     
    972976    if (pak->len <= 4 + s5len || pak->len == (UWORD)-1) 
  • climm/src/util_opts.c

    r2636 r2637  
    9696  { "scripting",     CO_SCRIPT        }, 
    9797  { "scriptingpath", CO_SCRIPT_PATH   }, 
     98  { "s5_use",        CO_S5USE         }, 
     99  { "s5_port",       CO_S5PORT        }, 
     100  { "s5_host",       CO_S5HOST        }, 
     101  { "s5_name",       CO_S5NAME        }, 
     102  { "s5_pass",       CO_S5PASS        }, 
    98103#ifdef ENABLE_OTR 
    99104  { "otrpolicy",     CO_OTRPOLICY     },