Changeset a29e2e492d5b03e2ab7a9aced0d1313f06a650c0

Show
Ignore:
Timestamp:
03/16/10 02:48:40 (2 years ago)
Author:
D.J. Capelis <dev@…>
Parents:
2e3212ee6039755ad0071edde541e432086c0216
Children:
6235648b3ca2df5a61e411548a29f45b2b3f27df
git-committer:
D.J. Capelis <dev@capelis.dj> / 2010-03-16T02:48:40Z-0700
Message:

Cleanup s/_TYPE/_SERVICE/ and implement LIST command, HELP now complaint
with RFC 1078

Files:
3 modified

Legend:

Unmodified
Added
Removed
  • config.c

    r50d3946 ra29e2e4  
    22 
    33struct service help; 
     4struct service list; 
    45struct service multiplex; 
    56struct service ssl; 
     
    2627{ 
    2728    help.name = "HELP\0"; 
    28     help.service_type = HELP_TYPE; 
    29     help.next = &multiplex; 
     29    help.service_type = HELP_SERVICE; 
     30    help.next = &list; 
     31    list.name = "LIST\0"; 
     32    list.service_type = LIST_SERVICE; 
     33    list.next = &multiplex; 
    3034    multiplex.name = "MULTIPLEX\0"; 
    31     multiplex.service_type = MULTIPLEX_TYPE; 
     35    multiplex.service_type = MULTIPLEX_SERVICE; 
    3236    multiplex.next = &ssl; 
    3337    ssl.name = "SSL\0"; 
    34     ssl.service_type = SSL_TYPE; 
     38    ssl.service_type = SSL_SERVICE; 
    3539    ssl.next = &auth; 
    3640    auth.name = "AUTH\0"; 
    37     auth.service_type = AUTH_TYPE; 
     41    auth.service_type = AUTH_SERVICE; 
    3842    auth.next = &host; 
    3943    host.name = "HOST\0"; 
    40     host.service_type = HOST_TYPE; 
     44    host.service_type = HOST_SERVICE; 
    4145    host.next = &shell; 
    4246    shell.name = "SHELL\0"; 
    43     shell.service_type = CUSTOM_TYPE; 
     47    shell.service_type = CUSTOM_SERVICE; 
    4448    inet_pton(AF_INET6, "::ffff:127.0.0.1", &(shellsocket.sin6_addr)); 
    4549    shellsocket.sin6_family=AF_INET6; 
     
    4953    shell.next = &echo; 
    5054    echo.name = "ECHO\0"; 
    51     echo.service_type = CUSTOM_TYPE; 
     55    echo.service_type = CUSTOM_SERVICE; 
    5256    inet_pton(AF_INET6, "::ffff:127.0.0.1", &(shellsocket2.sin6_addr)); 
    5357    shellsocket2.sin6_family=AF_INET6; 
     
    5761    echo.next = &hello; 
    5862    hello.name = "HELLO\0"; 
    59     hello.service_type = CUSTOM_TYPE; 
     63    hello.service_type = CUSTOM_SERVICE; 
    6064    inet_pton(AF_INET6, "::ffff:127.0.0.1", &(s_hello.sin6_addr)); 
    6165    s_hello.sin6_family=AF_INET6; 
     
    6569    hello.next = &web; 
    6670    rot13.name = "ROT13\0"; 
    67     rot13.service_type = CUSTOM_TYPE; 
     71    rot13.service_type = CUSTOM_SERVICE; 
    6872    inet_pton(AF_INET6, "::ffff:127.0.0.1", &(s_rot13.sin6_addr)); 
    6973    s_rot13.sin6_family=AF_INET6; 
     
    7377    rot13.next = &web; 
    7478    web.name = "WEB\0"; 
    75     web.service_type = CUSTOM_TYPE; 
     79    web.service_type = CUSTOM_SERVICE; 
    7680    inet_pton(AF_INET6, "::ffff:127.0.0.1", &(s_web.sin6_addr)); 
    7781    s_web.sin6_family=AF_INET6; 
     
    8185    web.next = &web2; 
    8286    web2.name = "WEB\0"; 
    83     web2.service_type = CUSTOM_TYPE; 
     87    web2.service_type = CUSTOM_SERVICE; 
    8488    inet_pton(AF_INET6, "::ffff:127.0.0.1", &(s_web2.sin6_addr)); 
    8589    s_web2.sin6_family=AF_INET6; 
  • handler.c

    r50d3946 ra29e2e4  
    1717    int multiplex = 0; 
    1818    struct service * service = NULL; 
     19    struct service * listservice = NULL; 
    1920    int i = 0; 
    2021    int outsock = 0; 
     
    9697        service = parse(&offset, &size, getbuffer, buffer, user, host); 
    9798 
    98         if(service == -1) 
     99        if(service == (void *) -1) 
    99100            continue; 
    100101 
     
    114115        } 
    115116 
    116         if(service->service_type == HELP_TYPE) 
     117        if(service->service_type == HELP_SERVICE || service->service_type == LIST_SERVICE) 
    117118        { 
    118119            i = 0; 
    119120            response = calloc(BUFFER, sizeof(char)); 
    120             service = servicelist->next; 
    121             while(service) 
    122             { 
    123                 if((service->service_type == SSL_TYPE && ssl) || (service->service_type == MULTIPLEX_TYPE && multiplex)) 
    124                 { 
    125                     service = service->next; 
     121            listservice = servicelist; 
     122            while(listservice) 
     123            { 
     124                if((listservice->service_type == HELP_SERVICE || listservice->service_type == LIST_SERVICE)) 
     125                { 
     126                    listservice = listservice->next; 
    126127                    continue; 
    127128                } 
    128                 if(service->restrict_user != NULL) 
    129                 { 
    130                     if(user == NULL || service->restrict_user == NULL) 
    131                     { 
    132                         service = service->next; 
     129                if((listservice->service_type == SSL_SERVICE && ssl) || (listservice->service_type == MULTIPLEX_SERVICE && multiplex)) 
     130                { 
     131                    listservice = listservice->next; 
     132                    continue; 
     133                } 
     134                if(listservice->restrict_user != NULL) 
     135                { 
     136                    if(user == NULL || listservice->restrict_user == NULL) 
     137                    { 
     138                        listservice = listservice->next; 
    133139                        continue; 
    134140                    } 
    135                     if(strcmp(user, service->restrict_user)) 
    136                     { 
    137                         service = service->next; 
     141                    if(strcmp(user, listservice->restrict_user)) 
     142                    { 
     143                        listservice = listservice->next; 
    138144                        continue; 
    139145                    } 
    140146                } 
    141                 if(service->restrict_host != NULL) 
    142                 { 
    143                     if(host == NULL || service->restrict_host == NULL) 
    144                     { 
    145                         service = service->next; 
     147                if(listservice->restrict_host != NULL) 
     148                { 
     149                    if(host == NULL || listservice->restrict_host == NULL) 
     150                    { 
     151                        listservice = listservice->next; 
    146152                        continue; 
    147153                    } 
    148                     if(strcmp(host, service->restrict_host)) 
    149                     { 
    150                         service = service->next; 
     154                    if(strcmp(host, listservice->restrict_host)) 
     155                    { 
     156                        listservice = listservice->next; 
    151157                        continue; 
    152158                    } 
    153159                } 
    154                 i += strlen(service->name) + 2; 
     160                i += strlen(listservice->name) + 2; 
    155161                if(i > BUFFER) 
    156162                    response = realloc(response, i); 
    157                 strcat(response+i-(strlen(service->name)+2), service->name); 
     163                strcat(response+i-(strlen(listservice->name)+2), listservice->name); 
    158164                response[i-1] = '\n'; 
    159165                response[i-2] = '\r'; 
    160                 service = service->next; 
    161                 //TODO: Access control 
     166                listservice = listservice->next; 
    162167            } 
    163168            if(multiplex) 
     
    168173                SSL_write(ssl, response, i); 
    169174            free(response); 
     175            if(service->service_type == HELP_SERVICE) 
     176                goto kill; 
    170177            if(mode) 
    171178                goto process; 
     
    174181        } 
    175182 
    176         if(service->service_type == MULTIPLEX_TYPE) 
     183        if(service->service_type == MULTIPLEX_SERVICE) 
    177184        { 
    178185            if(multiplex) 
     
    198205        } 
    199206 
    200         if(service->service_type == SSL_TYPE) 
     207        if(service->service_type == SSL_SERVICE) 
    201208        { 
    202209            //TODO: OpenSSL is not re-entrant, care about that. 
     
    264271 
    265272        /* Imagine the most minimalistic demo-driven auth service you could think of... this is a hair below that */ 
    266         if(service->service_type == AUTH_TYPE) 
     273        if(service->service_type == AUTH_SERVICE) 
    267274        { 
    268275            if(multiplex) 
     
    329336        } 
    330337 
    331         if(service->service_type == HOST_TYPE) 
     338        if(service->service_type == HOST_SERVICE) 
    332339        { 
    333340            if(multiplex) 
     
    367374        } 
    368375 
    369         if(service->service_type == CUSTOM_TYPE) 
     376        if(service->service_type == CUSTOM_SERVICE) 
    370377        { 
    371378            // TODO: access control 
  • main.h

    r5e6da2c ra29e2e4  
    2828 
    2929/* defines */ 
    30 #define HELP_TYPE 1 
    31 #define MULTIPLEX_TYPE 2 
    32 #define SSL_TYPE 3 
    33 #define AUTH_TYPE 4 
    34 #define HOST_TYPE 5 
    35 #define CUSTOM_TYPE -1 
     30#define HELP_SERVICE 1 
     31#define LIST_SERVICE 2 
     32#define MULTIPLEX_SERVICE 3 
     33#define SSL_SERVICE 4 
     34#define AUTH_SERVICE 5 
     35#define HOST_SERVICE 6 
     36#define CUSTOM_SERVICE -1 
    3637 
    3738/* Forward declarations */