Imported Upstream version 2.6.0

This commit is contained in:
arnaud.quette@free.fr 2011-01-26 10:35:08 +01:00
parent 26fb71b504
commit 459aaf9392
510 changed files with 40508 additions and 18859 deletions

View file

@ -70,9 +70,7 @@ static ctype_t *firstclient = NULL;
/* default is to listen on all local interfaces */
static stype_t *firstaddr = NULL;
#ifdef HAVE_IPV6
static int opt_af = AF_UNSPEC;
#endif
typedef enum {
DRIVER = 1,
@ -95,7 +93,6 @@ static char pidfn[SMALLBUF];
/* set by signal handlers */
static int reload_flag = 0, exit_flag = 0;
#ifdef HAVE_IPV6
static const char *inet_ntopW (struct sockaddr_storage *s)
{
static char str[40];
@ -111,7 +108,6 @@ static const char *inet_ntopW (struct sockaddr_storage *s)
return NULL;
}
}
#endif
/* return a pointer to the named ups if possible */
upstype_t *get_ups_ptr(const char *name)
@ -181,59 +177,6 @@ void listen_add(const char *addr, const char *port)
/* create a listening socket for tcp connections */
static void setuptcp(stype_t *server)
{
#ifndef HAVE_IPV6
struct hostent *host;
struct sockaddr_in sockin;
int res, one = 1;
host = gethostbyname(server->addr);
if (!host) {
struct in_addr listenaddr;
if (!inet_aton(server->addr, &listenaddr)) {
fatal_with_errno(EXIT_FAILURE, "inet_aton");
}
host = gethostbyaddr(&listenaddr, sizeof(listenaddr), AF_INET);
if (!host) {
fatal_with_errno(EXIT_FAILURE, "gethostbyaddr");
}
}
if ((server->sock_fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
fatal_with_errno(EXIT_FAILURE, "socket");
}
res = setsockopt(server->sock_fd, SOL_SOCKET, SO_REUSEADDR, (void *) &one, sizeof(one));
if (res != 0) {
fatal_with_errno(EXIT_FAILURE, "setsockopt(SO_REUSEADDR)");
}
memset(&sockin, '\0', sizeof(sockin));
sockin.sin_family = AF_INET;
sockin.sin_port = htons(atoi(server->port));
memcpy(&sockin.sin_addr, host->h_addr, host->h_length);
if (bind(server->sock_fd, (struct sockaddr *) &sockin, sizeof(sockin)) == -1) {
fatal_with_errno(EXIT_FAILURE, "Can't bind TCP port %s", server->port);
}
if ((res = fcntl(server->sock_fd, F_GETFL, 0)) == -1) {
fatal_with_errno(EXIT_FAILURE, "fcntl(get)");
}
if (fcntl(server->sock_fd, F_SETFL, res | O_NDELAY) == -1) {
fatal_with_errno(EXIT_FAILURE, "fcntl(set)");
}
if (listen(server->sock_fd, 16)) {
fatal_with_errno(EXIT_FAILURE, "listen");
}
#else
struct addrinfo hints, *res, *ai;
int v = 0, one = 1;
@ -290,7 +233,6 @@ static void setuptcp(stype_t *server)
}
freeaddrinfo(res);
#endif
/* don't fail silently */
if (server->sock_fd < 0) {
@ -468,7 +410,8 @@ static void check_command(int cmdnum, ctype_t *client, int numarg,
}
#ifdef HAVE_WRAP
request_init(&req, RQ_DAEMON, progname, RQ_CLIENT_ADDR, client->addr, RQ_USER, client->username, 0);
request_init(&req, RQ_DAEMON, progname, RQ_FILE, client->sock_fd, RQ_USER, client->username, 0);
fromhost(&req);
if (!hosts_access(&req)) {
/* tcp-wrappers says access should be denied */
@ -508,11 +451,7 @@ static void parse_net(ctype_t *client)
/* answer incoming tcp connections */
static void client_connect(stype_t *server)
{
#ifndef HAVE_IPV6
struct sockaddr_in csock;
#else
struct sockaddr_storage csock;
#endif
socklen_t clen;
int fd;
ctype_t *client;
@ -530,11 +469,7 @@ static void client_connect(stype_t *server)
time(&client->last_heard);
#ifndef HAVE_IPV6
client->addr = xstrdup(inet_ntoa(csock.sin_addr));
#else
client->addr = xstrdup(inet_ntopW(&csock));
#endif
pconf_init(&client->ctx, NULL);
@ -610,7 +545,6 @@ void server_load(void)
/* default behaviour if no LISTEN addres has been specified */
if (!firstaddr) {
#ifdef HAVE_IPV6
if (opt_af != AF_INET) {
listen_add("::1", string_const(PORT));
}
@ -618,9 +552,6 @@ void server_load(void)
if (opt_af != AF_INET6) {
listen_add("127.0.0.1", string_const(PORT));
}
#else
listen_add("127.0.0.1", string_const(PORT));
#endif
}
for (server = firstaddr; server; server = server->next) {
@ -879,12 +810,11 @@ static void help(const char *progname)
printf(" -D raise debugging level\n");
printf(" -h display this help\n");
printf(" -r <dir> chroots to <dir>\n");
printf(" -q raise log level threshold\n");
printf(" -u <user> switch to <user> (if started as root)\n");
printf(" -V display the version of this software\n");
#ifdef HAVE_IPV6
printf(" -4 IPv4 only\n");
printf(" -6 IPv6 only\n");
#endif
exit(EXIT_SUCCESS);
}
@ -943,24 +873,21 @@ int main(int argc, char **argv)
{
int i, cmd = 0;
char *chroot_path = NULL;
const char *user = NULL;
const char *user = RUN_AS_USER;
struct passwd *new_uid = NULL;
progname = xbasename(argv[0]);
/* pick up a default from configure --with-user */
user = RUN_AS_USER;
/* yes, xstrdup - the conf handlers call free on this later */
statepath = xstrdup(dflt_statepath());
datapath = xstrdup(DATADIR);
/* set up some things for later */
snprintf(pidfn, sizeof(pidfn), "%s/upsd.pid", altpidpath());
snprintf(pidfn, sizeof(pidfn), "%s/%s.pid", altpidpath(), progname);
printf("Network UPS Tools upsd %s\n", UPS_VERSION);
printf("Network UPS Tools %s %s\n", progname, UPS_VERSION);
while ((i = getopt(argc, argv, "+h46p:r:i:fu:Vc:D")) != -1) {
while ((i = getopt(argc, argv, "+h46p:qr:i:fu:Vc:D")) != -1) {
switch (i) {
case 'h':
help(progname);
@ -970,6 +897,9 @@ int main(int argc, char **argv)
fatalx(EXIT_FAILURE, "Specifying a listening addresses with '-i <address>' and '-p <port>'\n"
"is deprecated. Use 'LISTEN <address> [<port>]' in 'upsd.conf' instead.\n"
"See 'man 8 upsd.conf' for more information.");
case 'q':
nut_log_level++;
break;
case 'r':
chroot_path = optarg;
break;
@ -977,7 +907,6 @@ int main(int argc, char **argv)
user = optarg;
break;
case 'V':
/* do nothing - we already printed the banner */
exit(EXIT_SUCCESS);
@ -996,15 +925,13 @@ int main(int argc, char **argv)
nut_debug_level++;
break;
#ifdef HAVE_IPV6
case '4':
case '4':
opt_af = AF_INET;
break;
case '6':
case '6':
opt_af = AF_INET6;
break;
#endif
default:
help(progname);
@ -1028,7 +955,7 @@ int main(int argc, char **argv)
setup_signals();
open_syslog("upsd");
open_syslog(progname);
/* send logging to the syslog pre-background for later use */
syslogbit_set();
@ -1049,6 +976,9 @@ int main(int argc, char **argv)
/* start server */
server_load();
/* initialize SSL before we drop privileges (we may not be able to read the keyfile as non-root) */
ssl_init();
become_user(new_uid);
if (chdir(statepath)) {
@ -1067,8 +997,6 @@ int main(int argc, char **argv)
fatalx(EXIT_FAILURE, "Fatal error: at least one UPS must be defined in ups.conf");
}
ssl_init();
/* try to bring in the var/cmd descriptions */
desc_load();
@ -1089,3 +1017,4 @@ int main(int argc, char **argv)
upslogx(LOG_INFO, "Signal %d: exiting", exit_flag);
return EXIT_SUCCESS;
}