Changeset a29e2e492d5b03e2ab7a9aced0d1313f06a650c0
- 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:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r50d3946
|
ra29e2e4
|
|
| 2 | 2 | |
| 3 | 3 | struct service help; |
| | 4 | struct service list; |
| 4 | 5 | struct service multiplex; |
| 5 | 6 | struct service ssl; |
| … |
… |
|
| 26 | 27 | { |
| 27 | 28 | 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; |
| 30 | 34 | multiplex.name = "MULTIPLEX\0"; |
| 31 | | multiplex.service_type = MULTIPLEX_TYPE; |
| | 35 | multiplex.service_type = MULTIPLEX_SERVICE; |
| 32 | 36 | multiplex.next = &ssl; |
| 33 | 37 | ssl.name = "SSL\0"; |
| 34 | | ssl.service_type = SSL_TYPE; |
| | 38 | ssl.service_type = SSL_SERVICE; |
| 35 | 39 | ssl.next = &auth; |
| 36 | 40 | auth.name = "AUTH\0"; |
| 37 | | auth.service_type = AUTH_TYPE; |
| | 41 | auth.service_type = AUTH_SERVICE; |
| 38 | 42 | auth.next = &host; |
| 39 | 43 | host.name = "HOST\0"; |
| 40 | | host.service_type = HOST_TYPE; |
| | 44 | host.service_type = HOST_SERVICE; |
| 41 | 45 | host.next = &shell; |
| 42 | 46 | shell.name = "SHELL\0"; |
| 43 | | shell.service_type = CUSTOM_TYPE; |
| | 47 | shell.service_type = CUSTOM_SERVICE; |
| 44 | 48 | inet_pton(AF_INET6, "::ffff:127.0.0.1", &(shellsocket.sin6_addr)); |
| 45 | 49 | shellsocket.sin6_family=AF_INET6; |
| … |
… |
|
| 49 | 53 | shell.next = &echo; |
| 50 | 54 | echo.name = "ECHO\0"; |
| 51 | | echo.service_type = CUSTOM_TYPE; |
| | 55 | echo.service_type = CUSTOM_SERVICE; |
| 52 | 56 | inet_pton(AF_INET6, "::ffff:127.0.0.1", &(shellsocket2.sin6_addr)); |
| 53 | 57 | shellsocket2.sin6_family=AF_INET6; |
| … |
… |
|
| 57 | 61 | echo.next = &hello; |
| 58 | 62 | hello.name = "HELLO\0"; |
| 59 | | hello.service_type = CUSTOM_TYPE; |
| | 63 | hello.service_type = CUSTOM_SERVICE; |
| 60 | 64 | inet_pton(AF_INET6, "::ffff:127.0.0.1", &(s_hello.sin6_addr)); |
| 61 | 65 | s_hello.sin6_family=AF_INET6; |
| … |
… |
|
| 65 | 69 | hello.next = &web; |
| 66 | 70 | rot13.name = "ROT13\0"; |
| 67 | | rot13.service_type = CUSTOM_TYPE; |
| | 71 | rot13.service_type = CUSTOM_SERVICE; |
| 68 | 72 | inet_pton(AF_INET6, "::ffff:127.0.0.1", &(s_rot13.sin6_addr)); |
| 69 | 73 | s_rot13.sin6_family=AF_INET6; |
| … |
… |
|
| 73 | 77 | rot13.next = &web; |
| 74 | 78 | web.name = "WEB\0"; |
| 75 | | web.service_type = CUSTOM_TYPE; |
| | 79 | web.service_type = CUSTOM_SERVICE; |
| 76 | 80 | inet_pton(AF_INET6, "::ffff:127.0.0.1", &(s_web.sin6_addr)); |
| 77 | 81 | s_web.sin6_family=AF_INET6; |
| … |
… |
|
| 81 | 85 | web.next = &web2; |
| 82 | 86 | web2.name = "WEB\0"; |
| 83 | | web2.service_type = CUSTOM_TYPE; |
| | 87 | web2.service_type = CUSTOM_SERVICE; |
| 84 | 88 | inet_pton(AF_INET6, "::ffff:127.0.0.1", &(s_web2.sin6_addr)); |
| 85 | 89 | s_web2.sin6_family=AF_INET6; |
-
|
r50d3946
|
ra29e2e4
|
|
| 17 | 17 | int multiplex = 0; |
| 18 | 18 | struct service * service = NULL; |
| | 19 | struct service * listservice = NULL; |
| 19 | 20 | int i = 0; |
| 20 | 21 | int outsock = 0; |
| … |
… |
|
| 96 | 97 | service = parse(&offset, &size, getbuffer, buffer, user, host); |
| 97 | 98 | |
| 98 | | if(service == -1) |
| | 99 | if(service == (void *) -1) |
| 99 | 100 | continue; |
| 100 | 101 | |
| … |
… |
|
| 114 | 115 | } |
| 115 | 116 | |
| 116 | | if(service->service_type == HELP_TYPE) |
| | 117 | if(service->service_type == HELP_SERVICE || service->service_type == LIST_SERVICE) |
| 117 | 118 | { |
| 118 | 119 | i = 0; |
| 119 | 120 | 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; |
| 126 | 127 | continue; |
| 127 | 128 | } |
| 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; |
| 133 | 139 | continue; |
| 134 | 140 | } |
| 135 | | if(strcmp(user, service->restrict_user)) |
| 136 | | { |
| 137 | | service = service->next; |
| | 141 | if(strcmp(user, listservice->restrict_user)) |
| | 142 | { |
| | 143 | listservice = listservice->next; |
| 138 | 144 | continue; |
| 139 | 145 | } |
| 140 | 146 | } |
| 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; |
| 146 | 152 | continue; |
| 147 | 153 | } |
| 148 | | if(strcmp(host, service->restrict_host)) |
| 149 | | { |
| 150 | | service = service->next; |
| | 154 | if(strcmp(host, listservice->restrict_host)) |
| | 155 | { |
| | 156 | listservice = listservice->next; |
| 151 | 157 | continue; |
| 152 | 158 | } |
| 153 | 159 | } |
| 154 | | i += strlen(service->name) + 2; |
| | 160 | i += strlen(listservice->name) + 2; |
| 155 | 161 | if(i > BUFFER) |
| 156 | 162 | response = realloc(response, i); |
| 157 | | strcat(response+i-(strlen(service->name)+2), service->name); |
| | 163 | strcat(response+i-(strlen(listservice->name)+2), listservice->name); |
| 158 | 164 | response[i-1] = '\n'; |
| 159 | 165 | response[i-2] = '\r'; |
| 160 | | service = service->next; |
| 161 | | //TODO: Access control |
| | 166 | listservice = listservice->next; |
| 162 | 167 | } |
| 163 | 168 | if(multiplex) |
| … |
… |
|
| 168 | 173 | SSL_write(ssl, response, i); |
| 169 | 174 | free(response); |
| | 175 | if(service->service_type == HELP_SERVICE) |
| | 176 | goto kill; |
| 170 | 177 | if(mode) |
| 171 | 178 | goto process; |
| … |
… |
|
| 174 | 181 | } |
| 175 | 182 | |
| 176 | | if(service->service_type == MULTIPLEX_TYPE) |
| | 183 | if(service->service_type == MULTIPLEX_SERVICE) |
| 177 | 184 | { |
| 178 | 185 | if(multiplex) |
| … |
… |
|
| 198 | 205 | } |
| 199 | 206 | |
| 200 | | if(service->service_type == SSL_TYPE) |
| | 207 | if(service->service_type == SSL_SERVICE) |
| 201 | 208 | { |
| 202 | 209 | //TODO: OpenSSL is not re-entrant, care about that. |
| … |
… |
|
| 264 | 271 | |
| 265 | 272 | /* 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) |
| 267 | 274 | { |
| 268 | 275 | if(multiplex) |
| … |
… |
|
| 329 | 336 | } |
| 330 | 337 | |
| 331 | | if(service->service_type == HOST_TYPE) |
| | 338 | if(service->service_type == HOST_SERVICE) |
| 332 | 339 | { |
| 333 | 340 | if(multiplex) |
| … |
… |
|
| 367 | 374 | } |
| 368 | 375 | |
| 369 | | if(service->service_type == CUSTOM_TYPE) |
| | 376 | if(service->service_type == CUSTOM_SERVICE) |
| 370 | 377 | { |
| 371 | 378 | // TODO: access control |
-
|
r5e6da2c
|
ra29e2e4
|
|
| 28 | 28 | |
| 29 | 29 | /* 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 |
| 36 | 37 | |
| 37 | 38 | /* Forward declarations */ |