2002-06-07 01:45:19 +04:00
|
|
|
/* $NetBSD: update.c,v 1.8 2002/06/06 21:45:20 itojun Exp $ */
|
1997-10-10 01:20:16 +04:00
|
|
|
|
1996-11-26 19:48:08 +03:00
|
|
|
/*
|
|
|
|
* Routines for controlled update/initialization of request structures.
|
1999-07-03 16:30:16 +04:00
|
|
|
*
|
1996-11-26 19:48:08 +03:00
|
|
|
* request_init() initializes its argument. Pointers and string-valued members
|
|
|
|
* are initialized to zero, to indicate that no lookup has been attempted.
|
1999-07-03 16:30:16 +04:00
|
|
|
*
|
1996-11-26 19:48:08 +03:00
|
|
|
* request_set() adds information to an already initialized request structure.
|
1999-07-03 16:30:16 +04:00
|
|
|
*
|
1996-11-26 19:48:08 +03:00
|
|
|
* Both functions take a variable-length name-value list.
|
1999-07-03 16:30:16 +04:00
|
|
|
*
|
1996-11-26 19:48:08 +03:00
|
|
|
* Diagnostics are reported through syslog(3).
|
1999-07-03 16:30:16 +04:00
|
|
|
*
|
1996-11-26 19:48:08 +03:00
|
|
|
* Author: Wietse Venema, Eindhoven University of Technology, The Netherlands.
|
|
|
|
*/
|
|
|
|
|
1997-10-10 01:20:16 +04:00
|
|
|
#include <sys/cdefs.h>
|
1996-11-26 19:48:08 +03:00
|
|
|
#ifndef lint
|
1997-10-10 01:20:16 +04:00
|
|
|
#if 0
|
1996-11-26 19:48:08 +03:00
|
|
|
static char sccsid[] = "@(#) update.c 1.1 94/12/28 17:42:56";
|
1997-10-10 01:20:16 +04:00
|
|
|
#else
|
2002-06-07 01:45:19 +04:00
|
|
|
__RCSID("$NetBSD: update.c,v 1.8 2002/06/06 21:45:20 itojun Exp $");
|
1997-10-10 01:20:16 +04:00
|
|
|
#endif
|
1996-11-26 19:48:08 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* System libraries */
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <syslog.h>
|
|
|
|
#include <string.h>
|
1997-10-10 01:20:16 +04:00
|
|
|
#include <unistd.h>
|
1996-11-26 19:48:08 +03:00
|
|
|
|
|
|
|
/* Local stuff. */
|
|
|
|
|
|
|
|
#include "mystdarg.h"
|
|
|
|
#include "tcpd.h"
|
|
|
|
|
1997-10-10 01:20:16 +04:00
|
|
|
static struct request_info *request_fill __P((struct request_info *, va_list));
|
|
|
|
|
1996-11-26 19:48:08 +03:00
|
|
|
/* request_fill - request update engine */
|
|
|
|
|
|
|
|
static struct request_info *request_fill(request, ap)
|
|
|
|
struct request_info *request;
|
|
|
|
va_list ap;
|
|
|
|
{
|
|
|
|
int key;
|
|
|
|
char *ptr;
|
|
|
|
|
|
|
|
while ((key = va_arg(ap, int)) > 0) {
|
|
|
|
switch (key) {
|
|
|
|
default:
|
|
|
|
tcpd_warn("request_fill: invalid key: %d", key);
|
|
|
|
return (request);
|
|
|
|
case RQ_FILE:
|
|
|
|
request->fd = va_arg(ap, int);
|
|
|
|
continue;
|
|
|
|
case RQ_CLIENT_SIN:
|
1999-08-31 17:58:58 +04:00
|
|
|
request->client->sin = va_arg(ap, struct sockaddr *);
|
1996-11-26 19:48:08 +03:00
|
|
|
continue;
|
|
|
|
case RQ_SERVER_SIN:
|
1999-08-31 17:58:58 +04:00
|
|
|
request->server->sin = va_arg(ap, struct sockaddr *);
|
1996-11-26 19:48:08 +03:00
|
|
|
continue;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* All other fields are strings with the same maximal length.
|
|
|
|
*/
|
|
|
|
|
|
|
|
case RQ_DAEMON:
|
|
|
|
ptr = request->daemon;
|
|
|
|
break;
|
|
|
|
case RQ_USER:
|
|
|
|
ptr = request->user;
|
|
|
|
break;
|
|
|
|
case RQ_CLIENT_NAME:
|
|
|
|
ptr = request->client->name;
|
|
|
|
break;
|
|
|
|
case RQ_CLIENT_ADDR:
|
|
|
|
ptr = request->client->addr;
|
|
|
|
break;
|
|
|
|
case RQ_SERVER_NAME:
|
|
|
|
ptr = request->server->name;
|
|
|
|
break;
|
|
|
|
case RQ_SERVER_ADDR:
|
|
|
|
ptr = request->server->addr;
|
|
|
|
break;
|
|
|
|
}
|
2002-06-07 01:45:19 +04:00
|
|
|
strlcpy(ptr, va_arg(ap, char *), STRING_LENGTH);
|
1996-11-26 19:48:08 +03:00
|
|
|
}
|
|
|
|
return (request);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* request_init - initialize request structure */
|
|
|
|
|
|
|
|
struct request_info *VARARGS(request_init, struct request_info *, request)
|
|
|
|
{
|
|
|
|
static struct request_info default_info;
|
|
|
|
struct request_info *r;
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize data members. We do not assign default function pointer
|
|
|
|
* members, to avoid pulling in the whole socket module when it is not
|
|
|
|
* really needed.
|
|
|
|
*/
|
|
|
|
VASTART(ap, struct request_info *, request);
|
|
|
|
*request = default_info;
|
|
|
|
request->fd = -1;
|
2002-06-07 01:42:42 +04:00
|
|
|
(void)strlcpy(request->daemon, unknown, sizeof(request->daemon));
|
1997-01-23 17:01:45 +03:00
|
|
|
(void)snprintf(request->pid, sizeof(request->pid), "%d", getpid());
|
1996-11-26 19:48:08 +03:00
|
|
|
request->client->request = request;
|
|
|
|
request->server->request = request;
|
|
|
|
r = request_fill(request, ap);
|
|
|
|
VAEND(ap);
|
|
|
|
return (r);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* request_set - update request structure */
|
|
|
|
|
|
|
|
struct request_info *VARARGS(request_set, struct request_info *, request)
|
|
|
|
{
|
|
|
|
struct request_info *r;
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
VASTART(ap, struct request_info *, request);
|
|
|
|
r = request_fill(request, ap);
|
|
|
|
VAEND(ap);
|
|
|
|
return (r);
|
|
|
|
}
|