Fix mdoc(7)/man(7) mix up.
[netbsd-mini2440.git] / lib / libwrap / update.c
blobd06f66d77042cd33137694d29413d9d49af48975
1 /* $NetBSD: update.c,v 1.7 2002/06/06 21:42:43 itojun Exp $ */
3 /*
4 * Routines for controlled update/initialization of request structures.
5 *
6 * request_init() initializes its argument. Pointers and string-valued members
7 * are initialized to zero, to indicate that no lookup has been attempted.
8 *
9 * request_set() adds information to an already initialized request structure.
11 * Both functions take a variable-length name-value list.
13 * Diagnostics are reported through syslog(3).
15 * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands.
18 #include <sys/cdefs.h>
19 #ifndef lint
20 #if 0
21 static char sccsid[] = "@(#) update.c 1.1 94/12/28 17:42:56";
22 #else
23 __RCSID("$NetBSD: update.c,v 1.7 2002/06/06 21:42:43 itojun Exp $");
24 #endif
25 #endif
27 /* System libraries */
29 #include <stdio.h>
30 #include <syslog.h>
31 #include <string.h>
32 #include <unistd.h>
34 /* Local stuff. */
36 #include "mystdarg.h"
37 #include "tcpd.h"
39 static struct request_info *request_fill __P((struct request_info *, va_list));
41 /* request_fill - request update engine */
43 static struct request_info *request_fill(request, ap)
44 struct request_info *request;
45 va_list ap;
47 int key;
48 char *ptr;
50 while ((key = va_arg(ap, int)) > 0) {
51 switch (key) {
52 default:
53 tcpd_warn("request_fill: invalid key: %d", key);
54 return (request);
55 case RQ_FILE:
56 request->fd = va_arg(ap, int);
57 continue;
58 case RQ_CLIENT_SIN:
59 request->client->sin = va_arg(ap, struct sockaddr *);
60 continue;
61 case RQ_SERVER_SIN:
62 request->server->sin = va_arg(ap, struct sockaddr *);
63 continue;
66 * All other fields are strings with the same maximal length.
69 case RQ_DAEMON:
70 ptr = request->daemon;
71 break;
72 case RQ_USER:
73 ptr = request->user;
74 break;
75 case RQ_CLIENT_NAME:
76 ptr = request->client->name;
77 break;
78 case RQ_CLIENT_ADDR:
79 ptr = request->client->addr;
80 break;
81 case RQ_SERVER_NAME:
82 ptr = request->server->name;
83 break;
84 case RQ_SERVER_ADDR:
85 ptr = request->server->addr;
86 break;
88 strlcpy(ptr, va_arg(ap, char *), STRING_LENGTH);
90 return (request);
93 /* request_init - initialize request structure */
95 struct request_info *VARARGS(request_init, struct request_info *, request)
97 static struct request_info default_info;
98 struct request_info *r;
99 va_list ap;
102 * Initialize data members. We do not assign default function pointer
103 * members, to avoid pulling in the whole socket module when it is not
104 * really needed.
106 VASTART(ap, struct request_info *, request);
107 *request = default_info;
108 request->fd = -1;
109 (void)strlcpy(request->daemon, unknown, sizeof(request->daemon));
110 (void)snprintf(request->pid, sizeof(request->pid), "%d", getpid());
111 request->client->request = request;
112 request->server->request = request;
113 r = request_fill(request, ap);
114 VAEND(ap);
115 return (r);
118 /* request_set - update request structure */
120 struct request_info *VARARGS(request_set, struct request_info *, request)
122 struct request_info *r;
123 va_list ap;
125 VASTART(ap, struct request_info *, request);
126 r = request_fill(request, ap);
127 VAEND(ap);
128 return (r);