2010-03-25 17:46:16 +02:00
|
|
|
/*
|
|
|
|
* uhttpd - Tiny single-threaded httpd - Main component
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010 Jo-Philipp Wich <xm@subsignal.org>
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define _XOPEN_SOURCE 500 /* crypt() */
|
|
|
|
|
|
|
|
#include "uhttpd.h"
|
|
|
|
#include "uhttpd-utils.h"
|
|
|
|
#include "uhttpd-file.h"
|
|
|
|
|
|
|
|
#ifdef HAVE_CGI
|
|
|
|
#include "uhttpd-cgi.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_LUA
|
|
|
|
#include "uhttpd-lua.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_TLS
|
|
|
|
#include "uhttpd-tls.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
static int run = 1;
|
|
|
|
|
|
|
|
static void uh_sigterm(int sig)
|
|
|
|
{
|
|
|
|
run = 0;
|
|
|
|
}
|
|
|
|
|
2010-07-23 16:15:22 +03:00
|
|
|
static void uh_config_parse(struct config *conf)
|
2010-03-25 17:46:16 +02:00
|
|
|
{
|
|
|
|
FILE *c;
|
|
|
|
char line[512];
|
2010-08-14 03:54:24 +03:00
|
|
|
char *col1 = NULL;
|
|
|
|
char *col2 = NULL;
|
2010-03-25 17:46:16 +02:00
|
|
|
char *eol = NULL;
|
|
|
|
|
2010-07-23 16:15:22 +03:00
|
|
|
const char *path = conf->file ? conf->file : "/etc/httpd.conf";
|
|
|
|
|
|
|
|
|
2012-05-03 20:19:22 +03:00
|
|
|
if ((c = fopen(path, "r")) != NULL)
|
2010-03-25 17:46:16 +02:00
|
|
|
{
|
|
|
|
memset(line, 0, sizeof(line));
|
|
|
|
|
2012-05-03 20:19:22 +03:00
|
|
|
while (fgets(line, sizeof(line) - 1, c))
|
2010-03-25 17:46:16 +02:00
|
|
|
{
|
2012-05-03 20:19:22 +03:00
|
|
|
if ((line[0] == '/') && (strchr(line, ':') != NULL))
|
2010-03-25 17:46:16 +02:00
|
|
|
{
|
2012-05-03 20:19:22 +03:00
|
|
|
if (!(col1 = strchr(line, ':')) || (*col1++ = 0) ||
|
2010-08-14 03:54:24 +03:00
|
|
|
!(col2 = strchr(col1, ':')) || (*col2++ = 0) ||
|
2012-05-03 20:19:22 +03:00
|
|
|
!(eol = strchr(col2, '\n')) || (*eol++ = 0))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2010-03-25 17:46:16 +02:00
|
|
|
|
2012-05-03 20:19:22 +03:00
|
|
|
if (!uh_auth_add(line, col1, col2))
|
2010-03-25 17:46:16 +02:00
|
|
|
{
|
|
|
|
fprintf(stderr,
|
2012-05-03 20:19:22 +03:00
|
|
|
"Notice: No password set for user %s, ignoring "
|
|
|
|
"authentication on %s\n", col1, line
|
2010-03-25 17:46:16 +02:00
|
|
|
);
|
2010-07-23 16:15:22 +03:00
|
|
|
}
|
|
|
|
}
|
2012-05-03 20:19:22 +03:00
|
|
|
else if (!strncmp(line, "I:", 2))
|
2010-07-23 16:15:22 +03:00
|
|
|
{
|
2012-05-03 20:19:22 +03:00
|
|
|
if (!(col1 = strchr(line, ':')) || (*col1++ = 0) ||
|
|
|
|
!(eol = strchr(col1, '\n')) || (*eol++ = 0))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2010-03-25 17:46:16 +02:00
|
|
|
|
2010-08-14 03:54:24 +03:00
|
|
|
conf->index_file = strdup(col1);
|
2010-07-23 16:15:22 +03:00
|
|
|
}
|
2012-05-03 20:19:22 +03:00
|
|
|
else if (!strncmp(line, "E404:", 5))
|
2010-07-23 16:15:22 +03:00
|
|
|
{
|
2012-05-03 20:19:22 +03:00
|
|
|
if (!(col1 = strchr(line, ':')) || (*col1++ = 0) ||
|
|
|
|
!(eol = strchr(col1, '\n')) || (*eol++ = 0))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2010-07-23 16:15:22 +03:00
|
|
|
|
2010-08-14 03:54:24 +03:00
|
|
|
conf->error_handler = strdup(col1);
|
2010-03-25 17:46:16 +02:00
|
|
|
}
|
2010-08-14 03:54:24 +03:00
|
|
|
#ifdef HAVE_CGI
|
2012-05-03 20:19:22 +03:00
|
|
|
else if ((line[0] == '*') && (strchr(line, ':') != NULL))
|
2010-08-14 03:54:24 +03:00
|
|
|
{
|
2012-05-03 20:19:22 +03:00
|
|
|
if (!(col1 = strchr(line, '*')) || (*col1++ = 0) ||
|
2010-08-18 03:04:52 +03:00
|
|
|
!(col2 = strchr(col1, ':')) || (*col2++ = 0) ||
|
2012-05-03 20:19:22 +03:00
|
|
|
!(eol = strchr(col2, '\n')) || (*eol++ = 0))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2010-08-14 03:54:24 +03:00
|
|
|
|
2012-05-03 20:19:22 +03:00
|
|
|
if (!uh_interpreter_add(col1, col2))
|
2010-08-14 03:54:24 +03:00
|
|
|
{
|
|
|
|
fprintf(stderr,
|
2012-05-03 20:19:22 +03:00
|
|
|
"Unable to add interpreter %s for extension %s: "
|
|
|
|
"Out of memory\n", col2, col1
|
2010-08-14 03:54:24 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2010-03-25 17:46:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fclose(c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-28 03:52:24 +03:00
|
|
|
static void uh_listener_cb(struct uloop_fd *u, unsigned int events);
|
|
|
|
|
2012-05-03 20:19:22 +03:00
|
|
|
static int uh_socket_bind(fd_set *serv_fds, int *max_fd,
|
|
|
|
const char *host, const char *port,
|
|
|
|
struct addrinfo *hints, int do_tls,
|
|
|
|
struct config *conf)
|
|
|
|
{
|
2010-03-25 17:46:16 +02:00
|
|
|
int sock = -1;
|
|
|
|
int yes = 1;
|
|
|
|
int status;
|
|
|
|
int bound = 0;
|
|
|
|
|
2011-01-10 01:35:45 +02:00
|
|
|
int tcp_ka_idl, tcp_ka_int, tcp_ka_cnt;
|
2010-08-18 03:04:52 +03:00
|
|
|
|
2010-03-25 17:46:16 +02:00
|
|
|
struct listener *l = NULL;
|
|
|
|
struct addrinfo *addrs = NULL, *p = NULL;
|
|
|
|
|
2012-05-03 20:19:22 +03:00
|
|
|
if ((status = getaddrinfo(host, port, hints, &addrs)) != 0)
|
2010-03-25 17:46:16 +02:00
|
|
|
{
|
|
|
|
fprintf(stderr, "getaddrinfo(): %s\n", gai_strerror(status));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* try to bind a new socket to each found address */
|
2012-05-03 20:19:22 +03:00
|
|
|
for (p = addrs; p; p = p->ai_next)
|
2010-03-25 17:46:16 +02:00
|
|
|
{
|
|
|
|
/* get the socket */
|
2012-05-03 20:19:22 +03:00
|
|
|
if ((sock = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) == -1)
|
2010-03-25 17:46:16 +02:00
|
|
|
{
|
|
|
|
perror("socket()");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* "address already in use" */
|
2012-05-03 20:19:22 +03:00
|
|
|
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)))
|
2010-03-25 17:46:16 +02:00
|
|
|
{
|
|
|
|
perror("setsockopt()");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2010-08-18 03:04:52 +03:00
|
|
|
/* TCP keep-alive */
|
2012-05-03 20:19:22 +03:00
|
|
|
if (conf->tcp_keepalive > 0)
|
2010-08-18 03:04:52 +03:00
|
|
|
{
|
2011-01-10 01:35:45 +02:00
|
|
|
tcp_ka_idl = 1;
|
|
|
|
tcp_ka_cnt = 3;
|
|
|
|
tcp_ka_int = conf->tcp_keepalive;
|
|
|
|
|
2012-05-03 20:19:22 +03:00
|
|
|
if (setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, &yes, sizeof(yes)) ||
|
2011-01-10 01:35:45 +02:00
|
|
|
setsockopt(sock, SOL_TCP, TCP_KEEPIDLE, &tcp_ka_idl, sizeof(tcp_ka_idl)) ||
|
|
|
|
setsockopt(sock, SOL_TCP, TCP_KEEPINTVL, &tcp_ka_int, sizeof(tcp_ka_int)) ||
|
2012-05-03 20:19:22 +03:00
|
|
|
setsockopt(sock, SOL_TCP, TCP_KEEPCNT, &tcp_ka_cnt, sizeof(tcp_ka_cnt)))
|
2011-01-10 01:35:45 +02:00
|
|
|
{
|
|
|
|
fprintf(stderr, "Notice: Unable to enable TCP keep-alive: %s\n",
|
|
|
|
strerror(errno));
|
|
|
|
}
|
2010-08-18 03:04:52 +03:00
|
|
|
}
|
|
|
|
|
2010-03-25 17:46:16 +02:00
|
|
|
/* required to get parallel v4 + v6 working */
|
2012-05-03 20:19:22 +03:00
|
|
|
if (p->ai_family == AF_INET6)
|
2010-03-25 17:46:16 +02:00
|
|
|
{
|
2012-05-03 20:19:22 +03:00
|
|
|
if (setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, &yes, sizeof(yes)) == -1)
|
2010-03-25 17:46:16 +02:00
|
|
|
{
|
|
|
|
perror("setsockopt()");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* bind */
|
2012-05-03 20:19:22 +03:00
|
|
|
if (bind(sock, p->ai_addr, p->ai_addrlen) == -1)
|
2010-03-25 17:46:16 +02:00
|
|
|
{
|
|
|
|
perror("bind()");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* listen */
|
2012-05-03 20:19:22 +03:00
|
|
|
if (listen(sock, UH_LIMIT_CLIENTS) == -1)
|
2010-03-25 17:46:16 +02:00
|
|
|
{
|
|
|
|
perror("listen()");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* add listener to global list */
|
2012-05-03 20:19:22 +03:00
|
|
|
if (!(l = uh_listener_add(sock, conf)))
|
2010-03-25 17:46:16 +02:00
|
|
|
{
|
2010-08-14 03:54:24 +03:00
|
|
|
fprintf(stderr, "uh_listener_add(): Failed to allocate memory\n");
|
2010-03-25 17:46:16 +02:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef HAVE_TLS
|
|
|
|
/* init TLS */
|
|
|
|
l->tls = do_tls ? conf->tls : NULL;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* add socket to server fd set */
|
|
|
|
FD_SET(sock, serv_fds);
|
2010-03-27 02:00:33 +02:00
|
|
|
fd_cloexec(sock);
|
2010-03-25 17:46:16 +02:00
|
|
|
*max_fd = max(*max_fd, sock);
|
|
|
|
|
2012-05-28 03:52:24 +03:00
|
|
|
l->fd.cb = uh_listener_cb;
|
2012-07-06 20:29:25 +03:00
|
|
|
uloop_fd_add(&l->fd, ULOOP_READ);
|
2012-05-28 03:52:24 +03:00
|
|
|
|
2010-03-25 17:46:16 +02:00
|
|
|
bound++;
|
|
|
|
continue;
|
|
|
|
|
|
|
|
error:
|
2012-05-03 20:19:22 +03:00
|
|
|
if (sock > 0)
|
2010-03-25 17:46:16 +02:00
|
|
|
close(sock);
|
|
|
|
}
|
|
|
|
|
|
|
|
freeaddrinfo(addrs);
|
|
|
|
|
|
|
|
return bound;
|
|
|
|
}
|
|
|
|
|
2012-05-03 20:19:22 +03:00
|
|
|
static struct http_request * uh_http_header_parse(struct client *cl,
|
|
|
|
char *buffer, int buflen)
|
2010-03-25 17:46:16 +02:00
|
|
|
{
|
2012-05-28 03:52:24 +03:00
|
|
|
char *method = buffer;
|
2010-03-25 17:46:16 +02:00
|
|
|
char *path = NULL;
|
|
|
|
char *version = NULL;
|
|
|
|
|
|
|
|
char *headers = NULL;
|
|
|
|
char *hdrname = NULL;
|
|
|
|
char *hdrdata = NULL;
|
|
|
|
|
|
|
|
int i;
|
|
|
|
int hdrcount = 0;
|
|
|
|
|
2012-05-28 03:52:24 +03:00
|
|
|
struct http_request *req = &cl->request;
|
2010-03-25 17:46:16 +02:00
|
|
|
|
|
|
|
|
|
|
|
/* terminate initial header line */
|
2012-05-03 20:19:22 +03:00
|
|
|
if ((headers = strfind(buffer, buflen, "\r\n", 2)) != NULL)
|
2010-03-25 17:46:16 +02:00
|
|
|
{
|
|
|
|
buffer[buflen-1] = 0;
|
|
|
|
|
|
|
|
*headers++ = 0;
|
|
|
|
*headers++ = 0;
|
|
|
|
|
|
|
|
/* find request path */
|
2012-05-03 20:19:22 +03:00
|
|
|
if ((path = strchr(buffer, ' ')) != NULL)
|
2010-03-25 17:46:16 +02:00
|
|
|
*path++ = 0;
|
|
|
|
|
|
|
|
/* find http version */
|
2012-05-03 20:19:22 +03:00
|
|
|
if ((path != NULL) && ((version = strchr(path, ' ')) != NULL))
|
2010-03-25 17:46:16 +02:00
|
|
|
*version++ = 0;
|
|
|
|
|
|
|
|
|
|
|
|
/* check method */
|
2012-05-03 20:19:22 +03:00
|
|
|
if (strcmp(method, "GET") && strcmp(method, "HEAD") && strcmp(method, "POST"))
|
2010-03-25 17:46:16 +02:00
|
|
|
{
|
|
|
|
/* invalid method */
|
|
|
|
uh_http_response(cl, 405, "Method Not Allowed");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switch(method[0])
|
|
|
|
{
|
|
|
|
case 'G':
|
2012-05-28 03:52:24 +03:00
|
|
|
req->method = UH_HTTP_MSG_GET;
|
2010-03-25 17:46:16 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'H':
|
2012-05-28 03:52:24 +03:00
|
|
|
req->method = UH_HTTP_MSG_HEAD;
|
2010-03-25 17:46:16 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'P':
|
2012-05-28 03:52:24 +03:00
|
|
|
req->method = UH_HTTP_MSG_POST;
|
2010-03-25 17:46:16 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check path */
|
2012-05-03 20:19:22 +03:00
|
|
|
if (!path || !strlen(path))
|
2010-03-25 17:46:16 +02:00
|
|
|
{
|
|
|
|
/* malformed request */
|
|
|
|
uh_http_response(cl, 400, "Bad Request");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-05-28 03:52:24 +03:00
|
|
|
req->url = path;
|
2010-03-25 17:46:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* check version */
|
2012-05-03 20:19:22 +03:00
|
|
|
if ((version == NULL) || (strcmp(version, "HTTP/0.9") &&
|
|
|
|
strcmp(version, "HTTP/1.0") && strcmp(version, "HTTP/1.1")))
|
2010-03-25 17:46:16 +02:00
|
|
|
{
|
|
|
|
/* unsupported version */
|
|
|
|
uh_http_response(cl, 400, "Bad Request");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-05-28 03:52:24 +03:00
|
|
|
req->version = strtof(&version[5], NULL);
|
2010-03-25 17:46:16 +02:00
|
|
|
}
|
|
|
|
|
2012-05-28 03:52:24 +03:00
|
|
|
D("SRV: %s %s HTTP/%.1f\n",
|
|
|
|
(req->method == UH_HTTP_MSG_POST) ? "POST" :
|
|
|
|
(req->method == UH_HTTP_MSG_GET) ? "GET" : "HEAD",
|
|
|
|
req->url, req->version);
|
2010-03-25 17:46:16 +02:00
|
|
|
|
|
|
|
/* process header fields */
|
2012-05-03 20:19:22 +03:00
|
|
|
for (i = (int)(headers - buffer); i < buflen; i++)
|
2010-03-25 17:46:16 +02:00
|
|
|
{
|
|
|
|
/* found eol and have name + value, push out header tuple */
|
2012-05-03 20:19:22 +03:00
|
|
|
if (hdrname && hdrdata && (buffer[i] == '\r' || buffer[i] == '\n'))
|
2010-03-25 17:46:16 +02:00
|
|
|
{
|
|
|
|
buffer[i] = 0;
|
|
|
|
|
|
|
|
/* store */
|
2012-05-28 03:52:24 +03:00
|
|
|
if ((hdrcount + 1) < array_size(req->headers))
|
2010-03-25 17:46:16 +02:00
|
|
|
{
|
2012-05-28 03:52:24 +03:00
|
|
|
D("SRV: HTTP: %s: %s\n", hdrname, hdrdata);
|
|
|
|
|
|
|
|
req->headers[hdrcount++] = hdrname;
|
|
|
|
req->headers[hdrcount++] = hdrdata;
|
2010-03-25 17:46:16 +02:00
|
|
|
|
|
|
|
hdrname = hdrdata = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* too large */
|
|
|
|
else
|
|
|
|
{
|
2012-05-28 03:52:24 +03:00
|
|
|
D("SRV: HTTP: header too big (too many headers)\n");
|
2010-03-25 17:46:16 +02:00
|
|
|
uh_http_response(cl, 413, "Request Entity Too Large");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* have name but no value and found a colon, start of value */
|
2012-05-03 20:19:22 +03:00
|
|
|
else if (hdrname && !hdrdata &&
|
|
|
|
((i+1) < buflen) && (buffer[i] == ':'))
|
|
|
|
{
|
2010-03-25 17:46:16 +02:00
|
|
|
buffer[i] = 0;
|
2012-03-04 17:53:51 +02:00
|
|
|
hdrdata = &buffer[i+1];
|
|
|
|
|
|
|
|
while ((hdrdata + 1) < (buffer + buflen) && *hdrdata == ' ')
|
|
|
|
hdrdata++;
|
2010-03-25 17:46:16 +02:00
|
|
|
}
|
|
|
|
|
2010-12-25 00:03:34 +02:00
|
|
|
/* have no name and found [A-Za-z], start of name */
|
2012-05-03 20:19:22 +03:00
|
|
|
else if (!hdrname && isalpha(buffer[i]))
|
2010-03-25 17:46:16 +02:00
|
|
|
{
|
|
|
|
hdrname = &buffer[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* valid enough */
|
2012-05-28 03:52:24 +03:00
|
|
|
req->redirect_status = 200;
|
|
|
|
return req;
|
2010-03-25 17:46:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Malformed request */
|
|
|
|
uh_http_response(cl, 400, "Bad Request");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static struct http_request * uh_http_header_recv(struct client *cl)
|
|
|
|
{
|
2012-05-28 03:52:24 +03:00
|
|
|
char *bufptr = cl->httpbuf.buf;
|
2010-03-25 17:46:16 +02:00
|
|
|
char *idxptr = NULL;
|
|
|
|
|
2012-05-30 18:30:07 +03:00
|
|
|
ssize_t blen = sizeof(cl->httpbuf.buf)-1;
|
2010-03-25 17:46:16 +02:00
|
|
|
ssize_t rlen = 0;
|
|
|
|
|
2012-05-30 18:30:07 +03:00
|
|
|
memset(bufptr, 0, sizeof(cl->httpbuf.buf));
|
2010-03-25 17:46:16 +02:00
|
|
|
|
2012-05-03 20:19:22 +03:00
|
|
|
while (blen > 0)
|
2010-03-25 17:46:16 +02:00
|
|
|
{
|
2012-05-28 03:52:24 +03:00
|
|
|
/* receive data */
|
|
|
|
ensure_out(rlen = uh_tcp_recv(cl, bufptr, blen));
|
|
|
|
D("SRV: Client(%d) peek(%d) = %d\n", cl->fd.fd, blen, rlen);
|
2010-03-25 17:46:16 +02:00
|
|
|
|
2012-05-28 03:52:24 +03:00
|
|
|
if (rlen <= 0)
|
2010-03-25 17:46:16 +02:00
|
|
|
{
|
2012-05-28 03:52:24 +03:00
|
|
|
D("SRV: Client(%d) dead [%s]\n", cl->fd.fd, strerror(errno));
|
|
|
|
return NULL;
|
|
|
|
}
|
2010-08-18 03:04:52 +03:00
|
|
|
|
2012-05-28 03:52:24 +03:00
|
|
|
blen -= rlen;
|
|
|
|
bufptr += rlen;
|
2010-09-09 23:15:02 +03:00
|
|
|
|
2012-05-28 03:52:24 +03:00
|
|
|
if ((idxptr = strfind(cl->httpbuf.buf, sizeof(cl->httpbuf.buf),
|
|
|
|
"\r\n\r\n", 4)))
|
2010-03-25 17:46:16 +02:00
|
|
|
{
|
2012-05-28 03:52:24 +03:00
|
|
|
/* header read complete ... */
|
|
|
|
cl->httpbuf.ptr = idxptr + 4;
|
|
|
|
cl->httpbuf.len = bufptr - cl->httpbuf.ptr;
|
|
|
|
|
|
|
|
return uh_http_header_parse(cl, cl->httpbuf.buf,
|
|
|
|
(cl->httpbuf.ptr - cl->httpbuf.buf));
|
2010-03-25 17:46:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* request entity too large */
|
2012-05-28 03:52:24 +03:00
|
|
|
D("SRV: HTTP: header too big (buffer exceeded)\n");
|
2010-03-25 17:46:16 +02:00
|
|
|
uh_http_response(cl, 413, "Request Entity Too Large");
|
2010-08-18 03:04:52 +03:00
|
|
|
|
|
|
|
out:
|
2010-03-25 17:46:16 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-08-14 03:54:24 +03:00
|
|
|
#if defined(HAVE_LUA) || defined(HAVE_CGI)
|
2010-03-25 17:46:16 +02:00
|
|
|
static int uh_path_match(const char *prefix, const char *url)
|
|
|
|
{
|
2012-05-03 20:19:22 +03:00
|
|
|
if ((strstr(url, prefix) == url) &&
|
|
|
|
((prefix[strlen(prefix)-1] == '/') ||
|
2010-03-25 17:46:16 +02:00
|
|
|
(strlen(url) == strlen(prefix)) ||
|
2012-05-03 20:19:22 +03:00
|
|
|
(url[strlen(prefix)] == '/')))
|
|
|
|
{
|
2010-03-25 17:46:16 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2010-08-14 03:54:24 +03:00
|
|
|
#endif
|
2010-03-25 17:46:16 +02:00
|
|
|
|
2012-05-28 03:52:24 +03:00
|
|
|
static bool uh_dispatch_request(struct client *cl, struct http_request *req)
|
2012-05-03 20:19:22 +03:00
|
|
|
{
|
2012-05-28 03:52:24 +03:00
|
|
|
struct path_info *pin;
|
2010-08-14 03:54:24 +03:00
|
|
|
struct interpreter *ipr = NULL;
|
2012-05-28 03:52:24 +03:00
|
|
|
struct config *conf = cl->server->conf;
|
2010-03-25 17:46:16 +02:00
|
|
|
|
2012-05-28 03:52:24 +03:00
|
|
|
#ifdef HAVE_LUA
|
|
|
|
/* Lua request? */
|
|
|
|
if (conf->lua_state &&
|
|
|
|
uh_path_match(conf->lua_prefix, req->url))
|
2010-08-14 03:54:24 +03:00
|
|
|
{
|
2012-05-28 03:52:24 +03:00
|
|
|
return conf->lua_request(cl, conf->lua_state);
|
2010-08-14 03:54:24 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
2012-05-28 03:52:24 +03:00
|
|
|
|
|
|
|
#ifdef HAVE_UBUS
|
|
|
|
/* ubus request? */
|
|
|
|
if (conf->ubus_state &&
|
|
|
|
uh_path_match(conf->ubus_prefix, req->url))
|
2010-08-14 03:54:24 +03:00
|
|
|
{
|
2012-05-28 03:52:24 +03:00
|
|
|
return conf->ubus_request(cl, conf->ubus_state);
|
2010-08-14 03:54:24 +03:00
|
|
|
}
|
2012-05-28 03:52:24 +03:00
|
|
|
else
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* dispatch request */
|
|
|
|
if ((pin = uh_path_lookup(cl, req->url)) != NULL)
|
|
|
|
{
|
|
|
|
/* auth ok? */
|
|
|
|
if (!pin->redirected && uh_auth_check(cl, req, pin))
|
|
|
|
{
|
|
|
|
#ifdef HAVE_CGI
|
|
|
|
if (uh_path_match(conf->cgi_prefix, pin->name) ||
|
|
|
|
(ipr = uh_interpreter_lookup(pin->phys)) != NULL)
|
|
|
|
{
|
|
|
|
return uh_cgi_request(cl, pin, ipr);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return uh_file_request(cl, pin);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 404 - pass 1 */
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Try to invoke an error handler */
|
|
|
|
if ((pin = uh_path_lookup(cl, conf->error_handler)) != NULL)
|
|
|
|
{
|
|
|
|
/* auth ok? */
|
|
|
|
if (uh_auth_check(cl, req, pin))
|
|
|
|
{
|
|
|
|
req->redirect_status = 404;
|
|
|
|
#ifdef HAVE_CGI
|
|
|
|
if (uh_path_match(conf->cgi_prefix, pin->name) ||
|
|
|
|
(ipr = uh_interpreter_lookup(pin->phys)) != NULL)
|
|
|
|
{
|
|
|
|
return uh_cgi_request(cl, pin, ipr);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return uh_file_request(cl, pin);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 404 - pass 2 */
|
|
|
|
else
|
|
|
|
{
|
|
|
|
uh_http_sendhf(cl, 404, "Not Found", "No such file or directory");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2010-08-14 03:54:24 +03:00
|
|
|
}
|
|
|
|
|
2012-05-28 03:52:24 +03:00
|
|
|
static void uh_client_cb(struct uloop_fd *u, unsigned int events);
|
2010-08-14 03:54:24 +03:00
|
|
|
|
2012-05-28 03:52:24 +03:00
|
|
|
static void uh_listener_cb(struct uloop_fd *u, unsigned int events)
|
|
|
|
{
|
|
|
|
int new_fd;
|
|
|
|
struct listener *serv;
|
2010-08-14 03:54:24 +03:00
|
|
|
struct client *cl;
|
2012-05-28 03:52:24 +03:00
|
|
|
struct config *conf;
|
2010-08-14 03:54:24 +03:00
|
|
|
|
2012-05-28 03:52:24 +03:00
|
|
|
serv = container_of(u, struct listener, fd);
|
|
|
|
conf = serv->conf;
|
2010-08-14 03:54:24 +03:00
|
|
|
|
2012-05-28 03:52:24 +03:00
|
|
|
/* defer client if maximum number of requests is exceeded */
|
|
|
|
if (serv->n_clients >= conf->max_requests)
|
|
|
|
return;
|
2010-08-14 03:54:24 +03:00
|
|
|
|
2012-05-28 03:52:24 +03:00
|
|
|
/* handle new connections */
|
|
|
|
if ((new_fd = accept(u->fd, NULL, 0)) != -1)
|
2010-08-14 03:54:24 +03:00
|
|
|
{
|
2012-05-28 03:52:24 +03:00
|
|
|
D("SRV: Server(%d) accept => Client(%d)\n", u->fd, new_fd);
|
2010-08-14 03:54:24 +03:00
|
|
|
|
2012-05-28 03:52:24 +03:00
|
|
|
/* add to global client list */
|
|
|
|
if ((cl = uh_client_add(new_fd, serv)) != NULL)
|
2010-08-14 03:54:24 +03:00
|
|
|
{
|
2012-05-28 03:52:24 +03:00
|
|
|
/* add client socket to global fdset */
|
2012-07-06 20:29:25 +03:00
|
|
|
uloop_fd_add(&cl->fd, ULOOP_READ);
|
2010-08-14 03:54:24 +03:00
|
|
|
|
2012-05-28 03:52:24 +03:00
|
|
|
#ifdef HAVE_TLS
|
|
|
|
/* setup client tls context */
|
|
|
|
if (conf->tls)
|
2010-08-14 03:54:24 +03:00
|
|
|
{
|
2012-05-28 03:52:24 +03:00
|
|
|
if (conf->tls_accept(cl) < 1)
|
2010-08-14 03:54:24 +03:00
|
|
|
{
|
2012-05-28 03:52:24 +03:00
|
|
|
D("SRV: Client(%d) SSL handshake failed, drop\n", new_fd);
|
2010-08-14 03:54:24 +03:00
|
|
|
|
2012-05-28 03:52:24 +03:00
|
|
|
/* remove from global client list */
|
|
|
|
uh_client_remove(cl);
|
|
|
|
return;
|
2010-08-14 03:54:24 +03:00
|
|
|
}
|
2012-05-28 03:52:24 +03:00
|
|
|
}
|
|
|
|
#endif
|
2010-08-14 03:54:24 +03:00
|
|
|
|
2012-05-28 03:52:24 +03:00
|
|
|
cl->fd.cb = uh_client_cb;
|
|
|
|
fd_cloexec(new_fd);
|
|
|
|
}
|
2010-08-14 03:54:24 +03:00
|
|
|
|
2012-05-28 03:52:24 +03:00
|
|
|
/* insufficient resources */
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fprintf(stderr, "uh_client_add(): Cannot allocate memory\n");
|
|
|
|
close(new_fd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-08-14 03:54:24 +03:00
|
|
|
|
2012-07-06 20:29:25 +03:00
|
|
|
static void uh_pipe_cb(struct uloop_fd *u, unsigned int events)
|
|
|
|
{
|
|
|
|
struct client *cl = container_of(u, struct client, pipe);
|
|
|
|
|
|
|
|
D("SRV: Client(%d) pipe(%d) readable\n", cl->fd.fd, cl->pipe.fd);
|
|
|
|
|
|
|
|
uh_client_cb(&cl->fd, ULOOP_WRITE);
|
|
|
|
}
|
|
|
|
|
2012-05-28 03:52:24 +03:00
|
|
|
static void uh_child_cb(struct uloop_process *p, int rv)
|
|
|
|
{
|
|
|
|
struct client *cl = container_of(p, struct client, proc);
|
2010-08-14 03:54:24 +03:00
|
|
|
|
2012-05-28 03:52:24 +03:00
|
|
|
D("SRV: Client(%d) child(%d) is dead\n", cl->fd.fd, cl->proc.pid);
|
2010-08-14 03:54:24 +03:00
|
|
|
|
2012-05-28 03:52:24 +03:00
|
|
|
cl->dead = true;
|
|
|
|
cl->fd.eof = true;
|
|
|
|
uh_client_cb(&cl->fd, ULOOP_READ | ULOOP_WRITE);
|
|
|
|
}
|
2010-08-14 03:54:24 +03:00
|
|
|
|
2012-05-28 03:52:24 +03:00
|
|
|
static void uh_kill9_cb(struct uloop_timeout *t)
|
|
|
|
{
|
|
|
|
struct client *cl = container_of(t, struct client, timeout);
|
2010-08-14 03:54:24 +03:00
|
|
|
|
2012-05-28 03:52:24 +03:00
|
|
|
if (!kill(cl->proc.pid, 0))
|
|
|
|
{
|
|
|
|
D("SRV: Client(%d) child(%d) kill(SIGKILL)...\n",
|
|
|
|
cl->fd.fd, cl->proc.pid);
|
|
|
|
|
|
|
|
kill(cl->proc.pid, SIGKILL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void uh_timeout_cb(struct uloop_timeout *t)
|
|
|
|
{
|
|
|
|
struct client *cl = container_of(t, struct client, timeout);
|
|
|
|
|
|
|
|
D("SRV: Client(%d) child(%d) timed out\n", cl->fd.fd, cl->proc.pid);
|
|
|
|
|
|
|
|
if (!kill(cl->proc.pid, 0))
|
|
|
|
{
|
|
|
|
D("SRV: Client(%d) child(%d) kill(SIGTERM)...\n",
|
|
|
|
cl->fd.fd, cl->proc.pid);
|
|
|
|
|
|
|
|
kill(cl->proc.pid, SIGTERM);
|
|
|
|
|
|
|
|
cl->timeout.cb = uh_kill9_cb;
|
|
|
|
uloop_timeout_set(&cl->timeout, 1000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void uh_client_cb(struct uloop_fd *u, unsigned int events)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct client *cl;
|
|
|
|
struct config *conf;
|
|
|
|
struct http_request *req;
|
|
|
|
|
|
|
|
cl = container_of(u, struct client, fd);
|
|
|
|
conf = cl->server->conf;
|
|
|
|
|
|
|
|
D("SRV: Client(%d) enter callback\n", u->fd);
|
|
|
|
|
|
|
|
/* undispatched yet */
|
|
|
|
if (!cl->dispatched)
|
|
|
|
{
|
|
|
|
/* we have no headers yet and this was a write event, ignore... */
|
|
|
|
if (!(events & ULOOP_READ))
|
|
|
|
{
|
|
|
|
D("SRV: Client(%d) ignoring write event before headers\n", u->fd);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* attempt to receive and parse headers */
|
|
|
|
if (!(req = uh_http_header_recv(cl)))
|
|
|
|
{
|
|
|
|
D("SRV: Client(%d) failed to receive header\n", u->fd);
|
|
|
|
uh_client_shutdown(cl);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* process expect headers */
|
|
|
|
foreach_header(i, req->headers)
|
|
|
|
{
|
|
|
|
if (strcasecmp(req->headers[i], "Expect"))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (strcasecmp(req->headers[i+1], "100-continue"))
|
|
|
|
{
|
|
|
|
D("SRV: Client(%d) unknown expect header (%s)\n",
|
|
|
|
u->fd, req->headers[i+1]);
|
|
|
|
|
|
|
|
uh_http_response(cl, 417, "Precondition Failed");
|
|
|
|
uh_client_shutdown(cl);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
D("SRV: Client(%d) sending HTTP/1.1 100 Continue\n", u->fd);
|
|
|
|
|
|
|
|
uh_http_sendf(cl, NULL, "HTTP/1.1 100 Continue\r\n\r\n");
|
|
|
|
cl->httpbuf.len = 0; /* client will re-send the body */
|
|
|
|
break;
|
2010-08-14 03:54:24 +03:00
|
|
|
}
|
|
|
|
}
|
2012-05-28 03:52:24 +03:00
|
|
|
|
|
|
|
/* RFC1918 filtering */
|
|
|
|
if (conf->rfc1918_filter &&
|
|
|
|
sa_rfc1918(&cl->peeraddr) && !sa_rfc1918(&cl->servaddr))
|
|
|
|
{
|
|
|
|
uh_http_sendhf(cl, 403, "Forbidden",
|
|
|
|
"Rejected request from RFC1918 IP "
|
|
|
|
"to public server address");
|
|
|
|
|
|
|
|
uh_client_shutdown(cl);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* dispatch request */
|
|
|
|
if (!uh_dispatch_request(cl, req))
|
|
|
|
{
|
|
|
|
D("SRV: Client(%d) failed to dispach request\n", u->fd);
|
|
|
|
uh_client_shutdown(cl);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-07-06 20:29:25 +03:00
|
|
|
/* request handler spawned a pipe, register handler */
|
|
|
|
if (cl->pipe.fd)
|
|
|
|
{
|
|
|
|
D("SRV: Client(%d) pipe(%d) spawned\n", u->fd, cl->pipe.fd);
|
|
|
|
|
|
|
|
cl->pipe.cb = uh_pipe_cb;
|
|
|
|
uloop_fd_add(&cl->pipe, ULOOP_READ);
|
|
|
|
}
|
|
|
|
|
2012-05-28 03:52:24 +03:00
|
|
|
/* request handler spawned a child, register handler */
|
|
|
|
if (cl->proc.pid)
|
|
|
|
{
|
|
|
|
D("SRV: Client(%d) child(%d) spawned\n", u->fd, cl->proc.pid);
|
|
|
|
|
|
|
|
cl->proc.cb = uh_child_cb;
|
|
|
|
uloop_process_add(&cl->proc);
|
|
|
|
|
|
|
|
cl->timeout.cb = uh_timeout_cb;
|
|
|
|
uloop_timeout_set(&cl->timeout, conf->script_timeout * 1000);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* header processing complete */
|
|
|
|
D("SRV: Client(%d) dispatched\n", u->fd);
|
|
|
|
cl->dispatched = true;
|
2010-08-14 03:54:24 +03:00
|
|
|
}
|
|
|
|
|
2012-05-28 03:52:24 +03:00
|
|
|
if (!cl->cb(cl))
|
|
|
|
{
|
|
|
|
D("SRV: Client(%d) response callback signalized EOF\n", u->fd);
|
|
|
|
uh_client_shutdown(cl);
|
|
|
|
return;
|
|
|
|
}
|
2010-08-14 03:54:24 +03:00
|
|
|
}
|
|
|
|
|
2011-01-28 21:50:33 +02:00
|
|
|
#ifdef HAVE_TLS
|
2011-07-17 10:18:59 +03:00
|
|
|
static inline int uh_inittls(struct config *conf)
|
2011-01-28 21:50:33 +02:00
|
|
|
{
|
|
|
|
/* library handle */
|
|
|
|
void *lib;
|
|
|
|
|
|
|
|
/* already loaded */
|
2012-05-03 20:19:22 +03:00
|
|
|
if (conf->tls != NULL)
|
2011-01-28 21:50:33 +02:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* load TLS plugin */
|
2012-05-03 20:19:22 +03:00
|
|
|
if (!(lib = dlopen("uhttpd_tls.so", RTLD_LAZY | RTLD_GLOBAL)))
|
2011-01-28 21:50:33 +02:00
|
|
|
{
|
|
|
|
fprintf(stderr,
|
2012-05-03 20:19:22 +03:00
|
|
|
"Notice: Unable to load TLS plugin - disabling SSL support! "
|
|
|
|
"(Reason: %s)\n", dlerror()
|
2011-01-28 21:50:33 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* resolve functions */
|
2012-05-03 20:19:22 +03:00
|
|
|
if (!(conf->tls_init = dlsym(lib, "uh_tls_ctx_init")) ||
|
2011-01-28 21:50:33 +02:00
|
|
|
!(conf->tls_cert = dlsym(lib, "uh_tls_ctx_cert")) ||
|
|
|
|
!(conf->tls_key = dlsym(lib, "uh_tls_ctx_key")) ||
|
|
|
|
!(conf->tls_free = dlsym(lib, "uh_tls_ctx_free")) ||
|
|
|
|
!(conf->tls_accept = dlsym(lib, "uh_tls_client_accept")) ||
|
|
|
|
!(conf->tls_close = dlsym(lib, "uh_tls_client_close")) ||
|
|
|
|
!(conf->tls_recv = dlsym(lib, "uh_tls_client_recv")) ||
|
2012-05-03 20:19:22 +03:00
|
|
|
!(conf->tls_send = dlsym(lib, "uh_tls_client_send")))
|
|
|
|
{
|
2011-01-28 21:50:33 +02:00
|
|
|
fprintf(stderr,
|
2012-05-03 20:19:22 +03:00
|
|
|
"Error: Failed to lookup required symbols "
|
|
|
|
"in TLS plugin: %s\n", dlerror()
|
2011-01-28 21:50:33 +02:00
|
|
|
);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* init SSL context */
|
2012-05-03 20:19:22 +03:00
|
|
|
if (!(conf->tls = conf->tls_init()))
|
2011-01-28 21:50:33 +02:00
|
|
|
{
|
|
|
|
fprintf(stderr, "Error: Failed to initalize SSL context\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
2010-08-14 03:54:24 +03:00
|
|
|
|
|
|
|
int main (int argc, char **argv)
|
|
|
|
{
|
2010-03-25 17:46:16 +02:00
|
|
|
/* master file descriptor list */
|
2011-01-10 01:35:45 +02:00
|
|
|
fd_set serv_fds;
|
2010-03-25 17:46:16 +02:00
|
|
|
|
|
|
|
/* working structs */
|
|
|
|
struct addrinfo hints;
|
|
|
|
struct sigaction sa;
|
|
|
|
struct config conf;
|
|
|
|
|
|
|
|
/* maximum file descriptor number */
|
2010-08-14 03:54:24 +03:00
|
|
|
int cur_fd, max_fd = 0;
|
2010-03-25 17:46:16 +02:00
|
|
|
|
2010-04-15 22:46:35 +03:00
|
|
|
#ifdef HAVE_TLS
|
2010-03-25 17:46:16 +02:00
|
|
|
int tls = 0;
|
|
|
|
int keys = 0;
|
2010-04-15 22:46:35 +03:00
|
|
|
#endif
|
|
|
|
|
2010-03-25 17:46:16 +02:00
|
|
|
int bound = 0;
|
|
|
|
int nofork = 0;
|
|
|
|
|
|
|
|
/* args */
|
2010-03-28 05:35:45 +03:00
|
|
|
int opt;
|
2010-03-25 17:46:16 +02:00
|
|
|
char bind[128];
|
|
|
|
char *port = NULL;
|
|
|
|
|
2011-01-28 21:50:33 +02:00
|
|
|
#ifdef HAVE_LUA
|
2010-04-15 22:46:35 +03:00
|
|
|
/* library handle */
|
|
|
|
void *lib;
|
|
|
|
#endif
|
2010-03-25 17:46:16 +02:00
|
|
|
|
|
|
|
FD_ZERO(&serv_fds);
|
|
|
|
|
2012-05-28 03:52:24 +03:00
|
|
|
/* handle SIGPIPE, SIGINT, SIGTERM */
|
2010-03-25 17:46:16 +02:00
|
|
|
sa.sa_flags = 0;
|
|
|
|
sigemptyset(&sa.sa_mask);
|
|
|
|
|
|
|
|
sa.sa_handler = SIG_IGN;
|
|
|
|
sigaction(SIGPIPE, &sa, NULL);
|
2010-03-27 02:00:33 +02:00
|
|
|
|
2010-03-25 17:46:16 +02:00
|
|
|
sa.sa_handler = uh_sigterm;
|
|
|
|
sigaction(SIGINT, &sa, NULL);
|
|
|
|
sigaction(SIGTERM, &sa, NULL);
|
|
|
|
|
|
|
|
/* prepare addrinfo hints */
|
|
|
|
memset(&hints, 0, sizeof(hints));
|
|
|
|
hints.ai_family = AF_UNSPEC;
|
|
|
|
hints.ai_socktype = SOCK_STREAM;
|
|
|
|
hints.ai_flags = AI_PASSIVE;
|
|
|
|
|
|
|
|
/* parse args */
|
|
|
|
memset(&conf, 0, sizeof(conf));
|
|
|
|
memset(bind, 0, sizeof(bind));
|
|
|
|
|
2012-05-28 03:52:24 +03:00
|
|
|
uloop_init();
|
2010-03-25 17:46:16 +02:00
|
|
|
|
2012-05-03 20:19:22 +03:00
|
|
|
while ((opt = getopt(argc, argv,
|
2012-05-28 03:52:24 +03:00
|
|
|
"fSDRC:K:E:I:p:s:h:c:l:L:d:r:m:n:x:i:t:T:A:u:U:")) > 0)
|
2012-05-03 20:19:22 +03:00
|
|
|
{
|
2010-03-25 17:46:16 +02:00
|
|
|
switch(opt)
|
|
|
|
{
|
|
|
|
/* [addr:]port */
|
|
|
|
case 'p':
|
|
|
|
case 's':
|
2012-05-03 20:19:22 +03:00
|
|
|
if ((port = strrchr(optarg, ':')) != NULL)
|
2010-03-25 17:46:16 +02:00
|
|
|
{
|
2012-05-03 20:19:22 +03:00
|
|
|
if ((optarg[0] == '[') && (port > optarg) && (port[-1] == ']'))
|
2010-03-25 17:46:16 +02:00
|
|
|
memcpy(bind, optarg + 1,
|
|
|
|
min(sizeof(bind), (int)(port - optarg) - 2));
|
|
|
|
else
|
|
|
|
memcpy(bind, optarg,
|
|
|
|
min(sizeof(bind), (int)(port - optarg)));
|
|
|
|
|
|
|
|
port++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
port = optarg;
|
|
|
|
}
|
|
|
|
|
2010-04-03 16:09:10 +03:00
|
|
|
#ifdef HAVE_TLS
|
2012-05-03 20:19:22 +03:00
|
|
|
if (opt == 's')
|
2010-03-25 17:46:16 +02:00
|
|
|
{
|
2012-05-03 20:19:22 +03:00
|
|
|
if (uh_inittls(&conf))
|
2010-03-25 17:46:16 +02:00
|
|
|
{
|
|
|
|
fprintf(stderr,
|
|
|
|
"Notice: TLS support is disabled, "
|
|
|
|
"ignoring '-s %s'\n", optarg
|
|
|
|
);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
tls = 1;
|
|
|
|
}
|
2010-04-03 16:09:10 +03:00
|
|
|
#endif
|
2010-03-25 17:46:16 +02:00
|
|
|
|
|
|
|
/* bind sockets */
|
2012-05-03 20:19:22 +03:00
|
|
|
bound += uh_socket_bind(&serv_fds, &max_fd,
|
|
|
|
bind[0] ? bind : NULL,
|
|
|
|
port, &hints, (opt == 's'), &conf);
|
2010-03-25 17:46:16 +02:00
|
|
|
|
2010-06-12 15:58:11 +03:00
|
|
|
memset(bind, 0, sizeof(bind));
|
2010-03-25 17:46:16 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
#ifdef HAVE_TLS
|
|
|
|
/* certificate */
|
|
|
|
case 'C':
|
2012-05-03 20:19:22 +03:00
|
|
|
if (!uh_inittls(&conf))
|
2010-03-25 17:46:16 +02:00
|
|
|
{
|
2012-05-03 20:19:22 +03:00
|
|
|
if (conf.tls_cert(conf.tls, optarg) < 1)
|
2010-03-25 17:46:16 +02:00
|
|
|
{
|
|
|
|
fprintf(stderr,
|
2012-05-03 20:19:22 +03:00
|
|
|
"Error: Invalid certificate file given\n");
|
2010-03-25 17:46:16 +02:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
keys++;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* key */
|
|
|
|
case 'K':
|
2012-05-03 20:19:22 +03:00
|
|
|
if (!uh_inittls(&conf))
|
2010-03-25 17:46:16 +02:00
|
|
|
{
|
2012-05-03 20:19:22 +03:00
|
|
|
if (conf.tls_key(conf.tls, optarg) < 1)
|
2010-03-25 17:46:16 +02:00
|
|
|
{
|
|
|
|
fprintf(stderr,
|
2012-05-03 20:19:22 +03:00
|
|
|
"Error: Invalid private key file given\n");
|
2010-03-25 17:46:16 +02:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
keys++;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* docroot */
|
|
|
|
case 'h':
|
2012-05-03 20:19:22 +03:00
|
|
|
if (! realpath(optarg, conf.docroot))
|
2010-03-25 17:46:16 +02:00
|
|
|
{
|
|
|
|
fprintf(stderr, "Error: Invalid directory %s: %s\n",
|
2012-05-03 20:19:22 +03:00
|
|
|
optarg, strerror(errno));
|
2010-03-25 17:46:16 +02:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2010-07-23 16:15:22 +03:00
|
|
|
/* error handler */
|
|
|
|
case 'E':
|
2012-05-03 20:19:22 +03:00
|
|
|
if ((strlen(optarg) == 0) || (optarg[0] != '/'))
|
2010-07-23 16:15:22 +03:00
|
|
|
{
|
|
|
|
fprintf(stderr, "Error: Invalid error handler: %s\n",
|
2012-05-03 20:19:22 +03:00
|
|
|
optarg);
|
2010-07-23 16:15:22 +03:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
conf.error_handler = optarg;
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* index file */
|
|
|
|
case 'I':
|
2012-05-03 20:19:22 +03:00
|
|
|
if ((strlen(optarg) == 0) || (optarg[0] == '/'))
|
2010-07-23 16:15:22 +03:00
|
|
|
{
|
|
|
|
fprintf(stderr, "Error: Invalid index page: %s\n",
|
2012-05-03 20:19:22 +03:00
|
|
|
optarg);
|
2010-07-23 16:15:22 +03:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
conf.index_file = optarg;
|
|
|
|
break;
|
|
|
|
|
2010-04-15 22:46:35 +03:00
|
|
|
/* don't follow symlinks */
|
|
|
|
case 'S':
|
|
|
|
conf.no_symlinks = 1;
|
|
|
|
break;
|
|
|
|
|
2010-07-23 16:15:22 +03:00
|
|
|
/* don't list directories */
|
|
|
|
case 'D':
|
|
|
|
conf.no_dirlists = 1;
|
|
|
|
break;
|
|
|
|
|
2010-08-11 03:05:34 +03:00
|
|
|
case 'R':
|
|
|
|
conf.rfc1918_filter = 1;
|
|
|
|
break;
|
|
|
|
|
2012-05-28 03:52:24 +03:00
|
|
|
case 'n':
|
|
|
|
conf.max_requests = atoi(optarg);
|
|
|
|
break;
|
|
|
|
|
2010-03-25 17:46:16 +02:00
|
|
|
#ifdef HAVE_CGI
|
|
|
|
/* cgi prefix */
|
|
|
|
case 'x':
|
|
|
|
conf.cgi_prefix = optarg;
|
|
|
|
break;
|
2010-08-14 03:54:24 +03:00
|
|
|
|
|
|
|
/* interpreter */
|
|
|
|
case 'i':
|
2012-05-03 20:19:22 +03:00
|
|
|
if ((optarg[0] == '.') && (port = strchr(optarg, '=')))
|
2010-08-14 03:54:24 +03:00
|
|
|
{
|
|
|
|
*port++ = 0;
|
|
|
|
uh_interpreter_add(optarg, port);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Error: Invalid interpreter: %s\n",
|
2012-05-03 20:19:22 +03:00
|
|
|
optarg);
|
2010-08-14 03:54:24 +03:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
break;
|
2010-03-25 17:46:16 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_LUA
|
|
|
|
/* lua prefix */
|
|
|
|
case 'l':
|
|
|
|
conf.lua_prefix = optarg;
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* lua handler */
|
|
|
|
case 'L':
|
|
|
|
conf.lua_handler = optarg;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2012-05-28 03:52:24 +03:00
|
|
|
#ifdef HAVE_UBUS
|
|
|
|
/* ubus prefix */
|
|
|
|
case 'u':
|
|
|
|
conf.ubus_prefix = optarg;
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* ubus socket */
|
|
|
|
case 'U':
|
|
|
|
conf.ubus_socket = optarg;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2010-03-27 02:00:33 +02:00
|
|
|
#if defined(HAVE_CGI) || defined(HAVE_LUA)
|
|
|
|
/* script timeout */
|
|
|
|
case 't':
|
|
|
|
conf.script_timeout = atoi(optarg);
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2010-04-15 22:46:35 +03:00
|
|
|
/* network timeout */
|
|
|
|
case 'T':
|
|
|
|
conf.network_timeout = atoi(optarg);
|
|
|
|
break;
|
|
|
|
|
2011-01-10 01:35:45 +02:00
|
|
|
/* tcp keep-alive */
|
|
|
|
case 'A':
|
|
|
|
conf.tcp_keepalive = atoi(optarg);
|
|
|
|
break;
|
|
|
|
|
2010-03-25 17:46:16 +02:00
|
|
|
/* no fork */
|
|
|
|
case 'f':
|
|
|
|
nofork = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* urldecode */
|
|
|
|
case 'd':
|
2012-05-03 20:19:22 +03:00
|
|
|
if ((port = malloc(strlen(optarg)+1)) != NULL)
|
2010-03-25 17:46:16 +02:00
|
|
|
{
|
2011-01-28 21:50:33 +02:00
|
|
|
/* "decode" plus to space to retain compat */
|
|
|
|
for (opt = 0; optarg[opt]; opt++)
|
|
|
|
if (optarg[opt] == '+')
|
|
|
|
optarg[opt] = ' ';
|
2012-05-03 20:19:18 +03:00
|
|
|
/* opt now contains strlen(optarg) -- no need to re-scan */
|
|
|
|
memset(port, 0, opt+1);
|
|
|
|
if (uh_urldecode(port, opt, optarg, opt) < 0)
|
2012-05-03 20:19:22 +03:00
|
|
|
fprintf(stderr, "uhttpd: invalid encoding\n");
|
2011-01-28 21:50:33 +02:00
|
|
|
|
2010-03-25 17:46:16 +02:00
|
|
|
printf("%s", port);
|
|
|
|
free(port);
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* basic auth realm */
|
|
|
|
case 'r':
|
|
|
|
conf.realm = optarg;
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* md5 crypt */
|
|
|
|
case 'm':
|
|
|
|
printf("%s\n", crypt(optarg, "$1$"));
|
|
|
|
exit(0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* config file */
|
|
|
|
case 'c':
|
|
|
|
conf.file = optarg;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
fprintf(stderr,
|
|
|
|
"Usage: %s -p [addr:]port [-h docroot]\n"
|
|
|
|
" -f Do not fork to background\n"
|
|
|
|
" -c file Configuration file, default is '/etc/httpd.conf'\n"
|
|
|
|
" -p [addr:]port Bind to specified address and port, multiple allowed\n"
|
|
|
|
#ifdef HAVE_TLS
|
|
|
|
" -s [addr:]port Like -p but provide HTTPS on this port\n"
|
|
|
|
" -C file ASN.1 server certificate file\n"
|
|
|
|
" -K file ASN.1 server private key file\n"
|
|
|
|
#endif
|
|
|
|
" -h directory Specify the document root, default is '.'\n"
|
2010-07-23 16:15:22 +03:00
|
|
|
" -E string Use given virtual URL as 404 error handler\n"
|
|
|
|
" -I string Use given filename as index page for directories\n"
|
2010-04-15 22:46:35 +03:00
|
|
|
" -S Do not follow symbolic links outside of the docroot\n"
|
2010-07-23 16:15:22 +03:00
|
|
|
" -D Do not allow directory listings, send 403 instead\n"
|
2010-08-11 03:05:34 +03:00
|
|
|
" -R Enable RFC1918 filter\n"
|
2012-05-28 03:52:24 +03:00
|
|
|
" -n count Maximum allowed number of concurrent requests\n"
|
2010-03-25 17:46:16 +02:00
|
|
|
#ifdef HAVE_LUA
|
|
|
|
" -l string URL prefix for Lua handler, default is '/lua'\n"
|
|
|
|
" -L file Lua handler script, omit to disable Lua\n"
|
|
|
|
#endif
|
2012-05-28 03:52:24 +03:00
|
|
|
#ifdef HAVE_UBUS
|
|
|
|
" -u string URL prefix for HTTP/JSON handler, default is '/ubus'\n"
|
|
|
|
" -U file Override ubus socket path\n"
|
|
|
|
#endif
|
2010-03-25 17:46:16 +02:00
|
|
|
#ifdef HAVE_CGI
|
|
|
|
" -x string URL prefix for CGI handler, default is '/cgi-bin'\n"
|
2010-08-14 03:54:24 +03:00
|
|
|
" -i .ext=path Use interpreter at path for files with the given extension\n"
|
2010-03-27 02:00:33 +02:00
|
|
|
#endif
|
2012-05-28 03:52:24 +03:00
|
|
|
#if defined(HAVE_CGI) || defined(HAVE_LUA) || defined(HAVE_UBUS)
|
|
|
|
" -t seconds CGI, Lua and UBUS script timeout in seconds, default is 60\n"
|
2010-03-25 17:46:16 +02:00
|
|
|
#endif
|
2010-04-15 22:46:35 +03:00
|
|
|
" -T seconds Network timeout in seconds, default is 30\n"
|
2010-03-25 17:46:16 +02:00
|
|
|
" -d string URL decode given string\n"
|
|
|
|
" -r string Specify basic auth realm\n"
|
|
|
|
" -m string MD5 crypt given string\n"
|
|
|
|
"\n", argv[0]
|
|
|
|
);
|
|
|
|
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef HAVE_TLS
|
2012-05-03 20:19:22 +03:00
|
|
|
if ((tls == 1) && (keys < 2))
|
2010-03-25 17:46:16 +02:00
|
|
|
{
|
|
|
|
fprintf(stderr, "Error: Missing private key or certificate file\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-05-03 20:19:22 +03:00
|
|
|
if (bound < 1)
|
2010-03-25 17:46:16 +02:00
|
|
|
{
|
|
|
|
fprintf(stderr, "Error: No sockets bound, unable to continue\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* default docroot */
|
2012-05-03 20:19:22 +03:00
|
|
|
if (!conf.docroot[0] && !realpath(".", conf.docroot))
|
2010-03-25 17:46:16 +02:00
|
|
|
{
|
|
|
|
fprintf(stderr, "Error: Can not determine default document root: %s\n",
|
|
|
|
strerror(errno));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* default realm */
|
2012-05-03 20:19:22 +03:00
|
|
|
if (!conf.realm)
|
2010-03-25 17:46:16 +02:00
|
|
|
conf.realm = "Protected Area";
|
|
|
|
|
|
|
|
/* config file */
|
2010-07-23 16:15:22 +03:00
|
|
|
uh_config_parse(&conf);
|
2010-03-25 17:46:16 +02:00
|
|
|
|
2012-05-28 03:52:24 +03:00
|
|
|
/* default max requests */
|
|
|
|
if (conf.max_requests <= 0)
|
|
|
|
conf.max_requests = 3;
|
|
|
|
|
2010-04-15 22:46:35 +03:00
|
|
|
/* default network timeout */
|
2012-05-03 20:19:22 +03:00
|
|
|
if (conf.network_timeout <= 0)
|
2010-04-15 22:46:35 +03:00
|
|
|
conf.network_timeout = 30;
|
|
|
|
|
2012-05-28 03:52:24 +03:00
|
|
|
#if defined(HAVE_CGI) || defined(HAVE_LUA) || defined(HAVE_UBUS)
|
2010-03-27 02:00:33 +02:00
|
|
|
/* default script timeout */
|
2012-05-03 20:19:22 +03:00
|
|
|
if (conf.script_timeout <= 0)
|
2010-03-27 02:00:33 +02:00
|
|
|
conf.script_timeout = 60;
|
|
|
|
#endif
|
|
|
|
|
2010-03-25 17:46:16 +02:00
|
|
|
#ifdef HAVE_CGI
|
|
|
|
/* default cgi prefix */
|
2012-05-03 20:19:22 +03:00
|
|
|
if (!conf.cgi_prefix)
|
2010-03-25 17:46:16 +02:00
|
|
|
conf.cgi_prefix = "/cgi-bin";
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_LUA
|
|
|
|
/* load Lua plugin */
|
2012-05-03 20:19:22 +03:00
|
|
|
if (!(lib = dlopen("uhttpd_lua.so", RTLD_LAZY | RTLD_GLOBAL)))
|
2010-03-25 17:46:16 +02:00
|
|
|
{
|
|
|
|
fprintf(stderr,
|
2012-05-03 20:19:22 +03:00
|
|
|
"Notice: Unable to load Lua plugin - disabling Lua support! "
|
|
|
|
"(Reason: %s)\n", dlerror());
|
2010-03-25 17:46:16 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* resolve functions */
|
2012-05-03 20:19:22 +03:00
|
|
|
if (!(conf.lua_init = dlsym(lib, "uh_lua_init")) ||
|
2010-04-15 22:46:35 +03:00
|
|
|
!(conf.lua_close = dlsym(lib, "uh_lua_close")) ||
|
2012-05-03 20:19:22 +03:00
|
|
|
!(conf.lua_request = dlsym(lib, "uh_lua_request")))
|
|
|
|
{
|
2010-03-25 17:46:16 +02:00
|
|
|
fprintf(stderr,
|
2012-05-03 20:19:22 +03:00
|
|
|
"Error: Failed to lookup required symbols "
|
|
|
|
"in Lua plugin: %s\n", dlerror()
|
2010-03-25 17:46:16 +02:00
|
|
|
);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* init Lua runtime if handler is specified */
|
2012-05-03 20:19:22 +03:00
|
|
|
if (conf.lua_handler)
|
2010-03-25 17:46:16 +02:00
|
|
|
{
|
|
|
|
/* default lua prefix */
|
2012-05-03 20:19:22 +03:00
|
|
|
if (!conf.lua_prefix)
|
2010-03-25 17:46:16 +02:00
|
|
|
conf.lua_prefix = "/lua";
|
|
|
|
|
2012-05-03 20:19:20 +03:00
|
|
|
conf.lua_state = conf.lua_init(&conf);
|
2010-03-25 17:46:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-05-28 03:52:24 +03:00
|
|
|
#ifdef HAVE_UBUS
|
|
|
|
/* load ubus plugin */
|
|
|
|
if (!(lib = dlopen("uhttpd_ubus.so", RTLD_LAZY | RTLD_GLOBAL)))
|
|
|
|
{
|
|
|
|
fprintf(stderr,
|
|
|
|
"Notice: Unable to load ubus plugin - disabling ubus support! "
|
|
|
|
"(Reason: %s)\n", dlerror());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* resolve functions */
|
|
|
|
if (!(conf.ubus_init = dlsym(lib, "uh_ubus_init")) ||
|
|
|
|
!(conf.ubus_close = dlsym(lib, "uh_ubus_close")) ||
|
|
|
|
!(conf.ubus_request = dlsym(lib, "uh_ubus_request")))
|
|
|
|
{
|
|
|
|
fprintf(stderr,
|
|
|
|
"Error: Failed to lookup required symbols "
|
|
|
|
"in ubus plugin: %s\n", dlerror()
|
|
|
|
);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* default ubus prefix */
|
|
|
|
if (!conf.ubus_prefix)
|
|
|
|
conf.ubus_prefix = "/ubus";
|
|
|
|
|
|
|
|
conf.ubus_state = conf.ubus_init(&conf);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-03-25 17:46:16 +02:00
|
|
|
/* fork (if not disabled) */
|
2012-05-03 20:19:22 +03:00
|
|
|
if (!nofork)
|
2010-03-25 17:46:16 +02:00
|
|
|
{
|
2012-05-03 20:19:22 +03:00
|
|
|
switch (fork())
|
2010-03-25 17:46:16 +02:00
|
|
|
{
|
|
|
|
case -1:
|
|
|
|
perror("fork()");
|
|
|
|
exit(1);
|
|
|
|
|
|
|
|
case 0:
|
|
|
|
/* daemon setup */
|
2012-05-03 20:19:22 +03:00
|
|
|
if (chdir("/"))
|
2010-03-25 17:46:16 +02:00
|
|
|
perror("chdir()");
|
|
|
|
|
2012-05-03 20:19:22 +03:00
|
|
|
if ((cur_fd = open("/dev/null", O_WRONLY)) > -1)
|
2010-03-25 17:46:16 +02:00
|
|
|
dup2(cur_fd, 0);
|
|
|
|
|
2012-05-03 20:19:22 +03:00
|
|
|
if ((cur_fd = open("/dev/null", O_RDONLY)) > -1)
|
2010-03-25 17:46:16 +02:00
|
|
|
dup2(cur_fd, 1);
|
|
|
|
|
2012-05-03 20:19:22 +03:00
|
|
|
if ((cur_fd = open("/dev/null", O_RDONLY)) > -1)
|
2010-03-25 17:46:16 +02:00
|
|
|
dup2(cur_fd, 2);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-14 03:54:24 +03:00
|
|
|
/* server main loop */
|
2012-05-28 03:52:24 +03:00
|
|
|
uloop_run();
|
2010-03-25 17:46:16 +02:00
|
|
|
|
|
|
|
#ifdef HAVE_LUA
|
|
|
|
/* destroy the Lua state */
|
2012-05-03 20:19:22 +03:00
|
|
|
if (conf.lua_state != NULL)
|
2010-08-14 03:54:24 +03:00
|
|
|
conf.lua_close(conf.lua_state);
|
2010-03-25 17:46:16 +02:00
|
|
|
#endif
|
|
|
|
|
2012-05-28 03:52:24 +03:00
|
|
|
#ifdef HAVE_UBUS
|
|
|
|
/* destroy the ubus state */
|
|
|
|
if (conf.ubus_state != NULL)
|
|
|
|
conf.ubus_close(conf.ubus_state);
|
|
|
|
#endif
|
|
|
|
|
2010-03-25 17:46:16 +02:00
|
|
|
return 0;
|
|
|
|
}
|